-- [[ FonZii by Tillï-Draenor ]]

local fontPath = [[Interface\AddOns\FonZii\BarlowCondensed-Bold.ttf]]

local function Apply()
    -- Core UI & Combat Overhaul
    -- Removed UNIT_NAME_FONT and NAMEPLATE_FONT to prevent 3D flickering/glitches
    STANDARD_TEXT_FONT, DAMAGE_TEXT_FONT, CHATTING_FONT = fontPath, fontPath, fontPath

    -- Classic-Specific Compatibility (Era/SoD/Cata)
    if WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE then
        UIDROPDOWNMENU_DEFAULT_TEXT_FONT = fontPath
        NAMEPLATE_SPELL_CAST_FONT = fontPath
        FRIENDS_FONT = fontPath 
        MORPHEUS_FONT = fontPath 
    end

    -- Global UI Object Scan
    for _, fontObj in pairs(_G) do
        if type(fontObj) == "table" and fontObj.GetFont and fontObj.SetFont then
            -- Skip specific names that cause the "flashing" in the 3D world
            local name = fontObj:GetName()
            if name ~= "UnitNameFont" and name ~= "NamePlateFont" then
                pcall(function()
                    local _, size, flags = fontObj:GetFont()
                    fontObj:SetFont(fontPath, size, flags)
                end)
            end
        end
    end
end

-- Event handler for login
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
    Apply()
    f:UnregisterAllEvents()
end)

-- Reload Friendly Instant Apply
if IsLoggedIn() then Apply() end