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

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

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

import { r } from "./p-7d0f58d6.js";

const objectsToListItemData = t => {
  const i = [];
  t.forEach((t => {
    const e = t.id;
    const s = t.name;
    const a = t.icon;
    const n = false;
    i.push({
      itemId: e,
      itemValue: s,
      itemIcon: a,
      itemChecked: n
    });
  }));
  return i;
};

const l = ':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}.control-wrapper{display:flex;gap:var(--spacing-gap-m);align-items:center}.control-wrapper--vertical{flex-direction:column;align-items:start}.controls-wrapper{display:flex;gap:var(--spacing-gap-m)}.controls-wrapper--vertical{flex-direction:column;align-items:start}.input-text{box-sizing:border-box;background-color:transparent;border:1px solid var(--color-border-neutral-default);border-radius:4px;height:26px;color:var(--color-text-neutral-default);font-size:var(--font-size-body-xs)}.input-text--full-width{align-self:stretch}:host{display:block}.header{display:grid;grid-template-columns:1fr min-content min-content;grid-template-areas:"label label label" "input cancel export";grid-gap:var(--spacing-gap-l)}.header .label{grid-area:label}.header .input{grid-area:input}.header .cancel{grid-area:cancel}.header .export{grid-area:export}';

const c = class {
  constructor(e) {
    t(this, e);
    this.componentDidRenderFirstTime = i(this, "componentDidRenderFirstTime", 7);
    this.selectionChanged = i(this, "selectionChanged", 7);
    this.renderedFirstTime = false;
    this.includeAll = false;
    // 7.LISTENERS //
    // 8.PUBLIC METHODS API //
    // 9.LOCAL METHODS //
        this.objectSelectionChangedHandler = t => {
      const i = Array.isArray(t.detail) ? t.detail : [ t.detail ];
      this.selectedObjects = i.map((t => t.itemId));
    };
    this.removeObjectsHandler = () => {
      this.objects = this.objects.filter((t => !this.selectedObjects.includes(t.id)));
      this.selectedObjects = [];
      this.updateSelection(false);
    };
    this.removeAllObjectsHandler = () => {
      this.objects = [];
      this.selectedObjects = [];
      this.updateSelection(false);
    };
    this.includeAllHandler = () => {
      this.includeAll = this.includeAllCheckboxEl.value === "true";
      if (this.includeAll) {
        this.selectedObjects = this.objects.map((t => t.id));
        this.objects = [];
        this.updateSelection(true);
      } else {
        this.selectedObjects = [];
        this.updateSelection(false);
      }
      this.selectionChanged.emit();
    };
    this.addCallbackHandler = async () => {
      if (this.addCallback) {
        const t = await this.addCallback();
        const i = t.filter((t => !this.objects.some((i => i.id === t.id))));
        this.objects = [ ...this.objects, ...i ];
        this.updateSelection(false);
      }
    };
    this.referencesCallbackHandler = async () => {
      if (this.referencesCallback && this.objects.length > 0) {
        const t = this.objects.map((t => t.id));
        const i = await this.referencesCallback(t);
        const e = i.filter((t => !this.objects.some((i => i.id === t.id))));
        this.objects = [ ...this.objects, ...e ];
        this.updateSelection(false);
      }
    };
    this.updateSelection = t => {
      const i = {
        includeAll: this.includeAllCheckboxEl.value === "true",
        objectIds: t ? this.selectedObjects : this.objects.map((t => t.id))
      };
      this.selection = i;
      this.selectionChanged.emit();
    };
    this.objects = [];
    this.selectedObjects = [];
    this.displayTitle = false;
    this.selection = undefined;
    this.addCallback = undefined;
    this.referencesCallback = undefined;
  }
  // 6.COMPONENT LIFECYCLE METHODS //
  async componentWillLoad() {
    this._componentLocale = await o.getComponentStrings(this.el);
  }
  componentDidRender() {
    if (!this.renderedFirstTime) {
      this.componentDidRenderFirstTime.emit(this.el);
      this.renderedFirstTime = true;
    }
  }
  // 10.RENDER() FUNCTION //
  render() {
    return e(s, {
      class: "gx-ide-component gx-ide-bpm-objects-selector"
    }, e("div", {
      class: "gx-ide-main-wrapper"
    }, e("gx-ide-container", {
      slimmerFooter: n.gxIdeContainer.slimmerFooter
    }, e("gx-ide-list-selector", {
      id: "path-list",
      type: "multi-selection",
      listName: "path-list",
      ordered: true,
      onSelectionChanged: this.objectSelectionChangedHandler,
      class: "path-list"
    }, r(objectsToListItemData(this.objects))), e("div", {
      class: "controls-wrapper"
    }, e("label", {
      htmlFor: "include-all"
    }, this._componentLocale.main.includeAllLabel), e("ch-checkbox", {
      id: "include-all",
      accessibleName: this._componentLocale.main.includeAllLabel,
      checkedValue: "true",
      unCheckedValue: "false",
      value: "checked",
      onInput: this.includeAllHandler,
      ref: t => this.includeAllCheckboxEl = t
    }), e("button", {
      onClick: this.addCallbackHandler,
      disabled: this.includeAll
    }, this._componentLocale.main.addButton), e("button", {
      onClick: this.referencesCallbackHandler,
      disabled: this.objects.length === 0
    }, this._componentLocale.main.referencesButton), e("button", {
      onClick: this.removeObjectsHandler,
      disabled: this.selectedObjects.length === 0 || this.includeAll
    }, this._componentLocale.main.removeButton, " (", this.selectedObjects.length, ")")), e("button", {
      slot: "footer-end",
      onClick: this.removeAllObjectsHandler,
      disabled: this.includeAll
    }, this._componentLocale.main.clearButton))));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/bpm-objects-selector" ];
  }
  get el() {
    return a(this);
  }
};

c.style = l;

export { c as gx_ide_bpm_objects_selector };
//# sourceMappingURL=p-cdd2e79d.entry.js.map