{% if missive.is_persisted %}
{% comment %}
Saved missive: every PDF physical attachment in priority order
(first_document at priority 0, then user attachments). Non-PDF skipped.
{% endcomment %}
{% for doc in missive.attachments_physical %}
{% include "django_pymissive/includes/postal_pdf_attachment_preview.html" %}
{% endfor %}
{% else %}
{# Campaign preview: render the letter as a PDF (via download_pdf, which
runs body_to_pdf and the full first_document_processors chain incl.
watermark) instead of inline HTML, so the preview matches what the
recipient receives. Fall back to inline HTML when no campaign is
bound (e.g. ad-hoc unsaved missive preview). Other PDF attachments
follow underneath, also via PDF.js. #}
{% if campaign %}
📄{% trans "Letter (first page)" %}
{% trans "Loading…" %}
{% else %}
{% include "django_pymissive/includes/postal_a4_letter_page.html" %}
{% endif %}
{% for doc in missive.attachments_physical %}
{% if not doc.is_first_document %}
{% include "django_pymissive/includes/postal_pdf_attachment_preview.html" %}
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}
{% block preview_scripts %}
{% trans "PDF.js unavailable." as pdfjs_msg_unavailable %}
{% trans "Open attachment" as pdfjs_msg_open %}
{% trans "Could not render document" as pdfjs_msg_error %}
{% endblock %}