"use server"
import { getPubs, getResponses, getStories } from "app/lib/get";
import SubmissionForm from "app/ui/forms/sub";
import prisma from "app/lib/db";
import { CreateContainer, CreateContainerContent, CreateContainerHeader } from "app/ui/createContainer";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";

export default async function Page() {
	const stories = await getStories()
	const pubs = await getPubs()
	const responses = await getResponses()
	async function createSub(data) {
		"use server"
		const res = await prisma.sub.create({ data })
		console.log(res)
		revalidatePath("/submission")
		redirect("/submission")

	}
	return (
		<CreateContainer>
			<CreateContainerHeader>New submission</CreateContainerHeader>
			<CreateContainerContent>
				<SubmissionForm stories={stories} pubs={pubs} responses={responses} createSub={createSub} />
			</CreateContainerContent>
		</CreateContainer>
	)
}
