--[[
    Cerebro - Command Registry: UI Commands
    Extracted from UI/CommandRegistry.lua (Phase 2a decomposition)

    Commands:
      toggle_ui      (original lines 24-37)
      show_standings (original lines 38-51)
      show_history   (original lines 52-65)
      show_test_ui   (original lines 538-554)
      help           (original lines 802-811)
      show_intro     (original lines 1006-1022)
      show_config    (original lines 1023-1043)
      discord_export (original lines 1092-1109)

    @module UI.Commands.UICommands
    @version 0.12.0
]]--

local AddonName, PrivateTable = ...
local Cerebro = LibStub("AceAddon-3.0"):GetAddon(AddonName)

Cerebro._commandDefs = Cerebro._commandDefs or {}
local defs = Cerebro._commandDefs

-- UI Commands
defs[#defs + 1] = {
	id = "toggle_ui",
	displayName = "Toggle Main UI",
	description = "Opens or closes the main Cerebro window",
	officerOnly = false,
	slash = "/cb show or /cb",
	handler = function(ctx)
		if Cerebro.modules.UI then
			Cerebro.modules.UI:Toggle()
		else
			Cerebro:Print("UI module not loaded.")
		end
	end
}

defs[#defs + 1] = {
	id = "show_standings",
	displayName = "Show Standings",
	description = "Opens the standings tab",
	officerOnly = false,
	slash = "/cb standings",
	handler = function(ctx)
		if Cerebro.modules.UI then
			Cerebro.modules.UI:ShowStandings()
		else
			Cerebro:Print("UI module not loaded.")
		end
	end
}

defs[#defs + 1] = {
	id = "show_history",
	displayName = "Show History",
	description = "Opens the EPGP transaction history",
	officerOnly = false,
	slash = "/cb history",
	handler = function(ctx)
		if Cerebro.modules.UI then
			Cerebro.modules.UI:ShowHistory()
		else
			Cerebro:Print("UI module not loaded.")
		end
	end
}

-- UI Development
defs[#defs + 1] = {
	id = "show_test_ui",
	displayName = "UI Sandbox",
	description = "Opens the visual development sandbox for testing UI components",
	officerOnly = false,
	hidden = false,
	dangerous = false,
	slash = "/cb testui",
	handler = function(ctx)
		if Cerebro.modules.UISandbox then
			Cerebro.modules.UISandbox:Toggle()
		else
			Cerebro:Print("UISandbox module not loaded.")
		end
	end
}

defs[#defs + 1] = {
	id = "help",
	displayName = "Show Help",
	description = "Displays available commands",
	officerOnly = false,
	slash = "/cb help",
	handler = function(ctx)
		Cerebro:ShowHelp()
	end
}

defs[#defs + 1] = {
	id = "show_intro",
	displayName = "Show Onboarding",
	description = "Re-shows the onboarding wizard",
	officerOnly = false,
	hidden = false,
	dangerous = false,
	slash = "/cb intro",
	handler = function(ctx)
		local Onboarding = Cerebro:GetModule("Onboarding", true)
		if Onboarding then
			Onboarding:Show(true)  -- force=true to show even if completed
		else
			Cerebro:Print("Onboarding module not loaded.")
		end
	end
}

-- Configuration
defs[#defs + 1] = {
	id = "show_config",
	displayName = "Show Configuration",
	description = "Opens the Blizzard Interface Options panel for Cerebro",
	officerOnly = false,
	hidden = false,
	dangerous = false,
	aliases = {"config", "options"},
	slash = "/cb config or /cb options",
	handler = function(ctx)
		if Cerebro.modules.UI and Cerebro.modules.UI.ShowConfig then
			Cerebro.modules.UI:ShowConfig()
		else
			-- Fallback to Blizzard panel
			InterfaceOptionsFrame_OpenToCategory(Cerebro.optionsFrame)
			InterfaceOptionsFrame_OpenToCategory(Cerebro.optionsFrame) -- Called twice for Blizz UI bug
		end
	end
}

-- Discord Export
defs[#defs + 1] = {
	id = "discord_export",
	displayName = "Discord Export",
	description = "Opens the Discord webhook export window",
	officerOnly = false,
	hidden = false,
	dangerous = false,
	slash = "/cb discord",
	handler = function(ctx)
		if Cerebro.modules.DiscordExport then
			Cerebro.modules.DiscordExport:ShowExportWindow()
		else
			Cerebro:Print("DiscordExport module not loaded.")
		end
	end
}
