"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 classnames_1 = __importDefault(require("classnames"));
var Icon_1 = require("../Icon");
var COLORS = ['#ff4c57', '#00bcff', '#8b7cff', '#19adcf', '#ff7c00'];
var getColorForString = function (text) {
    var numberHash = text.split('').reduce(function (acc, char) { return acc + char.charCodeAt(0); }, 0);
    return COLORS[numberHash % COLORS.length];
};
var CatalogItemIcon = /** @class */ (function (_super) {
    __extends(CatalogItemIcon, _super);
    function CatalogItemIcon() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CatalogItemIcon.prototype.renderIcon = function () {
        var iconName = this.props.iconName;
        if (!iconName) {
            return (react_1.default.createElement("div", { className: "rc-catalog-item-icon__icon--close" },
                react_1.default.createElement(Icon_1.Icon, { name: "close" })));
        }
        return (react_1.default.createElement("div", { className: "rc-catalog-item-icon__icon" },
            react_1.default.createElement(Icon_1.Icon, { name: iconName })));
    };
    CatalogItemIcon.prototype.render = function () {
        var _a = this.props, testAutomationId = _a.testAutomationId, iconName = _a.iconName, backgroundColor = _a.backgroundColor, size = _a.size, isRound = _a.isRound;
        var className = classnames_1.default('rc-catalog-item-icon', {
            'rc-catalog-item-icon--round': isRound,
            'rc-catalog-item-icon--placeholder': !iconName
        });
        var style = {
            fontSize: size + "px"
        };
        if (iconName) {
            style.backgroundColor = backgroundColor || getColorForString(iconName);
        }
        return (react_1.default.createElement("div", { style: style, className: className, "data-test-automation-id": testAutomationId }, this.renderIcon()));
    };
    CatalogItemIcon.propTypes = {
        iconName: prop_types_1.default.string,
        backgroundColor: prop_types_1.default.string,
        size: prop_types_1.default.number,
        isRound: prop_types_1.default.bool,
        testAutomationId: prop_types_1.default.string
    };
    CatalogItemIcon.defaultProps = {
        iconName: null,
        backgroundColor: null,
        size: 60,
        isRound: null,
        testAutomationId: 'catalogItemIcon'
    };
    return CatalogItemIcon;
}(react_1.default.PureComponent));
exports.CatalogItemIcon = CatalogItemIcon;
//# sourceMappingURL=CatalogItemIcon.js.map