/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var isObjectLikeC22c7e3b = require('../../../chunks/isObjectLike-c22c7e3b.js');
var isArrayCd7357b9 = require('../../../chunks/isArray-cd7357b9.js');
var isNumberC4eb560e = require('../../../chunks/isNumber-c4eb560e.js');
var log = require('../../../chunks/log.js');
var hooks_useCommonClassname = require('../../../hooks/use-common-classname.js');
var hooks_useVmodel = require('../../../hooks/use-vmodel.js');
var hooks_useFormDisabled = require('../../../hooks/use-form-disabled.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash');
require('../../../chunks/zh_CN.js');
require('lodash/kebabCase');

function fillZero(length) {
  return new Array(length).fill(0).join("");
}
function isInputNumber(num) {
  if (!num) return true;
  if (typeof num === "number") return Number.isNaN(num);
  var r = /^[0-9|e|E|-]+\.*[0-9|e|E|-]*$/.test(num);
  if (!r) return false;
  var eCount = 0;
  var negativeCount = 0;
  var dotCount = 0;
  for (var i = 0, len = num.length; i < len; i++) {
    if (num[i] === ".") {
      dotCount += 1;
      if (dotCount > 1) return false;
    }
    if (/(e|E)+/.test(num[i])) {
      eCount += 1;
      if (eCount > 1) return false;
    }
    if (num[i] === "-") {
      negativeCount += 1;
      if (negativeCount > 2) return false;
    }
  }
  return true;
}
function removeInvalidZero(num) {
  var decimal = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  if (num.includes(".")) {
    log.log.error("InputNumber", "num is not a integer number.");
    return num;
  }
  if (!num || num === "0" && decimal) return "";
  if (num === "0") return num;
  return (decimal ? num.replace(/0+$/, "") : num.replace(/^0+/, "")) || "0";
}
function largeIntNumberAdd(num1, num2) {
  var decimal = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
  var number1 = removeInvalidZero(num1, decimal);
  var number2 = removeInvalidZero(num2, decimal);
  var isFirstLarger = number1.length > number2.length;
  var maxNumber = isFirstLarger ? number1 : number2;
  var minNumber = isFirstLarger ? number2 : number1;
  var newNumber = [];
  var step = [];
  var diff = decimal ? 0 : maxNumber.length - minNumber.length;
  var len = decimal ? minNumber.length : maxNumber.length;
  for (var i = len - 1; i >= 0; i--) {
    var minIndex = i - diff;
    var count = Number(maxNumber[i]) + (Number(minNumber[minIndex]) || 0) + (step[i] || 0);
    if (count >= 10) step[i - 1] = 1;
    newNumber.unshift(String(count % 10));
  }
  if (step[-1]) newNumber.unshift("1");
  if (decimal) return newNumber.concat(maxNumber.slice(len, maxNumber.length)).join("");
  return newNumber.join("");
}
function largePositiveNumberAdd(num1, num2) {
  var [intNumber1 = "0", decimalNumber1 = "0"] = num1.split(".");
  var [intNumber2 = "0", decimalNumber2 = "0"] = num2.split(".");
  var integerSum = largeIntNumberAdd(intNumber1, intNumber2);
  if (decimalNumber1 === "0" && decimalNumber2 === "0") return integerSum;
  var newDecimalNumber1 = removeInvalidZero(decimalNumber1, true);
  var newDecimalNumber2 = removeInvalidZero(decimalNumber2, true);
  var decimalNumberSum = largeIntNumberAdd(newDecimalNumber1, newDecimalNumber2, true);
  var decimalLength = decimalNumberSum.length;
  if (decimalLength > newDecimalNumber1.length && decimalLength > newDecimalNumber2.length) {
    return [removeInvalidZero(largeIntNumberAdd(integerSum, "1")), removeInvalidZero(decimalNumberSum.slice(1), true)].filter(v => v).join(".");
  }
  return [removeInvalidZero(integerSum), removeInvalidZero(decimalNumberSum, true)].filter(v => v).join(".");
}
function compareLargeIntegerNumber(num1, num2) {
  var number1 = removeInvalidZero(num1);
  var number2 = removeInvalidZero(num2);
  if (number1.length === number2.length) {
    for (var i = 0, len = number1.length; i < len; i++) {
      if (number1[i] > number2[i]) return 1;
      if (number1[i] < number2[i]) return -1;
    }
    return 0;
  }
  return number1.length > number2.length ? 1 : -1;
}
function compareLargeDecimalNumber(num1, num2) {
  var number1 = num1 && num1 !== "0" ? num1.replace(/0+$/, "") : "0";
  var number2 = num2 && num2 !== "0" ? num2.replace(/0+$/, "") : "0";
  var maxLength = Math.max(number1.length, number2.length);
  for (var i = 0, len = maxLength; i < len; i++) {
    if ((number1[i] || 0) > (number2[i] || 0)) return 1;
    if ((number1[i] || 0) < (number2[i] || 0)) return -1;
  }
  return 0;
}
function compareLargeNumber(num1, num2) {
  var [integer1, decimal1] = num1.split(".");
  var [integer2, decimal2] = num2.split(".");
  var result = compareLargeIntegerNumber(integer1.replace("-", ""), integer2.replace("-", ""));
  var integer1IsNegative = integer1.includes("-");
  var integer2IsNegative = integer2.includes("-");
  if (integer1IsNegative && !integer2IsNegative) return -1;
  if (!integer1IsNegative && integer2IsNegative) return 1;
  if (integer1IsNegative && integer2IsNegative) {
    if (result === 0) return 0;
    return result > 0 ? -1 : 1;
  }
  if (result === 0) return compareLargeDecimalNumber(decimal1, decimal2);
  return result;
}
function isInfinity(num) {
  return [-Infinity, Infinity].includes(Number(num));
}
function isSafeNumber(num) {
  return Number(num) < Number.MAX_SAFE_INTEGER && Number(num) > Number.MIN_SAFE_INTEGER;
}
function compareNumber(num1, num2, largeNumber) {
  var isSafeNumberCompare = isSafeNumber(num1) && isSafeNumber(num2) && !largeNumber;
  var isInfinityCompare = isInfinity(num1) || isInfinity(num2);
  if (isSafeNumberCompare || isInfinityCompare) {
    if (Number(num1) === Number(num2)) return 0;
    return Number(num1) > Number(num2) ? 1 : -1;
  }
  return compareLargeNumber(String(num1), String(num2));
}
function largeIntegerNumberSubtract(num1, num2, p) {
  if (num1 === num2) return "0";
  var {
    decimal,
    stayZero
  } = p || {};
  var number1 = removeInvalidZero(num1);
  var number2 = removeInvalidZero(num2);
  var isFirstLarger = compareLargeIntegerNumber(number1, number2) > 0;
  var maxNumber = isFirstLarger ? number1 : number2;
  var minNumber = isFirstLarger ? number2 : number1;
  var newNumber = [];
  var step = [];
  var diff = decimal ? 0 : maxNumber.length - minNumber.length;
  var len = decimal ? minNumber.length : maxNumber.length;
  for (var i = len - 1; i >= 0; i--) {
    var minIndex = i - diff;
    var count = Number(maxNumber[i]) - (Number(minNumber[minIndex]) || 0) - (step[i] || 0);
    if (count < 0) {
      step[i - 1] = 1;
      count += 10;
    }
    newNumber.unshift(String(count));
  }
  if (decimal) return newNumber.concat(maxNumber.slice(len, maxNumber.length)).join("");
  var finalNumber = newNumber.join("");
  if (!stayZero) finalNumber = finalNumber.replace(/^0+/, "");
  return removeInvalidZero(isFirstLarger ? finalNumber : "-".concat(finalNumber));
}
function largePositiveNumberSubtract(num1, num2) {
  if (num1 === num2) return "0";
  var isFirstLarger = compareNumber(num1, num2, true) > 0;
  var maxNumber = isFirstLarger ? num1 : num2;
  var minNumber = isFirstLarger ? num2 : num1;
  var [intNumber1, decimalNumber1 = "0"] = maxNumber.split(".");
  var [intNumber2, decimalNumber2 = "0"] = minNumber.split(".");
  var integerNumber = largeIntegerNumberSubtract(intNumber1, intNumber2);
  if (decimalNumber1 === "0" && decimalNumber2 === "0") return isFirstLarger ? integerNumber : "-".concat(integerNumber);
  var decimalNumber = "";
  var addOneNumber = decimalNumber1;
  if (decimalNumber1.length < decimalNumber2.length) addOneNumber = "".concat(decimalNumber1).concat(fillZero(decimalNumber2.length - decimalNumber1.length));
  if (compareLargeDecimalNumber(addOneNumber, decimalNumber2) >= 0) {
    decimalNumber = largeIntegerNumberSubtract(addOneNumber, decimalNumber2, {
      decimal: true
    });
  } else {
    if (decimalNumber1.length < decimalNumber2.length || decimalNumber1 === "0") {
      decimalNumber = largeIntegerNumberSubtract("1".concat(addOneNumber), decimalNumber2, {
        stayZero: true
      });
      decimalNumber = fillZero(decimalNumber2.length - decimalNumber.length) + decimalNumber;
    } else {
      decimalNumber = largeIntegerNumberSubtract(decimalNumber1, decimalNumber2, {
        decimal: true
      });
    }
    integerNumber = largeIntegerNumberSubtract(integerNumber, "1");
  }
  var finalNumber = decimalNumber ? [integerNumber, decimalNumber].join(".") : integerNumber;
  return isFirstLarger ? finalNumber : "-".concat(finalNumber);
}
function largeNumberSubtract(num1, num2) {
  var isFirstNegative = num1[0] === "-";
  var isSecondNegative = num2[0] === "-";
  if (isFirstNegative && !isSecondNegative) {
    var r = largePositiveNumberAdd(num1.slice(1), num2);
    return "-".concat(r);
  }
  if (isFirstNegative && isSecondNegative) return largePositiveNumberSubtract(num2.slice(1), num1.slice(1));
  if (!isFirstNegative && isSecondNegative) return largePositiveNumberAdd(num1, num2.slice(1));
  return largePositiveNumberSubtract(num1, num2);
}
function largeNumberAdd(num1, num2) {
  var isFirstNegative = num1[0] === "-";
  var isSecondNegative = num2[0] === "-";
  if (isFirstNegative && !isSecondNegative) return largePositiveNumberSubtract(num2, num1.slice(1));
  if (isFirstNegative && isSecondNegative) {
    var r = largePositiveNumberAdd(num2.slice(1), num1.slice(1));
    return "-".concat(r);
  }
  if (!isFirstNegative && isSecondNegative) return largePositiveNumberSubtract(num1, num2.slice(1));
  return largePositiveNumberAdd(num1, num2);
}
function largeNumberToFixed(number) {
  var decimalPlaces = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
  var largeNumber = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
  if (!largeNumber) return Number(number).toFixed(decimalPlaces);
  if (typeof number !== "string") return String(number);
  var [num1, num2] = number.split(".");
  if (!num2) return decimalPlaces ? [number, fillZero(decimalPlaces)].join(".") : number;
  if (decimalPlaces === 0) return Number(num2[0]) >= 5 ? largePositiveNumberAdd(num1, "1") : num1;
  var decimalNumber = num2.slice(0, decimalPlaces);
  if (num2.length < decimalPlaces) {
    decimalNumber += fillZero(decimalPlaces - num2.length);
  } else {
    decimalNumber = Number(num2[decimalPlaces]) >= 5 ? largePositiveNumberAdd(decimalNumber, "1") : decimalNumber;
  }
  return [num1, decimalNumber].join(".");
}
function formatENumber(num) {
  var [num1, num2] = num.split("e");
  var [integer, initDecimal = ""] = num.split(".");
  var zeroCount = Number(num2);
  var [decimal] = initDecimal.split("e");
  if (zeroCount > decimal.length) {
    var multipleZero = fillZero(zeroCount - decimal.length);
    return num1.replace(/(^0+|\.)/g, "") + multipleZero;
  }
  var n1 = integer.replace(/^0+/, "") + decimal.slice(0, zeroCount);
  var d2 = decimal.slice(zeroCount);
  return d2 ? [n1, d2].join(".") : n1;
}

