'use client'; import { useState, useEffect, useRef } from 'react'; import Image from 'next/image'; import { tvAPI } from '@/lib/api'; import { getImageUrl } from '@/lib/neoApi'; import type { TVShowDetails } from '@/lib/api'; import MoviePlayer from '@/components/MoviePlayer'; import TorrentSelector from '@/components/TorrentSelector'; import FavoriteButton from '@/components/FavoriteButton'; import Reactions from '@/components/Reactions'; import { formatDate } from '@/lib/utils'; import { PlayCircle, ArrowLeft } from 'lucide-react'; interface TVContentProps { showId: string; initialShow: TVShowDetails; } export default function TVContent({ showId, initialShow }: TVContentProps) { const [show] = useState(initialShow); const [imdbId, setImdbId] = useState(null); const [isPlayerFullscreen, setIsPlayerFullscreen] = useState(false); const [isControlsVisible, setIsControlsVisible] = useState(false); const controlsTimeoutRef = useRef(null); useEffect(() => { const fetchImdbId = async () => { try { // Используем dedicated эндпоинт для получения IMDb ID const { data } = await tvAPI.getImdbId(showId); if (data?.imdb_id) { setImdbId(data.imdb_id); } } catch (err) { console.error('Error fetching IMDb ID:', err); } }; // Проверяем, есть ли ID в initialShow, чтобы избежать лишнего запроса if (initialShow.external_ids?.imdb_id) { setImdbId(initialShow.external_ids.imdb_id); } else { fetchImdbId(); } }, [showId, initialShow.external_ids]); const showControls = () => { if (controlsTimeoutRef.current) { clearTimeout(controlsTimeoutRef.current); } setIsControlsVisible(true); controlsTimeoutRef.current = setTimeout(() => { setIsControlsVisible(false); }, 3000); }; const handleOpenPlayer = () => { setIsPlayerFullscreen(true); showControls(); }; const handleClosePlayer = () => { setIsPlayerFullscreen(false); if (controlsTimeoutRef.current) { clearTimeout(controlsTimeoutRef.current); } }; return ( <>
{`Постер

{show.name}

{show.tagline && (

{show.tagline}

)}
Рейтинг: {show.vote_average.toFixed(1)} | Сезонов: {show.number_of_seasons} | {formatDate(show.first_air_date)}
{show.genres.map((genre) => ( {genre.name} ))}

{show.overview}

{imdbId && ( )}
{imdbId && (
)}
{isPlayerFullscreen && imdbId && (
)} ); }