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 _GxIdeTeamDevUpdatePartialSelection__componentLocale, _GxIdeTeamDevUpdatePartialSelection_renderedFirstTime, _GxIdeTeamDevUpdatePartialSelection_shortcutsSrc, _GxIdeTeamDevUpdatePartialSelection_chGridEl, _GxIdeTeamDevUpdatePartialSelection_cancelHandler, _GxIdeTeamDevUpdatePartialSelection_confirmHandler, _GxIdeTeamDevUpdatePartialSelection_getObjectsHandler, _GxIdeTeamDevUpdatePartialSelection_listenChanges, _GxIdeTeamDevUpdatePartialSelection_removeAllHandler, _GxIdeTeamDevUpdatePartialSelection_removeSelectedObjectsHandler, _GxIdeTeamDevUpdatePartialSelection_renderObjects;
// Stencil
import { Host, getAssetPath, h } from "@stencil/core";
// Other Libraries
import { getIconPath } from "@genexus/mercury";
// Custom Imports
import { config } from "../../../common/config";
import { Locale } from "../../../common/locale";
import { formatDate } from "../../../common/helpers";
const CSS_BUNDLES = [
    "resets/box-sizing",
    "components/button",
    "components/edit",
    "components/icon",
    "components/radio-group",
    "components/tabular-grid",
    "utils/form",
    "utils/layout",
    "utils/spacing",
    "utils/typography"
];
const GEMINI_TOOLS_ADD_ICON = getIconPath({
    category: "gemini-tools",
    name: "add-circle",
    colorType: "primary"
});
export class GxIdeTeamDevUpdatePartialSelection {
    constructor() {
        _GxIdeTeamDevUpdatePartialSelection__componentLocale.set(this, void 0);
        _GxIdeTeamDevUpdatePartialSelection_renderedFirstTime.set(this, false);
        _GxIdeTeamDevUpdatePartialSelection_shortcutsSrc.set(this, getAssetPath(`./gx-ide-assets/team-dev-update-partial-selection/shortcuts.json`));
        _GxIdeTeamDevUpdatePartialSelection_chGridEl.set(this, void 0);
        _GxIdeTeamDevUpdatePartialSelection_cancelHandler.set(this, () => {
            this.cancelCallback();
        });
        _GxIdeTeamDevUpdatePartialSelection_confirmHandler.set(this, () => {
            if (this.confirmCallback) {
                const allRowsIds = [];
                this.selection.forEach(row => {
                    allRowsIds.push(row.id);
                });
                this.confirmCallback(allRowsIds);
            }
        });
        _GxIdeTeamDevUpdatePartialSelection_getObjectsHandler.set(this, () => {
            this.addCallback().then((items) => {
                if ((items === null || items === void 0 ? void 0 : items.length) > 0) {
                    this.selection = [...this.selection, ...items];
                    this.selectedObjectsIds = [];
                }
            });
        });
        _GxIdeTeamDevUpdatePartialSelection_listenChanges.set(this, () => {
            __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_chGridEl, "f").addEventListener("selectionChanged", (ev) => {
                this.selectedObjectsIds = ev.detail.rowsId;
            });
        });
        _GxIdeTeamDevUpdatePartialSelection_removeAllHandler.set(this, () => {
            this.selection = [];
        });
        _GxIdeTeamDevUpdatePartialSelection_removeSelectedObjectsHandler.set(this, () => {
            const selection = this.selection.filter(item => !this.selectedObjectsIds.includes(item.id));
            this.selection = selection;
            this.selectedObjectsIds = [];
        });
        _GxIdeTeamDevUpdatePartialSelection_renderObjects.set(this, () => {
            return (h("ch-tabular-grid", { allowColumnReorder: false, columnResizeMode: "single", class: "tabular-grid tabular-grid-main", "row-selection-mode": "multiple", keyboardNavigationMode: "focus", ref: (el) => (__classPrivateFieldSet(this, _GxIdeTeamDevUpdatePartialSelection_chGridEl, el, "f")), part: "ch-grid-objects" }, h("ch-tabular-grid-columnset", { class: "tabular-grid-column-set" }, h("ch-tabular-grid-column", { columnName: "", settingable: false, sortable: false, size: config.tabularGrid.colSize.minContent, class: "tabular-grid-column" }), h("ch-tabular-grid-column", { columnName: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").tableHead.name, settingable: false, sortable: false, size: "1fr", class: "tabular-grid-column" }), h("ch-tabular-grid-column", { columnName: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").tableHead.type, settingable: false, sortable: false, size: "minmax(120px,auto)", class: "tabular-grid-column" }), h("ch-tabular-grid-column", { columnName: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").tableHead.description, settingable: false, sortable: false, size: "minmax(120px,auto)", class: "tabular-grid-column" }), h("ch-tabular-grid-column", { columnName: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").tableHead.modifiedOn, settingable: false, sortable: false, size: config.tabularGrid.colSize.maxContent, class: "tabular-grid-column" })), this.selection.map((obj) => (h("ch-tabular-grid-row", { rowid: obj.id, key: obj.id, class: "tabular-grid-row" }, h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, h("ch-image", { src: obj.typeIcon, class: "icon-s" })), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, obj.name), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, obj.type), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, obj.description), h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, `${formatDate(obj.modifiedOn)}`))))));
        });
        this.selectedObjectsIds = [];
        this.addCallback = undefined;
        this.cancelCallback = undefined;
        this.confirmCallback = undefined;
        this.selection = [];
    }
    componentDidLoad() {
        __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_listenChanges, "f").call(this);
    }
    componentDidRender() {
        if (!__classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_renderedFirstTime, "f")) {
            this.componentDidRenderFirstTime.emit(__classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").componentName);
            __classPrivateFieldSet(this, _GxIdeTeamDevUpdatePartialSelection_renderedFirstTime, true, "f");
        }
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, await Locale.getComponentStrings(this.el), "f");
        this.componentDidLoadEvent.emit(true);
    }
    /**
     * Validate necessary data input
     */
    async validate() {
        const isValid = true;
        return isValid;
    }
    render() {
        const buttonRemoveSelectedDisabled = !(this.selectedObjectsIds.length > 0);
        return (h(Host, { class: "widget" }, h("ch-theme", { model: CSS_BUNDLES }), h("ch-shortcuts", { src: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_shortcutsSrc, "f") }), h("section", { class: "section" }, h("header", { class: "header field-group dialog-header header header-two-cols spacing-body-block-start spacing-body-inline" }, h("div", { class: "buttons-spacer" }, h("button", {
            // remove selected button
            class: "button-secondary", onClick: !buttonRemoveSelectedDisabled &&
                __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_removeSelectedObjectsHandler, "f"), part: "remove", disabled: buttonRemoveSelectedDisabled
        }, __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").btnRemoveSelectedObjects), h("button", {
            // add button
            class: "button-secondary button-icon-and-text", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_getObjectsHandler, "f"), part: "add"
        }, h("ch-image", { class: "icon-m", src: GEMINI_TOOLS_ADD_ICON }), __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").btnAddObject))), __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_renderObjects, "f").call(this), h("footer", { class: "dialog-footer dialog-footer-space-between spacing-body-block-end spacing-body-inline" }, h("button", {
            // remove all button
            class: "button-tertiary", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_removeAllHandler, "f"), disabled: !(this.selection.length > 0), part: "clear"
        }, __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").footer.btnRemoveAll), h("div", { class: "buttons-spacer" }, h("button", {
            // cancel button
            class: "button-secondary", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_cancelHandler, "f"), part: "cancel"
        }, __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").footer.btnCancel), h("button", {
            // confirm button
            class: "button-primary", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection_confirmHandler, "f"), part: "confirm"
        }, __classPrivateFieldGet(this, _GxIdeTeamDevUpdatePartialSelection__componentLocale, "f").footer.btnConfirm))))));
    }
    static get is() { return "gx-ide-team-dev-update-partial-selection"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["update-partial-selection.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["update-partial-selection.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/team-dev-update-partial-selection"]; }
    static get properties() {
        return {
            "addCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "AddCallback",
                    "resolved": "() => Promise<ObjectData[]>",
                    "references": {
                        "AddCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/team-dev/update-partial-selection/update-partial-selection.tsx",
                            "id": "src/components/team-dev/update-partial-selection/update-partial-selection.tsx::AddCallback"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked to return a list of new objects to populate objects table."
                }
            },
            "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/team-dev/update-partial-selection/update-partial-selection.tsx",
                            "id": "src/components/team-dev/update-partial-selection/update-partial-selection.tsx::CancelCallback"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when the user wishes to cancel the selection of objects."
                }
            },
            "confirmCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "ConfirmCallback",
                    "resolved": "(ids: string[]) => Promise<void>",
                    "references": {
                        "ConfirmCallback": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/team-dev/update-partial-selection/update-partial-selection.tsx",
                            "id": "src/components/team-dev/update-partial-selection/update-partial-selection.tsx::ConfirmCallback"
                        }
                    }
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when confirm action is executed passing the selected objects ids."
                }
            },
            "selection": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "ObjectData[]",
                    "resolved": "ObjectData[]",
                    "references": {
                        "ObjectData": {
                            "location": "local",
                            "path": "/home/runner/work/genexus-ide-ui/genexus-ide-ui/src/components/team-dev/update-partial-selection/update-partial-selection.tsx",
                            "id": "src/components/team-dev/update-partial-selection/update-partial-selection.tsx::ObjectData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Current objects selection in the grid"
                },
                "defaultValue": "[]"
            }
        };
    }
    static get states() {
        return {
            "selectedObjectsIds": {}
        };
    }
    static get events() {
        return [{
                "method": "componentDidLoadEvent",
                "name": "componentDidLoadEvent",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Emitted once just after the component is fully loaded and the first render() occurs."
                },
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                }
            }, {
                "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 methods() {
        return {
            "validate": {
                "complexType": {
                    "signature": "() => Promise<boolean>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<boolean>"
                },
                "docs": {
                    "text": "Validate necessary data input",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
}
_GxIdeTeamDevUpdatePartialSelection__componentLocale = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_renderedFirstTime = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_shortcutsSrc = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_chGridEl = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_cancelHandler = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_confirmHandler = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_getObjectsHandler = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_listenChanges = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_removeAllHandler = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_removeSelectedObjectsHandler = new WeakMap(), _GxIdeTeamDevUpdatePartialSelection_renderObjects = new WeakMap();
//# sourceMappingURL=update-partial-selection.js.map
