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

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

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

import "lit";

import "lit/directives/when.js";

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

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

/**
 * @description This function converts SelectorCategoryData[] SuggestData
 */ const convertToTreeItem = e => {
  var t;
  return {
    caption: e.name,
    id: e.id,
    items: ((t = e.items) !== null && t !== void 0 ? t : []).map(convertToTreeItem),
    lazy: e.hasChildren && (e.items == null || e.items.length === 0),
    leaf: e.hasChildren === false,
    startImgSrc: e.icon
  };
};

/**
 * @description This function converts ReferenceData[] data to TreeItemData[]
 */ const convertReferenceDataToTreeViewData = e => {
  const t = [];
  if (!e) {
    return t;
  }
  e.forEach((e => {
    t.push(convertToTreeItem(e));
  }));
  return t;
};

const mapSelectorCategoryDataToComboBoxModel = e => e.map((e => {
  const t = {
    value: e.name,
    caption: e.name,
    expandable: true,
    expanded: true,
    items: e.items.map((e => ({
      value: e.id,
      caption: e.description,
      startImgSrc: e.icon
    })))
  };
  return t;
}));

const o = ":host{display:grid;block-size:100%}.opacity-0{opacity:0}.gxi-hidden{display:none !important}.align-center{display:flex;align-items:center}.align-end{display:flex;align-items:end}.overflow-auto{overflow:auto}:host(.gx-ide-component){height:100% !important;display:flex !important;flex-direction:column !important}.gx-ide-main-wrapper{color:var(--gx-ide-component-text-color);font-weight:var(--font-style-regular);font-size:var(--font-size-body-m);font-family:var(--font-family-body);height:100%;display:flex;flex-direction:column;flex-grow:1;box-sizing:border-box}.buttons-container{display:flex;gap:var(--spacing-gap-m)}.giu-static-pill-icon-and-text,.giu-static-pill{background-color:var(--elevation-background-color, var(--color-accent-surface-elevation-1));padding-inline:var(--spacing-padding-m);color:var(--color-text-neutral-default);font-size:var(--font-size-body-s);line-height:var(--line-height-relaxed);font-weight:var(--font-style-regular);border-radius:4px;min-block-size:25px;display:inline-grid;align-items:center;pointer-events:none;inline-size:max-content}.giu-static-pill-icon-and-text{display:inline-grid;grid-auto-flow:column;grid-auto-columns:max-content;gap:var(--spacing-gap-m)}.tab-full-width-buttons::part(tab-list block-start),.tab-full-width-buttons::part(tab-list block-end){grid-auto-columns:1fr}.tab-full-width-buttons::part(tab block-start){justify-content:center}.tree-view::part(item__header){--icon__system_warning_warning--disabled:var(\n    --icon__system_warning_warning--enabled\n  )}.tabular-grid{--focus-outline-width:1px}:host{display:grid;block-size:100%;grid-template-rows:max-content 1fr}.section{display:contents}.header{}.header__top{grid-template-columns:max-content 1fr max-content}.header__bottom{display:grid;grid-template-rows:1fr;transition:var(--timing-fast) grid-template-rows}.header__bottom--hidden{grid-template-rows:0fr}.header__bottom .outer-wrapper{overflow:hidden}.header__bottom .inner-wrapper{padding-top:12px;display:flex;flex-direction:row;align-items:center;justify-content:space-between}.header__bottom .inner-wrapper__left{display:flex;align-items:center;gap:var(--spacing-gap-xl)}.main{display:grid;grid-template-columns:1fr 1fr}.section__referenced-by,.section__references-to{display:grid;grid-template-rows:max-content 1fr}.dialog-header__referenced-by,.dialog-header__references-to{padding-block-start:16px}.main__referenced-by,.main__references-to{grid-auto-rows:max-content;overflow:auto}.main__referenced-by{border-inline-end:var(--section-common-border)}.text-align-center{text-align:center}";

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

var c, h, f, p, g, u, m, b, w, v, y, x, _, k;

const j = [ "resets/box-sizing", "components/button", "components/pills", "components/combo-box", "components/icon", "components/checkbox", "components/tree-view", "utils/spacing", "utils/layout", "utils/form", "utils/typography" ];

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

const W = a({
  category: "navigation",
  name: "arrow-down-skyblue",
  colorType: "primary"
});

const z = {
  alreadyProcessed: true,
  autoExpand: false,
  hideMatchesAndShowNonMatches: false,
  highlightMatchedItems: false,
  matchCase: false,
  regularExpression: false,
  strict: false,
  renderActiveItemIconOnExpand: true
};

