local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__ArrayFind = ____lualib.__TS__ArrayFind
local ____exports = {}
local getNewLazarus
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local PlayerType = ____isaac_2Dtypescript_2Ddefinitions.PlayerType
local ____players = require("functions.players")
local getPlayersOfType = ____players.getPlayersOfType
local isTaintedLazarus = ____players.isTaintedLazarus
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
function getNewLazarus(self, oldLazarus)
    local oldCharacter = oldLazarus:GetPlayerType()
    local newCharacter
    if oldCharacter == PlayerType.LAZARUS_B then
        newCharacter = PlayerType.LAZARUS_2_B
    elseif oldCharacter == PlayerType.LAZARUS_2_B then
        newCharacter = PlayerType.LAZARUS_B
    else
        return nil
    end
    local playersOfType = getPlayersOfType(nil, newCharacter)
    return __TS__ArrayFind(
        playersOfType,
        function(____, player) return player.FrameCount == oldLazarus.FrameCount end
    )
end
local v = {run = {usedFlipAtLeastOnce = false}}
____exports.FlipDetection = __TS__Class()
local FlipDetection = ____exports.FlipDetection
FlipDetection.name = "FlipDetection"
__TS__ClassExtends(FlipDetection, Feature)
function FlipDetection.prototype.____constructor(self, postFlip, postFirstFlip)
    Feature.prototype.____constructor(self)
    self.v = v
    self.postUseItemFlip = function(____, _collectibleType, _rng, player, _useFlags, _activeSlot, _customVarData)
        if not isTaintedLazarus(nil, player) then
            return nil
        end
        local newLazarus = getNewLazarus(nil, player)
        if newLazarus == nil then
            return nil
        end
        if not v.run.usedFlipAtLeastOnce then
            v.run.usedFlipAtLeastOnce = true
            self.postFirstFlip:fire(newLazarus, player)
        end
        self.postFlip:fire(newLazarus, player)
        return nil
    end
    self.callbacksUsed = {{ModCallback.POST_USE_ITEM, self.postUseItemFlip, {CollectibleType.FLIP}}}
    self.postFlip = postFlip
    self.postFirstFlip = postFirstFlip
end
return ____exports
