import { notFound } from "next/navigation";
import { OfferForm } from "@/components/admin/OfferForm";
import { getOfferByIdAdmin, updateOffer } from "@/lib/actions/offers";

export default async function EditOfferPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const offerId = Number(id);
  if (Number.isNaN(offerId)) notFound();

  const offer = await getOfferByIdAdmin(offerId);
  if (!offer) notFound();

  const boundUpdate = updateOffer.bind(null, offerId);

  return (
    <div>
      <h1 className="text-2xl font-bold text-charcoal-950">Edit Offer</h1>
      <div className="mt-8">
        <OfferForm offer={offer} action={boundUpdate} />
      </div>
    </div>
  );
}
