import PropTypes from 'prop-types';
import { Tooltip, Typography } from '@mui/material';
import { jsx as _jsx } from "react/jsx-runtime";
function shortenString(str, maxLength = 10) {
  if (typeof str === 'string' && str?.length > maxLength) {
    return `${str.slice(0, maxLength - 1)}...${str.slice(-2)}`;
  }
  return str;
}
function ShortenLabel({
  children,
  maxLength = 10,
  sx = null,
  hiddenTip = false
}) {
  if (children?.length <= maxLength) {
    return /*#__PURE__*/_jsx(Typography, {
      sx: sx,
      children: children
    });
  }
  if (hiddenTip) {
    return /*#__PURE__*/_jsx(Typography, {
      sx: sx,
      children: shortenString(children, maxLength)
    });
  }
  return /*#__PURE__*/_jsx(Tooltip, {
    title: children,
    placement: "top",
    children: /*#__PURE__*/_jsx(Typography, {
      sx: sx,
      children: shortenString(children, maxLength)
    })
  });
}
ShortenLabel.propTypes = {
  children: PropTypes.string.isRequired,
  maxLength: PropTypes.number,
  sx: PropTypes.object,
  hiddenTip: PropTypes.bool
};
export default ShortenLabel;