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; }
import React, { useRef } from 'react';
import styled from 'styled-components';
import { useIntersect } from '../../common/Hooks';
import { containerStyles, intersectionStyles, scrollerStyles, fadeStyles } from './FadedScroll.styles';
var Container = styled.div.withConfig({
  displayName: "FadedScroll__Container",
  componentId: "sc-134qq0d-0"
})(["", " ", ""], containerStyles, fadeStyles);
var Scroller = styled.div.withConfig({
  displayName: "FadedScroll__Scroller",
  componentId: "sc-134qq0d-1"
})(["", ""], scrollerStyles);
var Content = styled.div.withConfig({
  displayName: "FadedScroll__Content",
  componentId: "sc-134qq0d-2"
})(["position:relative;overflow-x:hidden;"]);
var IntersectionBottom = styled.div.withConfig({
  displayName: "FadedScroll__IntersectionBottom",
  componentId: "sc-134qq0d-3"
})(["", " bottom:0;"], intersectionStyles);
var IntersectionTop = styled.div.withConfig({
  displayName: "FadedScroll__IntersectionTop",
  componentId: "sc-134qq0d-4"
})(["", " top:0;"], intersectionStyles);
var components = {
  Scroller: Scroller,
  Content: Content
};
export var 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 = useIntersect(),
    _useIntersect2 = _slicedToArray(_useIntersect, 2),
    setIntersectionTopRef = _useIntersect2[0],
    intersectionTopRatio = _useIntersect2[1];
  var _useIntersect3 = useIntersect(),
    _useIntersect4 = _slicedToArray(_useIntersect3, 2),
    setIntersectionBottomRef = _useIntersect4[0],
    intersectionBottomRatio = _useIntersect4[1];
  var contentRef = useRef(null);
  return React.createElement(Container, {
    className: className,
    enableMobileFade: enableMobileFade,
    fadeTopPercentage: disableTopFade ? 0 : fadeHeight,
    fadeBottomPercentage: 100 - fadeHeight,
    intersectionTopRatio: intersectionTopRatio,
    intersectionBottomRatio: intersectionBottomRatio,
    maxHeight: maxHeight
  }, React.createElement(Scroller, {
    enableMobileFade: enableMobileFade,
    maxHeight: maxHeight
  }, React.createElement(Content, {
    ref: contentRef
  }, React.createElement(IntersectionTop, {
    ref: setIntersectionTopRef
  }), children, React.createElement(IntersectionBottom, {
    ref: setIntersectionBottomRef
  }))));
};
FadedScroll.components = components;
FadedScroll.displayName = 'FadedScroll';