import Link from "next/link";
import { Button } from "@/components/ui/button";
import AdminPageHeader from "@/components/admin/admin-page-header";
import ProjectForm from "@/components/admin/project-form";
import { prisma } from "@/lib/db";
import type { ProjectInput } from "@/lib/validations/project";

export default async function NewProjectPage() {
  const categories = await prisma.category.findMany({
    where: { kind: "PROJECT" },
    orderBy: [{ order: "asc" }, { nameEn: "asc" }],
    select: { id: true, nameAr: true, nameEn: true },
  });

  const defaultValues: ProjectInput = {
    type: "PORTFOLIO",
    slug: "",
    titleAr: "",
    titleEn: "",
    summaryAr: "",
    summaryEn: "",
    descAr: "",
    descEn: "",
    coverImage: "",
    images: [],
    technologies: [],
    externalUrl: "",
    repoUrl: "",
    platform: "",
    appStoreUrl: "",
    testflightUrl: "",
    appVersion: "",
    supportUrl: "",
    appPrivacyUrl: "",
    status: "DRAFT",
    isFeatured: false,
    sortOrder: 0,
    categoryId: "",
  };

  return (
    <div className="mx-auto w-full max-w-7xl">
      <AdminPageHeader
        title="New project"
        description="Create a project or app record with media, links, category, and publishing controls."
        actions={
          <Button asChild variant="outline">
            <Link href="/admin/projects">Back to projects</Link>
          </Button>
        }
      />
      <ProjectForm mode="create" categories={categories} defaultValues={defaultValues} />
    </div>
  );
}
