local z=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local A=(script:FindFirstAncestor("\067\109\100\114\065\100\100\105\116\105\111\110\115")).Packages local Y=require(A.Roact)local m=require(A.Util)local W=Y.PureComponent:extend("\068\114\097\103\103\101\114")function W.handleInput(Y,A)local W=A.UserInputType local a=W==Enum.UserInputType.MouseButton1 local H=W==Enum.UserInputType.Touch if not Y.CurrentInput and(a or H)then Y.CurrentInput=A local W=m.Maid.new()local X=A.Position local function F(z)local A=z-X Y.props.Move(Vector2.new(A.X,A.Y))X=z end if a then W:giveTasks({z.InputChanged:Connect(function(z)if z.UserInputType==Enum.UserInputType.MouseMovement then F(z.Position)end end),z.InputEnded:Connect(function(z)if z==Y.CurrentInput then W:clean()Y.CurrentInput=nil end end)})elseif H then W:giveTasks({(A:GetPropertyChangedSignal("\080\111\115\105\116\105\111\110")):Connect(function()F(A.Position)end),A:GetPropertyChangedSignal("\085\115\101\114\073\110\112\117\116\083\116\097\116\101",function()local z=A.UserInputState if z==Enum.UserInputState.End or z==Enum.UserInputState.Cancel then W:clean()Y.CurrentInput=nil end end)})end end end function W.render(z)return Y.createElement("\070\114\097\109\101",{Size=z.props.Size;Position=z.props.Position;AnchorPoint=z.props.AnchorPoint,Active=true;BackgroundTransparency=1;[Y.Event.InputBegan]=function(A,Y)z:handleInput(Y)end})end return W
local UserInputService = game:GetService("UserInputService")

local Packages = script:FindFirstAncestor("CmdrAdditions").Packages

local Roact = require(Packages.Roact)
local Util = require(Packages.Util)

local Dragger = Roact.PureComponent:extend("Dragger")

function Dragger:handleInput(input)
	local userInputType = input.UserInputType

	local isMouse = userInputType == Enum.UserInputType.MouseButton1
	local isTouch = userInputType == Enum.UserInputType.Touch

	if not self.CurrentInput and (isMouse or isTouch) then
		self.CurrentInput = input

		local maid = Util.Maid.new()

		local lastPosition = input.Position
		local function updatePosition(position)
			local deltaPosition = position - lastPosition
			self.props.Move(Vector2.new(deltaPosition.X, deltaPosition.Y))
			lastPosition = position
		end
		
		if isMouse then
			maid:giveTasks({
				UserInputService.InputChanged:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseMovement then
						updatePosition(input.Position)
					end
				end),

				UserInputService.InputEnded:Connect(function(input)
					if input == self.CurrentInput then
						maid:clean()
						self.CurrentInput = nil
					end
				end)
			})
		elseif isTouch then
			maid:giveTasks({
				input:GetPropertyChangedSignal("Position"):Connect(function()
					updatePosition(input.Position)
				end),

				input:GetPropertyChangedSignal("UserInputState", function()
					local userInputState = input.UserInputState
	
					if
						userInputState == Enum.UserInputState.End
						or userInputState == Enum.UserInputState.Cancel
					then
						maid:clean()
						self.CurrentInput = nil
					end
				end)
			})
		end
	end
end

function Dragger:render()
	return Roact.createElement("Frame", {
		Size = self.props.Size,
		Position = self.props.Position,
		AnchorPoint = self.props.AnchorPoint,

		Active = true,
		BackgroundTransparency = 1,

		[Roact.Event.InputBegan] = function(_, input)
			self:handleInput(input)
		end
	})
end

return Dragger