import { notFound } from 'next/navigation';
import { prisma } from '@/lib/prisma';
import { AuthorForm } from '@/components/admin/author-form';
import type { Locale } from '@/i18n/config';

export default async function EditAuthorPage({
  params: { locale, id }
}: {
  params: { locale: Locale; id: string };
}) {
  const author = await prisma.author.findUnique({ where: { id }, include: { translations: true } });
  if (!author) notFound();

  const fr = author.translations.find((t) => t.locale === 'fr');
  const ar = author.translations.find((t) => t.locale === 'ar');

  return (
    <div>
      <h1 className="font-display text-2xl font-semibold">Modifier l'auteur</h1>
      <div className="mt-6">
        <AuthorForm
          locale={locale}
          initial={{
            id: author.id,
            fr: fr ? { name: fr.name, bio: fr.bio ?? undefined } : undefined,
            ar: ar ? { name: ar.name, bio: ar.bio ?? undefined } : undefined
          }}
        />
      </div>
    </div>
  );
}
