import React from "react";

export function Progress({ value = 0, max = 100, label, showValue = false, className = "", ...props }) {
  const pct = Math.max(0, Math.min(100, (value / max) * 100));
  return (
    <div className={["o-progress", className].filter(Boolean).join(" ")} data-slot="progress" role="progressbar" aria-valuenow={value} aria-valuemax={max} {...props}>
      {label || showValue ? (
        <div className="o-row" style={{ justifyContent: "space-between" }}>
          {label ? <span className="o-progress__label" data-slot="progress-label">{label}</span> : <span />}
          {showValue ? <span className="o-progress__value" data-slot="progress-value">{Math.round(pct)}%</span> : null}
        </div>
      ) : null}
      <span className="o-progress__track" data-slot="progress-track">
        <span className="o-progress__indicator" data-slot="progress-indicator" style={{ width: pct + "%", display: "block" }} />
      </span>
    </div>
  );
}
