require "TimedActions/ISStartVehicleEngine"

local function OpenTigerUpdate(player, vehicle)
    local vehicle = player:getVehicle()
    local maxY = getCore():getScreenHeight()
    local maxX = getCore():getScreenWidth()
    local ui = ISPanzerUpdate:new((maxX - 751) / 2, (maxY - 550) / 2, 751, 550, player, vehicle)
    ui:initialise()
    ui:addToUIManager()
end

local function OpenCrewLevel(player, vehicle)
    local vehicle = player:getVehicle()
    local maxY = getCore():getScreenHeight()
    local maxX = getCore():getScreenWidth()
    local ui = ISPanzerCrewLevel:new((maxX - 840) / 2, (maxY - 350) / 2, 840, 350, player, vehicle)
    ui:initialise()
    ui:addToUIManager()
end

local function EnableGunLight(player, vehicle)
    local modData = vehicle:getModData()
    if not modData.enableGunLight then
        modData.enableGunLight = true
    else
        modData.enableGunLight = false
    end
end

local function CrewLeaderShutUp(player, vehicle)
    local modData = vehicle:getModData()
    if not modData.CrewLeaderShutUp then
        modData.CrewLeaderShutUp = true
    else
        modData.CrewLeaderShutUp = false
    end
end
local function StartRepairAction(playerObj, vehicle)
    local vehicleBack = vehicle:getPartById("TruckBed")
    local inv = playerObj:getInventory()
    ISTimedActionQueue.add(ISStartPanzerRepairAction:new(playerObj, vehicle))
end

local ISVehicleMenu_showRadialMenu_old = ISVehicleMenu.showRadialMenu
function ISVehicleMenu.showRadialMenu(player)
    ISVehicleMenu_showRadialMenu_old(player)
    local vehicle = player:getVehicle()
    if (vehicle and GetPanzerType(vehicle)) then
        local menu = getPlayerRadialMenu(player:getPlayerNum())
        if vehicle:getSeat(player) == 0 then

            local texture1 = getTexture("media/textures/ActiveAntiZombie.png")
            menu:addSlice(getText("IGUI_OpenReacherPanel"), texture1, OpenTigerUpdate, player, vehicle)
            local texture2 = getTexture("media/textures/UI/AutoMG.png")
            menu:addSlice(getText("IGUI_OpenPanzerCrewPanel"), texture2, OpenCrewLevel, player, vehicle)
            local texture2 = getTexture("media/textures/UI/ShutUp.png")
            menu:addSlice(getText("IGUI_CrewLeaderShutUp"), texture2, CrewLeaderShutUp, player, vehicle)
            if HasUnlockThisReasearch(vehicle, "TurretLight") then
                local texture2 = getTexture("media/textures/UI/TurretLight.png")
                menu:addSlice(getText("IGUI_EnableGunLight"), texture2, EnableGunLight, player, vehicle)
            end
        end
        if PanzerList[GetPanzerType(vehicle)].CanSelfRepair then
            local texture2 = getTexture("media/textures/ActiveRepair.png")
            menu:addSlice(getText("IGUI_StartRepairAction"), texture2, StartRepairAction, player, vehicle)
        end
        if player:isNPC() then
            return
        end
        local vehicle = ISVehicleMenu.getVehicleToInteractWith(player)
        if not vehicle then
            return
        end
        local vehicleName = vehicle:getScript():getFullName()
        if not vehicleName then
            return
        end

    end
end
