// "use server"
import prisma from "app/lib/db"
import { columns } from "app/submission/columns"
import { PageHeader, PageSubHeader } from "app/ui/pageHeader"
import { DataTable } from "app/ui/tables/data-table"
import { Badge } from "@/components/ui/badge"
import GenreBadges from "app/ui/genreBadges"

//ids are string here because they're coming from url params
async function getStoryWithGenres(id: string) {
  return prisma.story.findFirst({
    where: { id: Number(id) }, include: {
      genres: true
    }
  })
}
async function getStorySubmissions(id: string) {
  return prisma.sub.findMany({
    where: { storyId: Number(id) }, include: {
      story: true,
      pub: true,
      response: true
    }
  })
}


export default async function Page({ params }: { params: { id: string } }) {
  const data = await getStoryWithGenres(params.id)
  const storySubs = await getStorySubmissions(params.id)
  return <>
    <div className="container">
      <PageHeader>{data?.title ?? ""}</PageHeader>
      <GenreBadges genres={data.genres} className="my-6" />
      <PageSubHeader>Submissions:</PageSubHeader>
      <DataTable columns={columns} data={storySubs} />

    </div>

  </>
}


