import { FC } from 'react';

import Chip, { ChipProps } from '@material-hu/mui/Chip';

const COUNT_LIMIT = 99;

/** @deprecated — Use Badge from @material-hu/components/design-system/Badge instead */
type BadgeProps = ChipProps & {
  count: number;
  isUnread?: boolean;
  limit?: number;
  isOnlyBadge?: boolean;
};

/** @deprecated — Use Badge from @material-hu/components/design-system/Badge instead */
const Badge: FC<BadgeProps> = props => {
  const {
    count,
    limit = COUNT_LIMIT,
    isUnread,
    isOnlyBadge = false,
    ...chipProps
  } = props;

  if (!isUnread && !(count && count > 0)) return null;

  let label = `${count}`;
  if (isUnread || isOnlyBadge) label = '';
  else if (count > limit) label = `+${limit}`;

  return (
    <Chip
      color="primary"
      label={label}
      size="small"
      sx={{
        height: 18,
        minWidth: isOnlyBadge ? 18 : 23,
        px: 1,
        ml: 1,
        '& .MuiChip-label': {
          overflow: 'unset',
          p: 0,
        },
      }}
      {...chipProps}
    />
  );
};

export default Badge;
