{% extends 'base.html' %}
{% block title %}Requests{% endblock %}
{% block content %}
    <div>
        <ul class="nav nav-pills nav-pills-spacer" id="tabs">
            {% if access_user_request_allowed_exist and facility_managers_exist %}
                <li class="{% if tab == 'access' %}active{% endif %}">
                    <a href="#access-requests" onclick="window.location = '{% url "user_requests" "access" %}'">{{ access_requests_title }}
                        {% if temporary_access_notification_count %}
                            <span class="badge badge-tab-top">{{ temporary_access_notification_count }}</span>
                        {% endif %}
                    </a>
                </li>
            {% endif %}
            {% if buddy_system_areas_exist %}
                <li class="{% if tab == 'buddy' %}active{% endif %}">
                    <a href="#buddy-requests" onclick="window.location = '{% url "user_requests" "buddy" %}'">{{ buddy_requests_title }}
                        {% if buddy_notification_count %}
                            <span class="badge badge-tab-top">{{ buddy_notification_count }}</span>
                        {% endif %}
                    </a>
                </li>
            {% endif %}
        </ul>
    </div>
    <div class="tab-content">
        {% if access_user_request_allowed_exist and facility_managers_exist %}
            <div class="tab-pane {% if tab == 'access' %}active{% endif %}" id="access-requests">
                {# This will be loaded asynchronously #}
            </div>
        {% endif %}
        {% if buddy_system_areas_exist %}
	        <div class="tab-pane {% if tab == 'buddy' %}active{% endif %}" id="buddy-requests">
                {# This will be loaded asynchronously #}
            </div>
        {% endif %}
    </div>
    <script>
        $("#tabs").find("a").click(switch_tab);

        function load_buddy_board()
        {
            let failure_dialog = ajax_complete_callback("Unable to load buddy requests", "There was a problem looking up buddy requests.");
            $("#buddy-requests").load("{% url 'buddy_requests' %}", undefined, failure_dialog);
        }
        function load_access_requests()
        {
            let failure_dialog = ajax_complete_callback("Unable to load access requests", "There was a problem loading access requests.");
            $("#access-requests").load("{% url 'access_requests' %}", undefined, failure_dialog);
        }
        {% if tab == 'buddy' %}load_buddy_board();{% endif %}
        {% if tab == 'access' %}load_access_requests();{% endif %}
    </script>
{% endblock %}