"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _text = _interopRequireDefault(require("../../atoms/text/text"));
var _pressable = _interopRequireDefault(require("../../atoms/pressable/pressable"));
var _pearl = require("../../../pearl");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
/**
 * CustomBadge is a component that renders a badge with a value.
 * The value can be a number, a string, or a React element.
 * If the value is a number or a string, it will be rendered inside a Text component.
 * If the value is a React element, it will be cloned and rendered as is.
 * If the value is an array, it will be joined into a string and rendered inside a Text component.
 * If the value is undefined, nothing will be rendered.
 */
const CustomBadge = /*#__PURE__*/_react.default.memo( /*#__PURE__*/_react.default.forwardRef(({
  children,
  atoms
}, ref) => {
  // Function to render the value of the badge
  const renderValue = (0, _react.useMemo)(() => {
    if (children === undefined) return null;

    // If children is an array, join it into a string
    if (Array.isArray(children)) children = children.join("");

    // If children is a number or a string, render it inside a Text component
    if (typeof children === "number" || typeof children === "string") return /*#__PURE__*/_react.default.createElement(_text.default, atoms.text, children);
    // If children is a React element, clone it and render it as is
    else return /*#__PURE__*/_react.default.cloneElement(children);
  }, [children, atoms]);
  return /*#__PURE__*/_react.default.createElement(_pressable.default, _extends({}, atoms.box, {
    ref: ref,
    alignItems: "center",
    justifyContent: "center"
  }), renderValue);
}));

/** A Badge is a small component typically used to communicate a numerical value or indicate the status of an item to the user. */
const Badge = (0, _pearl.pearl)(CustomBadge, {
  componentName: "Badge",
  type: "molecule",
  animatable: true
}, undefined, {
  partForOverridenStyleProps: "box",
  partForOverridenNativeProps: "box",
  partForOverridenAnimationProps: "box"
});
Badge.displayName = "Badge";
var _default = exports.default = Badge;
//# sourceMappingURL=badge.js.map