"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 CatalogPrice_1 = require("./CatalogPrice");
var Spinner_1 = require("../Spinner/Spinner");
var Highlighter_1 = require("../Highlighter");
var CatalogSearchResultItem = /** @class */ (function (_super) {
    __extends(CatalogSearchResultItem, _super);
    function CatalogSearchResultItem() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.getQueryRegex = function () {
            var query = _this.props.query;
            return !!query ? new RegExp(query, 'i') : null;
        };
        return _this;
    }
    CatalogSearchResultItem.prototype.renderIcon = function () {
        return react_1.default.cloneElement(this.props.icon, { size: 40, isRound: true });
    };
    CatalogSearchResultItem.prototype.renderPrice = function () {
        var _a = this.props, price = _a.price, isLoading = _a.isLoading;
        if (isLoading) {
            return react_1.default.createElement(Spinner_1.Spinner, { size: 18 });
        }
        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, { isAlignRight: true, shouldPreserveFromPadding: true, pricePurchase: pricePurchase, priceAnnual: priceAnnual, priceMonthly: priceMonthly, isPriceFrom: isPriceFrom }));
    };
    CatalogSearchResultItem.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" },
            react_1.default.createElement(Highlighter_1.Highlighter, { highlightRegexp: this.getQueryRegex() }, description)));
    };
    CatalogSearchResultItem.prototype.render = function () {
        var _a = this.props, name = _a.name, testAutomationId = _a.testAutomationId;
        return (react_1.default.createElement("div", { className: "rc-catalog-search-result-item", "data-test-automation-id": testAutomationId },
            react_1.default.createElement("div", { className: "rc-catalog-search-result-item__side-content" }, this.renderIcon()),
            react_1.default.createElement("div", { className: "rc-catalog-search-result-item__content" },
                react_1.default.createElement("div", { className: "rc-catalog-list-item__text rc-catalog-list-item__name", "data-test-automation-id": "name" },
                    react_1.default.createElement(Highlighter_1.Highlighter, { highlightRegexp: this.getQueryRegex() }, name)),
                this.renderDescription()),
            react_1.default.createElement("div", { className: "rc-catalog-search-result-item__side-content" }, this.renderPrice())));
    };
    CatalogSearchResultItem.propTypes = {
        name: prop_types_1.default.string.isRequired,
        description: prop_types_1.default.string,
        price: prop_types_1.default.object,
        icon: prop_types_1.default.node.isRequired,
        color: prop_types_1.default.string,
        isLoading: prop_types_1.default.bool,
        query: prop_types_1.default.string,
        testAutomationId: prop_types_1.default.string
    };
    CatalogSearchResultItem.defaultProps = {
        description: null,
        price: null,
        color: null,
        isLoading: false,
        query: '',
        testAutomationId: 'catalogSearchResultItem'
    };
    return CatalogSearchResultItem;
}(react_1.default.PureComponent));
exports.CatalogSearchResultItem = CatalogSearchResultItem;
//# sourceMappingURL=CatalogSearchResultItem.js.map