<?php
/**
 * HVAC Dashboard Template
 * 
 * Unified template for trainer and master trainer dashboards
 * 
 * @package HVAC_Community_Events
 * @since 2.0.0
 */

// Define constant to indicate we are in a page template
define('HVAC_IN_PAGE_TEMPLATE', true);

// Security check
if (!defined('ABSPATH')) {
    exit;
}

get_header();

// Determine dashboard type based on page slug
$page_slug = get_post_field('post_name', get_queried_object_id());
$is_master_dashboard = (strpos($page_slug, 'master-dashboard') !== false);

// Security check
if (!is_user_logged_in()) {
    wp_safe_redirect(home_url('/community-login/'));
    exit;
}

$user = wp_get_current_user();
if ($is_master_dashboard) {
    if (!in_array('hvac_master_trainer', $user->roles)) {
        wp_die(__('Access denied. Master trainer role required.', 'hvac-community-events'));
    }
} else {
    if (!array_intersect(['hvac_trainer', 'hvac_master_trainer'], $user->roles)) {
        wp_die(__('Access denied. Trainer role required.', 'hvac-community-events'));
    }
}
?>

<div class="hvac-page-wrapper hvac-dashboard-page <?php echo $is_master_dashboard ? 'hvac-master-dashboard' : 'hvac-trainer-dashboard'; ?>">
    <?php
    // Load page header (navigation, breadcrumbs)
    get_template_part('templates/parts/hvac-page-header', null, [
        'show_navigation' => true,
        'show_breadcrumbs' => true,
        'page_config' => [
            'menu_type' => $is_master_dashboard ? 'master_trainer' : 'trainer'
        ]
    ]);
    ?>
    
    <div class="container">
        <?php
        // Load status messages
        get_template_part('templates/parts/hvac-status-messages');
        
        if ($is_master_dashboard) {
            // Master dashboard content
            get_template_part('templates/views/master-dashboard-content');
        } else {
            // Trainer dashboard content  
            get_template_part('templates/views/trainer-dashboard-content');
        }
        ?>
    </div>
</div>

<?php get_footer(); ?>