import type { Metadata } from 'next';
import { getSEOConfig } from '../../../lib/seo-config';
import ProductsServerComponent from '@/app/components/products/ProductsServerComponent';

// Generate static params for supported locales
export async function generateStaticParams() {
    return [
        { locale: 'zh' },
        { locale: 'zh-CN' },
        { locale: 'zh-TW' },
        { locale: 'en' },
    ];
}

// Generate metadata for the products page
export async function generateMetadata({
    params: { locale },
}: {
    params: { locale: string };
}): Promise<Metadata> {
    const language = locale === 'zh' ? 'zh-CN' : locale === 'zh-CN' ? 'zh-CN' : locale === 'zh-TW' ? 'zh-TW' : 'en';
    const seo = getSEOConfig('products', language);

    return {
        title: seo.title,
        description: seo.description,
        keywords: seo.keywords,
        openGraph: {
            title: seo.openGraph?.title,
            description: seo.openGraph?.description,
            type: seo.openGraph?.type as any,
            images: seo.openGraph?.images,
        },
        twitter: {
            card: seo.twitter?.card as any,
            title: seo.twitter?.title,
            description: seo.twitter?.description,
            images: seo.twitter?.images,
        },
        alternates: {
            canonical: locale === 'zh' ? '/products' : `/${locale}/products`,
            languages: {
                'zh-CN': '/products',
                'zh-TW': '/zh-TW/products',
                en: '/en/products',
            },
        },
    };
}

export default function ProductsPage({ params: { locale } }: { params: { locale: string } }) {
    const mappedLocale = locale === 'zh' ? 'zh-CN' : locale === 'zh-CN' ? 'zh-CN' : locale === 'zh-TW' ? 'zh-TW' : 'en';
    
    return <ProductsServerComponent locale={mappedLocale} />;
}
