{% extends 'base/layout.html' %}
{% load helpers %}

{% block title %}Scripts{% endblock %}

{% block tabs %}
  <ul class="nav nav-tabs px-3">
    <li class="nav-item" role="presentation">
      <a class="nav-link active" role="tab">Scripts</a>
    </li>
  </ul>
{% endblock tabs %}

{% block content-wrapper %}
  <div class="tab-content">
    {% if scripts %}
      {% for module, module_scripts in scripts.items %}
        <div class="card">
          <h5 class="card-header">
            <a name="module.{{ module }}"></a>
            <i class="mdi mdi-file-document-outline"></i> {{ module|bettertitle }}
          </h5>
          <div class="card-body">
            <table class="table table-hover table-headings reports">
              <thead>
                <tr>
                  <th width="250">Name</th>
                  <th width="110">Status</th>
                  <th>Description</th>
                  <th class="text-end">Last Run</th>
                </tr>
              </thead>
              <tbody>
                {% for class_name, script in module_scripts.items %}
                  <tr>
                    <td>
                      <a href="{% url 'extras:script' module=script.module name=class_name %}" name="script.{{ class_name }}">{{ script.name }}</a>
                    </td>
                    <td>
                      {% include 'extras/inc/job_label.html' with result=script.result %}
                    </td>
                    <td>
                      {{ script.Meta.description|markdown|placeholder }}
                    </td>
                    {% if script.result %}
                      <td class="text-end">
                        <a href="{% url 'extras:script_result' job_result_pk=script.result.pk %}">{{ script.result.created|annotated_date }}</a>
                      </td>
                    {% else %}
                      <td class="text-end text-muted">Never</td>
                    {% endif %}
                  </tr>
                {% endfor %}
              </tbody>
            </table>
          </div>
        </div>
      {% endfor %}
    {% else %}
      <div class="alert alert-info">
        <h4 class="alert-heading">No Scripts Found</h4>
        Scripts should be saved to <code>{{ settings.SCRIPTS_ROOT }}</code>.
        <hr/>
        This path can be changed by setting <code>SCRIPTS_ROOT</code> in NetBox's configuration.
      </div>
    {% endif %}
  </div>
{% endblock content-wrapper %}
