"use strict";
const common_vendor = require("../../common/vendor.js");
const config_request = require("../../config/request.js");
const config_frontEndConfig = require("../../config/frontEndConfig.js");
const utils_common = require("../../utils/common.js");
const frontEndConfigFn = () => {
  return new Promise(async (resolve) => {
    let accountInfo = getApp().globalData.accountInfo;
    if (accountInfo.miniProgram.envVersion == "release") {
      common_vendor.index.request({
        url: `${config_request.BASE_URL}api/wechaSmallproFrontEndConfig/localConfig.do`,
        method: "GET",
        data: {},
        header: {
          "content-type": "application/x-www-form-urlencoded"
        },
        success(resp) {
          resp.data.fixedAppjsGlobalData = config_frontEndConfig.frontEndConfig.fixedAppjsGlobalData;
          common_vendor.index.setStorageSync("frontEndConfig", resp.data);
          resolve(resp.data);
        },
        fail(error) {
          resolve(false);
        }
      });
    } else {
      common_vendor.index.setStorageSync("frontEndConfig", config_frontEndConfig.frontEndConfig);
      resolve(config_frontEndConfig.frontEndConfig);
    }
  });
};
const useSetFrontEndConfig = async () => {
  let has = false;
  let frontEndConfigs;
  if (common_vendor.index.getStorageSync("frontEndConfigRequest") || utils_common.isEmpty(common_vendor.index.getStorageSync("frontEndConfig"))) {
    frontEndConfigs = await frontEndConfigFn();
  } else {
    frontEndConfigs = common_vendor.index.getStorageSync("frontEndConfig");
  }
  return new Promise(async (resolve) => {
    if (!frontEndConfigs.appjsGlobalData) {
      utils_common.showModal("小程序登录初始化数据信息未配置");
      has = true;
    } else {
      getApp().globalData = Object.assign(getApp().globalData, {
        smallPro_version: getApp().globalData.accountInfo.miniProgram.version || "0.0.0",
        // 登录请求时版本信息， 本地和体验版本都是0.0.0，正式线用获取的
        ...frontEndConfigs.fixedAppjsGlobalData,
        ...frontEndConfigs.appjsGlobalData
      });
    }
    if (!frontEndConfigs.webUiDiy) {
      utils_common.showModal(
        frontEndConfigs === false ? "网络请求异常，请切换网络重新进入！" : "webUiDiy配置信息未配置"
      );
      common_vendor.index.hideLoading();
      has = true;
    } else {
      let config = frontEndConfigs.webUiDiy;
      getApp().globalData.config = frontEndConfigs.webUiDiy;
      let distric = config && config.pageConfiguration && config.pageConfiguration.hospitalDistrict_config;
      if (getApp().globalData.hasDistrict && distric && distric.districtList instanceof Array && distric.districtList[0].districtId) {
        getApp().globalData.districtId = distric.districtList[0].districtId;
      }
    }
    if (frontEndConfigs.appjsGlobalData.updateOrNot) {
      common_vendor.index.redirectTo({
        url: `pages/st1/business/otherService/building/building`
      });
      has = true;
    }
    resolve(has);
  });
};
exports.useSetFrontEndConfig = useSetFrontEndConfig;
//# sourceMappingURL=../../../.sourcemap/mp-alipay/hook/use-front-end-config/index.js.map
