"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Badge", {
    enumerable: true,
    get: function() {
        return Badge;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _define_property = require("@swc/helpers/_/_define_property");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _type_of = require("@swc/helpers/_/_type_of");
var _react = /*#__PURE__*/ _interop_require_default._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _typings = require("../../utils/typings");
var _configprovider = require("../configprovider");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    value: '',
    dot: false,
    max: 99,
    top: 0,
    right: 0,
    fill: 'solid',
    size: 'large'
});
var Badge = function Badge(props) {
    var isIcon = function isIcon() {
        if ((typeof value === "undefined" ? "undefined" : (0, _type_of._)(value)) === 'object' && value) return value;
    };
    var isNumber = function isNumber() {
        if (typeof value === 'number' && value) return value;
    };
    var isString = function isString() {
        if (typeof value === 'string' && value) return value;
    };
    var _this;
    var rtl = (0, _configprovider.useRtl)();
    var _$_object_spread = (0, _object_spread._)({}, defaultProps, props), className = _$_object_spread.className, style = _$_object_spread.style, value = _$_object_spread.value, max = _$_object_spread.max, children = _$_object_spread.children, dot = _$_object_spread.dot, top = _$_object_spread.top, right = _$_object_spread.right, fill = _$_object_spread.fill, size = _$_object_spread.size;
    var classPrefix = 'nut-badge';
    var classes = (0, _classnames.default)(classPrefix, className);
    var getContent = function getContent() {
        if (dot || value === 0) return null;
        if (typeof value === 'number') {
            return max < value ? "".concat(max, "+") : "".concat(value);
        }
        return value;
    };
    var _obj;
    var contentClasses = (0, _classnames.default)((_obj = {}, (0, _define_property._)(_obj, "".concat(classPrefix, "-sup"), isNumber() || isString() || dot), (0, _define_property._)(_obj, "".concat(classPrefix, "-number"), isNumber()), (0, _define_property._)(_obj, "".concat(classPrefix, "-one"), typeof getContent() === 'string' && ((_this = "".concat(getContent())) === null || _this === void 0 ? void 0 : _this.length) === 1), (0, _define_property._)(_obj, "".concat(classPrefix, "-dot"), dot), (0, _define_property._)(_obj, "".concat(classPrefix, "-dot-").concat(size), dot), (0, _define_property._)(_obj, "".concat(classPrefix, "-").concat(fill), fill === 'outline'), (0, _define_property._)(_obj, "".concat(classPrefix, "-content"), children), _obj));
    var getPositionStyle = function getPositionStyle() {
        return (0, _define_property._)({
            top: "".concat(Number(top) || 0, "px")
        }, rtl ? 'left' : 'right', "".concat(Number(right) || 0, "px"));
    };
    var _obj1;
    return /*#__PURE__*/ _react.default.createElement("div", {
        className: classes,
        style: style
    }, isIcon() && /*#__PURE__*/ _react.default.createElement("div", {
        className: (0, _classnames.default)("".concat(classPrefix, "-content"), (_obj1 = {}, (0, _define_property._)(_obj1, "".concat(classPrefix, "-icon"), true), (0, _define_property._)(_obj1, "".concat(classPrefix, "-icon-rtl"), rtl), _obj1)),
        style: getPositionStyle()
    }, value), children, !isIcon() && (getContent() || dot) && /*#__PURE__*/ _react.default.createElement("div", {
        className: contentClasses,
        style: getPositionStyle()
    }, getContent()));
};
Badge.displayName = 'NutBadge';
