import { defineStore } from 'pinia'
import { ref } from 'vue'
import Evt from '@/common/utils/evt.ts'

export const useAppSettingStore = defineStore('AppSetting', () => {
  const theme = ref<string>('light')
  const collectedMenus = ref<AppTypes.Menu[]>([])
  const menus = ref<AppTypes.Menu[]>([])
  const menuTree = ref<AppTypes.Menu[]>([])
  const language = ref<'zh' | 'en'>('zh')
  const logo = ref<string | null>(null)
  const companyName = ref<string | null>(null)

  function $reset() {
    collectedMenus.value = []
    menus.value = []
    menuTree.value = []
  }

  Evt.on('logout', $reset)

  return {
    collectedMenus,
    menus,
    menuTree,
    theme,
    logo,
    language,
    companyName,
    $reset,
  }
}, {
  persist: {
    paths: [
      'theme',
      'collectedMenus',
      'menus',
      'menuTree',
      'language',
      'logo',
      'companyName',
    ],
  },
})
