import { create } from 'zustand'

export type ToastSeverity = 'success' | 'error' | 'warning' | 'info'

export interface ToastMessage {
  id: string
  message: string
  severity: ToastSeverity
  duration?: number
}

interface ToastState {
  toasts: ToastMessage[]
  showToast: (message: string, severity?: ToastSeverity, duration?: number) => void
  dismissToast: (id: string) => void
}

export const useToastStore = create<ToastState>((set) => ({
  toasts: [],
  showToast: (message, severity = 'success', duration = 4000) => {
    const id = crypto.randomUUID()
    set((s) => ({ toasts: [...s.toasts, { id, message, severity, duration }] }))
  },
  dismissToast: (id) => {
    set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }))
  },
}))
