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

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

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

const mapKbsModelToActionListModel = t => {
  const i = [];
  t.forEach((t => {
    i.push({
      id: t.id,
      type: "actionable",
      caption: t.name
    });
  }));
  return i;
};

const c = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;block-size:100%;grid-template-rows:max-content 1fr max-content}.section{display:contents}header{display:grid;grid-template-rows:max-content;grid-template-columns:1fr 1fr max-content}.button-change{align-self:center;justify-self:end}.main{display:grid;grid-template-columns:1fr;grid-template-rows:max-content 1fr max-content max-content;position:relative}.search-kbs{inline-size:50%}.versions-container{grid-auto-rows:max-content}.versions-container__input{display:grid;grid-template-columns:1fr max-content;gap:var(--spacing-gap-m)}.location-custom-wrapper{display:flex;align-items:center;gap:var(--spacing-gap-xs);flex-grow:1;min-inline-size:0}.location-field{flex-grow:1;min-inline-size:0}.location-field>.input{inline-size:100%}";

var d = undefined && undefined.__classPrivateFieldSet || function(t, i, s, e, a) {
  if (e === "m") throw new TypeError("Private method is not writable");
  if (e === "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 e === "a" ? a.call(t, s) : a ? a.value = s : i.set(t, s), s;
};

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

var p, u, m, b, v, w, g, y, k, M, W, x, T, j, _, C, S, L, z, E, I, $, A, N, P, F, K, V, B;

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

const U = o({
  category: "system",
  name: "information",
  colorType: "on-surface"
});

const H = o({
  category: "system",
  name: "folder",
  colorType: "primary"
});

const q = "default";

const G = "custom";

const J = class {
  constructor(e) {
    t(this, e);
    p.set(this, o({
      category: "system",
      name: "search",
      colorType: "interactive"
    }));
    u.set(this, o({
      category: "system",
      name: "more-horizontal",
      colorType: "interactive"
    }));
    m.set(this, [ {
      value: "Trunk",
      caption: "Trunk Version"
    }, {
      value: "All",
      caption: "All Versions"
    }, {
      value: "Select",
      caption: "Select Version"
    } ]);
    b.set(this, void 0);
    v.set(this, []);
    w.set(this, []);
    g.set(this, void 0);
    y.set(this, i(`./gx-ide-assets/create-kb-from-server/shortcuts.json`));
    k.set(this, void 0);
    M.set(this, false);
    W.set(this, void 0);
    x.set(this, void 0);
    T.set(this, void 0);
    j.set(this, (() => {
      this.cancelCallback();
    }));
    _.set(this, (async () => {
      this.changeConnectionCallback({
        authenticationType: this.connectionData.authenticationType,
        serverUrl: this.connectionData.serverUrl,
        userName: this.connectionData.userName,
        userPassword: this.connectionData.userPassword
      });
    }));
    C.set(this, (t => {
      this.locationMode = t.detail;
      if (this.locationMode === q) {
        this.kbLocation = "";
      }
    }));
    S.set(this, (async () => {
      const t = await this.selectLocationCallback();
      if (t) {
        this.kbLocation = t;
      }
    }));
    L.set(this, (t => {
      this.kbLocation = t.detail;
    }));
    z.set(this, (async () => {
      if (this.versionSelectedType !== "Select") {
        d(this, w, [], "f");
      }
      this.createKBCallback({
        selectedKB: f(this, k, "f"),
        versionSelected: this.versionSelectedType,
        localKBName: this.localKbNameInputValue,
        kbLocation: this.locationMode === G ? this.kbLocation || undefined : undefined,
        versionList: f(this, w, "f")
      }).then((t => {
        this.validatableControls = l(t, this.validatableControls);
      }));
    }));
    // TODO: evaluate if this should be a global helper function.
    // It is used on other dialogs as well.
        E.set(this, (t => {
      var i, e, a;
      return ((e = (i = this.validatableControls) === null || i === void 0 ? void 0 : i.get(t === null || t === void 0 ? void 0 : t.id)) === null || e === void 0 ? void 0 : e.hasError) && ((a = this.validatableControls.get(t.id)) === null || a === void 0 ? void 0 : a.message) && s("ch-tooltip", {
        class: "tooltip",
        actionElement: t,
        blockAlign: r.tooltipSettings.blockAlign,
        inlineAlign: r.tooltipSettings.inlineAlign,
        delay: r.tooltipSettings.delay
      }, this.validatableControls.get(t.id).message);
    }));
    I.set(this, (t => {
      this.filterValue = t.detail.toLowerCase();
      this.kbsFilteredActionListModel = f(this, v, "f").filter((t => t.caption.toLowerCase().includes(this.filterValue)));
    }));
    $.set(this, (async () => {
      await this.getGXserverKBsCallback({
        authenticationType: this.connectionData.authenticationType,
        serverUrl: this.connectionData.serverUrl,
        userName: this.connectionData.userName,
        userPassword: this.connectionData.userPassword
      }).then((t => {
        d(this, v, mapKbsModelToActionListModel(t), "f");
        this.kbsFilteredActionListModel = f(this, v, "f");
        this.filterValue = "";
      }));
    }));
    A.set(this, (() => {
      // populate validatableControls with the controls that could have errors.
      const t = [ f(this, T, "f") ];
      t.forEach((t => {
        if (t.id) {
          this.validatableControls.set(t.id, {
            reference: t,
            hasError: false,
            message: undefined
          });
        }
      }));
    }));
    N.set(this, (t => {
      this.localKbNameInputValue = t.detail;
      d(this, M, true, "f");
    }));
    P.set(this, (async () => {
      if (this.selectKBVersionsCallback) {
        await this.selectKBVersionsCallback(f(this, k, "f")).then((t => {
          if (t === null || t === void 0 ? void 0 : t.length) {
            d(this, w, t.map((t => ({
              id: t.id,
              name: t.name
            }))), "f");
            if (t.length === 1 && f(this, w, "f")[0].id === 0) {
              this.localKbNameInputValue = f(this, k, "f");
              this.versionsValueInput = f(this, b, "f").kb.versionsPlaceholder;
            } else if (t.length > 1) {
              this.localKbNameInputValue = f(this, k, "f");
              this.versionsValueInput = `${t.length.toString()} ${f(this, b, "f").kb.versionSelectedFieldValue}`;
            } else {
              this.localKbNameInputValue = `${f(this, k, "f")}_${f(this, w, "f")[0].name}`;
              this.versionsValueInput = `${t[0].name} ${f(this, b, "f").kb.oneVersionSelectedFieldValue}`;
            }
          }
        }));
      }
    }));
    F.set(this, (t => {
      var i;
      const s = (i = t.detail[0]) === null || i === void 0 ? void 0 : i.item;
      if (s === undefined) {
        this.enableSelectVersionsButton = false;
        d(this, k, undefined, "f");
        return;
      }
      this.enableSelectVersionsButton = true;
      d(this, k, s.id, "f");
      if (f(this, M, "f")) {
        return;
      }
      this.localKbNameInputValue = s.caption;
      if (this.versionSelectedType === "Select") {
        this.versionsValueInput = "";
        d(this, w, [], "f");
      }
    }));
    K.set(this, (t => {
      this.versionSelectedType = t.detail;
    }));
    V.set(this, (t => {
      t.sort(((t, i) => {
        var s, e;
        return (s = t.caption) === null || s === void 0 ? void 0 : s.toLocaleLowerCase().localeCompare((e = i.caption) === null || e === void 0 ? void 0 : e.toLocaleLowerCase());
      }));
    }));
    B.set(this, (() => s("footer", {
      class: "footer dialog-footer-with-border spacing-body-inline spacing-body-block-end"
    }, s("div", {
      class: "buttons-spacer"
    }, s("button", {
      // cancel button
      class: "button-secondary",
      onClick: f(this, j, "f"),
      part: "button button-cancel"
    }, f(this, b, "f").footer.cancel), s("button", {
      // create kb button
      class: "button-primary",
      onClick: this.enableSelectVersionsButton && f(this, z, "f"),
      disabled: !this.enableSelectVersionsButton,
      part: "button button-create-kb"
    }, f(this, b, "f").footer.createKb)))));
    this.enableSelectVersionsButton = false;
    this.localKbNameInputValue = "";
    this.loading = true;
    this.filterValue = "";
    this.kbsFilteredActionListModel = [];
    this.validatableControls = new Map;
    this.versionSelectedType = undefined;
    this.versionsValueInput = "";
    this.locationMode = q;
    this.kbLocation = undefined;
    this.canSetLocation = false;
    this.connectionData = undefined;
    this.cancelCallback = undefined;
    this.changeConnectionCallback = undefined;
    this.createKBCallback = undefined;
    this.getGXserverKBsCallback = undefined;
    this.selectLocationCallback = undefined;
    this.selectKBVersionsCallback = undefined;
  }
  async componentDidLoad() {
    await f(this, $, "f").call(this);
    this.loading = false;
  }
  async componentWillLoad() {
    d(this, b, await h.getComponentStrings(this.el), "f");
    d(this, W, [ {
      value: q,
      caption: f(this, b, "f").kb.kbLocationDefault
    }, {
      value: G,
      caption: f(this, b, "f").kb.kbLocationCustom
    } ], "f");
  }
  /**
     * Suspends or reactivates the shortcuts
     */  async suspendShortcuts(t) {
    if (t) {
      f(this, g, "f").suspend = true;
    } else {
      f(this, g, "f").suspend = false;
    }
  }
  render() {
    return s(a, {
      class: "widget"
    }, s("ch-theme", {
      model: D
    }), s("ch-shortcuts", {
      src: f(this, y, "f"),
      ref: t => d(this, g, t, "f")
    }), s("section", {
      class: "section"
    }, s("header", {
      class: "header dialog-header-with-border space-body spacing-body-inline spacing-body-block-start"
    }, s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label"
    }, f(this, b, "f").header.serverUrl), s("p", null, this.connectionData.serverUrl)), s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label"
    }, f(this, b, "f").header.user), s("p", null, this.connectionData.userName)), s("button", {
      id: "change-connection-button",
      class: "button-tertiary button-change",
      onClick: f(this, _, "f")
    }, f(this, b, "f").header.change)), s("section", {
      class: "main field-group spacing-body"
    }, this.loading ? s("gx-ide-loader", {
      loaderTitle: f(this, b, "f").loader.title,
      description: f(this, b, "f").loader.description,
      show: true
    }) : s(e, null, s("ch-edit", {
      class: "input search-kbs",
      id: "local-kb-name",
      startImgSrc: f(this, p, "f"),
      type: "search",
      onInput: f(this, I, "f"),
      placeholder: f(this, b, "f").kb.searchKbsPlaceholder
    }), f(this, v, "f").length === 0 || this.kbsFilteredActionListModel.length === 0 ? s("div", {
      class: "list-box"
    }, s("gx-ide-empty-state", {
      stateIconSrc: U,
      stateTitle: f(this, b, "f").emptyKBsText,
      isAnimated: true
    })) : s("ch-action-list-render", {
      selection: "single",
      class: "list-box",
      onSelectedItemsChange: f(this, F, "f"),
      model: this.kbsFilteredActionListModel,
      sortItemsCallback: f(this, V, "f")
    }), s("div", {
      class: "versions-container field-group"
    }, s("ch-radio-group-render", {
      class: "radio-group",
      model: f(this, m, "f"),
      onChange: f(this, K, "f"),
      value: f(this, m, "f")[0].value,
      ref: t => {
        d(this, x, t, "f");
        if (f(this, x, "f")) {
          this.versionSelectedType = f(this, x, "f").value;
        }
      }
    }), this.versionSelectedType === "Select" && s("div", {
      class: "versions-container__item field-group"
    }, s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label",
      htmlFor: "control-id-1"
    }, f(this, b, "f").kb.versionsLabel), s("div", {
      class: "versions-container__input"
    }, s("ch-edit", {
      class: "input",
      readonly: true,
      placeholder: this.enableSelectVersionsButton ? f(this, b, "f").kb.versionsPlaceholder : f(this, b, "f").kb.versionsPlaceholderDisabled,
      value: this.versionsValueInput
    }), s("button", {
      id: "select-version-button",
      class: "button-tertiary button-icon-only",
      onClick: f(this, P, "f"),
      disabled: !this.enableSelectVersionsButton
    }, s("ch-image", {
      src: f(this, u, "f"),
      class: "icon-m",
      disabled: !this.enableSelectVersionsButton
    })))))), s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label",
      htmlFor: "localKbName"
    }, f(this, b, "f").kb.localKbNameLabel), s("ch-edit", {
      // local kb name
      class: "input",
      id: "localKbName",
      value: this.localKbNameInputValue,
      onInput: f(this, N, "f"),
      placeholder: f(this, b, "f").kb.localKbNamePlaceholder,
      ref: t => {
        d(this, T, t, "f");
        if (f(this, T, "f")) {
          f(this, A, "f").call(this);
        }
      }
    }), f(this, E, "f").call(this, f(this, T, "f"))), this.canSetLocation && s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label",
      htmlFor: "kbLocation"
    }, f(this, b, "f").kb.kbLocation), s("ch-radio-group-render", {
      class: "radio-group",
      id: "kbLocation",
      model: f(this, W, "f"),
      value: q,
      onChange: f(this, C, "f")
    }), this.locationMode === G && s("div", {
      class: "location-custom-wrapper"
    }, s("div", {
      class: "location-field"
    }, s("ch-edit", {
      class: "input",
      value: this.kbLocation,
      id: "kbLocation",
      onInput: f(this, L, "f")
    })), s("button", {
      class: "button-tertiary button-icon-only",
      "aria-label": f(this, b, "f").kb.selectLocationButton,
      title: f(this, b, "f").kb.selectLocationButton,
      onClick: f(this, S, "f")
    }, s("ch-image", {
      class: "icon-m",
      type: "mask",
      src: H
    })))))), f(this, B, "f").call(this)));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/create-kb-from-server" ];
  }
  get el() {
    return n(this);
  }
};

p = new WeakMap, u = new WeakMap, m = new WeakMap, b = new WeakMap, v = new WeakMap, 
w = new WeakMap, g = new WeakMap, y = new WeakMap, k = new WeakMap, M = new WeakMap, 
W = new WeakMap, x = new WeakMap, T = new WeakMap, j = new WeakMap, _ = new WeakMap, 
C = new WeakMap, S = new WeakMap, L = new WeakMap, z = new WeakMap, E = new WeakMap, 
I = new WeakMap, $ = new WeakMap, A = new WeakMap, N = new WeakMap, P = new WeakMap, 
F = new WeakMap, K = new WeakMap, V = new WeakMap, B = new WeakMap;

J.style = c;

export { J as gx_ide_create_kb_from_server };
//# sourceMappingURL=p-cf61384e.entry.js.map