local ADDON_NAME, ns = ...

local function get(info) return ns.db.profile[info[#info]] end
local function set(info, val) ns.db.profile[info[#info]] = val end

local options = {
    type = "group",
    name = ns.GREEN .. "RatedTracker Field Manual" .. ns.RESET,
    args = {
        header = {
            type = "description", order = 1, width = "full", fontSize = "large",
            name = "Fast in-game PvP reference. Open with /rtfm.",
        },
        gap1 = { type = "description", order = 2, width = "full", name = " " },
        open = {
            type = "execute", order = 3, name = "Open the Field Manual", width = "full",
            func = function() ns:Show() end,
        },
        gap2 = { type = "description", order = 4, width = "full", name = " " },
        autoOpenInBlitz = {
            type = "toggle", order = 10, width = "full",
            name = "Auto-open the matching guide in Blitz maps",
            desc = "When you enter a supported Battleground Blitz map, open its guide automatically.",
            get = get, set = set,
        },
        debugMode = {
            type = "toggle", order = 12, width = "full",
            name = "Debug messages", get = get, set = set,
        },
    },
}

local function RegisterOptions()
    local AceConfig = LibStub("AceConfig-3.0", true)
    local AceConfigDialog = LibStub("AceConfigDialog-3.0", true)
    if not (AceConfig and AceConfigDialog) then return end
    AceConfig:RegisterOptionsTable("RatedTrackerFieldManual", options)
    AceConfigDialog:AddToBlizOptions("RatedTrackerFieldManual", "RatedTracker Field Manual")
end

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function() RegisterOptions() end)
