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

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

const mapOptionsToComboBoxItemModel = t => t.map((t => {
  var e;
  return {
    value: t.id,
    caption: t.label,
    startImgSrc: (e = t.iconName) !== null && e !== void 0 ? e : ""
  };
}));

const n = ':host{display:grid;block-size:100%;overflow:auto;grid-template-rows:max-content 1fr max-content}.section{display:contents}.header{grid-template:"name type" max-content "object object" max-content;grid-template-columns:1fr 1fr}.name__field{grid-area:name}.name__label{inline-size:40px}.type__field{grid-area:type}.more__btn{grid-area:more;inline-size:64px}.object-selector__field{grid-area:object}.main{overflow:auto}ch-tabular-grid.tabular-grid--empty::part(main){overflow:hidden}ch-tabular-grid-rowset-empty{position:relative}.tabular-grid-row 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}.matching-attributes{margin:0}';

var o = 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 c = undefined && undefined.__classPrivateFieldSet || function(t, e, i, s, a) {
  if (s === "m") throw new TypeError("Private method is not writable");
  if (s === "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 s === "a" ? a.call(t, i) : a ? a.value = i : e.set(t, i), i;
};

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

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

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

const T = class {
  constructor(i) {
    t(this, i);
    /**
         * Component hard-coded strings translations.
         */    d.set(this, void 0);
    /* References needed to collect data */    h.set(this, void 0);
    u.set(this, (t => {
      this.contextMenuCallback({
        selection: this.selectedAttributesIds,
        clientX: t.clientX,
        clientY: t.clientY
      });
    }));
    f.set(this, (() => {
      this.deleteSelectionCallback(this.selectedAttributesIds);
    }));
    m.set(this, (() => {
      o(this, h, "f").selectAllRows(false);
    }));
    b.set(this, (() => {
      var t;
      this.loading = true;
      const e = {
        name: this.name.trim(),
        type: this.type,
        object: (t = this.object) === null || t === void 0 ? void 0 : t.id
      };
      this.loadCallback(e).then((t => {
        var e;
        this.attributes = t;
        if (((e = this.selectedAttributesIds) === null || e === void 0 ? void 0 : e.length) > 0) {
          this.selectedAttributesIds = [];
          o(this, m, "f").call(this);
        }
        this.loading = false;
      }));
    }));
    p.set(this, (() => {
      // for grid selection
      o(this, h, "f").addEventListener("selectionChanged", (t => {
        this.selectedAttributesIds = t.detail.rowsId;
        this.selectionChangeCallback(this.selectedAttributesIds);
      }));
      o(this, h, "f").addEventListener("contextmenu", (t => {
        t.preventDefault();
        t.stopPropagation();
        o(this, u, "f").call(this, t);
      }));
      o(this, h, "f").addEventListener("rowDoubleClicked", (() => {
        o(this, g, "f").call(this);
      }));
    }));
    g.set(this, (() => {
      this.openSelectionCallback(this.selectedAttributesIds);
    }));
    w.set(this, (async () => {
      const t = await this.objectActionCallback();
      this.object = {
        id: t.id,
        name: t.name,
        iconSrc: t.iconSrc
      };
      return new Promise((t => {
        t(null);
      }));
    }));
    v.set(this, (t => {
      this.object = t.detail;
      o(this, b, "f").call(this);
    }));
    y.set(this, (() => {
      var t;
      const i = ((t = this.attributes) === null || t === void 0 ? void 0 : t.length) === 0 || !this.attributes;
      return e("ch-tabular-grid", {
        class: {
          "tabular-grid": true,
          "tabular-grid--empty": i,
          main: true
        },
        ref: t => c(this, h, t, "f"),
        "row-selection-mode": "multiple",
        part: "ch-grid-attributes"
      }, e("ch-tabular-grid-columnset", {
        class: "tabular-grid-column-set"
      }, e("ch-tabular-grid-column", {
        "column-name": "",
        "column-name-position": "text",
        settingable: false,
        sortable: false,
        size: r.tabularGrid.colSize.maxContent,
        class: "tabular-grid-column"
      }), e("ch-tabular-grid-column", {
        "column-name": o(this, d, "f").tableHead.name,
        "column-name-position": "text",
        size: r.tabularGrid.colSize.auto,
        class: "tabular-grid-column",
        settingable: false,
        sortable: false
      }), e("ch-tabular-grid-column", {
        "column-name": o(this, d, "f").tableHead.type,
        "column-name-position": "text",
        class: "tabular-grid-column",
        size: r.tabularGrid.colSize.auto,
        settingable: false,
        sortable: false
      }), e("ch-tabular-grid-column", {
        "column-name": o(this, d, "f").tableHead.description,
        "column-name-position": "text",
        size: r.tabularGrid.colSize.auto,
        class: "tabular-grid-column",
        settingable: false,
        sortable: false
      })), o(this, k, "f").call(this));
    }));
    k.set(this, (() => {
      if (this.loading) {
        return e("ch-tabular-grid-rowset", {
          class: "tabular-grid-rowset"
        }, e("ch-tabular-grid-rowset-empty", null, e("gx-ide-loader", {
          loaderTitle: o(this, d, "f").loader.title,
          description: o(this, d, "f").loader.description,
          show: true
        })));
      } else if (this.attributes.length) {
        return e("ch-tabular-grid-rowset", {
          class: "tabular-grid-rowset"
        }, this.attributes.map((t => e("ch-tabular-grid-row", {
          class: "tabular-grid-row",
          rowid: t.id
        }, e("ch-tabular-grid-cell", {
          class: "tabular-grid-cell"
        }, e("ch-image", {
          class: "icon-xs",
          src: t.icon
        })), e("ch-tabular-grid-cell", {
          class: "tabular-grid-cell"
        }, t.name), e("ch-tabular-grid-cell", {
          class: "tabular-grid-cell"
        }, t.type), e("ch-tabular-grid-cell", {
          class: "tabular-grid-cell"
        }, t.description)))));
      } else {
        // filter returned none
        return e("ch-tabular-grid-rowset", {
          class: "tabular-grid-rowset"
        }, e("ch-tabular-grid-rowset-empty", null, e("gx-ide-empty-state", {
          stateIconSrc: z,
          stateTitle: o(this, d, "f").emptyStateTitle,
          isAnimated: true
        })));
      }
    }));
    x.set(this, (() => {
      var t;
      return e("header", {
        class: "header field-group dialog-header-with-border spacing-body"
      }, e("div", {
        class: "field field-inline name__field"
      }, e("label", {
        class: "label name__label",
        htmlFor: "name"
      }, o(this, d, "f").filter.name), e("ch-edit", {
        // Name
        id: "name",
        class: "input",
        value: this.name,
        debounce: 300,
        onInput: o(this, j, "f"),
        part: "filter-name"
      })), e("div", {
        class: "field field-inline type__field"
      }, e("label", {
        class: "label",
        htmlFor: "type"
      }, o(this, d, "f").filter.type), e("ch-combo-box-render", {
        // Type
        id: "type",
        class: "combo-box",
        disabled: !this.types,
        value: this.type,
        model: mapOptionsToComboBoxItemModel((t = this.types) !== null && t !== void 0 ? t : []),
        part: "filter-type",
        onInput: o(this, W, "f")
      })), e("div", {
        class: "field field-inline object-selector__field"
      }, e("label", {
        class: "label",
        htmlFor: "object-selector"
      }, o(this, d, "f").filter.object), e("gx-ide-entity-selector", {
        // Object
        id: "object-selector",
        value: this.object,
        labelPosition: "none",
        defaultValue: null,
        selectEntityCallback: o(this, w, "f"),
        onValueChanged: o(this, v, "f"),
        part: "filter-module-folder"
      })));
    }));
    _.set(this, (() => {
      o(this, h, "f").selectAllRows();
    }));
    j.set(this, (t => {
      this.name = t.detail.trim();
      o(this, b, "f").call(this);
    }));
    W.set(this, (t => {
      this.type = t.detail;
      o(this, b, "f").call(this);
    }));
    this.attributes = undefined;
    this.selectedAttributesIds = [];
    this.filterMore = false;
    this.name = "";
    this.loading = true;
    this.object = undefined;
    this.type = undefined;
    this.contextMenuCallback = undefined;
    this.deleteSelectionCallback = undefined;
    this.loadCallback = undefined;
    this.objectActionCallback = undefined;
    this.objects = undefined;
    this.openSelectionCallback = undefined;
    this.selectionChangeCallback = undefined;
    this.types = undefined;
  }
  async componentWillLoad() {
    c(this, d, await l.getComponentStrings(this.el), "f");
  }
  componentDidLoad() {
    o(this, p, "f").call(this);
    this.type = this.types[0].id;
 // before #getAttributes
        o(this, b, "f").call(this);
  }
  keyDownHandler(t) {
    if (document.activeElement === this.el) {
      switch (t.key) {
       case "Enter":
        o(this, g, "f").call(this);
        break;

       case "Delete":
        o(this, f, "f").call(this);
        break;
      }
    }
  }
  /**
     * Reloads the view, refreshing the filters and attributes table.
     */  async reload() {
    this.name = "";
    this.type = this.types[0].id;
    this.object = null;
    o(this, b, "f").call(this);
  }
  /**
     * Validate necessary data input
     */  async validate() {
    const t = true;
    return t;
  }
  render() {
    var t, s;
    const a = !this.attributes || this.attributes.length === 0;
    const r = ((t = this.attributes) === null || t === void 0 ? void 0 : t.length) === 1 ? o(this, d, "f").matchingAttribute : o(this, d, "f").matchingAttributes;
    const l = ((s = this.attributes) === null || s === void 0 ? void 0 : s.length) || 0;
    return e(i, {
      class: "widget"
    }, e("ch-theme", {
      model: M
    }), e("section", {
      class: "section"
    }, o(this, x, "f").call(this), o(this, y, "f").call(this), e("footer", {
      class: "dialog-footer dialog-footer-with-border spacing-body-block-end spacing-body-inline dialog-footer-space-between"
    }, e("p", {
      class: "body-regular-s matching-attributes"
    }, `${l} ${r}`), e("button", {
      id: "button-select-all",
      class: "button-primary",
      onClick: o(this, _, "f"),
      disabled: a,
      part: "button button--select-all"
    }, o(this, d, "f").footer.btnSelectAll))));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/ww-attributes" ];
  }
  get el() {
    return s(this);
  }
};

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

T.style = n;

export { T as gx_ide_ww_attributes };
//# sourceMappingURL=p-308ad50f.entry.js.map