<?php
/**
 * Template Name: Master Dashboard
 * Description: Template for the master trainer dashboard page
 */

// Define constant to indicate we are in a page template
if (!defined('HVAC_IN_PAGE_TEMPLATE')) {
    define('HVAC_IN_PAGE_TEMPLATE', true);
}

get_header();

// Authentication handled by centralized HVAC_Access_Control system
// Redundant template-level auth check removed to prevent content blocking

echo '<div class="hvac-page-wrapper hvac-master-dashboard-page">';
echo '<div class="container">';

// Render master trainer navigation inside the wrapper
if (class_exists('HVAC_Master_Menu_System')) {
    $master_menu = HVAC_Master_Menu_System::instance();
    $master_menu->render_master_menu();
}

// Render breadcrumbs inside the wrapper
if (class_exists('HVAC_Breadcrumbs')) {
    // Fix: The method is render_breadcrumbs(), not render()
    $breadcrumbs_instance = HVAC_Breadcrumbs::instance();
    echo $breadcrumbs_instance->render_breadcrumbs();
}

// Render the master dashboard content with output buffering
$template_path = HVAC_PLUGIN_DIR . 'templates/template-hvac-master-dashboard.php';

ob_start();
if (file_exists($template_path)) {
    include $template_path;
} else {
    // Log error for admins only
    if (current_user_can('manage_options')) {
        echo '<div class="notice notice-error"><p>Template file not found. Please contact support.</p></div>';
    }
}
$dashboard_content = ob_get_clean();

// Output the dashboard content
echo $dashboard_content;

echo '</div>'; // .container
echo '</div>'; // .hvac-page-wrapper

get_footer();
