-- Game menu button.
-- Adds an ArenaCore button to the ESC menu.

local AC = _G.ArenaCore
if not AC then return end

-- Create module
AC.GameMenuButton = AC.GameMenuButton or {}
local GameMenuButton = AC.GameMenuButton

-- Module state
GameMenuButton.isEnabled = false
GameMenuButton.isHooked = false

-- Add ArenaCore button to the game menu
function GameMenuButton:AddButton()
    if not GameMenuFrame then return end
    
    -- Just a little spacer so it doesn't look jammed in.
    GameMenuFrame:AddSection()
    
    -- Fancy text + logo so it's easy to spot.
    local iconPath = "Interface\\AddOns\\ArenaCore\\Media\\Textures\\aclogo"
    local buttonText = string.format("|cff8B45FFArena|r |cffB266FFCore|r |T%s:16:16:0:0|t", iconPath)
    
    GameMenuFrame:AddButton(
        buttonText,
        function()
            -- Same thing as the slash command.
            if AC and AC.OpenConfigPanel then
                AC:OpenConfigPanel(true)  -- true = toggle mode
            else
                print("|cffFF0000[ArenaCore]|r Config panel not loaded!")
            end
            
            -- Get the menu out of the way.
            HideUIPanel(GameMenuFrame)
        end
    )
end

-- Enable the game menu button
function GameMenuButton:Enable()
    if self.isEnabled then return end
    
    -- InitButtons runs whenever Blizzard rebuilds the menu.
    if not self.isHooked then
        hooksecurefunc(GameMenuFrame, "InitButtons", function()
            GameMenuButton:AddButton()
        end)
        self.isHooked = true
    end
    
    self.isEnabled = true
    -- Silently enabled (no chat spam for users)
end

-- Disable the game menu button
function GameMenuButton:Disable()
    -- Can't unhook, but we can stop adding the button.
    self.isEnabled = false
    -- Silently disabled (no chat spam for users)
end

-- Initialize on addon load (silently)
