--DISPLAY
function()
	local mana = UnitPower("player")
	local maxmana = UnitPowerMax("player")
	return string.format("%.f%%", (mana / maxmana) * 100)
end

--NAME
function()
	local mana = UnitPower("player")
	local maxmana = UnitPowerMax("player")
	return aura_env.shorten(mana)
end

--UNIT_POWER
function()
	return true
end

--DURATION
function()
	local mana = UnitPower("player")
	local maxmana = UnitPowerMax("player")
	return maxmana - mana, maxmana, 1
end

--SPELL_UPDATE_COOLDOWN
function()
	return true
end

--DURATION
function()
	local id = 109132
	if IsPlayerSpell(115008) then id = 115008 end
	local charges, maxCharges, start, duration = GetSpellCharges(id)
	if charges >= 2 then
		return 0, 1, 1, 1
	elseif charges == 1 then
		expirationTime = start + duration
		return duration, expirationTime
	elseif charges < 1 then
		return 1, 1, 1, 1
	end
end

--INIT
aura_env.shorten = function(val)
	local function round(var, n)
		if (n) then
			var = math.floor((var * 10^n) + 0.5) / (10^n)
		else
			var = math.floor(var+0.5)
		end
		return var
	end
	local n = 2
	if val < 1e3 then
		return round(val, n)
	elseif val > 1e3 and val < 1e6 then
		return round(val / 1e3, n) .. "k"
	elseif val > 1e6 and val < 1e9 then
		return round(val / 1e6, n) .. "M"
	elseif val > 1e9 then
		return round(val / 1e9, n) .. "G"
	end
end