import {useState, PropsWithChildren} from "react"
import {NotifyContext} from "../contexts"
import {NotifyPopup} from "../molecules"
import {NotifyPopupProps, INotifyPopup} from "../props"

export const NotifyProvider = ({children}: PropsWithChildren) => {
  const [notify, setNotify] = useState<NotifyPopupProps | null>(null)

  const toggleNotify = (content?: NotifyPopupProps) => setNotify(content || null)

  const value: INotifyPopup = {notify, toggleNotify}

  return (
    <NotifyContext.Provider value={value}>
      <NotifyPopup />
      {children}
    </NotifyContext.Provider>
  )
}
