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 __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 _GxIdeNavigationReport_componentLocale, _GxIdeNavigationReport_items, _GxIdeNavigationReport_combinedRegExp, _GxIdeNavigationReport_itemsSelectionChangedHandler, _GxIdeNavigationReport_sortItemsCallback, _GxIdeNavigationReport_statusButtonsSelectionChangedHandler, _GxIdeNavigationReport_patternInputHandler, _GxIdeNavigationReport_handleChangedItems;
// Stencil
import { Host, h } from "@stencil/core";
// Custom Imports
import { Locale } from "../../common/locale";
import { mapNavigationDataToTreeView, STATUS_REGEXP_KEY, CAPTION_REGEXP_KEY } from "./helpers";
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/tab",
    "components/tooltip",
    "components/tree-view",
    "utils/form--full",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "chameleon/scrollbar"
];
export class GxIdeNavigationReport {
    constructor() {
        /**
         * The component hard-coded strings translations.
         */
        // eslint-disable-next-line @stencil-community/own-props-must-be-private
        _GxIdeNavigationReport_componentLocale.set(this, void 0);
        _GxIdeNavigationReport_items.set(this, []);
        _GxIdeNavigationReport_combinedRegExp.set(this, () => {
            const statusPattern = this.navigationItemsStatusRegExpString || "";
            const captionPattern = this.navigationItemsCaptionRegExpString || "";
            // Create a RegExp that combines the values from the buttons statues and the filer value.
            const combinedPattern = `${statusPattern && `(${statusPattern})`}${statusPattern && captionPattern ? ".*" : ""}${captionPattern && `(${captionPattern})`}`;
            this.navigationItemsRegExp = new RegExp(combinedPattern, "i");
        });
        _GxIdeNavigationReport_itemsSelectionChangedHandler.set(this, (event) => {
            var _a;
            const selectedItemId = (_a = event.detail[0]) === null || _a === void 0 ? void 0 : _a.item.id;
            if (selectedItemId) {
                this.itemSelectedCallback(selectedItemId);
            }
        });
        _GxIdeNavigationReport_sortItemsCallback.set(this, (subModel) => {
            return subModel.sort((a, b) => a.caption.localeCompare(b.caption));
        });
        _GxIdeNavigationReport_statusButtonsSelectionChangedHandler.set(this, (event) => {
            const activeStates = event.detail;
            const statuses = [];
            const errorIndex = activeStates.findIndex(state => state.itemId === "errors");
            const warningIndex = activeStates.findIndex(state => state.itemId === "warnings");
            const successIndex = activeStates.findIndex(state => state.itemId === "successes");
            if (errorIndex !== -1) {
                statuses.push("error");
            }
            if (warningIndex !== -1) {
                statuses.push("warning");
            }
            if (successIndex !== -1) {
                statuses.push("success");
            }
            if (statuses.length) {
                const statusOptions = statuses.join("|");
                this.navigationItemsStatusRegExpString = `"${STATUS_REGEXP_KEY}":"(${statusOptions})"`;
            }
            else {
                this.navigationItemsStatusRegExpString = `"${STATUS_REGEXP_KEY}":""`;
            }
            // Update statusInfo for the status-buttons
            this.statusInfo = {
                error: {
                    display: errorIndex !== -1,
                    number: this.statusInfo.error.number
                },
                warning: {
                    display: warningIndex !== -1,
                    number: this.statusInfo.warning.number
                },
                success: {
                    display: successIndex !== -1,
                    number: this.statusInfo.success.number
                }
            };
        });
        _GxIdeNavigationReport_patternInputHandler.set(this, (event) => {
            const patternFilterValue = event.detail;
            this.navigationItemsCaptionRegExpString = `"${CAPTION_REGEXP_KEY}":".*${patternFilterValue}.*"`;
        });
        _GxIdeNavigationReport_handleChangedItems.set(this, (newItems) => {
            __classPrivateFieldSet(this, _GxIdeNavigationReport_items, newItems, "f");
            this.reportTreeItems = mapNavigationDataToTreeView(newItems);
            let errorsCount = 0;
            let warningsCount = 0;
            let successCount = 0;
            this.reportTreeItems.forEach(item => {
                const metadataObject = JSON.parse(item.metadata);
                let statusValue;
                if (STATUS_REGEXP_KEY in metadataObject) {
                    statusValue = metadataObject[STATUS_REGEXP_KEY];
                }
                if (statusValue && statusValue === "error") {
                    errorsCount++;
                }
                else if (statusValue && statusValue === "warning") {
                    warningsCount++;
                }
                else if (statusValue && statusValue === "success") {
                    successCount++;
                }
            });
            this.statusInfo["error"].number = errorsCount;
            this.statusInfo["warning"].number = warningsCount;
            this.statusInfo["success"].number = successCount;
        });
        this.reportTreeItems = [];
        this.navigationItemsStatusRegExpString = "";
        this.navigationItemsCaptionRegExpString = "";
        this.navigationItemsRegExp = undefined;
        this.confirmed = false;
        this.headerState = "none";
        this.statusInfo = {
            error: {
                display: true,
                number: 0
            },
            warning: {
                display: true,
                number: 0
            },
            success: {
                display: true,
                number: 0
            }
        };
        this.someStatusVisible = undefined;
        this.headerData = undefined;
        this.confirmCallback = undefined;
        this.cancelCallback = undefined;
        this.closeCallback = undefined;
        this.itemSelectedCallback = undefined;
    }
    navigationItemsStatusRegExpStringChanged() {
        __classPrivateFieldGet(this, _GxIdeNavigationReport_combinedRegExp, "f").call(this);
    }
    navigationItemsCaptionRegExpStringChanged() {
        __classPrivateFieldGet(this, _GxIdeNavigationReport_combinedRegExp, "f").call(this);
    }
    /**
     * Add a new item
     */
    async addItem(item) {
        __classPrivateFieldGet(this, _GxIdeNavigationReport_handleChangedItems, "f").call(this, __classPrivateFieldGet(this, _GxIdeNavigationReport_items, "f").concat([item]));
    }
    /**
     * Clear items
     */
    async clearItems() {
        __classPrivateFieldGet(this, _GxIdeNavigationReport_handleChangedItems, "f").call(this, []);
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeNavigationReport_componentLocale, await Locale.getComponentStrings(this.el), "f");
    }
    render() {
        var _a;
        return (h(Host, { class: {
                "widget": true,
                "display-header-type": !!this.headerData
            } }, h("ch-theme", { model: CSS_BUNDLES }), h("section", { class: "section" }, this.headerData && (h("header", { class: "header dialog-header-with-border spacing-body-inline spacing-body-block-start" }, h("div", { class: "header__description" }, h("h3", { class: "subtitle-regular-s" }, this.headerData.title), h("p", { class: "body-regular-s header__description-p" }, this.headerData.description)), h("div", { class: "header__actions" }, h("div", { class: "buttons-spacer header__actions" }, (_a = this.headerData.buttons) === null || _a === void 0 ? void 0 : _a.map(button => {
            var _a;
            const buttonIcon = button.icon;
            const buttonType = (_a = button.type) !== null && _a !== void 0 ? _a : "button-primary";
            return (h("button", { class: {
                    [buttonType]: true,
                    "button-icon-and-text": !!buttonIcon
                }, onClick: button.callback }, buttonIcon && (h("ch-image", { class: "icon-m", src: buttonIcon })), button.caption));
        }))))), h("section", { class: "aside field-group" }, h("header", { class: "aside__header spacing-body-inline spacing-body-block-start" }, h("div", { class: "field field-block" }, h("label", { class: "label", htmlFor: "pattern" }, __classPrivateFieldGet(this, _GxIdeNavigationReport_componentLocale, "f").aside.filterLabel), h("ch-edit", { id: "pattern", class: "input", placeholder: __classPrivateFieldGet(this, _GxIdeNavigationReport_componentLocale, "f").aside.filterPlaceholder, onInput: __classPrivateFieldGet(this, _GxIdeNavigationReport_patternInputHandler, "f") }))), h("ch-tree-view-render", { class: "tree-view", "show-lines": "last", filter: this.navigationItemsRegExp, filterType: "metadata", model: this.reportTreeItems, onSelectedItemsChange: __classPrivateFieldGet(this, _GxIdeNavigationReport_itemsSelectionChangedHandler, "f"), sortItemsCallback: __classPrivateFieldGet(this, _GxIdeNavigationReport_sortItemsCallback, "f"), filterOptions: {
                autoExpand: true,
                hideMatchesAndShowNonMatches: false
            } })), h("section", { class: "main spacing-body" }, h("slot", null)), h("footer", { class: "footer dialog-footer-with-border dialog-footer-start spacing-body-inline spacing-body-block-end" }, h("gx-ide-status-buttons", { errors: this.statusInfo.error.number, warnings: this.statusInfo.warning.number, successes: this.statusInfo.success.number, hideMessage: true, compact: true, onSelectionChanged: __classPrivateFieldGet(this, _GxIdeNavigationReport_statusButtonsSelectionChangedHandler, "f") })))));
    }
    static get is() { return "gx-ide-navigation-report"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["navigation-report.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["navigation-report.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/navigation-report"]; }
    static get properties() {
        return {
            "headerData": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "HeaderData",
                    "resolved": "{ title: string; description: string; buttons: HeaderButtonData[]; }",
                    "references": {
                        "HeaderData": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/navigation-report/navigation-report.tsx",
                            "id": "src/components/navigation-report/navigation-report.tsx::HeaderData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The header data to display on the header."
                }
            },
            "confirmCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ConfirmCallback",
                    "resolved": "() => Promise<void>",
                    "references": {
                        "ConfirmCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/navigation-report/navigation-report.tsx",
                            "id": "src/components/navigation-report/navigation-report.tsx::ConfirmCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user confirms data base reorganization"
                }
            },
            "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/navigation-report/navigation-report.tsx",
                            "id": "src/components/navigation-report/navigation-report.tsx::CancelCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when user cancels reorganization"
                }
            },
            "closeCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "CloseCallback",
                    "resolved": "() => Promise<void>",
                    "references": {
                        "CloseCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/navigation-report/navigation-report.tsx",
                            "id": "src/components/navigation-report/navigation-report.tsx::CloseCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback to be invoked when the user closes the dialog"
                }
            },
            "itemSelectedCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ItemSelectedCallback",
                    "resolved": "(id: string) => Promise<void>",
                    "references": {
                        "ItemSelectedCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/navigation-report/navigation-report.tsx",
                            "id": "src/components/navigation-report/navigation-report.tsx::ItemSelectedCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when a list item is selected"
                }
            }
        };
    }
    static get states() {
        return {
            "reportTreeItems": {},
            "navigationItemsStatusRegExpString": {},
            "navigationItemsCaptionRegExpString": {},
            "navigationItemsRegExp": {},
            "confirmed": {},
            "headerState": {},
            "statusInfo": {},
            "someStatusVisible": {}
        };
    }
    static get events() {
        return [{
                "method": "componentDidRenderEvent",
                "name": "componentDidRenderEvent",
                "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 methods() {
        return {
            "addItem": {
                "complexType": {
                    "signature": "(item: NavigationData) => Promise<void>",
                    "parameters": [{
                            "name": "item",
                            "type": "{ id: string; result: Status; icon: string; name: string; }",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "NavigationData": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/navigation-report/navigation-report.tsx",
                            "id": "src/components/navigation-report/navigation-report.tsx::NavigationData"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Add a new item",
                    "tags": []
                }
            },
            "clearItems": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Clear items",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "navigationItemsStatusRegExpString",
                "methodName": "navigationItemsStatusRegExpStringChanged"
            }, {
                "propName": "navigationItemsCaptionRegExpString",
                "methodName": "navigationItemsCaptionRegExpStringChanged"
            }];
    }
}
_GxIdeNavigationReport_componentLocale = new WeakMap(), _GxIdeNavigationReport_items = new WeakMap(), _GxIdeNavigationReport_combinedRegExp = new WeakMap(), _GxIdeNavigationReport_itemsSelectionChangedHandler = new WeakMap(), _GxIdeNavigationReport_sortItemsCallback = new WeakMap(), _GxIdeNavigationReport_statusButtonsSelectionChangedHandler = new WeakMap(), _GxIdeNavigationReport_patternInputHandler = new WeakMap(), _GxIdeNavigationReport_handleChangedItems = new WeakMap();
//# sourceMappingURL=navigation-report.js.map