const C = class {
  constructor(i) {
    e(this, i);
    c.set(this, new Map);
    h.set(this, t(`./gx-ide-assets/references/shortcuts.json`));
    f.set(this, void 0);
    p.set(this, void 0);
    /**
         * Evaluates whether to call loadReferencesCallback based on the presence of a selected object.
         */    g.set(this, (() => {
      if (this.selectedObject) {
        this.selectedObjectChanged(this.selectedObject);
      }
    }));
    /**
         * Hides or shows the bar (the bottom section of the header).
         */    u.set(this, (() => {
      this.barHidden = !this.barHidden;
    }));
    /**
         * Invokes 'loadReferencesCallback' for 'Is Referenced By' and 'Has References To' panels.
         */    m.set(this, (async (e, t = false) => {
      if (this.loadReferencesCallback) {
        this.loadReferencesCallback(e, t).then((e => {
          if (t) {
            this.referencesToTreeData = convertReferenceDataToTreeViewData(e);
          } else {
            this.referencedByTreeData = convertReferenceDataToTreeViewData(e);
          }
        }));
      }
    }));
    b.set(this, (() => {
      var e;
      // Returns an empty Promise
            this.openObjectCallback((e = this.selectedObject) === null || e === void 0 ? void 0 : e.id);
    }));
    /**
         * Fired when user clicks the ch-suggest button (...)
         */    w.set(this, (async () => {
      const e = await this.openSelectorDialogCallback();
      if (e) {
        this.selectedObject = e;
      }
    }));
    v.set(this, (e => {
      if (this.selectReferenceCallback) {
        const t = e.detail.map((e => e.item.id));
        this.selectReferenceCallback(t[0]);
        // returns void
            }
    }));
    y.set(this, (e => {
      const t = e.detail.id;
      if (this.openObjectCallback) {
        this.openObjectCallback(t);
        // returns void
            }
    }));
    x.set(this, (e => async t => {
      if (this.loadReferencesCallback) {
        const i = e === "references-to";
        const s = await this.loadReferencesCallback(t, i);
        const n = convertReferenceDataToTreeViewData(s);
        return new Promise((e => {
          e(n);
        }));
      }
      return new Promise((e => {
        e([]);
      }));
    }));
    _.set(this, (e => {
      const t = e.detail;
      const i = l(this, c, "f").get(t);
      if (i) {
        this.selectedObject = i;
      }
    }));
    k.set(this, (e => {
      // WA to know if the event was from searching on the input or an item selection.
      // const partValue = (e.target as HTMLElement).getAttribute("part");
      const t = e.detail;
      if (this.selectorSourceCallback) {
        this.selectorSourceCallback(t).then((e => {
          // update map
          l(this, c, "f").clear();
          e === null || e === void 0 ? void 0 : e.forEach((e => {
            e.items.forEach((e => {
              l(this, c, "f").set(e.description, {
                id: e.id,
                typeName: e.typeName,
                icon: e.icon,
                name: e.name,
                description: e.description
              });
            }));
          }));
          this.objectsSuggestions = mapSelectorCategoryDataToComboBoxModel(e);
        }));
      }
    }));
    this.barHidden = false;
    this.objectsSuggestions = undefined;
    this.referencedByTreeData = undefined;
    this.referencesToTreeData = undefined;
    this.loadReferencesCallback = undefined;
    this.openObjectCallback = undefined;
    this.openSelectorDialogCallback = undefined;
    this.selectReferenceCallback = undefined;
    this.selectorSourceCallback = undefined;
    this.selectedObject = undefined;
  }
  selectedObjectChanged(e) {
    if (e === null || e === void 0 ? void 0 : e.id) {
      /* update "is referenced by*/
      l(this, m, "f").call(this, e.id, false);
      /* update "has references to*/      l(this, m, "f").call(this, e.id, true);
    }
  }
  componentDidLoad() {
    l(this, p, "f").focus();
  }
  async componentWillLoad() {
    d(this, f, await r.getComponentStrings(this.el), "f");
    l(this, g, "f").call(this);
  }
  render() {
    var e, t, n, a, r, o, c, g, m;
    return i(s, {
      class: "widget"
    }, i("ch-theme", {
      model: j
    }), i("section", {
      class: "section"
    }, i("header", {
      class: "header dialog-header-with-border spacing-body-inline spacing-body-block-start"
    }, i("div", {
      class: "header__top field-group"
    }, i("button", {
      type: "button",
      class: "button-tertiary button-icon-only",
      "aria-label": l(this, f, "f").header.toggleBar,
      part: "toggle-bar-button",
      onClick: l(this, u, "f")
    }, i("ch-image", {
      class: "icon-m",
      src: W,
      containerRef: this.el
    })), i("div", {
      class: "field field-inline"
    }, i("label", {
      // select object
      class: "label",
      part: "select-object-label",
      htmlFor: "object-selector-suggest"
    }, l(this, f, "f").header.selectObject), i("ch-combo-box-render", {
      accessibleName: l(this, f, "f").header.selectObject,
      class: "combo-box",
      model: this.objectsSuggestions,
      suggest: true,
      onInput: l(this, k, "f"),
      onChange: l(this, _, "f"),
      value: (e = this.selectedObject) === null || e === void 0 ? void 0 : e.name,
      part: "object-selector-suggest",
      suggestOptions: z,
      ref: e => d(this, p, e, "f")
    })), i("button", {
      type: "button",
      class: "button-tertiary button-icon-only",
      "aria-label": l(this, f, "f").header.openSelectorButton,
      onClick: l(this, w, "f"),
      part: "open-selector-dialog-button"
    }, i("ch-image", {
      class: "icon-m",
      src: M,
      containerRef: this.el
    }))), i("div", {
      class: {
        header__bottom: true,
        "header__bottom--hidden": this.barHidden
      }
    }, i("div", {
      class: "outer-wrapper"
    }, i("div", {
      class: "inner-wrapper"
    }, i("div", {
      class: "inner-wrapper__left"
    }, i("ch-image", {
      class: "icon-m",
      src: this.selectedObject.icon,
      containerRef: this.el
    }), i("a", {
      class: "text-link",
      onClick: l(this, b, "f"),
      part: "open-object-text-link",
      "aria-label": l(this, f, "f").main.selectedObjectLink
    }, `${(t = this.selectedObject) === null || t === void 0 ? void 0 : t.name} : ${(n = this.selectedObject) === null || n === void 0 ? void 0 : n.description}`)))))), i("div", {
      class: "main"
    }, i("section", {
      class: "section__referenced-by"
    }, i("h2", {
      class: "dialog-header dialog-header-with-border dialog-header__referenced-by heading-5 text-align-center spacing-body-inline subtitle-regular-xs"
    }, l(this, f, "f").main.isReferencedBy), i("div", {
      // is referenced by
      class: "main__referenced-by spacing-body-block-start spacing-body-block-end"
    }, i("ch-tree-view-render", {
      class: {
        "gxi-hidden": !((a = this.referencedByTreeData) === null || a === void 0 ? void 0 : a.length),
        "tree-view": true
      },
      part: "referenced-by-tree",
      model: this.referencedByTreeData,
      "aria-label": l(this, f, "f").main.referencedByTreeAccessible,
      lazyLoadTreeItemsCallback: l(this, x, "f").call(this, "referenced-by"),
      onSelectedItemsChange: l(this, v, "f"),
      dragDisabled: true,
      dropDisabled: true,
      onItemOpenReference: l(this, y, "f"),
      showLines: "last"
    }), !((r = this.referencedByTreeData) === null || r === void 0 ? void 0 : r.length) && i("gx-ide-empty-state", {
      stateTitle: ((o = this.referencedByTreeData) === null || o === void 0 ? void 0 : o.length) === 0 ? l(this, f, "f").main.isReferencedByEmpty : l(this, f, "f").main.isReferencedByError
    }))), i("section", {
      class: "section__references-to"
    }, i("h2", {
      class: "dialog-header dialog-header-with-border dialog-header__references-to heading-5 text-align-center spacing-body-inline subtitle-regular-xs"
    }, l(this, f, "f").main.hasReferencesTo), i("div", {
      // has references to
      class: "main__references-to spacing-body-block-start spacing-body-block-end"
    }, i("ch-tree-view-render", {
      class: {
        "gxi-hidden": !((c = this.referencesToTreeData) === null || c === void 0 ? void 0 : c.length),
        "tree-view": true
      },
      part: "referenced-to-tree",
      model: this.referencesToTreeData,
      "aria-label": l(this, f, "f").main.referencesToTreeAccessible,
      lazyLoadTreeItemsCallback: l(this, x, "f").call(this, "references-to"),
      onSelectedItemsChange: l(this, v, "f"),
      dragDisabled: true,
      dropDisabled: true,
      onItemOpenReference: l(this, y, "f"),
      showLines: "last"
    }), !((g = this.referencesToTreeData) === null || g === void 0 ? void 0 : g.length) && i("gx-ide-empty-state", {
      stateTitle: ((m = this.referencesToTreeData) === null || m === void 0 ? void 0 : m.length) === 0 ? l(this, f, "f").main.hasReferencesEmpty : l(this, f, "f").main.hasReferencesToError
    }))))), i("ch-shortcuts", {
      src: l(this, h, "f")
    }));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/references" ];
  }
  get el() {
    return n(this);
  }
  static get watchers() {
    return {
      selectedObject: [ "selectedObjectChanged" ]
    };
  }
};

c = new WeakMap, h = new WeakMap, f = new WeakMap, p = new WeakMap, g = new WeakMap, 
u = new WeakMap, m = new WeakMap, b = new WeakMap, w = new WeakMap, v = new WeakMap, 
y = new WeakMap, x = new WeakMap, _ = new WeakMap, k = new WeakMap;

C.style = o;

export { C as gx_ide_references };
//# sourceMappingURL=p-9a10fa97.entry.js.map