'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 locale = require('./locale-ff30a5f3.js');

const ACTIVE_ITEM_DEFAULT_ICON = assetsManager.getIconPath({
    category: "system",
    name: "check-circle",
    colorType: "primary"
});
const convertItemsNodeListToFlattenedTreeViewModel = (itemsList, checkboxType) => {
    const itemsListFlattenedTreeViewModel = [];
    const processNode = (item) => {
        var _a;
        const startImgSrc = item.active && !item.iconStart
            ? ACTIVE_ITEM_DEFAULT_ICON
            : item.iconStart;
        const leaf = !((_a = item.nodes) === null || _a === void 0 ? void 0 : _a.length);
        const checkbox = checkboxType === "all" ||
            (checkboxType === "custom" && item.checkbox) ||
            (checkboxType === "leaf" && leaf);
        const metaData = JSON.stringify({
            versionType: item.type
        });
        itemsListFlattenedTreeViewModel.push({
            caption: item.name,
            checkbox: checkbox,
            checked: item.checked,
            startImgSrc: startImgSrc,
            endImgSrc: item.iconEnd,
            expanded: item.expanded,
            id: item.id.toString(),
            items: null,
            leaf: leaf,
            metadata: metaData,
            parts: item.parts,
            selected: item.selected,
            order: item.order
        });
        if (item.nodes) {
            item.nodes.forEach(childNode => processNode(childNode));
        }
    };
    itemsList.forEach(item => processNode(item));
    return itemsListFlattenedTreeViewModel;
};
const convertItemsListToTreeViewModel = (itemsList, checkboxType) => {
    const itemsListTreeViewModel = [];
    itemsList.forEach(item => {
        var _a;
        const startImgSrc = item.active && !item.iconStart
            ? ACTIVE_ITEM_DEFAULT_ICON
            : item.iconStart;
        const leaf = !((_a = item.nodes) === null || _a === void 0 ? void 0 : _a.length);
        const checkbox = checkboxType === "all" ||
            (checkboxType === "custom" && item.checkbox) ||
            (checkboxType === "leaf" && leaf);
        const expanded = item.expanded;
        const iconStart = startImgSrc;
        const iconEnd = item.iconEnd;
        const metaData = JSON.stringify({
            versionType: item.type
        });
        const order = parseInt(item.id);
        itemsListTreeViewModel.push({
            caption: item.name,
            checkbox: checkbox,
            checked: item.checked,
            startImgSrc: iconStart,
            endImgSrc: iconEnd,
            expanded: expanded,
            id: item.id.toString(),
            items: !leaf
                ? convertItemsListToTreeViewModel(item.nodes, checkboxType)
                : null,
            leaf: leaf,
            metadata: metaData,
            parts: item.parts,
            order: order,
            selected: item.selected
        });
    });
    return itemsListTreeViewModel;
};
const findItemNode = (id, item) => {
    if (item.id === id) {
        return item;
    }
    if (item.nodes) {
        for (const itemNode of item.nodes) {
            const result = findItemNode(id, itemNode);
            if (result) {
                return result;
            }
        }
    }
    return null;
};
function findItemInArray(itemsNodes, id) {
    for (const item of itemsNodes) {
        const result = findItemNode(id, item);
        if (result) {
            return result;
        }
    }
    return null;
}
const setAllLeafsCheckedFalse = (itemsList) => {
    const uncheck = (itemNode) => {
        var _a;
        itemNode.checked = false;
        if ((_a = itemNode.nodes) === null || _a === void 0 ? void 0 : _a.length) {
            itemNode.nodes.forEach(childNode => uncheck(childNode));
        }
    };
    itemsList.forEach(item => uncheck(item));
    return itemsList;
};
const unselectAllNodes = (itemsList) => {
    const unselect = (itemNode) => {
        var _a;
        itemNode.selected = false;
        if ((_a = itemNode.nodes) === null || _a === void 0 ? void 0 : _a.length) {
            itemNode.nodes.forEach(childNode => unselect(childNode));
        }
    };
    itemsList.forEach(item => unselect(item));
};
const checkItems = (itemsList, idsChecked) => {
    setAllLeafsCheckedFalse(itemsList);
    idsChecked.forEach(id => {
        const itemFind = findItemInArray(itemsList, id);
        if (itemFind) {
            itemFind.checked = true;
        }
    });
    return itemsList;
};
const expandItems = (itemsList, idsChecked) => {
    idsChecked.forEach(id => {
        const itemFind = findItemInArray(itemsList, id);
        if (itemFind) {
            itemFind.expanded = true;
        }
    });
    return itemsList;
};
const selectItems = (itemsList, idsSelected) => {
    idsSelected.forEach(id => {
        const itemFind = findItemInArray(itemsList, id);
        if (itemFind) {
            itemFind.selected = true;
        }
    });
    return itemsList;
};
function searchInNode(item, id) {
    var _a;
    // If the current node is the searched node, we return an empty list (it has no parents in this branch)
    if (item.id === id) {
        return [];
    }
    // We traverse each child looking for the target node
    if ((_a = item.nodes) === null || _a === void 0 ? void 0 : _a.length) {
        for (const node of item.nodes) {
            const parents = searchInNode(node, id);
            if (parents !== null) {
                // If we find it, we include the current node at the beginning of the path and return
                return [item.id, ...parents];
            }
        }
    }
    return null;
}
const searchParentsItems = (items, ids) => {
    const parents = [];
    for (const id of ids) {
        for (const rootItem of items) {
            const results = searchInNode(rootItem, id);
            if (results !== null) {
                results.forEach(result => {
                    parents.push(result);
                });
            }
        }
    }
    return parents;
};
/**
 * Recursively searches for the first node with the active=true property
 * @param nodes Array of nodes to search through
 * @returns An object with caption, iconStart, and path to the first active node found, or null if none is found
 */
