import { defineStore } from 'pinia';

interface AppConfig {
  projectType: string;
  baseApi: string;
  timeout: number;
  pagePermission: boolean;
  actionPermission: boolean;
  customAppTitle?: boolean;
  layout?: Function;
  headerBellInfo?: object;
  customInitMessageCount?: Function | Boolean; // 自定义消息数量获取事件
}
export const appConfigStore = defineStore({
  id: 'appConfig',
  /**
   * module   测试用
   * @returns
   */
  state(): AppConfig {
    return {
      projectType: 'web',
      baseApi: '/api',
      timeout: 15 * 1000,
      pagePermission: true,
      actionPermission: true,
      customAppTitle: false,
      customInitMessageCount: false,
      headerBellInfo: {
        isShow: false,
        api: '',
        toRouterName: '',
      },
    };
  },
  getters: {
    getHeaderBellInfo: (state: any) => state.headerBellInfo,
  },
  actions: {
    setConfig(config: AppConfig) {
      Object.keys(config).forEach((key) => {
        this[key] = config[key];
      });
    },
  },
});