import { Progress } from '@/components/ui/progress';
import { useLang } from '@/hooks/use-lang';
import { Star } from 'lucide-react';
interface StudentFeedbackProps {
totalReviews: CourseTotalReview;
}
const StudentFeedback = ({ totalReviews }: StudentFeedbackProps) => {
const { common, frontend } = useLang();
// Calculate average rating from distribution
const calculateAverageRating = () => {
if (!totalReviews?.rating_distribution?.length || totalReviews.total_reviews === 0) {
return 0;
}
// Calculate weighted average
const totalScore = totalReviews.rating_distribution.reduce((sum, item) => {
return sum + item.stars * (item.percentage / 100);
}, 0);
// Round to 1 decimal place
return Math.round(totalScore * 10) / 10;
};
const averageRating = calculateAverageRating();
const renderStars = (rating: number, filled: boolean = true): JSX.Element[] => {
return Array.from({ length: 5 }, (_, index) => (
{totalReviews.total_reviews} {totalReviews.total_reviews === 1 ? 'Review' : 'Reviews'}