// 运行时配置
import { TOKEN, CURRENT_MENU } from '@/utils/constant';
import { type RuntimeAntdConfig } from '@umijs/max';

import { errorConfig } from '../config/requestErrorConfig';

// 全局初始化数据配置，用于 Layout 用户信息和权限初始化
// 更多信息见文档：https://umijs.org/docs/api/runtime-config#getinitialstate


// antd 主题配置
export const antd: RuntimeAntdConfig = (memo) => {
  const newMemo = {
    ...memo,
    theme: {
      ...memo.theme,
      // algorithm: theme.darkAlgorithm,
    },
    appConfig: {
      message: {
        // 配置 message 最大显示数，超过限制时，最早的消息会被自动关闭
        maxCount: 3,
      },
    },
  };

  return newMemo;
};

export async function getInitialState(): Promise<{
  
  accessInfo?: any;
  loading?: boolean;
}> {
//  获取父系统传递的数据


  let accessInfo = {};
  // 是否开发环境
  // const isDev = process.env.NODE_ENV === 'development';
  // if (window.location.pathname !== loginPath) {
  //   const userInfoRes = await getAccessInfo();
  //   const data: any = {};
  //   if (userInfoRes.data) {
  //     for (const item of userInfoRes.data) {
  //       data[item] = true;
  //     }
  //   }
  //   accessInfo = data;
  // }
  // console.log(accessInfo);

  return {
    accessInfo,
  };
}
/**
 * @name request 配置，可以配置错误处理
 * 它基于 axios 和 ahooks 的 useRequest 提供了一套统一的网络请求和错误处理方案。
 * @doc https://umijs.org/docs/max/request#配置
 */
export const request = {
  ...errorConfig,
};

export const qiankun = {
  
  // 应用加载之前
  async bootstrap() {},
  // 应用 render 之前触发
  async mount(props: any) {
    
    if (props?.globalState?.token) {
      localStorage.setItem(TOKEN, props.globalState.token);
      localStorage.setItem(CURRENT_MENU, props.globalState.menuData);

    }
  },
  // 应用卸载之后触发
  async unmount() {
    localStorage.removeItem(TOKEN);
    localStorage.removeItem(CURRENT_MENU);
  },
};
// start();
