<?php

namespace App\Http\Controllers;

class ProfilController extends Controller
{
    public function index()
    {
        $satgasUsers = [];
        
        if (auth()->check() && auth()->user()->isLldiktiRole()) {
            // Fetch Satgas PTS users
            $satgasUsers = \App\Models\User::where('role', 'satgas_kampus')->get();
            
            // Calculate completed cases for each satgas based on their pts_nama
            foreach ($satgasUsers as $satgas) {
                $satgas->completed_cases = \App\Models\Laporan::where('pts_nama', $satgas->pts_nama)
                    ->where('status', 'selesai')
                    ->count();
            }
        }

        return view('profil', compact('satgasUsers'));
    }
}
