Quantcast
local _, addon = ...
local timer = addon:NewModule("Timer")

local frame

function timer:Create(castingBar)
	frame = castingBar:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
	return timer
end

function timer:SetValue(castingBar)
	if castingBar.casting then
		local value = self.maxValue - self.value
		if timer:IsHidden() then
			frame:SetText(nil)
		elseif timer:HasTotalTimeOnly() then
			frame:SetFormattedText("%.1f", self.maxValue)
		elseif timer:HasCastTimeOnly() then
			frame:SetFormattedText("%.1f", value)
		else
			frame:SetFormattedText("%.1f/%.1f", value, self.maxValue)
		end
	elseif castingBar.channeling then
		frame:SetFormattedText("%.1f", self.value)
	end
end

function timer:Hide()
	frame:Hide()
end

function timer:Show()
	frame:Show()
end

function timer:IsHidden()
	return addon.db.profile.timerDisplay == "Hide"
end

function timer:HasTotalTimeOnly()
	return not timer:IsHidden() and addon.db.profile.timerDisplay == "Hide Total Time"
end

function timer:HasCastTimeOnly()
	return not timer:IsHidden() and addon.db.profile.timerDisplay == "Hide Cast Time"
end

function timer:SetPosition(parent)
	local parent = self:GetParent()
	-- NYI
end

function timer:SetDisplay(timerDisplay)
	addon.db.profile.timerDisplay = timerDisplay
end

function timer:GetDisplay()
	return addon.db.profile.timerDisplay
end

function timer:SetVisibility(parent)
	if not self:IsHidden() then
		self:SetPosition(parent)
		self:Show()
	else
		self:Hide()
	end
end