{% load character_extras %}
<div class="col">
    <div class="card character" data-id="{{ character.pk }}">
        <div class="card-body">
            <h5 class="card-title">
                {% if character.profile_picture %}
                    <img src="{{ character.profile_picture.url }}"
                         class="profile-pic-small rounded-5"
                         alt="Image de profil"
                    >
                {% endif %}
                {% if character.private %}
                    <i class="fa-solid fa-lock"
                       data-bs-toggle="tooltip"
                       data-bs-placement="top"
                       data-bs-title="Personnage privé, ne peut pas être invité dans un nouveau groupe."
                    ></i>
                {% endif %}
                {{ character.name }}
            </h5>
            <p class="card-text">
                {{ character.race.name }} {{ character.profile.name }} niv. {{ character.level }}<br>
                <span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Attaque au contact">
                    ⚔️&nbsp;{{ character.attack_melee|modifier }}
                </span> /
                <span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Attaque à distance">
                    🏹&nbsp;{{ character.attack_range|modifier }}
                </span> /
                <span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Attaque magique">
                    🪄&nbsp;{{ character.attack_magic|modifier }}
                </span> /
                <span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="DEF">
                    🛡️&nbsp;{{ character.defense }}
                </span><br>
                <span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Initiative">
                    🎲&nbsp;{{ character.modifier_initiative|modifier }}
                </span> /
                <span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Mod. FOR">
                    💪&nbsp;{{ character.modifier_strength|modifier }}
                </span>
            </p>
            {% include "character/snippets/character_details/health_bar.html" %}
            {% if character.mana_max > 0 %}
                <div class="mt-1">
                    {% include "character/snippets/character_details/mana_bar.html" %}
                </div>
            {% endif %}
            <p class="card-text mt-3">
                {% with character.states.all as character_states %}
                    {% for state in all_states %}
                        <img src="{{ state.icon_url }}" alt="{{ state.name }}" height="25" width="25"
                             data-bs-toggle="tooltip"
                             data-bs-placement="top"
                             data-bs-title="{{ state.name }} : {{ state.description }}"
                             {% if state in character_states %}
                                 class="state-enabled"
                             {% endif %}
                        >
                    {% endfor %}
                {% endwith %}
            </p>
            <div class="btn-group btn-group-sm">
                {% if character.player == user %}
                    <a href="{% url "character:view" pk=character.pk %}{% if party %}?party={{ party.pk }}{% endif %}" class="btn btn-success">
                        <i class="fa-solid fa-user"></i> Jouer
                    </a>
                    {% if party %}
                        {% if character in party.characters.all %}
                            <a href="{% url "party:leave" pk=party.pk character_pk=character.pk %}" class="btn btn-warning">
                                <i class="fa-solid fa-person-walking-arrow-right"></i> Quitter le groupe
                            </a>
                        {% elif character in party.invited_characters.all %}
                            <a href="{% url "party:join" pk=party.pk character_pk=character.pk %}" class="btn btn-primary">
                                <i class="fa-solid fa-check"></i> Rejoindre
                            </a>
                            <a href="{% url "party:refuse" pk=party.pk character_pk=character.pk %}" class="btn btn-warning">
                                <i class="fa-solid fa-person-walking-arrow-right"></i> Refuser l'invitation
                            </a>
                        {% endif %}
                    {% else %}
                        <a href="{% url "character:delete" pk=character.pk %}" class="btn btn-danger delete">
                            <i class="fa-solid fa-user-minus"></i> Supprimer
                        </a>
                    {% endif %}
                {% elif character|managed_by:user %}
                    <a href="{% url "character:view" pk=character.pk %}{% if party %}?party={{ party.pk }}{% endif %}" class="btn btn-primary manage">
                        <i class="fa-solid fa-cog"></i> Gérer
                    </a>
                {% else %}
                    <a href="{% url "character:view" pk=character.pk %}{% if party %}?party={{ party.pk }}{% endif %}" class="btn btn-primary observe">
                        <i class="fa-solid fa-eye"></i> Observer
                    </a>
                {% endif %}
            </div>
        </div>
    </div>
</div>
