import { addEventListener } from '@wix/bex-core/util';
import { withoutIrrelevant } from '@wix/bex-core';
import { cairoItemSelectionToggled } from '@wix/bex-core/bi';
import { action } from 'mobx';
const withoutDefaults = withoutIrrelevant();
export class PickerContentStateBI {
    constructor(params) {
        this.state = params.state;
    }
    init() {
        const { events } = this.state;
        const disposers = [
            addEventListener(events, 'beforeToggleIsSelectAll', () => {
                const { picker, reportBi } = this.state;
                const { collection: { bulkSelect, query: { search }, }, } = picker;
                const numItemsBefore = bulkSelect.selectedCountOrTotal;
                return {
                    afterToggleIsSelectAll: action(() => {
                        const { allSelected } = bulkSelect;
                        reportBi(withoutDefaults(cairoItemSelectionToggled)({
                            ...picker._commonDynamicBiParams(),
                            url: typeof window !== 'undefined' ? window.location.href : '',
                            isSelectAll: true,
                            isFromSearch: !search.isEmpty,
                            searchQuery: search.value,
                            itemId: allSelected ? 'All' : undefined,
                            clickType: allSelected ? 'Selection' : 'Deselection',
                            numItemsBefore,
                            numItemsAfter: bulkSelect.selectedCountOrTotal,
                        }));
                    }),
                };
            }),
        ];
        return () => {
            disposers.forEach((d) => d());
        };
    }
}
//# sourceMappingURL=PickerContentStateBI.js.map