local M=game:GetService("\082\117\110\083\101\114\118\105\099\101")local B=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local f=game:GetService("\080\108\097\121\101\114\115")local e=script.Parent.Parent local D=e.Modules local A=require(D.Packages)local n=require(A.Directory.Roact)local H=n.Component:extend("\080\097\099\107\101\116\067\105\114\099\108\101\065\114\099\115")local function b(M,B,f)return M+(B-M)*f end local function d(M)local B=M.Data.EndPercent local f=M.Data.StartPercent local e=M.Data.VisiblePercent return n.createElement("\073\109\097\103\101\076\097\098\101\108",{BackgroundTransparency=1;Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\051\053\056\055\051\054\055\048\056\049";ImageColor3=M.Highlighted:map(function(e)if e>=f and e<=B then return M.Data.Color:Lerp(Color3.new(1,1,1),.5)end return M.Data.Color end);Size=UDim2.fromScale(2,1),Position=UDim2.fromScale(M.Side=="\076\101\102\116"and 0 or-1,0),ZIndex=M.ZIndex},{UIGradient=n.createElement("\085\073\071\114\097\100\105\101\110\116",{Rotation=M.AnimationAlpha:map(function(B)if M.Side=="\076\101\102\116"then local M=b(0,e,math.clamp(B*2,0,1))local f=-3.6*M+180 return f else local M=b(0,e-50,math.clamp(B*2-1,0,1))return b(0,-180,M/100)*2 end end),Transparency=NumberSequence.new({NumberSequenceKeypoint.new(0,0);NumberSequenceKeypoint.new(M.Side=="\076\101\102\116"and.498 or.5,0);NumberSequenceKeypoint.new(M.Side=="\076\101\102\116"and.499 or.501,1),NumberSequenceKeypoint.new(1,1)})})})end function H.init(e)e.AnimationAlpha,e.SetAnimationAlpha=n.createBinding(0)e.ActualAlpha,e.SetActualAlpha=n.createBinding(0)e.MousePosition,e.SetMousePosition=n.createBinding(Vector2.zero)e.HighlightedPercent,e.SetHighlightedPercent=n.createBinding(-1)local D=2 local H=A.IsPlugin and e.props.PluginMouse or f.LocalPlayer:GetMouse()M.RenderStepped:Connect(function(M)local f=Vector2.new(H.X,H.Y)e.SetMousePosition(f)local A=e.ActualAlpha:getValue()e.SetAnimationAlpha(B:GetValue(A,Enum.EasingStyle.Quad,Enum.EasingDirection.Out))e.SetActualAlpha(math.clamp(A+M*D,0,1))end)end function H.render(M)local B={Left={};Right={}}local f=0 M.SetActualAlpha(0)local e=#M.props.Arcs for D,A in ipairs(M.props.Arcs)do local n=(e-D)+2 local H=math.min(f+A.Percent,100)if f>100 then break end if H>50 and f<=50 then B.Left[D]=d({ZIndex=n;Data={StartPercent=f;EndPercent=f+A.Percent;VisiblePercent=50;Color=A.Color};Side="\076\101\102\116";AnimationAlpha=M.AnimationAlpha;Highlighted=M.HighlightedPercent})end local b=H>50 and"\082\105\103\104\116"or"\076\101\102\116"B[b][D]=d({ZIndex=n,Data={StartPercent=f,EndPercent=f+A.Percent,VisiblePercent=H,Color=A.Color};Side=b,AnimationAlpha=M.AnimationAlpha;Highlighted=M.HighlightedPercent})f+=A.Percent end return n.createElement("\070\114\097\109\101",{BackgroundTransparency=1;Size=UDim2.new(1,-8,1,-8),Position=UDim2.fromScale(.5,.5);AnchorPoint=Vector2.new(.5,.5);[n.Event.MouseEnter]=function()M.MouseOver=true end,[n.Event.MouseLeave]=function()M.MouseOver=false M.SetHighlightedPercent(-1)end,[n.Event.MouseMoved]=function(B)if M.MouseOver then local f=M.MousePosition:getValue()local e=B.AbsolutePosition+B.AbsoluteSize/2 local D=math.deg(math.atan2(f.Y-e.Y,f.X-e.X))+90 if D<0 then D+=360 end local A=(D/360)*100 M.SetHighlightedPercent(100-A)end end,[n.Event.InputEnded]=function()local B=M.HighlightedPercent:getValue()if B==-1 then return end M.SetHighlightedPercent(-1)end},{Left=n.createElement("\070\114\097\109\101",{BackgroundTransparency=1,ClipsDescendants=true;Size=UDim2.fromScale(.5,1)},{Arcs=n.createFragment(B.Left)}),Right=n.createElement("\070\114\097\109\101",{AnchorPoint=Vector2.new(1,0),BackgroundTransparency=1,ClipsDescendants=true;Position=UDim2.fromScale(1,0);Size=UDim2.fromScale(.5,1)},{Arcs=n.createFragment(B.Right)})})end return H
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local PacketProfiler = script.Parent.Parent
local Modules = PacketProfiler.Modules
local Packages = require(Modules.Packages)

local Roact = require(Packages.Directory.Roact)

local PacketCircleArcs = Roact.Component:extend("PacketCircleArcs")

local function lerp(a, b, alpha)
	return a + (b - a)*alpha
end

local function CircleArc(props)
	local EndPercent = props.Data.EndPercent
	local StartPercent = props.Data.StartPercent
	local VisiblePercent = props.Data.VisiblePercent

	return Roact.createElement("ImageLabel", {
		BackgroundTransparency = 1,
		Image = "rbxassetid://3587367081",
		ImageColor3 = props.Highlighted:map(function(Percent)
			if Percent >= StartPercent and Percent <= EndPercent then
				return props.Data.Color:Lerp(Color3.new(1, 1, 1), 0.5)
			end

			return props.Data.Color
		end),
		Size = UDim2.fromScale(2, 1),
		Position = UDim2.fromScale(props.Side == "Left" and 0 or -1, 0),
		ZIndex = props.ZIndex,
	}, {
		UIGradient = Roact.createElement("UIGradient", {
			Rotation = props.AnimationAlpha:map(function(Alpha)
				if props.Side == "Left" then
					local AlphaPercent = lerp(0, VisiblePercent, math.clamp(Alpha*2, 0, 1))
					local Angle = -3.6*AlphaPercent + 180
					return Angle
				else
					local AlphaPercent = lerp(0, VisiblePercent - 50, math.clamp(Alpha*2 - 1, 0, 1))
					return lerp(0, -180, AlphaPercent / 100) * 2
				end
			end),
			Transparency = NumberSequence.new({
				NumberSequenceKeypoint.new(0, 0),
				NumberSequenceKeypoint.new(props.Side == "Left" and 0.498 or 0.5, 0),
				NumberSequenceKeypoint.new(props.Side == "Left" and 0.499 or 0.501, 1),
				NumberSequenceKeypoint.new(1, 1),
			}),
			-- There's a weird bug with UIGradient which causes discoloration,
			-- but this small offset fixes it
			--Offset = Vector2.new(0, 0.0002),
		}),
	})
end

function PacketCircleArcs:init()
	self.AnimationAlpha, self.SetAnimationAlpha = Roact.createBinding(0)
	self.ActualAlpha, self.SetActualAlpha = Roact.createBinding(0)
	self.MousePosition, self.SetMousePosition = Roact.createBinding(Vector2.zero)
	self.HighlightedPercent, self.SetHighlightedPercent = Roact.createBinding(-1)

	local Speed = 2
	local Mouse = Packages.IsPlugin and self.props.PluginMouse or Players.LocalPlayer:GetMouse()
	RunService.RenderStepped:Connect(function(Step)
		local MousePosition = Vector2.new(Mouse.X, Mouse.Y)
		self.SetMousePosition(MousePosition)

		local alpha = self.ActualAlpha:getValue()

		self.SetAnimationAlpha(TweenService:GetValue(alpha, Enum.EasingStyle.Quad, Enum.EasingDirection.Out))
		self.SetActualAlpha(math.clamp(alpha + Step*Speed, 0, 1))
	end)
end

function PacketCircleArcs:render()
	local CircleArcs = {
		Left = {},
		Right = {},
	}
	local StartPercent = 0

	self.SetActualAlpha(0)

	local NumArcs = #self.props.Arcs
	for Index, Arc in ipairs(self.props.Arcs) do
		local ZIndex = (NumArcs - Index) + 2
		local EndPercent = math.min(StartPercent + Arc.Percent, 100)

		if StartPercent > 100 then
			break
		end

		if EndPercent > 50 and StartPercent <= 50 then
			CircleArcs.Left[Index] = CircleArc({
				ZIndex = ZIndex,
				Data = {
					StartPercent = StartPercent,
					EndPercent = StartPercent + Arc.Percent,
					VisiblePercent = 50,
					Color = Arc.Color,
				},
				Side = "Left",
				AnimationAlpha = self.AnimationAlpha,
				Highlighted = self.HighlightedPercent,
			})
		end

		local ArcSide = EndPercent > 50 and "Right" or "Left"
		CircleArcs[ArcSide][Index] = CircleArc({
			ZIndex = ZIndex,
			Data = {
				StartPercent = StartPercent,
				EndPercent = StartPercent + Arc.Percent,
				VisiblePercent = EndPercent,
				Color = Arc.Color,
			},
			Side = ArcSide,
			AnimationAlpha = self.AnimationAlpha,
			Highlighted = self.HighlightedPercent,
		})

		StartPercent += Arc.Percent
	end

	return Roact.createElement("Frame", {
		BackgroundTransparency = 1,
		Size = UDim2.new(1, -8, 1, -8),
		Position = UDim2.fromScale(0.5, 0.5),
		AnchorPoint = Vector2.new(0.5, 0.5),

		[Roact.Event.MouseEnter] = function()
			self.MouseOver = true
		end,
		[Roact.Event.MouseLeave] = function()
			self.MouseOver = false
			self.SetHighlightedPercent(-1)
		end,
		[Roact.Event.MouseMoved] = function(Rbx)
			if self.MouseOver then
				local MousePosition = self.MousePosition:getValue()
				local Center = Rbx.AbsolutePosition + Rbx.AbsoluteSize/2
				local Angle = math.deg(math.atan2(MousePosition.Y - Center.Y, MousePosition.X - Center.X)) + 90
				if Angle < 0 then
					Angle += 360
				end

				local Percent = Angle / 360 * 100
				self.SetHighlightedPercent(100 - Percent)
			end
		end,
		[Roact.Event.InputEnded] = function()
			local Percent = self.HighlightedPercent:getValue()
			if Percent == -1 then
				return
			end

			--[[
			for _, Arc in self.props.Arcs do
				if Percent >= Arc.StartPercent and Percent <= Arc.StartPercent + Arc.Percent then
					-- Add future behavior here
					break
				end
			end
			]]

			self.SetHighlightedPercent(-1)
		end,
	}, {
		Left = Roact.createElement("Frame", {
			BackgroundTransparency = 1,
			ClipsDescendants = true,
			Size = UDim2.fromScale(0.5, 1),
		}, {
			Arcs = Roact.createFragment(CircleArcs.Left),
		}),
		Right = Roact.createElement("Frame", {
			AnchorPoint = Vector2.new(1, 0),
			BackgroundTransparency = 1,
			ClipsDescendants = true,
			Position = UDim2.fromScale(1, 0),
			Size = UDim2.fromScale(0.5, 1),
		}, {
			Arcs = Roact.createFragment(CircleArcs.Right),
		})
	})
end

return PacketCircleArcs