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

export const useUiStore = defineStore('ui', () => {
  const currentTab = ref(localStorage.getItem('sp_current_tab') || 'notes')
  const showLoginModal = ref(false)
  const toasts = ref([])

  function setTab(tab) {
    currentTab.value = tab
    localStorage.setItem('sp_current_tab', tab)
  }

  function openLogin() {
    showLoginModal.value = true
  }

  function closeLogin() {
    showLoginModal.value = false
  }

  function toast(msg, duration = 2000) {
    toasts.value.push(msg)
    setTimeout(() => {
      toasts.value.shift()
    }, duration)
  }

  return { currentTab, showLoginModal, toasts, setTab, openLogin, closeLogin, toast }
})
