-- tests/test_nav_selectors.lua
-- Verifies nav.isActive_<view> and nav.isLeafActive_<view>_<value> selectors
-- generated from NAV_TREE.
dofile("wow_mock.lua")
dofile("../Core/HDGR_SchemeConstants.lua")
dofile("../Core/HDGR_Constants.lua")
dofile("../Core/HDGR_Format.lua")
dofile("../Core/HDGR_Paths.lua")
dofile("../Core/HDGR_Log.lua")
dofile("../Core/HDGR_Memo.lua")
dofile("../Core/HDGR_Store.lua")
dofile("../Core/HDGR_BlizzardEvents.lua")
dofile("../Core/HDGR_Environment.lua")
dofile("../Core/HDGR_Modules.lua")
dofile("../UI/HDGR_Theme.lua")
dofile("../Core/HDGR_Init.lua")
dofile("../UI/HDGR_LayoutConfig.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Decor.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Acquisition.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Recipes.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Warehouse.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Alts.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Mogul.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Styles.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Trainers.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_HouseTab.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Debug.lua")
dofile("../UI/LayoutConfig/HDGR_LayoutConfig_Config.lua")
dofile("../UI/HDGR_Selectors.lua")
dofile("../UI/HDGR_Selectors_Status.lua")

HDG_DB = {}
HDG.Store:LoadFromSavedVariables()

local S = HDG.Selectors
local function assertEq(a, b, l)
    if a ~= b then
        error(l .. ": expected " .. tostring(b) .. ", got " .. tostring(a), 2)
    end
end

local state = HDG.Store:GetState()
-- Warehouse is now its own view (extracted from recipes 2026-05-30); the
-- Crafting children (Recipes/Warehouse) are plain view-leaves, so highlight
-- is view-based (nav.isActive_<view>), not the old rightColumnMode leaf state.
state.account.ui.view = "warehouse"
assertEq(S:Call("nav.isActive_warehouse", state, {}), true,  "warehouse view active")
assertEq(S:Call("nav.isActive_recipes",   state, {}), false, "recipes inactive on warehouse")
assertEq(S:Call("nav.isActive_mogul",     state, {}), false, "parent mogul inactive")
state.account.ui.view = "recipes"
assertEq(S:Call("nav.isActive_recipes",   state, {}), true,  "recipes view active")
assertEq(S:Call("nav.isActive_warehouse", state, {}), false, "warehouse inactive on recipes")

-- Hub lights when a VIEW-leaf child is the active view (Crafting -> Warehouse,
-- a child on its own view). Exercises the nav.tree hub-active fold.
state.account.ui.view = "warehouse"
local tree = S:Call("nav.tree", state, {})
local craftingHub
for _, n in ipairs(tree) do if n.label == "Crafting" then craftingHub = n end end
assertEq(craftingHub ~= nil, true, "Crafting hub present in nav.tree")
assertEq(craftingHub.active, true, "Crafting hub lit when on its Warehouse child view")

print("test_nav_selectors.lua passed")
