local PT = AhUI

PT.fonts = PT.fonts or {}

local function CreateFontObject(name, path, height, flags)
    local obj = CreateFont(name)
    obj:SetFont(path, height, flags)
    return obj
end

PT.fonts.normal = CreateFontObject("AhUI_Font_Normal", "Interface\\AddOns\\AhUI\\fonts\\GothamXNarrow-Medium.ttf", 14, "")
PT.fonts.small  = CreateFontObject("AhUI_Font_Small",  "Interface\\AddOns\\AhUI\\fonts\\GothamXNarrow-Medium.ttf", 12, "")
PT.fonts.title  = CreateFontObject("AhUI_Font_Title",  "Interface\\AddOns\\AhUI\\fonts\\GothamXNarrow-Medium.ttf", 16, "OUTLINE")

function PT:StyleButton(btn, size)
    if not btn or not btn.GetFontString then return end
    local fs = btn:GetFontString()
    if fs and fs.SetFont then
        fs:SetFont(PT.FONT, size or 12, "")
    end
end

function PT:RestyleButtons(frame, size)
    if not frame or not frame.GetChildren then return end
    local function walk(parent)
        if not parent or not parent.GetChildren then return end
        local children = { parent:GetChildren() }
        for _, child in ipairs(children) do
            if child.IsObjectType and child:IsObjectType("Button") and child.GetFontString then
                local fs = child:GetFontString()
                if fs and fs.SetFont then
                    fs:SetFont(PT.FONT, size or 12, "")
                end
            end
            walk(child)
        end
    end
    walk(frame)
end
