{% extends 'base.html' %}
{% load training_tags %}
{% block title %}{{ requests_page_title }}{% endblock %}
{% block extrahead %}
    {# For training requests #}
    {% load static %}
    <script type="text/javascript" src="{% static "datetimepicker/bootstrap-datetimepicker.js" %}"></script>
    <link rel="stylesheet" type="text/css" href="{% static "datetimepicker/bootstrap-datetimepicker.css" %}" />
{% endblock %}
{% block content %}
    <div class="clearfix" style="margin-top: 0;">
        <ul class="nav nav-pills nav-pills-spacer"
            id="tabs"
            style="display: inline-block;
                   float: right;
                   margin-bottom: 15px">
            {% if access_user_request_allowed_exist and facility_managers_exist %}
                <li class="{% if tab == 'access' %}active{% endif %}">
                    <a href="#access-requests" onclick="location.href = '{% 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="location.href = '{% 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 %}
            {% if adjustment_request_allowed and facility_managers_exist %}
                <li class="{% if tab == 'adjustment' %}active{% endif %}">
                    <a href="#adjustment-requests" onclick="location.href = '{% url "user_requests" "adjustment" %}'">{{ adjustment_requests_title }}
                        {% if adjustment_notification_count %}
                            <span class="badge badge-tab-top">{{ adjustment_notification_count }}</span>
                        {% endif %}
                    </a>
                </li>
            {% endif %}
            {% if training_show_in_user_requests %}
                <li class="{% if tab == 'training' %}active{% endif %}">
                    {% if user|is_trainer %}
                        <a href="#training-requests" onclick="location.href = '{% url "user_requests" "training" %}'">Training
                            {% if training_request_notification_count %}
                                <span class="badge badge-tab-top">{{ training_request_notification_count }}</span>
                            {% endif %}
                        </a>
                    {% else %}
                        <a href="#training-requests" onclick="location.href = '{% url "training_requests" %}'">Training
                            {% if training_invitation_notification_count %}
                                <span class="badge badge-tab-top">{{ training_invitation_notification_count }}</span>
                            {% endif %}
                        </a>
                    {% endif %}
                </li>
            {% endif %}
            {% if staff_assistance_request_allowed %}
                <li class="{% if tab == 'staff_assistance' %}active{% endif %}">
                    <a href="#staff-assistance-requests"
                       onclick="location.href = '{% url "user_requests" "staff_assistance" %}'">{{ staff_assistance_requests_title }}
                        {% if staff_assistance_notification_count %}
                            <span class="badge badge-tab-top">{{ staff_assistance_notification_count }}</span>
                        {% endif %}
                    </a>
                </li>
            {% endif %}
        </ul>
        <h1 class="pull-left" style="margin-top: 0;margin-right: 20px">
            {% if tab == 'access' %}
                {{ access_requests_title }}
            {% elif tab == 'buddy' %}
                {{ buddy_requests_title }}
            {% elif tab == 'adjustment' %}
                {{ adjustment_requests_title }}
            {% elif tab == 'training' %}
                Training requests
            {% elif tab == 'staff_assistance' %}
                {{ staff_assistance_requests_title }}
            {% else %}
                Requests
            {% endif %}
        </h1>
    </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 %}
        {% if adjustment_request_allowed and facility_managers_exist %}
            <div class="tab-pane{% if tab == 'adjustment' %} active{% endif %}" id="adjustment-requests">
                {# This will be loaded asynchronously #}
            </div>
        {% endif %}
        {% if training_show_in_user_requests %}
            <div class="tab-pane{% if tab == 'training' %} active{% endif %}" id="training-requests">
                {# This will be loaded asynchronously #}
            </div>
        {% endif %}
        {% if staff_assistance_request_allowed %}
            <div class="tab-pane{% if tab == 'staff_assistance' %} active{% endif %}" id="staff-assistance-requests">
                {# This will be loaded asynchronously #}
            </div>
        {% endif %}
    </div>
    {# For training tab	#}
    {% include 'snippets/confirm_action_modal.html' %}
    <script>
        $("#tabs").find("a").click(switch_tab);

        let general_failure_callback = ajax_failure_callback("There was an error processing your request")

        function load_buddy_board()
        {
            show_spinner();
            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()
        {
            show_spinner();
            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);
        }
        function load_adjustment_requests()
        {
            show_spinner();
            let failure_dialog = ajax_complete_callback("Unable to load adjustment requests", "There was a problem loading adjustment requests.");
            $("#adjustment-requests").load("{% url 'adjustment_requests' %}", undefined, failure_dialog);
        }
        function load_training_requests()
        {
            show_spinner();
            let failure_dialog = ajax_complete_callback("Unable to load training requests", "There was a problem loading training requests.");
            $("#training-requests").load("{% url 'schedule_training_events_ajax' %}?{{ request.META.QUERY_STRING|safe }}", undefined, failure_dialog);
        }
        function load_staff_assistance_requests()
        {
            show_spinner();
            let failure_dialog = ajax_complete_callback("Unable to load staff assistance requests", "There was a problem looking up staff assistance requests.");
            $("#staff-assistance-requests").load("{% url 'staff_assistance_requests' %}", undefined, failure_dialog);
        }

        $(function ()
        {
            {% if tab == 'buddy' %}load_buddy_board();{% endif %}
            {% if tab == 'access' %}load_access_requests();{% endif %}
            {% if tab == 'adjustment' %}load_adjustment_requests();{% endif %}
            {% if tab == 'staff_assistance' %}load_staff_assistance_requests();{% endif %}
			{% if tab == 'training' %}load_training_requests();{% endif %}
        });
    </script>
{% endblock %}
