"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 react_bootstrap_1 = require("react-bootstrap");
var functions_1 = require("../../utils/functions");
var DangerousHTML_1 = require("../DangerousHTML");
var Block_1 = require("../Block");
var Button_1 = require("../Button");
var Spinner_1 = require("../Spinner");
var flexBlock_1 = require("../flexBlock");
var CatalogSimplePrice_1 = require("./CatalogSimplePrice");
var index_en_US_1 = __importDefault(require("../../../lang/common/index-en_US"));
var CatalogListDetails = /** @class */ (function (_super) {
    __extends(CatalogListDetails, _super);
    function CatalogListDetails() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.ref = react_1.default.createRef();
        return _this;
    }
    CatalogListDetails.prototype.componentDidMount = function () {
        var shouldScrollIntoView = this.props.shouldScrollIntoView;
        if (shouldScrollIntoView) {
            functions_1.scrollEelementIntoView(this.ref.current);
        }
    };
    CatalogListDetails.prototype.renderAlert = function () {
        var alertMessage = this.props.alertMessage;
        if (!alertMessage) {
            return null;
        }
        return (react_1.default.createElement(Block_1.Block, { addTopOffset: true, addHorizontalOffset: true, cancelBottomOffset: true },
            react_1.default.createElement(react_bootstrap_1.Alert, { bsStyle: "warning", "data-test-automation-id": "alertMessage" },
                react_1.default.createElement(DangerousHTML_1.DangerousHTML, null, alertMessage))));
    };
    CatalogListDetails.prototype.renderPrice = function () {
        var price = this.props.price;
        if (!price) {
            return null;
        }
        var pricePurchase = price.pricePurchase, priceAnnual = price.priceAnnual, priceMonthly = price.priceMonthly, isPriceFrom = price.isPriceFrom;
        return (react_1.default.createElement("div", { className: "rc-catalog-list-details__price-container" },
            react_1.default.createElement(CatalogSimplePrice_1.CatalogSimplePrice, { shouldPreserveFromPadding: true, pricePurchase: pricePurchase, priceAnnual: priceAnnual, priceMonthly: priceMonthly, isPriceFrom: isPriceFrom })));
    };
    CatalogListDetails.prototype.renderActionButton = function () {
        var _a = this.props, action = _a.action, textPurchase = _a.textPurchase, isLoading = _a.isLoading, isActionDisabled = _a.isActionDisabled;
        var isDisabled = isLoading || isActionDisabled || typeof action !== 'function';
        var loadingSpinner = isLoading ? react_1.default.createElement(Spinner_1.Spinner, { size: 18 }) : null;
        return (react_1.default.createElement(flexBlock_1.FlexBlock, { align: flexBlock_1.FlexBlock.CENTER, justify: flexBlock_1.FlexBlock.END, gutterWidth: 10 },
            loadingSpinner,
            react_1.default.createElement(Button_1.Button, { bsStyle: "primary", onClick: action, testAutomationId: "catalogListDetailsButton", disabled: isDisabled }, textPurchase)));
    };
    CatalogListDetails.prototype.render = function () {
        var _a = this.props, description = _a.description, testAutomationId = _a.testAutomationId, textDetails = _a.textDetails;
        return (react_1.default.createElement("section", { ref: this.ref, className: "rc-catalog-list-details", "data-test-automation-id": testAutomationId },
            react_1.default.createElement("div", { className: "rc-catalog-list-details__content" },
                react_1.default.createElement("div", { className: "rc-catalog-list-details__description-container" },
                    react_1.default.createElement("div", { className: "rc-catalog-list-details__description-heading" }, textDetails),
                    react_1.default.createElement("div", { className: "rc-catalog-list-details__description", "data-test-automation-id": "catalogListDetailsDescription" },
                        react_1.default.createElement(DangerousHTML_1.DangerousHTML, null, description))),
                react_1.default.createElement("div", { className: "rc-catalog-list-details__right" },
                    this.renderPrice(),
                    this.renderAlert())),
            react_1.default.createElement("div", { className: "rc-catalog-list-details__actions text-right" }, this.renderActionButton())));
    };
    CatalogListDetails.propTypes = {
        description: prop_types_1.default.string.isRequired,
        action: prop_types_1.default.func,
        testAutomationId: prop_types_1.default.string,
        textDetails: prop_types_1.default.string,
        textPurchase: prop_types_1.default.string,
        price: prop_types_1.default.shape({
            pricePurchase: prop_types_1.default.object,
            priceAnnual: prop_types_1.default.object,
            priceMonthly: prop_types_1.default.object,
            isPriceFrom: prop_types_1.default.bool
        }).isRequired,
        shouldScrollIntoView: prop_types_1.default.bool,
        alertMessage: prop_types_1.default.string,
        isActionDisabled: prop_types_1.default.bool,
        isLoading: prop_types_1.default.bool
    };
    CatalogListDetails.defaultProps = {
        testAutomationId: 'catalogListDetails',
        action: null,
        get textDetails() {
            return index_en_US_1.default.DETAILS;
        },
        get textPurchase() {
            return index_en_US_1.default.PURCHASE;
        },
        shouldScrollIntoView: false,
        alertMessage: null,
        isActionDisabled: false,
        isLoading: false,
        isDisabled: false
    };
    return CatalogListDetails;
}(react_1.default.PureComponent));
exports.CatalogListDetails = CatalogListDetails;
//# sourceMappingURL=CatalogListDetails.js.map