import type { Locale } from "@/i18n/config";
import type { Dictionary } from "@/i18n/get-dictionary";
import { products } 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 { ProductCard } from "@/components/shared/product-card";

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

export function ProductsSection({ locale, t, items }: ProductsSectionProps) {
  return (
    <Section id={sectionIds.products} labelledBy="products-title" className="max-md:py-5 md:max-lg:py-10">
      <SectionHeading
        id="products-title"
        label={t.label}
        title={t.title}
        action={<SeeAllLink href={routes.products(locale)} label={t.seeAll} />}
      />
      <ul className="grid gap-5 pt-5 md:pt-10 lg:grid-cols-2 lg:gap-10 lg:pt-12">
        {products.map(({ id, slug, image, color, position, details }) => (
          <li key={id}>
            <ProductCard image={image} color={color} position={position} href={details && routes.product(locale, slug)} {...items[id]} />
          </li>
        ))}
      </ul>
    </Section>
  );
}
