import type { Metadata } from "next";
import { locales } from "@/i18n/config";
import { getDictionary, getLocale } from "@/i18n/get-dictionary";
import { Footer } from "@/components/layout/footer/footer";
import { Header } from "@/components/layout/header/header";
import { ProductsListSection } from "@/features/products/list/products-list-section";

export async function generateMetadata(): Promise<Metadata> {
  const { products, brand } = await getDictionary();
  return {
    title: `${products.metaTitle} | ${brand.name}`,
    alternates: { languages: Object.fromEntries(locales.map((l) => [l, `/${l}/products`])) },
  };
}

export default async function ProductsPage() {
  const [locale, dict] = await Promise.all([getLocale(), getDictionary()]);

  return (
    <>
      <Header locale={locale} nav={dict.nav} activeKey="products" />
      <main>
        <ProductsListSection locale={locale} t={dict.products} items={dict.catalog.products} categoryLabels={dict.catalog.categories} />
      </main>
      <Footer locale={locale} t={dict.footer} brandName={dict.brand.name} className="lg:mt-[324px]" />
    </>
  );
}
