import request from '@/webPublic/zyd_public/request/request';

window.differenceBetweenServerAndClientTime = 0;
export const getTime = () => {
  const config = window.specialImportantSystemConfig || {};
  if (config.mockServer) {
    return request(
      `${config.mockServer}/${config.gateWayUrl.zydxg}/InstructorConfigApi/getCurrentDate`,
      {
        method: 'POST',
        body: {},
      },
    )
      .then(t => {
        if (t) {
          window.differenceBetweenServerAndClientTime = t - new Date().getTime(); // 服务器时间 与 客户端时间的差值
        }
        return true;
      });
  } else {
    return new Promise((resolve) => {
      window.differenceBetweenServerAndClientTime = 0;
      resolve(true);
    });
  }
};

export async function queryCurrent() {
  let t = await getTime();
  const config = window.specialImportantSystemConfig || {};
  if (config.mockServer) {
    return request(
      `${config.mockServer}/${config.gateWayUrl.zydxg}/UserApi/queryCurrent`,
      {
        method: 'POST',
        body: {},
      },
    );
  }
}
