"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TableTopNotificationState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _bexCore = require("@wix/bex-core");
var _state = require("../../state");
var _mobx = require("mobx");
var _bi = require("@wix/bex-core/bi");
// import type { ScrollAwayPushStrategy } from './ScrollAwayPushStrategy';
// import { ScrollAwayScheduleStrategy } from './ScrollAwayScheduleStrategy';
// type ScrolledAwayStrategy = ScrollAwayPushStrategy | ScrollAwayScheduleStrategy;

class TableTopNotificationState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "getStickyContentHeight", void 0);
    (0, _defineProperty2.default)(this, "topNotification", void 0);
    (0, _defineProperty2.default)(this, "intersection", new _state.IntersectionObserverState());
    (0, _defineProperty2.default)(this, "consideredVisibleRatio", void 0);
    (0, _defineProperty2.default)(this, "reportBI", void 0);
    (0, _defineProperty2.default)(this, "position", 'inline');
    this.getStickyContentHeight = params.getStickyContentHeight;
    this.topNotification = params.topNotification;
    this.consideredVisibleRatio = params.consideredVisibleRatio ?? 0.9;
    this.reportBI = params.reportBI;
    (0, _mobx.makeObservable)(this, {
      position: _mobx.observable.ref
    });
  }
  init() {
    const {
      topNotification: {
        events
      }
    } = this;
    const disposers = [(0, _bexCore.addEventListener)(events, 'enter', () => {
      this.reportBI((0, _bexCore.withoutDefaults)(_bi.cairoTableTopNotificationDisplayed)({
        notificationText: this.topNotification.data ?? undefined
      }));
      const startTime = performance.now();
      events.once('dismissed', ({
        dismissMode
      }) => {
        const duration = Math.round(performance.now() - startTime);
        this.reportBI((0, _bexCore.withoutDefaults)(_bi.cairoTableTopNotificationDismissed)({
          dismissMode,
          duration,
          notificationText: this.topNotification.data ?? undefined
        }));
      });
    })];
    return () => {
      disposers.forEach(d => d == null ? void 0 : d());
    };
  }
}
exports.TableTopNotificationState = TableTopNotificationState;
//# sourceMappingURL=TableTopNotificationState.js.map