import {getCategoryBySlugWitData} from '@prisma/client/sql'
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 Categories({
	params
}: {
	params: Promise<{slug?: string}>
}) {
	const {slug} = await params
	const [uri] = slug || []
	const category: CategoryPageSqlSchema[] = await db.$queryRawTyped(
		getCategoryBySlugWitData(uri)
	)

	if (category.length < 2) notFound()

	return <CategoryPageIndex data={category} />
}
