local W=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local q=W.AvatarEditor local e=require(q.Shared.Util.Maid)local t=require(q.Shared.Util.Signal)local V=require(q.Client.Theme)local d=(require(q.Gui.ColorTemplateToLua))()local E={}E.__index=E local function L(W)local q,e,t=string.match(W,"\094\035\063\040\037\119\037\119\041\040\037\119\037\119\041\040\037\119\037\119\041\036")return Color3.fromRGB(tonumber(q,16),tonumber(e,16),tonumber(t,16))end local function v(W)return string.format("\035\037\048\050\088\037\048\050\088\037\048\050\088",W.R*255,W.G*255,W.B*255)end local function F(W,q)return v(W)==v(q)end function E.new(W,q,L)local v=setmetatable({},E)v.Frame=W v.Wearing=L v.Children={}v.Maid=e.new()v.Listeners=e.new()v.ItemSelected=t.new()v.Maid:GiveTask(V.Changed:Connect(function()v:Render()end))v.Maid:GiveTask(V:Bind(W,"\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"))for q,e in ipairs(q)do local t=d:Clone()t.BackgroundColor3=e t.Wearing.Visible=F(L,e)t.Parent=W v.Children[q]=t v.Maid:GiveTask(V:Bind(t.Wearing,"\073\109\097\103\101\067\111\108\111\114\051","\087\101\097\114\105\110\103"))v.Maid:GiveTask(t.Activated:Connect(function(W)v.ItemSelected:Fire(q)end))end return v end function E.Render(W)local q=W.Listeners local e=W.Wearing q:DoCleaning()for W,q in ipairs(W.Children)do q.Wearing.Visible=F(e,q.BackgroundColor3)end end function E.UpdateWearing(q,W)q.Wearing=W q:Render()end function E.Destroy(W)W.Maid:Destroy()W.Maid=nil W.Listeners:Destroy()W.Listeners=nil W.Frame=nil W.Wearing=nil for W,q in ipairs(W.Children)do q:Destroy()end table.clear(W.Children)W.ItemSelected:Destroy()W.ItemSelected=nil end return E
-- Class
-- 0_1195
-- January 10, 2021

--[[



]]

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local AvatarEditor = ReplicatedStorage.AvatarEditor
local Maid = require(AvatarEditor.Shared.Util.Maid)
local Signal = require(AvatarEditor.Shared.Util.Signal)
local Theme = require(AvatarEditor.Client.Theme)

local buttonTemplate = require(AvatarEditor.Gui.ColorTemplateToLua)()

local Class = {}
Class.__index = Class


local function fromHex(hex)
	local r, g, b = string.match(hex, "^#?(%w%w)(%w%w)(%w%w)$")
	return Color3.fromRGB(tonumber(r, 16), tonumber(g, 16), tonumber(b, 16))
end

local function toHex(color)
	return string.format("#%02X%02X%02X", color.R * 255, color.G * 255, color.B * 255)
end


local function isWearing(assets, color3)
	return toHex(assets) == toHex(color3)
end


function Class.new(frame, colorData, wearingTone)
	local self = setmetatable({}, Class)
	
	self.Frame = frame
	self.Wearing = wearingTone
	self.Children = {}
	self.Maid = Maid.new()
	self.Listeners = Maid.new()
	self.ItemSelected = Signal.new()
	
	self.Maid:GiveTask(Theme.Changed:Connect(function()
		self:Render()
	end))

	self.Maid:GiveTask(Theme:Bind(frame, "ScrollBarImageColor3", "Scrollbar"))
	
	for i, v in ipairs(colorData) do
		local button = buttonTemplate:Clone()
		button.BackgroundColor3 = v
		button.Wearing.Visible = isWearing(wearingTone, v)
		button.Parent = frame
		self.Children[i] = button
		
		self.Maid:GiveTask(Theme:Bind(button.Wearing, "ImageColor3", "Wearing"))
		
		self.Maid:GiveTask(button.Activated:Connect(function(inputObject)
			self.ItemSelected:Fire(i)
		end))
	end
	
	return self
end


function Class:Render()
	local maid = self.Listeners
	local wearingTone = self.Wearing
	
	maid:DoCleaning()
	
	for i, v in ipairs(self.Children) do
		v.Wearing.Visible = isWearing(wearingTone, v.BackgroundColor3)
	end
end


function Class:UpdateWearing(wearingTone)
	self.Wearing = wearingTone
	self:Render()
end


function Class:Destroy()
	self.Maid:Destroy()
	self.Maid = nil
	self.Listeners:Destroy()
	self.Listeners = nil
	self.Frame = nil
	self.Wearing = nil
	for i, v in ipairs(self.Children) do
		v:Destroy()
	end
	table.clear(self.Children)
	self.ItemSelected:Destroy()
	self.ItemSelected = nil
end


return Class