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

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

const o = "type";

const r = "object";

const convertObjectDataToTreeItem = (t, i) => i.map((i => ({
  id: i.id,
  caption: i.name,
  startImgSrc: t,
  expanded: true,
  leaf: true,
  metadata: r
})));

const convertObjectTypeDataToTreeView = t => {
  const i = [];
  if (!t) {
    return i;
  }
  for (const e of t) {
    if (e.items.length > 0) {
      i.push({
        id: e.id,
        caption: e.name,
        startImgSrc: e.icon,
        expanded: true,
        leaf: false,
        metadata: o,
        items: convertObjectDataToTreeItem(e.icon, e.items)
      });
    }
  }
  return i;
};

const createArrayOfItems = (t, i) => {
  // The resulting array with 'items' property added to each type
  const e = i.map((i => {
    // Filter objects that match the current type id
    const e = t.filter((t => t.type === i.id));
    // Return a new object type with the 'items' property
        return Object.assign(Object.assign({}, i), {
      items: e
    });
  }));
  const s = convertObjectTypeDataToTreeView(e);
  return s;
};

const h = ":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 max-content}.header{display:grid;padding:var(--gxg-container--padding);gap:var(--spacing-gap-l);grid-template-columns:1fr auto;margin-block-end:16px}.header :nth-child(2){align-self:self-end}.deploy-properties{display:grid;grid-auto-rows:max-content;grid-template-columns:max-content 1fr max-content;align-items:center;border-block-start:var(--section-common-border);padding-block-start:16px}.label.target-types{grid-column:1}.target-types-combo{grid-column:2}.target-types-button-checkbox-wrapper{grid-column:3}.label.application-server{grid-column:1}.application-server-combo{grid-column:2}.label.generator{grid-column:1}.generator-combo{grid-column:2}.target-type__description{grid-column:2}.label.display-name{grid-column:1}.display-name-input{grid-column:2}.footer{margin-block-start:16px}";

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

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

var c, f, p, u, m, b, g, v, w, y, k, x, M, W, _, j, C, T, I, z, D, E, H, O, S, L, P, F, R, V, $, A, G, N;

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

const q = "true";

const B = "false";

