GuildHelper = GuildHelper or {}

local addon = GuildHelper

addon.Router = addon.Router or {}
addon.Router.views = addon.Router.views or {}

function addon.Router:Register(name, callback)
    self.views[name] = callback
end

function addon.Router:Navigate(name)
    local callback = self.views[name]

    if not callback then
        addon:Debug("Missing route", name)
        return
    end

    addon.Store:GetProfile().ui.selectedView = name

    if InCombatLockdown and InCombatLockdown() then
        if addon.MainFrame then
            addon.MainFrame.pendingRefreshAfterCombat = true
        end
        return
    end

    callback()
end

function addon.Router:GetCurrentView()
    return addon.Store:GetProfile().ui.selectedView or "dashboard"
end
