import Link from "next/link";
import { notFound } from "next/navigation";
import { ArrowLeft } from "lucide-react";
import { AdForm } from "@/components/admin/AdForm";
import { getAdByIdAdmin } from "@/lib/queries/ads";

interface EditAdPageProps {
  params: Promise<{ id: string }>;
}

export default async function EditAdPage({ params }: EditAdPageProps) {
  const { id } = await params;
  const ad = await getAdByIdAdmin(id);
  if (!ad) notFound();

  return (
    <div className="space-y-6">
      <Link
        href="/admin/ads"
        className="inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-primary"
      >
        <ArrowLeft className="size-4" />
        返回廣告列表
      </Link>
      <h1 className="text-2xl font-bold">編輯廣告：{ad.name}</h1>
      <AdForm ad={ad} />
    </div>
  );
}