var __classPrivateFieldGet = (this && this.__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 = (this && this.__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 _GxIdeRestoreVersion_componentLocale, _GxIdeRestoreVersion_chShortcutsEl, _GxIdeRestoreVersion_shortcutsSrc, _GxIdeRestoreVersion_confirmHandler, _GxIdeRestoreVersion_cancelHandler, _GxIdeRestoreVersion_versionsToComboBoxItemModel, _GxIdeRestoreVersion_handleComboBoxInput, _GxIdeRestoreVersion_selectSourceVersionHandler, _GxIdeRestoreVersion_renderFooter;
import { getIconPath } from "@genexus/mercury";
import { getAssetPath, h, Host } from "@stencil/core";
import { Locale } from "../../common/locale";
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/form--full",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "utils/elevation",
    "chameleon/scrollbar"
];
const SHOW_MORE_ICON = getIconPath({
    category: "gemini-tools",
    name: "show-more-horizontal",
    colorType: "interactive"
});
const VERSION_FROZEN_OBJECT_ICON = getIconPath({
    category: "objects",
    name: "version-frozen"
});
const VERSION_OBJECT_ICON = getIconPath({
    category: "objects",
    name: "version"
});
const VERSION_ICON = getIconPath({
    category: "system",
    name: "version",
    colorType: "on-surface"
});
// Uncomment this when the sync environments feature is available
// const CHECKBOX_CHECKED_VALUE = "true";
export class GxIdeRestoreVersion {
    constructor() {
        _GxIdeRestoreVersion_componentLocale.set(this, void 0);
        _GxIdeRestoreVersion_chShortcutsEl.set(this, void 0);
        _GxIdeRestoreVersion_shortcutsSrc.set(this, getAssetPath(`./gx-ide-assets/restore-version/shortcuts.json`));
        _GxIdeRestoreVersion_confirmHandler.set(this, async () => {
            const restoreVersionData = {
                toVersionGuid: this.toVersionInfo.guid,
                toVersionName: this.toVersionInfo.name,
                fromVersionGuid: this.versions.find(version => version.name === this.selectedSourceVersionName).guid,
                fromVersionName: this.selectedSourceVersionName,
                syncEnvironments: this.syncEnvironments
            };
            await this.confirmCallback(restoreVersionData);
        });
        _GxIdeRestoreVersion_cancelHandler.set(this, async () => {
            await this.cancelCallback();
        });
        _GxIdeRestoreVersion_versionsToComboBoxItemModel.set(this, (versions) => {
            this.versionsComboBoxModel = versions.map(version => ({
                caption: version.name,
                value: version.guid,
                startImgSrc: version.isFrozen
                    ? VERSION_FROZEN_OBJECT_ICON
                    : VERSION_OBJECT_ICON
            }));
        });
        _GxIdeRestoreVersion_handleComboBoxInput.set(this, (event) => {
            this.selectedSourceVersionName = event.detail;
        });
        // Uncomment this when the sync environments feature is available
        // #handleCheckBoxValueChange = (
        //   event: ChCheckboxCustomEvent<any> | InputEvent
        // ) => {
        //   this.syncEnvironments = event.detail === CHECKBOX_CHECKED_VALUE;
        // };
        _GxIdeRestoreVersion_selectSourceVersionHandler.set(this, async () => {
            this.selectedSourceVersion = await this.selectSourceVersionCallback();
            this.selectedSourceVersionName = this.selectedSourceVersion[0].name;
        });
        _GxIdeRestoreVersion_renderFooter.set(this, () => {
            const disableConfirmButton = !this.selectedSourceVersionName ||
                !this.versionsComboBoxModel.some(v => v.caption === this.selectedSourceVersionName);
            return (h("footer", { class: "footer dialog-footer dialog-footer-with-border spacing-body" }, h("div", { class: "buttons-spacer" }, h("button", { id: "cancel-button", class: "button-secondary", onClick: __classPrivateFieldGet(this, _GxIdeRestoreVersion_cancelHandler, "f") }, __classPrivateFieldGet(this, _GxIdeRestoreVersion_componentLocale, "f").footer.cancel), h("button", { id: "confirm-button", class: "button-primary", onClick: __classPrivateFieldGet(this, _GxIdeRestoreVersion_confirmHandler, "f"), disabled: disableConfirmButton }, __classPrivateFieldGet(this, _GxIdeRestoreVersion_componentLocale, "f").footer.confirm))));
        });
        this.syncEnvironments = false;
        this.selectedSourceVersionName = "";
        this.selectedSourceVersion = [];
        this.versionsComboBoxModel = [];
        this.selectSourceVersionCallback = undefined;
        this.confirmCallback = undefined;
        this.cancelCallback = undefined;
        this.toVersionInfo = undefined;
        this.versions = undefined;
    }
    versionsChanged() {
        __classPrivateFieldGet(this, _GxIdeRestoreVersion_versionsToComboBoxItemModel, "f").call(this, this.versions);
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeRestoreVersion_componentLocale, await Locale.getComponentStrings(this.el), "f");
        __classPrivateFieldGet(this, _GxIdeRestoreVersion_versionsToComboBoxItemModel, "f").call(this, this.versions || []);
    }
    /**
     * Suspends or reactivates the shortcuts
     */
    async suspendShortcuts(suspendShortcuts) {
        if (suspendShortcuts) {
            __classPrivateFieldGet(this, _GxIdeRestoreVersion_chShortcutsEl, "f").suspend = true;
        }
        else {
            __classPrivateFieldGet(this, _GxIdeRestoreVersion_chShortcutsEl, "f").suspend = false;
        }
    }
    render() {
        return (h(Host, { class: "widget" }, h("ch-theme", { model: CSS_BUNDLES }), h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeRestoreVersion_shortcutsSrc, "f"), ref: (el) => (__classPrivateFieldSet(this, _GxIdeRestoreVersion_chShortcutsEl, el, "f")) }), h("div", { class: "main-container spacing-body" }, h("p", { class: "giu-static-pill-icon-and-text elevation-2" }, h("ch-image", { class: "icon-m", type: "mask", src: VERSION_ICON }), h("span", null, `${__classPrivateFieldGet(this, _GxIdeRestoreVersion_componentLocale, "f").descriptions.pill} - ${this.toVersionInfo.name}`)), h("p", { class: "body-regular-m" }, __classPrivateFieldGet(this, _GxIdeRestoreVersion_componentLocale, "f").descriptions.summary), h("div", { class: "field field-block" }, h("label", { class: "label", htmlFor: "versions-combo-box" }, __classPrivateFieldGet(this, _GxIdeRestoreVersion_componentLocale, "f").labels.fromVersion), h("div", { class: "versions-container" }, h("ch-combo-box-render", { class: "combo-box", id: "versions-combo-box", model: this.versionsComboBoxModel, placeholder: __classPrivateFieldGet(this, _GxIdeRestoreVersion_componentLocale, "f").placeHolders.fromVersion, value: this.selectedSourceVersionName, suggest: true, onInput: __classPrivateFieldGet(this, _GxIdeRestoreVersion_handleComboBoxInput, "f") }), h("button", { id: "select-version-button", class: "button-secondary button-icon-only", onClick: __classPrivateFieldGet(this, _GxIdeRestoreVersion_selectSourceVersionHandler, "f") }, h("ch-image", { src: SHOW_MORE_ICON, class: "icon-m" }))))), __classPrivateFieldGet(this, _GxIdeRestoreVersion_renderFooter, "f").call(this)));
    }
    static get is() { return "gx-ide-restore-version"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["restore-version.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["restore-version.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/restore-version"]; }
    static get properties() {
        return {
            "selectSourceVersionCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "() => Promise<KBVersion[]>",
                    "resolved": "() => Promise<KBVersion[]>",
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "KBVersion": {
                            "location": "import",
                            "path": "../team-dev/version-control/common/types",
                            "id": "src/components/team-dev/version-control/common/types.ts::KBVersion"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked by pressing the ellipsis in the version selector."
                }
            },
            "confirmCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "(\n    restoreVersionData: RestoreVersionData\n  ) => Promise<void>",
                    "resolved": "(restoreVersionData: RestoreVersionData) => Promise<void>",
                    "references": {
                        "RestoreVersionData": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/restore-version/restore-version.tsx",
                            "id": "src/components/restore-version/restore-version.tsx::RestoreVersionData"
                        },
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked by pressing the Confirm button."
                }
            },
            "cancelCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "() => Promise<void>",
                    "resolved": "() => Promise<void>",
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked by pressing the Cancel button."
                }
            },
            "toVersionInfo": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "KBVersion",
                    "resolved": "{ id: number; name: string; isFrozen?: boolean; guid?: string; }",
                    "references": {
                        "KBVersion": {
                            "location": "import",
                            "path": "../team-dev/version-control/common/types",
                            "id": "src/components/team-dev/version-control/common/types.ts::KBVersion"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The target version to which the restore will be made."
                }
            },
            "versions": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "KBVersion[]",
                    "resolved": "KBVersion[]",
                    "references": {
                        "KBVersion": {
                            "location": "import",
                            "path": "../team-dev/version-control/common/types",
                            "id": "src/components/team-dev/version-control/common/types.ts::KBVersion"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "List of versions to show in the versions combo box."
                }
            }
        };
    }
    static get states() {
        return {
            "syncEnvironments": {},
            "selectedSourceVersionName": {},
            "selectedSourceVersion": {},
            "versionsComboBoxModel": {}
        };
    }
    static get methods() {
        return {
            "suspendShortcuts": {
                "complexType": {
                    "signature": "(suspendShortcuts: boolean) => Promise<void>",
                    "parameters": [{
                            "name": "suspendShortcuts",
                            "type": "boolean",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Suspends or reactivates the shortcuts",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "versions",
                "methodName": "versionsChanged"
            }];
    }
}
_GxIdeRestoreVersion_componentLocale = new WeakMap(), _GxIdeRestoreVersion_chShortcutsEl = new WeakMap(), _GxIdeRestoreVersion_shortcutsSrc = new WeakMap(), _GxIdeRestoreVersion_confirmHandler = new WeakMap(), _GxIdeRestoreVersion_cancelHandler = new WeakMap(), _GxIdeRestoreVersion_versionsToComboBoxItemModel = new WeakMap(), _GxIdeRestoreVersion_handleComboBoxInput = new WeakMap(), _GxIdeRestoreVersion_selectSourceVersionHandler = new WeakMap(), _GxIdeRestoreVersion_renderFooter = new WeakMap();
//# sourceMappingURL=restore-version.js.map
