{% from 'macros.html' import follow_area with context %}
{% from 'bootstrap/nav.html' import render_nav_item %}


<div class="row">
    <div class="col-md-3">
        <a href="{% if current_user == user %}{{ url_for('.change_avatar') }}{% else %}#{% endif %}"
           title="更改头像">
            <img class="img-fluid rounded" src="{{ url_for('main.get_avatar', filename=user.avatar_l) }}">
        </a>
    </div>
    <div class="col-md-9">
        <h1>{{ user.name }}
            <small class="text-muted">{{ user.username }}</small>
        </h1>
        {% if user.bio %}<p>{{ user.bio }}</p>{% endif %}
        <p>
            {% if user.website %}
                <span class="oi oi-link-intact"></span>
                <a href="{{ user.website }}" target="_blank">{{ user.website|truncate(30) }}</a>&nbsp;&nbsp;
            {% endif %}
            {% if user.location %}
                <span class="oi oi-map-marker"></span>
                <a href="https://www.google.com/maps?q={{ user.location }}"
                   target="_blank">{{ user.location|truncate(30) }}</a>&nbsp;&nbsp;
            {% endif %}
            <span class="oi oi-calendar"></span>
            Joined {{ moment(user.member_since).format('LL') }}
        </p>
        <div>
            {% if current_user != user %}
                {% if current_user.can('MODERATE') %}
                    {% if user.locked %}
                        <form class="inline" action="{{ url_for('admin.unlock_user', user_id=user.id) }}" method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-secondary btn-sm" value="未锁">
                        </form>
                    {% else %}
                        <form class="inline" action="{{ url_for('admin.lock_user', user_id=user.id) }}" method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-warning btn-sm" value="锁住">
                        </form>
                    {% endif %}
                    {% if user.active %}
                        <form class="inline" action="{{ url_for('admin.block_user', user_id=user.id) }}" method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-warning btn-sm" value="堵塞">
                        </form>
                    {% else %}
                        <form class="inline" action="{{ url_for('admin.unblock_user', user_id=user.id) }}"
                              method="post">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn btn-secondary btn-sm" value="未堵塞">
                        </form>
                    {% endif %}
                    <a class="btn btn-light btn-sm" href="mailto:{{ user.email }}">邮箱</a>
                {% endif %}

                {% if current_user.is_admin %}
                    <a class="btn btn-warning btn-sm" href="{{ url_for('admin.edit_profile_admin', user_id=user.id) }}">编辑简介</a>
                {% endif %}
            {% endif %}
            <div class="float-right">
                {{ follow_area(user) }}
                {% if current_user.is_authenticated and user == current_user %}
                    <a class="btn btn-outline-primary btn-sm" href="{{ url_for('.edit_profile') }}">编辑简介</a>
                {% endif %}
            </div>
        </div>
    </div>
</div>
<div class="user-nav">
    <ul class="nav nav-tabs">
        {{ render_nav_item('user.index', '照片', user.photos|length, username=user.username) }}
        {{ render_nav_item('user.show_collections', '收藏', user.collections|length, username=user.username) }}
        {{ render_nav_item('user.show_following', '已关注', user.following.count() - 1, username=user.username) }}
        {{ render_nav_item('user.show_followers', '粉丝', user.followers.count() - 1, username=user.username) }}
    </ul>
</div>
