'use client'; import { useEffect, useRef } from 'react'; import { BookOpen, MessageSquare, Flashlight, MousePointer2, Play, Highlighter, SlidersHorizontal, StickyNote, Eye, } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useI18n } from '@/lib/hooks/use-i18n'; import type { LectureNoteEntry } from '@/lib/types/chat'; const ACTION_ICON_ONLY: Record = { spotlight: { Icon: Flashlight, style: 'bg-yellow-50 dark:bg-yellow-500/15 border-yellow-300/40 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300', }, laser: { Icon: MousePointer2, style: 'bg-red-50 dark:bg-red-500/15 border-red-300/40 dark:border-red-500/30 text-red-600 dark:text-red-300', }, play_video: { Icon: Play, style: 'bg-yellow-50 dark:bg-yellow-500/15 border-yellow-300/40 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300', }, widget_highlight: { Icon: Highlighter, style: 'bg-amber-50 dark:bg-amber-500/15 border-amber-300/40 dark:border-amber-500/30 text-amber-700 dark:text-amber-300', }, widget_setState: { Icon: SlidersHorizontal, style: 'bg-indigo-50 dark:bg-indigo-500/15 border-indigo-300/40 dark:border-indigo-500/30 text-indigo-700 dark:text-indigo-300', }, widget_annotation: { Icon: StickyNote, style: 'bg-sky-50 dark:bg-sky-500/15 border-sky-300/40 dark:border-sky-500/30 text-sky-700 dark:text-sky-300', }, widget_reveal: { Icon: Eye, style: 'bg-emerald-50 dark:bg-emerald-500/15 border-emerald-300/40 dark:border-emerald-500/30 text-emerald-700 dark:text-emerald-300', }, }; interface LectureNotesViewProps { notes: LectureNoteEntry[]; currentSceneId?: string | null; currentActionIndex?: number | null; canJumpToAction?: (sceneId: string, actionIndex: number) => boolean; onJumpToAction?: (sceneId: string, actionIndex: number) => void; } export function LectureNotesView({ notes, currentSceneId, currentActionIndex, canJumpToAction, onJumpToAction, }: LectureNotesViewProps) { const { t } = useI18n(); const containerRef = useRef(null); // Auto-scroll to the current scene note useEffect(() => { if (!currentSceneId || !containerRef.current) return; const el = containerRef.current.querySelector(`[data-scene-id="${currentSceneId}"]`); if (el) { el.scrollIntoView({ behavior: 'smooth', block: 'center' }); } }, [currentSceneId]); // Empty state if (notes.length === 0) { return (

{t('chat.lectureNotes.empty')}

{t('chat.lectureNotes.emptyHint')}

); } return (
{notes.map((note, index) => { const isCurrent = note.sceneId === currentSceneId; const pageNum = index + 1; const pageLabel = t('chat.lectureNotes.pageLabel', { n: pageNum }); return (
{/* Page label row */}
{/* Timeline dot */}
{pageLabel} {isCurrent && ( {t('chat.lectureNotes.currentPage')} )}
{/* Scene title */}

{note.sceneTitle}

{/* Ordered items: spotlight/laser inline at sentence start, discussion as card */}
{(() => { // Build render rows: group inline actions (spotlight/laser) with next speech, // but render discussion as its own block type Row = | { kind: 'speech'; inlineActions: string[]; text: string; actionIndex: number; actionId: string; } | { kind: 'discussion'; label?: string; actionIndex: number; actionId: string } | { kind: 'trailing'; inlineActions: string[] }; const rows: Row[] = []; let pendingInline: string[] = []; for (const item of note.items) { if (item.kind === 'action' && item.type === 'discussion') { // Flush pending inline actions as trailing if any if (pendingInline.length > 0) { rows.push({ kind: 'trailing', inlineActions: pendingInline, }); pendingInline = []; } rows.push({ kind: 'discussion', label: item.label, actionIndex: item.actionIndex, actionId: item.actionId, }); } else if (item.kind === 'action') { pendingInline.push(item.type); } else { rows.push({ kind: 'speech', inlineActions: pendingInline, text: item.text, actionIndex: item.actionIndex, actionId: item.actionId, }); pendingInline = []; } } if (pendingInline.length > 0) { rows.push({ kind: 'trailing', inlineActions: pendingInline }); } return rows.map((row, i) => { if (row.kind === 'discussion') { return (
{row.label}
); } const actions = row.kind === 'trailing' ? row.inlineActions : row.inlineActions; const isSpeech = row.kind === 'speech'; const isActiveSpeech = isCurrent && isSpeech && row.actionIndex === currentActionIndex; const canJump = isCurrent && isSpeech && !!onJumpToAction && (canJumpToAction?.(note.sceneId, row.actionIndex) ?? false); const jumpTitle = canJump ? t('chat.lectureNotes.jumpToLine') : t('chat.lectureNotes.jumpUnavailable'); const content = ( <> {actions.map((a, j) => { const cfg = ACTION_ICON_ONLY[a]; if (!cfg) return null; const { Icon, style } = cfg; return ( ); })} {isSpeech ? row.text : null} ); if (isSpeech) { return ( ); } return (

{content}

); }); })()}
); })}
); }