local l=(LibStub("\065\099\101\065\100\100\111\110-\051\046\048")):NewAddon("\083\104\111\116\116\097","\065\099\101\067\111\110\115\111\108\101-\051\046\048","\065\099\101\069\118\101\110\116-\051\046\048","\065\099\101\084\105\109\101\114-\051\046\048")local r="\064\112\114\111\106\101\099\116-\118\101\114\115\105\111\110\064"r="\109\097\105\110"local i="\104\116\116\112\115\058\047\047\100\105\115\099\111\114\100\046\103\103\047\077\072\113\071\082\112\090\120\098\066"local y="\104\116\116\112\115\058\047\047\103\105\116\104\117\098\046\099\111\109\047\109\097\114\116\105\110\098\106\101\108\100\098\097\107\047\115\104\111\116\116\097"local P="\064\112\114\111\106\101\099\116-\116\105\109\101\115\116\097\109\112\064"P="\049\055\050\053\055\049\054\051\050\054"local g=true g=false local B=(LibStub("\065\099\101\076\111\099\097\108\101-\051\046\048")):GetLocale("\083\104\111\116\116\097",g)function l.OpenToCategory()Settings.OpenToCategory("\083\104\111\116\116\097")end local function C(l)return B["\099\104\101\099\107\098\111\120\084\101\120\116\046"..l[#l]]end local function U(l)return l*60 end local function f(r)if r~=nil then l:Print(r)end Screenshot()end function l.TimedScreenshot(l)l:Print("\071\111\116 \116\105\109\101\100 \101\118\101\110\116\044 \116\097\107\105\110\103 \115\099\114\101\101\110\115\104\111\116")f()end local function c(l)UIParent:Hide()f(l)C_Timer.After(.01,function()UIParent:Show()end)end local W=(LibStub("\076\105\098\068\097\116\097\066\114\111\107\101\114-\049\046\049")):NewDataObject("\083\104\111\116\116\097",{type="\100\097\116\097 \115\111\117\114\099\101";text="\083\104\111\116\116\097";icon=237290;OnClick=function()if IsShiftKeyDown()then HideUIPanel(SettingsPanel)Settings.OpenToCategory("\083\104\111\116\116\097")elseif IsControlKeyDown()then f()else c()end end,OnTooltipShow=function(l)if not l or not l.AddLine then return end l:AddLine("\083\104\111\116\116\097")l:AddLine(" ")l:AddLine(B["\109\105\110\105\109\097\112\046\099\108\105\099\107"])l:AddLine(B["\109\105\110\105\109\097\112\046\099\116\114\108\067\108\105\099\107"])l:AddLine(" ")l:AddLine(B["\109\105\110\105\109\097\112\046\115\104\105\102\116\067\108\105\099\107"])end})local u={profile={minimap={hide=false},events={["\042\042"]=false;blizzard={PLAYER_LOGIN=true;PLAYER_LEVEL_UP=true,PLAYER_DEAD=true;LOOT_ITEM_ROLL_WON=true;BOSS_KILL=true};timer={}}}}function l.BlizzardEventOption(l)return{name=C;type="\116\111\103\103\108\101";width="\102\117\108\108";set=function(r,i)local y=r[#r]l.db.profile.events.blizzard[y]=i l:conditionallyRegisterBlizzardEvent(i,y)end;get=function(r)local i=r[#r]return l.db.profile.events.blizzard[i]end}end function l.PLAYER_STARTED_MOVING(l)l:Print("\071\111\116 \111\118\101\114\114\105\100\100\101\110 \101\118\101\110\116\044 \116\097\107\105\110\103 \115\099\114\101\101\110\115\104\111\116")end function l.PLAYER_LOGIN(l)l:Print("\071\111\116 \101\118\101\110\116 \112\108\097\121\101\114 \108\111\103\105\110\058 \116\097\107\105\110\103 \115\099\114\101\101\110\115\104\111\116")l:ScheduleTimer("\084\105\109\101\100\083\099\114\101\101\110\115\104\111\116",5)end function l.ACHIEVEMENT_EARNED(l)l:ScheduleTimer("\084\105\109\101\100\083\099\114\101\101\110\115\104\111\116",.5)end function l.CHAT_MSG_TEXT_EMOTE(l)l:ScheduleTimer("\084\105\109\101\100\083\099\114\101\101\110\115\104\111\116",.5)end function l.TRADE_ACCEPT_UPDATE(l)if l==1 then f()end end function l.PLAYER_LEVEL_UP(l)l:ScheduleTimer("\084\105\109\101\100\083\099\114\101\101\110\115\104\111\116",.5)end function l.LoadOptions(l)local r={type="\103\114\111\117\112";args={general_options={name=C,type="\103\114\111\117\112",order=0,inline=true;args={hideMinimap={name=C,type="\116\111\103\103\108\101",set=function(r,i)l.db.profile.minimap.hide=i if i then(LibStub("\076\105\098\068\066\073\099\111\110-\049\046\048")):Hide("\083\104\111\116\116\097")else(LibStub("\076\105\098\068\066\073\099\111\110-\049\046\048")):Show("\083\104\111\116\116\097")end end,get=function(r)return l.db.profile.minimap.hide end}}};blizzard_events={name=C,type="\103\114\111\117\112";order=2,inline=true;args={PLAYER_LOGIN=l:BlizzardEventOption();CHAT_MSG_CHANNEL=l:BlizzardEventOption(),PLAYER_LEVEL_UP=l:BlizzardEventOption();MAIL_SHOW=l:BlizzardEventOption();READY_CHECK=l:BlizzardEventOption(),ZONE_CHANGED=l:BlizzardEventOption();ZONE_CHANGED_NEW_AREA=l:BlizzardEventOption();HEARTHSTONE_BOUND=l:BlizzardEventOption();PLAYER_STARTED_MOVING=l:BlizzardEventOption(),AUCTION_HOUSE_SHOW=l:BlizzardEventOption(),GROUP_FORMED=l:BlizzardEventOption(),TRADE_ACCEPT_UPDATE=l:BlizzardEventOption(),BOSS_KILL=l:BlizzardEventOption(),ENCOUNTER_END=l:BlizzardEventOption(),QUEST_TURNED_IN=l:BlizzardEventOption();LOOT_ITEM_ROLL_WON=l:BlizzardEventOption();PLAYER_DEAD=l:BlizzardEventOption();CHAT_MSG_TEXT_EMOTE=l:BlizzardEventOption()}};timer_events={name=C;type="\103\114\111\117\112";inline=true;order=1,args={every_5_minutes=l:TimerEventOption(5,0);every_10_minutes=l:TimerEventOption(10,1),every_30_minutes=l:TimerEventOption(30,2)}}}}if WOW_PROJECT_ID==WOW_PROJECT_MAINLINE then r.args.blizzard_events.args.MAJOR_FACTION_RENOWN_LEVEL_CHANGED=l:BlizzardEventOption()end if WOW_PROJECT_ID==WOW_PROJECT_MAINLINE or WOW_PROJECT_ID==WOW_PROJECT_WRATH_CLASSIC then r.args.blizzard_events.args.ACHIEVEMENT_EARNED=l:BlizzardEventOption()end return r end function l.conditionallyRegisterBlizzardEvent(i,l,r)local y=i[r]if not y then y="\068\101\102\097\117\108\116\066\108\105\122\122\097\114\100\072\097\110\100\108\101\114"end if l then i:Print(format("\069\110\097\098\108\105\110\103 \101\118\101\110\116\058 \037\115 ",r))i:RegisterEvent(r,y,i)else i:Print(format("\068\105\115\097\098\108\105\110\103 \101\118\101\110\116\058 \037\115 ",r))i:UnregisterEvent(r)end end function l.DefaultBlizzardHandler(l)l:Print("\068\101\102\097\117\108\116 \104\097\110\100\108\101\114\058 \103\111\116 \101\110\097\098\108\101\100 \066\108\105\122\122\097\114\100 \101\118\101\110\116\044 \116\097\107\105\110\103 \115\099\114\101\101\110\115\104\111\116\046")f()end local function G(l)local r=time()local i=tonumber(l)local y=r-i return math.floor(y/86400)end local function o()if WOW_PROJECT_ID==WOW_PROJECT_MAINLINE then return"\114\101\116\097\105\108"elseif WOW_PROJECT_ID==WOW_PROJECT_WRATH_CLASSIC then return"\099\108\097\115\115\105\099"elseif WOW_PROJECT_ID==WOW_PROJECT_CLASSIC then return"\099\108\097\115\115\105\099\095\101\114\097"end return"\117\110\107\110\111\119\110"end local e={type="\103\114\111\117\112";name=B.about,args={version={name=format("\086\101\114\115\105\111\110\058 \037\115",r),order=0,type="\100\101\115\099\114\105\112\116\105\111\110"};date={name=format("\068\097\116\101\058 \037\115 \040\037\115 \100\097\121\115 \097\103\111\041",date("\037\120",P),G(P)),order=1;type="\100\101\115\099\114\105\112\116\105\111\110"},screenshotLocation={name=format(B.saveLocationHelpText,o(),o());order=5;fontSize="\108\097\114\103\101",type="\100\101\115\099\114\105\112\116\105\111\110"};discord={name=format("\037\115 \040\037\115\041",B.joinDiscord,B.pressCtrlC);type="\105\110\112\117\116";order=6;width="\100\111\117\098\108\101",get=function(l)return i end};code={name=format("\037\115 \040\037\115\041",B.gitHubLink,B.pressCtrlC),type="\105\110\112\117\116",order=7,width="\100\111\117\098\108\101",get=function(l)return y end},love={name="\070\111\114 \078\097\110\100\097\114\046 \077\097\100\101 \119\105\116\104 \108\111\118\101 \105\110 \077\101\108\098\111\117\114\110\101\044 \065\117\115\116\114\097\108\105\097",order=80,fontSize="\115\109\097\108\108",type="\100\101\115\099\114\105\112\116\105\111\110"}}}function l.TimerEventOption(i,l,r)return{name=C;type="\116\111\103\103\108\101",order=r;set=function(r,y)i.db.profile.events.timer[l]=y i:conditionallyEnableTimer(y,l)end;get=function(r)return i.db.profile.events.timer[l]end}end function l.conditionallyEnableTimer(i,l,r)if l then i:Print(format("\069\110\097\098\108\105\110\103 \037\115 \109\105\110\117\116\101 \116\105\109\101\114",r))i.timerEvents[r]=i:ScheduleRepeatingTimer("\084\105\109\101\100\083\099\114\101\101\110\115\104\111\116",U(r))else i:Print(format("\067\097\110\099\101\108\108\105\110\103 \037\115 \109\105\110\117\116\101 \116\105\109\101\114",r))i:CancelTimer(i.timerEvents[r])end end function l.OnInitialize(l)l.db=(LibStub("\065\099\101\068\066-\051\046\048")):New("\083\104\111\116\116\097\068\066\118\050",u)l.timerEvents={};(LibStub("\076\105\098\068\066\073\099\111\110-\049\046\048")):Register("\083\104\111\116\116\097",W,l.db.profile.minimap)local i=(LibStub("\065\099\101\068\066\079\112\116\105\111\110\115-\051\046\048")):GetOptionsTable(l.db)local y=LibStub("\065\099\101\067\111\110\102\105\103\082\101\103\105\115\116\114\121-\051\046\048")y:RegisterOptionsTable("\083\104\111\116\116\097",l:LoadOptions())y:RegisterOptionsTable("\083\104\111\116\116\097 \097\098\111\117\116",e)y:RegisterOptionsTable("\083\104\111\116\116\097 \112\114\111\102\105\108\101\115",i)local P=LibStub("\065\099\101\067\111\110\102\105\103\068\105\097\108\111\103-\051\046\048")P:AddToBlizOptions("\083\104\111\116\116\097","\083\104\111\116\116\097")P:AddToBlizOptions("\083\104\111\116\116\097 \112\114\111\102\105\108\101\115","\080\114\111\102\105\108\101\115","\083\104\111\116\116\097")P:AddToBlizOptions("\083\104\111\116\116\097 \097\098\111\117\116","\065\098\111\117\116","\083\104\111\116\116\097")l:Print(r.." \108\111\097\100\101\100\033")end function l.OnEnable(l)for r,i in pairs(l.db.profile.events.blizzard)do if i then l:conditionallyRegisterBlizzardEvent(true,r)end end for r,i in pairs(l.db.profile.events.timer)do if i then l:conditionallyEnableTimer(true,r)end end end function l.OnDisable(l)for r,i in pairs(l.db.profile.events.blizzard)do if i then l:conditionallyRegisterBlizzardEvent(false,r)end end l:CancelAllTimers()end l:RegisterChatCommand("\115\104\111\116\116\097","\079\112\101\110\084\111\067\097\116\101\103\111\114\121")l:RegisterChatCommand("\115\104","\079\112\101\110\084\111\067\097\116\101\103\111\114\121")
---@type Shotta
local Shotta = LibStub("AceAddon-3.0"):NewAddon("Shotta", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")

-- luacheck: push ignore VERSION
local VERSION = "@project-version@"
--@alpha@
VERSION = "main" -- hardcode for debuggability
--@end-alpha@
-- luacheck: pop

---@type string
local DISCORD_LINK = "https://discord.gg/MHqGRpZxbB"
---@type string
local GITHUB_LINK = "https://github.com/martinbjeldbak/shotta"

-- luacheck: push ignore UPDATED_TIMESTAMP
---@type string
local UPDATED_TIMESTAMP = "@project-timestamp@"
--@alpha@
UPDATED_TIMESTAMP = "1725716326" -- hardcode for debuggability
--@end-alpha@
-- luacheck: pop

-- luacheck: push ignore TRANSLATE_FAIL_SILENTLY
---@type boolean
local TRANSLATE_FAIL_SILENTLY = true
--@alpha@
TRANSLATE_FAIL_SILENTLY = false
--@end-alpha@
-- luacheck: pop

local L = LibStub("AceLocale-3.0"):GetLocale("Shotta", TRANSLATE_FAIL_SILENTLY)

function Shotta.OpenToCategory()
	Settings.OpenToCategory("Shotta")
end

---Uses AcLocale to translate an option
---@param info table
---@return string
local function localizedCheckboxName(info)
	return L["checkboxText." .. info[#info]]
end

---Converts minutes to seconds
---@param min number how many minutes should be converted to seconds
---@return number minutes in seconds
local function toMinutes(min)
	return min * 60
end

---Makes client take a screenshot. Simply wraps the WoW global method.
---@param text? string Optional text to log
local function TakeScreenshot(text)
	if text ~= nil then
		Shotta:Print(text)
	end

	Screenshot()
end

function Shotta:TimedScreenshot()
	--@alpha@
	self:Print("Got timed event, taking screenshot")
	--@end-alpha@
	TakeScreenshot()
end

local function TakeUILessScreenshot(text)
	UIParent:Hide()

	TakeScreenshot(text)

	C_Timer.After(0.01, function()
		UIParent:Show()
	end)
end

local iconOptions = LibStub("LibDataBroker-1.1"):NewDataObject("Shotta", {
	type = "data source",
	text = "Shotta",
	icon = 237290,
	OnClick = function()
		if IsShiftKeyDown() then
			HideUIPanel(SettingsPanel)
			Settings.OpenToCategory("Shotta")
		elseif IsControlKeyDown() then
			TakeScreenshot()
		else
			TakeUILessScreenshot()
		end
	end,
	OnTooltipShow = function(tooltip)
		if not tooltip or not tooltip.AddLine then
			return
		end

		tooltip:AddLine("Shotta")
		tooltip:AddLine(" ")
		tooltip:AddLine(L["minimap.click"])
		tooltip:AddLine(L["minimap.ctrlClick"])
		tooltip:AddLine(" ")
		tooltip:AddLine(L["minimap.shiftClick"])
	end,
})

local defaults = {
	---@type table<string, table>
	profile = {
		---@type table<string, boolean>
		minimap = {
			hide = false,
		},
		---@type table<string, table|boolean>
		events = {
			["**"] = false,
			---@type table<string, boolean>
			blizzard = {
				-- enable these events by default
				PLAYER_LOGIN = true,
				PLAYER_LEVEL_UP = true,
				PLAYER_DEAD = true,
				LOOT_ITEM_ROLL_WON = true,
				BOSS_KILL = true,
			},
			---@type table<number, boolean>
			timer = {},
		},
	},
}

function Shotta:BlizzardEventOption()
	---@type AceOptionsTable
	return {
		name = localizedCheckboxName,
		type = "toggle",
		width = "full",
		set = function(info, val)
			local triggerName = info[#info]
			self.db.profile.events.blizzard[triggerName] = val
			self:conditionallyRegisterBlizzardEvent(val, triggerName)
		end,
		get = function(info)
			local triggerName = info[#info]
			return self.db.profile.events.blizzard[triggerName]
		end,
	}
end

function Shotta:PLAYER_STARTED_MOVING()
	self:Print("Got overridden event, taking screenshot")
end

function Shotta:PLAYER_LOGIN()
	--@alpha@
	self:Print("Got event player login: taking screenshot")
	--@end-alpha@
	self:ScheduleTimer("TimedScreenshot", 5)
end

function Shotta:ACHIEVEMENT_EARNED()
	self:ScheduleTimer("TimedScreenshot", 0.5)
end

function Shotta:CHAT_MSG_TEXT_EMOTE()
	self:ScheduleTimer("TimedScreenshot", 0.5)
end

function Shotta.TRADE_ACCEPT_UPDATE(playerAccepted)
	-- TODO: TEST ME
	if playerAccepted == 1 then
		TakeScreenshot()
	end
end

function Shotta:PLAYER_LEVEL_UP()
	-- 	-- TODO: implement these modifiers
	-- 	-- if Shotta.db.screenshottableEvents.levelUp.modifiers.showMainChat then
	-- 	-- 	if Shotta.db.screenshottableEvents.levelUp.modifiers.showMainChat.enabled then
	-- 	-- 		ChatFrame1Tab:Click()
	-- 	-- 	end
	-- 	-- end

	-- 	-- if Shotta.db.screenshottableEvents.levelUp.modifiers.showPlayed.enabled then
	-- 	-- 	screenshotFrame.waitingForTimePlayed = true
	-- 	-- 	RequestTimePlayed() -- trigger "TIME_PLAYED_MSG" event
	-- 	-- 	return
	-- 	-- end

	self:ScheduleTimer("TimedScreenshot", 0.5)
end

function Shotta:LoadOptions()
	local config = {
		type = "group",
		args = {
			general_options = {
				name = localizedCheckboxName,
				type = "group",
				order = 0,
				inline = true,
				args = {
					hideMinimap = {
						name = localizedCheckboxName,
						type = "toggle",
						set = function(_, val)
							self.db.profile.minimap.hide = val
							if val then
								LibStub("LibDBIcon-1.0"):Hide("Shotta")
							else
								LibStub("LibDBIcon-1.0"):Show("Shotta")
							end
						end,
						get = function(_)
							return self.db.profile.minimap.hide
						end,
					},
				},
			},
			blizzard_events = {
				name = localizedCheckboxName,
				type = "group",
				order = 2,
				inline = true,
				args = {
					PLAYER_LOGIN = self:BlizzardEventOption(),
					CHAT_MSG_CHANNEL = self:BlizzardEventOption(),
					PLAYER_LEVEL_UP = self:BlizzardEventOption(),
					MAIL_SHOW = self:BlizzardEventOption(),
					READY_CHECK = self:BlizzardEventOption(),
					ZONE_CHANGED = self:BlizzardEventOption(),
					ZONE_CHANGED_NEW_AREA = self:BlizzardEventOption(),
					HEARTHSTONE_BOUND = self:BlizzardEventOption(),
					--@debug@
					PLAYER_STARTED_MOVING = self:BlizzardEventOption(),
					--@end-debug@
					AUCTION_HOUSE_SHOW = self:BlizzardEventOption(),
					GROUP_FORMED = self:BlizzardEventOption(),
					TRADE_ACCEPT_UPDATE = self:BlizzardEventOption(),
					BOSS_KILL = self:BlizzardEventOption(),
					ENCOUNTER_END = self:BlizzardEventOption(),
					QUEST_TURNED_IN = self:BlizzardEventOption(),
					LOOT_ITEM_ROLL_WON = self:BlizzardEventOption(),
					PLAYER_DEAD = self:BlizzardEventOption(),
					CHAT_MSG_TEXT_EMOTE = self:BlizzardEventOption(),
				},
			},
			timer_events = {
				name = localizedCheckboxName,
				type = "group",
				inline = true,
				order = 1,
				args = {
					every_5_minutes = self:TimerEventOption(5, 0),
					every_10_minutes = self:TimerEventOption(10, 1),
					every_30_minutes = self:TimerEventOption(30, 2),
				},
			},
		},
	}
	if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
		config.args.blizzard_events.args.MAJOR_FACTION_RENOWN_LEVEL_CHANGED = self:BlizzardEventOption()
	end

	if (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE) or (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC) then
		config.args.blizzard_events.args.ACHIEVEMENT_EARNED = self:BlizzardEventOption()
	end

	return config
end

function Shotta:conditionallyRegisterBlizzardEvent(newValue, blizzardEvent)
	local handler = self[blizzardEvent]

	if not handler then
		handler = "DefaultBlizzardHandler"
	end

	if newValue then
		--@alpha@
		self:Print(format("Enabling event: %s ", blizzardEvent))
		--@end-alpha@
		self:RegisterEvent(blizzardEvent, handler, self)
	else
		--@alpha@
		self:Print(format("Disabling event: %s ", blizzardEvent))
		--@end-alpha@
		self:UnregisterEvent(blizzardEvent)
	end
end

function Shotta:DefaultBlizzardHandler()
	--@alpha@
	self:Print("Default handler: got enabled Blizzard event, taking screenshot.")
	--@end-alpha@
	TakeScreenshot()
end

---Computes number of days the input day is from today
---@param sourceDate string|number The iso timestamp of requested day
---@return integer number of days since sourceDate
local function daysAgo(sourceDate)
	local currentTime = time()
	local sourceDatetime = tonumber(sourceDate)
	local diffSeconds = currentTime - sourceDatetime
	return math.floor(diffSeconds / (24 * 60 * 60))
end

local function folderName()
	if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
		return "retail"
	elseif WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC then
		return "classic"
	elseif WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
		return "classic_era"
	end

	return "unknown"
end

local aboutOptions = {
	type = "group",
	name = L["about"],
	args = {
		version = {
			name = format("Version: %s", VERSION),
			order = 0,
			type = "description",
		},
		date = {
			name = format("Date: %s (%s days ago)", date("%x", UPDATED_TIMESTAMP), daysAgo(UPDATED_TIMESTAMP)),
			order = 1,
			type = "description",
		},
		screenshotLocation = {
			name = format(L["saveLocationHelpText"], folderName(), folderName()),
			order = 5,
			fontSize = "large",
			type = "description",
		},
		discord = {
			name = format("%s (%s)", L["joinDiscord"], L["pressCtrlC"]),
			type = "input",
			order = 6,
			width = "double",
			get = function(_)
				return DISCORD_LINK
			end,
		},
		code = {
			name = format("%s (%s)", L["gitHubLink"], L["pressCtrlC"]),
			type = "input",
			order = 7,
			width = "double",
			get = function(_)
				return GITHUB_LINK
			end,
		},

		love = {
			name = "For Nandar. Made with love in Melbourne, Australia",
			order = 80,
			fontSize = "small",
			type = "description",
		},
	},
}

function Shotta:TimerEventOption(minutes, order)
	return {
		name = localizedCheckboxName,
		type = "toggle",
		order = order,
		set = function(_, val)
			self.db.profile.events.timer[minutes] = val

			self:conditionallyEnableTimer(val, minutes)
		end,
		get = function(_)
			return self.db.profile.events.timer[minutes]
		end,
	}
end

function Shotta:conditionallyEnableTimer(val, minutes)
	if val then
		--@alpha@
		self:Print(format("Enabling %s minute timer", minutes))
		--@end-alpha@
		self.timerEvents[minutes] = self:ScheduleRepeatingTimer("TimedScreenshot", toMinutes(minutes))
	else
		--@alpha@
		self:Print(format("Cancelling %s minute timer", minutes))
		--@end-alpha@
		self:CancelTimer(self.timerEvents[minutes])
	end
end

function Shotta:OnInitialize()
	self.db = LibStub("AceDB-3.0"):New("ShottaDBv2", defaults)
	self.timerEvents = {}

	LibStub("LibDBIcon-1.0"):Register("Shotta", iconOptions, self.db.profile.minimap)

	local profileOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)

	local acreg = LibStub("AceConfigRegistry-3.0")
	acreg:RegisterOptionsTable("Shotta", self:LoadOptions())
	acreg:RegisterOptionsTable("Shotta about", aboutOptions)
	acreg:RegisterOptionsTable("Shotta profiles", profileOptions)

	local acdia = LibStub("AceConfigDialog-3.0")
	acdia:AddToBlizOptions("Shotta", "Shotta")
	acdia:AddToBlizOptions("Shotta profiles", "Profiles", "Shotta")
	acdia:AddToBlizOptions("Shotta about", "About", "Shotta")

	self:Print(VERSION .. " loaded!")
end

function Shotta:OnEnable()
	-- Do more initialization here, that really enables the use of your addon.
	-- Register Events, Hook functions, Create Frames, Get information from
	-- the game that wasn't available in OnInitialize
	--
	for event, enabled in pairs(self.db.profile.events.blizzard) do
		if enabled then
			self:conditionallyRegisterBlizzardEvent(true, event)
		end
	end

	for min, enabled in pairs(self.db.profile.events.timer) do
		if enabled then
			self:conditionallyEnableTimer(true, min)
		end
	end
end

function Shotta:OnDisable()
	-- Unhook, Unregister Events, Hide frames that you created.
	-- You would probably only use an OnDisable if you want to
	-- build a "standby" mode, or be able to toggle modules on/off.

	-- Unregister all events
	for event, enabled in pairs(self.db.profile.events.blizzard) do
		if enabled then
			self:conditionallyRegisterBlizzardEvent(false, event)
		end
	end

	self:CancelAllTimers()
end

Shotta:RegisterChatCommand("shotta", "OpenToCategory")
Shotta:RegisterChatCommand("sh", "OpenToCategory")
