/* Coded by L1ghtM3n@protonmail.com */

$(document).ready(function() {
     // Init dropdowns
     var elems = document.querySelectorAll(".dropdown-trigger");
     var instances = M.Dropdown.init(elems, {"coverTrigger": false, "closeOnClick": false});

    // Get GDP data from table
    let gdpData = {};
    var table = document.getElementById("stats_table");
    for (var i = 0, row; row = table.rows[i]; i++) {
        var iso = row.cells[1].innerHTML;
        var count = row.cells[3].innerHTML;
        if (iso.length == 2) {
            gdpData[iso] = count;
        }
    }
    // Init map
    $("#world-map").vectorMap({
        map: "world_mill",
        series: {
        regions: [{
            values: gdpData,
            scale: ["#ffc8d3", "#ff7c96"],
            normalizeFunction: "polynomial"
        }]},
            onRegionTipShow: function(e, el, code) {
            if (gdpData[code] == undefined) {
                gdpData[code] = 0
            }
            el.html(el.html() + " (Reports counts : " + gdpData[code] + ")");
        }
    });

    // Init navbar
    $(".sidenav").sidenav();
});

