"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _amosAntd = require("amos-antd"), _moment = _interopRequireDefault(require("moment"));

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var a = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var n = i ? Object.getOwnPropertyDescriptor(e, l) : null;
    n && (n.get || n.set) ? Object.defineProperty(a, l, n) : a[l] = e[l];
  }
  return a.default = e, r && r.set(e, a), a;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, a = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, i);
    } else r = a.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

var Option = _amosAntd.Select.Option, RadioButton = _amosAntd.Radio.Button, RadioGroup = _amosAntd.Radio.Group, PropsFilter = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    return (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "dateChange", (function(e) {
      a.props.changeFilters(a.props.dataIndex, e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "selectTypeFilter", (function() {
      switch (a.props.st) {
       case "text":
        return a.textContent();

       case "list":
        return a.listContent();

       case "date":
        return a.dateContent();

       case "redio":
        return a.redioContent();
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "textContent", (function() {
      return _react.default.createElement(_amosAntd.Input, {
        id: "filterValue",
        value: a.state.textValue,
        className: "amos-filter-text",
        onChange: a.textChange,
        name: "filterValue"
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "dateContent", (function() {
      return _react.default.createElement(_amosAntd.DatePicker, {
        className: "amos-filter-date",
        format: "YYYY-MM-DD HH:mm:ss",
        showTime: {
          defaultValue: (0, _moment.default)("00:00:00", "HH:mm:ss")
        },
        onChange: a.dateChange,
        name: "filterValue",
        id: "filterValue"
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "listContent", (function() {
      var e = a.props.list, t = a.state.listValue;
      return _react.default.createElement(_amosAntd.Select, {
        allowClear: !0,
        showSearch: !0,
        optionFilterProp: "children",
        onChange: a.selectChange,
        value: t,
        className: "amos-filter-list",
        dropdownStyle: {
          maxHeight: "110px",
          overflow: "overlay"
        }
      }, _react.default.createElement(Option, {
        key: "all",
        value: "全部"
      }, "全部"), e.map((function(e) {
        return _react.default.createElement(Option, {
          key: e.value,
          value: e.value
        }, e.name);
      })));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "redioContent", (function() {
      var e = a.props.list;
      return _react.default.createElement(RadioGroup, {
        onChange: a.radioChange,
        defaultValue: "全部",
        className: "amos-filter-redio"
      }, _react.default.createElement(RadioButton, {
        value: "全部"
      }, "全部"), e.map((function(e) {
        return _react.default.createElement(RadioButton, {
          key: e,
          value: e
        }, e);
      })));
    })), a.state = {
      count: 1,
      filterValue: "",
      textValue: "",
      listValue: "全部"
    }, a.textChange = a.textChange.bind((0, _assertThisInitialized2.default)(a)), a.radioChange = a.radioChange.bind((0, 
    _assertThisInitialized2.default)(a)), a.selectChange = a.selectChange.bind((0, _assertThisInitialized2.default)(a)), 
    a;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = e.st;
      if ("text" === t) {
        var r = e.defaultValue;
        1 === this.state.count && r && "" !== r && this.setState({
          textValue: r,
          count: 0
        });
      }
      if ("list" === t) {
        var a = e.defaultValue;
        1 === this.state.count && a && "" !== a && this.setState({
          listValue: a,
          count: 0
        });
      }
    }
  }, {
    key: "textChange",
    value: function(e) {
      this.setState({
        textValue: e.target.value
      }), this.props.changeFilters(this.props.dataIndex, e.target.value);
    }
  }, {
    key: "radioChange",
    value: function(e) {
      this.props.changeFilters(this.props.dataIndex, e.target.value);
    }
  }, {
    key: "selectChange",
    value: function(e) {
      this.setState({
        listValue: e
      }), this.props.changeFilters(this.props.dataIndex, e);
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props.title;
      return _react.default.createElement("li", {
        className: "amos-table-filter-li"
      }, _react.default.createElement("span", {
        className: "amos-prop-filter"
      }, e), _react.default.createElement("span", {
        className: "amos-filter-value"
      }, this.selectTypeFilter()));
    }
  } ]), r;
}(_react.Component);

PropsFilter.displayName = "PropsFilter", PropsFilter.propTypes = {
  title: _propTypes.default.string,
  st: _propTypes.default.string,
  list: _propTypes.default.array,
  changeFilters: _propTypes.default.func,
  dataIndex: _propTypes.default.string
}, PropsFilter.defaultProps = {
  list: [],
  allFilter: []
};

var _default = PropsFilter;

exports.default = _default;