-- InventoryPanePrerenderPatch.lua
-- Patches ISInventoryPane prerender for Inventory Tetris B42

local Logger = require("Utils/Logger")
local InventoryPanePrerenderPatch = {}

function InventoryPanePrerenderPatch.apply()
    if not ISInventoryPane or not ISInventoryPane.prerender then
        Logger.error("ISInventoryPane not available")
        return false
    end

    Logger.log("Applying ISInventoryPane prerender patch...")

    -- Store original prerender function
    local og_prerender = ISInventoryPane.prerender
    
    -- Override prerender function
    function ISInventoryPane:prerender()
        og_prerender(self)
        
        -- Hide headers
        self.nameHeader:setVisible(false)
        self.typeHeader:setVisible(false)
        
        -- Draw version text
        if self.parent and self.parent.onCharacter then
            local ourVersion = "B42 Patch " .. (_G.InventoryTetrisPatchConfig and 
                              _G.InventoryTetrisPatchConfig.Version or "v1.0.4")
            
            -- Calculate position for right-aligned text
            local ourVersionWidth = getTextManager():MeasureStringX(UIFont.Small, ourVersion)
            local rightMargin = 8
            
            -- Draw version on the right side
            self:drawText(ourVersion, self.width - ourVersionWidth - rightMargin - 8, 
                         self.height - 18, 0.3, 0.3, 0.3, 0.82, UIFont.Small)
        end
    end

    Logger.success("ISInventoryPane prerender patch applied successfully")
    return true
end

return InventoryPanePrerenderPatch