{% extends "admin/base_site.html" %}
{% load i18n admin_urls static admin_list prelude_utils %}

{% block extrastyle %}
  {{ block.super }}
  <link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}">
  {% if cl.formset %}
  <link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">
  {% endif %}
  
  {% if cl.formset or action_form %}
    <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
  {% endif %}
  {{ media.css }}
  
  {% if not actions_on_top and not actions_on_bottom %}
    <style>
      #changelist table thead th:first-child {width: inherit}
    </style>
  {% endif %}
{% endblock %}

{% block extrahead %}
    <!-- EXTRAHEAD -->
    {{ block.super }}
    {{ media.js }}
{% endblock %}

{% block extrafooter %}
<script type="text/javascript" src="{% static 'prelude_django_admin_toolkit/js/admin_changelist.js' %}"></script>
{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% endblock %}

{% if not is_popup %}
{% block breadcrumbs %}
<ul class="uk-breadcrumb">
    <li><a href="{% url 'admin:index' %}">{% trans 'Home' %}</a></li>
    <li><a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a></li>
    <li><span>{{ cl.opts.verbose_name_plural|capfirst }}</span></li>
</ul>
{% endblock %}
{% endif %}

{% block content %}
<div id="content-main">
	{# APP Header - Gray bar with ADD and Filter actions #}
    <div class="uk-clearfix uk-background-muted uk-padding-remove">
		<div class="uk-padding uk-padding-remove-vertical" uk-height-match>
			<div class="uk-float-left uk-flex uk-flex-middle">
				<span class="uk-text-lead">{{ cl.opts.verbose_name_plural|capfirst }}</span>
			</div>
			{% block object-tools %}
				{% block object-tools-items %}
					{% change_list_object_tools %}
				{% endblock %}
			{% endblock %}
		</div>
	</div>

    <div class="uk-padding"> 
   
   	{% block messages %}
		{% if messages %}			
			{% for message in messages %}
				<div {% if message.tags %}class="uk-alert-{{ message.tags }}"{% endif %} uk-alert>
					<a class="uk-alert-close" uk-close></a>
					<p>{{ message|capfirst }}</p>
				</div>
			{% endfor %}
		{% endif %}
	{% endblock messages %}
   
    {% if cl.formset and cl.formset.errors %}
        <p class="errornote">
        {% if cl.formset.total_error_count == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
        </p>
        {{ cl.formset.non_form_errors }}
    {% endif %}
    <div class="module uk-clear-fix"> {# Changelist #}
      {# block search has been moved to actions.html #}
      
      {# Filter screen #}
      {% block filters %}
          {% if cl.has_filters %}
          <div id="filters-modal" uk-modal>
            <div class="uk-modal-dialog">
                <button class="uk-modal-close-default" type="button" uk-close></button>
                <div class="uk-modal-header">
                    <h3 class="uk-modal-title">{% trans 'Filter' %}</h3>
                </div>
                <div class="uk-modal-body">
                
                	<div class="uk-child-width-1-2@s" uk-grid>
                    	{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
                	</div>
               
                	{% if cl.date_hierarchy %}
						{% block date_hierarchy %}
        				<h4>By date Hierarchy</h4>
						<p>
							{% date_hierarchy cl %}
						</p>
      					{% endblock %}
					{% endif %}
                </div>
                <div class="uk-modal-footer uk-text-right">
                    <button class="uk-button uk-button-default uk-modal-close" type="button">{% trans 'Cancel' %}</button>
                    {# <button class="uk-button uk-button-primary uk-text-secondary" type="button">Save</button> #}
                </div>
            </div>
          </div>
          {% endif %}
      {% endblock %}
  
      <form id="changelist-search" method="get" action="{{ request.get_full_path }}">
		<input id="searchbar" name="q" type="hidden" />
		
		{% for pair in cl.params.items %}
			{% if pair.0 != 'q' %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}">{% endif %}
		{% endfor %}
	  </form>

      <form id="changelist-form" method="post"{% if cl.formset and cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
      {% if cl.formset %}
        <div>{{ cl.formset.management_form }}</div>
      {% endif %}
      
      {% block result_list %}
          {% if actions_on_top %}
	          {% if action_form and cl.show_admin_actions or cl.search_fields %}
	          	{% admin_actions %}
	          {% endif %}
          {% endif %}
          
          {% result_list cl %}
          
          {# test how action_form would work with bottom-bar #}
          {% if actions_on_bottom %}
			  {% if action_form and cl.show_admin_actions or cl.search_fields %}
				  {% admin_actions %}
			  {% endif %}
          {% endif %}
      {% endblock %}
      
      {% block pagination %}{% pagination cl %}{% endblock %}
      </form>
    </div>
  </div>
</div>
{% endblock %}
