function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import React, { forwardRef } from "react";
import { cx } from "../../utils";
import { base as viewCSS } from "./variations/_view/base";
import { base as sizeCSS } from "./variations/_size/base";
import { base as pilledCSS } from "./variations/_pilled/base";
import { base as transparentCSS } from "./variations/_transparent/base";
import { base as clearCSS } from "./variations/_clear/base";
import { StyledContentLeft, StyledContentMain, StyledContentRight, base } from "./Badge.styles";
import { classes, privateTokens } from "./Badge.tokens";
export var badgeRoot = function badgeRoot(Root) {
    return /*#__PURE__*/ forwardRef(function(props, ref) {
        var children = props.children, className = props.className, style = props.style, text = props.text, contentLeft = props.contentLeft, contentRight = props.contentRight, size = props.size, view = props.view, customColor = props.customColor, customBackgroundColor = props.customBackgroundColor, _props_pilled = props.pilled, pilled = _props_pilled === void 0 ? false : _props_pilled, _props_transparent = props.transparent, transparent = _props_transparent === void 0 ? false : _props_transparent, _props_clear = props.clear, clear = _props_clear === void 0 ? false : _props_clear, _props_maxWidth = props.maxWidth, maxWidth = _props_maxWidth === void 0 ? 'auto' : _props_maxWidth, rest = _object_without_properties(props, [
            "children",
            "className",
            "style",
            "text",
            "contentLeft",
            "contentRight",
            "size",
            "view",
            "customColor",
            "customBackgroundColor",
            "pilled",
            "transparent",
            "clear",
            "maxWidth"
        ]);
        var pilledClass = pilled ? classes.badgePilled : undefined;
        var transparentClass = transparent ? classes.badgeTransparent : undefined;
        var clearClass = clear ? classes.badgeClear : undefined;
        var truncateClass = maxWidth !== 'auto' ? classes.badgeTruncate : undefined;
        var txt = !text && typeof children === 'string' ? children : text;
        var iconOnlyClass = !txt && contentLeft ? classes.iconOnly : undefined;
        var BadgeContent = function BadgeContent() {
            if (contentLeft) {
                return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(StyledContentLeft, null, contentLeft), txt ? /*#__PURE__*/ React.createElement(StyledContentMain, null, txt) : children);
            }
            return /*#__PURE__*/ React.createElement(React.Fragment, null, txt ? /*#__PURE__*/ React.createElement(StyledContentMain, null, txt) : children, contentRight && /*#__PURE__*/ React.createElement(StyledContentRight, null, contentRight));
        };
        var _obj;
        return /*#__PURE__*/ React.createElement(Root, _object_spread({
            ref: ref,
            className: cx(pilledClass, transparentClass, clearClass, truncateClass, iconOnlyClass, className),
            view: view,
            size: size,
            pilled: pilled,
            transparent: transparent,
            clear: clear,
            style: _object_spread_props(_object_spread({}, style), (_obj = {
                maxWidth: maxWidth
            }, _define_property(_obj, privateTokens.customBackground, customBackgroundColor), _define_property(_obj, privateTokens.customColor, customColor), _obj))
        }, rest), /*#__PURE__*/ React.createElement(BadgeContent, null));
    });
};
export var badgeConfig = {
    name: 'Badge',
    tag: 'div',
    layout: badgeRoot,
    base: base,
    variations: {
        view: {
            css: viewCSS
        },
        size: {
            css: sizeCSS
        },
        pilled: {
            css: pilledCSS,
            attrs: true
        },
        transparent: {
            css: transparentCSS,
            attrs: true
        },
        clear: {
            css: clearCSS,
            attrs: true
        }
    },
    defaults: {
        view: 'primary',
        size: 'm'
    }
};
