"use client"; import { useEffect, useRef } from "react"; import { X } from "lucide-react"; import type { PromptProjection } from "@/lib/types"; import { RichText } from "@/components/ui/RichText"; export function PromptDrawer({ prompt, loading, error, onClose }: { prompt?: PromptProjection; loading: boolean; error?: string; onClose: () => void }) { const close = useRef(null); const dialog = useRef(null); useEffect(() => { close.current?.focus(); }, []); useEffect(() => { const handler = (event: KeyboardEvent) => { if (event.key === "Escape") onClose(); }; window.addEventListener("keydown", handler); return () => window.removeEventListener("keydown", handler); }, [onClose]); const trapFocus = (event: React.KeyboardEvent) => { if (event.key !== "Tab") return; const focusable = [...(dialog.current?.querySelectorAll('button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])') || [])]; if (!focusable.length) return; const first = focusable[0]; const last = focusable[focusable.length - 1]; if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); } else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); } }; return ; }