/**
 * @overview Life of German Reallife - Gui Playerlist playerlist.js
 * @author VegaZ. Siga.
 * @copyright (c) 2008 - 2018 Life of German
 */

export default function playerList(globalData: GlobalData): void {

    var playerlistBrowser: BrowserMp = null;
    var pList;

    mp.events.add("showPlayerlist", (playersJson) => {
        
        if (playerlistBrowser !== null) {
            playerlistBrowser.destroy();
            playerlistBrowser = null;
            globalData.InInput = false;
            mp.gui.cursor.show(false, false);
            mp.gui.chat.activate(true);         
        }
        else if (!globalData.InInput) {
            globalData.InInput = true;
            playerlistBrowser = mp.browsers.new('package://assets/html/Playerlist/Tabliste.html');
            mp.gui.chat.activate(false);
            mp.gui.cursor.show(true, true);
            pList = JSON.parse(playersJson);
            pList.forEach((player) => {
                playerlistBrowser.execute(`ad_row('${JSON.stringify(player.Id)}','${JSON.stringify(player.Name)}',0,0,'${JSON.stringify(player.Ping)}');`);
            });
        }                    
    });

    mp.events.add("CEF:fetchPlayerList", () => {
        
    });
}

//function getTable() {
//    var table = "";
//    pList.forEach((player) => {
//        var tableRow = "<tr><td>" + player.Id + "</td><td>" + player.Name + "</td><td>" + player.Ping + "</td>";
//        table = table + tableRow;
//    })
//    return document.write(table);
//}