local N=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local C=N("\083\105\103\110\097\108")local F={}F.__index=F F.ClassName="\073\110\112\117\116\077\111\100\101"function F.new(N)local h=setmetatable({},F)h._lastEnabled=0 h._valid={}h.Name=N or"\085\110\110\097\109\101\100"h.Enabled=C.new()return h end function F.GetLastEnabledTime(N)return N._lastEnabled end function F.AddKeys(F,N,C)C=C or Enum.KeyCode if type(N)=="\115\116\114\105\110\103"then local C={}for N in N:gmatch("\037\119\043")do table.insert(C,N)end N=C end for N,h in pairs(N)do if type(h)=="\115\116\114\105\110\103"then h=C[h]end F._valid[h]=true end return F end function F.AddInputMode(C,N)for N,F in pairs(N._valid)do C._valid[N]=true end return C end function F.GetKeys(N)local C={}for N,F in pairs(N._valid)do table.insert(C,N)end return C end function F.IsValid(C,N)assert(N,"\077\117\115\116 \115\101\110\100 \105\110 \105\110\112\117\116\084\121\112\101")return C._valid[N]end function F.Enable(N)N._lastEnabled=tick()N.Enabled:Fire()end function F.Evaluate(C,N)if C:IsValid(N.UserInputType)or C:IsValid(N.KeyCode)then C:Enable()end end return F
---  Trace input mode state and trigger changes correctly
-- @classmod InputMode

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local Signal = require("Signal")

local InputMode = {}
InputMode.__index = InputMode
InputMode.ClassName = "InputMode"

function InputMode.new(name)
	local self = setmetatable({}, InputMode)

	self._lastEnabled = 0
	self._valid = {}

	self.Name = name or "Unnamed"

	--- Fires off when the mode is enabled
	-- @signal Enabled
	self.Enabled = Signal.new()

	return self
end

function InputMode:GetLastEnabledTime()
	return self._lastEnabled
end

---
-- @param Keys A string for ease of use, or a table of keys
-- @param [EnumSet] The enum set to pull from. Defaults to KeyCode.
function InputMode:AddKeys(keys, enumSet)
	enumSet = enumSet or Enum.KeyCode

	if type(keys) == "string" then
		local newKeys = {}
		for key in keys:gmatch("%w+") do
			table.insert(newKeys, key)
		end
		keys = newKeys
	end

	for _, key in pairs(keys) do
		if type(key) == "string" then
			key = enumSet[key]
		end

		self._valid[key] = true
	end

	return self
end

function InputMode:AddInputMode(inputMode)
	for key, _ in pairs(inputMode._valid) do
		self._valid[key] = true
	end
	return self
end

function InputMode:GetKeys()
	local keys = {}
	for key, _ in pairs(self._valid) do
		table.insert(keys, key)
	end
	return keys
end

---
-- @param inputType May be a UserInputType or KeyCode
function InputMode:IsValid(inputType)
	assert(inputType, "Must send in inputType")

	return self._valid[inputType]
end

--- Enables the mode
function InputMode:Enable()
	self._lastEnabled = tick()
	self.Enabled:Fire()
end

--- Evaluates the input object, and if it's valid, enables the mode
function InputMode:Evaluate(inputObject)
	if self:IsValid(inputObject.UserInputType) or self:IsValid(inputObject.KeyCode) then
		self:Enable()
	end
end

return InputMode