import ArtworkGallery from "@/components/artworks/ArtworkGallery";
import FilterBar from "@/components/artworks/FilterBar";
import { getArtworksPage } from "@/lib/queryArtworks";
import { PlusCircleIcon } from "lucide-react";
import Link from "next/link";

export default async function ArtworksPage({
  searchParams
}: {
  searchParams?: {
    // type?: string;
    published?: string;
    // groupBy?: string;
    // year?: string;
    // album?: string;
    cursor?: string;
  }
}) {
  const {
    // type = "all",
    published = "all",
    // groupBy = "year",
    // year,
    // album,
    cursor = undefined
  } = await searchParams ?? {};
  // const groupMode = groupBy === "album" ? "album" : "year";
  // const groupId = groupMode === "album" ? album ?? "all" : year ?? "all";

  // Filter by type
  // if (type !== "all") {
  //   where.typeId = type === "none" ? null : type;
  // }

  // Filter by published status
  // if (published === "published") {
  //   where.published = true;
  // } else if (published === "unpublished") {
  //   where.published = false;
  // } else if (published === "needsWork") {
  //   where.needsWork = true;
  // }

  // Filter by group (year or album)
  // if (groupMode === "year" && groupId !== "all") {
  //   where.year = parseInt(groupId);
  // } else if (groupMode === "album" && groupId !== "all") {
  //   where.albumId = groupId;
  // }

  const { items, nextCursor } = await getArtworksPage(
    {
      published,
      cursor,
      take: 48
    }
  )

  return (
    <div>
      <div className="flex justify-between pb-4 items-end">
        <h1 className="text-2xl font-bold mb-4">Artworks</h1>
        <Link href="/uploads/single" 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" /> Upload new artwork
        </Link>
        <Link href="/uploads/bulk" 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" /> Upload many artwork
        </Link>
      </div>
      <FilterBar
        // types={types}
        // albums={albums}
        // years={years}
        // currentType={type}
        currentPublished={published}
      // groupBy={groupMode}
      // groupId={groupId}
      />
      <div className="mt-6">
        {items.length > 0 ? (
          <ArtworkGallery initialArtworks={items} initialCursor={nextCursor} />
        ) : (
          <p className="text-muted-foreground italic">No artworks found.</p>
        )}
      </div>
    </div >
  );
}