<?php
// Pie compartido del panel administrativo.
$ui_admin_footer_session_text = trim((string)($ui_admin_footer_session_text ?? 'Sesión segura')) ?: 'Sesión segura';
?>
        </main>
        <style>
        body.admin-premium .premium-content{padding-bottom:62px!important}
        body.admin-premium .premium-footer{left:248px!important;right:0!important;width:auto!important;min-height:62px!important;padding:0 18px!important;display:block!important;z-index:70!important;box-shadow:0 -10px 28px rgba(15,23,42,.13)!important}
        body.admin-premium .admin-shell.sidebar-collapsed .premium-footer{left:78px!important;right:0!important;width:auto!important}
        body.admin-premium .premium-sidebar{padding-bottom:62px!important}
        .premium-footer-inner{width:min(1320px,calc(100% - 24px));min-height:62px;margin:0 auto;display:grid;grid-template-columns:minmax(190px,.8fr) minmax(300px,1.35fr) minmax(190px,.8fr);align-items:center;gap:18px}
        .premium-footer-brand{color:var(--admin-footer-text);font-size:11.5px;font-weight:900;white-space:nowrap}.premium-footer-copy{color:var(--admin-footer-text);font-size:11.5px;font-weight:650;text-align:center;line-height:1.4}.premium-footer-links{justify-content:flex-end}.premium-footer-status{display:inline!important;padding:0!important;border:0!important;border-radius:0!important;background:transparent!important;box-shadow:none!important;color:var(--admin-footer-text)!important;font-size:10.5px!important;font-weight:700!important;line-height:1.4!important;cursor:default!important;white-space:nowrap}
        @media(max-width:1024px){body.admin-premium .premium-footer,body.admin-premium .admin-shell.sidebar-collapsed .premium-footer{left:0!important;right:0!important;width:auto!important}}
        @media(max-width:760px){body.admin-premium .premium-footer,body.admin-premium .admin-shell.sidebar-collapsed .premium-footer{position:relative!important;left:0!important;min-height:auto!important}.premium-footer-inner{width:100%;min-height:auto;padding:13px 0;grid-template-columns:1fr;justify-items:center;gap:7px}.premium-footer-links{justify-content:center}.premium-footer-brand,.premium-footer-status{white-space:normal;text-align:center}body.admin-premium .premium-sidebar{padding-bottom:0!important}}
        
        /* AFENIXX-ADMIN-FOOTER-FLOW-20260724 */
        body.admin-premium .premium-content{
            padding-bottom:0!important;
        }

        body.admin-premium .premium-footer,
        body.admin-premium .admin-shell.sidebar-collapsed .premium-footer{
            position:relative!important;
            inset:auto!important;
            left:auto!important;
            right:auto!important;
            bottom:auto!important;
            width:100%!important;
            z-index:10!important;
            box-shadow:0 -8px 24px rgba(15,23,42,.08)!important;
        }

        body.admin-premium .premium-sidebar{
            padding-bottom:0!important;
        }
</style>
        <footer class="premium-footer">
            <div class="premium-footer-inner">
                <span class="premium-footer-brand"><strong><?= htmlspecialchars($ui_title_system ?? 'Ave Fénix') ?></strong></span>
                <span class="premium-footer-copy"><?= htmlspecialchars($ui_footer_text ?? 'Panel administrativo') ?></span>
                <span class="premium-footer-links"><span class="premium-footer-status"><?= htmlspecialchars($ui_admin_footer_session_text) ?> · <?= htmlspecialchars($rol_actual ?? ($_SESSION['admin']['rol'] ?? 'Usuario')) ?></span></span>
            </div>
        </footer>
    </div>
</div>

<script>window.jQuery || document.write('<script src="https://code.jquery.com/jquery-3.6.0.min.js"><\/script>');</script>
<script>
if (window.jQuery && !jQuery.fn.DataTable) {
    document.write('<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"><\/script>');
}
</script>
<script>window.Swal || document.write('<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"><\/script>');</script>
<script>
if (window.jQuery && !jQuery.fn.select2) {
    document.write('<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.full.min.js"><\/script>');
}
</script>

