import { r as t, g as i, h as e, H as s, a as n } from "./p-9b9ccd0c.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";

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

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

import { v as r } from "./p-b32b6b1f.js";

const d = 'button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;grid-template-rows:max-content 1fr max-content;block-size:100%;overflow:auto}.section{display:contents}.main{display:grid;grid-template-rows:1fr max-content;overflow:auto}.field-group-name-description-module{grid-template-areas:"name-label name-input" "description-label description-input" "module-label module-entity-selector";grid-template-columns:max-content 1fr}.name-label{grid-area:name-label}.name-input{grid-area:name-input}.description-label{grid-area:description-label}.description-input{grid-area:description-input}.module-label{grid-area:module-label}.module-entity-selector{grid-area:module-entity-selector}.radio-file-input-wrapper{grid-template-columns:max-content 1fr}div.field-file-input{grid-template-columns:1fr max-content}.json-area{display:grid;grid-template-rows:1fr max-content;overflow:auto}.slotted-container{overflow:auto;block-size:100%}.assume-varchar-checkbox{margin-inline-start:16px;margin-block-end:16px;inline-size:max-content}.input-file{display:grid;grid-template-columns:1fr max-content}.radio-group{gap:30px !important}.tooltip{height:0px}';

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

var f, p, u, m, b, v, g, w, y, k, x, M, W, j, C, E, T, F, z, P, I, L;

const S = [ "resets/box-sizing", "components/tab", "components/tooltip", "utils/form--full", "utils/layout", "utils/typography", "utils/spacing", "chameleon/scrollbar" ];

const V = o({
  category: "gemini-tools",
  name: "file",
  colorType: "primary"
});

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

