import { useEffect, useRef } from 'react' import { createPortal } from 'react-dom' import { HOUSE_STYLE } from '../../utils/houseTheme' import { clockTime, youtubeEmbedUrl } from '../../lib/youtubeEmbed' import type { Stance } from '../../utils/boxSplit' import QuoteCard from './QuoteCard' export interface MeetingVideo { videoId: string /** Seconds into the recording where the quoted passage starts; null when untimed. */ start: number | null title: string /** "Charlotte, NC · 2026-05-26" */ sub?: string /** The recording on YouTube at that moment, for "Open on YouTube". */ url: string | null /** The verbatim passage that put the meeting on the chart, matched words in (#1036). */ quote?: string | null /** Where and when, from the record, for the quote card (#1108): "Charlotte, NC" and an ISO date. */ place?: string | null date?: string | null /** The speaker, when the passage is a speaker's own words: name as served ("Audra T."), side, real role, item. */ speakerName?: string | null side?: Stance | null role?: string | null item?: string | null /** Where the public stood at this meeting, labelled as the meeting's (#1293); null: no line. */ stanceNote?: string | null } interface Props { video: MeetingVideo | null onClose: () => void } /** * The meeting recording in place (#972). Nothing from YouTube is fetched until this opens: the iframe exists only while * `video` is set, so closing removes it and stops playback. Escape, the close button and a click on the backdrop close it; * focus goes to the close button on open, stays inside while open, and the caller restores it to the dot it came from. */ const STORY_KEYS = new Set([' ', 'Spacebar', 'PageDown', 'PageUp', 'ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'Enter']) export default function MeetingVideoModal({ video, onClose }: Props) { const closeRef = useRef(null) const boxRef = useRef(null) const backdropRef = useRef(null) useEffect(() => { if (!video) return closeRef.current?.focus() const onKey = (e: globalThis.KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault() e.stopPropagation() onClose() return } // The story's own keys (window listeners: Space, PageDown, arrows…) must not move the page behind the dialog. Keys // inside the dialog keep their default action (a focused button or link still works); nothing reaches the story. if (STORY_KEYS.has(e.key)) { e.stopPropagation() if (!boxRef.current?.contains(document.activeElement)) e.preventDefault() } if (e.key !== 'Tab' || !boxRef.current) return // Keep focus inside the dialog (the iframe takes its own focus; Tab around the controls). const f = [...boxRef.current.querySelectorAll('button, a[href], iframe')] if (!f.length) return const first = f[0]! const last = f[f.length - 1]! if (e.shiftKey && document.activeElement === first) { e.preventDefault() last.focus() } else if (!e.shiftKey && document.activeElement === last) { e.preventDefault() first.focus() } } document.addEventListener('keydown', onKey, true) // Lock the page under the dialog: the story scrolls on (and smooth-scrolls with Lenis), so locking // alone isn't enough; wheel and touch over the backdrop are stopped outright (the player's iframe gets its own). const html = document.documentElement const prev = { html: html.style.overflow, body: document.body.style.overflow } html.style.overflow = 'hidden' document.body.style.overflow = 'hidden' // Only the backdrop itself is blocked: the dialog may be taller than a short window and must still scroll // (its overscroll-behavior: contain keeps that scroll from chaining to the page). const block = (e: Event) => { if (e.cancelable && !boxRef.current?.contains(e.target as Node)) e.preventDefault() } const bd = backdropRef.current bd?.addEventListener('wheel', block, { passive: false }) bd?.addEventListener('touchmove', block, { passive: false }) return () => { document.removeEventListener('keydown', onKey, true) bd?.removeEventListener('wheel', block) bd?.removeEventListener('touchmove', block) html.style.overflow = prev.html document.body.style.overflow = prev.body } }, [video, onClose]) if (!video || typeof document === 'undefined') return null return createPortal(
{/* data-lenis-prevent: the story's smooth scroller must not scroll the page under the dialog. */}
e.stopPropagation()} onKeyDown={(e) => e.stopPropagation()} >
{video.quote ? ( // The quoted moment in the card format (#1108), without the image: the dialog plays the recording itself. ) : (

{video.title}

{[video.sub, video.start != null && video.start > 0 ? `from ${clockTime(video.start)}, where the passage starts` : null] .filter(Boolean) .join(' · ')}

)}