var baseGetTag = isObjectLikeC22c7e3b._baseGetTag,
  isArray = isArrayCd7357b9.isArray_1,
  isObjectLike = isObjectLikeC22c7e3b.isObjectLike_1;
var stringTag = "[object String]";
function isString(value) {
  return typeof value == "string" || !isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag;
}
var isString_1 = isString;
function canAddNumber(num, max) {
  var largeNumber = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
  if (!num && num !== 0) return true;
  if (largeNumber && isString_1(num)) return compareNumber(num, max, largeNumber) < 0;
  return num < max;
}
function canReduceNumber(num, min) {
  var largeNumber = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
  if (!num && num !== 0) return true;
  if (largeNumber && isString_1(num)) return compareNumber(num, min, largeNumber) > 0;
  return num > min;
}
function formatToNumber(num, extra) {
  if (num === void 0 || num === null || num === "") return num;
  if (num === "-") return 0;
  if (num[num.length - 1] === ".") return num.slice(0, -1);
  var isLargeNumber = (extra === null || extra === void 0 ? void 0 : extra.largeNumber) && isString_1(num);
  var newNumber = num;
  if (isString_1(num) && num.includes("e") || isNumberC4eb560e.isNumber_1(num)) newNumber = isLargeNumber ? formatENumber(num) : Number(num);
  if ((extra === null || extra === void 0 ? void 0 : extra.decimalPlaces) !== void 0) {
    newNumber = largeNumberToFixed(newNumber, extra.decimalPlaces, extra.largeNumber);
  }
  var val = isLargeNumber || (extra === null || extra === void 0 ? void 0 : extra.decimalPlaces) !== void 0 ? newNumber : Number(newNumber);
  if (String(val) === "NaN") return void 0;
  return val;
}
function putInRangeNumber(val, params) {
  if (val === "") return void 0;
  var {
    max,
    min,
    lastValue,
    largeNumber
  } = params;
  if (!isInputNumber(val)) return lastValue;
  if (largeNumber && (isString_1(max) || max === Infinity) && (isString_1(min) || min === -Infinity)) {
    if (compareNumber(max, val, largeNumber) < 0) return max;
    if (compareNumber(min, val, largeNumber) > 0) return min;
    return val;
  }
  return Math.max(Number(min), Math.min(Number(max), Number(val)));
}
function positiveAdd(num1, num2) {
  var _num1$toString$split$, _num2$toString$split$;
  if (!num1 || !num2) return (num1 || 0) + (num2 || 0);
  var r1 = ((_num1$toString$split$ = num1.toString().split(".")[1]) === null || _num1$toString$split$ === void 0 ? void 0 : _num1$toString$split$.length) || 0;
  var r2 = ((_num2$toString$split$ = num2.toString().split(".")[1]) === null || _num2$toString$split$ === void 0 ? void 0 : _num2$toString$split$.length) || 0;
  if (!r1 || !r2) return num1 + num2;
  var newNumber1 = num1;
  var newNumber2 = num2;
  var diff = Math.abs(r1 - r2);
  var digit = 10 ** Math.max(r1, r2);
  if (diff > 0) {
    var cm = 10 ** diff;
    if (r1 > r2) {
      newNumber1 = Number(num1.toString().replace(".", ""));
      newNumber2 = Number(num2.toString().replace(".", "")) * cm;
    } else {
      newNumber1 = Number(num1.toString().replace(".", "")) * cm;
      newNumber2 = Number(num2.toString().replace(".", ""));
    }
  } else {
    newNumber1 = Number(num1.toString().replace(".", ""));
    newNumber2 = Number(num2.toString().replace(".", ""));
  }
  return (newNumber1 + newNumber2) / digit;
}
function positiveSubtract(num1, num2) {
  var _num1$toString$split$2, _num2$toString$split$2;
  if (!num1 || !num2) return (num1 || 0) - (num2 || 0);
  var r1 = ((_num1$toString$split$2 = num1.toString().split(".")[1]) === null || _num1$toString$split$2 === void 0 ? void 0 : _num1$toString$split$2.length) || 0;
  var r2 = ((_num2$toString$split$2 = num2.toString().split(".")[1]) === null || _num2$toString$split$2 === void 0 ? void 0 : _num2$toString$split$2.length) || 0;
  var digit = 10 ** Math.max(r1, r2);
  var n = r1 >= r2 ? r1 : r2;
  return Number(((num1 * digit - num2 * digit) / digit).toFixed(n));
}
function add(num1, num2) {
  if (num1 < 0 && num2 > 0) return positiveSubtract(num2, Math.abs(num1));
  if (num1 < 0 && num2 < 0) return positiveAdd(Math.abs(num1), Math.abs(num2)) * -1;
  if (num1 > 0 && num2 < 0) return positiveSubtract(num1, Math.abs(num2));
  return positiveAdd(num1, num2);
}
function subtract(num1, num2) {
  if (num1 < 0 && num2 > 0) return positiveAdd(Math.abs(num1), num2) * -1;
  if (num1 < 0 && num2 < 0) return positiveSubtract(Math.abs(num2), Math.abs(num1));
  if (num1 > 0 && num2 < 0) return positiveAdd(num1, Math.abs(num2));
  return positiveSubtract(num1, num2);
}
function getStepValue(p) {
  var {
    op,
    step,
    lastValue = 0,
    max,
    min,
    largeNumber
  } = p;
  if (step <= 0) {
    log.log.error("InputNumber", "step must be larger than 0.");
    return lastValue;
  }
  var tStep = isNumberC4eb560e.isNumber_1(step) ? String(step) : step;
  var newVal;
  if (op === "add") {
    if (largeNumber && isString_1(lastValue)) newVal = largeNumberAdd(String(lastValue), String(tStep));else newVal = add(Number(lastValue || 0), Number(step));
  } else if (op === "reduce") {
    if (largeNumber && isString_1(lastValue)) newVal = largeNumberSubtract(String(lastValue), String(tStep));else newVal = subtract(Number(lastValue || 0), Number(step));
  }
  if (lastValue === void 0) newVal = putInRangeNumber(newVal, {
    max,
    min,
    lastValue,
    largeNumber
  });
  return largeNumber ? newVal : Number(newVal);
}
function getMaxOrMinValidateResult(p) {
  var {
    largeNumber,
    value,
    max,
    min
  } = p;
  if (largeNumber === void 0) return void 0;
  if (largeNumber && isNumberC4eb560e.isNumber_1(value)) log.log.warn("InputNumber", "largeNumber value must be a string.");
  var error;
  if (compareNumber(value, max, largeNumber) > 0) error = "exceed-maximum";else if (compareNumber(value, min, largeNumber) < 0) error = "below-minimum";else error = void 0;
  return error;
}
function canInputNumber(number, largeNumber) {
  if (!number && typeof number === "string") return true;
  var isNumber2 = largeNumber && isInputNumber(number) || !Number.isNaN(Number(number));
  if (!isNumber2 && !["-", ".", "e", "E"].includes(number.slice(-1))) return false;
  return true;
}

