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

{% block title %}Docházka{% endblock %}

{% block body %}

    <h2>Docházka</h2>
    <h3 class="h3 card-title mb-3 font-weight-normal"> Žáka {{ zak.jmeno}} {{ zak.prijmeni}} </h3>

    <hr>

    {% set var = 0 %}
    {% set poc = 0 %}
    {% for a in absence %}
        {% if a.datum|date('Y') == rok and a.zak != null and a.zak.id == zak.id and not a.pritomen == 1 %}
            {% set poc = poc + 1 %}
        {% endif %}
        {% if not app.user.rodic == null %}
            {% for z in app.user.rodic.zak %}
                {% if a.zak != null and a.zak.id == z.id %}
                    {% set var = a.id %}
                {% endif %}
            {% endfor %}
        {% endif %}
    {% endfor %}


    <div class="card shadow-sm justify-content-center" style= "margin: 20px; height:40px">
        <span>
            Celkový počet zameškaných hodin: {{ poc }}
        </span>
    </div>

    <div class="text-left">
        {{ form_start(form) }}

        <div class="input-group mb-3">
            <div class="input-group-prepend">

                {% if is_granted('ROLE_PARENT') %}

                    <a href="{{ path('absence.omluvenka', {absence: var, new: 1}) }}" class="btn btn-outline-primary btn-group">Přidat Omluvenku</a>

                {% endif %}

                {{ form_widget(form.vyber) }}

            </div>
            {{ form_widget(form.rok) }}
        </div>

        {{ form_end(form) }}
    </div>

    <div class="shadow" style="width: max-content;">
        <table id="table" data-toggle="table" data-height="500"
               class="table table-bordered table-borderless">
            <thead class="thead-light">
            <tr>
                {% if is_granted('ROLE_PARENT') %}
                <th> ID </th>
                {% endif %}
                <th> Předmět </th>
                <th> Datum </th>
                <th> Čas </th>
                <th> Info </th>
                <th> Přítomen </th>
            </tr>
            </thead>

            <tbody>


            {% for a in absence %}
                {% if a.zak != null and a.zak.id == zak.id and a.datum|date('Y') == rok %}

            <tr style="transform: rotate(0);">
                {% if is_granted('ROLE_PARENT') %}
                    <td scope="colgroup" style="background-color: #808080; color: #f2f2f2">
                        <a href="{{ path('absence.omluvenka', {absence: a.id, new: 0}) }}" class="stretched-link">{{ a.id }}</a>
                    </td>
                {% endif %}

                <td style="background-color: #bfbfbf">
                    {% if a.predmet == null %}
                        <span>N/A</span>
                    {% else %}
                        {{ a.predmet }}
                    {% endif %}
                </td>

                <td>
                    {% if a.datum == null %}
                        <span>N/A</span>
                    {% else %}
                        {{ a.datum|date('d-M-Y') }}
                    {% endif %}
                </td>

                <td>
                    {% if a.doba == null %}
                        <span>N/A</span>
                    {% else %}
                        {{ a.doba }}
                    {% endif %}
                </td>

                <td>
                    {% if a.poznamka == null %}
                        <span>N/A</span>
                    {% else %}
                        {{ a.poznamka }}
                    {% endif %}
                </td>

                <td style="background-color: #808080; color: #f2f2f2">
                    {% if a.pritomen == 1 %}
                        <span>Ano</span>
                    {% else %}
                        <span>Ne</span>
                    {% endif %}
                </td>
            </tr>

                {% endif %}
            {% endfor %}
            {% set poc = 0 %}

            </tbody>
        </table>
    </div>

{% endblock %}