<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>
        Requests
    </title>
    <!--     Fonts and icons     -->
    {% include 'admin/includes/imports.top.html' %}
</head>

<body class="g-sidenav-show  bg-gray-100">
    {% include 'admin/includes/part.menu.html' %}
    <main class="main-content position-relative max-height-vh-100 h-100 border-radius-lg ">
        <!-- Navbar -->
        {% include 'admin/includes/part.header.html' %}
        <!-- End Navbar -->
        <div class="container-fluid py-4">
            <div class="row g-2">
                <div class="col-md-12">
                    <div class="card mb-4">
                        <div class="card-header pb-0">
                            <h6>Requests</h6>
                        </div>
                        <div class="card-body px-0 pt-0">
                            <div class="table-responsive p-0">
                                <table class="table align-items-center mb-0">
                                    <thead>
                                        <tr>
                                            <th
                                                class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">
                                                #</th>
                                            <th
                                                class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">
                                                Name & Email</th>
                                            <th
                                                class="text-start text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">
                                                Phone</th>
                                            <th
                                                class="text-start text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">
                                                Car Details</th>
                                            <th
                                                class="text-start text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">
                                                Subject</th>
                                            <th
                                                class="text-start text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">
                                                Date</th>
                                            <th
                                                class="text-start text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">
                                                Opened & <br> Completed</th>
                                            <th
                                                class="text-start text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">
                                                #</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for q in questions %}
                                        <tr>
                                            <td class="align-middle text-center text-sm">
                                                <div>
                                                    <img src="{{url_for('static', filename='files')}}/{{q.requests.images[0]}}"
                                                        class="avata avatar img-fluid border shadow" alt="user1">
                                                </div>
                                            </td>
                                            <td>
                                                <div class="d-flex px-2 py-1">

                                                    <div class="d-flex flex-column justify-content-center">
                                                        <h6 class="mb-0 text-sm">{{ q.name }}</h6>
                                                        <a href="mailto://{{ q.email }}"
                                                            class="text-xs text-secondary mb-0">{{ q.email }}</a>
                                                    </div>
                                                </div>
                                            </td>
                                            <td class="align-middle text-start text-sm">
                                                <a href="tel://{{q.phone}}"
                                                    class="badge text-dark text-xs ps-1 badge-sm rounded-0 border-2 p-0 border-start border-info">{{q.phone}}</a>
                                            </td>
                                            <td class="align-middle text-start text-sm">
                                                <span class="mb-0 text-sm">
                                                    {{q.requests.year}} {{q.requests.model2.car_make.name}}
                                                    {{q.requests.model2.name}}
                                                </span>
                                            </td>
                                            <td class="align-middle text-start text-sm">
                                                <span class="mb-0 text-sm">
                                                    {{q.subject | truncate(30)}}
                                                </span>
                                            </td>
                                            <td class="align-middle text-start text-sm">
                                                <span class="mb-0 text-sm">
                                                    {{q.date | humanize_date}}
                                                </span>
                                            </td>
                                            <td class="align-middle text-start text-sm">
                                                <div>{% if q.seen %}
                                                    <span
                                                        class="badge text-dark ps-1 badge-sm rounded-0 border-2 p-0 border-start border-success">
                                                        Opened
                                                    </span>
                                                    {% else %}
                                                    <span
                                                        class="badge text-dark ps-1 badge-sm rounded-0 border-2 p-0 border-start border-danger">
                                                        Not Opened
                                                    </span>
                                                    {% endif %}
                                                </div>
                                                <div>
                                                    {% if q.completed %}
                                                    <span
                                                        class="badge text-dark ps-1 badge-sm p-0 rounded-0 border-2 border-start border-success">
                                                        Completed
                                                    </span>
                                                    {% else %}
                                                    <span
                                                        class="badge text-dark ps-1 badge-sm p-0 rounded-0 border-2 border-start border-danger">
                                                        Not Completed
                                                    </span>
                                                    {% endif %}
                                                </div>
                                            </td>
                                            <td class="align-middle text-center text-sm">
                                                <a href="{{url_for('open_request', id=q.id)}}"
                                                    class=" badge badge-sm border-1 border-info bg-info">Open</a>

                                            </td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="card-footer">
                            <div class="d-flex justify-content-center">
                                {% set current_page = request.args.get('page', none) | int%}

                                {% set pvis = '' %}
                                {% set nvis = '' %}

                                {% if last_page %}
                                {% set nvis = 'disabled' %}
                                {% endif %}

                                {% if current_page == 0 or current_page == 1 %}
                                {% set current_page = 1 %}
                                {% set pvis = 'disabled' %}
                                {% endif %}

                                {% set next = current_page + 1%}
                                {% set prev = current_page - 1%}

                                {% set prev_url = url_for('admin_requests', page=prev)%}
                                {% set next_url = url_for('admin_requests', page=next)%}


                                <div class="pagination-area">
                                    <div aria-label="Page navigation example">
                                        <ul class="pagination my-3">
                                            <li class="page-item">
                                                <a class="{{pvis}} page-link bg-info text-white border-black"
                                                    href="{{prev_url}}" aria-label="Previous">
                                                    <span aria-hidden="true"><i
                                                            class="fa text-white fa-angle-double-left"></i></span>
                                                </a>
                                            </li>
                                            <li class="page-item">
                                                <a class="{{nvis}}  page-link bg-info text-white border-black"
                                                    href="{{next_url}}" aria-label="Next">
                                                    <span aria-hidden="true"><i
                                                            class="fa text-white fa-angle-double-right"></i></span>
                                                </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {% include 'admin/includes/part.footer.html' %}
        </div>
    </main>
    <!--   Core JS Files   -->
    {% include 'admin/includes/imports.bottom.html' %}
    <script>
        var win = navigator.platform.indexOf('Win') > -1;
        if (win && document.querySelector('#sidenav-scrollbar')) {
            var options = {
                damping: '0.5'
            }
            Scrollbar.init(document.querySelector('#sidenav-scrollbar'), options);
        }
    </script>
</body>

</html>