"use client";

import { FolderKanban } from "lucide-react";

import { useProjects } from "@/components/projects/projects-context";
import { ProjectCard } from "@/components/projects/project-card";
import { CreateProjectDialog } from "@/components/projects/create-project-dialog";

export function ProjectsListView() {
  const { projects } = useProjects();

  return (
    <div className="flex h-full flex-col gap-4 p-4">
      <div className="flex flex-wrap items-end justify-between gap-3 px-1">
        <div>
          <h1 className="font-heading text-xl font-bold tracking-tight">Projects</h1>
          <p className="mt-0.5 text-[13px] text-muted-foreground">
            Each project is its own isolated board, separate from Home.
          </p>
        </div>
        {projects.length > 0 && (
          <p className="rounded-full bg-foreground/5 px-3 py-1 text-xs font-medium text-muted-foreground tabular-nums">
            {projects.length} project{projects.length === 1 ? "" : "s"}
          </p>
        )}
      </div>

      {projects.length === 0 && (
        <div className="flex flex-col items-center gap-3 rounded-2xl border border-dashed border-border/80 p-10 text-center">
          <div className="flex size-14 items-center justify-center rounded-2xl bg-primary/10 text-primary">
            <FolderKanban className="size-7" />
          </div>
          <div className="space-y-1">
            <h2 className="font-heading text-lg font-semibold">No projects yet</h2>
            <p className="max-w-xs text-sm text-muted-foreground">
              Create one to get its own board, separate from Home.
            </p>
          </div>
        </div>
      )}

      <div className="grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-4">
        {projects.map((project) => (
          <ProjectCard key={project.id} project={project} />
        ))}
        <CreateProjectDialog />
      </div>
    </div>
  );
}
