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,...)
		--print(bar)
		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

function WN_GetDBMBar(barLabel)
	for bar,text in pairs(dbmTimers) do
	--	print(text)
		if text == barLabel then
			return bar,text
		end
	end
end
	
WhatsNext:AddConditionalStatement("DBM Timer Shown",{
	category = "Deadly Boss Mods",
	test = function(checkTable)
		return WN_GetDBMBar(checkTable.timerLabel) ~= nil
	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)
		local bar = WN_GetDBMBar(checkTable.timerLabel)
		return bar ~= nil and tonumber(bar.timer) > tonumber(checkTable.time) 
	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)
		local bar = WN_GetDBMBar(checkTable.timerLabel)
		return bar ~= nil and tonumber(bar.timer) < tonumber(checkTable.time) 
	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},
	}
})