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

import Label from '../Label';
import Tooltip from '../Tooltip';
import { jsx as _jsx } from "react/jsx-runtime";
const GroupLabel = _ref => {
  let {
    group,
    onClose
  } = _ref;
  const {
    renderHeaderLabel,
    renderHeaderLabelTitle,
    closable = false,
    renderHeaderLabelTooltip = closable ? () => 'Close group' : undefined,
    intent
  } = group;
  if (!renderHeaderLabel && !renderHeaderLabelTitle) {
    return null;
  }
  const handleClick = closable ? onClose : undefined;
  const labelProps = {
    intent,
    onClick: handleClick,
    icon: closable ? 'cross-mark' : undefined,
    children: renderHeaderLabelTitle ? renderHeaderLabelTitle(group) : null,
    caps: false,
    size: 'md'
  };
  if (renderHeaderLabel) {
    return renderHeaderLabel(group, labelProps);
  }
  const wrapInTooltip = content => {
    if (!renderHeaderLabelTooltip) return content;
    const title = renderHeaderLabelTooltip(group);
    if (!title) return content;
    return /*#__PURE__*/_jsx(Tooltip, {
      title: title,
      children: content
    });
  };
  const label = /*#__PURE__*/_jsx(Label, {
    ...labelProps
  });
  return wrapInTooltip(label);
};
export default GroupLabel;