"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 functions_1 = require("../../utils/functions");
var CatalogItemIcon_1 = require("./CatalogItemIcon");
var CatalogSimplePrice_1 = require("./CatalogSimplePrice");
var CatalogGridItem = /** @class */ (function (_super) {
    __extends(CatalogGridItem, _super);
    function CatalogGridItem() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.handleKeyDown = functions_1.filterKeyCodes(_this.props.onClick);
        return _this;
    }
    CatalogGridItem.prototype.renderDescription = function () {
        var _a = this.props, description = _a.description, price = _a.price;
        if (!description && !price) {
            return null;
        }
        if (price) {
            var pricePurchase = price.pricePurchase, priceAnnual = price.priceAnnual, priceMonthly = price.priceMonthly, isPriceFrom = price.isPriceFrom;
            return (react_1.default.createElement(CatalogSimplePrice_1.CatalogSimplePrice, { isCentered: true, pricePurchase: pricePurchase, priceAnnual: priceAnnual, priceMonthly: priceMonthly, isPriceFrom: isPriceFrom }));
        }
        return (react_1.default.createElement("div", { className: "rc-catalog-grid-item__desc", "data-test-automation-id": "description" }, description));
    };
    CatalogGridItem.prototype.renderIcon = function () {
        var _a = this.props, icon = _a.icon, color = _a.color;
        if (react_1.default.isValidElement(icon)) {
            return icon;
        }
        return react_1.default.createElement(CatalogItemIcon_1.CatalogItemIcon, { isRound: true, size: 90, iconName: icon, backgroundColor: color });
    };
    CatalogGridItem.prototype.render = function () {
        var _a = this.props, testAutomationId = _a.testAutomationId, name = _a.name, onClick = _a.onClick;
        return (react_1.default.createElement("div", { "data-test-automation-id": testAutomationId, className: "rc-catalog-grid-item__block", role: "button", onClick: onClick, onKeyDown: this.handleKeyDown, tabIndex: 0 },
            this.renderIcon(),
            react_1.default.createElement("div", { className: "rc-catalog-grid-item__name", "data-test-automation-id": "name" }, name),
            this.renderDescription()));
    };
    CatalogGridItem.propTypes = {
        testAutomationId: prop_types_1.default.string,
        name: prop_types_1.default.string.isRequired,
        description: prop_types_1.default.string,
        icon: prop_types_1.default.string,
        color: prop_types_1.default.string,
        onClick: prop_types_1.default.func,
        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
        })
    };
    CatalogGridItem.defaultProps = {
        testAutomationId: 'catalogGridItem',
        description: null,
        icon: null,
        color: null,
        price: null,
        onClick: function () { }
    };
    return CatalogGridItem;
}(react_1.default.PureComponent));
exports.CatalogGridItem = CatalogGridItem;
//# sourceMappingURL=CatalogGridItem.js.map