"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const event = require("../../../constants/event.js");
const index$4 = require("../../../../node_modules/@vueuse/core/index.js");
const shared_esmBundler = require("../../../../../@vue/shared/dist/shared.esm-bundler.js");
const error = require("../../../utils/error.js");
const icon = require("../../../utils/vue/icon.js");
const index = require("../../../hooks/use-attrs/index.js");
const index$1 = require("../../../hooks/use-namespace/index.js");
const index$8 = require("../../../hooks/use-cursor/index.js");
const index$2 = require("../../../hooks/use-focus-controller/index.js");
const index$5 = require("../../../hooks/use-composition/index.js");
const index$6 = require("../../icon/index.js");
const useFormCommonProps = require("../../form/src/hooks/use-form-common-props.js");
const useFormItem = require("../../form/src/hooks/use-form-item.js");
const input = require("./input.js");
const utils = require("./utils.js");
const index$3 = require("../../../../../@element-plus/icons-vue/dist/index.js");
const vue = require("vue");
const isNil = require("../../../../../lodash-es/isNil.js");
const index$7 = require("../../../../node_modules/@vueuse/shared/index.js");
const _hoisted_1 = [
  "id",
  "name",
  "minlength",
  "maxlength",
  "type",
  "disabled",
  "readonly",
  "autocomplete",
  "tabindex",
  "aria-label",
  "placeholder",
  "form",
  "autofocus",
  "role",
  "inputmode"
];
const _hoisted_2 = [
  "id",
  "name",
  "minlength",
  "maxlength",
  "tabindex",
  "disabled",
  "readonly",
  "autocomplete",
  "aria-label",
  "placeholder",
  "form",
  "autofocus",
  "rows",
  "role",
  "inputmode"
];
const COMPONENT_NAME = "ElInput";
var input_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ vue.defineComponent({
  name: COMPONENT_NAME,
  inheritAttrs: false,
  __name: "input",
  props: input.inputProps,
  emits: input.inputEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const rawAttrs = vue.useAttrs();
    const attrs = index.useAttrs();
    const slots = vue.useSlots();
    const containerKls = vue.computed(() => [
      props.type === "textarea" ? nsTextarea.b() : nsInput.b(),
      nsInput.m(inputSize.value),
      nsInput.is("disabled", inputDisabled.value),
      nsInput.is("exceed", inputExceed.value),
      {
        [nsInput.b("group")]: slots.prepend || slots.append,
        [nsInput.m("prefix")]: slots.prefix || props.prefixIcon,
        [nsInput.m("suffix")]: slots.suffix || props.suffixIcon || props.clearable || props.showPassword,
        [nsInput.bm("suffix", "password-clear")]: showClear.value && showPwdVisible.value,
        [nsInput.b("hidden")]: props.type === "hidden"
      },
      rawAttrs.class
    ]);
    const wrapperKls = vue.computed(() => [nsInput.e("wrapper"), nsInput.is("focus", isFocused.value)]);
    const { form: elForm, formItem: elFormItem } = useFormItem.useFormItem();
    const { inputId } = useFormItem.useFormItemInputId(props, { formItemContext: elFormItem });
    const inputSize = useFormCommonProps.useFormSize();
    const inputDisabled = useFormCommonProps.useFormDisabled();
    const nsInput = index$1.useNamespace("input");
    const nsTextarea = index$1.useNamespace("textarea");
    const input2 = vue.shallowRef();
    const textarea = vue.shallowRef();
    const hovering = vue.ref(false);
    const passwordVisible = vue.ref(false);
    const countStyle = vue.ref();
    const textareaCalcStyle = vue.shallowRef(props.inputStyle);
    const _ref = vue.computed(() => input2.value || textarea.value);
    const { wrapperRef, isFocused, handleFocus, handleBlur } = index$2.useFocusController(_ref, {
      disabled: inputDisabled,
      afterBlur() {
        var _a;
        if (props.validateEvent) (_a = elFormItem == null ? void 0 : elFormItem.validate) == null ? void 0 : _a.call(elFormItem, "blur").catch((err) => error.debugWarn(err));
      }
    });
    const needStatusIcon = vue.computed(() => (elForm == null ? void 0 : elForm.statusIcon) ?? false);
    const validateState = vue.computed(() => (elFormItem == null ? void 0 : elFormItem.validateState) || "");
    const validateIcon = vue.computed(() => validateState.value && icon.ValidateComponentsMap[validateState.value]);
    const passwordIcon = vue.computed(() => passwordVisible.value ? index$3.View : index$3.Hide);
    const containerStyle = vue.computed(() => [rawAttrs.style]);
    const textareaStyle = vue.computed(() => [
      props.inputStyle,
      textareaCalcStyle.value,
      { resize: props.resize }
    ]);
    const nativeInputValue = vue.computed(() => isNil.default(props.modelValue) ? "" : String(props.modelValue));
    const showClear = vue.computed(() => props.clearable && !inputDisabled.value && !props.readonly && !!nativeInputValue.value && (isFocused.value || hovering.value));
    const showPwdVisible = vue.computed(() => props.showPassword && !inputDisabled.value && !!nativeInputValue.value);
    const isWordLimitVisible = vue.computed(() => props.showWordLimit && !!props.maxlength && (props.type === "text" || props.type === "textarea") && !inputDisabled.value && !props.readonly && !props.showPassword);
    const textLength = vue.computed(() => nativeInputValue.value.length);
    const inputExceed = vue.computed(() => !!isWordLimitVisible.value && textLength.value > Number(props.maxlength));
    const suffixVisible = vue.computed(() => !!slots.suffix || !!props.suffixIcon || showClear.value || props.showPassword || isWordLimitVisible.value || !!validateState.value && needStatusIcon.value);
    const hasModelModifiers = vue.computed(() => !!Object.keys(props.modelModifiers).length);
    const [recordCursor, setCursor] = index$8.useCursor(input2);
    index$4.useResizeObserver(textarea, (entries) => {
      onceInitSizeTextarea();
      if (!isWordLimitVisible.value || props.resize !== "both" && props.resize !== "horizontal") return;
      const { width } = entries[0].contentRect;
      countStyle.value = { right: `calc(100% - ${width + 22 - 10}px)` };
    });
    const resizeTextarea = () => {
      const { type, autosize } = props;
      if (!index$7.isClient || type !== "textarea" || !textarea.value) return;
      if (autosize) {
        const minRows = shared_esmBundler.isObject(autosize) ? autosize.minRows : void 0;
        const maxRows = shared_esmBundler.isObject(autosize) ? autosize.maxRows : void 0;
        const textareaStyle2 = utils.calcTextareaHeight(textarea.value, minRows, maxRows);
        textareaCalcStyle.value = {
          overflowY: "hidden",
          ...textareaStyle2
        };
        vue.nextTick(() => {
          textarea.value.offsetHeight;
          textareaCalcStyle.value = textareaStyle2;
        });
      } else textareaCalcStyle.value = { minHeight: utils.calcTextareaHeight(textarea.value).minHeight };
    };
    const createOnceInitResize = (resizeTextarea2) => {
      let isInit = false;
      return () => {
        var _a;
        if (isInit || !props.autosize) return;
        if (!(((_a = textarea.value) == null ? void 0 : _a.offsetParent) === null)) {
          setTimeout(resizeTextarea2);
          isInit = true;
        }
      };
    };
    const onceInitSizeTextarea = createOnceInitResize(resizeTextarea);
    const setNativeInputValue = () => {
      const input3 = _ref.value;
      const formatterValue = props.formatter ? props.formatter(nativeInputValue.value) : nativeInputValue.value;
      if (!input3 || input3.value === formatterValue || props.type === "file") return;
      input3.value = formatterValue;
    };
    const formatValue = (value) => {
      const { trim, number } = props.modelModifiers;
      if (trim) value = value.trim();
      if (number) value = `${utils.looseToNumber(value)}`;
      if (props.formatter && props.parser) value = props.parser(value);
      return value;
    };
    const handleInput = async (event$1) => {
      if (isComposing.value) return;
      const { lazy } = props.modelModifiers;
      let { value } = event$1.target;
      if (lazy) {
        emit(event.INPUT_EVENT, value);
        return;
      }
      value = formatValue(value);
      if (String(value) === nativeInputValue.value) {
        if (props.formatter) setNativeInputValue();
        return;
      }
      recordCursor();
      emit(event.UPDATE_MODEL_EVENT, value);
      emit(event.INPUT_EVENT, value);
      await vue.nextTick();
      if (props.formatter && props.parser || !hasModelModifiers.value) setNativeInputValue();
      setCursor();
    };
    const handleChange = async (event$1) => {
      let { value } = event$1.target;
      value = formatValue(value);
      if (props.modelModifiers.lazy) emit(event.UPDATE_MODEL_EVENT, value);
      emit(event.CHANGE_EVENT, value, event$1);
      await vue.nextTick();
      setNativeInputValue();
    };
    const { isComposing, handleCompositionStart, handleCompositionUpdate, handleCompositionEnd } = index$5.useComposition({
      emit,
      afterComposition: handleInput
    });
    const handlePasswordVisible = () => {
      passwordVisible.value = !passwordVisible.value;
    };
    const focus = () => {
      var _a;
      return (_a = _ref.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      return (_a = _ref.value) == null ? void 0 : _a.blur();
    };
    const handleMouseLeave = (evt) => {
      hovering.value = false;
      emit("mouseleave", evt);
    };
    const handleMouseEnter = (evt) => {
      hovering.value = true;
      emit("mouseenter", evt);
    };
    const handleKeydown = (evt) => {
      emit("keydown", evt);
    };
    const select = () => {
      var _a;
      (_a = _ref.value) == null ? void 0 : _a.select();
    };
    const clear = (evt) => {
      emit(event.UPDATE_MODEL_EVENT, "");
      emit(event.CHANGE_EVENT, "");
      emit("clear", evt);
      emit(event.INPUT_EVENT, "");
    };
    vue.watch(() => props.modelValue, () => {
      var _a;
      vue.nextTick(() => resizeTextarea());
      if (props.validateEvent) (_a = elFormItem == null ? void 0 : elFormItem.validate) == null ? void 0 : _a.call(elFormItem, "change").catch((err) => error.debugWarn(err));
    });
    vue.watch(nativeInputValue, (newValue) => {
      if (!_ref.value) return;
      const { trim, number } = props.modelModifiers;
      const elValue = _ref.value.value;
      const displayValue = (number || props.type === "number") && !/^0\d/.test(elValue) ? `${utils.looseToNumber(elValue)}` : elValue;
      if (displayValue === newValue) return;
      if (document.activeElement === _ref.value && _ref.value.type !== "range") {
        if (trim && displayValue.trim() === newValue) return;
      }
      setNativeInputValue();
    });
    vue.watch(() => props.type, async () => {
      await vue.nextTick();
      setNativeInputValue();
      resizeTextarea();
    });
    vue.onMounted(() => {
      if (!props.formatter && props.parser) error.debugWarn(COMPONENT_NAME, "If you set the parser, you also need to set the formatter.");
      setNativeInputValue();
      vue.nextTick(resizeTextarea);
    });
    __expose({
      input: input2,
      textarea,
      ref: _ref,
      textareaStyle,
      autosize: vue.toRef(props, "autosize"),
      isComposing,
      focus,
      blur,
      select,
      clear,
      resizeTextarea
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", {
        class: vue.normalizeClass([containerKls.value, {
          [vue.unref(nsInput).bm("group", "append")]: _ctx.$slots.append,
          [vue.unref(nsInput).bm("group", "prepend")]: _ctx.$slots.prepend
        }]),
        style: vue.normalizeStyle(containerStyle.value),
        onMouseenter: handleMouseEnter,
        onMouseleave: handleMouseLeave
      }, [vue.createCommentVNode(" input "), __props.type !== "textarea" ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
        vue.createCommentVNode(" prepend slot "),
        _ctx.$slots.prepend ? (vue.openBlock(), vue.createElementBlock("div", {
          key: 0,
          class: vue.normalizeClass(vue.unref(nsInput).be("group", "prepend"))
        }, [vue.renderSlot(_ctx.$slots, "prepend")], 2)) : vue.createCommentVNode("v-if", true),
        vue.createElementVNode("div", {
          ref_key: "wrapperRef",
          ref: wrapperRef,
          class: vue.normalizeClass(wrapperKls.value)
        }, [
          vue.createCommentVNode(" prefix slot "),
          _ctx.$slots.prefix || __props.prefixIcon ? (vue.openBlock(), vue.createElementBlock("span", {
            key: 0,
            class: vue.normalizeClass(vue.unref(nsInput).e("prefix"))
          }, [vue.createElementVNode("span", { class: vue.normalizeClass(vue.unref(nsInput).e("prefix-inner")) }, [vue.renderSlot(_ctx.$slots, "prefix"), __props.prefixIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$6.ElIcon), {
            key: 0,
            class: vue.normalizeClass(vue.unref(nsInput).e("icon"))
          }, {
            default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.prefixIcon)))]),
            _: 1
          }, 8, ["class"])) : vue.createCommentVNode("v-if", true)], 2)], 2)) : vue.createCommentVNode("v-if", true),
          vue.createElementVNode("input", vue.mergeProps({
            id: vue.unref(inputId),
            ref_key: "input",
            ref: input2,
            class: vue.unref(nsInput).e("inner")
          }, vue.unref(attrs), {
            name: __props.name,
            minlength: __props.minlength,
            maxlength: __props.maxlength,
            type: __props.showPassword ? passwordVisible.value ? "text" : "password" : __props.type,
            disabled: vue.unref(inputDisabled),
            readonly: __props.readonly,
            autocomplete: __props.autocomplete,
            tabindex: __props.tabindex,
            "aria-label": __props.ariaLabel,
            placeholder: __props.placeholder,
            style: __props.inputStyle,
            form: __props.form,
            autofocus: __props.autofocus,
            role: __props.containerRole,
            inputmode: __props.inputmode,
            onCompositionstart: _cache[0] || (_cache[0] = (...args) => vue.unref(handleCompositionStart) && vue.unref(handleCompositionStart)(...args)),
            onCompositionupdate: _cache[1] || (_cache[1] = (...args) => vue.unref(handleCompositionUpdate) && vue.unref(handleCompositionUpdate)(...args)),
            onCompositionend: _cache[2] || (_cache[2] = (...args) => vue.unref(handleCompositionEnd) && vue.unref(handleCompositionEnd)(...args)),
            onInput: handleInput,
            onChange: handleChange,
            onKeydown: handleKeydown
          }), null, 16, _hoisted_1),
          vue.createCommentVNode(" suffix slot "),
          suffixVisible.value ? (vue.openBlock(), vue.createElementBlock("span", {
            key: 1,
            class: vue.normalizeClass(vue.unref(nsInput).e("suffix"))
          }, [vue.createElementVNode("span", { class: vue.normalizeClass(vue.unref(nsInput).e("suffix-inner")) }, [
            !showClear.value || !showPwdVisible.value || !isWordLimitVisible.value ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [vue.renderSlot(_ctx.$slots, "suffix"), __props.suffixIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$6.ElIcon), {
              key: 0,
              class: vue.normalizeClass(vue.unref(nsInput).e("icon"))
            }, {
              default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.suffixIcon)))]),
              _: 1
            }, 8, ["class"])) : vue.createCommentVNode("v-if", true)], 64)) : vue.createCommentVNode("v-if", true),
            showClear.value ? (vue.openBlock(), vue.createBlock(vue.unref(index$6.ElIcon), {
              key: 1,
              class: vue.normalizeClass([vue.unref(nsInput).e("icon"), vue.unref(nsInput).e("clear")]),
              onMousedown: vue.withModifiers(vue.unref(shared_esmBundler.NOOP), ["prevent"]),
              onClick: clear
            }, {
              default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.clearIcon)))]),
              _: 1
            }, 8, ["class", "onMousedown"])) : vue.createCommentVNode("v-if", true),
            showPwdVisible.value ? (vue.openBlock(), vue.createBlock(vue.unref(index$6.ElIcon), {
              key: 2,
              class: vue.normalizeClass([vue.unref(nsInput).e("icon"), vue.unref(nsInput).e("password")]),
              onClick: handlePasswordVisible,
              onMousedown: vue.withModifiers(vue.unref(shared_esmBundler.NOOP), ["prevent"]),
              onMouseup: vue.withModifiers(vue.unref(shared_esmBundler.NOOP), ["prevent"])
            }, {
              default: vue.withCtx(() => [vue.renderSlot(_ctx.$slots, "password-icon", { visible: passwordVisible.value }, () => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(passwordIcon.value)))])]),
              _: 3
            }, 8, [
              "class",
              "onMousedown",
              "onMouseup"
            ])) : vue.createCommentVNode("v-if", true),
            isWordLimitVisible.value ? (vue.openBlock(), vue.createElementBlock("span", {
              key: 3,
              class: vue.normalizeClass([vue.unref(nsInput).e("count"), vue.unref(nsInput).is("outside", __props.wordLimitPosition === "outside")])
            }, [vue.createElementVNode("span", { class: vue.normalizeClass(vue.unref(nsInput).e("count-inner")) }, vue.toDisplayString(textLength.value) + " / " + vue.toDisplayString(__props.maxlength), 3)], 2)) : vue.createCommentVNode("v-if", true),
            validateState.value && validateIcon.value && needStatusIcon.value ? (vue.openBlock(), vue.createBlock(vue.unref(index$6.ElIcon), {
              key: 4,
              class: vue.normalizeClass([
                vue.unref(nsInput).e("icon"),
                vue.unref(nsInput).e("validateIcon"),
                vue.unref(nsInput).is("loading", validateState.value === "validating")
              ])
            }, {
              default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(validateIcon.value)))]),
              _: 1
            }, 8, ["class"])) : vue.createCommentVNode("v-if", true)
          ], 2)], 2)) : vue.createCommentVNode("v-if", true)
        ], 2),
        vue.createCommentVNode(" append slot "),
        _ctx.$slots.append ? (vue.openBlock(), vue.createElementBlock("div", {
          key: 1,
          class: vue.normalizeClass(vue.unref(nsInput).be("group", "append"))
        }, [vue.renderSlot(_ctx.$slots, "append")], 2)) : vue.createCommentVNode("v-if", true)
      ], 64)) : (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [
        vue.createCommentVNode(" textarea "),
        vue.createElementVNode("textarea", vue.mergeProps({
          id: vue.unref(inputId),
          ref_key: "textarea",
          ref: textarea,
          class: [
            vue.unref(nsTextarea).e("inner"),
            vue.unref(nsInput).is("focus", vue.unref(isFocused)),
            vue.unref(nsTextarea).is("clearable", __props.clearable)
          ]
        }, vue.unref(attrs), {
          name: __props.name,
          minlength: __props.minlength,
          maxlength: __props.maxlength,
          tabindex: __props.tabindex,
          disabled: vue.unref(inputDisabled),
          readonly: __props.readonly,
          autocomplete: __props.autocomplete,
          style: textareaStyle.value,
          "aria-label": __props.ariaLabel,
          placeholder: __props.placeholder,
          form: __props.form,
          autofocus: __props.autofocus,
          rows: __props.rows,
          role: __props.containerRole,
          inputmode: __props.inputmode,
          onCompositionstart: _cache[3] || (_cache[3] = (...args) => vue.unref(handleCompositionStart) && vue.unref(handleCompositionStart)(...args)),
          onCompositionupdate: _cache[4] || (_cache[4] = (...args) => vue.unref(handleCompositionUpdate) && vue.unref(handleCompositionUpdate)(...args)),
          onCompositionend: _cache[5] || (_cache[5] = (...args) => vue.unref(handleCompositionEnd) && vue.unref(handleCompositionEnd)(...args)),
          onInput: handleInput,
          onFocus: _cache[6] || (_cache[6] = (...args) => vue.unref(handleFocus) && vue.unref(handleFocus)(...args)),
          onBlur: _cache[7] || (_cache[7] = (...args) => vue.unref(handleBlur) && vue.unref(handleBlur)(...args)),
          onChange: handleChange,
          onKeydown: handleKeydown
        }), null, 16, _hoisted_2),
        showClear.value ? (vue.openBlock(), vue.createBlock(vue.unref(index$6.ElIcon), {
          key: 0,
          class: vue.normalizeClass([vue.unref(nsTextarea).e("icon"), vue.unref(nsTextarea).e("clear")]),
          onMousedown: vue.withModifiers(vue.unref(shared_esmBundler.NOOP), ["prevent"]),
          onClick: clear
        }, {
          default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.clearIcon)))]),
          _: 1
        }, 8, ["class", "onMousedown"])) : vue.createCommentVNode("v-if", true),
        isWordLimitVisible.value ? (vue.openBlock(), vue.createElementBlock("span", {
          key: 1,
          style: vue.normalizeStyle(countStyle.value),
          class: vue.normalizeClass([vue.unref(nsInput).e("count"), vue.unref(nsInput).is("outside", __props.wordLimitPosition === "outside")])
        }, vue.toDisplayString(textLength.value) + " / " + vue.toDisplayString(__props.maxlength), 7)) : vue.createCommentVNode("v-if", true)
      ], 64))], 38);
    };
  }
});
exports.default = input_vue_vue_type_script_setup_true_lang_default;
