import "antd/es/form/style";
import _Form from "antd/es/form";

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

import * as React from 'react';
import { isEmpty } from 'lodash-es';
import classNames from 'classnames';
import { useBoolean } from 'ahooks';

function FilterItem(props) {
  var _classNames;

  var name = props.name,
      children = props.children;

  var _useBoolean = useBoolean(),
      _useBoolean2 = _slicedToArray(_useBoolean, 2),
      focus = _useBoolean2[0],
      toggle = _useBoolean2[1].toggle;

  var _useBoolean3 = useBoolean(),
      _useBoolean4 = _slicedToArray(_useBoolean3, 2),
      hasVal = _useBoolean4[0],
      setHasVal = _useBoolean4[1].toggle;

  var _useBoolean5 = useBoolean(),
      _useBoolean6 = _slicedToArray(_useBoolean5, 2),
      hover = _useBoolean6[0],
      _useBoolean6$ = _useBoolean6[1],
      setFalse = _useBoolean6$.setFalse,
      setTrue = _useBoolean6$.setTrue;

  var onMouseEnter = function onMouseEnter() {
    setTrue();
  };

  var onMouseLeave = function onMouseLeave() {
    setFalse();
  };

  var onChange = function onChange(value) {
    var _children$props, _children$props$onCha;

    setHasVal(!isEmpty(value));

    for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
      args[_key - 1] = arguments[_key];
    }

    (_children$props = children.props) === null || _children$props === void 0 ? void 0 : (_children$props$onCha = _children$props.onChange) === null || _children$props$onCha === void 0 ? void 0 : _children$props$onCha.call.apply(_children$props$onCha, [_children$props, value].concat(args));
  };

  var onFocus = function onFocus(event) {
    var _children$props2, _children$props2$onFo;

    toggle(true);
    (_children$props2 = children.props) === null || _children$props2 === void 0 ? void 0 : (_children$props2$onFo = _children$props2.onFocus) === null || _children$props2$onFo === void 0 ? void 0 : _children$props2$onFo.call(_children$props2, event);
  };

  var onBlur = function onBlur(event) {
    var _children$props3, _children$props3$onBl;

    toggle(false);
    (_children$props3 = children.props) === null || _children$props3 === void 0 ? void 0 : (_children$props3$onBl = _children$props3.onBlur) === null || _children$props3$onBl === void 0 ? void 0 : _children$props3$onBl.call(_children$props3, event);
  };

  return /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(props.prefixCls, "-filter-item"), (_classNames = {}, _defineProperty(_classNames, "".concat(props.prefixCls, "-filter-item-hover"), hover), _defineProperty(_classNames, "".concat(props.prefixCls, "-filter-item-focus"), focus), _defineProperty(_classNames, "".concat(props.prefixCls, "-filter-item-has-value"), hasVal), _classNames)),
    onMouseEnter: onMouseEnter,
    onMouseLeave: onMouseLeave
  }, /*#__PURE__*/React.createElement(_Form.Item, {
    name: name,
    style: {
      marginBottom: 0
    }
  }, /*#__PURE__*/React.cloneElement(children, {
    onChange: onChange,
    onFocus: onFocus,
    onBlur: onBlur
  })));
}

export default FilterItem;