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__DecorateLegacy = ____lualib.__TS__DecorateLegacy
local ____exports = {}
local convertRedHeartContainers, removeRedHearts
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local HeartSubType = ____isaac_2Dtypescript_2Ddefinitions.HeartSubType
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local PickupVariant = ____isaac_2Dtypescript_2Ddefinitions.PickupVariant
local ____decorators = require("decorators")
local Exported = ____decorators.Exported
local ____ModCallbackCustom = require("enums.ModCallbackCustom")
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
local ____pickups = require("functions.pickups")
local isRedHeart = ____pickups.isRedHeart
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
function convertRedHeartContainers(self, player, heartSubType)
    local maxHearts = player:GetMaxHearts()
    if maxHearts == 0 then
        return
    end
    player:AddMaxHearts(maxHearts * -1, false)
    repeat
        local ____switch13 = heartSubType
        local ____cond13 = ____switch13 == HeartSubType.SOUL
        if ____cond13 then
            do
                player:AddSoulHearts(maxHearts)
                break
            end
        end
        ____cond13 = ____cond13 or ____switch13 == HeartSubType.BLACK
        if ____cond13 then
            do
                player:AddBlackHearts(maxHearts)
                break
            end
        end
    until true
end
function removeRedHearts(self, player)
    local hearts = player:GetHearts()
    if hearts > 0 then
        player:AddHearts(hearts * -1)
    end
end
____exports.CharacterHealthConversion = __TS__Class()
local CharacterHealthConversion = ____exports.CharacterHealthConversion
CharacterHealthConversion.name = "CharacterHealthConversion"
__TS__ClassExtends(CharacterHealthConversion, Feature)
function CharacterHealthConversion.prototype.____constructor(self)
    Feature.prototype.____constructor(self)
    self.characterHealthReplacementMap = __TS__New(Map)
    self.prePickupCollisionHeart = function(____, pickup, collider)
        if not isRedHeart(nil, pickup) then
            return nil
        end
        local player = collider:ToPlayer()
        if player == nil then
            return nil
        end
        local character = player:GetPlayerType()
        local conversionHeartSubType = self.characterHealthReplacementMap:get(character)
        if conversionHeartSubType == nil then
            return nil
        end
        return false
    end
    self.postPEffectUpdateReordered = function(____, player)
        local character = player:GetPlayerType()
        local conversionHeartSubType = self.characterHealthReplacementMap:get(character)
        if conversionHeartSubType == nil then
            return nil
        end
        convertRedHeartContainers(nil, player, conversionHeartSubType)
        removeRedHearts(nil, player)
    end
    self.callbacksUsed = {{ModCallback.PRE_PICKUP_COLLISION, self.prePickupCollisionHeart, {PickupVariant.HEART}}}
    self.customCallbacksUsed = {{ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED, self.postPEffectUpdateReordered}}
end
function CharacterHealthConversion.prototype.registerCharacterHealthConversion(self, playerType, conversionHeartSubType)
    if self.characterHealthReplacementMap:has(playerType) then
        error(("Failed to register a character of type " .. tostring(playerType)) .. " because there is already an existing registered character with that type.")
    end
    self.characterHealthReplacementMap:set(playerType, conversionHeartSubType)
end
__TS__DecorateLegacy({Exported}, CharacterHealthConversion.prototype, "registerCharacterHealthConversion", true)
return ____exports
