<?php

namespace App\Http\Controllers\Student;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Inertia\Inertia;

class DashboardController extends Controller
{
    public function index()
    {
        $user = Auth::user();
        $enrollments = $user->enrollments()
            ->with([
                'course' => fn ($q) => $q->withCount('sections'),
                'course.category',
                'course.instructor',
            ])
            ->latest()
            ->get();

        return Inertia::render('Student/Pages/Dashboard', [
            'enrollments' => $enrollments,
        ]);
    }
}
