local z=game:GetService("\085\115\101\114\073\110\112\117\116\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="\083\108\105\100\101\114"function f.New(M,a,f)local B=M.Library assert(f.Title,"\083\108\105\100\101\114 - \077\105\115\115\105\110\103 \084\105\116\108\101\046")assert(f.Default,"\083\108\105\100\101\114 - \077\105\115\115\105\110\103 \100\101\102\097\117\108\116 \118\097\108\117\101\046")assert(f.Min,"\083\108\105\100\101\114 - \077\105\115\115\105\110\103 \109\105\110\105\109\117\109 \118\097\108\117\101\046")assert(f.Max,"\083\108\105\100\101\114 - \077\105\115\115\105\110\103 \109\097\120\105\109\117\109 \118\097\108\117\101\046")assert(f.Rounding,"\083\108\105\100\101\114 - \077\105\115\115\105\110\103 \114\111\117\110\100\105\110\103 \118\097\108\117\101\046")local s={Value=nil;Min=f.Min;Max=f.Max;Rounding=f.Rounding;Callback=f.Callback or function(z) end;Type="\083\108\105\100\101\114"}local U=false local S=(require(P.Element))(f.Title,f.Description,M.Container,false)S.DescLabel.Size=UDim2.new(1,-170,0,14)s.SetTitle=S.SetTitle s.SetDesc=S.SetDesc local F=n("\073\109\097\103\101\076\097\098\101\108",{AnchorPoint=Vector2.new(0,.5);Position=UDim2.new(0,-7,.5,0),Size=UDim2.fromOffset(14,14);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";ThemeTag={ImageColor3="\065\099\099\101\110\116"}})local k=n("\070\114\097\109\101",{BackgroundTransparency=1,Position=UDim2.fromOffset(7,0),Size=UDim2.new(1,-14,1,0)},{F})local r=n("\070\114\097\109\101",{Size=UDim2.new(0,0,1,0);ThemeTag={BackgroundColor3="\065\099\099\101\110\116"}},{n("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(1,0)})})local i=n("\084\101\120\116\076\097\098\101\108",{FontFace=Font.new("\114\098\120\097\115\115\101\116\058\047\047\102\111\110\116\115\047\102\097\109\105\108\105\101\115\047\071\111\116\104\097\109\083\083\109\046\106\115\111\110");Text="\086\097\108\117\101",TextSize=12,TextWrapped=true;TextXAlignment=Enum.TextXAlignment.Right;BackgroundColor3=Color3.fromRGB(255,255,255);BackgroundTransparency=1,Size=UDim2.new(0,100,0,14);Position=UDim2.new(0,-4,.5,0);AnchorPoint=Vector2.new(1,.5);ThemeTag={TextColor3="\083\117\098\084\101\120\116"}})local c=n("\070\114\097\109\101",{Size=UDim2.new(1,0,0,4),AnchorPoint=Vector2.new(1,.5);Position=UDim2.new(1,-10,.5,0),BackgroundTransparency=.4,Parent=S.Frame;ThemeTag={BackgroundColor3="\083\108\105\100\101\114\082\097\105\108"}},{n("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(1,0)}),n("\085\073\083\105\122\101\067\111\110\115\116\114\097\105\110\116",{MaxSize=Vector2.new(150,math.huge)});i,r;k})h.AddSignal(F.InputBegan,function(z)if z.UserInputType==Enum.UserInputType.MouseButton1 or z.UserInputType==Enum.UserInputType.Touch then U=true end end)h.AddSignal(F.InputEnded,function(z)if z.UserInputType==Enum.UserInputType.MouseButton1 or z.UserInputType==Enum.UserInputType.Touch then U=false end end)h.AddSignal(z.InputChanged,function(z)if U and(z.UserInputType==Enum.UserInputType.MouseMovement or z.UserInputType==Enum.UserInputType.Touch)then local a=math.clamp((z.Position.X-k.AbsolutePosition.X)/k.AbsoluteSize.X,0,1)s:SetValue(s.Min+(s.Max-s.Min)*a)end end)function s.OnChanged(a,z)s.Changed=z z(s.Value)end function s.SetValue(a,z)a.Value=B:Round(math.clamp(z,s.Min,s.Max),s.Rounding)F.Position=UDim2.new((a.Value-s.Min)/(s.Max-s.Min),-7,.5,0)r.Size=UDim2.fromScale((a.Value-s.Min)/(s.Max-s.Min),1)i.Text=tostring(a.Value)B:SafeCallback(s.Callback,a.Value)B:SafeCallback(s.Changed,a.Value)end function s.Destroy(z)S:Destroy()B.Options[a]=nil end s:SetValue(f.Default)B.Options[a]=s return s end return f
local UserInputService = game:GetService("UserInputService")
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 = "Slider"

