local ____lualib = require("lualib_bundle")
local Set = ____lualib.Set
local __TS__New = ____lualib.__TS__New
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local EntityGridCollisionClass = ____isaac_2Dtypescript_2Ddefinitions.EntityGridCollisionClass
local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local ____ISCFeature = require("enums.ISCFeature")
local ISCFeature = ____ISCFeature.ISCFeature
local ____ModCallbackCustom = require("enums.ModCallbackCustom")
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
local ____SlotDestructionType = require("enums.SlotDestructionType")
local SlotDestructionType = ____SlotDestructionType.SlotDestructionType
local ____slots = require("functions.slots")
local isSlotMachine = ____slots.isSlotMachine
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
local v = {room = {destroyedSlotSet = __TS__New(Set)}}
____exports.SlotDestroyedDetection = __TS__Class()
local SlotDestroyedDetection = ____exports.SlotDestroyedDetection
SlotDestroyedDetection.name = "SlotDestroyedDetection"
__TS__ClassExtends(SlotDestroyedDetection, Feature)
function SlotDestroyedDetection.prototype.____constructor(self, postSlotDestroyed, roomHistory)
    Feature.prototype.____constructor(self)
    self.v = v
    self.postEntityRemoveSlot = function(____, entity)
        local slot = entity
        if self.roomHistory:isLeavingRoom() then
            return
        end
        if isSlotMachine(nil, slot) then
            self:postEntityRemoveSlotMachine(slot)
        else
            self:postEntityRemoveBeggar(slot)
        end
    end
    self.postSlotUpdate = function(____, slot)
        local ptrHash = GetPtrHash(slot)
        local alreadyDestroyed = v.room.destroyedSlotSet:has(ptrHash)
        if alreadyDestroyed then
            return
        end
        self:checkDestroyedFromCollisionClass(slot)
    end
    self.featuresUsed = {ISCFeature.ROOM_HISTORY}
    self.callbacksUsed = {{ModCallback.POST_ENTITY_REMOVE, self.postEntityRemoveSlot, {EntityType.SLOT}}}
    self.customCallbacksUsed = {{ModCallbackCustom.POST_SLOT_UPDATE, self.postSlotUpdate}}
    self.postSlotDestroyed = postSlotDestroyed
    self.roomHistory = roomHistory
end
function SlotDestroyedDetection.prototype.postEntityRemoveSlotMachine(self, slot)
    self.postSlotDestroyed:fire(slot, SlotDestructionType.COLLECTIBLE_PAYOUT)
end
function SlotDestroyedDetection.prototype.postEntityRemoveBeggar(self, slot)
    local sprite = slot:GetSprite()
    local animation = sprite:GetAnimation()
    local slotDestructionType = animation == "Teleport" and SlotDestructionType.COLLECTIBLE_PAYOUT or SlotDestructionType.NORMAL
    self.postSlotDestroyed:fire(slot, slotDestructionType)
end
function SlotDestroyedDetection.prototype.checkDestroyedFromCollisionClass(self, slot)
    if slot.GridCollisionClass == EntityGridCollisionClass.GROUND then
        local ptrHash = GetPtrHash(slot)
        v.room.destroyedSlotSet:add(ptrHash)
        self.postSlotDestroyed:fire(slot, SlotDestructionType.NORMAL)
    end
end
return ____exports
