import { prisma } from '@peyzajart/db'
import { notFound } from 'next/navigation'
import Link from 'next/link'
import AdminDealerForm from '../../../../../components/AdminDealerForm'

export const dynamic = 'force-dynamic'

interface Props { params: { id: string } }

export default async function AdminEditDealerPage({ params }: Props) {
  const id = parseInt(params.id, 10)
  if (isNaN(id)) notFound()

  const dealer = await prisma.dealer.findUnique({
    where: { id },
    select: {
      id: true, dealerCode: true, companyName: true, contactName: true,
      email: true, phone: true, address: true, city: true, discountRate: true,
    },
  })
  if (!dealer) notFound()

  return (
    <div className="p-6 md:p-8 max-w-2xl">
      <div className="mb-6">
        <Link href="/admin/dealers" className="font-body text-xs text-earth hover:text-brown transition-colors">← Bayiler</Link>
        <h1 className="font-display text-4xl font-light text-brown mt-2">Bayi Düzenle</h1>
      </div>
      <AdminDealerForm dealer={dealer} />
    </div>
  )
}
