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

{% block title %}{% endblock %}

{% block stylesheets %}
    <link rel="stylesheet" type="text/css" href="{{ asset('plugins/table/datatable/datatables.css') }}">
    <link rel="stylesheet" type="text/css" href="{{ asset('plugins/table/datatable/dt-global_style.css') }}">
    <link href="{{ asset('assets/css/components/custom-modal.css') }}" rel="stylesheet" type="text/css"/>
    <link href="{{ asset('assets/css/scrollspyNav.css') }}" rel="stylesheet" type="text/css" />
    <link href="{{ asset('plugins/flatpickr/custom-flatpickr.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('plugins/noUiSlider/custom-nouiSlider.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('plugins/bootstrap-range-Slider/bootstrap-slider.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('plugins/summernote/summernote-bs4.css') }}" rel="stylesheet" type="text/css">
{% endblock %}

{% block body %}
       <div class="layout-px-spacing">
    <div class="page-header">
        <div class="page-title">
            <h3>Gestion des taches</h3>
        </div>
        <button type="button" class="btn btn-primary mb-2 mr-2" data-toggle="modal"
                data-target="#addUser" style="float: right; margin-bottom: 16px; margin-top: 30px;">
            Ajouter une tache
        </button>
        <!-- Modal -->
        <div class="modal fade" id="addUser" tabindex="-1" role="dialog"
             aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Ajouter une tache</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                 viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
                                 stroke-linecap="round" stroke-linejoin="round" class="feather feather-x">
                                <line x1="18" y1="6" x2="6" y2="18"></line>
                                <line x1="6" y1="6" x2="18" y2="18"></line>
                            </svg>
                        </button>
                    </div>
                    <form method="post" enctype="multipart/form-data">
                        <div class="modal-body">
                            <div class="row mb-4">
                                <div class="col">
                                    <input type="text" name="mission" class="form-control" placeholder="Mission" required>
                                </div>
                            </div>
                            <div class="row mb-4">
                                <div class="col-12 form-group mb-4">
                                    <textarea type="text" name="description" class="form-control summernote"
                                              placeholder="Travaux effectues" required></textarea>
                                </div>
                            </div>
                            <div class="col-12 form-group mb-4">
                                <select class="form-control" name="client" required>
                                    <option selected="selected" disabled>Choisir un client......</option>
                                    {% for client in clients %}
                                        <option value="{{ client.id }}">{{ client.company }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                            <div class="row mb-4">
                                <div class="col-lg-6">
                                    <input type="number" step="0.25" min="0.25" max="8" name="hours" class="form-control" placeholder="Nombre d'heures" required>
                                </div>
                                <div class="col-lg-6">
                                    <div class="form-group mb-0">
                                        <input class="form-control" type="date" name="date" value="{{ "now"|date("Y-m-d") }}" required>
                                    </div>
                                </div>
                            </div>

                        </div>
                        <div class="modal-footer">
                            <button class="btn" data-dismiss="modal"><i class="flaticon-cancel-12"></i> Annuler
                            </button>
                            <button type="submit" class="btn btn-primary">Enregistrer</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="row" id="cancel-row">

        <div class="col-xl-12 col-lg-12 col-sm-12  layout-spacing">
            <div class="widget-content widget-content-area br-6">
                <div class="table-responsive mb-4 mt-4">
                    <table id="zero-config" class="table table-hover" style="width:100%">
                        <thead>
                        <tr>
                            {% if (is_granted('ROLE_ADMIN')) %}
                            <th>Collaborateur</th>
                            {% endif %}
                            <th>Date</th>
                            <th>Client</th>
                            <th>Mission</th>
                            <th>Temps (heures)</th>
                            <th class="no-content"></th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for task in tasks %}
                            <tr>
                                {% if (is_granted('ROLE_ADMIN')) %}
                                    {% if 'ROLE_ADMIN' in task.collaborater.roles %}
                                        <td>Vous</td>
                                    {% else %}
                                        <td>
                                            {{ task.collaborater.getFirsName ~ ' ' ~ task.collaborater.getLastName }}
                                        </td>
                                    {% endif %}
                                {% endif %}
                                <td>{{ task.date|date("d/m/Y") }}</td>
                                <td>{{ task.client.company }}</td>
                                <td>{{ task.mission }}</td>
                                <td>{{ task.hours }}</td>
                                <td>
                                    {% if (is_granted('ROLE_ADMIN')) %}
                                    {#<a href="{{ path('comptable_edit', {'id': task.id}) }}"
                                       class="btn btn-warning mb-2 mr-2 rounded-circle" title="modifier">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                             viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
                                             stroke-linecap="round" stroke-linejoin="round"
                                             class="feather feather-user-plus">
                                            <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
                                            <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
                                        </svg>
                                    </a>#}
                                    <form method="post" action="{{ path('time_management_delete', {'id': task.id}) }}"
                                          onsubmit="return confirm('Êtes-vous sûr de vouloir supprimer {{ task.mission }}');"
                                          style="display: inline">
                                        <input type="hidden" name="_method" value="DELETE">
                                        <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ task.id) }}">
                                        <button class="btn btn-danger mb-2 mr-2 rounded-circle" title="Supprimer">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                                 viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
                                                 stroke-linecap="round" stroke-linejoin="round"
                                                 class="feather feather-trash-2">
                                                <polyline points="3 6 5 6 21 6"></polyline>
                                                <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
                                                <line x1="10" y1="11" x2="10" y2="17"></line>
                                                <line x1="14" y1="11" x2="14" y2="17"></line>
                                            </svg>
                                        </button>
                                    </form>
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

    </div>
</div>
{% endblock %}

{% block javascripts %}
    <script src="{{ asset('plugins/table/datatable/datatables.js') }}"></script>
    <script src="{{ asset('assets/js/scrollspyNav.js') }}"></script>
    <script src="{{ asset('plugins/flatpickr/flatpickr.js') }}"></script>
    <script src="{{ asset('plugins/noUiSlider/nouislider.min.js') }}"></script>

    <script src="{{ asset('plugins/flatpickr/custom-flatpickr.js') }}"></script>
    <script src="{{ asset('plugins/noUiSlider/custom-nouiSlider.js') }}"></script>
    <script src="{{ asset('plugins/bootstrap-range-Slider/bootstrap-rangeSlider.js') }}"></script>
    <script src="{{ asset('plugins/summernote/summernote-bs4.min.js') }}"></script>
    <script>
        $('.summernote').summernote({
            placeholder: 'Travaux effectues',
            tabsize: 2,
            height: 100
        });
        $('#zero-config').DataTable({
            "oLanguage": {
                "oPaginate": {
                    "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>',
                    "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>'
                },
                "sInfo": "Afficher la page _PAGE_ de _PAGES_",
                "sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
                "sSearchPlaceholder": "Recherche...",
                "sLengthMenu": "Résultats :  _MENU_",
            },
            "stripeClasses": [],
            "lengthMenu": [7, 10, 20, 50],
            "pageLength": 7
        });
    </script>

{% endblock %}