"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../constants");
var _Label = _interopRequireDefault(require("../Label"));
var _Icon = _interopRequireDefault(require("../Icon"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

/**
 * `Badge` component is used for showing small numerical value or status attached to an interface element.
 * @since 0.0.58
 */
const Badge = _ref => {
  let {
    baseClassName = `${_constants.CLS_PREFIX}badge`,
    className,
    children,
    label,
    intent,
    hidden,
    ...props
  } = _ref;
  const isAmpty = !label;
  if (_react.Children.toArray(children).length && !hidden) {
    if (! /*#__PURE__*/(0, _react.isValidElement)(label)) {
      label = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Label.default, {
        intent: "danger",
        children: label
      });
    }
    if ( /*#__PURE__*/(0, _react.isValidElement)(label)) {
      const cloneProps = {
        className: (0, _classnames.default)(`${baseClassName}__value`, {
          [`${baseClassName}__value--dot`]: isAmpty
        }, label.props.className)
      };
      if (intent && (label.type === _Label.default || label.type === _Icon.default)) {
        cloneProps.intent = intent;
      }
      label = /*#__PURE__*/(0, _react.cloneElement)(label, cloneProps);
    }
  } else {
    label = null;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)(baseClassName, className),
    ...props,
    children: [children, label]
  });
};
var _default = exports.default = Badge;