import { action, computed, makeObservable, observable } from 'mobx';
export class MultiBulkActionToolbarState {
    constructor(props) {
        this._primaryActionItems = [];
        this._secondaryActionItems = [];
        const { collection, extensionMenuItems } = props;
        this._collection = collection;
        this._extensionMenuItems = extensionMenuItems;
        makeObservable(this, {
            _primaryActionItems: observable.ref,
            _secondaryActionItems: observable.ref,
            setActions: action,
            primaryActionItems: computed,
            secondaryActionItems: computed,
            secondaryActionItemsCount: computed,
        });
    }
    setActions({ primaryActionItems = [], secondaryActionItems = [], }) {
        this._primaryActionItems = primaryActionItems.map((item) => ({
            ...item,
            subItems: item.subItems
                ? Array.isArray(item.subItems?.[0])
                    ? item.subItems
                    : [item.subItems]
                : item.subItems,
        }));
        this._secondaryActionItems = Array.isArray(secondaryActionItems?.[0])
            ? secondaryActionItems
            : [secondaryActionItems];
    }
    _moreActionItemClick(item) {
        const { result: { total }, bulkSelect, } = this._collection;
        const { selectedIds, uncheckedIds, allSelected } = bulkSelect;
        item.onClick({
            selectedIds,
            uncheckedIds,
            isSelectAll: allSelected,
            total,
            ...this._extensionMenuItems.containerProps,
        });
    }
    get primaryActionItems() {
        return this._primaryActionItems;
    }
    get secondaryActionItems() {
        const moreActionItems = this._extensionMenuItems.menuItems.map((item) => ({
            ...item,
            label: item.text,
            onClick: () => this._moreActionItemClick(item),
        })) || [];
        return [...this._secondaryActionItems, moreActionItems];
    }
    get secondaryActionItemsCount() {
        return this.secondaryActionItems.reduce((result, group) => result + group.length, 0);
    }
}
//# sourceMappingURL=MultiBulkActionToolbarState.js.map