<?php
 
 /**
 * =============================================================================
 * @package         Blue Raven (Free Version)
 * @Plugin URI      https://enterrahost.com/plugins/blue-raven
 * 
 * @Author          EnterraHost
 * @Author URI      https://enterrahost.com
 * @License         GPL-2.0-or-later
 *  
 * @Copyright       (c) 2025 EnterraHost
 * @Contents        Header PHP
 *
 * =============================================================================
 * 
 * || INDEX:
 * ||   - BLUE RAVEN ADMIN HEADER
 * || 
 * =============================================================================
 */

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

/*
============================================================
   BLUE RAVEN ADMIN HEADER
============================================================
*/

class Blue_Raven_Admin_Header {
    
    private $plugin_url;
    private $plugin_path;
    
    /**
     * Constructor for the Blue Raven admin class.
     *
     * Initializes plugin paths and performs setup actions such as
     * asset registration or state configuration if needed.
     *
     * @access public
     */
    public function __construct() {
        $this->plugin_url = BLUERAVEN_PLUGIN_URL;
        $this->plugin_path = BLUERAVEN_PLUGIN_DIR;
    }
    
    /**
     * Renders the Blue Raven admin interface.
     *
     * Public method that triggers output of the plugin's admin UI components.
     * Typically called when loading the plugin settings page.
     *
     * @access public
     * @static
     * @return void
     */
    public static function render() {
        $instance = new self();
        $instance->header();
    }
    
    /**
     * Outputs the admin page header and navigation menu.
     *
     * Displays plugin title, navigation buttons, help links,
     * and other top-level interface elements.
     *
     * @access private
     * @return void
     */
    private function header() {
        $this->enqueue_assets();
    
    define('BLUE_RAVEN_PLUGIN_URL', BLUERAVEN_PLUGIN_URL);
    wp_enqueue_style(
        'blue-raven-fontawesome',
        BLUE_RAVEN_PLUGIN_URL . 'assets/css/all.min.css',
        [],
        '7.0.0'
    );

        ?>
        <div class="enterra-header screen-big">
            <div class="flex-sb">
                <h1><?php echo esc_html('Blue Raven'); ?></h1>
            </div>
            <div class="header-menu">
                <nav class="flex-sb">
                    <div class="flex-left" style='min-width: 500px;'>
                        <p class="enterra-nav-button spacing-right" id="home"><?php esc_html_e('Home', 'blue-raven'); ?></p>
                        <p class="enterra-nav-button spacing-right" id="my-products"><?php esc_html_e('My Products', 'blue-raven'); ?></p>
                        <p class="enterra-nav-button spacing-right" id="tools"><?php esc_html_e('Tools', 'blue-raven'); ?></p>
                    </div>
                    <div class="flex-sb">
                        <p class="spacing-right-small header-text" style="margin-top:0.4em;">
                            <a id='feather-count-display' href="https://enterrahost.com/blue-raven/" target="_blank" style="text-decoration:none;" ><?php esc_html(BlueRaven_FeatherCheck('f')); ?></a>
                        </p>
                        <p class="enterra-square-button" style="margin-top:0.4em;">
                            <a href="https://portal.enterrahost.com/store/feather-store">
                                <img class="enterra-menu-icon" src="<?php echo esc_url($this->plugin_url . '/assets/media/feather-icon-plus.webp'); ?>" alt="<?php esc_attr_e('Feather Count', 'blue-raven'); ?>">
                            </a>
                        </p>
                        <p class="header-text spacing-left-small" style="margin-top:0.4em;">
                            <a href="https://portal.enterrahost.com/serverstatus.php?view=open" title="<?php esc_attr_e('View system status', 'blue-raven'); ?>">
                                <?php esc_html_e('System', 'blue-raven'); ?>
                                <span id="status-indicator" style="display: inline-block; width: 15px; height: 15px; border-radius: 50%; background-color: gray; margin-left: 5px; vertical-align: middle;"></span>
                            </a>
                        </p>
                        <!--<p class="enterra-nav-button spacing-right-small header-text">-->
                        <!--    <a href="#">-->
                        <!--        <i class="fas  style="font-size: 22px;"></i>-->
                        <!--    </a>-->
                        <!--</p>-->
                        <p class="header-text spacing-left-small" style="margin-top:0.5em;">
                             <a href="https://portal.enterrahost.com/knowledgebase/1/Blue-Raven" target="_blank" rel="noopener" style="margin-left: 8px;" title="<?php esc_attr_e('Learn more', 'blue-raven'); ?>">
                                 <i class="fas fa-question-circle"></i>
                            </a>
                        </p>
                    </div>
                </nav>
            </div>
        </div>
        <div class="enterra-header screen-small">
            <div class="flex-sb">
                <h1><?php echo esc_html('Blue Raven'); ?></h1>
            </div>
            <div class="header-menu">
                <nav class="flex-sb">
                    <p style="padding: 0rem 1rem;"><?php esc_html_e("Blue Raven isn’t available on screens this small just yet.", "blue-raven"); ?></p>
                </nav>
            </div>
        </div>
        
        <img class="enterra-enterrahost-logo" src="<?php echo esc_url($this->plugin_url . '/assets/media/EnterrahostLogo-plugin.webp'); ?>" alt="<?php esc_attr_e('Logo', 'blue-raven'); ?>">
        <?php
    }
    
