'use client'; import { useCallback, useState } from 'react'; import { Plus } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { SectionBlock } from './SectionBlock'; import { SectionPicker } from './SectionPicker'; import { cn } from '@/lib/utils'; import { Section, SectionType } from '@/types/audio'; interface SectionTrackProps { sections: Section[]; durationBars: number; pixelsPerBar: number; selectedId: string | null; onSelect: (id: string | null) => void; onAdd: (type: SectionType, startBar: number, endBar: number) => void; onResize: (id: string, startBar: number, endBar: number) => void; onMove: (id: string, startBar: number) => void; onDelete: (id: string) => void; className?: string; } export function SectionTrack({ sections, durationBars, pixelsPerBar, selectedId, onSelect, onAdd, onResize, onMove, onDelete, className, }: SectionTrackProps) { const [showPicker, setShowPicker] = useState(false); const [pickerPosition, setPickerPosition] = useState({ x: 0, bar: 0 }); const handleTrackClick = useCallback( (e: React.MouseEvent) => { const rect = e.currentTarget.getBoundingClientRect(); const x = e.clientX - rect.left; const bar = Math.floor(x / pixelsPerBar); if (bar >= 0 && bar < durationBars) { setPickerPosition({ x, bar }); setShowPicker(true); } }, [pixelsPerBar, durationBars] ); const handleSelectType = useCallback( (type: SectionType) => { const endBar = Math.min(durationBars, pickerPosition.bar + 4); onAdd(type, pickerPosition.bar, endBar); }, [pickerPosition.bar, durationBars, onAdd] ); return (
Sections
{Array.from({ length: durationBars }, (_, i) => (
))} {sections.map((section) => ( ))} {showPicker && (
setShowPicker(false)} />
)}
); }