--[[VARIABLE DEFINITION ANOMALY DETECTED, DECOMPILATION OUTPUT POTENTIALLY INCORRECT]]--
--[[VARIABLE DEFINITION ANOMALY DETECTED, DECOMPILATION OUTPUT POTENTIALLY INCORRECT]]--
-- Decompiled with the Synapse X Luau decompiler.

local l__HDAdminMain__1 = _G.HDAdminMain;
local l__CmdBar__2 = l__HDAdminMain__1.gui.CmdBar;
local v3 = {
	maxSuggestions = 5, 
	mainParent = l__CmdBar__2, 
	textBox = l__CmdBar__2.SearchFrame.TextBox, 
	rframe = l__CmdBar__2.ResultsFrame, 
	suggestionPos = 1, 
	suggestionDisplayed = 0, 
	forceExecute = false, 
	highlightColor = Color3.fromRGB(50, 50, 50), 
	otherColor = Color3.fromRGB(80, 80, 80), 
	suggestionLabels = {}, 
	currentBarCommand = nil
};
l__CmdBar__2.Visible = false;
local function u1(p1)
	local v4 = nil;
	local v5 = "";
	v4 = p1.suggestionLabels["Label" .. p1.suggestionPos];
	if p1.specificArg then
		local v6 = v4.Name .. " ";
		p1.textBox.Text = v6;
		coroutine.wrap(function()
			for v7 = 1, 10 do
				p1.textBox:ReleaseFocus();
				wait();
			end;
		end)();
		wait();
		p1.textBox.Text = v6;
		return;
	end;
	local v8 = string.sub(p1.textBox.Text, 1, 1);
	local u2 = -1;
	local u3 = {};
	p1.textBox.Text:gsub("([^" .. l__HDAdminMain__1.pdata.SplitKey .. "]+)", function(p2)
		u2 = u2 + 1;
		if v4.ArgPos - 1 < u2 then
			return;
		end;
		table.insert(u3, p2 .. " ");
	end);
	if u2 == 0 and (v8 == l__HDAdminMain__1.settings.UniversalPrefix or v8 == l__HDAdminMain__1.pdata.Prefix) then
		v5 = v8;
	end;
	local v9 = ((v5 .. table.concat(u3, "")) .. v4.Name) .. l__HDAdminMain__1.pdata.SplitKey;
	p1.textBox.Text = v9;
	wait();
	p1.textBox.Text = v9;
	p1.textBox:CaptureFocus();
	p1.textBox.CursorPosition = #v9 + 1;
end;
local u4 = {};
local u5 = {};
local function u6(p3)
	local l__maxSuggestions__10 = p3.maxSuggestions;
	local v11 = 1 - 1;
	while true do
		local v12 = p3.rframe.LabelTemplate:Clone();
		v12.Name = "Label" .. v11;
		v12.Visible = false;
		v12.Parent = p3.rframe;
		local u7 = v11;
		v12.MouseEnter:Connect(function()
			p3.suggestionPos = u7;
		end);
		v12.MouseButton1Up:Connect(function()
			p3.suggestionPos = u7;
			u1(p3);
		end);
		if 0 <= 1 then
			if not (u7 < l__maxSuggestions__10) then
				break;
			end;
		elseif not (l__maxSuggestions__10 < u7) then
			break;
		end;
		u7 = u7 + 1;	
	end;
end;
local function u8(p4)
	p4.textBox.FocusLost:connect(function(p5)
		if p4.mainParent.Name ~= "CmdBar" or p4.specificArg then
			if p4.suggestionDisplayed > 0 then
				u1(p4, p4.specificArg);
				return;
			end;
		else
			if p4.suggestionDisplayed > 0 and not forceExecute and l__HDAdminMain__1.device ~= "Mobile" then
				u1(p4);
				return;
			end;
			if p5 then
				if forceExecute then
					u1(p4);
				end;
				u4:CloseCmdBar();
				if #p4.textBox.Text > 1 then
					local v13 = p4.textBox.Text;
					local v14 = string.sub(v13, 1, 1);
					if v14 ~= l__HDAdminMain__1.settings.UniversalPrefix and v14 ~= l__HDAdminMain__1.pdata.Prefix then
						v13 = l__HDAdminMain__1.pdata.Prefix .. v13;
					end;
					if string.sub(v13, -1) == " " then
						v13 = string.sub(v13, 1, -1);
					end;
					l__HDAdminMain__1.signals.RequestCommand:InvokeServer(v13);
				end;
			end;
		end;
	end);
