{% extends "auth/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block page_content %}

<div class="page-header">
    <h1>Manage Project Access</h1>
</div>

<div class="container mt-5">

    <a href="{{ back_url }}"><button type="button" class="btn btn-light btn-lg mb-3"><i class="fas fa-chevron-circle-left mr-3"></i>Return to Project Information</button></a>

    <div class="card" >
        <div class="card-header">Project Information</div>
        <div class="card-body">
            <p class="card-text font-weight-light font-italic">This section gives information on which user and group owns the project. Only dashboard admin and group managers can manage edit group members and access. This must be done in the admin section of the dashboard.</p>

            <div id="project-info-table" class="d-flex justify-content-center">
                <table class="table table-striped table-responsive-sm">
                    <tr>
                        <td>Project ID</td>
                        <td>{{ project.id }}</td>
                    </tr>
                    <tr>
                        <td>Project Name</td>
                        <td>{{ project.name }}</td>
                    </tr>
                    <tr>
                        <td>Project Owner</td>
                        <td>{{ project.owner.username }}</td>
                    </tr>
                    <tr>
                        <td>Project Group</td>
                        <td>{{ project.group.name }}</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
        

    <form action method="post">
        {{ form.csrf_token }}
        <div class="card" >
            <div class="card-header">
                {{ project.name }}: Special Permissions<span class="edit-section float-right" id="group-info-button"></span>
            </div>
            <div class="card-body" id="group-info">
                <h5 class="card-title">Set Special User Permissions</h5>
               
                <p class="card-text font-weight-light font-italic">Give individual dashboard users access and permissions to the project. This section will only reflect special user permissions. Your username is listed first, be careful managing your access.</p>

                <fieldset class="form-group">
        
                    <div class="form-group">
                        <table class="table">
                            <tr>
                                <th>User Name</th>
                                <th>read</th>
                                <th>update</th>
                                <th>create</th>
                                <th>delete</th>
                                <th>manage</th>
                            </tr>
        
                            {% for user in users %}
                                <tr>  
                                <td>{{ user["username"] }}</td>
                                    {% for permission in ["read", "update", "create", "delete", "manage"] %}
                                        <td>
                                            {{ form["user_"+user["id"]|string+"_"+permission] }}
                                        </td>
                                    {% endfor %}
                                </tr>
                            {% endfor %}
                        </table>
                    </div>
                </fieldset>
            </div>
        </div>
        <div class="mb-5"> 
            {{ wtf.form_field(form.submit, class="btn btn-primary form-control") }}
        </div>
    </form>
</div>
</div>


{% endblock %}

