@extends('layouts.app') @section('title', 'Lesson Viewer') @php $lesson = $data['data'] ?? []; $sections = $courseData['data']['sections'] ?? []; $course = $courseData['data']['course'] ?? []; // 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; @endphp @section('content')

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

Continue your learning journey.

← Back to Course
@if(isset($data['success']) && $data['success'] && !empty($lesson))

Course Content

@foreach($sections as $section)
{{ $section['title'] ?? 'Section' }}
@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
@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(($lesson['duration_minutes'] ?? 0) > 0) {{ $lesson['duration_minutes'] }} min @endif @if($lesson['is_free_preview'] ?? false) Free Preview @endif

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

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

{{ $lesson['short_description'] }}

@endif @if(!empty($lesson['description']))

{{ $lesson['description'] }}

@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')
@if(!empty($lesson['content']['content']))
{!! $lesson['content']['content'] !!}
@else
No content available for this lesson.
@endif
@break @case('quiz')
@php $questions = $lesson['content']['questions'] ?? []; $settings = $lesson['content']['settings'] ?? []; @endphp @if(!empty($settings))
@if(($settings['passing_grade'] ?? 0) > 0) Passing Grade: {{ $settings['passing_grade'] }}% @endif @if(($settings['max_attempts'] ?? 0) > 0) Max Attempts: {{ $settings['max_attempts'] }} @endif @if(($settings['duration_minutes'] ?? 0) > 0) Duration: {{ $settings['duration_minutes'] }} min @endif
@endif @if(count($questions) > 0)
@foreach($questions as $qIndex => $question)
{{ $qIndex + 1 }}

{{ $question['question_text'] ?? 'Question ' . ($qIndex + 1) }}

@if(!empty($question['explanation']))

{{ $question['explanation'] }}

@endif
{{ $question['points'] ?? 1 }} pts
@if(!empty($question['options']))
@foreach($question['options'] as $optIndex => $option) @php $optValue = is_array($option) ? ($option['text'] ?? $option['value'] ?? '') : $option; @endphp @endforeach
@else
@endif
@endforeach
@else

This quiz has no questions configured yet.

@endif
@break @case('assignment')
@php $instructions = $lesson['content']['instructions'] ?? ($lesson['content']['content'] ?? null); $files = $lesson['content']['files'] ?? []; $maxAttempts = $lesson['content']['max_attempts'] ?? 0; $passingScore = $lesson['content']['passing_score'] ?? 0; @endphp @if($maxAttempts > 0 || $passingScore > 0)
@if($maxAttempts > 0) Max Attempts: {{ $maxAttempts }} @endif @if($passingScore > 0) Passing Score: {{ $passingScore }}% @endif
@endif @if($instructions)

Instructions

{!! $instructions !!}
@endif @if(count($files) > 0)

Attached Files

@endif

Submit Your Work

Upload your completed assignment below.

Drag & drop files here or click to browse

@break @case('document')
@if(!empty($lesson['content']['content']))
{!! $lesson['content']['content'] !!}
@endif @php $files = $lesson['content']['files'] ?? []; @endphp @if(count($files) > 0)

Attached Files

@endif
@break @default
This lesson type ({{ $lesson['type'] ?? 'unknown' }}) is not supported yet.
@endswitch
@if(!empty($lesson['materials']) && count($lesson['materials']) > 0) @endif
@if($prevLesson)
Previous
{{ $prevLesson['title'] ?? '' }}
@else @endif @if($nextLesson)
Next
{{ $nextLesson['title'] ?? '' }}
@else
Course Completed
@endif
@else
Failed to render lesson. Content not found or bad response.
@endif
@endsection