var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import lang from '../../../lang/common/index-en_US';
var PricePropType = {
    price: PropTypes.string,
    bonusPrice: PropTypes.string,
    discountValue: PropTypes.string
};
var CatalogSimplePrice = /** @class */ (function (_super) {
    __extends(CatalogSimplePrice, _super);
    function CatalogSimplePrice() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CatalogSimplePrice.prototype.renderPrefix = function (text) {
        if (text === void 0) { text = ''; }
        var _a = this.props, shouldPreserveFromPadding = _a.shouldPreserveFromPadding, isCentered = _a.isCentered, isAlignRight = _a.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));
    };
    CatalogSimplePrice.prototype.renderFrom = function () {
        var _a = this.props, isPriceFrom = _a.isPriceFrom, textFrom = _a.textFrom;
        var text = isPriceFrom ? textFrom : null;
        return this.renderPrefix(text);
    };
    CatalogSimplePrice.prototype.renderOr = function () {
        var textOr = this.props.textOr;
        return this.renderPrefix(textOr);
    };
    CatalogSimplePrice.prototype.renderDiscount = function (_a) {
        var price = _a.price, bonusPrice = _a.bonusPrice, discountValue = _a.discountValue;
        if (!discountValue) {
            return null;
        }
        var _b = this.props, textOff = _b.textOff, shouldPreserveFromPadding = _b.shouldPreserveFromPadding, isCentered = _b.isCentered, isAlignRight = _b.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),
            "\u00A0",
            React.createElement("span", { className: "rc-catalog-simple-price__discount-amount", "data-test-automation-id": "text" },
                discountValue,
                " ",
                textOff)));
    };
    CatalogSimplePrice.prototype.renderPrice = function (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));
    };
    CatalogSimplePrice.prototype.renderPriceLineOne = function () {
        var _a = this.props, pricePurchase = _a.pricePurchase, priceAnnual = _a.priceAnnual, priceMonthly = _a.priceMonthly, textPerMonth = _a.textPerMonth, textPerYear = _a.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)));
    };
    CatalogSimplePrice.prototype.renderPriceLineTwo = function () {
        var _a = this.props, pricePurchase = _a.pricePurchase, priceAnnual = _a.priceAnnual, priceMonthly = _a.priceMonthly, textPerMonth = _a.textPerMonth, textPerYear = _a.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));
    };
    CatalogSimplePrice.prototype.render = function () {
        var _a = this.props, testAutomationId = _a.testAutomationId, isCentered = _a.isCentered, isAlignRight = _a.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()));
    };
    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
    };
    CatalogSimplePrice.defaultProps = {
        pricePurchase: null,
        priceAnnual: null,
        priceMonthly: null,
        priceOneTime: null,
        isPriceFrom: false,
        shouldPreserveFromPadding: false,
        isCentered: false,
        isAlignRight: false,
        testAutomationId: 'catalogItemPrice',
        get textFrom() {
            return lang.FROM;
        },
        get textOr() {
            return lang.OR;
        },
        textPerMonth: function () {
            return lang.MONTH;
        },
        textPerYear: function () {
            return lang.YEAR;
        },
        textOff: function () {
            return lang.OFF;
        }
    };
    return CatalogSimplePrice;
}(React.PureComponent));
export { CatalogSimplePrice };
//# sourceMappingURL=CatalogSimplePrice.js.map