local y=Roact.PureComponent:extend(script.Name)function y.init(y)y.Maid=Maid.new()end function y.willUnmount(y)y.Maid:Destroy()ContextActionService:UnbindAction("\083\108\105\100\101\114\068\114\097\103\103\105\110\103")end function y.render(y)return new("\073\109\097\103\101\066\117\116\116\111\110",{Active=false;Size=y.props.Size,BackgroundColor3=y.props.BackgroundColor3,LayoutOrder=y.props.LayoutOrder,AutoButtonColor=false;BorderSizePixel=0;[Roact.Event.InputBegan]=function(c,T)if T.UserInputType.Name=="\077\111\117\115\101\066\117\116\116\111\110\049"or T.UserInputType.Name=="\084\111\117\099\104"then y:HandleDragInput(c,T)y:ListenToDragEvents(c)end end},Cryo.Dictionary.join(y.props[Roact.Children]or{},{Corners=new("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(0,4)});Thumb=new("\070\114\097\109\101",{AnchorPoint=Vector2.new(.5,.5);BackgroundColor3=Color3.fromRGB(255,255,255);BorderSizePixel=0,Position=typeof(y.props.Value)=="\110\117\109\098\101\114"and y.props.Value or y.props.Value:map(function(y)return UDim2.new(y,0,.5,0)end);Size=UDim2.new(0,4,0,4),ZIndex=2},{Corners=new("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(1,0)}),Shadow=new("\070\114\097\109\101",{AnchorPoint=Vector2.new(.5,.5);BackgroundColor3=Color3.fromRGB(56,56,56);BorderSizePixel=0,Position=UDim2.new(.5,0,.5,0);Size=UDim2.new(0,6,0,6)},{Corners=new("\085\073\067\111\114\110\101\114",{CornerRadius=UDim.new(1,0)})})})}))end function y.IsDragInput(y)return y.UserInputType.Name=="\077\111\117\115\101\077\111\118\101\109\101\110\116"or y.UserInputType.Name=="\077\111\117\115\101\066\117\116\116\111\110\049"or y.UserInputType.Name=="\084\111\117\099\104"end function y.ListenToDragEvents(c,y)local function T(y,c,T)return Enum.ContextActionResult.Sink end ContextActionService:BindAction("\083\108\105\100\101\114\068\114\097\103\103\105\110\103",T,false,Enum.UserInputType.MouseButton1,Enum.UserInputType.MouseMovement,Enum.UserInputType.Touch)c.Maid.DragChangeListener=UserInputService.InputChanged:Connect(function(T)if c.IsDragInput(T)then c:HandleDragInput(y,T)end end)c.Maid.DragEndListener=UserInputService.InputEnded:Connect(function(T)if c.IsDragInput(T)then c:HandleDragInput(y,T)c.Maid.DragChangeListener=nil c.Maid.DragEndListener=nil ContextActionService:UnbindAction("\083\108\105\100\101\114\068\114\097\103\103\105\110\103")end end)end function y.HandleDragInput(T,y,c)local F=math.clamp((c.Position.X-y.AbsolutePosition.X)/y.AbsoluteSize.X,0,1)T.props.OnValueChanged(F)end return y
-- Create component
local Slider = Roact.PureComponent:extend(script.Name)

function Slider:init()
	self.Maid = Maid.new()
end

function Slider:willUnmount()
	self.Maid:Destroy()
	ContextActionService:UnbindAction("SliderDragging")
end

function Slider:render()
	return new(
		"ImageButton",
		{
			Active = false,
			Size = self.props.Size,
			BackgroundColor3 = self.props.BackgroundColor3,
			LayoutOrder = self.props.LayoutOrder,
			AutoButtonColor = false,
			BorderSizePixel = 0,
			[Roact.Event.InputBegan] = function(rbx, Input)
				if (Input.UserInputType.Name == "MouseButton1") or (Input.UserInputType.Name == "Touch") then
					self:HandleDragInput(rbx, Input)
					self:ListenToDragEvents(rbx)
				end
			end,
		},
		Cryo.Dictionary.join(self.props[Roact.Children] or {}, {
			Corners = new("UICorner", {
				CornerRadius = UDim.new(0, 4),
			}),
			Thumb = new("Frame", {
				AnchorPoint = Vector2.new(0.5, 0.5),
				BackgroundColor3 = Color3.fromRGB(255, 255, 255),
				BorderSizePixel = 0,
				Position = (typeof(self.props.Value) == "number") and self.props.Value
					or self.props.Value:map(function(Value)
						return UDim2.new(Value, 0, 0.5, 0)
					end),
				Size = UDim2.new(0, 4, 0, 4),
				ZIndex = 2,
			}, {
				Corners = new("UICorner", {
					CornerRadius = UDim.new(1, 0),
				}),
				Shadow = new("Frame", {
					AnchorPoint = Vector2.new(0.5, 0.5),
					BackgroundColor3 = Color3.fromRGB(56, 56, 56),
					BorderSizePixel = 0,
					Position = UDim2.new(0.5, 0, 0.5, 0),
					Size = UDim2.new(0, 6, 0, 6),
				}, {
					Corners = new("UICorner", {
						CornerRadius = UDim.new(1, 0),
					}),
				}),
			}),
		})
	)
end

function Slider.IsDragInput(Input)
	return (Input.UserInputType.Name == "MouseMovement")
		or (Input.UserInputType.Name == "MouseButton1")
		or (Input.UserInputType.Name == "Touch")
end

function Slider:ListenToDragEvents(SliderObject)
	local function Callback(Action, State, Input)
		return Enum.ContextActionResult.Sink
	end
	ContextActionService:BindAction(
		"SliderDragging",
		Callback,
		false,
		Enum.UserInputType.MouseButton1,
		Enum.UserInputType.MouseMovement,
		Enum.UserInputType.Touch
	)

	self.Maid.DragChangeListener = UserInputService.InputChanged:Connect(function(Input)
		if self.IsDragInput(Input) then
			self:HandleDragInput(SliderObject, Input)
		end
	end)
	self.Maid.DragEndListener = UserInputService.InputEnded:Connect(function(Input)
		if self.IsDragInput(Input) then
			self:HandleDragInput(SliderObject, Input)
			self.Maid.DragChangeListener = nil
			self.Maid.DragEndListener = nil
			ContextActionService:UnbindAction("SliderDragging")
		end
	end)
end

function Slider:HandleDragInput(SliderObject, Input)
	local Alpha = math.clamp((Input.Position.X - SliderObject.AbsolutePosition.X) / SliderObject.AbsoluteSize.X, 0, 1)
	self.props.OnValueChanged(Alpha)
end

return Slider
