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 _GxIdeBpmAppDeclaration_componentLocale, _GxIdeBpmAppDeclaration_animateEmptyState, _GxIdeBpmAppDeclaration_shortcutsSrc, _GxIdeBpmAppDeclaration_ACCESS_CAPTION_MAP, _GxIdeBpmAppDeclaration_setAccessCaptions, _GxIdeBpmAppDeclaration_applicationInputChangedHandler, _GxIdeBpmAppDeclaration_cancelCallbackHandler, _GxIdeBpmAppDeclaration_clearApplicationHandler, _GxIdeBpmAppDeclaration_confirmCallbackHandler, _GxIdeBpmAppDeclaration_mapRelevantDataOptionsToComboBoxModel, _GxIdeBpmAppDeclaration_mapSuggestedApplicationsToComboBoxModel, _GxIdeBpmAppDeclaration_relevantDataInputHandler, _GxIdeBpmAppDeclaration_selectApplicationCallbackHandler, _GxIdeBpmAppDeclaration_selectMappingCallbackHandler, _GxIdeBpmAppDeclaration_setApplicationData, _GxIdeBpmAppDeclaration_suggestInputHandler, _GxIdeBpmAppDeclaration_updateApplicationData, _GxIdeBpmAppDeclaration_renderDataMappingsGrid;
import { Host, h, getAssetPath } from "@stencil/core";
import { getIconPath } from "@genexus/mercury";
import { Locale } from "../../../common/locale";
import { config } from "../../../common/config";
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/button",
    "components/combo-box",
    "components/icon",
    "components/tabular-grid",
    "utils/elevation",
    "utils/form",
    "utils/layout",
    "utils/spacing"
];
const ADD_ICON = getIconPath({
    category: "system",
    name: "add",
    colorType: "interactive"
});
const FILTER_ICON = getIconPath({
    category: "window-tools",
    name: "filter",
    colorType: "on-surface"
});
const MORE_ICON = getIconPath({
    category: "system",
    name: "more-horizontal",
    colorType: "primary"
});
const SUGGEST_OPTIONS = {
    alreadyProcessed: true,
    autoExpand: false,
    hideMatchesAndShowNonMatches: false,
    highlightMatchedItems: false,
    matchCase: false,
    regularExpression: false,
    strict: false,
    renderActiveItemIconOnExpand: true
};
export class GxIdeBpmAppDeclaration {
    constructor() {
        /**
         * The component hard-coded strings translations.
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxIdeBpmAppDeclaration_componentLocale.set(this, void 0);
        _GxIdeBpmAppDeclaration_animateEmptyState.set(this, true);
        _GxIdeBpmAppDeclaration_shortcutsSrc.set(this, getAssetPath(`./gx-ide-assets/bpm-app-declaration/shortcuts.json`));
        _GxIdeBpmAppDeclaration_ACCESS_CAPTION_MAP.set(this, {
            // To be defined on componentWillLoad
            in: undefined,
            out: undefined,
            inout: undefined
        });
        _GxIdeBpmAppDeclaration_setAccessCaptions.set(this, () => {
            __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_ACCESS_CAPTION_MAP, "f").in = __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").dataMappings.access.in;
            __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_ACCESS_CAPTION_MAP, "f").out =
                __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").dataMappings.access.out;
            __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_ACCESS_CAPTION_MAP, "f").inout =
                __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").dataMappings.access.inout;
        });
        _GxIdeBpmAppDeclaration_applicationInputChangedHandler.set(this, async (event) => {
            const selectedApplicationName = event.detail;
            this.application.mappings = await this.getDataMappingCallback(selectedApplicationName);
        });
        _GxIdeBpmAppDeclaration_cancelCallbackHandler.set(this, () => {
            this.cancelCallback();
        });
        _GxIdeBpmAppDeclaration_clearApplicationHandler.set(this, () => {
            this.application = {
                application: {
                    name: "",
                    typeIcon: ""
                },
                mappings: []
            };
        });
        _GxIdeBpmAppDeclaration_confirmCallbackHandler.set(this, () => {
            this.confirmCallback(this.application);
        });
        _GxIdeBpmAppDeclaration_mapRelevantDataOptionsToComboBoxModel.set(this, (relevantDataOptions) => {
            return relevantDataOptions.map(optionName => {
                return {
                    caption: optionName,
                    value: optionName
                };
            });
        });
        _GxIdeBpmAppDeclaration_mapSuggestedApplicationsToComboBoxModel.set(this, (suggestedApplicationsNames) => {
            return suggestedApplicationsNames.map(applicationName => {
                return {
                    caption: applicationName,
                    value: applicationName
                };
            });
        });
        _GxIdeBpmAppDeclaration_relevantDataInputHandler.set(this, (mappingIndex) => async (event) => {
            const inputValue = event.detail;
            this.application.mappings[mappingIndex].relevantData = inputValue;
        });
        _GxIdeBpmAppDeclaration_selectApplicationCallbackHandler.set(this, async () => {
            const applicationDeclarationData = await this.selectApplicationCallback();
            if (applicationDeclarationData) {
                __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_setApplicationData, "f").call(this, applicationDeclarationData.application);
                this.application.mappings = applicationDeclarationData.mappings;
            }
        });
        _GxIdeBpmAppDeclaration_selectMappingCallbackHandler.set(this, (parameter, mappingIndex) => async () => {
            const returnedRelevantData = await this.selectMappingCallback(parameter);
            if (returnedRelevantData) {
                const currentRelevantDataOptions = this.application.mappings[mappingIndex].relevantDataOptions;
                const indexOfReturnedRelevantData = currentRelevantDataOptions.indexOf(returnedRelevantData);
                if (indexOfReturnedRelevantData === -1) {
                    // returnedRelevantData is a new option. Add to combo-box.
                    currentRelevantDataOptions.push(returnedRelevantData);
                }
                // Set as selected
                this.application.mappings[mappingIndex].relevantData =
                    returnedRelevantData;
                __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_updateApplicationData, "f").call(this);
            }
        });
        _GxIdeBpmAppDeclaration_setApplicationData.set(this, (applicationData) => {
            if (applicationData) {
                const applicationName = applicationData.name;
                this.application.application.name = applicationName;
                this.applicationComboBoxModel = [
                    {
                        caption: applicationName,
                        value: applicationName,
                        startImgSrc: applicationData.typeIcon
                    }
                ];
            }
        });
        _GxIdeBpmAppDeclaration_suggestInputHandler.set(this, async (event) => {
            const inputValue = event.detail;
            this.application.application.name = inputValue;
            const suggestedApplicationNames = await this.suggestApplicationsCallback(inputValue);
            this.applicationComboBoxModel =
                __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_mapSuggestedApplicationsToComboBoxModel, "f").call(this, suggestedApplicationNames);
        });
        _GxIdeBpmAppDeclaration_updateApplicationData.set(this, () => {
            this.application = Object.assign({}, this.application);
        });
        // Renders
        _GxIdeBpmAppDeclaration_renderDataMappingsGrid.set(this, () => {
            var _a;
            const applicationDataToDisplay = this.application.mappings.length;
            if (applicationDataToDisplay) {
                // Set as animated for the next time.
                __classPrivateFieldSet(this, _GxIdeBpmAppDeclaration_animateEmptyState, true, "f");
            }
            return (h("div", { class: "field-group data-mapping-grid-container" }, h("div", { class: "field field-block" }, h("label", { class: "spacing-body-inline-start label" }, __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").dataMappings.title), h("ch-tabular-grid", { class: {
                    "tabular-grid": true,
                    "tabular-grid-application-declaration": true,
                    "scrollable": true,
                    "empty-result": !applicationDataToDisplay
                }, part: "ch-grid-data-mappings" }, h("ch-tabular-grid-columnset", { class: "tabular-grid-column-set" }, h("ch-tabular-grid-column", { class: "tabular-grid-column", columnName: ((_a = this.application.application) === null || _a === void 0 ? void 0 : _a.typeIcon) ===
                    "objects/transaction"
                    ? __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").dataMappings.firstColName
                    : __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").dataMappings.firstColNameParameter, settingable: false, sortable: false, size: config.tabularGrid.colSize.common }), h("ch-tabular-grid-column", { class: "tabular-grid-column", columnName: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").dataMappings.secondColName, settingable: false, sortable: false, size: config.tabularGrid.colSize.common }), h("ch-tabular-grid-column", { class: "tabular-grid-column", settingable: false, sortable: false, size: config.tabularGrid.colSize.auto })), this.application.mappings.length ? (h("ch-tabular-grid-rowset", { class: "tabular-grid-rowset" }, this.application.mappings.map((obj, index) => (h("ch-tabular-grid-row", { class: "tabular-grid-row", rowId: `${index}-${obj.parameter}`, key: `${index}-${obj.parameter}-grid-row` }, h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, h("span", { class: "pill-tag elevation-3" }, __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_ACCESS_CAPTION_MAP, "f")[obj.access]), obj.parameter), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, h("ch-combo-box-render", { class: "combo-box", model: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_mapRelevantDataOptionsToComboBoxModel, "f").call(this, obj.relevantDataOptions), value: obj.relevantData, key: `${index}-${obj.parameter}-combo-box`, onInput: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_relevantDataInputHandler, "f").call(this, index) })), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, h("button", { "data-index": index, onClick: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_selectMappingCallbackHandler, "f").call(this, obj.parameter, index), class: "button-tertiary button-icon-only", "aria-label": __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").buttons.selectMapping, title: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").buttons.selectMapping }, h("ch-image", { class: "icon-m", src: ADD_ICON })))))))) : (h("ch-tabular-grid-rowset", { class: "tabular-grid-rowset" }, h("ch-tabular-grid-rowset-empty", null, h("gx-ide-empty-state", { isAnimated: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_animateEmptyState, "f"), stateIconSrc: FILTER_ICON, stateTitle: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").emptyState.title, stateDescription: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").emptyState.description }))))))));
        });
        this.applicationComboBoxModel = [];
        this.application = undefined;
        this.cancelCallback = undefined;
        this.confirmCallback = undefined;
        this.getDataMappingCallback = undefined;
        this.selectApplicationCallback = undefined;
        this.selectMappingCallback = undefined;
        this.suggestApplicationsCallback = undefined;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeBpmAppDeclaration_componentLocale, await Locale.getComponentStrings(this.el), "f");
        __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_setApplicationData, "f").call(this, this.application.application);
        if (this.application.mappings.length === 0) {
            __classPrivateFieldSet(this, _GxIdeBpmAppDeclaration_animateEmptyState, false, "f");
        }
        __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_setAccessCaptions, "f").call(this);
    }
    render() {
        return (h(Host, { class: "widget" }, h("ch-theme", { model: CSS_BUNDLES }), h("section", { class: "section" }, h("header", { slot: "header", class: "header spacing-body" }, h("ch-combo-box-render", { class: "combo-box", value: this.application.application.name, model: this.applicationComboBoxModel, suggestDebounce: config.inputDebounce, suggest: true, suggestOptions: SUGGEST_OPTIONS, onInput: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_suggestInputHandler, "f"), onChange: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_applicationInputChangedHandler, "f") }), h("div", { class: "buttons-spacer" }, h("button", { onClick: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_selectApplicationCallbackHandler, "f"), class: "button-tertiary button-icon-only", "aria-label": __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").buttons.selectApplication, title: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").buttons.selectApplication }, h("ch-image", { class: "icon-m", src: MORE_ICON })), h("button", { onClick: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_clearApplicationHandler, "f"), class: "button-secondary" }, "Clear"))), __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_renderDataMappingsGrid, "f").call(this), h("footer", { class: "dialog-footer spacing-body-block-end spacing-body-inline" }, h("div", { class: "buttons-spacer" }, h("button", { class: "button-secondary", onClick: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_cancelCallbackHandler, "f") }, __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").buttons.cancelButton), h("button", { class: "button-primary", onClick: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_confirmCallbackHandler, "f") }, __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_componentLocale, "f").buttons.confirmButton)))), h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeBpmAppDeclaration_shortcutsSrc, "f") })));
    }
    static get is() { return "gx-ide-bpm-app-declaration"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["bpm-app-declaration.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bpm-app-declaration.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/bpm-app-declaration"]; }
    static get properties() {
        return {
            "application": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "ApplicationDeclarationData",
                    "resolved": "{ application?: ApplicationData; mappings: DataMappingData[]; }",
                    "references": {
                        "ApplicationDeclarationData": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/application-declaration/bpm-app-declaration.tsx",
                            "id": "src/components/bpm/application-declaration/bpm-app-declaration.tsx::ApplicationDeclarationData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Current value of the application declaration. Keep in mind that this property will be used by\nthe host to initialize the component, meaning it will assign the current declaration value."
                }
            },
            "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/application-declaration/bpm-app-declaration.tsx",
                            "id": "src/components/bpm/application-declaration/bpm-app-declaration.tsx::CancelCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user cancels application declaration"
                }
            },
            "confirmCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ConfirmCallback",
                    "resolved": "(data: ApplicationDeclarationData) => Promise<void>",
                    "references": {
                        "ConfirmCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/application-declaration/bpm-app-declaration.tsx",
                            "id": "src/components/bpm/application-declaration/bpm-app-declaration.tsx::ConfirmCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user confirms application declaration"
                }
            },
            "getDataMappingCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "GetDataMappingCallback",
                    "resolved": "(applicationName: string) => Promise<DataMappingData[]>",
                    "references": {
                        "GetDataMappingCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/application-declaration/bpm-app-declaration.tsx",
                            "id": "src/components/bpm/application-declaration/bpm-app-declaration.tsx::GetDataMappingCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user select one of the options provided by the suggest"
                }
            },
            "selectApplicationCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "SelectApplicationCallback",
                    "resolved": "() => Promise<ApplicationDeclarationData>",
                    "references": {
                        "SelectApplicationCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/application-declaration/bpm-app-declaration.tsx",
                            "id": "src/components/bpm/application-declaration/bpm-app-declaration.tsx::SelectApplicationCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked to get access to selection application dialog"
                }
            },
            "selectMappingCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "SelectMappingCallback",
                    "resolved": "(parameter: string) => Promise<string>",
                    "references": {
                        "SelectMappingCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/application-declaration/bpm-app-declaration.tsx",
                            "id": "src/components/bpm/application-declaration/bpm-app-declaration.tsx::SelectMappingCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user press mapping auto-def button"
                }
            },
            "suggestApplicationsCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "SuggestApplicationsCallback",
                    "resolved": "(prefix: string) => Promise<string[]>",
                    "references": {
                        "SuggestApplicationsCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/bpm/application-declaration/bpm-app-declaration.tsx",
                            "id": "src/components/bpm/application-declaration/bpm-app-declaration.tsx::SuggestApplicationsCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked to get options for application input suggest"
                }
            }
        };
    }
    static get states() {
        return {
            "applicationComboBoxModel": {}
        };
    }
    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"; }
}
_GxIdeBpmAppDeclaration_componentLocale = new WeakMap(), _GxIdeBpmAppDeclaration_animateEmptyState = new WeakMap(), _GxIdeBpmAppDeclaration_shortcutsSrc = new WeakMap(), _GxIdeBpmAppDeclaration_ACCESS_CAPTION_MAP = new WeakMap(), _GxIdeBpmAppDeclaration_setAccessCaptions = new WeakMap(), _GxIdeBpmAppDeclaration_applicationInputChangedHandler = new WeakMap(), _GxIdeBpmAppDeclaration_cancelCallbackHandler = new WeakMap(), _GxIdeBpmAppDeclaration_clearApplicationHandler = new WeakMap(), _GxIdeBpmAppDeclaration_confirmCallbackHandler = new WeakMap(), _GxIdeBpmAppDeclaration_mapRelevantDataOptionsToComboBoxModel = new WeakMap(), _GxIdeBpmAppDeclaration_mapSuggestedApplicationsToComboBoxModel = new WeakMap(), _GxIdeBpmAppDeclaration_relevantDataInputHandler = new WeakMap(), _GxIdeBpmAppDeclaration_selectApplicationCallbackHandler = new WeakMap(), _GxIdeBpmAppDeclaration_selectMappingCallbackHandler = new WeakMap(), _GxIdeBpmAppDeclaration_setApplicationData = new WeakMap(), _GxIdeBpmAppDeclaration_suggestInputHandler = new WeakMap(), _GxIdeBpmAppDeclaration_updateApplicationData = new WeakMap(), _GxIdeBpmAppDeclaration_renderDataMappingsGrid = new WeakMap();
//# sourceMappingURL=bpm-app-declaration.js.map
