"use strict";
const React = require("react");
const classNames = require("../_util/classNames.js");
const input = require("./input.js");
const index$1 = require("../../icon/react-icon/IconEye/index.js");
const index$2 = require("../../icon/react-icon/IconEyeInvisible/index.js");
const index = require("../ConfigProvider/index.js");
const useMergeValue = require("../_util/hooks/useMergeValue.js");
const omit = require("../_util/omit.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var Password = React__default.default.forwardRef(function(props, ref) {
  var _a;
  var _b = __read(useMergeValue(false, {
    defaultValue: props.defaultVisibility,
    value: props.visibility
  }), 2), visibility = _b[0], setVisibility = _b[1];
  var getPrefixCls = React.useContext(index.ConfigContext).getPrefixCls;
  var className = props.className, visibilityToggle = props.visibilityToggle, onVisibilityChange = props.onVisibilityChange, rest = __rest(props, ["className", "visibilityToggle", "onVisibilityChange"]);
  var prefixCls = getPrefixCls("input-password");
  var classNames$1 = classNames(prefixCls, (_a = {}, _a[prefixCls + "-visibility"] = visibilityToggle, _a), className);
  var onClickVisibility = function(v) {
    if (!("visibility" in props)) {
      setVisibility(v);
    }
    onVisibilityChange && onVisibilityChange(v);
  };
  var icon = props.suffix;
  if (visibilityToggle) {
    var IconProps = {
      onClick: function() {
        return onClickVisibility(!visibility);
      },
      onMouseDown: function(e) {
        return e.preventDefault();
      },
      onMouseUp: function(e) {
        return e.preventDefault();
      }
    };
    if (props.suffix) {
      icon = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
        ...__assign({}, IconProps),
        children: props.suffix
      });
    } else {
      var IconComponent = visibility ? index$1 : index$2;
      icon = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(IconComponent, {
        ...__assign({}, IconProps)
      });
    }
  }
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(input.default, {
    ...__assign({}, omit(rest, ["visibility", "defaultVisibility"]), {
      type: visibility ? "text" : "password",
      className: classNames$1,
      ref,
      suffix: icon
    })
  });
});
Password.displayName = "Password";
Password.defaultProps = {
  visibilityToggle: true
};
const Password$1 = Password;
module.exports = Password$1;
//# sourceMappingURL=password.js.map
