import { notFound } from "next/navigation";
import { prisma } from "@/lib/db";
import { AddonForm } from "@/components/admin/AddonForm";
import { AddonScreenshots } from "@/components/admin/AddonScreenshots";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";

export const dynamic = "force-dynamic";

export default async function EditAddonPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const addon = await prisma.addon.findUnique({
    where: { id },
    include: { screenshots: { orderBy: { sortOrder: "asc" } } },
  });

  if (!addon) notFound();

  return (
    <div className="mx-auto max-w-2xl space-y-6">
      <h1 className="text-3xl font-bold">编辑插件</h1>
      <AddonForm initialData={addon} />
      <Card>
        <CardHeader>
          <CardTitle>说明截图</CardTitle>
        </CardHeader>
        <CardContent>
          <AddonScreenshots
            addonId={addon.id}
            initial={JSON.parse(JSON.stringify(addon.screenshots))}
          />
        </CardContent>
      </Card>
    </div>
  );
}
