"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ScrollAwayPushStrategy = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
class ScrollAwayPushStrategy {
  constructor(state) {
    (0, _defineProperty2.default)(this, "state", void 0);
    this.state = state;
    (0, _mobx.makeObservable)(this, {
      switchToSticky: _mobx.action.bound,
      switchToInline: _mobx.action.bound,
      onIntersectionRatioChanged: _mobx.action.bound
    });
  }
  switchToSticky() {
    const {
      consideredVisibleRatio,
      intersection: {
        intersectionRatio
      },
      position
    } = this.state;
    if (position !== 'sticky' && intersectionRatio < consideredVisibleRatio) {
      this.state.position = 'sticky';
    }
  }
  switchToInline() {
    this.state.position = 'inline';
  }
  onIntersectionRatioChanged(ratio) {
    const {
      position,
      consideredVisibleRatio
    } = this.state;
    if (position === 'sticky' && ratio >= consideredVisibleRatio) {
      this.state.position = 'inline';
    }
  }
  init() {
    const {
      topNotification
    } = this.state;
    topNotification.events.on('enter', this.switchToSticky);
    topNotification.events.on('beforeExit', this.switchToSticky);
    topNotification.events.on('exited', this.switchToInline);
    return () => {
      topNotification.events.off('enter', this.switchToSticky);
      topNotification.events.off('beforeExit', this.switchToSticky);
      topNotification.events.off('exited', this.switchToInline);
    };
  }
}
exports.ScrollAwayPushStrategy = ScrollAwayPushStrategy;
//# sourceMappingURL=ScrollAwayPushStrategy.js.map