function useInputNumber(props, context) {
  const {
    classPrefix,
    sizeClassNames,
    statusClassNames
  } = hooks_useCommonClassname["default"]();
  const {
    value,
    max,
    min
  } = VueCompositionAPI.toRefs(props);
  const [tValue, setTValue] = hooks_useVmodel["default"](value, props.defaultValue, props.onChange, "change");
  const inputRef = VueCompositionAPI.ref();
  const userInput = VueCompositionAPI.ref("");
  const displayValue = VueCompositionAPI.ref();
  const {
    formDisabled
  } = hooks_useFormDisabled["default"]();
  const tDisabled = VueCompositionAPI.computed(() => props.disabled || formDisabled.value);
  const isError = VueCompositionAPI.ref();
  const disabledReduce = VueCompositionAPI.computed(() => tDisabled.value || !canReduceNumber(tValue.value, props.min, props.largeNumber));
  const disabledAdd = VueCompositionAPI.computed(() => tDisabled.value || !canAddNumber(tValue.value, props.max, props.largeNumber));
  const wrapClasses = VueCompositionAPI.computed(() => [`${classPrefix.value}-input-number`, sizeClassNames[props.size], {
    [statusClassNames.disabled]: tDisabled.value,
    [`${classPrefix.value}-is-controls-right`]: props.theme === "column",
    [`${classPrefix.value}-input-number--${props.theme}`]: props.theme,
    [`${classPrefix.value}-input-number--auto-width`]: props.autoWidth
  }]);
  const reduceClasses = VueCompositionAPI.computed(() => [`${classPrefix.value}-input-number__decrease`, {
    [statusClassNames.disabled]: disabledReduce.value
  }]);
  const addClasses = VueCompositionAPI.computed(() => [`${classPrefix.value}-input-number__increase`, {
    [statusClassNames.disabled]: disabledAdd.value
  }]);
  const getUserInput = value2 => {
    var _inputRef$value, _inputRef$value$$el;
    if (!value2 && value2 !== 0) return "";
    let inputStr = value2 || value2 === 0 ? String(value2) : "";
    if (!((_inputRef$value = inputRef.value) !== null && _inputRef$value !== void 0 && (_inputRef$value$$el = _inputRef$value.$el) !== null && _inputRef$value$$el !== void 0 && _inputRef$value$$el.contains(document.activeElement))) {
      const num = formatToNumber(inputStr, {
        decimalPlaces: props.decimalPlaces,
        largeNumber: props.largeNumber
      });
      inputStr = num || num === 0 ? String(num) : "";
      if (props.format) inputStr = String(props.format(value2, {
        fixedNumber: inputStr
      }));
    }
    return inputStr;
  };
  VueCompositionAPI.watch(tValue, val => {
    const inputValue = [void 0, null].includes(val) ? "" : String(val);
    userInput.value = getUserInput(inputValue);
  }, {
    immediate: true
  });
  VueCompositionAPI.onMounted(() => {
    userInput.value = getUserInput(tValue.value);
  });
  VueCompositionAPI.watch([tValue, max, min], () => {
    var _props$onValidate;
    if ([void 0, "", null].includes(tValue.value)) return;
    const error = getMaxOrMinValidateResult({
      value: tValue.value,
      largeNumber: props.largeNumber,
      max: props.max,
      min: props.min
    });
    isError.value = error;
    (_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 ? void 0 : _props$onValidate.call(props, {
      error
    });
    context.emit("validate", {
      error
    });
  }, {
    immediate: true
  });
  const handleStepValue = op => getStepValue({
    op,
    step: props.step,
    max: props.max,
    min: props.min,
    lastValue: tValue.value,
    largeNumber: props.largeNumber
  });
  const handleReduce = e => {
    if (disabledReduce.value || props.readonly) return;
    const newValue = handleStepValue("reduce");
    setTValue(newValue, {
      type: "reduce",
      e
    });
  };
  const handleAdd = e => {
    if (disabledAdd.value || props.readonly) return;
    const newValue = handleStepValue("add");
    setTValue(newValue, {
      type: "add",
      e
    });
  };
  const onInnerInputChange = (val, ctx) => {
    if (!canInputNumber(val, props.largeNumber)) return;
    userInput.value = val;
    const isDelete = ctx.e.inputType === "deleteContentBackward";
    const newVal = isDelete || props.largeNumber || !val ? val : Number(val);
    if (newVal !== tValue.value && !["-", ".", "e", "E"].includes(val.slice(-1))) setTValue(newVal, {
      type: "input",
      e: ctx.e
    });
  };
  const handleBlur = (value2, ctx) => {
    var _props$onBlur;
    userInput.value = getUserInput(tValue.value);
    const newValue = formatToNumber(value2, {
      decimalPlaces: props.decimalPlaces,
      largeNumber: props.largeNumber
    });
    if (newValue !== value2 && String(newValue) !== value2) setTValue(newValue, {
      type: "blur",
      e: ctx.e
    });
    (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 ? void 0 : _props$onBlur.call(props, newValue, ctx);
    context.emit("blur", newValue, ctx);
  };
  const handleFocus = (value2, ctx) => {
    var _props$onFocus;
    userInput.value = tValue.value || tValue.value === 0 ? String(tValue.value) : "";
    (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, value2, ctx);
    context.emit("focus", value2, ctx);
  };
  const handleKeydown = (value2, ctx) => {
    var _props$onKeydown;
    const {
      e
    } = ctx;
    const keyEvent = {
      ArrowUp: handleAdd,
      ArrowDown: handleReduce
    };
    const code = e.code || e.key;
    if (keyEvent[code] !== void 0) keyEvent[code](e);
    (_props$onKeydown = props.onKeydown) === null || _props$onKeydown === void 0 ? void 0 : _props$onKeydown.call(props, value2, ctx);
    context.emit("keydown", value2, ctx);
  };
  const handleKeyup = (value2, ctx) => {
    var _props$onKeyup;
    (_props$onKeyup = props.onKeyup) === null || _props$onKeyup === void 0 ? void 0 : _props$onKeyup.call(props, value2, ctx);
    context.emit("keyup", value2, ctx);
  };
  const handleKeypress = (value2, ctx) => {
    var _props$onKeypress;
    (_props$onKeypress = props.onKeypress) === null || _props$onKeypress === void 0 ? void 0 : _props$onKeypress.call(props, value2, ctx);
    context.emit("keypress", value2, ctx);
  };
  const handleEnter = (value2, ctx) => {
    var _props$onEnter;
    userInput.value = getUserInput(value2);
    const newValue = formatToNumber(value2, {
      decimalPlaces: props.decimalPlaces,
      largeNumber: props.largeNumber
    });
    if (newValue !== value2 && String(newValue) !== value2) setTValue(newValue, {
      type: "enter",
      e: ctx.e
    });
    (_props$onEnter = props.onEnter) === null || _props$onEnter === void 0 ? void 0 : _props$onEnter.call(props, newValue, ctx);
    context.emit("enter", newValue, ctx);
  };
  const focus = () => {
    inputRef.value.focus();
  };
  const blur = () => {
    inputRef.value.blur();
  };
  const listeners = {
    blur: handleBlur,
    focus: handleFocus,
    keydown: handleKeydown,
    keyup: handleKeyup,
    keypress: handleKeypress,
    enter: handleEnter,
    click: focus
  };
  return {
    classPrefix,
    wrapClasses,
    reduceClasses,
    addClasses,
    displayValue,
    tDisabled,
    isError,
    listeners,
    userInput,
    tValue,
    inputRef,
    formDisabled,
    focus,
    blur,
    handleReduce,
    handleAdd,
    onInnerInputChange
  };
}

exports["default"] = useInputNumber;
//# sourceMappingURL=use-input-number.js.map
