local LibStub = LibStub
local Broker_MicroMenu = LibStub:GetLibrary("LibDataBroker-1.1",true):GetDataObjectByName("Broker_MicroMenu")
local version = GetAddOnMetadata("Broker_MicroMenu","X-Curse-Packaged-Version") or ""
local L = LibStub("AceLocale-3.0"):GetLocale("Broker_MicroMenu")
local db

local aceoptions = { 
    name = "Broker MicroMenu".." "..version,
    handler = DungeonHelper,
	type='group',
	desc = "Broker MicroMenu",
	childGroups = "tab",
    args = {
		general = {
			name = L["General"],
			type="group",
			order = 1,
			args={
				showWorldLatency = {
					type = 'toggle',
					order = 1,
					name = L["Show World Latency"],
					desc = L["Show latency for combat data, data from the people around you (specs, gear, enchants, etc.)."],
					get = function(info, value)
						return db.showWorldLatency
					end,
					set = function(info, value)
						db.showWorldLatency = value
						Broker_MicroMenu:UpdateText()
					end,
				},
				showHomeLatency = {
					type = 'toggle',
					order = 2,
					name = L["Show Home Latency"],
					desc = L["Show latency for chat data, auction house stuff some addon data, and various other data."],
					get = function(info, value)
						return db.showHomeLatency
					end,
					set = function(info, value)
						db.showHomeLatency = value
						Broker_MicroMenu:UpdateText()
					end,
				},
				showFPS = {
					type = 'toggle',
					order = 2,
					name = L["Show FPS"],
					desc = L["Show frames per second."],
					get = function(info, value)
						return db.showFPS
					end,
					set = function(info, value)
						db.showFPS = value
						Broker_MicroMenu:UpdateText()
					end,
				},
				disableColoring = {
					type = 'toggle',
					order = 3,
					name = L["Disable Coloring"],
					desc = L["Disable Coloring"],
					get = function(info, value)
						return db.disableColoring
					end,
					set = function(info, value)
						db.disableColoring = value
						Broker_MicroMenu:UpdateText()
					end,
				},
				fpsFirst = {
					type = 'toggle',
					order = 4,
					name = L["Show FPS First"],
					desc = L["Show FPS First"],
					get = function(info, value)
						return db.fpsFirst
					end,
					set = function(info, value)
						db.fpsFirst = value
						Broker_MicroMenu:UpdateText()
					end,
				},
			},
		},
	}
}

function Broker_MicroMenu:RegisterOptions()
	local defaults = {
		profile = {
			showWorldLatency = true,
			showFPS = true,
		}
	}

	db = LibStub("AceDB-3.0"):New("Broker_MicroMenuDB", defaults, "Default")
	db = db.profile
	Broker_MicroMenu:SetDB(db)	
	LibStub("AceConfig-3.0"):RegisterOptionsTable("Broker_MicroMenu", aceoptions)
	LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Broker_MicroMenu", "Broker MicroMenu")
	--aceoptions.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
end

function Broker_MicroMenu:OpenOptions()
	LibStub("AceConfigDialog-3.0"):Open("Broker_MicroMenu")
end