import { Star, StarHalf, StarOff } from 'lucide-react';
import { cn } from '@/lib/utils';

interface StarRatingProps {
  rating: number;
  totalStars?: number;
  className?: string;
  starClassName?: string;
}

export default function StarRating({
  rating,
  totalStars = 5,
  className,
  starClassName
}: StarRatingProps) {
  const fullStars = Math.floor(rating);
  const halfStar = rating % 1 !== 0;
  const emptyStars = totalStars - fullStars - (halfStar ? 1 : 0);

  return (
    <div className={cn("flex items-center gap-0.5", className)}>
      {[...Array(fullStars)].map((_, i) => (
        <Star key={`full-${i}`} className={cn("h-5 w-5 fill-yellow-400 text-yellow-400", starClassName)} />
      ))}
      {halfStar && <StarHalf className={cn("h-5 w-5 fill-yellow-400 text-yellow-400", starClassName)} />}
      {[...Array(emptyStars)].map((_, i) => (
        <Star key={`empty-${i}`} className={cn("h-5 w-5 text-muted-foreground/30", starClassName)} />
      ))}
    </div>
  );
}
