<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use App\Voter;

class MayaController extends Controller
{
    public function index()
    {
        $electionId = 8;

        // Only virtual attendees (kehadiran = 2) for election_id = 8
        $virtuals = Voter::where('election_id', $electionId)
                         ->where('kehadiran', 2)
                         ->get();

        // Total virtual attendees
        $total_virtuals = Voter::where('election_id', $electionId)
                               ->where('kehadiran', 2)
                               ->count();

        // Total voters for election 8
        $votes = Voter::where('election_id', $electionId)->count();

        // All voters for the election
        $voters = Voter::where('election_id', $electionId)->get();

        // Load view into PDF
        $pdf = App::make('dompdf.wrapper');
        $pdf->loadView('report.maya', compact('virtuals', 'voters', 'total_virtuals', 'votes'));

        return $pdf->stream();
    }
}
