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

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

import { c as n } from "./p-c5196b3b.js";

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

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

import "lit";

import "lit/directives/when.js";

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

const l = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;grid-template-rows:max-content 1fr max-content;overflow:auto;block-size:100%}.section{display:contents}.header__field-group{display:grid;grid-template-columns:1fr 1fr}.tabular-grid{contain:size}.data ch-tabular-grid-cell:is(:nth-child(2),:nth-child(3),:nth-child(4)){align-items:start;justify-content:start;display:inline-block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-inline-size:0}ch-tabular-grid.empty-result::part(main){overflow:hidden}ch-tabular-grid-rowset-empty{position:relative}";

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

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

var d, u, f, b, p, m, g, w, y, v, k, M, W, j, x, C, z, E, T, _, D;

// Best performance bundle
const P = [ "resets/box-sizing", "components/button", "components/edit", "components/tabular-grid", "components/icon", "utils/form", "utils/layout", "utils/spacing", "chameleon/scrollbar" ];

const S = o({
  category: "window-tools",
  name: "filter",
  colorType: "on-surface"
});

const F = class {
  constructor(i) {
    t(this, i);
    d.set(this, void 0);
 // used to select the first item after "loadItemsCallback"
        u.set(this, false);
 // used to select the first item after "loadItemsCallback"
        f.set(this, void 0);
    b.set(this, false);
    p.set(this, e(`./gx-ide-assets/data-selector/shortcuts.json`));
    /* References needed to collect data */    m.set(this, void 0);
    g.set(this, void 0);
    w.set(this, void 0);
    y.set(this, void 0);
    /**
         * After items have been loaded and rendered, the first row should be selected.
         */    v.set(this, (() => {
      if (c(this, u, "f")) {
        c(this, y, "f").selectRow(c(this, d, "f"));
      }
      h(this, u, false, "f");
    }));
    k.set(this, (t => {
      if (t.key === "Enter") {
        c(this, M, "f").call(this, t);
      }
    }));
    M.set(this, (t => {
      t.stopPropagation();
      this.confirmCallback(this.selectedObjectsIds);
    }));
    W.set(this, (async t => {
      t.stopPropagation();
      if (this.selectedObjectsIds[0]) {
        const t = await this.editCallback(this.selectedObjectsIds[0]);
        if (t) {
          c(this, z, "f").call(this);
        }
      }
    }));
    j.set(this, (t => {
      // TODO : revise why this is necessary
      // just prevent keypress propagation
      if (t.key === "Enter") {
        t.stopPropagation();
      }
    }));
    x.set(this, (t => {
      this.selectedObjectsIds = t.detail.rowsId;
    }));
    C.set(this, (async () => {
      const t = await this.newVariableCallback();
      if (t) {
        c(this, z, "f").call(this);
      }
    }));
    z.set(this, (() => {
      var t, e, s;
      this.objects = [];
      const i = {
        pattern: (t = c(this, m, "f")) === null || t === void 0 ? void 0 : t.value,
        object: (s = (e = c(this, g, "f")) === null || e === void 0 ? void 0 : e.value) === null || s === void 0 ? void 0 : s.id
      };
      this.loading = true;
      this.loadItemsCallback(i).then((t => {
        if (t.length) {
          this.objects = c(this, D, "f").call(this, t);
          h(this, d, this.objects[0].id, "f");
          h(this, u, true, "f");
        }
        this.selectedObjectsIds = [];
        this.loading = false;
      }));
    }));
    E.set(this, (() => [ s("div", {
      class: "header__field-group field-group"
    }, s("div", {
      class: "field field-block pattern-field"
    }, s("label", {
      class: "label",
      htmlFor: "filter-pattern"
    }, c(this, f, "f").filter.pattern), s("ch-edit", {
      autoFocus: true,
      id: "filter-pattern",
      name: "filter-pattern",
      class: "input pattern-input",
      part: "filter-pattern",
      debounce: n.inputDebounce,
      onInput: c(this, z, "f"),
      ref: t => h(this, m, t, "f")
    })), s("gx-ide-entity-selector", {
      id: "object-selector",
      value: this.defaultModule,
      defaultValue: this.defaultModule,
      selectEntityCallback: this.selectObjectCallback,
      ref: t => h(this, g, t, "f"),
      class: "entity",
      onValueChanged: c(this, z, "f")
    })) ]));
    T.set(this, (() => {
      const t = !this.objects.length;
      const e = this.loader && this.loading;
      if (!t || e) {
        h(this, b, true, "f");
 // improve performance if is first render
            }
      return s("ch-tabular-grid", {
        class: {
          "tabular-grid": true,
          "empty-result": this.objects.length === 0,
          data: true
        },
        rowSelectionMode: this.selectionType,
        onKeyDown: c(this, k, "f"),
        part: "ch-grid-objects",
        onSelectionChanged: this.objects.length ? c(this, x, "f") : undefined,
        ref: t => h(this, y, t, "f")
      }, s("ch-tabular-grid-columnset", {
        class: "tabular-grid-column-set"
      }, s("ch-tabular-grid-column", {
        "column-name-position": "text",
        settingable: false,
        sortable: false,
        size: n.tabularGrid.colSize.maxContent,
        class: "tabular-grid-column"
      }), s("ch-tabular-grid-column", {
        "column-name": c(this, f, "f").tableHead.name,
        "column-name-position": "text",
        settingable: false,
        sortable: false,
        size: n.tabularGrid.colSize.common,
        class: "tabular-grid-column"
      }), s("ch-tabular-grid-column", {
        "column-name": c(this, f, "f").tableHead.dataType,
        "column-name-position": "text",
        settingable: false,
        sortable: false,
        size: n.tabularGrid.colSize.common,
        class: "tabular-grid-column"
      }), s("ch-tabular-grid-column", {
        "column-name": c(this, f, "f").tableHead.description,
        "column-name-position": "text",
        settingable: false,
        sortable: false,
        size: n.tabularGrid.colSize.common,
        class: "tabular-grid-column"
      })), !t ? s("ch-tabular-grid-rowset", {
        class: "tabular-grid-rowset"
      }, this.objects.map((t => s("ch-tabular-grid-row", {
        rowid: t.id,
        onDblClick: c(this, M, "f"),
        class: "tabular-grid-row"
      }, s("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, s("ch-image", {
        src: t.type === "attribute" ? "objects/attribute" : "objects-parts/variables",
        class: "icon-s"
      })), s("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, t.name), s("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, t.dataType), s("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, t.description))))) : s("ch-tabular-grid-rowset", {
        class: "tabular-grid-rowset"
      }, s("ch-tabular-grid-rowset-empty", null, e ? s("gx-ide-loader", {
        loaderTitle: c(this, f, "f").loader.title,
        show: true
      }) : s("gx-ide-empty-state", {
        isAnimated: c(this, b, "f"),
        stateIconSrc: S,
        stateTitle: c(this, f, "f").emptyState.title
      }))));
    }));
    _.set(this, (() => {
      if (!this.editCallback && !this.newVariableCallback) {
        return null;
      }
      const t = this.newVariableCallback && !this.loading;
      const e = this.editCallback && !this.loading && this.selectedObjectsIds.length;
      return s("div", {
        class: "buttons-spacer"
      }, this.newVariableCallback ? s("button", {
        // New Variable Button
        class: "button-secondary",
        disabled: !t,
        part: "button button-new",
        type: "button",
        onClick: c(this, C, "f")
      }, c(this, f, "f").footer.btnNew) : [], this.editCallback ? s("button", {
        // Edit Button
        class: "button-secondary",
        disabled: !e,
        part: "button button-edit",
        type: "button",
        onClick: e && c(this, W, "f")
      }, c(this, f, "f").footer.btnEdit) : []);
    }));
    D.set(this, (t => 
    // TODO (make this a common helper function
    // and use it in other dialog grids that
    // require filter by name).
    t.sort(((t, e) => {
      const s = t.name.toLowerCase(), i = e.name.toLowerCase();
      if (s < i) {
        return -1;
      }
      if (s > i) {
        return 1;
      }
      return 0;
    }))));
    this.loading = true;
    this.objects = [];
    this.selectedObjectsIds = [];
    this.cancelCallback = undefined;
    this.confirmCallback = undefined;
    this.defaultModule = undefined;
    this.displayTitle = false;
    this.editCallback = undefined;
    this.loadItemsCallback = undefined;
    this.loader = false;
    this.newVariableCallback = undefined;
    this.selectObjectCallback = undefined;
    this.selectionType = "multiple";
  }
  async componentWillLoad() {
    h(this, f, await r.getComponentStrings(this.el), "f");
  }
  connectedCallback() {
    c(this, z, "f").call(this);
  }
  componentDidLoad() {
    c(this, m, "f").focus();
  }
  componentDidRender() {
    c(this, v, "f").call(this);
  }
  /**
     * Suspends or reactivates the shortcuts
     */  async suspendShortcuts(t) {
    if (t) {
      c(this, w, "f").suspend = true;
    } else {
      c(this, w, "f").suspend = false;
    }
  }
  /**
     * Validate necessary data input
     */  async validate() {
    const t = true;
    return t;
  }
  render() {
    const t = !this.loading;
    const e = !!this.newVariableCallback || !!this.editCallback;
    return s(i, {
      onKeyPress: c(this, j, "f"),
      class: "widget"
    }, s("ch-theme", {
      model: P
    }), s("ch-shortcuts", {
      src: c(this, p, "f"),
      ref: t => h(this, w, t, "f")
    }), s("section", {
      class: "section"
    }, s("header", {
      class: "header dialog-header-with-border spacing-body-block-start spacing-body-inline"
    }, c(this, E, "f").call(this)), c(this, T, "f").call(this), s("footer", {
      class: {
        footer: true,
        "dialog-footer-with-border": true,
        "dialog-footer-space-between": e,
        "spacing-body-inline": true,
        "spacing-body-block-end": true
      }
    }, c(this, _, "f").call(this), s("div", {
      class: "buttons-spacer"
    }, s("button", {
      // Cancel Button
      class: "button-secondary",
      part: "button button-cancel",
      type: "button",
      onClick: this.cancelCallback
    }, c(this, f, "f").footer.btnCancel), s("button", {
      // Confirm Button
      class: "button-primary",
      part: "button button-ok",
      disabled: !t,
      type: "button",
      onClick: t && c(this, M, "f")
    }, c(this, f, "f").footer.btnConfirm)))));
  }
  static get delegatesFocus() {
    return true;
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/data-selector" ];
  }
  get el() {
    return a(this);
  }
};

d = new WeakMap, u = new WeakMap, f = new WeakMap, b = new WeakMap, p = new WeakMap, 
m = new WeakMap, g = new WeakMap, w = new WeakMap, y = new WeakMap, v = new WeakMap, 
k = new WeakMap, M = new WeakMap, W = new WeakMap, j = new WeakMap, x = new WeakMap, 
C = new WeakMap, z = new WeakMap, E = new WeakMap, T = new WeakMap, _ = new WeakMap, 
D = new WeakMap;

F.style = l;

export { F as gx_ide_data_selector };
//# sourceMappingURL=p-e0fb6257.entry.js.map