{# plugins/growlog/templates/growlog/log_list.html #}
{% import 'core_ui/_media_macros.html' as media %}
{% extends 'core_ui/base.html' %}

{% block content %}
<h2>Logs for Plant #{{ plant.id }}</h2>
<a href="{{ url_for('growlog.add_log', plant_id=plant.id) }}">Add New Log</a>

<ul>
  {% for log in logs %}
    <li class="mb-3">
      <strong>{{ log.timestamp.strftime('%Y-%m-%d') }}:</strong>
      {{ log.event_type }} – {{ log.note }}
      {% if log.media_items %}
        <br><em>Images:</em>
        <ul class="list-unstyled ps-3">
          {% for image in log.media_items %}
            <li class="mb-2">
              <img
                src="{{ generate_image_url(image) }}"
                width="150"
                class="img-thumbnail"
                alt="Log image"
              ><br>
              {{ image.caption or "No caption" }}
            </li>
          {% endfor %}
        </ul>
      {% endif %}
    </li>
  {% endfor %}
</ul>

{# Use shared macro for any remaining media lists #}
{{ media.render_media_list(logs|map(attribute='media_items')|sum, thumb_width=150, current_user=current_user) }}
{% endblock %}
