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 { CatalogPrice } from './CatalogPrice';
import { Spinner } from '../Spinner/Spinner';
import { Highlighter } from '../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.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.createElement(Spinner, { size: 18 });
        }
        if (!price) {
            return null;
        }
        var pricePurchase = price.pricePurchase, priceAnnual = price.priceAnnual, priceMonthly = price.priceMonthly, isPriceFrom = price.isPriceFrom;
        return (React.createElement(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.createElement("div", { className: "rc-catalog-list-item__text rc-catalog-list-item__description", "data-test-automation-id": "description" },
            React.createElement(Highlighter, { highlightRegexp: this.getQueryRegex() }, description)));
    };
    CatalogSearchResultItem.prototype.render = function () {
        var _a = this.props, name = _a.name, testAutomationId = _a.testAutomationId;
        return (React.createElement("div", { className: "rc-catalog-search-result-item", "data-test-automation-id": testAutomationId },
            React.createElement("div", { className: "rc-catalog-search-result-item__side-content" }, this.renderIcon()),
            React.createElement("div", { className: "rc-catalog-search-result-item__content" },
                React.createElement("div", { className: "rc-catalog-list-item__text rc-catalog-list-item__name", "data-test-automation-id": "name" },
                    React.createElement(Highlighter, { highlightRegexp: this.getQueryRegex() }, name)),
                this.renderDescription()),
            React.createElement("div", { className: "rc-catalog-search-result-item__side-content" }, this.renderPrice())));
    };
    CatalogSearchResultItem.propTypes = {
        name: PropTypes.string.isRequired,
        description: PropTypes.string,
        price: PropTypes.object,
        icon: PropTypes.node.isRequired,
        color: PropTypes.string,
        isLoading: PropTypes.bool,
        query: PropTypes.string,
        testAutomationId: PropTypes.string
    };
    CatalogSearchResultItem.defaultProps = {
        description: null,
        price: null,
        color: null,
        isLoading: false,
        query: '',
        testAutomationId: 'catalogSearchResultItem'
    };
    return CatalogSearchResultItem;
}(React.PureComponent));
export { CatalogSearchResultItem };
//# sourceMappingURL=CatalogSearchResultItem.js.map