{# All form fields — compact single-line rows, grouped by section #}
{% if form_fields %}
{% set ns = namespace(pending_section='') %}
{% for field in form_fields %}
{% set ftype = field.type %}
{% set fid = field.id | string %}
{% set val = form_data.get(fid, '') %}
{# Section heading — buffer it, only flush when a visible field follows #}
{% if ftype == 'section' %}
{% set ns.pending_section = field.label %}
{# Skip display-only types #}
{% elif ftype in ('label', 'button_submit', 'button_print', 'button_email') %}
{# All input field types — render as compact row #}
{% else %}
{# Flush pending section header #}
{% if ns.pending_section %}
{{ ns.pending_section }}
{% set ns.pending_section = '' %}
{% endif %}
{{ field.label }}
{# ── Rating ── #}
{% if ftype == 'rating' %}
{% set score = val | int %}
{% if score > 0 %}
{% for i in range(1,6) %}{{ '★' if i <= score else '☆' }}{% endfor %}{{ score }}/5
{% else %}
Not rated
{% endif %}
{# ── Image / Photo ── #}
{% elif ftype == 'image' %}
{% if val %}
{% else %}
No photo
{% endif %}
{# ── Signature ── #}
{% elif ftype == 'signature' %}
{% if val and val.startswith('data:') %}
{% else %}
No signature
{% endif %}
{# ── Checkbox single ── #}
{% elif ftype == 'checkbox' %}
{% if val == 'yes' %}
Yes
{% else %}
No
{% endif %}
{# ── Checkbox group ── #}
{% elif ftype == 'checkbox_group' %}
{% if val and val is iterable and val is not string and val | length > 0 %}
{% for opt in val %}{{ opt }}{% endfor %}
{% else %}
None selected
{% endif %}
{# ── Table ── #}
{% elif ftype == 'table' %}
{% if val and val is iterable and val is not string %}
{% for hdr in (field.col_headers or ['Column 1']) %}
{{ hdr }}
{% endfor %}
{% for row in val %}
{% for hdr in (field.col_headers or ['Column 1']) %}
{{ row.get(hdr,'') }}
{% endfor %}
{% endfor %}
{% else %}
No data
{% endif %}
{# ── Everything else: text, textarea, number, date, email, radio, select ── #}
{% else %}
{% if val %}
{{ val }}
{% else %}
—
{% endif %}
{% endif %}