{% extends "dashboard/base.html" %}
{% load staticfiles %}
{% load i18n %}
{% load render_table from django_tables2 %}

{% block title-page %}{% trans "Templates" %}{% endblock %}

{% block content %}

<div class="row">
  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading">
        <a href="{% url "dashboard.views.template-choose" %}" class="pull-right btn btn-success btn-xs template-choose">
          <i class="fa fa-plus"></i> {% trans "new template" %}
        </a>
        <h3 class="no-margin"><i class="fa fa-puzzle-piece"></i> {% trans "Templates" %}</h3>
      </div>
      <div class="panel-body">
        <div class="row">
          <div class="col-md-offset-8 col-md-4" id="template-list-search">
            <form action="" method="GET">
              <div class="input-group">
                {{ search_form.s }}
                <div class="input-group-btn">
                  {{ search_form.stype }}
                  <button type="submit" class="btn btn-primary input-tags">
                    <i class="fa fa-search"></i>
                  </button>
                </div>
              </div><!-- .input-group -->
            </form>
          </div><!-- .col-md-4 #template-list-search -->
        </div>
      </div>
      <div class="panel-body">
        <div class="table-responsive">
          {% render_table table %}
        </div>
      </div>
    </div>
  </div>
</div>

{% if show_lease_table %}
<div class="row">
  <div class="col-md-6">
    <div class="panel panel-default">
      <div class="panel-heading">
        {% if perms.vm.create_leases %}
        <a href="{% url "dashboard.views.lease-create" %}"
          class="pull-right btn btn-success btn-xs" style="margin-right: 10px;">
          <i class="fa fa-plus"></i> {% trans "new lease" %}
        </a>
        {% endif %}
        <h3 class="no-margin"><i class="fa fa-clock-o"></i> {% trans "Leases" %}</h3>
      </div>
      <div class="panel-body">
        <div class="" style="max-width: 600px;">
          {% render_table lease_table %}
        </div>
      </div>
    </div>
  </div>

  <div class="col-md-6">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="no-margin">
          <i class="fa fa-puzzle-piece"></i>
          {% trans "Rarely used templates" %}
        </h3>
      </div>
      <div class="panel-body">
        <dl>
          <dt>{% trans "Never instantiated" %}</dd>
          <dd>
            {% include "dashboard/_list-templates.html" with templates=unused_templates.never_instantiated %}
          </dd>
          <dt>{% trans "Templates without running instances" %}</dd>
          <dd>
            {% include "dashboard/_list-templates.html" with templates=unused_templates.templates_wo_instances %}
          </dd>
          <dt>{% trans "Templates without instances, last instance created more than 90 days ago" %}</dd>
          <dd>
            {% include "dashboard/_list-templates.html" with templates=unused_templates.templates_wo_instances_90 %}
          </dd>
          <dt>{% trans "Templates without instances, last instance created more than 180 days ago" %}</dd>
          <dd>
            {% include "dashboard/_list-templates.html" with templates=unused_templates.templates_wo_instances_180 %}
          </dd>
        </dl>
      </div>
    </div>
  </div>
</div>
{% endif %}
{% endblock %}
