/**
*
* CardGrid
*
*/

import PropTypes from 'prop-types';

import React from 'react';
import './_pagination.scss';
class Pagination extends React.Component { // eslint-disable-line react/prefer-stateless-function


  handleScroll = (e) => {
    const offset = 50;
    if ((e.target.scrollHeight - e.target.scrollTop) - offset <= e.target.clientHeight && !this.props.templateInProgress) {
      this.props.onPageChange();
    }
  };

  render() {
    return (
      <div style={this.props.style ? this.props.style : {}} onScrollCapture={this.handleScroll}>
        {this.props.children}
      </div>
    );
  }
}

Pagination.propTypes = {
  children: PropTypes.element,
  onPageChange: PropTypes.func,
  style: PropTypes.object,
  templateInProgress: PropTypes.bool,
};

Pagination.defaultProps = {};

export default Pagination;
