<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal">&times;</button>
	<h4 class="modal-title">{{ reservation.reservation_item }} reservation details</h4>
</div>
<div class="modal-body">
	{% if reservation.short_notice %}
		<div class="alert alert-danger">{{ facility_name }} staff were not given sufficient notice to configure this tool. There is no guarantee that this tool will be configured properly at time of use.</div>
	{% endif %}
	{% if reservation.missed %}
		<div class="alert alert-danger">This reservation was automatically removed from the calendar due to {{ reservation.reservation_item_type.value }} inactivity.</div>
	{% endif %}

	{% if user.is_staff %}
		<div class="input-group">
			<span class="input-group-addon">
				Title
			</span>
			<input type="text" id="title" class="form-control" placeholder="{{ reservation.user }}" maxlength="200" value="{{ reservation.title }}">
			<span class="input-group-btn">
				<button type="button" class="btn btn-success" data-dismiss="modal" onclick="$('#dialog').one('hidden.bs.modal', function() { set_reservation_title('{% url 'set_reservation_title' reservation.id %}', {{ reservation.id }}, $('#title').val()) })">Set title</button>
			</span>
		</div>
	{% elif reservation.title %}
		Title: {{ reservation.title }}<br>
	{% endif %}

	User: <a title="Click to email this user" href="{% url 'get_email_form_for_user' reservation.user.id %}">{{ reservation.user }}</a><br>
	Created by: {{ reservation.creator }}<br>
	Created on: {{ reservation.creation_time }}<br>
	{% if reservation.tool %}
		Tool: <a title="Click to go to the tool control page for this tool" href="{% url 'tool_control' reservation.tool.id %}">{{ reservation.tool }}</a><br>
	{% elif reservation.area %}
		Area: {{ reservation.area }}<br>
	{% endif %}
	{% if reservation.project %}
		<div id="reservation_project">
			Project: {{ reservation.project }}
			{% if reservation_project_can_be_changed %}<span class="glyphicon glyphicon-pencil pull-right" title="Change the project" onclick="$('#reservation_project').hide();$('#reservation_change_project').show();"></span>{% endif %}
			<br>
		</div>
		{% if reservation_project_can_be_changed %}
			<div class="input-group" id="reservation_change_project" style="display: none">
				<span class="input-group-addon">
					Project
				</span>
				<select id="change_project" name="project" class="form-control">
					{% for p in reservation.user.active_projects %}
						<option value="{{ p.id }}" {% if reservation.project.id == p.id %}selected{% endif %}>{{ p }}</option>
					{% endfor %}
				</select>
				<span class="input-group-btn">
					<button type="button" class="btn btn-success" data-dismiss="modal" onclick="$('#dialog').one('hidden.bs.modal', function() { change_reservation_project('{% url 'change_reservation_project' reservation.id %}', $('#change_project').val()) })">Change project</button>
				</span>
			</div>
		{% endif %}
	{% endif %}
	Start: {{ reservation.start }}<br>
	End: {{ reservation.end }}<br>
	Identifier: {{ reservation.id }}<br>
    {% if reservation.question_data_json.items %}
        Reservation questions:
        <ul style="margin-bottom: 0">
        {% for question_name, data in reservation.question_data_json.items %}
            {% if data.type == 'group' %}
                <li>{{ data.title }}{% if data.title|slice:"-1:" != ":" %}:{% endif %}</li>
                <ul style="margin-bottom: 0">
                {% for number, data_input in data.user_input.items %}
                    <li><span>{{ number }}:</span></li>
                    <ul style="margin-bottom: 0">
                        {% for name, input in data_input.items %}
                            <li><span style="margin-left: 15px">{{ name }}: {{ input|linebreaksbr }}</span></li>
                        {% endfor %}
                    </ul>
                {% endfor %}
                </ul>
            {% else %}
                <li>{{ data.title }}: {{ data.user_input|linebreaksbr }}</li>
            {% endif %}
        {% endfor %}
        </ul>
    {% endif %}
	{% if reservation.self_configuration %}
		{{ reservation.user }} has opted to perform the tool configuration.<br>
	{% endif %}
	{% if reservation.additional_information %}
		Additional information:<br>
		{{ reservation.additional_information|linebreaksbr }}
	{% endif %}
</div>
{# Allow the user to cancel the reservation if they have that priviledge. #}
{% if not reservation.missed and not reservation.cancelled %}
	{% if reservation.user.id == user.id and reservation.has_not_ended or user.is_staff %}
		<div class="modal-footer">
			{# You must provide a reason if you are cancelling someone else's reservation. #}
			{% if reservation.user == user %}
				<button type="button" class="btn btn-danger" data-dismiss="modal" onclick="$('#dialog').one('hidden.bs.modal', function() { cancel_reservation('{% url 'cancel_reservation' reservation.id %}', 'Reservation {{ reservation.id }}') })">Cancel this reservation</button>
			{% else %}
				<div class="input-group">
					<input type="text" id="reason" class="form-control" placeholder="Reason for cancellation (required)" maxlength="3000">
					<span class="input-group-btn">
						<button type="button" class="btn btn-danger" data-dismiss="modal" onclick="$('#dialog').one('hidden.bs.modal', function() { cancel_reservation('{% url 'cancel_reservation' reservation.id %}', 'Reservation {{ reservation.id }}', $('#reason').val()) })">Cancel this reservation</button>
					</span>
				</div>
				<script>
					autofocus("#reason");
				</script>
			{% endif %}
		</div>
	{% endif %}
{% endif %}