local M=script.Parent local B=require(M.Themes)local f=require(M.Packages.Flipper)local e={Registry={};Signals={};TransparencyMotors={};DefaultProperties={ScreenGui={ResetOnSpawn=false;ZIndexBehavior=Enum.ZIndexBehavior.Sibling};Frame={BackgroundColor3=Color3.new(1,1,1);BorderColor3=Color3.new(0,0,0);BorderSizePixel=0};ScrollingFrame={BackgroundColor3=Color3.new(1,1,1),BorderColor3=Color3.new(0,0,0);ScrollBarImageColor3=Color3.new(0,0,0)};TextLabel={BackgroundColor3=Color3.new(1,1,1);BorderColor3=Color3.new(0,0,0);Font=Enum.Font.SourceSans;Text="";TextColor3=Color3.new(0,0,0);BackgroundTransparency=1;TextSize=14};TextButton={BackgroundColor3=Color3.new(1,1,1),BorderColor3=Color3.new(0,0,0);AutoButtonColor=false,Font=Enum.Font.SourceSans,Text="",TextColor3=Color3.new(0,0,0);TextSize=14},TextBox={BackgroundColor3=Color3.new(1,1,1),BorderColor3=Color3.new(0,0,0);ClearTextOnFocus=false,Font=Enum.Font.SourceSans;Text="";TextColor3=Color3.new(0,0,0),TextSize=14},ImageLabel={BackgroundTransparency=1;BackgroundColor3=Color3.new(1,1,1);BorderColor3=Color3.new(0,0,0),BorderSizePixel=0};ImageButton={BackgroundColor3=Color3.new(1,1,1),BorderColor3=Color3.new(0,0,0);AutoButtonColor=false},CanvasGroup={BackgroundColor3=Color3.new(1,1,1);BorderColor3=Color3.new(0,0,0);BorderSizePixel=0}}}local function D(M,B)if B.ThemeTag then e.AddThemeObject(M,B.ThemeTag)end end function e.AddSignal(M,B)table.insert(e.Signals,M:Connect(B))end function e.Disconnect()for M=#e.Signals,1,-1 do local B=table.remove(e.Signals,M)B:Disconnect()end end function e.GetThemeProperty(f)if B[(require(M)).Theme][f]then return B[(require(M)).Theme][f]end return B.Dark[f]end function e.UpdateTheme()for M,B in next,e.Registry do for B,f in next,B.Properties do M[B]=e.GetThemeProperty(f)end end for M,B in next,e.TransparencyMotors do B:setGoal(f.Instant.new(e.GetThemeProperty("\069\108\101\109\101\110\116\084\114\097\110\115\112\097\114\101\110\099\121")))end end function e.AddThemeObject(M,B)local f=#e.Registry+1 local D={Object=M,Properties=B;Idx=f}e.Registry[M]=D e.UpdateTheme()return M end function e.OverrideTag(M,B)e.Registry[M].Properties=B e.UpdateTheme()end function e.New(M,B,f)local A=Instance.new(M)for M,B in next,e.DefaultProperties[M]or{}do A[M]=B end for M,B in next,B or{}do if M~="\084\104\101\109\101\084\097\103"then A[M]=B end end for M,B in next,f or{}do B.Parent=A end D(A,B)return A end function e.SpringMotor(B,D,A,n,H)n=n or false H=H or false local b=f.SingleMotor.new(B)b:onStep(function(M)D[A]=M end)if H then table.insert(e.TransparencyMotors,b)end local function d(B,e)e=e or false if not n then if not e then if A=="\066\097\099\107\103\114\111\117\110\100\084\114\097\110\115\112\097\114\101\110\099\121"and(require(M)).DialogOpen then return end end end b:setGoal(f.Spring.new(B,{frequency=8}))end return b,d end return e
local Root = script.Parent
local Themes = require(Root.Themes)
local Flipper = require(Root.Packages.Flipper)

