{% extends '__layout__.html' %}
{% block title %}Friend Requests{% endblock %}
{% block head %}
<link href="/static/css/profile.css" rel="stylesheet"/> <!-- Its just easier to resuse this-->
<style>
    .border {
        border-color: var(--linebreak) !important;
    }
    #nav-tab .nav-link {
        color: var(--text-muted) !important;
    }
    #nav-tab .nav-link.active {
        color: var(--bs-body-color) !important;
    }
</style>
{% endblock %}
{% block content %}
<div id="main">
    <div class="container" style="max-width: 800px;">
        <div class="d-flex align-items-center">
            <a href="/users/{{profile.id}}/profile">
                <img src="/Thumbs/Head.ashx?x=100&y=100&userId={{profile.id}}" width="80px" height="80px" class="rounded-2">
            </a>
            <h2 class="ms-3">Friend Requests</h2>
        </div>
        <nav class="mt-2 rounded-top" style="background-color: var(--surface-alt) !important;overflow: hidden;">
            <div class="nav nav-underline nav-fill" id="nav-tab" role="tablist">
                <a class="nav-link" type="button" role="tab" aria-selected="false" href="/users/{{profile.id}}/friends">Friends</a>
              <a class="nav-link" type="button" role="tab" aria-selected="false" href="/users/{{profile.id}}/following">Following</a>
              <a class="nav-link" type="button" role="tab" aria-selected="false" href="/users/{{profile.id}}/followers">Followers</a>
              {% if profile.id == currentuser.id %}
              <a class="nav-link active" type="button" role="tab" aria-selected="true">Requests{% if currentuser.friend_requests > 0: %}<span class="badge text-bg-danger ms-1">{{currentuser.friend_requests}}</span>{%endif%}</a>
              {%endif%}
            </div>
        </nav>
        <div>
            <div class="d-flex align-items-center">
                <h4 class="m-0 mt-2">Requests ( {{FriendRequests.total}} )</h4>
                <form class="ms-auto mt-2" method="post" action="/users/{{profile.id}}/requests/clear">
                    <input type="hidden" name="csrf_token" value="{{csrf_token()}}">
                    <button class="btn btn-danger btn-sm" type="submit">Deny All</button>
                </form>
            </div>
            <div class="row mt-2">
                {% for request in FriendRequests: %}
                <div class="col-6 col-sm-4 mb-2">
                    <div class="bg-surface border p-2 rounded d-flex">
                        <a href="/users/{{request.requester.id}}/profile">
                            <img src="/Thumbs/Head.ashx?x=100&y=100&userId={{request.requester.id}}" width="80px" height="80px" class="rounded-2" alt="{{request.requester.username}}">
                        </a>
                        <div class="h-100">
                            <a class="text-body text-decoration-none ms-2" href="/users/{{request.requester.id}}/profile">{{request.requester.username}}</a>
                            <div class="ms-2 mt-4 input-group flex-nowrap" >
                                <form method="post" action="/users/{{request.requester.id}}/acceptfriend?redirect=0">
                                    <input type="hidden" name="csrf_token" value="{{csrf_token()}}">
                                    <button class="btn btn-success btn-sm rounded-end-0" type="submit"><span class="bi bi-check-lg"></span></button>
                                </form>
                                <form method="post" action="/users/{{request.requester.id}}/declinefriend?redirect=0">
                                    <input type="hidden" name="csrf_token" value="{{csrf_token()}}">
                                    <button class="btn btn-danger btn-sm rounded-start-0" type="submit"><span class="bi bi-x-lg"></span></button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                {%endfor%}
            </div>
            {% if FriendRequests.total <= 0: %}
                <p class="w-100 text-secondary text-center text-body mt-4 mb-4">No results found</p>
            {% endif %}
        </div>
        <div class="d-flex mt-2 align-items-center">
            <a class="ms-auto text-decoration-none {%if not FriendRequests.has_prev:%}text-secondary{%endif%}" {%if FriendRequests.has_prev: %}href="/users/{{profile.id}}/requests?page={{FriendRequests.page - 1}}{%endif%}">Previous</a>
            <p class="m-0 ms-2 me-2 text-body">Page {{FriendRequests.page}} of {{FriendRequests.pages}}</p>
            <a class="me-auto text-decoration-none {%if not FriendRequests.has_next: %}text-secondary{%endif%}" {%if FriendRequests.has_next: %}href="/users/{{profile.id}}/requests?page={{FriendRequests.page + 1}}{%endif%}">Next</a>
        </div>
    </div>
</div>
{% endblock %}