/* STENCIL IMPORTS */
import { Host, h } from "@stencil/core";
/* OTHER LIBRARIES IMPORTS */
/* CUSTOM IMPORTS */
import { config } from "../../../common/config";
import { Locale } from "../../../common/locale";
export class GxIdeTemplate {
    constructor() {
        this.renderedFirstTime = false;
        // 7.LISTENERS //
        // 8.PUBLIC METHODS API //
        // 9.LOCAL METHODS //
        this.loadFileHandle = async () => {
            this.fileInput.click();
        };
        this.handleFileInputChange = (event) => {
            const fileInput = event.target;
            if (fileInput.files && fileInput.files.length > 0) {
                const newFile = fileInput.files[0];
                this.selectedFile = newFile;
                this.pathValue = this.selectedFile.name;
            }
            this.fileInput.value = null;
        };
        this.handlePathInputChange = (event) => {
            this.selectedFile = null;
            const inputElement = event.target;
            const newValue = inputElement.value;
            this.pathValue = newValue;
        };
        this.confirmCallbackHandle = async () => {
            if (this.confirmCallback) {
                const fileName = this.pathValue
                    .replace(/^.*?([^\\\/]*)$/, "$1")
                    .toLowerCase()
                    .trim();
                if (fileName === ".gxpm" || !fileName.endsWith(".gxpm")) {
                    return;
                }
                const fileData = this.selectedFile
                    ? this.selectedFile
                    : new File([this.pathValue], fileName);
                const data = {
                    automaticBackup: this.automaticBackupEl.value === "true",
                    file: fileData
                };
                await this.confirmCallback(data);
                this.fileInput.value = null;
                this.selectedFile = null;
                this.pathValue = "";
                this.automaticBackupEl.value = "false";
            }
        };
        this.selectedFile = null;
        this.pathValue = "";
        this.displayTitle = false;
        this.confirmCallback = undefined;
        this.cancelCallback = undefined;
    }
    // 6.COMPONENT LIFECYCLE METHODS //
    async componentWillLoad() {
        this._componentLocale = await Locale.getComponentStrings(this.el);
    }
    componentDidRender() {
        if (!this.renderedFirstTime) {
            this.componentDidRenderFirstTime.emit(this._componentLocale.componentName);
            this.renderedFirstTime = true;
        }
    }
    // 10.RENDER() FUNCTION //
    render() {
        return (h(Host, { class: "gx-ide-component" }, h("div", { class: "gx-ide-main-wrapper" }, h("gx-ide-container", { slimmerFooter: config.gxIdeContainer.slimmerFooter }, h("div", { class: "header" }, h("label", { htmlFor: "project-path" }, this._componentLocale.main.projectPathInputLabel), h("input", { type: "text", class: "input-text", id: "project-path", value: this.pathValue, onChange: this.handlePathInputChange }), h("input", { type: "file", id: "input_file", accept: ".gxpm", ref: el => (this.fileInput = el), onChange: this.handleFileInputChange, class: "hidden-input" }), h("button", { onClick: this.loadFileHandle }, this._componentLocale.main.addFilesButton)), h("div", { class: "control-wrapper" }, h("label", { htmlFor: "automatic-backup" }, this._componentLocale.main.automaticBackupCheckboxLabel), h("ch-checkbox", { id: "automatic-backup", accessibleName: "automatic-backup", checkedValue: "true", unCheckedValue: "false", value: "checked", ref: (el) => (this.automaticBackupEl = el) })), h("button", { slot: "footer-end", onClick: this.cancelCallback }, this._componentLocale.footer.cancelButton), h("button", { slot: "footer-end", onClick: this.confirmCallbackHandle }, this._componentLocale.footer.confirmButton)))));
    }
    static get is() { return "gx-ide-bpm-import-gxpm"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["bpm-import-gxpm.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bpm-import-gxpm.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/bpm-import-gxpm"]; }
    static get properties() {
        return {
            "displayTitle": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "false",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If true it displays the component title on the header"
                },
                "attribute": "display-title",
                "reflect": false,
                "defaultValue": "false"
            },
            "confirmCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "(data: ImportData) => Promise<void>",
                    "resolved": "(data: ImportData) => Promise<void>",
                    "references": {
                        "ImportData": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/import-gxpm/bpm-import-gxpm.tsx",
                            "id": "src/components/bpm/import-gxpm/bpm-import-gxpm.tsx::ImportData"
                        },
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "param",
                            "text": "data - The data to be processed. This can be a string or a File object."
                        }, {
                            "name": "returns",
                            "text": "A Promise that resolves to void, indicating the completion of the operation."
                        }],
                    "text": "Callback function to be executed when OK button is pressed.\nThis callback is expected to handle the file or string input and return a Promise that resolves when is completed."
                }
            },
            "cancelCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "() => Promise<void>",
                    "resolved": "() => Promise<void>",
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user press 'Cancel' button."
                }
            }
        };
    }
    static get states() {
        return {
            "selectedFile": {},
            "pathValue": {}
        };
    }
    static get events() {
        return [{
                "method": "componentDidRenderFirstTime",
                "name": "componentDidRenderFirstTime",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "description",
                            "text": "Gets fired when the component has rendered for the first time."
                        }],
                    "text": ""
                },
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "el"; }
}
//# sourceMappingURL=bpm-import-gxpm.js.map
