'use client'; import { useState, useEffect, use } from 'react'; import Link from 'next/link'; import { notFound } from 'next/navigation'; import { getLessonBySlug, getLessons } from '@/lib/actions/lessonActions'; import { VideoPlayer } from '@/components/VideoPlayer'; import { CodeBlock } from '@/components/CodeBlock'; import { ResourceCard } from '@/components/ResourceCard'; import { FileText, Code, Download, Clock, FileArchive, FileSpreadsheet, ArrowLeft, Share2, Check, Eye, Calendar, Sparkles, ExternalLink, Loader2 } from 'lucide-react'; import { YoutubeIcon as Youtube } from '@/components/icons/YoutubeIcon'; import { GithubIcon as Github } from '@/components/icons/BrandIcons'; export default function LessonDetailPage({ params }: { params: Promise<{ locale: string; slug: string }>; }) { const { locale, slug } = use(params); const [activeTab, setActiveTab] = useState<'code' | 'notes' | 'downloads' | 'chapters'>('code'); const [copiedLink, setCopiedLink] = useState(false); const [lesson, setLesson] = useState(null); const [relatedLessons, setRelatedLessons] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function loadData() { setLoading(true); const data = await getLessonBySlug(slug); if (data) { setLesson(data); // Auto-select first non-empty tab const hasCode = data.codeSnippets && data.codeSnippets.length > 0; const hasNotes = data.notesMarkdown && data.notesMarkdown.length > 0; const hasDownloads = data.downloads && data.downloads.length > 0; const hasChapters = data.chapters && data.chapters.length > 0; if (hasCode) setActiveTab('code'); else if (hasNotes) setActiveTab('notes'); else if (hasDownloads) setActiveTab('downloads'); else if (hasChapters) setActiveTab('chapters'); const all = await getLessons(); setRelatedLessons(all.filter((v: any) => v.id !== data.id).slice(0, 3)); } setLoading(false); } loadData(); }, [slug]); if (!loading && !lesson) { notFound(); } if (loading || !lesson) { return (

Loading tutorial...

); } const hasCode = lesson.codeSnippets && lesson.codeSnippets.length > 0; const hasNotes = lesson.notesMarkdown && lesson.notesMarkdown.length > 0; const hasDownloads = lesson.downloads && lesson.downloads.length > 0; const hasChapters = lesson.chapters && lesson.chapters.length > 0; const hasAnyResources = hasCode || hasNotes || hasDownloads || hasChapters; const handleShare = async () => { try { await navigator.clipboard.writeText(window.location.href); setCopiedLink(true); setTimeout(() => setCopiedLink(false), 2000); } catch (err) { console.error('Share error:', err); } }; return (
{/* Breadcrumb & Navigation Back */}
Home / Lessons / {lesson.title}
Back to Lessons
{/* Main Header Info */}
{lesson.category} {new Date(lesson.publishDate).toLocaleDateString()} {lesson.viewsCount.toLocaleString()} Views {hasDownloads && ( {lesson.downloadCount.toLocaleString()} Downloads )}

{lesson.title}

{lesson.summary}

{/* Embedded Video Player */} {/* Resource Tabs (Shown ONLY if resources exist) */} {hasAnyResources && (
{/* Tab Header Buttons */}
{hasCode && ( )} {hasNotes && ( )} {hasDownloads && ( )} {hasChapters && ( )}
{/* Tab Contents */}
{/* TAB 1: CODE BLOCKS */} {activeTab === 'code' && hasCode && (
💡 You can inspect all code snippets by clicking file tabs and copy them directly into your project using "Copy Code".
)} {/* TAB 2: LESSON NOTES */} {activeTab === 'notes' && hasNotes && (

Key Lesson Notes & Takeaways

{lesson.notesMarkdown.map((note: string, idx: number) => (
{note}
))}
)} {/* TAB 3: DOWNLOADS & LINKS */} {activeTab === 'downloads' && hasDownloads && (
{lesson.downloads.map((item: any, idx: number) => (
{item.type === 'zip' && } {item.type === 'github' && } {item.type === 'pdf' && } {item.type === 'link' && }

{item.title}

{item.size &&

Size: {item.size}

}
Download / Open
))}
)} {/* TAB 4: CHAPTERS */} {activeTab === 'chapters' && hasChapters && (

Timestamped Video Index

{lesson.chapters.map((chap: any) => (
{chap.time} {chap.title}
Watch
))}
)}
)} {/* Related YouTube Videos */}

Other Popular Video Tutorials

{relatedLessons.map((rel) => ( ))}
); }