/**
 * Toast composable - replaces @nuxtjs/toast
 * Uses Vuetify's snackbar under the hood via a simple reactive state.
 */
interface ToastState {
  show: boolean
  message: string
  color: string
  icon: string
  timeout: number
}

const toastState = reactive<ToastState>({
  show: false,
  message: '',
  color: 'info',
  icon: '',
  timeout: 3000,
})

export function useToast() {
  function show(message: string, options: Partial<Omit<ToastState, 'show' | 'message'>> = {}) {
    toastState.message = message
    toastState.color = options.color || 'info'
    toastState.icon = options.icon || ''
    toastState.timeout = options.timeout || 3000
    toastState.show = true
  }

  function success(message: string) {
    show(message, { color: 'success', icon: 'mdi-check-circle' })
  }

  function error(message: string) {
    show(message, { color: 'error', icon: 'mdi-alert-circle' })
  }

  function warning(message: string) {
    show(message, { color: 'warning', icon: 'mdi-alert' })
  }

  function info(message: string) {
    show(message, { color: 'info', icon: 'mdi-information' })
  }

  return {
    state: toastState,
    show,
    success,
    error,
    warning,
    info,
  }
}
