'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-75aef097.js');
const assetsManager = require('./assets-manager-089e91b1.js');
require('./mer-animated-dots-78490ca4.js');
require('lit');
require('lit/directives/when.js');
require('lit/directives/if-defined.js');
const config = require('./config-3bb95f39.js');
const locale = require('./locale-ff30a5f3.js');
const helpers = require('./helpers-bb6622f5.js');

const mapModuleServerDataToComboBoxModel = (servers) => servers.map(server => ({
    value: server.id,
    caption: server.name
}));
const mapModuleVersionDataToComboBoxModel = (moduleVersions) => moduleVersions.map(moduleVersion => ({
    value: moduleVersion.id,
    caption: moduleVersion.name
}));
const renderModuleDataProperties = (options) => {
    if (options.length) {
        const items = [];
        options.forEach(option => {
            const isArray = Array.isArray(option.value);
            if (isArray && option.value.length) {
                const item = (index.h("div", { class: "md-property__list-container" },
                    index.h("p", { class: "md-property__key subtitle-semi-bold-xs" },
                        option.name,
                        " :"),
                    index.h("ul", { class: "md-property__list" }, option.value.map(subItem => {
                        return (index.h("li", { class: "md-property__list-item body-regular-s" }, subItem));
                    }))));
                items.push(item);
            }
            else if (!isArray) {
                const item = (index.h("div", { class: option.inline
                        ? "md-property md-property--inline"
                        : "md-property md-property--block" },
                    index.h("p", { class: "md-property__key subtitle-semi-bold-xs" },
                        option.name,
                        " :"),
                    index.h("p", { class: "md-property__value body-regular-s" }, option.value)));
                items.push(item);
            }
        });
        return items;
    }
    return null;
};

const manageModuleReferencesCss = ".hiChar{color:var(--color-text-primary-default);filter:brightness(1.3)}:host{display:grid;block-size:100%;overflow:auto;grid-template-areas:\"modules-container module-info\" \"footer footer\";grid-template-columns:1fr 1fr;grid-template-rows:1fr max-content}.main{display:contents}.modules__container{padding-inline-end:12px;grid-area:modules-container;grid-template-rows:max-content 1fr;overflow:auto}.combo-box-servers{flex-shrink:0;flex-grow:1}.modules__main{display:grid;grid-template-rows:max-content 1fr;overflow:auto}.modules__main-header{display:grid;gap:8px}.browse-modules button{flex-grow:1}.module-icon{margin-block-start:8px;transform:scale(1) translateX(4px)}.module-grid-item-info{grid-template-columns:max-content 1fr}.grid-or-loader-container{display:grid;position:relative;overflow:hidden;margin-block-start:12px}.tabular-grid{overflow:hidden}.tabular-grid-column-set{display:none}.tabular-grid-cell-icon{pointer-events:none}gx-ide-empty-state{position:absolute}.module-info{padding-inline-start:12px;grid-area:module-info;position:relative}.modules-container,.module-info{overflow:auto}.module-info{display:grid;grid-template-rows:max-content 1fr;overflow:auto}.module-info__action-container{display:flex;flex-direction:row;align-items:center;gap:var(--spacing-gap-m)}.module-info__action-container:before{content:\"\";inline-size:8px;block-size:8px;border-radius:50%;display:block;background-color:var(--color-icon-neutral-disabled)}.module-info__action-container--installed{color:var(--color-text-success-default)}.module-info__action-container--installed:before{background-color:var(--color-text-success-default)}.module-info__action-container--uninstallable:before{background-color:var(--color-icon-warning-default)}.module-info__header{display:grid;gap:var(--spacing-gap-m)}.module-info__title{display:grid;grid-template-columns:max-content 1fr;align-items:center;gap:var(--spacing-gap-xl)}.module-info__icon{transform:scale(1) translateX(4px)}.module-info__alert-message{padding:var(--spacing-padding-m) var(--spacing-padding-l);border-radius:4px;background-color:var(--color-accent-warning-contrast);color:var(--color-text-neutral-default);border:1px solid var(--color-border-warning-default);text-align:center;line-height:var(--line-height-spacious)}.module-info__properties{display:grid;overflow:auto;grid-auto-rows:max-content}.md-property,.md-property__list-container{padding-block:8px;display:grid;gap:var(--spacing-gap-xs);border-block-end:1px solid var(--elevation-border-color, var(--color-border-surface-on-surface))}.md-property:last-child,.md-property__list-container:last-child{border-block-end:0}.md-property__list{margin:0;list-style-type:none;display:inline-flex;padding:0;gap:var(--spacing-gap-xs);flex-wrap:wrap}.md-property__list-item{background-color:var(--color-accent-surface-elevation-2);padding:2px 8px;border-radius:4px;text-transform:lowercase}.md-property--inline{grid-template-columns:max-content 1fr;align-items:start;gap:var(--spacing-gap-m)}.available-versions .versions{flex:1}.available-versions .button-status{min-inline-size:48px;inline-size:max-content;box-sizing:border-box}.footer{grid-area:footer}p.body-regular-s,li.body-regular-s{line-height:var(--line-height-relaxed)}";

