{% load helpers %}
{# renders panel on object (device, module) with firmware info assigned to it #}

<div class="card">
  <h5 class="card-header">
    Firmware 
    {% if perms.netbox_firmware.change_firmware %}
      <div class="card-actions">
        {% with object|meta:"model_name" as object_type %}
          <a href="{% url 'plugins:netbox_firmware:firmwareassignment_add' %}?{{object_type}}={{object.id}}" class="btn btn-sm btn-ghost-primary">
        {% endwith %}
          <i class="mdi mdi-vector-link" aria-hidden="true"></i> Add Assignment
        </a>
      </div>
    {% endif %}
  </h5>
  <!--check if firmware item is filled and then show name version and status that is given-->
  {% if assignments %}
    <div class="card-body">
      <table class="table">
        <thead>
          <tr>
            <th>Name</th>
            <th>Status</th>
            <th>Description</th>
            <th>Patch date</th>
          </tr>
        </thead>
        <tbody>
          {% for assignment in assignments %}
          <tr>
            <td><a href="{% url 'plugins:netbox_firmware:firmware' assignment.firmware.id %}">{{ assignment.firmware.name }}</a></td>
            <td>{{ assignment.firmware.status }}</td>
            <td>{{ assignment.description }}</td>
            <td>{{ assignment.patch_date }}</td>
            {% if perms.netbox_firmware.change_firmwareassignment %}
            <td>
              <a href="{% url 'plugins:netbox_firmware:firmwareassignment_edit' assignment.id %}" class="btn btn-sm btn-ghost-primary">
                <i class="mdi mdi-pencil" aria-hidden="true"></i> Edit
              </a>
            </td>
          {% endif %}
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  {% else %}
    <div class="card-body">
      <p class="card-text">No firmware assigned for {{ object }}</p>
    </div>
  {% endif %}
</div>