function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
import { Button, Input } from 'antd';
import React, { useState } from 'react';
import { classPrefix } from './row2Column';
var ColumnFilterPanel = function ColumnFilterPanel(_ref) {
  var filterProps = _ref.filterProps,
    columnList = _ref.columnList;
  var confirm = filterProps.confirm,
    clearFilters = filterProps.clearFilters,
    setSelectedKeys = filterProps.setSelectedKeys;
  var _useState = useState(''),
    _useState2 = _slicedToArray(_useState, 2),
    search = _useState2[0],
    setSearch = _useState2[1];
  function onSearch() {
    if (!search) {
      if (clearFilters) clearFilters();
      confirm();
      return;
    }
    setSelectedKeys(columnList.filter(function (item) {
      return new RegExp(search).test(item.name);
    }).map(function (item) {
      return item.name;
    }));
    confirm();
  }
  function onReset() {
    setSearch('');
    if (clearFilters) clearFilters();
    confirm();
  }
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-filter-panel")
  }, /*#__PURE__*/React.createElement(Input, {
    placeholder: "\u8F93\u5165\u5B57\u6BB5\u540D\u79F0\u8FDB\u884C\u641C\u7D22",
    autoFocus: true,
    value: search,
    onChange: function onChange(e) {
      e.persist();
      setSearch(e.target.value);
    },
    onPressEnter: onSearch
  }), /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    size: "small",
    onClick: onSearch
  }, "\u641C\u7D22"), /*#__PURE__*/React.createElement(Button, {
    size: "small",
    onClick: onReset
  }, "\u91CD\u7F6E"));
};
export default ColumnFilterPanel;