<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Sorteo PHP - Ingreso de Nombres</title>

    <!-- Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">

    <style>
        body {
            background: #f0f2f5;
        }
        .card {
            border-radius: 12px;
        }
        .btn-sorteo {
            font-size: 22px;
            padding: 15px 25px;
            border-radius: 10px;
        }
        .emoji {
            font-size: 40px;
        }
    </style>
</head>
<body>

<div class="container py-4">

    <div class="text-center mb-4">
        <h1 class="fw-bold">🎉 SORTEO ALEATORIO 🎉</h1>
        <p class="text-secondary fs-5">Preparense!!!!!!! jejejeje...</p>
    </div>

    <!-- FORMULARIO oculto (si lo necesitas para registrar automáticamente) -->
    <form action="guardar.php" method="post" class="d-none">
        <input type="hidden" name="nombre" required>
        <button type="submit">Agregar</button>
    </form>

    <!-- TARJETA DE LISTA DE PARTICIPANTES -->
    <div class="card shadow mx-auto mb-4" style="max-width: 700px;">
        <div class="card-header bg-primary text-white text-center">
            <h4 class="mb-0">📋 Lista de participantes activos</h4>
        </div>

        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-striped table-hover mb-0">
                    <thead class="table-dark text-center">
                        <tr>
                            <th>N°</th>
                            <th>DNI</th>
                            <th>Nombres</th>
                            <th>Apellidos</th>
                        </tr>
                    </thead>
                    <tbody class="text-center">
                        <?php
                        include 'conexion.php';
                        $sql = "SELECT * FROM afiliado WHERE estado='ACTIVO' AND (sorteo IS NULL OR sorteo <> 'NO') ORDER BY apepat;";
                        $result = $conn->query($sql);

                        $contador = 1;

                        while ($row = $result->fetch_assoc()) {
                            echo "<tr>";
                            echo "<td>$contador</td>";
                            echo "<td>{$row['dni']}</td>";
                            echo "<td>{$row['nombres']}</td>";
                            echo "<td>{$row['apepat']} {$row['apemat']}</td>";
                            echo "</tr>";
                            $contador++;
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- BOTÓN DE SORTEO -->
    <div class="text-center">
        <form action="sortear.php" method="post">
            <button type="submit" class="btn btn-success btn-sorteo shadow">
                🎲 REALIZAR SORTEO
            </button>
        </form>
    </div>

</div>

</body>
</html>
