local I=Roact.PureComponent:extend(script.Name)function I.init(I)I.Maid=Maid.new()end function I.willUnmount(I)I.Maid:Destroy()ContextActionService:UnbindAction("\083\108\105\100\101\114\068\114\097\103\103\105\110\103")end function I.render(I)return new("\073\109\097\103\101\066\117\116\116\111\110",{Active=false;Size=I.props.Size,BackgroundColor3=I.props.BackgroundColor3,LayoutOrder=I.props.LayoutOrder;AutoButtonColor=false,BorderSizePixel=0,[Roact.Event.InputBegan]=function(n,M)if M.UserInputType.Name=="\077\111\117\115\101\066\117\116\116\111\110\049"or M.UserInputType.Name=="\084\111\117\099\104"then I:HandleDragInput(n,M)I:ListenToDragEvents(n)end end},Cryo.Dictionary.join(I.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(I.props.Value)=="\110\117\109\098\101\114"and I.props.Value or I.props.Value:map(function(I)return UDim2.new(I,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 I.IsDragInput(I)return I.UserInputType.Name=="\077\111\117\115\101\077\111\118\101\109\101\110\116"or I.UserInputType.Name=="\077\111\117\115\101\066\117\116\116\111\110\049"or I.UserInputType.Name=="\084\111\117\099\104"end function I.ListenToDragEvents(n,I)local function M(I,n,M)return Enum.ContextActionResult.Sink end ContextActionService:BindAction("\083\108\105\100\101\114\068\114\097\103\103\105\110\103",M,false,Enum.UserInputType.MouseButton1,Enum.UserInputType.MouseMovement,Enum.UserInputType.Touch)n.Maid.DragChangeListener=UserInputService.InputChanged:Connect(function(M)if n.IsDragInput(M)then n:HandleDragInput(I,M)end end)n.Maid.DragEndListener=UserInputService.InputEnded:Connect(function(M)if n.IsDragInput(M)then n:HandleDragInput(I,M)n.Maid.DragChangeListener=nil n.Maid.DragEndListener=nil ContextActionService:UnbindAction("\083\108\105\100\101\114\068\114\097\103\103\105\110\103")end end)end function I.HandleDragInput(M,I,n)local w=math.clamp((n.Position.X-I.AbsolutePosition.X)/I.AbsoluteSize.X,0,1)M.props.OnValueChanged(w)end return I

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
