"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _input = _interopRequireDefault(require("antd/lib/input"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _SearchOutlined = _interopRequireDefault(require("@ant-design/icons/SearchOutlined"));
var _reactHighlightWords = _interopRequireDefault(require("react-highlight-words"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function columnSearch(_ref) {
  var t = _ref.t,
    dataIndex = _ref.dataIndex,
    title = _ref.title,
    width = _ref.width;
  // 查询
  var handleSearch = function handleSearch(selectedKeys, confirm, dataIndex) {
    confirm();
    t.setState({
      searchText: selectedKeys[0],
      searchedColumn: dataIndex
    });
  };

  // 重置
  var handleReset = function handleReset(clearFilters) {
    clearFilters();
    t.setState({
      searchText: ''
    });
  };
  return {
    filterDropdown: function filterDropdown(_ref2) {
      var setSelectedKeys = _ref2.setSelectedKeys,
        selectedKeys = _ref2.selectedKeys,
        confirm = _ref2.confirm,
        clearFilters = _ref2.clearFilters;
      return /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          padding: 8
        }
      }, /*#__PURE__*/_react["default"].createElement(_input["default"], {
        ref: function ref(node) {
          t.searchInput = node;
        },
        placeholder: "\u67E5\u8BE2 ".concat(title),
        value: selectedKeys[0],
        onChange: function onChange(e) {
          return setSelectedKeys(e.target.value ? [e.target.value] : []);
        },
        onPressEnter: function onPressEnter() {
          return handleSearch(selectedKeys, confirm, dataIndex);
        },
        style: {
          width: 188,
          marginBottom: 8,
          display: 'block'
        }
      }), /*#__PURE__*/_react["default"].createElement(_button["default"], {
        type: "primary",
        onClick: function onClick() {
          return handleSearch(selectedKeys, confirm, dataIndex);
        },
        size: "small",
        style: {
          width: 90,
          marginRight: 8
        }
      }, "\u67E5\u8BE2"), /*#__PURE__*/_react["default"].createElement(_button["default"], {
        onClick: function onClick() {
          return handleReset(clearFilters);
        },
        size: "small",
        style: {
          width: 90
        }
      }, "\u91CD\u7F6E"));
    },
    filterIcon: function filterIcon(filtered) {
      return /*#__PURE__*/_react["default"].createElement(_SearchOutlined["default"], {
        style: {
          color: filtered ? '#1890ff' : undefined
        }
      });
    },
    onFilter: function onFilter(value, record) {
      return record[dataIndex].toString().toLowerCase().includes(value.toLowerCase());
    },
    onFilterDropdownVisibleChange: function onFilterDropdownVisibleChange(visible) {
      if (visible) {
        setTimeout(function () {
          return t.searchInput.select();
        });
      }
    },
    render: function render(text, record) {
      return t.state.searchedColumn === dataIndex ? /*#__PURE__*/_react["default"].createElement(_reactHighlightWords["default"], {
        highlightStyle: {
          backgroundColor: '#ffc069',
          padding: 0
        },
        searchWords: [t.state.searchText],
        autoEscape: true,
        textToHighlight: record[dataIndex] && record[dataIndex].toString()
      }) : width ? /*#__PURE__*/_react["default"].createElement("div", {
        className: "ant-table-row-cell-ellipsis",
        style: {
          width: width - 10
        },
        title: record[dataIndex]
      }, record[dataIndex]) : record[dataIndex];
    }
  };
}
var _default = exports["default"] = columnSearch;
//# sourceMappingURL=columnSearch.js.map
