/** Spinner — an indeterminate loading indicator (LD). */

import { cn } from "../lib/cn";

export interface SpinnerProps {
  /** Diameter in pixels. Defaults to 16. */
  size?: number;
  /** Extra classes (e.g. a colour override). */
  className?: string;
  /** Accessible label; defaults to "Loading". */
  label?: string;
}

/** A CSS-only spinning ring that inherits the current text colour. */
export function Spinner({ size = 16, className, label = "Loading" }: SpinnerProps) {
  return (
    <span
      role="status"
      aria-label={label}
      className={cn(
        "inline-block animate-spin rounded-full border-2 border-current border-t-transparent",
        className,
      )}
      style={{ width: size, height: size }}
    />
  );
}
