{% extends 'user-base.html' %}
{% block content %}


<!--cart-->
<div class="row">

  <div class="col-sm-6 col-md-6">
      <div class="card text-white bg-secondary mb-3">
      <div class="card-header"><h5 class="card-title">Google <span><i class="fa fa-google" aria-hidden="true"></i></span></h5></div>
        <div class="card-body">
          <table class="table">
            <tr><td><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Reviews</td> <td>Count</td></tr>
            <tr>
              <td>This month (so far)</td>
              <td>{{ google_this_month }}</td>
            </tr>
            <tr>
              <td>Last month</td>
              <td>{{ google_last_month }}</td>
            </tr>
          </table>
        </div>
      </div>
  </div>

<!--  <div class="col-sm-6 col-md-4">-->
<!--      <div class="card text-white bg-danger mb-3">-->
<!--      <div class="card-header"><h5 class="card-title">Yelp <span><i class="fa fa-yelp" aria-hidden="true"></i></span></h5></div>-->
<!--        <div class="card-body">-->
<!--          <table class="table">-->
<!--            <tr>-->
<!--              <td><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  Total Review</td>-->
<!--              <td>{{ yelp_total }}</td>-->
<!--            </tr>-->
<!--            <tr>-->
<!--              <td><i class="fa fa-line-chart" aria-hidden="true"></i>  Growth</td>-->
<!--              <td>{{ yelp_total_growth }}%</td>-->
<!--            </tr>-->
<!--          </table>-->
<!--        </div>-->
<!--      </div>-->
<!--  </div>-->

  <div class="col-sm-6 col-md-6">
      <div class="card text-white bg-primary mb-3">
      <div class="card-header"><h5 class="card-title">Facebook <span><i class="fa fa-facebook" aria-hidden="true"></i></span></h5></div>
        <div class="card-body">
          <table class="table">
            <tr>
              <td><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Reviews</td> <td>Count</td></tr>
            <tr>
              <td>This month (so far)</td>
              <td>{{ facebook_this_month }}</td>
            </tr>
            <tr>
              <td>Last month</td>
              <td>{{ facebook_last_month }}</td>
            </tr>
          </table>
        </div>
      </div>
  </div>

</div>

<!--    canvas-->
  <canvas class="my-4" id="myChart" width="900" height="300"></canvas>
 </div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js" integrity="sha256-TQq84xX6vkwR0Qs1qH5ADkP+MvH0W+9E7TdHJsoIQiM=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>

<script>
  var ctx = document.getElementById("myChart");
  var location_id = document.getElementById("location_id").value;
  console.log(location_id.value)
  var endpoint = '/user/api/analytics';
  params = {
      "location_id":location_id.trim()
  }
  console.log(params)
  $.ajax({
        type: "get",
        url: endpoint,
        data: params,
        dataType: 'json',
        success: function(data) {
        console.log(data)
          var myBarChart = new Chart(ctx, {
          type: 'bar',
          data: {
              labels: data.label,
              datasets: [
                  {
                    label: 'Google',
                    data: data.google,
                    borderColor: 'rgb(255, 204, 0)',
                    backgroundColor: 'rgb(255, 204, 0)',
                    borderWidth: 1,
                    fill: false
                },
                {
                    label: 'Facebook',
                    data: data.facebook,
                    borderColor: 'rgb(0, 51, 204)',
                    backgroundColor: 'rgb(0, 51, 204)',
                    borderWidth: 1,
                    fill: false
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        display: true,
                        scaleLabel: {
                          display: true,
                          fontSize: 16,
                          fontStyle: 'italic',
                          labelString: 'Total review count'
                        },
                        ticks: {
                            beginAtZero: true,
                            stepSize: 1
                        }
                    }],
                    xAxes: [{
                        display: true,
                            scaleLabel: {
                              display: true,
                              fontSize: 16,
                              fontStyle: 'italic',
                              labelString: 'Day of the month'
                            },
                        gridLines: {
                            drawOnChartArea:false
                        }
                    }]
                },
                title: {
                    display: true,
                    fontSize: 16,
                    text: "Review of this month in all platforms."
                }
            }
        });
    },

    error: function(error_data) {
       console.log(error_data);
    }
  });
</script>
{% endblock %}