import { db } from "@/lib/db";
import { notFound } from "next/navigation";
import MatchForm from "../../MatchForm";

export default async function EditMatchPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const [match, countries, rounds] = await Promise.all([
    db.match.findUnique({ where: { id } }),
    db.country.findMany({ orderBy: { name: "asc" } }),
    db.round.findMany({ orderBy: { number: "asc" } }),
  ]);

  if (!match) notFound();

  return (
    <div className="max-w-xl">
      <h1 className="text-2xl font-bold mb-6">ویرایش بازی</h1>
      <MatchForm countries={countries} rounds={rounds} matchId={match.id} initial={match} />
    </div>
  );
}
