import { proxyCustomElement, HTMLElement, createEvent, getAssetPath, h, Fragment, Host } from '@stencil/core/internal/client';
import { L as Locale } from './locale.js';
import { g as getIconPath } from './mer-animated-dots.js';
import 'lit';
import 'lit/directives/when.js';
import 'lit/directives/if-defined.js';

const mapTypesToComboboxItemModel = (types) => {
    if (!types || !Array.isArray(types)) {
        return [];
    }
    const typesComboBoxItemModel = [];
    types.forEach(type => {
        const typeObject = {
            value: type.type,
            caption: type.type
        };
        typesComboBoxItemModel.push(typeObject);
    });
    return typesComboBoxItemModel;
};

const editModuleServerCss = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;grid-template-rows:1fr max-content;overflow:auto}.section{display:contents}.main{grid-auto-rows:max-content}.source-container{display:grid;grid-template-columns:1fr max-content;gap:var(--spacing-gap-m)}.footer{margin-block-start:16px}";

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 _GxIdeEditModuleServer__componentLocale, _GxIdeEditModuleServer_renderedFirstTime, _GxIdeEditModuleServer_serverTypesModel, _GxIdeEditModuleServer_shortcutsSrc, _GxIdeEditModuleServer_chShortcutsEl, _GxIdeEditModuleServer_nameEl, _GxIdeEditModuleServer_passwordEl, _GxIdeEditModuleServer_serverTypeEl, _GxIdeEditModuleServer_sourceEl, _GxIdeEditModuleServer_userEl, _GxIdeEditModuleServer_cancelCallbackHandler, _GxIdeEditModuleServer_confirmCallbackHandler, _GxIdeEditModuleServer_handleServerTypeChange, _GxIdeEditModuleServer_renderFooter, _GxIdeEditModuleServer_renderServerOptions, _GxIdeEditModuleServer_selectSourceCallbackHandle;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/form--full",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "chameleon/scrollbar"
];
const MORE_ICON = getIconPath({
    category: "gemini-tools",
    name: "show-more-horizontal",
    colorType: "on-surface"
});
const GxIdeEditModuleServer$1 = /*@__PURE__*/ proxyCustomElement(class GxIdeEditModuleServer extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.componentDidRenderFirstTime = createEvent(this, "componentDidRenderFirstTime", 7);
        _GxIdeEditModuleServer__componentLocale.set(this, void 0);
        _GxIdeEditModuleServer_renderedFirstTime.set(this, false);
        _GxIdeEditModuleServer_serverTypesModel.set(this, []);
        _GxIdeEditModuleServer_shortcutsSrc.set(this, getAssetPath(`./gx-ide-assets/edit-module-server/shortcuts.json`));
        _GxIdeEditModuleServer_chShortcutsEl.set(this, void 0);
        _GxIdeEditModuleServer_nameEl.set(this, void 0);
        _GxIdeEditModuleServer_passwordEl.set(this, void 0);
        _GxIdeEditModuleServer_serverTypeEl.set(this, void 0);
        _GxIdeEditModuleServer_sourceEl.set(this, void 0);
        _GxIdeEditModuleServer_userEl.set(this, void 0);
        _GxIdeEditModuleServer_cancelCallbackHandler.set(this, async () => {
            await this.cancelCallback();
        });
        _GxIdeEditModuleServer_confirmCallbackHandler.set(this, async () => {
            if (this.confirmCallback) {
                const selectedTypeId = this.types.find(({ type }) => type === this.selectedType);
                let data = {};
                if (selectedTypeId.type === "remote") {
                    data = {
                        id: selectedTypeId.id,
                        name: __classPrivateFieldGet(this, _GxIdeEditModuleServer_nameEl, "f").value,
                        type: __classPrivateFieldGet(this, _GxIdeEditModuleServer_serverTypeEl, "f").value,
                        authenticated: selectedTypeId.authenticated,
                        source: __classPrivateFieldGet(this, _GxIdeEditModuleServer_sourceEl, "f").value,
                        user: __classPrivateFieldGet(this, _GxIdeEditModuleServer_userEl, "f").value,
                        password: __classPrivateFieldGet(this, _GxIdeEditModuleServer_passwordEl, "f").value
                    };
                }
                else {
                    data = {
                        id: selectedTypeId.id,
                        name: __classPrivateFieldGet(this, _GxIdeEditModuleServer_nameEl, "f").value,
                        type: __classPrivateFieldGet(this, _GxIdeEditModuleServer_serverTypeEl, "f").value,
                        authenticated: selectedTypeId.authenticated,
                        source: __classPrivateFieldGet(this, _GxIdeEditModuleServer_sourceEl, "f").value
                    };
                }
                await this.confirmCallback(data);
            }
        });
        _GxIdeEditModuleServer_handleServerTypeChange.set(this, (e) => {
            this.selectedType = e.detail;
        });
        _GxIdeEditModuleServer_renderFooter.set(this, () => {
            return (h("footer", { class: "footer dialog-footer dialog-footer-with-border spacing-body-block-end spacing-body-inline" }, h("div", { class: "buttons-spacer" }, h("button", { class: "button-secondary", id: "button-cancel", onClick: __classPrivateFieldGet(this, _GxIdeEditModuleServer_cancelCallbackHandler, "f"), part: "button-cancel" }, __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").footer.btnCancel), h("button", { class: "button-primary", id: "button-create", onClick: __classPrivateFieldGet(this, _GxIdeEditModuleServer_confirmCallbackHandler, "f"), part: "button-create" }, __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").footer.btnConfirm))));
        });
        _GxIdeEditModuleServer_renderServerOptions.set(this, () => {
            return (h(Fragment, null, h("label", { class: "label", htmlFor: "user" }, __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").user), h("ch-edit", { id: "user", part: "user", class: "input", placeholder: __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").user, ref: (el) => (__classPrivateFieldSet(this, _GxIdeEditModuleServer_userEl, el, "f")) }), h("label", { class: "label", htmlFor: "password" }, __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").password), h("ch-edit", { id: "password", part: "password", class: "input", placeholder: __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").password, ref: (el) => (__classPrivateFieldSet(this, _GxIdeEditModuleServer_passwordEl, el, "f")) })));
        });
        _GxIdeEditModuleServer_selectSourceCallbackHandle.set(this, async () => {
            if (this.selectSourceCallback) {
                const path = await this.selectSourceCallback();
                if (path) {
                    __classPrivateFieldGet(this, _GxIdeEditModuleServer_sourceEl, "f").value = path;
                }
            }
        });
        this.selectedType = "local";
        this.cancelCallback = undefined;
        this.confirmCallback = undefined;
        this.name = undefined;
        this.selectSourceCallback = undefined;
        this.source = undefined;
        this.type = undefined;
        this.types = undefined;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeEditModuleServer__componentLocale, await Locale.getComponentStrings(this.el), "f");
        __classPrivateFieldSet(this, _GxIdeEditModuleServer_serverTypesModel, mapTypesToComboboxItemModel(this.types), "f");
        if (this.types && this.types.length > 0) {
            this.selectedType = this.types[0].type;
        }
    }
    componentDidRender() {
        if (!__classPrivateFieldGet(this, _GxIdeEditModuleServer_renderedFirstTime, "f")) {
            this.componentDidRenderFirstTime.emit(__classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").componentName);
            __classPrivateFieldSet(this, _GxIdeEditModuleServer_renderedFirstTime, true, "f");
        }
    }
    /**
     * Suspends or reactivates the shortcuts
     */
    async suspendShortcuts(suspendShortcuts) {
        if (suspendShortcuts) {
            __classPrivateFieldGet(this, _GxIdeEditModuleServer_chShortcutsEl, "f").suspend = true;
        }
        else {
            __classPrivateFieldGet(this, _GxIdeEditModuleServer_chShortcutsEl, "f").suspend = false;
        }
    }
    render() {
        const renderLocalSourceButton = this.selectedType === "local";
        const sourceChEdit = (h("ch-edit", { placeholder: __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").source, ref: (el) => (__classPrivateFieldSet(this, _GxIdeEditModuleServer_sourceEl, el, "f")), value: this.source, class: "input", part: "source", id: "source" }));
        const sourceButton = (h("button", { class: "button-tertiary button-icon-only", "aria-label": "caption", onClick: __classPrivateFieldGet(this, _GxIdeEditModuleServer_selectSourceCallbackHandle, "f") }, h("ch-image", { class: "icon-m", src: MORE_ICON })));
        return (h(Host, { class: "widget" }, h("ch-theme", { model: CSS_BUNDLES }), h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeEditModuleServer_shortcutsSrc, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeEditModuleServer_chShortcutsEl, el, "f")) }), h("section", { class: "section" }, h("main", { class: "main field-group-justified-start" }, h("label", { class: "label", htmlFor: "server-type" }, __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").type), h("ch-combo-box-render", { accessibleName: "server types", id: "server-type", part: "server-type", class: "combo-box", model: __classPrivateFieldGet(this, _GxIdeEditModuleServer_serverTypesModel, "f"), value: this.selectedType, onChange: __classPrivateFieldGet(this, _GxIdeEditModuleServer_handleServerTypeChange, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeEditModuleServer_serverTypeEl, el, "f")) }), h("label", { class: "label", htmlFor: "name" }, __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").name), h("ch-edit", { placeholder: __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").name, ref: (el) => (__classPrivateFieldSet(this, _GxIdeEditModuleServer_nameEl, el, "f")), value: this.name, part: "name", class: "input", id: "name" }), h("label", { class: "label", htmlFor: "source" }, __classPrivateFieldGet(this, _GxIdeEditModuleServer__componentLocale, "f").source), renderLocalSourceButton ? (h("div", { class: "source-container" }, [sourceChEdit, sourceButton])) : (sourceChEdit), this.selectedType === "remote" && __classPrivateFieldGet(this, _GxIdeEditModuleServer_renderServerOptions, "f").call(this)), __classPrivateFieldGet(this, _GxIdeEditModuleServer_renderFooter, "f").call(this))));
    }
    static get assetsDirs() { return ["gx-ide-assets/edit-module-server"]; }
    get el() { return this; }
    static get style() { return editModuleServerCss; }
}, [1, "gx-ide-edit-module-server", {
        "cancelCallback": [16],
        "confirmCallback": [16],
        "name": [1],
        "selectSourceCallback": [16],
        "source": [1],
        "type": [1],
        "types": [16],
        "selectedType": [32],
        "suspendShortcuts": [64]
    }]);
_GxIdeEditModuleServer__componentLocale = new WeakMap(), _GxIdeEditModuleServer_renderedFirstTime = new WeakMap(), _GxIdeEditModuleServer_serverTypesModel = new WeakMap(), _GxIdeEditModuleServer_shortcutsSrc = new WeakMap(), _GxIdeEditModuleServer_chShortcutsEl = new WeakMap(), _GxIdeEditModuleServer_nameEl = new WeakMap(), _GxIdeEditModuleServer_passwordEl = new WeakMap(), _GxIdeEditModuleServer_serverTypeEl = new WeakMap(), _GxIdeEditModuleServer_sourceEl = new WeakMap(), _GxIdeEditModuleServer_userEl = new WeakMap(), _GxIdeEditModuleServer_cancelCallbackHandler = new WeakMap(), _GxIdeEditModuleServer_confirmCallbackHandler = new WeakMap(), _GxIdeEditModuleServer_handleServerTypeChange = new WeakMap(), _GxIdeEditModuleServer_renderFooter = new WeakMap(), _GxIdeEditModuleServer_renderServerOptions = new WeakMap(), _GxIdeEditModuleServer_selectSourceCallbackHandle = new WeakMap();
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-edit-module-server"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-edit-module-server":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeEditModuleServer$1);
            }
            break;
    } });
}

const GxIdeEditModuleServer = GxIdeEditModuleServer$1;
const defineCustomElement = defineCustomElement$1;

export { GxIdeEditModuleServer, defineCustomElement };

//# sourceMappingURL=gx-ide-edit-module-server.js.map