{% extends 'base.html.twig' %}
{% block title %}
	{{parent()}}Liste des categories
{% endblock %}
{% block body %}
	<div class="container-fluid">
		<h1 class="text-center text-primary mt-4 pt-4 display-1 fw-bold">
			LISTE DES CATEGORIES</h1>
		<div class="row justify-content-center">
			<div class="col-12 col-md-8 bg-white p-4 m-0 text-primary">
				<div class="table-responsive">
					{{ form_start(form) }}
					<table class="table table-hover">
						<thead>
							<tr class="fw-bold text-primary">
								<th scope="col">Libelle</th>
								<th scope="col"></th>
								<th scope="col"></th>
								<th scope="col"></th>
							</tr>
						</thead>
						<tbody>
							{% for categorie in categories |sort((a, b) =>a.libelle <=> b.libelle) %}
								<tr class="{{ cycle(['table-primary', 'table-secondary'], loop.index0) }}">
									<td>{{ categorie.libelle | capitalize }}

										{% if categorie.scategories | length > 0 %}
											<ul>
												{% for sc in categorie.scategories |sort((a, b) => a.numero <=> b.numero) %}
													<li>{{sc.numero}}
														-
														{{sc.libelle | capitalize }}
														<a href="{{path("app_supprimer_scategorie",{'id':sc.id})}}">
															<i class="bi bi-trash-fill textdark"></i>
														</a>
													</li>
												{% endfor %}
											</ul>
										{% endif %}
									</td>
									<td>
										<a href="{{path("app_modifier_categorie",{'id':categorie.id})}}">
											<i class="bi bi-pen-fill text-dark"></i>
										</a>
									</td>
									<td>
										<a href="{{path("app_supprimer_categorie",{'id':categorie.id})}}">
											<i class="bi bi-trash-fill textdark"></i>
										</a>
									</td>
									<td>{{ form_widget(form.categories[categorie.id]) }}</td>

								</tr>
							{% endfor %}
						</tbody>
					</table>

					<div class="text-center">
						{{ form_widget(form.supprimer) }}
						{{ form_end(form) }}
					</div>
				</div>
			</div>
		</div>
	{% endblock %}
