import { r as registerInstance, g as getAssetPath, h, H as Host, a as getElement } from './index-b153bfd0.js';
import { c as config } from './config-5a775b7a.js';
import { c as clearControlError, v as validateControls } from './form-validation-21ab3766.js';
import { L as Locale } from './locale-e5107fad.js';

const namePickerCss = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;block-size:100%;grid-template-rows:1fr max-content}.field-group{grid-auto-rows:max-content}.main{overflow:auto}.section{display:contents}.tooltip{position:absolute}";

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 _GxIdeNamePicker_componentLocale, _GxIdeNamePicker_inputValueEl, _GxIdeNamePicker_shortcutsSrc, _GxIdeNamePicker_handleInputValueChange, _GxIdeNamePicker_cancelClickHandler, _GxIdeNamePicker_confirmClickHandler, _GxIdeNamePicker_initializeValidatableControls, _GxIdeNamePicker_evaluateTooltipRender;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/form",
    "utils/spacing",
    "utils/layout",
    "chameleon/scrollbar",
    "components/button",
    "components/edit",
    "components/tooltip"
];
const GxIdeNamePicker = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        /**
         * The component hard-coded strings translations.
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxIdeNamePicker_componentLocale.set(this, void 0);
        _GxIdeNamePicker_inputValueEl.set(this, void 0);
        _GxIdeNamePicker_shortcutsSrc.set(this, getAssetPath(`./gx-ide-assets/name-picker/shortcuts.json`));
        _GxIdeNamePicker_handleInputValueChange.set(this, (event) => {
            this.inputValue = event.detail;
            clearControlError(this.validatableControls, "input-name");
        });
        _GxIdeNamePicker_cancelClickHandler.set(this, async () => {
            this.cancelCallback();
        });
        _GxIdeNamePicker_confirmClickHandler.set(this, async () => {
            const formSubmitResult = await this.confirmCallback(this.inputValue);
            this.validatableControls = validateControls(formSubmitResult, this.validatableControls);
        });
        _GxIdeNamePicker_initializeValidatableControls.set(this, () => {
            // populate validatableControls with the controls that could have errors.
            const validatableControls = [__classPrivateFieldGet(this, _GxIdeNamePicker_inputValueEl, "f")];
            validatableControls.forEach(validatableControl => {
                if (validatableControl.id) {
                    this.validatableControls.set(validatableControl.id, {
                        reference: validatableControl,
                        hasError: false,
                        message: undefined
                    });
                }
            });
        });
        // TODO: evaluate if this should be a global helper function.
        // It is used on other dialogs as well.
        _GxIdeNamePicker_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) && (h("ch-tooltip", { class: "tooltip", actionElement: controlReference, blockAlign: config.tooltipSettings.blockAlign, inlineAlign: config.tooltipSettings.inlineAlign, delay: config.tooltipSettings.delay }, this.validatableControls.get(controlReference.id).message));
        });
        this.inputValue = undefined;
        this.validatableControls = new Map();
        this.cancelCallback = undefined;
        this.confirmCallback = undefined;
        this.defaultInputValue = undefined;
    }
    defaultInputValueChanged(newDefaultInputValue) {
        this.inputValue = newDefaultInputValue;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeNamePicker_componentLocale, await Locale.getComponentStrings(this.el), "f");
        this.defaultInputValueChanged(this.defaultInputValue);
    }
    componentDidLoad() {
        __classPrivateFieldGet(this, _GxIdeNamePicker_initializeValidatableControls, "f").call(this);
    }
    render() {
        const confirmButtonDisabled = !this.inputValue || this.inputValue.length === 0;
        return (h(Host, { class: "widget" }, h("ch-theme", { model: CSS_BUNDLES }), h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeNamePicker_shortcutsSrc, "f") }), h("section", { class: "section" }, h("div", { class: "main scrollable field-group spacing-body" }, h("div", { class: "field field-block" }, h("label", { class: "label", htmlFor: "input-name" }, __classPrivateFieldGet(this, _GxIdeNamePicker_componentLocale, "f").labels.name), h("ch-edit", { type: "text", id: "input-name", class: "input", placeholder: __classPrivateFieldGet(this, _GxIdeNamePicker_componentLocale, "f").placeHolders.name, value: this.inputValue, onInput: __classPrivateFieldGet(this, _GxIdeNamePicker_handleInputValueChange, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeNamePicker_inputValueEl, el, "f")) }), __classPrivateFieldGet(this, _GxIdeNamePicker_evaluateTooltipRender, "f").call(this, __classPrivateFieldGet(this, _GxIdeNamePicker_inputValueEl, "f")))), h("footer", { class: "dialog-footer-with-border spacing-body" }, h("div", { class: "buttons-spacer" }, h("button", { id: "cancel-button", class: "button-secondary", onClick: __classPrivateFieldGet(this, _GxIdeNamePicker_cancelClickHandler, "f") }, __classPrivateFieldGet(this, _GxIdeNamePicker_componentLocale, "f").buttons.cancel), h("button", { id: "confirm-button", class: "button-primary", onClick: __classPrivateFieldGet(this, _GxIdeNamePicker_confirmClickHandler, "f"), disabled: confirmButtonDisabled }, __classPrivateFieldGet(this, _GxIdeNamePicker_componentLocale, "f").buttons.confirm))))));
    }
    static get assetsDirs() { return ["gx-ide-assets/name-picker"]; }
    get el() { return getElement(this); }
    static get watchers() { return {
        "defaultInputValue": ["defaultInputValueChanged"]
    }; }
};
_GxIdeNamePicker_componentLocale = new WeakMap(), _GxIdeNamePicker_inputValueEl = new WeakMap(), _GxIdeNamePicker_shortcutsSrc = new WeakMap(), _GxIdeNamePicker_handleInputValueChange = new WeakMap(), _GxIdeNamePicker_cancelClickHandler = new WeakMap(), _GxIdeNamePicker_confirmClickHandler = new WeakMap(), _GxIdeNamePicker_initializeValidatableControls = new WeakMap(), _GxIdeNamePicker_evaluateTooltipRender = new WeakMap();
GxIdeNamePicker.style = namePickerCss;

export { GxIdeNamePicker as gx_ide_name_picker };

//# sourceMappingURL=gx-ide-name-picker.entry.js.map