import { Progress } from '@/components/ui/progress';
import { useLang } from '@/hooks/use-lang';
import { Star } from 'lucide-react';
interface OverviewProps {
total_reviews: number;
rating_distribution: {
stars: number;
percentage: number;
}[];
}
const ReviewsOverview = ({ total_reviews, rating_distribution }: OverviewProps) => {
const { common, frontend } = useLang();
// Calculate average rating from distribution
const calculateAverageRating = () => {
if (!rating_distribution?.length || total_reviews === 0) {
return 0;
}
// Calculate weighted average
const totalScore = 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) => (
{total_reviews} {total_reviews === 1 ? 'Review' : 'Reviews'}