'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
require('../../space/index.cjs');
require('../../config-provider/index.cjs');
var index = require('../style/index.cjs');
var util = require('./util.cjs');
var props = require('./props.cjs');
var statusUtils = require('../../../utils/statusUtils.cjs');
var context = require('../../space/src/context.cjs');
var disabledContext = require('../../config-provider/src/context/disabledContext.cjs');
var Input = require('../../../vue-components/vc-input/src/Input.cjs');
var omit = require('../../../utils/lang/omit.cjs');
var NoCompactStyle = require('../../space/src/NoCompactStyle.cjs');
var _class = require('../../../utils/dom/class.cjs');

var AInput = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInput",
  inheritAttrs: false,
  props: props.inputProps(),
  setup(props, {
    slots,
    attrs,
    expose,
    emit
  }) {
    const inputRef = vue.ref();
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
    const mergedStatus = vue.computed(() => statusUtils.getMergedStatus(formItemInputContext.status, props.status));
    const {
      direction,
      prefixCls,
      size,
      autocomplete
    } = useConfigInject.default("input", props);
    const {
      compactSize,
      compactItemClassnames
    } = context.useCompactItemContext(prefixCls, direction);
    const mergedSize = vue.computed(() => {
      return compactSize.value || size.value;
    });
    const [wrapSSR, hashId] = index.default(prefixCls);
    const disabled = disabledContext.useInjectDisabled();
    const focus = (option) => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.focus(option);
    };
    const blur = () => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.blur();
    };
    const setSelectionRange = (start, end, _direction) => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.setSelectionRange(start, end, _direction);
    };
    const select = () => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.select();
    };
    expose({
      focus,
      blur,
      input: inputRef,
      setSelectionRange,
      select
    });
    const removePasswordTimeoutRef = vue.ref([]);
    const removePasswordTimeout = () => {
      removePasswordTimeoutRef.value.push(setTimeout(() => {
        var _a, _b, _c, _d;
        if (((_a = inputRef.value) == null ? void 0 : _a.input) && ((_b = inputRef.value) == null ? void 0 : _b.input.getAttribute("type")) === "password" && ((_c = inputRef.value) == null ? void 0 : _c.input.hasAttribute("value")))
          (_d = inputRef.value) == null ? void 0 : _d.input.removeAttribute("value");
      }));
    };
    vue.onMounted(() => {
      removePasswordTimeout();
    });
    vue.onBeforeUpdate(() => {
      removePasswordTimeoutRef.value.forEach((item) => clearTimeout(item));
    });
    vue.onBeforeUnmount(() => {
      removePasswordTimeoutRef.value.forEach((item) => clearTimeout(item));
    });
    const handleBlur = (e) => {
      removePasswordTimeout();
      emit("blur", e);
      formItemContext.onFieldBlur();
    };
    const handleFocus = (e) => {
      removePasswordTimeout();
      emit("focus", e);
    };
    const triggerChange = (e) => {
      emit("update:value", e.target.value);
      emit("change", e);
      emit("input", e);
      formItemContext.onFieldChange();
    };
    return () => {
      var _a, _b, _c, _d, _e, _f;
      const {
        hasFeedback,
        feedbackIcon
      } = formItemInputContext;
      const {
        allowClear,
        bordered = true,
        prefix = (_a = slots.prefix) == null ? void 0 : _a.call(slots),
        suffix = (_b = slots.suffix) == null ? void 0 : _b.call(slots),
        addonAfter = (_c = slots.addonAfter) == null ? void 0 : _c.call(slots),
        addonBefore = (_d = slots.addonBefore) == null ? void 0 : _d.call(slots),
        id = (_e = formItemContext.id) == null ? void 0 : _e.value,
        ...rest
      } = props;
      const suffixNode = (hasFeedback || suffix) && vue.createVNode(vue.Fragment, null, [suffix, hasFeedback && feedbackIcon]);
      const prefixClsValue = prefixCls.value;
      const inputHasPrefixSuffix = util.hasPrefixSuffix({
        prefix,
        suffix
      }) || !!hasFeedback;
      const clearIcon = slots.clearIcon || (() => vue.createVNode(iconsVue.CloseCircleFilled, null, null));
      return wrapSSR(vue.createVNode(Input.default, {
        ...attrs,
        ...omit.omit(rest, ["onUpdate:value", "onChange", "onInput"]),
        "onChange": triggerChange,
        "id": id,
        "disabled": (_f = props.disabled) != null ? _f : disabled.value,
        "ref": inputRef,
        "prefixCls": prefixClsValue,
        "autocomplete": autocomplete.value,
        "onBlur": handleBlur,
        "onFocus": handleFocus,
        "prefix": prefix,
        "suffix": suffixNode,
        "allowClear": allowClear,
        "addonAfter": addonAfter && vue.createVNode(NoCompactStyle.NoCompactStyle, null, {
          default: () => [vue.createVNode(FormItemContext.NoFormStatus, null, {
            default: () => [addonAfter]
          })]
        }),
        "addonBefore": addonBefore && vue.createVNode(NoCompactStyle.NoCompactStyle, null, {
          default: () => [vue.createVNode(FormItemContext.NoFormStatus, null, {
            default: () => [addonBefore]
          })]
        }),
        "class": [attrs.class, compactItemClassnames.value],
        "inputClassName": _class.classNames({
          [`${prefixClsValue}-sm`]: mergedSize.value === "small",
          [`${prefixClsValue}-lg`]: mergedSize.value === "large",
          [`${prefixClsValue}-rtl`]: direction.value === "rtl",
          [`${prefixClsValue}-borderless`]: !bordered
        }, !inputHasPrefixSuffix && statusUtils.getStatusClassNames(prefixClsValue, mergedStatus.value), hashId.value),
        "affixWrapperClassName": _class.classNames({
          [`${prefixClsValue}-affix-wrapper-sm`]: mergedSize.value === "small",
          [`${prefixClsValue}-affix-wrapper-lg`]: mergedSize.value === "large",
          [`${prefixClsValue}-affix-wrapper-rtl`]: direction.value === "rtl",
          [`${prefixClsValue}-affix-wrapper-borderless`]: !bordered
        }, statusUtils.getStatusClassNames(`${prefixClsValue}-affix-wrapper`, mergedStatus.value, hasFeedback), hashId.value),
        "wrapperClassName": _class.classNames({
          [`${prefixClsValue}-group-rtl`]: direction.value === "rtl"
        }, hashId.value),
        "groupClassName": _class.classNames({
          [`${prefixClsValue}-group-wrapper-sm`]: mergedSize.value === "small",
          [`${prefixClsValue}-group-wrapper-lg`]: mergedSize.value === "large",
          [`${prefixClsValue}-group-wrapper-rtl`]: direction.value === "rtl"
        }, statusUtils.getStatusClassNames(`${prefixClsValue}-group-wrapper`, mergedStatus.value, hasFeedback), hashId.value)
      }, {
        ...slots,
        clearIcon
      }));
    };
  }
});

exports.default = AInput;
//# sourceMappingURL=Input.cjs.map
