{% load i18n %}
{% load evelinks %}
{% load memberaudit %}


<div class="panel panel-default">
    <div class="panel-heading" style="display:flex;">
        <h3 class="panel-title">{% translate 'Characters' %}</h3>
    </div>
    <div class="panel-body">
        <!-- Characters -->
        <div class="character-cards">
            <ul class="cards_container">
                <!-- Add New Character -->
                <li class="cards_item">
                    <div class="card">
                        <div class="card-header">{% translate 'Register Character' %}</div>

                        <div class="card-body card__content">
                            <a href="{% url 'memberaudit:add_character' %}">
                                <img src="{{ 1|character_portrait_url:256 }}" alt="Add character">
                            </a>
                        </div>

                        <div class="card-footer">
                            <a class="btn btn-primary btn-sm" href="{% url 'memberaudit:add_character' %}">{% translate 'Register' %}</a>
                        </div>
                    </div>
                </li>

                {% if has_registered_characters %}
                    <!-- Registered Characters -->
                    {% for auth_character in auth_characters|dictsort:"character_name" %}
                        <li class="cards_item">
                            <div class="card">
                                <div class="card-header">
                                    {% include 'memberaudit/partials/character_name.html' with total_update_status=auth_character.total_update_status %}
                                </div>

                                <div class="card-body card__content">
                                    <p>
                                        <a href="{% url 'memberaudit:character_viewer' auth_character.character.pk %}">
                                            <span class="aa-memberaudit-launcher-character-image">
                                                <img src="{{ auth_character.character_id|character_portrait_url:256 }}" alt="{{ auth_character.character_name }}">

                                                {% if auth_character.alliance_id %}
                                                    <span class="aa-memberaudit-alliance-logo">
                                                        <img class="" src="{{ auth_character.alliance_id|alliance_logo_url:64 }}" title="{{ auth_character.alliance_name }}">
                                                    </span>
                                                {% endif %}

                                                <span class="aa-memberaudit-corporation-logo">
                                                    <img class="" src="{{ auth_character.corporation_id|corporation_logo_url:64 }}" title="{{ auth_character.corporation_name }}">
                                                </span>
                                            </span>
                                        </a>
                                    </p>

                                    <div class="text-center">
                                        {% include 'memberaudit/partials/solar_system.html' with character=auth_character.character only %}<br>
                                        {% if auth_character.character.wallet_balance %}
                                            {% natural_number auth_character.character.wallet_balance.total %} ISK<br>
                                        {% else %}
                                            <span class="text-muted">{% translate "(no data yet)" %}</span>
                                        {% endif %}

                                    </div>
                                </div>

                                <div class="card-footer">
                                    <a class="btn btn-success btn-sm" href="{% url 'memberaudit:character_viewer' auth_character.character.pk %}"
                                        role="button" title="{% translate 'View this character.' %}">
                                        <i class="fas fa-sign-in-alt"></i>
                                    </a>

                                    {% if perms.memberaudit.share_characters %}
                                        {% if auth_character.character.is_shared %}
                                            <a class="btn btn-primary btn-sm" href="{% url 'memberaudit:unshare_character' auth_character.character.pk %}"
                                                role="button" title="{% translate 'Disable access to this character for recruiters.' %}">
                                                <i class="far fa-eye-slash"></i>
                                            </a>
                                        {% else %}
                                            {% blocktranslate asvar confirm_share_message %}Are you sure you want to allow others to see this character?{% endblocktranslate %}
                                            <a class="btn btn-warning btn-sm" href="{% url 'memberaudit:share_character' auth_character.character.pk %}"
                                                role="button"
                                                onclick="return confirm('{{ confirm_share_message }}')"
                                                title="{% translate 'Allow others to see this character.' %}">
                                                <i class="far fa-eye"></i>
                                            </a>
                                        {% endif %}
                                    {% endif %}

                                    {% blocktranslate asvar confirm_remove_message %}Are you sure you want to remove this character?{% endblocktranslate %}
                                    <a class="btn btn-danger btn-sm" href="{% url 'memberaudit:remove_character' auth_character.character.pk %}"
                                        role="button" title="{% translate 'Remove this character.' %}"
                                        onclick="return confirm('{{ confirm_remove_message }}')">
                                        <i class="far fa-trash-alt"></i>
                                    </a>
                                </div>
                            </div>
                        </li>
                    {% endfor %}
                {% endif %}
            </ul>
        </div>

        {% if characters_need_token_refresh|length > 0 %}
            <p class="text-warning">
                <strong>
                <i class="fas fa-exclamation-triangle"></i>
                {% translate 'Please re-register characters with issues:' %}&nbsp;&nbsp;</strong>
                {{ characters_need_token_refresh|join:", " }}
            </p>
        {% endif %}

        {% if unregistered_chars|length > 0 %}
            <p class="text-warning">
                <strong>
                <i class="fas fa-exclamation-triangle"></i>
                {% translate 'Please register unregistered characters:' %}&nbsp;&nbsp;</strong>
                {{ unregistered_chars|join:", " }}
            </p>
        {% endif %}

        <p class="text-muted">
            <i class="fas fa-crown"></i> {% translate 'Main character' %}&nbsp;|&nbsp;
            <i class="far fa-eye"></i> {% translate 'Currently shared with others' %}&nbsp;|&nbsp;
            ⬤ {% translate 'Update status' %}
        </p>
    </div>
</div>
