// src/app/[slug]/page.tsx
import { notFound } from "next/navigation";
import { findBySlug } from "@/lib/slugMap";

import ProductCategory from "@/components/product/Category";
import ProductDetail from "@/components/product/ProductDetail";
import ArticleCategory from "@/components/article/Category";
import ArticleDetail from "@/components/article/ArticleDetail";
import ArticleHome from "@/components/article/Home";

export default async function SlugPage({
    params,
}: {
    params: { slug: string };
}) {
    const { slug } = await params;
    if (!slug) return notFound();

    const result = findBySlug(slug);
    if (!result) return notFound();

    switch (result.type) {
        case "product_category":
            return <ProductCategory data={result.data} />;

        case "product_detail":
            return <ProductDetail data={result.data} />;

        case "article_home":
            return <ArticleHome slug={slug} />;

        case "article_category":
            return <ArticleCategory data={result.data} />;

        case "article_detail":
            return <ArticleDetail slug={result.data.slug} />;

        default:
            return notFound();
    }
}
