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

import { L as c } from "./p-311eedf3.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 taskDocumentsToActionListItemModel = (e, t) => {
  const s = [];
  e === null || e === void 0 ? void 0 : e.forEach(((e, i) => {
    const a = `task-${e.name}`;
    const l = e.name;
    s.push({
      id: a,
      caption: l,
      selected: t ? t.name === e.name : i === 0,
      type: "actionable"
    });
  }));
  return s;
};

/* References Types*/
/**
 * @description This function converts string[] to ComboBoxItemModel[]
 */ const convertSuggestedDocumentsToSuggestItems = e => {
  const t = [];
  if (e.length) {
    e.forEach((e => {
      const s = {
        value: e,
        caption: e
      };
      t.push(s);
    }));
  }
  return t;
};

const r = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;grid-template-columns:1fr;grid-template-rows:1fr max-content;block-size:100%;overflow:auto}.section{display:contents}.main{display:grid;grid-template-rows:max-content 1fr max-content;block-size:100%;overflow:auto}.documents__header{grid-template-columns:1fr max-content}.documents__suggest{flex:1}";

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

var h = undefined && undefined.__classPrivateFieldSet || function(e, t, 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 t === "function" ? e !== t || !a : !t.has(e)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return i === "a" ? a.call(e, s) : a ? a.value = s : t.set(e, s), s;
};

var d, u, f, b, m, g, p, w, k, v, x, y, M, W, _, C, E, T, j, I, R, q, D, V, S, z, B, N;

const A = "true";

const G = [ "resets/box-sizing", "components/list-box", "components/tabular-grid", "utils/form--full", "utils/layout", "utils/spacing", "chameleon/scrollbar" ];

const H = o({
  category: "objects",
  name: "module"
});

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

const L = o({
  category: "menus",
  name: "delete",
  colorType: "primary"
});

const O = "CH-CHECKBOX";

