/* STENCIL IMPORTS */
import { Host, h } from "@stencil/core";
/* OTHER LIBRARIES IMPORTS */
/* CUSTOM IMPORTS */
import { config } from "../../../common/config";
import { Locale } from "../../../common/locale";
/* import { renderListItems } from "../../../common/render-list-item"; */
export class GxIdeBpmExportXpdl {
    constructor() {
        this.renderedFirstTime = false;
        // 7.LISTENERS //
        // 8.PUBLIC METHODS API //
        // 9.LOCAL METHODS //
        this.exportHandler = () => {
            var _a;
            if (this.exportCallback) {
                this.notExporting = false;
                const data = {
                    directoryName: this.exportInputEl.value,
                    Objects: (_a = this.bpmObjectSelectorEl.selection) !== null && _a !== void 0 ? _a : {
                        includeAll: false,
                        objectIds: []
                    }
                };
                this.exportCallback(data)
                    .then(() => {
                    this.notExporting = true;
                })
                    .catch(() => {
                    // error handling
                    this.notExporting = true;
                });
            }
        };
        this.inputHandle = async () => {
            var _a;
            this.emptyInput = !((_a = this.exportInputEl.value) === null || _a === void 0 ? void 0 : _a.length);
        };
        this.handleSelectionChanged = () => {
            this.emptyObjects = !this.bpmObjectSelectorEl.selection.objectIds.length;
        };
        this.emptyInput = true;
        this.emptyObjects = true;
        this.notExporting = true;
        this.displayTitle = false;
        this.exportCallback = undefined;
        this.cancelCallback = undefined;
        this.addCallback = undefined;
        this.referencesCallback = 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: "export-directory", class: "label" }, this._componentLocale.main.exportInputLabel), h("input", { type: "text", id: "export-directory", class: "input-text input", onInput: this.inputHandle, ref: el => (this.exportInputEl = el) }), h("button", { class: "export", disabled: this.emptyInput || this.emptyObjects, onClick: this.exportHandler }, this._componentLocale.main.exportButton), h("button", { class: "cancel", disabled: this.notExporting, onClick: this.cancelCallback }, this._componentLocale.main.cancelButton)), h("gx-ide-bpm-objects-selector", { id: "gx-ide-bpm-objects-selector", addCallback: this.addCallback, referencesCallback: this.referencesCallback, ref: el => (this.bpmObjectSelectorEl =
                el), onSelectionChanged: this.handleSelectionChanged })))));
    }
    static get is() { return "gx-ide-bpm-export-xpdl"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["bpm-export-xpdl.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bpm-export-xpdl.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/bpm-export-xpdl"]; }
    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"
            },
            "exportCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ExportCallback",
                    "resolved": "(exportData: ExportData) => Promise<boolean>",
                    "references": {
                        "ExportCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/export-xpdl/bpm-export-xpdl.tsx",
                            "id": "src/components/bpm/export-xpdl/bpm-export-xpdl.tsx::ExportCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "param",
                            "text": "exportData - The data required for the export process."
                        }, {
                            "name": "returns",
                            "text": "A promise that resolves to a boolean indicating the success of the export operation.\nReturns `true` if the export was successful, and `false` otherwise."
                        }],
                    "text": "Callback function invoked when the user presses the 'Create' button.\nThis function is expected to handle the export process based on the provided export data."
                }
            },
            "cancelCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "CancelCallback",
                    "resolved": "() => Promise<void>",
                    "references": {
                        "CancelCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/export-xpdl/bpm-export-xpdl.tsx",
                            "id": "src/components/bpm/export-xpdl/bpm-export-xpdl.tsx::CancelCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user press 'Cancel' button"
                }
            },
            "addCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "() => Promise<ObjectData[]>",
                    "resolved": "() => Promise<ObjectData[]>",
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "ObjectData": {
                            "location": "import",
                            "path": "../objects-selector/helpers",
                            "id": "src/components/bpm/objects-selector/helpers.ts::ObjectData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "returns",
                            "text": "A Promise that resolves to an array of ObjectData. Each ObjectData contains the ID, icon, and name of an object."
                        }],
                    "text": "Callback invoked when the user presses the 'Add' button. associated with gx-ide-bpm-objects-selector\nThis function is expected to return a list of selected objects' basic information."
                }
            },
            "referencesCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "(ids: string[]) => Promise<ObjectData[]>",
                    "resolved": "(ids: string[]) => Promise<ObjectData[]>",
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "ObjectData": {
                            "location": "import",
                            "path": "../objects-selector/helpers",
                            "id": "src/components/bpm/objects-selector/helpers.ts::ObjectData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "param",
                            "text": "ids - An array of IDs of the objects currently added to the list."
                        }, {
                            "name": "returns",
                            "text": "A Promise that resolves to an array of ObjectData. Each ObjectData contains the ID, icon, and name of an object."
                        }],
                    "text": "Callback invoked when the user presses the 'References' button. associated with gx-ide-bpm-objects-selector\nReceives a parameter which is an array of IDs of the objects currently added to the list.\nReturns a Promise that resolves to an array of ObjectData, where each ObjectData contains the ID, icon, and name of an object."
                }
            }
        };
    }
    static get states() {
        return {
            "emptyInput": {},
            "emptyObjects": {},
            "notExporting": {}
        };
    }
    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-export-xpdl.js.map
