-----------------------------------------------------------------------
-----------------------------------------------------------------------
-------------------------- KATTAJ1 - TTAJ1bl4 -------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------

require "ISUI/ISInventoryPaneContextMenu"

local USMPrestrictEquippedOptions = {}

function USMPrestrictEquippedOptions.apply(player, context, items)
    -- print("OnFillInventoryObjectContextMenu event triggered")

    local specificItems = {
        -- Military Backpack Pocket Small
            
        -- Military Backpack Strategist Medium
        "Base.USMP_Backpack_Strategist_Medium_UCP",
        "Base.USMP_Backpack_Strategist_Medium_UCP_Tight",
        "Base.USMP_Backpack_Strategist_Medium_OCP",
        "Base.USMP_Backpack_Strategist_Medium_OCP_Tight",
    
        -- Military Backpack Ranger Large
        "Base.USMP_Backpack_Ranger_Large_UCP",
        "Base.USMP_Backpack_Ranger_Large_UCP_Tight",
        "Base.USMP_Backpack_Ranger_Large_OCP",
        "Base.USMP_Backpack_Ranger_Large_OCP_Tight",
    
        -- Military Backpack Colossus VeryLarge
        "Base.USMP_Backpack_Colossus_VeryLarge_UCP",
        "Base.USMP_Backpack_Colossus_VeryLarge_UCP_Tight",
        "Base.USMP_Backpack_Colossus_VeryLarge_OCP",
        "Base.USMP_Backpack_Colossus_VeryLarge_OCP_Tight",
    
        -- Military Backpack Echo Radio
        "Base.USMP_Backpack_Echo_Radio_UCP",
        "Base.USMP_Backpack_Echo_Radio_UCP_Tight",
        "Base.USMP_Backpack_Echo_Radio_OCP",
        "Base.USMP_Backpack_Echo_Radio_OCP_Tight",

        -- Military_BagLeg_MagSecure_Small
        "Base.USMP_BagLeg_MagSecure_Small_UCP_Left",
        "Base.USMP_BagLeg_MagSecure_Small_UCP_Right",
        "Base.USMP_BagLeg_MagSecure_Small_UCP_ArmorLeft",
        "Base.USMP_BagLeg_MagSecure_Small_UCP_ArmorRight",
        "Base.USMP_BagLeg_MagSecure_Small_OCP_Left",
        "Base.USMP_BagLeg_MagSecure_Small_OCP_Right",
        "Base.USMP_BagLeg_MagSecure_Small_OCP_ArmorLeft",
        "Base.USMP_BagLeg_MagSecure_Small_OCP_ArmorRight",

        -- Military_BagLeg_Utility_Medium
        "Base.USMP_BagLeg_Utility_Medium_UCP_Left",
        "Base.USMP_BagLeg_Utility_Medium_UCP_Right",
        "Base.USMP_BagLeg_Utility_Medium_UCP_ArmorLeft",
        "Base.USMP_BagLeg_Utility_Medium_UCP_ArmorRight",
        "Base.USMP_BagLeg_Utility_Medium_OCP_Left",
        "Base.USMP_BagLeg_Utility_Medium_OCP_Right",
        "Base.USMP_BagLeg_Utility_Medium_OCP_ArmorLeft",
        "Base.USMP_BagLeg_Utility_Medium_OCP_ArmorRight"
    }

    local commonContextOptions = {
        "ContextMenu_Wear",
        "ContextMenu_Equip_on_your_Back",
        "ContextMenu_AttachPouchToHipLeft",
        "ContextMenu_AttachPouchToHipRight",
        "ContextMenu_AttachPouchToHipLeftOnArmor",
        "ContextMenu_AttachPouchToHipRightOnArmor"
    }


    for i, v in ipairs(items) do
        local testItem = v
        if not instanceof(v, "InventoryItem") then
            testItem = v.items[1]
        end

        if instanceof(testItem, "InventoryItem") and testItem:isEquipped() then
            local itemType = testItem:getFullType()
            if table.contains(specificItems, itemType) then
                for _, contextOption in ipairs(commonContextOptions) do
                    context:removeOptionByName(getText(contextOption))
                end

                local restrictedMessage = context:addOption("Unequip this item to access wear options.", nil)
                restrictedMessage.notAvailable = true
            end
        end
    end
end

Events.OnFillInventoryObjectContextMenu.Add(USMPrestrictEquippedOptions.apply)

function table.contains(table, element)
    for _, value in pairs(table) do
        if value == element then
            return true
        end
    end
    return false
end






