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

{% block title %} Groupe des catégories {% endblock %}

{% block content %}
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-gray-800">Groupe des catégories</h1>
    <ol class="breadcrumb float-sm-right">
        <li class="breadcrumb-item">Groupe des catégories</li>
    </ol>
</div>




<!-- Begin Page Content -->
<div class="container-fluid">
    
    {% include 'backend_admin/basic/notice.html.twig' %}

    
    {% if groupe.id is empty%}
        <div class="card mb-4">
            <div class="card-header">
                Ajouter un nouveau groupe
            </div>
            <div class="card-body">
                
                    {{ form_start(form, {'action': path('backend_admin_groupe_categorie_add'), 'method': 'POST'}) }}
                        <div class="row g-3">
                            <div class="col-3">
                                {{ form_label(form.nom, 'Nom de groupe', {'attr': {'class': 'form-label'}}) }}
                                <div class="input-group">
                                    
                                    {{ form_widget(form.nom, {'attr': {'class': 'form-control'}}) }}
                                    <div class="invalid-feedback">
                                        {{ form_errors(form.nom) }}
                                    </div>
                                </div>
                            </div>

                            <div class="col-3 offset-1">
                                {{ form_label(form.icon_fontawesome, 'Icon fontawesome menu', {'attr': {'class': 'form-label'}}) }}
                                <div class="input-group">
                                    
                                    {{ form_widget(form.icon_fontawesome, {'attr': {'class': 'form-control'}}) }}
                                    <div class="invalid-feedback">
                                        {{ form_errors(form.icon_fontawesome) }}
                                    </div>
                                </div>
                            </div>

                            <div class="col-3 offset-1">
                                {{ form_label(form.image, 'Image memu', {'attr': {'class': 'form-label'}}) }}
                                {{ form_widget(form.image, {'attr': {'class': 'form-control'}}) }}
                                <div class="invalid-feedback">{{ form_errors(form.image) }}</div>
                            </div>

                            <div class="col-md-2">
                                {{ form_widget(form.save, {'label': "Ajouter", 'attr': {'class': 'w-90 btn btn-primary '}}) }} 
                            </div>
                        </div>
                    {{ form_end(form) }}
                
            </div>
        </div>
    {% else %}
        <div class="card mb-4">
            <div class="card-header">
                Modifier un groupe
            </div>
            <div class="card-body">
                {{ form_start(form, {'action': path('backend_admin_groupe_categorie_update',{'id': groupe.id}), 'method': 'POST'}) }}
                    <div class="row g-3">
                        <div class="col-3">
                            {{ form_label(form.nom, 'Nom de groupe', {'attr': {'class': 'form-label'}}) }}
                            <div class="input-group">
                                
                                {{ form_widget(form.nom, {'attr': {'class': 'form-control'}}) }}
                                <div class="invalid-feedback">
                                    {{ form_errors(form.nom) }}
                                </div>
                            </div>
                        </div>

                        <div class="col-3 offset-1">
                            {{ form_label(form.icon_fontawesome, 'Icon fontawesome menu', {'attr': {'class': 'form-label'}}) }}
                            <div class="input-group">
                                
                                {{ form_widget(form.icon_fontawesome, {'attr': {'class': 'form-control'}}) }}
                                <div class="invalid-feedback">
                                    {{ form_errors(form.icon_fontawesome) }}
                                </div>
                            </div>
                        </div>

                        <div class="col-3">
                            {{ form_label(form.image, 'Image memu', {'attr': {'class': 'form-label'}}) }}
                            {{ form_widget(form.image, {'attr': {'class': 'form-control'}}) }}
                            <div class="invalid-feedback">{{ form_errors(form.image) }}</div>
                        </div>

                        <div class="col-1">
                            <a href="{{ path('backend_admin_groupe_categorie_remove_image',{id:groupe.id}) }}" class="btn btn-danger  mt-4">
                            <i class="fa-solid fa-trash"></i> Image</a>
                        </div>

                        <div class="col-md-2">
                            {{ form_widget(form.save, {'label': "Modifier", 'attr': {'class': 'w-90 btn btn-primary '}}) }} 
                        </div>
                    </div>
                {{ form_end(form) }}
            </div>
    {% endif %}
             

    <!-- DataTales Example -->
    <div class="card shadow mb-4">
       
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Liste des groupes</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTableGroupes" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Nom</th>
                            <th>Liste des catégories</th>
                            <th>Modifier</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>#</th>
                            <th>Nom</th>
                            <th>Liste des catégories</th>
                            <th>Modifier</th>
                        </tr>
                    </tfoot>
                    <tbody>
                        {% for groupe in groupes %}
                            <tr>
                                <td>{{ groupe.id }}</td>
                                <td>{{ groupe.nom }}</td>
                                <td>
									<ul class="list-group list-group-flush">
										{% for categorie in groupe.getCategories() %}
											<li class="list-group-item">{{ categorie.getNom() }}</li>
										{% endfor %}
									</ul>
								</td>
                                <td>    
                                    <a href="{{ path('backend_admin_groupe_categorie_index',{idGroupe:groupe.id}) }}" title="modifier" class="btn btn-info btn-action"><i class="fa fa-edit"></i></a>
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>               
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    {{ encore_entry_script_tags('app_backend_other') }}
{% endblock %}