import T from "../../../@ant-design/icons/es/icons/EyeInvisibleOutlined.mjs";
import _ from "../../../@ant-design/icons/es/icons/EyeOutlined.mjs";
import z from "../../../classnames/index.mjs";
import V from "../../../rc-util/es/omit.mjs";
import { composeRef as k } from "../../../rc-util/es/ref.mjs";
import * as n from "react";
import { useState as D, useRef as M } from "react";
import "../config-provider/index.mjs";
import S from "./hooks/useRemovePasswordTimeout.mjs";
import $ from "./Input.mjs";
import { ConfigContext as A } from "../config-provider/context.mjs";
var U = globalThis && globalThis.__rest || function(e, r) {
  var o = {};
  for (var t in e)
    Object.prototype.hasOwnProperty.call(e, t) && r.indexOf(t) < 0 && (o[t] = e[t]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
    for (var s = 0, t = Object.getOwnPropertySymbols(e); s < t.length; s++)
      r.indexOf(t[s]) < 0 && Object.prototype.propertyIsEnumerable.call(e, t[s]) && (o[t[s]] = e[t[s]]);
  return o;
};
const q = (e) => e ? /* @__PURE__ */ n.createElement(_, null) : /* @__PURE__ */ n.createElement(T, null), B = {
  click: "onClick",
  hover: "onMouseOver"
}, x = /* @__PURE__ */ n.forwardRef((e, r) => {
  const {
    visibilityToggle: o = !0
  } = e, t = typeof o == "object" && o.visible !== void 0, [s, d] = D(() => t ? o.visible : !1), b = M(null);
  n.useEffect(() => {
    t && d(o.visible);
  }, [t, o]);
  const y = S(b), C = () => {
    const {
      disabled: f
    } = e;
    f || (s && y(), d((u) => {
      var i;
      const c = !u;
      return typeof o == "object" && ((i = o.onVisibleChange) === null || i === void 0 || i.call(o, c)), c;
    }));
  }, P = (f) => {
    const {
      action: u = "click",
      iconRender: i = q
    } = e, c = B[u] || "", m = i(s), h = {
      [c]: C,
      className: `${f}-icon`,
      key: "passwordIcon",
      onMouseDown: (p) => {
        p.preventDefault();
      },
      onMouseUp: (p) => {
        p.preventDefault();
      }
    };
    return /* @__PURE__ */ n.cloneElement(/* @__PURE__ */ n.isValidElement(m) ? m : /* @__PURE__ */ n.createElement("span", null, m), h);
  }, {
    className: O,
    prefixCls: w,
    inputPrefixCls: E,
    size: l
  } = e, j = U(e, ["className", "prefixCls", "inputPrefixCls", "size"]), {
    getPrefixCls: v
  } = n.useContext(A), I = v("input", E), a = v("input-password", w), N = o && P(a), R = z(a, O, {
    [`${a}-${l}`]: !!l
  }), g = Object.assign(Object.assign({}, V(j, ["suffix", "iconRender", "visibilityToggle"])), {
    type: s ? "text" : "password",
    className: R,
    prefixCls: I,
    suffix: N
  });
  return l && (g.size = l), /* @__PURE__ */ n.createElement($, Object.assign({
    ref: k(r, b)
  }, g));
});
process.env.NODE_ENV !== "production" && (x.displayName = "Password");
const Z = x;
export {
  Z as default
};
