"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = 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 _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _core = require("@react-awesome-query-builder/core");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _GroupContainer = _interopRequireDefault(require("../containers/GroupContainer"));
var _Draggable = _interopRequireDefault(require("../containers/Draggable"));
var _Group = require("./Group");
var _RuleGroupActions = require("./RuleGroupActions");
var _FieldWrapper = _interopRequireDefault(require("../rule/FieldWrapper"));
var _utils = require("../utils");
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; })(); }
var getFieldConfig = _core.Utils.ConfigUtils.getFieldConfig;
var RuleGroup = /*#__PURE__*/function (_BasicGroup) {
  function RuleGroup(props) {
    var _this;
    (0, _classCallCheck2["default"])(this, RuleGroup);
    _this = _callSuper(this, RuleGroup, [props]);
    _this.childrenClassName = function () {
      return "rule_group--children";
    };
    _this.renderHeaderWrapper = function () {
      return null;
    };
    _this.renderFooterWrapper = function () {
      return null;
    };
    _this.renderConjs = function () {
      return null;
    };
    _this.canAddGroup = function () {
      return false;
    };
    _this.canAddRule = function () {
      return true;
    };
    _this.canDeleteGroup = function () {
      return false;
    };
    return _this;
  }
  (0, _inherits2["default"])(RuleGroup, _BasicGroup);
  return (0, _createClass2["default"])(RuleGroup, [{
    key: "onPropsChanged",
    value: function onPropsChanged(nextProps) {
      (0, _get2["default"])((0, _getPrototypeOf2["default"])(RuleGroup.prototype), "onPropsChanged", this).call(this, nextProps);
    }
  }, {
    key: "reordableNodesCntForItem",
    value: function reordableNodesCntForItem(_item) {
      if (this.props.isLocked) return 0;
      var children1 = this.props.children1;
      return (children1 === null || children1 === void 0 ? void 0 : children1.size) || 0;
    }
  }, {
    key: "renderChildrenWrapper",
    value: function renderChildrenWrapper() {
      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, this.renderDrag(), this.renderField(), this.renderActions(), (0, _get2["default"])((0, _getPrototypeOf2["default"])(RuleGroup.prototype), "renderChildrenWrapper", this).call(this));
    }
  }, {
    key: "renderField",
    value: function renderField() {
      var _this$props = this.props,
        config = _this$props.config,
        selectedField = _this$props.selectedField,
        selectedFieldSrc = _this$props.selectedFieldSrc,
        selectedFieldType = _this$props.selectedFieldType,
        setField = _this$props.setField,
        setFuncValue = _this$props.setFuncValue,
        setFieldSrc = _this$props.setFieldSrc,
        parentField = _this$props.parentField,
        id = _this$props.id,
        groupId = _this$props.groupId,
        isLocked = _this$props.isLocked;
      var immutableFieldsMode = config.settings.immutableFieldsMode;
      return /*#__PURE__*/_react["default"].createElement(_FieldWrapper["default"], {
        key: "field",
        classname: "group--field",
        config: config,
        canSelectFieldSource: false,
        selectedField: selectedField,
        selectedFieldSrc: selectedFieldSrc,
        selectedFieldType: selectedFieldType,
        setField: setField,
        setFuncValue: setFuncValue,
        setFieldSrc: setFieldSrc,
        parentField: parentField,
        readonly: immutableFieldsMode || isLocked,
        id: id,
        groupId: groupId
      });
    }
  }, {
    key: "renderActions",
    value: function renderActions() {
      var _this$props2 = this.props,
        config = _this$props2.config,
        addRule = _this$props2.addRule,
        isLocked = _this$props2.isLocked,
        isTrueLocked = _this$props2.isTrueLocked,
        id = _this$props2.id;
      return /*#__PURE__*/_react["default"].createElement(_RuleGroupActions.RuleGroupActions, {
        config: config,
        addRule: addRule,
        canAddRule: this.canAddRule(),
        canDeleteGroup: this.canDeleteGroup(),
        removeSelf: this.removeSelf,
        setLock: this.setLock,
        isLocked: isLocked,
        isTrueLocked: isTrueLocked,
        id: id
      });
    }
  }, {
    key: "extraPropsForItem",
    value: function extraPropsForItem(_item) {
      var _selectedFieldConfig$;
      var _this$props3 = this.props,
        selectedField = _this$props3.selectedField,
        lev = _this$props3.lev,
        config = _this$props3.config;
      var selectedFieldConfig = getFieldConfig(config, selectedField);
      return {
        parentField: selectedField,
        parentFieldPathSize: lev + 1,
        parentFieldCanReorder: (_selectedFieldConfig$ = selectedFieldConfig === null || selectedFieldConfig === void 0 ? void 0 : selectedFieldConfig.canReorder) !== null && _selectedFieldConfig$ !== void 0 ? _selectedFieldConfig$ : config.settings.canReorder
      };
    }
  }]);
}(_Group.BasicGroup);
RuleGroup.propTypes = _objectSpread(_objectSpread({}, _Group.BasicGroup.propTypes), {}, {
  selectedField: _propTypes["default"].any,
  selectedFieldSrc: _propTypes["default"].string,
  parentField: _propTypes["default"].string,
  setField: _propTypes["default"].func,
  setFieldSrc: _propTypes["default"].func,
  lev: _propTypes["default"].number // from GroupContainer
});
var _default = exports["default"] = (0, _GroupContainer["default"])((0, _Draggable["default"])("group rule_group")((0, _utils.WithConfirmFn)(RuleGroup)), "rule_group");