import { getTranslations, Locale, getNavigationPaths } from '@/lib/i18n';
import { generateMetadata as generateSEOMetadata } from '@/lib/seo';
import { getLatestNewsArticles } from '@/lib/markdown';
import Layout from '@/components/Layout';
import HomePageClient from '@/components/HomePageClient';
import HomePageSEO from '@/components/HomePageSEO';

interface HomePageProps {
    params: {
        locale: Locale;
    };
}

export async function generateStaticParams() {
    const locales = ['zh-CN', 'zh-TW', 'en'];
    return locales.map((locale) => ({
        locale,
    }));
}

export async function generateMetadata({ params }: HomePageProps) {
    return generateSEOMetadata(params.locale, 'home');
}

export default async function HomePage({ params }: HomePageProps) {
    const { locale } = params;
    const [common, home, latestNews] = await Promise.all([
        getTranslations(locale, 'common'),
        getTranslations(locale, 'home'),
        getLatestNewsArticles(locale, 3),
    ]);

    const navigationPaths = getNavigationPaths(locale);
    const navigation = [
        {
            name: common.navigation.home,
            href: navigationPaths.find((p) => p.key === 'home')?.path || '/',
        },
        {
            name: common.navigation.products,
            href: navigationPaths.find((p) => p.key === 'products')?.path || '/products',
        },
        {
            name: common.navigation.news,
            href: navigationPaths.find((p) => p.key === 'news')?.path || '/news',
        },
        {
            name: common.navigation.support,
            href: navigationPaths.find((p) => p.key === 'support')?.path || '/support',
        },
        {
            name: common.navigation.about,
            href: navigationPaths.find((p) => p.key === 'about')?.path || '/about',
        },
    ];

    return (
        <>
            <HomePageSEO locale={locale} data-oid="ow9gpey" />
            <Layout locale={locale} navigation={navigation} common={common} data-oid="kpluc9n">
                <HomePageClient locale={locale} home={home} common={common} latestNews={latestNews} data-oid="xqjcs:v" />
            </Layout>
        </>
    );
}
