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",
	text = "timer {timerLabel} is shown. (Requires DBM)",
	test = function(checkTable)
		return WN_GetDBMBar(checkTable.timerLabel) ~= nil
	end,
	arguments = {
		timerLabel = {label = "Timer Name", type = "text", default = ""},
	}
})	

WhatsNext:AddConditionalStatement("DBM Timer Time Remaining",{
	category = "Deadly Boss Mods",
	text = "timer {timerLabel} is shown and has more than {time} seconds remaining. (Requires DBM)",
	test = function(checkTable)
		local bar = WN_GetDBMBar(checkTable.timerLabel)
		return bar ~= nil and tonumber(bar.timer) > tonumber(checkTable.time) 
	end,
	arguments = {
		timerLabel = {label = "Timer Name", type = "text", default = ""},
		time = {label = "Seconds", type = "integer", default = 3, min = 1, max = 60},
	}
})	

WhatsNext:AddConditionalStatement("DBM Timer Less Time Remaining",{
	category = "Deadly Boss Mods",
	text = "timer {timerLabel} is shown and has less than {time} seconds remaining. (Requires DBM)",
	test = function(checkTable)
		local bar = WN_GetDBMBar(checkTable.timerLabel)
		return bar ~= nil and tonumber(bar.timer) < tonumber(checkTable.time) 
	end,
	arguments = {
		timerLabel = {label = "Timer Name", type = "text", default = ""},
		time = {label = "Seconds", type = "integer", default = 3, min = 1, max = 60},
	}
})