--PLAYER_REGEN_DISABLED PLAYER_REGEN_ENABLED COMBAT_TICKER_TICK COMBAT_TICKER_FALSE
function(e)
	if not WeakAurasSaved.CustomTrash then WeakAurasSaved.CustomTrash = {} end
	if not WeakAurasSaved.CustomTrash.CombatTimers then WeakAurasSaved.CustomTrash.CombatTimers = {}; aura_env.updateTimers() end
	if e == "PLAYER_REGEN_ENABLED" then
		if WeakAurasSaved.CustomTrash.CombatTimers.ticker then WeakAurasSaved.CustomTrash.CombatTimers.ticker:Cancel(); WeakAurasSaved.CustomTrash.CombatTimers.ticker = nil end
	elseif e == "PLAYER_REGEN_DISABLED" then
		WeakAurasSaved.CustomTrash.CombatTimers.time = 0
		WeakAuras.ScanEvents("COMBAT_TICKER_TICK")
		WeakAurasSaved.CustomTrash.CombatTimers.nearestTime = {["time"] = 999, ["id"] = 0}
		aura_env.nextTimer(WeakAurasSaved.CustomTrash.CombatTimers.time)
		if not WeakAurasSaved.CustomTrash.CombatTimers.ticker then WeakAurasSaved.CustomTrash.CombatTimers.ticker = C_Timer.NewTicker(1, function() WeakAuras.ScanEvents("COMBAT_TICKER_TICK") end) end
	elseif e == "COMBAT_TICKER_TICK" then
		WeakAurasSaved.CustomTrash.CombatTimers.time = WeakAurasSaved.CustomTrash.CombatTimers.time + 1
		WeakAurasSaved.CustomTrash.CombatTimers.nearestTime.time = WeakAurasSaved.CustomTrash.CombatTimers.nearestTime.time - 1
		if WeakAurasSaved.CustomTrash.CombatTimers.timers[WeakAurasSaved.CustomTrash.CombatTimers.time] then
			WeakAurasSaved.CustomTrash.CombatTimers.nearestTime = {["time"] = 999, ["id"] = 0}
			aura_env.nextTimer(WeakAurasSaved.CustomTrash.CombatTimers.time)
			C_Timer.After(aura_env.config.dur, function() WeakAuras.ScanEvents("COMBAT_TICKER_FALSE") end)
			return true
		end
	end
end

--UNTRIGGER
function(e)
	if e == "COMBAT_TICKER_FALSE" then
		return true
	end
end

--Aura #2
--COMBAT_TICKER_TICK
function(e)
	return true
end

--DISPLAY
function()
	local temps = {
		[1] = {["m"] = 0, ["s"] = 0, ["res"] = WeakAurasSaved.CustomTrash.CombatTimers.time},
		[2] = {["m"] = 0, ["s"] = 0, ["res"] = WeakAurasSaved.CustomTrash.CombatTimers.nearestTime.time},
		[3] = {["m"] = 0, ["s"] = 0, ["res"] = WeakAurasSaved.CustomTrash.CombatTimers.nearestTime.id},
	}

	for k,v in ipairs(temps) do
		while v.res >= 60 do
			v.m = v.m + 1
			v.res = v.res - 60
		end
		v.s = v.res
		if v.s < 10 then
			v.s = string.format("0%d", v.s)
		end
		if type(v.s) ~= "string" then tostring(v.s) end
	end

	return string.format("%d:%s\n%d:%s (%d:%s)", temps[1].m, temps[1].s, temps[2].m, temps[2].s, temps[3].m, temps[3].s)
end

--INIT
if not WeakAurasSaved.CustomTrash then WeakAurasSaved.CustomTrash = {} end
if not WeakAurasSaved.CustomTrash.CombatTimers then WeakAurasSaved.CustomTrash.CombatTimers = {} end

WeakAurasSaved.CustomTrash.CombatTimers.nearestTime = {["time"] = 999, ["id"] = 0}
WeakAurasSaved.CustomTrash.CombatTimers.time = 0

aura_env.updateTimers = function()
    WeakAurasSaved.CustomTrash.CombatTimers.timers = {}
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m1 or 0) * 60) + (aura_env.config.s1 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m2 or 0) * 60) + (aura_env.config.s2 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m3 or 0) * 60) + (aura_env.config.s3 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m4 or 0) * 60) + (aura_env.config.s4 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m5 or 0) * 60) + (aura_env.config.s5 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m6 or 0) * 60) + (aura_env.config.s6 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m7 or 0) * 60) + (aura_env.config.s7 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m8 or 0) * 60) + (aura_env.config.s8 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m9 or 0) * 60) + (aura_env.config.s9 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m10 or 0) * 60) + (aura_env.config.s10 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m11 or 0) * 60) + (aura_env.config.s11 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m12 or 0) * 60) + (aura_env.config.s12 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m13 or 0) * 60) + (aura_env.config.s13 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m14 or 0) * 60) + (aura_env.config.s14 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m15 or 0) * 60) + (aura_env.config.s15 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m16 or 0) * 60) + (aura_env.config.s16 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m17 or 0) * 60) + (aura_env.config.s17 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m18 or 0) * 60) + (aura_env.config.s18 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m19 or 0) * 60) + (aura_env.config.s19 or 0)] = 1
    WeakAurasSaved.CustomTrash.CombatTimers.timers[((aura_env.config.m20 or 0) * 60) + (aura_env.config.s20 or 0)] = 1
end

aura_env.updateTimers()

aura_env.nextTimer = function(time)
    for k,v in pairs(WeakAurasSaved.CustomTrash.CombatTimers.timers) do
        local dtime = k - time
        if dtime < WeakAurasSaved.CustomTrash.CombatTimers.nearestTime.time and dtime > 0 then
            WeakAurasSaved.CustomTrash.CombatTimers.nearestTime.time = dtime
            WeakAurasSaved.CustomTrash.CombatTimers.nearestTime.id = k 
        end
    end
    return 0
end