import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
var _excluded = ["id", "value", "fractionDigits", "currencySymbol", "hideTrailingZeros"];
import React from 'react';
import warning from 'warning';
import { MAX_SAFE_DIGITS } from "../../CurrencyInput/constants";
import { CurrencyHelper } from "../../CurrencyInput/CurrencyHelper";
import { CommonWrapper } from "../../../internal/CommonWrapper";
import { forwardRefAndName } from "../../../lib/forwardRefAndName";
var FRACTION_DIGITS_DEFAULT = 2;
export var CurrencyLabelDataTids = {
  root: 'CurrencyLabel__root'
};

/**
 * `CurrencyLabel` — подпись для денежных сумм (и других числовых значений).
 */
var CurrencyLabel = forwardRefAndName('CurrencyLabel', function CurrencyLabel(_ref, ref) {
  var id = _ref.id,
    value = _ref.value,
    _ref$fractionDigits = _ref.fractionDigits,
    fractionDigits = _ref$fractionDigits === void 0 ? FRACTION_DIGITS_DEFAULT : _ref$fractionDigits,
    currencySymbol = _ref.currencySymbol,
    _ref$hideTrailingZero = _ref.hideTrailingZeros,
    hideTrailingZeros = _ref$hideTrailingZero === void 0 ? false : _ref$hideTrailingZero,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  React.useEffect(function () {
    warning(fractionDigits <= MAX_SAFE_DIGITS, "[CurrencyLabel]: Prop 'fractionDigits' exceeds " + MAX_SAFE_DIGITS + ".\nSee CurrencyInput documentation");
    var _ref2 = CurrencyHelper.destructString(String(value)) || {
        fraction: ''
      },
      fraction = _ref2.fraction;
    warning(fraction.length <= fractionDigits, "[CurrencyLabel]: Prop 'fractionDigits' less than fractional part of the 'value' property," + "'value' will not be cutted");
    warning(Number.isInteger(fractionDigits), "[CurrencyLabel]: Prop 'fractionDigits' is not integer, fraction part of these property will not be used");
  }, [fractionDigits, value]);
  return /*#__PURE__*/(
    React.createElement(CommonWrapper, rest, /*#__PURE__*/
    React.createElement("span", {
      id: id,
      "data-tid": CurrencyLabelDataTids.root,
      ref: ref
    }, CurrencyHelper.format(value, {
      fractionDigits: fractionDigits,
      hideTrailingZeros: hideTrailingZeros
    }), currencySymbol && String.fromCharCode(0xa0) /* &nbsp; */, currencySymbol))
  );
});
export { CurrencyLabel };