-- @author DoomTero 2026
-- @copyright 2026 DoomTero - ZomboRut original work. ref:33faa785
-- @license Proprietary. Not licensed for reuse, redistribution or derivative works without written permission from DoomTero. Ask - permission is obtainable. See ZomboRut/LICENSE.txt

local ZR_MenuUtil = {}

function ZR_MenuUtil.findOnTilesAndNeighbors(worldobjects, which, predicate)
	for i = 1, #worldobjects do
		local obj = worldobjects[i]
		if predicate(obj) then return obj end
	end
	for i = 1, #worldobjects do
		local obj = worldobjects[i]
		local sq = obj and obj.getSquare and obj:getSquare()
		local cell = sq and sq:getCell()
		if sq and cell then
			local x, y, z = sq:getX(), sq:getY(), sq:getZ()
			for dx = -1, 1 do
				for dy = -1, 1 do
					local s = cell:getGridSquare(x + dx, y + dy, z)
					if s then
						if which ~= "moving" then
							local statics = s:getStaticMovingObjects()
							if statics then
								for j = 0, statics:size() - 1 do
									local m = statics:get(j)
									if predicate(m) then return m end
								end
							end
						end
						if which ~= "static" then
							local moving = s:getMovingObjects()
							if moving then
								for j = 0, moving:size() - 1 do
									local m = moving:get(j)
									if predicate(m) then return m end
								end
							end
						end
					end
				end
			end
		end
	end
	return nil
end

function ZR_MenuUtil.banditsAvailable()
	return Bandit ~= nil and BanditCustom ~= nil and BanditBrain ~= nil
end

ZR_MenuUtil.ICON_DIR = "media/ui/ContextMenu/"

function ZR_MenuUtil.icon(option, name)
	if option and name then
		option.iconTexture = getTexture(ZR_MenuUtil.ICON_DIR .. name .. ".png")
	end
	return option
end

local SCENE_LABEL_KEYS = {
	["Defeat Punch"]            = "ContextMenu_ZR_Scene_DefeatPunch",
	["Defeat BJ"]               = "ContextMenu_ZR_Scene_DefeatBJ",
	["Defeat Lunge"]            = "ContextMenu_ZR_Scene_DefeatLunge",
	["Defeat Lesbian Face Sit"] = "ContextMenu_ZR_Scene_DefeatLesbianFaceSit",
	["Defeat Forced Cowgirl"]   = "ContextMenu_ZR_Scene_DefeatForcedCowgirl",
	["BJ"]                      = "ContextMenu_ZR_Scene_BJ",
	["Cowgirl"]                 = "ContextMenu_ZR_Scene_Cowgirl",
	["Drag Subdued"]            = "ContextMenu_ZR_Scene_DragSubduedZombie",
	["Holding"]                 = "ContextMenu_ZR_Scene_Holding",
	["Standing Doggy"]          = "ContextMenu_ZR_Scene_StandingDoggy",
	["Sprinter Takedown"]       = "ContextMenu_ZR_Scene_SprinterTakedown",
}

function ZR_MenuUtil.sceneLabel(label)
	if not label then return label end
	local key = SCENE_LABEL_KEYS[label]
	if not key then return label end
	return getTextOrNull(key) or label
end

return ZR_MenuUtil
