{% extends 'base_main.html' %}

{% block title %}Аккаунт{% endblock %}

{% block main %}
    <h2 style="margin-bottom: 40px;">Информация об аккаунте</h2>
    <div class="row">
        <div class="col-3">
            <div style="height: 100%; width: 100%;">
                <img src="{{ account.userinfo.profile_pic_url }}" height="100%" width="100%" alt="Фото профиля">
            </div>
            {% if owner %}
                <label for="file-upload" class="btn btn-light" style="margin-top: -100px; margin-left: 10%; width: 80%;">
                    <i class="fa fa-upload"></i> Загрузить фото
                </label>
                <input type="file" form="photoform" style="display: none;" accept="image/png, image/jpg" class="btn form-control-file" id="file-upload" value="Выбрать файл" name="file" onchange="document.getElementById('photoform').submit();">
                <form method="POST" enctype="multipart/form-data" id="photoform">
                    <input type="hidden" name="action" value="upload_photo">
                    {% csrf_token %}
                </form>
            {% endif %}
        </div>
        <div class="col-9">
            <h3>
                {{ account.userinfo.surname }} {{ account.userinfo.name }}
                <span style="margin-left: 15px; margin-bottom: 20px;" class="badge badge-{% if account.userinfo.activity_status == online_status %}success{% else %}secondary{% endif %}">{{ account.userinfo.activity_status }}</span>
                {% if not owner %}
                    <form method="POST">
                        {% csrf_token %}
                        <input type="hidden" name="action" value="friendship">
                            {% if friendship_status == 0 %}
                                <button type="submit" class="btn btn-primary" name="to_do" value="add">Добавить в друзья</button>
                            {% else %}{% if friendship_status == 1 %}
                                <button class="btn btn-success"><i class="fa fa-check"></i> Друзья</button> <button class="btn btn-danger" type="submit" name="to_do" value="delete"><i class="fa fa-times"></i> Удалить</button>
                            {% else %}{% if friendship_status == 2 %}
                                <button class="btn btn-info">Приглашение отправлено</button> <button class="btn btn-danger" type="submit" name="to_do" value="delete">Отменить</button>
                            {% else %}
                                <button class="btn btn-info" type="submit" name="to_do" value="yes">Принять</button> <button class="btn btn-danger" type="submit" name="to_do" value="no">Отклонить</button>
                            {% endif %}{% endif %}{% endif %}
                    </form>
                {% endif %}
                {% if user.is_superuser and owner %}
                    <a style="margin-left: 15px;" href="/admin/" class="badge badge-secondary">Админ</a>
                {% endif %}
            </h3>
            <table>
                <tr>
                    <td>
                        <h2><i class="fa fa-user"></i></h2>
                    </td>
                    <td><div style="width: 20px;"></div></td>
                    <td>
                        <p style="padding-top: 8px; font-size: 24px;">{{ account.username }}</p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h2><i class="fa fa-star"></i></h2>
                    </td>
                    <td><div style="width: 20px;"></div></td>
                    <td>
                        <p style="padding-top: 8px; font-size: 24px;">{{ account.userinfo.rating }}</p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h2><i class="fa fa-arrow-up"></i></h2>
                    </td>
                    <td><div style="width: 20px;"></div></td>
                    <td>
                        <p style="padding-top: 8px; font-size: 24px;">{{ account.userinfo.place }}</p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h2><i class="fa fa-calendar"></i></h2>
                    </td>
                    <td><div style="width: 20px;"></div></td>
                    <td>
                        <p style="padding-top: 8px; font-size: 24px;">{{ account.date_joined.date }}</p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h2><i class="fa fa-desktop"></i></h2>
                    </td>
                    <td><div style="width: 20px;"></div></td>
                    <td><p style="padding-top: 8px; font-size: 24px;">
                        {% if owner %}
                            <form method="POST">
                                {% csrf_token %}
                                <input type="hidden" name="action" value="set_language">
                                <select name="language" onchange="this.form.submit();">
                                    <option value="-1">Предпочитаемый язык отсутствует</option>
                                    {% for lang in languages %}
                                        <option value="{{ lang.id }}"{% if account.userinfo.favourite_language_id == lang.id %} selected{% endif %}>{{ lang }}</option>
                                    {% endfor %}
                                </select>
                            </form>
                        {% else %}
                            {% if account.userinfo.has_favourite_language %}
                                <img src="{{ account.userinfo.favourite_language.logo_url }}" height="24px" width="24px"> {{ account.userinfo.favourite_language.name }}
                            {% else %}
                                Предпочитаемый язык отсутствует
                            {% endif %}
                        {% endif %}
                    </p></td>
                </tr>

            </table>
        </div>
    </div>
    {% if owner %}
    <hr><hr>
    <h2>Уведомления</h2>
        <form method="POST">
        {% csrf_token %}
        <input type="hidden" name="action" value="notifications">
    <table>
        <tr>
            <td style="width: 200px;">
                Результаты решений
            </td>
            <td>
                <input type="checkbox" name="notification_solution_result" {% if user.userinfo.notification_solution_result %}checked{% endif %}>
            </td>
        </tr>
        <tr>
            <td style="width: 200px;">
                Заявки в друзья
            </td>
            <td>
                <input type="checkbox" name="notification_friends" {% if user.userinfo.notification_friends %}checked{% endif %}>
            </td>
        </tr>
        <tr>
            <td style="width: 200px;">
                Сообщения в оффлайн
            </td>
            <td>
                <input type="checkbox" name="notification_messages" {% if user.userinfo.notification_messages %}checked{% endif %}>
            </td>
        </tr>
    </table>
                <button type="submit" class="btn btn-light" style="margin-top: 15px;"><i class="fa fa-save"></i> Сохранить</button>

                </form>
        <hr><hr>
        <h2 style="margin-bottom: 20px;">Друзья</h2>
        <h5>
        {% for friendship in user.userinfo.friends %}
            <i class="fa fa-user"></i> <a href="/account?username={% if friendship.to_user == user %}{{ friendship.from_user.username }}{% else %}{{ friendship.to_user.username }}{% endif %}">{% if friendship.to_user == user %}{{ friendship.from_user.username }}{% else %}{{ friendship.to_user.username }}{% endif %}</a>{% if not friendship.verified %}   <i class="fa fa-circle" style="color: blue;"></i> {% endif %}<br>
        {% endfor %}
        </h5>
    {% endif %}
{% endblock %}