import LinearProgress from "@mui/material/LinearProgress";
import Box from "@mui/material/Box";

export type ProgressColor =
  | "primary"
  | "success"
  | "warning"
  | "error"
  | "info";

/** Determinate linear progress bar. `value` is 0–100 (clamped). */
export default function ProgressBar({
  value,
  color = "primary",
  height = 8,
  label,
}: {
  value: number;
  color?: ProgressColor;
  height?: number;
  /** Accessible name for the progress bar (announced by screen readers). */
  label?: string;
}) {
  const clamped = Number.isFinite(value)
    ? Math.max(0, Math.min(100, value))
    : 0;
  return (
    <Box sx={{ width: "100%" }}>
      <LinearProgress
        variant="determinate"
        value={clamped}
        color={color}
        aria-label={label ?? `Průběh ${Math.round(clamped)} %`}
        sx={{ height, borderRadius: height / 2 }}
      />
    </Box>
  );
}
