import { notFound } from "next/navigation";
import { TourForm } from "@/components/admin/tour/TourForm";
import { prisma } from "@/lib/prisma";
import { updateTour } from "../../actions";

export default async function EditTourPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const tourId = Number(id);

  if (Number.isNaN(tourId)) {
    notFound();
  }

  const tour = await prisma.tour.findUnique({ where: { id: tourId } });

  if (!tour) {
    notFound();
  }

  return (
    <div>
      <h1 className="text-2xl font-semibold text-heading">
        Edit Paket Tour
      </h1>
      <p className="mt-1 text-sm text-body">{tour.title}</p>

      <div className="mt-6 rounded-2xl bg-white p-8 shadow-sm">
        <TourForm
          action={updateTour.bind(null, tourId)}
          tour={tour}
          submitLabel="Simpan Perubahan"
        />
      </div>
    </div>
  );
}
