-- **************************************************
-- ██████  ██████   █████  ██    ██ ███████ ███    ██ 
-- ██   ██ ██   ██ ██   ██ ██    ██ ██      ████   ██ 
-- ██████  ██████  ███████ ██    ██ █████   ██ ██  ██ 
-- ██   ██ ██   ██ ██   ██  ██  ██  ██      ██  ██ ██ 
-- ██████  ██   ██ ██   ██   ████   ███████ ██   ████
-- **************************************************

local function TryUseSyringe(playerObj, item)
    if not item then return end
    ISInventoryPaneContextMenu.transferIfNeeded(playerObj, item)
    ISTimedActionQueue.add(BB_FAO_ISTimedAction:InjectSyringe(playerObj, item))
end

local function onFillInventoryObjectContextMenu(player, context, items)
    local adrenalineItem = false
    local syringe1Item = false

    local item = nil

    for i = 1, #items do
		if not instanceof(items[i], "InventoryItem") then
			item = items[i].items[1]
		else
			item = items[i]
		end

        if item then
            local itemType = item:getType()
            if itemType == "AdrenalineSyringe" then adrenalineItem = item end
            if itemType == "Syringe1" then syringe1Item = item end
        end
    end

    local playerObj = getPlayer(); if not playerObj then return end

    if adrenalineItem then
        context:addOptionOnTop(getText("ContextMenu_InjectSyringe") .. " " .. adrenalineItem:getName(), playerObj, TryUseSyringe, adrenalineItem)
    end

    if syringe1Item then
        context:addOptionOnTop(getText("ContextMenu_InjectSyringe") .. " " .. syringe1Item:getName(), playerObj, TryUseSyringe, syringe1Item)
    end
end

Events.OnFillInventoryObjectContextMenu.Add(onFillInventoryObjectContextMenu)