import q from "../../../@ant-design/icons/es/icons/SearchOutlined.mjs";
import F from "../../../classnames/index.mjs";
import { composeRef as G } from "../../../rc-util/es/ref.mjs";
import * as l from "react";
import { cloneElement as k } from "../_util/reactNode.mjs";
import H from "../button/button.mjs";
import "../config-provider/index.mjs";
import J from "../config-provider/hooks/useSize.mjs";
import { useCompactItemContext as K } from "../space/Compact.mjs";
import L from "./Input.mjs";
import { ConfigContext as Q } from "../config-provider/context.mjs";
var W = globalThis && globalThis.__rest || function(n, m) {
  var c = {};
  for (var e in n)
    Object.prototype.hasOwnProperty.call(n, e) && m.indexOf(e) < 0 && (c[e] = n[e]);
  if (n != null && typeof Object.getOwnPropertySymbols == "function")
    for (var r = 0, e = Object.getOwnPropertySymbols(n); r < e.length; r++)
      m.indexOf(e[r]) < 0 && Object.prototype.propertyIsEnumerable.call(n, e[r]) && (c[e[r]] = n[e[r]]);
  return c;
};
const w = /* @__PURE__ */ l.forwardRef((n, m) => {
  const {
    prefixCls: c,
    inputPrefixCls: e,
    className: r,
    size: C,
    suffix: A,
    enterButton: u = !1,
    addonAfter: x,
    loading: O,
    disabled: S,
    onSearch: d,
    onChange: E,
    onCompositionStart: v,
    onCompositionEnd: b
  } = n, R = W(n, ["prefixCls", "inputPrefixCls", "className", "size", "suffix", "enterButton", "addonAfter", "loading", "disabled", "onSearch", "onChange", "onCompositionStart", "onCompositionEnd"]), {
    getPrefixCls: _,
    direction: N
  } = l.useContext(Q), h = l.useRef(!1), a = _("input-search", c), j = _("input", e), {
    compactSize: I
  } = K(a, N), f = J((t) => {
    var o;
    return (o = C ?? I) !== null && o !== void 0 ? o : t;
  }), y = l.useRef(null), $ = (t) => {
    t && t.target && t.type === "click" && d && d(t.target.value, t, {
      source: "clear"
    }), E && E(t);
  }, P = (t) => {
    var o;
    document.activeElement === ((o = y.current) === null || o === void 0 ? void 0 : o.input) && t.preventDefault();
  }, g = (t) => {
    var o, s;
    d && d((s = (o = y.current) === null || o === void 0 ? void 0 : o.input) === null || s === void 0 ? void 0 : s.value, t, {
      source: "input"
    });
  }, T = (t) => {
    h.current || O || g(t);
  }, D = typeof u == "boolean" ? /* @__PURE__ */ l.createElement(q, null) : null, z = `${a}-button`;
  let p;
  const i = u || {}, B = i.type && i.type.__ANT_BUTTON === !0;
  B || i.type === "button" ? p = k(i, Object.assign({
    onMouseDown: P,
    onClick: (t) => {
      var o, s;
      (s = (o = i == null ? void 0 : i.props) === null || o === void 0 ? void 0 : o.onClick) === null || s === void 0 || s.call(o, t), g(t);
    },
    key: "enterButton"
  }, B ? {
    className: z,
    size: f
  } : {})) : p = /* @__PURE__ */ l.createElement(H, {
    className: z,
    type: u ? "primary" : void 0,
    size: f,
    disabled: S,
    key: "enterButton",
    onMouseDown: P,
    onClick: g,
    loading: O,
    icon: D
  }, u), x && (p = [p, k(x, {
    key: "addonAfter"
  })]);
  const M = F(a, {
    [`${a}-rtl`]: N === "rtl",
    [`${a}-${f}`]: !!f,
    [`${a}-with-button`]: !!u
  }, r), U = (t) => {
    h.current = !0, v == null || v(t);
  }, V = (t) => {
    h.current = !1, b == null || b(t);
  };
  return /* @__PURE__ */ l.createElement(L, Object.assign({
    ref: G(y, m),
    onPressEnter: T
  }, R, {
    size: f,
    onCompositionStart: U,
    onCompositionEnd: V,
    prefixCls: j,
    addonAfter: p,
    suffix: A,
    onChange: $,
    className: M,
    disabled: S
  }));
});
process.env.NODE_ENV !== "production" && (w.displayName = "Search");
const lt = w;
export {
  lt as default
};
