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

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

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

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

import "lit";

import "lit/directives/when.js";

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

const convertActionToTreeViewItem = e => {
  const t = [];
  if (!e) {
    return t;
  }
  e.forEach((e => {
    const i = {
      id: e.id,
      caption: `${e.name}`,
      expanded: true,
      leaf: true,
      checkbox: true
    };
    t.push(i);
  }));
  return t;
};

const l = 'button.button-secondary{border-color:var(--color-border-neutral-default)}section{display:grid;block-size:100%;grid-template-rows:max-content 1fr max-content}.main{position:relative;display:contents}.input-file{display:flex}.field{width:100%}.dialog-header__operations,.dialog-header__description{padding-block-start:16px}.header__field-group{grid-template:"import-file-label import-file-name buttons-container" max-content "module-folder-label module-folder module-folder" max-content/max-content 1fr max-content}.module-folder-name{grid-area:module-folder}.module-folder-label{grid-area:module-folder-label}.import-file-label{grid-area:import-file-label}.header__buttons-container{grid-area:buttons-container}.section-grid{display:grid;grid-template:"top-content-operations top-content-description" max-content "operations-area operations-description" 1fr/1fr 1fr;background-color:var(--items-container__bg-color);border-style:var(--items-container__border-style);border-width:var(--items-container__border-width);border-color:var(--items-container__border-color);border-block-start:0;overflow-y:auto}.list-wrapper{grid-area:operations-area;border-inline-end:var(--section-common-border)}.label{margin-block-start:8px !important}.tree-operations::part(item__header){padding-inline-start:0}.procedure-description{grid-area:operations-description;overflow:auto;text-align:justify}.dialog-header__operations{grid-area:top-content-operations;background-color:var(--items-container__bg-color)}.dialog-header__description{grid-area:top-content-description;background-color:var(--items-container__bg-color)}.text-align-center{text-align:center}';

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

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

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

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

const T = n({
  category: "gemini-tools",
  name: "file",
  colorType: "on-surface"
});

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

const I = "allChecked";

const P = "allUnchecked";

