var __classPrivateFieldGet = (this && this.__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 = (this && this.__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;
import { Host, h, getAssetPath, Fragment } from "@stencil/core";
import { Locale } from "../../../common/locale";
import { getIconPath } from "@genexus/mercury";
import { mapTypesToComboboxItemModel } from "./helpers";
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"
});
export class GxIdeEditModuleServer {
    constructor() {
        _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
                    };
                }
                const result = await this.confirmCallback(data);
                if (result.success) {
                    // display success message
                }
                else {
                    // display error message
                }
            }
        });
        _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 is() { return "gx-ide-edit-module-server"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["edit-module-server.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["edit-module-server.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/edit-module-server"]; }
    static get properties() {
        return {
            "cancelCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "CancelCallback",
                    "resolved": "() => Promise<void>",
                    "references": {
                        "CancelCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/modules/edit-module-server/edit-module-server.tsx",
                            "id": "src/components/modules/edit-module-server/edit-module-server.tsx::CancelCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Cancel callback"
                }
            },
            "confirmCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ConfirmCallback",
                    "resolved": "(data: ModuleServerFullData) => Promise<EditServerModuleResult>",
                    "references": {
                        "ConfirmCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/modules/edit-module-server/edit-module-server.tsx",
                            "id": "src/components/modules/edit-module-server/edit-module-server.tsx::ConfirmCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Confirm callback"
                }
            },
            "name": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The name of the server"
                },
                "attribute": "name",
                "reflect": false
            },
            "selectSourceCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "SelectSourceCallback",
                    "resolved": "() => Promise<string>",
                    "references": {
                        "SelectSourceCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/modules/edit-module-server/edit-module-server.tsx",
                            "id": "src/components/modules/edit-module-server/edit-module-server.tsx::SelectSourceCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when wants to select a local folder that have modules inside"
                }
            },
            "source": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Disk path or server url"
                },
                "attribute": "source",
                "reflect": false
            },
            "type": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Id of the currently selected server type"
                },
                "attribute": "type",
                "reflect": false
            },
            "types": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ModuleServerType[]",
                    "resolved": "ModuleServerType[]",
                    "references": {
                        "ModuleServerType": {
                            "location": "import",
                            "path": "../types",
                            "id": "src/components/modules/types.ts::ModuleServerType"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The type of the server"
                }
            }
        };
    }
    static get states() {
        return {
            "selectedType": {}
        };
    }
    static get events() {
        return [{
                "method": "componentDidRenderFirstTime",
                "name": "componentDidRenderFirstTime",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "This event is emitted once just after the component is fully loaded and the first render() occurs"
                },
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                }
            }];
    }
    static get methods() {
        return {
            "suspendShortcuts": {
                "complexType": {
                    "signature": "(suspendShortcuts: boolean) => Promise<void>",
                    "parameters": [{
                            "name": "suspendShortcuts",
                            "type": "boolean",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Suspends or reactivates the shortcuts",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
}
_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();
//# sourceMappingURL=edit-module-server.js.map
