require "TimedActions/ISStartVehicleEngine"

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

local function StartRepairAction(playerObj, vehicle)
    ISTimedActionQueue.add(ISStartPanzerRepairAction:new(playerObj, vehicle))
end

local function SwitchAutoBalance(player, vehicle)
    if vehicle:getSeat(player) == 0 then
        if vehicle:getModData().AutoBalance then
            vehicle:getModData().AutoBalance = false
            player:Say(getText("IGUI_AutoBalanceOn"))
        else
            vehicle:getModData().AutoBalance = true
            player:Say(getText("IGUI_AutoBalanceOff"))
        end
    end
end

local function SwitchLight(player, vehicle)
    if vehicle:getSeat(player) == 0 then
        if vehicle:getModData().NightLight then
            vehicle:getModData().NightLight = false
            player:Say(getText("IGUI_LightOn"))
        else
            vehicle:getModData().NightLight = true
            player:Say(getText("IGUI_LightOff"))
        end
    end
end

local ISVehicleMenu_showRadialMenu_old = ISVehicleMenu.showRadialMenu
function ISVehicleMenu.showRadialMenu(player)
    ISVehicleMenu_showRadialMenu_old(player)
    local vehicle = player:getVehicle()
    if (vehicle and GetHeliType(vehicle)) then
        local menu = getPlayerRadialMenu(player:getPlayerNum())
        if HeliList[GetHeliType(vehicle)].BasicResearch then
            for i = 1, #HeliList[GetHeliType(vehicle)].BasicResearch do
                local research = HeliList[GetHeliType(vehicle)].BasicResearch[i]
                local modData = vehicle:getModData().researchTable
                if not modData then
                    modData = {}
                end
                modData[research] = true
                vehicle:getModData().researchTable = modData
            end
        end
        if vehicle:getSeat(player) == 0 then
            if HeliList[GetHeliType(vehicle)].ResearchUI then
                local texture1 = getTexture("media/textures/ActiveAntiZombie.png")
                menu:addSlice(getText("IGUI_OpenReacherPanel"), texture1, OpenHeliUpdate, player, vehicle)
            end
            local texture2 = getTexture("media/textures/UI/cd_98_main_rotor.png")
            menu:addSlice(getText("IGUI_AutoBalance"), texture2, SwitchAutoBalance, player, vehicle)
            if HasUnlockThisReasearch(vehicle, "NightLight") then
                local texture2 = getTexture("media/textures/UI/LaserWeapon.png")
                menu:addSlice(getText("IGUI_SwitchLight"), texture2, SwitchLight, player, vehicle)
            end
        end
        if HeliList[GetHeliType(vehicle)].CanSelfRepair then
            local texture2 = getTexture("media/textures/ActiveRepair.png")
            menu:addSlice(getText("IGUI_StartRepairAction"), texture2, StartRepairAction, player, vehicle)
        end
    end
end

