'use strict';

var storage = require('../utils/storage.js');
var pinia = require('pinia');
var themeConfig = require('../stores/themeConfig.js');
var logo = require('../theme-chalk/assets/logo.png.js');
var idleTimeout = require('./idleTimeout.js');
require('../api/index.js');
var index = require('../api/sys/index.js');
var index$1 = require('../api/base/index.js');

async function loadSysInfo(tenantid) {
  var _a;
  const storesThemeConfig = themeConfig.useThemeConfig();
  const { themeConfig: themeConfig$1 } = pinia.storeToRefs(storesThemeConfig);
  const [err, res] = await index.feature(index$1.useBaseApi("sysTenant").gcomm(null, "sysInfo/" + Number(tenantid)));
  if (err) {
    themeConfig$1.value.logoUrl = logo.default;
    storage.Local.remove("themeConfig");
    storage.Local.set("themeConfig", storesThemeConfig.themeConfig);
    return;
  } else {
    if (res.data.type != "success" || res.data.result == null) return;
    const data = res.data.result;
    themeConfig$1.value.logoUrl = data.logo;
    themeConfig$1.value.globalTitle = data.title;
    themeConfig$1.value.globalViceTitle = data.viceTitle;
    themeConfig$1.value.globalViceTitleMsg = data.viceDesc;
    themeConfig$1.value.icp = data.icp;
    themeConfig$1.value.icpUrl = data.icpUrl;
    themeConfig$1.value.isWatermark = data.watermark != null;
    themeConfig$1.value.watermarkText = data.watermark;
    themeConfig$1.value.copyright = data.copyright;
    themeConfig$1.value.version = data.version;
    themeConfig$1.value.carouselFiles = data.carouselFiles;
    themeConfig$1.value.primary = data.themeColor;
    themeConfig$1.value.layout = data.layout;
    themeConfig$1.value.animation = data.animation;
    themeConfig$1.value.secondVer = data.secondVer;
    themeConfig$1.value.captcha = data.captcha;
    themeConfig$1.value.adminTel = data.adminTel;
    themeConfig$1.value.forceChangePassword = data.forceChangePassword;
    themeConfig$1.value.passwordExpirationTime = data.passwordExpirationTime;
    themeConfig$1.value.i18NSwitch = data.i18NSwitch;
    themeConfig$1.value.idleTimeout = data.idleTimeout;
    themeConfig$1.value.onlineNotice = data.onlineNotice;
    themeConfig$1.value.mobileLogin = data.mobileLogin;
    themeConfig$1.value.isExpireTip = data.isExpireTip;
    themeConfig$1.value.expireDay = data.expireDay;
    themeConfig$1.value.scanLogin = data.scanLogin;
    themeConfig$1.value.signUp = data.signUp;
    window.__env__.VITE_SM_PUBLIC_KEY = data.publicKey;
    updateFavicon(data.logo);
    idleTimeout.updateIdleTimeout((_a = themeConfig$1.value.idleTimeout) != null ? _a : 0);
    storage.Local.remove("themeConfig");
    storage.Local.set("themeConfig", storesThemeConfig.themeConfig);
  }
}
const updateFavicon = (url) => {
  const favicon = document.getElementById("favicon");
  favicon.href = url ? url : "data:;base64,=";
};

exports.loadSysInfo = loadSysInfo;
exports.updateFavicon = updateFavicon;
