import { addEventListener, withoutDefaults, } from '@wix/bex-core';
import { IntersectionObserverState } from '../../state';
import { makeObservable, observable } from 'mobx';
import { cairoTableTopNotificationDismissed, cairoTableTopNotificationDisplayed, } from '@wix/bex-core/bi';
export class TableTopNotificationState {
    constructor(params) {
        this.intersection = new IntersectionObserverState();
        this.position = 'inline';
        this.getStickyContentHeight = params.getStickyContentHeight;
        this.topNotification = params.topNotification;
        this.consideredVisibleRatio = params.consideredVisibleRatio ?? 0.9;
        this.reportBI = params.reportBI;
        makeObservable(this, {
            position: observable.ref,
        });
    }
    init() {
        const { topNotification: { events }, } = this;
        const disposers = [
            addEventListener(events, 'enter', () => {
                this.reportBI(withoutDefaults(cairoTableTopNotificationDisplayed)({
                    notificationText: this.topNotification.data ?? undefined,
                }));
                const startTime = performance.now();
                events.once('dismissed', ({ dismissMode }) => {
                    const duration = Math.round(performance.now() - startTime);
                    this.reportBI(withoutDefaults(cairoTableTopNotificationDismissed)({
                        dismissMode,
                        duration,
                        notificationText: this.topNotification.data ?? undefined,
                    }));
                });
            }),
        ];
        return () => {
            disposers.forEach((d) => d?.());
        };
    }
}
//# sourceMappingURL=TableTopNotificationState.js.map