import { cn } from "cn";
import type { Locale } from "@/i18n/config";
import type { Dictionary } from "@/i18n/get-dictionary";
import { projects } from "@/content/catalog";
import { routes, sectionIds } from "@/lib/routes";
import { SectionHeading } from "@/components/shared/section-heading";
import { SeeAllLink } from "@/components/shared/see-all-link";
import { Section } from "@/components/shared/section";
import { ProjectCard } from "@/components/shared/project-card";

type ProjectsSectionProps = {
  locale: Locale;
  t: Dictionary["home"]["projects"];
  items: Dictionary["catalog"]["projects"];
};

export function ProjectsSection({ locale, t, items }: ProjectsSectionProps) {
  return (
    <Section id={sectionIds.projects} labelledBy="projects-title" className="max-md:py-5 md:max-lg:py-10">
      <SectionHeading
        id="projects-title"
        label={t.label}
        title={t.title}
        action={<SeeAllLink href={routes.projects(locale)} label={t.seeAll} />}
      />
      <ul className="grid gap-5 pt-5 md:grid-cols-2 md:pt-10 lg:grid-cols-3 lg:gap-10 lg:pt-12">
        {projects
          .filter((project) => !project.hideOnHome)
          .map(({ id, slug, image, color, position, hideOnPhone }) => (
          // Phone (Figma 390): 322px cards, centred; only 4 projects.
          <li key={id} className={cn("max-md:mx-auto max-md:w-full max-md:max-w-[322px]", hideOnPhone && "max-md:hidden")}>
            <ProjectCard image={image} color={color} position={position} href={routes.project(locale, slug)} {...items[id]} />
          </li>
        ))}
      </ul>
    </Section>
  );
}
