import { useT } from "@agent-native/core/client/i18n"; import { IconX } from "@tabler/icons-react"; import { useEffect, useState, type ReactNode } from "react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; const AGENT_SIDEBAR_WIDTH_KEY = "agent-native-sidebar-width"; const DEFAULT_AGENT_SIDEBAR_WIDTH = 380; /** Match AgentSidebar width so app-owned panels sit flush on the right edge. * Uses the same localStorage key the framework writes on resize (280–700px). * Reads once on mount only — live agent-sidebar drags do not update this hook. */ function useAgentSidebarWidth() { const [width, setWidth] = useState(DEFAULT_AGENT_SIDEBAR_WIDTH); useEffect(() => { try { const saved = window.localStorage.getItem(AGENT_SIDEBAR_WIDTH_KEY); if (!saved) return; const parsed = Number.parseInt(saved, 10); if (parsed >= 280 && parsed <= 700) setWidth(parsed); } catch { // Keep the default width if storage is unavailable. } }, []); return width; } export function SidePanel({ children, className, title, subtitle, closeLabel, onClose, }: { children: ReactNode; className?: string; title?: string; subtitle?: string; closeLabel?: string; onClose?: () => void; }) { const t = useT(); const resolvedCloseLabel = closeLabel ?? t("common.closePanel"); const width = useAgentSidebarWidth(); useEffect(() => { if (!onClose) return; function handleKeyDown(event: KeyboardEvent) { if (event.key !== "Escape") return; event.preventDefault(); onClose?.(); } window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [onClose]); return ( ); }