"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _icons = require("@wii/icons");
var _wauConfigProvider = require("../wau-config-provider");
var _input = _interopRequireDefault(require("../input"));
require("./style");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const WauSearch = /*#__PURE__*/(0, _react.forwardRef)(({
  onSearch: customOnSearch,
  onChange: customOnChange,
  iconProps,
  ...props
}, ref) => {
  const {
    getPrefixCls
  } = (0, _react.useContext)(_wauConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls('search');
  const inputRef = (0, _react.useRef)(null);
  const onChange = (0, _react.useCallback)(e => {
    if (e && e.target && e.type === 'click' && customOnSearch) {
      customOnSearch(e.target.value, e);
    }
    if (customOnChange) {
      customOnChange(e);
    }
  }, [customOnChange, customOnSearch]);
  const handlePressEnter = (0, _react.useCallback)(e => {
    var _inputRef$current, _inputRef$current$inp;
    customOnSearch === null || customOnSearch === void 0 ? void 0 : customOnSearch((_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : (_inputRef$current$inp = _inputRef$current.input) === null || _inputRef$current$inp === void 0 ? void 0 : _inputRef$current$inp.value, e);
  }, [customOnSearch]);
  const handleSearchIconClick = (0, _react.useCallback)(e => {
    var _inputRef$current2, _inputRef$current2$in;
    customOnSearch === null || customOnSearch === void 0 ? void 0 : customOnSearch((_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : (_inputRef$current2$in = _inputRef$current2.input) === null || _inputRef$current2$in === void 0 ? void 0 : _inputRef$current2$in.value, e);
  }, [customOnSearch]);
  (0, _react.useImperativeHandle)(ref, () => inputRef.current);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_input.default, {
    type: "search",
    className: prefixCls,
    ref: inputRef,
    suffix: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.WauSearchOutlined, {
      onClick: handleSearchIconClick,
      className: `${prefixCls}-icon`,
      ...iconProps
    }),
    onChange: onChange,
    onPressEnter: handlePressEnter,
    ...props
  });
});
var _default = WauSearch;
exports.default = _default;