const D = class {
  constructor(s) {
    e(this, s);
    this.componentDidRenderFirstTime = t(this, "componentDidRenderFirstTime", 7);
    h.set(this, void 0);
    p.set(this, false);
    f.set(this, i(`./gx-ide-assets/new-object/shortcuts.json`));
    u.set(this, void 0);
    b.set(this, void 0);
    m.set(this, void 0);
    g.set(this, void 0);
    // 9.LOCAL METHODS //
        v.set(this, (() => {
      if (this.cancelCallback) {
        this.cancelCallback();
      }
    }));
    w.set(this, (async () => {
      await this.importCallback(this.selectedOperations);
    }));
    y.set(this, (e => {
      if (e.detail.size === 0) {
        return;
      }
      const t = e.detail;
      const i = [ ...t.values() ].filter((e => e.item.checked));
      this.selectedOperations = i.map((e => e.item.id));
      // Evaluate "Select All" checkbox state (siguiendo el patrón de kb-manager-import)
            if (t.size === i.length) {
        this.selectAllCheckboxValue = I;
        this.selectAllCheckboxIndeterminate = false;
      } else if (i.length === 0) {
        this.selectAllCheckboxValue = P;
        this.selectAllCheckboxIndeterminate = false;
      } else {
        this.selectAllCheckboxIndeterminate = true;
      }
    }));
    k.set(this, (e => {
      if ("detail" in e && d(this, g, "f")) {
        const t = e.detail === I;
        // Usar updateAllItemsProperties como en kb-manager-import
                d(this, g, "f").updateAllItemsProperties({
          checked: t
        });
        this.selectedOperations = t ? this.operations.map((e => e.id)) : [];
        this.selectAllCheckboxValue = t ? I : P;
        this.selectAllCheckboxIndeterminate = false;
      }
    }));
    _.set(this, (e => {
      var t;
      this.selectedOperationForDescription = (t = this.operations.filter((t => {
        var i;
        return t.id === ((i = e.detail[0]) === null || i === void 0 ? void 0 : i.item.id);
      }))[0]) === null || t === void 0 ? void 0 : t.description;
    }));
    x.set(this, (() => {
      this.selectedFile = null;
      d(this, b, "f").value = null;
      this.operations = [];
      this.actionListItems = [];
      this.selectedOperationForDescription = null;
    }));
    W.set(this, (async e => {
      var t;
      const i = e.target;
      if (((t = i.files) === null || t === void 0 ? void 0 : t.length) > 0) {
        this.selectedFile = i.files[0];
        this.operations = await this.loadCallback(this.selectedFile, d(this, m, "f").value.id);
        this.actionListItems = convertActionToTreeViewItem(this.operations);
      }
    }));
    M.set(this, (() => {
      d(this, b, "f").click();
    }));
    C.set(this, (() => {
      var e;
      return o("footer", {
        class: "dialog-footer dialog-footer-space-between spacing-body-block-end spacing-body-inline"
      }, o("div", {
        class: "buttons-spacer"
      }, o("ch-checkbox", {
        id: "select-all-checkbox",
        class: "checkbox",
        checkedValue: I,
        unCheckedValue: P,
        caption: d(this, h, "f").main.selectAll,
        value: this.selectAllCheckboxValue,
        indeterminate: this.selectAllCheckboxIndeterminate,
        onInput: d(this, k, "f"),
        disabled: this.importingIsInProcess || !((e = this.operations) === null || e === void 0 ? void 0 : e.length),
        part: "select-all-checkbox"
      })), o("div", {
        class: "buttons-spacer"
      }, o("button", {
        class: "button-secondary",
        slot: "footer-end",
        part: "button-cancel",
        onClick: d(this, v, "f")
      }, d(this, h, "f").footer.cancel), o("button", {
        class: "button-primary",
        slot: "footer-end",
        part: "button-confirm",
        onClick: d(this, w, "f")
      }, d(this, h, "f").footer.import)));
    }));
    this.actionListItems = [];
    this.importingIsInProcess = false;
    this.operations = [];
    this.selectedFile = undefined;
    this.selectedOperationForDescription = undefined;
    this.selectedOperations = [];
    this.selectAllCheckboxValue = undefined;
    this.selectAllCheckboxIndeterminate = false;
    this.defaultParent = undefined;
    this.displayTitle = false;
    this.cancelCallback = undefined;
    this.importCallback = undefined;
    this.loadCallback = undefined;
    this.selectParentCallback = undefined;
  }
  componentDidRender() {
    if (!d(this, p, "f")) {
      this.componentDidRenderFirstTime.emit(d(this, h, "f").componentName);
      c(this, p, true, "f");
    }
  }
  async componentWillLoad() {
    c(this, h, await r.getComponentStrings(this.el), "f");
  }
  /**
     * Suspends or reactivates the shortcuts
     */  async suspendShortcuts(e) {
    if (e) {
      d(this, u, "f").suspend = true;
    } else {
      d(this, u, "f").suspend = false;
    }
  }
  render() {
    var e;
    return o(s, {
      class: "widget"
    }, o("ch-theme", {
      model: j
    }), o("ch-shortcuts", {
      src: d(this, f, "f"),
      ref: e => c(this, u, e, "f")
    }), o("section", null, o("header", {
      class: "header dialog-header-with-border space-body spacing-body-inline spacing-body-block-start",
      role: "banner"
    }, o("div", {
      class: "field-group header__field-group"
    }, o("div", {
      class: "import-file-label"
    }, o("div", {
      class: "field field-block"
    }, o("label", {
      class: "label",
      htmlFor: "file-name"
    }, d(this, h, "f").header.fileNameLabel))), o("div", {
      class: "input-file"
    }, o("div", {
      class: "field input-file"
    }, o("ch-edit", {
      autoFocus: true,
      id: "file-name",
      class: "input file",
      part: "file-name",
      type: "text",
      readonly: true,
      value: (e = this.selectedFile) === null || e === void 0 ? void 0 : e.name,
      placeholder: d(this, h, "f").header.fileNamePlaceholder,
      startImgSrc: T
    }), o("input", {
      hidden: true,
      type: "file",
      accept: ".json, .yaml",
      onChange: d(this, W, "f"),
      ref: e => c(this, b, e, "f")
    })), o("div", {
      class: "cancel-btn "
    }, o("button", {
      "aria-label": d(this, h, "f").header.removeFileSelection,
      title: d(this, h, "f").header.removeFileSelection,
      id: "reset-all-button",
      class: "button-tertiary button-icon-only",
      part: "reset-all-button",
      onClick: d(this, x, "f")
    }, o("ch-image", {
      class: "icon-m",
      src: E
    })))), o("div", {
      class: "header__buttons-container"
    }, o("button", {
      id: "select-file-load-button",
      class: "button-primary",
      part: "select-file-load-button",
      onClick: d(this, M, "f"),
      disabled: this.importingIsInProcess
    }, d(this, h, "f").header.selectFileButton)), o("div", {
      class: "module-folder-label"
    }, o("div", {
      class: "field field-block"
    }, o("label", {
      class: "label"
    }, d(this, h, "f").header.moduleFolderLabel))), o("div", {
      class: "field module-folder-name "
    }, o("gx-ide-entity-selector", {
      value: this.defaultParent,
      defaultValue: this.defaultParent,
      selectEntityCallback: this.selectParentCallback,
      labelPosition: "none",
      ref: e => c(this, m, e, "f"),
      class: "module-folder"
    })))), o("main", {
      class: "main"
    }, o("div", {
      class: "section-grid"
    }, o("h2", {
      id: "operations-title",
      class: "dialog-header dialog-header-with-border dialog-header__operations subtitle-regular-xs text-align-center spacing-body-inline"
    }, d(this, h, "f").main.operations), o("div", {
      class: "list-wrapper field-group spacing-body-block-start spacing-body-inline scrollable",
      role: "region",
      "aria-labelledby": "operations-title"
    }, o("ch-tree-view-render", {
      class: "tree-view tree-operations",
      model: this.actionListItems,
      "show-lines": "last",
      onCheckedItemsChange: d(this, y, "f"),
      onSelectedItemsChange: d(this, _, "f"),
      ref: e => c(this, g, e, "f")
    })), o("h2", {
      id: "description-title",
      class: "dialog-header dialog-header-with-border dialog-header__description subtitle-regular-xs text-align-center spacing-body-inline"
    }, d(this, h, "f").main.procedureDescription), o("div", {
      class: "procedure-description field-group spacing-body-block-start spacing-body-inline scrollable",
      role: "region",
      "aria-labelledby": "description-title"
    }, this.selectedOperationForDescription))), d(this, C, "f").call(this)));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/open-api-import" ];
  }
  get el() {
    return a(this);
  }
};

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

D.style = l;

export { D as gx_ide_open_api_import };
//# sourceMappingURL=p-af267991.entry.js.map