import {useState, PropsWithChildren} from "react"
import {DialogContext} from "../contexts"
import {Dialog} from "../molecules"
import {DialogContentProps, DialogProps} from "../props"

export const DialogProvider = ({children}: PropsWithChildren) => {
  const [dialog, setDialog] = useState<DialogContentProps>({message: "", body: null})

  const toggleDialog = (data?: DialogContentProps) => {
    setDialog(data || {message: "", body: null})
  }

  const value: DialogProps = {dialog, toggleDialog}

  return (
    <DialogContext.Provider value={value}>
      {children}
      <Dialog />
    </DialogContext.Provider>
  )
}
