"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FadedScroll = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _Hooks = require("../../common/Hooks");
var _FadedScroll = require("./FadedScroll.styles");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var Container = _styledComponents.default.div.withConfig({
  displayName: "FadedScroll__Container",
  componentId: "sc-134qq0d-0"
})(["", " ", ""], _FadedScroll.containerStyles, _FadedScroll.fadeStyles);
var Scroller = _styledComponents.default.div.withConfig({
  displayName: "FadedScroll__Scroller",
  componentId: "sc-134qq0d-1"
})(["", ""], _FadedScroll.scrollerStyles);
var Content = _styledComponents.default.div.withConfig({
  displayName: "FadedScroll__Content",
  componentId: "sc-134qq0d-2"
})(["position:relative;overflow-x:hidden;"]);
var IntersectionBottom = _styledComponents.default.div.withConfig({
  displayName: "FadedScroll__IntersectionBottom",
  componentId: "sc-134qq0d-3"
})(["", " bottom:0;"], _FadedScroll.intersectionStyles);
var IntersectionTop = _styledComponents.default.div.withConfig({
  displayName: "FadedScroll__IntersectionTop",
  componentId: "sc-134qq0d-4"
})(["", " top:0;"], _FadedScroll.intersectionStyles);
var components = {
  Scroller: Scroller,
  Content: Content
};
var FadedScroll = exports.FadedScroll = function FadedScroll(_ref) {
  var children = _ref.children,
    className = _ref.className,
    disableTopFade = _ref.disableTopFade,
    _ref$enableMobileFade = _ref.enableMobileFade,
    enableMobileFade = _ref$enableMobileFade === void 0 ? false : _ref$enableMobileFade,
    _ref$fadeHeight = _ref.fadeHeight,
    fadeHeight = _ref$fadeHeight === void 0 ? 15 : _ref$fadeHeight,
    maxHeight = _ref.maxHeight;
  var _useIntersect = (0, _Hooks.useIntersect)(),
    _useIntersect2 = _slicedToArray(_useIntersect, 2),
    setIntersectionTopRef = _useIntersect2[0],
    intersectionTopRatio = _useIntersect2[1];
  var _useIntersect3 = (0, _Hooks.useIntersect)(),
    _useIntersect4 = _slicedToArray(_useIntersect3, 2),
    setIntersectionBottomRef = _useIntersect4[0],
    intersectionBottomRatio = _useIntersect4[1];
  var contentRef = (0, _react.useRef)(null);
  return _react.default.createElement(Container, {
    className: className,
    enableMobileFade: enableMobileFade,
    fadeTopPercentage: disableTopFade ? 0 : fadeHeight,
    fadeBottomPercentage: 100 - fadeHeight,
    intersectionTopRatio: intersectionTopRatio,
    intersectionBottomRatio: intersectionBottomRatio,
    maxHeight: maxHeight
  }, _react.default.createElement(Scroller, {
    enableMobileFade: enableMobileFade,
    maxHeight: maxHeight
  }, _react.default.createElement(Content, {
    ref: contentRef
  }, _react.default.createElement(IntersectionTop, {
    ref: setIntersectionTopRef
  }), children, _react.default.createElement(IntersectionBottom, {
    ref: setIntersectionBottomRef
  }))));
};
FadedScroll.components = components;
FadedScroll.displayName = 'FadedScroll';