import { getGenres } from "app/lib/get";
import StoryForm from "app/ui/forms/story";
import prisma from "app/lib/db";
export default async function Page() {
	const genres = await getGenres()
	async function createStory(data) {
		"use server"
		const genresArray = data.genres.map(e => { return { id: e } })
		const res = await prisma.story.create({
			data: {
				title: data.title,
				word_count: data.word_count,
			}
		})
		console.log(res)
		const genresRes = await prisma.story.update({
			where: { id: res.id },
			data: {
				genres: { set: genresArray }
			}
		})
		console.log(genresRes)
	}
	return <StoryForm genres={genres} createStory={createStory} />
}
