<?php
/**
 * Template Name: Manage Event Integrated
 * Description: Integrated event management hub for HVAC trainers
 */

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

// Check if user is logged in
if (!is_user_logged_in()) {
    wp_redirect(home_url('/training-login/'));
    exit;
}

get_header();
?>

<style>
.hvac-event-manage-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.hvac-page-header {
    text-align: center;
    margin-bottom: 40px;
}

.hvac-page-header h1 {
    color: #1a1a1a;
    font-size: 36px;
    margin-bottom: 10px;
}

.hvac-page-header p {
    color: #666;
    font-size: 18px;
}

/* Action cards grid */
.hvac-action-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.action-card {
    background: #fff;
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s, box-shadow 0.3s;
}

.action-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
}

.action-card-icon {
    font-size: 48px;
    margin-bottom: 20px;
    color: #0073aa;
}

.action-card h2 {
    color: #333;
    font-size: 24px;
    margin-bottom: 15px;
}

.action-card p {
    color: #666;
    margin-bottom: 25px;
    line-height: 1.6;
}

.action-card .button {
    display: inline-block;
    background: #0073aa;
    color: white;
    padding: 12px 30px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 16px;
    transition: background 0.3s;
}

.action-card .button:hover {
    background: #005a87;
    color: white;
}

.action-card.secondary .button {
    background: #666;
}

.action-card.secondary .button:hover {
    background: #444;
}

/* Recent events section */
.hvac-recent-events {
    background: #fff;
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.hvac-recent-events h2 {
    color: #333;
    font-size: 24px;
    margin-bottom: 20px;
}

.recent-events-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.recent-events-list li {
    padding: 15px 0;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.recent-events-list li:last-child {
    border-bottom: none;
}

.event-info {
    flex: 1;
}

.event-info .event-title {
    font-weight: 600;
    color: #0073aa;
    text-decoration: none;
    font-size: 16px;
}

.event-info .event-title:hover {
    text-decoration: underline;
}

.event-info .event-date {
    color: #666;
    font-size: 14px;
    margin-top: 4px;
}

.event-quick-actions {
    display: flex;
    gap: 10px;
}

.event-quick-actions a {
    color: #666;
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
    transition: all 0.3s;
}

.event-quick-actions a:hover {
    background: #0073aa;
    color: white;
    border-color: #0073aa;
}

/* Help section */
.hvac-help-section {
    background: #f7f7f7;
    border-radius: 8px;
    padding: 30px;
    margin-top: 40px;
    text-align: center;
}

.hvac-help-section h3 {
    color: #333;
    font-size: 20px;
    margin-bottom: 10px;
}

.hvac-help-section p {
    color: #666;
    margin-bottom: 20px;
}

.hvac-help-links {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.hvac-help-links a {
    color: #0073aa;
    text-decoration: none;
}

.hvac-help-links a:hover {
    text-decoration: underline;
}
</style>

<div class="hvac-event-manage-wrapper">
    <?php
    // Display trainer navigation menu
    if (class_exists('HVAC_Menu_System')) {
        HVAC_Menu_System::instance()->render_trainer_menu();
    }
    
    // Display breadcrumbs
    if (class_exists('HVAC_Breadcrumbs')) {
        HVAC_Breadcrumbs::instance()->render();
    }
    ?>
    
    <div class="hvac-page-header">
        <h1>Event Management Center</h1>
        <p>Create, manage, and track your HVAC training events</p>
    </div>
    
    <div class="hvac-action-cards">
        <div class="action-card">
            <div class="action-card-icon">📝</div>
            <h2>Create New Event</h2>
            <p>Share your expertise by creating a new training event for the HVAC community.</p>
            <a href="<?php echo home_url('/trainer/events/create/'); ?>" class="button">Create Event</a>
        </div>
        
        <div class="action-card">
            <div class="action-card-icon">📋</div>
            <h2>My Events</h2>
            <p>View and manage all your training events in one place. Edit details, update schedules, and more.</p>
            <a href="<?php echo home_url('/trainer/events/my-events/'); ?>" class="button">View My Events</a>
        </div>
        
        <div class="action-card">
            <div class="action-card-icon">🎓</div>
            <h2>Certificates</h2>
            <p>Generate and manage certificates for attendees who completed your training events.</p>
            <a href="<?php echo home_url('/trainer/certificate-reports/'); ?>" class="button">Manage Certificates</a>
        </div>
    </div>
    
    <?php
    // Get user's recent events
    $current_user_id = get_current_user_id();
    $recent_events = get_posts(array(
        'post_type' => 'tribe_events',
        'author' => $current_user_id,
        'posts_per_page' => 5,
        'post_status' => array('publish', 'pending', 'draft'),
        'orderby' => 'modified',
        'order' => 'DESC'
    ));
    
    if (!empty($recent_events)) :
    ?>
        <div class="hvac-recent-events">
            <h2>Recent Events</h2>
            <ul class="recent-events-list">
                <?php foreach ($recent_events as $event) : 
                    $start_date = get_post_meta($event->ID, '_EventStartDate', true);
                ?>
                    <li>
                        <div class="event-info">
                            <a href="<?php echo get_permalink($event->ID); ?>" class="event-title" target="_blank">
                                <?php echo esc_html($event->post_title); ?>
                            </a>
                            <div class="event-date">
                                <?php echo $start_date ? date('F j, Y', strtotime($start_date)) : 'Date TBD'; ?>
                                • <?php echo ucfirst($event->post_status); ?>
                            </div>
                        </div>
                        <div class="event-quick-actions">
                            <a href="<?php echo home_url('/trainer/events/edit/' . $event->ID . '/'); ?>">Edit</a>
                            <a href="<?php echo get_permalink($event->ID); ?>" target="_blank">View</a>
                        </div>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>
    <?php endif; ?>
    
    <div class="hvac-help-section">
        <h3>Need Help?</h3>
        <p>Get assistance with creating and managing your training events.</p>
        <div class="hvac-help-links">
            <a href="<?php echo home_url('/trainer/documentation/'); ?>">Documentation</a>
            <a href="<?php echo home_url('/contact/'); ?>">Contact Support</a>
            <a href="<?php echo home_url('/trainer/faq/'); ?>">FAQs</a>
        </div>
    </div>
</div>

<?php
get_footer();
?>