import { FaqItem } from '@/lib/api';
import FaqClient from './FaqClient';

const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';

// Fetch the published FAQ list on the server so the questions and answers are
// rendered into the initial HTML (crawlers see the content without running JS).
async function getFaqs(): Promise<FaqItem[]> {
  try {
    const res = await fetch(`${apiUrl}/api/faq`, { next: { revalidate: 60 } });
    if (!res.ok) return [];
    const data = await res.json();
    return data.faqs || [];
  } catch {
    return [];
  }
}

export default async function FAQPage() {
  const faqs = await getFaqs();
  return <FaqClient initialFaqs={faqs} />;
}
