import { createVNode, defineComponent, shallowRef, computed, mergeProps } from 'vue';
import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons-vue';
import classNames from '../_util/classNames.mjs';
import { isValidElement } from '../_util/props-util/index.mjs';
import { cloneElement } from '../_util/vnode.mjs';
import '../hooks/index.mjs';
import omit from '../_util/omit.mjs';
import inputProps from './inputProps.mjs';
import Input from './Input.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';

const ActionMap = {
  click: "onClick",
  hover: "onMouseover"
};
const defaultIconRender = (visible) => visible ? createVNode(EyeOutlined, null, null) : createVNode(EyeInvisibleOutlined, null, null);
var Password = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInputPassword",
  inheritAttrs: false,
  props: {
    ...inputProps(),
    prefixCls: String,
    inputPrefixCls: String,
    action: {
      type: String,
      default: "click"
    },
    visibilityToggle: {
      type: Boolean,
      default: true
    },
    iconRender: Function
  },
  setup(props, {
    slots,
    attrs,
    expose
  }) {
    const visible = shallowRef(false);
    const onVisibleChange = () => {
      const {
        disabled
      } = props;
      if (disabled)
        return;
      visible.value = !visible.value;
    };
    const inputRef = 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 cloneElement(isValidElement(icon) ? icon : createVNode("span", null, [icon]), iconProps);
    };
    const {
      prefixCls,
      getPrefixCls
    } = useConfigInject("input-password", props);
    const inputPrefixCls = computed(() => getPrefixCls("input", props.inputPrefixCls));
    const renderPassword = () => {
      const {
        size,
        visibilityToggle,
        ...restProps
      } = props;
      const suffixIcon = visibilityToggle && getIcon(prefixCls.value);
      const inputClassName = classNames(prefixCls.value, attrs.class, {
        [`${prefixCls.value}-${size}`]: !!size
      });
      const omittedProps = {
        ...omit(restProps, ["suffix", "iconRender", "action"]),
        ...attrs,
        type: visible.value ? "text" : "password",
        class: inputClassName,
        prefixCls: inputPrefixCls.value,
        suffix: suffixIcon
      };
      if (size)
        omittedProps.size = size;
      return createVNode(Input, mergeProps({
        "ref": inputRef
      }, omittedProps), slots);
    };
    return () => {
      return renderPassword();
    };
  }
});

export { Password as default };
//# sourceMappingURL=Password.mjs.map
