<?php
/**
 * Status Modal Bootstrap
 * 
 * Initializes and loads the status modal system components
 * 
 * @since 2.1.0
 * @package VMPFence
 * @subpackage StatusModal
 */

if (!defined('ABSPATH')) {
    exit;
}

class VMPFence_Status_Modal_Bootstrap {
    
    /**
     * Initialize the status modal system
     */
    public static function init() {
        // Load controllers
        self::load_controllers();
        
        // Load models
        self::load_models();
        
        // Load AJAX handlers
        self::load_ajax_handlers();
        
        // Enqueue assets for admin pages
        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_assets'));
        
        // Add modal HTML to admin footer
        add_action('admin_footer', array(__CLASS__, 'render_modal_template'));
    }
    
    /**
     * Load AJAX handlers
     */
    private static function load_ajax_handlers() {
        require_once dirname(__FILE__) . '/ajax/status-ajax.php';
    }
    
    /**
     * Load controller classes
     */
    private static function load_controllers() {
        require_once dirname(__FILE__) . '/controllers/class-status-calculator.php';
    }
    
    /**
     * Load model classes
     */
    private static function load_models() {
        require_once dirname(__FILE__) . '/models/class-firewall-status.php';
        require_once dirname(__FILE__) . '/models/class-scanner-status.php';
    }
    
    /**
     * Enqueue CSS and JavaScript assets
     */
    public static function enqueue_assets($hook) {
        // Only load on VMPFence admin pages
        if (strpos($hook, 'vmpfence') === false) {
            return;
        }
        
        wp_enqueue_style(
            'vmpfence-status-modal',
            plugins_url('assets/css/status-modal.css', __FILE__),
            array(),
            VMPFENCE_VERSION
        );
        
        wp_enqueue_script(
            'vmpfence-status-modal',
            plugins_url('assets/js/status-modal.js', __FILE__),
            array('jquery'),
            VMPFENCE_VERSION,
            true
        );
        
        // Pass PHP data to JavaScript
        wp_localize_script('vmpfence-status-modal', 'vmpfenceStatusData', array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'nonce' => wp_create_nonce('vmpfence_status_modal_nonce'),
        ));
    }
    
    /**
     * Render modal HTML template in footer
     */
    public static function render_modal_template() {
        $screen = get_current_screen();
        if (!$screen || strpos($screen->id, 'vmpfence') === false) {
            return;
        }
        
        include dirname(__FILE__) . '/views/modal-template.php';
    }
}
