<?php

namespace App\Http\Controllers;

use App\Models\Evaluation;
use App\Models\Indicator;
use App\Models\Land;
use App\Models\Rule;
use App\Models\User;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function admin()
    {
        $userCount = User::count();
        $landCount = Land::count();
        $indicatorCount = Indicator::whereIn('id', function ($query) {
            $query->select('indicator_id')->from('rule');
        })->count();
        $rulesCount = Rule::count();

        $evaluations = Evaluation::with('land.detailLands')->get();
        return view('dashboard.admin', compact('userCount', 'landCount', 'indicatorCount', 'rulesCount', 'evaluations'));
    }

    public function petugas()
    {
        $landCount = Land::where('user_id', auth()->id())->count();
        $indicatorCount = Indicator::whereIn('id', function ($query) {
            $query->select('indicator_id')->from('rule');
        })->count();

        $evaluations = Evaluation::with('land.detailLands')->where('user_id', auth()->id())->get();
        return view('dashboard.petugas', compact('landCount', 'indicatorCount', 'evaluations'));
    }
}
