import a, { forwardRef as te, useRef as z, useContext as oe, useEffect as re } from "react";
import se from "../../../@ant-design/icons/es/icons/CloseCircleFilled.mjs";
import v from "../../../classnames/index.mjs";
import ae from "../../../rc-input/es/Input.mjs";
import { composeRef as le } from "../../../rc-util/es/ref.mjs";
import { getStatusClassNames as I, getMergedStatus as ne } from "../_util/statusUtils.mjs";
import { devUseWarning as ie } from "../_util/warning.mjs";
import "../config-provider/index.mjs";
import ue from "../config-provider/DisabledContext.mjs";
import ce from "../config-provider/hooks/useSize.mjs";
import { FormItemInputContext as de, NoFormStyle as B } from "../form/context.mjs";
import { useCompactItemContext as fe, NoCompactStyle as k } from "../space/Compact.mjs";
import me from "./hooks/useRemovePasswordTimeout.mjs";
import pe from "./style/index.mjs";
import { hasPrefixSuffix as ge } from "./utils.mjs";
import ve from "../config-provider/hooks/useCSSVarCls.mjs";
import { ConfigContext as Ce } from "../config-provider/context.mjs";
var be = globalThis && globalThis.__rest || function(t, i) {
  var s = {};
  for (var r in t)
    Object.prototype.hasOwnProperty.call(t, r) && i.indexOf(r) < 0 && (s[r] = t[r]);
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
    for (var l = 0, r = Object.getOwnPropertySymbols(t); l < r.length; l++)
      i.indexOf(r[l]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[l]) && (s[r[l]] = t[r[l]]);
  return s;
};
function Ae(t, i) {
  if (!t)
    return;
  t.focus(i);
  const {
    cursor: s
  } = i || {};
  if (s) {
    const r = t.value.length;
    switch (s) {
      case "start":
        t.setSelectionRange(0, 0);
        break;
      case "end":
        t.setSelectionRange(r, r);
        break;
      default:
        t.setSelectionRange(0, r);
        break;
    }
  }
}
const xe = /* @__PURE__ */ te((t, i) => {
  var s;
  const {
    prefixCls: r,
    bordered: l = !0,
    status: A,
    size: b,
    disabled: x,
    onBlur: w,
    onFocus: S,
    suffix: E,
    allowClear: c,
    addonAfter: j,
    addonBefore: F,
    className: D,
    style: V,
    styles: T,
    rootClassName: W,
    onChange: y,
    classNames: C
  } = t, H = be(t, ["prefixCls", "bordered", "status", "size", "disabled", "onBlur", "onFocus", "suffix", "allowClear", "addonAfter", "addonBefore", "className", "style", "styles", "rootClassName", "onChange", "classNames"]), {
    getPrefixCls: M,
    direction: f,
    input: o
  } = a.useContext(Ce), e = M("input", r), h = z(null), _ = ve(e), [Q, m, U] = pe(e, _), {
    compactSize: q,
    compactItemClassnames: G
  } = fe(e, f), d = ce((n) => {
    var u;
    return (u = b ?? q) !== null && u !== void 0 ? u : n;
  }), J = a.useContext(ue), P = x ?? J, {
    status: K,
    hasFeedback: p,
    feedbackIcon: L
  } = oe(de), N = ne(K, A), g = ge(t) || !!p, R = z(g);
  if (process.env.NODE_ENV !== "production") {
    const n = ie("Input");
    re(() => {
      var u;
      g && !R.current && process.env.NODE_ENV !== "production" && n(document.activeElement === ((u = h.current) === null || u === void 0 ? void 0 : u.input), "usage", "When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change. Read more: https://ant.design/components/input/#FAQ"), R.current = g;
    }, [g]);
  }
  const O = me(h, !0), X = (n) => {
    O(), w == null || w(n);
  }, Y = (n) => {
    O(), S == null || S(n);
  }, Z = (n) => {
    O(), y == null || y(n);
  }, ee = (p || E) && /* @__PURE__ */ a.createElement(a.Fragment, null, E, p && L);
  let $;
  return typeof c == "object" && (c != null && c.clearIcon) ? $ = c : c && ($ = {
    clearIcon: /* @__PURE__ */ a.createElement(se, null)
  }), Q(/* @__PURE__ */ a.createElement(ae, Object.assign({
    ref: le(i, h),
    prefixCls: e,
    autoComplete: o == null ? void 0 : o.autoComplete
  }, H, {
    disabled: P,
    onBlur: X,
    onFocus: Y,
    style: Object.assign(Object.assign({}, o == null ? void 0 : o.style), V),
    styles: Object.assign(Object.assign({}, o == null ? void 0 : o.styles), T),
    suffix: ee,
    allowClear: $,
    className: v(D, W, U, _, m, G, o == null ? void 0 : o.className),
    onChange: Z,
    addonAfter: j && /* @__PURE__ */ a.createElement(k, null, /* @__PURE__ */ a.createElement(B, {
      override: !0,
      status: !0
    }, j)),
    addonBefore: F && /* @__PURE__ */ a.createElement(k, null, /* @__PURE__ */ a.createElement(B, {
      override: !0,
      status: !0
    }, F)),
    classNames: Object.assign(Object.assign(Object.assign({}, C), o == null ? void 0 : o.classNames), {
      input: v({
        [`${e}-sm`]: d === "small",
        [`${e}-lg`]: d === "large",
        [`${e}-rtl`]: f === "rtl",
        [`${e}-borderless`]: !l
      }, !g && I(e, N), C == null ? void 0 : C.input, (s = o == null ? void 0 : o.classNames) === null || s === void 0 ? void 0 : s.input, m)
    }),
    classes: {
      affixWrapper: v({
        [`${e}-affix-wrapper-sm`]: d === "small",
        [`${e}-affix-wrapper-lg`]: d === "large",
        [`${e}-affix-wrapper-rtl`]: f === "rtl",
        [`${e}-affix-wrapper-borderless`]: !l
      }, I(`${e}-affix-wrapper`, N, p), m),
      wrapper: v({
        [`${e}-group-rtl`]: f === "rtl"
      }, m),
      group: v({
        [`${e}-group-wrapper-sm`]: d === "small",
        [`${e}-group-wrapper-lg`]: d === "large",
        [`${e}-group-wrapper-rtl`]: f === "rtl",
        [`${e}-group-wrapper-disabled`]: P
      }, I(`${e}-group-wrapper`, N, p), m)
    }
  })));
}), De = xe;
export {
  De as default,
  Ae as triggerFocus
};
