import { createContext, useCallback, useContext, useMemo, useState, type ReactNode, } from 'react' import { XMarkIcon } from '@heroicons/react/24/outline' import DocumentViewer from './DocumentViewer' /** * DocumentViewerContext — the document analogue of MeetingVideoContext. * * The hero's "Agenda" / "Minutes" chips call openDocument(...) to launch the PDF * in ONE centered modal popout (react-pdf inside), mirroring how "Watch * recording" pops open the video. One modal exists at a time; closing it unmounts * the viewer so the PDF.js worker + bytes are released. */ interface DocTarget { /** Real external document URL (proxied same-origin by the viewer). */ url: string /** Heading label, e.g. "Agenda" or "Minutes". */ label: string /** Optional caption (e.g. the document date). */ caption?: string } interface DocumentViewerCtx { openDocument: (target: DocTarget) => void } const Ctx = createContext(null) /** Hook for triggers (chips). Returns null when no provider is mounted. */ // eslint-disable-next-line react-refresh/only-export-components export function useDocumentViewer(): DocumentViewerCtx | null { return useContext(Ctx) } export function DocumentViewerProvider({ children }: { children: ReactNode }) { const [target, setTarget] = useState(null) const openDocument = useCallback((t: DocTarget) => setTarget(t), []) const ctx = useMemo(() => ({ openDocument }), [openDocument]) return ( {children} {target && (
setTarget(null)} role="dialog" aria-modal="true" aria-label={target.label} >
e.stopPropagation()}>
)}
) }