'use strict';

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

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var index = require('../../utils/index.js');
var formatCurrency = require('./utils/formatCurrency.js');
var Price_styles = require('./Price.styles.js');
var base = require('./variations/_view/base.js');
var Price_tokens = require('./Price.tokens.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["children", "locale", "currency", "minimumFractionDigits", "stroked", "periodicity", "view", "className", "stroke"];

/**
 * Компонент для отображения цены / стоимости / суммы.
 */
var priceRoot = function priceRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (_ref, outerRootRef) {
    var children = _ref.children,
      _ref$locale = _ref.locale,
      locale = _ref$locale === void 0 ? 'ru' : _ref$locale,
      _ref$currency = _ref.currency,
      currency = _ref$currency === void 0 ? 'rub' : _ref$currency,
      _ref$minimumFractionD = _ref.minimumFractionDigits,
      minimumFractionDigits = _ref$minimumFractionD === void 0 ? 0 : _ref$minimumFractionD,
      _ref$stroked = _ref.stroked,
      stroked = _ref$stroked === void 0 ? false : _ref$stroked,
      periodicity = _ref.periodicity,
      view = _ref.view,
      className = _ref.className,
      _ref$stroke = _ref.stroke,
      stroke = _ref$stroke === void 0 ? false : _ref$stroke,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
    var strokedClass = stroked || stroke ? Price_tokens.classes.stroked : undefined;
    var hasCurrency = currency && currency.length === 3;
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      view: view,
      ref: outerRootRef,
      className: index.cx(strokedClass, className)
    }, rest), hasCurrency && formatCurrency.formatCurrency({
      value: children,
      locale: locale,
      currency: currency,
      minimumFractionDigits: minimumFractionDigits
    }), periodicity && /*#__PURE__*/React__default.default.createElement(Price_styles.StyledPeriodicity, null, periodicity));
  });
};
var priceConfig = {
  name: 'Price',
  tag: 'span',
  layout: priceRoot,
  base: Price_styles.base,
  variations: {
    view: {
      css: base.base
    }
  },
  defaults: {
    view: 'default'
  }
};

exports.priceConfig = priceConfig;
exports.priceRoot = priceRoot;
