local function V()costume=Costume.new(bodyFrame.Costume)maid.PageMaid:GiveTask(costume)maid.PageMaid:GiveTask(costume.Delete:Connect(function(V)promptOverlay:PromptConfirm({Title="\068\101\108\101\116\101 \116\104\105\115 \111\117\116\102\105\116\063",Text="\065\114\101 \121\111\117 \115\117\114\101 \121\111\117 \119\097\110\116 \116\111 \100\101\108\101\116\101 \116\104\105\115 \111\117\116\102\105\116\063"},function()remoteEvent:FireServer("\100\101\108\101\116\101",V)end)end))maid.PageMaid:GiveTask(costume.Wear:Connect(function(V)remoteEvent:FireServer("\119\101\097\114",V)end))maid.PageMaid:GiveTask(function()costume=nil end)end local function B()config=Config.new(bodyFrame.Settings)maid.PageMaid:GiveTask(config)maid.PageMaid:GiveTask(function()config=nil end)end local function I()colorList=ColorList.new(bodyFrame.Appearance.SkinTone,Colors,Wearing:GetTone())maid.PageMaid:GiveTask(colorList)maid.PageMaid:GiveTask(colorList.ItemSelected:Connect(function(V)remoteEvent:FireServer("\116\111\110\101",V)end))scale=Scale.new(bodyFrame.Appearance.Scale,Wearing:GetScale())maid.PageMaid:GiveTask(scale)maid.PageMaid:GiveTask(scale.ScaleUpdated:Connect(function(V,B)remoteEvent:FireServer("\115\099\097\108\101",V,B)end))maid.PageMaid:GiveTask(function()colorList=nil scale=nil end)end local function b(V)return V.LayoutOrder==categoryPageIndex end local function K(V)return searchState.assetType==QueryMap.AssetType[V.Name]end local function D(V,B)for V,I in ipairs(V)do I.ColorSpring.Target=B(I.Button)and 1 or 0 end end local function J(V)subcategoryPageIndex=V.LayoutOrder searchState.search=""searchState.assetType=QueryMap.AssetType[V.Name]searchState.wearing=false search.Frame.TextBox.Text=searchState.search end local function W(V)for V,B in ipairs(V:GetChildren())do if not B:IsA("\071\117\105\066\117\116\116\111\110")then continue end if B.LayoutOrder==subcategoryPageIndex then J(B)end local I=TabButton.new(B,function(V)if searchState.assetType==QueryMap.AssetType[B.Name]then return end J(B)D(subcategoryButtons,K)catalogList:Update(true)end)table.insert(subcategoryButtons,I)end maid.PageMaid.SubPage:GiveTask(function()for V,B in ipairs(subcategoryButtons)do B:Destroy()end table.clear(subcategoryButtons)end)D(subcategoryButtons,K)end local function g()maid.PageMaid.SubPage:DoCleaning()local V=subcategoryPageLayout.CurrentPage categoryPageIndex=V.LayoutOrder D(categoryButtons,b)searchState.search=""searchState.assetType=0 searchState.wearing=false search.Frame.TextBox.Text=searchState.search if categoryPageIndex==4 then searchState.wearing=true else W(V)end catalogList:Update(true)end local function j()maid.PageMaid.SubPage=Maid.new()for V,B in ipairs(mainHeader.CategoryTabs:GetChildren())do if not B:IsA("\071\117\105\066\117\116\116\111\110")then continue end local I=TabButton.new(B,function(V)subcategoryPageIndex=0 subcategoryPageLayout:JumpToIndex(B.LayoutOrder)end)table.insert(categoryButtons,I)end g()maid.PageMaid:GiveTask((subcategoryPageLayout:GetPropertyChangedSignal("\067\117\114\114\101\110\116\080\097\103\101")):Connect(g))maid.PageMaid:GiveTask(function()for V,B in ipairs(categoryButtons)do B:Destroy()end table.clear(categoryButtons)end)end local function Z()maid.PageMaid:DoCleaning()local b=bodyPageLayout.CurrentPage bodyPageIndex=b.LayoutOrder local K=string.lower(b.Name)if K=="\109\097\105\110"then j()elseif K=="\115\101\116\116\105\110\103\115"then B()catalogList:Update(true)elseif K=="\097\112\112\101\097\114\097\110\099\101"then I()catalogList:Update(true)elseif K=="\099\111\115\116\117\109\101"then V()catalogList:Update(true)end end local function y(V)if bodyPageIndex==V.LayoutOrder then bodyPageLayout:JumpToIndex(1)else bodyPageLayout:JumpTo(V)end end local function Q()maid:DoCleaning()local V=UserCanUse:CanUse(player)if not V then module.PermissionFailed:Fire()return end module.Started:Fire()maid.PageMaid=Maid.new()Theme:Set((player:WaitForChild("\065\069\095\083\101\116\116\105\110\103\115")):GetAttribute("\084\104\101\109\101"))maid:GiveTask(Theme:Bind(editorFrame,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\080\114\105\109\097\114\121"))maid:GiveTask(Theme:Bind(footer,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\083\101\099\111\110\100\097\114\121"))maid:GiveTask(Theme:Bind(footer.Appearance,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(footer.Appearance.Icon,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))maid:GiveTask(Theme:Bind(footer.Costume,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(footer.Costume.Icon,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))maid:GiveTask(Theme:Bind(footer.Settings,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(footer.Reset,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\082\101\115\101\116"))maid:GiveTask(Theme:Bind(footer.Version,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))maid:GiveTask(Theme:Bind(mainHeader,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\083\101\099\111\110\100\097\114\121"))for V,B in ipairs(mainHeader.CategoryTabs:GetChildren())do if not B:IsA("\071\117\105\066\117\116\116\111\110")then continue end maid:GiveTask(Theme:Bind(B,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(B,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))maid:GiveTask(Theme:Bind(B.Icon,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))end maid:GiveTask(Theme:Bind(mainHeader.Search,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(mainHeader.Search.Icon,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))maid:GiveTask(Theme:Bind(mainHeader.Search.TextBox,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))maid:GiveTask(Theme:Bind(mainHeader.Search.TextBox,"\080\108\097\099\101\104\111\108\100\101\114\067\111\108\111\114\051","\080\108\097\099\101\104\111\108\100\101\114\084\101\120\116"))maid:GiveTask(Theme:Bind(mainHeader.Search.Clear,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(mainHeader.Search.Clear,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))for V,B in ipairs(mainHeader.SubTabs:GetChildren())do if not B:IsA("\070\114\097\109\101")then continue end for V,B in ipairs(B:GetChildren())do if not B:IsA("\071\117\105\066\117\116\116\111\110")then continue end maid:GiveTask(Theme:Bind(B,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(B,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))maid:GiveTask(Theme:Bind(B.Icon,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))end end maid:GiveTask(Theme:Bind(expandButton,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))maid:GiveTask(Theme:Bind(expandButton.Icon,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))maid:GiveTask(Theme:Bind(viewportFrame.Footer.Save,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\083\097\118\101"))maid:GiveTask(Theme:Bind(viewportFrame.Footer.Save.Icon,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))bodyPageLayout:JumpToIndex(0)tweenSpring.Target=1 promptOverlay=PromptOverlay.new(mainGui.Overlay)maid:GiveTask(promptOverlay)search=Search.new(mainHeader.Search,searchState)maid:GiveTask(search)catalogList=CatalogList.new(mainContainer.ScrollingFrame,CatalogData,Wearing:Get(),searchState)maid:GiveTask(catalogList)maid:GiveTask(catalogList.ViewDetails:Connect(function(V)promptOverlay:PromptPurchase(V.id)end))maid:GiveTask(catalogList.ItemSelected:Connect(function(V,B)if not B then local B=QueryMap.GetOptionName("\065\115\115\101\116\084\121\112\101",V.assetType)if string.find(B,"\065\099\099\101\115\115\111\114\121")or B=="\072\097\116"then local V=player.Character local B=V and V:FindFirstChildWhichIsA("\072\117\109\097\110\111\105\100")if not B or not(B.Health>0)then return end if#B:GetAccessories()>=Settings.MAX_ACCESSORIES then return end end end remoteEvent:FireServer("\097\099\099\101\115\115\111\114\121",V.id)end))maid:GiveTask(search.SearchChanged:Connect(function()catalogList:Update(true)end))maid:GiveTask(footer.Reset.Activated:Connect(function(V)remoteEvent:FireServer("\114\101\115\101\116")end))maid:GiveTask(footer.Settings.Activated:Connect(function(V)y(bodyFrame.Settings)end))maid:GiveTask(footer.Appearance.Activated:Connect(function(V)y(bodyFrame.Appearance)end))maid:GiveTask(footer.Costume.Activated:Connect(function(V)y(bodyFrame.Costume)end))local B=false maid:GiveTask(expandButton.Activated:Connect(function(V)B=not B tweenSpring.Target=B and.05 or 1 expandButton.Icon.ImageRectOffset=B and Vector2.new(93,493)or Vector2.new(179,407)end))maid:GiveTask(viewportFrame.Footer.Save.Activated:Connect(function(V)promptOverlay:PromptCostume(function(V)local B=player:FindFirstChild("\065\069\095\067\111\115\116\117\109\101\115")if not B then return end if#B:GetChildren()<Settings.MAX_COSTUME then remoteEvent:FireServer("\099\114\101\097\116\101",V)else end end)end))maid:GiveTask((bodyPageLayout:GetPropertyChangedSignal("\067\117\114\114\101\110\116\080\097\103\101")):Connect(Z))maid:GiveTask(Theme.Changed:Connect(function(V)remoteEvent:FireServer("\116\104\101\109\101",V)end))maid:GiveTask(function()module.Destroyed:Fire()tweenSpring.Target=0 expandButton.Icon.ImageRectOffset=Vector2.new(179,407)search=nil catalogList=nil promptOverlay=nil colorList=nil scale=nil bodyPageLayout:JumpToIndex(0)end)bodyPageLayout:JumpToIndex(bodyPageIndex)module.Loaded:Fire()end remoteEvent.OnClientEvent:Connect(function(V,...)Wearing:Update()if V=="\097\099\099\101\115\115\111\114\121"then if catalogList then catalogList:UpdateWearing(Wearing:Get())end elseif V=="\114\101\115\101\116"then if colorList then colorList:UpdateWearing(Wearing:GetTone())end if catalogList then catalogList:UpdateWearing(Wearing:Get())end if scale then for V,B in pairs(Wearing:GetScale())do scale:UpdateWearing(V,B)end end elseif V=="\116\111\110\101"then if colorList then colorList:UpdateWearing(Wearing:GetTone())end elseif V=="\115\099\097\108\101"then local V,B=...if scale then scale:UpdateWearing(V,B)end end searchState.uid=Wearing.UID end)



local function loadCostumes()
	costume = Costume.new(bodyFrame.Costume)
	maid.PageMaid:GiveTask(costume)

	maid.PageMaid:GiveTask(costume.Delete:Connect(function(description)
		promptOverlay:PromptConfirm({
			Title = "Delete this outfit?",
			Text = "Are you sure you want to delete this outfit?"
		}, function()
			remoteEvent:FireServer("delete", description)
		end)
	end))

	maid.PageMaid:GiveTask(costume.Wear:Connect(function(description)
		remoteEvent:FireServer("wear", description)
	end))

	maid.PageMaid:GiveTask(function()
		costume = nil
	end)
end


local function loadConfig()
	config = Config.new(bodyFrame.Settings)
	maid.PageMaid:GiveTask(config)

	maid.PageMaid:GiveTask(function()
		config = nil
	end)
end


local function loadAppearance()
	colorList = ColorList.new(bodyFrame.Appearance.SkinTone, Colors, Wearing:GetTone())
	maid.PageMaid:GiveTask(colorList)
	maid.PageMaid:GiveTask(colorList.ItemSelected:Connect(function(index)
		remoteEvent:FireServer("tone", index)
	end))

	scale = Scale.new(bodyFrame.Appearance.Scale, Wearing:GetScale())
	maid.PageMaid:GiveTask(scale)
	maid.PageMaid:GiveTask(scale.ScaleUpdated:Connect(function(scale, value)
		remoteEvent:FireServer("scale", scale, value)
	end))

	maid.PageMaid:GiveTask(function()
		colorList = nil
		scale = nil
	end)
end


local function categorySelectionFilter(button)
	return button.LayoutOrder == categoryPageIndex
end

local function subcategorySelectionFilter(button)
	return searchState.assetType == QueryMap.AssetType[button.Name]
end

local function updateButtonSelection(buttons, filterCallback)
	for i, v in ipairs(buttons) do
		v.ColorSpring.Target = filterCallback(v.Button) and 1 or 0
	end
end

local function subcategoryChanged(button)
	subcategoryPageIndex = button.LayoutOrder

	searchState.search = ""
	searchState.assetType = QueryMap.AssetType[button.Name]
	searchState.wearing = false
	search.Frame.TextBox.Text = searchState.search
end

local function loadSubcategory(subcategoryTabs)
	for i, v in ipairs(subcategoryTabs:GetChildren()) do
		if not v:IsA("GuiButton") then
			continue
		end

		--local name = string.lower(v.Name)

		if v.LayoutOrder == subcategoryPageIndex then
			subcategoryChanged(v)
		end

		local button = TabButton.new(v, function(inputObject)
			if searchState.assetType == QueryMap.AssetType[v.Name] then
				return
			end

			subcategoryChanged(v)
			updateButtonSelection(subcategoryButtons, subcategorySelectionFilter)
			catalogList:Update(true)
		end)

		table.insert(subcategoryButtons, button)
	end

	maid.PageMaid.SubPage:GiveTask(function()
		for i, v in ipairs(subcategoryButtons) do
			v:Destroy()
		end
		table.clear(subcategoryButtons)
	end)

	updateButtonSelection(subcategoryButtons, subcategorySelectionFilter)
end

local function categoryPageChanged()
	maid.PageMaid.SubPage:DoCleaning()

	local currentPage = subcategoryPageLayout.CurrentPage
	categoryPageIndex = currentPage.LayoutOrder

	updateButtonSelection(categoryButtons, categorySelectionFilter)

	--local name = string.lower(currentPage.Name)

	searchState.search = ""
	searchState.assetType = 0
	searchState.wearing = false
	search.Frame.TextBox.Text = searchState.search

	if categoryPageIndex == 4 then
		searchState.wearing = true
	else
		loadSubcategory(currentPage)
	end

	catalogList:Update(true)
end

local function loadMain()
	maid.PageMaid.SubPage = Maid.new()

	for i, v in ipairs(mainHeader.CategoryTabs:GetChildren()) do
		if not v:IsA("GuiButton") then
			continue
		end

		local button = TabButton.new(v, function(inputObject)
			subcategoryPageIndex = 0
			subcategoryPageLayout:JumpToIndex(v.LayoutOrder)
		end)

		table.insert(categoryButtons, button)
	end

	categoryPageChanged()

	maid.PageMaid:GiveTask(subcategoryPageLayout:GetPropertyChangedSignal("CurrentPage"):Connect(categoryPageChanged))

	maid.PageMaid:GiveTask(function()
		for i, v in ipairs(categoryButtons) do
			v:Destroy()
		end
		table.clear(categoryButtons)
	end)
end


local function bodyPageChanged()
	maid.PageMaid:DoCleaning()

	local currentPage = bodyPageLayout.CurrentPage
	bodyPageIndex = currentPage.LayoutOrder

	local name = string.lower(currentPage.Name)

	if name == "main" then
		loadMain()
	elseif name == "settings" then
		loadConfig()
		catalogList:Update(true)
	elseif name == "appearance" then
		loadAppearance()
		catalogList:Update(true)
	elseif name == "costume" then
		loadCostumes()
		catalogList:Update(true)
	end
end

local function jumpToPage(page)
	if bodyPageIndex == page.LayoutOrder then
		bodyPageLayout:JumpToIndex(1)
	else
		bodyPageLayout:JumpTo(page)
	end
end

local function load()
	maid:DoCleaning()
	
	local canUse = UserCanUse:CanUse(player)
	if not canUse then
		module.PermissionFailed:Fire()
		return
	end

	module.Started:Fire()
	
	maid.PageMaid = Maid.new()

	Theme:Set(player:WaitForChild("AE_Settings"):GetAttribute("Theme"))

	-- TODO theme the loading page?
	
	maid:GiveTask(Theme:Bind(editorFrame, "BackgroundColor3", "Primary"))
	maid:GiveTask(Theme:Bind(footer, "BackgroundColor3", "Secondary"))
	maid:GiveTask(Theme:Bind(footer.Appearance, "BackgroundColor3", "TabButton"))
	maid:GiveTask(Theme:Bind(footer.Appearance.Icon, "ImageColor3", "Deselected"))
	maid:GiveTask(Theme:Bind(footer.Costume, "BackgroundColor3", "TabButton"))
	maid:GiveTask(Theme:Bind(footer.Costume.Icon, "ImageColor3", "Deselected"))
	maid:GiveTask(Theme:Bind(footer.Settings, "BackgroundColor3", "TabButton"))
	maid:GiveTask(Theme:Bind(footer.Reset, "BackgroundColor3", "Reset"))
	maid:GiveTask(Theme:Bind(footer.Version, "TextColor3", "Text"))
	maid:GiveTask(Theme:Bind(mainHeader, "BackgroundColor3", "Secondary"))
	for i, v in ipairs(mainHeader.CategoryTabs:GetChildren()) do
		if not v:IsA("GuiButton") then
			continue
		end
		maid:GiveTask(Theme:Bind(v, "BackgroundColor3", "TabButton"))
		maid:GiveTask(Theme:Bind(v, "TextColor3", "Text"))
		maid:GiveTask(Theme:Bind(v.Icon, "ImageColor3", "Deselected"))
	end
	maid:GiveTask(Theme:Bind(mainHeader.Search, "BackgroundColor3", "TabButton"))
	maid:GiveTask(Theme:Bind(mainHeader.Search.Icon, "ImageColor3", "Deselected"))
	maid:GiveTask(Theme:Bind(mainHeader.Search.TextBox, "TextColor3", "Text"))
	maid:GiveTask(Theme:Bind(mainHeader.Search.TextBox, "PlaceholderColor3", "PlaceholderText"))
	maid:GiveTask(Theme:Bind(mainHeader.Search.Clear, "BackgroundColor3", "TabButton"))
	maid:GiveTask(Theme:Bind(mainHeader.Search.Clear, "ImageColor3", "Deselected"))
	for i, v in ipairs(mainHeader.SubTabs:GetChildren()) do
		if not v:IsA("Frame") then
			continue
		end
		for j, w in ipairs(v:GetChildren()) do
			if not w:IsA("GuiButton") then
				continue
			end
			maid:GiveTask(Theme:Bind(w, "BackgroundColor3", "TabButton"))
			maid:GiveTask(Theme:Bind(w, "TextColor3", "Text"))
			maid:GiveTask(Theme:Bind(w.Icon, "ImageColor3", "Deselected"))
		end
	end
	maid:GiveTask(Theme:Bind(expandButton, "BackgroundColor3", "TabButton"))
	maid:GiveTask(Theme:Bind(expandButton.Icon, "ImageColor3", "Deselected"))
	maid:GiveTask(Theme:Bind(viewportFrame.Footer.Save, "BackgroundColor3", "Save"))
	maid:GiveTask(Theme:Bind(viewportFrame.Footer.Save.Icon, "ImageColor3", "Deselected"))

	bodyPageLayout:JumpToIndex(0)
	tweenSpring.Target = 1

	promptOverlay = PromptOverlay.new(mainGui.Overlay)
	maid:GiveTask(promptOverlay)

	search = Search.new(mainHeader.Search, searchState)
	maid:GiveTask(search)

	catalogList = CatalogList.new(mainContainer.ScrollingFrame, CatalogData, Wearing:Get(), searchState)
	maid:GiveTask(catalogList)
	maid:GiveTask(catalogList.ViewDetails:Connect(function(data)
		promptOverlay:PromptPurchase(data.id)
	end))
	maid:GiveTask(catalogList.ItemSelected:Connect(function(data, wearing)
		if not wearing then
			local assetType = QueryMap.GetOptionName("AssetType", data.assetType)
			if string.find(assetType, "Accessory") or assetType == "Hat" then
				local character = player.Character
				local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
				if not humanoid or not (humanoid.Health > 0) then
					return
				end

				if #humanoid:GetAccessories() >= Settings.MAX_ACCESSORIES then
					return
				end
			end
		end

		remoteEvent:FireServer("accessory", data.id)
	end))

	maid:GiveTask(search.SearchChanged:Connect(function()
		catalogList:Update(true)
	end))

	maid:GiveTask(footer.Reset.Activated:Connect(function(inputObject)
		remoteEvent:FireServer("reset")
	end))

	maid:GiveTask(footer.Settings.Activated:Connect(function(inputObject)
		jumpToPage(bodyFrame.Settings)
	end))

	maid:GiveTask(footer.Appearance.Activated:Connect(function(inputObject)
		jumpToPage(bodyFrame.Appearance)
	end))

	maid:GiveTask(footer.Costume.Activated:Connect(function(inputObject)
		jumpToPage(bodyFrame.Costume)
	end))

	local expandedView = false
	maid:GiveTask(expandButton.Activated:Connect(function(inputObject)
		expandedView = not expandedView
		tweenSpring.Target = expandedView and 0.05 or 1
		expandButton.Icon.ImageRectOffset = expandedView and Vector2.new(93, 493) or Vector2.new(179, 407)
	end))

	maid:GiveTask(viewportFrame.Footer.Save.Activated:Connect(function(inputObject)
		promptOverlay:PromptCostume(function(name)
			local folder = player:FindFirstChild("AE_Costumes")
			if not folder then
				return
			end

			if #folder:GetChildren() < Settings.MAX_COSTUME then
				remoteEvent:FireServer("create", name)
			else
				-- warn("too many outfits")
			end
		end)
	end))

	maid:GiveTask(bodyPageLayout:GetPropertyChangedSignal("CurrentPage"):Connect(bodyPageChanged))

	maid:GiveTask(Theme.Changed:Connect(function(theme)
		remoteEvent:FireServer("theme", theme)
	end))

	maid:GiveTask(function()
		module.Destroyed:Fire()
		tweenSpring.Target = 0

		expandButton.Icon.ImageRectOffset = Vector2.new(179, 407)

		search = nil
		catalogList = nil
		promptOverlay = nil
		colorList = nil
		scale = nil

		bodyPageLayout:JumpToIndex(0)
	end)

	--lastInputTypeChanged(UserInput:GetLastInputType())
	--maid:GiveTask(UserInput.LastInputTypeChanged:Connect(lastInputTypeChanged))

	bodyPageLayout:JumpToIndex(bodyPageIndex)

	module.Loaded:Fire()
end


remoteEvent.OnClientEvent:Connect(function(key, ...)
	Wearing:Update()

	if key == "accessory" then
		if catalogList then
			catalogList:UpdateWearing(Wearing:Get())
		end
	elseif key == "reset" then
		if colorList then
			colorList:UpdateWearing(Wearing:GetTone())
		end
		if catalogList then
			catalogList:UpdateWearing(Wearing:Get())
		end
		if scale then
			for k, v in pairs(Wearing:GetScale()) do
				scale:UpdateWearing(k, v)
			end
		end
	elseif key == "tone" then
		if colorList then
			colorList:UpdateWearing(Wearing:GetTone())
		end
	elseif key == "scale" then
		local scaleName, value = ...
		if scale then
			scale:UpdateWearing(scaleName, value)
		end
	end

	searchState.uid = Wearing.UID
end)
