// SPDX-License-Identifier: GPL-3.0-or-later

interface ProgressBarProps {
  value: number;
  max?: number;
  showLabel?: boolean;
  size?: 'sm' | 'md' | 'lg';
  color?: 'primary' | 'success' | 'warning' | 'danger';
  indeterminate?: boolean;
}

export default function ProgressBar({
  value,
  max = 100,
  showLabel = true,
  size = 'md',
  color = 'primary',
  indeterminate = false,
}: ProgressBarProps) {
  const percentage = Math.min(Math.max((value / max) * 100, 0), 100);

  const sizeClasses = {
    sm: 'h-1',
    md: 'h-2',
    lg: 'h-3',
  };

  const colorClasses = {
    primary: 'bg-primary-600',
    success: 'bg-green-600',
    warning: 'bg-yellow-500',
    danger: 'bg-red-600',
  };

  return (
    <div className="w-full">
      <div className={`w-full bg-slate-200 dark:bg-slate-700 rounded-full overflow-hidden ${sizeClasses[size]}`}>
        {indeterminate ? (
          <div
            className={`h-full ${colorClasses[color]} relative progress-indeterminate`}
            style={{ width: '100%' }}
          />
        ) : (
          <div
            className={`h-full ${colorClasses[color]} transition-all duration-300 ease-out rounded-full`}
            style={{ width: `${percentage}%` }}
          />
        )}
      </div>
      {showLabel && !indeterminate && (
        <div className="flex justify-between mt-1 text-xs text-slate-600 dark:text-slate-400">
          <span>{Math.round(percentage)}%</span>
        </div>
      )}
    </div>
  );
}
