import { r as t, c as e, h as i, H as s, a as o } from "./p-9b9ccd0c.js";

import { g as r } from "./p-d42e842b.js";

import "./p-6534555e.js";

import "lit";

import "lit/directives/when.js";

import "lit/directives/if-defined.js";

import { L as n } from "./p-311eedf3.js";

const a = ".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 l = undefined && undefined.__classPrivateFieldGet || function(t, e, i, s) {
  if (i === "a" && !s) throw new TypeError("Private accessor was defined without a getter");
  if (typeof e === "function" ? t !== e || !s : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return i === "m" ? s : i === "a" ? s.call(t) : s ? s.value : e.get(t);
};

var d = undefined && undefined.__classPrivateFieldSet || function(t, e, i, s, o) {
  if (s === "m") throw new TypeError("Private method is not writable");
  if (s === "a" && !o) throw new TypeError("Private accessor was defined without a setter");
  if (typeof e === "function" ? t !== e || !o : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return s === "a" ? o.call(t, i) : o ? o.value = i : e.set(t, i), i;
};

var c, h, u, f, p, b;

const m = [ "resets/box-sizing", "components/edit", "components/button", "components/icon", "utils/form" ];

const w = r({
  category: "gemini-tools",
  name: "show-more-horizontal",
  colorType: "primary"
});

const v = r({
  category: "gemini-tools",
  name: "reset",
  colorType: "primary"
});

const g = class {
  constructor(s) {
    t(this, s);
    this.valueChanged = e(this, "valueChanged", 7);
    c.set(this, void 0);
    h.set(this, (() => {
      var t;
      this.value = this.defaultValue;
      this.iconSrc = (t = this.defaultValue) === null || t === void 0 ? void 0 : t.iconSrc;
    }));
    u.set(this, (() => {
      this.selectEntityCallback().then((t => {
        if (t) {
          this.value = t;
        }
      }));
    }));
    f.set(this, (t => {
      if (t.type === "focus") {
        this.buttonHasFocus = true;
      } else if (t.type === "blur") {
        this.buttonHasFocus = false;
      }
    }));
    p.set(this, (() => {
      var t, e;
      return i("div", {
        part: "wrapper",
        class: "wrapper"
      }, i("ch-edit", {
        accessibleName: this.labelPosition === "none" && l(this, c, "f").entitySelectorInputAccessibleName,
        class: "input",
        disabled: this.disabled,
        name: this.name || l(this, c, "f").entitySelectorNameAttribute,
        startImgSrc: this.iconSrc,
        readonly: true,
        value: ((t = this.value) === null || t === void 0 ? void 0 : t.name) || ((e = this.defaultValue) === null || e === void 0 ? void 0 : e.name),
        id: "entity-input"
      }), i("button", {
        part: "button-clear",
        class: "icon-button",
        "aria-label": l(this, c, "f").clearButtonLabel,
        title: l(this, c, "f").clearButtonLabel,
        type: "button",
        disabled: this.disabled,
        onClick: l(this, h, "f"),
        onFocus: this.buttonHasFocus ? l(this, f, "f") : undefined,
        onBlur: !this.buttonHasFocus ? l(this, f, "f") : undefined
      }, i("ch-image", {
        class: "icon-m",
        src: v,
        disabled: this.disabled
      })), i("button", {
        class: "icon-button",
        "aria-label": l(this, c, "f").selectButtonLabel,
        title: l(this, c, "f").selectButtonLabel,
        type: "button",
        disabled: !this.selectEntityCallback || this.disabled,
        onClick: l(this, u, "f"),
        onBlur: !this.buttonHasFocus ? l(this, f, "f") : undefined,
        onFocus: this.buttonHasFocus ? l(this, f, "f") : undefined
      }, i("ch-image", {
        class: "icon-m",
        src: w,
        disabled: this.disabled
      })));
    }));
    b.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);
    l(this, b, "f").call(this);
  }
  // 6.Component Lifecycle Events
  async componentWillLoad() {
    d(this, c, await n.getComponentStrings(this.el), "f");
  }
  connectedCallback() {
    l(this, b, "f").call(this);
  }
  render() {
    return i(s, {
      class: {
        "entity-selector--button-has-focus": this.buttonHasFocus
      }
    }, i("ch-theme", {
      model: m
    }), this.labelPosition !== "none" ? i("div", {
      class: {
        field: true,
        "field-block": this.labelPosition === "block-start",
        "field-inline": this.labelPosition === "inline-start"
      }
    }, i("label", {
      class: "label",
      htmlFor: "entity-input"
    }, this.labelCaption || l(this, c, "f").entitySelectorInputAccessibleName), l(this, p, "f").call(this)) : l(this, p, "f").call(this));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/entity-selector" ];
  }
  get el() {
    return o(this);
  }
  static get watchers() {
    return {
      value: [ "valueChangedHandler" ]
    };
  }
};

c = new WeakMap, h = new WeakMap, u = new WeakMap, f = new WeakMap, p = new WeakMap, 
b = new WeakMap;

g.style = a;

export { g as gx_ide_entity_selector };
//# sourceMappingURL=p-80259b9e.entry.js.map