library MultiboardControl initializer init
	import Statistics

	multiboard mb
	timer time = CreateTimer()

	public function showBoard takes nothing returns nothing
		MultiboardDisplay(mb, true)
	end

	function periodic takes nothing returns nothing
		string colorCode = "|cffffffff"
		integer secondsLeft = Statistics.roundEndTime - Statistics.secondsElapsed
		integer minutesLeft
		string seconds = "0"
		string minutes = " "
		if secondsLeft < 0 then
			secondsLeft = 0
		end
		minutesLeft = R2I(secondsLeft / 60)
		secondsLeft = ModuloInteger(secondsLeft, 60)
		if secondsLeft < 10 then
			seconds = seconds + I2S(secondsLeft)
		else
			seconds = I2S(secondsLeft)
		end
		if minutesLeft > 0 then
			minutes = I2S(minutesLeft)
		else
			if secondsLeft <= 0 then
				colorCode = "|cff444444"
			elseif secondsLeft < 10 and ModuloInteger(secondsLeft, 2) == 0 then
				colorCode = "|cffee0000"
			elseif secondsLeft < 30 and ModuloInteger(secondsLeft, 2) == 0 then
				colorCode = "|cff999999"
			end
		end

		MultiboardSetTitleText(mb, "|cff999999Hunters|r  " + I2S(Statistics.hunterWins) + " - " + I2S(Statistics.beastWins) + "  |cff411d0aBeasts|r")
		MultiboardSetItemValue(MultiboardGetItem(mb, 0, 1), colorCode + minutes + "|r:" + colorCode + seconds + "|r")
	end

	function act takes nothing returns nothing
		DestroyTimer(GetExpiredTimer())

		mb = CreateMultiboard()
		MultiboardSetColumnCount(mb, 2)
		MultiboardSetRowCount(mb, 1)

		MultiboardSetItemsStyle(mb, true, false)
		MultiboardSetItemWidth(MultiboardGetItem(mb, 0, 0), .09)
		MultiboardSetItemWidth(MultiboardGetItem(mb, 0, 1), .04)

		MultiboardSetTitleText(mb, "|cff999999Hunters|r  0 - 0  |cff411d0aBeasts|r")
		MultiboardSetItemValue(MultiboardGetItem(mb, 0, 0), "|cffffcc00Round Time:|r")
		MultiboardSetItemValue(MultiboardGetItem(mb, 0, 1), "0:00")

		TimerStart(time, 1., true, function periodic)
	end

	function init takes nothing returns nothing
		TimerStart(CreateTimer(), 0., false, function act)
	end
endlibrary
