import { useState, type CSSProperties, type ReactNode } from 'react' import { highlightSnippet } from '../../lib/highlight' import { clockTime, youtubeEmbedUrl, youtubeHoverEmbedUrl } from '../../lib/youtubeEmbed' import type { Stance } from '../../utils/boxSplit' import { BOX_COLORS, STANCE_LABEL } from '../home/storyColors' import { aiSummary, initialsOf, playLabel, quoteDate, recordedRole } from './quoteCardUtils' import './QuoteCard.css' export interface QuoteCardProps { /** "De Soto, MO", from the record. */ place: string /** ISO date of the meeting, or null when the record has none. */ date?: string | null /** The verbatim passage; matched words in (rendered with highlightSnippet, React-escaped). */ quote: string /** The speaker's recorded side; absent for a meeting passage. */ side?: Stance | null /** The name as served ("Rob D."), never more than the record gives. */ speakerName?: string | null /** The real role on record ("Resident"). */ role?: string | null /** The item the comment is on (decision headline): shown as "On: …". */ item?: string | null /** The meeting's title, for a meeting passage with no speaker. */ meeting?: string | null /** A short line on where the public stood at this meeting (#1230), e.g. "Public: Favor gun rights" or * "Mentions gun control; no public stance in this meeting"; none → nothing shown. */ stanceNote?: string | null /** The recording's YouTube id: its real thumbnail is shown. None → no image block. */ videoId?: string | null /** Seconds into the recording where the passage starts. */ startSeconds?: number | null /** The recording at that moment, opened by the image when there is no onPlay. */ url?: string | null /** Play in place (the caller's video popup) instead of opening `url`. */ onPlay?: () => void /** The meeting's AI summary from the record (#1124), clamped to about 3 lines and labelled; none → nothing shown. */ summary?: string | null /** The meeting page in the app, with the scope already in its query (#1124); none → no link. */ analysisUrl?: string | null /** Play the recording inside the card (#1277, the story maps' hover card): `autoplay` embeds it playing, muted, at * `startSeconds`, with no play button (desktop mouse hover only); `click` shows the still image with a play button that * plays it in the card (keyboard focus, reduced motion, data saving). None → the image opens `onPlay` / `url`. */ inlineVideo?: 'autoplay' | 'click' /** The map hover card (#1277), person-first: the recording, the quote, who said it, then the meeting, place and date; * tighter text, the quote clamped, no AI summary or analysis link (the card lets the mouse through to the map, so it * holds nothing to click but the recording). */ compact?: boolean /** `card`: with the recording image; `header`: no image (the meeting video popup, which plays the video itself). */ variant?: 'card' | 'header' className?: string style?: CSSProperties /** Extra lines under the card's text (counts, links), from the caller. */ children?: ReactNode } /** Text colours for the side label: the box colour, darkened only where the box colour is too light to read as text. */ // A question is drawn as No side on the maps (#1110), so its label takes the same colour. const SIDE_TEXT: Record = { ...BOX_COLORS } function PlayGlyph() { return ( ) } /** * A quoted moment from a meeting, in the owner's card format (#1108): the meeting's real recording thumbnail with a play * button, where and when, the verbatim quote large, and a speaker row (an initials circle, the name as served, the side and * the real role or item). Only what the record holds is shown: no photo of anyone, no invented line; a missing field is left * out. Wide cards (560px and up) put the image on the left; narrower ones stack. */ export default function QuoteCard({ place, date, quote, side, speakerName, role, item, meeting, stanceNote, videoId, startSeconds, url, onPlay, summary, analysisUrl, inlineVideo, compact = false, variant = 'card', className, style, children, }: QuoteCardProps) { const when = quoteDate(date) const from = variant === 'header' && startSeconds != null && startSeconds > 0 ? `from ${clockTime(startSeconds)}` : null const where = [place, when, from].filter(Boolean).join(' · ') const initials = initialsOf(speakerName) const roleShown = recordedRole(role) const hasSpeaker = Boolean(speakerName || side || roleShown) const line = [roleShown, item ? `On: ${item}` : null].filter(Boolean).join(' · ') const showImage = variant === 'card' && Boolean(videoId) const label = playLabel(startSeconds) const summaryShown = compact ? null : aiSummary(summary) // Which recording the reader pressed play on (`click`): keyed by video and moment, so a card that moves to another // passage shows its still image again instead of carrying the play over. const [playing, setPlaying] = useState(null) const videoKey = videoId ? `${videoId}:${startSeconds ?? 0}` : null const embed = showImage && videoId ? inlineVideo === 'autoplay' ? youtubeHoverEmbedUrl(videoId, startSeconds) : inlineVideo === 'click' && playing === videoKey ? youtubeEmbedUrl(videoId, startSeconds) : null : null const media = showImage ? ( <> {`Recording {label} ) : null return (
{showImage && (embed ? ( // One player per card; a new src (another state's passage) is a new iframe, and unmounting the card stops it.