local j=(require(script.Parent.loader)).load(script)local E=j("\066\097\115\105\099\080\097\110\101")local T=j("\066\097\115\105\099\080\097\110\101\085\116\105\108\115")local e=j("\066\108\101\110\100")local q=j("\070\105\108\116\101\114\101\100\079\098\115\101\114\118\097\098\108\101\076\105\115\116\086\105\101\119")local p=j("\079\098\115\101\114\118\097\098\108\101\076\105\115\116")local o=j("\082\101\115\117\108\116\069\110\116\114\121")local B=j("\082\120")local x=j("\082\120\066\114\105\111\085\116\105\108\115")local G=j("\086\097\108\117\101\079\098\106\101\099\116")local f=setmetatable({},E)f.ClassName="\067\111\109\109\097\110\100\080\097\108\101\116\116\101\082\101\115\117\108\116\115"f.__index=f function f.new()local j=setmetatable(E.new(),f)j._percentVisibleTarget=G.new(0)j._maid:GiveTask(j._percentVisibleTarget)j._size=G.new(Vector2.new())j._maid:GiveTask(j._size)j._contentHeight=G.new(0)j._maid:GiveTask(j._contentHeight)j._results=p.new()j._maid:GiveTask(j._results)j._filteredResults=q.new(j._results,f._observeScore)j._maid:GiveTask(j._filteredResults)j._maid:GiveTask(j.VisibleChanged:Connect(function(E)j._percentVisibleTarget.Value=E and 1 or 0 end))return j end function f.GetResults(j)return j._results:GetList()end function f.ObserveResultsBrio(j)return j._results:ObserveItemsBrio()end function f.SetCurrentProperties(T,j,E)for E,e in E do local q=e:GetName()local p=j[q]local B=o.new()B:SetDataType((e:GetRawData()).ValueType.Category,typeof(p))B:SetPropertyName(q)B:SetPropertyValue(p)T._maid:GiveTask(B)T._results:Add(B)end end function f.ObserveSize(j)return j._size:Observe()end function f._observeScore(j)return j:ObserveScore()end function f.Render(j)local E=e.Spring((e.toPropertyObservable(j._percentVisibleTarget)):Pipe({B.startWith({0})}),35,1)local q=e.AccelTween((e.toPropertyObservable(j._percentVisibleTarget)):Pipe({B.startWith({0})}),400)local p=e.Computed(q,function(j)return 1-j end)j._maid:GiveTask((e.Computed(E,function(E)local T=j._results:GetList()local e=#T for j,T in T do local q=(j-1)/e+1e-05 T:SetVisible(q<=E)end end)):Subscribe())return(e.New("\070\114\097\109\101"))({Name="\067\111\109\109\097\110\100\080\097\108\101\116\116\101\082\101\115\117\108\116\115";BackgroundTransparency=1;Position=UDim2.fromScale(0,.26);Size=e.Computed(E,function(j)return UDim2.fromScale(1,j*.74)end);[e.OnChange("\065\098\115\111\108\117\116\101\083\105\122\101")]=function(E)j._size.Value=E end;[e.Children]={(e.New("\070\114\097\109\101"))({Name="\099\111\110\116\097\105\110\101\114",Size=UDim2.fromScale(1,1),BackgroundTransparency=1,ZIndex=2,[e.Children]={(e.New("\085\073\080\097\100\100\105\110\103"))({PaddingBottom=UDim.new(.040541,0),PaddingLeft=UDim.new(.01875,0),PaddingRight=UDim.new(.01875,0);PaddingTop=UDim.new(.040541,0)});(e.New("\070\114\097\109\101"))({Name="\115\101\108\101\099\116\105\111\110\066\097\099\107\105\110\103",Size=UDim2.new(1,0,0,50),BackgroundColor3=Color3.fromRGB(50,50,50);BackgroundTransparency=e.Computed(p,function(j)return 1-(1-j)*.3 end),[e.Children]={(e.New("\085\073\067\111\114\110\101\114"))({CornerRadius=UDim.new(.177778,0)})}}),(e.New("\083\099\114\111\108\108\105\110\103\070\114\097\109\101"))({Name="\099\111\110\116\101\110\116\115";Active=true;BackgroundTransparency=1,BottomImage="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\117\105\047\083\099\114\111\108\108\047\115\099\114\111\108\108-\109\105\100\100\108\101\046\112\110\103";ScrollBarImageColor3=Color3.fromRGB(175,175,175);ScrollBarImageTransparency=p;ScrollBarThickness=5;ScrollingDirection=Enum.ScrollingDirection.Y,ScrollingEnabled=T.observeVisible(j);Size=UDim2.fromScale(1,1),TopImage="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\117\105\047\083\099\114\111\108\108\047\115\099\114\111\108\108-\109\105\100\100\108\101\046\112\110\103";ZIndex=3,CanvasSize=e.Computed(j._contentHeight,function(j)return UDim2.fromOffset(0,j)end),[e.Children]={(e.New("\085\073\076\105\115\116\076\097\121\111\117\116"))({HorizontalAlignment=Enum.HorizontalAlignment.Center;Padding=UDim.new(.021,0)});(j._filteredResults:ObserveItemsBrio()):Pipe({x.map(function(j)return j:Render()end)})}})}})}})end return f
local require = require(script.Parent.loader).load(script)

local BasicPane = require("BasicPane")
local BasicPaneUtils = require("BasicPaneUtils")
local Blend = require("Blend")
local FilteredObservableListView = require("FilteredObservableListView")
local ObservableList = require("ObservableList")
local ResultEntry = require("ResultEntry")
local Rx = require("Rx")
local RxBrioUtils = require("RxBrioUtils")
local ValueObject = require("ValueObject")

local CommandPaletteResults = setmetatable({}, BasicPane)
CommandPaletteResults.ClassName = "CommandPaletteResults"
CommandPaletteResults.__index = CommandPaletteResults

function CommandPaletteResults.new()
	local self = setmetatable(BasicPane.new(), CommandPaletteResults)

	self._percentVisibleTarget = ValueObject.new(0)
	self._maid:GiveTask(self._percentVisibleTarget)

	self._size = ValueObject.new(Vector2.new())
	self._maid:GiveTask(self._size)

	self._contentHeight = ValueObject.new(0)
	self._maid:GiveTask(self._contentHeight)

	self._results = ObservableList.new()
	self._maid:GiveTask(self._results)

	self._filteredResults = FilteredObservableListView.new(self._results, CommandPaletteResults._observeScore)
	self._maid:GiveTask(self._filteredResults)

	self._maid:GiveTask(self.VisibleChanged:Connect(function(isVisible)
		self._percentVisibleTarget.Value = isVisible and 1 or 0
	end))

	return self
end

function CommandPaletteResults:GetResults()
	return self._results:GetList()
end

function CommandPaletteResults:ObserveResultsBrio()
	return self._results:ObserveItemsBrio()
end

function CommandPaletteResults:SetCurrentProperties(targetInstance, properties)
	for _, member in properties do
		local propertyName = member:GetName()
		local propertyValue = targetInstance[propertyName]

		local entry = ResultEntry.new()
		entry:SetDataType(member:GetRawData().ValueType.Category, typeof(propertyValue))
		entry:SetPropertyName(propertyName)
		entry:SetPropertyValue(propertyValue)
		self._maid:GiveTask(entry)

		self._results:Add(entry)
	end
end

function CommandPaletteResults:ObserveSize()
	return self._size:Observe()
end

function CommandPaletteResults._observeScore(entry)
	return entry:ObserveScore()
end

function CommandPaletteResults:Render()
	local percentVisible = Blend.Spring(Blend.toPropertyObservable(self._percentVisibleTarget):Pipe({
		Rx.startWith({0})
	}), 35, 1)

	local percentAlpha = Blend.AccelTween(Blend.toPropertyObservable(self._percentVisibleTarget):Pipe({
		Rx.startWith({0})
	}), 400)

	local transparency = Blend.Computed(percentAlpha, function(percent)
		return 1 - percent
	end)

	self._maid:GiveTask(Blend.Computed(percentVisible, function(percent)
		local results = self._results:GetList()
		local itemCount = #results

		for index, entry in results do
			local progress = (index - 1) / itemCount + 1e-5
			entry:SetVisible(progress <= percent)
		end
	end):Subscribe())

	return Blend.New "Frame" {
		Name = "CommandPaletteResults";
		BackgroundTransparency = 1;
		Position = UDim2.fromScale(0, 0.26);

		Size = Blend.Computed(percentVisible, function(percent)
			return UDim2.fromScale(1, percent * 0.74);
		end);

		[Blend.OnChange "AbsoluteSize"] = function(absoluteSize)
			self._size.Value = absoluteSize
		end;

		[Blend.Children] = {
			Blend.New "Frame" {
				Name = "container";
				Size = UDim2.fromScale(1, 1);
				BackgroundTransparency = 1;
				ZIndex = 2;

				[Blend.Children] = {
					Blend.New "UIPadding" {
						PaddingBottom = UDim.new(0.040541, 0);
						PaddingLeft = UDim.new(0.01875, 0);
						PaddingRight = UDim.new(0.01875, 0);
						PaddingTop = UDim.new(0.040541, 0);
					};

					Blend.New "Frame" {
						Name = "selectionBacking";
						Size = UDim2.new(1, 0, 0, 50);
						BackgroundColor3 = Color3.fromRGB(50, 50, 50);

						BackgroundTransparency = Blend.Computed(transparency, function(percent)
							return 1 - ((1 - percent) * 0.3)
						end);

						[Blend.Children] = {
							Blend.New "UICorner" {
								CornerRadius = UDim.new(0.177778, 0);
							};
						};
					};

					Blend.New "ScrollingFrame" {
						Name = "contents";
						Active = true;
						BackgroundTransparency = 1;
						BottomImage = "rbxasset://textures/ui/Scroll/scroll-middle.png";
						ScrollBarImageColor3 = Color3.fromRGB(175, 175, 175);
						ScrollBarImageTransparency = transparency;
						ScrollBarThickness = 5;
						ScrollingDirection = Enum.ScrollingDirection.Y;
						ScrollingEnabled = BasicPaneUtils.observeVisible(self);
						Size = UDim2.fromScale(1, 1);
						TopImage = "rbxasset://textures/ui/Scroll/scroll-middle.png";
						ZIndex = 3;

						CanvasSize = Blend.Computed(self._contentHeight, function(height)
							return UDim2.fromOffset(0, height)
						end);

						[Blend.Children] = {
							Blend.New "UIListLayout" {
								HorizontalAlignment = Enum.HorizontalAlignment.Center;
								Padding = UDim.new(0.021, 0);

								-- [Blend.OnChange "AbsoluteContentSize"] = function(contentSize)
								-- 	self._contentHeight.Value = contentSize.Y
								-- end;
							};

							self._filteredResults:ObserveItemsBrio():Pipe({
								RxBrioUtils.map(function(entry)
									return entry:Render()
								end)
							})
						};
					};
				};
			};
		};
	}
end

return CommandPaletteResults