"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
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 _core = require("@react-awesome-query-builder/core");
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _Item = require("./item/Item");
var _SortableContainer = _interopRequireDefault(require("./containers/SortableContainer"));
var _reactUtils = require("../utils/reactUtils");
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 && {}.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 _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 _Utils$TreeUtils = _core.Utils.TreeUtils,
  getTotalReordableNodesCountInTree = _Utils$TreeUtils.getTotalReordableNodesCountInTree,
  getTotalRulesCountInTree = _Utils$TreeUtils.getTotalRulesCountInTree;
var _Utils$DefaultUtils = _core.Utils.DefaultUtils,
  createListWithOneElement = _Utils$DefaultUtils.createListWithOneElement,
  emptyProperties = _Utils$DefaultUtils.emptyProperties;
var Builder = /*#__PURE__*/function (_Component) {
  function Builder(props) {
    var _this;
    (0, _classCallCheck2["default"])(this, Builder);
    _this = _callSuper(this, Builder, [props]);
    _this.pureShouldComponentUpdate = (0, _reactUtils.pureShouldComponentUpdate)(_this);
    _this._updPath(props);
    return _this;
  }
  (0, _inherits2["default"])(Builder, _Component);
  return (0, _createClass2["default"])(Builder, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate(nextProps, nextState) {
      var should = this.pureShouldComponentUpdate(nextProps, nextState);
      return should;
    }
  }, {
    key: "_updPath",
    value: function _updPath(props) {
      var id = props.tree.get("id");
      this.path = createListWithOneElement(id);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
        tree = _this$props.tree,
        config = _this$props.config,
        actions = _this$props.actions,
        onDragStart = _this$props.onDragStart;
      var rootType = tree.get("type");
      var isTernary = rootType == "switch_group";
      var reordableNodesCnt = isTernary ? null : getTotalReordableNodesCountInTree(tree);
      var totalRulesCnt = isTernary ? null : getTotalRulesCountInTree(tree);
      var id = tree.get("id");
      return /*#__PURE__*/_react["default"].createElement(_Item.Item, {
        key: id,
        id: id,
        path: this.path,
        type: rootType,
        properties: tree.get("properties") || emptyProperties(),
        config: config,
        actions: actions,
        children1: tree.get("children1") || emptyProperties(),
        reordableNodesCnt: reordableNodesCnt,
        totalRulesCnt: totalRulesCnt,
        parentReordableNodesCnt: 0,
        onDragStart: onDragStart
      });
    }
  }]);
}(_react.Component);
Builder.propTypes = {
  tree: _propTypes["default"].any.isRequired,
  //instanceOf(Immutable.Map)
  config: _propTypes["default"].object.isRequired,
  actions: _propTypes["default"].object.isRequired,
  onDragStart: _propTypes["default"].func
};
var _default = exports["default"] = (0, _SortableContainer["default"])(Builder);