/** @format */
import { dateUtil } from '/nerv-lib/util/date-util';
import mockResource from './resource.json';
import { http } from '/nerv-lib/saas';
import { ref } from 'vue';
import { permission } from '/@/api/origanizemanage';

// const { linkList } = sessionStorage.getItem('userInfo')
//   ? JSON.parse(sessionStorage.getItem('userInfo')!)
//   : [{}];
// const value = ref(linkList[0]?.orgId);

const transform = (data, map) => {
  return Object.keys(map).reduce((pre, cur) => {
    pre[cur] = data[map[cur]];
    return pre;
  }, {});
};
export const appConfig = {
  projectType: 'web',
  baseApi: '/api',
  enablePermissions: false,
  // themeColor: '#eee',
  siderPosition: 'left',
  baseHeader: '/parkingManage',
  baseRouter: '/parkingManage/parkingLotManage',
  themeConfig: {
    bgImageUrl: `${import.meta.env.VITE_PUBLIC_PATH}/asset/image/login/background.png`,
  },
  // userCustomRouterGuard: (to, from, next, whiteNameList, authorizationStore, appConfig) => {
  //   console.log({ to, from, next, whiteNameList, authorizationStore, appConfig }, 'routeConfig');
  //   next();
  // },

  // customUpdatePwd: () => import('/@/view/updatePassword/updatePassword.vue'),

  // userInfoApi: () => {
  //   return {
  //     code: 200,
  //     success: true,
  //     data: {
  //       accountCode: '1305107806187376793',
  //       accountName: 'adm*n',
  //       accountType: 'admin',
  //       accountStatus: 1,
  //       accountRealName: 'admin',
  //       organizationCode: 'dingcloud',
  //       authConfigList: [],
  //       organizeResCode: [],
  //       leadDepartmentUuidList: [],
  //     },
  //   };
  // },

  headerSlotConfig: {
    component: 'NsSelectApi',
    componentProps: {
      style: { width: '200px' },
      api: '/carbon-smart/user/login/logInInfo',
      placeholder: '请选择',
      autoSelectFirst: true,
      onChange: (cur) => {
        // value.value = cur;
      },
      resultField: 'data.linkList',
      labelField: 'orgName',
      valueField: 'orgId',
      immediate: true,
      dropdownReload: true,
    },
  },
  timeout: 60 * 1000,
  userLoginApi: '/carbon-smart/user/login',
  userResourceApi: () => {
    return { data: mockResource.menus };
  },
  userInfoApi: () => {
    return http.post('/carbon-smart/user/login/logInInfo').then((res) => {
      const info = res.data;
      const trD = transform(info, {
        accountCode: 'userId',
        accountName: 'realName',
        accountRealName: 'realName',
        orgId: 'orgId',
        orgName: 'orgName',
        projectId: 'projectId',
        linkList: 'linkList',
        permissionInfoList: 'permissionInfoList',
      });

      return { data: { ...trD } };
    });
  },

  useHistoryTag: false,
  // 修改密码配置
  updatePassWordInfo: {
    title: '修改密码',
    subtitle: 'huaxing平台',
    api: '/api/web/objs/User/changePassword',
  },
  // headerBellInfo: {
  //   isShow: true,
  //   api: '/api/web/objs/bulletin/readCount',
  //   toRouterName: 'NoticeManageIndex',
  // },
  resourceInfo: {
    // application: {
    //   version: '1.1.74',
    //   label: '停车业务平台',
    //   dataScope: {
    //     scopeMode: 0,
    //     scopeType: '',
    //     dataTips: '',
    //   },
    // },
    api: permission.add,
  },
};
