"use client"; import React, { useEffect, useState } from "react"; import { HelpCircle, ChevronDown } from "lucide-react"; import { motion, AnimatePresence } from "motion/react"; import { useSettingsStore } from "../lib/store/settingsStore"; import { safeJsonLd } from "../lib/schema"; import api from "../lib/services/api"; export interface FAQItem { id: string; question: string; answer: string; order: number; } export default function FAQSection() { const getText = useSettingsStore((state) => state.getText); const [faqs, setFaqs] = useState([]); const [openIndex, setOpenIndex] = useState(0); const [isLoading, setIsLoading] = useState(true); useEffect(() => { async function loadFaqs() { try { setIsLoading(true); const res = await api.get("/faq"); const list = Array.isArray(res.data) ? res.data : []; setFaqs(list); } catch (err) { console.error("Failed to load FAQs:", err); setFaqs([]); } finally { setIsLoading(false); } } loadFaqs(); }, []); if (!isLoading && faqs.length === 0) { return null; } // Schema.org FAQPage JSON-LD structure const faqSchema = { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": faqs.map((faq) => ({ "@type": "Question", "name": faq.question, "acceptedAnswer": { "@type": "Answer", "text": faq.answer, }, })), }; return (
{/* Schema.org FAQPage Rich Snippet */} {faqs.length > 0 && (