import * as NativeUI from '../libs/NativeUI';
const Menu = NativeUI.Menu;
const UIMenuItem = NativeUI.UIMenuItem;
const UIMenuListItem = NativeUI.UIMenuListItem;
const UIMenuCheckboxItem = NativeUI.UIMenuCheckboxItem;
const UIMenuSliderItem = NativeUI.UIMenuSliderItem;
const BadgeStyle = NativeUI.BadgeStyle;
const Point = NativeUI.Point;
const ItemsCollection = NativeUI.ItemsCollection;
const Color = NativeUI.Color;
const ListItem = NativeUI.ListItem;

export default function planeSchoolHandle(globalData: IGlobalData) {

    var keyBound = false;
    var mainMenu: NativeUI.Menu;
    let send = new UIMenuItem("Pruefung starten", "");
    var timer;
    var timerCheckpoint;
    var timerSet = false;
    var Player;
    var timeToWait = 0;
    var checkPoint;
    var counter = 0;
    var waitFinished = false;

    mp.events.add('planeSchoolMenu', () => {
        mp.game.ui.setTextComponentFormat('STRING');
        mp.game.ui.addTextComponentSubstringPlayerName('Drücke ~INPUT_CONTEXT~, um das Flugschulmenü zu öffnen');
        mp.game.ui.displayHelpTextFromStringLabel(0, true, true, -1);
        mp.keys.bind(0x45, false, keyPressHandler);
        keyBound = true;
    });

    mp.events.add('removeplaneSchoolMenu', () => {
        
        mp.game.ui.clearHelp(true);
        if (mainMenu != null) {
            mainMenu.Close();
        }

        if (keyBound) {
            keyBound = false;
            mp.keys.unbind(0x45, false, keyPressHandler);
        }
    });

    mp.events.add('waitPlayerEntersVehicle1', () => {
        timerSet = true;
        timer = setInterval(timerPlayerInVehicle1, 3000);
    });

    mp.events.add('stopTimer', () => {
        timerSet = false;
        clearInterval(timer);
    });
    
    function timerPlayerInVehicle1() {
        if (timerSet) {
            mp.events.callRemote('timerCheckVehicle1');
        }
    };

    function keyPressHandler() {
        if (globalData.InChat || globalData.InMenu) return;

        mp.events.call('removeplaneSchoolMenu', false);
        mp.events.callRemote('startplaneSchool');
    }
}