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

export const useErrorStore = defineStore('error-data', () => {
  const visible = ref<boolean>(false)
  const title = ref<string>('')
  const msg = ref<string>('')

  function set(obj: { title: string; msg: string }, timeout?: number) {
    title.value = obj.title
    msg.value = obj.msg
    show(timeout)
  }

  function show(timeout: number = -1) {
    visible.value = true

    if (timeout > 0) {
      setTimeout(() => (visible.value = false), timeout)
    }
  }

  function hide() {
    visible.value = false
  }

  return { visible, title, msg, show, hide, set }
})
