/**
 * 应用状态管理
 */
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppStore = defineStore('app', () => {
  // 侧边栏状态
  const sidebarCollapsed = ref(false)

  // 设备类型
  const deviceTypes = ref<any[]>([])

  // 网点树
  const organizationTree = ref<any[]>([])

  // 未读消息数
  const unreadCount = ref(0)

  /**
   * 切换侧边栏
   */
  const toggleSidebar = () => {
    sidebarCollapsed.value = !sidebarCollapsed.value
  }

  /**
   * 设置侧边栏状态
   */
  const setSidebarCollapsed = (collapsed: boolean) => {
    sidebarCollapsed.value = collapsed
  }

  /**
   * 设置设备类型
   */
  const setDeviceTypes = (types: any[]) => {
    deviceTypes.value = types
  }

  /**
   * 设置网点树
   */
  const setOrganizationTree = (tree: any[]) => {
    organizationTree.value = tree
  }

  /**
   * 设置未读消息数
   */
  const setUnreadCount = (count: number) => {
    unreadCount.value = count
  }

  return {
    // 状态
    sidebarCollapsed,
    deviceTypes,
    organizationTree,
    unreadCount,
    // 方法
    toggleSidebar,
    setSidebarCollapsed,
    setDeviceTypes,
    setOrganizationTree,
    setUnreadCount
  }
})
