"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 lodash_1 = require("lodash");
var react_bootstrap_1 = require("react-bootstrap");
var functions_1 = require("../../utils/functions");
var CatalogPrice_1 = require("./CatalogPrice");
var Icon_1 = require("../Icon");
var CatalogListItem = /** @class */ (function (_super) {
    __extends(CatalogListItem, _super);
    function CatalogListItem() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.handleClick = function () {
            var onClick = _this.props.onClick;
            if (lodash_1.isFunction(onClick)) {
                onClick();
            }
        };
        _this.handleKeyPress = functions_1.filterKeyCodes(_this.handleClick);
        return _this;
    }
    CatalogListItem.prototype.renderDescription = function () {
        var description = this.props.description;
        if (!description) {
            return null;
        }
        return (react_1.default.createElement("div", { className: "rc-catalog-list-item__text rc-catalog-list-item__description", "data-test-automation-id": "description" }, functions_1.stripTags(description)));
    };
    CatalogListItem.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(CatalogPrice_1.CatalogPrice, { shouldPreserveFromPadding: true, pricePurchase: pricePurchase, priceAnnual: priceAnnual, priceMonthly: priceMonthly, isPriceFrom: isPriceFrom }));
    };
    CatalogListItem.prototype.renderArrow = function () {
        var _a = this.props, children = _a.children, isExpanded = _a.isExpanded;
        var arrow = 'chevron-right-big';
        if (children) {
            if (isExpanded) {
                arrow = 'chevron-up-big';
            }
            else {
                arrow = 'chevron-down-big';
            }
        }
        return (react_1.default.createElement("div", { className: "rc-catalog-list-item__arrow" },
            react_1.default.createElement(Icon_1.Icon, { name: arrow, testAutomationId: "arrow" })));
    };
    CatalogListItem.prototype.renderChildren = function () {
        var _a = this.props, children = _a.children, isExpanded = _a.isExpanded;
        if (!children || !isExpanded) {
            return null;
        }
        return (react_1.default.createElement(react_bootstrap_1.Collapse, { in: isExpanded, "data-test-automation-id": "children" },
            react_1.default.createElement("div", { className: "rc-catalog-list-item__children" }, children)));
    };
    CatalogListItem.prototype.renderIcon = function () {
        return react_1.default.cloneElement(this.props.icon, { size: 60, isRound: true });
    };
    CatalogListItem.prototype.render = function () {
        var _a = this.props, name = _a.name, testAutomationId = _a.testAutomationId;
        return (react_1.default.createElement("div", { className: "rc-catalog-list-item", "data-test-automation-id": testAutomationId },
            react_1.default.createElement("div", { "data-test-automation-id": "header", className: "rc-catalog-list-item__header", tabIndex: 0, role: "button", title: name, onClick: this.handleClick, onKeyDown: this.handleKeyPress },
                react_1.default.createElement("div", { className: "rc-catalog-list-item__main" },
                    react_1.default.createElement("div", { className: "rc-catalog-list-item__icon" }, this.renderIcon()),
                    react_1.default.createElement("div", { className: "rc-catalog-list-item__content" },
                        react_1.default.createElement("div", { className: "rc-catalog-list-item__text rc-catalog-list-item__name", "data-test-automation-id": "name" }, name),
                        this.renderDescription())),
                react_1.default.createElement("div", { className: "rc-catalog-list-item__price-container" }, this.renderPrice()),
                this.renderArrow()),
            this.renderChildren()));
    };
    CatalogListItem.propTypes = {
        name: prop_types_1.default.string.isRequired,
        description: prop_types_1.default.string,
        icon: prop_types_1.default.node.isRequired,
        color: prop_types_1.default.string,
        image: 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
        }),
        isExpanded: prop_types_1.default.bool,
        onClick: prop_types_1.default.func,
        testAutomationId: prop_types_1.default.string
    };
    CatalogListItem.defaultProps = {
        description: null,
        color: null,
        image: null,
        price: null,
        isExpanded: false,
        onClick: null,
        testAutomationId: 'catalogListItem'
    };
    return CatalogListItem;
}(react_1.default.PureComponent));
exports.CatalogListItem = CatalogListItem;
//# sourceMappingURL=CatalogListItem.js.map