<div id="<?php echo esc_attr( $data['id'] ); ?>" class="fab-container fab-notice">
    <div class="fab-redirect-notice-content">
        <!-- Notice Header -->
        <h3 class="flex flex-col items-center text-base gap-y-4">
            <img src="<?php echo esc_url( $data['loading'] ); ?>" alt="Floating Awesome Button" class="w-32 h-32 mr-2">
            <span class="font-semibold"><?php echo esc_html( $data['title'] ); ?></span>
        </h3>

        <!-- Notice Content -->
        <p class="py-2">
            <?php echo esc_html( $data['message'] ); ?>
            <span id="fab-redirect-countdown" class="font-bold text-lg"></span> 
        </p>

        <!-- Notice Button -->
        <div class="flex justify-start gap-x-2">
            <?php foreach ( $data['buttons'] as $button ) : ?>
                <?php if ( isset( $button['action'] ) ) : ?>
                    <button class="<?php echo esc_attr( $button['classes'] ); ?>" data-action="<?php echo esc_attr( $button['action'] ); ?>">
                        <?php echo esc_html( $button['message'] ); ?>
                    </button>
                <?php else : ?>
                    <a href="<?php echo esc_url( $button['url'] ); ?>" class="<?php echo esc_attr( $button['classes'] ); ?>" target="<?php echo esc_attr( $button['target'] ?? '_self' ); ?>">
                        <?php echo esc_html( $button['message'] ); ?>
                    </a>
                <?php endif; ?>
            <?php endforeach; ?>
        </div>
    </div>
</div>

<script>
    jQuery(document).ready(function($) {
        // Prevent all forms from being submitted
        $('form').on('submit', function(e) {
            e.preventDefault();
            return false;
        });

        // Countdown
        var countdown = <?php echo esc_js( $data['timeout'] ); ?>;
        var countdownElement = $('#fab-redirect-countdown');
        var countdownInterval = setInterval(function() {
            countdown--;
            countdownElement.text(countdown);
            
            if (countdown <= 0) {
                clearInterval(countdownInterval);
                window.location.href = '<?php echo esc_js( $data['redirect_url'] ); ?>';
            }
        }, 1000);
        
    });
</script>
