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