"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
            t[p[i]] = s[p[i]];
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var ColorHash = require("color-hash");
var assign = require("lodash/assign");
var memoize = require("lodash/memoize");
var React = require("react");
var styled_components_1 = require("styled-components");
var asRendition_1 = require("../asRendition");
var utils_1 = require("../utils");
var Txt_1 = require("./Txt");
var colorHash = new ColorHash();
var backgroundColor = memoize(function (text) {
    return colorHash.hex(text.replace(/\s/g, ''));
});
var BaseBadge = styled_components_1.default(Txt_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\tborder-radius: ", ";\n\tdisplay: inline-block;\n\tmin-width: 40px;\n\ttext-align: center;\n\tfont-weight: 800;\n\tfont-style: normal;\n\tfont-stretch: normal;\n\tletter-spacing: 0.5px;\n"], ["\n\tborder-radius: ", ";\n\tdisplay: inline-block;\n\tmin-width: 40px;\n\ttext-align: center;\n\tfont-weight: 800;\n\tfont-style: normal;\n\tfont-stretch: normal;\n\tletter-spacing: 0.5px;\n"])), function (props) { return utils_1.px(props.theme.radius); });
var Badge = function (_a) {
    var xsmall = _a.xsmall, small = _a.small, children = _a.children, theme = _a.theme, props = __rest(_a, ["xsmall", "small", "children", "theme"]);
    var fontSize = 2;
    if (small) {
        fontSize = 1;
    }
    if (xsmall) {
        fontSize = 10;
    }
    if (typeof children !== 'string') {
        throw new Error("The child element of the Badge component must be a string, received: " + typeof children);
    }
    return (React.createElement(BaseBadge, __assign({ p: "2px 5px", fontSize: fontSize }, props, { color: props.color || '#fff', bg: utils_1.getColor(assign(props, { theme: theme }), 'bg', 'main') ||
            backgroundColor(children) }), children));
};
exports.default = asRendition_1.default(Badge, [], ['bg', 'color']);
var templateObject_1;
