<?php

namespace RinnovoBooking\Core;

class Notification {
    public static function enqueue_assets() {
        wp_enqueue_script('rinnovo_booking-notifications-js', plugin_dir_url(__FILE__) . '../js/notifications.js', ['jquery'], '1.0', true);
        wp_enqueue_style('rinnovo_booking-notifications-css', plugin_dir_url(__FILE__) . '../css/notifications.css', [], '1.0');
    }

    public static function display_notification($message = 'nulla da dichiarare', $type = 'info', $title = 'Attenzione!') {
        // Enqueue the JS & CSS
        self::enqueue_assets();

        // Pass the notification data to the frontend
        add_action('wp_footer', function () use ($message, $type, $title) {
            ?>
            <script>                
                document.addEventListener('DOMContentLoaded', function () {
                    Notification.showNotification('<?php echo $title; ?>', '<?php echo $message; ?>', '<?php echo $type; ?>');
                });
            </script>
            <?php
        });
    }
}