function Element:New(Idx, Config)
	local Library = self.Library
	assert(Config.Title, "Slider - Missing Title.")
	assert(Config.Default, "Slider - Missing default value.")
	assert(Config.Min, "Slider - Missing minimum value.")
	assert(Config.Max, "Slider - Missing maximum value.")
	assert(Config.Rounding, "Slider - Missing rounding value.")

	local Slider = {
		Value = nil,
		Min = Config.Min,
		Max = Config.Max,
		Rounding = Config.Rounding,
		Callback = Config.Callback or function(Value) end,
		Type = "Slider",
	}

	local Dragging = false

	local SliderFrame = require(Components.Element)(Config.Title, Config.Description, self.Container, false)
	SliderFrame.DescLabel.Size = UDim2.new(1, -170, 0, 14)

	Slider.SetTitle = SliderFrame.SetTitle
	Slider.SetDesc = SliderFrame.SetDesc

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

	local SliderRail = New("Frame", {
		BackgroundTransparency = 1,
		Position = UDim2.fromOffset(7, 0),
		Size = UDim2.new(1, -14, 1, 0),
	}, {
		SliderDot,
	})

	local SliderFill = New("Frame", {
		Size = UDim2.new(0, 0, 1, 0),
		ThemeTag = {
			BackgroundColor3 = "Accent",
		},
	}, {
		New("UICorner", {
			CornerRadius = UDim.new(1, 0),
		}),
	})

	local SliderDisplay = New("TextLabel", {
		FontFace = Font.new("rbxasset://fonts/families/GothamSSm.json"),
		Text = "Value",
		TextSize = 12,
		TextWrapped = true,
		TextXAlignment = Enum.TextXAlignment.Right,
		BackgroundColor3 = Color3.fromRGB(255, 255, 255),
		BackgroundTransparency = 1,
		Size = UDim2.new(0, 100, 0, 14),
		Position = UDim2.new(0, -4, 0.5, 0),
		AnchorPoint = Vector2.new(1, 0.5),
		ThemeTag = {
			TextColor3 = "SubText",
		},
	})

	local SliderInner = New("Frame", {
		Size = UDim2.new(1, 0, 0, 4),
		AnchorPoint = Vector2.new(1, 0.5),
		Position = UDim2.new(1, -10, 0.5, 0),
		BackgroundTransparency = 0.4,
		Parent = SliderFrame.Frame,
		ThemeTag = {
			BackgroundColor3 = "SliderRail",
		},
	}, {
		New("UICorner", {
			CornerRadius = UDim.new(1, 0),
		}),
		New("UISizeConstraint", {
			MaxSize = Vector2.new(150, math.huge),
		}),
		SliderDisplay,
		SliderFill,
		SliderRail,
	})

	Creator.AddSignal(SliderDot.InputBegan, function(Input)
		if
			Input.UserInputType == Enum.UserInputType.MouseButton1
			or Input.UserInputType == Enum.UserInputType.Touch
		then
			Dragging = true
		end
	end)

	Creator.AddSignal(SliderDot.InputEnded, function(Input)
		if
			Input.UserInputType == Enum.UserInputType.MouseButton1
			or Input.UserInputType == Enum.UserInputType.Touch
		then
			Dragging = false
		end
	end)

	Creator.AddSignal(UserInputService.InputChanged, function(Input)
		if
			Dragging
			and (
				Input.UserInputType == Enum.UserInputType.MouseMovement
				or Input.UserInputType == Enum.UserInputType.Touch
			)
		then
			local SizeScale =
				math.clamp((Input.Position.X - SliderRail.AbsolutePosition.X) / SliderRail.AbsoluteSize.X, 0, 1)
			Slider:SetValue(Slider.Min + ((Slider.Max - Slider.Min) * SizeScale))
		end
	end)

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

	function Slider:SetValue(Value)
		self.Value = Library:Round(math.clamp(Value, Slider.Min, Slider.Max), Slider.Rounding)
		SliderDot.Position = UDim2.new((self.Value - Slider.Min) / (Slider.Max - Slider.Min), -7, 0.5, 0)
		SliderFill.Size = UDim2.fromScale((self.Value - Slider.Min) / (Slider.Max - Slider.Min), 1)
		SliderDisplay.Text = tostring(self.Value)

		Library:SafeCallback(Slider.Callback, self.Value)
		Library:SafeCallback(Slider.Changed, self.Value)
	end

	function Slider:Destroy()
		SliderFrame:Destroy()
		Library.Options[Idx] = nil
	end

	Slider:SetValue(Config.Default)

	Library.Options[Idx] = Slider
	return Slider
end

return Element
