@php
$courses = getCourses($program->id);
$encryptedSectionId = Route::current()->parameter('slug');
$decryptedSectionId = $encryptedSectionId ? decryption($encryptedSectionId) : null;
//Auth::user()->id
$name = Auth::user()->name;
$parts = explode(' ', $name, 2); // Split name into two parts
$first_name = $parts[0] ?? ''; // First name
$last_name = $parts[1] ?? ''; // Last name (if exists)
$username = session('username');
$password = session('password');
$str = $first_name.'|'.$last_name.'|'.$username.'|'.$password.'|'.Auth::user()->email;
$strEncode = encryption($str);
$program_slug = $program->slug;
$EXAM_URL = env('EXAM_URL').$program_slug.'/'.$program_slug.'/'.$strEncode;
$firstSegment = Request::segment(1);
@endphp
@php
$previousExamStatus = true; // Assume first course is accessible
@endphp
@foreach ($courses as $course)
@php
$sections = getSections($course->id);
/* $courseActive = collect($sections)->contains(fn($section) => $decryptedSectionId == $section->id); */
$courseActive = $firstSegment === 'sectiondetails' ? collect($sections)->contains(fn($section) => $decryptedSectionId == $section->id) : false;
$result = getHistory($course->id);
@endphp
@php
$isIntroCourse = $course->slug == 'about-this-course';
// Current course exam status
$examStatus = $isIntroCourse ? true : getUserExamStatus($course->id, Auth::user()->id);
$examStatus = $examStatus ? true : null;
// Show if:
// - it's already completed
// - or previous course is done
// - or it's intro
$shouldShow = $examStatus || $previousExamStatus || $isIntroCourse;
// Disable click only if neither current nor previous is done
$disabled = !$examStatus && !$previousExamStatus && !$isIntroCourse;
$linkStyle = $disabled ? 'pointer-events: none; opacity: 0.5; cursor: not-allowed;' : '';
$courseUrl = env('APP_URL') . 'course/' . $course->slug;
@endphp
{{-- {{$loop->parent->iteration}}.{{$loop->iteration}} --}}
@php
// Store for next loop
$previousExamStatus = $examStatus;
@endphp
@endforeach
{{-- --}}