"use strict";
var __webpack_modules__ = {
    "dayjs/plugin/updateLocale": function(module) {
        module.exports = import("dayjs/plugin/updateLocale");
    }
};
var __webpack_module_cache__ = {};
function __webpack_require__(moduleId) {
    var cachedModule = __webpack_module_cache__[moduleId];
    if (void 0 !== cachedModule) return cachedModule.exports;
    var module = __webpack_module_cache__[moduleId] = {
        exports: {}
    };
    __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
    return module.exports;
}
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    LocalePlugin: ()=>LocalePlugin
});
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_dayjs_namespaceObject = require("dayjs");
var external_dayjs_default = /*#__PURE__*/ __webpack_require__.n(external_dayjs_namespaceObject);
const Plugin_js_namespaceObject = require("../../application/Plugin.js");
const index_js_namespaceObject = require("../../locale/index.js");
const external_loadConstrueLocale_js_namespaceObject = require("./loadConstrueLocale.js");
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
class LocalePlugin extends Plugin_js_namespaceObject.Plugin {
    async afterAdd() {
        const api = this.app.apiClient;
        const locale = api.auth.locale;
        try {
            var _data_data, _data_data1, _data_data2, _data_data3, _data_data4;
            const res = await api.request({
                url: 'app:getLang',
                params: {
                    locale
                },
                headers: {
                    'X-Role': 'anonymous'
                }
            });
            const data = null == res ? void 0 : res.data;
            this.locales = (null == data ? void 0 : data.data) || {};
            this.app.use(external_antd_namespaceObject.ConfigProvider, {
                locale: this.locales.antd,
                popupMatchSelectWidth: false
            });
            this.app.use(external_antd_namespaceObject.App, {
                component: false
            });
            if (null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.lang) {
                var _data_data5, _data_data6;
                api.auth.setLocale(null == data ? void 0 : null === (_data_data5 = data.data) || void 0 === _data_data5 ? void 0 : _data_data5.lang);
                this.app.i18n.changeLanguage(null == data ? void 0 : null === (_data_data6 = data.data) || void 0 === _data_data6 ? void 0 : _data_data6.lang);
            }
            Object.keys((null == data ? void 0 : null === (_data_data1 = data.data) || void 0 === _data_data1 ? void 0 : _data_data1.resources) || {}).forEach((key)=>{
                var _data_data, _data_data1;
                this.app.i18n.addResources(null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.lang, key, (null == data ? void 0 : null === (_data_data1 = data.data) || void 0 === _data_data1 ? void 0 : _data_data1.resources[key]) || {});
            });
            (0, schema_namespaceObject.setValidateLanguage)(null == data ? void 0 : null === (_data_data2 = data.data) || void 0 === _data_data2 ? void 0 : _data_data2.lang);
            (0, external_loadConstrueLocale_js_namespaceObject.loadConstrueLocale)(null == data ? void 0 : data.data);
            const dayjsLang = index_js_namespaceObject.dayjsLocale[null == data ? void 0 : null === (_data_data3 = data.data) || void 0 === _data_data3 ? void 0 : _data_data3.lang] || 'en';
            await import("dayjs/locale/".concat(dayjsLang));
            external_dayjs_default().locale(dayjsLang);
            const updateLocale = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "dayjs/plugin/updateLocale"));
            external_dayjs_default().extend(updateLocale.default);
            const localeSetting = {
                invalidDate: '-'
            };
            external_dayjs_default().updateLocale(dayjsLang, localeSetting);
            window['cronLocale'] = null == data ? void 0 : null === (_data_data4 = data.data) || void 0 === _data_data4 ? void 0 : _data_data4.cron;
        } catch (error) {
            var _error_response;
            if ((null == error ? void 0 : null === (_error_response = error.response) || void 0 === _error_response ? void 0 : _error_response.status) === 401) setTimeout(()=>{
                window.location.href = '/signIn';
            }, 1000);
            throw error;
        }
    }
    constructor(...args){
        super(...args), _define_property(this, "locales", {});
    }
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
