<?php
// includes/footer.php

// Previne acesso direto
if (!defined('BASE_PATH')) {
    die('Acesso direto não permitido');
}

?>
    </main>
    
    <!-- Footer -->
    <footer class="footer mt-5">
        <div class="footer-top py-5" style="background: var(--dark-color);">
            <div class="container">
                <div class="row g-4">
                    <div class="col-lg-4 col-md-6">
                        <div class="footer-info">
                            <h3 class="text-white mb-4">
                                <img src="/assets/img/logo-white.png" alt="<?php echo SITE_NAME; ?>" height="40">
                                <?php echo SITE_NAME; ?>
                            </h3>
                            <p class="text-light mb-4">
                                Transforma tu carrera a través de una educación gratuita y de calidad.
                            </p>
                            <div class="social-links">
                                <a href="#" class="facebook" aria-label="Facebook">
                                    <i class="fab fa-facebook"></i>
                                </a>
                                <a href="#" class="instagram" aria-label="Instagram">
                                    <i class="fab fa-instagram"></i>
                                </a>
                                <a href="#" class="linkedin" aria-label="LinkedIn">
                                    <i class="fab fa-linkedin"></i>
                                </a>
                                <a href="#" class="youtube" aria-label="YouTube">
                                    <i class="fab fa-youtube"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-lg-2 col-md-6">
                        <h4 class="text-white mb-4">Enlaces Rápidos</h4>
                        <ul class="list-unstyled footer-links">
                            <li><a href="/">Inicio</a></li>
                            <li><a href="/cursos.php">Cursos</a></li>
                            <li><a href="/sobre.php">Sobre Nosotros</a></li>
                            <li><a href="/contacto.php">Contacto</a></li>
                        </ul>
                    </div>
                   
                    <div class="col-lg-4 col-md-6">
                        <h4 class="text-white mb-4">Boletín</h4>
                        <p class="text-light mb-4">
                            Recibe novedades sobre cursos gratuitos y contenido exclusivo.
                        </p>
                        <form class="newsletter-form" id="newsletterForm">
                            <div class="input-group">
                                <input type="email" class="form-control" id="newsletterEmail" placeholder="Tu correo electrónico" required>
                                <button class="btn btn-primary" type="submit" id="newsletterBtn">
                                    <span class="btn-text">Suscribirse</span>
                                    <span class="btn-loading" style="display: none;">
                                        <i class="fas fa-spinner fa-spin"></i>
                                    </span>
                                </button>
                            </div>
                            <div id="newsletterMessage" class="newsletter-message" style="display: none;"></div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="footer-bottom py-3" style="background: #111827;">
            <div class="container">
                <div class="row align-items-center">
                    <div class="col-md-6 text-center text-md-start">
                        <p class="mb-md-0 text-light">
                            &copy; <?php echo date('Y'); ?> <?php echo SITE_NAME; ?>. 
                            Todos los derechos reservados.
                        </p>
                    </div>
                    <div class="col-md-6 text-center text-md-end">
                        <ul class="list-inline mb-0">
                            <li class="list-inline-item">
                                <a href="/privacidad.php">Política de Privacidad</a>
                            </li>
                            <li class="list-inline-item">
                                <a href="/terminos.php">Términos de Uso</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </footer>
    
    <style>
        :root {
            --primary-color: #4F46E5;
            --secondary-color: #7C3AED;
            --dark-color: #1F2937;
            --gradient: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
        }
        
        .footer {
            color: rgba(255, 255, 255, 0.8);
        }
        
        .footer h4 {
            font-size: 1.25rem;
            font-weight: 600;
            margin-bottom: 1.5rem;
            position: relative;
        }
        
        .footer h4::after {
            content: '';
            position: absolute;
            bottom: -8px;
            left: 0;
            width: 40px;
            height: 3px;
            background: var(--gradient);
            border-radius: 2px;
        }
        
        .footer-links {
            margin: 0;
            padding: 0;
        }
        
        .footer-links li {
            margin-bottom: 0.75rem;
        }
        
        .footer-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: all 0.3s ease;
            position: relative;
            display: inline-block;
        }
        
        .footer-links a:hover {
            color: var(--primary-color);
            transform: translateX(5px);
        }
        
        .footer-links a::before {
            content: '→';
            position: absolute;
            left: -20px;
            opacity: 0;
            transition: all 0.3s ease;
            color: var(--primary-color);
        }
        
        .footer-links a:hover::before {
            opacity: 1;
            left: -15px;
        }
        
        .social-links {
            margin-top: 1.5rem;
            display: flex;
            gap: 0.75rem;
        }
        
        .social-links a {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 45px;
            height: 45px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            color: white;
            text-decoration: none;
            transition: all 0.3s ease;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .social-links a:hover {
            background: var(--gradient);
            transform: translateY(-3px) scale(1.1);
            box-shadow: 0 8px 25px rgba(79, 70, 229, 0.4);
        }
        
        .social-links .facebook:hover {
            background: linear-gradient(135deg, #1877f2, #42a5f5);
        }
        
        .social-links .instagram:hover {
            background: linear-gradient(135deg, #e4405f, #fd1d1d, #fcb045);
        }
        
        .social-links .linkedin:hover {
            background: linear-gradient(135deg, #0077b5, #00a0dc);
        }
        
        .social-links .youtube:hover {
            background: linear-gradient(135deg, #ff0000, #ff4500);
        }
        
        .newsletter-form {
            position: relative;
        }
        
        .newsletter-form .form-control {
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: white;
            padding: 0.875rem 1rem;
            border-radius: 12px 0 0 12px;
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .newsletter-form .form-control:focus {
            background: rgba(255, 255, 255, 0.15);
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
            color: white;
        }
        
        .newsletter-form .form-control::placeholder {
            color: rgba(255, 255, 255, 0.6);
        }
        
        .newsletter-form .btn {
            border-radius: 0 12px 12px 0;
            padding: 0.875rem 1.5rem;
            background: var(--gradient);
            border: none;
            font-weight: 600;
            transition: all 0.3s ease;
            min-width: 120px;
        }
        
        .newsletter-form .btn:hover:not(:disabled) {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(79, 70, 229, 0.4);
        }
        
        .newsletter-form .btn:disabled {
            opacity: 0.8;
            cursor: not-allowed;
        }
        
        .newsletter-message {
            margin-top: 0.75rem;
            padding: 0.5rem 0.75rem;
            border-radius: 8px;
            font-size: 0.875rem;
            font-weight: 500;
            animation: slideDown 0.3s ease-out;
        }
        
        .newsletter-message.success {
            background: rgba(16, 185, 129, 0.2);
            color: #10B981;
            border: 1px solid rgba(16, 185, 129, 0.3);
        }
        
        .newsletter-message.error {
            background: rgba(239, 68, 68, 0.2);
            color: #EF4444;
            border: 1px solid rgba(239, 68, 68, 0.3);
        }
        
        .newsletter-message.info {
            background: rgba(59, 130, 246, 0.2);
            color: #3B82F6;
            border: 1px solid rgba(59, 130, 246, 0.3);
        }
        
        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .footer-bottom {
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
        }
        
        .footer-bottom a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: all 0.3s ease;
            position: relative;
        }
        
        .footer-bottom a:hover {
            color: var(--primary-color);
        }
        
        .footer-bottom a::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: var(--gradient);
            transition: width 0.3s ease;
        }
        
        .footer-bottom a:hover::after {
            width: 100%;
        }
        
        .list-inline-item:not(:last-child) {
            margin-right: 1.5rem;
        }
        
        .footer-info h3 {
            background: var(--gradient);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 700;
        }
        
        @media (max-width: 768px) {
            .footer h4::after {
                left: 50%;
                transform: translateX(-50%);
            }
            
            .footer-info {
                text-align: center;
            }
            
            .footer-info h3 {
                font-size: 1.5rem;
            }
            
            .social-links {
                justify-content: center;
            }
            
            .footer-bottom {
                text-align: center;
            }
            
            .footer-bottom .row > div {
                margin-bottom: 1rem;
            }
            
            .list-inline-item:not(:last-child) {
                margin-right: 1rem;
            }
            
            .footer-links a::before {
                display: none;
            }
            
            .footer-links a:hover {
                transform: none;
            }
        }
        
        /* Animações */
        .footer {
            animation: fadeInUp 0.8s ease-out;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .footer-links li {
            animation: fadeInLeft 0.6s ease-out;
            animation-fill-mode: both;
        }
        
        .footer-links li:nth-child(1) { animation-delay: 0.1s; }
        .footer-links li:nth-child(2) { animation-delay: 0.2s; }
        .footer-links li:nth-child(3) { animation-delay: 0.3s; }
        .footer-links li:nth-child(4) { animation-delay: 0.4s; }
        
        @keyframes fadeInLeft {
            from {
                opacity: 0;
                transform: translateX(-20px);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }
        
        .social-links a {
            animation: bounceIn 0.6s ease-out;
            animation-fill-mode: both;
        }
        
        .social-links a:nth-child(1) { animation-delay: 0.1s; }
        .social-links a:nth-child(2) { animation-delay: 0.2s; }
        .social-links a:nth-child(3) { animation-delay: 0.3s; }
        .social-links a:nth-child(4) { animation-delay: 0.4s; }
        
        @keyframes bounceIn {
            0%, 20%, 40%, 60%, 80% {
                transform: translateY(0) scale(1);
                animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
            }
            0% {
                opacity: 0;
                transform: scale3d(.3, .3, .3);
            }
            20% {
                transform: scale3d(1.1, 1.1, 1.1);
            }
            40% {
                transform: scale3d(.9, .9, .9);
            }
            60% {
                opacity: 1;
                transform: scale3d(1.03, 1.03, 1.03);
            }
            80% {
                transform: scale3d(.97, .97, .97);
            }
            100% {
                opacity: 1;
                transform: scale3d(1, 1, 1);
            }
        }
    </style>
    
    <!-- Bootstrap Bundle JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- Smooth Scroll -->
    <script>
        // Smooth scroll para links internos
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                const target = document.querySelector(this.getAttribute('href'));
                if (target) {
                    target.scrollIntoView({
                        behavior: 'smooth',
                        block: 'start'
                    });
                }
            });
        });
        
        // Newsletter form handler com AJAX
        document.addEventListener('DOMContentLoaded', function() {
            const newsletterForm = document.getElementById('newsletterForm');
            if (newsletterForm) {
                newsletterForm.addEventListener('submit', function(e) {
                    e.preventDefault();
                    
                    const emailInput = document.getElementById('newsletterEmail');
                    const submitBtn = document.getElementById('newsletterBtn');
                    const btnText = submitBtn.querySelector('.btn-text');
                    const btnLoading = submitBtn.querySelector('.btn-loading');
                    const messageDiv = document.getElementById('newsletterMessage');
                    
                    const email = emailInput.value.trim();
                    
                    if (!email) {
                        showMessage('Por favor, insira um email válido.', 'error');
                        return;
                    }
                    
                    if (!isValidEmail(email)) {
                        showMessage('Por favor, insira um email válido.', 'error');
                        return;
                    }
                    
                    // Mostrar loading
                    btnText.style.display = 'none';
                    btnLoading.style.display = 'inline';
                    submitBtn.disabled = true;
                    hideMessage();
                    
                    // Enviar requisição AJAX
                    fetch('/newsletter/subscribe', {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json',
                            'X-Requested-With': 'XMLHttpRequest'
                        },
                        body: JSON.stringify({
                            email: email,
                            source: 'footer_form'
                        })
                    })
                    .then(response => {
                        if (!response.ok) {
                            throw new Error('Error en la respuesta del servidor');
                        }
                        return response.json();
                    })
                    .then(data => {
                        if (data.success) {
                            showMessage(data.message, 'success');
                            emailInput.value = '';
                            
                            // Opcional: tracking de conversão
                            if (typeof gtag !== 'undefined') {
                                gtag('event', 'newsletter_signup', {
                                    'event_category': 'engagement',
                                    'event_label': 'footer_form'
                                });
                            }
                        } else {
                            showMessage(data.message, 'error');
                        }
                    })
                    .catch(error => {
                        console.error('Erro na inscrição:', error);
                        showMessage('Error al procesar la suscripción. Intenta de nuevo más tarde.', 'error');
                    })
                    .finally(() => {
                        // Restaurar botão
                        btnText.style.display = 'inline';
                        btnLoading.style.display = 'none';
                        submitBtn.disabled = false;
                    });
                });
            }
            
            function showMessage(message, type) {
                const messageDiv = document.getElementById('newsletterMessage');
                messageDiv.textContent = message;
                messageDiv.className = 'newsletter-message ' + type;
                messageDiv.style.display = 'block';
                
                // Auto-hide após 5 segundos
                setTimeout(() => {
                    hideMessage();
                }, 5000);
            }
            
            function hideMessage() {
                const messageDiv = document.getElementById('newsletterMessage');
                messageDiv.style.display = 'none';
            }
            
            function isValidEmail(email) {
                const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
                return emailRegex.test(email);
            }
        });
    </script>
    
    <!-- Google Analytics -->
    <?php if (defined('GA_TRACKING_ID')): ?>
    <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo GA_TRACKING_ID; ?>"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', '<?php echo GA_TRACKING_ID; ?>');
    </script>
    <?php endif; ?>
    
    <!-- Scripts customizados da página -->
    <?php if (isset($customScripts)): ?>
        <?php foreach ($customScripts as $script): ?>
            <script src="<?php echo $script; ?>"></script>
        <?php endforeach; ?>
    <?php endif; ?>
    
    <!-- Pixel IntegraOn - Versão Final Silenciosa -->
    <?php
    if (isset($integraOnPixel) && $integraOnPixel->isConfigured()) {
        echo $integraOnPixel->generatePixelScript();
    }
    ?>

    <!-- Script final para envio de UTMs aos pixels -->
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        // Envia UTMs para todos os pixels configurados
        <?php
        if (function_exists('sendUtmsToPixels')) {
            sendUtmsToPixels();
        }
        ?>
    });
    </script>
</body>
</html>