'use strict';

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

const index = require('./index-75aef097.js');
const config = require('./config-3bb95f39.js');
const locale = require('./locale-ff30a5f3.js');
const formValidation = require('./form-validation-54acc775.js');

const curlInspectorCss = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;grid-template-rows:max-content 1fr max-content;block-size:100%;overflow:auto}.section{display:contents}.main{display:grid;overflow:auto}.field-group-name-description-module{align-items:center;grid-template-areas:\"name-label name-input\" \"description-label description-input\" \"module-label module-entity-selector\";grid-template-columns:max-content 1fr}.name-label{grid-area:name-label}.name-input{grid-area:name-input}.description-label{grid-area:description-label}.description-input{grid-area:description-input}.module-label{grid-area:module-label}.module-entity-selector{grid-area:module-entity-selector}.tooltip{height:0}";

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 _GxIdeCurlInspector_componentLocale, _GxIdeCurlInspector_chShortcutsEl, _GxIdeCurlInspector_descriptionEl, _GxIdeCurlInspector_moduleEntitySelector, _GxIdeCurlInspector_nameEl, _GxIdeCurlInspector_editorEl, _GxIdeCurlInspector_curlContentChangeHandler, _GxIdeCurlInspector_keydownHandler, _GxIdeCurlInspector_initializeValidatableControls, _GxIdeCurlInspector_evaluateTooltipRender, _GxIdeCurlInspector_validateForm, _GxIdeCurlInspector_handleEditorChange, _GxIdeCurlInspector_handleSlotChange, _GxIdeCurlInspector_createHandler;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/tooltip",
    "utils/form--full",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "chameleon/scrollbar"
];
const GxIdeCurlInspector = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        _GxIdeCurlInspector_componentLocale.set(this, void 0);
        _GxIdeCurlInspector_chShortcutsEl.set(this, void 0);
        _GxIdeCurlInspector_descriptionEl.set(this, void 0);
        _GxIdeCurlInspector_moduleEntitySelector.set(this, void 0);
        _GxIdeCurlInspector_nameEl.set(this, void 0);
        _GxIdeCurlInspector_editorEl.set(this, void 0);
        _GxIdeCurlInspector_curlContentChangeHandler.set(this, void 0);
        _GxIdeCurlInspector_keydownHandler.set(this, void 0);
        _GxIdeCurlInspector_initializeValidatableControls.set(this, () => {
            const validatableControls = [
                __classPrivateFieldGet(this, _GxIdeCurlInspector_nameEl, "f"),
                __classPrivateFieldGet(this, _GxIdeCurlInspector_moduleEntitySelector, "f")
            ];
            validatableControls.forEach(validatableControl => {
                if (validatableControl.id) {
                    this.validatableControls.set(validatableControl.id, {
                        reference: validatableControl,
                        hasError: false,
                        message: undefined
                    });
                }
            });
        });
        _GxIdeCurlInspector_evaluateTooltipRender.set(this, (controlReference) => {
            var _a, _b, _c;
            return ((_b = (_a = this.validatableControls) === null || _a === void 0 ? void 0 : _a.get(controlReference === null || controlReference === void 0 ? void 0 : controlReference.id)) === null || _b === void 0 ? void 0 : _b.hasError) &&
                ((_c = this.validatableControls.get(controlReference.id)) === null || _c === void 0 ? void 0 : _c.message) && (index.h("ch-tooltip", { class: "tooltip", actionElement: controlReference, blockAlign: config.config.tooltipSettings.blockAlign, inlineAlign: config.config.tooltipSettings.inlineAlign, delay: config.config.tooltipSettings.delay }, this.validatableControls.get(controlReference.id).message));
        });
        _GxIdeCurlInspector_validateForm.set(this, () => {
            var _a, _b, _c, _d, _e;
            const name = ((_b = (_a = __classPrivateFieldGet(this, _GxIdeCurlInspector_nameEl, "f")) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.trim()) || "";
            const parentId = ((_d = (_c = __classPrivateFieldGet(this, _GxIdeCurlInspector_moduleEntitySelector, "f")) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.id) || "";
            const curl = ((_e = this.curlContent) === null || _e === void 0 ? void 0 : _e.trim()) || "";
            const isNameValid = this.validateNameCallback
                ? this.validateNameCallback(name)
                : Boolean(name);
            const isParentValid = Boolean(parentId);
            const isCurlValid = Boolean(curl);
            this.isFormValid = isNameValid && isParentValid && isCurlValid;
        });
        _GxIdeCurlInspector_handleEditorChange.set(this, () => {
            if (__classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f")) {
                this.curlContent = __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").text;
                __classPrivateFieldGet(this, _GxIdeCurlInspector_validateForm, "f").call(this);
            }
        });
        _GxIdeCurlInspector_handleSlotChange.set(this, (e) => {
            const elements = e.target.assignedElements();
            if (elements.length) {
                __classPrivateFieldSet(this, _GxIdeCurlInspector_editorEl, elements[0], "f");
                __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").addEventListener("input", __classPrivateFieldGet(this, _GxIdeCurlInspector_handleEditorChange, "f"));
                __classPrivateFieldSet(this, _GxIdeCurlInspector_curlContentChangeHandler, ((event) => {
                    this.curlContent = event.detail.content;
                    __classPrivateFieldGet(this, _GxIdeCurlInspector_handleEditorChange, "f").call(this);
                }), "f");
                __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").addEventListener("curl-content-change", __classPrivateFieldGet(this, _GxIdeCurlInspector_curlContentChangeHandler, "f"));
                __classPrivateFieldSet(this, _GxIdeCurlInspector_keydownHandler, (event) => {
                    if ((event.ctrlKey || event.metaKey) && event.key === "v") {
                        setTimeout(() => {
                            __classPrivateFieldGet(this, _GxIdeCurlInspector_handleEditorChange, "f").call(this);
                        }, 0);
                    }
                }, "f");
                __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").addEventListener("keydown", __classPrivateFieldGet(this, _GxIdeCurlInspector_keydownHandler, "f"));
                this.curlContent = __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").text;
                __classPrivateFieldGet(this, _GxIdeCurlInspector_validateForm, "f").call(this);
            }
        });
        _GxIdeCurlInspector_createHandler.set(this, () => {
            var _a;
            const data = {
                name: __classPrivateFieldGet(this, _GxIdeCurlInspector_nameEl, "f").value,
                description: __classPrivateFieldGet(this, _GxIdeCurlInspector_descriptionEl, "f").value,
                parentId: (_a = __classPrivateFieldGet(this, _GxIdeCurlInspector_moduleEntitySelector, "f").value) === null || _a === void 0 ? void 0 : _a.id,
                curl: this.curlContent
            };
            this.confirmCallback(data).then((formSubmitResult) => {
                this.validatableControls = formValidation.validateControls(formSubmitResult, this.validatableControls);
            });
        });
        this.showTooltipError = false;
        this.isFormValid = false;
        this.curlContent = "";
        this.validatableControls = new Map();
        this.cancelCallback = undefined;
        this.confirmCallback = undefined;
        this.defaultParent = undefined;
        this.parent = undefined;
        this.selectModuleCallback = undefined;
        this.validateNameCallback = undefined;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeCurlInspector_componentLocale, await locale.Locale.getComponentStrings(this.el), "f");
    }
    componentDidLoad() {
        __classPrivateFieldGet(this, _GxIdeCurlInspector_initializeValidatableControls, "f").call(this);
    }
    disconnectedCallback() {
        if (__classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f") && __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").removeEventListener) {
            __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").removeEventListener("input", __classPrivateFieldGet(this, _GxIdeCurlInspector_handleEditorChange, "f"));
            __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").removeEventListener("curl-content-change", __classPrivateFieldGet(this, _GxIdeCurlInspector_curlContentChangeHandler, "f"));
            __classPrivateFieldGet(this, _GxIdeCurlInspector_editorEl, "f").removeEventListener("keydown", __classPrivateFieldGet(this, _GxIdeCurlInspector_keydownHandler, "f"));
        }
    }
    /**
     * Suspends or reactivates the shortcuts
     */
    async suspendShortcuts(suspendShortcuts) {
        __classPrivateFieldGet(this, _GxIdeCurlInspector_chShortcutsEl, "f").suspend = suspendShortcuts;
    }
    render() {
        return (index.h(index.Host, { class: "widget" }, index.h("ch-theme", { model: CSS_BUNDLES }), index.h("ch-shortcuts", { src: "./gx-ide-assets/curl-inspector/shortcuts.json", ref: (el) => (__classPrivateFieldSet(this, _GxIdeCurlInspector_chShortcutsEl, el, "f")) }), index.h("section", { class: "section" }, index.h("header", { class: "header field-group spacing-body dialog-header" }, index.h("div", { class: "field-group field-group-name-description-module" }, index.h("label", { class: "label name-label", htmlFor: "input-name" }, __classPrivateFieldGet(this, _GxIdeCurlInspector_componentLocale, "f").header.nameFieldLabel), index.h("ch-edit", { class: "input name-input", id: "input-name", ref: (el) => (__classPrivateFieldSet(this, _GxIdeCurlInspector_nameEl, el, "f")), onInput: __classPrivateFieldGet(this, _GxIdeCurlInspector_validateForm, "f") }), __classPrivateFieldGet(this, _GxIdeCurlInspector_evaluateTooltipRender, "f").call(this, __classPrivateFieldGet(this, _GxIdeCurlInspector_nameEl, "f")), index.h("label", { class: "label description-label", htmlFor: "input-description" }, __classPrivateFieldGet(this, _GxIdeCurlInspector_componentLocale, "f").header.descriptionFieldLabel), index.h("ch-edit", { class: "input description-input", id: "input-description", ref: (el) => (__classPrivateFieldSet(this, _GxIdeCurlInspector_descriptionEl, el, "f")) }), index.h("label", { class: "label module-label", htmlFor: "input-module" }, __classPrivateFieldGet(this, _GxIdeCurlInspector_componentLocale, "f").header.moduleFolderLabel), index.h("gx-ide-entity-selector", { class: "module module-entity-selector", id: "module", value: this.defaultParent, ref: (el) => (__classPrivateFieldSet(this, _GxIdeCurlInspector_moduleEntitySelector, el, "f")), labelPosition: "none", defaultValue: this.defaultParent, selectEntityCallback: this.selectModuleCallback }), __classPrivateFieldGet(this, _GxIdeCurlInspector_evaluateTooltipRender, "f").call(this, __classPrivateFieldGet(this, _GxIdeCurlInspector_moduleEntitySelector, "f")))), index.h("div", { class: "main field-group scrollable" }, index.h("slot", { name: "CurlTextEditor", onSlotchange: __classPrivateFieldGet(this, _GxIdeCurlInspector_handleSlotChange, "f") })), index.h("footer", { class: "dialog-footer dialog-footer spacing-body-block-end spacing-body-inline" }, index.h("div", { class: "buttons-spacer" }, index.h("button", { class: "button-secondary", id: "button-cancel", onClick: this.cancelCallback, part: "button-cancel" }, __classPrivateFieldGet(this, _GxIdeCurlInspector_componentLocale, "f").footer.btnCancel), index.h("button", { class: "button-primary", id: "button-ok", onClick: __classPrivateFieldGet(this, _GxIdeCurlInspector_createHandler, "f"), part: "button-ok", disabled: !this.isFormValid }, __classPrivateFieldGet(this, _GxIdeCurlInspector_componentLocale, "f").footer.btnCreate))))));
    }
    static get assetsDirs() { return ["gx-ide-assets/curl-inspector"]; }
    get el() { return index.getElement(this); }
};
_GxIdeCurlInspector_componentLocale = new WeakMap(), _GxIdeCurlInspector_chShortcutsEl = new WeakMap(), _GxIdeCurlInspector_descriptionEl = new WeakMap(), _GxIdeCurlInspector_moduleEntitySelector = new WeakMap(), _GxIdeCurlInspector_nameEl = new WeakMap(), _GxIdeCurlInspector_editorEl = new WeakMap(), _GxIdeCurlInspector_curlContentChangeHandler = new WeakMap(), _GxIdeCurlInspector_keydownHandler = new WeakMap(), _GxIdeCurlInspector_initializeValidatableControls = new WeakMap(), _GxIdeCurlInspector_evaluateTooltipRender = new WeakMap(), _GxIdeCurlInspector_validateForm = new WeakMap(), _GxIdeCurlInspector_handleEditorChange = new WeakMap(), _GxIdeCurlInspector_handleSlotChange = new WeakMap(), _GxIdeCurlInspector_createHandler = new WeakMap();
GxIdeCurlInspector.style = curlInspectorCss;

exports.gx_ide_curl_inspector = GxIdeCurlInspector;

//# sourceMappingURL=gx-ide-curl-inspector.cjs.entry.js.map