import ListCustomCards from "@/components/commissions/customCards/ListCustomCards";
import { prisma } from "@/lib/prisma";
import { PlusCircleIcon } from "lucide-react";
import Link from "next/link";

export default async function CommissionCustomCardsPage() {
  const cards = await prisma.commissionCustomCard.findMany({
    include: {
      options: { include: { option: true }, orderBy: { sortIndex: "asc" } },
      extras: { include: { extra: true }, orderBy: { sortIndex: "asc" } },
    },
    orderBy: [{ sortIndex: "asc" }, { name: "asc" }],
  });

  return (
    <div>
      <div className="flex gap-4 justify-between pb-8">
        <h1 className="text-2xl font-bold mb-4">Custom Commission Cards</h1>
        <Link
          href="/commissions/custom-cards/new"
          className="flex gap-2 items-center cursor-pointer bg-primary hover:bg-primary/90 text-primary-foreground px-4 py-2 rounded"
        >
          <PlusCircleIcon className="h-[1.2rem] w-[1.2rem] scale-100 rotate-0 transition-all text-primary-foreground" />
          Add new Card
        </Link>
      </div>
      {cards && cards.length > 0 ? (
        <ListCustomCards cards={cards} />
      ) : (
        <p className="text-muted-foreground italic">No custom cards found.</p>
      )}
    </div>
  );
}
