import { forwardRef, type HTMLAttributes } from 'react';
import { cn } from '@/lib/cn';

interface ProgressProps extends HTMLAttributes<HTMLDivElement> {
  value?: number;
  max?: number;
}

const Progress = forwardRef<HTMLDivElement, ProgressProps>(
  ({ className, value = 0, max = 100, ...props }, ref) => {
    const percentage = Math.min(Math.max((value / max) * 100, 0), 100);

    return (
      <div
        ref={ref}
        role="progressbar"
        aria-valuemin={0}
        aria-valuemax={max}
        aria-valuenow={value}
        className={cn(
          'relative h-2 w-full overflow-hidden rounded-full bg-gray-200',
          className,
        )}
        {...props}
      >
        <div
          className="h-full rounded-full bg-[#FF6B00] transition-all"
          style={{ width: `${percentage}%` }}
        />
      </div>
    );
  },
);

Progress.displayName = 'Progress';

export { Progress };
