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

export const useAppStore = defineStore('app', () => {
  // 页面加载状态
  const loading = ref(false)

  // 侧边栏折叠状态
  const sidebarCollapsed = ref(false)

  // 当前展开的菜单
  const openedMenus = ref<string[]>([])

  const setLoading = (value: boolean) => {
    loading.value = value
  }

  const toggleSidebar = () => {
    sidebarCollapsed.value = !sidebarCollapsed.value
  }

  const setOpenedMenus = (menus: string[]) => {
    openedMenus.value = menus
  }

  return {
    loading,
    sidebarCollapsed,
    openedMenus,
    setLoading,
    toggleSidebar,
    setOpenedMenus
  }
})
