"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 __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var functions_1 = require("../../utils/functions");
var DangerousHTML_1 = require("../DangerousHTML");
var Button_1 = require("../Button");
var Spinner_1 = require("../Spinner");
var flexBlock_1 = require("../flexBlock");
var Block_1 = require("../Block");
var index_en_US_1 = __importDefault(require("../../../lang/common/index-en_US"));
var classnames_1 = __importDefault(require("classnames"));
var CatalogListDetails = /** @class */ (function (_super) {
    __extends(CatalogListDetails, _super);
    function CatalogListDetails() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.getNodeRef = function (element) {
            if (_this.ref !== element && element) {
                var shouldScrollIntoView = _this.props.shouldScrollIntoView;
                if (shouldScrollIntoView) {
                    functions_1.scrollElementIntoView(element);
                }
            }
            _this.ref = element;
        };
        return _this;
    }
    CatalogListDetails.prototype.renderRightDetails = function () {
        var renderRightDetails = this.props.renderRightDetails;
        return renderRightDetails || null;
    };
    CatalogListDetails.prototype.renderActionButton = function () {
        var _a = this.props, action = _a.action, textPurchase = _a.textPurchase, isLoading = _a.isLoading, isActionDisabled = _a.isActionDisabled;
        if (!action) {
            return null;
        }
        var isDisabled = isLoading || isActionDisabled || typeof action !== 'function';
        var loadingSpinnerNode = isLoading ? React.createElement(Spinner_1.Spinner, { size: 18 }) : null;
        return (React.createElement("div", { className: "rc-catalog-list-details__actions text-right" },
            React.createElement(flexBlock_1.FlexBlock, { align: flexBlock_1.FlexBlock.CENTER, justify: flexBlock_1.FlexBlock.END, gutterWidth: 10 },
                loadingSpinnerNode,
                React.createElement(Button_1.Button, { bsStyle: "primary", onClick: action, testAutomationId: "catalogListDetailsButton", disabled: isDisabled }, textPurchase))));
    };
    CatalogListDetails.prototype.renderAlert = function () {
        var alert = this.props.alert;
        if (!alert) {
            return null;
        }
        return (React.createElement(Block_1.Block, { addHorizontalOffset: true, cancelBottomOffset: true }, alert));
    };
    CatalogListDetails.prototype.renderWarning = function () {
        var warning = this.props.warning;
        if (!warning) {
            return null;
        }
        return (React.createElement(Block_1.Block, { addTopOffset: true, cancelBottomOffset: true }, warning));
    };
    CatalogListDetails.prototype.renderTitle = function () {
        var title = this.props.title;
        if (!title) {
            return null;
        }
        return (React.createElement("div", { className: "rc-catalog-list-details__titlebar", "data-test-automation-id": "header" }, title));
    };
    CatalogListDetails.prototype.render = function () {
        var _a = this.props, testAutomationId = _a.testAutomationId, textDetails = _a.textDetails;
        var _b = this.props, description = _b.description, narrow = _b.narrow;
        if (typeof description === 'string') {
            description = React.createElement(DangerousHTML_1.DangerousHTML, null, description);
        }
        var className = classnames_1.default('rc-catalog-list-details', { narrow: narrow });
        return (React.createElement("section", { ref: this.getNodeRef, className: className, "data-test-automation-id": testAutomationId },
            React.createElement("div", { className: "rc-catalog-list-details__content" },
                this.renderTitle(),
                React.createElement("div", { className: "rc-catalog-list-details__description-container" },
                    React.createElement(flexBlock_1.FlexBlock, { direction: flexBlock_1.FlexBlock.COLUMN, align: flexBlock_1.FlexBlock.START, justify: flexBlock_1.FlexBlock.SPACE_BETWEEN, className: "rc-catalog-list-details__description-wrap" },
                        React.createElement("div", { className: "rc-catalog-list-details__description-heading-wrap" },
                            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" }, description)),
                        this.renderWarning())),
                React.createElement("div", { className: "rc-catalog-list-details__right" },
                    this.renderRightDetails(),
                    this.renderAlert())),
            this.renderActionButton()));
    };
    CatalogListDetails.defaultProps = {
        testAutomationId: 'catalogListDetails',
        action: null,
        get textDetails() {
            return index_en_US_1.default.DETAILS;
        },
        get textPurchase() {
            return index_en_US_1.default.PURCHASE;
        },
        title: null,
        shouldScrollIntoView: false,
        isActionDisabled: false,
        isLoading: false,
        isDisabled: false,
        alert: null,
        warning: null,
        narrow: false
    };
    return CatalogListDetails;
}(React.PureComponent));
exports.CatalogListDetails = CatalogListDetails;
//# sourceMappingURL=CatalogListDetails.js.map