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

/**
 * 应用全局状态：侧边栏折叠、主题、设备尺寸
 */
export const useAppStore = defineStore(
  'app',
  () => {
    const sidebarCollapsed = ref(false)
    const device = ref<'desktop' | 'mobile'>('desktop')

    function toggleSidebar() {
      sidebarCollapsed.value = !sidebarCollapsed.value
    }

    function toggleDevice(d: 'desktop' | 'mobile') {
      device.value = d
    }

    return { sidebarCollapsed, device, toggleSidebar, toggleDevice }
  },
  {
    persist: {
      key: 'snack-admin-app',
      pick: ['sidebarCollapsed']
    }
  }
)
