{% extends '@Approval/layout.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}

{% block report_title %}{{ report_title|trans }}{% endblock %}

{% block page_actions %}
    {% import "macros/widgets.html.twig" as widgets %}
    {% if (is_granted('ROLE_SUPER_ADMIN')) %}
        {% set actions = {'create': {'url': path('approval_create_workday_history'), 'class': 'modal-ajax-form', 'attr': {'data-event': 'kimai.appWorkdayHistory'}, 'title': 'create'}} %}
        {% set event = trigger('actions.create_workday_history', {'actions': actions, 'view': 'create'}) %}
        {{ widgets.page_actions(event.payload.actions) }}
    {% endif %}
{% endblock %}

{% block report %}
    {% set tableName = 'workday_history' %}

    <p>{{ 'description.workday_history'|trans }}</p>

    {% if tables is defined %}
      <div class="row">
          <div class="col-md-12">
              {{ tables.data_table_column_modal(tableName, columns) }}
              {{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.leaveUpdate'}) }}
          </div>
      </div>
    {% endif %}

    <table class="table table-hover dataTable">
        <thead>
            <tr>
                <th>{{ 'user'|trans }}</th>
                <th class="text-center">{{ 'Monday'|trans({},'system-configuration')}}</th>
                <th class="text-center">{{ 'Tuesday'|trans({},'system-configuration')}}</th>
                <th class="text-center">{{ 'Wednesday'|trans({},'system-configuration')}}</th>
                <th class="text-center">{{ 'Thursday'|trans({},'system-configuration')}}</th>
                <th class="text-center">{{ 'Friday'|trans({},'system-configuration')}}</th>
                <th class="text-center">{{ 'Saturday'|trans({},'system-configuration')}}</th>
                <th class="text-center">{{ 'Sunday'|trans({},'system-configuration')}}</th>
                <th class="text-center">{{ 'label.valid_till'|trans}}</th>
                <th class="actions"></th>
            </tr>
        </thead>
        <tbody>
            {% for entry in workdayHistory %}
                <tr>
                    <td class="text-center">{{ entry.user.displayName }}</td>
                    <td class="text-center">{{ entry.monday | duration }}</td>
                    <td class="text-center">{{ entry.tuesday | duration }}</td>
                    <td class="text-center">{{ entry.wednesday | duration }}</td>
                    <td class="text-center">{{ entry.thursday | duration }}</td>
                    <td class="text-center">{{ entry.friday | duration }}</td>
                    <td class="text-center">{{ entry.saturday | duration }}</td>
                    <td class="text-center">{{ entry.sunday | duration }}</td>
                    <td class="text-center">{{ entry.validTill | date_format('Y-m-d') }}</td>
                    <td class="actions">
                        {% set deleteLinkPath = path('delete_workday_history', {'entryId': entry.id, 'attr': {}}) %}
                        <a href="{{ deleteLinkPath }}" class="btn btn-trash btn-icon api-link text-red" data-event="kimai.historyDelete" data-method="GET" data-question="confirm.delete" data-msg-error="action.delete.error" data-msg-success="action.delete.success">
                            <i class="fa fa-trash"></i>
                        </a>
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% endblock %}
