{% extends 'base.html.twig' %}
{% block title %}Tous les produits{% endblock %}
{% block body %}
<div class="container mt-2">
<div class="row">
<div class="col-12 header-title">
<h1>Nos produits</h1>
</div>
</div>
<div class="row">
<div class="col-12">
{% for label, messages in app.flashes %}
{% for message in messages %}
<div class="alert alert-{{ label }} alert-dismissible fade show" role="alert">
<strong>{{ message }}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
{% if products is defined and products is not empty %}
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
{% for product in products %}
<div class="col">
<div class="card card-product h-100">
<div class="row g-0 h-100">
<div class="col-md-6 p-0">
{% if product.picture is not empty and fileExists(product.picture) %}
<img src="{{ asset('uploads/images/' ~ product.picture) }}"
alt="{{ product.title }}"
class="w-100 h-100 object-fit-cover" style="border-radius: 2%;"/>
{% else %}
<img src="{{ asset('images/logo.svg') }}" alt="Default image"
class="w-100 h-100 object-fit-cover" style="border-radius: 2%;">
{% endif %}
</div>
<div class="col-md-6 d-flex flex-column">
<div class="card-body d-flex flex-column h-100">
<h5 class="card-title">{{ product.title }}</h5>
<p class="card-text small flex-grow-1">{{ product.description|u.truncate(80, '...') }}</p>
<div class="mt-auto">
<p class="card-text fw-bold mb-2">{{ product.price|format_currency('EUR') }}</p>
<div class="mb-2">
{% if product.isCustomizable %}
<span class="badge bg-success">Personnalisable</span>
{% else %}
<span class="badge bg-secondary">Non personnalisable</span>
{% endif %}
</div>
{% if product.isCustomizable %}
<button type="button" class="btn btn-sm btn-green w-100"
data-bs-toggle="modal"
data-bs-target="#customModal-{{ product.id }}">
Ajouter au panier
</button>
{% else %}
<a href="{{ path('product_add_cart', {'id': product.id }) }}"
class="btn btn-sm btn-green w-100">Ajouter au panier</a>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
{% if product.isCustomizable %}
<div class="modal fade" id="customModal-{{ product.id }}" tabindex="-1"
aria-labelledby="customModalLabel-{{ product.id }}"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="customModalLabel-{{ product.id }}">Personnalisation
de votre achat</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<form action="{{ path('product_add_cart', {'id': product.id}) }}" method="POST">
<div class="modal-body">
<div class="mb-3">
<label for="customization-{{ product.id }}" class="form-label">Personnalisation
:</label>
<input type="text" class="form-control" name="customization"
id="customization-{{ product.id }}">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Annuler
</button>
<button type="submit" class="btn btn-design">Ajouter au panier</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% else %}
<div class="row">
<div class="col-12 text-center">
<span>Il n'y a pas de produits pour le moment.</span>
</div>
</div>
{% endif %}
<div class="navigation my-2">
{{ knp_pagination_render(products) }}
</div>
</div>
{% endblock %}