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

{% block extrastyle %}
<style>
  .clan-name-container {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .crest-group {
    display: flex;
    align-items: center;
    width: 26px;
    gap: 0px;
  }

  .top-clan-crest {
    width: auto;
    height: 14px;
    margin: 0;
  }

  .custom-top-indicator {
    font-size: 0.6rem;
    opacity: 0.55;
  }

  .custom-top-header {
    border-top: 3px solid #8b5cf6;
    background: linear-gradient(to bottom, rgba(139, 92, 246, 0.04), transparent 80px);
  }
</style>
{% endblock %}

{% block content %}
<div class="container mt-5">
  <div class="card shadow-lg p-4 custom-top-header">
    <h2 class="text-center mb-4">
      {{ custom_top.title }}
      <span class="custom-top-indicator text-muted ms-2" title="{% trans 'Ranking exclusivo do servidor' %}">✦</span>
    </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>{{ column_label }}</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 player.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|get_dict_item:column_key|default:"-" }}</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 %}
