"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
exports.__esModule = true;
exports.SidebarContentWrapper = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireWildcard(require("react"));
var _SidebarSt = require("./Sidebar.st.css.js");
var _constants = require("./constants");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Sidebar/SidebarContentWrapper.jsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
/** A sidebar content children wrapper to add gradient  */
var SidebarContentWrapper = exports.SidebarContentWrapper = /*#__PURE__*/function (_Component) {
  function SidebarContentWrapper(props) {
    var _this;
    (0, _classCallCheck2["default"])(this, SidebarContentWrapper);
    _this = _callSuper(this, SidebarContentWrapper, [props]);
    _this._handleChildrenResize = function () {
      _this._shouldAddGradient();
    };
    _this.childrenContainerRef = /*#__PURE__*/_react["default"].createRef();
    _this.childrenContentRef = /*#__PURE__*/_react["default"].createRef();
    _this.state = {
      isScrollbarDisplayed: false
    };
    _this.childrenResizeObserver = typeof window !== 'undefined' && 'ResizeObserver' in window && new ResizeObserver(_this._handleChildrenResize);
    return _this;
  }
  (0, _inherits2["default"])(SidebarContentWrapper, _Component);
  return (0, _createClass2["default"])(SidebarContentWrapper, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this._shouldAddGradient();
      var childrenResizeObserver = this.childrenResizeObserver,
        childrenContainerRef = this.childrenContainerRef,
        childrenContentRef = this.childrenContentRef;
      if (childrenResizeObserver && childrenContainerRef.current) {
        childrenResizeObserver.observe(childrenContainerRef.current);
      }
      if (childrenResizeObserver && childrenContentRef.current) {
        childrenResizeObserver.observe(childrenContentRef.current);
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      var childrenResizeObserver = this.childrenResizeObserver,
        childrenContainerRef = this.childrenContainerRef,
        childrenContentRef = this.childrenContentRef;
      if (childrenResizeObserver && childrenContainerRef.current) {
        childrenResizeObserver.unobserve(childrenContainerRef.current);
      }
      if (childrenResizeObserver && childrenContentRef.current) {
        childrenResizeObserver.unobserve(childrenContentRef.current);
      }
    }
  }, {
    key: "_shouldAddGradient",
    value: function _shouldAddGradient() {
      var _this$childrenContain = this.childrenContainerRef.current,
        scrollHeight = _this$childrenContain.scrollHeight,
        clientHeight = _this$childrenContain.clientHeight;
      this.setState({
        isScrollbarDisplayed: scrollHeight > clientHeight
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
        skin = _this$props.skin,
        containerClasses = _this$props.containerClasses,
        children = _this$props.children,
        containerDataHook = _this$props.containerDataHook;
      var css = _objectSpread(_objectSpread({}, _SidebarSt.classes), {}, {
        containerClasses: containerClasses
      });
      var gradientClasses = (0, _SidebarSt.st)(_SidebarSt.classes.gradient, {
        skin: skin
      });
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: css.containerClasses,
        ref: this.childrenContainerRef,
        "data-hook": containerDataHook,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 72,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: css.childrenContent,
        ref: this.childrenContentRef,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 77,
          columnNumber: 9
        }
      }, children), this.state.isScrollbarDisplayed && /*#__PURE__*/_react["default"].createElement("div", {
        className: gradientClasses,
        "data-hook": _constants.dataHooks.scrollBarGradient,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 81,
          columnNumber: 11
        }
      }));
    }
  }]);
}(_react.Component);
SidebarContentWrapper.defaultProps = {
  skin: _constants.sidebarSkins.dark
};