"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = require("react");

var _propTypes = _interopRequireDefault(require("prop-types"));

// Copyright 1999-2017. Plesk International GmbH. All rights reserved.
class ScrollDirection extends _react.Component {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2.default)(this, "state", {
      direction: 'up'
    });
    (0, _defineProperty2.default)(this, "prevScrollTop", 0);
    (0, _defineProperty2.default)(this, "handleScroll", e => {
      const {
        scrollTop
      } = e.target;
      const direction = scrollTop > this.prevScrollTop ? 'down' : 'up';
      this.prevScrollTop = scrollTop;
      this.setState({
        direction
      });
    });
  }

  render() {
    const {
      children
    } = this.props;
    return children({
      direction: this.state.direction,
      handleScroll: this.handleScroll
    });
  }

}

ScrollDirection.propTypes = {
  children: _propTypes.default.func.isRequired
};
var _default = ScrollDirection;
exports.default = _default;