var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m")
        throw new TypeError("Private method is not writable");
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _GxManageModuleReferences_componentLocale, _GxManageModuleReferences_moduleVersionsMap, _GxManageModuleReferences_modulesMap, _GxManageModuleReferences_modulesJustFetched, _GxManageModuleReferences_searchModulesFilterValue, _GxManageModuleReferences_modulesGrid, _GxManageModuleReferences_progressBarEl, _GxManageModuleReferences_segmentedControlModel, _GxManageModuleReferences_clearAll, _GxManageModuleReferences_filterModules, _GxManageModuleReferences_getActionFromCurrentModuleVersion, _GxManageModuleReferences_handleFilterChangeHandler, _GxManageModuleReferences_handleModuleChange, _GxManageModuleReferences_moduleActionHandler, _GxManageModuleReferences_moduleTypeButtonClicked, _GxManageModuleReferences_moduleVersionsValueChangedHandler, _GxManageModuleReferences_onProgress, _GxManageModuleReferences_progressBarCloseHandler, _GxManageModuleReferences_reloadServer, _GxManageModuleReferences_renderEmptyStateModules, _GxManageModuleReferences_renderInstalledVersion, _GxManageModuleReferences_renderModuleVersions, _GxManageModuleReferences_renderModulesGrid, _GxManageModuleReferences_renderVersionName, _GxManageModuleReferences_renderVersionWarningMessage, _GxManageModuleReferences_serverSelectedCallbackHandler, _GxManageModuleReferences_serverValueChangedHandler, _GxManageModuleReferences_showModuleMenu;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/form",
    "utils/layout",
    "utils/typography",
    "components/button",
    "components/icon",
    "components/combo-box",
    "components/edit",
    "components/tabular-grid",
    "components/segmented-control",
    "chameleon/scrollbar",
    "utils/spacing"
];
// icons
const SHOW_MORE_ICON = assetsManager.getIconPath({
    category: "gemini-tools",
    name: "show-more-horizontal",
    colorType: "primary"
});
const RESET_ICON = assetsManager.getIconPath({
    category: "gemini-tools",
    name: "reset",
    colorType: "primary"
});
const MODULE_ICON = assetsManager.getIconPath({
    category: "objects",
    name: "module"
});
const FILTER_ICON = assetsManager.getIconPath({
    category: "system",
    name: "filters",
    colorType: "on-surface"
});
const MVS = "__"; // The separator between module-id, and module-version-id
const GxManageModuleReferences = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        _GxManageModuleReferences_componentLocale.set(this, void 0);
        /**
         * #moduleVersionsMap maps a module version (identified as module-id + version-id), with the ModuleVersionData
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxManageModuleReferences_moduleVersionsMap.set(this, new Map());
        /**
         * maps a module-id, with the module current installed version, and the list of versions as a ComboBoxModel representation.
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxManageModuleReferences_modulesMap.set(this, new Map());
        // #modulesJustFetched is used to select the current module on componentDidRender
        _GxManageModuleReferences_modulesJustFetched.set(this, false);
        _GxManageModuleReferences_searchModulesFilterValue.set(this, void 0);
        _GxManageModuleReferences_modulesGrid.set(this, void 0);
        _GxManageModuleReferences_progressBarEl.set(this, void 0);
        _GxManageModuleReferences_segmentedControlModel.set(this, []);
        _GxManageModuleReferences_clearAll.set(this, () => {
            __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").clear();
            __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").clear();
        });
        _GxManageModuleReferences_filterModules.set(this, () => {
            let filteredModules;
            // 1. Filter by type first
            // browse
            if (this.selectedModuleType === "browse") {
                filteredModules = this.modulesAll;
            }
            // installed
            else if (this.selectedModuleType === "installed") {
                filteredModules = this.modulesAll.filter((module) => {
                    // if the module has a currentVersion (not undefined) it means it is installed
                    return module.currentVersion;
                });
            }
            else if (this.selectedModuleType === "updates") {
                filteredModules = this.modulesAll.filter((module) => {
                    return module.versions.find(version => version.action === "update");
                });
            }
            // 2. Then filter by user input
            if (__classPrivateFieldGet(this, _GxManageModuleReferences_searchModulesFilterValue, "f")) {
                filteredModules = filteredModules.filter(module => {
                    const moduleSelectedVersion = __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").get(`${module.id}${MVS}${__classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(module.id).currentSelectedVersion}`);
                    const moduleSelectedVersionName = moduleSelectedVersion.name.toLowerCase();
                    const moduleSelectedVersionDescription = moduleSelectedVersion.description.toLowerCase();
                    return ((moduleSelectedVersionName === null || moduleSelectedVersionName === void 0 ? void 0 : moduleSelectedVersionName.includes(__classPrivateFieldGet(this, _GxManageModuleReferences_searchModulesFilterValue, "f"))) ||
                        (moduleSelectedVersionDescription === null || moduleSelectedVersionDescription === void 0 ? void 0 : moduleSelectedVersionDescription.includes(__classPrivateFieldGet(this, _GxManageModuleReferences_searchModulesFilterValue, "f"))));
                });
            }
            this.filteredModules = filteredModules;
        });
        _GxManageModuleReferences_getActionFromCurrentModuleVersion.set(this, () => {
            const action = __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").get(`${this.selectedModuleId}${MVS}${__classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).currentSelectedVersion}`).action;
            return action || "install";
        });
        _GxManageModuleReferences_handleFilterChangeHandler.set(this, (event) => {
            const searchValue = event.detail.trim().toLowerCase();
            __classPrivateFieldSet(this, _GxManageModuleReferences_searchModulesFilterValue, searchValue, "f");
            __classPrivateFieldGet(this, _GxManageModuleReferences_filterModules, "f").call(this);
        });
        _GxManageModuleReferences_handleModuleChange.set(this, (event) => {
            this.selectedModuleId = event.detail.rowsId[0];
            // update selected versions comboBox model
            const selectedModuleVersionsInfoArray = __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).comboBoxVersionsModel;
            this.selectedModuleVersions = selectedModuleVersionsInfoArray.map(versionInfo => {
                return {
                    caption: versionInfo.value,
                    value: versionInfo.value
                };
            });
        });
        /**
         * Perform an action relative to a module using callbackExecuteAction callback and receive the state of that action with onProgress callback
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxManageModuleReferences_moduleActionHandler.set(this, (module) => async () => {
            await __classPrivateFieldGet(this, _GxManageModuleReferences_progressBarEl, "f").reset(); // sets the progress bar to 0
            this.executeActionCallbackInProgress = true;
            this.actionInProgress = true;
            const moduleSelectedVersionId = __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).currentSelectedVersion;
            const actionSuccessful = await this.executeActionCallback(this.selectedServerId, module.id, moduleSelectedVersionId, __classPrivateFieldGet(this, _GxManageModuleReferences_getActionFromCurrentModuleVersion, "f").call(this), __classPrivateFieldGet(this, _GxManageModuleReferences_onProgress, "f"));
            this.executeActionCallbackInProgress = false;
            if (actionSuccessful) {
                __classPrivateFieldGet(this, _GxManageModuleReferences_serverSelectedCallbackHandler, "f").call(this, this.selectedServerId, false);
            }
        });
        _GxManageModuleReferences_moduleTypeButtonClicked.set(this, (event) => {
            this.selectedModuleType = event.detail;
            __classPrivateFieldGet(this, _GxManageModuleReferences_filterModules, "f").call(this);
        });
        _GxManageModuleReferences_moduleVersionsValueChangedHandler.set(this, (event) => {
            const versionId = event.detail;
            const currentModuleMapValue = __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId);
            currentModuleMapValue.currentSelectedVersion = versionId.toString();
            __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").set(this.selectedModuleId, currentModuleMapValue);
            this.reRenderCounter++;
        });
        /**
         * Callback invoked to get the progress when module is performing an action
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxManageModuleReferences_onProgress.set(this, (message, progress, state) => {
            const data = { message, progress, state };
            this.selectedModuleAction = Object.assign({}, data);
            this.progressValue = this.selectedModuleAction.progress;
            this.progressState = this.selectedModuleAction.state;
        });
        _GxManageModuleReferences_progressBarCloseHandler.set(this, () => { });
        _GxManageModuleReferences_reloadServer.set(this, () => {
            __classPrivateFieldGet(this, _GxManageModuleReferences_serverSelectedCallbackHandler, "f").call(this, this.selectedServerId, true);
        });
        _GxManageModuleReferences_renderEmptyStateModules.set(this, () => {
            return (index.h("gx-ide-empty-state", { isAnimated: true, stateIconSrc: FILTER_ICON, stateTitle: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modules.noModulesFilter }));
        });
        _GxManageModuleReferences_renderInstalledVersion.set(this, () => {
            const currentInstalledVersion = __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).currentInstalledVersion;
            let caption;
            let cssClass = "module-info__action-container";
            if (currentInstalledVersion) {
                caption = `${__classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modulesInformation.moduleProperties.installed}: ${currentInstalledVersion}`;
                cssClass += ` module-info__action-container--installed`;
            }
            else {
                caption =
                    __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modulesInformation.moduleProperties.notInstalled;
            }
            return (index.h("div", { class: cssClass }, index.h("p", { class: "body-regular-m" }, caption)));
        });
        _GxManageModuleReferences_renderModuleVersions.set(this, () => {
            const currentSelectedModule = __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId);
            const selectedVersionValue = currentSelectedModule.currentSelectedVersion;
            const moduleSelectedVersion = __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").get(`${this.selectedModuleId}${MVS}${__classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).currentSelectedVersion}`);
            const moduleSelectedVersionAction = moduleSelectedVersion.action;
            return (index.h("div", { class: "field field-block available-versions" }, index.h("label", { class: "label", htmlFor: "available-versions" }, __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").availableVersions), index.h("div", { class: "buttons-spacer combo-and-button" }, index.h("ch-combo-box-render", { id: "available-versions", class: "combo-box versions", value: selectedVersionValue, onInput: __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsValueChangedHandler, "f"), disabled: this.loadingServer, model: this.selectedModuleVersions }), index.h("button", { class: "button-primary button-status", disabled: this.executeActionCallbackInProgress ||
                    moduleSelectedVersionAction === "incompatible" ||
                    moduleSelectedVersionAction === "not-installable", onClick: __classPrivateFieldGet(this, _GxManageModuleReferences_moduleActionHandler, "f").call(this, currentSelectedModule.moduleData) }, __classPrivateFieldGet(this, _GxManageModuleReferences_getActionFromCurrentModuleVersion, "f").call(this)))));
        });
        _GxManageModuleReferences_renderModulesGrid.set(this, () => {
            return (index.h("ch-tabular-grid", {
                // TODO: Evaluate if the tabular-grid is the right tool for this job.
                rowSelectionMode: "single", part: "ch-grid-pending-commits", class: "tabular-grid scrollable", onSelectionChanged: __classPrivateFieldGet(this, _GxManageModuleReferences_handleModuleChange, "f"), ref: el => (__classPrivateFieldSet(this, _GxManageModuleReferences_modulesGrid, el, "f"))
            }, index.h("ch-tabular-grid-columnset", { class: "tabular-grid-column-set" }, index.h("ch-tabular-grid-column", { class: "tabular-grid-column", settingable: false, sortable: false, size: config.config.tabularGrid.colSize.common })), this.filteredModules.length ? (index.h("ch-tabular-grid-rowset", { class: "tabular-grid-rowset" }, this.filteredModules.map((module) => {
                const moduleIsInstalled = module.currentVersion;
                const moduleSelectedVersion = __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").get(`${module.id}${MVS}${__classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(module.id).currentSelectedVersion}`);
                const moduleSelectedVersionName = moduleSelectedVersion.name;
                const moduleSelectedVersionDescription = moduleSelectedVersion.description;
                return (index.h("ch-tabular-grid-row", {
                    // TODO: Replace tabular grid with other control, since it does not makes sense to use a grid with only one column.
                    class: "tabular-grid-row", rowid: module.id, key: module.id
                }, index.h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, index.h("div", { class: "module-grid-item-info field-group" }, index.h("ch-image", { class: "icon-m module-icon", src: MODULE_ICON, disabled: !moduleIsInstalled }), index.h("div", { class: "field field-block" }, index.h("h6", { class: "subtitle-semi-bold-xs" }, helpers.hiChar(moduleSelectedVersionName, __classPrivateFieldGet(this, _GxManageModuleReferences_searchModulesFilterValue, "f"))), index.h("p", { class: "body-regular-s" }, helpers.hiChar(moduleSelectedVersionDescription, __classPrivateFieldGet(this, _GxManageModuleReferences_searchModulesFilterValue, "f"))))))));
            }))) : (index.h("ch-tabular-grid-rowset", { class: "tabular-grid-rowset" }, index.h("ch-tabular-grid-rowset-empty", null, __classPrivateFieldGet(this, _GxManageModuleReferences_renderEmptyStateModules, "f").call(this))))));
        });
        /* module details/information renders*/
        _GxManageModuleReferences_renderVersionName.set(this, () => {
            const moduleSelectedVersion = __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").get(`${this.selectedModuleId}${MVS}${__classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).currentSelectedVersion}`);
            const selectedModule = __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId);
            const moduleIsInstalled = selectedModule.currentInstalledVersion;
            return (index.h("div", { class: "module-info__title" }, index.h("ch-image", { class: "icon-l module-info__icon", src: MODULE_ICON, disabled: !moduleIsInstalled }), index.h("h6", { class: "subtitle-semi-bold-s" }, moduleSelectedVersion.name)));
        });
        _GxManageModuleReferences_renderVersionWarningMessage.set(this, () => {
            const moduleVersionWarningMessage = __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").get(`${this.selectedModuleId}${MVS}${__classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).currentSelectedVersion}`).warningMessage;
            if (moduleVersionWarningMessage) {
                return (index.h("p", { class: "module-info__alert-message body-regular-s" }, moduleVersionWarningMessage));
            }
        });
        _GxManageModuleReferences_serverSelectedCallbackHandler.set(this, async (id, reload) => {
            if (this.serverSelectedCallback) {
                this.selectedServerId = id;
                this.loadingServer = true;
                const resolvedObjects = await this.serverSelectedCallback(id, reload);
                this.modulesAll = [...resolvedObjects];
                this.loadingServer = false;
            }
        });
        _GxManageModuleReferences_serverValueChangedHandler.set(this, (event) => {
            this.selectedModuleId = undefined; // clear selected module
            __classPrivateFieldSet(this, _GxManageModuleReferences_searchModulesFilterValue, "", "f"); // clear filter
            this.selectedModuleType = "browse"; // set "browse" as the default selected type
            const serverId = event.detail;
            __classPrivateFieldGet(this, _GxManageModuleReferences_serverSelectedCallbackHandler, "f").call(this, serverId, false);
        });
        _GxManageModuleReferences_showModuleMenu.set(this, async (e) => {
            if (this.serverContextMenuCallback) {
                const buttonBoundingClientRect = e.target.getBoundingClientRect();
                await this.serverContextMenuCallback({
                    selection: [this.selectedServerId],
                    clientX: buttonBoundingClientRect.x,
                    clientY: buttonBoundingClientRect.y
                });
            }
        });
        this.actionInProgress = false;
        this.executeActionCallbackInProgress = false;
        this.filteredModules = [];
        this.loadingServer = false;
        this.modulesAll = [];
        this.progressState = "in-progress";
        this.progressValue = 0;
        this.reRenderCounter = 0;
        this.selectedModuleAction = {
            message: "",
            progress: 0,
            state: "in-progress"
        };
        this.selectedModuleId = undefined;
        this.selectedModuleType = "browse";
        this.selectedServerId = undefined;
        this.selectedServerValue = undefined;
        this.serversComboBoxModel = [];
        this.selectedModuleVersions = [];
        this.autoCloseProgressBar = false;
        this.executeActionCallback = undefined;
        this.serverContextMenuCallback = undefined;
        this.serverSelectedCallback = undefined;
        this.servers = [];
        this.showServerCommands = false;
    }
    modulesAllChanged(newModules) {
        let currentSelectedVersion;
        if (this.selectedModuleId) {
            // If this.selectedModuleId has a value, serverSelectedCallback was called
            // but the server is the same. This occurs when a user action (e.g., install
            // or restore) requires modules to update. The selected module and version
            // remain unchanged. We must save the current version before #clearAll().
            currentSelectedVersion = __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId).currentSelectedVersion;
        }
        __classPrivateFieldGet(this, _GxManageModuleReferences_clearAll, "f").call(this);
        newModules.forEach(module => {
            let currentSelectedVersionValue = module.versions[0].id;
            if (currentSelectedVersion && this.selectedModuleId === module.id) {
                currentSelectedVersionValue = currentSelectedVersion;
            }
            // fulfill #modulesMap
            const moduleVersionsComboBoxModel = mapModuleVersionDataToComboBoxModel(module.versions);
            __classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").set(module.id, {
                moduleData: module,
                currentInstalledVersion: module.currentVersion,
                currentSelectedVersion: currentSelectedVersionValue,
                comboBoxVersionsModel: moduleVersionsComboBoxModel
            });
            // fulfill #moduleVersionsMap.
            module.versions.forEach(version => {
                const moduleVersionCombinedId = `${module.id}${MVS}${version.id}`;
                __classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").set(moduleVersionCombinedId, {
                    id: version.id,
                    action: version.action,
                    description: version.description,
                    properties: version.properties,
                    name: version.name,
                    warningMessage: version.warningMessage
                });
            });
        });
        __classPrivateFieldSet(this, _GxManageModuleReferences_modulesJustFetched, true, "f");
        __classPrivateFieldGet(this, _GxManageModuleReferences_filterModules, "f").call(this);
    }
    serversChanged(newServers) {
        if (newServers.length) {
            this.serversComboBoxModel =
                mapModuleServerDataToComboBoxModel(newServers);
            this.selectedServerValue = this.serversComboBoxModel[0].value;
        }
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxManageModuleReferences_componentLocale, await locale.Locale.getComponentStrings(this.el), "f");
        this.serversChanged(this.servers); // map ModuleServerData to ComboBoxModel
        __classPrivateFieldSet(this, _GxManageModuleReferences_segmentedControlModel, [
            {
                id: "browse",
                caption: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modules.buttonsContainer.browse
            },
            {
                id: "installed",
                caption: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modules.buttonsContainer.installed
            },
            {
                id: "updates",
                caption: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modules.buttonsContainer.updates
            }
        ], "f");
    }
    async componentDidLoad() {
        await __classPrivateFieldGet(this, _GxManageModuleReferences_serverSelectedCallbackHandler, "f").call(this, this.servers[0].id, false);
    }
    componentDidRender() {
        if (__classPrivateFieldGet(this, _GxManageModuleReferences_modulesJustFetched, "f") && this.selectedModuleId) {
            // set selected module as selected on the grid after server reload.
            __classPrivateFieldGet(this, _GxManageModuleReferences_modulesGrid, "f").selectRow(this.selectedModuleId, true);
            __classPrivateFieldSet(this, _GxManageModuleReferences_modulesJustFetched, false, "f");
        }
    }
    progressBarClosedHandler() {
        // set it to false, to fire a re-render the next time the progress-bar is active.
        this.actionInProgress = false;
    }
    render() {
        return (index.h(index.Host, { class: "widget" }, index.h("ch-theme", { model: CSS_BUNDLES }), index.h("section", { class: "main" }, index.h("div", { class: "modules__container field-group" }, index.h("header", { class: "modules__header field-group" }, index.h("div", { class: "field field-block" }, index.h("label", { class: "label", htmlFor: "servers-list" }, __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modules.selectServer), index.h("div", { class: "modules__header-controls buttons-spacer" }, index.h("ch-combo-box-render", {
            // select server
            id: "servers-list", class: "combo-box combo-box-servers", model: this.serversComboBoxModel, value: this.selectedServerValue, disabled: this.loadingServer, onInput: __classPrivateFieldGet(this, _GxManageModuleReferences_serverValueChangedHandler, "f")
        }), index.h("div", null, this.showServerCommands && (index.h("button", {
            // server context menu button
            class: "button-tertiary button-icon-only", onClick: __classPrivateFieldGet(this, _GxManageModuleReferences_showModuleMenu, "f"), "aria-label": __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").showServerMenu, title: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").showServerMenu
        }, index.h("ch-image", { src: SHOW_MORE_ICON, class: "icon-m" }))), index.h("button", {
            // reload server selected button
            class: "button-tertiary button-icon-only", onClick: __classPrivateFieldGet(this, _GxManageModuleReferences_reloadServer, "f"), "aria-label": __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").reloadModules, title: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").reloadModules
        }, index.h("ch-image", { src: RESET_ICON, class: "icon-m" })))))), index.h("div", {
            // Modules main
            class: "modules__main"
        }, index.h("div", { class: "modules__main-header" }, index.h("div", {
            // search modules
            class: "field field-block"
        }, index.h("label", { class: "label", htmlFor: "search-modules" }, __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modules.searchModules), index.h("ch-edit", { class: "input", value: __classPrivateFieldGet(this, _GxManageModuleReferences_searchModulesFilterValue, "f"), onInput: __classPrivateFieldGet(this, _GxManageModuleReferences_handleFilterChangeHandler, "f"), disabled: this.loadingServer })), index.h("div", { class: "browse-modules" }, index.h("ch-segmented-control-render", { class: "segmented-control-filled", model: __classPrivateFieldGet(this, _GxManageModuleReferences_segmentedControlModel, "f"), selectedId: this.selectedModuleType, onSelectedItemChange: __classPrivateFieldGet(this, _GxManageModuleReferences_moduleTypeButtonClicked, "f") }))), index.h("div", { class: "grid-or-loader-container" }, this.loadingServer ? (index.h("gx-ide-loader", { loaderTitle: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").servers.loading, show: true })) : (__classPrivateFieldGet(this, _GxManageModuleReferences_renderModulesGrid, "f").call(this))))), index.h("div", { class: "module-info field-group" }, this.selectedModuleId ? ([
            index.h("header", { class: "module-info__header" }, __classPrivateFieldGet(this, _GxManageModuleReferences_renderVersionName, "f").call(this), __classPrivateFieldGet(this, _GxManageModuleReferences_renderInstalledVersion, "f").call(this), __classPrivateFieldGet(this, _GxManageModuleReferences_renderModuleVersions, "f").call(this), __classPrivateFieldGet(this, _GxManageModuleReferences_renderVersionWarningMessage, "f").call(this)),
            index.h("div", { class: "module-info__properties scrollable" }, index.h("div", { class: "module-info__properties-inner-wrapper" }, renderModuleDataProperties(__classPrivateFieldGet(this, _GxManageModuleReferences_moduleVersionsMap, "f").get(`${this.selectedModuleId}__${__classPrivateFieldGet(this, _GxManageModuleReferences_modulesMap, "f").get(this.selectedModuleId)
                .currentSelectedVersion}`).properties)))
        ]) : (index.h("gx-ide-empty-state", { class: "recent-objects__empty-state", stateIconSrc: MODULE_ICON, stateTitle: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modulesInformation.emptyState.title, stateDescription: __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").modulesInformation.emptyState
                .description }))), index.h("footer", { class: "footer" }, index.h("gx-ide-progress-bar", { class: "border-block-start", slot: "footer-above", part: "progress-bar", stateType: this.progressState, caption: this.selectedModuleAction.message ||
                __classPrivateFieldGet(this, _GxManageModuleReferences_componentLocale, "f").progressBar.defaultCaption, progress: this.progressValue, active: this.actionInProgress, closeType: this.autoCloseProgressBar ? "auto-close" : "button", closedCallback: __classPrivateFieldGet(this, _GxManageModuleReferences_progressBarCloseHandler, "f"), ref: el => (__classPrivateFieldSet(this, _GxManageModuleReferences_progressBarEl, el, "f")) })))));
    }
    static get assetsDirs() { return ["gx-ide-assets/manage-module-references"]; }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "modulesAll": ["modulesAllChanged"],
        "servers": ["serversChanged"]
    }; }
};
_GxManageModuleReferences_componentLocale = new WeakMap(), _GxManageModuleReferences_moduleVersionsMap = new WeakMap(), _GxManageModuleReferences_modulesMap = new WeakMap(), _GxManageModuleReferences_modulesJustFetched = new WeakMap(), _GxManageModuleReferences_searchModulesFilterValue = new WeakMap(), _GxManageModuleReferences_modulesGrid = new WeakMap(), _GxManageModuleReferences_progressBarEl = new WeakMap(), _GxManageModuleReferences_segmentedControlModel = new WeakMap(), _GxManageModuleReferences_clearAll = new WeakMap(), _GxManageModuleReferences_filterModules = new WeakMap(), _GxManageModuleReferences_getActionFromCurrentModuleVersion = new WeakMap(), _GxManageModuleReferences_handleFilterChangeHandler = new WeakMap(), _GxManageModuleReferences_handleModuleChange = new WeakMap(), _GxManageModuleReferences_moduleActionHandler = new WeakMap(), _GxManageModuleReferences_moduleTypeButtonClicked = new WeakMap(), _GxManageModuleReferences_moduleVersionsValueChangedHandler = new WeakMap(), _GxManageModuleReferences_onProgress = new WeakMap(), _GxManageModuleReferences_progressBarCloseHandler = new WeakMap(), _GxManageModuleReferences_reloadServer = new WeakMap(), _GxManageModuleReferences_renderEmptyStateModules = new WeakMap(), _GxManageModuleReferences_renderInstalledVersion = new WeakMap(), _GxManageModuleReferences_renderModuleVersions = new WeakMap(), _GxManageModuleReferences_renderModulesGrid = new WeakMap(), _GxManageModuleReferences_renderVersionName = new WeakMap(), _GxManageModuleReferences_renderVersionWarningMessage = new WeakMap(), _GxManageModuleReferences_serverSelectedCallbackHandler = new WeakMap(), _GxManageModuleReferences_serverValueChangedHandler = new WeakMap(), _GxManageModuleReferences_showModuleMenu = new WeakMap();
GxManageModuleReferences.style = manageModuleReferencesCss;

exports.gx_ide_manage_module_references = GxManageModuleReferences;

//# sourceMappingURL=gx-ide-manage-module-references.cjs.entry.js.map