{% extends "layouts/base.html" %}
{% load lineage_extras %}
{% load i18n %}

{% block extrastyle %}
<style>
  .clan-name-container {
    display: flex;
    align-items: center;
    gap: 6px; /* Espaço entre o grupo de crests e o nome */
  }

  .crest-group {
    display: flex;
    align-items: center;
    width: 26px;
    gap: 0px; /* Espaço entre as duas imagens */
  }

  .top-clan-crest {
    width: auto;
    height: 14px;
    margin: 0;
  }
</style>
{% endblock %}

{% block content %}
<div class="container mt-5">
  <div class="card shadow-lg p-4">
    <h2 class="text-center mb-4">{% trans "Ranking Nível" %}</h2>

    {% if players %}
    <div class="table-responsive-md">
      <table class="table table-striped">
        <thead>
          <tr>
            <th>#</th>
            <th>{% trans "Personagem" %}</th>
            <th class="d-none d-md-table-cell">{% trans "Clan" %}</th>
            <th>{% trans "Nível" %}</th>
            <th>{% trans "PvPs" %}</th>
            <th class="d-none d-md-table-cell">{% trans "PKs" %}</th>
            <th>{% trans "Online" %}</th>
            <th class="d-none d-md-table-cell">{% trans "Tempo Online" %}</th>
          </tr>
        </thead>
        <tbody>
          {% for player in players %}
          <tr>
            <td>{{ forloop.counter }}</td>
            <td>{{ player.char_name }}</td>
            <td><div class="clan-name-container">
              <div class="crest-group">
                {% if clan.ally_crest_image_base64 %}
                  <img src="data:image/png;base64,{{ player.ally_crest_image_base64 }}" alt="Crest da Aliança" class="top-clan-crest">
                {% endif %}
                <img src="data:image/png;base64,{{ player.clan_crest_image_base64 }}" alt="Crest do Clã" class="top-clan-crest">
              </div>
              {{ player.clan_name|default:"-" }}
            </div></td>
            <td>{{ player.level }}</td>
            <td>{{ player.pvpkills }}</td>
            <td class="d-none d-md-table-cell">{{ player.pkkills }}</td>
            <td>{% if player.online > 0 %}🟢{% else %}⚪{% endif %}</td>
            <td class="d-none d-md-table-cell">{{ player.onlinetime|humanize_time }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    {% else %}
    <div class="alert alert-warning text-center">
      {% trans "Nenhum dado encontrado." %}
    </div>
    {% endif %}
  </div>
</div>
{% endblock %}
