<section class="comments-section mt-4 mb-4" id="comments" style="text-align: left; max-width: 700px; margin-left: auto; margin-right: auto;">
<h3 class="text-white mb-3">
Comments
{% if comments|length > 0 %}
<span class="badge bg-secondary">{{ comments|length }}</span>
{% endif %}
</h3>
{% for message in app.flashes('comment') %}
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
{% if app.user %}
<div class="mb-4 p-3 rounded" style="background: rgba(255,255,255,0.05);">
{{ form_start(formComment) }}
<div style="width: 100%;">
{{ form_widget(formComment.comment, {'attr': {'class': 'form-control bg-dark text-white border-secondary comment-form-textarea mb-2', 'placeholder': 'Write a comment...', 'rows': '2', 'style': 'width: 100%;'}}) }}
{{ form_errors(formComment.comment) }}
</div>
<div class="d-flex align-items-center gap-2 flex-wrap">
{{ form_widget(formComment.captcha) }}
{{ form_widget(formComment.submit, {'attr': {'class': 'btn btn-primary btn-sm ms-auto'}}) }}
</div>
{{ form_end(formComment) }}
</div>
{% else %}
<p class="mb-4">
<a href="{{ path('security_login') }}" class="btn btn-outline-light btn-sm">Log in to leave a comment</a>
</p>
{% endif %}
{% if comments|length > 0 %}
{% for comment in comments %}
<div class="d-flex gap-2 mb-3 pb-3 {% if not loop.last %}border-bottom border-secondary{% endif %}">
<a href="{{ path('user_user', {username: comment.user.username}) }}" title="{{ comment.user.username }}" class="flex-shrink-0">
{% if comment.user.picture == 1 %}
<img class="rounded-circle" src="{{ asset('images/user/' ~ comment.user.username ~ '.jpg') }}" width="36" height="36" alt="{{ comment.user.username }}"/>
{% else %}
<picture>
<source srcset="{{ asset('images/generic-avatar-comment.webp') }}" type="image/webp">
<img class="rounded-circle" src="{{ asset('images/generic-avatar-comment.jpg') }}" width="36" height="36" alt="{{ comment.user.username }}"/>
</picture>
{% endif %}
</a>
<div class="flex-grow-1" style="min-width: 0;">
<div class="d-flex justify-content-between align-items-center">
<div>
<a href="{{ path('user_user', {username: comment.user.username}) }}" class="text-white text-decoration-none fw-bold small">{{ comment.user.username }}</a>
<small class="text-muted ms-1">{{ comment.createdAt|ago }}</small>
</div>
{% if app.user == comment.user or is_granted('ROLE_ADMIN') %}
<div class="dropdown">
<button class="btn btn-sm btn-link text-muted p-0 comment-dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fas fa-ellipsis-v"></i>
</button>
<ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end">
<li><a class="dropdown-item" href="{{ path('user_edit_comment', {id: comment.id}) }}"><i class="fas fa-edit me-2"></i>Edit</a></li>
<li><a class="dropdown-item text-danger" href="{{ path('user_remove_comment', {id: comment.id}) }}" onclick="return confirm('Are you sure you want to delete this comment?');"><i class="fas fa-trash me-2"></i>Delete</a></li>
</ul>
</div>
{% endif %}
</div>
<p class="mb-0 mt-1 text-light small">{{ comment.comment|e }}</p>
</div>
</div>
{% endfor %}
{% else %}
<p class="text-muted fst-italic small">No comments yet. Be the first to comment!</p>
{% endif %}
</section>