import { prisma } from '@/lib/prisma';
import { PostForm } from '@/components/admin/post-form';
import type { Locale } from '@/i18n/config';

export default async function NewPostPage({ params: { locale } }: { params: { locale: Locale } }) {
  const [authors, tags] = await Promise.all([
    prisma.author.findMany({ include: { translations: { where: { locale: 'fr' } } } }),
    prisma.tag.findMany({ include: { translations: { where: { locale: 'fr' } } } })
  ]);

  return (
    <div>
      <h1 className="font-display text-2xl font-semibold">Nouvel article</h1>
      <div className="mt-6">
        <PostForm
          locale={locale}
          authors={authors.map((a) => ({ id: a.id, name: a.translations[0]?.name ?? a.slug }))}
          tags={tags.map((t) => ({ id: t.id, name: t.translations[0]?.name ?? t.slug }))}
        />
      </div>
    </div>
  );
}
