"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.SELECTFIELDS = exports.SELECTCHANGE = exports.OPTIONDATASET = exports.MENURESULT = exports.MENUDATASET = exports.FILTERMENUDATASET = exports.CONDITIONSTATUS = exports.CONDITIONDATASET = void 0;
exports.isEqualDynamicProps = isEqualDynamicProps;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _tslib = require("tslib");

var _react = _interopRequireWildcard(require("react"));

var _mobxReact = require("mobx-react");

var _mobx = require("mobx");

var _uniq = _interopRequireDefault(require("lodash/uniq"));

var _pull = _interopRequireDefault(require("lodash/pull"));

var _noop = _interopRequireDefault(require("lodash/noop"));

var _map = _interopRequireDefault(require("lodash/map"));

var _isObject = _interopRequireDefault(require("lodash/isObject"));

var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));

var _isNumber = _interopRequireDefault(require("lodash/isNumber"));

var _isFunction = _interopRequireDefault(require("lodash/isFunction"));

var _isEqual = _interopRequireDefault(require("lodash/isEqual"));

var _isArray = _interopRequireDefault(require("lodash/isArray"));

var _isString = _interopRequireDefault(require("lodash/isString"));

var _omit = _interopRequireDefault(require("lodash/omit"));

var _debounce = _interopRequireDefault(require("lodash/debounce"));

var _difference = _interopRequireDefault(require("lodash/difference"));

var _defer = _interopRequireDefault(require("lodash/defer"));

var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));

var _classnames = _interopRequireDefault(require("classnames"));

var _utils = require("../../../../lib/configure/utils");

var _UnitConvertor = require("../../../../lib/_util/UnitConvertor");

var _icon = _interopRequireDefault(require("../../../../lib/icon"));

var _KeyCode = _interopRequireDefault(require("../../../../lib/_util/KeyCode"));

var _enum = require("../../../../lib/trigger/enum");

var _DataSet = _interopRequireDefault(require("../../data-set/DataSet"));

var _enum2 = require("../../data-set/enum");

var _button = _interopRequireDefault(require("../../button"));

var _dropdown = _interopRequireDefault(require("../../dropdown"));

var _textField = _interopRequireDefault(require("../../text-field"));

var _tooltip = _interopRequireDefault(require("../../tooltip"));

var _TableContext = _interopRequireDefault(require("../TableContext"));

var _localeContext = require("../../locale-context");

var _autobind = _interopRequireDefault(require("../../_util/autobind"));

var _isEmpty3 = _interopRequireDefault(require("../../_util/isEmpty"));

var _FieldList = _interopRequireDefault(require("../../table/query-bar/FieldList"));

var _ColumnFilter = _interopRequireDefault(require("../tool-bar/ColumnFilter"));

var _enum3 = require("../../text-field/enum");

var _QuickFilterMenu = _interopRequireDefault(require("../../table/query-bar/quick-filter/QuickFilterMenu"));

var _QuickFilterMenuContext = _interopRequireDefault(require("../../table/query-bar/quick-filter/QuickFilterMenuContext"));

var _QuickFilterDataSet = require("../../table/query-bar/quick-filter/QuickFilterDataSet");

var _singleton = require("../../tooltip/singleton");

var _enum4 = require("../../field/enum");

var _TableButtons = _interopRequireDefault(require("../../table/query-bar/TableButtons"));

var _utils2 = require("../../field/utils");

/**
 * 当前数据是否有值并需要选中
 * @param data
 */
function isSelect(data) {
  if ((0, _isObject["default"])(data[1])) {
    return !(0, _isEmpty2["default"])(data[1]);
  }

  return data[0] !== '__dirty' && !(0, _isEmpty3["default"])(data[1]);
}

function isEqualDynamicProps(originalValue, newValue, dataSet, record, name) {
  if ((0, _isEqual["default"])(newValue, originalValue)) {
    return true;
  }

  if ((0, _isObject["default"])(newValue) && (0, _isObject["default"])(originalValue) && Object.keys(newValue).length) {
    var combineKeys = Object.keys(newValue).concat(Object.keys(originalValue));
    return combineKeys.every(function (key) {
      var value = newValue[key];
      var oldValue = originalValue[key];

      if (oldValue === value) {
        return true;
      }

      if ((0, _isEmpty3["default"])(oldValue) && (0, _isEmpty3["default"])(value)) {
        return true;
      }

      if (name && name.includes('.')) {
        return (0, _isEmpty3["default"])(oldValue) && (0, _isEmpty3["default"])(record.get(name));
      }

      if ((0, _isNumber["default"])(oldValue) || (0, _isNumber["default"])(value)) {
        var oEp = (0, _isNumber["default"])(oldValue) ? (0, _isEmpty3["default"])(oldValue) : (0, _isEmpty2["default"])(oldValue);
        var nEp = (0, _isNumber["default"])(value) ? (0, _isEmpty3["default"])(value) : (0, _isEmpty2["default"])(value);

        if (oEp && nEp) {
          return true;
        }

        return String(oldValue) === String(value);
      }

      var field = dataSet.getField(key);

      if (field && field.get('range', record)) {
        var rangeValue = value ? (0, _isArray["default"])(value) ? value.join('') : Object.values(value).join('') : '';
        var rangeOldValue = oldValue ? (0, _isArray["default"])(oldValue) ? oldValue.join('') : Object.values(oldValue).join('') : '';
        return rangeValue === rangeOldValue;
      }

      if (field && field.get('lovCode') && oldValue && value) {
        var valueField = dataSet.getField(key).get('valueField', record);
        var textField = dataSet.getField(key).get('textField', record);
        return value[valueField] === oldValue[valueField] && value[textField] === oldValue[textField];
      }

      return (0, _isEqual["default"])(oldValue, value);
    });
  }

  return (0, _isEqual["default"])(newValue, originalValue);
}

function getQueryData(queryDataSet) {
  var current = queryDataSet.current;

  if (current) {
    var queryData = (0, _omit["default"])(current.toData(true), ['__dirty']);
    return Object.keys(queryData).reduce(function (p, key) {
      var value = queryData[key];

      if (!(0, _isEmpty3["default"])(value)) {
        p[key] = value;
      }

      return p;
    }, {});
  }

  return {};
}

var CONDITIONSTATUS = '__CONDITIONSTATUS__';
exports.CONDITIONSTATUS = CONDITIONSTATUS;
var SELECTFIELDS = '__SELECTFIELDS__';
exports.SELECTFIELDS = SELECTFIELDS;
var MENUDATASET = '__MENUDATASET__';
exports.MENUDATASET = MENUDATASET;
var CONDITIONDATASET = '__CONDITIONDATASET__';
exports.CONDITIONDATASET = CONDITIONDATASET;
var OPTIONDATASET = '__OPTIONDATASET__';
exports.OPTIONDATASET = OPTIONDATASET;
var FILTERMENUDATASET = '__FILTERMENUDATASET__';
exports.FILTERMENUDATASET = FILTERMENUDATASET;
var MENURESULT = '__MENURESULT__';
exports.MENURESULT = MENURESULT;
var SELECTCHANGE = '__SELECTCHANGE__';
exports.SELECTCHANGE = SELECTCHANGE;

