<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
  Copyright 2024 Esri
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.â€‹
*/
var __decorate = (this &amp;&amp; this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c &lt; 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" &amp;&amp; typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i &gt;= 0; i--) if (d = decorators[i]) r = (c &lt; 3 ? d(r) : c &gt; 3 ? d(target, key, r) : d(target, key)) || r;
    return c &gt; 3 &amp;&amp; r &amp;&amp; Object.defineProperty(target, key, r), r;
};
var __importDefault = (this &amp;&amp; this.__importDefault) || function (mod) {
    return (mod &amp;&amp; mod.__esModule) ? mod : { "default": mod };
};
define(["require", "exports", "esri/core/accessorSupport/decorators", "esri/widgets/support/widget", "esri/widgets/Widget", "esri/widgets/Expand", "esri/core/reactiveUtils", "../../functionality/configurationSettings", "./support/constants", "./support/enums", "../t9nUtils", "./support/utils", "esri/intl", "../locale"], function (require, exports, decorators_1, widget_1, Widget_1, Expand_1, reactiveUtils_1, configurationSettings_1, constants_1, enums_1, t9nUtils_1, utils_1, intl_1, locale_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    Widget_1 = __importDefault(Widget_1);
    Expand_1 = __importDefault(Expand_1);
    let LanguageSwitcher = class LanguageSwitcher extends Widget_1.default {
        constructor(params) {
            super(params);
        }
        postInitialize() {
            this._init();
        }
        destroy() {
            this.removeHandles(constants_1.HANDLES_KEY);
        }
        _init() {
            this._portalItem = this.base?.results?.applicationItem?.value;
        }
        async _updateUI() {
            const currentLocale = (0, intl_1.getLocale)();
            if (!this.configurationSettings?.languageSwitcher)
                return;
            const locales = this.configurationSettings?.languageSwitcherConfig?.locales ?? [];
            const localeExists = locales.find((localeItem) =&gt; localeItem.locale === currentLocale);
            const defaultLocale = this.configurationSettings?.languageSwitcherConfig?.defaultLocale;
            const isDefault = currentLocale === defaultLocale;
            if (!localeExists &amp;&amp; !isDefault)
                return;
            const localeCode = this.selectedLanguageData?.locale;
            const calculatedLocale = localeCode ?? defaultLocale ?? "en";
            const codeToUse = (0, locale_1.calculateLocale)(calculatedLocale);
            (0, utils_1.updateLocale)(codeToUse);
            const t9nData = this.selectedLanguageData?.data
                ? (0, utils_1.convertT9nToConfigData)(this.selectedLanguageData.data, this.base)
                : await (0, utils_1.getT9nData)(this.selectedLanguageData, this.base);
            Object.keys(t9nData).forEach((key) =&gt; {
                const value = t9nData[key];
                // This ensures that the filterConfig and searchConfiguration watcher callback functions are fired
                if (key === "filterConfig" || key === "searchConfiguration") {
                    this.configurationSettings[key] = null;
                    setTimeout(() =&gt; (this.configurationSettings[key] = value), 50);
                }
                else {
                    this.configurationSettings[key] = value;
                }
            });
        }
        getLanguageSwitcherHandles(widgetProps) {
            this.addHandles((0, reactiveUtils_1.watch)(() =&gt; this.configurationSettings?.languageSwitcherConfig, () =&gt; {
                this.languageSwitcherConfigCallback(widgetProps);
            }, { initial: true }), constants_1.HANDLES_KEY);
            return [
                (0, reactiveUtils_1.watch)(() =&gt; this.configurationSettings?.languageSwitcher, () =&gt; this.languageSwitcherCallback(widgetProps, enums_1.ProperyNames.LanguageSwitcher), { initial: true }),
                (0, reactiveUtils_1.watch)(() =&gt; this.configurationSettings?.languageSwitcherOpenAtStart, () =&gt; this.languageSwitcherCallback(widgetProps, enums_1.ProperyNames.LanguageSwitcherOpenAtStart), { initial: true }),
                (0, reactiveUtils_1.watch)(() =&gt; this.configurationSettings?.languageSwitcherPosition, () =&gt; this.languageSwitcherCallback(widgetProps, enums_1.ProperyNames.LanguageSwitcherPosition), { initial: true }),
            ];
        }
        render() {
            const { configurationSettings, _portalItem } = this;
            const config = configurationSettings.languageSwitcherConfig;
            const icon = config?.icon ?? enums_1.Defaults.Icon;
            const locales = config?.locales;
            const defaultLocale = config?.defaultLocale ?? null;
            return ((0, widget_1.tsx)("instant-apps-language-switcher", { bind: this, afterCreate: widget_1.storeNode, class: constants_1.CSS.base, icon: icon, locales: locales, portalItem: _portalItem, defaultLocale: defaultLocale, onselectedLanguageUpdated: this.handleSelection, view: this.view, "data-node-ref": "langSwitcherNode" }));
        }
        setExpandGroup(expandGroup) {
            const languageSwitcher = this.view?.ui?.find(constants_1.NODE_ID);
            if (!languageSwitcher || !expandGroup)
                return;
            this.expandGroup = expandGroup;
            languageSwitcher.group = expandGroup;
        }
        handleLanguageSwitcher(props) {
            const { config, propertyName } = props;
            const { languageSwitcher, languageSwitcherOpenAtStart, languageSwitcherConfig, languageSwitcherPosition, } = config;
            const node = this.view.ui.find(constants_1.NODE_ID);
            if (propertyName === enums_1.ProperyNames.LanguageSwitcher) {
                if (languageSwitcher) {
                    if (!node) {
                        const config = {
                            id: constants_1.NODE_ID,
                            content: this,
                            focusTrapDisabled: true,
                            expandIcon: languageSwitcherConfig?.icon ?? enums_1.Defaults.Icon,
                            expanded: languageSwitcherOpenAtStart,
                            view: this.view,
                            mode: "floating",
                        };
                        if (this.expandTooltip)
                            config.expandTooltip = this.expandTooltip;
                        if (this.collapseTooltip)
                            config.collapseTooltip = this.collapseTooltip;
                        if (this.expandGroup)
                            config.group = this.expandGroup;
                        const expand = new Expand_1.default(config);
                        this.setupAutoUpdateStrings(expand);
                        this.view.ui.add(expand, languageSwitcherPosition ?? enums_1.Defaults.Position);
                    }
                }
                else {
                    if (node) {
                        this.view.ui.remove(node);
                    }
                }
            }
            else if (node &amp;&amp;
                propertyName === enums_1.ProperyNames.LanguageSwitcherOpenAtStart) {
                node.expanded = languageSwitcherOpenAtStart;
            }
            else if (node &amp;&amp; propertyName === enums_1.ProperyNames.LanguageSwitcherPosition) {
                if (this.expandGroup)
                    node.group = this.expandGroup;
                this.view.ui.move(node, languageSwitcherPosition ?? enums_1.Defaults.Position);
            }
        }
        async handleSelection(e) {
            const languageData = e.detail;
            this._set("selectedLanguageData", languageData);
            this._updateUI();
        }
        languageSwitcherCallback(widgetProps, propertyName) {
            widgetProps.propertyName = propertyName;
            const languageSwitcher = this.handleLanguageSwitcher(widgetProps);
            (0, reactiveUtils_1.when)(() =&gt; languageSwitcher, () =&gt; {
                (0, reactiveUtils_1.when)(() =&gt; this.selectedLanguageData, async () =&gt; this._updateUI(), { initial: true, once: true });
            }, { initial: true, once: true });
        }
        async languageSwitcherConfigCallback(widgetProps) {
            const expand = widgetProps?.view?.ui?.find("esri-language-switcher");
            if (this.langSwitcherNode) {
                expand.expandIcon =
                    this.configurationSettings.languageSwitcherConfig.icon;
                this.langSwitcherNode.config =
                    this.configurationSettings.languageSwitcherConfig;
            }
            if ((0, configurationSettings_1.isWithinConfigurationExperience)() &amp;&amp; this.langSwitcherNode) {
                await this.langSwitcherNode.refresh();
            }
            this._updateUI();
        }
        setupAutoUpdateStrings(expand) {
            if (this.messageBundleName &amp;&amp;
                this.expandTooltipKey &amp;&amp;
                this.collapseTooltipKey) {
                t9nUtils_1.autoUpdatedStrings.add({
                    obj: expand,
                    property: "expandTooltip",
                    bundleName: this.messageBundleName,
                    key: this.expandTooltipKey,
                });
                t9nUtils_1.autoUpdatedStrings.add({
                    obj: expand,
                    property: "collapseTooltip",
                    bundleName: this.messageBundleName,
                    key: this.collapseTooltipKey,
                });
            }
        }
    };
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "base", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "configurationSettings", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "view", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "handles", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "langSwitcherNode", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "expandTooltip", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "collapseTooltip", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "expandTooltipKey", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "collapseTooltipKey", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "messageBundleName", void 0);
    __decorate([
        (0, decorators_1.property)()
    ], LanguageSwitcher.prototype, "expandGroup", void 0);
    __decorate([
        (0, decorators_1.property)({
            readOnly: true,
        })
    ], LanguageSwitcher.prototype, "selectedLanguageData", void 0);
    LanguageSwitcher = __decorate([
        (0, decorators_1.subclass)("LanguageSwitcher")
    ], LanguageSwitcher);
    exports.default = LanguageSwitcher;
});
</pre></body></html>