import { defineStore } from 'pinia'
import { store } from '@/stores'

interface PortalConfig {
  website: string
  [key: string]: any
}

interface CommonState {
  portalName: string
  currentPortalConfig: PortalConfig
}

export const useCommonStore = defineStore('common', {
  state: (): CommonState => ({
    portalName: '我的后台系统',
    currentPortalConfig: {
      website: '我的后台系统',
    },
  }),
  actions: {
    /**
     * 更新 portal 配置
     */
    SET_PORTAL_CONFIG(config: Partial<PortalConfig>) {
      this.currentPortalConfig = { ...this.currentPortalConfig, ...config }
      this.portalName = this.currentPortalConfig.website || this.portalName
    },
  },
})

// 用于 setup 外使用
export function useCommonStoreWithOut() {
  return useCommonStore(store)
}
