'use client'; import * as React from 'react'; import { Upload, Plus } from 'lucide-react'; import { Modal } from '@/components/ui/Modal'; import { Button } from '@/components/ui/Button'; import { decodeAudioFile } from '@/lib/audio/decoder'; export interface ImportTrackDialogProps { open: boolean; onClose: () => void; onImportTrack: (buffer: AudioBuffer, name: string) => void; } export function ImportTrackDialog({ open, onClose, onImportTrack, }: ImportTrackDialogProps) { const [isDragging, setIsDragging] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false); const fileInputRef = React.useRef(null); const handleFiles = async (files: FileList) => { setIsLoading(true); try { // Process files sequentially for (let i = 0; i < files.length; i++) { const file = files[i]; if (!file.type.startsWith('audio/')) { console.warn(`Skipping non-audio file: ${file.name}`); continue; } try { const buffer = await decodeAudioFile(file); const trackName = file.name.replace(/\.[^/.]+$/, ''); // Remove extension onImportTrack(buffer, trackName); } catch (error) { console.error(`Failed to import ${file.name}:`, error); } } onClose(); } finally { setIsLoading(false); } }; const handleFileSelect = (e: React.ChangeEvent) => { const files = e.target.files; if (files && files.length > 0) { handleFiles(files); } // Reset input e.target.value = ''; }; const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); setIsDragging(true); }; const handleDragLeave = (e: React.DragEvent) => { e.preventDefault(); setIsDragging(false); }; const handleDrop = (e: React.DragEvent) => { e.preventDefault(); setIsDragging(false); const files = e.dataTransfer.files; if (files && files.length > 0) { handleFiles(files); } }; return (
{/* Drag and Drop Area */}

{isLoading ? 'Importing files...' : 'Drag and drop audio files here'}

or

{/* Supported Formats */}

Supported formats:

MP3, WAV, OGG, FLAC, M4A, AAC, and more

💡 Tip: Select multiple files at once or drag multiple files to import them all as separate tracks

{/* Actions */}
); }