import { useEffect, useRef } from 'react'; import { BookOpen, MessageSquare, Flashlight, MousePointer2, Play } 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', }, }; interface LectureNotesViewProps { notes: LectureNoteEntry[]; currentSceneId?: string | null; } export function LectureNotesView({ notes, currentSceneId }: 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 } | { kind: 'discussion'; label?: 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 }); } else if (item.kind === 'action') { pendingInline.push(item.type); } else { rows.push({ kind: 'speech', inlineActions: pendingInline, text: item.text, }); 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; return (

{actions.map((a, j) => { const cfg = ACTION_ICON_ONLY[a]; if (!cfg) return null; const { Icon, style } = cfg; return ( ); })} {row.kind === 'speech' ? row.text : null}

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