'use client'; import { useMemo } from 'react'; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, } from '@djangocfg/ui-core/components'; import { usePageSnapshot } from './use-page-snapshot'; /** Props for `PageSnapshotPreview`. */ export interface PageSnapshotPreviewProps { /** Whether the drawer is open. */ open: boolean; /** Called when the user dismisses the drawer. */ onOpenChange: (open: boolean) => void; } /** * The trust surface: a side drawer that shows the user exactly what * page-context snapshot would be sent to the AI — already redacted. * * It captures fresh on open (preview mode, ignoring the opt-in gate) so * what the user sees is what the next message would actually carry. */ export function PageSnapshotPreview({ open, onOpenChange, }: PageSnapshotPreviewProps) { const { generatePreview } = usePageSnapshot(); // Capture a preview only while the drawer is open — no point walking // the DOM otherwise. Re-runs whenever the drawer is (re)opened. const preview = useMemo( () => (open ? generatePreview() : null), [open, generatePreview], ); const json = useMemo( () => preview ? JSON.stringify(preview.payload.snapshot, null, 2) : '', [preview], ); const meta = preview?.payload.metadata; return ( Page context preview This is exactly what the assistant sees about your screen. Sensitive values are already removed. {meta && (
~{meta.tokenEstimate} tokens {meta.redactedCount} redacted {meta.foldedCount} groups folded
)}
          {json || 'Nothing to preview.'}
        
); }