@extends('layouts.app') @section('title', $course['name'] ?? 'Course Details') @php $course = $data['data']['course'] ?? []; $sections = $data['data']['sections'] ?? []; $lesson = $lessonData['data'] ?? []; // Flatten all lessons for navigation $allLessons = []; foreach ($sections as $section) { foreach ($section['lessons'] ?? [] as $l) { $allLessons[] = $l; } } $currentIndex = null; foreach ($allLessons as $idx => $l) { if (($l['id'] ?? null) == $lessonId) { $currentIndex = $idx; break; } } $prevLesson = ($currentIndex !== null && $currentIndex > 0) ? $allLessons[$currentIndex - 1] : null; $nextLesson = ($currentIndex !== null && $currentIndex < count($allLessons) - 1) ? $allLessons[$currentIndex + 1] : null; // Get duration for timer $durationMinutes = 0; if ($lesson['type'] ?? '' == 'quiz') { $durationMinutes = $lesson['content']['settings']['duration_minutes'] ?? 0; } else { $durationMinutes = $lesson['duration_minutes'] ?? 0; } // Load previously saved quiz answers $savedAnswers = []; if (isset($savedSubmission) && $savedSubmission) { $savedAnswers = $savedSubmission->answers ?? []; } @endphp @section('content')

{{ $course['name'] ?? 'Course Details' }}

{{ $course['description'] ?? 'Explore the curriculum and start learning.' }}

@if(isset($data['success']) && $data['success'] && !empty($course))

Course Content

{{ count($allLessons) }} lessons
@foreach($sections as $section)
{{ $section['title'] ?? 'Section' }} {{ count($section['lessons'] ?? []) }}
@foreach($section['lessons'] ?? [] as $l) @php $isActive = ($l['id'] ?? null) == $lessonId; $typeIcon = match($l['type'] ?? 'text') { 'video' => '', 'quiz' => '', 'assignment' => '', default => '', }; @endphp {!! $typeIcon !!}

{{ $l['title'] ?? 'Untitled' }}

{{ ucfirst($l['type'] ?? 'lesson') }}

@if($isActive) @endif
@endforeach
@endforeach
@if(!empty($lesson) && isset($lessonData['success']) && $lessonData['success'])
@php $typeColor = match($lesson['type'] ?? 'text') { 'video' => 'bg-red-100 text-red-700', 'quiz' => 'bg-green-100 text-green-700', 'assignment' => 'bg-indigo-100 text-indigo-700', 'document' => 'bg-amber-100 text-amber-700', default => 'bg-gray-100 text-gray-700', }; @endphp {{ ucfirst($lesson['type'] ?? 'Lesson') }} @if($durationMinutes > 0 && ($lesson['type'] ?? '') != 'quiz') {{ $durationMinutes }} min @endif @if($lesson['is_free_preview'] ?? false) Free Preview @endif

{{ $lesson['title'] ?? 'Untitled Lesson' }}

@if(!empty($lesson['short_description']))

{{ strip_tags(html_entity_decode($lesson['short_description'])) }}

@endif @if(($lesson['type'] ?? '') == 'quiz') @php $questions = $lesson['content']['questions'] ?? []; $settings = $lesson['content']['settings'] ?? []; $totalQuestions = count($questions); $passingGrade = $settings['passing_grade'] ?? 70; $maxAttempts = $settings['max_attempts'] ?? 1; $durationMinutesForQuiz = $settings['duration_minutes'] ?? 0; @endphp
Quiz Assessment
@if($settings['random_questions'] ?? false) Random Order @endif @if($settings['random_answers'] ?? false) Random Answers @endif
{{ $totalQuestions }} Questions
{{ $passingGrade }}% Passing
{{ $durationMinutesForQuiz }} Minutes
{{ $maxAttempts }} Attempts
@if($durationMinutesForQuiz > 0)
Time: --:--
@endif
@endif
@switch($lesson['type'] ?? 'text') @case('video')
@php $url = $lesson['content']['url'] ?? ''; $videoId = null; if ($url) { preg_match('/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/', $url, $matches); $videoId = $matches[1] ?? null; } @endphp @if($videoId)
@elseif($url) @else
No video URL provided.
@endif
@break @case('text')
@php $textContent = $lesson['content']['content'] ?? ($lesson['content'] ?? ''); @endphp @if(!empty($textContent))
{!! $textContent !!}
@else
No content available for this lesson.
@endif
@if(!empty($lesson['materials']) && count($lesson['materials']) > 0)

Lesson Materials

@foreach($lesson['materials'] as $material)

{{ $material['title'] ?? 'Untitled' }}

{{ strtoupper($material['type'] ?? 'file') }}

Download
@endforeach
@endif @break @case('quiz')
@if(!empty($questions))
@foreach($questions as $index => $question)
{{ $index + 1 }}

{{ $question['question_text'] }}

{{ $question['points'] ?? 1 }} pts
@if(!empty($question['options']))
@foreach($question['options'] as $option) @php $isSaved = isset($savedAnswers[$question['id']]) && $savedAnswers[$question['id']] == $option; @endphp @endforeach
@endif
@endforeach
@else
No quiz questions available.
@endif
@if(!empty($lesson['materials']) && count($lesson['materials']) > 0)

Lesson Materials

@foreach($lesson['materials'] as $material)

{{ $material['title'] ?? 'Untitled' }}

{{ strtoupper($material['type'] ?? 'file') }}

Download
@endforeach
@endif @break @case('assignment')

Instructions

{!! $lesson['content']['instructions'] ?? '

No instructions provided.

' !!}
@if(!empty($lesson['materials']) && count($lesson['materials']) > 0)

Assignment Materials

@foreach($lesson['materials'] as $material)

{{ $material['title'] ?? 'Untitled' }}

{{ strtoupper($material['type'] ?? 'file') }}

Download
@endforeach
@endif
@break @default
No content available for this lesson.
@endswitch
@if($prevLesson) Previous @else
@endif @if($nextLesson) Next @endif
@else

Select a lesson from the sidebar to start learning.

@endif
@else

Course not found or you don't have access to this course.

Browse Courses
@endif
@endsection @push('scripts') @endpush