/**
 * FAQ page — fully driven by the merchant's dashboard configuration.
 *
 * The merchant configures FAQs in the Brainerce dashboard under
 *   Sell → Content → FAQ
 *
 * This page fetches the merchant's *primary* FAQ (key='main'). For topical
 * FAQs (e.g. /faq/shipping), copy this route to `app/faq/[topic]/page.tsx`
 * and pass `params.topic` to `client.content.faq.get(topic, locale)`.
 */
import * as React from 'react';
import type { Metadata } from 'next';

import { getServerClient } from '@/core/lib/brainerce.server';
import { localePath } from '@/core/lib/locale-path';
import { getServerNamespace } from '@/core/lib/server-messages';
import { FaqSection } from '@/ui/layout/faq-section';
<% if (i18nEnabled) { %>
type PageProps = {
  params: Promise<{ locale: string }>;
};

// The canonical is set here because the root layout no longer sets one: a
// layout-level canonical is inherited by every page without its own, and this
// page used to tell Google it was a duplicate of the homepage.
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
  const { locale } = await params;
  const [faq, strings] = await Promise.all([
    (await getServerClient(locale)).content.faq.get('main', locale).catch(() => null),
    getServerNamespace('faq', locale),
  ]);
  return {
    title: faq?.name ?? strings.title ?? '',
    alternates: { canonical: localePath(locale, '/faq') },
  };
}

export default async function FaqPage({ params }: PageProps) {
  const { locale } = await params;
  const faq = await (await getServerClient(locale)).content.faq.get('main', locale).catch(() => null);
  return <FaqSection faq={faq} />;
}
<% } else { %>
// The canonical is set here because the root layout no longer sets one: a
// layout-level canonical is inherited by every page without its own, and this
// page used to tell Google it was a duplicate of the homepage.
export async function generateMetadata(): Promise<Metadata> {
  const [faq, strings] = await Promise.all([
    (await getServerClient()).content.faq.get('main').catch(() => null),
    getServerNamespace('faq'),
  ]);
  return {
    title: faq?.name ?? strings.title ?? '',
    alternates: { canonical: localePath(undefined, '/faq') },
  };
}

export default async function FaqPage() {
  const faq = await (await getServerClient()).content.faq.get('main').catch(() => null);
  return <FaqSection faq={faq} />;
}
<% } %>
