include("shared.lua")


function ENT:Initialize()
	local mat = CreateMaterial( "pizzaMat", "VertexLitGeneric", {
	 ["$basetexture"] = "color/white",
	 ["$model"] = 1,
	 ["$translucent"] = 1,
	 ["$vertexalpha"] = 1,
	 ["$vertexcolor"] = 1
	} )
	self:SetMaterial("!pizzaMat")
end

//----------------------------//
function ENT:Draw()
	self:DrawModel()
	if(LocalPlayer():GetPos():Distance(self:GetPos()) < 500)then
		self:Draw_MainInfo()
	end
end
function ENT:DrawTranslucent()
	self:Draw()
end


local ButtonIcon = Material("materials/zerochain/zpizmak/ui/zpizmak_button.png", "smooth")
local ArrowIcon = Material("materials/zerochain/zpizmak/ui/zpizmak_arrow.png", "smooth")

local ClockBaseIcon = Material("materials/zerochain/zpizmak/ui/zpizmak_clock_base.png", "smooth")
local ClockPointerIcon = Material("materials/zerochain/zpizmak/ui/zpizmak_clock_pointer.png", "smooth")


function ENT:Draw_MainInfo()


	local time = self:GetPizzaWaitTime()

	if(time > 0)then

		local status = self:GetPizzaType()
		local maxTime =(zpizmak.f.GetPizzaByName(status).BakeTime || 0) + zpizmak.config.Customer_ExtraWaitTime

		local Pos = self:GetPos()+self:GetForward()*-15 + Vector(0,0,25)
		Pos = Pos + self:GetUp()*math.abs(math.sin(CurTime()*2) * 5)
		local Ang = Angle( 0, LocalPlayer():EyeAngles().y - 90, 90 )


		time = math.Round(time - CurTime())
		local progress = (1 / maxTime) * time
		local c = zpizmak.f.LerpColor(progress, Color(255,0,0,255), Color(0,255,0,255))
		cam.Start3D2D(Pos , Ang, 0.1)

			surface.SetDrawColor( 0, 0, 0, 100 )
			surface.SetMaterial( ButtonIcon )
			surface.DrawTexturedRect( -50, -410, 100, 80 )

			draw.DrawText(time, "zpizmak_plate_font02",0, -415,  c, TEXT_ALIGN_CENTER  )


			surface.SetDrawColor( c )
			surface.SetMaterial( ArrowIcon )
			surface.DrawTexturedRect( -70, -100, 140, 140 )

			surface.SetDrawColor( 0, 0, 0, 100 )
			surface.SetMaterial( ButtonIcon )
			surface.DrawTexturedRect( -150, -175, 300, 60 )

			draw.DrawText(status, "zpizmak_pizza_font01",0, -170,  Color(255,255,255), TEXT_ALIGN_CENTER  )

			surface.SetDrawColor( 255, 255, 255, 255 )
			surface.SetMaterial( ClockBaseIcon )
			surface.DrawTexturedRect( -90, -360, 180, 180 )

			surface.SetDrawColor( 255, 255, 255, 255 )
			surface.SetMaterial( ClockPointerIcon )
			surface.DrawTexturedRectRotated( 0, -270, 180, 180 ,  Lerp(progress, 0 ,360) )

		cam.End3D2D()
	end

end

//Utility
function ENT:GetPizzaByName(name)
	local piz = nil
	for k, v in pairs(zpizmak.config.Pizzas) do
		if(v.Name == name)then
			piz = v
			break
		end
	end
	return piz
end
//////

function ENT:Think()
	self:SetNextClientThink( CurTime())
    return true
end
function ENT:OnRemove() end
