local M=game:GetService("\084\101\120\116\083\101\114\118\105\099\101")local B=game:GetService("\082\117\110\083\101\114\118\105\099\101")local f=script.Parent.Parent local e=f.Modules local D=require(e.Packages)local A=require(D.Directory.Roact)local n=10 local H=not B:IsRunning()local function b(M)return A.createElement("\084\101\120\116\066\117\116\116\111\110",{AutoLocalize=false;Text=M.ButtonName;TextXAlignment=Enum.TextXAlignment.Right;TextYAlignment=Enum.TextYAlignment.Center,Font=Enum.Font.Code,TextColor3=M.Theme.Name=="\076\105\103\104\116"and Color3.new(0,0,0)or Color3.new(1,1,1);TextSize=n+2;BackgroundColor3=M.Theme:GetColor("\083\099\114\111\108\108\066\097\114\066\097\099\107\103\114\111\117\110\100"),Size=M.Size;BorderSizePixel=0;[A.Event.Activated]=M.OnClick})end local d=A.Component:extend("\084\111\112\098\097\114\066\117\116\116\111\110\115\071\114\111\117\112")function d.init(M)M.MouseHovering,M.SetMouseHovering=A.createBinding(0)M.TopbarRef=A.createRef()end function d.render(B)local f=B.props local e={}local D=M:GetTextSize(f.Text,n+2,Enum.Font.Code,Vector2.new(10000,n+1))local d=D.X for B,f in f.Options do local e=M:GetTextSize(f.Name,n+1,Enum.Font.Code,Vector2.new(10000,n+1))d=math.max(d,e.X)end for M,B in f.Options do table.insert(e,b({ButtonName=B.Name,OnClick=B.Callback,Theme=f.Theme;Size=UDim2.fromOffset(d,n+1)}))end return A.createElement("\084\101\120\116\076\097\098\101\108",{AutoLocalize=false;Text=f.Text;TextColor3=f.Theme.Name=="\076\105\103\104\116"and Color3.new(0,0,0)or Color3.new(1,1,1);BackgroundColor3=B.MouseHovering:map(function(M)return M>0 and f.Theme:GetColor("\076\105\103\104\116")or f.Theme:GetColor("\083\099\114\111\108\108\066\097\114\066\097\099\107\103\114\111\117\110\100")end);TextSize=n+2;Font=Enum.Font.Code;BorderSizePixel=0;Size=UDim2.fromOffset(D.X,n);TextXAlignment=Enum.TextXAlignment.Left;TextYAlignment=Enum.TextYAlignment.Center,LayoutOrder=f.LayoutOrder;Visible=not H,[A.Event.MouseEnter]=function()B.SetMouseHovering(1)end,[A.Event.MouseLeave]=function()task.defer(function()if B.MouseHovering:getValue()==1 then B.SetMouseHovering(0)end end)end,[A.Ref]=B.TopbarRef},{OptionsHolder=A.createElement("\070\114\097\109\101",{AutomaticSize=Enum.AutomaticSize.Y;BackgroundTransparency=1,Visible=B.MouseHovering:map(function(M)return M>0 end);Position=UDim2.fromOffset(0,n),[A.Event.MouseEnter]=function()B.SetMouseHovering(2)end;[A.Event.MouseLeave]=function()task.defer(function()if B.MouseHovering:getValue()==2 then B.SetMouseHovering(0)end end)end;Size=UDim2.fromOffset(d,0)},{OptionsListLayout=A.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{FillDirection=Enum.FillDirection.Vertical,HorizontalAlignment=Enum.HorizontalAlignment.Left;VerticalAlignment=Enum.VerticalAlignment.Top});Buttons=A.createFragment(e)})})end return d
local TextService = game:GetService("TextService")
local RunService = game:GetService("RunService")

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

local Roact = require(Packages.Directory.Roact)

local TOPBAR_HEIGHT = 10
local IsEditMode = not RunService:IsRunning()

