{% extends 'generic/object.html' %}
{% load static %}
{% load helpers %}
{% load plugins %}
{% load render_table from django_tables2 %}

{% block extra_controls %}
  {% if perms.ipfabric_netbox.sync_ingest %}
    {% if object.ready_for_sync %}
      <form action="{% url 'plugins:ipfabric_netbox:ipfabricsync_sync' pk=object.pk %}" method="post">
        {% csrf_token %}
        <button type="submit" class="btn btn-sm btn-primary">
          <i class="mdi mdi-sync" aria-hidden="true"></i> Adhoc Ingestion
        </button>
      </form>
    {% else %}
      <span class="inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-delay="100" data-bs-placement="bottom">
        <button class="btn btn-sm btn-primary" disabled>
          <i class="mdi mdi-sync" aria-hidden="true"></i> Adhoc Ingestion
        </button>
      </span>
    {% endif %}
  {% endif %}
{% endblock %}

{% block content %}
<div class="row mb-3">
  <div class="col col-md-6">
    <div class="card">
      <h5 class="card-header">Ingestion Information</h5>
      <div class="card-body">
        <table class="table table-hover attr-table">
          <tr>
            <th scope="row">Name</th>
            <td>{{ object.name }}</td>
          </tr>
          <tr>
            <th scope="row">Source</th>
            <td><a href="{% url 'plugins:ipfabric_netbox:ipfabricsource' pk=object.snapshot_data.source.pk %}">{{ object.snapshot_data.source.name }}</a></td>
          </tr>
          <tr>
            <th scope="row">Snapshot</th>
            <td><a href="{% url 'plugins:ipfabric_netbox:ipfabricsnapshot' pk=object.snapshot_data.pk %}">{{ object.snapshot_data.name}}</a></td>
          </tr>
          <tr>
            <th scope="row">Status</th>
            <td>{% badge object.get_status_display bg_color=object.get_status_color %}</td>
          </tr>
          <tr>
            <th scope="row">Last synced</th>
            <td>{{ object.last_synced|placeholder }}</td>
          </tr>
          <tr>
            <th scope="row">Latest branch</th>
            <td><div {% if object.status == 'queued' or object.status == 'syncing'  %} hx-get="{% url 'plugins:ipfabric_netbox:ipfabricsync' pk=object.pk %}" hx-trigger="every 1s"{% endif %}>{% include 'ipfabric_netbox/partials/sync_last_branch.html' %}</div></td>
          </tr>
          <tr>
            <th scope="row">Schedule</th>
            <td><div>{{ object.scheduled }}</div></td>
          </tr>
          <tr>
            <th scope="row">Interval</th>
            <td><div>{{ object.interval }}</div></td>
          </tr>
          <tr>
            <th scope="row">User</th>
            <td><div>{{ object.user }}</div></td>
          </tr>
          </tr>
        </table>
      </div>
    </div>
    {% include 'inc/panels/tags.html' %}
    {% plugin_left_page object %}
  </div>
  <div class="col col-md-6">
    <div class="card">
      <h5 class="card-header">Parameters</h5>
      <div class="card-body">
        <table class="table table-hover attr-table">
          {% for name, field in object.parameters.items %}
            <tr>
              <th scope="row">{{ name }}</th>
              <td>{{ object.parameters|get_key:name|placeholder }}</td>
            </tr>
          {% empty %}
            <tr>
              <td colspan="2" class="text-muted">
                No parameters defined
              </td>
            </tr>
          {% endfor %}
        </table>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <h5 >Parameters</h5>
        {% include 'extras/inc/configcontext_format.html' %}
      </div>
      <div class="card-body">
        {% include 'extras/inc/configcontext_data.html' with data=object.parameters format=format %}
      </div>
    </div>
    {% include 'inc/panels/custom_fields.html' %}
    {% plugin_right_page object %}
  </div>
</div>
{% endblock %}
