"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.CurrencyLabelDataTids = exports.CurrencyLabel = void 0;var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireDefault(require("react"));
var _warning = _interopRequireDefault(require("warning"));

var _constants = require("../CurrencyInput/constants");
var _CurrencyHelper = require("../CurrencyInput/CurrencyHelper");

var _CommonWrapper = require("../../internal/CommonWrapper");
var _forwardRefAndName = require("../../lib/forwardRefAndName");var _excluded = ["id", "value", "fractionDigits", "currencySymbol", "hideTrailingZeros"];
















var FRACTION_DIGITS_DEFAULT = 2;

var CurrencyLabelDataTids = exports.CurrencyLabelDataTids = {
  root: 'CurrencyLabel__root'
};

/**
 * `CurrencyLabel` — подпись для денежных сумм (и других числовых значений).
 */
var CurrencyLabel = exports.CurrencyLabel = (0, _forwardRefAndName.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 = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
    _react.default.useEffect(function () {
      (0, _warning.default)(
        fractionDigits <= _constants.MAX_SAFE_DIGITS, "[CurrencyLabel]: Prop 'fractionDigits' exceeds " +
        _constants.MAX_SAFE_DIGITS + ".\nSee CurrencyInput documentation"
      );

      var _ref2 = _CurrencyHelper.CurrencyHelper.destructString(String(value)) || { fraction: '' },fraction = _ref2.fraction;
      (0, _warning.default)(
        fraction.length <= fractionDigits,
        "[CurrencyLabel]: Prop 'fractionDigits' less than fractional part of the 'value' property," + "'value' will not be cutted"

      );

      (0, _warning.default)(
        Number.isInteger(fractionDigits), "[CurrencyLabel]: Prop 'fractionDigits' is not integer, fraction part of these property will not be used"

      );
    }, [fractionDigits, value]);

    return /*#__PURE__*/(
      _react.default.createElement(_CommonWrapper.CommonWrapper, rest, /*#__PURE__*/
      _react.default.createElement("span", { id: id, "data-tid": CurrencyLabelDataTids.root, ref: ref },
      _CurrencyHelper.CurrencyHelper.format(value, { fractionDigits: fractionDigits, hideTrailingZeros: hideTrailingZeros }),
      currencySymbol && String.fromCharCode(0xa0) /* &nbsp; */,
      currencySymbol
      )
      ));

  }
);