"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 classnames_1 = __importDefault(require("classnames"));
var index_en_US_1 = __importDefault(require("../../../lang/common/index-en_US"));
var CatalogPrice = /** @class */ (function (_super) {
    __extends(CatalogPrice, _super);
    function CatalogPrice() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CatalogPrice.prototype.renderPrefix = function (text) {
        var _a = this.props, shouldPreserveFromPadding = _a.shouldPreserveFromPadding, isCentered = _a.isCentered, isAlignRight = _a.isAlignRight, hideCaptions = _a.hideCaptions;
        if (hideCaptions || (!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));
    };
    CatalogPrice.prototype.renderFrom = function () {
        var _a = this.props, isPriceFrom = _a.isPriceFrom, textFrom = _a.textFrom;
        var text = isPriceFrom ? textFrom : '';
        return this.renderPrefix(text);
    };
    CatalogPrice.prototype.renderOr = function () {
        var textOr = this.props.textOr;
        return this.renderPrefix(textOr);
    };
    CatalogPrice.prototype.renderDiscount = function (_a) {
        var price = _a.price, 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)));
    };
    CatalogPrice.prototype.renderPrice = function (price, period) {
        var bonusPrice = price.bonusPrice;
        var periodDescriptorNode = null;
        var priceNode = null;
        if (bonusPrice) {
            priceNode = bonusPrice;
        }
        else {
            var textFree = this.props.textFree;
            priceNode = textFree;
        }
        if (period && bonusPrice) {
            periodDescriptorNode = (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" },
            priceNode,
            periodDescriptorNode));
    };
    CatalogPrice.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)));
    };
    CatalogPrice.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));
    };
    CatalogPrice.prototype.render = function () {
        var _a = this.props, testAutomationId = _a.testAutomationId, isCentered = _a.isCentered, isAlignRight = _a.isAlignRight, inheritFontSize = _a.inheritFontSize;
        var className = classnames_1.default('rc-catalog-simple-price', {
            'rc-catalog-simple-price--inheritFontSize': inheritFontSize,
            '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()));
    };
    CatalogPrice.defaultProps = {
        pricePurchase: null,
        priceAnnual: null,
        priceMonthly: null,
        priceOneTime: null,
        isPriceFrom: false,
        shouldPreserveFromPadding: false,
        isCentered: false,
        isAlignRight: false,
        testAutomationId: 'catalogItemPrice',
        inheritFontSize: false,
        hideCaptions: false,
        get textFrom() {
            return index_en_US_1.default.FROM;
        },
        get textOr() {
            return index_en_US_1.default.OR;
        },
        get textPerMonth() {
            return index_en_US_1.default.MONTH;
        },
        get textPerYear() {
            return index_en_US_1.default.YEAR;
        },
        get textOff() {
            return index_en_US_1.default.OFF;
        },
        get textFree() {
            return index_en_US_1.default.FREE;
        }
    };
    return CatalogPrice;
}(react_1.default.PureComponent));
exports.CatalogPrice = CatalogPrice;
//# sourceMappingURL=CatalogPrice.js.map