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

import ProductCategory from "@/components/product/category";
import ProductDetail from "@/components/product/detail";
import ArticleCategory from "@/components/article/category";
import ArticleDetail from "@/components/article/detail";
import ArticleHome from "@/components/article/home";

export default async function SlugPage({
    params,
}: {
    params: Promise<{ slug: string }>;
}) {
    const { slug } = await params;    
    if (!slug) {
        notFound();
    }
    
    const result = findBySlug(slug);
    
    if (!result) {
        notFound();
    }

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

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

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

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

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

        default:
            const _exhaustive: never = result;
            notFound();
    }
}
