'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
var classNames = require('../_util/classNames.js');
var index = require('../_util/props-util/index.js');
var vnode = require('../_util/vnode.js');
require('../hooks/index.js');
var omit = require('../_util/omit.js');
var inputProps = require('./inputProps.js');
var Input = require('./Input.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

const ActionMap = {
  click: "onClick",
  hover: "onMouseover"
};
const defaultIconRender = (visible) => visible ? vue.createVNode(CloseOutlined.EyeOutlined, null, null) : vue.createVNode(CloseOutlined.EyeInvisibleOutlined, null, null);
var Password = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInputPassword",
  inheritAttrs: false,
  props: {
    ...inputProps.default(),
    prefixCls: String,
    inputPrefixCls: String,
    action: {
      type: String,
      default: "click"
    },
    visibilityToggle: {
      type: Boolean,
      default: true
    },
    iconRender: Function
  },
  setup(props, {
    slots,
    attrs,
    expose
  }) {
    const visible = vue.shallowRef(false);
    const onVisibleChange = () => {
      const {
        disabled
      } = props;
      if (disabled)
        return;
      visible.value = !visible.value;
    };
    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(index.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 = classNames.default(prefixCls.value, attrs.class, {
        [`${prefixCls.value}-${size}`]: !!size
      });
      const omittedProps = {
        ...omit.default(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, vue.mergeProps({
        "ref": inputRef
      }, omittedProps), slots);
    };
    return () => {
      return renderPassword();
    };
  }
});

exports.default = Password;
//# sourceMappingURL=Password.js.map
