<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sistema de Trámite Documentario</title>
    <link rel="icon" type="image/png" href="<?= BASE_HREF ?>assets/favicon.png">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');

        body {
            background-color: #f8f9fa;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            font-family: 'Poppins', sans-serif;
            color: #343a40; 
        }

        .container {
            text-align: center;
            width: 100%;
            max-width: 500px;
        }

        .title {
            font-size: 22px;
            font-weight: 600;
            color: #495057;
            margin-bottom: 40px;
        }

        .role-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
            gap: 24px;
            justify-content: center;
            max-width: 320px;
            margin: 0 auto 40px;
        }

        .role {
            display: flex;
            flex-direction: column;
            align-items: center;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .circle {
            width: 140px;
            height: 140px;
            background: white;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            border: 3px solid transparent;
            overflow: hidden; 
        }

        .role:hover .circle,
        .role.selected .circle {
            border-color: #007bff;
            box-shadow: 0 6px 14px rgba(0, 123, 255, 0.3);
        }

        .circle img {
            width: 90%;
            height: 90%;
            object-fit: contain;
        }

        .role span {
            font-size: 14px;
            font-weight: 500;
            margin-top: 12px; 
            color: #495057;
        }

        .continue-btn {
            background-color: #007bff;
            color: white;
            font-size: 16px;
            padding: 12px 24px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            transition: 0.3s;
            display: block;
            margin: 20px auto 0;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .continue-btn:disabled {
            background-color: #adb5bd;
            cursor: not-allowed;
            box-shadow: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="title">Hola, ¿con qué rol deseas continuar?</div>
        <div class="role-container">
            <?php foreach ($roles as $type): ?>
                <div class="role" onclick="selectPersonType(this, '<?= $type->name ?>')">
                    <div class="circle">
                        <img src="<?= BASE_SRC ?>assets/roles/<?= $type->name ?>.png" alt="<?= $type->name ?>">
                    </div>
                    <span><?= htmlspecialchars($type->description) ?></span>
                </div>
            <?php endforeach; ?>
        </div>
        <form id="rolForm" action="<?= BASE_ACTION ?>set-role" method="POST">
            <input type="hidden" name="role" id="personTypeInput">
            <button id="continueBtn" class="continue-btn" disabled>Continuar</button>
        </form>
    </div>

    <script>
    let selectedRole = null;

    function selectPersonType(element, role) {
        document.querySelectorAll('.role').forEach(pt => pt.classList.remove('selected'));
        element.classList.add('selected');
        selectedRole = role;
        document.getElementById('personTypeInput').value = role;
        document.getElementById('continueBtn').disabled = false;
    }

    document.getElementById('continueBtn').addEventListener('click', function() {
        if (selectedRole) {
            document.getElementById('rolForm').submit();
        }
    });
</script>
</body>
</html>
