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

export default function playerList() {

    var playerlistBrowser
    var pList;

    mp.events.add("showPlayerlist", () => {
        if (!playerlistBrowser) {
            playerlistBrowser = mp.browsers.new('package://Gui/playerlist.html');
            mp.gui.chat.activate(false);
            mp.gui.cursor.show(true, true);
        }
    });

    mp.events.add("fetchPlayerList", (playersJson) => {

        pList = JSON.parse(playersJson);

        pList.forEach((player) => {
            mp.gui.chat.push(player.Id + ", " + player.Name + ", " + player.Ping);
        });
    });
}

//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);
//}