'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/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 InputElement = require('./InputElement.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 _class = require('../../../utils/dom/class.cjs');
var omit = require('../../../utils/lang/omit.cjs');
var is = require('../../../utils/is.cjs');
var NoCompactStyle = require('../../space/src/NoCompactStyle.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');

var AInputNumber = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInputNumber",
  inheritAttrs: false,
  props: props.inputNumberProps(),
  // emits: ['focus', 'blur', 'change', 'input', 'update:value'],
  slots: Object,
  setup(props, {
    emit,
    expose,
    attrs,
    slots
  }) {
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
    const mergedStatus = vue.computed(() => statusUtils.getMergedStatus(formItemInputContext.status, props.status));
    const {
      prefixCls,
      size,
      direction,
      disabled
    } = useConfigInject.default("input-number", props);
    const {
      compactSize,
      compactItemClassnames
    } = context.useCompactItemContext(prefixCls, direction);
    const disabledContext$1 = disabledContext.useInjectDisabled();
    const mergedDisabled = vue.computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : disabledContext$1.value;
    });
    const [wrapSSR, hashId] = index.default(prefixCls);
    const mergedSize = vue.computed(() => compactSize.value || size.value);
    const mergedValue = vue.shallowRef(props.value === void 0 ? props.defaultValue : props.value);
    const focused = vue.shallowRef(false);
    vue.watch(() => props.value, () => {
      mergedValue.value = props.value;
    });
    const inputNumberRef = vue.shallowRef(null);
    const focus = () => {
      var _a;
      (_a = inputNumberRef.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      (_a = inputNumberRef.value) == null ? void 0 : _a.blur();
    };
    expose({
      focus,
      blur
    });
    const handleChange = (val) => {
      if (props.value === void 0)
        mergedValue.value = val;
      emit("update:value", val);
      emit("change", val);
      formItemContext.onFieldChange();
    };
    const handleBlur = (e) => {
      focused.value = false;
      emit("blur", e);
      formItemContext.onFieldBlur();
    };
    const handleFocus = (e) => {
      focused.value = true;
      emit("focus", e);
    };
    return () => {
      var _a, _b, _c, _d;
      const {
        hasFeedback,
        isFormItemInput,
        feedbackIcon
      } = formItemInputContext;
      const id = (_a = props.id) != null ? _a : formItemContext.id.value;
      const {
        class: className,
        bordered,
        readonly,
        style,
        addonBefore = (_b = slots.addonBefore) == null ? void 0 : _b.call(slots),
        addonAfter = (_c = slots.addonAfter) == null ? void 0 : _c.call(slots),
        prefix = (_d = slots.prefix) == null ? void 0 : _d.call(slots),
        valueModifiers = {},
        ...others
      } = {
        ...attrs,
        ...props,
        id,
        disabled: mergedDisabled.value
      };
      const preCls = prefixCls.value;
      const inputNumberClass = _class.classNames({
        [`${preCls}-lg`]: mergedSize.value === "large",
        [`${preCls}-sm`]: mergedSize.value === "small",
        [`${preCls}-rtl`]: direction.value === "rtl",
        [`${preCls}-readonly`]: readonly,
        [`${preCls}-borderless`]: !bordered,
        [`${preCls}-in-form-item`]: isFormItemInput
      }, statusUtils.getStatusClassNames(preCls, mergedStatus.value), className, compactItemClassnames.value, hashId.value);
      let element = vue.createVNode(InputElement.default, {
        ...omit.omit(others, ["size", "defaultValue"]),
        "ref": inputNumberRef,
        "lazy": !!valueModifiers.lazy,
        "value": mergedValue.value,
        "class": inputNumberClass,
        "prefixCls": preCls,
        "readonly": readonly,
        "onChange": handleChange,
        "onBlur": handleBlur,
        "onFocus": handleFocus
      }, {
        upHandler: slots.upIcon ? () => vue.createVNode("span", {
          "class": `${preCls}-handler-up-inner`
        }, [slots.upIcon()]) : () => vue.createVNode(iconsVue.UpOutlined, {
          "class": `${preCls}-handler-up-inner`
        }, null),
        downHandler: slots.downIcon ? () => vue.createVNode("span", {
          "class": `${preCls}-handler-down-inner`
        }, [slots.downIcon()]) : () => vue.createVNode(iconsVue.DownOutlined, {
          "class": `${preCls}-handler-down-inner`
        }, null)
      });
      const hasAddon = is.isValidValue(addonBefore) || is.isValidValue(addonAfter);
      const hasPrefix = is.isValidValue(prefix);
      if (hasPrefix || hasFeedback) {
        const affixWrapperCls = _class.classNames(`${preCls}-affix-wrapper`, statusUtils.getStatusClassNames(`${preCls}-affix-wrapper`, mergedStatus.value, hasFeedback), {
          [`${preCls}-affix-wrapper-focused`]: focused.value,
          [`${preCls}-affix-wrapper-disabled`]: mergedDisabled.value,
          [`${preCls}-affix-wrapper-sm`]: mergedSize.value === "small",
          [`${preCls}-affix-wrapper-lg`]: mergedSize.value === "large",
          [`${preCls}-affix-wrapper-rtl`]: direction.value === "rtl",
          [`${preCls}-affix-wrapper-readonly`]: readonly,
          [`${preCls}-affix-wrapper-borderless`]: !bordered,
          // className will go to addon wrapper
          [`${className}`]: !hasAddon && className
        }, hashId.value);
        element = vue.createVNode("div", {
          "class": affixWrapperCls,
          "style": style,
          "onClick": focus
        }, [hasPrefix && vue.createVNode("span", {
          "class": `${preCls}-prefix`
        }, [prefix]), element, hasFeedback && vue.createVNode("span", {
          "class": `${preCls}-suffix`
        }, [feedbackIcon])]);
      }
      if (hasAddon) {
        const wrapperClassName = `${preCls}-group`;
        const addonClassName = `${wrapperClassName}-addon`;
        const addonBeforeNode = addonBefore ? vue.createVNode("div", {
          "class": addonClassName
        }, [addonBefore]) : null;
        const addonAfterNode = addonAfter ? vue.createVNode("div", {
          "class": addonClassName
        }, [addonAfter]) : null;
        const mergedWrapperClassName = _class.classNames(`${preCls}-wrapper`, wrapperClassName, {
          [`${wrapperClassName}-rtl`]: direction.value === "rtl"
        }, hashId.value);
        const mergedGroupClassName = _class.classNames(`${preCls}-group-wrapper`, {
          [`${preCls}-group-wrapper-sm`]: mergedSize.value === "small",
          [`${preCls}-group-wrapper-lg`]: mergedSize.value === "large",
          [`${preCls}-group-wrapper-rtl`]: direction.value === "rtl"
        }, statusUtils.getStatusClassNames(`${prefixCls}-group-wrapper`, mergedStatus.value, hasFeedback), className, hashId.value);
        element = vue.createVNode("div", {
          "class": mergedGroupClassName,
          "style": style
        }, [vue.createVNode("div", {
          "class": mergedWrapperClassName
        }, [addonBeforeNode && vue.createVNode(NoCompactStyle.NoCompactStyle, null, {
          default: () => [vue.createVNode(FormItemContext.NoFormStatus, null, {
            default: () => [addonBeforeNode]
          })]
        }), element, addonAfterNode && vue.createVNode(NoCompactStyle.NoCompactStyle, null, {
          default: () => [vue.createVNode(FormItemContext.NoFormStatus, null, {
            default: () => [addonAfterNode]
          })]
        })])]);
      }
      return wrapSSR(vnode.cloneElement(element, {
        style
      }));
    };
  }
});

exports.default = AInputNumber;
//# sourceMappingURL=InputNumber.cjs.map
