local x=script.Parent.Parent local C=require(x:WaitForChild("\076\097\122\121\076\111\097\100\101\114"))local I=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local N=game:GetService("\082\117\110\083\101\114\118\105\099\101")local X=.0225 local a=Vector3.new(1,-1,1)local O={[Enum.UserInputType.MouseButton1]=true,[Enum.UserInputType.Touch]=true}local q={[Enum.UserInputType.MouseMovement]=true;[Enum.UserInputType.Touch]=true}local c={}c.__index=c c.__type="\068\114\097\103\103\101\114"function c.__tostring(x)return c.__type end function c.new(x)local I=setmetatable({},c)I._Maid=C.Utilities.Maid.new()I._DragBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")I._StartBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")I._StopBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")I.Element=x I.IsDragging=false I.DragChanged=I._DragBind.Event I.DragStart=I._StartBind.Event I.DragStop=I._StopBind.Event init(I)return I end function init(x)local C=x.Element local N=x._Maid local X=x._DragBind local a=Vector3.new()local c N:Mark(x._DragBind)N:Mark(x._StartBind)N:Mark(x._StopBind)N:Mark(C.InputBegan:Connect(function(C)if O[C.UserInputType]then a=C.Position x.IsDragging=true x._StartBind:Fire()local I I=C.Changed:Connect(function()if C.UserInputState==Enum.UserInputState.End or C.UserInputState==Enum.UserInputState.Cancel then if I then I:Disconnect()I=nil x.IsDragging=false x._StopBind:Fire()end end end)end end))N:Mark(C.InputChanged:Connect(function(x)if q[x.UserInputType]then c=x end end))N:Mark(I.InputChanged:Connect(function(I,N)if I==c and x.IsDragging then local x=I.Position-a X:Fire(C,I,x)end end))end function c.Destroy(x)x._Maid:Sweep()x.DragChanged=nil x.DragStart=nil x.DragStop=nil x.Element=nil end return c
-- Meant for internal use, no documentation given

-- CONSTANTS

local GuiLib = script.Parent.Parent
local Lazy = require(GuiLib:WaitForChild("LazyLoader"))

local UIS = game:GetService("UserInputService")
local RUNSERVICE = game:GetService("RunService")

local DEADZONE2 = 0.15^2
local FLIP_THUMB = Vector3.new(1, -1, 1)

local VALID_PRESS = {
	[Enum.UserInputType.MouseButton1] = true;
	[Enum.UserInputType.Touch] = true;
}

local VALID_MOVEMENT = {
	[Enum.UserInputType.MouseMovement] = true;
	[Enum.UserInputType.Touch] = true;
}

-- Class

local DraggerClass = {}
DraggerClass.__index = DraggerClass
DraggerClass.__type = "Dragger"

function DraggerClass:__tostring()
	return DraggerClass.__type
end

-- Public Constructors

function DraggerClass.new(element)
	local self = setmetatable({}, DraggerClass)
	
	self._Maid = Lazy.Utilities.Maid.new()
	self._DragBind = Instance.new("BindableEvent")
	self._StartBind = Instance.new("BindableEvent")
	self._StopBind = Instance.new("BindableEvent")
	
	self.Element = element
	self.IsDragging = false
	self.DragChanged = self._DragBind.Event
	self.DragStart = self._StartBind.Event
	self.DragStop = self._StopBind.Event
	
	init(self)
	
	return self
end

-- Private Methods

function init(self)
	local element = self.Element
	local maid = self._Maid
	local dragBind = self._DragBind
	local lastMousePosition = Vector3.new()
	local dragInput
	
	maid:Mark(self._DragBind)
	maid:Mark(self._StartBind)
	maid:Mark(self._StopBind)
	
	maid:Mark(element.InputBegan:Connect(function(input)
		if (VALID_PRESS[input.UserInputType]) then
			lastMousePosition = input.Position
			self.IsDragging = true
			self._StartBind:Fire()
			
			local inputEndConn; inputEndConn = input.Changed:Connect(function()
				if input.UserInputState == Enum.UserInputState.End or input.UserInputState == Enum.UserInputState.Cancel then
					if inputEndConn then
						inputEndConn:Disconnect()
						inputEndConn = nil
						
						self.IsDragging = false
						self._StopBind:Fire()
					end
				end
			end)
		end
	end))
	
	maid:Mark(element.InputChanged:Connect(function(input)
		if (VALID_MOVEMENT[input.UserInputType]) then
			dragInput = input
		end
	end))
	
	maid:Mark(UIS.InputChanged:Connect(function(input, process)
		if input == dragInput and self.IsDragging then
			local delta = input.Position - lastMousePosition
			dragBind:Fire(element, input, delta)
		end
	end))
	
	--maid:Mark(element.InputBegan:Connect(function(input)
	--	if (VALID_PRESS[input.UserInputType]) then
	--		lastMousePosition = input.Position
	--		self.IsDragging = true
	--		self._StartBind:Fire()
	--	end
	--end))
	
	--maid:Mark(UIS.InputEnded:Connect(function(input)
	--	if (VALID_PRESS[input.UserInputType]) then
	--		self.IsDragging = false
	--		self._StopBind:Fire()
	--	end
	--end))
	
	--maid:Mark(UIS.InputChanged:Connect(function(input, process)
	--	if (self.IsDragging) then
	--		if (VALID_MOVEMENT[input.UserInputType]) then
	--			local delta = input.Position - lastMousePosition
	--			lastMousePosition = input.Position
	--			dragBind:Fire(element, input, delta)
	--		end
	--	end
	--end))
end

-- Public Methods

function DraggerClass:Destroy()
	self._Maid:Sweep()
	self.DragChanged = nil
	self.DragStart = nil
	self.DragStop = nil
	self.Element = nil
end

--

return DraggerClass