"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > 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__, {
    i18nBackendOptions: ()=>i18nBackendOptions,
    i18nTranslationNamespace: ()=>i18nTranslationNamespace,
    init18n: ()=>init18n
});
const external_dompurify_namespaceObject = require("dompurify");
var external_dompurify_default = /*#__PURE__*/ __webpack_require__.n(external_dompurify_namespaceObject);
const external_i18next_http_backend_namespaceObject = require("i18next-http-backend");
var external_i18next_http_backend_default = /*#__PURE__*/ __webpack_require__.n(external_i18next_http_backend_namespaceObject);
const asset_path_utils_cjs_namespaceObject = require("../../../utils/asset-path-utils.cjs");
const availableLocales_cjs_namespaceObject = require("../../../generated/availableLocales.cjs");
var availableLocales_cjs_default = /*#__PURE__*/ __webpack_require__.n(availableLocales_cjs_namespaceObject);
const i18nTranslationNamespace = 'translation';
function i18nBackendOptions(atomicInterface) {
    return {
        loadPath: `${(0, asset_path_utils_cjs_namespaceObject.getAssetPath)(atomicInterface.languageAssetsPath)}/{{lng}}.json?lng={{lng}}&ns={{ns}}`,
        request: async (_options, url, _payload, callback)=>{
            try {
                const [fetchUrl, searchParams] = url.split('?');
                const urlParams = new URLSearchParams(searchParams);
                const lng = urlParams.get('lng');
                const ns = urlParams.get('ns');
                if (!isI18nLocaleAvailable(lng)) throw new Error(`Unsupported locale "${lng}"`);
                if (ns !== i18nTranslationNamespace) throw new Error(`Unsupported namespace "${ns}"`);
                const response = await fetch(fetchUrl);
                if (200 !== response.status && 304 !== response.status) throw new Error(`Unsuccessful request returned status "${response.status}"`);
                callback(null, {
                    status: response.status,
                    data: await response.json()
                });
            } catch (error) {
                callback(error, {
                    status: 404,
                    data: ''
                });
            }
        }
    };
}
function init18n(atomicInterface) {
    return atomicInterface.i18n.use(external_i18next_http_backend_default()).init({
        debug: 'debug' === atomicInterface.logLevel,
        lng: atomicInterface.language,
        nsSeparator: '___',
        fallbackLng: 'en',
        backend: i18nBackendOptions(atomicInterface),
        interpolation: {
            escape: (str)=>external_dompurify_default().sanitize(str)
        },
        compatibilityJSON: 'v4'
    });
}
function isI18nLocaleAvailable(locale) {
    return availableLocales_cjs_default().includes(locale.toLowerCase());
}
exports.i18nBackendOptions = __webpack_exports__.i18nBackendOptions;
exports.i18nTranslationNamespace = __webpack_exports__.i18nTranslationNamespace;
exports.init18n = __webpack_exports__.init18n;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "i18nBackendOptions",
    "i18nTranslationNamespace",
    "init18n"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
