interface Props {
  name: string;
  /** Tricks won this round. */
  won: number;
  /** Bid for this round (null until the player has guessed). */
  guess: number | null;
  /** Whether it is this player's turn — the only state that highlights a circle. */
  active: boolean;
  size?: number;
}

export default function PlayerCircle({ name, won, guess, active, size = 52 }: Props) {
  const nameFont = Math.max(9, Math.round(size * 0.17));
  const valueFont = Math.round(size * 0.32);
  // Oval: height a touch shorter than size so it reads as an ellipse. Width
  // starts at `size` (a circle for short names) but grows with the name via
  // fit-content + padding, up to a cap beyond which the name is ellipsised
  // rather than wrapping (wrapping would break the fixed height/oval shape).
  const height = Math.round(size * 0.78);
  const hPad = Math.round(size * 0.16);
  const maxWidth = Math.round(size * 2);

  return (
    <div
      // Only the active player is highlighted (gold ring + glow) — colors come
      // from the velvet-table palette tokens (tailwind.config.js), not literals.
      className={`flex flex-col items-center justify-center rounded-full ${
        active ? 'bg-circle-active border-2 border-gold' : 'bg-circle border-[1.5px] border-gold/20'
      }`}
      style={{
        width: 'fit-content',
        minWidth: size,
        maxWidth,
        height,
        paddingLeft: hPad,
        paddingRight: hPad,
        boxShadow: '0 2px 10px rgba(0,0,0,.45)',
        animation: active ? 'ar 2.2s ease-in-out infinite' : undefined,
      }}
    >
      <span
        className={`uppercase leading-tight text-center overflow-hidden text-ellipsis whitespace-nowrap max-w-full ${active ? 'text-gold' : 'text-green-circle'}`}
        style={{
          fontFamily: '"DM Sans",sans-serif',
          fontSize: nameFont,
          letterSpacing: '.09em',
          fontWeight: 500,
        }}
      >
        {name}
      </span>
      <span
        className={`leading-none ${active ? 'text-gold-bright' : 'text-gold'}`}
        style={{
          fontFamily: '"Playfair Display",serif',
          fontSize: valueFont,
          fontWeight: active ? 700 : 400,
        }}
      >
        {won}
        <span style={{ fontSize: valueFont * 0.6, color: '#b0a585' }}>/{guess ?? '?'}</span>
      </span>
    </div>
  );
}
