{% extends 'layouts/admin.twig' %}

{% block content %}

    <ul class="breadcrumbs el">
        <li><a href="/admin/">Admin</a> /</li>
        <li class="end">List of patients</li>
    </ul>

    <h1>{{ title }}</h1>

    {% include 'admin/patients/tabnav.twig' %}

    <form action="" method="GET" class="style">
        <fieldset class="show">
            <h1><a class="show el">Search <i class="fa fa-caret-right"></i></a></h1>
            <div class="row">
                <label for="memeberid">Patient ID</label>
                <input type="text" name="id" id="memeberid" value="{{ request.id }}" />
            </div>
            <div class="row">
                <label for="firstname">Firstname</label>
                <input type="text" name="firstname" id="firstname" value="{{ request.firstname }}" />
            </div>
            <div class="row">
                <label for="lastname">Surname</label>
                <input type="text" name="lastname" id="lastname" value="{{ request.lastname }}" />
            </div>
            <div class="row">
                <label for="email">Email</label>
                <input type="text" name="email" id="email" value="{{ request.email }}" />
            </div>
            <div class="row">
                <label for="contact_no">Phone Number</label>
                <input type="text" name="contact_no" id="contact_no" value="{{ request.contact_no }}" />
            </div>
            <div class="row">
                <label for="date_of_birth">Date of Birth</label>
                <input type="text"
                       name="date_of_birth"
                       placeholder="dd/mm/yyyy e.g. 06/07/1990"
                       id="date_of_birth"
                       value="{{ request.date_of_birth }}" />
            </div>
            {% if showNewsletterFilter %}
                <div class="row">
                    <label for="newsletter">
                        Subscribed to newsletter
                    </label>
                    <select name="newsletter"
                            id="newsletter"
                    >
                        <option value="">
                            Any
                        </option>
                        <option value="yes"
                                {{ request.newsletter == 'yes' ? 'selected' : '' }}
                        >
                            Yes
                        </option>
                        <option value="no"
                                {{ request.newsletter == 'no' ? 'selected' : '' }}
                        >
                            No
                        </option>
                    </select>
                </div>
            {% endif %}

            <div class="search-button">
                <input type="hidden" name="action" value="search"/>
                <input type="submit" value="Search" class="BUTTON"/>
            </div>
        </fieldset>
    </form>

{% if patients.count() > 0 %}
    <table class="manage-items">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Phone Number</th>
            <th>Age</th>
            {% if can('LOGIN_AS_PATIENT') %}
                <th class="center">Login as</th>
            {% endif %}
            <th class="center">View</th>
        </tr>
        <tbody class="tabular">
    {% for patient in patients %}
        <tr id="rorder-{{ patient.id }}">
            <td>
                <a href="{{ route('admin-patients-profile', {
                    'id': patient.id
                }) }}">
                    {{ patient.id }}
                </a>
            </td>
            <td>
                <a href="{{ route('admin-patients-profile', {
                    'id': patient.id
                }) }}">
                    {{ patient.addressBilling.firstname }} {{ patient.addressBilling.lastname }}
                </a>
            </td>
            <td>{{ patient.email }}</td>
            <td>{{ patient.contact_no }}</td>
            <td>{{ patient.age }}</td>

            {% if can('LOGIN_AS_PATIENT') %}
                <td>
                    <a href="{{ route('admin-login-as-member', {
                        id: patient.id
                    }) }}"
                       target="_blank"
                    >
                        Login
                        <i class="fa fa-sign-in" aria-hidden="true"></i>
                    </a>
                </td>
            {% endif %}

            <td class="center">
                <a href="{{ route('admin-patients-profile', {
                    'id': patient.id
                }) }}" class="edit">
                    <i class="fa fa-eye"></i>
                </a>
            </td>
        </tr>
    {% endfor %}
        </tbody>
    </table>

    <form action="{{ route('admin-patients-export') }}" method="post" class="style">
        <fieldset class="show">
            <h1><a class="show el">Export Patients <i class="fa fa-caret-down"></i></a></h1>
            <div class="row">Click export below to export the above patients as a CSV</div>
        </fieldset>
        <div class="row">
            <input type="hidden" name="id" value="{{ request.id }}"/>
            <input type="hidden" name="firstname" value="{{ request.firstname }}"/>
            <input type="hidden" name="lastname" value="{{ request.lastname }}"/>
            <input type="hidden" name="email" value="{{ request.email }}"/>
            <input type="hidden" name="contact_no" value="{{ request.contact_no }}"/>
            <input type="submit" value="Export"/>
        </div>
    </form>

{% else %}
    <p>There were no patients found matching your search criteria</p>
{% endif %}

{% endblock %}