'use client'; import { useState, useEffect, useRef } from 'react'; import Image from 'next/image'; import { tvShowsAPI } from '@/lib/neoApi'; import { getImageUrl } from '@/lib/neoApi'; import type { TVShowDetails } from '@/lib/neoApi'; 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'; import { NextSeo } from 'next-seo'; interface TVContentProps { showId: string; initialShow: TVShowDetails; } export default function TVContent({ showId, initialShow }: TVContentProps) { const [show] = useState(initialShow); const [externalIds, setExternalIds] = useState(null); const [imdbId, setImdbId] = useState(null); const [isPlayerFullscreen, setIsPlayerFullscreen] = useState(false); const [isControlsVisible, setIsControlsVisible] = useState(false); const controlsTimeoutRef = useRef(null); useEffect(() => { const fetchExternalIds = async () => { try { const data = await tvShowsAPI.getExternalIds(showId); setExternalIds(data); if (data?.imdb_id) { setImdbId(data.imdb_id); } } catch (err) { console.error('Error fetching external ids:', err); } }; if (initialShow.external_ids?.imdb_id) { setImdbId(initialShow.external_ids.imdb_id); } else { fetchExternalIds(); } }, [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 ( <> {/* schema.org TVSeries */}