<?php

namespace App\Http\Controllers\ParentPortal;

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

class ChildController extends PageController
{
    use ResolvesParentScope;

    public function index(): View
    {
        return $this->page('parent.children.index', [
            'crumbTitle' => 'My Children',
            'crumbSub' => 'Linked student profiles',
            'students' => $this->guardianStudents(),
            'activeChild' => $this->activeStudent(),
        ]);
    }

    public function show(Student $student): View
    {
        $this->authorizeStudent($student);
        $this->parentScope()->setActiveStudent($student->id);

        $student->load(['classes.classTeacher', 'guardians', 'academicYear']);

        return $this->page('parent.children.show', [
            'crumbTitle' => 'Child Profile',
            'crumbSub' => $student->full_name,
            'student' => $student,
            'students' => $this->guardianStudents(),
            'activeChild' => $student,
        ]);
    }
}
