<h2 class="toc">Date picker</h2>

{% apply view_source %}
<div class="daterange-container" class="pull-right bg-light w-100">
  <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
  <span></span>
</div>
<script>
$(function() {
  // initialize daterange
  var start = moment().subtract(29, 'days');
  var end = moment();

  // TODO: rewrite this better
  function cb(start, end) {
    $('.daterange-container span').html(
      start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
  }

  $(".daterange-container").daterangepicker({
    startDate: start,
    endDate: end,
    ranges: {
      'Today': [moment(), moment()],
      'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
      'Last 7 Days': [moment().subtract(6, 'days'), moment()],
      'Last 30 Days': [moment().subtract(29, 'days'), moment()],
      'This Month': [moment().startOf('month'), moment().endOf('month')],
      'Last Month': [moment().subtract(1, 'month').startOf('month'),
        moment().subtract(1, 'month').endOf('month')]
    }
  }, cb)
  cb(start, end)
})
</script>
{% end %}
