<?php
if (isset($_SESSION['message'])) {
    $message = $_SESSION['message'];
    $message_type = $_SESSION['message_type'];

    unset($_SESSION['message']);
    unset($_SESSION['message_type']);
}
?>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        <?php if (isset($message)) : ?>
            Swal.fire({
                toast: true,
                position: 'top-end',
                icon: '<?php echo $message_type === "success" ? "success" : "error"; ?>',
                title: '<?php echo ucfirst($message_type); ?>',
                text: '<?php echo $message; ?>',
                showConfirmButton: false,
                timer: 3000,
                timerProgressBar: true,
                didOpen: (toast) => {
                    toast.addEventListener('mouseenter', Swal.stopTimer)
                    toast.addEventListener('mouseleave', Swal.resumeTimer)
                }
            });
        <?php endif; ?>
    });
</script>
<style>
    .swal2-popup {
        width: 300px !important;
        padding: 20px !important;
    }

    .swal2-title {
        font-size: 18px !important;
    }

    .swal2-html-container {
        font-size: 14px !important;
    }

    .swal2-confirm {
        font-size: 14px !important;
    }

    .swal2-cancel {
        font-size: 14px !important;
    }
</style>