import getAnimeInfo from "@/src/utils/getAnimeInfo.utils"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faPlay, faClosedCaptioning, faMicrophone, } from "@fortawesome/free-solid-svg-icons"; import { useEffect, useState } from "react"; import { Link, useNavigate, useParams } from "react-router-dom"; import website_name from "@/src/config/website"; import CategoryCard from "@/src/components/categorycard/CategoryCard"; import Sidecard from "@/src/components/sidecard/Sidecard"; import Loader from "@/src/components/Loader/Loader"; import Error from "@/src/components/error/Error"; import { useLanguage } from "@/src/context/LanguageContext"; import { useHomeInfo } from "@/src/context/HomeInfoContext"; import Voiceactor from "@/src/components/voiceactor/Voiceactor"; function InfoItem({ label, value, isProducer = true }) { return ( value && (
{`${label}: `} {Array.isArray(value) ? ( value.map((item, index) => isProducer ? ( :;,.?/\\|{}[\]`~*_]/g, "") .split(" ") .join("-") .replace(/-+/g, "-")}`} key={index} className="cursor-pointer hover:text-[#ffbade]" > {item} {index < value.length - 1 && ", "} ) : ( {item} ) ) ) : isProducer ? ( :;,.?/\\|{}[\]`~*_]/g, "") .split(" ") .join("-") .replace(/-+/g, "-")}`} className="cursor-pointer hover:text-[#ffbade]" > {value} ) : ( {value} )}
) ); } function Tag({ bgColor, index, icon, text }) { return (
{icon && }

{text}

); } function AnimeInfo({ random = false }) { const { language } = useLanguage(); const { id: paramId } = useParams(); const id = random ? null : paramId; const [isFull, setIsFull] = useState(false); const [animeInfo, setAnimeInfo] = useState(null); const [seasons, setSeasons] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const { homeInfo } = useHomeInfo(); const { id: currentId } = useParams(); const navigate = useNavigate(); useEffect(() => { if (id === "404-not-found-page") { console.log("404 got!"); return null; } else { const fetchAnimeInfo = async () => { setLoading(true); try { const data = await getAnimeInfo(id, random); setSeasons(data?.seasons); setAnimeInfo(data.data); } catch (err) { console.error("Error fetching anime info:", err); setError(err); } finally { setLoading(false); } }; fetchAnimeInfo(); window.scrollTo({ top: 0, behavior: "smooth" }); } }, [id, random]); useEffect(() => { if (animeInfo && location.pathname === `/${animeInfo.id}`) { document.title = `Watch ${animeInfo.title} English Sub/Dub online Free on ${website_name}`; } return () => { document.title = `${website_name} | Free anime streaming platform`; }; }, [animeInfo]); if (loading) return ; if (error) { return ; } if (!animeInfo) { navigate("/404-not-found-page"); return undefined; } const { title, japanese_title, poster, animeInfo: info } = animeInfo; const tags = [ { condition: info.tvInfo?.rating, bgColor: "#ffffff", text: info.tvInfo.rating, }, { condition: info.tvInfo?.quality, bgColor: "#FFBADE", text: info.tvInfo.quality, }, { condition: info.tvInfo?.sub, icon: faClosedCaptioning, bgColor: "#B0E3AF", text: info.tvInfo.sub, }, { condition: info.tvInfo?.dub, icon: faMicrophone, bgColor: "#B9E7FF", text: info.tvInfo.dub, }, ]; return ( <>
{`${title}
{`${title} {animeInfo.adultContent && (
18+
)}
    {[ ["Home", "home"], [info.tvInfo?.showType, info.tvInfo?.showType], ].map(([text, link], index) => (
  • {text}
  • ))}

    {language === "EN" ? title : japanese_title}

{language === "EN" ? title : japanese_title}

{tags.map( ({ condition, icon, bgColor, text }, index) => condition && ( ) )}
{[info.tvInfo?.showType, info.tvInfo?.duration].map( (item, index) => item && (

{item}

) )}
{animeInfo?.animeInfo?.Status?.toLowerCase() !== "not-yet-aired" ? (

Watch Now

) : (

Not released

)} {info?.Overview && (
{info.Overview.length > 270 ? ( <> {isFull ? info.Overview : `${info.Overview.slice(0, 270)}...`} setIsFull(!isFull)} > {isFull ? "- Less" : "+ More"} ) : ( info.Overview )}
)}

{`${website_name} is the best site to watch `} {title} {` SUB online, or you can even watch `} {title} {` DUB in HD quality.`}

Share Anime

Share Anime

to your friends

{info?.Overview && (

Overview:

{info.Overview}

)} {[ { label: "Japanese", value: info?.Japanese }, { label: "Synonyms", value: info?.Synonyms }, { label: "Aired", value: info?.Aired }, { label: "Premiered", value: info?.Premiered }, { label: "Duration", value: info?.Duration }, { label: "Status", value: info?.Status }, { label: "MAL Score", value: info?.["MAL Score"] }, ].map(({ label, value }, index) => ( ))} {info?.Genres && (

Genres:

{info.Genres.map((genre, index) => ( {genre} ))}
)} {[ { label: "Studios", value: info?.Studios }, { label: "Producers", value: info?.Producers }, ].map(({ label, value }, index) => ( ))}

{`${website_name} is the best site to watch `} {title} {` SUB online, or you can even watch `} {title} {` DUB in HD quality.`}

{seasons?.length > 0 && (

More Seasons

{seasons.map((season, index) => (

{season.season}

))}
)} {animeInfo?.charactersVoiceActors.length > 0 && ( )} {animeInfo.recommended_data.length > 0 && ( )}
{animeInfo.related_data.length > 0 && ( )} {homeInfo && homeInfo.most_popular && ( )}
); } export default AnimeInfo;