
import React, { useCallback } from "react"
import toaster from "toasted-notes"
import Toast from "../../components/toast"

/**
 * Creates a toast, a small notification for conveying a message to the user.
 */

export default function useToast() {
  const create = useCallback(
    ({ position = "bottom", duration = 5000, ...rest }) => {
      const options = { position, duration }

      toaster.notify(
        ({ onClose }) => <Toast handleClose={onClose} {...rest} />,
        options
      )
    },
    []
  )

  return create
}