// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

import { isValidElement, cloneElement, Children } from 'react';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import Label from '../Label';
import Icon from '../Icon';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
/**
 * `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 = `${CLS_PREFIX}badge`,
    className,
    children,
    label,
    intent,
    hidden,
    ...props
  } = _ref;
  const isAmpty = !label;
  if (Children.toArray(children).length && !hidden) {
    if (! /*#__PURE__*/isValidElement(label)) {
      label = /*#__PURE__*/_jsx(Label, {
        intent: "danger",
        children: label
      });
    }
    if ( /*#__PURE__*/isValidElement(label)) {
      const cloneProps = {
        className: classNames(`${baseClassName}__value`, {
          [`${baseClassName}__value--dot`]: isAmpty
        }, label.props.className)
      };
      if (intent && (label.type === Label || label.type === Icon)) {
        cloneProps.intent = intent;
      }
      label = /*#__PURE__*/cloneElement(label, cloneProps);
    }
  } else {
    label = null;
  }
  return /*#__PURE__*/_jsxs("div", {
    className: classNames(baseClassName, className),
    ...props,
    children: [children, label]
  });
};
export default Badge;