"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

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

var _Fab = _interopRequireDefault(require("@material-ui/core/Fab"));

var _VerticalAlignTop = _interopRequireDefault(require("@material-ui/icons/VerticalAlignTop"));

var _styles = require("@material-ui/core/styles");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const styles = theme => {
  return {
    fab: {
      position: 'fixed',
      zIndex: 100
    }
  };
};

const ScrollToTopFab = props => {
  const {
    theme,
    label,
    bottom,
    right,
    Icon,
    parentRef,
    selector,
    scrollParent
  } = props;

  const scrollToTop = props => {
    if (selector) {
      const x = document.querySelector(selector);
      x.scrollTo(0, 0);
    } else if (parentRef && parentRef.current) {
      let e = scrollParent ? parentRef.current.parentElement : parentRef.current;
      e.scrollTo(0, 0);
    } else {
      document.body.scrollTop = document.documentElement.scrollTop = 0;
      if (window.scrollTo) window.scrollTo(0, 0);
    }
  };

  const fabProps = {
    'aria-label': label,
    onClick: scrollToTop || scrollToTop.bind(void 0, props),
    style: {
      bottom: bottom || 30,
      right: right || 30
    }
  };
  return /*#__PURE__*/_react.default.createElement(_Fab.default, _extends({}, fabProps, {
    className: props.classes.fab
  }), Icon);
};

ScrollToTopFab.propTypes = {
  classes: _propTypes.default.object,
  bottom: _propTypes.default.number,
  right: _propTypes.default.number,
  theme: _propTypes.default.object,
  Icon: _propTypes.default.object,
  label: _propTypes.default.string,
  selector: _propTypes.default.string,
  parentRef: _propTypes.default.object,
  scrollParent: _propTypes.default.bool
};
ScrollToTopFab.defaultProps = {
  Icon: /*#__PURE__*/_react.default.createElement(_VerticalAlignTop.default, null),
  label: 'top'
};

var _default = (0, _styles.withStyles)(styles)((0, _styles.withTheme)(ScrollToTopFab));

exports.default = _default;