"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.Price = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

var _react = _interopRequireDefault(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _ = require("../");

var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;

var renderPrice = function renderPrice(price, size, currency, isInitial) {
  if (size === void 0) {
    size = 'normal';
  }

  if (!price && price !== 0) return null;

  if (typeof price === 'number' || typeof price === 'string') {
    var _price$toString$split = price.toString().split('.'),
        amount = _price$toString$split[0],
        pennies = _price$toString$split[1];

    return /*#__PURE__*/_react["default"].createElement(RegularPrice, {
      "data-price": true,
      size: size
    }, amount, /*#__PURE__*/_react["default"].createElement(Pennies, {
      size: size,
      isInitial: isInitial
    }, ",", (pennies || '').padEnd(2, '0')), /*#__PURE__*/_react["default"].createElement(CurrencyLabel, {
      size: size,
      isInitial: isInitial
    }, currency));
  }

  return /*#__PURE__*/_react["default"].createElement(RegularPrice, {
    size: size
  }, price.price, /*#__PURE__*/_react["default"].createElement(Pennies, {
    size: size,
    isInitial: isInitial
  }, ",", price.pennies), /*#__PURE__*/_react["default"].createElement(CurrencyLabel, {
    size: size,
    isInitial: isInitial
  }, price.currency || currency));
};

var Price = function Price(_ref) {
  var price = _ref.price,
      discountedPrice = _ref.discountedPrice,
      discountPercentage = _ref.discountPercentage,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 'normal' : _ref$size,
      currency = _ref.currency,
      _ref$hideDiscountPerc = _ref.hideDiscountPercentage,
      hideDiscountPercentage = _ref$hideDiscountPerc === void 0 ? false : _ref$hideDiscountPerc;
  var isDiscounted = Boolean(discountedPrice);
  return /*#__PURE__*/_react["default"].createElement(Container, {
    "data-price-container": ""
  }, /*#__PURE__*/_react["default"].createElement(PriceLabel, {
    "data-price-label": "",
    "data-discounted": Boolean(discountedPrice)
  }, !isDiscounted && renderPrice(price, size, currency, true), isDiscounted && /*#__PURE__*/_react["default"].createElement(Discount, null, /*#__PURE__*/_react["default"].createElement(DiscountedPrice, {
    "data-discount-price": ""
  }, renderPrice(discountedPrice, size, currency)), /*#__PURE__*/_react["default"].createElement(InitialPrice, {
    "data-initial-price": ""
  }, renderPrice(price, size, currency, true)), !hideDiscountPercentage && /*#__PURE__*/_react["default"].createElement(DiscountPercentage, {
    "data-discount-percentage": "",
    size: size
  }, "-", discountPercentage, "%"))));
};

exports.Price = Price;

var Discount = _styledComponents["default"].div.attrs({
  className: 'd-flex'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  align-items: baseline;\n"])));

var Container = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: flex;\n  align-items: center;\n"])));

var PriceLabel = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: flex;\n  align-items: flex-end;\n"])));

var RegularPrice = (0, _styledComponents["default"])(_.Typography).attrs({
  variant: 1,
  as: 'span'
})(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  ", "\n\n  ", "\n  color: ", ";\n  line-height: 1;\n"])), function (props) {
  return props.size === 'tiny' && "\n    font-size: 1.8rem;\n  ";
}, function (props) {
  return props.size === 'small' && "\n    font-size: 2.4rem;\n  ";
}, function (_ref2) {
  var theme = _ref2.theme;
  return theme.palette.primary;
});

var InitialPrice = _styledComponents["default"].span.attrs({
  className: 'mx-3'
})(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  text-decoration: line-through;\n  font-size: 1.5rem;\n  line-height: 1.2;\n\n  & span {\n    font-size: 1.5rem;\n    line-height: 1.2;\n  }\n"])));

var CurrencyLabel = _styledComponents["default"].span(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  ", "\n"])), function (props) {
  return !props.isInitial && "\n      font-size: 1rem;\n      margin-top: 0.5rem;\n  ";
});

var Pennies = _styledComponents["default"].span(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  ", "\n"])), function (props) {
  return "\n\n      " + (props.size === 'tiny' && "\n        bottom: " + (props.isInitial ? '0' : '-1.3rem') + ";\n      ") + "\n  ";
});

var DiscountPercentage = _styledComponents["default"].span.attrs({
  className: 'p-2'
})(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  font-size: 1.4rem;\n  line-height: 1;\n  border-radius: 0.3rem;\n  color: ", ";\n  background: ", ";\n  margin-bottom: 0.2rem;\n"])), function (_ref3) {
  var theme = _ref3.theme;
  return theme.palette.secondary;
}, function (_ref4) {
  var theme = _ref4.theme;
  return theme.palette.discount;
});

var DiscountedPrice = (0, _styledComponents["default"])(_.Typography).attrs({
  variant: 1,
  as: 'span'
})(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  line-height: 1;\n\n  & span {\n    color: ", ";\n  }\n"])), function (_ref5) {
  var theme = _ref5.theme;
  return theme.palette.discount;
});
//# sourceMappingURL=index.js.map