--- @author DoomTero 2026

require "ISUI/ISContextMenu"
require "ISUI/ISToolTip"
require "ISUI/ISWorldObjectContextMenu"

local ContextMenu = {}

local MENU_MODULES = { "ZLMain" }
local loaded       = {}
local isLoaded     = false

local function ensureLoaded()
	if isLoaded then return end
	for i = 1, #MENU_MODULES do
		loaded[i] = require("ZomboRut/ContextMenu/" .. MENU_MODULES[i])
	end
	isLoaded = true
end

local function build(playerIndex, context, worldobjects, test)
	if test and ISWorldObjectContextMenu.Test then return true end
	if test then return ISWorldObjectContextMenu.setTest() end

	local player = getSpecificPlayer(playerIndex)
	if not player or player:isAsleep() or player:getVehicle() then return end

	ensureLoaded()
	for i = 1, #loaded do
		loaded[i](ContextMenu, player, context, worldobjects)
	end
end

Events.OnPreFillWorldObjectContextMenu.Add(build)

return ContextMenu
