import { defineComponent, ref, computed, onMounted, onBeforeUpdate, onBeforeUnmount, createVNode, Fragment } from 'vue';
import { CloseCircleFilled } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../vue-components/index.mjs';
import { useInjectFormItemContext, FormItemInputContext, NoFormStatus } from '../../form/src/FormItemContext.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import '../../space/index.mjs';
import '../../config-provider/index.mjs';
import useStyle from '../style/index.mjs';
import { hasPrefixSuffix } from './util.mjs';
import { inputProps } from './props.mjs';
import { getMergedStatus, getStatusClassNames } from '../../../utils/statusUtils.mjs';
import { useCompactItemContext } from '../../space/src/context.mjs';
import { useInjectDisabled } from '../../config-provider/src/context/disabledContext.mjs';
import VcInput from '../../../vue-components/vc-input/src/Input.mjs';
import { omit } from '../../../utils/lang/omit.mjs';
import { NoCompactStyle } from '../../space/src/NoCompactStyle.mjs';
import { classNames } from '../../../utils/dom/class.mjs';

var AInput = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInput",
  inheritAttrs: false,
  props: inputProps(),
  setup(props, {
    slots,
    attrs,
    expose,
    emit
  }) {
    const inputRef = ref();
    const formItemContext = useInjectFormItemContext();
    const formItemInputContext = FormItemInputContext.useInject();
    const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
    const {
      direction,
      prefixCls,
      size,
      autocomplete
    } = useConfigInject("input", props);
    const {
      compactSize,
      compactItemClassnames
    } = useCompactItemContext(prefixCls, direction);
    const mergedSize = computed(() => {
      return compactSize.value || size.value;
    });
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const disabled = 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 = 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");
      }));
    };
    onMounted(() => {
      removePasswordTimeout();
    });
    onBeforeUpdate(() => {
      removePasswordTimeoutRef.value.forEach((item) => clearTimeout(item));
    });
    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) && createVNode(Fragment, null, [suffix, hasFeedback && feedbackIcon]);
      const prefixClsValue = prefixCls.value;
      const inputHasPrefixSuffix = hasPrefixSuffix({
        prefix,
        suffix
      }) || !!hasFeedback;
      const clearIcon = slots.clearIcon || (() => createVNode(CloseCircleFilled, null, null));
      return wrapSSR(createVNode(VcInput, {
        ...attrs,
        ...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 && createVNode(NoCompactStyle, null, {
          default: () => [createVNode(NoFormStatus, null, {
            default: () => [addonAfter]
          })]
        }),
        "addonBefore": addonBefore && createVNode(NoCompactStyle, null, {
          default: () => [createVNode(NoFormStatus, null, {
            default: () => [addonBefore]
          })]
        }),
        "class": [attrs.class, compactItemClassnames.value],
        "inputClassName": classNames({
          [`${prefixClsValue}-sm`]: mergedSize.value === "small",
          [`${prefixClsValue}-lg`]: mergedSize.value === "large",
          [`${prefixClsValue}-rtl`]: direction.value === "rtl",
          [`${prefixClsValue}-borderless`]: !bordered
        }, !inputHasPrefixSuffix && getStatusClassNames(prefixClsValue, mergedStatus.value), hashId.value),
        "affixWrapperClassName": 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
        }, getStatusClassNames(`${prefixClsValue}-affix-wrapper`, mergedStatus.value, hasFeedback), hashId.value),
        "wrapperClassName": classNames({
          [`${prefixClsValue}-group-rtl`]: direction.value === "rtl"
        }, hashId.value),
        "groupClassName": classNames({
          [`${prefixClsValue}-group-wrapper-sm`]: mergedSize.value === "small",
          [`${prefixClsValue}-group-wrapper-lg`]: mergedSize.value === "large",
          [`${prefixClsValue}-group-wrapper-rtl`]: direction.value === "rtl"
        }, getStatusClassNames(`${prefixClsValue}-group-wrapper`, mergedStatus.value, hasFeedback), hashId.value)
      }, {
        ...slots,
        clearIcon
      }));
    };
  }
});

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