import React, { useEffect, useState } from 'react'; import type { ReactElement } from 'react'; import Head from 'next/head'; import { useRouter } from 'next/router'; import axios from 'axios'; import Link from 'next/link'; import LayoutGuest from '../../layouts/Guest'; import { useAppSelector } from '../../stores/hooks'; import { mdiClockOutline, mdiAccount, mdiTagOutline, mdiTranslate, mdiArrowLeft } from '@mdi/js'; import BaseIcon from '../../components/BaseIcon'; import BaseButton from '../../components/BaseButton'; // Course Details Page export default function CourseDetailsPage() { const router = useRouter(); const { id } = router.query; const projectName = useAppSelector((state) => state.style.projectName) || 'EduFlow'; const [course, setCourse] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { // Wait for router to be ready and id to be available if (!router.isReady) return; if (id && typeof id === 'string') { const fetchCourse = async () => { try { setLoading(true); console.log('Fetching course with ID:', id); const response = await axios.get(`/courses/${id}`); setCourse(response.data); setError(null); } catch (err) { console.error('Failed to fetch course:', err); setError(err); } finally { setLoading(false); } }; fetchCourse(); } else { // If router is ready but no ID, stop loading console.log('Router ready but no ID found in query:', router.query); setLoading(false); } }, [id, router.isReady]); const Header = () => (
{projectName}
All Courses
); const Footer = () => (
{projectName}

Empowering learners worldwide.

© 2026 {projectName} LMS. All rights reserved.
); if (loading) { return (

Loading course details...

); } if (error || !course) { return (

Course not found

The course you are looking for might have been removed or the link is incorrect.

router.push('/')} icon={mdiArrowLeft} />
); } const getThumbnail = (course: any) => { if (course.thumbnail && course.thumbnail.length > 0) { return `/api/file/download?privateUrl=${course.thumbnail[0].privateUrl}`; } return 'https://images.pexels.com/photos/1181244/pexels-photo-1181244.jpeg?auto=compress&cs=tinysrgb&w=600'; }; return (
{`${course.title} | ${projectName}`}
{/* Hero Section */}
{course.category && ( {course.category.name} )} {course.level || 'Beginner'}

{course.title}

{course.short_description}

By {course.instructor ? `${course.instructor.firstName}${course.instructor.lastName ? " " + course.instructor.lastName : ""}` : 'Instructor'}
{course.duration && (
{course.duration} minutes
)} {course.language && (
{course.language}
)}
{/* Main Content */}

Course Description

{course.description || 'No description available.'}

Curriculum

{course.lessons_course?.length || 0} lessons
{course.lessons_course && course.lessons_course.length > 0 ? ( course.lessons_course.sort((a: any, b: any) => (a.order || 0) - (b.order || 0)).map((lesson: any, index: number) => (
{index + 1}

{lesson.title}

{lesson.content || lesson.short_description || 'No content description.'}

{lesson.duration && (
{lesson.duration} min
)}
)) ) : (

No lessons available for this course yet.

)}
{/* Sidebar */}
{course.title}
{course.price === 0 || !course.price || course.price === '0' ? 'Free' : `$${course.price}`} {course.price > 0 && ( $349 )}

30-Day Money-Back Guarantee

Course Features

  • {course.duration ? `${course.duration} minutes total` : 'Flexible duration'}
  • Direct instructor access
  • Certificate of completion
); } CourseDetailsPage.getLayout = function getLayout(page: ReactElement) { return {page}; };