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 { isFunction } from 'lodash';
import { Collapse } from 'react-bootstrap';
import { filterKeyCodes, stripTags } from '../../utils/functions';
import { CatalogItemIcon } from './CatalogItemIcon';
import { CatalogSimplePrice } from './CatalogSimplePrice';
import { Icon } from '../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 (isFunction(onClick)) {
                onClick();
            }
        };
        _this.handleKeyPress = filterKeyCodes(_this.handleClick);
        return _this;
    }
    CatalogListItem.prototype.renderDescription = function () {
        var description = this.props.description;
        if (!description) {
            return null;
        }
        return (React.createElement("div", { className: "rc-catalog-list-item__text rc-catalog-list-item__description", "data-test-automation-id": "description" }, 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.createElement(CatalogSimplePrice, { 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.createElement("div", { className: "rc-catalog-list-item__arrow" },
            React.createElement(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.createElement(Collapse, { in: isExpanded, "data-test-automation-id": "children" },
            React.createElement("div", { className: "rc-catalog-list-item__children" }, children)));
    };
    CatalogListItem.prototype.renderIcon = function () {
        var _a = this.props, icon = _a.icon, color = _a.color;
        if (React.isValidElement(icon)) {
            return icon;
        }
        return React.createElement(CatalogItemIcon, { isRound: true, iconName: icon, backgroundColor: color });
    };
    CatalogListItem.prototype.render = function () {
        var _a = this.props, name = _a.name, testAutomationId = _a.testAutomationId;
        return (React.createElement("div", { className: "rc-catalog-list-item", "data-test-automation-id": testAutomationId },
            React.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.createElement("div", { className: "rc-catalog-list-item__main" },
                    React.createElement("div", { className: "rc-catalog-list-item__icon" }, this.renderIcon()),
                    React.createElement("div", { className: "rc-catalog-list-item__content" },
                        React.createElement("div", { className: "rc-catalog-list-item__text rc-catalog-list-item__name", "data-test-automation-id": "name" }, name),
                        this.renderDescription())),
                React.createElement("div", { className: "rc-catalog-list-item__price-container" }, this.renderPrice()),
                this.renderArrow()),
            this.renderChildren()));
    };
    CatalogListItem.propTypes = {
        name: PropTypes.string.isRequired,
        description: PropTypes.string,
        icon: PropTypes.node,
        color: PropTypes.string,
        image: PropTypes.string,
        price: PropTypes.shape({
            pricePurchase: PropTypes.object,
            priceAnnual: PropTypes.object,
            priceMonthly: PropTypes.object,
            isPriceFrom: PropTypes.bool
        }),
        isExpanded: PropTypes.bool,
        onClick: PropTypes.func,
        testAutomationId: PropTypes.string
    };
    CatalogListItem.defaultProps = {
        description: null,
        icon: null,
        color: null,
        image: null,
        price: null,
        isExpanded: false,
        onClick: null,
        testAutomationId: 'catalogListItem'
    };
    return CatalogListItem;
}(React.PureComponent));
export { CatalogListItem };
//# sourceMappingURL=CatalogListItem.js.map