<?php
/**
 * Página completa para la sección de autores directa, para fines de prueba
 */
// Configuraciones básicas
session_start();
$currentLanguage = 'es';
$text = [
    'authors' => 'Autores',
    'authorsDesc' => 'Añada información sobre los autores del trabajo',
    'previous' => 'Anterior',
    'next' => 'Siguiente'
];
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sección de Autores - TRAUMA 2025</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        /* Estilos básicos inline para prueba */
        :root {
            --primary-color: #4eb1b9;
            --secondary-color: #37b698;
            --tertiary-color: #427d6e;
            --dark-color: #327063;
            --light-color: #a6d1c4;
            --text-color: #333;
            --light-gray: #f5f5f5;
            --medium-gray: #e0e0e0;
            --border-color: #ccc;
            --success-color: #37b698;
            --error-color: #e74c3c;
        }
        
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { 
            font-family: 'Segoe UI', Roboto, Arial, sans-serif; 
            line-height: 1.6; 
            color: var(--text-color); 
            background-color: #f9f9f9;
            padding: 20px;
        }
        
        .container { 
            width: 100%; 
            max-width: 1200px; 
            margin: 0 auto; 
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            padding: 30px;
        }
        
        .section-header {
            margin-bottom: 30px;
        }
        
        .section-title {
            font-size: 24px;
            color: var(--tertiary-color);
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .section-title i {
            color: var(--primary-color);
        }
        
        .section-description {
            color: #666;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: var(--tertiary-color);
        }
        
        .required::after {
            content: "*";
            color: var(--error-color);
            margin-left: 4px;
        }
        
        input, select, textarea {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
            background-color: #f9fafb;
        }
        
        input:focus, select:focus, textarea:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(78, 177, 185, 0.2);
            background-color: white;
        }
        
        .radio-group {
            display: flex;
            gap: 20px;
        }
        
        .radio-option {
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
        }
        
        .radio-option input[type="radio"] {
            width: auto;
        }
        
        .author-note {
            background-color: #fff9e6;
            padding: 15px;
            margin-bottom: 25px;
            border-radius: 8px;
            border-left: 5px solid #f39c12;
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .author-note i {
            font-size: 24px;
            color: #f39c12;
        }
        
        .author-card {
            background-color: #f9f9f9;
            padding: La25px;
            border-radius: 8px;
            margin-bottom: 25px;
            border-left: 4px solid var(--secondary-color);
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        }
        
        .author-card h3 {
            color: var(--dark-color);
            margin-bottom: 20px;
            font-size: 18px;
            display: flex;
            align-items: center;
            gap: 10px;
            border-bottom: 1px solid var(--light-color);
            padding-bottom: 10px;
        }
        
        .author-card h3 i {
            color: var(--secondary-color);
        }
        
        .form-row {
            display: flex;
            gap: 20px;
            margin-bottom: 0;
        }
        
        .form-col {
            flex: 1;
        }
        
        .help-text {
            font-size: 13px;
            color: #666;
            margin-top: 5px;
        }
        
        .error-message {
            color: var(--error-color);
            font-size: 13px;
            margin-top: 5px;
            display: none;
        }
        
        .btn {
            display: inline-block;
            padding: 12px 24px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-weight: 600;
            font-size: 16px;
            transition: all 0.3s ease;
        }
        
        .btn:hover {
            background-color: var(--tertiary-color);
            transform: translateY(-2px);
        }
        
        .btn i {
            margin-right: 8px;
        }
        
        .btn-next i {
            margin-left: 8px;
            margin-right: 0;
        }
        
        .form-navigation {
            display: flex;
            justify-content: space-between;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid var(--light-gray);
        }
        
        @media (max-width: 768px) {
            .form-row {
                flex-direction: column;
                gap: 0;
            }
            
            .container {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="section-header">
            <h2 class="section-title"><i class="fas fa-users"></i> <?php echo $text['authors']; ?></h2>
            <p class="section-description"><?php echo $text['authorsDesc']; ?></p>
        </div>
        
        <form id="authors-form">
            <div class="form-group">
                <label for="author_count" class="required">Número de Autores</label>
                <select id="author_count" name="author_count" required>
                    <option value="" disabled>Seleccione la cantidad de autores</option>
                    <?php for ($i = 1; $i <= 10; $i++): ?>
                    <option value="<?php echo $i; ?>" <?php echo $i == 1 ? 'selected' : ''; ?>><?php echo $i; ?> <?php echo $i == 1 ? 'autor' : 'autores'; ?></option>
                    <?php endfor; ?>
                </select>
                <span class="help-text"><i class="fas fa-info-circle"></i> Por favor indique el número total de autores (máximo 10)</span>
            </div>
            
            <div class="author-note">
                <i class="fas fa-info-circle"></i>
                <p>Proporcione la información para todos los autores. El primer autor será considerado el autor principal y contacto para correspondencia.</p>
            </div>
            
            <!-- Contenedor para autores adicionales (se llenará con JavaScript) -->
            <div id="additional-authors-container"></div>
            
            <!-- Formulario del primer autor siempre visible -->
            <div class="author-card" id="author-1-card">
                <h3><i class="fas fa-user-circle"></i> Autor Principal</h3>
                
                <div class="form-group">
                    <label for="author_1_title" class="required">Título</label>
                    <select id="author_1_title" name="authors[1][title]" required>
                        <option value="" selected disabled>Seleccione un título</option>
                        <option value="Dr.">Dr.</option>
                        <option value="Dra.">Dra.</option>
                        <option value="Sr.">Sr.</option>
                        <option value="Sra.">Sra.</option>
                        <option value="Prof.">Prof.</option>
                        <option value="Lic.">Lic.</option>
                        <option value="Ing.">Ing.</option>
                        <option value="Otro">Otro</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label for="author_1_name" class="required">Nombre Completo</label>
                    <input type="text" id="author_1_name" name="authors[1][name]" required placeholder="Ingrese el nombre completo del autor">
                </div>
                
                <div class="form-group">
                    <label for="author_1_email" class="required">Correo Electrónico</label>
                    <input type="email" id="author_1_email" name="authors[1][email]" required placeholder="Ingrese el correo electrónico">
                </div>
                
                <div class="form-group">
                    <label class="required">¿Es el Autor Principal Miembro de la SPT?</label>
                    <div class="radio-group">
                        <label class="radio-option">
                            <input type="radio" id="author_1_spt_yes" name="authors[1][is_spt_member]" value="yes" required>
                            <span>Sí</span>
                        </label>
                        <label class="radio-option">
                            <input type="radio" id="author_1_spt_no" name="authors[1][is_spt_member]" value="no">
                            <span>No</span>
                        </label>
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-col">
                        <div class="form-group">
                            <label for="author_1_institution" class="required">Institución</label>
                            <input type="text" id="author_1_institution" name="authors[1][institution]" required placeholder="Ingrese la institución del autor">
                        </div>
                    </div>
                    <div class="form-col">
                        <div class="form-group">
                            <label for="author_1_country" class="required">País</label>
                            <select id="author_1_country" name="authors[1][country]" required>
                                <option value="" selected disabled>Seleccione un país</option>
                                <option value="AR">Argentina</option>
                                <option value="BO">Bolivia</option>
                                <option value="BR">Brasil</option>
                                <option value="CA">Canadá</option>
                                <option value="CL">Chile</option>
                                <option value="CO">Colombia</option>
                                <option value="CR">Costa Rica</option>
                                <option value="CU">Cuba</option>
                                <option value="EC">Ecuador</option>
                                <option value="SV">El Salvador</option>
                                <option value="ES">España</option>
                                <option value="US">Estados Unidos</option>
                                <option value="GT">Guatemala</option>
                                <option value="HN">Honduras</option>
                                <option value="MX">México</option>
                                <option value="NI">Nicaragua</option>
                                <option value="PA">Panamá</option>
                                <option value="PY">Paraguay</option>
                                <option value="PE">Perú</option>
                                <option value="PR">Puerto Rico</option>
                                <option value="DO">República Dominicana</option>
                                <option value="UY">Uruguay</option>
                                <option value="VE">Venezuela</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="form-navigation">
                <button type="button" class="btn btn-prev"><i class="fas fa-arrow-left"></i> <?php echo $text['previous']; ?></button>
                <button type="button" class="btn btn-next"><?php echo $text['next']; ?> <i class="fas fa-arrow-right"></i></button>
            </div>
        </form>
    </div>

    <!-- Template para autores adicionales -->
    <template id="author-template">
        <div class="author-card" data-author-id="{AUTHOR_ID}">
            <h3><i class="fas fa-user-circle"></i> Autor <span class="author-number">{AUTHOR_NUMBER}</span></h3>
            
            <div class="form-group">
                <label for="author_{AUTHOR_ID}_title" class="required">Título</label>
                <select id="author_{AUTHOR_ID}_title" name="authors[{AUTHOR_ID}][title]" required>
                    <option value="" selected disabled>Seleccione un título</option>
                    <option value="Dr.">Dr.</option>
                    <option value="Dra.">Dra.</option>
                    <option value="Sr.">Sr.</option>
                    <option value="Sra.">Sra.</option>
                    <option value="Prof.">Prof.</option>
                    <option value="Lic.">Lic.</option>
                    <option value="Ing.">Ing.</option>
                    <option value="Otro">Otro</option>
                </select>
            </div>
            
            <div class="form-group">
                <label for="author_{AUTHOR_ID}_name" class="required">Nombre Completo</label>
                <input type="text" id="author_{AUTHOR_ID}_name" name="authors[{AUTHOR_ID}][name]" required placeholder="Ingrese el nombre completo del autor">
            </div>
            
            <div class="form-group">
                <label for="author_{AUTHOR_ID}_email" class="required">Correo Electrónico</label>
                <input type="email" id="author_{AUTHOR_ID}_email" name="authors[{AUTHOR_ID}][email]" required placeholder="Ingrese el correo electrónico">
            </div>
            
            <div class="form-group">
                <label class="required">¿Es el Autor <span class="author-number">{AUTHOR_NUMBER}</span> Miembro de la SPT?</label>
                <div class="radio-group">
                    <label class="radio-option">
                        <input type="radio" id="author_{AUTHOR_ID}_spt_yes" name="authors[{AUTHOR_ID}][is_spt_member]" value="yes" required>
                        <span>Sí</span>
                    </label>
                    <label class="radio-option">
                        <input type="radio" id="author_{AUTHOR_ID}_spt_no" name="authors[{AUTHOR_ID}][is_spt_member]" value="no">
                        <span>No</span>
                    </label>
                </div>
            </div>
            
            <div class="form-row">
                <div class="form-col">
                    <div class="form-group">
                        <label for="author_{AUTHOR_ID}_institution" class="required">Institución</label>
                        <input type="text" id="author_{AUTHOR_ID}_institution" name="authors[{AUTHOR_ID}][institution]" required placeholder="Ingrese la institución del autor">
                    </div>
                </div>
                <div class="form-col">
                    <div class="form-group">
                        <label for="author_{AUTHOR_ID}_country" class="required">País</label>
                        <select id="author_{AUTHOR_ID}_country" name="authors[{AUTHOR_ID}][country]" required>
                            <option value="" selected disabled>Seleccione un país</option>
                            <option value="AR">Argentina</option>
                            <option value="BO">Bolivia</option>
                            <option value="BR">Brasil</option>
                            <option value="CA">Canadá</option>
                            <option value="CL">Chile</option>
                            <option value="CO">Colombia</option>
                            <option value="CR">Costa Rica</option>
                            <option value="CU">Cuba</option>
                            <option value="EC">Ecuador</option>
                            <option value="SV">El Salvador</option>
                            <option value="ES">España</option>
                            <option value="US">Estados Unidos</option>
                            <option value="GT">Guatemala</option>
                            <option value="HN">Honduras</option>
                            <option value="MX">México</option>
                            <option value="NI">Nicaragua</option>
                            <option value="PA">Panamá</option>
                            <option value="PY">Paraguay</option>
                            <option value="PE">Perú</option>
                            <option value="PR">Puerto Rico</option>
                            <option value="DO">República Dominicana</option>
                            <option value="UY">Uruguay</option>
                            <option value="VE">Venezuela</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </template>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Manejo dinámico de autores adicionales
            const authorCountSelect = document.getElementById('author_count');
            const additionalAuthorsContainer = document.getElementById('additional-authors-container');
            const authorTemplate = document.getElementById('author-template');
            
            if (authorCountSelect && additionalAuthorsContainer && authorTemplate) {
                // Función para generar formularios de autores adicionales
                function generateAdditionalAuthorForms(count) {
                    // Limpiar el contenedor de autores adicionales
                    additionalAuthorsContainer.innerHTML = '';
                    
                    // No generamos el autor 1 porque ya está fijo en el HTML
                    for (let i = 1; i < count; i++) {
                        const authorId = i + 1;
                        const authorNumber = i + 1;
                        
                        // Clonar el template
                        const authorHtml = authorTemplate.innerHTML
                            .replace(/{AUTHOR_ID}/g, authorId)
                            .replace(/{AUTHOR_NUMBER}/g, authorNumber);
                        
                        // Crear un div para contener el formulario del autor
                        const authorDiv = document.createElement('div');
                        authorDiv.innerHTML = authorHtml;
                        
                        // Añadir al contenedor de autores adicionales
                        additionalAuthorsContainer.appendChild(authorDiv.firstElementChild);
                    }
                }
                
                // Escuchar cambios en el selector de número de autores
                authorCountSelect.addEventListener('change', function() {
                    const count = parseInt(this.value, 10);
                    if (!isNaN(count) && count > 0 && count <= 10) {
                        generateAdditionalAuthorForms(count);
                    }
                });
                
                // Generar el formulario inicial si hay un valor preseleccionado
                if (authorCountSelect.value) {
                    const count = parseInt(authorCountSelect.value, 10);
                    if (!isNaN(count) && count > 1) { // Solo si es más de 1
                        generateAdditionalAuthorForms(count);
                    }
                }
            }
            
            // Simular acciones de navegación (solo para demostración)
            document.querySelector('.btn-prev').addEventListener('click', function() {
                alert('Navegando a la sección anterior...');
            });
            
            document.querySelector('.btn-next').addEventListener('click', function() {
                // Validación básica del formulario
                const form = document.getElementById('authors-form');
                const requiredFields = form.querySelectorAll('[required]');
                let isValid = true;
                
                requiredFields.forEach(field => {
                    if (field.type === 'radio') {
                        // Para radios, verificar si alguno en el mismo grupo está marcado
                        if (!document.querySelector(`input[name="${field.name}"]:checked`)) {
                            isValid = false;
                            // Encontrar el elemento padre para mostrar el error
                            const fieldGroup = field.closest('.form-group');
                            if (fieldGroup) {
                                const errorMsg = fieldGroup.querySelector('.error-message');
                                if (errorMsg) {
                                    errorMsg.style.display = 'block';
                                }
                            }
                        }
                    } else if (!field.value.trim()) {
                        isValid = false;
                        field.style.borderColor = 'var(--error-color)';
                        // Mostrar mensaje de error si existe
                        const errorId = `${field.id}-error`;
                        const errorMsg = document.getElementById(errorId);
                        if (errorMsg) {
                            errorMsg.style.display = 'block';
                        }
                    }
                });
                
                if (isValid) {
                    alert('Formulario válido. Navegando a la siguiente sección...');
                } else {
                    alert('Por favor, complete todos los campos obligatorios.');
                }
            });
        });
    </script>
</body>
</html>