{% if ep.audio.duration_seconds %}
{% set total = ep.audio.duration_seconds|int %}
{% set h = total // 3600 %}{% set m = (total % 3600) // 60 %}{% set s = total % 60 %}
{% if h %}{{ '%d:%02d:%02d'|format(h, m, s) }}{% else %}{{ '%d:%02d'|format(m, s) }}{% endif %}
{% else %}
—
{% endif %}
{%- set meta_findings = report.get_episode_findings(ep.guid, 'meta') -%}
{%- set image_findings = report.get_episode_findings(ep.guid, 'image') -%}
{%- set audio_findings = report.get_episode_findings(ep.guid, 'audio') -%}
{%- set has_errors = meta_findings or image_findings or audio_findings -%}
{%- if not has_errors -%}
OK
{% include "icon_circle.svg" %}
{%- else -%}
{%- macro render_badge(findings, icon_svg, a11y_text) -%}
{%- if findings -%}
{%- set has_fail = findings|selectattr('level', 'equalto', level_fail)|list -%}
{%- set codes = findings|map(attribute='code')|unique|join(', ') -%}
{%- if has_fail -%}
{{ a11y_text }}: {{ codes }}
{{ icon_svg|safe }}
{%- else -%}
{{ a11y_text }}: {{ codes }}
{{ icon_svg|safe }}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
{% set icon_audio %}{% include "icon_audio.svg" %}{% endset %}
{% set icon_image %}{% include "icon_image.svg" %}{% endset %}
{% set icon_meta %}{% include "icon_meta.svg" %}{% endset %}
{{ render_badge(audio_findings, icon_audio, 'Audio issues') }}
{{ render_badge(image_findings, icon_image, 'Image issues') }}
{{ render_badge(meta_findings, icon_meta, 'Metadata issues') }}
{%- endif -%}
{%- set has_audio_fail = audio_findings | selectattr("level", "equalto", level_fail) | list | length > 0 -%}
{%- set _show_audio_bypass = show_audio_bypass if show_audio_bypass is defined else false -%}
{%- set _show_image_bypass = show_image_bypass if show_image_bypass is defined else false -%}
{% set all_findings = meta_findings + image_findings + audio_findings %}
{% if all_findings %}
{% for f in all_findings %}
{{ f.domain.value }}
{{ f.message }}
{% if loop.index0 == meta_findings|length and f.domain.value == 'image' %}
{%- if _show_image_bypass -%}
{{ render_bypass(ep.image_url, ep.guid, slug) }}
{%- elif image_findings|length > 0 -%}
{%- endif -%}
{% elif loop.index0 == meta_findings|length + image_findings|length and f.domain.value == 'audio' %}
{%- if _show_audio_bypass -%}
{{ render_bypass(ep.audio.url, ep.guid, slug) }}
{%- elif has_audio_fail or (pe and not pe.ok) -%}
{%- endif -%}
{% endif %}