-- PageRegistry.lua
-- Central lookup for standalone window page modules.

local addonName, SinsToolkit = ...

SinsToolkit.UI = SinsToolkit.UI or {}
SinsToolkit.UI.Pages = SinsToolkit.UI.Pages or {}

local PageRegistry = {}
SinsToolkit.UI.Pages.Registry = PageRegistry

local pages = {}
local orderedPageIDs = {}

function PageRegistry:RegisterPage(id, page)
    if type(id) ~= "string" or id == "" then return end
    if type(page) ~= "table" then return end
    if pages[id] then return end

    pages[id] = page
    orderedPageIDs[#orderedPageIDs + 1] = id
end

function PageRegistry:GetPage(id)
    return pages[id]
end

function PageRegistry:GetPages()
    local list = {}
    for _, id in ipairs(orderedPageIDs) do
        list[#list + 1] = pages[id]
    end
    return list
end

function PageRegistry:ShowPage(id)
    for pageID, page in pairs(pages) do
        if pageID == id then
            if page.Show then page:Show() end
        else
            if page.Hide then page:Hide() end
        end
    end
end
