'use client' import { useEffect, useState } from 'react' import { cn } from '@/lib/utils' /** Parse a chapter timestamp ("M:SS" or "H:MM:SS") into seconds. */ function parseTime(time: string): number { const parts = time.split(':').map(Number) if (parts.some(Number.isNaN)) return 0 return parts.reduce((acc, n) => acc * 60 + n, 0) } interface Chapter { /** Chapter label. */ title: string /** Timestamp, e.g. "0:45". */ time?: string } interface VideoChaptersProps { /** Panel heading. Defaults to "Chapters". */ title?: string chapters: Chapter[] className?: string } /** * Right-rail list of the current video's chapters — flat and borderless to * match the docs' "On this page" TOC (small muted label, hover-highlighted * rows). Rows are skip-to controls; they activate once the lesson's video is * recorded. */ export function VideoChapters({ title = 'Chapters', chapters, className }: VideoChaptersProps) { // Chapters only seek when a VideoPlaceholder with a real video is on the page. // Handshake so the rows stay inert (not falsely clickable) on video-less lessons. const [hasVideo, setHasVideo] = useState(false) useEffect(() => { const onReady = () => setHasVideo(true) window.addEventListener('academy:video-ready', onReady) window.dispatchEvent(new Event('academy:video-query')) return () => window.removeEventListener('academy:video-ready', onReady) }, []) return ( ) }