// import { getCurrentUser, getToken } from '@/webPublic/one_stop_public/utils/token';

// import {getCurrentUser, getUserInfo} from '@/H5Public/utils/2022new/currentUser';
import { getIsBei_Dian, getToken } from '@/H5Public/utils/authority';
import { getUserInfo } from './currentUser';
import { isJSON } from '../authority';
// import { getUrlParams } from '@/H5Public/utils/handleString';

export const getSysCode = () => {
  return  getYunShangGuiZhouSyStemConfig().sysCode || window.specialImportantSystemConfig.sysCode;
};


export const setYunShangGuiZhouSystemCode = (code) => {
  const localStorageData = localStorage.getItem('antd-pro-systemConfig');
  if(!localStorageData || !localStorageData.includes(code)){
    localStorage.setItem('antd-pro-systemConfig', JSON.stringify({
      code: code,
    }));
  }
};

// 查询系统配置
export const getYunShangGuiZhouSyStemConfig = () => {
  const localStorageData = localStorage.getItem('antd-pro-systemConfig');
  if (localStorageData && isJSON(localStorageData)) {
    let d = JSON.parse(localStorageData);
    return {
      sysCode: d.code,
      logo: '',
      name: d.name,
      siteId: '5',
      siteUrl: '',
    };
  } else {
    return {
      sysCode: undefined,
      name: '',
    };
  }
};

export function getHeaders(url = '') {
  const token = getToken();
  // const currentInfo = getCurrentUser();
  // const onestopInfo = getUserInfo();
  // const id =  onestopInfo.id || currentInfo.xgUserId;
  // const timestamp = onestopInfo.differenceBetweenServerAndClientTime ? new Date().getTime() + onestopInfo.differenceBetweenServerAndClientTime : new Date().getTime();
  // const secretString = token + id + timestamp;

  const res = {
    headers: {
      Authorization: `bearer ${token}`,
      sysCode: getSysCode(),
      tenant:  getUserInfo().tenantCode || window.specialImportantSystemConfig.tenant,
    },
  };
  if(getIsBei_Dian() && window.location.origin.indexOf('localhost') > -1){
    res.headers.env = 'test';
  }
  //
  // if(getIsBei_Dian() && process.env.){
  // }
  return res;
}
