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

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

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

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

const mapAuthenticationTypeToComboBoxModel = t => t.map((t => ({
  value: t.id,
  caption: t.name
})));

const l = 'button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;block-size:100%;overflow:auto;grid-template-rows:1fr max-content}.main{display:grid;grid-template-areas:"server-url server-url" "authentication-type ." "user-name user-password";grid-auto-rows:max-content;grid-template-columns:1fr 1fr}.section{display:contents}.authentication-type{grid-area:authentication-type}.server-url{grid-area:server-url}.user-name{grid-area:user-name}.user-password{grid-area:user-password}.tooltip{position:absolute}';

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

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

var c, u, p, f, v, m, w, b, y, g, k, M, W;

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

const T = class {
  constructor(i) {
    t(this, i);
    /**
         * The component hard-coded strings translations.
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        c.set(this, void 0);
    u.set(this, void 0);
    p.set(this, void 0);
    f.set(this, void 0);
    v.set(this, e(`./gx-ide-assets/connect-gx-server/shortcuts.json`));
    m.set(this, (() => {
      this.cancelCallback();
    }));
    w.set(this, (async () => {
      this.connectCallback(this.gxServerConnectionData).then((t => {
        this.validatableControls = n(t, this.validatableControls);
      }));
    }));
    // TODO: evaluate if this should be a global helper function.
    // It is used on other dialogs as well.
        b.set(this, (t => {
      var e, i, a;
      return ((i = (e = this.validatableControls) === null || e === void 0 ? void 0 : e.get(t === null || t === void 0 ? void 0 : t.id)) === null || i === void 0 ? void 0 : i.hasError) && ((a = this.validatableControls.get(t.id)) === null || a === void 0 ? void 0 : a.message) && s("ch-tooltip", {
        class: "tooltip",
        actionElement: t,
        blockAlign: o.tooltipSettings.blockAlign,
        inlineAlign: o.tooltipSettings.inlineAlign,
        delay: o.tooltipSettings.delay
      }, this.validatableControls.get(t.id).message);
    }));
    y.set(this, (() => {
      var t, e, s, i;
      this.authenticationTypesChanged(this.authenticationTypes);
      // set initial values:
      // server url
            this.gxServerConnectionData.serverUrl = (t = this.defaultConnectionData) === null || t === void 0 ? void 0 : t.serverUrl;
      //server name
            this.gxServerConnectionData.serverName = (e = this.defaultConnectionData) === null || e === void 0 ? void 0 : e.serverName;
      // authentication type
            this.gxServerConnectionData.authenticationType = {
        id: (s = this.authenticationTypesComboBoxModel[0]) === null || s === void 0 ? void 0 : s.value,
        name: (i = this.authenticationTypesComboBoxModel[0]) === null || i === void 0 ? void 0 : i.caption
      };
    }));
    g.set(this, (() => {
      // populate #controlsValidation with the controls that could have errors.
      const t = [ d(this, u, "f"), d(this, p, "f"), d(this, f, "f") ];
      t.forEach((t => {
        if (t.id) {
          this.validatableControls.set(t.id, {
            reference: t,
            hasError: false,
            message: undefined
          });
        }
      }));
    }));
    k.set(this, (t => {
      const e = t.detail;
      const s = this.authenticationTypes.findIndex((t => t.id === e));
      const i = this.authenticationTypes[s].name;
      this.gxServerConnectionData.authenticationType = {
        id: e,
        name: i
      };
    }));
    M.set(this, (t => {
      this.gxServerConnectionData.userName = t.detail;
    }));
    W.set(this, (t => {
      this.gxServerConnectionData.userPassword = t.detail;
    }));
    this.authenticationTypesComboBoxModel = undefined;
    this.gxServerConnectionData = {
      authenticationType: {
        id: null,
        name: null
      },
      serverUrl: null,
      userName: null,
      userPassword: null,
      serverName: null
    };
    this.validatableControls = new Map;
    this.authenticationTypes = undefined;
    this.cancelCallback = undefined;
    this.connectCallback = undefined;
    this.defaultConnectionData = undefined;
    this.enableCustomServer = false;
  }
  authenticationTypesChanged(t) {
    if (t === null || t === void 0 ? void 0 : t.length) {
      this.authenticationTypesComboBoxModel = mapAuthenticationTypeToComboBoxModel(t);
    }
  }
  async componentWillLoad() {
    h(this, c, await r.getComponentStrings(this.el), "f");
    d(this, y, "f").call(this);
  }
  async componentDidLoad() {
    d(this, g, "f").call(this);
  }
  render() {
    var t, e, a, o;
    return s(i, {
      class: "widget"
    }, s("ch-theme", {
      model: x
    }), s("ch-shortcuts", {
      src: d(this, v, "f")
    }), s("section", {
      class: "section"
    }, s("div", {
      class: "main field-group spacing-body"
    }, s("div", {
      // server urls
      class: "field field-block server-url"
    }, s("label", {
      class: "label",
      htmlFor: "server-url"
    }, d(this, c, "f").main.serverURLLabel), s("ch-edit", {
      type: "url",
      id: "server-url",
      class: "input",
      value: (t = this.gxServerConnectionData) === null || t === void 0 ? void 0 : t.serverUrl,
      readonly: true,
      ref: t => h(this, f, t, "f")
    })), s("div", {
      // authentication types
      class: "field field-block authentication-type"
    }, s("label", {
      class: "label",
      htmlFor: "authentication-type"
    }, d(this, c, "f").main.authenticationTypeLabel), s("ch-combo-box-render", {
      id: "authentication-type",
      class: "combo-box",
      accessibleName: "Authentication Types",
      model: this.authenticationTypesComboBoxModel,
      placeholder: "Select an authentication type",
      value: (e = this.gxServerConnectionData) === null || e === void 0 ? void 0 : e.authenticationType.id,
      onInput: d(this, k, "f")
    })), s("div", {
      // username
      class: "field field-block user-name"
    }, s("label", {
      class: "label",
      htmlFor: "username"
    }, d(this, c, "f").main.usernameLabel), s("ch-edit", {
      type: "text",
      id: "username",
      class: "input",
      value: (a = this.gxServerConnectionData) === null || a === void 0 ? void 0 : a.userName,
      onInput: d(this, M, "f"),
      ref: t => h(this, u, t, "f")
    }), d(this, b, "f").call(this, d(this, u, "f"))), s("div", {
      // user password
      class: "field field-block user-password"
    }, s("label", {
      class: "label",
      htmlFor: "password"
    }, d(this, c, "f").main.passwordLabel), s("ch-edit", {
      type: "password",
      id: "password",
      class: "input",
      value: (o = this.gxServerConnectionData) === null || o === void 0 ? void 0 : o.userPassword,
      onInput: d(this, W, "f"),
      ref: t => h(this, p, t, "f"),
      showPasswordButton: true
    }), d(this, b, "f").call(this, d(this, p, "f")))), s("footer", {
      class: "dialog-footer-with-border spacing-body"
    }, s("div", {
      class: "buttons-spacer"
    }, s("button", {
      id: "cancel-button",
      // cancel button
      class: "button-secondary",
      onClick: d(this, m, "f")
    }, d(this, c, "f").footer.backButtonCaption), s("button", {
      id: "connect-button",
      // connect button
      class: "button-primary",
      onClick: d(this, w, "f")
    }, d(this, c, "f").footer.connectButtonCaption)))));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/connect-gx-server" ];
  }
  get el() {
    return a(this);
  }
  static get watchers() {
    return {
      authenticationTypes: [ "authenticationTypesChanged" ]
    };
  }
};

c = new WeakMap, u = new WeakMap, p = new WeakMap, f = new WeakMap, v = new WeakMap, 
m = new WeakMap, w = new WeakMap, b = new WeakMap, y = new WeakMap, g = new WeakMap, 
k = new WeakMap, M = new WeakMap, W = new WeakMap;

T.style = l;

export { T as gx_ide_connect_gx_server };
//# sourceMappingURL=p-fb5dd0a2.entry.js.map