local Creator = {
	Registry = {},
	Signals = {},
	TransparencyMotors = {},
	DefaultProperties = {
		ScreenGui = {
			ResetOnSpawn = false,
			ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
		},
		Frame = {
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			BorderSizePixel = 0,
		},
		ScrollingFrame = {
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			ScrollBarImageColor3 = Color3.new(0, 0, 0),
		},
		TextLabel = {
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			Font = Enum.Font.SourceSans,
			Text = "",
			TextColor3 = Color3.new(0, 0, 0),
			BackgroundTransparency = 1,
			TextSize = 14,
		},
		TextButton = {
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			AutoButtonColor = false,
			Font = Enum.Font.SourceSans,
			Text = "",
			TextColor3 = Color3.new(0, 0, 0),
			TextSize = 14,
		},
		TextBox = {
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			ClearTextOnFocus = false,
			Font = Enum.Font.SourceSans,
			Text = "",
			TextColor3 = Color3.new(0, 0, 0),
			TextSize = 14,
		},
		ImageLabel = {
			BackgroundTransparency = 1,
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			BorderSizePixel = 0,
		},
		ImageButton = {
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			AutoButtonColor = false,
		},
		CanvasGroup = {
			BackgroundColor3 = Color3.new(1, 1, 1),
			BorderColor3 = Color3.new(0, 0, 0),
			BorderSizePixel = 0,
		},
	},
}

local function ApplyCustomProps(Object, Props)
	if Props.ThemeTag then
		Creator.AddThemeObject(Object, Props.ThemeTag)
	end
end

function Creator.AddSignal(Signal, Function)
	table.insert(Creator.Signals, Signal:Connect(Function))
end

function Creator.Disconnect()
	for Idx = #Creator.Signals, 1, -1 do
		local Connection = table.remove(Creator.Signals, Idx)
		Connection:Disconnect()
	end
end

function Creator.GetThemeProperty(Property)
	if Themes[require(Root).Theme][Property] then
		return Themes[require(Root).Theme][Property]
	end
	return Themes["Dark"][Property]
end

function Creator.UpdateTheme()
	for Instance, Object in next, Creator.Registry do
		for Property, ColorIdx in next, Object.Properties do
			Instance[Property] = Creator.GetThemeProperty(ColorIdx)
		end
	end

	for _, Motor in next, Creator.TransparencyMotors do
		Motor:setGoal(Flipper.Instant.new(Creator.GetThemeProperty("ElementTransparency")))
	end
end

function Creator.AddThemeObject(Object, Properties)
	local Idx = #Creator.Registry + 1
	local Data = {
		Object = Object,
		Properties = Properties,
		Idx = Idx,
	}

	Creator.Registry[Object] = Data
	Creator.UpdateTheme()
	return Object
end

function Creator.OverrideTag(Object, Properties)
	Creator.Registry[Object].Properties = Properties
	Creator.UpdateTheme()
end

function Creator.New(Name, Properties, Children)
	local Object = Instance.new(Name)

	-- Default properties
	for Name, Value in next, Creator.DefaultProperties[Name] or {} do
		Object[Name] = Value
	end

	-- Properties
	for Name, Value in next, Properties or {} do
		if Name ~= "ThemeTag" then
			Object[Name] = Value
		end
	end

	-- Children
	for _, Child in next, Children or {} do
		Child.Parent = Object
	end

	ApplyCustomProps(Object, Properties)
	return Object
end

function Creator.SpringMotor(Initial, Instance, Prop, IgnoreDialogCheck, ResetOnThemeChange)
	IgnoreDialogCheck = IgnoreDialogCheck or false
	ResetOnThemeChange = ResetOnThemeChange or false
	local Motor = Flipper.SingleMotor.new(Initial)
	Motor:onStep(function(value)
		Instance[Prop] = value
	end)

	if ResetOnThemeChange then
		table.insert(Creator.TransparencyMotors, Motor)
	end

	local function SetValue(Value, Ignore)
		Ignore = Ignore or false
		if not IgnoreDialogCheck then
			if not Ignore then
				if Prop == "BackgroundTransparency" and require(Root).DialogOpen then
					return
				end
			end
		end
		Motor:setGoal(Flipper.Spring.new(Value, { frequency = 8 }))
	end

	return Motor, SetValue
end

return Creator
