---@class AddonPrivate
local Private = select(2, ...)

---@class ExpansionUtil
local expansionUtil = {
    expansions = {},
    expansionData = {}
}
Private.ExpansionUtil = expansionUtil

function expansionUtil:RegisterExpansion(expansionData, expansionName)
    tinsert(self.expansions, expansionName)
    self.expansionData[#self.expansions] = expansionData
    Private.UI:UpdateTabs()
end

function expansionUtil:GetExpansion(expansionIndex)
    return self.expansionData[expansionIndex]
end

function expansionUtil:GetExpansionByName(expansionName)
    local index = self:GetExpansionIndex(expansionName)
    if not index then return end
    return self:GetExpansion(index)
end

function expansionUtil:GetExpansionIndex(expansionName)
    for i, name in ipairs(self:GetExpansions()) do
        if name == expansionName then
            return i
        end
    end
end

function expansionUtil:GetExpansions()
    return self.expansions
end

function expansionUtil:InitLibStub()
    local lib = LibStub:NewLibrary("MetaTracker", 1)
    if not lib then return end

    function lib:RegisterExpansion(...)
        expansionUtil:RegisterExpansion(...)
    end
end

function expansionUtil:GetAllExpansions()
    return Private.constants.EXPANSIONS
end

function expansionUtil:GetUnloadedExpansions()
    local unloaded = {}
    for _, expansion in ipairs(self:GetAllExpansions()) do
        if not self:GetExpansionByName(expansion) then
            tinsert(unloaded, expansion)
        end
    end
    if #unloaded == 0 then
        return {"None"}
    end
    return unloaded
end