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

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

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

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

const r = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;block-size:100%;grid-template-rows:1fr max-content}.field-group{grid-auto-rows:max-content}.main{overflow:auto}.section{display:contents}.tooltip{position:absolute}.checkbox{inline-size:max-content}";

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

var d, f, u, p, v, b, w, m, k, y;

const g = [ "resets/box-sizing", "utils/form", "utils/spacing", "utils/layout", "chameleon/scrollbar", "components/checkbox", "components/button", "components/edit", "components/tooltip" ];

// ch-checkbox
const x = "on";

const M = "set-new-version-as-active";

const W = "create-linked-local-version";

const V = "create-as-protected-version";

const I = class {
  constructor(i) {
    t(this, i);
    /**
         * The component hard-coded strings translations.
         */
    // eslint-disable-next-line @stencil-community/own-props-must-be-private
        d.set(this, void 0);
    f.set(this, void 0);
    u.set(this, e(`./gx-ide-assets/new-version/shortcuts.json`));
    p.set(this, (t => {
      const e = t.target;
      if (e.id === M) {
        this.setNewVersionAsActive = t.detail === x;
      } else if (e.id === W) {
        this.createLinkedLocalVersion = t.detail === x;
      } else if (e.id === V) {
        this.createAsProtectedVersion = t.detail === x;
      }
    }));
    v.set(this, (t => {
      this.versionName = t.detail;
      if (!this.versionDescriptionEdited) {
        this.versionDescription = t.detail;
      }
    }));
    b.set(this, (t => {
      this.versionDescription = t.detail;
      if (this.versionDescription === "") {
        this.versionDescriptionEdited = false;
        this.versionDescription = this.versionName;
      } else {
        this.versionDescriptionEdited = true;
      }
    }));
    w.set(this, (async () => {
      this.cancelCallback();
    }));
    m.set(this, (async () => {
      const t = {
        versionName: this.versionName,
        versionDescription: this.versionDescription,
        setNewVersionAsActive: this.setNewVersionAsActive,
        createLocalLinkedVersion: this.createLinkedLocalVersion,
        createProtectedVersion: this.createAsProtectedVersion
      };
      const e = await this.createCallback(t);
      this.validatableControls = a(e, this.validatableControls);
    }));
    k.set(this, (() => {
      // populate validatableControls with the controls that could have errors.
      const t = [ l(this, f, "f") ];
      t.forEach((t => {
        if (t.id) {
          this.validatableControls.set(t.id, {
            reference: t,
            hasError: false,
            message: undefined
          });
        }
      }));
    }));
    // TODO: evaluate if this should be a global helper function.
    // It is used on other dialogs as well.
        y.set(this, (t => {
      var e, i, o;
      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) && ((o = this.validatableControls.get(t.id)) === null || o === void 0 ? void 0 : o.message) && s("ch-tooltip", {
        class: "tooltip",
        actionElement: t,
        blockAlign: c.tooltipSettings.blockAlign,
        inlineAlign: c.tooltipSettings.inlineAlign,
        delay: c.tooltipSettings.delay
      }, this.validatableControls.get(t.id).message);
    }));
    this.versionName = undefined;
    this.versionDescription = undefined;
    this.versionDescriptionEdited = false;
    this.setNewVersionAsActive = false;
    this.createLinkedLocalVersion = false;
    this.createAsProtectedVersion = false;
    this.validatableControls = new Map;
    this.isRemoteOperation = false;
    this.isFreezeOperation = false;
    this.showLinkedLocalVersionCheckbox = false;
    this.cancelCallback = undefined;
    this.createCallback = undefined;
    this.defaultInputValues = undefined;
  }
  defaultInputValuesChanged(t) {
    this.versionName = t === null || t === void 0 ? void 0 : t.versionName;
    this.versionDescription = t === null || t === void 0 ? void 0 : t.versionDescription;
  }
  async componentWillLoad() {
    h(this, d, await n.getComponentStrings(this.el), "f");
    this.defaultInputValuesChanged(this.defaultInputValues);
  }
  componentDidLoad() {
    l(this, k, "f").call(this);
  }
  render() {
    const t = !this.versionName || this.versionName.length === 0;
    return s(i, {
      class: "widget"
    }, s("ch-theme", {
      model: g
    }), s("ch-shortcuts", {
      src: l(this, u, "f")
    }), s("section", {
      class: "section"
    }, s("div", {
      class: "main scrollable field-group spacing-body"
    }, s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label",
      htmlFor: "version-name"
    }, l(this, d, "f").labels.name), s("ch-edit", {
      type: "text",
      id: "version-name",
      class: "input",
      placeholder: l(this, d, "f").placeHolders.name,
      value: this.versionName,
      onInput: l(this, v, "f"),
      ref: t => h(this, f, t, "f"),
      autoFocus: true
    }), l(this, y, "f").call(this, l(this, f, "f"))), s("div", {
      class: "field field-block"
    }, s("label", {
      class: "label",
      htmlFor: "version-description"
    }, l(this, d, "f").labels.description), s("ch-edit", {
      type: "text",
      id: "version-description",
      class: "input",
      placeholder: l(this, d, "f").placeHolders.description,
      value: this.versionDescription,
      onInput: l(this, b, "f")
    })), !this.isRemoteOperation ? s("div", {
      class: "field field-inline"
    }, s("ch-checkbox", {
      class: "checkbox",
      id: "set-new-version-as-active",
      checkedValue: x,
      onInput: l(this, p, "f"),
      caption: l(this, d, "f").labels.setActive
    })) : s("div", {
      class: "layout layout--cols-2"
    }, this.showLinkedLocalVersionCheckbox && s("div", {
      class: "layout__panel"
    }, s("ch-checkbox", {
      class: "checkbox",
      id: "create-linked-local-version",
      checkedValue: x,
      onInput: l(this, p, "f"),
      caption: l(this, d, "f").labels.createLinkedLocalVersion
    })), !this.isFreezeOperation && s("div", {
      class: "layout__panel"
    }, s("ch-checkbox", {
      class: "checkbox",
      id: "create-as-protected-version",
      checkedValue: x,
      onInput: l(this, p, "f"),
      caption: l(this, d, "f").labels.createAsProtectedVersion
    })))), s("footer", {
      class: "dialog-footer-with-border spacing-body"
    }, s("div", {
      class: "buttons-spacer"
    }, s("button", {
      id: "cancel-button",
      class: "button-secondary",
      onClick: l(this, w, "f")
    }, l(this, d, "f").buttons.cancel), s("button", {
      id: "create-button",
      class: "button-primary",
      onClick: l(this, m, "f"),
      disabled: t
    }, l(this, d, "f").buttons.create)))));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/new-version" ];
  }
  get el() {
    return o(this);
  }
  static get watchers() {
    return {
      defaultInputValues: [ "defaultInputValuesChanged" ]
    };
  }
};

d = new WeakMap, f = new WeakMap, u = new WeakMap, p = new WeakMap, v = new WeakMap, 
b = new WeakMap, w = new WeakMap, m = new WeakMap, k = new WeakMap, y = new WeakMap;

I.style = r;

export { I as gx_ide_new_version };
//# sourceMappingURL=p-c3a355c6.entry.js.map