{% extends "/base.html" %}

{% block title %} UI Tables {% endblock %} 

<!-- Specific CSS goes HERE -->
{% block stylesheets %}{% endblock stylesheets %}

{% block content %}
{% with messages = get_flashed_messages() %}
        {% if messages %}
            <div class="flash">
                {{ messages }}
            </div>
        {% endif %}
{% endwith %}
    <!-- [ Main Content ] start -->
    <section class="pcoded-main-container">
        <div class="pcoded-wrapper">

            <div class="pcoded-content">
                <div class="pcoded-inner-content">
                    <!-- [ breadcrumb ] start -->
                    <div class="page-header">
                        <div class="page-block">
                            <div class="row align-items-center">
                                <div class="col-md-12">
                                    <div class="page-header-title">
                                        <h5 class="m-b-0"></h5>
                                    </div>
                                    <ul class="breadcrumb">
                                        <li class="breadcrumb-item"><a href="/dashboard"><i class="feather icon-home"></i></a></li>
                                        <li class="breadcrumb-item"><a href="">Users</a></li>
                                        <!-- <li class="breadcrumb-item"><a href="">Basic Tables</a></li> -->
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div> 
                    <!--
                    <div class="main-body">
                        <div class="page-wrapper">
                            <div class="row">
                                [ basic-table ] start -->
                                <div class="col-xl-12">
                                    <div class="card">
                                        <div class="card-header">
                                            <h5>User Table</h5>
                                        </div>
                                        <div style="text-align: end"><button type="submit" class="btn btn-secondary" title="Create User" onclick="window.location.href='/add_user'">Add User</button></div>
                                        <div class="card-block table-border-style">
                                            <div class="table-responsive">
                                                <table class="table">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>User Name</th>
                                                            <th>Email</th>
                                                            <th>Roll</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <!-- Your rows inside the table HERE: -->
                                                        {% for user in users.items %}
                                                        <tr>
                                                            <th scope="row">{{ user.id }}</th>
                                                            <td contenteditable="false" class="editable" data-field="username">{{ user.username }}</td>
                                                            <td contenteditable="false" class="editable" data-field="email">{{ user.email }}</td>
                                                            <td contenteditable="false" class="editable" data-field="role">{{ user.role }}</td>
                                                            <td>
                                                                <a href="/edit/{{ user.id }}" class="fas fa-pencil-alt"></a>
                                                            </td>
                                                        </tr>
                                                        {% endfor %}
                                                    </tbody>
                                                    <tfoot>
                                                        <tr>
                                                            <td colspan="4" class="text-right">
                                                                <div class="pagination-container">
                                                                    {% if users.has_prev %}
                                                                        <a href="{{ url_for('auth_blueprint.users_display', page=users.prev_num) }}" class="btn btn-primary">Previous</a>
                                                                    {% endif %}
                                                                    
                                                                    {% if users.has_next %}
                                                                        <a href="{{ url_for('auth_blueprint.users_display', page=users.next_num) }}" class="btn btn-primary">Next</a>
                                                                    {% endif %}
                                                                </div>
                                                            </td>
                                                        </tr>
                                                    </tfoot>
                                                    
                                                    
                                                    
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
            
                    </div>
    </section>
    
    <!-- [ Main Content ] end -->

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}
<script>
   document.addEventListener('DOMContentLoaded', function() {
            const flashMessage = document.querySelector(".flash");
            if (flashMessage) {
                toastMixin.fire({
                    animation: true,
                    title: flashMessage
                });
            }
        });
</script>
{% endblock javascripts %}
