local GlobalAddonName, ExRT = ...

local module = ExRT.mod:New("AutoLogging",ExRT.L.Logging,nil,true)

module.db.raidIDs = {
	[988]=true,	--BF
	[994]=true,	--H
}

function module.options:Load()
	self.enableChk = ExRT.lib.CreateCheckBox(self,nil,10,-15,ExRT.L.LoggingEnable)
	self.enableChk:SetScript("OnClick", function(self,event) 
		if self:GetChecked() then
			VExRT.Logging.enabled = true
			module:Enable()
		else
			VExRT.Logging.enabled = nil
			module:Disable()
		end
	end)
	self.enableChk:SetChecked(VExRT.Logging.enabled)
		
	self.shtml1 = ExRT.lib.CreateText(self,585,0,"TOP",0,-45,nil,"TOP",nil,12,"- "..ExRT.L.RaidLootT17Highmaul.."\n- "..ExRT.L.RaidLootT17BF)

	self.shtml2 = ExRT.lib.CreateText(self,605,0,nil,10,-15,nil,"TOP",nil,12,ExRT.L.LoggingHelp1)
	ExRT.lib.SetPoint(self.shtml2,"TOP",self.shtml1,"BOTTOM",0,-15)
end


function module:Enable()
	module:RegisterEvents('ZONE_CHANGED_NEW_AREA')
	module.main:ZONE_CHANGED_NEW_AREA()
end
function module:Disable()
	module:UnregisterEvents('ZONE_CHANGED_NEW_AREA')
	module.main:ZONE_CHANGED_NEW_AREA()
end


function module.main:ADDON_LOADED()
	VExRT = _G.VExRT
	VExRT.Logging = VExRT.Logging or {}

	if VExRT.Logging.enabled then
		module:Enable()
	end
end

local function GetCurrentMapAreaID_Fix()
	if VExRT.Logging.enabled then
		return GetCurrentMapAreaID()
	else
		return 0
	end
end

local prevZone = 0
function module.main:ZONE_CHANGED_NEW_AREA()
	local zoneID = GetCurrentMapAreaID()
	if module.db.raidIDs[zoneID] then
		LoggingCombat(true)
		print(ExRT.L.LoggingStart)
	else
		if module.db.raidIDs[prevZone] and LoggingCombat() then
			LoggingCombat(false)
			print(ExRT.L.LoggingEnd)
		end
	end
	prevZone = zoneID
end
