import type { Locale } from "@/i18n/config";
import type { Dictionary } from "@/i18n/get-dictionary";
import { routes } from "@/lib/routes";
import { products } from "@/content/catalog";
import { FilterGrid } from "@/components/shared/filter-grid";
import { PageIntro } from "@/components/shared/page-intro";
import { ProductCard } from "@/components/shared/product-card";
import { Section } from "@/components/shared/section";

type ProductsListSectionProps = {
  locale: Locale;
  t: Dictionary["products"];
  items: Dictionary["catalog"]["products"];
  categoryLabels: Dictionary["catalog"]["categories"];
};

/** Products page: title, intro, category chips and all product cards (Figma "Products", 1440). */
export function ProductsListSection({ locale, t, items, categoryLabels }: ProductsListSectionProps) {
  return (
    // Under the fixed header: Figma desktop 100px header + 80px. Phone/tablet: 80px header + 20/40px.
    <Section labelledBy="products-page-title" className="pt-[100px] md:pt-[120px] lg:pt-[180px]">
      <div className="flex flex-col gap-10">
        <PageIntro id="products-page-title" title={t.title} lines={t.intro} />
        <FilterGrid
          allLabel={t.all}
          labels={categoryLabels}
          filterLabel={t.filterLabel}
          itemCategories={products.map((p) => p.categories)}
          // Same grid as the Home products section: 2 columns on desktop, 1 below.
          listClassName="grid gap-5 lg:grid-cols-2 lg:gap-10"
        >
          {products.map(({ id, slug, image, color, position, details }) => (
            <ProductCard key={id} image={image} color={color} position={position} href={details && routes.product(locale, slug)} {...items[id]} />
          ))}
        </FilterGrid>
      </div>
    </Section>
  );
}