local function TopbarOptionsButton(props)
	return Roact.createElement("TextButton", {
		AutoLocalize = false,
		Text = props.ButtonName,
		TextXAlignment = Enum.TextXAlignment.Right,
		TextYAlignment = Enum.TextYAlignment.Center,
		Font = Enum.Font.Code,
		TextColor3 = props.Theme.Name == "Light" and Color3.new(0, 0, 0) or Color3.new(1, 1, 1),
		TextSize = TOPBAR_HEIGHT + 2,
		BackgroundColor3 = props.Theme:GetColor("ScrollBarBackground"),
		Size = props.Size,
		BorderSizePixel = 0,
		[Roact.Event.Activated] = props.OnClick,
	})
end

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

function TopbarButtonsGroup:init()
	self.MouseHovering, self.SetMouseHovering = Roact.createBinding(0)
	self.TopbarRef = Roact.createRef()
end

function TopbarButtonsGroup:render()
	local props = self.props
	local Buttons = {}

	local ButtonGroupTextSize = TextService:GetTextSize(props.Text, TOPBAR_HEIGHT + 2, Enum.Font.Code, Vector2.new(10000, TOPBAR_HEIGHT + 1))
	local LongestButtonWidth = ButtonGroupTextSize.X
	for _, Data in props.Options do
		local ButtonTextSize = TextService:GetTextSize(Data.Name, TOPBAR_HEIGHT + 1, Enum.Font.Code, Vector2.new(10000, TOPBAR_HEIGHT + 1))
		LongestButtonWidth = math.max(LongestButtonWidth, ButtonTextSize.X)
	end

	for _, Data in props.Options do
		table.insert(Buttons, TopbarOptionsButton({
			ButtonName = Data.Name,
			OnClick = Data.Callback,
			Theme = props.Theme,
			Size = UDim2.fromOffset(LongestButtonWidth, TOPBAR_HEIGHT + 1),
		}))
	end

	return Roact.createElement("TextLabel", {
		AutoLocalize = false,
		Text = props.Text,
		TextColor3 = props.Theme.Name == "Light" and Color3.new(0, 0, 0) or Color3.new(1, 1, 1),
		BackgroundColor3 = self.MouseHovering:map(function(VisibleIndex)
			return VisibleIndex > 0 and props.Theme:GetColor("Light") or props.Theme:GetColor("ScrollBarBackground")
		end),
		TextSize = TOPBAR_HEIGHT + 2,
		Font = Enum.Font.Code,
		BorderSizePixel = 0,
		Size = UDim2.fromOffset(ButtonGroupTextSize.X, TOPBAR_HEIGHT),
		TextXAlignment = Enum.TextXAlignment.Left,
		TextYAlignment = Enum.TextYAlignment.Center,
		LayoutOrder = props.LayoutOrder,
		Visible = not IsEditMode,
		[Roact.Event.MouseEnter] = function()
			self.SetMouseHovering(1)
		end,
		[Roact.Event.MouseLeave] = function()
			task.defer(function()
				if self.MouseHovering:getValue() == 1 then
					self.SetMouseHovering(0)
				end
			end)
		end,
		[Roact.Ref] = self.TopbarRef,
	}, {
		OptionsHolder = Roact.createElement("Frame", {
			AutomaticSize = Enum.AutomaticSize.Y,
			BackgroundTransparency = 1,
			Visible = self.MouseHovering:map(function(VisibleIndex)
				return VisibleIndex > 0
			end),
			Position = UDim2.fromOffset(0, TOPBAR_HEIGHT),
			[Roact.Event.MouseEnter] = function()
				self.SetMouseHovering(2)
			end,
			[Roact.Event.MouseLeave] = function()
				task.defer(function()
					if self.MouseHovering:getValue() == 2 then
						self.SetMouseHovering(0)
					end
				end)
			end,
			Size = UDim2.fromOffset(LongestButtonWidth, 0),
		}, {
			OptionsListLayout = Roact.createElement("UIListLayout", {
				FillDirection = Enum.FillDirection.Vertical,
				HorizontalAlignment = Enum.HorizontalAlignment.Left,
				VerticalAlignment = Enum.VerticalAlignment.Top,
			}),
			Buttons = Roact.createFragment(Buttons),
		})
	})
end

return TopbarButtonsGroup