import {Alert} from '~/types/interfaces'
import {defineStore} from "pinia";
import {TYPE_ALERT} from "~/types/enum/enums";
import {Ref, ref} from "@vue/reactivity";

export const usePageStore = defineStore('page', () => {
    const alerts: Ref<Array<Alert>> = ref([])

    const removeSlowlyAlert = () => {
      setTimeout(() => {
        alerts.value.shift()
      }, 300)
    }

    /**
     * Ajout des alerts dans le store
     * @param type
     * @param messages
     */
    const addAlert = (type: TYPE_ALERT, messages: Array<string>) => {
      const alert: Alert = {
        type: type,
        messages: messages
      }
      alerts.value.push(alert)
    }

    return {
        alerts,
        removeSlowlyAlert,
        addAlert
    }
})
