{{-- resources/views/tests/weekly/index.blade.php --}} @php $user = auth()->user(); $role = $user->membership_status ?? $user->role ?? 'member'; // ✅ Layout resolver (نفس منطقك بس بشكل أنظف) $layout = match ($role) { 'super-admin' => 'layouts.superadmin', 'advisor' => 'layouts.advisor', 'admin', 'moderator' => 'layouts.moderator', default => 'layouts.member', }; @endphp @extends($layout) @section('title', 'الاختبارات الأسبوعية') @section('page-title', '📚 الاختبارات الأسبوعية') @section('content') @php /* ========================= * 1) Page counters (عرض فقط) * ========================= */ $totalCount = $tests->count(); $doneCount = $tests->filter(fn($t) => (int)($t->my_submissions_count ?? 0) > 0)->count(); $pendingCount = max(0, $totalCount - $doneCount); /* ========================= * 2) Helpers (داخل الصفحة) * ========================= */ $nowTs = time(); // ✅ نفس منطقك: دقائق/ساعات/أيام — بس كـ helper $remainingLabel = function (int $fromTs, int $toTs): string { $diffSeconds = max(0, $toTs - $fromTs); $diffMinutes = (int) floor($diffSeconds / 60); if ($diffMinutes < 60) return $diffMinutes . ' دقيقة'; if ($diffMinutes < 1440) return (int) floor($diffMinutes / 60) . ' ساعة'; return (int) floor($diffMinutes / 1440) . ' يوم'; }; // ✅ محرك الـUI لكل اختبار (منطقك + تصنيف منطقي) $uiForTest = function ($test) use ($nowTs, $remainingLabel) { $alreadyDone = (int)($test->my_submissions_count ?? 0) > 0; // ✅ تجنّب N+1 لو عندك withCount('questions') (وإلا fallback) $questionsCount = $test->questions_count ?? $test->questions()->count(); // ✅ منطق الوقت بدون isFuture/isPast (كما هو) $startTs = $test->start_at ? strtotime((string)$test->start_at) : null; $endTs = $test->end_at ? strtotime((string)$test->end_at) : null; $notStartedYet = $startTs && $startTs > $nowTs; $ended = $endTs && $endTs < $nowTs; $timeLeftLabel = null; if ($notStartedYet) { $timeLeftLabel = $remainingLabel($nowTs, (int)$startTs); } // ✅ Chips ستايل سقراط $timeChip = match (true) { $notStartedYet => 'bg-amber-100 text-amber-700 border-amber-200', $ended => 'bg-rose-100 text-rose-700 border-rose-200', default => 'bg-emerald-100 text-emerald-700 border-emerald-200', }; $solveChip = $alreadyDone ? 'bg-cyan-100 text-cyan-700 border-cyan-200' : 'bg-white border border-slate-200 text-slate-600'; $timeLabel = $notStartedYet ? 'لم يبدأ بعد' : ($ended ? 'انتهى' : 'متاح الآن'); $solveLabel = $alreadyDone ? 'تم الحل' : 'بانتظار الحل'; // ✅ تقسيم منطقي للعرض $bucket = match (true) { $notStartedYet => 'not_started', $ended => 'ended', $alreadyDone => 'available_done', default => 'available_pending', }; return compact( 'alreadyDone', 'questionsCount', 'startTs', 'endTs', 'notStartedYet', 'ended', 'timeLeftLabel', 'timeChip', 'solveChip', 'timeLabel', 'solveLabel', 'bucket' ); }; /* ========================= * 3) Build UI map + groups * ========================= */ $testsUi = $tests->map(fn($t) => [ 'model' => $t, 'ui' => $uiForTest($t), ]); $groups = [ 'available_pending' => [ 'title' => '✅ متاح الآن — ابدأ الحل', 'hint' => 'اختبارات جاهزة للحل الآن.', 'items' => $testsUi->filter(fn($x) => $x['ui']['bucket'] === 'available_pending'), ], 'available_done' => [ 'title' => '📌 متاح الآن — تم الحل', 'hint' => 'تقدر تفتح وتراجع نتيجتك.', 'items' => $testsUi->filter(fn($x) => $x['ui']['bucket'] === 'available_done'), ], 'not_started' => [ 'title' => '⏳ لم يبدأ بعد', 'hint' => 'راح ينفتح تلقائياً عند موعده.', 'items' => $testsUi->filter(fn($x) => $x['ui']['bucket'] === 'not_started'), ], 'ended' => [ 'title' => '🧊 انتهت', 'hint' => 'اختبارات انتهى وقتها.', 'items' => $testsUi->filter(fn($x) => $x['ui']['bucket'] === 'ended'), ], ]; @endphp
@include('tests.weekly.partials._hero', compact('user','totalCount','doneCount','pendingCount')) @include('tests.weekly.partials._flash') @if(isset($kpi)) @include('tests.weekly.partials._kpi', compact('kpi')) @endif @include('tests.weekly.partials._sections', compact('groups')) @include('tests.weekly.partials._footer')
@endsection