const A = class {
  constructor(s) {
    t(this, s);
    f.set(this, void 0);
    p.set(this, {
      name: "",
      description: "",
      assumeVarcharForNull: false,
      parentId: "",
      json: ""
    });
    u.set(this, []);
    m.set(this, i(`./gx-ide-assets/json-import/shortcuts.json`));
    b.set(this, void 0);
    v.set(this, void 0);
    g.set(this, void 0);
    w.set(this, void 0);
    y.set(this, void 0);
    k.set(this, void 0);
    x.set(this, void 0);
    M.set(this, (() => {
      const t = [ h(this, k, "f"), h(this, y, "f") ];
      t.forEach((t => {
        if (t.id) {
          this.validatableControls.set(t.id, {
            reference: t,
            hasError: false,
            message: undefined
          });
        }
      }));
    }));
    W.set(this, (t => {
      var i, s, n;
      return ((s = (i = this.validatableControls) === null || i === void 0 ? void 0 : i.get(t === null || t === void 0 ? void 0 : t.id)) === null || s === void 0 ? void 0 : s.hasError) && ((n = this.validatableControls.get(t.id)) === null || n === void 0 ? void 0 : n.message) && e("ch-tooltip", {
        class: "tooltip",
        actionElement: t,
        blockAlign: a.tooltipSettings.blockAlign,
        inlineAlign: a.tooltipSettings.inlineAlign,
        delay: a.tooltipSettings.delay
      }, this.validatableControls.get(t.id).message);
    }));
    j.set(this, (() => {
      var t, i;
      const e = ((i = (t = h(this, k, "f")) === null || t === void 0 ? void 0 : t.value) === null || i === void 0 ? void 0 : i.trim()) || "";
      const s = this.radioGroupValue === "file" ? this.fileName : this.jsonContent;
      const n = this.validateNameCallback ? this.validateNameCallback(e) : Boolean(e);
      const o = this.radioGroupValue === "file" ? Boolean(this.fileName) : this.validateJSONCallback ? this.validateJSONCallback(s) : false;
      this.isFormValid = n && o;
    }));
    C.set(this, (() => {
      h(this, j, "f").call(this);
    }));
    E.set(this, (() => {
      var t;
      this.radioGroupValue = h(this, x, "f").value;
      if (this.radioGroupValue === "file") {
        h(this, b, "f").value = "false";
      } else {
        h(this, p, "f").json = null;
        h(this, F, "f").call(this);
        h(this, j, "f").call(this);
      }
      (t = this.modeChangeCallback) === null || t === void 0 ? void 0 : t.call(this, this.radioGroupValue);
    }));
    T.set(this, (() => {
      var t;
      h(this, p, "f").name = h(this, k, "f").value;
      h(this, p, "f").description = h(this, g, "f").value;
      h(this, p, "f").parentId = (t = h(this, y, "f").value) === null || t === void 0 ? void 0 : t.id;
      h(this, p, "f").assumeVarcharForNull = h(this, b, "f").value === "true";
      this.confirmCallback(h(this, p, "f")).then((t => {
        this.validatableControls = r(t, this.validatableControls);
      }));
    }));
    F.set(this, (() => {
      var t;
      h(this, p, "f").json = null;
      h(this, w, "f").value = null;
      this.fileName = null;
      (t = this.fileChangeCallback) === null || t === void 0 ? void 0 : t.call(this, null);
      h(this, j, "f").call(this);
    }));
    z.set(this, (t => {
      var i, e;
      const s = t.target;
      if (((i = s.files) === null || i === void 0 ? void 0 : i.length) > 0 && this.radioGroupValue === "file") {
        h(this, p, "f").json = s.files[0];
        this.fileName = s.files[0].name;
        (e = this.fileChangeCallback) === null || e === void 0 ? void 0 : e.call(this, s.files[0]);
        h(this, j, "f").call(this);
      }
    }));
    P.set(this, (() => {
      h(this, w, "f").click();
    }));
    I.set(this, (() => {
      h(this, j, "f").call(this);
    }));
    L.set(this, (t => {
      const i = t.target.assignedElements();
      if (i.length > 0) {
        const t = i[0];
        t.addEventListener("json-content-change", (t => {
          if (this.radioGroupValue === "text") {
            this.jsonContent = t.detail.content;
            h(this, I, "f").call(this);
          }
        }));
      }
    }));
    this.fileName = undefined;
    this.radioGroupValue = "file";
    this.isFormValid = false;
    this.jsonContent = "";
    this.validatableControls = new Map;
    this.cancelCallback = undefined;
    this.confirmCallback = undefined;
    this.defaultParent = undefined;
    this.defaultRadioValue = undefined;
    this.parent = undefined;
    this.selectModuleCallback = undefined;
    this.modeChangeCallback = undefined;
    this.fileChangeCallback = undefined;
    this.validateNameCallback = undefined;
    this.validateJSONCallback = undefined;
    this.onJsonContentChange = undefined;
  }
  async componentWillLoad() {
    c(this, f, await l.getComponentStrings(this.el), "f");
    c(this, u, [ {
      value: "file",
      caption: h(this, f, "f").header.filePathLabel
    }, {
      value: "text",
      caption: h(this, f, "f").main.jsonAreaLabel
    } ], "f");
  }
  componentDidLoad() {
    h(this, M, "f").call(this);
  }
  /**
     * Suspends or reactivates the shortcuts
     */  async suspendShortcuts(t) {
    h(this, v, "f").suspend = t;
  }
  render() {
    return e(s, {
      class: "widget"
    }, e("ch-theme", {
      model: S
    }), e("ch-shortcuts", {
      src: h(this, m, "f"),
      ref: t => c(this, v, t, "f")
    }), e("section", {
      class: "section"
    }, e("header", {
      class: "header field-group spacing-body dialog-header-with-border"
    }, e("div", {
      class: "field-group field-group-name-description-module"
    }, e("label", {
      // name
      class: "label name-label",
      htmlFor: "input-name"
    }, h(this, f, "f").header.nameFieldLabel), e("ch-edit", {
      class: "input name-input",
      id: "input-name",
      ref: t => c(this, k, t, "f"),
      onInput: h(this, C, "f")
    }), h(this, W, "f").call(this, h(this, k, "f")), e("label", {
      // description
      class: "label description-label",
      htmlFor: "input-description"
    }, h(this, f, "f").header.descriptionFieldLabel), e("ch-edit", {
      class: "input description-input",
      id: "input-description",
      ref: t => c(this, g, t, "f")
    }), e("label", {
      // module/folder
      class: "label module-label",
      htmlFor: "input-module"
    }, h(this, f, "f").header.moduleFolderLabel), e("gx-ide-entity-selector", {
      class: "module module-entity-selector",
      id: "module",
      value: this.defaultParent,
      ref: t => c(this, y, t, "f"),
      labelPosition: "none",
      defaultValue: this.defaultParent,
      selectEntityCallback: this.selectModuleCallback
    }), h(this, W, "f").call(this, h(this, y, "f"))), e("div", {
      class: "radio-file-input-wrapper field-group"
    }, e("ch-radio-group-render", {
      // file url/text
      class: "radio-group",
      model: h(this, u, "f"),
      onChange: h(this, E, "f"),
      value: this.defaultRadioValue,
      ref: t => c(this, x, t, "f")
    }), e("div", {
      class: "field field-inline field-file-input"
    }, e("ch-edit", {
      autoFocus: true,
      id: "file-name",
      class: "input",
      part: "file-name",
      type: "text",
      value: this.fileName,
      readonly: true,
      placeholder: h(this, f, "f").header.fileNamePlaceholder,
      startImgSrc: V,
      disabled: this.radioGroupValue !== "file"
    }), e("input", {
      hidden: true,
      type: "file",
      accept: ".json",
      onChange: h(this, z, "f"),
      ref: t => c(this, w, t, "f")
    }), e("div", {
      class: "buttons-spacer"
    }, e("button", {
      "aria-label": h(this, f, "f").header.removeFileSelection,
      title: h(this, f, "f").header.removeFileSelection,
      id: "reset-all-button",
      class: "button-tertiary button-icon-only",
      part: "reset-all-button",
      onClick: h(this, F, "f"),
      disabled: this.radioGroupValue !== "file"
    }, e("ch-image", {
      class: "icon-m",
      src: _
    })), e("button", {
      id: "select-file-load-button",
      class: "button-primary",
      part: "select-file-load-button",
      onClick: h(this, P, "f"),
      disabled: this.radioGroupValue !== "file"
    }, h(this, f, "f").header.selectfileButton))))), e("div", {
      class: "main field-group"
    }, e("div", {
      class: "json-area"
    }, e("div", {
      class: "slotted-container scrollable"
    }, e("slot", {
      name: "JsonTextEditor",
      onSlotchange: h(this, L, "f")
    }))), e("ch-checkbox", {
      class: "checkbox assume-varchar-checkbox",
      caption: h(this, f, "f").main.checkBoxLabel,
      checkedValue: "true",
      ref: t => c(this, b, t, "f")
    })), e("footer", {
      class: "dialog-footer dialog-footer-with-border spacing-body-block-end spacing-body-inline"
    }, e("div", {
      class: "buttons-spacer"
    }, e("button", {
      class: "button-secondary",
      id: "button-cancel",
      onClick: this.cancelCallback,
      part: "button-cancel"
    }, h(this, f, "f").footer.btnCancel), e("button", {
      class: "button-primary",
      id: "button-ok",
      onClick: h(this, T, "f"),
      part: "button-ok",
      disabled: !this.isFormValid
    }, h(this, f, "f").footer.btnOk)))));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/json-import" ];
  }
  get el() {
    return n(this);
  }
};

f = new WeakMap, p = new WeakMap, u = new WeakMap, m = new WeakMap, b = new WeakMap, 
v = new WeakMap, g = new WeakMap, w = new WeakMap, y = new WeakMap, k = new WeakMap, 
x = new WeakMap, M = new WeakMap, W = new WeakMap, j = new WeakMap, C = new WeakMap, 
E = new WeakMap, T = new WeakMap, F = new WeakMap, z = new WeakMap, P = new WeakMap, 
I = new WeakMap, L = new WeakMap;

A.style = d;

export { A as gx_ide_json_import };
//# sourceMappingURL=p-0e4daeb7.entry.js.map