"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _constants = require("../../constants");

var _Label = _interopRequireDefault(require("../Label"));

var _Icon = _interopRequireDefault(require("../Icon"));

// Copyright 1999-2020. 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 = ({
  baseClassName = "".concat(_constants.CLS_PREFIX, "badge"),
  className,
  children,
  label,
  intent,
  hidden,
  ...props
}) => {
  const isAmpty = !label;

  if (_react.Children.toArray(children).length && !hidden) {
    if (! /*#__PURE__*/(0, _react.isValidElement)(label)) {
      label = /*#__PURE__*/_react.default.createElement(_Label.default, {
        intent: "danger"
      }, label);
    }

    if ( /*#__PURE__*/(0, _react.isValidElement)(label)) {
      const cloneProps = {
        className: (0, _classnames.default)("".concat(baseClassName, "__value"), {
          ["".concat(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__*/_react.default.createElement("div", (0, _extends2.default)({
    className: (0, _classnames.default)(baseClassName, className)
  }, props), children, label);
};

var _default = Badge;
exports.default = _default;