import { getCurrentUser, getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import gg5xxxxx 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;

export function getHeaders(url = '') {
  const token = getToken();
  const currentInfo = getCurrentUser() || {};
  const user = getUserInfo() || {};
  const userId = user.id || currentInfo.xgUserId;
  // debugger;
  const timestamp = user.differenceBetweenServerAndClientTime ? new Date().getTime() + user.differenceBetweenServerAndClientTime : new Date().getTime();
  const secretString = token + userId + timestamp;
  if(!token || token === 'null'){
    return {
      headers: {},
    }
  }
  const res = {
    headers: {
      Authorization: `bearer ${token}`,
    },
  };
  if (getIsBei_Dian() && userId
  ) {
    res.headers.auth = gg5xxxxx(secretString);
    res.headers.timestamp = timestamp;
    if (isTest) {
      // console.log(
      //   {
      //     url: url,
      //     secretString,
      //     md5S: gg5xxxxx(secretString),
      //     timestamp,
      //     userId: userId,
      //   },
      // );
    }
  }
  return res;
}
