-- MULTI BOT LOGOUT FIX
-- This script disables MultiBot before logout to prevent memory corruption

-- Hook the original logout function
local originalLogout = Logout
function Logout()
    -- Disable MultiBot addon before logout
    if MultiBot then
        DEFAULT_CHAT_FRAME:AddMessage("MultiBot: Disabling before logout to prevent crash...")
        
        -- Hide all MultiBot frames
        if MultiBot.frames then
            for key, frame in pairs(MultiBot.frames) do
                if frame and frame.Hide then
                    frame:Hide()
                end
            end
        end
        
        -- Clear global references
        MultiBot = nil
        _G.MultiBot = nil
    end
    
    -- Call original logout
    originalLogout()
end

-- Also hook the quit function
local originalQuit = Quit
function Quit()
    -- Disable MultiBot addon before quit
    if MultiBot then
        DEFAULT_CHAT_FRAME:AddMessage("MultiBot: Disabling before quit to prevent crash...")
        
        -- Hide all MultiBot frames
        if MultiBot.frames then
            for key, frame in pairs(MultiBot.frames) do
                if frame and frame.Hide then
                    frame:Hide()
                end
            end
        end
        
        -- Clear global references
        MultiBot = nil
        _G.MultiBot = nil
    end
    
    -- Call original quit
    originalQuit()
end
