local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local LevelCurse = ____isaac_2Dtypescript_2Ddefinitions.LevelCurse
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____constants = require("core.constants")
local UI_HEART_WIDTH = ____constants.UI_HEART_WIDTH
local VectorZero = ____constants.VectorZero
local ____vector = require("functions.vector")
local copyVector = ____vector.copyVector
function ____exports.getScreenBottomRightPos(self)
    local screenWidth = Isaac.GetScreenWidth()
    local screenHeight = Isaac.GetScreenHeight()
    return Vector(screenWidth, screenHeight)
end
--- In the options menu, players have the ability to set a HUD offset (which gets written to the
-- `HudOffset` attribute in the "options.ini" file). This function uses the current HUD offset to
-- generate a vector that should be added to the corresponding position that you want to draw a UI
-- element at.
-- 
-- For example:
-- - If the user does not have a HUD offset configured, this function will return `Vector(0, 0)`.
-- - If the user has a HUD offset of 1.0 configured, this function will return `Vector(20, 12)`.
function ____exports.getHUDOffsetVector(self)
    local hudOffset = math.floor(Options.HUDOffset * 10)
    if hudOffset < 1 or hudOffset > 10 then
        return copyVector(nil, VectorZero)
    end
    local x = hudOffset * 2
    local y = hudOffset
    if y >= 4 then
        y = y + 1
    end
    if y >= 9 then
        y = y + 1
    end
    return Vector(x, y)
end
--- Returns how many hearts are in the heart UI row. If the player has more than 6 hearts, this
-- function will return 6.
function ____exports.getHeartRowLength(self, player)
    local maxHearts = player:GetMaxHearts()
    local soulHearts = player:GetSoulHearts()
    local boneHearts = player:GetBoneHearts()
    local brokenHearts = player:GetBrokenHearts()
    local combinedHearts = maxHearts + soulHearts + boneHearts * 2 + brokenHearts * 2
    local heartRowLength = combinedHearts / 2
    return math.min(heartRowLength, 6)
end
--- Helper function to get the width of the first player's hearts on the UI. This is useful for
-- drawing UI elements to the right of where the player's hearts are. Make sure to use this in
-- combination with the `getHUDOffsetVector` helper function.
function ____exports.getHeartsUIWidth(self)
    local level = game:GetLevel()
    local curses = level:GetCurses()
    local player = Isaac.GetPlayer()
    local extraLives = player:GetExtraLives()
    local effects = player:GetEffects()
    local hasHolyMantleEffect = effects:HasCollectibleEffect(CollectibleType.HOLY_MANTLE)
    local heartRowLength = ____exports.getHeartRowLength(nil, player)
    if hasHolyMantleEffect then
        heartRowLength = heartRowLength + 1
    end
    if curses == LevelCurse.UNKNOWN then
        heartRowLength = 1
    end
    local width = heartRowLength * UI_HEART_WIDTH
    if extraLives > 9 then
        width = width + 20
        if player:HasCollectible(CollectibleType.GUPPYS_COLLAR) then
            width = width + 6
        end
    elseif extraLives > 0 then
        width = width + 16
        if player:HasCollectible(CollectibleType.GUPPYS_COLLAR) then
            width = width + 4
        end
    end
    return width
end
function ____exports.getScreenBottomCenterPos(self)
    local bottomRightPos = ____exports.getScreenBottomRightPos(nil)
    return Vector(bottomRightPos.X / 2, bottomRightPos.Y)
end
function ____exports.getScreenBottomLeftPos(self)
    local bottomRightPos = ____exports.getScreenBottomRightPos(nil)
    return Vector(0, bottomRightPos.Y)
end
function ____exports.getScreenBottomY(self)
    local bottomRightPos = ____exports.getScreenBottomRightPos(nil)
    return bottomRightPos.Y
end
function ____exports.getScreenCenterPos(self)
    local bottomRightPos = ____exports.getScreenBottomRightPos(nil)
    return bottomRightPos / 2
end
function ____exports.getScreenRightX(self)
    local bottomRightPos = ____exports.getScreenBottomRightPos(nil)
    return bottomRightPos.X
end
function ____exports.getScreenTopCenterPos(self)
    local bottomRightPos = ____exports.getScreenBottomRightPos(nil)
    return Vector(bottomRightPos.X / 2, 0)
end
function ____exports.getScreenTopLeftPos(self)
    return copyVector(nil, VectorZero)
end
function ____exports.getScreenTopRightPos(self)
    local bottomRightPos = ____exports.getScreenBottomRightPos(nil)
    return Vector(bottomRightPos.X, 0)
end
--- Get how many hearts are currently being shown on the hearts UI.
-- 
-- This function is originally from piber20 Helper.
function ____exports.getVisibleHearts(self, player)
    local effectiveMaxHearts = player:GetEffectiveMaxHearts()
    local soulHearts = player:GetSoulHearts()
    local boneHearts = player:GetBoneHearts()
    local maxHearts = math.max(effectiveMaxHearts, boneHearts * 2)
    local visibleHearts = math.ceil((maxHearts + soulHearts) / 2)
    if visibleHearts < 1 then
        visibleHearts = 1
    end
    return visibleHearts
end
return ____exports
