import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'

export const useToastStore = defineStore('toastStore', () => {
  const toastTimeout = ref<number>(5000)
  const toasts = reactive<Record<string, any>>({})

  const AddToast = (toast: string, type: string, timeout?: number) => {
    const iTimeout: number = timeout || 0
    const rnd: number = Number(Math.floor(Math.random() * 10000000000))
    
    toasts[rnd] = {} as Record<string, any>
    toasts[rnd].text = toast
    toasts[rnd].timeout = iTimeout
    toasts[rnd].id = rnd
    toasts[rnd].type = type
  }
  return {
    toastTimeout,
    toasts,
    AddToast
  }
})
