'use client' import { useState } from 'react' import Image from 'next/image' import { Play, Trash2, ListPlus } from 'lucide-react' interface Song { id: string youtubeId: string title: string channelName: string thumbnail: string duration: number } interface Playlist { id: string name: string } interface SongCardProps { song: Song onPlay: (song: Song) => void onDelete: (songId: string) => void playlists?: Playlist[] onAddToPlaylist?: (songId: string, playlistId: string) => void } function formatDuration(seconds: number): string { const mins = Math.floor(seconds / 60) const secs = seconds % 60 return `${mins}:${secs.toString().padStart(2, '0')}` } export default function SongCard({ song, onPlay, onDelete, playlists, onAddToPlaylist }: SongCardProps) { const [showPlaylistMenu, setShowPlaylistMenu] = useState(false) const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) const handleDelete = (e: React.MouseEvent) => { e.stopPropagation() setShowDeleteConfirm(true) } const confirmDelete = (e: React.MouseEvent) => { e.stopPropagation() onDelete(song.id) setShowDeleteConfirm(false) } const cancelDelete = (e: React.MouseEvent) => { e.stopPropagation() setShowDeleteConfirm(false) } const handleAddToPlaylist = (e: React.MouseEvent, playlistId: string) => { e.stopPropagation() if (onAddToPlaylist) { onAddToPlaylist(song.id, playlistId) } setShowPlaylistMenu(false) } const togglePlaylistMenu = (e: React.MouseEvent) => { e.stopPropagation() setShowPlaylistMenu(!showPlaylistMenu) } return (
{/* Delete confirmation modal */} {showDeleteConfirm && (
e.stopPropagation()} >

Delete song?

Are you sure you want to delete "{song.title}"?

)}
{playlists && playlists.length > 0 && onAddToPlaylist && (
{showPlaylistMenu && (
{playlists.map((playlist) => ( ))}
)}
)}
{song.title}

{song.title}

{song.channelName}

{formatDuration(song.duration)}
) }