'use client'
import * as React from 'react'
import { cn } from '@/lib/utils'
import { Button } from '@/components/ui/button'
import { Slider } from '@/components/ui/slider'
// Icons
const PlayIcon = () => (
)
const PauseIcon = () => (
)
const SkipBackIcon = () => (
)
const SkipForwardIcon = () => (
)
const ShuffleIcon = () => (
)
const RepeatIcon = () => (
)
const VolumeIcon = ({ muted }: { muted: boolean }) => (
)
// Waveform visualization
function Waveform({
progress = 0,
bars = 50,
className
}: {
progress?: number
bars?: number
className?: string
}) {
const heights = React.useMemo(() => {
return Array.from({ length: bars }, () => 20 + Math.random() * 80)
}, [bars])
return (
{heights.map((height, i) => {
const isPlayed = (i / bars) * 100 <= progress
return (
)
})}
)
}
// Equalizer animation
function Equalizer({ playing = false, className }: { playing?: boolean; className?: string }) {
return (
{[0.4, 0.7, 0.5, 0.9, 0.6].map((delay, i) => (
))}
)
}
// Format time helper
function formatTime(seconds: number): string {
const mins = Math.floor(seconds / 60)
const secs = Math.floor(seconds % 60)
return `${mins}:${secs.toString().padStart(2, '0')}`
}
// Main Audio Player
interface AudioPlayerProps {
title?: string
artist?: string
coverUrl?: string
duration?: number
variant?: 'default' | 'compact' | 'mini'
className?: string
}
function AudioPlayer({
title = 'Track Title',
artist = 'Artist Name',
coverUrl,
duration = 240,
variant = 'default',
className,
}: AudioPlayerProps) {
const [isPlaying, setIsPlaying] = React.useState(false)
const [progress, setProgress] = React.useState(35)
const [volume, setVolume] = React.useState(80)
const [isMuted, setIsMuted] = React.useState(false)
const [shuffle, setShuffle] = React.useState(false)
const [repeat, setRepeat] = React.useState(false)
const currentTime = (progress / 100) * duration
if (variant === 'mini') {
return (
{coverUrl ? (

) : (
)}
)
}
if (variant === 'compact') {
return (
{coverUrl ? (

) : (
)}
{formatTime(currentTime)}
setProgress(val)}
className="flex-1"
/>
{formatTime(duration)}
)
}
// Default full player
return (
{/* Header with artwork and info */}
{coverUrl ? (

) : (
🎵
)}
{title}
{artist}
WAV
128 BPM
A min
{/* Waveform */}
{/* Controls */}
{/* Progress */}
{formatTime(currentTime)}
setProgress(val)}
className="flex-1"
/>
{formatTime(duration)}
{/* Main controls */}
{
setVolume(val)
setIsMuted(val === 0)
}}
className="w-20"
/>
)
}
export { AudioPlayer, Waveform, Equalizer }