"use strict";

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

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

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

var _styles = require("@vincent_za/styles");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(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); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n    overflow: auto;\n    ", ";\n\n    &:hover {\n      ", ";\n      ", ";\n    };\n\n    ", ";\n    ", ";\n    ", ";\n  "]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

function ScrollHOC(WrappedComponent) {
  var _class, _temp;

  var Wrap = (0, _styledComponents.default)(WrappedComponent)(_templateObject(), function (props) {
    return props.isAppElement ? "\n      overflow-x: hidden;\n      ".concat(!props.isTouchDevice && _styles.SCROLLBARS_APP, ";") : "".concat(!props.isTouchDevice && _styles.SCROLLBARS_MIN_HIDDEN, ";");
  }, function (props) {
    return !props.isTouchDevice && !props.isAppElement && _styles.SCROLLBARS_MIN;
  }, function (props) {
    return !props.isTouchDevice && !props.isAppElement && props.isLightScrollVariant && _styles.SCROLLBARS_MIN_LIGHT;
  }, function (props) {
    return (props.isNoOverflow || props.isOverflowX || props.isOverflowY) && 'overflow: hidden';
  }, function (props) {
    return props.isOverflowY && 'overflow-y: auto';
  }, function (props) {
    return props.isOverflowX && 'overflow-x: auto';
  });
  return _temp = _class =
  /*#__PURE__*/
  function (_React$PureComponent) {
    _inherits(Scroll, _React$PureComponent);

    function Scroll() {
      _classCallCheck(this, Scroll);

      return _possibleConstructorReturn(this, _getPrototypeOf(Scroll).apply(this, arguments));
    }

    _createClass(Scroll, [{
      key: "render",
      value: function render() {
        var _this$props = this.props,
            isAppElement = _this$props.isAppElement,
            isTouchDevice = _this$props.isTouchDevice,
            isLightScrollVariant = _this$props.isLightScrollVariant,
            isNoOverflow = _this$props.isNoOverflow,
            isOverflowX = _this$props.isOverflowX,
            isOverflowY = _this$props.isOverflowY,
            className = _this$props.className,
            children = _this$props.children;
        return _react.default.createElement(Wrap, _extends({
          isAppElement: isAppElement,
          isTouchDevice: isTouchDevice,
          isLightScrollVariant: isLightScrollVariant,
          isNoOverflow: isNoOverflow,
          isOverflowX: isOverflowX,
          isOverflowY: isOverflowY,
          className: className
        }, this.props, {
          ref: this.props.passedRef
        }), children);
      }
    }]);

    return Scroll;
  }(_react.default.PureComponent), _defineProperty(_class, "propTypes", {
    isAppElement: _propTypes.bool,
    isTouchDevice: _propTypes.bool.isRequired,
    isLightScrollVariant: _propTypes.bool,
    isNoOverflow: _propTypes.bool,
    isOverflowX: _propTypes.bool,
    isOverflowY: _propTypes.bool,
    className: _propTypes.string,
    children: _propTypes.node.isRequired
  }), _defineProperty(_class, "defaultProps", {
    isAppElement: false,
    isLightScrollVariant: false,
    isNoOverflow: false,
    isOverflowX: false,
    isOverflowY: false,
    className: undefined
  }), _temp;
}

var _default = ScrollHOC;
exports.default = _default;