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

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

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

  return (
    <div>
      <h1 className="font-display text-2xl font-semibold">Modifier le service</h1>
      <div className="mt-6">
        <ServiceForm
          locale={locale}
          initial={{
            id: service.id,
            order: service.order,
            published: service.published,
            heroImage: service.heroImage ?? undefined,
            fr: fr ? { title: fr.title, summary: fr.summary, description: fr.description } : undefined,
            ar: ar ? { title: ar.title, summary: ar.summary, description: ar.description } : undefined
          }}
        />
      </div>
    </div>
  );
}
