local MAJOR, MINOR = "LibMatic-FontPack-1.0", 2
assert(LibStub, MAJOR .. " requires LibStub")
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end

local LSM = LibStub("LibSharedMedia-3.0", true)

local DEFAULT_EMBED = "Libs\\LibMatic\\"

lib.fonts = {
    { name = "Level Up", file = "Levelup.ttf" },
}

function lib:GetPath(addon, file, embed)
    embed = embed or DEFAULT_EMBED
    if embed ~= "" and embed:sub(-1) ~= "\\" then embed = embed .. "\\" end
    return "Interface\\AddOns\\" .. addon .. "\\" .. embed .. "Fonts\\" .. file
end

function lib:GetBasePath(addon, embed)
    embed = embed or DEFAULT_EMBED
    if embed ~= "" and embed:sub(-1) ~= "\\" then embed = embed .. "\\" end
    return "Interface\\AddOns\\" .. addon .. "\\" .. embed .. "Fonts\\"
end

-- The pack's fonts carry Latin glyphs only: on a non-English client they
-- render as empty boxes, so registration is a no-op everywhere but English
-- and those clients keep the game's own shipped fonts.
local english = type(GetLocale) == "function"
    and (GetLocale() == "enUS" or GetLocale() == "enGB") or false

function lib:Register(addon, embed)
    if not english then return 0 end
    if not LSM then LSM = LibStub("LibSharedMedia-3.0", true) end
    if not LSM or type(addon) ~= "string" or addon == "" then return 0 end
    local count = 0
    for _, entry in ipairs(self.fonts) do
        local path = self:GetPath(addon, entry.file, embed)
        LSM:Register("font", entry.name, path)
        count = count + 1
        if entry.aliases then
            for _, alias in ipairs(entry.aliases) do
                LSM:Register("font", alias, path)
                count = count + 1
            end
        end
    end
    return count
end
