include("shared.lua")

/*---------------------------------------------------------
   Name: ENT:Draw()
---------------------------------------------------------*/
function ENT:Draw()

	self.Entity:DrawModel()
	
	local green = Color(45, 175, 45, 255)
	local red = Color(230, 45, 45, 255)
	local ledcolor
	
 	local TargetPos
 	local TargetPos1 = self.Entity:GetPos() + (self.Entity:GetUp() * 9) + (self.Entity:GetRight() * 2.5) + (self.Entity:GetForward() * 1.5)
	local TargetPos2 = self.Entity:GetPos() + (self.Entity:GetUp() * 8.1) + (self.Entity:GetRight() * 3.75) + (self.Entity:GetForward() * 1.5)

	local FixAngles = self.Entity:GetAngles()
	local FixRotation
	
	if GetConVar("default_css_c4") == nil then //it damn well better not be but you had to fuck with something, didn't you?
		TargetPos = TargetPos1
		ledcolor = green
		FixRotation = Vector(0, 270, 0)
	else
		if GetConVar("default_css_c4"):GetBool() then
			TargetPos = TargetPos1
			ledcolor = green
			FixRotation = Vector(0, 270, 0)
		else
			TargetPos = TargetPos2
			ledcolor = red
			FixRotation = Vector(0, 180, 0)
		end
	end
	

	FixAngles:RotateAroundAxis(FixAngles:Right(), FixRotation.x)
	FixAngles:RotateAroundAxis(FixAngles:Up(), FixRotation.y)
	FixAngles:RotateAroundAxis(FixAngles:Forward(), FixRotation.z)

	local m, s = self:FormatTime(self.C4CountDown)

	self.Text = string.format("%02d", m) .. ":" .. string.format("%02d", s)
	
	cam.Start3D2D(TargetPos, FixAngles, .07)
		draw.SimpleText(self.Text, "CloseCaption_Normal", 31, -22, ledcolor, 1, 1)
	cam.End3D2D() 
end

/*---------------------------------------------------------
   Name: ENT:FormatTime()
---------------------------------------------------------*/
function ENT:FormatTime(seconds)

	local m = seconds % 604800 % 86400 % 3600 / 60
	local s = seconds % 604800 % 86400 % 3600 % 60

	return math.floor(m), math.floor(s)
end