local dbmTimers = {}
local bar


if DBM then
	local tempMod = DBM:NewMod("temp")
	local tempTimer = tempMod:NewTimer(-1,"temp",-1)
	local meta = getmetatable(tempTimer).__index
	local Start = meta.Start
	meta.Start = function(self,timer, ...)
		local bar = Start(self,timer,...)
		if bar then
			if not dbmTimers[bar.frame] then
				local OnHide = bar.frame:GetScript("OnHide")
				bar.frame:SetScript("OnHide",function(self) 
					if OnHide then 
						OnHide(self)
					end
					dbmTimers[bar] = ""
				end)
			end
			dbmTimers[bar] = _G[bar.frame:GetName().."BarName"]:GetText()
		end
		return bar
	end
end
	
WhatsNext:AddConditionalStatement("DBM Timer Shown",{
	category = "Deadly Boss Mods",
	test = function(checkTable)
		for bar,text in pairs(dbmTimers) do 
			if text == checkTable.timerLabel then
				return true
			end
		end
		return false
	end,
	text = function(checkTable) 
		return "timer "..tostring(checkTable.timerLabel) .. " is shown. (Requires DBM)"
	end,
	arguments = {
		timerLabel = {type = "text", default = ""},
	}
})	

WhatsNext:AddConditionalStatement("DBM Timer Time Remaining",{
	category = "Deadly Boss Mods",
	test = function(checkTable)
		for bar,text in pairs(dbmTimers) do 
			if text == checkTable.timerLabel then
				return tonumber(bar.timer) > tonumber(checkTable.time) 
			end
		end
		return false
	end,
	text = function(checkTable) 
		return "timer "..tostring(checkTable.timerLabel) .. " is shown and has more than " .. tostring(checkTable.time) .. " seconds remaining. (Requires DBM)"
	end,
	arguments = {
		timerLabel = {type = "text", default = ""},
		time = {type = "integer", default = 3},
	}
})	

WhatsNext:AddConditionalStatement("DBM Timer Less Time Remaining",{
	category = "Deadly Boss Mods",
	test = function(checkTable)
		for bar,text in pairs(dbmTimers) do 
			if text == checkTable.timerLabel then
				return tonumber(bar.timer) < tonumber(checkTable.time) 
			end
		end
		return false
	end,
	text = function(checkTable) 
		return "timer "..tostring(checkTable.timerLabel) .. " is shown and has less than " .. tostring(checkTable.time) .. " seconds remaining. (Requires DBM)"
	end,
	arguments = {
		timerLabel = {type = "text", default = ""},
		time = {type = "integer", default = 3},
	}
})