var TableDynamicFilterBar = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(TableDynamicFilterBar, _Component);

  var _super = (0, _createSuper2["default"])(TableDynamicFilterBar);

  function TableDynamicFilterBar(props, context) {
    var _this;

    (0, _classCallCheck2["default"])(this, TableDynamicFilterBar);
    _this = _super.call(this, props, context);
    _this.refDropdown = null;
    _this.refFilterWrapper = null;
    _this.refSingleWrapper = null;
    _this.refEditors = new Map();
    _this.refFilterItems = new Map();
    _this.originalConditionFields = [];
    _this.enterNum = 0;

    _this.handleClickOut = function (e) {
      if (_this.refDropdown && !_this.refDropdown.contains(e.target)) {
        _this.fieldSelectHidden = true;
      }
    };

    _this.setOriginalConditionFields = function (code) {
      var queryDataSet = _this.props.queryDataSet;

      if (!code) {
        if (queryDataSet) {
          _this.initConditionFields({
            dataSet: queryDataSet,
            record: queryDataSet.get(0)
          });
        }
      } else {
        _this.originalConditionFields = Array.isArray(code) ? code : [code];
      }

      queryDataSet.setState(SELECTFIELDS, (0, _toConsumableArray2["default"])(_this.originalConditionFields));
    };
    /**
     * 勾选
     * @param code
     * @param record
     */


    _this.handleSelect = function (code, record) {
      var queryDataSet = _this.props.queryDataSet;
      var codes = Array.isArray(code) ? code : [code];
      var selectFields = queryDataSet.getState(SELECTFIELDS) || [];
      queryDataSet.setState(SELECTFIELDS, (0, _uniq["default"])([].concat((0, _toConsumableArray2["default"])(selectFields), (0, _toConsumableArray2["default"])(codes))));
      var shouldUpdate = queryDataSet.getState(SELECTFIELDS).length !== _this.originalConditionFields.length || !!(0, _difference["default"])((0, _mobx.toJS)(queryDataSet.getState(SELECTFIELDS)), (0, _mobx.toJS)(_this.originalConditionFields)).length;
      var isDirty = record ? record.dirty : false;

      _this.setConditionStatus(shouldUpdate || isDirty ? _enum2.RecordStatus.update : _enum2.RecordStatus.sync);

      queryDataSet.setState(SELECTCHANGE, shouldUpdate);
    };
    /**
     * 取消勾选
     * @param code
     */


    _this.handleUnSelect = function (code) {
      var queryDataSet = _this.props.queryDataSet;
      var codes = Array.isArray(code) ? code : [code];

      if (queryDataSet) {
        var current = queryDataSet.current;

        if (current) {
          codes.forEach(function (name) {
            return current.set(name, undefined);
          });
        }
      }

      var selectFields = queryDataSet.getState(SELECTFIELDS) || [];
      queryDataSet.setState(SELECTFIELDS, _pull["default"].apply(void 0, [(0, _toConsumableArray2["default"])(selectFields)].concat((0, _toConsumableArray2["default"])(codes))));
      var shouldUpdate = queryDataSet.getState(SELECTFIELDS).length !== _this.originalConditionFields.length || !!(0, _difference["default"])((0, _mobx.toJS)(queryDataSet.getState(SELECTFIELDS)), (0, _mobx.toJS)(_this.originalConditionFields)).length;

      _this.setConditionStatus(shouldUpdate ? _enum2.RecordStatus.update : _enum2.RecordStatus.sync);

      queryDataSet.setState(SELECTCHANGE, shouldUpdate);
    };

    (0, _mobx.runInAction)(function () {
      _this.fieldSelectHidden = true;
      _this.expand = true;
    });
    return _this;
  }

  (0, _createClass2["default"])(TableDynamicFilterBar, [{
    key: "prefixCls",
    get: function get() {
      if ('prefixCls' in this.props) {
        var prefixCls = this.props.prefixCls;
        return prefixCls;
      }

      var _this$context$tableSt = this.context.tableStore.proPrefixCls,
          proPrefixCls = _this$context$tableSt === void 0 ? (0, _utils.getProPrefixCls)('performance-table') : _this$context$tableSt;
      return proPrefixCls;
    }
  }, {
    key: "queryFields",
    get: function get() {
      var _this$props = this.props,
          queryFields = _this$props.queryFields,
          queryDataSet = _this$props.queryDataSet;
      var menuDataSet = queryDataSet.getState(MENUDATASET);
      var isTenant = menuDataSet && menuDataSet.current && menuDataSet.current.get('isTenant');
      return queryFields.filter(function (component) {
        if (component.props.hidden) {
          return !component.props.hidden;
        }

        if (isTenant && queryDataSet && queryDataSet.getField(component.props.name)) {
          return queryDataSet.getField(component.props.name).get('fieldVisible') !== 0;
        }

        return !component.props.hidden;
      });
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;

      var _this$props2 = this.props,
          fuzzyQueryOnly = _this$props2.fuzzyQueryOnly,
          queryDataSet = _this$props2.queryDataSet;

      if (!fuzzyQueryOnly) {
        this.processDataSetListener(true);

        if (queryDataSet && queryDataSet.records.length > 0 && !queryDataSet.getState(MENUDATASET)) {
          this.handleDataSetCreate();
        }

        document.addEventListener('click', this.handleClickOut);

        if (this.isSingleLineOpt() && this.refSingleWrapper) {
          var _this$refSingleWrappe = this.refSingleWrapper.getBoundingClientRect(),
              height = _this$refSingleWrappe.height;

          var _this$refSingleWrappe2 = this.refSingleWrapper.children[0].children[0].getBoundingClientRect(),
              childHeight = _this$refSingleWrappe2.height;

          (0, _mobx.runInAction)(function () {
            _this2.showExpandIcon = height > childHeight + 18;
          });
        }
      }

      if (this.originalValue === undefined && queryDataSet && queryDataSet.current) {
        this.initConditionFields({
          dataSet: queryDataSet,
          record: queryDataSet.current
        });
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      var fuzzyQueryOnly = this.props.fuzzyQueryOnly;

      if (!fuzzyQueryOnly) {
        document.removeEventListener('click', this.handleClickOut);
        this.processDataSetListener(false);
      }

      if (this.isTooltipShown) {
        (0, _singleton.hide)();
        delete this.isTooltipShown;
      }
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      var _this3 = this;

      var fuzzyQueryOnly = nextProps.fuzzyQueryOnly,
          queryDataSet = nextProps.queryDataSet; // eslint-disable-next-line react/destructuring-assignment

      if (queryDataSet !== this.props.queryDataSet || fuzzyQueryOnly !== this.props.fuzzyQueryOnly) {
        (0, _mobx.runInAction)(function () {
          _this3.fieldSelectHidden = true;
          _this3.expand = true;
        });

        if (!fuzzyQueryOnly) {
          // 移除原有实例监听
          this.processDataSetListener(false);
          this.processDataSetListener(true, nextProps);

          if (this.isSingleLineOpt() && this.refSingleWrapper) {
            var _this$refSingleWrappe3 = this.refSingleWrapper.getBoundingClientRect(),
                height = _this$refSingleWrappe3.height;

            var _this$refSingleWrappe4 = this.refSingleWrapper.children[0].children[0].getBoundingClientRect(),
                childHeight = _this$refSingleWrappe4.height;

            (0, _mobx.runInAction)(function () {
              _this3.showExpandIcon = height > childHeight + 18;
            });
          }
        }

        if (this.originalValue === undefined && queryDataSet && queryDataSet.current) {
          this.initConditionFields({
            dataSet: queryDataSet,
            record: queryDataSet.current
          });
        }
      }
    }
  }, {
    key: "processDataSetListener",
    value: function processDataSetListener(flag, nextProps) {
      var _ref = nextProps || this.props,
          queryDataSet = _ref.queryDataSet;

      if (queryDataSet) {
        var handler = flag ? queryDataSet.addEventListener : queryDataSet.removeEventListener;
        handler.call(queryDataSet, _enum2.DataSetEvents.validate, this.handleDataSetValidate);
        handler.call(queryDataSet, _enum2.DataSetEvents.update, this.handleDataSetUpdate);
        handler.call(queryDataSet, _enum2.DataSetEvents.create, this.handleDataSetCreate);
        handler.call(queryDataSet, _enum2.DataSetEvents.reset, this.handleDataSetReset);
        handler.call(queryDataSet, _enum2.DataSetEvents.load, this.handleDataSetLoad);
      }
    }
    /**
     * queryDataSet 查询前校验事件 触发展开动态字段
     * @param dataSet 查询DS
     * @param result
     */

  }, {
    key: "handleDataSetValidate",
    value: function () {
      var _handleDataSetValidate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref2) {
        var _this4 = this;

        var dataSet, result, refSingleWrapper;
        return _regenerator["default"].wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                dataSet = _ref2.dataSet, result = _ref2.result;
                _context.next = 3;
                return result;

              case 3:
                if (_context.sent) {
                  _context.next = 7;
                  break;
                }

                (0, _mobx.runInAction)(function () {
                  var current = dataSet.current;
                  dataSet.fields.forEach(function (field, key) {
                    if (!field.isValid(current)) {
                      _this4.handleSelect(key);
                    }
                  });
                  _this4.expand = true;
                });
                refSingleWrapper = this.refSingleWrapper;

                if (refSingleWrapper) {
                  refSingleWrapper.style.height = '';
                  refSingleWrapper.style.overflow = '';
                }

              case 7:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function handleDataSetValidate(_x) {
        return _handleDataSetValidate.apply(this, arguments);
      }

      return handleDataSetValidate;
    }()
  }, {
    key: "setConditionStatus",
    value: function setConditionStatus(value, orglValue) {
      var queryDataSet = this.props.queryDataSet;
      queryDataSet.setState(CONDITIONSTATUS, value);

      if (value === _enum2.RecordStatus.sync && orglValue) {
        this.originalValue = orglValue;
      }
    }
    /**
     * 筛选条件更新 触发表格查询
     */

  }, {
    key: "handleDataSetUpdate",
    value: function () {
      var _handleDataSetUpdate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(_ref3) {
        var record, name, oldValue, value, _this$props3, dataSet, queryDataSet, _this$props3$onQuery, onQuery, autoQuery, field, shouldQuery, rangeValue, rangeOldValue, status, hasFocus, _iterator, _step, _step$value, key, _value;

        return _regenerator["default"].wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                record = _ref3.record, name = _ref3.name, oldValue = _ref3.oldValue, value = _ref3.value;
                _this$props3 = this.props, dataSet = _this$props3.dataSet, queryDataSet = _this$props3.queryDataSet, _this$props3$onQuery = _this$props3.onQuery, onQuery = _this$props3$onQuery === void 0 ? _noop["default"] : _this$props3$onQuery, autoQuery = _this$props3.autoQuery;
                field = queryDataSet && queryDataSet.getField(name);
                shouldQuery = true;

                if (field && field.get('range', record)) {
                  rangeValue = value ? (0, _isArray["default"])(value) ? value.join('') : Object.values(value).join('') : '';
                  rangeOldValue = oldValue ? (0, _isArray["default"])(oldValue) ? oldValue.join('') : Object.values(oldValue).join('') : '';
                  shouldQuery = rangeValue !== rangeOldValue;
                }

                status = _enum2.RecordStatus.update;

                if (record) {
                  status = isEqualDynamicProps(this.originalValue, (0, _omit["default"])(record.toData(), ['__dirty']), queryDataSet, record, name) ? _enum2.RecordStatus.sync : _enum2.RecordStatus.update;
                }

                this.setConditionStatus(status);

                if (!(autoQuery && shouldQuery)) {
                  _context2.next = 28;
                  break;
                }

                _context2.next = 11;
                return dataSet.modifiedCheck(undefined, dataSet, 'query');

              case 11:
                if (!_context2.sent) {
                  _context2.next = 27;
                  break;
                }

                _context2.t0 = queryDataSet && queryDataSet.current;

                if (!_context2.t0) {
                  _context2.next = 17;
                  break;
                }

                _context2.next = 16;
                return queryDataSet.current.validate();

              case 16:
                _context2.t0 = _context2.sent;

              case 17:
                if (!_context2.t0) {
                  _context2.next = 22;
                  break;
                }

                dataSet.query();
                onQuery();
                _context2.next = 25;
                break;

              case 22:
                hasFocus = false;
                _iterator = (0, _createForOfIteratorHelper2["default"])(this.refEditors.entries());

                try {
                  for (_iterator.s(); !(_step = _iterator.n()).done;) {
                    _step$value = (0, _slicedToArray2["default"])(_step.value, 2), key = _step$value[0], _value = _step$value[1];

                    if (_value && !_value.valid && !hasFocus) {
                      if ((0, _isFunction["default"])(this.refEditors.get(key).focus)) {
                        this.refEditors.get(key).focus();
                      }

                      hasFocus = true;
                    }
                  }
                } catch (err) {
                  _iterator.e(err);
                } finally {
                  _iterator.f();
                }

              case 25:
                _context2.next = 28;
                break;

              case 27:
                record.init(name, oldValue);

              case 28:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function handleDataSetUpdate(_x2) {
        return _handleDataSetUpdate.apply(this, arguments);
      }

      return handleDataSetUpdate;
    }()
    /**
     * queryDS 新建，初始勾选值
     */

  }, {
    key: "handleDataSetCreate",
    value: function handleDataSetCreate() {
      var queryDataSet = this.props.queryDataSet;

      if (queryDataSet) {
        this.initConditionFields({
          dataSet: queryDataSet,
          record: queryDataSet.current
        });
      }

      this.initMenuDataSet();
    }
    /**
    * queryDS reset，初始记录
    */

  }, {
    key: "handleDataSetReset",
    value: function handleDataSetReset() {
      var queryDataSet = this.props.queryDataSet;

      if (queryDataSet && !this.tableFilterAdapter) {
        queryDataSet.create();
      }
    }
    /**
     * queryDS load，兼容项目loadData([])的处理，初始化记录
     */

  }, {
    key: "handleDataSetLoad",
    value: function handleDataSetLoad(_ref4) {
      var dataSet = _ref4.dataSet;

      if (!this.tableFilterAdapter && !dataSet.length) {
        dataSet.create();
      }
    }
    /**
    * 初始化勾选值、条件字段
    * @param props
    */

  }, {
    key: "initConditionFields",
    value: function initConditionFields(props) {
      var _this5 = this;

      var dataSet = props.dataSet,
          record = props.record;
      var originalValue = (0, _omit["default"])(record.toData(), ['__dirty']);
      var conditionData = Object.entries(originalValue);
      this.originalValue = originalValue;
      this.originalConditionFields = [];
      var fields = dataSet.fields;
      (0, _map["default"])(conditionData, function (data) {
        var name = data[0];

        if (!fields.has(data[0]) && (0, _isObject["default"])(data[1]) && !(0, _isEmpty2["default"])(data[1]) && !(0, _isArray["default"])(data[1])) {
          name = "".concat(data[0], ".").concat(Object.keys(data[1])[0]);
        }

        if (isSelect(data) && !(dataSet.getState(SELECTFIELDS) || []).includes(name)) {
          var field = dataSet.getField(name);

          if (!field || !field.get('bind', record) || field.get('usedFlag')) {
            _this5.originalConditionFields.push(name);

            _this5.handleSelect(name);
          }
        }
      });
    }
  }, {
    key: "initMenuDataSet",
    value: function () {
      var _initMenuDataSet = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
        var _this6 = this;

        var _this$props4, queryDataSet, dynamicFilterBar, searchCode, getConfig, searchCodes, menuDataSet, conditionDataSet, optionDataSet, filterMenuDataSet, status, result, menuRecord, current;

        return _regenerator["default"].wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                _this$props4 = this.props, queryDataSet = _this$props4.queryDataSet, dynamicFilterBar = _this$props4.dynamicFilterBar, searchCode = _this$props4.searchCode;
                getConfig = this.context.tableStore.getConfig;
                searchCodes = dynamicFilterBar && dynamicFilterBar.searchCode || searchCode;
                menuDataSet = new _DataSet["default"]((0, _QuickFilterDataSet.QuickFilterDataSet)({
                  searchCode: searchCodes,
                  queryDataSet: queryDataSet,
                  tableFilterAdapter: this.tableFilterAdapter
                }), {
                  getConfig: getConfig
                });
                conditionDataSet = new _DataSet["default"]((0, _QuickFilterDataSet.ConditionDataSet)(), {
                  getConfig: getConfig
                });
                optionDataSet = new _DataSet["default"]({
                  paging: false,
                  selection: _enum2.DataSetSelection.single,
                  fields: [{
                    // 是否租户默认配置
                    name: 'isTenant',
                    type: _enum2.FieldType.string,
                    transformResponse: function transformResponse(value) {
                      return value ? (0, _localeContext.$l)('Table', 'preset') : (0, _localeContext.$l)('Table', 'user');
                    },
                    group: true
                  }]
                }, {
                  getConfig: getConfig
                });
                filterMenuDataSet = new _DataSet["default"]({
                  autoCreate: true,
                  fields: [{
                    name: 'filterName',
                    type: _enum2.FieldType.string,
                    textField: 'searchName',
                    valueField: 'searchId',
                    options: optionDataSet,
                    ignore: _enum2.FieldIgnore.always
                  }]
                }, {
                  getConfig: getConfig
                });
                status = _enum2.RecordStatus.update;

                if (queryDataSet && queryDataSet.current) {
                  status = isEqualDynamicProps(this.originalValue, (0, _omit["default"])(queryDataSet.current.toData(), ['__dirty']), queryDataSet, queryDataSet.current) ? _enum2.RecordStatus.sync : _enum2.RecordStatus.update;
                } else {
                  status = _enum2.RecordStatus.sync;
                }

                queryDataSet.setState(MENUDATASET, menuDataSet);
                queryDataSet.setState(CONDITIONDATASET, conditionDataSet);
                queryDataSet.setState(OPTIONDATASET, optionDataSet);
                queryDataSet.setState(FILTERMENUDATASET, filterMenuDataSet);
                queryDataSet.setState(CONDITIONSTATUS, status);
                _context3.next = 16;
                return menuDataSet.query();

              case 16:
                result = _context3.sent;
                queryDataSet.setState(MENURESULT, result);

                if (optionDataSet) {
                  optionDataSet.loadData(result);
                }

                menuRecord = menuDataSet.current;

                if (menuRecord) {
                  conditionDataSet.loadData(menuRecord.get('conditionList'));
                }

                if (result && result.length) {
                  (0, _mobx.runInAction)(function () {
                    _this6.shouldLocateData = true;
                  });

                  if (queryDataSet && queryDataSet.fields) {
                    this.tempFields = queryDataSet.snapshot().dataSet.fields;
                  }
                } else {
                  current = filterMenuDataSet.current;
                  if (current) current.set('filterName', undefined);
                  (0, _mobx.runInAction)(function () {
                    _this6.shouldLocateData = true;
                  });
                }

                return _context3.abrupt("return", true);

              case 23:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      function initMenuDataSet() {
        return _initMenuDataSet.apply(this, arguments);
      }

      return initMenuDataSet;
    }()
    /**
     * tableFilterSuffix 预留自定义区域
     */

  }, {
    key: "renderSuffix",
    value: function renderSuffix() {
      var _this$context = this.context,
          tableStore = _this$context.tableStore,
          proPrefixCls = _this$context.tableStore.proPrefixCls;
      var _this$props5 = this.props,
          dynamicFilterBar = _this$props5.dynamicFilterBar,
          queryDataSet = _this$props5.queryDataSet,
          dataSet = _this$props5.dataSet,
          _this$props5$buttons = _this$props5.buttons,
          buttons = _this$props5$buttons === void 0 ? [] : _this$props5$buttons;
      var suffixes = dynamicFilterBar && dynamicFilterBar.suffixes || tableStore.getConfig('tableFilterSuffix');
      var children = [];
      var suffixesDom = null;
      var tableButtons = buttons.length ? /*#__PURE__*/_react["default"].createElement(_TableButtons["default"], {
        key: "toolbar",
        prefixCls: "".concat(proPrefixCls, "-dynamic-filter"),
        buttons: buttons
      }) : null;

      if (suffixes && suffixes.length) {
        suffixes.forEach(function (suffix) {
          if (suffix === 'filter') {
            children.push( /*#__PURE__*/_react["default"].createElement(_ColumnFilter["default"], {
              prefixCls: proPrefixCls
            }));
          } else if ( /*#__PURE__*/(0, _react.isValidElement)(suffix)) {
            children.push(suffix);
          } else if ((0, _isFunction["default"])(suffix)) {
            children.push(suffix({
              queryDataSet: queryDataSet,
              dataSet: dataSet
            }));
          }
        });
        suffixesDom = /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "-dynamic-filter-bar-suffix")
        }, children);
      }

      return [tableButtons, suffixesDom];
    }
  }, {
    key: "getPrefix",
    value: function getPrefix() {
      var proPrefixCls = this.context.tableStore.proPrefixCls;
      var _this$props6 = this.props,
          dynamicFilterBar = _this$props6.dynamicFilterBar,
          queryDataSet = _this$props6.queryDataSet,
          dataSet = _this$props6.dataSet;
      var prefixes = dynamicFilterBar && dynamicFilterBar.prefixes;
      var children = [];

      if (prefixes && prefixes.length) {
        prefixes.forEach(function (prefix) {
          if ((0, _isString["default"])(prefix) && prefix === 'filter') {
            children.push( /*#__PURE__*/_react["default"].createElement(_ColumnFilter["default"], {
              prefixCls: proPrefixCls
            }));
          } else if ( /*#__PURE__*/(0, _react.isValidElement)(prefix)) {
            children.push(prefix);
          } else if ((0, _isFunction["default"])(prefix)) {
            children.push(prefix({
              queryDataSet: queryDataSet,
              dataSet: dataSet
            }));
          }
        });
        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "-dynamic-filter-bar-prefix")
        }, children), /*#__PURE__*/_react["default"].createElement("span", {
          className: "".concat(proPrefixCls, "-filter-search-divide")
        }));
      }

      return null;
    }
    /**
     * 注入 onEnterDown 事件
     * @param element
     * @param name
     */

  }, {
    key: "createFields",
    value: function createFields(element, name) {
      var _this7 = this;

      var onEnterDown = element.props.onEnterDown;
      var props = {
        onEnterDown: onEnterDown && (0, _isFunction["default"])(onEnterDown) ? onEnterDown : function () {
          _this7.handleQuery();
        },
        ref: function ref(node) {
          return _this7.refEditors.set(name, node);
        },
        _inTable: true,
        showValidation: 'tooltip'
      };
      var elementName = element && (0, _isFunction["default"])(element.type) && element.type.displayName;

      if ((0, _isUndefined["default"])(element.props.suffix) && ['Currency', 'NumberField', 'EmailField', 'UrlField', 'TextField'].includes(elementName)) {
        (0, _extends2["default"])(props, {
          suffix: /*#__PURE__*/_react["default"].createElement(_icon["default"], {
            type: "search"
          })
        });
      }

      return /*#__PURE__*/(0, _react.cloneElement)(element, props);
    }
    /**
     * 判断查询值是否为空
     * @param value
     */

  }, {
    key: "isEmpty",
    value: function isEmpty(value) {
      return (0, _mobx.isArrayLike)(value) ? !value.length : (0, _isEmpty3["default"])(value);
    }
  }, {
    key: "tableFilterAdapter",
    get: function get() {
      var _this$props7 = this.props,
          dynamicFilterBar = _this$props7.dynamicFilterBar,
          searchCode = _this$props7.searchCode;
      var tableStore = this.context.tableStore;
      var searchCodes = dynamicFilterBar && dynamicFilterBar.searchCode || searchCode;
      return searchCodes ? dynamicFilterBar && dynamicFilterBar.tableFilterAdapter || tableStore.getConfig('tableFilterAdapter') : null;
    }
    /**
     * 是否单行操作
     */

  }, {
    key: "isSingleLineOpt",
    value: function isSingleLineOpt() {
      var fuzzyQuery = this.props.fuzzyQuery;
      return !(fuzzyQuery || this.tableFilterAdapter);
    }
  }, {
    key: "renderRefreshBtn",
    value: function renderRefreshBtn() {
      var _this8 = this;

      var proPrefixCls = this.context.tableStore.proPrefixCls;
      return /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(proPrefixCls, "-filter-menu-query"),
        onClick: function onClick(e) {
          e.stopPropagation();
          var _this8$props = _this8.props,
              dataSet = _this8$props.dataSet,
              queryDataSet = _this8$props.queryDataSet,
              _this8$props$onRefres = _this8$props.onRefresh,
              onRefresh = _this8$props$onRefres === void 0 ? _noop["default"] : _this8$props$onRefres;
          var data = getQueryData(queryDataSet);
          onRefresh({
            dataSet: dataSet,
            queryDataSet: queryDataSet,
            data: data,
            params: _this8.searchText
          });
        }
      }, /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
        title: (0, _localeContext.$l)('Table', 'refresh')
      }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
        type: "refresh"
      })));
    }
    /**
     * 渲染展开逻辑
     * @param hidden 是否隐藏全部
     */

  }, {
    key: "getExpandNode",
    value: function getExpandNode(hidden) {
      var _this9 = this;

      var proPrefixCls = this.context.tableStore.proPrefixCls;
      var refreshBtn = this.props.refreshBtn;
      if (!this.showExpandIcon && !hidden) return refreshBtn ? this.renderRefreshBtn() : null;
      return /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(proPrefixCls, "-filter-menu-expand"),
        onClick: function onClick() {
          var refSingleWrapper = _this9.refSingleWrapper;

          if (refSingleWrapper) {
            var _refSingleWrapper$get = refSingleWrapper.getBoundingClientRect(),
                height = _refSingleWrapper$get.height;

            var _refSingleWrapper$chi = refSingleWrapper.children[0].children[0].getBoundingClientRect(),
                childHeight = _refSingleWrapper$chi.height;

            (0, _mobx.runInAction)(function () {
              _this9.expand = hidden ? height <= 0 : height <= childHeight + 18;
            });

            if (hidden && height) {
              // 收起全部
              refSingleWrapper.style.display = 'none';
            } else {
              refSingleWrapper.style.display = 'flex';
              refSingleWrapper.style.height = '';
              refSingleWrapper.style.overflow = '';
            }

            if (height > childHeight + 18 && !hidden) {
              // 收起留一行高度
              refSingleWrapper.style.height = (0, _UnitConvertor.pxToRem)(childHeight + 18, true) || '';
              refSingleWrapper.style.overflow = 'hidden';
            } else {
              refSingleWrapper.style.height = '';
              refSingleWrapper.style.overflow = '';
            }
          }
        }
      }, refreshBtn ? this.renderRefreshBtn() : null, this.expand ? /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
        title: (0, _localeContext.$l)('Table', 'collapse')
      }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
        type: "baseline-arrow_drop_up"
      })) : /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
        title: (0, _localeContext.$l)('Table', 'expand_button')
      }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
        type: "baseline-arrow_drop_down"
      })));
    }
    /**
     * 渲染模糊搜索
     */

  }, {
    key: "getFuzzyQuery",
    value: function getFuzzyQuery() {
      var _this10 = this;

      var fuzzyQuery = this.props.fuzzyQuery;
      if (!fuzzyQuery) return null;
      var _this$props8 = this.props,
          dataSet = _this$props8.dataSet,
          dynamicFilterBar = _this$props8.dynamicFilterBar,
          autoQueryAfterReset = _this$props8.autoQueryAfterReset,
          fuzzyQueryPlaceholder = _this$props8.fuzzyQueryPlaceholder,
          _this$props8$onReset = _this$props8.onReset,
          onReset = _this$props8$onReset === void 0 ? _noop["default"] : _this$props8$onReset;
      var _this$context2 = this.context,
          tableStore = _this$context2.tableStore,
          _this$context2$tableS = _this$context2.tableStore,
          proPrefixCls = _this$context2$tableS.proPrefixCls,
          node = _this$context2$tableS.node,
          highlightRowIndexs = _this$context2$tableS.highlightRowIndexs;
      var searchText = dynamicFilterBar && dynamicFilterBar.searchText || tableStore.getConfig('tableFilterSearchText') || 'params';
      var placeholder = fuzzyQueryPlaceholder || (0, _localeContext.$l)('Table', 'enter_search_content');
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(proPrefixCls, "-filter-search")
      }, /*#__PURE__*/_react["default"].createElement(_textField["default"], {
        style: {
          width: 280
        },
        clearButton: true,
        placeholder: placeholder,
        prefix: /*#__PURE__*/_react["default"].createElement(_icon["default"], {
          type: "search"
        }),
        value: this.searchText,
        valueChangeAction: _enum3.ValueChangeAction.input,
        onChange: (0, _debounce["default"])(function (value) {
          (0, _mobx.runInAction)(function () {
            _this10.searchText = value || '';

            if (dynamicFilterBar && dynamicFilterBar.quickSearch) {
              tableStore.highlightRowIndexs = [];
              tableStore.searchText = value || '';
              node.forceUpdate();
            }
          });
          dataSet.setQueryParameter(searchText, value);

          _this10.handleQuery();
        }, 500),
        onKeyDown: function onKeyDown(e) {
          if (e.keyCode === _KeyCode["default"].ENTER && dynamicFilterBar && dynamicFilterBar.quickSearch) {
            e.preventDefault();
            var rows = (0, _toConsumableArray2["default"])(new Set(highlightRowIndexs));
            node.scrollTop(rows[_this10.enterNum] * node.getRowHeight());
            _this10.enterNum += 1;

            if (_this10.enterNum + 1 > rows.length) {
              _this10.enterNum = 0;
            }
          }
        },
        onClear: function onClear() {
          (0, _mobx.runInAction)(function () {
            _this10.searchText = '';

            if (dynamicFilterBar && dynamicFilterBar.quickSearch) {
              tableStore.searchText = '';
              tableStore.highlightRowIndexs = [];
              node.forceUpdate();
            }
          });
          onReset();

          if (autoQueryAfterReset) {
            dataSet.setQueryParameter(searchText, undefined);

            _this10.handleQuery(true);
          }
        }
      }));
    }
    /**
     * 渲染重置按钮
     */

  }, {
    key: "getResetButton",
    value: function getResetButton() {
      var _this11 = this;

      var proPrefixCls = this.context.tableStore.proPrefixCls;
      var _this$props9 = this.props,
          queryDataSet = _this$props9.queryDataSet,
          autoQueryAfterReset = _this$props9.autoQueryAfterReset,
          _this$props9$onReset = _this$props9.onReset,
          onReset = _this$props9$onReset === void 0 ? _noop["default"] : _this$props9$onReset;
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(proPrefixCls, "-filter-buttons")
      }, queryDataSet.getState(CONDITIONSTATUS) === _enum2.RecordStatus.update && /*#__PURE__*/_react["default"].createElement(_button["default"], {
        onClick: function onClick() {
          if (queryDataSet) {
            var current = queryDataSet.current;

            if (current) {
              current.reset();

              _this11.handleDataSetCreate();

              queryDataSet.setState(SELECTFIELDS, (0, _toConsumableArray2["default"])(_this11.originalConditionFields));
            }
          }

          _this11.setConditionStatus(_enum2.RecordStatus.sync);

          onReset();

          if (autoQueryAfterReset) {
            _this11.handleQuery();
          }
        }
      }, (0, _localeContext.$l)('Table', 'reset_button')));
    }
    /**
     * 筛选头
     * fuzzyQuery + quickFilterMenu + resetButton + buttons
     */

  }, {
    key: "getFilterMenu",
    value: function getFilterMenu() {
      var proPrefixCls = this.context.tableStore.proPrefixCls;
      var _this$props10 = this.props,
          queryFields = _this$props10.queryFields,
          queryDataSet = _this$props10.queryDataSet,
          dataSet = _this$props10.dataSet,
          dynamicFilterBar = _this$props10.dynamicFilterBar,
          searchCode = _this$props10.searchCode,
          autoQuery = _this$props10.autoQuery,
          fuzzyQueryOnly = _this$props10.fuzzyQueryOnly;
      var prefix = this.getPrefix();
      var suffix = this.renderSuffix();
      var fuzzyQuery = this.getFuzzyQuery();

      if (fuzzyQueryOnly) {
        return /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "-filter-menu")
        }, prefix, fuzzyQuery, suffix);
      }

      if (queryDataSet && queryFields.length) {
        var searchCodes = dynamicFilterBar && dynamicFilterBar.searchCode || searchCode;
        var quickFilterMenu = this.tableFilterAdapter && searchCodes ? /*#__PURE__*/_react["default"].createElement(_QuickFilterMenuContext["default"].Provider, {
          value: {
            tempQueryFields: this.tempFields,
            autoQuery: autoQuery,
            prefixCls: proPrefixCls,
            expand: this.expand,
            dataSet: dataSet,
            queryDataSet: queryDataSet,
            onChange: this.handleSelect,
            conditionStatus: queryDataSet.getState(CONDITIONSTATUS),
            onStatusChange: this.setConditionStatus,
            selectFields: queryDataSet.getState(SELECTFIELDS),
            onOriginalChange: this.setOriginalConditionFields,
            menuDataSet: queryDataSet.getState(MENUDATASET),
            filterMenuDataSet: queryDataSet.getState(FILTERMENUDATASET),
            conditionDataSet: queryDataSet.getState(CONDITIONDATASET),
            optionDataSet: queryDataSet.getState(OPTIONDATASET),
            shouldLocateData: this.shouldLocateData,
            initConditionFields: this.initConditionFields,
            newFilterDataSet: {}
          }
        }, /*#__PURE__*/_react["default"].createElement(_QuickFilterMenu["default"], null)) : null;
        var resetButton = this.isSingleLineOpt() || this.tableFilterAdapter ? null : this.getResetButton();
        return /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "-filter-menu")
        }, prefix, fuzzyQuery, quickFilterMenu, resetButton, this.isSingleLineOpt() ? null : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
          className: "".concat(proPrefixCls, "-filter-search-divide")
        }), this.getExpandNode(true)), suffix);
      }
    }
    /**
    * 查询字段初始顺序
    * 排除动态属性影响
    */

  }, {
    key: "originOrderQueryFields",
    get: function get() {
      var queryDataSet = this.props.queryDataSet;
      var result = [];

      if (queryDataSet) {
        var fields = queryDataSet.fields,
            _queryDataSet$props$f = queryDataSet.props.fields,
            propFields = _queryDataSet$props$f === void 0 ? [] : _queryDataSet$props$f;
        var cloneFields = fields.toJS();
        propFields.forEach(function (_ref5) {
          var name = _ref5.name;

          if (name) {
            var field = cloneFields.get(name);

            var hasBindProps = function hasBindProps(propsName) {
              return field && field.get(propsName) && field.get(propsName).bind;
            };

            if (field && !field.get('bind') && !hasBindProps('computedProps') && !hasBindProps('dynamicProps') && !field.get('name').includes('__tls')) {
              result.push(field);
            }
          }
        });
      }

      return result;
    }
  }, {
    key: "handleHelpMouseEnter",
    value: function handleHelpMouseEnter(e, help) {
      var target = e.target;
      (0, _singleton.show)(target, {
        title: help
      });
      this.isTooltipShown = true;
    }
  }, {
    key: "handleHelpMouseLeave",
    value: function handleHelpMouseLeave() {
      (0, _singleton.hide)();
    }
  }, {
    key: "renderTooltipHelp",
    value: function renderTooltipHelp(help) {
      var _this12 = this;

      if (help) {
        return /*#__PURE__*/_react["default"].createElement(_icon["default"], {
          type: "help",
          // @ts-ignore
          onMouseEnter: function onMouseEnter(e) {
            return _this12.handleHelpMouseEnter(e, help);
          },
          onMouseLeave: this.handleHelpMouseLeave
        });
      }
    }
    /**
     * 渲染查询条
     */

  }, {
    key: "getQueryBar",
    value: function getQueryBar() {
      var _this13 = this;

      var _this$context3 = this.context,
          tableStore = _this$context3.tableStore,
          proPrefixCls = _this$context3.tableStore.proPrefixCls;
      var _this$props11 = this.props,
          _this$props11$queryFi = _this$props11.queryFieldsLimit,
          queryFieldsLimit = _this$props11$queryFi === void 0 ? 3 : _this$props11$queryFi,
          queryFields = _this$props11.queryFields,
          queryDataSet = _this$props11.queryDataSet,
          fuzzyQueryOnly = _this$props11.fuzzyQueryOnly;
      var menuDataSet = queryDataSet.getState(MENUDATASET);
      var isTenant = menuDataSet && menuDataSet.current && menuDataSet.current.get('isTenant');
      var fieldsLimit = queryFieldsLimit;

      if (isTenant) {
        fieldsLimit = 0;
      }

      var selectFields = queryDataSet.getState(SELECTFIELDS) || [];

      if (fuzzyQueryOnly) {
        return /*#__PURE__*/_react["default"].createElement("div", {
          key: "query_bar",
          className: "".concat(proPrefixCls, "-dynamic-filter-bar")
        }, this.getFilterMenu());
      }

      if (queryDataSet && queryFields.length) {
        var singleLineModeAction = this.isSingleLineOpt() ? /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "-dynamic-filter-bar-single-action")
        }, this.getResetButton(), this.getExpandNode(false)) : null;
        return /*#__PURE__*/_react["default"].createElement("div", {
          key: "query_bar",
          className: "".concat(proPrefixCls, "-dynamic-filter-bar")
        }, this.getFilterMenu(), /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "--dynamic-filter-single-wrapper"),
          ref: function ref(node) {
            return _this13.refSingleWrapper = node;
          }
        }, /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "-filter-wrapper")
        }, this.queryFields.slice(0, fieldsLimit).map(function (element) {
          var _classNames;

          var _element$props = element.props,
              name = _element$props.name,
              hidden = _element$props.hidden,
              showHelp = _element$props.showHelp,
              disabled = _element$props.disabled,
              help = _element$props.help;

          var isLabelShowHelp = (showHelp || tableStore.getConfig('showHelp')) === _enum4.ShowHelp.label;

          if (hidden) return null;
          var queryField = queryDataSet.getField(name);
          var label = queryField && queryField.get('label', queryDataSet.current);
          var isRequired = queryField && queryField.get('required');
          var validationMessage = queryField && queryField.getValidationMessage(queryDataSet.current);
          var hasValue = !_this13.isEmpty(queryDataSet.current && queryDataSet.current.get(name));
          var isDisabled = disabled || queryField && queryField.get('disabled', queryDataSet.current);
          var itemContentClassName = (0, _classnames["default"])("".concat(proPrefixCls, "-filter-content"), (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(proPrefixCls, "-filter-content-disabled"), isDisabled), (0, _defineProperty2["default"])(_classNames, "".concat(proPrefixCls, "-filter-content-required"), isRequired), (0, _defineProperty2["default"])(_classNames, "".concat(proPrefixCls, "-filter-content-has-value"), hasValue), (0, _defineProperty2["default"])(_classNames, "".concat(proPrefixCls, "-filter-content-invalid"), validationMessage), _classNames));
          return /*#__PURE__*/_react["default"].createElement("div", {
            className: itemContentClassName,
            key: name,
            onMouseDown: function onMouseDown() {
              if (!isDisabled) {
                var editor = _this13.refEditors.get(name);

                if (editor && (0, _isFunction["default"])(editor.focus)) {
                  (0, _defer["default"])(function () {
                    _this13.refEditors.get(name).focus();
                  }, 50);
                }
              }
            },
            onClick: function onClick() {
              if (!isDisabled) {
                var filterItem = _this13.refFilterItems.get(name);

                if (filterItem) {
                  if (!filterItem.className.includes("c7n-pro-lov-click")) {
                    filterItem.className += ' c7n-pro-lov-click';
                  }
                }
              }
            },
            onBlur: function onBlur() {
              var filterItem = _this13.refFilterItems.get(name);

              if (filterItem && filterItem.className.includes("c7n-pro-lov-click")) {
                filterItem.className = filterItem.className.split(" c7n-pro-lov-click")[0];
              }
            },
            onMouseEnter: function onMouseEnter(e) {
              if (validationMessage) {
                var currentTarget = e.currentTarget;
                (0, _singleton.show)(currentTarget, {
                  title: (0, _utils2.renderValidationMessage)(validationMessage, true),
                  theme: 'light',
                  placement: 'top'
                });
                _this13.isTooltipShown = true;
              }
            },
            onMouseLeave: function onMouseLeave() {
              (0, _singleton.hide)();
            }
          }, /*#__PURE__*/_react["default"].createElement("span", {
            className: "".concat(proPrefixCls, "-filter-label")
          }, label, isLabelShowHelp ? _this13.renderTooltipHelp(help || queryField && queryField.get('help', queryDataSet.current)) : null), /*#__PURE__*/_react["default"].createElement("span", {
            className: (0, _classnames["default"])("".concat(proPrefixCls, "-filter-item"), (0, _defineProperty2["default"])({}, "".concat(proPrefixCls, "-filter-item-has-value"), hasValue)),
            ref: function ref(node) {
              return _this13.refFilterItems.set(name, node);
            }
          }, _this13.createFields(element, name)));
        }), this.queryFields.slice(fieldsLimit).map(function (element) {
          var _classNames3;

          var _element$props2 = element.props,
              name = _element$props2.name,
              hidden = _element$props2.hidden,
              showHelp = _element$props2.showHelp,
              disabled = _element$props2.disabled,
              help = _element$props2.help;

          var isLabelShowHelp = (showHelp || tableStore.getConfig('showHelp')) === _enum4.ShowHelp.label;

          if (hidden) return null;
          var queryField = queryDataSet.getField(name);
          var label = queryField && queryField.get('label', queryDataSet.current);
          var isRequired = queryField && queryField.get('required');
          var validationMessage = queryField && queryField.getValidationMessage(queryDataSet.current);
          var hasValue = !_this13.isEmpty(queryDataSet.current && queryDataSet.current.get(name));
          var isDisabled = disabled || queryField && queryField.get('disabled', queryDataSet.current);
          var itemContentClassName = (0, _classnames["default"])("".concat(proPrefixCls, "-filter-content"), (_classNames3 = {}, (0, _defineProperty2["default"])(_classNames3, "".concat(proPrefixCls, "-filter-content-disabled"), isDisabled), (0, _defineProperty2["default"])(_classNames3, "".concat(proPrefixCls, "-filter-content-required"), isRequired), (0, _defineProperty2["default"])(_classNames3, "".concat(proPrefixCls, "-filter-content-has-value"), hasValue), (0, _defineProperty2["default"])(_classNames3, "".concat(proPrefixCls, "-filter-content-invalid"), validationMessage), _classNames3));

          if (selectFields.includes(name)) {
            return /*#__PURE__*/_react["default"].createElement("div", {
              className: itemContentClassName,
              key: name,
              onMouseDown: function onMouseDown() {
                if (!isDisabled) {
                  var editor = _this13.refEditors.get(name);

                  if (editor && (0, _isFunction["default"])(editor.focus)) {
                    (0, _defer["default"])(function () {
                      _this13.refEditors.get(name).focus();
                    }, 50);
                  }
                }
              },
              onClick: function onClick() {
                if (!isDisabled) {
                  var filterItem = _this13.refFilterItems.get(name);

                  if (filterItem) {
                    if (!filterItem.className.includes("c7n-pro-lov-click")) {
                      filterItem.className += ' c7n-pro-lov-click';
                    }
                  }
                }
              },
              onBlur: function onBlur() {
                var filterItem = _this13.refFilterItems.get(name);

                if (filterItem && filterItem.className.includes("c7n-pro-lov-click")) {
                  filterItem.className = filterItem.className.split(" c7n-pro-lov-click")[0];
                }
              },
              onMouseEnter: function onMouseEnter(e) {
                if (validationMessage) {
                  var currentTarget = e.currentTarget;
                  (0, _singleton.show)(currentTarget, {
                    title: (0, _utils2.renderValidationMessage)(validationMessage, true),
                    theme: 'light',
                    placement: 'top'
                  });
                  _this13.isTooltipShown = true;
                }
              },
              onMouseLeave: function onMouseLeave() {
                (0, _singleton.hide)();
              }
            }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
              type: "cancel",
              className: "".concat(proPrefixCls, "-filter-item-close"),
              onMouseDown: function onMouseDown(e) {
                e.stopPropagation();
              },
              onClick: function onClick() {
                _this13.handleUnSelect([name]);
              }
            }), /*#__PURE__*/_react["default"].createElement("span", {
              className: "".concat(proPrefixCls, "-filter-label")
            }, label, isLabelShowHelp ? _this13.renderTooltipHelp(help || queryField && queryField.get('help', queryDataSet.current)) : null), /*#__PURE__*/_react["default"].createElement("span", {
              className: (0, _classnames["default"])("".concat(proPrefixCls, "-filter-item"), (0, _defineProperty2["default"])({}, "".concat(proPrefixCls, "-filter-item-has-value"), hasValue)),
              ref: function ref(node) {
                return _this13.refFilterItems.set(name, node);
              }
            }, _this13.createFields(element, name)));
          }

          return null;
        }), fieldsLimit < this.queryFields.length && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(proPrefixCls, "-filter-item")
        }, /*#__PURE__*/_react["default"].createElement(_dropdown["default"], {
          visible: !this.fieldSelectHidden,
          overlay: /*#__PURE__*/_react["default"].createElement("div", {
            role: "none",
            ref: function ref(node) {
              return _this13.refDropdown = node;
            },
            onClick: function onClick(e) {
              e.stopPropagation();
            }
          }, /*#__PURE__*/_react["default"].createElement(_FieldList["default"], {
            groups: [{
              title: (0, _localeContext.$l)('Table', 'predefined_fields'),
              fields: isTenant ? (0, _toConsumableArray2["default"])(queryDataSet.fields.values()) : this.originOrderQueryFields.slice(fieldsLimit)
            }],
            prefixCls: "".concat(proPrefixCls, "-filter-list") || 'c7n-pro-table-filter-list',
            closeMenu: function closeMenu() {
              return (0, _mobx.runInAction)(function () {
                return _this13.fieldSelectHidden = true;
              });
            },
            value: selectFields,
            onSelect: this.handleSelect,
            onUnSelect: this.handleUnSelect
          })),
          trigger: [_enum.Action.click]
        }, /*#__PURE__*/_react["default"].createElement("span", {
          className: "".concat(proPrefixCls, "-add-fields"),
          onClick: function onClick(e) {
            e.nativeEvent.stopImmediatePropagation();
            (0, _mobx.runInAction)(function () {
              _this13.fieldSelectHidden = false;
            });
          }
        }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
          type: "add"
        }), (0, _localeContext.$l)('Table', 'add_filter'))))), singleLineModeAction));
      }

      return null;
    }
  }, {
    key: "handleQuery",
    value: function handleQuery(collapse) {
      var _this$props12 = this.props,
          dataSet = _this$props12.dataSet,
          queryDataSet = _this$props12.queryDataSet,
          _this$props12$onQuery = _this$props12.onQuery,
          onQuery = _this$props12$onQuery === void 0 ? _noop["default"] : _this$props12$onQuery,
          autoQuery = _this$props12.autoQuery;

      if (autoQuery) {
        dataSet.query();
      }

      if (!collapse) {
        var data = getQueryData(queryDataSet);
        onQuery({
          dataSet: dataSet,
          queryDataSet: queryDataSet,
          data: data,
          params: this.searchText
        });
      }
    }
  }, {
    key: "render",
    value: function render() {
      return this.getQueryBar();
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _TableContext["default"];
    }
  }]);
  return TableDynamicFilterBar;
}(_react.Component);

