import { useState } from 'react'
import type { AlertStatus } from '../components/CalledItAlert'

export type ToastState = {
  status: AlertStatus
  title: string
  description?: string
} | null

export function useToast() {
  const [toast, setToast] = useState<ToastState>(null)

  function showToast(status: AlertStatus, title: string, description?: string) {
    setToast({ status, title, description })
  }

  function showError(title: string, description?: string) {
    showToast('error', title, description)
  }

  function showSuccess(title: string, description?: string) {
    showToast('success', title, description)
  }

  function dismiss() {
    setToast(null)
  }

  return { toast, showError, showSuccess, dismiss }
}
