'use strict';

setInterval(() => {
    var last_id = $('#lastip_id').val();

    $.get('hitstat.php', {last_id: last_id})
    .done((n) => {
        if( n.result == true ) {
            var data = n.data,
                last_id = n.last_id;

            for(var i=0; i<data.length; i++) {
                console.log(data[i].ip);
                setTimeout((e) => {
                    console.log(e);
                    var ctr = e.country.toLowerCase(),
                        device = '';
                    if(e.device == "web" || e.device == "desktop" ) {
                        device = "<img src='image/icon-laptop.png' style='height: 15px;'>";
                    }
                    if(e.device == "WAP" || e.device == "android" || e.device == "ios") {
                        device = "<img src='image/icon-cellphone.png' style='height: 15px;'>";
                    }
                    $("#listhits").prepend("<li>"+e.ip+" - <span class=\"flag-icon flag-icon-"+ctr+"\"></span> - "+device+"</li>");
                }, 1000, data[i]);
            }
            
            $("#lastip_id").val(last_id);
        }
    });
    
}, 5000);