// This script runs in the "Isolated World"
// It injects the bot script into the "Main World" (Page Context)

(async function () {
    console.log('[Magic Bot Extension] Initializing...');

    // 2. Inject Modules
    const modules = [
        'modules/core.js',
        'modules/socket.js',
        'modules/state.js',
        'modules/commands.js',
        'modules/ui.js',
        'modules/decision.js',
        'modules/main.js'
    ];

    modules.forEach(file => {
        const s = document.createElement('script');
        s.src = chrome.runtime.getURL(file);
        s.onload = function () {
            this.remove();
        };
        (document.head || document.documentElement).appendChild(s);
    });

    console.log('[Magic Bot Extension] Modules injection started.');
})();