<script>
(function ($) {
    if (!$) return;

    $(document).ready(function () {
        const adminMenuButton = $('#admin-menu-button');
        const adminConfigDropdownMenu = $('#admin-config-dropdown-menu');
        const myDataModal = $('#myDataModal');
        const myPlanModal = $('#myPlanModal');
        const brandPrimary = (getComputedStyle(document.documentElement).getPropertyValue('--brand-primary') || '#dc2626').trim();

        if (adminMenuButton.length && "<?php echo basename($_SERVER['PHP_SELF']); ?>" === "index.php") {
            $(document).on('click', '#admin-menu-button', function (event) {
                event.stopPropagation();
                adminConfigDropdownMenu.toggleClass('hidden');
                $(this).attr('aria-expanded', adminConfigDropdownMenu.hasClass('hidden') ? 'false' : 'true');
            });

            $(document).on('click', function (event) {
                if (!$(event.target).closest('#admin-menu-button, #admin-config-dropdown-menu').length) {
                    adminConfigDropdownMenu.addClass('hidden');
                    adminMenuButton.attr('aria-expanded', 'false');
                }
            });

            adminConfigDropdownMenu.on('click', 'a', function (e) {
                const targetId = $(this).attr('id');
                adminConfigDropdownMenu.addClass('hidden');
                adminMenuButton.attr('aria-expanded', 'false');

                if (targetId === 'configure-my-data-btn' && myDataModal.length) {
                    e.preventDefault();
                    e.stopPropagation();
                    myDataModal.removeClass('hidden').addClass('is-open');
                    return;
                }

                if (targetId === 'configure-my-plan-btn' && myPlanModal.length) {
                    e.preventDefault();
                    e.stopPropagation();
                    myPlanModal.removeClass('hidden').addClass('is-open');
                }
                // Los enlaces reales, como “Mi suscripción y saldo”, continúan su navegación normal.
            });

            $(document).on('click', '#openMyDataModalFromNotification', function (e) {
                e.preventDefault();
                if (myDataModal.length) myDataModal.removeClass('hidden').addClass('is-open');
            });
        }

        $(document).on('click', '#closeMyDataModalBtn, #cancelMyDataModalBtn', function () {
            myDataModal.removeClass('is-open');
        });

        $(document).on('submit', '#myDataForm', function (e) {
            e.preventDefault();
            $.ajax({
                url: 'procesar_datos.php',
                type: 'POST',
                data: $(this).serialize(),
                dataType: 'json',
                success: function (response) {
                    if (response.success) {
                        Swal.fire({title: '¡Éxito!', text: response.message, icon: 'success', confirmButtonColor: brandPrimary}).then(function () {
                            location.reload();
                        });
                    } else {
                        Swal.fire({title: 'Error', text: response.message, icon: 'error', confirmButtonColor: brandPrimary});
                    }
                },
                error: function () {
                    Swal.fire({title: 'Error', text: 'No se pudo comunicar con el servidor.', icon: 'error', confirmButtonColor: brandPrimary});
                }
            });
        });

        $(document).on('click', '#closeMyPlanModalBtn, #cancelMyPlanModalBtn', function () {
            myPlanModal.removeClass('is-open');
        });

        const superadminTelefono = "<?php echo htmlspecialchars($superadmin_telefono ?? ''); ?>";
        const nombreUsuarioLogueado = "<?php echo htmlspecialchars($_SESSION['admin']['nombre_usuario'] ?? 'Admin'); ?>";

        $(document).on('click', '.solicitar-plan-whatsapp-btn', function () {
            const buttonData = $(this).data();
            const planNombre = buttonData.nombrePlan;
            const planPrecioMensual = buttonData.precioMensual;
            const planPrecioAnual = buttonData.precioAnual;

            if (!planNombre) {
                Swal.fire('Atención', 'No se pudo obtener la información del plan.', 'warning');
                return;
            }
            if (!superadminTelefono) {
                Swal.fire('Error', 'El número de teléfono del Superadministrador no está configurado. No se puede enviar la solicitud.', 'error');
                return;
            }

            let mensaje = `Hola Superadministrador, soy ${nombreUsuarioLogueado} (Admin). Me gustaría solicitar información sobre el plan "${planNombre}".`;
            if (planPrecioMensual > 0) mensaje += ` Tiene un precio de S/${planPrecioMensual} al mes.`;
            if (planPrecioAnual > 0) mensaje += ` Y S/${planPrecioAnual} al año.`;
            mensaje += ' ¿Podrías darme más detalles?';

            window.open(`https://wa.me/${superadminTelefono}?text=${encodeURIComponent(mensaje)}`, '_blank');
            myPlanModal.removeClass('is-open');
        });
    });
})(window.jQuery);
</script>
<script src="../assets/js/admin-premium.js?v=4.1.0"></script>
<script src="../assets/js/admin-unified.js?v=9.1.0"></script>
<?php if (!in_array(basename($_SERVER['PHP_SELF']), ['index.php','gestionar_buzones.php','gestionar_dominios.php','gestionar_clientes.php','gestionar_cuentas.php','mis_referidos.php','mis_reportes.php','mi_suscripcion.php'], true)): ?>
<script src="../assets/js/admin-module-polish.js?v=6.0.2"></script>
<?php endif; ?>
<script src="../assets/js/admin-forms.js?v=9.0.0"></script>
<script src="../assets/js/superadmin-unified.js?v=3.0.0"></script>
</body>
</html>
