import { r as t, c as i, g as e, h as s, H as n, a } 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 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}.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)}";

var d = 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 = 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 p, u, m, b, v, w, g, k, y, M, W, x, j, T, _, C, E, S, $;

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

const z = class {
  constructor(n) {
    t(this, n);
    this.componentDidRenderFirstTime = i(this, "componentDidRenderFirstTime", 7);
    p.set(this, o({
      category: "gemini-tools",
      name: "show-more-horizontal",
      colorType: "on-surface"
    }));
    u.set(this, [ {
      value: "Trunk",
      caption: "Trunk Version"
    }, {
      value: "All",
      caption: "All Versions"
    }, {
      value: "Select",
      caption: "Select Version"
    } ]);
    m.set(this, void 0);
    b.set(this, []);
    v.set(this, false);
    w.set(this, void 0);
    g.set(this, e(`./gx-ide-assets/create-kb-from-server/shortcuts.json`));
    k.set(this, void 0);
    y.set(this, void 0);
    M.set(this, void 0);
    W.set(this, (() => {
      this.cancelCallback();
    }));
    x.set(this, (async () => {
      this.changeConnectionCallback({
        authenticationType: this.connectionData.authenticationType,
        serverUrl: this.connectionData.serverUrl,
        userName: this.connectionData.userName,
        userPassword: this.connectionData.userPassword
      });
    }));
    j.set(this, (async () => {
      if (this.versionSelectedType !== "Select") {
        d(this, b, [], "f");
      }
      this.shareKBCallback({
        name: this.kbName,
        serverUrl: this.connectionData.serverUrl,
        versionList: f(this, b, "f"),
        allVersions: this.versionSelectedType === "All"
      }).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.
        T.set(this, (t => {
      var i, e, n;
      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) && ((n = this.validatableControls.get(t.id)) === null || n === void 0 ? void 0 : n.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);
    }));
    _.set(this, (() => {
      // populate validatableControls with the controls that could have errors.
      const t = [ f(this, M, "f") ];
      t.forEach((t => {
        if (t.id) {
          this.validatableControls.set(t.id, {
            reference: t,
            hasError: false,
            message: undefined
          });
        }
      }));
    }));
    C.set(this, (t => {
      this.kbName = t.detail;
    }));
    E.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, b, t.map((t => ({
              id: t.id,
              name: t.name
            }))), "f");
            if (t.length === 1 && f(this, b, "f")[0].id === 0) {
              this.localKbNameInputValue = f(this, k, "f");
              this.versionsValueInput = f(this, m, "f").kb.versionsPlaceholder;
            } else if (t.length > 1) {
              this.localKbNameInputValue = f(this, k, "f");
              this.versionsValueInput = `${t.length.toString()} ${f(this, m, "f").kb.versionSelectedFieldValue}`;
            } else {
              this.localKbNameInputValue = `${f(this, k, "f")}_${f(this, b, "f")[0].name}`;
              this.versionsValueInput = `${t[0].name} ${f(this, m, "f").kb.oneVersionSelectedFieldValue}`;
            }
          }
        }));
      }
    }));
    S.set(this, (t => {
      this.versionSelectedType = t.detail;
      if (this.versionSelectedType === "Select") {
        this.enableSelectVersionsButton = true;
      } else {
        this.enableSelectVersionsButton = false;
      }
    }));
    $.set(this, (() => {
      const t = !this.kbName.length;
      return 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, W, "f"),
        part: "button button-cancel"
      }, f(this, m, "f").footer.cancel), s("button", {
        // share kb button
        class: "button-primary",
        onClick: !t && f(this, j, "f"),
        disabled: t,
        part: "button button-create-kb"
      }, f(this, m, "f").footer.shareKB)));
    }));
    this.enableSelectVersionsButton = false;
    this.validatableControls = new Map;
    this.versionSelectedType = undefined;
    this.versionsValueInput = "";
    this.connectionData = undefined;
    this.cancelCallback = undefined;
    this.changeConnectionCallback = undefined;
    this.kbName = undefined;
    this.shareKBCallback = undefined;
    this.selectKBVersionsCallback = undefined;
  }
  componentDidLoad() {
    this.versionSelectedType = f(this, y, "f").value;
    f(this, _, "f").call(this);
  }
  componentDidRender() {
    if (!f(this, v, "f")) {
      this.componentDidRenderFirstTime.emit(f(this, m, "f").componentName);
      d(this, v, true, "f");
    }
  }
  async componentWillLoad() {
    d(this, m, await h.getComponentStrings(this.el), "f");
  }
  /**
     * Suspends or reactivates the shortcuts
     */  async suspendShortcuts(t) {
    if (t) {
      f(this, w, "f").suspend = true;
    } else {
      f(this, w, "f").suspend = false;
    }
  }
  render() {
    return s(n, {
      class: "widget"
    }, s("ch-theme", {
      model: A
    }), s("ch-shortcuts", {
      src: f(this, g, "f"),
      ref: t => d(this, w, 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, m, "f").header.serverUrl), s("p", null, this.connectionData.serverUrl)), s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label"
    }, f(this, m, "f").header.user), s("p", null, this.connectionData.userName)), s("button", {
      id: "change-connection-button",
      class: "button-tertiary button-change",
      onClick: f(this, x, "f")
    }, f(this, m, "f").header.change)), s("section", {
      class: "main field-group spacing-body"
    }, s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label",
      htmlFor: "alias"
    }, f(this, m, "f").kb.aliasLabel), s("ch-edit", {
      // alias
      class: "input",
      id: "kb-name",
      value: this.kbName,
      onInput: f(this, C, "f"),
      placeholder: f(this, m, "f").kb.localKbNamePlaceholder,
      ref: t => d(this, M, t, "f")
    }), f(this, T, "f").call(this, f(this, M, "f"))), s("div", {
      class: "versions-container field-group"
    }, s("ch-radio-group-render", {
      class: "radio-group",
      model: f(this, u, "f"),
      onChange: f(this, S, "f"),
      value: f(this, u, "f")[0].value,
      ref: t => d(this, y, t, "f")
    }), 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, m, "f").kb.versionsLabel), s("div", {
      class: "versions-container__input"
    }, s("ch-edit", {
      class: "input",
      readonly: true,
      placeholder: this.enableSelectVersionsButton ? f(this, m, "f").kb.versionsPlaceholder : f(this, m, "f").kb.versionsPlaceholderDisabled,
      value: this.versionsValueInput
    }), s("button", {
      id: "select-version-button",
      class: "button-tertiary button-icon-only",
      onClick: f(this, E, "f"),
      disabled: !this.enableSelectVersionsButton
    }, s("ch-image", {
      src: f(this, p, "f"),
      class: "icon-xs"
    }))))))), f(this, $, "f").call(this)));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/share-kb" ];
  }
  get el() {
    return a(this);
  }
};

p = new WeakMap, u = new WeakMap, m = new WeakMap, b = new WeakMap, v = new WeakMap, 
w = new WeakMap, g = new WeakMap, k = new WeakMap, y = new WeakMap, M = new WeakMap, 
W = new WeakMap, x = new WeakMap, j = new WeakMap, T = new WeakMap, _ = new WeakMap, 
C = new WeakMap, E = new WeakMap, S = new WeakMap, $ = new WeakMap;

z.style = c;

export { z as gx_ide_share_kb };
//# sourceMappingURL=p-35c2a2f9.entry.js.map