/**
 * Auto-generated API method registration script.
 * Generated by Askama template engine from Rust.
 *
 * This script registers Python API methods with the JavaScript event bridge,
 * enabling bidirectional communication between Python and JavaScript.
 *
 * @file api_registration.js
 * @generated
 */
(function() {
    'use strict';

    /**
     * Register API methods with the AuroraView event bridge.
     *
     * This function iterates through all API method entries and registers
     * them with the JavaScript bridge, making them callable from JavaScript.
     *
     * @returns {boolean} True if registration succeeded, false otherwise
     */
    function registerMethods() {
        if (!window.auroraview || !window.auroraview._registerApiMethods) {
            console.warn('[AuroraView] Event bridge not available');
            return false;
        }
{% for entry in api_methods %}
{% if !entry.methods.is_empty() %}
        window.auroraview._registerApiMethods('{{ entry.namespace }}', [{% for m in entry.methods %}'{{ m }}'{% if !loop.last %}, {% endif %}{% endfor %}]);
{% endif %}
{% endfor %}
        console.log('[AuroraView] API methods registered via template');
        window.dispatchEvent(new CustomEvent('auroraview-api-ready'));
        return true;
    }

    // Priority: synchronous registration if bridge is ready
    if (window.auroraview && window.auroraview._ready) {
        registerMethods();
    } else if (window.auroraview && window.auroraview.whenReady) {
        window.auroraview.whenReady().then(registerMethods);
    } else {
        // Fallback: brief polling for edge cases
        /** @type {number} */
        var attempts = 0;
        /** @type {number} */
        var interval = setInterval(function() {
            attempts++;
            if (window.auroraview && window.auroraview._ready) {
                clearInterval(interval);
                registerMethods();
            } else if (attempts >= 20) {
                clearInterval(interval);
                console.error('[AuroraView] Bridge not available after 2s');
            }
        }, 100);
    }
})();

