'use strict';

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

const index = require('./index-75aef097.js');
const locale = require('./locale-ff30a5f3.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 convertActionToTreeViewItem = (operations) => {
    const treeData = [];
    if (!operations) {
        return treeData;
    }
    operations.forEach(operation => {
        const importCategoryTreeItem = {
            id: operation.id,
            caption: `${operation.name}`,
            expanded: true,
            leaf: true,
            checkbox: true
        };
        treeData.push(importCategoryTreeItem);
    });
    return treeData;
};

const openApiImportCss = "button.button-secondary{border-color:var(--color-border-neutral-default)}section{display:grid;block-size:100%;grid-template-rows:max-content 1fr max-content}.main{position:relative;display:contents}.input-file{display:flex}.field{width:100%}.dialog-header__operations,.dialog-header__description{padding-block-start:16px}.header__field-group{grid-template:\"import-file-label import-file-name buttons-container\" max-content \"module-folder-label module-folder module-folder\" max-content/max-content 1fr max-content}.module-folder-name{grid-area:module-folder}.module-folder-label{grid-area:module-folder-label}.import-file-label{grid-area:import-file-label}.header__buttons-container{grid-area:buttons-container}.section-grid{display:grid;grid-template:\"top-content-operations top-content-description\" max-content \"operations-area operations-description\" 1fr/1fr 1fr;background-color:var(--items-container__bg-color);border-style:var(--items-container__border-style);border-width:var(--items-container__border-width);border-color:var(--items-container__border-color);border-block-start:0;overflow-y:auto}.list-wrapper{grid-area:operations-area;border-inline-end:var(--section-common-border)}.label{margin-block-start:8px !important}.tree-operations::part(item__header){padding-inline-start:0}.procedure-description{grid-area:operations-description;overflow:auto;text-align:justify}.dialog-header__operations{grid-area:top-content-operations;background-color:var(--items-container__bg-color)}.dialog-header__description{grid-area:top-content-description;background-color:var(--items-container__bg-color)}.text-align-center{text-align:center}";

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 _GxIdeOpenAPIImport__componentLocale, _GxIdeOpenAPIImport_renderedFirstTime, _GxIdeOpenAPIImport_shortcutsSrc, _GxIdeOpenAPIImport_chShortcutsEl, _GxIdeOpenAPIImport_fileInputHiddenEl, _GxIdeOpenAPIImport_parentEl, _GxIdeOpenAPIImport_objectsTreeEl, _GxIdeOpenAPIImport_cancelImportHandler, _GxIdeOpenAPIImport_handleImport, _GxIdeOpenAPIImport_objectsTreeCheckedItemsChangedHandler, _GxIdeOpenAPIImport_handleSelectAll, _GxIdeOpenAPIImport_objectTreeClickedHandler, _GxIdeOpenAPIImport_removeFileSelection, _GxIdeOpenAPIImport_selectFileInputChangedHandler, _GxIdeOpenAPIImport_selectFileInputHandler, _GxIdeOpenAPIImport_renderFooter;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/button",
    "components/checkbox",
    "components/edit",
    "components/icon",
    "components/tree-view",
    "components/list-box",
    "utils/form",
    "utils/layout",
    "utils/spacing",
    "utils/typography"
];
const FILE_ICON = assetsManager.getIconPath({
    category: "gemini-tools",
    name: "file",
    colorType: "on-surface"
});
const MENU_DELETE = assetsManager.getIconPath({
    category: "menus",
    name: "delete",
    colorType: "primary"
});
const CHECKBOX_ALL_CHECKED_VALUE = "allChecked";
const CHECKBOX_ALL_UNCHECKED_VALUE = "allUnchecked";
const GxIdeOpenAPIImport = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.componentDidRenderFirstTime = index.createEvent(this, "componentDidRenderFirstTime", 7);
        _GxIdeOpenAPIImport__componentLocale.set(this, void 0);
        _GxIdeOpenAPIImport_renderedFirstTime.set(this, false);
        _GxIdeOpenAPIImport_shortcutsSrc.set(this, index.getAssetPath(`./gx-ide-assets/new-object/shortcuts.json`));
        _GxIdeOpenAPIImport_chShortcutsEl.set(this, void 0);
        _GxIdeOpenAPIImport_fileInputHiddenEl.set(this, void 0);
        _GxIdeOpenAPIImport_parentEl.set(this, void 0);
        _GxIdeOpenAPIImport_objectsTreeEl.set(this, void 0);
        // 9.LOCAL METHODS //
        _GxIdeOpenAPIImport_cancelImportHandler.set(this, () => {
            if (this.cancelCallback) {
                this.cancelCallback();
            }
        });
        _GxIdeOpenAPIImport_handleImport.set(this, async () => {
            await this.importCallback(this.selectedOperations);
        });
        _GxIdeOpenAPIImport_objectsTreeCheckedItemsChangedHandler.set(this, (event) => {
            if (event.detail.size === 0) {
                return;
            }
            const allItems = event.detail;
            const checkedItems = [...allItems.values()].filter(node => node.item.checked);
            this.selectedOperations = checkedItems.map(item => item.item.id);
            // Evaluate "Select All" checkbox state (siguiendo el patrón de kb-manager-import)
            if (allItems.size === checkedItems.length) {
                this.selectAllCheckboxValue = CHECKBOX_ALL_CHECKED_VALUE;
                this.selectAllCheckboxIndeterminate = false;
            }
            else if (checkedItems.length === 0) {
                this.selectAllCheckboxValue = CHECKBOX_ALL_UNCHECKED_VALUE;
                this.selectAllCheckboxIndeterminate = false;
            }
            else {
                this.selectAllCheckboxIndeterminate = true;
            }
        });
        _GxIdeOpenAPIImport_handleSelectAll.set(this, (event) => {
            if ("detail" in event && __classPrivateFieldGet(this, _GxIdeOpenAPIImport_objectsTreeEl, "f")) {
                const checked = event.detail ===
                    CHECKBOX_ALL_CHECKED_VALUE;
                // Usar updateAllItemsProperties como en kb-manager-import
                __classPrivateFieldGet(this, _GxIdeOpenAPIImport_objectsTreeEl, "f").updateAllItemsProperties({ checked: checked });
                this.selectedOperations = checked ? this.operations.map(op => op.id) : [];
                this.selectAllCheckboxValue = checked
                    ? CHECKBOX_ALL_CHECKED_VALUE
                    : CHECKBOX_ALL_UNCHECKED_VALUE;
                this.selectAllCheckboxIndeterminate = false;
            }
        });
        _GxIdeOpenAPIImport_objectTreeClickedHandler.set(this, (event) => {
            var _a;
            this.selectedOperationForDescription = (_a = this.operations.filter(op => { var _a; return op.id === ((_a = event.detail[0]) === null || _a === void 0 ? void 0 : _a.item.id); })[0]) === null || _a === void 0 ? void 0 : _a.description;
        });
        _GxIdeOpenAPIImport_removeFileSelection.set(this, () => {
            this.selectedFile = null;
            __classPrivateFieldGet(this, _GxIdeOpenAPIImport_fileInputHiddenEl, "f").value = null;
            this.operations = [];
            this.actionListItems = [];
            this.selectedOperationForDescription = null;
        });
        _GxIdeOpenAPIImport_selectFileInputChangedHandler.set(this, async (event) => {
            var _a;
            const target = event.target;
            if (((_a = target.files) === null || _a === void 0 ? void 0 : _a.length) > 0) {
                this.selectedFile = target.files[0];
                this.operations = await this.loadCallback(this.selectedFile, __classPrivateFieldGet(this, _GxIdeOpenAPIImport_parentEl, "f").value.id);
                this.actionListItems = convertActionToTreeViewItem(this.operations);
            }
        });
        _GxIdeOpenAPIImport_selectFileInputHandler.set(this, () => {
            __classPrivateFieldGet(this, _GxIdeOpenAPIImport_fileInputHiddenEl, "f").click();
        });
        _GxIdeOpenAPIImport_renderFooter.set(this, () => {
            var _a;
            return (index.h("footer", { class: "dialog-footer dialog-footer-space-between spacing-body-block-end spacing-body-inline" }, index.h("div", { class: "buttons-spacer" }, index.h("ch-checkbox", { id: "select-all-checkbox", class: "checkbox", checkedValue: CHECKBOX_ALL_CHECKED_VALUE, unCheckedValue: CHECKBOX_ALL_UNCHECKED_VALUE, caption: __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").main.selectAll, value: this.selectAllCheckboxValue, indeterminate: this.selectAllCheckboxIndeterminate, onInput: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_handleSelectAll, "f"), disabled: this.importingIsInProcess || !((_a = this.operations) === null || _a === void 0 ? void 0 : _a.length), part: "select-all-checkbox" })), index.h("div", { class: "buttons-spacer" }, index.h("button", { class: "button-secondary", slot: "footer-end", part: "button-cancel", onClick: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_cancelImportHandler, "f") }, __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").footer.cancel), index.h("button", { class: "button-primary", slot: "footer-end", part: "button-confirm", onClick: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_handleImport, "f") }, __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").footer.import))));
        });
        this.actionListItems = [];
        this.importingIsInProcess = false;
        this.operations = [];
        this.selectedFile = undefined;
        this.selectedOperationForDescription = undefined;
        this.selectedOperations = [];
        this.selectAllCheckboxValue = undefined;
        this.selectAllCheckboxIndeterminate = false;
        this.defaultParent = undefined;
        this.displayTitle = false;
        this.cancelCallback = undefined;
        this.importCallback = undefined;
        this.loadCallback = undefined;
        this.selectParentCallback = undefined;
    }
    componentDidRender() {
        if (!__classPrivateFieldGet(this, _GxIdeOpenAPIImport_renderedFirstTime, "f")) {
            this.componentDidRenderFirstTime.emit(__classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").componentName);
            __classPrivateFieldSet(this, _GxIdeOpenAPIImport_renderedFirstTime, true, "f");
        }
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeOpenAPIImport__componentLocale, await locale.Locale.getComponentStrings(this.el), "f");
    }
    /**
     * Suspends or reactivates the shortcuts
     */
    async suspendShortcuts(suspendShortcuts) {
        if (suspendShortcuts) {
            __classPrivateFieldGet(this, _GxIdeOpenAPIImport_chShortcutsEl, "f").suspend = true;
        }
        else {
            __classPrivateFieldGet(this, _GxIdeOpenAPIImport_chShortcutsEl, "f").suspend = false;
        }
    }
    render() {
        var _a;
        return (index.h(index.Host, { class: "widget" }, index.h("ch-theme", { model: CSS_BUNDLES }), index.h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_shortcutsSrc, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeOpenAPIImport_chShortcutsEl, el, "f")) }), index.h("section", null, index.h("header", { class: "header dialog-header-with-border space-body spacing-body-inline spacing-body-block-start", role: "banner" }, index.h("div", { class: "field-group header__field-group" }, index.h("div", { class: "import-file-label" }, index.h("div", { class: "field field-block" }, index.h("label", { class: "label", htmlFor: "file-name" }, __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").header.fileNameLabel))), index.h("div", { class: "input-file" }, index.h("div", { class: "field input-file" }, index.h("ch-edit", { autoFocus: true, id: "file-name", class: "input file", part: "file-name", type: "text", readonly: true, value: (_a = this.selectedFile) === null || _a === void 0 ? void 0 : _a.name, placeholder: __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").header.fileNamePlaceholder, startImgSrc: FILE_ICON }), index.h("input", { hidden: true, type: "file", accept: ".json, .yaml", onChange: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_selectFileInputChangedHandler, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeOpenAPIImport_fileInputHiddenEl, el, "f")) })), index.h("div", { class: "cancel-btn " }, index.h("button", { "aria-label": __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").header.removeFileSelection, title: __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").header.removeFileSelection, id: "reset-all-button", class: "button-tertiary button-icon-only", part: "reset-all-button", onClick: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_removeFileSelection, "f") }, index.h("ch-image", { class: "icon-m", src: MENU_DELETE })))), index.h("div", { class: "header__buttons-container" }, index.h("button", { id: "select-file-load-button", class: "button-primary", part: "select-file-load-button", onClick: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_selectFileInputHandler, "f"), disabled: this.importingIsInProcess }, __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").header.selectFileButton)), index.h("div", { class: "module-folder-label" }, index.h("div", { class: "field field-block" }, index.h("label", { class: "label" }, __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").header.moduleFolderLabel))), index.h("div", { class: "field module-folder-name " }, index.h("gx-ide-entity-selector", { value: this.defaultParent, defaultValue: this.defaultParent, selectEntityCallback: this.selectParentCallback, labelPosition: "none", ref: (el) => (__classPrivateFieldSet(this, _GxIdeOpenAPIImport_parentEl, el, "f")), class: "module-folder" })))), index.h("main", { class: "main" }, index.h("div", { class: "section-grid" }, index.h("h2", { id: "operations-title", class: "dialog-header dialog-header-with-border dialog-header__operations subtitle-regular-xs text-align-center spacing-body-inline" }, __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").main.operations), index.h("div", { class: "list-wrapper field-group spacing-body-block-start spacing-body-inline scrollable", role: "region", "aria-labelledby": "operations-title" }, index.h("ch-tree-view-render", { class: "tree-view tree-operations", model: this.actionListItems, "show-lines": "last", onCheckedItemsChange: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_objectsTreeCheckedItemsChangedHandler, "f"), onSelectedItemsChange: __classPrivateFieldGet(this, _GxIdeOpenAPIImport_objectTreeClickedHandler, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeOpenAPIImport_objectsTreeEl, el, "f")) })), index.h("h2", { id: "description-title", class: "dialog-header dialog-header-with-border dialog-header__description subtitle-regular-xs text-align-center spacing-body-inline" }, __classPrivateFieldGet(this, _GxIdeOpenAPIImport__componentLocale, "f").main.procedureDescription), index.h("div", { class: "procedure-description field-group spacing-body-block-start spacing-body-inline scrollable", role: "region", "aria-labelledby": "description-title" }, this.selectedOperationForDescription))), __classPrivateFieldGet(this, _GxIdeOpenAPIImport_renderFooter, "f").call(this))));
    }
    static get assetsDirs() { return ["gx-ide-assets/open-api-import"]; }
    get el() { return index.getElement(this); }
};
_GxIdeOpenAPIImport__componentLocale = new WeakMap(), _GxIdeOpenAPIImport_renderedFirstTime = new WeakMap(), _GxIdeOpenAPIImport_shortcutsSrc = new WeakMap(), _GxIdeOpenAPIImport_chShortcutsEl = new WeakMap(), _GxIdeOpenAPIImport_fileInputHiddenEl = new WeakMap(), _GxIdeOpenAPIImport_parentEl = new WeakMap(), _GxIdeOpenAPIImport_objectsTreeEl = new WeakMap(), _GxIdeOpenAPIImport_cancelImportHandler = new WeakMap(), _GxIdeOpenAPIImport_handleImport = new WeakMap(), _GxIdeOpenAPIImport_objectsTreeCheckedItemsChangedHandler = new WeakMap(), _GxIdeOpenAPIImport_handleSelectAll = new WeakMap(), _GxIdeOpenAPIImport_objectTreeClickedHandler = new WeakMap(), _GxIdeOpenAPIImport_removeFileSelection = new WeakMap(), _GxIdeOpenAPIImport_selectFileInputChangedHandler = new WeakMap(), _GxIdeOpenAPIImport_selectFileInputHandler = new WeakMap(), _GxIdeOpenAPIImport_renderFooter = new WeakMap();
GxIdeOpenAPIImport.style = openApiImportCss;

exports.gx_ide_open_api_import = GxIdeOpenAPIImport;

//# sourceMappingURL=gx-ide-open-api-import.cjs.entry.js.map