import { getCurrentUser, getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import Md5 from 'js-md5';
import { getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';


const isTest = getUrlInfo().test;
window.differenceBetweenServerAndClientTime = window.differenceBetweenServerAndClientTime || 0;
export function getHeaders(url = '') {
  const token = getToken();
  const currentInfo = getCurrentUser() || {};
  const user = getUserInfo() || {};
  const userId = user.id || currentInfo.xgUserId;
  const timestamp = new Date().getTime() + window.differenceBetweenServerAndClientTime;
  const secretString = token + userId + timestamp;

  const res = {
    headers: {
      Authorization: `bearer ${token}`,
    },
  };
  if(getIsBei_Dian() && userId){
    res.headers.auth = Md5(secretString);
    res.headers.timestamp = timestamp;
    if (isTest) {
      console.log(
        {
          secretString,
          md5S: Md5(secretString),
          timestamp,
          userId: userId,
          differenceBetweenServerAndClientTime: window.differenceBetweenServerAndClientTime,
        },
      );
    }
  }
  return res;
}
