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 classnames from 'classnames';
import { Icon } from '../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.createElement("div", { className: "rc-catalog-item-icon__icon--close" },
                React.createElement(Icon, { name: "close" })));
        }
        return (React.createElement("div", { className: "rc-catalog-item-icon__icon" },
            React.createElement(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('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.createElement("div", { style: style, className: className, "data-test-automation-id": testAutomationId }, this.renderIcon()));
    };
    CatalogItemIcon.propTypes = {
        iconName: PropTypes.string,
        backgroundColor: PropTypes.string,
        size: PropTypes.number,
        isRound: PropTypes.bool,
        testAutomationId: PropTypes.string
    };
    CatalogItemIcon.defaultProps = {
        iconName: null,
        backgroundColor: null,
        size: 60,
        isRound: null,
        testAutomationId: 'catalogItemIcon'
    };
    return CatalogItemIcon;
}(React.PureComponent));
export { CatalogItemIcon };
//# sourceMappingURL=CatalogItemIcon.js.map