"use client" import { useState, useEffect } from "react" import Image from "next/image" import { Play, SkipBack, SkipForward } from "lucide-react" import LoadingSpinner from "../objects/LoadingSpinner" import { SeekBar } from "@/components/objects/SeekBar" interface Song { albumArt: string name: string artist: string duration: string link?: string } interface Period { timePeriod: string songs: Song[] } export default function Home() { const [timePeriod, setTimePeriod] = useState("Early Summer 2024") const [songs, setSongs] = useState([]) const [currentIndex, setCurrentIndex] = useState(0) const [isLoading, setIsLoading] = useState(true) const [currentPosition, setCurrentPosition] = useState(0) useEffect(() => { setIsLoading(true) fetch("/data/music.json") .then((response) => response.json()) .then((data: Period[]) => { const selectedPeriod = data.find((period) => period.timePeriod === timePeriod) const songsList = selectedPeriod ? selectedPeriod.songs : [] setSongs(songsList) const newIndex = Math.floor(Math.random() * songsList.length) setCurrentIndex(newIndex) // Set initial random position for the selected song if (songsList.length > 0) { const durationInSeconds = parseDuration(songsList[newIndex]?.duration || "0:00") setCurrentPosition(Math.floor(Math.random() * durationInSeconds)) } setIsLoading(false) }) .catch((error) => { console.error("Error fetching music data:", error) setIsLoading(false) }) }, [timePeriod]) const handleNext = () => { setCurrentIndex((prevIndex) => { const nextIndex = (prevIndex + 1) % songs.length const durationInSeconds = parseDuration(songs[nextIndex].duration) setCurrentPosition(Math.floor(Math.random() * durationInSeconds)) return nextIndex }) } const handlePrevious = () => { setCurrentIndex((prevIndex) => { const nextIndex = (prevIndex - 1 + songs.length) % songs.length const durationInSeconds = parseDuration(songs[nextIndex].duration) setCurrentPosition(Math.floor(Math.random() * durationInSeconds)) return nextIndex }) } const parseDuration = (duration: string): number => { const [minutes, seconds] = duration.split(":").map(Number) return minutes * 60 + seconds } return (
) }