local _, Ns = ...

---------------------
-- Options Equates --
---------------------
local World, Equipped, Total, Live, Percentage, BNet = 1, 1, 1, 1, 1, 1
local Realm, Static, Rating, Max = 2, 2, 2, 2
local Both, Bags = 3, 3

-- Gold
function Ns.FunctionList.Money(HUD, data, options, ...)

	local money = GetMoney()
	local formattedMoney = (GetCoinTextureString(money))
	local returnText

	returnText = formattedMoney

	HUD:UpdateText(data, returnText)
end
------------------------------------------------

-- Speed
function Ns.FunctionList.Speed(HUD, data, options, ...)

	local fullSpeed = GetUnitSpeed("player") / 7 * 100
	local speedColor = ""
	local returnText
	local statusbar = fullSpeed

	if options.Color_Effect then
		if fullSpeed == 0 or fullSpeed == 100 then
			speedColor = ""
		elseif fullSpeed < 100 then
			speedColor = "|cffC41E3A"
		elseif fullSpeed > 100 then
			speedColor = "|cff00f26d"
		end
	end

	returnText = speedColor .. string.format("%d%%", ("%.0f"):format(fullSpeed))

	HUD:UpdateText(data, returnText)

	local barMax = 100
	if IsMounted() then barMax = 209 end
	if IsSwimming() then barMax = 100 end
	HUD:UpdateBar(data, statusbar, barMax)
end
------------------------------------------------

-- Target Speed
function Ns.FunctionList.TargetSpeed(HUD, data, options, ...)

	local targetSpeed = GetUnitSpeed("target") / 7 * 100
	local speedColor = ""

	if options.Color_Effect then
		if targetSpeed == 0 or targetSpeed == 100 then speedColor = ""
		elseif targetSpeed < 100 then speedColor = "|cffC41E3A"
		elseif targetSpeed > 100 then speedColor = "|cff71FFC9" end
	end

	HUD:UpdateText(data, speedColor .. string.format("%d%%", ("%.0f"):format(targetSpeed)))
end
------------------------------------------------

-- FPS
function Ns.FunctionList.FPS(HUD, data, options, ...)

	local framerate = GetFramerate()
	local fpsColor = ""

	if options.Color_Effect then
		if framerate <= 30 then fpsColor = "|cffC41E3A"
		elseif framerate > 30 and framerate < 50 then fpsColor = "|cffFF7C0A"
		elseif framerate >= 50 then fpsColor = "|cff71FFC9" end
	end

	HUD:UpdateText(data, fpsColor .. floor(framerate))
end
------------------------------------------------

-- Lag
function Ns.FunctionList.Lag(HUD, data, options, ...)

	local _, _, _, lagWorld = GetNetStats()
	local returnText

	if lagWorld <= 90 then
		returnText = "|cff00f26d" .. lagWorld .. " ms|r"
	elseif lagWorld >= 90 and lagWorld < 200 then
		returnText = "|cffFF7C0A" .. lagWorld .. " ms|r"
	elseif lagWorld >= 200 then
		returnText = "|cffC41E3A" .. lagWorld .. " ms|r"
	end

	HUD:UpdateText(data, returnText)
end
------------------------------------------------

-- Debuffs
function Ns.FunctionList.DebuffCounter(HUD, data, options, ...)

	HUD:UpdateText(data, Ns.debuffCount)
end
------------------------------------------------

-- Buffs
function Ns.FunctionList.BuffCounter(HUD, data, options, ...)

	HUD:UpdateText(data, Ns.buffCount)
end
------------------------------------------------

-- Durability
function Ns.FunctionList.Durability(HUD, data, options, ...)

	local Durability, Current, Full, Percent
	local LowestCurrent, LowestFull, t1, t2, t3 = 500, 0, 0, 0, 100
	local statusbar
	for i=1,19 do
		Current, Full = GetInventoryItemDurability(i)
		if Current and Full then
			Percent = floor(100*Current/Full + 0.5)
			if (Percent < t3) then
				t3 = Percent
			end
			if (Current < LowestCurrent) then
				LowestCurrent = Current
				LowestFull = Full
			end
			t1 = t1 + Current
			t2 = t2 + Full
		end
	end
	if t2 == 0 then
		Durability = "N/A"
	else
		Durability = floor(t1 * 100 / t2)
	end
	local Text = ""
	if type(Durability) == "number" then
		if not options.AutoColorOff then
			if Durability > 50 then
				Text = string.format("|cff%2xff00", ((Durability > 50) and (255 - 2.55*Durability) or (2.55*Durability)), Durability) .. Text
			else
				Text = string.format("|cffff%2x00", (2.55*Durability), Durability) .. Text
			end
		end
		Text = Text..Durability.."%"
		statusbar = Durability
	end

	HUD:UpdateText(data, Text)
	HUD:UpdateBar(data, statusbar, 100)
end
------------------------------------------------

-- Guild
function Ns.FunctionList.Guild(HUD, data, options, ...)

	local totalMembers, numOnline = GetNumGuildMembers()
	local returnText

	if not IsInGuild() then
		HUD:UpdateText(data, "0")
		return
	end

	if options.Display_Total then
		returnText = numOnline .. "/" .. totalMembers
	else
		returnText = tostring(numOnline)
	end

	HUD:UpdateText(data, returnText)
end
------------------------------------------------

-- Friends
function Ns.FunctionList.Friends(HUD, data, options, ...)

	local EB = options.BNet_Realm
	local bnetTotal, bnetOnline = BNGetNumFriends()
	local numFriends, realmOnline = C_FriendList.GetNumFriends()
	local returnText

	if Ns.Band(EB, BNet) then returnText = tostring(bnetOnline) end
	if Ns.Band(EB, Realm) then returnText = tostring(realmOnline) end
	if Ns.Band(EB, Both) then returnText = bnetOnline .. "/" .. realmOnline end

	HUD:UpdateText(data, returnText)
end
------------------------------------------------