'use client'; import { useState, useRef, useEffect } from 'react'; import Image from 'next/image'; import Link from 'next/link'; import AnimeRow from './AnimeRow'; import SeasonRow from './SeasonRow'; export default function AnimeDetails({ anime }) { const [isExpanded, setIsExpanded] = useState(false); const [activeVideo, setActiveVideo] = useState(null); const [activeTab, setActiveTab] = useState('synopsis'); const [synopsisOverflows, setSynopsisOverflows] = useState(false); const synopsisRef = useRef(null); console.log('AnimeDetails received:', anime); if (!anime?.info) { console.error('Invalid anime data structure:', anime); return null; } const { info, moreInfo, relatedAnime, recommendations, seasons } = anime; const hasCharacters = info.characterVoiceActor?.length > 0 || info.charactersVoiceActors?.length > 0; const hasVideos = info.promotionalVideos && info.promotionalVideos.length > 0; // Check if synopsis overflows when component mounts or when content changes useEffect(() => { if (synopsisRef.current) { const element = synopsisRef.current; setSynopsisOverflows(element.scrollHeight > element.clientHeight); } }, [info.description, activeTab]); // Video modal for promotional videos const VideoModal = ({ video, onClose }) => { if (!video) return null; return (
); }; // Format status with aired date const getStatusWithAired = () => { let status = moreInfo?.status || ''; if (moreInfo?.aired) { status += ` (${moreInfo.aired})`; } return status; }; return (
{/* Video Modal */} {activeVideo && setActiveVideo(null)} />} {/* Background Image with Gradient Overlay */}
{info.poster && ( <> {info.name}
)}
{/* Main Content */}
{/* Header Section - Title and Basic Info */}
{/* Poster */}
{info.name}
{/* Watch Button - Mobile & Desktop */} {info.stats?.episodes && (info.stats.episodes.sub > 0 || info.stats.episodes.dub > 0) && ( Start Watching )}
{/* Title and Metadata */}
{/* Title Section */}

{info.name}

{moreInfo?.japanese && (

{moreInfo.japanese}

)} {/* Synonyms */} {moreInfo?.synonyms && (

{moreInfo.synonyms}

)}
{/* Status Badges */}
{info.stats?.rating && (
{info.stats.rating}
)} {/* Status with Aired Date */} {moreInfo?.status && (
{getStatusWithAired()}
)} {info.stats?.type && (
{info.stats.type}
)} {info.stats?.episodes && (
{info.stats.episodes.sub > 0 && `SUB ${info.stats.episodes.sub}`} {info.stats.episodes.dub > 0 && info.stats.episodes.sub > 0 && ' | '} {info.stats.episodes.dub > 0 && `DUB ${info.stats.episodes.dub}`}
)} {info.stats?.quality && (
{info.stats.quality}
)} {info.stats?.duration && (
{info.stats.duration}
)}
{/* Genres & Studios */}
{/* Genres */} {moreInfo?.genres && moreInfo.genres.length > 0 && (

Genres

{moreInfo.genres.map((genre, index) => ( {genre} ))}
)} {/* Studios */} {moreInfo?.studios && (

Studios

{moreInfo.studios}
)}
{/* Details Tabs - Synopsis, Characters, Videos */}
{/* Tab Navigation */}
{hasCharacters && ( )} {hasVideos && ( )}
{/* Tab Content */}
{/* Synopsis Tab */} {activeTab === 'synopsis' && (

{info.description || 'No description available for this anime.'}

{synopsisOverflows && ( )}
)} {/* Characters Tab */} {activeTab === 'characters' && hasCharacters && (
{(info.characterVoiceActor || info.charactersVoiceActors || []).map((item, index) => (
{/* Character Image - No padding */}
{item.character.name}
{/* Text content in the middle */}
{/* Character Name */}

{item.character.name}

{item.character.cast || 'Main'}

{/* Voice Actor Name */}

{item.voiceActor.name}

{item.voiceActor.cast || 'Japanese'}

{/* Voice Actor Image - No padding */}
{item.voiceActor.name}
))}
)} {/* Videos Tab */} {activeTab === 'videos' && hasVideos && (
{info.promotionalVideos.map((video, index) => (
setActiveVideo(video)} >
{video.title
))}
)}
{/* Seasons Section */} {seasons && seasons.length > 0 && ( )} {/* Related Anime Section */} {relatedAnime && relatedAnime.length > 0 && ( )} {/* Recommendations Section */} {recommendations && recommendations.length > 0 && ( )}
); }