$(document).ready(function () {
 showSuicideData('all');
    showHorizontal('all');
    showSideMapData();
    showCivicIncidents('all');
    showBarData('all');
   

    // var ctx = document.getElementById("donutChart");
    // var myChart = new Chart(ctx, {
    //     type: "doughnut",
    //     data: {
    //         labels: ["Yes", "No"],
    //         datasets: [
    //             {
    //                 label: "User Survey Response",
    //                 data: [19, 12],
    //                 backgroundColor: ["#65CBC9", "#00C08B"],
    //                 /*borderColor: ["rgb(255,105,51)", "rgb(43,158,25)"],*/
    //                 borderWidth: 1
    //             },
    //         ],
    //     },
    //     options: {
    //         //cutoutPercentage: 40,
    //         responsive: true,
    //         legend: {
    //            display: false 
    //         },
    //         title: {
    //             //display: true,

    //         },
    //         cutoutPercentage: 90
    //     },
    // });


    //   linechart
   
    // streets - v1

});



var toggler = document.getElementsByClassName("caret");
var i;

for (i = 0; i < toggler.length; i++) {
    toggler[i].addEventListener("click", function () {
        this.parentElement.querySelector(".nested").classList.toggle("active");
        this.classList.toggle("caret-down");
    });
}




function showBarData(data) {
    var datas = data;
    $("#barChartData").load('showBarData.php?code=' + datas, {

    });
   // $("#mapRight").load('allSideMapData.php', {});
   showAllSideMapDataDateWise();
}

function showAllSideMapDataDateWise(){
 var startDate = $("#date-range").data('daterangepicker').startDate.format('YYYY-MM-DD');
    var endDate = $("#date-range").data('daterangepicker').endDate.format('YYYY-MM-DD');

    $("#mapRight").load("allSideMapDataDateWise.php?start_date=" + startDate + "&end_date=" + endDate, {});
}

function showSuicideData(data) {
    //alert(data);
    var datas = data;
    $("#suicideData").load('showSuicideData.php?geography=' + datas, {

    });

}
 function showCivicIncidents(data){
    if(data == 'all'){
$('#civicMonthText').text('Civic Space Related Incidents By Month');
    } else if(data == 'hea'){
$('#civicMonthText').text('Freedom of Expression');
    } else if(data == 'irr'){
$('#civicMonthText').text('Freedom of Association');
    }  else if(data == 'pre'){
$('#civicMonthText').text('Freedom of Assembly');
    }  else if(data == 'lock'){
$('#civicMonthText').text('Solidarity and Diversity');
    }  else if(data == 'qua'){
$('#civicMonthText').text('Dialogue and Consultation');
    }  else if(data == 'rel'){
$('#civicMonthText').text('Personal Safety and Well Being');
    } 
 var civicArray = [];

    $.ajax({
        url: 'returnGbvArray.php',
        type: 'GET',
        data: "type="+data,
        async: false,

        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function (response) {
            //alert(response);
            var result = response;

            civicArray = result[0];
        },

        error: function (xmlHttpRequest, textStatus, errorThrown) {
            // alert(errorThrown);
            // alert(textStatus);
        }
    });
 
    var ctx = document.getElementById("lineChart").getContext("2d");

    var myChart = new Chart(ctx, {
        type: "line",
        options: {
            legend: {
                display: false
            }                
        },
        data: {
		labels:	[
	        "October22",
                "November22",
                "December22",
                "January23",
                "February23",
                "March23",           
               
            ],
            datasets: [
                {
                    label: "Incidents", // Name the series
                    data: civicArray, // Specify the data values array
                    fill: false,
                    borderColor: "#A2D684",
                    backgroundColor: "#A2D684", // Add custom color background (Points and Fill)
                    borderWidth: 2, // Specify bar border width
                },
               
            ],
        },
    });
}
function showHorizontal(data) {
    //alert(data);
    var datas = data;
    $("#provinceChartHere").load('showProvinceIncidents.php?data=' + datas, {

    });

}

function showSideMapData() {
    $("#mapRight").load("allSideMapData.php", {});
}

function printIt() {
    var province = $('#province-select').val();
    var exists = $('#province-select').filter(function () {
        return $(this).val() == province;
    }).length;
    if (!province.length == 1) {
        province = 'all';
    }
    //alert(province);

    var type = $('#data-select').val();
    //alert(type);

    var startDate = $("#date-range").data('daterangepicker').startDate.format('YYYY-MM-DD');
    var endDate = $("#date-range").data('daterangepicker').endDate.format('YYYY-MM-DD');

    //alert(startDate);
    //alert(endDate);

    window.location.replace("showprintdata.php?type=" + type + "&start_date=" + startDate + "&end_date=" + endDate + "&province=" + province);
}



function printMap() {

    alert("niranjan");

    var divToPrint = document.getElementById('map');

    var newWin = window.open('', 'Print-Window');

    newWin.document.open();

    newWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</body></html>');

    newWin.document.close();

    setTimeout(function () {
        newWin.close();
    }, 10);

}


$('#btnPrint').click(function () {
    //document.getElementsByTagName("BODY")[0].style.display = "none";
    //alert(1);
    $(".nonPrint").hide();
    //$("#map").css("height","1270px");
    window.print();
    //$("#map").css("height","635px");
    $(".nonPrint").show();

});
