<?php
/**
 * Template Name: Create Event
 * Description: Template for creating new events with REST API (100% field control)
 */

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

get_header();
?>

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

.hvac-create-event-wrapper h1 {
    color: #1a1a1a;
    font-size: 28px;
    margin-bottom: 20px;
}

.hvac-form-notice {
    background: #f0f7ff;
    border: 1px solid #0073aa;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 20px;
}

.hvac-form-notice p {
    margin: 0;
    color: #0073aa;
}
</style>

<div class="hvac-create-event-wrapper">
    <?php
    // Display trainer navigation menu
    if (class_exists('HVAC_Menu_System')) {
        HVAC_Menu_System::instance()->render_trainer_menu();
    }
    ?>
    
    <h1>Create New Event</h1>
    
    <div class="hvac-form-notice">
        <p>Create your event with full control over all fields including excerpt, categories, featured images, and tags.</p>
    </div>
    
    <div class="hvac-page-content">
        <?php
        // Render the TEC form for structure, but enhance it with REST API
        echo do_shortcode('[tribe_community_events view="submission_form"]');
        ?>
    </div>
</div>

<script>
// Inline script to ensure REST API enhancement loads
jQuery(document).ready(function($) {
    console.log('[Create Event Page] Initializing REST API enhancement...');
    
    // Check if REST API script is loaded
    if (typeof HVACRestEventSubmission !== 'undefined') {
        console.log('[Create Event Page] REST API script already loaded');
    } else {
        console.log('[Create Event Page] Loading REST API script...');
        // Dynamically load the REST API script if not already loaded
        $.getScript('<?php echo HVAC_PLUGIN_URL; ?>assets/js/hvac-rest-api-event-submission.js')
            .done(function() {
                console.log('[Create Event Page] REST API script loaded successfully');
                if (typeof HVACRestEventSubmission !== 'undefined') {
                    HVACRestEventSubmission.init();
                }
            })
            .fail(function() {
                console.error('[Create Event Page] Failed to load REST API script');
            });
    }
});
</script>

<?php
get_footer();
?>