"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkYIDQ2YI5cjs = require('./chunk-YIDQ2YI5.cjs');


var _chunkBAUCJTNOcjs = require('./chunk-BAUCJTNO.cjs');


var _chunkXHXTTU65cjs = require('./chunk-XHXTTU65.cjs');


var _chunkGNRTDXICcjs = require('./chunk-GNRTDXIC.cjs');

// src/hooks/useNumberInput/utils/cleanValue.ts
var cleanValue = ({
  value,
  groupSeparator = ",",
  decimalSeparator = ".",
  allowDecimals = true,
  decimalsLimit = 2,
  allowNegativeValue = true,
  disableAbbreviations = false,
  prefix = "",
  transformRawValue = (rawValue) => rawValue
}) => {
  const transformedValue = transformRawValue(value);
  if (transformedValue === "-") {
    return transformedValue;
  }
  const abbreviations = disableAbbreviations ? [] : ["k", "m", "b"];
  const reg = new RegExp(`((^|\\D)-\\d)|(-${_chunkGNRTDXICcjs.escapeRegExp.call(void 0, prefix)})`);
  const isNegative = reg.test(transformedValue);
  const [prefixWithValue, preValue] = RegExp(`(\\d+)-?${_chunkGNRTDXICcjs.escapeRegExp.call(void 0, prefix)}`).exec(value) || [];
  const withoutPrefix = prefix ? prefixWithValue ? transformedValue.replace(prefixWithValue, "").concat(preValue) : transformedValue.replace(prefix, "") : transformedValue;
  const withoutSeparators = _chunkXHXTTU65cjs.removeSeparators.call(void 0, withoutPrefix, groupSeparator);
  const withoutInvalidChars = _chunkBAUCJTNOcjs.removeInvalidChars.call(void 0, withoutSeparators, [
    groupSeparator,
    decimalSeparator,
    ...abbreviations
  ]);
  let valueOnly = withoutInvalidChars;
  if (!disableAbbreviations) {
    if (abbreviations.some(
      (letter) => letter === withoutInvalidChars.toLowerCase().replace(decimalSeparator, "")
    )) {
      return "";
    }
    const parsed = _chunkYIDQ2YI5cjs.parseAbbrValue.call(void 0, withoutInvalidChars, decimalSeparator);
    if (parsed) {
      valueOnly = String(parsed);
    }
  }
  const includeNegative = isNegative && allowNegativeValue ? "-" : "";
  if (decimalSeparator && valueOnly.includes(decimalSeparator)) {
    const [int, decimals] = withoutInvalidChars.split(decimalSeparator);
    const trimmedDecimals = decimalsLimit && decimals ? decimals.slice(0, decimalsLimit) : decimals;
    const includeDecimals = allowDecimals ? `${decimalSeparator}${trimmedDecimals}` : "";
    return `${includeNegative}${int}${includeDecimals}`;
  }
  return `${includeNegative}${valueOnly}`;
};



exports.cleanValue = cleanValue;
