'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var props = require('./props.cjs');
var Input = require('./Input.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');
var is = require('../../../utils/is.cjs');
var _class = require('../../../utils/dom/class.cjs');
var omit = require('../../../utils/lang/omit.cjs');

const ActionMap = {
  click: "onClick",
  hover: "onMouseover"
};
const defaultIconRender = (visible) => visible ? vue.createVNode(iconsVue.EyeOutlined, null, null) : vue.createVNode(iconsVue.EyeInvisibleOutlined, null, null);
var AInputPassword = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInputPassword",
  inheritAttrs: false,
  props: {
    ...props.inputProps(),
    "prefixCls": String,
    "inputPrefixCls": String,
    "action": {
      type: String,
      default: "click"
    },
    "visibilityToggle": {
      type: Boolean,
      default: true
    },
    "visible": {
      type: Boolean,
      default: void 0
    },
    "onUpdate:visible": Function,
    "iconRender": Function
  },
  setup(props, {
    slots,
    attrs,
    expose,
    emit
  }) {
    const visible = vue.shallowRef(false);
    const onVisibleChange = () => {
      const {
        disabled
      } = props;
      if (disabled)
        return;
      visible.value = !visible.value;
      emit("update:visible", visible.value);
    };
    vue.watchEffect(() => {
      if (props.visible !== void 0)
        visible.value = !!props.visible;
    });
    const inputRef = vue.shallowRef();
    const focus = () => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.blur();
    };
    expose({
      focus,
      blur
    });
    const getIcon = (prefixCls2) => {
      const {
        action,
        iconRender = slots.iconRender || defaultIconRender
      } = props;
      const iconTrigger = ActionMap[action] || "";
      const icon = iconRender(visible.value);
      const iconProps = {
        [iconTrigger]: onVisibleChange,
        class: `${prefixCls2}-icon`,
        key: "passwordIcon",
        onMousedown: (e) => {
          e.preventDefault();
        },
        onMouseup: (e) => {
          e.preventDefault();
        }
      };
      return vnode.cloneElement(is.isValidElement(icon) ? icon : vue.createVNode("span", null, [icon]), iconProps);
    };
    const {
      prefixCls,
      getPrefixCls
    } = useConfigInject.default("input-password", props);
    const inputPrefixCls = vue.computed(() => getPrefixCls("input", props.inputPrefixCls));
    const renderPassword = () => {
      const {
        size,
        visibilityToggle,
        ...restProps
      } = props;
      const suffixIcon = visibilityToggle && getIcon(prefixCls.value);
      const inputClassName = _class.classNames(prefixCls.value, attrs.class, {
        [`${prefixCls.value}-${size}`]: !!size
      });
      const omittedProps = {
        ...omit.omit(restProps, ["suffix", "iconRender", "action"]),
        ...attrs,
        type: visible.value ? "text" : "password",
        class: inputClassName,
        prefixCls: inputPrefixCls.value,
        suffix: suffixIcon
      };
      if (size)
        omittedProps.size = size;
      return vue.createVNode(Input.default, {
        "ref": inputRef,
        ...omittedProps
      }, slots);
    };
    return () => {
      return renderPassword();
    };
  }
});

exports.default = AInputPassword;
//# sourceMappingURL=Password.cjs.map
