---
import { STATUTS } from '@notariat-ci/annuaire';
import { libelleStatut, traducteur, type Cle, type Langue } from '@notariat-ci/i18n';
import { StatusBadge } from '@notariat-ci/ui';
import Base from '../layouts/Base.astro';
import { QUESTIONS_FAQ } from '../lib/pages';

interface Props {
  langue: Langue;
}

const { langue } = Astro.props;
const t = traducteur(langue);
const questions = Array.from({ length: QUESTIONS_FAQ }, (_, i) => i + 1);
// Ancres stables pour les liens « définition » (minutes, statuts).
const ancres: Readonly<Record<number, string>> = { 2: 'statuts', 3: 'minutes' };
---

<Base langue={langue} titre={t('faq.titre')} description={t('faq.description')}>
  <h1 class="mb-2 text-4xl font-semibold">{t('faq.titre')}</h1>
  <p class="mb-8 max-w-prose text-lg">{t('faq.description')}</p>
  <div class="flex max-w-prose flex-col gap-8">
    {questions.map((n) => (
      <section id={ancres[n]} class="scroll-mt-4">
        <h2 class="mb-2 text-2xl font-semibold">{t(`faq.q${n}.question` as Cle)}</h2>
        <p>{t(`faq.q${n}.reponse` as Cle)}</p>
        {n === 2 && (
          <dl class="mt-4 flex flex-col gap-4">
            {STATUTS.map((statut) => (
              <div class="flex flex-col gap-1">
                <dt>
                  <StatusBadge status={statut} label={libelleStatut(langue, statut)} />
                </dt>
                <dd>{t(`definition.${statut}`)}</dd>
              </div>
            ))}
          </dl>
        )}
      </section>
    ))}
  </div>
</Base>
