{% load i18n admin_extras favorites %}

<tr class="model-{{ model_name }}{% if model.admin_url in request.path|urlencode %} current-model{% endif %}">
  <th scope="row" id="{{ row_dom_id }}">
    {% if ct_id %}
      <form method="post" action="{% url 'admin:favorite_toggle' ct_id %}" class="favorite-toggle-form">
        {% csrf_token %}
        <input type="hidden" name="next" value="{{ request.get_full_path|urlencode }}">
        {% if fav %}
          <input type="hidden" name="remove" value="1">
        {% else %}
          <input type="hidden" name="user_data" value="on">
        {% endif %}
        <button type="submit" class="favorite-star{% if fav %} favorited{% endif %}" title="{% translate 'Toggle favorite' %}" aria-label="{% translate 'Toggle favorite' %}">&#9733;</button>
      </form>
    {% endif %}
    {% if model.admin_url %}
      <a href="{{ model.admin_url }}"{% if model.admin_url in request.path|urlencode %} aria-current="page"{% endif %}>{{ fav.custom_label|default:model.name }}</a>
    {% else %}
      {{ fav.custom_label|default:model.name }}
    {% endif %}
    {% if show_model_badges %}
      {% if model.object_name == 'RFID' %}
        {% rfid_release_stats as rfid_stats %}
        {% if rfid_stats %}
          {% blocktranslate with released_allowed=rfid_stats.released_allowed registered=rfid_stats.total asvar rfid_badge_label trimmed %}
            {{ released_allowed }} released and allowed RFIDs out of {{ registered }} registered RFIDs
          {% endblocktranslate %}
          <span class="rfid-release-badge" aria-label="{{ rfid_badge_label }}" title="{{ rfid_badge_label }}">
            {{ rfid_stats.released_allowed }} / {{ rfid_stats.total }}
          </span>
        {% endif %}
      {% endif %}
      {% if model.object_name == 'Charger' %}
        {% charger_availability_stats as charger_stats %}
        {% if charger_stats %}
          {% if charger_stats.available_missing_cp_number %}
            {% blocktranslate with available=charger_stats.available_with_cp_number total=charger_stats.available_total missing=charger_stats.available_missing_cp_number asvar charger_badge_label trimmed %}
              {{ available }} chargers reporting Available status with a CP number, out of {{ total }} total Available chargers. {{ missing }} Available chargers are missing a connector letter.
            {% endblocktranslate %}
          {% else %}
            {% blocktranslate with available=charger_stats.available_with_cp_number total=charger_stats.available_total asvar charger_badge_label trimmed %}
              {{ available }} chargers reporting Available status with a CP number.
            {% endblocktranslate %}
          {% endif %}
          <span class="charger-availability-badge" aria-label="{{ charger_badge_label }}" title="{{ charger_badge_label }}">
            {{ charger_stats.available_with_cp_number }} / {{ charger_stats.available_total }}
          </span>
        {% endif %}
      {% endif %}
      {% lead_open_count app_label model.object_name as lead_open_count %}
      {% if lead_open_count is not None %}
        {% blocktranslate count open_count=lead_open_count asvar lead_open_label trimmed %}
          {{ open_count }} open lead
        {% plural %}
          {{ open_count }} open leads
        {% endblocktranslate %}
        <span class="lead-open-badge" aria-label="{{ lead_open_label }}" title="{{ lead_open_label }}">{{ lead_open_count }}</span>
      {% endif %}
      {% if model.object_name == 'Node' %}
        {% node_known_count as node_known_total %}
        {% if node_known_total is not None %}
          {% blocktranslate count node_total=node_known_total asvar node_known_label trimmed %}
            {{ node_total }} node known to this deployment
          {% plural %}
            {{ node_total }} nodes known to this deployment
          {% endblocktranslate %}
          <span class="node-count-badge" aria-label="{{ node_known_label }}" title="{{ node_known_label }}">{{ node_known_total }}</span>
        {% endif %}
      {% endif %}
      {% model_rule_status app_label model.object_name as model_rule %}
      {% if model_rule %}
        <span class="model-rule-status{% if model_rule.success %} model-rule-status--success{% else %} model-rule-status--error{% endif %}">
          <span class="model-rule-status__icon" aria-hidden="true">{{ model_rule.icon }}</span>
          <span class="model-rule-status__message">{{ model_rule.message }}</span>
        </span>
      {% endif %}
    {% endif %}
  </th>

  {% if model.admin_url and show_changelinks %}
    {% model_admin_actions app_label model.object_name as extra_actions %}
    <td class="actions" data-label="{% translate 'Model actions' %}">
      {% for action in extra_actions %}
        <a href="{{ action.url }}" class="actionlink" aria-describedby="{{ row_dom_id }}">{{ action.label }}</a>{% if not forloop.last %}&nbsp;{% endif %}
      {% endfor %}
    </td>
  {% else %}
    <td class="actions"></td>
  {% endif %}

  {% if model.add_url %}
    <td data-label="{% translate 'Add' %}"><a href="{{ model.add_url }}" class="addlink" aria-describedby="{{ row_dom_id }}">{% translate 'Add' %}</a></td>
  {% else %}
    <td data-label="{% translate 'Add' %}"></td>
  {% endif %}

  {% if model.admin_url and show_changelinks %}
    <td class="change-link-cell{% if model.view_only %} change-link-cell--view-only{% endif %}" data-label="{% translate 'Change or view list link' %}">
      {% if model.view_only %}
        <a href="{{ model.admin_url }}" class="viewlink" aria-describedby="{{ row_dom_id }}">{% translate 'View' %}</a>
      {% else %}
        <a href="{{ model.admin_url }}" class="changelink" aria-describedby="{{ row_dom_id }}" target="_blank" rel="noopener noreferrer">{% translate 'Change' %}</a>
      {% endif %}
    </td>
  {% elif show_changelinks %}
    <td class="change-link-cell" data-label="{% translate 'Change or view list link' %}"></td>
  {% endif %}
</tr>
