<?php
session_start();
// Aqui você deve validar se o usuário é ADMIN
$arquivo = 'solicitacoes_retirada.json';
$solicitacoes = file_exists($arquivo) ? json_decode(file_get_contents($arquivo), true) : [];
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <title>Admin | Rastro de Retiradas BRT</title>
</head>
<body class="bg-slate-50 p-6">

    <div class="max-w-6xl mx-auto">
        <div class="flex items-center justify-between mb-8">
            <div>
                <h1 class="text-2xl font-black text-[#003964] uppercase italic">Controle de <span class="text-yellow-500">Retiradas</span></h1>
                <p class="text-xs font-bold text-slate-400 uppercase tracking-widest">OABCG Soluções Digitais</p>
            </div>
            <div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100">
                <span class="text-[10px] font-black uppercase text-slate-400 block">Total de Pedidos</span>
                <span class="text-xl font-black text-[#003964]"><?php echo count($solicitacoes); ?></span>
            </div>
        </div>

        <div class="bg-white rounded-[2rem] shadow-xl border border-slate-100 overflow-hidden">
            <table class="w-full text-left">
                <thead class="bg-[#003964] text-white uppercase text-[10px] font-black tracking-widest">
                    <tr>
                        <th class="p-5">Data/Hora</th>
                        <th class="p-5">Entregador</th>
                        <th class="p-5">ID Pedido</th>
                        <th class="p-5">Status</th>
                        <th class="p-5 text-center">Ações</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    <?php if(empty($solicitacoes)): ?>
                        <tr><td colspan="5" class="p-10 text-center text-slate-400 font-bold italic">Nenhuma solicitação encontrada.</td></tr>
                    <?php endif; ?>

                    <?php foreach(array_reverse($solicitacoes) as $s): ?>
                    <tr class="hover:bg-slate-50 transition-colors">
                        <td class="p-5 text-xs font-bold text-slate-600"><?php echo $s['data_hora']; ?></td>
                        <td class="p-5 text-xs font-black text-[#003964] italic">
                            <i class="fas fa-bus-alt mr-2 text-yellow-500"></i> <?php echo $s['entregador_nome']; ?>
                        </td>
                        <td class="p-5 text-xs font-mono font-bold text-blue-500">#<?php echo $s['pedido_id']; ?></td>
                        <td class="p-5">
                            <span class="px-3 py-1 rounded-full text-[9px] font-black uppercase 
                                <?php echo $s['status'] == 'Pendente' ? 'bg-yellow-100 text-yellow-700' : 'bg-green-100 text-green-700'; ?>">
                                <?php echo $s['status']; ?>
                            </span>
                        </td>
                        <td class="p-5 text-center">
                            <div class="flex justify-center gap-2">
                                <button class="bg-[#003964] text-white p-2 rounded-lg text-xs hover:bg-green-600"><i class="fas fa-check"></i></button>
                                <button class="bg-red-100 text-red-600 p-2 rounded-lg text-xs hover:bg-red-600 hover:text-white"><i class="fas fa-trash"></i></button>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>

        <div class="mt-6 text-center">
            <p class="text-[10px] font-bold text-slate-400 uppercase italic">Relatório gerado em tempo real • BRT Express Logística</p>
        </div>
    </div>

</body>
</html>