{% extends "wagtailadmin/generic/base.html" %}
{% load i18n static wagtailadmin_tags %}

{% block extra_css %}
    {{ block.super }}
    {{ filter_form.media.css }}
    <link rel="stylesheet" href="{% static 'djinsight/wagtail/css/analytics.css' %}" type="text/css" />
{% endblock %}

{% block main_content %}
    {% block dji_filters %}
        {% include "djinsight/wagtail/reports/partials/_filters.html" %}
    {% endblock %}

    {% block dji_summary %}
        {% include "djinsight/wagtail/reports/partials/_summary.html" %}
    {% endblock %}

    {% block dji_chart %}
        {% include "djinsight/wagtail/reports/partials/_chart.html" %}
    {% endblock %}

    {% block dji_traffic_devices %}
        {% include "djinsight/wagtail/reports/partials/_traffic_devices.html" %}
    {% endblock %}

    {% block dji_table %}
        {% include "djinsight/wagtail/reports/partials/_table.html" %}
    {% endblock %}
{% endblock %}

{% block extra_js %}
    {{ block.super }}
    {{ filter_form.media.js }}
    <script src="{% static 'djinsight/wagtail/js/chart.min.js' %}"></script>
    {% block dji_extra_js %}
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        var periodSelect = document.getElementById('id_period');
        if (periodSelect) {
            periodSelect.addEventListener('change', function() {
                if (this.value !== 'custom') {
                    var df = document.getElementById('id_date_from');
                    var dt = document.getElementById('id_date_to');
                    if (df) df.value = '';
                    if (dt) dt.value = '';
                    this.form.submit();
                }
            });
        }
    });
    </script>
    {% endblock %}
{% endblock %}
