import { Link } from 'react-router-dom'; import { FaFire } from 'react-icons/fa'; // Changed FaStar to FaFire import { getFileUrl } from '../../services/pocketbaseService'; // Corrected import path import { useEffect } from 'react'; // Import useEffect for logging import { useAuth } from '../../contexts/AuthContext'; // Import useAuth // MediaCard component displays a card for a media item. // It now accepts averageRating and reviewCount props from the parent. // Added userProfile prop to check admin/critic role function MediaCard({ media, userProfile }) { // Destructure media properties, including the new ones from Supabase // Use 'path' for the link instead of 'id' // Используем 'poster' вместо 'poster_url' для имени файла const { id, title, poster, average_rating, review_count, release_date, type, path, is_published } = media; // Added is_published // Используем getFileUrl для получения URL постера const posterUrl = getFileUrl(media, 'poster'); // Используем имя поля 'poster' const releaseDate = release_date; const averageRating = average_rating; // This is the 10-point average from Supabase const reviewCount = review_count; // Use the 'path' field for the link const mediaLink = path ? `/media/${path}` : `/media/${id}`; // Fallback to id if path is missing (for old data) // Check if the current user is admin or critic const isAdminOrCritic = userProfile && (userProfile.role === 'admin' || userProfile.is_critic === true); // Add log to check average_rating and review_count here when component mounts or media prop changes useEffect(() => { console.log(`MediaCard for "${title}" rendered with media prop:`, media); console.log(`MediaCard for "${title}" stats:`, { average_rating: averageRating, review_count: reviewCount, is_published: is_published }); }, [media]); return (
{/* Added relative for absolute positioning */}
{/* Используем posterUrl, полученный через getFileUrl */} {title} {/* Display average rating and review count */} {/* Проверяем, что average_rating не null и не undefined перед отображением */} {/* Ensure average_rating is treated as a number */} {average_rating !== null && average_rating !== undefined && !isNaN(parseFloat(average_rating)) && (
{/* Changed FaStar to FaFire */} {/* Форматируем average_rating до одной десятичной */} {parseFloat(average_rating).toFixed(1)} / 10 {/* Optionally display review count */} {/* {review_count !== null && review_count !== undefined && ( ({review_count}) )} */}
)} {/* Admin/Critic mark for unpublished media */} {isAdminOrCritic && !is_published && (
Не опубликовано
)}

{title}

{releaseDate ? new Date(releaseDate).getFullYear() : 'N/A'}
); } export default MediaCard;