import { getContentData, getAllContent, ContentItem } from '@/lib/content';
import DocDetail from './DocDetail';

interface PageProps {
    params: { slug: string };
}

export default async function Page({ params: { slug } }: PageProps) {
    // 你可以根据需要改为从 headers、cookies 或其它方式获取语言
    const currentLang = 'zh-CN';

    let doc: ContentItem | null;
    let related: ContentItem[];
    try {
        doc = getContentData(currentLang, slug);
        const all = getAllContent(currentLang);
        related = all
            .filter(
                (item) => item.metadata.category === doc.metadata.category && item.slug !== slug,
            )
            .slice(0, 3);
    } catch {
        doc = null;
        related = [];
    }

    return <DocDetail doc={doc} relatedDocs={related} currentLang={currentLang} />;
}
