'use client'; import React from 'react'; import { useSearchParams, useRouter } from 'next/navigation'; import { usePlaylist } from '@/hooks/usePlaylist'; import { useVideo } from '@/hooks/useVideo'; import { Card, CardContent, CardFooter, CardHeader, CardTitle, } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { SegmentedProgressBar, WatchSegment } from '@/components/segmented-progress-bar'; import { AppSidebar } from '@/components/app-sidebar'; import { SiteHeader } from '@/components/site-header'; import { CommentsSection } from '@/components/comments-section'; import { formatDistanceToNow } from 'date-fns'; import { Lock, Heart, Edit } from 'lucide-react'; import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar'; import { Button } from '@/components/ui/button'; import { HlsPlayer } from '@/components/hls'; import { useSession } from 'next-auth/react'; import Image from 'next/image'; import { toast } from 'sonner'; type VideoFromApi = { id: string; title: string; description?: string | null; durationSec?: number | null; duration?: string | null; thumbnail?: string | null; url?: string | null; locked?: boolean; createdAt?: string | null; transcodingStatus?: string; videoUrls?: { hlsUrl: string | null; mp4Url: string; }; uploader?: { id: string; name?: string; image?: string; } | null; }; type ProgressResult = { progress?: { percent?: number }; segments?: WatchSegment[]; unlockedNext?: { id: string; title: string } | null; }; type TrackedVideo = { videoId: string; durationSec: number | null }; /** * Records which parts of a video were actually played and reports them to * /api/progress. * * It samples the