"use client"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup, } from "@mdxui/primitives/resizable"; import { useCallback, useEffect, useRef, useState } from "react"; import { EditorPane } from "./editor/editor-pane"; import type { EditorHandle } from "./editor-context"; import { PreviewPane } from "./preview/preview-pane"; interface EditorSplitPaneProps { content: string; onChange: (content: string) => void; path: string; isDirty?: boolean; isSaving?: boolean; onSave?: () => void; onClose?: () => void; } export function EditorSplitPane({ content, onChange, path, isDirty, isSaving, onSave, onClose, }: EditorSplitPaneProps) { const [defaultLayout, setDefaultLayout] = useState([50, 50]); const saveTimeoutRef = useRef | null>(null); const editorHandleRef = useRef(null); // Load saved layout from localStorage useEffect(() => { if (typeof window !== "undefined") { const saved = localStorage.getItem("editor-panel-layout"); if (saved) { try { const parsed = JSON.parse(saved); if (Array.isArray(parsed) && parsed.length === 2) { setDefaultLayout(parsed); } } catch { // Ignore parse errors } } } }, []); // Cleanup timeout on unmount useEffect(() => { return () => { if (saveTimeoutRef.current) { clearTimeout(saveTimeoutRef.current); } }; }, []); // Debounced localStorage save (500ms delay) const handleLayout = useCallback((sizes: number[]) => { if (saveTimeoutRef.current) { clearTimeout(saveTimeoutRef.current); } saveTimeoutRef.current = setTimeout(() => { localStorage.setItem("editor-panel-layout", JSON.stringify(sizes)); }, 500); }, []); // Jump to line using editor handle ref const handleJumpToLine = useCallback((line: number) => { editorHandleRef.current?.jumpToLine(line); }, []); return ( ); }