import Notify from '@components/Notify'
import toast from 'solid-toast'

export default function useToast() {
  const notify = {}

  notify.show = ({ status, title, description, closable = false }) => {
    return toast.custom((t) => (
      <Notify
        status={status}
        title={title}
        description={description}
        onClose={closable ? () => toast.dismiss(t.id) : null}
      />
    ))
  }

  notify.success = ({ title, description, closable = false }) => {
    return notify.show({ status: 'success', title, description, closable })
  }

  notify.error = ({ title, description, closable = false }) => {
    return notify.show({ status: 'error', title, description, closable })
  }

  notify.info = ({ title, description, closable = false }) => {
    return notify.show({ status: 'info', title, description, closable })
  }

  return notify
}
