import { proxyCustomElement, HTMLElement, createEvent, getAssetPath, h, Host } from '@stencil/core/internal/client';
import { g as getIconPath } from './mer-animated-dots.js';
import 'lit';
import 'lit/directives/when.js';
import 'lit/directives/if-defined.js';
import { c as config } from './config.js';
import { L as Locale } from './locale.js';
import { f as formatDate } from './helpers.js';

const updatePartialSelectionCss = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;block-size:100%;grid-template-rows:max-content 1fr max-content;overflow:auto}.section{display:contents}.header{justify-content:end}.tabular-grid-main{overflow:auto;block-size:100%}.tabular-grid-main ch-tabular-grid-cell:is(:nth-child(2),:nth-child(3),:nth-child(4)){align-items:start;justify-content:start;display:inline-block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-inline-size:0}";

var __classPrivateFieldGet = (undefined && undefined.__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 = (undefined && undefined.__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;
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"
});
const GxIdeTeamDevUpdatePartialSelection$1 = /*@__PURE__*/ proxyCustomElement(class GxIdeTeamDevUpdatePartialSelection extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.componentDidLoadEvent = createEvent(this, "componentDidLoadEvent", 7);
        this.componentDidRenderFirstTime = createEvent(this, "componentDidRenderFirstTime", 7);
        _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 assetsDirs() { return ["gx-ide-assets/team-dev-update-partial-selection"]; }
    get el() { return this; }
    static get style() { return updatePartialSelectionCss; }
}, [1, "gx-ide-team-dev-update-partial-selection", {
        "addCallback": [16],
        "cancelCallback": [16],
        "confirmCallback": [16],
        "selection": [1040],
        "selectedObjectsIds": [32],
        "validate": [64]
    }]);
_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();
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-team-dev-update-partial-selection"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-team-dev-update-partial-selection":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeTeamDevUpdatePartialSelection$1);
            }
            break;
    } });
}

const GxIdeTeamDevUpdatePartialSelection = GxIdeTeamDevUpdatePartialSelection$1;
const defineCustomElement = defineCustomElement$1;

export { GxIdeTeamDevUpdatePartialSelection, defineCustomElement };

//# sourceMappingURL=gx-ide-team-dev-update-partial-selection.js.map