1import React, { useState } from 'react';
2
3const FAQ_DATA = [
4 {
5 id: 'faq-1',
6 question: 'What prerequisites are required before starting React?',
7 answer: 'You should be comfortable with HTML5, modern CSS layouts (Flexbox/Grid), and ES6+ JavaScript concepts including let/const, arrow functions, destructuring, and array methods (map/filter).'
8 },
9 {
10 id: 'faq-2',
11 question: 'Why should I learn Vite instead of Create React App?',
12 answer: 'Vite leverages native browser ES Modules and esbuild, resulting in near-instant local server start times, lightning-fast Hot Module Replacement, and optimized production bundles.'
13 },
14 {
15 id: 'faq-3',
16 question: 'Does MSK Institute provide industry-recognized certificates?',
17 answer: 'Yes! Upon completing the comprehensive capstone projects and passing the graded quizzes, students receive a cryptographically verifiable MSK Institute Certificate of Completion.'
18 }
19];
20
21export default function FaqAccordion() {
22 // Store an array of active open IDs (supports both single and multi mode)
23 const [openIds, setOpenIds] = useState(['faq-1']);
24 const [allowMultiple, setAllowMultiple] = useState(false);
25
26 const toggleItem = (id) => {
27 if (allowMultiple) {
28 // Multi-open mode: toggle id in array
29 setOpenIds((prev) =>
30 prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
31 );
32 } else {
33 // Single-open mode: open clicked item, or close if already open
34 setOpenIds((prev) => (prev.includes(id) ? [] : [id]));
35 }
36 };
37
38 return (
39 <div className="faq-wrapper">
40 <header className="faq-header">
41 <h2>Frequently Asked Questions</h2>
42
43 {/* Toggle Mode Option */}
44 <label className="toggle-label">
45 <input
46 type="checkbox"
47 checked={allowMultiple}
48 onChange={(e) => {
49 setAllowMultiple(e.target.checked);
50 // Reset to at most 1 item when switching back to single mode
51 if (!e.target.checked && openIds.length > 1) {
52 setOpenIds(openIds.slice(0, 1));
53 }
54 }}
55 />
56 Allow multiple sections open at once
57 </label>
58 </header>
59
60 <div className="accordion-list">
61 {FAQ_DATA.map((item) => {
62 const isOpen = openIds.includes(item.id);
63
64 return (
65 <div key={item.id} className={`accordion-item ${isOpen ? 'active' : ''}`}>
66 {/* Header Button */}
67 <button
68 type="button"
69 className="accordion-trigger"
70 onClick={() => toggleItem(item.id)}
71 aria-expanded={isOpen}
72 aria-controls={`panel-${item.id}`}
73 >
74 <span className="accordion-title">{item.question}</span>
75 <span className="accordion-icon">{isOpen ? '−' : '+'}</span>
76 </button>
77
78 {/* Collapsible Panel */}
79 {isOpen && (
80 <div
81 id={`panel-${item.id}`}
82 className="accordion-panel"
83 role="region"
84 >
85 <p>{item.answer}</p>
86 </div>
87 )}
88 </div>
89 );
90 })}
91 </div>
92 </div>
93 );
94}