import { proxyCustomElement, HTMLElement, createEvent, getAssetPath, h, Host } from '@stencil/core/internal/client';
import { L as Locale } from './locale.js';

const stringIsNumber = (stringToCheck) => {
    let isNumber = false;
    isNumber = !isNaN(+stringToCheck) && stringToCheck.toString().length !== 0;
    return isNumber;
};

const updateToRevisionCss = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;overflow:auto;grid-template-areas:\"radio-group revision-number\" \"footer footer\";grid-template-columns:max-content minmax(200px, 1fr);grid-template-rows:max-content max-content}.main{display:contents}.radio-group{grid-area:radio-group}.revision-number{grid-area:revision-number}.footer{grid-area:footer}";

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 _GxIdeTeamDevUpdateToRevision__componentLocale, _GxIdeTeamDevUpdateToRevision_chShortcutsEl, _GxIdeTeamDevUpdateToRevision_radioGroupOptions, _GxIdeTeamDevUpdateToRevision_renderedFirstTime, _GxIdeTeamDevUpdateToRevision_shortcutsSrc, _GxIdeTeamDevUpdateToRevision_radioGroupEl, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, _GxIdeTeamDevUpdateToRevision_cancel, _GxIdeTeamDevUpdateToRevision_confirm, _GxIdeTeamDevUpdateToRevision_inputChangeHandler, _GxIdeTeamDevUpdateToRevision_radioGroupChangeHandler, _GxIdeTeamDevUpdateToRevision_renderFooter, _GxIdeTeamDevUpdateToRevision_setInitialCheckedRadio;
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/form",
    "utils/layout",
    "utils/spacing",
    "utils/typography",
    "components/radio-group",
    "components/button",
    "components/edit"
];
const RD_BTN_LATEST_REVISION_VALUE = "latestRevision";
const RD_BTN_UPDATE_TO_REVISION_VALUE = "updateToRevision";
const GxIdeTeamDevUpdateToRevision$1 = /*@__PURE__*/ proxyCustomElement(class GxIdeTeamDevUpdateToRevision extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.componentDidLoadEvent = createEvent(this, "componentDidLoadEvent", 7);
        this.componentDidRenderFirstTime = createEvent(this, "componentDidRenderFirstTime", 7);
        _GxIdeTeamDevUpdateToRevision__componentLocale.set(this, void 0);
        _GxIdeTeamDevUpdateToRevision_chShortcutsEl.set(this, void 0);
        _GxIdeTeamDevUpdateToRevision_radioGroupOptions.set(this, [
            { value: RD_BTN_LATEST_REVISION_VALUE, caption: "" },
            { value: RD_BTN_UPDATE_TO_REVISION_VALUE, caption: "" }
        ]);
        _GxIdeTeamDevUpdateToRevision_renderedFirstTime.set(this, false);
        _GxIdeTeamDevUpdateToRevision_shortcutsSrc.set(this, getAssetPath(`./gx-ide-assets/team-dev-update-to-revision/shortcuts.json`));
        _GxIdeTeamDevUpdateToRevision_radioGroupEl.set(this, void 0);
        _GxIdeTeamDevUpdateToRevision_revisionNumberEl.set(this, void 0);
        _GxIdeTeamDevUpdateToRevision_cancel.set(this, () => {
            this.cancelCallback();
        });
        _GxIdeTeamDevUpdateToRevision_confirm.set(this, () => {
            let revision = undefined;
            if (__classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_radioGroupEl, "f").value === RD_BTN_UPDATE_TO_REVISION_VALUE) {
                revision = __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, "f").value;
            }
            this.confirmCallback(revision);
        });
        _GxIdeTeamDevUpdateToRevision_inputChangeHandler.set(this, (event) => {
            this.isValid = stringIsNumber(event.detail);
        });
        _GxIdeTeamDevUpdateToRevision_radioGroupChangeHandler.set(this, (event) => {
            __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, "f").disabled =
                event.detail !== RD_BTN_UPDATE_TO_REVISION_VALUE;
            this.isValid = true;
            if (event.detail === RD_BTN_LATEST_REVISION_VALUE) {
                this.isValid = true;
            }
            else if (event.detail === RD_BTN_UPDATE_TO_REVISION_VALUE &&
                !stringIsNumber(__classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, "f").value)) {
                this.isValid = false;
                setTimeout(() => {
                    __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, "f").focus();
                }, 2000);
            }
        });
        _GxIdeTeamDevUpdateToRevision_renderFooter.set(this, () => {
            return (h("footer", { class: "footer dialog-footer spacing-body-block-start" }, h("div", { class: "buttons-spacer" }, h("button", { class: "button-secondary", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_cancel, "f"), part: "button-cancel" }, __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision__componentLocale, "f").footer.btnCancel), h("button", { class: "button-primary", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_confirm, "f"), part: "button-update", disabled: !this.isValid }, __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision__componentLocale, "f").footer.btnUpdate))));
        });
        _GxIdeTeamDevUpdateToRevision_setInitialCheckedRadio.set(this, () => {
            if (this.currentRevision === undefined) {
                __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_radioGroupEl, "f").value = RD_BTN_LATEST_REVISION_VALUE;
                this.isValid = true;
                __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, "f").disabled = true;
            }
            else {
                __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, "f").disabled = false;
                __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, "f").value = this.currentRevision;
                __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_radioGroupEl, "f").value = RD_BTN_UPDATE_TO_REVISION_VALUE;
            }
        });
        this.isValid = undefined;
        this.cancelCallback = undefined;
        this.confirmCallback = undefined;
        this.currentRevision = undefined;
    }
    componentDidLoad() {
        this.componentDidLoadEvent.emit(true);
        __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_setInitialCheckedRadio, "f").call(this);
    }
    componentDidRender() {
        if (!__classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_renderedFirstTime, "f")) {
            this.componentDidRenderFirstTime.emit(__classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision__componentLocale, "f").componentName);
            __classPrivateFieldSet(this, _GxIdeTeamDevUpdateToRevision_renderedFirstTime, true, "f");
        }
        __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_radioGroupOptions, "f").find(rg => rg.value === RD_BTN_LATEST_REVISION_VALUE).caption = __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision__componentLocale, "f").options.updateToLatest;
        __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_radioGroupOptions, "f").find(rg => rg.value === RD_BTN_UPDATE_TO_REVISION_VALUE).caption = __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision__componentLocale, "f").options.updateToRevision;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeTeamDevUpdateToRevision__componentLocale, await Locale.getComponentStrings(this.el), "f");
        this.isValid = true;
    }
    /**
     * Validate necessary data input
     */
    async validate() {
        const isValid = true;
        return isValid;
    }
    /**
     * Suspends or reactivates the shortcuts
     */
    async suspendShortcuts(suspendShortcuts) {
        if (suspendShortcuts) {
            __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_chShortcutsEl, "f").suspend = true;
        }
        else {
            __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_chShortcutsEl, "f").suspend = false;
        }
    }
    render() {
        return (h(Host, { class: "widget scrollable field-group spacing-body" }, h("ch-theme", { model: CSS_BUNDLES }), h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_shortcutsSrc, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeTeamDevUpdateToRevision_chShortcutsEl, el, "f")) }), h("section", { class: "main" }, h("ch-radio-group-render", { class: "radio-group", model: __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_radioGroupOptions, "f"), direction: "horizontal", onChange: __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_radioGroupChangeHandler, "f"), ref: (el) => {
                __classPrivateFieldSet(this, _GxIdeTeamDevUpdateToRevision_radioGroupEl, el, "f");
            } }), h("ch-edit", { autoFocus: true, class: "input revision-number", onInput: __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_inputChangeHandler, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeTeamDevUpdateToRevision_revisionNumberEl, el, "f")) }), __classPrivateFieldGet(this, _GxIdeTeamDevUpdateToRevision_renderFooter, "f").call(this))));
    }
    static get assetsDirs() { return ["gx-ide-assets/team-dev-update-to-revision"]; }
    get el() { return this; }
    static get style() { return updateToRevisionCss; }
}, [1, "gx-ide-team-dev-update-to-revision", {
        "cancelCallback": [16],
        "confirmCallback": [16],
        "currentRevision": [1, "current-revision"],
        "isValid": [32],
        "validate": [64],
        "suspendShortcuts": [64]
    }]);
