local j=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local H=game:GetService("\080\108\097\121\101\114\115")local p=j.AvatarEditor local e=require(p.Shared.Util.Maid)local A=require(p.Shared.Util.Promise)local M=require(p.Client.GuiLib.LazyLoader)local G=require(p.Client.Theme)local n=H.LocalPlayer local q={}q.__index=q function q.new(j)local H=setmetatable({},q)H.Frame=j H.ScrollingFrame=H.Frame.ScrollingFrame H.Maid=e.new()H.Maid:GiveTask(G:Bind(H.ScrollingFrame,"\083\099\114\111\108\108\066\097\114\073\109\097\103\101\067\111\108\111\114\051","\083\099\114\111\108\108\098\097\114"))H.Maid:GiveTask(G:Bind(H.ScrollingFrame.Theme.DropdownButton,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\101\114\116\105\097\114\121"))H.Maid:GiveTask(G:Bind(H.ScrollingFrame.Theme.DropdownButton.ListFrame,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\101\114\116\105\097\114\121"))H.Maid:GiveTask(G:Bind(H.ScrollingFrame.Theme.DropdownButton.Arrow,"\073\109\097\103\101\067\111\108\111\114\051","\068\101\115\101\108\101\099\116\101\100"))H.Maid:GiveTask(G:Bind(H.ScrollingFrame.Theme.DropdownButton.Option,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))H.Maid:GiveTask(G:Bind(H.ScrollingFrame.Theme.TextLabel,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))local W=H.ScrollingFrame.Theme.DropdownButton for j,e in ipairs(G:GetAll())do local A=p.DropdownTemplate:Clone()A.LayoutOrder=j A.Text=e A.Name=e H.Maid:GiveTask(G:Bind(A,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\101\114\116\105\097\114\121"))H.Maid:GiveTask(G:Bind(A,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))H.Maid:GiveTask(A)A.Parent=W.ListFrame.ScrollFrame end H.Maid:GiveTask(G:Bind(W.ListFrame.ScrollFrame,"\083\099\114\111\108\108\066\097\114\073\109\097\103\101\067\111\108\111\114\051","\083\099\114\111\108\108\098\097\114"))W.ListFrame.ScrollFrame.CanvasSize=UDim2.new(0,0,0,W.ListFrame.ScrollFrame.UIListLayout.AbsoluteContentSize.Y)local o=M.Classes.Dropdown.new(W,W.ListFrame)H.Maid:GiveTask(o)H.Maid:GiveTask(o.Changed:Connect(function(j)local H=j.Name G:Set(H)end));((A.new(function(j,H)local p=n:WaitForChild("\065\069\095\083\101\116\116\105\110\103\115")j(p)end)):andThen(function(j)H.Folder=j o:Set(W.ListFrame.ScrollFrame[H.Folder:GetAttribute("\084\104\101\109\101")])G:Set((o:Get()).Name)end)):catch(warn)return H end function q.Destroy(j)j.Maid:DoCleaning()j.Maid=nil setmetatable(j,nil)end return q


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local AvatarEditor = ReplicatedStorage.AvatarEditor
local Maid = require(AvatarEditor.Shared.Util.Maid)
local Promise = require(AvatarEditor.Shared.Util.Promise)
local GuiLib = require(AvatarEditor.Client.GuiLib.LazyLoader)
local Theme = require(AvatarEditor.Client.Theme)

local player = Players.LocalPlayer

local Class = {}
Class.__index = Class


function Class.new(frame)
	local self = setmetatable({}, Class)
	
	self.Frame = frame
	self.ScrollingFrame = self.Frame.ScrollingFrame
	self.Maid = Maid.new()

	self.Maid:GiveTask(Theme:Bind(self.ScrollingFrame, "ScrollBarImageColor3", "Scrollbar"))
	self.Maid:GiveTask(Theme:Bind(self.ScrollingFrame.Theme.DropdownButton, "BackgroundColor3", "Tertiary"))
	self.Maid:GiveTask(Theme:Bind(self.ScrollingFrame.Theme.DropdownButton.ListFrame, "BackgroundColor3", "Tertiary"))
	self.Maid:GiveTask(Theme:Bind(self.ScrollingFrame.Theme.DropdownButton.Arrow, "ImageColor3", "Deselected"))
	self.Maid:GiveTask(Theme:Bind(self.ScrollingFrame.Theme.DropdownButton.Option, "TextColor3", "Text"))
	self.Maid:GiveTask(Theme:Bind(self.ScrollingFrame.Theme.TextLabel, "TextColor3", "Text"))
	
	local dropdownButton = self.ScrollingFrame.Theme.DropdownButton
	for i, v in ipairs(Theme:GetAll()) do
		local button = AvatarEditor.DropdownTemplate:Clone()
		button.LayoutOrder = i
		button.Text = v
		button.Name = v
		self.Maid:GiveTask(Theme:Bind(button, "BackgroundColor3", "Tertiary"))
		self.Maid:GiveTask(Theme:Bind(button, "TextColor3", "Text"))
		self.Maid:GiveTask(button)
		button.Parent = dropdownButton.ListFrame.ScrollFrame
	end
	self.Maid:GiveTask(Theme:Bind(dropdownButton.ListFrame.ScrollFrame, "ScrollBarImageColor3", "Scrollbar"))
	
	-- for some reason AutomaticCanvasSize doesnt want to work here...
	dropdownButton.ListFrame.ScrollFrame.CanvasSize = UDim2.new(0, 0, 0, dropdownButton.ListFrame.ScrollFrame.UIListLayout.AbsoluteContentSize.Y)
	
	local themeDropdown = GuiLib.Classes.Dropdown.new(dropdownButton, dropdownButton.ListFrame)
	self.Maid:GiveTask(themeDropdown)
	
	self.Maid:GiveTask(themeDropdown.Changed:Connect(function(button)
		local theme = button.Name
		Theme:Set(theme)
	end))
	
	Promise.new(function(resolve, reject)
		local folder = player:WaitForChild("AE_Settings")
		resolve(folder)
	end)
	:andThen(function(folder)
		self.Folder = folder
		
		themeDropdown:Set(dropdownButton.ListFrame.ScrollFrame[self.Folder:GetAttribute("Theme")])
		Theme:Set(themeDropdown:Get().Name)
	end)
	:catch(warn)
	
	return self
end


function Class:Destroy()
	self.Maid:DoCleaning()
	self.Maid = nil
	setmetatable(self, nil)
end


return Class
