local MAJOR, MINOR = "LibMatic-FontPack-1.0", 1
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

function lib:Register(addon, embed)
    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
