import { r as registerInstance, c as createEvent, h, H as Host, a as getElement } from './index-b153bfd0.js';
import { g as getIconPath } from './assets-manager-7d6fc08f.js';
import './mer-animated-dots-7cbae6ef.js';
import 'lit';
import 'lit/directives/when.js';
import 'lit/directives/if-defined.js';
import { L as Locale } from './locale-e5107fad.js';

const entitySelectorCss = ".wrapper{display:grid;grid-template-columns:1fr max-content max-content;gap:var(--spacing-gap-m);border-radius:var(--control-border-radius);border:var(--control-border-width) solid var(--control-border-color);padding-block:var(--control-padding-block);padding-inline:var(--control-padding-inline)}.wrapper:hover{border-color:var(--control-border-color-hover)}.input{--control-border-width:0;--control-padding-block:0;--control-padding-inline:0;--focus-outline-width:0;--focus-outline:none;outline:none !important}:host(:focus-within) .wrapper{--focus-outline-width:2px;outline:var(--focus-outline-width) solid var(--color-border-primary-focused);outline-offset:calc(2px * -1)}:host(.entity-selector--button-has-focus) .wrapper{outline:none}:host([disabled]){pointer-events:none}:host([disabled]) .wrapper{background-color:var(--color-accent-neutral-disabled);border-color:var(--color-border-neutral-disabled)}";

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 _GxIdeEntitySelector_componentLocale, _GxIdeEntitySelector_btnClearClickHandler, _GxIdeEntitySelector_btnSelectClickHandler, _GxIdeEntitySelector_buttonFocusHandler, _GxIdeEntitySelector_renderControl, _GxIdeEntitySelector_updateIconSrc;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/edit",
    "components/button",
    "components/icon",
    "utils/form"
];
const SELECT_DEFAULT_ICON = getIconPath({
    category: "gemini-tools",
    name: "show-more-horizontal",
    colorType: "primary"
});
const CLEAR_ICON = getIconPath({
    category: "gemini-tools",
    name: "reset",
    colorType: "primary"
});
const GxIdeEntitySelector = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.valueChanged = createEvent(this, "valueChanged", 7);
        _GxIdeEntitySelector_componentLocale.set(this, void 0);
        _GxIdeEntitySelector_btnClearClickHandler.set(this, () => {
            var _a;
            this.value = this.defaultValue;
            this.iconSrc = (_a = this.defaultValue) === null || _a === void 0 ? void 0 : _a.iconSrc;
        });
        _GxIdeEntitySelector_btnSelectClickHandler.set(this, () => {
            this.selectEntityCallback().then(result => {
                if (result) {
                    this.value = result;
                }
            });
        });
        _GxIdeEntitySelector_buttonFocusHandler.set(this, (e) => {
            if (e.type === "focus") {
                this.buttonHasFocus = true;
            }
            else if (e.type === "blur") {
                this.buttonHasFocus = false;
            }
        });
        _GxIdeEntitySelector_renderControl.set(this, () => {
            var _a, _b;
            return (h("div", { part: "wrapper", class: "wrapper" }, h("ch-edit", { accessibleName: this.labelPosition === "none" &&
                    __classPrivateFieldGet(this, _GxIdeEntitySelector_componentLocale, "f").entitySelectorInputAccessibleName, class: "input", disabled: this.disabled, name: this.name || __classPrivateFieldGet(this, _GxIdeEntitySelector_componentLocale, "f").entitySelectorNameAttribute, startImgSrc: this.iconSrc, readonly: true, value: ((_a = this.value) === null || _a === void 0 ? void 0 : _a.name) || ((_b = this.defaultValue) === null || _b === void 0 ? void 0 : _b.name), id: "entity-input" }), h("button", { part: "button-clear", class: "icon-button", "aria-label": __classPrivateFieldGet(this, _GxIdeEntitySelector_componentLocale, "f").clearButtonLabel, title: __classPrivateFieldGet(this, _GxIdeEntitySelector_componentLocale, "f").clearButtonLabel, type: "button", disabled: this.disabled, onClick: __classPrivateFieldGet(this, _GxIdeEntitySelector_btnClearClickHandler, "f"), onFocus: this.buttonHasFocus ? __classPrivateFieldGet(this, _GxIdeEntitySelector_buttonFocusHandler, "f") : undefined, onBlur: !this.buttonHasFocus ? __classPrivateFieldGet(this, _GxIdeEntitySelector_buttonFocusHandler, "f") : undefined }, h("ch-image", { class: "icon-m", src: CLEAR_ICON, disabled: this.disabled })), h("button", { class: "icon-button", "aria-label": __classPrivateFieldGet(this, _GxIdeEntitySelector_componentLocale, "f").selectButtonLabel, title: __classPrivateFieldGet(this, _GxIdeEntitySelector_componentLocale, "f").selectButtonLabel, type: "button", disabled: !this.selectEntityCallback || this.disabled, onClick: __classPrivateFieldGet(this, _GxIdeEntitySelector_btnSelectClickHandler, "f"), onBlur: !this.buttonHasFocus ? __classPrivateFieldGet(this, _GxIdeEntitySelector_buttonFocusHandler, "f") : undefined, onFocus: this.buttonHasFocus ? __classPrivateFieldGet(this, _GxIdeEntitySelector_buttonFocusHandler, "f") : undefined }, h("ch-image", { class: "icon-m", src: SELECT_DEFAULT_ICON, disabled: this.disabled }))));
        });
        _GxIdeEntitySelector_updateIconSrc.set(this, () => {
            if (this.value && this.value.iconSrc) {
                this.iconSrc = this.value.iconSrc;
            }
        });
        this.buttonHasFocus = false;
        this.iconSrc = null;
        this.defaultValue = undefined;
        this.disabled = false;
        this.labelCaption = undefined;
        this.labelPosition = "block-start";
        this.name = undefined;
        this.selectEntityCallback = undefined;
        this.value = undefined;
    }
    valueChangedHandler() {
        this.valueChanged.emit(this.value);
        __classPrivateFieldGet(this, _GxIdeEntitySelector_updateIconSrc, "f").call(this);
    }
    // 6.Component Lifecycle Events
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeEntitySelector_componentLocale, await Locale.getComponentStrings(this.el), "f");
    }
    connectedCallback() {
        __classPrivateFieldGet(this, _GxIdeEntitySelector_updateIconSrc, "f").call(this);
    }
    render() {
        return (h(Host, { class: {
                "entity-selector--button-has-focus": this.buttonHasFocus
            } }, h("ch-theme", { model: CSS_BUNDLES }), this.labelPosition !== "none" ? (h("div", { class: {
                "field": true,
                "field-block": this.labelPosition === "block-start",
                "field-inline": this.labelPosition === "inline-start"
            } }, h("label", { class: "label", htmlFor: "entity-input" }, this.labelCaption ||
            __classPrivateFieldGet(this, _GxIdeEntitySelector_componentLocale, "f").entitySelectorInputAccessibleName), __classPrivateFieldGet(this, _GxIdeEntitySelector_renderControl, "f").call(this))) : (__classPrivateFieldGet(this, _GxIdeEntitySelector_renderControl, "f").call(this))));
    }
    static get assetsDirs() { return ["gx-ide-assets/entity-selector"]; }
    get el() { return getElement(this); }
    static get watchers() { return {
        "value": ["valueChangedHandler"]
    }; }
};
_GxIdeEntitySelector_componentLocale = new WeakMap(), _GxIdeEntitySelector_btnClearClickHandler = new WeakMap(), _GxIdeEntitySelector_btnSelectClickHandler = new WeakMap(), _GxIdeEntitySelector_buttonFocusHandler = new WeakMap(), _GxIdeEntitySelector_renderControl = new WeakMap(), _GxIdeEntitySelector_updateIconSrc = new WeakMap();
GxIdeEntitySelector.style = entitySelectorCss;

export { GxIdeEntitySelector as gx_ide_entity_selector };

//# sourceMappingURL=gx-ide-entity-selector.entry.js.map