"use strict";
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 __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var classnames_1 = __importDefault(require("classnames"));
var index_en_US_1 = __importDefault(require("../../../lang/common/index-en_US"));
var PricePropType = {
    price: prop_types_1.default.string,
    bonusPrice: prop_types_1.default.string,
    discountValue: prop_types_1.default.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_1.default('rc-catalog-simple-price__prefix', {
            'rc-catalog-simple-price__prefix--preventFixSize': !shouldPreserveFromPadding || isCentered || isAlignRight
        });
        return (react_1.default.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_1.default.createElement("div", { className: "rc-catalog-simple-price__discount", "data-test-automation-id": "discount" },
            fromPadding,
            react_1.default.createElement("s", { className: "rc-catalog-simple-price__old-price" }, price),
            "\u00A0",
            react_1.default.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_1.default.createElement("span", null,
                "/",
                react_1.default.createElement("span", { className: "rc-catalog-simple-price__period" }, period)));
        }
        return (react_1.default.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_1.default.createElement(react_1.default.Fragment, null,
            react_1.default.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_1.default.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_1.default('rc-catalog-simple-price', {
            'rc-catalog-simple-price--centered': isCentered,
            'rc-catalog-simple-price--right': isAlignRight
        });
        return (react_1.default.createElement("div", { className: className, "data-test-automation-id": testAutomationId },
            this.renderPriceLineOne(),
            this.renderPriceLineTwo()));
    };
    CatalogSimplePrice.propTypes = {
        pricePurchase: prop_types_1.default.shape(PricePropType),
        priceAnnual: prop_types_1.default.shape(PricePropType),
        priceMonthly: prop_types_1.default.shape(PricePropType),
        isPriceFrom: prop_types_1.default.bool,
        shouldPreserveFromPadding: prop_types_1.default.bool,
        isCentered: prop_types_1.default.bool,
        isAlignRight: prop_types_1.default.bool,
        testAutomationId: prop_types_1.default.string,
        textFrom: prop_types_1.default.string,
        textOr: prop_types_1.default.string,
        textPerMonth: prop_types_1.default.string,
        textPerYear: prop_types_1.default.string,
        textOff: prop_types_1.default.string
    };
    CatalogSimplePrice.defaultProps = {
        pricePurchase: null,
        priceAnnual: null,
        priceMonthly: null,
        priceOneTime: null,
        isPriceFrom: false,
        shouldPreserveFromPadding: false,
        isCentered: false,
        isAlignRight: false,
        testAutomationId: 'catalogItemPrice',
        get textFrom() {
            return index_en_US_1.default.FROM;
        },
        get textOr() {
            return index_en_US_1.default.OR;
        },
        textPerMonth: function () {
            return index_en_US_1.default.MONTH;
        },
        textPerYear: function () {
            return index_en_US_1.default.YEAR;
        },
        textOff: function () {
            return index_en_US_1.default.OFF;
        }
    };
    return CatalogSimplePrice;
}(react_1.default.PureComponent));
exports.CatalogSimplePrice = CatalogSimplePrice;
//# sourceMappingURL=CatalogSimplePrice.js.map