TableDynamicFilterBar.defaultProps = {
  queryFieldsLimit: 3,
  autoQueryAfterReset: true,
  fuzzyQuery: true,
  fuzzyQueryOnly: false,
  autoQuery: true,
  refreshBtn: true,
  buttons: []
};
(0, _tslib.__decorate)([_mobx.observable], TableDynamicFilterBar.prototype, "moreFields", void 0);
(0, _tslib.__decorate)([_mobx.observable], TableDynamicFilterBar.prototype, "fieldSelectHidden", void 0);
(0, _tslib.__decorate)([_mobx.observable], TableDynamicFilterBar.prototype, "expand", void 0);
(0, _tslib.__decorate)([_mobx.observable], TableDynamicFilterBar.prototype, "searchText", void 0);
(0, _tslib.__decorate)([_mobx.observable], TableDynamicFilterBar.prototype, "shouldLocateData", void 0);
(0, _tslib.__decorate)([_mobx.observable], TableDynamicFilterBar.prototype, "showExpandIcon", void 0);
(0, _tslib.__decorate)([_mobx.action], TableDynamicFilterBar.prototype, "handleClickOut", void 0);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleDataSetValidate", null);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "setConditionStatus", null);
(0, _tslib.__decorate)([_mobx.action], TableDynamicFilterBar.prototype, "setOriginalConditionFields", void 0);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleDataSetUpdate", null);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleDataSetCreate", null);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleDataSetReset", null);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleDataSetLoad", null);
(0, _tslib.__decorate)([_autobind["default"], _mobx.action], TableDynamicFilterBar.prototype, "initConditionFields", null);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "initMenuDataSet", null);
(0, _tslib.__decorate)([_mobx.action], TableDynamicFilterBar.prototype, "handleSelect", void 0);
(0, _tslib.__decorate)([_mobx.action], TableDynamicFilterBar.prototype, "handleUnSelect", void 0);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleHelpMouseEnter", null);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleHelpMouseLeave", null);
(0, _tslib.__decorate)([_autobind["default"]], TableDynamicFilterBar.prototype, "handleQuery", null);
TableDynamicFilterBar = (0, _tslib.__decorate)([_mobxReact.observer], TableDynamicFilterBar);
var _default = TableDynamicFilterBar;
exports["default"] = _default;
//# sourceMappingURL=TableDynamicFilterBar.js.map
