import { useEffect, useRef, useState } from 'react' import { LayoutGrid, RotateCcw, Save, Trash2 } from 'lucide-react' import { Tooltip } from '../../components/ui/tooltip' import { type EditorLayout, type LayoutPreset, loadLayoutPresets, saveLayoutPresets, } from './video-editor-utils' export interface VideoEditorLayoutMenuProps { currentLayout: EditorLayout onApplyLayout: (layout: EditorLayout) => void onResetLayout: () => void } export function VideoEditorLayoutMenu(props: VideoEditorLayoutMenuProps) { const { currentLayout, onApplyLayout, onResetLayout } = props const [showLayoutMenu, setShowLayoutMenu] = useState(false) const [layoutPresets, setLayoutPresets] = useState(loadLayoutPresets) const [savingPresetName, setSavingPresetName] = useState(null) const presetNameInputRef = useRef(null) const layoutMenuRef = useRef(null) useEffect(() => { if (!showLayoutMenu) { setSavingPresetName(null) return } const handleClick = (e: MouseEvent) => { if (layoutMenuRef.current && !layoutMenuRef.current.contains(e.target as Node)) { setShowLayoutMenu(false) } } document.addEventListener('mousedown', handleClick) return () => document.removeEventListener('mousedown', handleClick) }, [showLayoutMenu]) const handleSaveLayoutPreset = (name: string) => { const preset: LayoutPreset = { id: `preset-${Date.now()}`, name: name.trim() || 'Untitled', layout: { ...currentLayout }, } const updated = [...layoutPresets, preset] setLayoutPresets(updated) saveLayoutPresets(updated) } const handleDeleteLayoutPreset = (id: string) => { const updated = layoutPresets.filter(p => p.id !== id) setLayoutPresets(updated) saveLayoutPresets(updated) } const handleApplyLayoutPreset = (preset: LayoutPreset) => { onApplyLayout({ ...preset.layout }) setShowLayoutMenu(false) } return (
{showLayoutMenu && (
{savingPresetName !== null ? (
Name this layout:
setSavingPresetName(e.target.value)} onKeyDown={e => { if (e.key === 'Enter' && savingPresetName.trim()) { handleSaveLayoutPreset(savingPresetName) setSavingPresetName(null) } else if (e.key === 'Escape') { setSavingPresetName(null) } e.stopPropagation() }} placeholder="e.g. Wide Timeline" />
) : ( <> {layoutPresets.length > 0 && ( <>
Saved Layouts
{layoutPresets.map(preset => (
))} )} )}
)}
) }