using System;
using Autodesk.Max;
using ManagedServices;

namespace VR4LifeConnector
{
    public class VR4LifeMenuLoader
    {
        public static void Initialize()
        {
            string bootScript = @"
            (
                fn setupVRMenu = (
                    local mbar = menuMan.getMainMenuBar()
                    local existing = menuMan.findMenu ""Vr4Life""
                    if existing != undefined do menuMan.unRegisterMenu existing
                    
                    local m = menuMan.createMenu ""Vr4Life""
                    m.addItem (menuMan.createActionItem ""VR4Life_Launcher"" ""Immerse Games"") -1
                    m.addItem (menuMan.createActionItem ""VR4Life_Update"" ""Immerse Games"") -1
                    
                    mbar.addItem (menuMan.createSubMenuItem ""Vr4Life"" m) (mbar.numItems())
                    menuMan.updateMenuBar()
                )
                callbacks.removeScripts id:#vr4life
                callbacks.addScript #cuiRegisterMenus ""setupVRMenu()"" id:#vr4life
                setupVRMenu()
            )";

            // RESOLUÇÃO DO ERRO CS7036:
            // Adicionamos o segundo argumento 'MaxscriptSDK.ScriptSource.Embedded'
            // Isso indica ao Max que o script vem de dentro da DLL (embutido)
            MaxscriptSDK.ExecuteMaxscriptCommand(bootScript, MaxscriptSDK.ScriptSource.Embedded);
        }
    }
}