import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Grid from "@alifd/next/es/grid";
import _Form from "@alifd/next/es/form";
import React from 'react';
import "./index.scss";
import { bizCssPrefix } from "../../variables";
import events from "../../utils/events";
import { componentTypeList } from "../../type/type-data";
var FormItem = _Form.Item;
var Row = _Grid.Row,
  Col = _Grid.Col;
//这是过滤器
var CommonFilter = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(CommonFilter, _React$Component);
  function CommonFilter(_props) {
    var _this;
    _this = _React$Component.call(this, _props) || this;
    _this.submit = function (v, e) {
      if (e) return;
      var _this$props = _this.props,
        fieldList = _this$props.fieldList,
        children = _this$props.children;
      var commonVOs = [];
      var _loop = function _loop(i) {
        if (v[i] !== undefined) {
          var field = fieldList.filter(function (item) {
            return item.fieldName === i;
          })[0];
          var child = children.filter(function (item) {
            return item.key === field.id;
          })[0];
          var props = child.props;
          var comparison = props.comparison;
          if (!comparison) {
            comparison = props.bizType == 'text' ? 'like' : '=';
          }
          commonVOs.push({
            key: i,
            oper: comparison,
            value1: v[i]
          });
        }
      };
      for (var i in v) {
        _loop(i);
      }
      events.emit('onFilter', commonVOs);
    };
    _this.reset = function () {
      events.emit('onFilter', []);
    };
    _this.renderChildren_ = function () {
      var _this$props2 = _this.props,
        children = _this$props2.children,
        span = _this$props2.span,
        __designMode = _this$props2.__designMode;
      return React.Children.map(children, function (child) {
        var props = child.props;
        var componentType = props.componentType,
          comparison = props.comparison,
          bizType = props.bizType,
          isHide = props.isHide;
        var newComponentType = componentType;
        var newComparison = comparison;
        if (!componentType) {
          var list = componentTypeList.filter(function (item) {
            return item.tplType.includes(bizType);
          });
          newComponentType = list.length ? list[0].value : 'Input';
        }
        if (!comparison) {
          newComparison = bizType == 'text' ? 'like' : '=';
        }
        if (isHide && __designMode !== 'design') {
          return null;
        }
        return /*#__PURE__*/React.createElement(Col, {
          span: span
        }, /*#__PURE__*/React.cloneElement(child, {
          componentType: newComponentType,
          comparison: newComparison
        }));
      });
    };
    return _this;
  }
  var _proto = CommonFilter.prototype;
  _proto.render = function render() {
    var _this2 = this;
    var style = this.props.style;
    return /*#__PURE__*/React.createElement(_Form, {
      className: bizCssPrefix + '-common-filter',
      style: style
    }, /*#__PURE__*/React.createElement(Row, {
      align: "stretch",
      wrap: true
    }, this.renderChildren_()), /*#__PURE__*/React.createElement(Row, {
      align: "center"
    }, /*#__PURE__*/React.createElement(Col, {
      style: {
        textAlign: 'right'
      }
    }, /*#__PURE__*/React.createElement(FormItem, {
      wrapperCol: {
        offset: 12
      }
    }, /*#__PURE__*/React.createElement(_Form.Reset, {
      onClick: function onClick() {
        _this2.reset();
      },
      style: {
        marginRight: 10
      }
    }, "\u6E05\u7A7A"), /*#__PURE__*/React.createElement(_Form.Submit, {
      validate: true,
      type: "primary",
      onClick: function onClick(v, e) {
        return _this2.submit(v, e);
      },
      style: {
        marginRight: 10
      }
    }, "\u641C\u7D22")))));
  };
  return CommonFilter;
}(React.Component);
CommonFilter.displayName = 'CommonFilter';
export default CommonFilter;