local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____players = require("functions.players")
local getPlayersWithControllerIndex = ____players.getPlayersWithControllerIndex
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
local v = {run = {usedEsauJrFrame = nil, usedEsauJrControllerIndex = nil, usedEsauJrAtLeastOnce = false}}
____exports.EsauJrDetection = __TS__Class()
local EsauJrDetection = ____exports.EsauJrDetection
EsauJrDetection.name = "EsauJrDetection"
__TS__ClassExtends(EsauJrDetection, Feature)
function EsauJrDetection.prototype.____constructor(self, postEsauJr, postFirstEsauJr)
    Feature.prototype.____constructor(self)
    self.v = v
    self.postUpdate = function()
        local gameFrameCount = game:GetFrameCount()
        if v.run.usedEsauJrFrame == nil or gameFrameCount < v.run.usedEsauJrFrame + 1 then
            return
        end
        v.run.usedEsauJrFrame = nil
        if v.run.usedEsauJrControllerIndex == nil then
            return
        end
        local players = getPlayersWithControllerIndex(nil, v.run.usedEsauJrControllerIndex)
        v.run.usedEsauJrControllerIndex = nil
        local player = players[1]
        if player == nil then
            return
        end
        if not v.run.usedEsauJrAtLeastOnce then
            v.run.usedEsauJrAtLeastOnce = true
            self.postFirstEsauJr:fire(player)
        end
        self.postEsauJr:fire(player)
    end
    self.postUseItemEsauJr = function(____, _collectibleType, _rng, player, _useFlags, _activeSlot, _customVarData)
        local gameFrameCount = game:GetFrameCount()
        v.run.usedEsauJrFrame = gameFrameCount + 1
        v.run.usedEsauJrControllerIndex = player.ControllerIndex
        return nil
    end
    self.callbacksUsed = {{ModCallback.POST_UPDATE, self.postUpdate}, {ModCallback.POST_USE_ITEM, self.postUseItemEsauJr, {CollectibleType.ESAU_JR}}}
    self.postEsauJr = postEsauJr
    self.postFirstEsauJr = postFirstEsauJr
end
return ____exports
