--UNIT_HEALTH NAME_PLATE_UNIT_REMOVED NAME_PLATE_UNIT_ADDED UNIT_THREAT_LIST_UPDATE PLAYER_TARGET_CHANGED
function(allstates, e, u)
	if e == "PLAYER_TARGET_CHANGED" then
		return true
	elseif e == "UNIT_HEALTH" or e == "UNIT_THREAT_LIST_UPDATE" then
		if u then
			print(UnitDetailedThreatSituation("player", u))
			if UnitExists(u) and u:match("nameplate") and UnitDetailedThreatSituation("player", u) then
				local threat = select(5, UnitDetailedThreatSituation("player", u))
				local tank = UnitDetailedThreatSituation("player", u)
				local hp = UnitHealth(u)
				local maxhp = UnitHealthMax(u)
				local php = aura_env.round((hp / maxhp) * 100, 1)
				local name = UnitName(u)
				local target = false
				if UnitIsUnit(u, "target") then target = true end
				allstates[u] =
				{
					show = true,
					changed = true,
					name = name,
					unit = u,
					value = hp,
					total = maxhp,
					index = php,
					shp = aura_env.shorten(hp),
					tank = tank,
					target = target,
					resort = true,
					progressType = "static",
				}
				return true
			end
		end
	elseif e == "NAME_PLATE_UNIT_REMOVED" then
		if allstates[u] then allstates[u].changed = true; allstates[u].show = false; return true end
	elseif e == "NAME_PLATE_UNIT_ADDED" then
		if not allstates[u] then
			if u then
				if UnitExists(u) and UnitDetailedThreatSituation("player", u) then
					local threat = select(5, UnitDetailedThreatSituation("player", u))
					local tank = UnitDetailedThreatSituation("player", u)
					local hp = UnitHealth(u)
					local maxhp = UnitHealthMax(u)
					local php = aura_env.round((hp / maxhp) * 100, 1)
					local name = UnitName(u)
					local target = false
					if UnitIsUnit(u, "target") then target = true end
					allstates[u] =
					{
						show = true,
						changed = true,
						name = name,
						unit = u,
						value = hp,
						total = maxhp,
						index = php,
						shp = aura_env.shorten(hp),
						tank = tank,
						target = target,
						resort = true,
						progressType = "static",
					}
					return true
				end
			end
		end
	end
end

--ADDITIONAL INFO
{
	tank = "bool",
	target = "bool",
	index = "number",
}

--INIT
aura_env.round = function(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
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