<?php
/**
 * HVAC Profile Template
 * 
 * Unified template for profile viewing and editing
 * 
 * @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 if this is edit mode
$page_slug = get_post_field('post_name', get_queried_object_id());
$is_edit_mode = (strpos($page_slug, 'edit') !== false);

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

$user = wp_get_current_user();
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-profile-page <?php echo $is_edit_mode ? 'hvac-profile-edit' : 'hvac-profile-view'; ?>">
    <?php
    // Load page header (navigation, breadcrumbs)
    get_template_part('templates/parts/hvac-page-header', null, [
        'show_navigation' => true,
        'show_breadcrumbs' => !$is_edit_mode, // Hide breadcrumbs in edit mode for cleaner UI
        'page_config' => [
            'menu_type' => in_array('hvac_master_trainer', $user->roles) ? 'master_trainer' : 'trainer'
        ]
    ]);
    ?>
    
    <div class="container">
        <?php
        // Load status messages
        get_template_part('templates/parts/hvac-status-messages');
        
        if ($is_edit_mode) {
            // Profile edit content
            echo do_shortcode('[hvac_trainer_profile_edit]');
        } else {
            // Profile view content - use existing template content
            get_template_part('templates/views/trainer-profile-view');
        }
        ?>
    </div>
</div>

<?php get_footer(); ?>