    /**
    * Enqueues admin stylesheets and JavaScript files.
    *
    * Loads custom plugin assets only on relevant admin pages
    * using WordPress's enqueue system.
    *
    * @access private
    * @return void
    */
    private function enqueue_assets() {
        wp_enqueue_script('chart-js', $this->plugin_url . '/assets/js/chart.min.js', array(), '4.4.9', true);
        wp_enqueue_style('bootstrap-datepicker', $this->plugin_url . '/assets/css/bootstrap-datepicker.min.css', array(), '1.10.0');
        wp_enqueue_script('bootstrap-datepicker', $this->plugin_url . '/assets/js/bootstrap-datepicker.min.js', array('jquery'), '1.10.0', true);
        wp_enqueue_script('sales-analytics-script',$this->plugin_url . '/assets/js/sales-analytics.js',['jquery', 'wp-util', 'chart-js', 'bootstrap-datepicker'],filemtime($this->plugin_path . '/assets/js/sales-analytics.js'),true); 
        wp_localize_script('sales-analytics-script', 'blue_raven_salesAnalyticsData', array('ajax_url' => admin_url('admin-ajax.php'),'nonce' => wp_create_nonce('blue_raven_sales_analytics_nonce'),'months' => array('01' => 'January','02' => 'February','03' => 'March','04' => 'April','05' => 'May','06' => 'June','07' => 'July','08' => 'August','09' => 'September','10' => 'October','11' => 'November','12' => 'December')));
        
        wp_enqueue_script('blue-raven-admin', $this->plugin_url . '/assets/js/admin.js', ['jquery', 'wp-util'], filemtime($this->plugin_path . 'assets/js/admin.js'), true);
        wp_enqueue_script('blue-raven-tools',$this->plugin_url . '/assets/js/admin-tools.js',['jquery', 'wp-util'],filemtime($this->plugin_path . 'assets/js/admin-tools.js'),true); 
        wp_enqueue_script('blue-raven-products',$this->plugin_url . '/assets/js/admin-products.js',['jquery', 'wp-util'],filemtime($this->plugin_path . 'assets/js/admin-products.js'),true); 
        wp_enqueue_script('blue-raven-my-products',$this->plugin_url . '/assets/js/admin-my-products.js',['jquery', 'wp-util'],filemtime($this->plugin_path . 'assets/js/admin-my-products.js'),true); 
        wp_enqueue_script('blue-raven-my-table',$this->plugin_url . '/assets/js/my-products-table.js',['jquery', 'wp-util'],filemtime($this->plugin_path . 'assets/js/my-products-table.js'),true);
        wp_enqueue_script('blue-raven-product-page',$this->plugin_url . '/assets/js/my-product-page.js',['jquery', 'wp-util'],filemtime($this->plugin_path . 'assets/js/my-product-page.js'),true); 
        wp_enqueue_script('blue-raven-text-editor',$this->plugin_url . '/assets/js/admin-text-editor.js',['jquery', 'wp-util'],filemtime($this->plugin_path . 'assets/js/admin-text-editor.js'),true); 
        wp_enqueue_script('blue-raven-mail-form',$this->plugin_url . '/assets/js/admin-mail-form-tool.js',['jquery', 'wp-util'],filemtime($this->plugin_path . 'assets/js/admin-mail-form-tool.js'),true); 

        wp_localize_script('blue-raven-admin','blueRavenAdmin',['ajaxurl' => admin_url('admin-ajax.php'),'nonce' => wp_create_nonce('blue_raven_admin_nonce'),'namespace' => 'blueRavenAdmin',]);
        wp_localize_script('blue-raven-tools', 'blueRavenTools', [
            'ajaxurl'       => admin_url('admin-ajax.php'),
            'load_nonce'    => wp_create_nonce('blue_raven_load_nonce'),
            'tools_nonce'   => wp_create_nonce('blue_raven_tools_nonce'),
            'namespace'     => 'blueRavenTools',
            // Add your error messages here
            'errorEmpty'    => __('Error: You need a Verification Code to enable this.', 'blue-raven'),
            'errorFormat'   => __('Error: The Verification Code has an incorrect format.', 'blue-raven'),
        ]);
        wp_localize_script('blue-raven-products','blueRavenProducts',['ajaxurl' => admin_url('admin-ajax.php'),'product_nonce' => wp_create_nonce('blue_raven_products_nonce'),'namespace' => 'blueRavenProducts',]);
        wp_localize_script('blue-raven-my-products','blueRavenMyProducts',['ajaxurl' => admin_url('admin-ajax.php'),'my_product_nonce' => wp_create_nonce('blue_raven_my_products_nonce'),'namespace' => 'blueRavenMyProducts',]);
        wp_localize_script('blue-raven-my-table','blueRavenMyTable',['ajaxurl' => admin_url('admin-ajax.php'),'my_table_nonce' => wp_create_nonce('blue_raven_my_table_nonce'),'namespace' => 'blueRavenMyTable',]);
    }
}

