import { Textfit } from "react-textfit"; import Image from "next/image"; import { useEffect, useRef, useState } from "react"; import { convertUnixToTime } from "../../utils/getTimes"; import { PlayIcon } from "@heroicons/react/20/solid"; import { BackwardIcon, ForwardIcon } from "@heroicons/react/24/solid"; import Link from "next/link"; export default function Schedule({ data, scheduleData, time }) { let now = new Date(); let currentDay = now.toLocaleString("default", { weekday: "long" }).toLowerCase() + "Schedule"; currentDay = currentDay.replace("Schedule", ""); const [activeSection, setActiveSection] = useState(currentDay); const scrollRef = useRef(null); useEffect(() => { const index = Object.keys(scheduleData).indexOf(activeSection + "Schedule"); if (scrollRef.current) { scrollRef.current.scrollLeft = scrollRef.current.clientWidth * index; } }, [activeSection, scheduleData]); const handleScroll = (e) => { const { scrollLeft, clientWidth } = e.target; const index = Math.floor(scrollLeft / clientWidth); let day = Object.keys(scheduleData)[index]; day = day.replace("Schedule", ""); setActiveSection(day); }; // buttons to scroll horizontally const scrollLeft = () => { if (scrollRef.current.scrollLeft === 0) { scrollRef.current.scrollLeft = scrollRef.current.scrollWidth; } else { scrollRef.current.scrollLeft -= scrollRef.current.offsetWidth; } }; const scrollRight = () => { const difference = scrollRef.current.scrollWidth - scrollRef.current.offsetWidth - scrollRef.current.scrollLeft; if (difference < 5) { // adjust the threshold as needed scrollRef.current.scrollLeft = 0; } else { scrollRef.current.scrollLeft += scrollRef.current.offsetWidth; } }; return (

Don't miss out!

Coming Up Next!

{data.title.romaji || data.title.english || data.title.native}

{data.title.romaji || data.title.english || data.title.native}

{data.bannerImage ? ( banner next anime ) : ( banner next anime )}
{/* Countdown Timer */}
{/* Countdown Timer */}
{time.days} Days
{time.hours} Hours
{time.minutes} Mins
{time.seconds} Secs
{Object.entries(scheduleData).map(([section, data], index) => { const uniqueArray = data.reduce((accumulator, current) => { if (!accumulator.find((item) => item.id === current.id)) { accumulator.push(current); } return accumulator; }, []); return (
{uniqueArray.map((i, index) => { const currentTime = Date.now(); const hasAired = i.airingAt < currentTime; return (
coverSchedule

{i.title.romaji}

{convertUnixToTime(i.airingAt)} - Episode{" "} {i.airingEpisode}

); })}
); })}
{activeSection}
); }