-- TooltipOverlay.lua
-- Global tooltip renderer - Build 42 safe

require "InspectSystem/UI/UIThemes/Inspect_UIThemeRegistry"

TooltipOverlay = TooltipOverlay or {
    text = nil
}

function TooltipOverlay.render()
    if not TooltipOverlay.text or TooltipOverlay.text == "" then return end

    local text = TooltipOverlay.text

    -- Global mouse position
    local mx = getMouseX()
    local my = getMouseY()

    local padding = 6
    local font = UIFont.Small

    local tw = getTextManager():MeasureStringX(font, text)
    local th = getTextManager():getFontHeight(font)

    local x = mx + 12
    local y = my + 12
    local w = tw + padding * 2
    local h = th + padding * 2

    local t = InspectUI_GetTheme and InspectUI_GetTheme() or nil
    local bg = (t and t.panelBg) or {0, 0, 0, 0.92}
    local border = (t and t.border) or {0.75, 0.75, 0.75, 0.9}
    local textColor = (t and t.text) or {1, 1, 1, 1}

    ISUIElement.drawRectStatic(x, y, w, h, bg[4], bg[1], bg[2], bg[3])
    ISUIElement.drawRectBorderStatic(x, y, w, h, border[4], border[1], border[2], border[3])
    ISUIElement.drawTextStatic(text, x + padding, y + padding, textColor[1], textColor[2], textColor[3], textColor[4], font)
end

Events.OnPostUIDraw.Add(TooltipOverlay.render)
