{% macro photo_card(photo) %}
    <div class="photo-card card">
        <a class="card-thumbnail" href="{{ url_for('main.show_photo', photo_id=photo.id) }}">
            <img class="card-img-top portrait" src="{{ url_for('main.get_image', filename=photo.filename_s) }}">
        </a>
        <div class="card-body">
            <span class="oi oi-star"></span> {{ photo.collectors|length }}
            <span class="oi oi-comment-square"></span> {{ photo.comments|length }}
        </div>
    </div>
{% endmacro %}

{% macro user_card(user) %}
    <div class="user-card text-center">
        <a href="{{ url_for('user.index', username=user.username) }}">
            <img class="rounded avatar-m" src="{{ url_for('main.get_avatar', filename=user.avatar_m) }}">
        </a>
        <h6>
            <a href="{{ url_for('user.index', username=user.username) }}">{{ user.name }}</a>
        </h6>
        {{ follow_area(user) }}
    </div>
{% endmacro %}

{% macro follow_area(user) %}
    {% if current_user.is_authenticated %}
        {% if user != current_user %}
            {% if current_user.is_following(user) %}
                <form class="inline" method="post"
                      action="{{ url_for('user.unfollow', username=user.username, next=request.full_path) }}">
                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                    <button type="submit" class="btn btn-dark btn-sm">Unfollow</button>
                    {% if current_user.is_followed_by(user) %}
                        <p class="badge badge-light">Follow each other</p>
                    {% endif %}
                </form>
            {% else %}
                <form class="inline" method="post"
                      action="{{ url_for('user.follow', username=user.username, next=request.full_path) }}">
                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                    <button type="submit" class="btn btn-primary btn-sm">Follow</button>
                    {% if current_user.is_followed_by(user) %}
                        <p class="badge badge-light">Follows you</p>
                    {% endif %}
                </form>
            {% endif %}
        {% endif %}
    {% else %}
        <form class="inline" method="post"
              action="{{ url_for('user.follow', username=user.username) }}">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            <button type="submit" class="btn btn-primary btn-sm">Follow</button>
        </form>
    {% endif %}
{% endmacro %}
