{% extends "layout.html" %}

{% block title %}
    <p>List of Patients</p>
{% endblock %}

{% block body %}

<div class="search_block">
    <form action="/patients" method="POST">
        <div class="birthday_since_blok">
            <label for="birthday_since">Birthday since:</label>
            <input type="date" name="birthday_since" value="0000-00-00">
        </div>

        <div class="birthday_till_blok">
            <label for="birthday_till">Birthday till:</label>
            <input type="date" name="birthday_till" placeholder="dd.mm.yyyy">
        </div>

        <div class="by_doctor_search">
            <label for="doctor_id">Doctor:</label>
            <select name="doctor_id" >
                <option value="" >Any doctor</option>
                {% for doctor in doctors %}
                <option value={{ doctor['id'] }}>
                    {{ doctor['first_name'] }} {{ doctor['last_name'] }}
                </option>
                {% endfor %}

            </select>
        </div>
        
        <input type="submit" id="button" value="SEARCH">
    </form>
</div>

<div class="patient_list">
    <table class="table">
    <tr>
        <th>Name</th>
        <th>Age</th>
        <th>Gender</th>
        <th>Health State</th>
        <th>Doctor</th>
    </tr>
    {% for patient in patients %}
    <tr>
        <td>
            <a href="{{url_for('patient', id=patient['id'])}}">
                {{ patient['first_name'] }} {{ patient['last_name'] }}
            </a>
        </td>
        <td>{{ patient['age'] }}</td>
        <td>{{ patient['gender'] }}</td>
        <td>{{ patient['health_state'] }}</td>
        <td>
            {% set doctor = patient['doctor'] %}
            {% if doctor %}
            <a href="{{url_for('get_doctor', id=patient['doctor_id'])}}">
                {{ doctor['first_name'] }} {{ doctor['last_name'] }}
            </a>
            {% endif %}
        </td>
    </tr>
    {% endfor %}
    </table>
</div> 
{% endblock %}