local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local Map = ____lualib.Map
local __TS__New = ____lualib.__TS__New
local __TS__Iterator = ____lualib.__TS__Iterator
local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local Keyboard = ____isaac_2Dtypescript_2Ddefinitions.Keyboard
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local ____decorators = require("decorators")
local Exported = ____decorators.Exported
local ____input = require("functions.input")
local isKeyboardPressed = ____input.isKeyboardPressed
local ____DefaultMap = require("classes.DefaultMap")
local DefaultMap = ____DefaultMap.DefaultMap
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
____exports.CustomHotkeys = __TS__Class()
local CustomHotkeys = ____exports.CustomHotkeys
CustomHotkeys.name = "CustomHotkeys"
__TS__ClassExtends(CustomHotkeys, Feature)
function CustomHotkeys.prototype.____constructor(self)
    Feature.prototype.____constructor(self)
    self.staticHotkeyFunctionMap = __TS__New(Map)
    self.dynamicHotkeyFunctionMap = __TS__New(Map)
    self.keyPressedMap = __TS__New(DefaultMap, false)
    self.postRender = function()
        for ____, ____value in __TS__Iterator(self.staticHotkeyFunctionMap) do
            local keyboard = ____value[1]
            local triggerFunc = ____value[2]
            self:checkIfTriggered(keyboard, triggerFunc)
        end
        for ____, ____value in __TS__Iterator(self.dynamicHotkeyFunctionMap) do
            local keyboardFunc = ____value[1]
            local triggerFunc = ____value[2]
            local keyboard = keyboardFunc(nil)
            if keyboard ~= nil then
                self:checkIfTriggered(keyboard, triggerFunc)
            end
        end
    end
    self.callbacksUsed = {{ModCallback.POST_RENDER, self.postRender}}
end
function CustomHotkeys.prototype.checkIfTriggered(self, keyboard, triggerFunc)
    local isPressed = isKeyboardPressed(nil, keyboard)
    local wasPreviouslyPressed = self.keyPressedMap:getAndSetDefault(keyboard)
    self.keyPressedMap:set(keyboard, isPressed)
    if isPressed and not wasPreviouslyPressed then
        triggerFunc(nil)
    end
end
function CustomHotkeys.prototype.setConditionalHotkey(self, getKeyFunc, triggerFunc)
    if self.dynamicHotkeyFunctionMap:has(getKeyFunc) then
        error("Failed to register a hotkey due to a custom hotkey already being defined for the submitted function.")
    end
    self.dynamicHotkeyFunctionMap:set(getKeyFunc, triggerFunc)
end
__TS__DecorateLegacy({Exported}, CustomHotkeys.prototype, "setConditionalHotkey", true)
function CustomHotkeys.prototype.setHotkey(self, keyboard, triggerFunc)
    if self.staticHotkeyFunctionMap:has(keyboard) then
        error(((("Failed to register a hotkey due to a hotkey already being defined for: Keyboard." .. Keyboard[keyboard]) .. " (") .. tostring(keyboard)) .. ")")
    end
    self.staticHotkeyFunctionMap:set(keyboard, triggerFunc)
end
__TS__DecorateLegacy({Exported}, CustomHotkeys.prototype, "setHotkey", true)
function CustomHotkeys.prototype.unsetConditionalHotkey(self, getKeyFunc)
    if not self.dynamicHotkeyFunctionMap:has(getKeyFunc) then
        error("Failed to unregister a hotkey since there is no existing hotkey defined for the submitted function.")
    end
    self.dynamicHotkeyFunctionMap:delete(getKeyFunc)
end
__TS__DecorateLegacy({Exported}, CustomHotkeys.prototype, "unsetConditionalHotkey", true)
function CustomHotkeys.prototype.unsetHotkey(self, keyboard)
    if not self.staticHotkeyFunctionMap:has(keyboard) then
        error(((("Failed to unregister a hotkey since there is no existing hotkey defined for: Keyboard." .. Keyboard[keyboard]) .. " (") .. tostring(keyboard)) .. ")")
    end
    self.staticHotkeyFunctionMap:delete(keyboard)
end
__TS__DecorateLegacy({Exported}, CustomHotkeys.prototype, "unsetHotkey", true)
return ____exports
