<?php
require_once '../../Controlador/Utilidades/Conexion_BD.php';

$conn = new Conexion_BD();

// Consultas rápidas de totales
$totalUsuarios = $conn->getConnection()->query("SELECT COUNT(*) as total FROM usuarios")->fetch_assoc()['total'];
$totalVehiculos = $conn->getConnection()->query("SELECT COUNT(*) as total FROM vehiculos")->fetch_assoc()['total'];
$totalChoferes = $conn->getConnection()->query("SELECT COUNT(*) as total FROM choferes")->fetch_assoc()['total'];
$totalGrifos = $conn->getConnection()->query("SELECT COUNT(*) as total FROM grifos")->fetch_assoc()['total'];

// Total de abastecimientos (vehículos + galoneras)
$totalAbastecimientos = $conn->getConnection()->query("
    SELECT COUNT(*) as total 
    FROM (
        SELECT id FROM control_combustible
        UNION ALL
        SELECT id FROM control_abastecimiento_galonera
    ) AS total_abast
")->fetch_assoc()['total'];

$conn->closeConnection();
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Inicio Administrador</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Boxicons -->
    <link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
    <link rel="stylesheet" href="../../Modelo/Archivos_CSS/Style_Administrador.css" />
</head>
<body>

    <main class="container">
        <h3>Bienvenido Crack!</h3>
        <div class="row g-4 justify-content-center">
            <div class="col-12 col-sm-6 col-md-4 col-lg-3">
                <div class="card-info">
                    <i class='bx bx-user'></i>
                    <h5>Total Usuarios</h5>
                    <p><?= $totalUsuarios ?></p>
                </div>
            </div>

            <div class="col-12 col-sm-6 col-md-4 col-lg-3">
                <div class="card-info">
                    <i class='bx bx-bus'></i>
                    <h5>Total Vehículos</h5>
                    <p><?= $totalVehiculos ?></p>
                </div>
            </div>

            <div class="col-12 col-sm-6 col-md-4 col-lg-3">
                <div class="card-info">
                    <i class='bx bxs-id-card'></i>
                    <h5>Total Conductores</h5>
                    <p><?= $totalChoferes ?></p>
                </div>
            </div>

            <div class="col-12 col-sm-6 col-md-4 col-lg-3">
                <div class="card-info">
                    <i class='bx bxs-gas-pump'></i>
                    <h5>Total Grifos</h5>
                    <p><?= $totalGrifos ?></p>
                </div>
            </div>

            <div class="col-12 col-sm-6 col-md-4 col-lg-3">
                <div class="card-info">
                    <i class='bx bx-tachometer'></i>
                    <h5>Total Abastecimientos</h5>
                    <p><?= $totalAbastecimientos ?></p>
                </div>
            </div>
        </div>
    </main>

</body>
</html>
