local ____lualib = require("lualib_bundle")
local Map = ____lualib.Map
local __TS__New = ____lualib.__TS__New
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local ButtonAction = ____isaac_2Dtypescript_2Ddefinitions.ButtonAction
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local InputHook = ____isaac_2Dtypescript_2Ddefinitions.InputHook
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local ____constants = require("core.constants")
local VectorZero = ____constants.VectorZero
local ____decorators = require("decorators")
local Exported = ____decorators.Exported
local ____entitiesSpecific = require("functions.entitiesSpecific")
local getProjectiles = ____entitiesSpecific.getProjectiles
local getTears = ____entitiesSpecific.getTears
local removeAllProjectiles = ____entitiesSpecific.removeAllProjectiles
local removeAllTears = ____entitiesSpecific.removeAllTears
local ____isaacAPIClass = require("functions.isaacAPIClass")
local isTear = ____isaacAPIClass.isTear
local ____log = require("functions.log")
local logError = ____log.logError
local ____playerCollectibles = require("functions.playerCollectibles")
local useActiveItemTemp = ____playerCollectibles.useActiveItemTemp
local ____playerIndex = require("functions.playerIndex")
local getAllPlayers = ____playerIndex.getAllPlayers
local ____tstlClass = require("functions.tstlClass")
local getTSTLClassName = ____tstlClass.getTSTLClassName
local ____utils = require("functions.utils")
local assertDefined = ____utils.assertDefined
local ____ReadonlySet = require("types.ReadonlySet")
local ReadonlySet = ____ReadonlySet.ReadonlySet
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
local v = {run = {
    isPseudoPaused = false,
    shouldUnpause = false,
    initialDescriptions = __TS__New(Map)
}}
____exports.Pause = __TS__Class()
local Pause = ____exports.Pause
Pause.name = "Pause"
__TS__ClassExtends(Pause, Feature)
function Pause.prototype.____constructor(self, disableInputs)
    Feature.prototype.____constructor(self)
    self.v = v
    self.postUpdate = function()
        if not v.run.isPseudoPaused then
            return
        end
        local firstPlayer = Isaac.GetPlayer()
        useActiveItemTemp(nil, firstPlayer, CollectibleType.PAUSE)
        self:stopTearsAndProjectilesFromMoving()
    end
    self.inputActionGetActionValue = function(____, _entity, _inputHook, buttonAction)
        if buttonAction ~= ButtonAction.SHOOT_RIGHT then
            return
        end
        if not v.run.shouldUnpause then
            return
        end
        v.run.shouldUnpause = false
        return 1
    end
    self.callbacksUsed = {{ModCallback.POST_UPDATE, self.postUpdate}, {ModCallback.INPUT_ACTION, self.inputActionGetActionValue, {InputHook.GET_ACTION_VALUE}}}
    self.disableInputs = disableInputs
end
function Pause.prototype.stopTearsAndProjectilesFromMoving(self)
    local ____array_0 = __TS__SparseArrayNew(table.unpack(getTears(nil)))
    __TS__SparseArrayPush(
        ____array_0,
        table.unpack(getProjectiles(nil))
    )
    local tearsAndProjectiles = {__TS__SparseArraySpread(____array_0)}
    for ____, tearOrProjectile in ipairs(tearsAndProjectiles) do
        do
            local ptrHash = GetPtrHash(tearOrProjectile)
            local initialDescription = v.run.initialDescriptions:get(ptrHash)
            if initialDescription == nil then
                goto __continue9
            end
            tearOrProjectile.Position = initialDescription.position
            tearOrProjectile.PositionOffset = initialDescription.positionOffset
            tearOrProjectile.Velocity = VectorZero
            tearOrProjectile.Height = initialDescription.height
            tearOrProjectile.FallingSpeed = 0
            if isTear(nil, tearOrProjectile) then
                tearOrProjectile.FallingAcceleration = initialDescription.fallingAcceleration
            else
                tearOrProjectile.FallingAccel = initialDescription.fallingAcceleration
            end
        end
        ::__continue9::
    end
end
function Pause.prototype.isPaused(self)
    return v.run.isPseudoPaused
end
__TS__DecorateLegacy({Exported}, Pause.prototype, "isPaused", true)
function Pause.prototype.pause(self)
    if v.run.isPseudoPaused then
        logError("Failed to pseudo-pause the game, since it was already pseudo-paused.")
        return
    end
    v.run.isPseudoPaused = true
    v.run.initialDescriptions:clear()
    local ____array_1 = __TS__SparseArrayNew(table.unpack(getTears(nil)))
    __TS__SparseArrayPush(
        ____array_1,
        table.unpack(getProjectiles(nil))
    )
    local tearsAndProjectiles = {__TS__SparseArraySpread(____array_1)}
    for ____, tearOrProjectile in ipairs(tearsAndProjectiles) do
        local ptrHash = GetPtrHash(tearOrProjectile)
        local initialDescription = {
            position = tearOrProjectile.Position,
            positionOffset = tearOrProjectile.PositionOffset,
            velocity = tearOrProjectile.Velocity,
            height = tearOrProjectile.Height,
            fallingSpeed = tearOrProjectile.FallingSpeed,
            fallingAcceleration = isTear(nil, tearOrProjectile) and tearOrProjectile.FallingAcceleration or tearOrProjectile.FallingAccel
        }
        v.run.initialDescriptions:set(ptrHash, initialDescription)
    end
    local firstPlayer = Isaac.GetPlayer()
    useActiveItemTemp(nil, firstPlayer, CollectibleType.PAUSE)
    local tstlClassName = getTSTLClassName(nil, self)
    assertDefined(nil, tstlClassName, "Failed to get the class name for the pause feature.")
    local whitelist = __TS__New(ReadonlySet, {ButtonAction.MENU_CONFIRM, ButtonAction.CONSOLE})
    self.disableInputs:disableAllInputsExceptFor(tstlClassName, whitelist)
    for ____, player in ipairs(getAllPlayers(nil)) do
        player.ControlsEnabled = false
        player.Velocity = VectorZero
    end
    self:stopTearsAndProjectilesFromMoving()
end
__TS__DecorateLegacy({Exported}, Pause.prototype, "pause", true)
function Pause.prototype.unpause(self)
    if not v.run.isPseudoPaused then
        logError("Failed to pseudo-unpause the game, since it was not already pseudo-paused.")
        return
    end
    v.run.isPseudoPaused = false
    v.run.shouldUnpause = true
    local tstlClassName = getTSTLClassName(nil, self)
    assertDefined(nil, tstlClassName, "Failed to find get the class name for the pause feature.")
    self.disableInputs:enableAllInputs(tstlClassName)
    for ____, player in ipairs(getAllPlayers(nil)) do
        player.ControlsEnabled = true
    end
    removeAllTears(nil)
    removeAllProjectiles(nil)
end
__TS__DecorateLegacy({Exported}, Pause.prototype, "unpause", true)
return ____exports
