local z=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local a=script.Parent.Parent local h=require(a.Creator)local n=h.New local P=a.Components local f={}f.__index=f f.__type="\084\111\103\103\108\101"function f.New(M,a,f)local B=M.Library assert(f.Title,"\084\111\103\103\108\101 - \077\105\115\115\105\110\103 \084\105\116\108\101")local s={Value=f.Default or false;Callback=f.Callback or function(z) end;Type="\084\111\103\103\108\101"}local U=(require(P.Element))(f.Title,f.Description,M.Container,true)U.DescLabel.Size=UDim2.new(1,-54,0,14)s.SetTitle=U.SetTitle s.SetDesc=U.SetDesc local S=n("\073\109\097\103\101\076\097\098\101\108",{AnchorPoint=Vector2.new(0,.5);Size=UDim2.fromOffset(14,14);Position=UDim2.new(0,2,.5,0);Image="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\049\050\050\054\054\057\052\054\049\050\056";ImageTransparency=.5,ThemeTag={ImageColor3="\084\111\103\103\108\101\083\108\105\100\101\114"}})local F=n("\085\073\083\116\114\111\107\101",{Transparency=.5;ThemeTag={Color="\084\111\103\103\108\101\083\108\105\100\101\114"}})local k=n("\070\114\097\109\101",{Size=UDim2.fromOffset(36,18),AnchorPoint=Vector2.new(1,.5),Position=UDim2.new(1,-10,.5,0);Parent=U.Frame;BackgroundTransparency=1;ThemeTag={BackgroundColor3="\065\099\099\101\110\116"}},{n("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(0,9)});F,S})function s.OnChanged(a,z)s.Changed=z z(s.Value)end function s.SetValue(n,a)a=not(not a)s.Value=a h.OverrideTag(F,{Color=s.Value and"\065\099\099\101\110\116"or"\084\111\103\103\108\101\083\108\105\100\101\114"})h.OverrideTag(S,{ImageColor3=s.Value and"\084\111\103\103\108\101\084\111\103\103\108\101\100"or"\084\111\103\103\108\101\083\108\105\100\101\114"});(z:Create(S,TweenInfo.new(.25,Enum.EasingStyle.Quint,Enum.EasingDirection.Out),{Position=UDim2.new(0,s.Value and 19 or 2,.5,0)})):Play();(z:Create(k,TweenInfo.new(.25,Enum.EasingStyle.Quint,Enum.EasingDirection.Out),{BackgroundTransparency=s.Value and 0 or 1})):Play()S.ImageTransparency=s.Value and 0 or.5 B:SafeCallback(s.Callback,s.Value)B:SafeCallback(s.Changed,s.Value)end function s.Destroy(z)U:Destroy()B.Options[a]=nil end h.AddSignal(U.Frame.MouseButton1Click,function()s:SetValue(not s.Value)end)s:SetValue(s.Value)B.Options[a]=s return s end return f
local TweenService = game:GetService("TweenService")
local Root = script.Parent.Parent
local Creator = require(Root.Creator)

local New = Creator.New
local Components = Root.Components

local Element = {}
Element.__index = Element
Element.__type = "Toggle"

function Element:New(Idx, Config)
	local Library = self.Library
	assert(Config.Title, "Toggle - Missing Title")

	local Toggle = {
		Value = Config.Default or false,
		Callback = Config.Callback or function(Value) end,
		Type = "Toggle",
	}

	local ToggleFrame = require(Components.Element)(Config.Title, Config.Description, self.Container, true)
	ToggleFrame.DescLabel.Size = UDim2.new(1, -54, 0, 14)

	Toggle.SetTitle = ToggleFrame.SetTitle
	Toggle.SetDesc = ToggleFrame.SetDesc

	local ToggleCircle = New("ImageLabel", {
		AnchorPoint = Vector2.new(0, 0.5),
		Size = UDim2.fromOffset(14, 14),
		Position = UDim2.new(0, 2, 0.5, 0),
		Image = "http://www.roblox.com/asset/?id=12266946128",
		ImageTransparency = 0.5,
		ThemeTag = {
			ImageColor3 = "ToggleSlider",
		},
	})

	local ToggleBorder = New("UIStroke", {
		Transparency = 0.5,
		ThemeTag = {
			Color = "ToggleSlider",
		},
	})

	local ToggleSlider = New("Frame", {
		Size = UDim2.fromOffset(36, 18),
		AnchorPoint = Vector2.new(1, 0.5),
		Position = UDim2.new(1, -10, 0.5, 0),
		Parent = ToggleFrame.Frame,
		BackgroundTransparency = 1,
		ThemeTag = {
			BackgroundColor3 = "Accent",
		},
	}, {
		New("UICorner", {
			CornerRadius = UDim.new(0, 9),
		}),
		ToggleBorder,
		ToggleCircle,
	})

	function Toggle:OnChanged(Func)
		Toggle.Changed = Func
		Func(Toggle.Value)
	end

	function Toggle:SetValue(Value)
		Value = not not Value
		Toggle.Value = Value

		Creator.OverrideTag(ToggleBorder, { Color = Toggle.Value and "Accent" or "ToggleSlider" })
		Creator.OverrideTag(ToggleCircle, { ImageColor3 = Toggle.Value and "ToggleToggled" or "ToggleSlider" })
		TweenService:Create(
			ToggleCircle,
			TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.Out),
			{ Position = UDim2.new(0, Toggle.Value and 19 or 2, 0.5, 0) }
		):Play()
		TweenService:Create(
			ToggleSlider,
			TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.Out),
			{ BackgroundTransparency = Toggle.Value and 0 or 1 }
		):Play()
		ToggleCircle.ImageTransparency = Toggle.Value and 0 or 0.5

		Library:SafeCallback(Toggle.Callback, Toggle.Value)
		Library:SafeCallback(Toggle.Changed, Toggle.Value)
	end

	function Toggle:Destroy()
		ToggleFrame:Destroy()
		Library.Options[Idx] = nil
	end

	Creator.AddSignal(ToggleFrame.Frame.MouseButton1Click, function()
		Toggle:SetValue(not Toggle.Value)
	end)

	Toggle:SetValue(Toggle.Value)

	Library.Options[Idx] = Toggle
	return Toggle
end

return Element
