import _defineProperty from "@babel/runtime/helpers/defineProperty";
// Copyright 1999-2017. Plesk International GmbH. All rights reserved.
import { Component } from 'react';
import PropTypes from 'prop-types';

class ScrollDirection extends Component {
  constructor(...args) {
    super(...args);

    _defineProperty(this, "state", {
      direction: 'up'
    });

    _defineProperty(this, "prevScrollTop", 0);

    _defineProperty(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.func.isRequired
};
export default ScrollDirection;