import type { Metadata } from "next"
import { loadPublicSiteArticles } from "@/server/public-site/articles"
import { resolvePublicRouteMetadata } from "@/server/public-site/metadata"
import { SpaEntry } from "../spa-entry"

type CatchAllParams = {
    path?: string[]
}

type CatchAllPageProps = {
    params: Promise<CatchAllParams>
}

export async function generateMetadata({ params }: CatchAllPageProps): Promise<Metadata> {
    const resolvedParams = await params
    const pathSegments = resolvedParams.path ?? []
    const articles = pathSegments[0] === "p"
        ? await loadPublicSiteArticles({ includeNonIndexable: true })
        : []

    return resolvePublicRouteMetadata(pathSegments, articles)
}

export default function CatchAllPage() {
    return <SpaEntry />
}
