
"use client"
import { createSub } from "app/lib/create"
import { Dialog, DialogHeader, DialogTrigger, DialogContent, DialogClose, DialogTitle, DialogFooter, DialogDescription } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { ComponentProps } from "react";
import { Pub, Response, Story } from "@prisma/client";
import SubmissionForm from "app/ui/forms/sub";
import { Plus } from "lucide-react";
import { useState } from "react";


type CreateSubDefaults = {
  subId?: number,
  storyId: number,
  pubId: number,
  submitted: Date,
  responded: Date,
  respoonseId: number
}

export default function CreateSubmissionDialog({ stories, pubs, responses, defaults }: ComponentProps<"div"> & { stories: Story[], pubs: Pub[], responses: Response[], defaults?: CreateSubDefaults }) {

  const [isOpen, setIsOpen] = useState(false)
  function closeDialog() {
    setIsOpen(false)
  }

  return (
    <Dialog open={isOpen} onOpenChange={setIsOpen}>
      <DialogTrigger asChild>
        <Button>
          <span className="hidden md:block">Create new submission</span>
          <Plus className="block md:hidden" />
        </Button>
      </DialogTrigger>
      <DialogContent className="text-xs md:text-sm">
        <DialogHeader>
          <DialogTitle>New submission</DialogTitle>
          <DialogDescription>Create an entry for a new story i.e. a thing you intend to submit for publication.</DialogDescription>
        </DialogHeader>
        <SubmissionForm pubs={pubs} responses={responses} stories={stories} defaults={defaults} closeDialog={closeDialog} />
        <DialogFooter>
          <Button form="subform">Submit</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
