/**
 * @overview Life of German Reallife - Player Keys keys.js
 * @author VegaZ
 * @copyright (c) 2008 - 2018 Life of German
 */

//https://docs.microsoft.com/de-de/windows/desktop/inputdev/virtual-key-codes

import { Key } from '../game';
import KeyBinder from 'ragemp-better-bindings';

export default function keys(globalData: IGlobalData) {
    var showGui = true;

    //ENTER
    mp.keys.bind(0x0D, false, function () {
        if (globalData.InChat) {
            globalData.InChat = false;
        }
    });

    //LEFT ARROW (Interaktion mit anderen Spielern)
    mp.keys.bind(0x25, false, function () {
        if (!globalData.InChat && !globalData.InMenu && !globalData.InTuning) {
            mp.events.callRemote("keyPress:LEFT_ARROW");
        }
    });

    //UP ARROW (Interaktion mit Spielwelt)
    mp.keys.bind(0x26, false, function () {
        if (!globalData.InChat && !globalData.InMenu && !globalData.InTuning) {
            mp.events.callRemote("keyPress:UP_ARROW");
        }
    });

    //RIGHT ARROW (Fraktionsinteraktion)
    mp.keys.bind(0x27, false, function () {
        if (!globalData.InChat && !globalData.InMenu && !globalData.InTuning) {
            mp.events.callRemote("keyPress:RIGHT_ARROW");
        }
    });

    //F7 //Unshowalles
    mp.keys.bind(0x76, false, function () {
        if (showGui === true) {
            showGui = false;
            mp.events.call("toggleUi", false);
        } else {
            showGui = true;
            mp.events.call("toggleUi", true);
        }
    });

    //NUM2 //Save Blips in Edit Mode
    mp.keys.bind(0x62, false, function () {
        if (!globalData.InChat) {
            mp.events.callRemote("keyPress:NUM2");
        }
    });

    //NUM5 //Fraktionsinteraktion (Tasks sortieren)
    //mp.keys.bind(0x65, false, function () {
    //    if (!globalData.InChat && globalData.Interaction) {
    //        mp.events.call("sortFactionTasks", true);
    //    }
    //});

    //E
    mp.keys.bind(0x45, false, function () {
        if (!globalData.InChat) {
            mp.events.callRemote("keyPress:E");
        }
    });

    //I //Inventar
    mp.keys.bind(0x49, false, function () {
        if (!globalData.InChat && !globalData.InTuning) {
            mp.events.callRemote("keyPress:I");
        }
    });

    //O //Spielerliste
    mp.keys.bind(0x4F, true, function () {
        if (!globalData.InChat && !globalData.InTuning) {
            mp.events.callRemote("keyPress:O");
            //mp.events.call("showPlayerlist");
        }
    });

    //K //Dienstkleidung
    mp.keys.bind(0x4B, false, function () {
        if (!globalData.InChat && !globalData.InMenu) {
            mp.events.callRemote("keyPress:K");
        }
    });

    //L //Türen auf / zuschließen
    mp.keys.bind(0x4C, false, function () {
        if (!globalData.InChat) {
            mp.events.callRemote("keyPress:L");
        }
    });

    //M (Interaktionsmenü)
    mp.keys.bind(0x4D, false, function () {
        if (!globalData.InChat && !globalData.InTuning && !globalData.InMenu) {
            mp.events.callRemote("keyPress:M");
        }
    });

    //N //Motor Starten
    mp.keys.bind(0x4E, false, function () {
        if (!globalData.InChat) {
            mp.events.callRemote("keyPress:N");
        }
    });

    //T
    mp.keys.bind(0x54, false, function () {
        if (!globalData.InChat && !globalData.InTuning && !globalData.InMenu) {
            globalData.InChat = true;
        }
    });

    //Z // Fahrzeug Verwaltung - Menü
    KeyBinder.bind("z", () => {
        if (!globalData.InChat && !globalData.InTuning) {
            mp.events.callRemote("keyPress:Z");
        }
    });

    //J // Job Starten
    mp.keys.bind(0x4A, false, () => {
        if (!globalData.InChat && globalData.LoggedIn && !globalData.InTuning) {
            //mp.events.callRemote("CLIENT:JobManager_ShowJobMenu");
            mp.events.callRemote("keyPress:J");
        }
    });

    mp.keys.bind(0x7A, false, () => {
        mp.gui.takeScreenshot(new Date().toLocaleTimeString() + ".png", 1, 100, 80);
    });

    KeyBinder.bind("ctrl+h", () => {
        mp.events.callRemote("keyPress:ControllH"); //hup
        return;
    });

    //F2 //Noclip
    mp.keys.bind(0x71, false, () => {
        mp.events.callRemote("Noclip");
    });
}