local K=script:WaitForChild("\109\111\100\117\108\101\115")local r=(script.Parent:FindFirstChild("\076\111\097\100\101\114\085\116\105\108\115",true)).Parent local A=(require(r)).bootstrapPlugin(K)local a=game:GetService("\067\111\114\101\071\117\105")local W=game:GetService("\083\101\108\101\099\116\105\111\110")local Z=A("\067\111\109\109\097\110\100\080\097\108\101\116\116\101")local H=A("\067\111\109\109\097\110\100\080\097\108\101\116\116\101\067\111\110\115\116\097\110\116\115")local d=A("\077\097\105\100")local R local function N(K)local r=d.new()local A=Instance.new("\083\099\114\101\101\110\071\117\105")A.Name="\067\111\109\109\097\110\100\080\097\108\101\116\116\101"A.ZIndexBehavior=Enum.ZIndexBehavior.Sibling A.Parent=a r:GiveTask(A)local W=Z.new(K)r:GiveTask(W)r:GiveTask((W:Render({Parent=A})):Subscribe(function()W:SetInputFocused(true)end))W:Show()return r,W end local function j(K,r)if not r then return end R=nil r:Hide()task.delay(.3,function()K:Destroy()end)end local function u(K)local r=d.new()local A=K:CreatePluginAction("\091\067\111\109\109\097\110\100 \080\097\108\101\116\116\101\093 \079\112\101\110","\091\067\111\109\109\097\110\100 \080\097\108\101\116\116\101\093 \079\112\101\110","\079\112\101\110 \116\104\101 \067\111\109\109\097\110\100 \080\097\108\101\116\116\101 \111\110 \116\104\101 \099\117\114\114\101\110\116\108\121 \115\101\108\101\099\116\101\100 \105\110\115\116\097\110\099\101\046",H.PLUGIN_ICON,true)r:GiveTask(A.Triggered:Connect(function()if R then j(R)else local K=W:Get()if not K then print("\091\067\111\109\109\097\110\100\080\097\108\101\116\116\101\093 \080\108\101\097\115\101 \115\101\108\101\099\116 \097\110 \105\110\115\116\097\110\099\101\033")return end local A,a=N(K[1])R=a r._current=A A:GiveTask(a.EscapePressed:Connect(function()j(A,a)end))end end))r:GiveTask(K.Unloading:Connect(function()r:Destroy()end))return r end if plugin then u(plugin)end
local modules = script:WaitForChild("modules")
local loader = script.Parent:FindFirstChild("LoaderUtils", true).Parent

local require = require(loader).bootstrapPlugin(modules)

local CoreGui = game:GetService("CoreGui")
local Selection = game:GetService("Selection")

local CommandPalette = require("CommandPalette")
local CommandPaletteConstants = require("CommandPaletteConstants")
local Maid = require("Maid")

local currentPalette

local function renderPalette(targetInstance)
	local maid = Maid.new()

	local screenGui = Instance.new("ScreenGui")
	screenGui.Name = "CommandPalette"
	screenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
	screenGui.Parent = CoreGui
	maid:GiveTask(screenGui)

	local cmdPalette = CommandPalette.new(targetInstance)
	maid:GiveTask(cmdPalette)

	maid:GiveTask(cmdPalette:Render({
		Parent = screenGui;
	}):Subscribe(function()
		cmdPalette:SetInputFocused(true)
	end))

	cmdPalette:Show()

	return maid, cmdPalette
end

local function cleanup(maid, palette)
	if not palette then
		return
	end

	currentPalette = nil

	palette:Hide()

	task.delay(0.3, function()
		maid:Destroy()
	end)
end

local function initialize(plugin)
	local maid = Maid.new()

	local macro = plugin:CreatePluginAction(
		"[Command Palette] Open",
		"[Command Palette] Open",
		"Open the Command Palette on the currently selected instance.",
		CommandPaletteConstants.PLUGIN_ICON,
		true
	)

	maid:GiveTask(macro.Triggered:Connect(function()
		if currentPalette then
			cleanup(currentPalette)
		else
			local selection = Selection:Get()
			if not selection then
				print("[CommandPalette] Please select an instance!")
				return
			end

			local paletteMaid, palette = renderPalette(selection[1])

			currentPalette = palette
			maid._current = paletteMaid

			paletteMaid:GiveTask(palette.EscapePressed:Connect(function()
				cleanup(paletteMaid, palette)
			end))
		end
	end))

	maid:GiveTask(plugin.Unloading:Connect(function()
		maid:Destroy()
	end))

	return maid
end

if plugin then
	initialize(plugin)
end