<?php
/**
 * Template Builder AJAX Handler Entry Point
 * Routes AJAX requests to the template builder module
 */

// Set up JSON error handling
header('Content-Type: application/json');

try {
    // Initialize constants
    if (!defined('_INCLUDE')) {
        define('_INCLUDE', true);
    }
    if (!defined('_ISVALID')) {
        define('_ISVALID', true);
    }

    // Set up include path
    $main_dir = realpath(dirname(__FILE__));
    set_include_path($main_dir);

    // Load core configuration which properly initializes session through VSession::init()
    require_once 'f_core/config.core.php';

    // Now load and execute the module's AJAX handler
    require_once 'f_modules/m_frontend/templatebuilder_ajax.php';
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'error' => 'Server error: ' . $e->getMessage()
    ]);
}
?>
