import { proxyCustomElement, HTMLElement, getAssetPath, h, Host } from '@stencil/core/internal/client';
import { L as Locale } from './locale.js';
import { v as validateControls } from './form-validation.js';
import { c as config } from './config.js';

const newVersionCss = "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 __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m")
        throw new TypeError("Private method is not writable");
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _GxIdeNewVersion_componentLocale, _GxIdeNewVersion_versionNameEl, _GxIdeNewVersion_shortcutsSrc, _GxIdeNewVersion_handleCheckBoxValueChange, _GxIdeNewVersion_handleNameValueChange, _GxIdeNewVersion_handleDescriptionValueChange, _GxIdeNewVersion_cancelClickHandler, _GxIdeNewVersion_createClickHandler, _GxIdeNewVersion_initializeValidatableControls, _GxIdeNewVersion_evaluateTooltipRender;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/form",
    "utils/spacing",
    "utils/layout",
    "chameleon/scrollbar",
    "components/checkbox",
    "components/button",
    "components/edit",
    "components/tooltip"
];
// ch-checkbox
const CHECKED_VALUE = "on";
const SET_NEW_VERSION_AS_ACTIVE_ID = "set-new-version-as-active";
const CREATE_LINKED_LOCAL_VERSION_ID = "create-linked-local-version";
const CREATE_AS_PROTECTED_VERSION_ID = "create-as-protected-version";
const GxIdeNewVersion$1 = /*@__PURE__*/ proxyCustomElement(class GxIdeNewVersion extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /**
         * The component hard-coded strings translations.
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxIdeNewVersion_componentLocale.set(this, void 0);
        _GxIdeNewVersion_versionNameEl.set(this, void 0);
        _GxIdeNewVersion_shortcutsSrc.set(this, getAssetPath(`./gx-ide-assets/new-version/shortcuts.json`));
        _GxIdeNewVersion_handleCheckBoxValueChange.set(this, (event) => {
            const target = event.target;
            if (target.id === SET_NEW_VERSION_AS_ACTIVE_ID) {
                this.setNewVersionAsActive = event.detail === CHECKED_VALUE;
            }
            else if (target.id === CREATE_LINKED_LOCAL_VERSION_ID) {
                this.createLinkedLocalVersion = event.detail === CHECKED_VALUE;
            }
            else if (target.id === CREATE_AS_PROTECTED_VERSION_ID) {
                this.createAsProtectedVersion = event.detail === CHECKED_VALUE;
            }
        });
        _GxIdeNewVersion_handleNameValueChange.set(this, (event) => {
            this.versionName = event.detail;
            if (!this.versionDescriptionEdited) {
                this.versionDescription = event.detail;
            }
        });
        _GxIdeNewVersion_handleDescriptionValueChange.set(this, (event) => {
            this.versionDescription = event.detail;
            if (this.versionDescription === "") {
                this.versionDescriptionEdited = false;
                this.versionDescription = this.versionName;
            }
            else {
                this.versionDescriptionEdited = true;
            }
        });
        _GxIdeNewVersion_cancelClickHandler.set(this, async () => {
            this.cancelCallback();
        });
        _GxIdeNewVersion_createClickHandler.set(this, async () => {
            const newVersionData = {
                versionName: this.versionName,
                versionDescription: this.versionDescription,
                setNewVersionAsActive: this.setNewVersionAsActive,
                createLocalLinkedVersion: this.createLinkedLocalVersion,
                createProtectedVersion: this.createAsProtectedVersion
            };
            const formSubmitResult = await this.createCallback(newVersionData);
            this.validatableControls = validateControls(formSubmitResult, this.validatableControls);
        });
        _GxIdeNewVersion_initializeValidatableControls.set(this, () => {
            // populate validatableControls with the controls that could have errors.
            const validatableControls = [__classPrivateFieldGet(this, _GxIdeNewVersion_versionNameEl, "f")];
            validatableControls.forEach(validatableControl => {
                if (validatableControl.id) {
                    this.validatableControls.set(validatableControl.id, {
                        reference: validatableControl,
                        hasError: false,
                        message: undefined
                    });
                }
            });
        });
        // TODO: evaluate if this should be a global helper function.
        // It is used on other dialogs as well.
        _GxIdeNewVersion_evaluateTooltipRender.set(this, (controlReference) => {
            var _a, _b, _c;
            return ((_b = (_a = this.validatableControls) === null || _a === void 0 ? void 0 : _a.get(controlReference === null || controlReference === void 0 ? void 0 : controlReference.id)) === null || _b === void 0 ? void 0 : _b.hasError) &&
                ((_c = this.validatableControls.get(controlReference.id)) === null || _c === void 0 ? void 0 : _c.message) && (h("ch-tooltip", { class: "tooltip", actionElement: controlReference, blockAlign: config.tooltipSettings.blockAlign, inlineAlign: config.tooltipSettings.inlineAlign, delay: config.tooltipSettings.delay }, this.validatableControls.get(controlReference.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(newDefaultInputValues) {
        this.versionName = newDefaultInputValues === null || newDefaultInputValues === void 0 ? void 0 : newDefaultInputValues.versionName;
        this.versionDescription = newDefaultInputValues === null || newDefaultInputValues === void 0 ? void 0 : newDefaultInputValues.versionDescription;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeNewVersion_componentLocale, await Locale.getComponentStrings(this.el), "f");
        this.defaultInputValuesChanged(this.defaultInputValues);
    }
    componentDidLoad() {
        __classPrivateFieldGet(this, _GxIdeNewVersion_initializeValidatableControls, "f").call(this);
    }
    render() {
        const createButtonDisabled = !this.versionName || this.versionName.length === 0;
        return (h(Host, { class: "widget" }, h("ch-theme", { model: CSS_BUNDLES }), h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeNewVersion_shortcutsSrc, "f") }), h("section", { class: "section" }, h("div", { class: "main scrollable field-group spacing-body" }, h("div", { class: "field field-block" }, h("label", { class: "label", htmlFor: "version-name" }, __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").labels.name), h("ch-edit", { type: "text", id: "version-name", class: "input", placeholder: __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").placeHolders.name, value: this.versionName, onInput: __classPrivateFieldGet(this, _GxIdeNewVersion_handleNameValueChange, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeNewVersion_versionNameEl, el, "f")), autoFocus: true }), __classPrivateFieldGet(this, _GxIdeNewVersion_evaluateTooltipRender, "f").call(this, __classPrivateFieldGet(this, _GxIdeNewVersion_versionNameEl, "f"))), h("div", { class: "field field-block" }, h("label", { class: "label", htmlFor: "version-description" }, __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").labels.description), h("ch-edit", { type: "text", id: "version-description", class: "input", placeholder: __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").placeHolders.description, value: this.versionDescription, onInput: __classPrivateFieldGet(this, _GxIdeNewVersion_handleDescriptionValueChange, "f") })), !this.isRemoteOperation ? (h("div", { class: "field field-inline" }, h("ch-checkbox", { class: "checkbox", id: "set-new-version-as-active", checkedValue: CHECKED_VALUE, onInput: __classPrivateFieldGet(this, _GxIdeNewVersion_handleCheckBoxValueChange, "f"), caption: __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").labels.setActive }))) : (h("div", { class: "layout layout--cols-2" }, this.showLinkedLocalVersionCheckbox && (h("div", { class: "layout__panel" }, h("ch-checkbox", { class: "checkbox", id: "create-linked-local-version", checkedValue: CHECKED_VALUE, onInput: __classPrivateFieldGet(this, _GxIdeNewVersion_handleCheckBoxValueChange, "f"), caption: __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").labels.createLinkedLocalVersion }))), !this.isFreezeOperation && (h("div", { class: "layout__panel" }, h("ch-checkbox", { class: "checkbox", id: "create-as-protected-version", checkedValue: CHECKED_VALUE, onInput: __classPrivateFieldGet(this, _GxIdeNewVersion_handleCheckBoxValueChange, "f"), caption: __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").labels.createAsProtectedVersion })))))), h("footer", { class: "dialog-footer-with-border spacing-body" }, h("div", { class: "buttons-spacer" }, h("button", { id: "cancel-button", class: "button-secondary", onClick: __classPrivateFieldGet(this, _GxIdeNewVersion_cancelClickHandler, "f") }, __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").buttons.cancel), h("button", { id: "create-button", class: "button-primary", onClick: __classPrivateFieldGet(this, _GxIdeNewVersion_createClickHandler, "f"), disabled: createButtonDisabled }, __classPrivateFieldGet(this, _GxIdeNewVersion_componentLocale, "f").buttons.create))))));
    }
    static get assetsDirs() { return ["gx-ide-assets/new-version"]; }
    get el() { return this; }
    static get watchers() { return {
        "defaultInputValues": ["defaultInputValuesChanged"]
    }; }
    static get style() { return newVersionCss; }
}, [1, "gx-ide-new-version", {
        "isRemoteOperation": [4, "is-remote-operation"],
        "isFreezeOperation": [4, "is-freeze-operation"],
        "showLinkedLocalVersionCheckbox": [4, "show-linked-local-version-checkbox"],
        "cancelCallback": [16],
        "createCallback": [16],
        "defaultInputValues": [16],
        "versionName": [32],
        "versionDescription": [32],
        "versionDescriptionEdited": [32],
        "setNewVersionAsActive": [32],
        "createLinkedLocalVersion": [32],
        "createAsProtectedVersion": [32],
        "validatableControls": [32]
    }, undefined, {
        "defaultInputValues": ["defaultInputValuesChanged"]
    }]);
_GxIdeNewVersion_componentLocale = new WeakMap(), _GxIdeNewVersion_versionNameEl = new WeakMap(), _GxIdeNewVersion_shortcutsSrc = new WeakMap(), _GxIdeNewVersion_handleCheckBoxValueChange = new WeakMap(), _GxIdeNewVersion_handleNameValueChange = new WeakMap(), _GxIdeNewVersion_handleDescriptionValueChange = new WeakMap(), _GxIdeNewVersion_cancelClickHandler = new WeakMap(), _GxIdeNewVersion_createClickHandler = new WeakMap(), _GxIdeNewVersion_initializeValidatableControls = new WeakMap(), _GxIdeNewVersion_evaluateTooltipRender = new WeakMap();
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-new-version"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-new-version":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeNewVersion$1);
            }
            break;
    } });
}

const GxIdeNewVersion = GxIdeNewVersion$1;
const defineCustomElement = defineCustomElement$1;

export { GxIdeNewVersion, defineCustomElement };

//# sourceMappingURL=gx-ide-new-version.js.map