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 (
{convertUnixToTime(i.airingAt)} - Episode{" "} {i.airingEpisode}