import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
var PricePropType = {
  price: PropTypes.string,
  bonusPrice: PropTypes.string,
  discountValue: PropTypes.string
};
export var CatalogSimplePrice =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(CatalogSimplePrice, _React$PureComponent);

  function CatalogSimplePrice() {
    return _React$PureComponent.apply(this, arguments) || this;
  }

  var _proto = CatalogSimplePrice.prototype;

  _proto.renderPrefix = function renderPrefix(text) {
    var _this$props = this.props,
        shouldPreserveFromPadding = _this$props.shouldPreserveFromPadding,
        isCentered = _this$props.isCentered,
        isAlignRight = _this$props.isAlignRight;

    if (!text && !shouldPreserveFromPadding) {
      return null;
    }

    var className = classnames('rc-catalog-simple-price__prefix', {
      'rc-catalog-simple-price__prefix--preventFixSize': !shouldPreserveFromPadding || isCentered || isAlignRight
    });
    return React.createElement("span", {
      className: className,
      "data-test-automation-id": "prefix"
    }, text);
  };

  _proto.renderFrom = function renderFrom() {
    var _this$props2 = this.props,
        isPriceFrom = _this$props2.isPriceFrom,
        textFrom = _this$props2.textFrom;
    var text = isPriceFrom ? textFrom : null;
    return this.renderPrefix(text);
  };

  _proto.renderOr = function renderOr() {
    var textOr = this.props.textOr;
    return this.renderPrefix(textOr);
  };

  _proto.renderDiscount = function renderDiscount(_ref) {
    var price = _ref.price,
        bonusPrice = _ref.bonusPrice,
        discountValue = _ref.discountValue;

    if (!discountValue) {
      return null;
    }

    var _this$props3 = this.props,
        textOff = _this$props3.textOff,
        shouldPreserveFromPadding = _this$props3.shouldPreserveFromPadding,
        isCentered = _this$props3.isCentered,
        isAlignRight = _this$props3.isAlignRight;
    var fromPadding = !(isCentered || isAlignRight) && shouldPreserveFromPadding ? this.renderPrefix() : null;
    return React.createElement("div", {
      className: "rc-catalog-simple-price__discount",
      "data-test-automation-id": "discount"
    }, fromPadding, React.createElement("s", {
      className: "rc-catalog-simple-price__old-price"
    }, price), "\xA0", React.createElement("span", {
      className: "rc-catalog-simple-price__discount-amount",
      "data-test-automation-id": "text"
    }, discountValue, " ", textOff));
  };

  _proto.renderPrice = function renderPrice(price, period) {
    if (period === void 0) {
      period = null;
    }

    var bonusPrice = price.bonusPrice;
    var periodEl;

    if (period) {
      periodEl = React.createElement("span", null, "/", React.createElement("span", {
        className: "rc-catalog-simple-price__period"
      }, period));
    }

    return React.createElement("div", {
      className: "rc-catalog-simple-price__price",
      "data-test-automation-id": "price"
    }, bonusPrice, periodEl);
  };

  _proto.renderPriceLineOne = function renderPriceLineOne() {
    var _this$props4 = this.props,
        pricePurchase = _this$props4.pricePurchase,
        priceAnnual = _this$props4.priceAnnual,
        priceMonthly = _this$props4.priceMonthly,
        textPerMonth = _this$props4.textPerMonth,
        textPerYear = _this$props4.textPerYear;
    var price;
    var priceEl;

    if (pricePurchase) {
      price = pricePurchase;
      priceEl = this.renderPrice(pricePurchase);
    } else if (priceAnnual) {
      price = priceAnnual;
      priceEl = this.renderPrice(priceAnnual, textPerYear);
    } else if (priceMonthly) {
      price = priceMonthly;
      priceEl = this.renderPrice(priceMonthly, textPerMonth);
    } else {
      return null;
    }

    return React.createElement(React.Fragment, null, React.createElement("div", {
      className: "rc-catalog-simple-price__line"
    }, this.renderFrom(), priceEl), this.renderDiscount(price));
  };

  _proto.renderPriceLineTwo = function renderPriceLineTwo() {
    var _this$props5 = this.props,
        pricePurchase = _this$props5.pricePurchase,
        priceAnnual = _this$props5.priceAnnual,
        priceMonthly = _this$props5.priceMonthly,
        textPerMonth = _this$props5.textPerMonth,
        textPerYear = _this$props5.textPerYear;
    var price;

    if (pricePurchase && (priceAnnual || priceMonthly)) {
      if (priceAnnual) {
        price = this.renderPrice(priceAnnual, textPerYear);
      } else if (priceMonthly) {
        price = this.renderPrice(priceMonthly, textPerMonth);
      }
    } else if (priceAnnual && priceMonthly) {
      price = this.renderPrice(priceMonthly, textPerMonth);
    } else {
      return null;
    }

    return React.createElement("div", {
      className: "rc-catalog-simple-price__line rc-catalog-simple-price__line--secondary"
    }, this.renderOr(), price);
  };

  _proto.render = function render() {
    var _this$props6 = this.props,
        testAutomationId = _this$props6.testAutomationId,
        isCentered = _this$props6.isCentered,
        isAlignRight = _this$props6.isAlignRight;
    var className = classnames('rc-catalog-simple-price', {
      'rc-catalog-simple-price--centered': isCentered,
      'rc-catalog-simple-price--right': isAlignRight
    });
    return React.createElement("div", {
      className: className,
      "data-test-automation-id": testAutomationId
    }, this.renderPriceLineOne(), this.renderPriceLineTwo());
  };

  return CatalogSimplePrice;
}(React.PureComponent);

_defineProperty(CatalogSimplePrice, "propTypes", {
  pricePurchase: PropTypes.shape(PricePropType),
  priceAnnual: PropTypes.shape(PricePropType),
  priceMonthly: PropTypes.shape(PricePropType),
  isPriceFrom: PropTypes.bool,
  shouldPreserveFromPadding: PropTypes.bool,
  isCentered: PropTypes.bool,
  isAlignRight: PropTypes.bool,
  testAutomationId: PropTypes.string,
  textFrom: PropTypes.string,
  textOr: PropTypes.string,
  textPerMonth: PropTypes.string,
  textPerYear: PropTypes.string,
  textOff: PropTypes.string
});

_defineProperty(CatalogSimplePrice, "defaultProps", {
  pricePurchase: null,
  priceAnnual: null,
  priceMonthly: null,
  priceOneTime: null,
  isPriceFrom: false,
  shouldPreserveFromPadding: false,
  isCentered: false,
  isAlignRight: false,
  testAutomationId: 'catalogItemPrice',
  textFrom: 'from',
  textOr: 'or',
  textPerMonth: 'month',
  textPerYear: 'year',
  textOff: 'off'
});