import {getCatalogIndexData} from '@prisma/client/sql'
import {getLocale} from 'next-intl/server'
import {notFound} from 'next/navigation'

import CategoryPageIndex from '@/components/pages/category/page'
import {CategoryPageSqlSchema} from '@/lib/data/models/sqlSchemas'
import {db} from '@/lib/db/prisma/client'

export default async function CatalogPage({
	params
}: {
	params: Promise<{slug?: string}>
}) {
	const loc = await getLocale()
	const catalog: CategoryPageSqlSchema[] = await db.$queryRawTyped(
		getCatalogIndexData(loc)
	)

	if (catalog.length < 1) notFound()

	return <CategoryPageIndex data={catalog} />
}