const J = class {
  constructor(s) {
    t(this, s);
    this.componentDidLoadEvent = i(this, "componentDidLoadEvent", 7);
    this.componentDidRenderFirstTime = i(this, "componentDidRenderFirstTime", 7);
    c.add(this);
    /**
         * The component hard-coded strings translations.
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        f.set(this, void 0);
    p.set(this, false);
    u.set(this, new Map);
    m.set(this, void 0);
    b.set(this, void 0);
    g.set(this, void 0);
    v.set(this, void 0);
    w.set(this, void 0);
    y.set(this, void 0);
    k.set(this, void 0);
    x.set(this, (() => {
      if (this.defaultTargetTypeId) {
        const t = this.targetTypes.find((t => t.id === this.defaultTargetTypeId));
        if (t) {
          return t;
        }
      }
      return this.targetTypes[0];
    }));
    M.set(this, (() => {
      var t;
      this.noObjects = !!(((t = this.treeModel) === null || t === void 0 ? void 0 : t.length) === 0 || !this.treeModel);
    }));
    W.set(this, (async t => {
      await l(this, _, "f").call(this, t.detail);
      l(this, C, "f").call(this);
    }));
    _.set(this, (async t => {
      if (t === this.newDeploymentUnitId) {
        // New deployment unit should be created before executing the deploy action.
        return;
      }
      d(this, m, t, "f");
      const i = await this.getDeploymentUnitObjectsCallback(t);
      this.addedObjects = [ ...i ];
      this.treeModel = createArrayOfItems(this.addedObjects, this.allObjectTypes);
    }));
    j.set(this, (async () => {
      if (this.createDeploymentUnitCallback) {
        const t = await this.createDeploymentUnitCallback();
        if (!t) {
          return;
        }
        if (!this.deploymentUnits.find((i => i.id === t.id))) {
          // Update deployment units:
          this.deploymentUnits.unshift(t);
          // Update combo:
                    const i = l(this, P, "f").call(this, t);
          const e = [ i, ...l(this, y, "f").model ];
          l(this, y, "f").model = e;
        }
        l(this, y, "f").value = t.id;
        // Trigger selection callback:
                await l(this, _, "f").call(this, t.id);
      }
    }));
    C.set(this, (() => {
      if (this.optionsCallback) {
        this.optionsCallback(l(this, y, "f").value, l(this, g, "f").value);
      }
    }));
    T.set(this, (() => {
      const t = [ ...this.allObjectTypes ];
      this.addedObjects.forEach((i => {
        const e = this.allObjectTypes.find((t => t.id === i.type));
        if (!e) {
          t.push({
            id: i.type,
            name: i.type,
            icon: ""
          });
        }
      }));
      this.allObjectTypes = [ ...t ];
    }));
    I.set(this, (async () => {
      if (this.addObjectsCallback) {
        const t = await this.addObjectsCallback();
        this.addedObjects = [ ...t, ...this.addedObjects ];
        l(this, T, "f").call(this);
        this.treeModel = createArrayOfItems(this.addedObjects, this.allObjectTypes);
      }
    }));
    z.set(this, (async () => {
      var t, i;
      if (l(this, y, "f").value === this.newDeploymentUnitId) {
        await l(this, j, "f").call(this);
      }
      const e = {
        targetId: l(this, g, "f").value,
        applicationServerId: l(this, D, "f").call(this),
        displayName: (t = l(this, k, "f")) === null || t === void 0 ? void 0 : t.value,
        generatorId: (i = l(this, w, "f")) === null || i === void 0 ? void 0 : i.value,
        onlyPackage: l(this, b, "f") ? l(this, b, "f").value === q : undefined,
        objects: this.checkedObjectsIds
      };
      if (this.deployCallback) {
        this.allowDeploy = false;
        await this.deployCallback(e);
        this.allowDeploy = true;
      }
    }));
    D.set(this, (() => {
      var t, i, e;
      if ((t = l(this, v, "f")) === null || t === void 0 ? void 0 : t.value) {
        return l(this, v, "f").value;
      }
      return ((i = this.selectedDeployTargetData) === null || i === void 0 ? void 0 : i.applicationServers.length) > 0 ? (e = this.selectedDeployTargetData) === null || e === void 0 ? void 0 : e.applicationServers[0].id : undefined;
    }));
    E.set(this, (t => {
      const i = t.detail;
      this.selectedDeployTargetData = this.targetTypes.find((t => t.id === i)) || null;
      if (!this.selectedDeployTargetData.canCreatePackage && l(this, b, "f").value === q) {
        l(this, b, "f").value = B;
      }
      l(this, C, "f").call(this);
    }));
    O.set(this, (t => {
      const i = [ ...t.detail.values() ];
      this.checkedObjectsIds = i.filter((t => t.item.checked && t.item.metadata === r)).map((t => t.item.id));
    }));
    S.set(this, (() => {
      if (this.noObjects) {
        return e("gx-ide-empty-state", {
          isAnimated: false,
          stateTitle: l(this, f, "f").main.noObjectsToDisplay,
          key: "no-objects-empty-state",
          stateIconSrc: "objects/object"
        });
      }
      return e("ch-tree-view-render", {
        class: "tree-view",
        model: this.treeModel,
        dragDisabled: true,
        dropDisabled: true,
        toggleCheckboxes: true,
        showLines: "last",
        checked: true,
        checkbox: true,
        onCheckedItemsChange: l(this, O, "f")
      });
    }));
    L.set(this, (t => t.map((t => l(this, P, "f").call(this, t)))));
    P.set(this, (t => ({
      caption: t.name,
      value: t.id
    })));
    F.set(this, ((t, i = false) => {
      var s;
      const a = t.label.replace(/ /g, "-").toLowerCase();
      const n = `label ${a}`;
      const o = t.class ? `combo-box ${t.class}` : "combo-box";
      const r = [ e("label", {
        class: n,
        htmlFor: a
      }, t.label), e("ch-combo-box-render", {
        class: o,
        value: t.value ? t.value : (s = t.baseModel[0]) === null || s === void 0 ? void 0 : s.id,
        model: l(this, L, "f").call(this, t.baseModel),
        id: a,
        ref: t.refCallback,
        onInput: t.onInputCallback
      }) ];
      return i ? e("div", {
        class: "field field-inline"
      }, r) : r;
    }));
    R.set(this, (() => e("div", {
      slot: "header",
      class: "header dialog-header-with-border"
    }, l(this, F, "f").call(this, {
      id: "deploymentUnits",
      baseModel: this.deploymentUnits,
      label: l(this, f, "f").header.objectsToDeploy,
      value: l(this, m, "f"),
      refCallback: t => {
        d(this, y, t, "f");
      },
      onInputCallback: l(this, W, "f")
    }, true), e("button", {
      class: "button-primary",
      onClick: l(this, I, "f")
    }, l(this, f, "f").main.addButton))));
    V.set(this, (() => {
      var t;
      return l(this, F, "f").call(this, {
        id: "application-servers",
        class: "application-server-combo",
        baseModel: (t = this.selectedDeployTargetData) === null || t === void 0 ? void 0 : t.applicationServers,
        label: l(this, f, "f").main.applicationServer,
        refCallback: t => {
          d(this, v, t, "f");
        }
      });
    }));
    $.set(this, (() => {
      var t;
      return l(this, F, "f").call(this, {
        id: "generator",
        class: "generator-combo",
        baseModel: (t = this.selectedDeployTargetData) === null || t === void 0 ? void 0 : t.generators,
        label: l(this, f, "f").main.generator,
        refCallback: t => {
          d(this, w, t, "f");
        }
      });
    }));
    A.set(this, (() => {
      var t;
      return [ l(this, F, "f").call(this, {
        id: "targetTypes",
        class: "target-types-combo",
        baseModel: this.targetTypes,
        label: l(this, f, "f").main.targetTypes,
        value: this.selectedDeployTargetData ? this.selectedDeployTargetData.id : this.defaultTargetTypeId,
        refCallback: t => {
          d(this, g, t, "f");
        },
        onInputCallback: l(this, E, "f")
      }), e("div", {
        class: "target-types-button-checkbox-wrapper buttons-spacer"
      }, e("button", {
        class: "button-tertiary button-icon-only",
        onClick: l(this, C, "f")
      }, e("ch-image", {
        class: "icon-m",
        src: "system/settings/primary"
      })), e("ch-checkbox", {
        disabled: !((t = this.selectedDeployTargetData) === null || t === void 0 ? void 0 : t.canCreatePackage),
        class: "checkbox",
        caption: l(this, f, "f").main.onlyPackageLabel,
        part: "only-package-checkbox",
        checkedValue: q,
        unCheckedValue: B,
        value: B,
        ref: t => d(this, b, t, "f")
      })) ];
    }));
    G.set(this, (() => [ e("label", {
      class: "label display-name",
      htmlFor: "display-name"
    }, l(this, f, "f").main.displayName), e("ch-edit", {
      class: "input display-name-input",
      id: "display-name",
      ref: t => {
        if (t) {
          d(this, k, t, "f");
        }
      }
    }) ]));
    N.set(this, (() => e("div", {
      slot: "footer-end",
      class: "footer dialog-footer-with-border"
    }, e("button", {
      class: "button-primary",
      onClick: l(this, z, "f"),
      disabled: !this.allowDeploy
    }, l(this, f, "f").main.deployButton))));
    this.checkedObjectsIds = [];
    this.noObjects = undefined;
    this.selectedDeployTargetData = null;
    this.addedObjects = [];
    this.allObjectTypes = undefined;
    this.treeModel = [];
    this.allowDeploy = true;
    this.deploymentUnits = undefined;
    this.targetTypes = undefined;
    this.defaultTargetTypeId = undefined;
    this.newDeploymentUnitId = undefined;
    this.objectTypes = undefined;
    this.getDeploymentUnitObjectsCallback = undefined;
    this.optionsCallback = undefined;
    this.deployCallback = undefined;
    this.addObjectsCallback = undefined;
    this.createDeploymentUnitCallback = undefined;
  }
  watchTreeModelHandler(t) {
    this.noObjects = !!(t.length === 0 || !t);
  }
  watchObjectTypesHandler(t) {
    l(this, c, "m", H).call(this, t);
  }
  async componentWillLoad() {
    d(this, f, await n.getComponentStrings(this.el), "f");
    this.selectedDeployTargetData = l(this, x, "f").call(this);
    this.allObjectTypes = [ ...this.objectTypes ];
    l(this, M, "f").call(this);
    l(this, c, "m", H).call(this, this.allObjectTypes);
    if (this.deploymentUnits.length > 0) {
      l(this, _, "f").call(this, this.deploymentUnits[0].id);
      if (this.targetTypes.length > 0 && this.optionsCallback) {
        this.optionsCallback(this.deploymentUnits[0].id, this.targetTypes[0].id);
      }
    }
  }
  componentDidRender() {
    if (!l(this, p, "f")) {
      this.componentDidRenderFirstTime.emit(l(this, f, "f").componentName);
      d(this, p, true, "f");
    }
  }
  render() {
    var t, i, a, n, o, r, h;
    return e(s, {
      class: "widget spacing-body"
    }, e("ch-theme", {
      model: U
    }), l(this, R, "f").call(this), l(this, S, "f").call(this), e("div", {
      class: "deploy-properties field-group"
    }, l(this, A, "f").call(this), ((i = (t = this.selectedDeployTargetData) === null || t === void 0 ? void 0 : t.applicationServers) === null || i === void 0 ? void 0 : i.length) > 1 && this.selectedDeployTargetData.canSelectApplicationServer ? l(this, V, "f").call(this) : [], ((n = (a = this.selectedDeployTargetData) === null || a === void 0 ? void 0 : a.generators) === null || n === void 0 ? void 0 : n.length) > 0 ? l(this, $, "f").call(this) : [], ((o = this.selectedDeployTargetData) === null || o === void 0 ? void 0 : o.description) && e("p", {
      class: "body-italic-s target-type__description"
    }, (r = this.selectedDeployTargetData) === null || r === void 0 ? void 0 : r.description), ((h = this.selectedDeployTargetData) === null || h === void 0 ? void 0 : h.canDefineDisplayName) ? l(this, G, "f").call(this) : []), l(this, N, "f").call(this));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/deployment-tool" ];
  }
  get el() {
    return a(this);
  }
  static get watchers() {
    return {
      treeModel: [ "watchTreeModelHandler" ],
      objectTypes: [ "watchObjectTypesHandler" ]
    };
  }
};

f = new WeakMap, p = new WeakMap, u = new WeakMap, m = new WeakMap, b = new WeakMap, 
g = new WeakMap, v = new WeakMap, w = new WeakMap, y = new WeakMap, k = new WeakMap, 
x = new WeakMap, M = new WeakMap, W = new WeakMap, _ = new WeakMap, j = new WeakMap, 
C = new WeakMap, T = new WeakMap, I = new WeakMap, z = new WeakMap, D = new WeakMap, 
E = new WeakMap, O = new WeakMap, S = new WeakMap, L = new WeakMap, P = new WeakMap, 
F = new WeakMap, R = new WeakMap, V = new WeakMap, $ = new WeakMap, A = new WeakMap, 
G = new WeakMap, N = new WeakMap, c = new WeakSet, H = function _GxIdeDeploymentTool_flattenObjectTypes(t) {
  t.forEach((t => {
    l(this, u, "f").set(t.id, t);
  }));
};

J.style = h;

export { J as gx_ide_deployment_tool };
//# sourceMappingURL=p-508c4bee.entry.js.map