const F = class {
  constructor(a) {
    e(this, a);
    this.componentDidRenderFirstTime = t(this, "componentDidRenderFirstTime", 7);
    d.add(this);
    u.set(this, void 0);
    f.set(this, false);
    b.set(this, s(`./gx-ide-assets/bpm-task-documents/shortcuts.json`));
    m.set(this, void 0);
    g.set(this, void 0);
    p.set(this, void 0);
    w.set(this, void 0);
    k.set(this, void 0);
    v.set(this, void 0);
    x.set(this, void 0);
    y.set(this, void 0);
    M.set(this, void 0);
    C.set(this, (() => {
      this.cancelCallback();
    }));
    E.set(this, (() => {
      this.confirmCallback(this.documents);
    }));
    T.set(this, (async e => {
      const t = e.detail;
      this.suggestDocumentsCallback(t).then((e => {
        this.suggestedDocuments = convertSuggestedDocumentsToSuggestItems(e);
      })).catch((() => {}));
    }));
    I.set(this, (() => {
      this.documents = this.documents.filter((e => e.name !== this.selectedDocument.name));
      this.selectedDocument = null;
      n(this, D, "f").call(this);
    }));
    R.set(this, (async e => {
      if (e.detail) {
        n(this, d, "m", _).call(this, e.detail);
      }
    }));
    q.set(this, (e => {
      this.selectedDocument = this.documents.find((t => {
        var s;
        return t.name === ((s = e.detail[0]) === null || s === void 0 ? void 0 : s.item.caption);
      }));
    }));
    D.set(this, (() => {
      var e, t;
      (e = this.documents) === null || e === void 0 ? void 0 : e.sort(((e, t) => e.name.localeCompare(t.name)));
      this.documentsActionListState = taskDocumentsToActionListItemModel(this.documents, this.selectedDocument);
      this.selectedDocument = this.selectedDocument || ((t = this.documents) === null || t === void 0 ? void 0 : t[0]) || null;
    }));
    V.set(this, (async () => {
      const e = await this.selectDocumentCallback();
      if (e) {
        this.documentName = e;
        n(this, d, "m", _).call(this, e);
      }
    }));
    S.set(this, (() => {
      var e, t, s, a, l, c, o, r;
      return i("ch-tabular-grid", {
        class: "tabular-grid scrollable",
        rowSelectionMode: "none",
        keyboardNavigationMode: "focus",
        columnResizeMode: "single"
      }, i("ch-tabular-grid-columnset", {
        class: "tabular-grid-column-set"
      }, i("ch-tabular-grid-column", {
        class: "tabular-grid-column",
        columnId: "code",
        columnName: "",
        settingable: false,
        sortable: false
      }), i("ch-tabular-grid-column", {
        class: "tabular-grid-column",
        columnId: "enabled",
        settingable: false,
        sortable: false,
        columnName: n(this, u, "f").actions.enabledCheckbox
      }), i("ch-tabular-grid-column", {
        class: "tabular-grid-column",
        columnId: "required",
        settingable: false,
        sortable: false,
        columnName: n(this, u, "f").actions.requiredCheckbox
      })), i("ch-tabular-grid-row", {
        // read
        class: "tabular-grid-row",
        rowid: "read"
      }, i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, n(this, u, "f").actions.readLabel), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (e = this.selectedDocument) === null || e === void 0 ? void 0 : e.readEnabled.toString(),
        ref: e => h(this, v, e, "f")
      })), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (t = this.selectedDocument) === null || t === void 0 ? void 0 : t.readRequired.toString(),
        ref: e => h(this, x, e, "f")
      }))), i("ch-tabular-grid-row", {
        // new
        class: "tabular-grid-row",
        rowid: "read"
      }, i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, n(this, u, "f").actions.newLabel), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (s = this.selectedDocument) === null || s === void 0 ? void 0 : s.newEnabled.toString(),
        ref: e => h(this, w, e, "f")
      })), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (a = this.selectedDocument) === null || a === void 0 ? void 0 : a.newRequired.toString(),
        ref: e => h(this, k, e, "f")
      }))), i("ch-tabular-grid-row", {
        // update
        class: "tabular-grid-row",
        rowid: "read"
      }, i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, n(this, u, "f").actions.updateLabel), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (l = this.selectedDocument) === null || l === void 0 ? void 0 : l.updateEnabled.toString(),
        ref: e => h(this, y, e, "f")
      })), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (c = this.selectedDocument) === null || c === void 0 ? void 0 : c.updateRequired.toString(),
        ref: e => h(this, M, e, "f")
      }))), i("ch-tabular-grid-row", {
        // delete
        class: "tabular-grid-row",
        rowid: "read"
      }, i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, n(this, u, "f").actions.deleteLabel), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (o = this.selectedDocument) === null || o === void 0 ? void 0 : o.deleteEnabled.toString(),
        ref: e => h(this, g, e, "f")
      })), i("ch-tabular-grid-cell", {
        class: "tabular-grid-cell"
      }, i("ch-checkbox", {
        class: "checkbox",
        checkedValue: A,
        value: (r = this.selectedDocument) === null || r === void 0 ? void 0 : r.deleteRequired.toString(),
        ref: e => h(this, p, e, "f")
      }))));
    }));
    z.set(this, (() => i("gx-ide-empty-state", {
      class: "recent-objects__empty-state",
      stateIconSrc: H,
      isAnimated: n(this, f, "f"),
      stateTitle: n(this, u, "f").emptyRightPanelInfo.title
    }, i("button", {
      class: "button-secondary",
      onClick: n(this, V, "f")
    }, n(this, u, "f").emptyRightPanelInfo.buttonCaption))));
    B.set(this, (() => i("footer", {
      class: "footer dialog-footer dialog-footer-with-border spacing-body-block-end spacing-body-inline"
    }, i("div", {
      class: "buttons-spacer"
    }, i("button", {
      class: "button-secondary",
      id: "button-cancel",
      onClick: n(this, C, "f"),
      part: "button-cancel"
    }, n(this, u, "f").footer.cancelButton), i("button", {
      class: "button-primary",
      id: "button-create",
      onClick: n(this, E, "f"),
      part: "button-create"
    }, n(this, u, "f").footer.confirmButton)))));
    N.set(this, (() => [ i("div", {
      class: "documents__list spacing-body-inline"
    }, i("ch-action-list-render", {
      selection: "single",
      class: "list-box",
      model: this.documentsActionListState,
      onSelectedItemsChange: n(this, q, "f")
    })), n(this, S, "f").call(this) ]));
    this.documentsActionListState = [];
    this.documentName = null;
    this.selectedDocument = null;
    this.suggestedDocuments = undefined;
    this.documents = undefined;
    this.cancelCallback = undefined;
    this.confirmCallback = undefined;
    this.selectDocumentCallback = undefined;
    this.suggestDocumentsCallback = undefined;
  }
  async componentWillLoad() {
    h(this, u, await c.getComponentStrings(this.el), "f");
    n(this, D, "f").call(this);
  }
  componentDidRender() {
    if (!n(this, f, "f")) {
      this.componentDidRenderFirstTime.emit(n(this, u, "f").componentName);
      h(this, f, true, "f");
    }
    const e = this.el.shadowRoot;
    const t = n(this, d, "m", W).call(this, e);
    if (t) {
      t.forEach((e => {
        e.addEventListener("input", n(this, d, "m", j).bind(this));
      }));
    }
  }
  /**
     * Suspends or reactivates the shortcuts
     */  async suspendShortcuts(e) {
    if (e) {
      n(this, m, "f").suspend = true;
    } else {
      n(this, m, "f").suspend = false;
    }
  }
  render() {
    return i(a, {
      class: "widget"
    }, i("ch-theme", {
      model: G
    }), i("ch-shortcuts", {
      src: n(this, b, "f"),
      ref: e => h(this, m, e, "f")
    }), i("section", {
      class: "section"
    }, i("div", {
      class: "main field-group"
    }, i("div", {
      class: "documents__header buttons-spacer spacing-body-inline spacing-body-block-start"
    }, i("ch-combo-box-render", {
      class: "combo-box documents__suggest",
      model: this.suggestedDocuments,
      placeholder: n(this, u, "f").documents.suggestPlaceholder,
      suggest: true,
      onInput: n(this, T, "f"),
      onChange: n(this, R, "f"),
      suggestOptions: {
        alreadyProcessed: false,
        autoExpand: true,
        hideMatchesAndShowNonMatches: false,
        highlightMatchedItems: false,
        matchCase: false,
        regularExpression: false,
        strict: false
      }
    }), i("span", null, i("button", {
      class: "button-tertiary button-icon-only",
      "aria-label": n(this, u, "f").documents.addDocumentButtonLabel,
      title: n(this, u, "f").documents.addDocumentButtonLabel,
      onClick: n(this, V, "f")
    }, i("ch-image", {
      class: "icon-xs",
      src: P
    })), i("button", {
      class: "button-tertiary button-icon-only",
      "aria-label": n(this, u, "f").documents.clearDocumentButtonLabel,
      title: n(this, u, "f").documents.clearDocumentButtonLabel,
      onClick: n(this, I, "f")
    }, i("ch-image", {
      class: "icon-xs",
      src: L
    })))), this.documentsActionListState.length ? n(this, N, "f").call(this) : n(this, z, "f").call(this)), n(this, B, "f").call(this)));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/bpm-task-documents" ];
  }
  get el() {
    return l(this);
  }
};

