import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["prefixCls", "size", "class", "id"];
import { createVNode as _createVNode } from "vue";
import { defineComponent, inject, nextTick, onMounted, ref } from 'vue';
import PropTypes from '../_util/vue-types';
import { getOptionProps } from '../_util/props-util';
import classNames from '../_util/classNames';
import UpOutlined from '@ant-design/icons-vue/UpOutlined';
import DownOutlined from '@ant-design/icons-vue/DownOutlined';
import VcInputNumber from '../vc-input-number/src';
import { defaultConfigProvider } from '../config-provider';
import { tuple, withInstall } from '../_util/type';
import { useInjectFormItemContext } from '../form/FormItemContext';
var inputNumberProps = {
  prefixCls: PropTypes.string,
  min: PropTypes.number,
  max: PropTypes.number,
  value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
  step: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).def(1),
  defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
  tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
  disabled: PropTypes.looseBool,
  size: PropTypes.oneOf(tuple('large', 'small', 'default')),
  formatter: PropTypes.func,
  parser: PropTypes.func,
  decimalSeparator: PropTypes.string,
  placeholder: PropTypes.string,
  name: PropTypes.string,
  id: PropTypes.string,
  precision: PropTypes.number,
  autofocus: PropTypes.looseBool,
  onPressEnter: {
    type: Function
  },
  onChange: Function
};
var InputNumber = defineComponent({
  name: 'AInputNumber',
  inheritAttrs: false,
  props: inputNumberProps,
  emits: ['input', 'change', 'blur', 'update:value'],
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var formItemContext = useInjectFormItemContext();
    var inputNumberRef = ref(null);

    var focus = function focus() {
      inputNumberRef.value.focus();
    };

    var blur = function blur() {
      inputNumberRef.value.blur();
    };

    var handleChange = function handleChange(val) {
      emit('update:value', val);
      emit('change', val);
    };

    var handleBlur = function handleBlur() {
      emit('blur');
    };

    onMounted(function () {
      nextTick(function () {
        if (process.env.NODE_ENV === 'test') {
          if (props.autofocus && !props.disabled) {
            focus();
          }
        }
      });
    });
    return {
      configProvider: inject('configProvider', defaultConfigProvider),
      inputNumberRef: inputNumberRef,
      focus: focus,
      blur: blur,
      formItemContext: formItemContext,
      handleBlur: handleBlur,
      handleChange: handleChange
    };
  },
  render: function render() {
    var _classNames;

    var _ref2 = _objectSpread(_objectSpread({}, getOptionProps(this)), this.$attrs),
        customizePrefixCls = _ref2.prefixCls,
        size = _ref2.size,
        className = _ref2.class,
        _ref2$id = _ref2.id,
        id = _ref2$id === void 0 ? this.formItemContext.id.value : _ref2$id,
        others = _objectWithoutProperties(_ref2, _excluded);

    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('input-number', customizePrefixCls);
    var inputNumberClass = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-lg"), size === 'large'), _defineProperty(_classNames, "".concat(prefixCls, "-sm"), size === 'small'), _classNames), className);

    var upIcon = _createVNode(UpOutlined, {
      "class": "".concat(prefixCls, "-handler-up-inner")
    }, null);

    var downIcon = _createVNode(DownOutlined, {
      "class": "".concat(prefixCls, "-handler-down-inner")
    }, null);

    var vcInputNumberProps = _objectSpread(_objectSpread({
      prefixCls: prefixCls,
      upHandler: upIcon,
      downHandler: downIcon
    }, others), {}, {
      class: inputNumberClass,
      onChange: this.handleChange,
      onBlur: this.handleBlur,
      id: id
    });

    return _createVNode(VcInputNumber, _objectSpread(_objectSpread({}, vcInputNumberProps), {}, {
      "ref": "inputNumberRef"
    }), null);
  }
});
export default withInstall(InputNumber);