{% load edc_dashboard_extras %}
{% load edc_subject_dashboard_extras %}
{% load tz %}
{% load i18n %}

<a name="verify_requisition_identifier"></a>

<div class="panel-group">
	<div class="panel panel-success">
		<div class="panel-heading clearfix"><i class="fas fa-flask fa-fw" aria-hidden="true"></i> Requisitions
		<label class="small pull-right" title="visit report datetime">{{ appointment.object.visit.report_datetime|localtime|date:"SHORT_DATETIME_FORMAT" }}</label>
		</div>

		{% requisition_panel_actions requisitions %}

 		<div class="table-responsive">
			<table class="table table-striped table-hover">
				<tbody>

					{% for requisition in requisitions %}

				    	<tr>
				    		<td>
								<span class="text{% if requisition.entry_status == NOT_REQUIRED %} text-muted small{% endif %}">
								  <input type="checkbox" name="selected_panel_names" id="selected_panel_names" value="{{ requisition.panel_name }}" form="form_requisition_print_actions" {% if requisition.entry_status == NOT_REQUIRED %}disabled{% endif %}>
	                              {{ forloop.counter }}.&nbsp;
	                        	</span>
	                            {% if requisition.entry_status == NOT_REQUIRED %}
	                                <span class="text text-muted small">
                                	{{ requisition.object.panel_display_name }}
	                                </span>
                                {% else %}
                                	<span class="text text-default">{{ requisition.object.panel_display_name }} {{requisition.object.panel.name}}</span>
                                    {% if requisition.object.user_created and requisition.object.is_drawn%}
                                        <p class="text text-default small">
                                            {{ requisition.object.user_created }} on {{ requisition.object.object.created|date:"SHORT_DATETIME_FORMAT" }}
                                            {% if requisition.object.user_modified %} | {{ requisition.object.user_modified }} on {{ requisition.object.object.modified|date:"SHORT_DATETIME_FORMAT" }}{% endif %}
                                        </p>
                                        {% elif requisition.object.requisition_identifier  and not requisition.object.is_drawn %}
                                        <p class="text text-danger small">Requisition is incomplete.</p>
                                    {% endif %}
                                {% endif %}
				    		</td>
						    <td>
				    			{% if requisition.entry_status == KEYED %}
					    			{% if requisition.object.is_drawn == YES and requisition.object.requisition_identifier %}
					    				<span class="text text-success small">
					    					<i class="fas fa-check fa-sm"></i>
					    					{% if requisition.object.clinic_verified == YES %}<i class="fas fa-check fa-sm"></i>{% endif %}
					    				</span> <span class="text text-default"><strong>{{ requisition.object.requisition_identifier|human }}</strong></span>
					    			{% elif requisition.object.reason_not_drawn == NOT_REQUIRED %}
					    				<span class="text text-info small"><i class="fas fa-info-circle"></i> no longer required</span>
					    			{% elif requisition.object.requisition_identifier  and not requisition.object.is_drawn %}
					    				<span class="text text-danger"><i class="fas fa-hand-stop-o fa-fw"></i> <strong>{{ requisition.object.requisition_identifier|human }}</strong></span>
					    			{% elif requisition.object.is_drawn == NO %}
					    				<span class="text text-info small">not drawn</span>
					    			{% else %}
					    				<span class="text text-danger small"><i class="fas fa-warning"></i> ERROR</span>
					    			{% endif %}
				    			{% endif %}

								<span class="btn-group pull-right">
	                            {% if requisition.entry_status != NOT_REQUIRED %}
	    							<a role="button" class="btn btn-sm {% if requisition.entry_status == KEYED %}btn-success{% else %}{% if requisition.entry_status == NOT_REQUIRED %} disabled btn-default{% else %}btn-warning{% endif %}{% endif %}"
										{% if requisition.entry_status == KEYED and requisition.object.has_change_permission %}
											 id="{{ requisition.object.html_id }}" name="{{ requisition.object.html_id }}"
											 {%  if request.site.id == requisition.site.id %}href="{{ requisition.object.href }}"{% else %} disabled {% endif %}><span class="fas fa-pencil-alt fa-fw"></span> Change
                    {% elif requisition.entry_status != KEYED and requisition.object.has_add_permission %}
											 id="add-{{requisition.panel_name}}"
											 {%  if request.site.id == requisition.site.id %}href="{{ requisition.object.href }}"{% else %} disabled {% endif %}><span class="fas fa-plus fa-fw"></span> Add
                    {% elif requisition.entry_status == KEYED and requisition.object.has_view_permission %}
											 id="{{ requisition.object.html_id }}" name="{{ requisition.object.html_id }}"
											 {%  if request.site.id == requisition.site.id %}href="{{ requisition.object.href }}"{% else %} disabled {% endif %}><span class="fas fa-eye fa-fw"></span> View
                    {% else %}
                       disabled >{% if requisition.entry_status == KEYED %}<span class="fas fa-pen"></span> Change{% else %}<span class="fas fa-plus"></span> Add{% endif %}
										{% endif %}
		       						</a>
	                               {% if requisition.object.history_url %}
	                                   <a href="{{ requisition.object.history_url }}" role="button" class="btn btn-sm btn-default">{% trans 'History' %}</a>
	                               {% else %}
	                                   <a disabled role="button" class="btn btn-sm btn-default">{% trans 'History' %}</a>
	                               {% endif %}
	                              {% else%}
	                                <span class="text text-muted small">not required</span>
	                              {% endif %}
						       	</span>
						    </td>
				    	</tr>
				    {% endfor %}

                    {% if not requisitions %}
                        <tr>
                            <td colspan="4">
                            <span class="text text-muted small">
                                  There are no required requisitions for this visit.
                            </span>
                            </td>
                        </tr>
                    {% endif %}
				    {% if appointment.object.visit.visit.requisitions_prn %}
				    	<tr><td colspan="4">
						<span class="text text small pull-right">
				    	PRN Requisitions are available.
				    	</span>
				    	</td></tr>
				    {% endif %}



				</tbody>
			</table>
		</div>
	</div>
</div>
