"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
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 _classnames = _interopRequireDefault(require("classnames"));
var _Item = _interopRequireDefault(require("./Item"));
var _utils = require("./utils");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/NestableListBase/Container.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 _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; })(); }
var Container = /*#__PURE__*/function (_Component) {
  function Container() {
    (0, _classCallCheck2["default"])(this, Container);
    return _callSuper(this, Container, arguments);
  }
  (0, _inherits2["default"])(Container, _Component);
  return (0, _createClass2["default"])(Container, [{
    key: "render",
    value: function render() {
      var _this = this;
      var _this$props = this.props,
        items = _this$props.items,
        parentPosition = _this$props.parentPosition,
        childrenProperty = _this$props.childrenProperty,
        childrenStyle = _this$props.childrenStyle,
        renderAction = _this$props.renderAction,
        treeDepth = _this$props.treeDepth,
        _this$props$isParentL = _this$props.isParentLastItem,
        isParentLastItem = _this$props$isParentL === void 0 ? true : _this$props$isParentL,
        isRenderDraggingChildren = _this$props.isRenderDraggingChildren,
        topLevel = _this$props.topLevel,
        theme = _this$props.theme;
      var containerClass;
      if (theme) {
        containerClass = topLevel && theme.topContainer || theme.container;
      }
      var classes = (0, _classnames["default"])('nestable-container', {
        'nestable-top-container': topLevel
      }, containerClass);
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: classes,
        style: topLevel ? {} : childrenStyle,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 32,
          columnNumber: 7
        }
      }, items.map(function (item, i) {
        var position = parentPosition.concat([i]);
        var children = item[childrenProperty] && item[childrenProperty].map(function (child) {
          if (item.lockDropArea || item.isParentLocked) {
            child.isParentLocked = true;
            child.draggable = false;
          }
          return child;
        });
        var hasChildren = children && children.length;
        var isLastItem = items.length - 1 === i;
        var actionButton = renderAction({
          siblings: items,
          item: item,
          veryLastItem: isLastItem && isParentLastItem,
          depth: treeDepth
        });
        var veryLastItem = isLastItem && isParentLastItem && (!hasChildren || item.isCollapsed) && !actionButton;
        return /*#__PURE__*/_react["default"].createElement(_Item["default"], {
          id: item.id,
          key: item.id,
          item: item,
          index: i,
          isVeryLastItem: veryLastItem,
          siblings: items,
          isRenderDraggingChildren: isRenderDraggingChildren,
          position: position,
          depth: (0, _utils.getDepth)(item, childrenProperty),
          theme: theme,
          __self: _this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 60,
            columnNumber: 13
          }
        }, !item.isCollapsed && /*#__PURE__*/_react["default"].createElement("div", {
          __self: _this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 73,
            columnNumber: 17
          }
        }, hasChildren ? /*#__PURE__*/_react["default"].createElement(WrappedContainer, {
          isParentLastItem: isLastItem && isParentLastItem && !actionButton,
          items: children,
          renderAction: renderAction,
          isRenderDraggingChildren: isRenderDraggingChildren,
          parentPosition: position,
          childrenProperty: childrenProperty,
          childrenStyle: childrenStyle,
          theme: theme,
          treeDepth: treeDepth + 1,
          __self: _this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 75,
            columnNumber: 21
          }
        }) : null, actionButton));
      }));
    }
  }]);
}(_react.Component);
var WrappedContainer = /*#__PURE__*/function (_React$PureComponent) {
  function WrappedContainer() {
    (0, _classCallCheck2["default"])(this, WrappedContainer);
    return _callSuper(this, WrappedContainer, arguments);
  }
  (0, _inherits2["default"])(WrappedContainer, _React$PureComponent);
  return (0, _createClass2["default"])(WrappedContainer, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react["default"].createElement(Container, (0, _extends2["default"])({}, this.props, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 102,
          columnNumber: 12
        }
      }));
    }
  }]);
}(_react["default"].PureComponent);
var _default = exports["default"] = WrappedContainer;