end;
function u4.SetupTextbox(p6, p7, p8)
	u5[p7] = p8;
	u6(p8);
	u8(p8);
	local l__specificArg__9 = p8.specificArg;
	local function u10(p9, p10, p11, p12)
		if string.sub(string.lower(p12), 1, #p10) == p10 then
			table.insert(p9, {
				Name = p12, 
				ArgPos = p11
			});
			if #p9 ~= p8.maxSuggestions then
				return;
			end;
		else
			return;
		end;
		return true;
	end;
	local u11 = nil;
	p8.textBox.Changed:connect(function(p13)
		if p13 == "Text" then
			local v15 = nil;
			v15 = {};
			if l__specificArg__9 then
				table.insert(v15, p8.textBox.Text);
			else
				local u12 = -1;
				local u13 = nil;
				p8.textBox.Text:gsub("([^" .. l__HDAdminMain__1.pdata.SplitKey .. "]+)", function(p14)
					u12 = u12 + 1;
					if u12 == 0 then
						u13 = p14;
						return;
					end;
					if u12 > 0 then
						table.insert(v15, p14);
					end;
				end);
				if u12 > 0 and not p8.currentBarCommand then
					local v16 = string.sub(u13, 1, 1);
					if v16 == l__HDAdminMain__1.settings.UniversalPrefix or v16 == l__HDAdminMain__1.pdata.Prefix then
						u13 = string.sub(u13, 2);
					end;
					u13 = string.lower(u13);
					for v17, v18 in pairs(l__HDAdminMain__1.commandInfo) do
						if string.lower(v18.Name) == u13 then
							p8.currentBarCommand = v18;
						elseif v18.Aliases then
							for v19, v20 in pairs(v18.Aliases) do
								if string.lower(v20) == u13 then
									p8.currentBarCommand = v18;
								end;
							end;
						end;
					end;
				elseif u12 <= 0 then
					p8.currentBarCommand = nil;
				end;
			end;
			local v21 = {};
			p8.suggestionPos = 1;
			if #p8.textBox.Text > 1 or l__specificArg__9 and #p8.textBox.Text > 0 then
				if u12 == 0 then
					local v22 = string.lower(string.sub(p8.textBox.Text, 2));
					local v23 = string.lower(string.sub(p8.textBox.Text, 1, 1));
					local v24, v25, v26 = pairs(l__HDAdminMain__1.commandInfo);
					while true do
						local v27, v28 = v24(v25, v26);
						if not v27 then
							break;
						end;
						local v29 = v28.Prefixes[1];
						if string.sub(string.lower(v28.Name), 1, #v22) == v22 and v29 == v23 then
							table.insert(v21, {
								Name = v28.Name, 
								Args = v28.Args, 
								Prefixes = v28.Prefixes, 
								ArgPos = 0
							});
							if #v21 == p8.maxSuggestions then
								break;
							end;
						end;
						local l__UnFunction__30 = v28.UnFunction;
						if l__UnFunction__30 and (string.sub(string.lower(l__UnFunction__30), 1, #v22) == v22 and v29 == v23) then
							table.insert(v21, {
								Name = l__UnFunction__30, 
								Args = {}, 
								Prefixes = v28.Prefixes, 
								ArgPos = 0
							});
							if #v21 == p8.maxSuggestions then
								break;
							end;
						end;					
					end;
				elseif p8.currentBarCommand or l__specificArg__9 then
					if l__specificArg__9 then
						local v31 = l__specificArg__9;
					else
						v31 = p8.currentBarCommand.Args[u12];
					end;
					local v32 = {};
					local v33 = string.lower(v15[u12]);
					local v34 = string.sub(p8.textBox.Text, -1);
					if v34 ~= " " and v34 ~= l__HDAdminMain__1.pdata.SplitKey then
						if v31 == "player" or v31 == "playerarg" then
							for v35, v36 in pairs(l__HDAdminMain__1.qualifiers) do
								if u10(v21, v33, u12, v36) then
									break;
								end;
							end;
							if #v21 < p8.maxSuggestions then
								for v37, v38 in pairs(l__HDAdminMain__1.players:GetChildren()) do
									if u10(v21, v33, u12, v38.Name) then
										break;
									end;
								end;
							end;
						elseif v31 == "colour" or v31 == "color" or v31 == "color3" then
							for v39, v40 in pairs(l__HDAdminMain__1.colors) do
								if u10(v21, v33, u12, v40) then
									break;
								end;
							end;
						elseif v31 == "material" then
							for v41, v42 in pairs(l__HDAdminMain__1.materials) do
								if u10(v21, v33, u12, v42) then
									break;
								end;
							end;
						elseif v31 == "rank" then
							for v43, v44 in pairs(l__HDAdminMain__1.settings.Ranks) do
								if u10(v21, v33, u12, v44[2]) then
									break;
								end;
							end;
						elseif v31 == "team" or v31 == "teamcolor" then
							local l__teams__45 = l__HDAdminMain__1.teams;
							local v46, v47, v48 = pairs(l__teams__45.GetChildren(l__teams__45));
							while true do
								local v49, v50 = v46(v47, v48);
								if not v49 then
									break;
								end;
								v48 = v49;
								if u10(v21, v33, u12, v50.Name) then
									break;
								end;							
							end;
						elseif v31 == "morph" then
							local v51, v52, v53 = pairs(l__HDAdminMain__1.morphNames);
							while true do
								local v54, v55 = v51(v52, v53);
								if not v54 then
									break;
								end;
								v53 = v54;
								if u10(v21, v33, u12, v54) then
									break;
								end;							
							end;
						elseif v31 == "tools" or v31 == "gears" or v31 == "tool" or v31 == "gear" then
							local v56, v57, v58 = pairs(l__HDAdminMain__1.toolNames);
							while true do
								local v59, v60 = v56(v57, v58);
								if not v59 then
									break;
								end;
								v58 = v59;
								if u10(v21, v33, u12, v59) then
									break;
								end;							
							end;
						end;
					end;
				end;
			end;
			p8.suggestionDisplayed = #v21;
			if p8.currentBarCommand and #p8.currentBarCommand.Args == u12 and p8.suggestionDisplayed > 0 then
				forceExecute = true;
			else
				forceExecute = false;
			end;
			for v61 = 1, p8.maxSuggestions do
				local v62 = v21[v61];
				local v63 = p8.rframe["Label" .. v61];
				if v62 then
					local v64 = false;
					if v62.Args then
						v64 = true;
					end;
					local v65 = false;
					if v64 and v62.Prefixes[1] == l__HDAdminMain__1.settings.UniversalPrefix then
						v65 = true;
					end;
					local v66 = {};
					if v64 then
						for v67, v68 in pairs(v62.Args) do
							if not v65 or v68 ~= "player" or v68 == "playerarg" then
								table.insert(v66, "<" .. v68 .. ">");
							end;
						end;
					end;
					v63.TextLabel.Text = v62.Name .. " " .. table.concat(v66, " ");
					if v61 == p8.suggestionPos then
						v63.BackgroundColor3 = p8.highlightColor;
					else
						v63.BackgroundColor3 = p8.otherColor;
					end;
					p8.suggestionLabels["Label" .. v61] = v62;
					if p8.mainParent.Name ~= "CmdBar" then
						local l__Y__69 = p8.rframe.LabelTemplate.AbsoluteSize.Y;
						if l__HDAdminMain__1.gui.Notices.AbsoluteSize.Y < p8.rframe.AbsolutePosition.Y + l__Y__69 * v61 + 5 then
							if not u11 then
								u11 = p8.mainParent.Position;
							end;
							p8.mainParent.Position = p8.mainParent.Position - UDim2.new(0, 0, 0, l__Y__69);
						end;
					end;
					v63.Visible = true;
				else
					v63.Visible = false;
				end;
			end;
			if u11 and #v21 < 1 then
				p8.mainParent.Position = u11;
				u11 = nil;
			end;
			if #v21 < 1 and p8.mainParent.Name ~= "CmdBar" then
				p8.mainParent.ClipsDescendants = true;
			else
				p8.mainParent.ClipsDescendants = false;
			end;
		end;
	end);
end;
u4:SetupTextbox("cmdbar1", v3);
function u4.ToggleBar(p15, p16)
	if p16 == Enum.KeyCode.Quote then
		if l__HDAdminMain__1.gui.CmdBar.Visible then
			l__HDAdminMain__1:GetModule("CmdBar"):CloseCmdBar();
			return;
		else
			l__HDAdminMain__1:GetModule("CmdBar"):OpenCmdBar();
			return;
		end;
	end;
	if p16 == Enum.KeyCode.Semicolon then
		local l__Cmdbar2__70 = l__HDAdminMain__1.settings.Cmdbar2;
		if l__HDAdminMain__1.pdata.Rank > 0 or l__Cmdbar2__70 <= 0 then
			if l__HDAdminMain__1.pdata.Rank < l__Cmdbar2__70 then
				local v71 = l__HDAdminMain__1:GetModule("cf"):FormatNotice("CommandBarLocked", "2", l__HDAdminMain__1:GetModule("cf"):GetRankName(l__Cmdbar2__70));
				l__HDAdminMain__1:GetModule("Notices"):Notice("Error", v71[1], v71[2]);
				return;
			end;
			local l__cmdbar2__72 = u5.cmdbar2;
			if not l__cmdbar2__72 then
				l__HDAdminMain__1:GetModule("ClientCommands").cmdbar2.Function();
				return;
			end;
			if l__cmdbar2__72.mainParent.Visible then
				l__cmdbar2__72.mainParent.Visible = false;
				return;
			end;
			l__cmdbar2__72.mainParent.Visible = true;
		end;
	end;
end;
local u14 = { "Chat", "PlayerList" };
local u15 = {};
local l__CustomTopBar__16 = l__HDAdminMain__1.gui.CustomTopBar;
local u17 = 1;
local u18 = true;
function u4.OpenCmdBar(p17)
	local l__Cmdbar__73 = l__HDAdminMain__1.settings.Cmdbar;
	if l__HDAdminMain__1.pdata.Rank > 0 or l__Cmdbar__73 <= 0 then
		if l__HDAdminMain__1.pdata.Rank < l__Cmdbar__73 then
			local v74 = l__HDAdminMain__1:GetModule("cf"):FormatNotice("CommandBarLocked", "", l__HDAdminMain__1:GetModule("cf"):GetRankName(l__Cmdbar__73));
			l__HDAdminMain__1:GetModule("Notices"):Notice("Error", v74[1], v74[2]);
			return;
		end;
		v3.textBox:CaptureFocus();
		for v75, v76 in pairs(u14) do
			u15[v76] = l__HDAdminMain__1.starterGui:GetCoreGuiEnabled(v76);
			l__HDAdminMain__1.starterGui:SetCoreGuiEnabled(Enum.CoreGuiType[v76], false);
		end;
		l__CustomTopBar__16.BackgroundColor3 = Color3.fromRGB(50, 50, 50);
		u17 = l__CustomTopBar__16.BackgroundTransparency;
		u18 = l__CustomTopBar__16.Visible;
		l__CustomTopBar__16.BackgroundTransparency = 0;
		l__CustomTopBar__16.Visible = true;
		v3.textBox.Text = "";
		l__CmdBar__2.Visible = true;
		wait();
		v3.textBox.Text = l__HDAdminMain__1.pdata.Prefix;
		v3.textBox.CursorPosition = 3;
	end;
end;
function u4.CloseCmdBar(p18)
	l__CmdBar__2.Visible = false;
	for v77, v78 in pairs(u14) do
		local v79 = u15[v78];
		if v79 then
			l__HDAdminMain__1.starterGui:SetCoreGuiEnabled(Enum.CoreGuiType[v78], v79);
		end;
	end;
	l__CustomTopBar__16.BackgroundColor3 = Color3.fromRGB(31, 31, 31);
	l__CustomTopBar__16.BackgroundTransparency = u17;
	l__CustomTopBar__16.Visible = u18;
	coroutine.wrap(function()
		for v80 = 1, 10 do
			v3.textBox:ReleaseFocus();
			wait();
		end;
	end)();
end;
function u4.PressedArrowKey(p19, p20)
	for v81, v82 in pairs(u5) do
		if v82.mainParent.Visible and v82.textBox:IsFocused() then
			local v83 = v82.rframe:FindFirstChild("Label" .. v82.suggestionPos);
			if p20 == Enum.KeyCode.Down then
				v82.suggestionPos = v82.suggestionPos + 1;
				if v82.suggestionDisplayed < v82.suggestionPos then
					v82.suggestionPos = 1;
				end;
			elseif p20 == Enum.KeyCode.Up then
				v82.suggestionPos = v82.suggestionPos - 1;
				if v82.suggestionPos < 1 then
					v82.suggestionPos = v82.suggestionDisplayed;
				end;
			elseif p20 == Enum.KeyCode.Right then
				u1(v82);
			end;
			local v84 = v82.rframe["Label" .. v82.suggestionPos];
			if v84 ~= v83 then
				v83.BackgroundColor3 = v82.otherColor;
				v84.BackgroundColor3 = v82.highlightColor;
			end;
		end;
	end;
end;
return u4;