_GxIdeTeamDevUpdateToRevision__componentLocale = new WeakMap(), _GxIdeTeamDevUpdateToRevision_chShortcutsEl = new WeakMap(), _GxIdeTeamDevUpdateToRevision_radioGroupOptions = new WeakMap(), _GxIdeTeamDevUpdateToRevision_renderedFirstTime = new WeakMap(), _GxIdeTeamDevUpdateToRevision_shortcutsSrc = new WeakMap(), _GxIdeTeamDevUpdateToRevision_radioGroupEl = new WeakMap(), _GxIdeTeamDevUpdateToRevision_revisionNumberEl = new WeakMap(), _GxIdeTeamDevUpdateToRevision_cancel = new WeakMap(), _GxIdeTeamDevUpdateToRevision_confirm = new WeakMap(), _GxIdeTeamDevUpdateToRevision_inputChangeHandler = new WeakMap(), _GxIdeTeamDevUpdateToRevision_radioGroupChangeHandler = new WeakMap(), _GxIdeTeamDevUpdateToRevision_renderFooter = new WeakMap(), _GxIdeTeamDevUpdateToRevision_setInitialCheckedRadio = new WeakMap();
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-team-dev-update-to-revision"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-team-dev-update-to-revision":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeTeamDevUpdateToRevision$1);
            }
            break;
    } });
}

const GxIdeTeamDevUpdateToRevision = GxIdeTeamDevUpdateToRevision$1;
const defineCustomElement = defineCustomElement$1;

export { GxIdeTeamDevUpdateToRevision, defineCustomElement };

//# sourceMappingURL=gx-ide-team-dev-update-to-revision.js.map