import type { Metadata } from "next";
import { ArrowUpRight, CircleDollarSign } from "lucide-react";
import Link from "next/link";
import { getTranslations } from "next-intl/server";

import { Container } from "@/components/layout/container";
import { PageHero } from "@/components/layout/page-hero";
import { MotionFade } from "@/components/motion-fade";
import { buildLocalizedMetadata } from "@/lib/metadata";
import { AppCard } from "@/components/ui/app-card";
import { CardContent } from "@/components/ui/card";
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
import { pickText, productItems } from "@/lib/site-data";

type ProductsPageProps = {
  params: {
    locale: string;
  };
};

export async function generateMetadata({
  params: { locale },
}: ProductsPageProps): Promise<Metadata> {
  const localeKey = resolveLocale(locale);
  const t = await getTranslations({ locale: localeKey, namespace: "productsPage" });

  return await buildLocalizedMetadata({
    locale: localeKey,
    pathname: "/products",
    title: t("title"),
    description: t("intro"),
  });
}

export default async function ProductsPage({ params: { locale } }: ProductsPageProps) {
  const localeKey = resolveLocale(locale);
  const t = await getTranslations({ locale: localeKey, namespace: "productsPage" });

  return (
    <>
      <PageHero title={t("title")} description={t("intro")} />

      <Container className="flex flex-col gap-section pb-12 lg:pb-16">
        <section className="grid gap-4 md:grid-cols-3">
        {productItems.map((item, index) => (
          <MotionFade key={item.slug} delay={index * 0.05}>
            <AppCard interactive>
              <CardContent className="p-5">
                <Link
                  href={getLocalizedPath(localeKey, `/products/${item.slug}`)}
                  className="group block"
                >
                  <p className="text-sm text-muted-foreground/80">
                    {pickText(item.segment, localeKey)}
                  </p>
                  <h2 className="mt-3 text-xl font-semibold text-foreground">
                    {pickText(item.name, localeKey)}
                  </h2>
                  <p className="mt-2 text-sm text-muted-foreground">
                    {pickText(item.summary, localeKey)}
                  </p>
                  <p className="mt-4 inline-flex items-center gap-2 text-sm font-medium text-foreground/80">
                    <CircleDollarSign className="h-4 w-4 text-brand-secondary" />
                    {pickText(item.price, localeKey)}
                  </p>
                  <p className="mt-4 inline-flex items-center gap-2 text-sm font-medium text-foreground/80 group-hover:text-foreground">
                    {t("open")}
                    <ArrowUpRight className="h-4 w-4" />
                  </p>
                </Link>
              </CardContent>
            </AppCard>
          </MotionFade>
        ))}
        </section>
      </Container>
    </>
  );
}
