<?php

namespace App\Http\Controllers\ParentPortal;

use App\Http\Controllers\Admin\PageController;
use App\Http\Controllers\ParentPortal\Concerns\ResolvesParentScope;
use App\Models\Assessment;
use Illuminate\View\View;

class ExamController extends PageController
{
    use ResolvesParentScope;

    public function index(): View
    {
        $activeChild = $this->activeStudent();
        abort_unless($activeChild, 403);

        $classIds = $activeChild->classes()->pluck('classes.id');

        $exams = Assessment::query()
            ->with(['subject', 'schoolClass', 'term'])
            ->whereIn('class_id', $classIds)
            ->where('status', 'active')
            ->orderBy('assessment_date')
            ->paginate(20);

        return $this->page('parent.exams.index', [
            'crumbTitle' => 'Exams',
            'crumbSub' => $activeChild->full_name,
            'exams' => $exams,
            'students' => $this->guardianStudents(),
            'activeChild' => $activeChild,
        ]);
    }
}
