"use client"; import { useId, useRef, useState } from "react"; import { CaretDownIcon } from "@phosphor-icons/react/dist/ssr"; import styles from "./FaqSection.module.css"; export type FaqItem = { question: string; answer: string; }; type FaqSectionProps = { title: string; items: FaqItem[]; }; type AccordionItemProps = { item: FaqItem; isOpen: boolean; buttonId: string; panelId: string; onToggle: () => void; }; function AccordionItem({ item, isOpen, buttonId, panelId, onToggle, }: AccordionItemProps) { const panelRef = useRef(null); const handleToggle = () => { const panel = panelRef.current; if (!panel) return; if (panel.style.maxHeight) { panel.style.maxHeight = ""; } else { panel.style.maxHeight = panel.scrollHeight + "px"; } onToggle(); }; return (

{item.answer}

); } export default function FaqSection({ title, items }: FaqSectionProps) { const baseId = useId(); const [openIndex, setOpenIndex] = useState(null); return (

{title}

{items.map((item, index) => { const isOpen = openIndex === index; return ( setOpenIndex(isOpen ? null : index)} /> ); })}
); }