local c=6.1/#themeColors local T=pages.custom["\065\066 \084\104\101\109\101\083\101\108\101\099\116\105\111\110"]local m=true local function B(c,m)if c==nil then for T,B in pairs(themeColors)do if B[1]==main.pdata.Theme then c=B[1]m=B[2]break end end end if c then local B={}for c,T in pairs(main.gui:GetDescendants())do if T:IsA("\066\111\111\108\086\097\108\117\101")and T.Name=="\084\104\101\109\101"then table.insert(B,T.Parent)end end for c,T in pairs(B)do local B=m if T.Theme.Value then local c,T,u=Color3.toHSV(m)B=Color3.fromHSV(c,T,u*1.35)end if T:IsA("\084\101\120\116\076\097\098\101\108")then local c,u,G=Color3.toHSV(m)B=Color3.fromHSV(c,u,G*2)T.TextColor3=B else T.BackgroundColor3=B end end for T,m in pairs(T:GetChildren())do if m:IsA("\084\101\120\116\066\117\116\116\111\110")then if m.Name==c then m.BorderSizePixel=1 else m.BorderSizePixel=0 end end end end end for u,G in pairs(themeColors)do local Y=G[1]local l=G[2]local q=T.ThemeTemplate:Clone()q.Name=Y q.UIAspectRatioConstraint.AspectRatio=c q.BackgroundColor3=l q.MouseButton1Down:Connect(function()if m then m=false main.signals.ChangeSetting:InvokeServer({"\084\104\101\109\101",Y})B(Y,l)m=true end end)q.Visible=true q.Parent=T end

local ratio = 6.1/#themeColors
local themeFrame = pages.custom["AB ThemeSelection"]
local themeDe = true
local function updateThemeSelection(themeName, themeColor)
	if themeName == nil then
		for i,v in pairs(themeColors) do
			if v[1] == main.pdata.Theme then
				themeName = v[1]
				themeColor = v[2]
				break
			end
		end
	end
	if themeName then
		local themeFrames = {}
		for a,b in pairs(main.gui:GetDescendants()) do
			if b:IsA("BoolValue") and b.Name == "Theme" then
				table.insert(themeFrames, b.Parent)
			end
		end 
		for _,f in pairs(themeFrames) do
			local newThemeColor = themeColor
			if f.Theme.Value then
				local h,s,v = Color3.toHSV(themeColor)
				newThemeColor = Color3.fromHSV(h, s, v*1.35)
			end
			if f:IsA("TextLabel") then
				local h,s,v = Color3.toHSV(themeColor)
				newThemeColor = Color3.fromHSV(h, s, v*2)
				f.TextColor3 = newThemeColor
			else
				f.BackgroundColor3 = newThemeColor
			end
		end
		for a,b in pairs(themeFrame:GetChildren()) do
			if b:IsA("TextButton") then
				if b.Name == themeName then
					b.BorderSizePixel = 1
				else
					b.BorderSizePixel = 0
				end
			end
		end
	end
end
for i, theme in pairs(themeColors) do
	local themeName = theme[1]
	local themeColor = theme[2]
	local box = themeFrame.ThemeTemplate:Clone()
	box.Name = themeName
	box.UIAspectRatioConstraint.AspectRatio = ratio
	box.BackgroundColor3 = themeColor
	box.MouseButton1Down:Connect(function()
		if themeDe then
			themeDe = false
			main.signals.ChangeSetting:InvokeServer{"Theme", themeName}
			updateThemeSelection(themeName, themeColor)
			themeDe = true
		end
	end)
	box.Visible = true
	box.Parent = themeFrame
end
