<?php
session_start();
$meu_cpf = $_SESSION['usuario_cpf'] ?? '';
$entregadores = json_decode(file_get_contents('entregadores.json'), true) ?: [];
$corridas_disponiveis = json_decode(file_get_contents('db_pedidos.json'), true) ?: []; // Para o alerta no radar
$meu_perfil = [];

foreach ($entregadores as $e) {
    if (($e['cpf'] ?? $e['usuario']) == $meu_cpf) { $meu_perfil = $e; break; }
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body class="bg-gray-50">
    <div class="p-6 flex flex-col items-center">
        <div class="relative mb-4 mt-8">
            <div class="w-24 h-24 bg-black rounded-full border-4 border-[#FFD100] flex items-center justify-center overflow-hidden shadow-2xl">
                <i class="fas fa-user text-4xl text-[#FFD100]"></i>
            </div>
            <div class="absolute bottom-0 right-0 bg-green-500 w-6 h-6 rounded-full border-2 border-white"></div>
        </div>
        <h2 class="font-black italic uppercase text-lg"><?php echo $meu_perfil['nome'] ?? 'Entregador'; ?></h2>
        <p class="text-[10px] font-bold text-gray-400 uppercase italic">Média: <?php echo $meu_perfil['media_estrelas'] ?? '5.0'; ?> ★</p>

        <div class="w-full mt-10 space-y-4">
            <div class="bg-white p-5 rounded-[2rem] border border-gray-100 flex items-center gap-4">
                <i class="fas fa-id-card text-gray-300"></i>
                <p class="text-xs font-black italic"><?php echo $meu_cpf; ?></p>
            </div>
            <a href="logout.php" class="bg-red-50 text-red-500 p-5 rounded-[2rem] flex items-center justify-center gap-2 font-black italic uppercase text-[10px] w-full">
                <i class="fas fa-power-off"></i> Sair da Conta
            </a>
        </div>
    </div>

    <nav class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-100 px-8 py-5 z-[100] rounded-t-[2.5rem] shadow-[0_-10px_40px_rgba(0,0,0,0.08)]">
        <div class="max-w-md mx-auto flex justify-between items-center text-gray-300">
            <a href="admin.php" class="flex flex-col items-center transition-all <?php echo (basename($_SERVER['PHP_SELF']) == 'admin.php') ? 'text-black' : ''; ?>">
                <div class="relative">
                    <i class="fas fa-satellite-dish text-xl"></i>
                    <?php if (count($corridas_disponiveis) > 0): ?><span class="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full animate-ping"></span><?php endif; ?>
                </div>
                <span class="text-[8px] font-black uppercase mt-1 italic">Radar</span>
            </a>
            <a href="carteira_entregador.php" class="flex flex-col items-center transition-all <?php echo (basename($_SERVER['PHP_SELF']) == 'carteira_entregador.php') ? 'text-black' : ''; ?>">
                <i class="fas fa-wallet text-xl"></i>
                <span class="text-[8px] font-black uppercase mt-1 italic">Ganhos</span>
            </a>
            <a href="historico_entregas.php" class="flex flex-col items-center transition-all <?php echo (basename($_SERVER['PHP_SELF']) == 'historico_entregas.php') ? 'text-black' : ''; ?>">
                <i class="fas fa-list-ul text-xl"></i>
                <span class="text-[8px] font-black uppercase mt-1 italic">Corridas</span>
            </a>
            <a href="perfil_entregador.php" class="flex flex-col items-center transition-all <?php echo (basename($_SERVER['PHP_SELF']) == 'perfil_entregador.php') ? 'text-black' : ''; ?>">
                <div class="w-6 h-6 rounded-full bg-gray-100 border border-gray-200 flex items-center justify-center overflow-hidden">
                    <i class="fas fa-user text-xs"></i>
                </div>
                <span class="text-[8px] font-black uppercase mt-1 italic">Perfil</span>
            </a>
        </div>
    </nav>
    <div class="h-24"></div>
</body>
</html>