"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var FormattedPrice = function FormattedPrice(props) {
  var formattedPrice = Math.abs(props.price);
  var sign = props.price < 0 ? '-' : '';
  if (props.languageSettings) {
    formattedPrice = formattedPrice.toFixed(props.languageSettings.pricedecimals);
    formattedPrice = String(formattedPrice);
    var parts = formattedPrice.split('.');
    formattedPrice = addThousandsseparator(parts[0], props.languageSettings.thousandsseparator);
    if (parts[1] !== undefined) {
      formattedPrice += props.languageSettings.decimalpoint + parts[1];
    }
    if (props.channelSettings !== undefined && props.channelSettings.currencySymbol !== undefined) {
      if (props.languageSettings.currencysymbolposition === 'right') {
        formattedPrice = sign + formattedPrice + ' ' + props.channelSettings.currencySymbol;
      } else {
        formattedPrice = sign + props.channelSettings.currencySymbol + formattedPrice;
      }
    }
  }
  return /*#__PURE__*/_react["default"].createElement("span", null, formattedPrice);
};
var addThousandsseparator = function addThousandsseparator(nStr, separator) {
  nStr += '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(nStr)) {
    nStr = nStr.replace(rgx, '$1' + separator + '$2');
  }
  return nStr;
};
var _default = exports["default"] = FormattedPrice;