local addonName, ns = ...
local ApiVault = ns

ApiVault.Header = ApiVault.Header or {}
local Header = ApiVault.Header

local function createText(parent, template)
    local fs = parent:CreateFontString(nil, "OVERLAY", template or "GameFontNormal")
    fs:SetJustifyH("LEFT")
    fs:SetJustifyV("TOP")
    return fs
end

function Header:Render(panel, parent, title, description, badges, topOffset)
    local y = topOffset or -18
    local titleText = createText(parent, "GameFontHighlightLarge")
    titleText:SetPoint("TOPLEFT", parent, "TOPLEFT", 20, y)
    titleText:SetText(tostring(title or "ApiVault"))
    if panel and panel.Add then panel:Add(parent, titleText) end

    local desc = createText(parent, "GameFontDisable")
    desc:SetPoint("TOPLEFT", titleText, "BOTTOMLEFT", 0, -8)
    desc:SetPoint("RIGHT", parent, "RIGHT", -20, 0)
    desc:SetText(tostring(description or ""))
    if panel and panel.Add then panel:Add(parent, desc) end

    local badge = ApiVault.PolicyBadge and ApiVault.PolicyBadge:Create(parent, badges) or createText(parent, "GameFontNormalSmall")
    if not ApiVault.PolicyBadge then badge:SetText("[INSPECT-ONLY]") end
    badge:SetPoint("TOPLEFT", parent, "TOPLEFT", 20, y - 44)
    if panel and panel.Add then panel:Add(parent, badge) end

    return titleText, desc, badge
end
