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

{% block title %} Catégorie {% 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">Catégories</h1>
    <ol class="breadcrumb float-sm-right">
        <li class="breadcrumb-item">Catégorie</li>
    </ol>
</div>

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

    {% if categorie.id is empty%}
        <div class="card mb-4">
            <div class="card-header">
                Ajouter une nouvelle catégorie
            </div>
            <div class="card-body">
                {{ form_start(form, {'action': path('backend_admin_categorie_add'), 'method': 'POST'}) }}
                    <div class="row g-3">
               
                        <div class="col-6 my-3">
                            {{ form_label(form.nom, 'Nom Catégorie', {'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-6 my-3">
                            {{ form_label(form.groupeCategorie, 'Nom du groupe', {'attr': {'class': 'form-label'}}) }}
                            <div class="input-group">
                                
                                {{ form_widget(form.groupeCategorie, {'attr': {'class': 'form-control' }}) }}
                                <div class="invalid-feedback">
                                    {{ form_errors(form.groupeCategorie) }}
                                </div>
                            </div>
                        </div>

                        <div class="col-4">
                            {{ 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 une  catégorie
            </div>
            <div class="card-body">
                {{ form_start(form, {'action': path('backend_admin_categorie_update',{'id': categorie.id}), 'method': 'POST'}) }}
                    <div class="row g-3">
                        <div class="col-6 my-3">
                            {{ form_label(form.nom, 'Nom Catégorie', {'attr': {'class': 'form-label'}}) }}
                            <div class="input-group">
                                
                                {{ form_widget(form.nom, {'attr': {'class': 'form-control', 'value':categorie.nom }}) }}
                                <div class="invalid-feedback">
                                    {{ form_errors(form.nom) }}
                                </div>
                            </div>
                        </div>

                        <div class="col-6 my-3">
                            {{ form_label(form.groupeCategorie, 'Nom du groupe', {'attr': {'class': 'form-label'}}) }}
                            <div class="input-group">
                                
                                {{ form_widget(form.groupeCategorie, {'attr': {'class': 'form-control'}}) }}
                                <div class="invalid-feedback">
                                    {{ form_errors(form.groupeCategorie) }}
                                </div>
                            </div>
                        </div>

                        <div class="col-4">
                            {{ form_widget(form.save, {'label': "Modifier", 'attr': {'class': 'w-90 btn btn-primary '}}) }} 
                        </div>
                    
                    </div>
                {{ form_end(form) }}
            </div>
        </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 catégories</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table id="dataTableCategorie" class="table table-bordered" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Nom</th>
                            <th>Nombre des annonces</th>
                            <th>Modifier</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>#</th>
                            <th>Nom</th>
                            <th>Nombre des annonces</th>
                            <th>Modifier</th>
                        </tr>
                    </tfoot>
                    <tbody>
                        {% for categorie in categories %}
                            <tr>
                                <td>{{ categorie.id }}</td>
                                <td>{{ categorie.nom }}</td>
                                <td></td>
                                <td>    
                                    <a href="{{ path('backend_admin_categorie_index',{idCategorie:categorie.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 %}