import { r as e, h as t, H as i, a as s } 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 { c as a } from "./p-c5196b3b.js";

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

const o = ":host{display:grid;block-size:100%}.search{display:grid;grid-template-rows:max-content 1fr;gap:var(--spacing-gap-xl)}.search__header{display:grid;grid-template-columns:1fr}.search__results{position:relative}ch-tree-view-render::part(root-item item__header){padding-inline-start:0;font-weight:var(--font-style-semi-bold);font-size:var(--font-size-body-s);line-height:var(--line-height-relaxed);font-family:var(--font-family-body)}ch-tree-view-render::part(search-item item__header){padding-inline-start:0;font-weight:var(--font-style-regular);font-size:var(--font-size-body-s);line-height:var(--line-height-relaxed);font-family:var(--font-family-body);color:var(--color-text-neutral-neutral) !important}.input--loading::part(start-img){animation:spin 1s linear infinite}@keyframes spin{100%{transform:rotate(360deg)}}";

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

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

var c, d, f, p, m, u, g;

const w = [ "resets/box-sizing", "components/edit", "components/tree-view", "utils/typography", "utils/spacing", "chameleon/scrollbar" ];

const y = r({
  category: "system",
  name: "search",
  colorType: "on-surface"
});

const v = r({
  category: "system",
  name: "information",
  colorType: "on-interactive"
});

const b = class {
  constructor(i) {
    e(this, i);
    c.set(this, void 0);
    d.set(this, "");
    f.set(this, (async e => {
      var t;
      if (!this.isKbOpen) {
        return;
      }
      const i = e.target;
      const s = (t = i === null || i === void 0 ? void 0 : i.value) === null || t === void 0 ? void 0 : t.trim();
      h(this, d, s, "f");
      if (!s) {
        this.searchResultModel = [];
        this.hasSearched = false;
        this.isSearching = false;
        return;
      }
      this.hasSearched = true;
      this.isSearching = true;
      this.searchResultModel = [];
      try {
        const e = await this.searchCallback({
          text: s,
          onlyTitles: false,
          includeSubModules: true,
          allBranches: false,
          forLLM: false
        });
        this.searchResultModel = l(this, m, "f").call(this, e);
      } finally {
        this.isSearching = false;
      }
    }));
    p.set(this, (e => {
      if (e.key === "Enter") {
        l(this, f, "f").call(this, e);
      }
    }));
    m.set(this, (e => {
      if (!e || e.length === 0) {
        return [];
      }
      return [ {
        id: "root",
        caption: `${l(this, c, "f").labels.results} (${e.length})`,
        expanded: true,
        parts: "root-item",
        items: e.map((e => ({
          id: e.objectId,
          startImgSrc: e.objectIcon,
          caption: e.objectName,
          leaf: true,
          parts: "search-item"
        })))
      } ];
    }));
    u.set(this, (async e => {
      var t;
      const i = e.detail.id;
      await ((t = this.itemDoubleClickCallback) === null || t === void 0 ? void 0 : t.call(this, i));
    }));
    g.set(this, (() => {
      if (!this.isKbOpen) {
        return t("gx-ide-empty-state", {
          stateTitle: l(this, c, "f").noKbOpenState.title,
          stateDescription: l(this, c, "f").noKbOpenState.description,
          stateIconSrc: v,
          isAnimated: true
        });
      }
      if (this.isSearching) {
        return t("gx-ide-loader", {
          loaderTitle: l(this, c, "f").loader.title,
          show: true
        });
      }
      if (this.searchResultModel.length > 0) {
        return t("ch-tree-view-render", {
          class: "tree-view",
          model: this.searchResultModel,
          expandableButton: "no",
          expandOnClick: false,
          onItemOpenReference: l(this, u, "f")
        });
      }
      if (this.hasSearched) {
        return t("gx-ide-empty-state", {
          stateTitle: l(this, c, "f").emptyState.title,
          stateDescription: l(this, c, "f").emptyState.description,
          stateIconSrc: v,
          isAnimated: true
        });
      }
      return null;
    }));
    this.searchResultModel = [];
    this.hasSearched = false;
    this.isSearching = false;
    this.isKbOpen = false;
    this.searchCallback = undefined;
    this.itemDoubleClickCallback = undefined;
  }
  valueChangeHandler(e) {
    if (!e) {
      h(this, d, "", "f");
      this.searchResultModel = [];
      this.hasSearched = false;
      this.isSearching = false;
    }
  }
  /**
     * Method to show or hide the settings panel, can be called from the outside to control the visibility of the settings
     */  async showSettings(e) {
    return Promise.resolve();
  }
  async componentWillLoad() {
    h(this, c, await n.getComponentStrings(this.el), "f");
  }
  render() {
    return t(i, {
      class: "widget"
    }, t("ch-theme", {
      model: w
    }), t("section", {
      class: "spacing-body search"
    }, t("header", {
      class: "search__header"
    }, t("ch-edit", {
      id: "search-input",
      class: "input",
      accessibleName: l(this, c, "f").accessibleName,
      placeholder: l(this, c, "f").placeholders.search,
      debounce: a.inputDebounce,
      onInput: l(this, f, "f"),
      onKeyDown: l(this, p, "f"),
      type: "search",
      startImgSrc: y,
      disabled: !this.isKbOpen,
      value: l(this, d, "f")
    })), t("main", {
      class: "search__results"
    }, l(this, g, "f").call(this))));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/search" ];
  }
  get el() {
    return s(this);
  }
  static get watchers() {
    return {
      isKbOpen: [ "valueChangeHandler" ]
    };
  }
};

c = new WeakMap, d = new WeakMap, f = new WeakMap, p = new WeakMap, m = new WeakMap, 
u = new WeakMap, g = new WeakMap;

b.style = o;

export { b as gx_ide_search };
//# sourceMappingURL=p-8b5c826b.entry.js.map