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 { Alert } from 'react-bootstrap';
import { scrollEelementIntoView } from '../../utils/functions';
import { DangerousHTML } from '../DangerousHTML';
import { Block } from '../Block';
import { Button } from '../Button';
import { Spinner } from '../Spinner';
import { FlexBlock } from '../flexBlock';
import { CatalogSimplePrice } from './CatalogSimplePrice';
import lang from '../../../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.createRef();
        return _this;
    }
    CatalogListDetails.prototype.componentDidMount = function () {
        var shouldScrollIntoView = this.props.shouldScrollIntoView;
        if (shouldScrollIntoView) {
            scrollEelementIntoView(this.ref.current);
        }
    };
    CatalogListDetails.prototype.renderAlert = function () {
        var alertMessage = this.props.alertMessage;
        if (!alertMessage) {
            return null;
        }
        return (React.createElement(Block, { addTopOffset: true, addHorizontalOffset: true, cancelBottomOffset: true },
            React.createElement(Alert, { bsStyle: "warning", "data-test-automation-id": "alertMessage" },
                React.createElement(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.createElement("div", { className: "rc-catalog-list-details__price-container" },
            React.createElement(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.createElement(Spinner, { size: 18 }) : null;
        return (React.createElement(FlexBlock, { align: FlexBlock.CENTER, justify: FlexBlock.END, gutterWidth: 10 },
            loadingSpinner,
            React.createElement(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.createElement("section", { ref: this.ref, className: "rc-catalog-list-details", "data-test-automation-id": testAutomationId },
            React.createElement("div", { className: "rc-catalog-list-details__content" },
                React.createElement("div", { className: "rc-catalog-list-details__description-container" },
                    React.createElement("div", { className: "rc-catalog-list-details__description-heading" }, textDetails),
                    React.createElement("div", { className: "rc-catalog-list-details__description", "data-test-automation-id": "catalogListDetailsDescription" },
                        React.createElement(DangerousHTML, null, description))),
                React.createElement("div", { className: "rc-catalog-list-details__right" },
                    this.renderPrice(),
                    this.renderAlert())),
            React.createElement("div", { className: "rc-catalog-list-details__actions text-right" }, this.renderActionButton())));
    };
    CatalogListDetails.propTypes = {
        description: PropTypes.string.isRequired,
        action: PropTypes.func,
        testAutomationId: PropTypes.string,
        textDetails: PropTypes.string,
        textPurchase: PropTypes.string,
        price: PropTypes.shape({
            pricePurchase: PropTypes.object,
            priceAnnual: PropTypes.object,
            priceMonthly: PropTypes.object,
            isPriceFrom: PropTypes.bool
        }).isRequired,
        shouldScrollIntoView: PropTypes.bool,
        alertMessage: PropTypes.string,
        isActionDisabled: PropTypes.bool,
        isLoading: PropTypes.bool
    };
    CatalogListDetails.defaultProps = {
        testAutomationId: 'catalogListDetails',
        action: null,
        get textDetails() {
            return lang.DETAILS;
        },
        get textPurchase() {
            return lang.PURCHASE;
        },
        shouldScrollIntoView: false,
        alertMessage: null,
        isActionDisabled: false,
        isLoading: false,
        isDisabled: false
    };
    return CatalogListDetails;
}(React.PureComponent));
export { CatalogListDetails };
//# sourceMappingURL=CatalogListDetails.js.map