<?php

namespace App\Http\Controllers\Student;

use App\Http\Controllers\Admin\PageController;
use App\Services\School\TimetableCalendarService;
use Illuminate\View\View;

class TimetableController extends PageController
{
    public function __construct(private readonly TimetableCalendarService $calendar) {}

    public function index(): View
    {
        $student = auth()->user()?->student;
        $class = $this->calendar->resolveClassForStudent($student);
        $schedule = $this->calendar->mergedSchedule(
            classId: $class?->id,
            studentId: $student?->id,
            audience: 'students',
        );

        return $this->page('student.timetable.index', [
            'crumbTitle' => 'Timetable',
            'crumbSub' => $class?->name ?? 'Your schedule',
            'schedule' => $schedule,
            'class' => $class,
        ]);
    }
}
