$(document).ready(function () {

  showSideMapData();
  showBarData('all');
  showSuicideData('all');
  showHorizontal('all');

  var ctx = document.getElementById("donutChart");
  var myChart = new Chart(ctx, {
    type: "doughnut",
    data: {
      labels: ["NO", "YES"],
      datasets: [
        {
          label: "# of Tomatoes",
          data: [12, 19],
          backgroundColor: ["rgb(252, 178, 22)", "rgb(118, 192, 67)"],
          /*borderColor: ["rgb(255,105,51)", "rgb(43,158,25)"],*/
          borderWidth: 1,
        },
      ],
    },
    options: {
      //cutoutPercentage: 40,
      responsive: true,
      title: {
        //display: true,

      },
    },
  });


  //   linechart
  var sexualArray = [];
  var domesticArray = [];
  var otherArray = [];
  var humanArray = [];
  var dowryArray = [];
  var monthArray = [];

  $.ajax({
    url: 'returnGbvArray.php',
    type: 'get',
    data: "{}",
    async: false,

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

      sexualArray = result[0];
      domesticArray = result[1];
      otherArray = result[2];
      humanArray = result[3];
      dowryArray = result[4];
      monthArray = result[5];

    },

    error: function (xmlHttpRequest, textStatus, errorThrown) {
      // alert(errorThrown);
      // alert(textStatus);

    }
  });

  
  var ctx = document.getElementById("lineChart").getContext("2d");

  var myChart = new Chart(ctx, {
    type: "line",
    data: {
      labels: monthArray,
      datasets: [
        {
          label: "Domestic GBV", // Name the series
          data: domesticArray, // Specify the data values array
          fill: false,
          borderColor: "#11D58D",
          backgroundColor: "#11D58D", // Add custom color background (Points and Fill)
          borderWidth: 2, // Specify bar border width
        },
        {
          label: "Gender Based human Traficking", // Name the series
          data: humanArray, // Specify the data values array
          fill: false,
          borderColor: "#0E086E",
          backgroundColor: "#0E086E", // Add custom color background (Points and Fill)
          borderWidth: 2, // Specify bar border width
        }, {
          label: "Dispute Over Dowry", // Name the series
          data: dowryArray, // Specify the data values array
          fill: false,
          borderColor: "#DAA520",
          backgroundColor: "#DAA520", // Add custom color background (Points and Fill)
          borderWidth: 2, // Specify bar border width
        },
        {
          label: "Rape/Sexual GBV", // Name the series
          data: sexualArray, // Specify the data values array
          fill: false,
          borderColor: "#5A409B", // Add custom color border (Line)
          backgroundColor: "#5A409B", // Add custom color background (Points and Fill)
          borderWidth: 2, // Specify bar border width
        },

        {
          label: "Other GBV", // Name the series
          data: otherArray, // Specify the data values array
          fill: false,
          borderColor: "rgb(149, 187, 215)", // Add custom color border (Line)
          backgroundColor: "rgb(149, 187, 215)", // Add custom color background (Points and Fill)
          borderWidth: 2, // Specify bar border width
        },
      ],
    },
  });
  // 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 showSideMapData() {
  //var datas = data;
  //alert("hailu");
  $("#mapRight").load('allSideMapData.php', {});
}


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

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

}

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

  });

}

function showHorizontal(data) {
  //alert(data);
  var datas = data;
  $("#provinceChartHere").load('showProvinceIncidents.php?data=' + datas, {

  });

}

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

}

