"use strict";

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"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// 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 = `${_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)(`${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__*/_react.default.createElement("div", (0, _extends2.default)({
    className: (0, _classnames.default)(baseClassName, className)
  }, props), children, label);
};

var _default = Badge;
exports.default = _default;