u = new WeakMap, f = new WeakMap, b = new WeakMap, m = new WeakMap, g = new WeakMap, 
p = new WeakMap, w = new WeakMap, k = new WeakMap, v = new WeakMap, x = new WeakMap, 
y = new WeakMap, M = new WeakMap, C = new WeakMap, E = new WeakMap, T = new WeakMap, 
I = new WeakMap, R = new WeakMap, q = new WeakMap, D = new WeakMap, V = new WeakMap, 
S = new WeakMap, z = new WeakMap, B = new WeakMap, N = new WeakMap, d = new WeakSet, 
W = function _GxIdeBpmTaskDocuments_getAllCheckboxes(e) {
  const t = [];
  e.childNodes.forEach((e => {
    if (e.nodeName === O) {
      t.push(e);
    } else if (e instanceof HTMLElement) {
      t.push(...n(this, d, "m", _GxIdeBpmTaskDocuments_getAllCheckboxes).call(this, e));
    }
  }));
  return t;
}, _ = function _GxIdeBpmTaskDocuments_addDocument(e) {
  const t = this.documents.some((t => t.name === e));
  if (!t) {
    this.documents = [ ...this.documents, {
      name: e,
      deleteEnabled: false,
      deleteRequired: false,
      newEnabled: false,
      newRequired: false,
      readEnabled: false,
      readRequired: false,
      updateEnabled: false,
      updateRequired: false
    } ];
    n(this, D, "f").call(this);
  }
}, j = function _GxIdeBpmTaskDocuments_handleCheckboxChange() {
  const e = {
    name: this.selectedDocument.name,
    readEnabled: n(this, v, "f").value === A,
    readRequired: n(this, x, "f").value === A,
    newEnabled: n(this, w, "f").value === A,
    newRequired: n(this, k, "f").value === A,
    updateEnabled: n(this, y, "f").value === A,
    updateRequired: n(this, M, "f").value === A,
    deleteEnabled: n(this, g, "f").value === A,
    deleteRequired: n(this, p, "f").value === A
  };
  this.selectedDocument = e;
  this.documents = this.documents.map((e => e.name === this.selectedDocument.name ? this.selectedDocument : e));
};

F.style = r;

export { F as gx_ide_bpm_task_documents };
//# sourceMappingURL=p-4f58397f.entry.js.map