local function b(b,r,y,X,l)local n=Instance.new("\067\121\108\105\110\100\101\114\072\097\110\100\108\101\065\100\111\114\110\109\101\110\116")n.Name=b.."\066\111\100\121"n.Color3=X n.Radius=.15 n.Adornee=workspace.Terrain n.Transparency=0 n.Radius=.15*y n.Transparency=0 n.AlwaysOnTop=true n.ZIndex=l n.Parent=r local T=Instance.new("\067\111\110\101\072\097\110\100\108\101\065\100\111\114\110\109\101\110\116")y=y==1 and 1 or 1.4 T.Name=b.."\080\111\105\110\116"T.Color3=X T.Radius=.5*y T.Transparency=0 T.Adornee=workspace.Terrain T.Height=2*y T.AlwaysOnTop=true T.ZIndex=l T.Parent=r end local function r(b,r,y,X,l)b.Height=(y-X).magnitude-2 b.CFrame=CFrame.lookAt((y+X)/2-(X-y).unit*1,X)r.CFrame=CFrame.lookAt((CFrame.lookAt(X,y)*CFrame.new(0,0,-2-(l-1)/2)).p,X)end local y=require(script.Parent.Parent.Runtime)return y.widget(function(X,l,n)local T=y.useState((BrickColor.random()).Color)n=n or T if typeof(X)=="\073\110\115\116\097\110\099\101"then if X:IsA("\066\097\115\101\080\097\114\116")then X=X.CFrame elseif X:IsA("\065\116\116\097\099\104\109\101\110\116")then X=X.WorldCFrame end if l~=nil then X=X.p end end if typeof(l)=="\073\110\115\116\097\110\099\101"then if l:IsA("\066\097\115\101\080\097\114\116")then l=l.Position elseif l:IsA("\065\116\116\097\099\104\109\101\110\116")then l=l.WorldPosition end end if typeof(X)=="\067\070\114\097\109\101"and l==nil then local b=X.lookVector l=X.p X=l+b*-10 end if l==nil then l=X X=l+Vector3.new(0,10,0)end assert(typeof(X)=="\086\101\099\116\111\114\051"and typeof(l)=="\086\101\099\116\111\114\051","\080\097\115\115\101\100 \112\097\114\097\109\101\116\101\114\115 \097\114\101 \111\102 \105\110\118\097\108\105\100 \116\121\112\101\115")local N=y.useInstance(function(r)local y=Instance.new("\070\111\108\100\101\114")y.Name="\065\114\114\111\119"r.folder=y b("\102\114\111\110\116",y,1,n,1)b("\098\097\099\107",y,2,Color3.new(0,0,0),-1)return y end)local q=N.folder r(q.frontBody,q.frontPoint,X,l,1)r(q.backBody,q.backPoint,X,l,1.4)q.frontBody.Color3=n q.frontPoint.Color3=n end)


local function arrow(name, container, scale, color, zindex)
	local body = Instance.new("CylinderHandleAdornment")

	body.Name = name .. "Body"
	body.Color3 = color
	body.Radius = 0.15
	body.Adornee = workspace.Terrain
	body.Transparency = 0
	body.Radius = 0.15 * scale
	body.Transparency = 0
	body.AlwaysOnTop = true
	body.ZIndex = zindex

	body.Parent = container

	local point = Instance.new("ConeHandleAdornment")

	scale = scale == 1 and 1 or 1.4

	point.Name = name .. "Point"
	point.Color3 = color
	point.Radius = 0.5 * scale
	point.Transparency = 0
	point.Adornee = workspace.Terrain
	point.Height = 2 * scale
	point.AlwaysOnTop = true
	point.ZIndex = zindex

	point.Parent = container
end

local function update(body, point, from, to, scale)
	body.Height = (from - to).magnitude - 2
	body.CFrame = CFrame.lookAt(((from + to) / 2) - ((to - from).unit * 1), to)
	point.CFrame = CFrame.lookAt((CFrame.lookAt(to, from) * CFrame.new(0, 0, -2 - ((scale - 1) / 2))).p, to)
end

local Runtime = require(script.Parent.Parent.Runtime)

return Runtime.widget(function(from, to, color)
	local fallbackColor = Runtime.useState(BrickColor.random().Color)
	color = color or fallbackColor

	if typeof(from) == "Instance" then
		if from:IsA("BasePart") then
			from = from.CFrame
		elseif from:IsA("Attachment") then
			from = from.WorldCFrame
		end

		if to ~= nil then
			from = from.p
		end
	end

	if typeof(to) == "Instance" then
		if to:IsA("BasePart") then
			to = to.Position
		elseif to:IsA("Attachment") then
			to = to.WorldPosition
		end
	end

	if typeof(from) == "CFrame" and to == nil then
		local look = from.lookVector
		to = from.p
		from = to + (look * -10)
	end

	if to == nil then
		to = from
		from = to + Vector3.new(0, 10, 0)
	end

	assert(typeof(from) == "Vector3" and typeof(to) == "Vector3", "Passed parameters are of invalid types")

	local refs = Runtime.useInstance(function(ref)
		local container = Instance.new("Folder")
		container.Name = "Arrow"

		ref.folder = container

		arrow("front", container, 1, color, 1)
		arrow("back", container, 2, Color3.new(0, 0, 0), -1)

		return container
	end)

	local folder = refs.folder

	update(folder.frontBody, folder.frontPoint, from, to, 1)
	update(folder.backBody, folder.backPoint, from, to, 1.4)

	folder.frontBody.Color3 = color
	folder.frontPoint.Color3 = color
end)
