import { action, computed, makeObservable, observable } from 'mobx';
const statuses = {
    empty: {
        type: 'empty',
        toggle: () => statuses.partial,
        toggleCheckbox: true,
    },
    partial: {
        type: 'partial',
        toggle: () => statuses.full,
        toggleCheckbox: true,
    },
    full: {
        type: 'full',
        toggle: () => statuses.empty,
        toggleCheckbox: false,
    },
};
export class IndeterminateMapState {
    constructor() {
        this._map = observable.map([], {
            deep: false,
        });
        makeObservable(this, {
            toggle: action,
            setManyPartial: action,
            partialModeKeys: computed,
            partialModeKeysSet: computed,
        });
    }
    toggle(key) {
        const { _map } = this;
        const currentStatus = _map.get(key);
        if (currentStatus == null) {
            return;
        }
        const nextStatus = currentStatus.toggle();
        _map.set(key, nextStatus);
        return nextStatus;
    }
    setManyPartial(keys) {
        const { _map } = this;
        for (const key of keys) {
            if (!_map.has(key)) {
                _map.set(key, statuses.partial);
            }
        }
    }
    isPartial(key) {
        const { _map } = this;
        return _map.get(key)?.type === 'partial';
    }
    get partialModeKeys() {
        return Array.from(this._map.entries())
            .filter(([, value]) => value.type === 'partial')
            .map(([key]) => key);
    }
    get partialModeKeysSet() {
        const { partialModeKeys } = this;
        return new Set(partialModeKeys);
    }
}
//# sourceMappingURL=IndeterminateMapState.js.map