'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 FormItemContext = require('../form/FormItemContext.js');
require('../hooks/index.js');
var vnode = require('../_util/vnode.js');
var omit = require('../_util/omit.js');
var index$1 = require('../_util/vue-types/index.js');
var is = require('../_util/is.js');
var statusUtils = require('../_util/statusUtils.js');
var type = require('../_util/type.js');
var Compact = require('../space/Compact.js');
var DisabledContext = require('../config-provider/DisabledContext.js');
var index$2 = require('./style/index.js');
var InputNumber$1 = require('./src/InputNumber.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
const baseProps = InputNumber$1.inputNumberProps();
const inputNumberProps = () => ({
  ...baseProps,
  "size": type.stringType(),
  "bordered": type.booleanType(true),
  "placeholder": String,
  "name": String,
  "id": String,
  "type": String,
  "addonBefore": index$1.default.any,
  "addonAfter": index$1.default.any,
  "prefix": index$1.default.any,
  "onUpdate:value": baseProps.onChange,
  "valueModifiers": Object,
  "status": type.stringType()
});
const InputNumber = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AInputNumber",
  inheritAttrs: false,
  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
    } = Compact.useCompactItemContext(prefixCls, direction);
    const disabledContext = DisabledContext.useInjectDisabled();
    const mergedDisabled = vue.computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : disabledContext.value;
    });
    const [wrapSSR, hashId] = index$2.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 = classNames.default({
        [`${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(InputNumber$1.default, vue.mergeProps(omit.default(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(CloseOutlined.UpOutlined, {
          "class": `${preCls}-handler-up-inner`
        }, null),
        downHandler: slots.downIcon ? () => vue.createVNode("span", {
          "class": `${preCls}-handler-down-inner`
        }, [slots.downIcon()]) : () => vue.createVNode(CloseOutlined.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 = classNames.default(`${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,
          "onMouseup": () => inputNumberRef.value.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 = classNames.default(`${preCls}-wrapper`, wrapperClassName, {
          [`${wrapperClassName}-rtl`]: direction.value === "rtl"
        }, hashId.value);
        const mergedGroupClassName = classNames.default(`${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(Compact.NoCompactStyle, null, {
          default: () => [vue.createVNode(FormItemContext.NoFormStatus, null, _isSlot(addonBeforeNode) ? addonBeforeNode : {
            default: () => [addonBeforeNode]
          })]
        }), element, addonAfterNode && vue.createVNode(Compact.NoCompactStyle, null, {
          default: () => [vue.createVNode(FormItemContext.NoFormStatus, null, _isSlot(addonAfterNode) ? addonAfterNode : {
            default: () => [addonAfterNode]
          })]
        })])]);
      }
      return wrapSSR(vnode.cloneElement(element, {
        style
      }));
    };
  }
});
var index = Object.assign(InputNumber, {
  install: (app) => {
    app.component(InputNumber.name, InputNumber);
    return app;
  }
});

exports.default = index;
exports.inputNumberProps = inputNumberProps;
//# sourceMappingURL=index.js.map