const findFirstActiveNode = (nodes) => {
    // Helper function that keeps track of the path during recursion
    const findActiveWithPath = (nodeList, currentPath = []) => {
        // Base case: if nodes is undefined or empty
        if (!nodeList || nodeList.length === 0) {
            return null;
        }
        // Iterate through each node in the array
        for (const node of nodeList) {
            // Create a new path that includes the current node
            const nodePath = [...currentPath, node.id];
            // Check if the current node is active
            if (node.active === true) {
                return {
                    caption: node.name,
                    iconStart: node.iconStart,
                    path: nodePath
                };
            }
            // If the node has children, search through them with the updated path
            if (node.nodes && node.nodes.length > 0) {
                const result = findActiveWithPath(node.nodes, nodePath);
                // If we find an active node in this subtree, return it immediately
                if (result !== null) {
                    return result;
                }
            }
        }
        // No active node found in any of the nodes
        return null;
    };
    // Start the search with an empty path
    return findActiveWithPath(nodes);
};

const selectKbItemsCss = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{--search-input-max-inline-size:400px;display:grid;block-size:100%}:host(:not(.has-footer)){grid-template-rows:max-content 1fr}:host(.has-footer){grid-template-rows:max-content 1fr max-content}.header.has-active-item{grid-area:header}.section{display:contents}.header__first-row,.header__second-row{display:grid;grid-auto-flow:column}.header__first-row{grid-auto-columns:max-content}.header__second-row{grid-template-columns:minmax(150px, var(--search-input-max-inline-size)) max-content}.header__second-row--one-row{grid-template-columns:minmax(150px, var(--search-input-max-inline-size))}.active-item{background-color:var(--color-accent-surface-elevation-1);border-radius:4px;padding:var(--control-padding-block) var(--control-padding-inline);display:flex;align-items:center;gap:var(--spacing-gap-m)}.active-item__icon-container{display:contents}.active-item__icon{pointer-events:none}.active-item__link{text-decoration:underline;color:var(--color-text-primary-default);cursor:pointer}.active-item__link:hover{color:var(--color-text-primary-hover)}.active-item__link:active{color:var(--color-text-primary-pressed)}.trees{position:relative}";

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 _GxIdeSelectKbItems_instances, _GxIdeSelectKbItems__componentLocale, _GxIdeSelectKbItems_chShortcutsEl, _GxIdeSelectKbItems_selectedNodesIds, _GxIdeSelectKbItems_shortcutsSrc, _GxIdeSelectKbItems_updatedModelList, _GxIdeSelectKbItems_viewItemsAsModel, _GxIdeSelectKbItems_treeViewRenderEl, _GxIdeSelectKbItems_loadItems, _GxIdeSelectKbItems_cancelHandler, _GxIdeSelectKbItems_checkedItemsChangeHandler, _GxIdeSelectKbItems_confirmHandler, _GxIdeSelectKbItems_contextMenuHandler, _GxIdeSelectKbItems_executeDialogAction, _GxIdeSelectKbItems_patternSearchValueChangedHandler, _GxIdeSelectKbItems_renderActionButtons, _GxIdeSelectKbItems_renderFooter, _GxIdeSelectKbItems_selectedItemsChangeHandler, _GxIdeSelectKbItems_toggleAndSelectNodesInModelItems, _GxIdeSelectKbItems_toggleCheckedNodesInModelItems, _GxIdeSelectKbItems_updateViews, _GxIdeSelectKbItems_viewItemsAsChangedHandler, _GxIdeSelectKbItems_toggleCheckboxesChangedHandler, _GxIdeSelectKbItems_scrollIntoActiveVersionNode;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "chameleon/scrollbar",
    "components/tooltip",
    "components/tree-view",
    "utils/form--full",
    "utils/layout",
    "utils/spacing",
    "utils/typography"
];
const SYSTEM_SEARCH_ICON = assetsManager.getIconPath({
    category: "system",
    name: "search",
    colorType: "on-surface"
});
const VIEW_AS_TREE_ID = "tree";
const VIEW_AS_LIST_ID = "list";
const TOGGLE_CHECKBOXES_CHECKED_VALUE = "on";
const GxIdeSelectKbItems = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        _GxIdeSelectKbItems_instances.add(this);
        _GxIdeSelectKbItems__componentLocale.set(this, void 0);
        _GxIdeSelectKbItems_chShortcutsEl.set(this, void 0);
        _GxIdeSelectKbItems_selectedNodesIds.set(this, []);
        _GxIdeSelectKbItems_shortcutsSrc.set(this, index.getAssetPath(`./gx-ide-assets/select-kb-items/shortcuts.json`));
        _GxIdeSelectKbItems_updatedModelList.set(this, []);
        _GxIdeSelectKbItems_viewItemsAsModel.set(this, void 0);
        _GxIdeSelectKbItems_treeViewRenderEl.set(this, void 0);
        _GxIdeSelectKbItems_cancelHandler.set(this, () => {
            if (this.cancelCallback) {
                this.cancelCallback();
            }
        });
        _GxIdeSelectKbItems_checkedItemsChangeHandler.set(this, async (e) => {
            let checkedNodesIds = [];
            e.detail.forEach(node => {
                if (node.item.checked) {
                    checkedNodesIds.push(node.item.id);
                }
            });
            if (this.singleChecks) {
                // Detect the last change by comparing previous and new state
                let lastCheckedId = null;
                // If there are more in the new state, it was a check; if less, it was an uncheck
                if (checkedNodesIds.length > this.checkedNodesIds.length) {
                    // Find the newly checked item
                    lastCheckedId =
                        checkedNodesIds.find(id => !this.checkedNodesIds.includes(id)) ||
                            null;
                }
                else if (checkedNodesIds.length < this.checkedNodesIds.length) {
                    // Find the unchecked item (not used in single check, but kept for clarity)
                    lastCheckedId =
                        this.checkedNodesIds.find(id => !checkedNodesIds.includes(id)) ||
                            null;
                }
                // Only allow one if multiChecks is false
                if (this.singleChecks && checkedNodesIds.length > 1) {
                    // If we detected the last checked, keep it; otherwise, keep the first
                    checkedNodesIds = lastCheckedId
                        ? [lastCheckedId]
                        : [checkedNodesIds[0]];
                    // Uncheck the others
                    __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").updateItemsProperties(Array.from(e.detail.keys()).filter(id => id !== checkedNodesIds[0]), { checked: false });
                }
            }
            this.checkedNodesIds = checkedNodesIds;
            __classPrivateFieldSet(this, _GxIdeSelectKbItems_updatedModelList, checkItems(this.itemsList, this.checkedNodesIds), "f");
            if (this.checkedChanged) {
                this.checkedChanged(this.checkedNodesIds);
            }
        });
        _GxIdeSelectKbItems_confirmHandler.set(this, () => {
            if (this.confirmCallback) {
                this.confirmCallback(this.checkedNodesIds);
            }
        });
        _GxIdeSelectKbItems_contextMenuHandler.set(this, async (e) => {
            if (this.itemContextMenuCallback) {
                let info;
                const isSelected = __classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f").find(id => id === e.detail.id);
                if (!__classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f").length || !isSelected) {
                    await __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").updateItemsProperties(__classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f"), { selected: false });
                    await __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").updateItemsProperties([e.detail.id], {
                        selected: true
                    });
                    info = {
                        clientX: e.detail.contextmenuEvent.clientX,
                        clientY: e.detail.contextmenuEvent.clientY,
                        selection: [e.detail.id]
                    };
                }
                else {
                    info = {
                        clientX: e.detail.contextmenuEvent.clientX,
                        clientY: e.detail.contextmenuEvent.clientY,
                        selection: __classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f")
                    };
                }
                this.itemContextMenuCallback(info);
            }
        });
        _GxIdeSelectKbItems_executeDialogAction.set(this, (callback) => {
            return () => {
                callback(this.checkedNodesIds, __classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f"));
            };
        });
        _GxIdeSelectKbItems_patternSearchValueChangedHandler.set(this, (event) => {
            this.searchPatternValue = event.detail.toString();
        });
        _GxIdeSelectKbItems_renderActionButtons.set(this, () => {
            return (index.h("div", null, this.dialogActions.map(action => {
                return (index.h("button", { class: "button-tertiary", part: `button button-${action.name}`, onClick: __classPrivateFieldGet(this, _GxIdeSelectKbItems_executeDialogAction, "f").call(this, action.callback), disabled: this.loading }, action.name));
            })));
        });
        _GxIdeSelectKbItems_renderFooter.set(this, () => {
            var _a;
            return (index.h("footer", { class: "footer dialog-footer-with-border spacing-body-inline spacing-body-block-end dialog-footer-space-between" }, __classPrivateFieldGet(this, _GxIdeSelectKbItems_renderActionButtons, "f").call(this), index.h("div", { class: "buttons-spacer " }, this.cancelCallback && (index.h("button", { class: "button-secondary", part: "cancel-button", onClick: __classPrivateFieldGet(this, _GxIdeSelectKbItems_cancelHandler, "f") }, __classPrivateFieldGet(this, _GxIdeSelectKbItems__componentLocale, "f").footer.cancel)), this.confirmCallback && (index.h("button", { class: "button-primary", part: "confirm-button", onClick: __classPrivateFieldGet(this, _GxIdeSelectKbItems_confirmHandler, "f"), disabled: this.loading || ((_a = this.checkedNodesIds) === null || _a === void 0 ? void 0 : _a.length) === 0 }, __classPrivateFieldGet(this, _GxIdeSelectKbItems__componentLocale, "f").footer.select)))));
        });
        _GxIdeSelectKbItems_selectedItemsChangeHandler.set(this, (e) => {
            const selectedNodesIds = [];
            unselectAllNodes(this.itemsList);
            e.detail.forEach(node => {
                selectedNodesIds.push(node.item.id);
            });
            __classPrivateFieldSet(this, _GxIdeSelectKbItems_selectedNodesIds, selectedNodesIds, "f");
            if (this.selectionChanged) {
                this.selectionChanged(__classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f"));
            }
            __classPrivateFieldSet(this, _GxIdeSelectKbItems_updatedModelList, selectItems(this.itemsList, selectedNodesIds), "f");
        });
        _GxIdeSelectKbItems_toggleAndSelectNodesInModelItems.set(this, async (selectedItemsIds) => {
            const nodesToToggle = searchParentsItems(this.itemsList, selectedItemsIds);
            const newItemsSelected = selectItems(this.itemsList, selectedItemsIds);
            const newItemsExpanded = expandItems(newItemsSelected, nodesToToggle);
            __classPrivateFieldGet(this, _GxIdeSelectKbItems_updateViews, "f").call(this, newItemsExpanded);
        });
        _GxIdeSelectKbItems_toggleCheckedNodesInModelItems.set(this, async (selectedItemsIds) => {
            const nodesToToggle = searchParentsItems(this.itemsList, selectedItemsIds);
            const newItemsExpanded = expandItems(this.itemsList, nodesToToggle);
            __classPrivateFieldGet(this, _GxIdeSelectKbItems_updateViews, "f").call(this, newItemsExpanded);
        });
        _GxIdeSelectKbItems_updateViews.set(this, (newItemsList) => {
            this.nodeVersionsListTreeModel = convertItemsListToTreeViewModel(newItemsList, this.checkboxType);
            this.nodeListFlattenedTreeModel =
                convertItemsNodeListToFlattenedTreeViewModel(newItemsList, this.checkboxType);
        });
        _GxIdeSelectKbItems_viewItemsAsChangedHandler.set(this, async (event) => {
            const selectedViewType = event.detail;
            this.nodesVersionsViewType = selectedViewType;
            if (this.nodesVersionsViewType === "tree") {
                await __classPrivateFieldGet(this, _GxIdeSelectKbItems_toggleAndSelectNodesInModelItems, "f").call(this, __classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f"));
                await __classPrivateFieldGet(this, _GxIdeSelectKbItems_toggleCheckedNodesInModelItems, "f").call(this, this.checkedNodesIds);
            }
            __classPrivateFieldGet(this, _GxIdeSelectKbItems_updateViews, "f").call(this, __classPrivateFieldGet(this, _GxIdeSelectKbItems_updatedModelList, "f"));
        });
        _GxIdeSelectKbItems_toggleCheckboxesChangedHandler.set(this, (event) => {
            this.toggleCheckboxes = event.detail === TOGGLE_CHECKBOXES_CHECKED_VALUE;
        });
        _GxIdeSelectKbItems_scrollIntoActiveVersionNode.set(this, async () => {
            var _a;
            const doScrollIntoView = __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f") && ((_a = this.activeItemNode) === null || _a === void 0 ? void 0 : _a.path);
            if (doScrollIntoView) {
                await __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").scrollIntoVisible(this.activeItemNode.path);
            }
            if (this.activeItemCallback) {
                await this.activeItemCallback();
            }
        });
        this.activeItemNode = undefined;
        this.checkedNodesIds = [];
        this.renderFooter = false;
        this.nodeListFlattenedTreeModel = [];
        this.loading = true;
        this.nodesVersionsViewType = "tree";
        this.nodeVersionsListTreeModel = [];
        this.searchPatternValue = null;
        this.toggleCheckboxes = undefined;
        this.itemsList = [];
        this.activeItemCallback = undefined;
        this.cancelCallback = undefined;
        this.checkboxType = undefined;
        this.expandOnClick = true;
        this.checkedChanged = undefined;
        this.confirmCallback = undefined;
        this.dialogActions = [];
        this.itemContextMenuCallback = undefined;
        this.loadItemsCallback = undefined;
        this.showToggleCheckboxes = true;
        this.multiSelection = false;
        this.singleChecks = false;
        this.showActiveItemLink = false;
        this.useLoader = true;
        this.selectionChanged = undefined;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeSelectKbItems__componentLocale, await locale.Locale.getComponentStrings(this.el), "f");
        this.toggleCheckboxes = this.showToggleCheckboxes;
        __classPrivateFieldSet(this, _GxIdeSelectKbItems_viewItemsAsModel, [
            { value: VIEW_AS_TREE_ID, caption: __classPrivateFieldGet(this, _GxIdeSelectKbItems__componentLocale, "f").main.tree },
            { value: VIEW_AS_LIST_ID, caption: "List" }
        ], "f");
        this.renderFooter =
            this.dialogActions.length > 0 ||
                !!this.cancelCallback ||
                !!this.confirmCallback;
        __classPrivateFieldGet(this, _GxIdeSelectKbItems_instances, "m", _GxIdeSelectKbItems_loadItems).call(this);
    }
    async reloadItems() {
        await __classPrivateFieldGet(this, _GxIdeSelectKbItems_instances, "m", _GxIdeSelectKbItems_loadItems).call(this);
    }
    /**
     * Suspends or reactivates the shortcuts
     */
    async suspendShortcuts(suspendShortcuts) {
        if (suspendShortcuts) {
            __classPrivateFieldGet(this, _GxIdeSelectKbItems_chShortcutsEl, "f").suspend = true;
        }
        else {
            __classPrivateFieldGet(this, _GxIdeSelectKbItems_chShortcutsEl, "f").suspend = false;
        }
    }
    /**
     * Allow to update the selected items
     */
    async updateSelection(selectedItemsIds) {
        // first clear selected
        __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").updateItemsProperties(__classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedNodesIds, "f"), {
            selected: false
        });
        // then select
        __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").updateItemsProperties(selectedItemsIds, {
            selected: true
        });
    }
    /**
     * Allow to update the checked items
     */
    async updateCheckedItems(checkedItemsIds) {
        // first clear checks
        __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").updateItemsProperties(this.checkedNodesIds, {
            checked: false
        });
        // then select
        __classPrivateFieldGet(this, _GxIdeSelectKbItems_treeViewRenderEl, "f").updateItemsProperties(checkedItemsIds, {
            checked: true
        });
        this.checkedNodesIds = checkedItemsIds;
    }
    render() {
        return (index.h(index.Host, { class: { "widget": true, "has-footer": this.renderFooter } }, index.h("ch-theme", { model: CSS_BUNDLES }), index.h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeSelectKbItems_shortcutsSrc, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeSelectKbItems_chShortcutsEl, el, "f")) }), index.h("section", { class: "section" }, index.h("header", { part: "header", class: "header dialog-header field-group spacing-body-block-start spacing-body-inline" }, index.h("div", { class: "header__first-row field-group" }, index.h("div", { class: "field field-inline" }, index.h("span", null, index.h("label", { class: "label", htmlFor: "view-mode" }, "Select view mode:")), index.h("ch-radio-group-render", { class: "radio-group dummy-control-block-size", id: "view-mode", model: __classPrivateFieldGet(this, _GxIdeSelectKbItems_viewItemsAsModel, "f"), onChange: __classPrivateFieldGet(this, _GxIdeSelectKbItems_viewItemsAsChangedHandler, "f"), value: __classPrivateFieldGet(this, _GxIdeSelectKbItems_viewItemsAsModel, "f")[0].value })), this.checkboxType !== "none" && this.showToggleCheckboxes && (index.h("ch-checkbox", { class: "checkbox dummy-control-block-size", caption: "Toggle Checkboxes", id: "toggle-checkboxes", checkedValue: TOGGLE_CHECKBOXES_CHECKED_VALUE, value: TOGGLE_CHECKBOXES_CHECKED_VALUE, onInput: __classPrivateFieldGet(this, _GxIdeSelectKbItems_toggleCheckboxesChangedHandler, "f") }))), index.h("div", { class: {
                "field-group": true,
                "header__second-row": true,
                "header__second-row--one-row": !this.showActiveItemLink
            } }, index.h("ch-edit", { class: "input", placeholder: __classPrivateFieldGet(this, _GxIdeSelectKbItems__componentLocale, "f").header.searchPatternPlaceholder, startImgSrc: SYSTEM_SEARCH_ICON, onInput: __classPrivateFieldGet(this, _GxIdeSelectKbItems_patternSearchValueChangedHandler, "f"), accessibleName: "search pattern" }), this.activeItemNode && this.showActiveItemLink && (index.h("div", { class: "active-item" }, index.h("span", { class: "active-item__icon-container" }, index.h("ch-image", { class: "icon-m active-item__icon", src: this.activeItemNode.iconStart ||
                ACTIVE_ITEM_DEFAULT_ICON, containerRef: null })), __classPrivateFieldGet(this, _GxIdeSelectKbItems__componentLocale, "f").header.activeItem, index.h("button", { class: "active-item__link", onClick: __classPrivateFieldGet(this, _GxIdeSelectKbItems_scrollIntoActiveVersionNode, "f") }, this.activeItemNode.caption))))), index.h("div", { class: "spacing-body-inline-start trees" }, this.useLoader && this.loading ? (index.h("gx-ide-loader", { loaderTitle: __classPrivateFieldGet(this, _GxIdeSelectKbItems__componentLocale, "f").loader.title, description: __classPrivateFieldGet(this, _GxIdeSelectKbItems__componentLocale, "f").loader.description, show: true })) : (index.h("ch-tree-view-render", { class: "tree-view", model: this.nodesVersionsViewType === "tree"
                ? this.nodeVersionsListTreeModel
                : this.nodeListFlattenedTreeModel, "show-lines": this.nodesVersionsViewType === "tree" ? "all" : "none", expandableButton: this.nodesVersionsViewType === "tree" ? "decorative" : "no", onItemContextmenu: __classPrivateFieldGet(this, _GxIdeSelectKbItems_contextMenuHandler, "f"), onCheckedItemsChange: __classPrivateFieldGet(this, _GxIdeSelectKbItems_checkedItemsChangeHandler, "f"), onSelectedItemsChange: __classPrivateFieldGet(this, _GxIdeSelectKbItems_selectedItemsChangeHandler, "f"), expandOnClick: this.expandOnClick, multiSelection: this.multiSelection, filter: this.searchPatternValue, filterType: "caption", toggleCheckboxes: this.toggleCheckboxes, ref: (el) => {
                __classPrivateFieldSet(this, _GxIdeSelectKbItems_treeViewRenderEl, el, "f");
            } }))), this.renderFooter && __classPrivateFieldGet(this, _GxIdeSelectKbItems_renderFooter, "f").call(this))));
    }
    static get assetsDirs() { return ["gx-ide-assets/select-kb-items"]; }
    get el() { return index.getElement(this); }
};
_GxIdeSelectKbItems__componentLocale = new WeakMap(), _GxIdeSelectKbItems_chShortcutsEl = new WeakMap(), _GxIdeSelectKbItems_selectedNodesIds = new WeakMap(), _GxIdeSelectKbItems_shortcutsSrc = new WeakMap(), _GxIdeSelectKbItems_updatedModelList = new WeakMap(), _GxIdeSelectKbItems_viewItemsAsModel = new WeakMap(), _GxIdeSelectKbItems_treeViewRenderEl = new WeakMap(), _GxIdeSelectKbItems_cancelHandler = new WeakMap(), _GxIdeSelectKbItems_checkedItemsChangeHandler = new WeakMap(), _GxIdeSelectKbItems_confirmHandler = new WeakMap(), _GxIdeSelectKbItems_contextMenuHandler = new WeakMap(), _GxIdeSelectKbItems_executeDialogAction = new WeakMap(), _GxIdeSelectKbItems_patternSearchValueChangedHandler = new WeakMap(), _GxIdeSelectKbItems_renderActionButtons = new WeakMap(), _GxIdeSelectKbItems_renderFooter = new WeakMap(), _GxIdeSelectKbItems_selectedItemsChangeHandler = new WeakMap(), _GxIdeSelectKbItems_toggleAndSelectNodesInModelItems = new WeakMap(), _GxIdeSelectKbItems_toggleCheckedNodesInModelItems = new WeakMap(), _GxIdeSelectKbItems_updateViews = new WeakMap(), _GxIdeSelectKbItems_viewItemsAsChangedHandler = new WeakMap(), _GxIdeSelectKbItems_toggleCheckboxesChangedHandler = new WeakMap(), _GxIdeSelectKbItems_scrollIntoActiveVersionNode = new WeakMap(), _GxIdeSelectKbItems_instances = new WeakSet(), _GxIdeSelectKbItems_loadItems = async function _GxIdeSelectKbItems_loadItems() {
    try {
        this.loading = true;
        this.itemsList = await this.loadItemsCallback();
        __classPrivateFieldGet(this, _GxIdeSelectKbItems_updateViews, "f").call(this, this.itemsList);
        // Check and update activeItem
        this.activeItemNode = findFirstActiveNode(this.itemsList);
    }
    catch (error) {
        console.error("Error loading items:", error);
    }
    finally {
        this.loading = false;
    }
};
GxIdeSelectKbItems.style = selectKbItemsCss;

exports.gx_ide_select_kb_items = GxIdeSelectKbItems;

//# sourceMappingURL=gx-ide-select-kb-items.cjs.entry.js.map