{% extends 'admin_base.html.twig' %}

{% block title %}{{ title }}{% endblock %}

{% block body %}
    <h1>{{ title }}</h1>
    <div class="my-2">
        {{ include('specialist/admin/_form.html.twig') }}
    </div>

    <table class="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>FIO</th>
                <th>Picture</th>
                <th>Address</th>
                <th>Department</th>
                <th>Dcode or bitrixID</th>
                <th>Active</th>
                <th>Actions</th>
                <th>Updated Location</th>
                <th>Update</th>
            </tr>
        </thead>
        <tbody>
        {% for specialist in pagination %}
            <tr span="5">
                <td>{{ specialist.id }}</td>
                <td>{{ specialist.name }}</td>
                <td><a href="/specialist/picture/{{ specialist.id }}?size=1" target="_blank">show picture</a></td>
                
                {% if specialist.locationAllCount > 0 %}
                    <td>
                        {% for location in specialist.locationAll %}
                            <p>{{ location.filial.address }}</p>
                        {% endfor %}
                    </td>
                {% else %}
                    <td>there is no data</td>
                {% endif %}

                {% if specialist.locationAllCount > 0 %}
                    <td>
                        {% for location in specialist.locationAll %}
                            <p>{{ location.department.did }}</p>
                        {% endfor %}
                    </td>
                {% else %}
                    <td>there is no data</td>
                {% endif %}

                {% if specialist.locationAllCount > 0 %}
                    <td>
                        {% for location in specialist.locationAll %}
                            <p>{{ location.dcode }}</p>
                        {% endfor %}
                    </td>
                {% else %}
                    <td>there is no data</td>
                {% endif %}
                
                {% if specialist.locationAllCount > 0 %}
                    <td>
                        {% for location in specialist.locationAll %}
                            <p>{{ location.active ? 'on' : 'off'  }}</p>
                        {% endfor %}
                    </td>
                {% else %}
                    <td>there is no data</td>
                {% endif %}

                {% if specialist.locationAllCount == 0 %}
                    <td>disabled</td>
                {% else %}
                    <td>
                        {% for location in specialist.locationAll %}
                            {{ include('specialist/admin/_toggle_form.html.twig') }}
                        {% endfor %}
                    </td>
                {% endif %}

                {% if specialist.locationAllCount > 0 %}
                    <td>
                        {% for location in specialist.locationAll %}
                            <p>{{ location.updated|date('d.m.Y') }}</p>
                        {% endfor %}
                    </td>
                {% else %}
                    <td>there is no data</td>
                {% endif %}

                {% if specialist.updated is defined %}
                    <td>
                        <p>{{ specialist.updated|date('d.m.Y') }}</p>
                    </td>
                {% else %}
                    <td>there is no data</td>
                {% endif %}

            </tr>
        {% else %}
            <tr>
                <td colspan="6">no records found</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

     <div class="d-block text-center">
        {{ knp_pagination_render(pagination) }}
    </div>
{% endblock %}
