import type { Metadata } from 'next';
import { getSEOConfig } from '@/lib/seo-config';
import ConsultationDetailPageClient from '@/app/components/consultation/ConsultationDetailPageClient';

// Generate static params for consultation pages
export async function generateStaticParams() {
    const locales = ['zh-CN', 'zh-TW', 'en'];
    const consultationIds = ['cloud-migration', 'aws-optimization', 'security-audit']; // 示例咨询ID
    
    const params = [];
    for (const locale of locales) {
        for (const id of consultationIds) {
            // 为简体中文生成两个路由：zh 和 zh-CN
            if (locale === 'zh-CN') {
                params.push({ locale: 'zh', id });
                params.push({ locale: 'zh-CN', id });
            } else {
                params.push({ locale, id });
            }
        }
    }
    
    return params;
}

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

    return {
        title: `${seo.title} - ${id}`,
        description: seo.description,
        keywords: seo.keywords,
        openGraph: {
            title: `${seo.openGraph?.title} - ${id}`,
            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} - ${id}`,
            description: seo.twitter?.description,
            images: seo.twitter?.images,
        },
        alternates: {
            canonical: locale === 'zh' ? `/consultation/${id}` : `/${locale}/consultation/${id}`,
            languages: {
                'zh-CN': `/consultation/${id}`,
                'zh-TW': `/zh-TW/consultation/${id}`,
                en: `/en/consultation/${id}`,
            },
        },
    };
}

export default function ConsultationDetailPage({
    params: { locale, id },
}: {
    params: { locale: string; id: string };
}) {
    return <ConsultationDetailPageClient consultationId={id} locale={locale} />;
}
