{% load util %}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="color-scheme" content="light dark">
        <meta name="supported-color-schemes" content="light dark">
        <style>
            body {
                padding: 0 0;
                margin: 0 0;
                background-color: #fcfdff;
                color: #121212;
            }
            .aw-log-ok, .aw-stats-ok {
                color: #22bb33;
            }
            .aw-log-skip, .aw-stats-skipped, .aw-stats-ignored {
                color: #40a6ce;
            }
            .aw-log-warn, .aw-stats-rescued {
                color: #7b3ed2;
            }
            .aw-log-err, .aw-stats-unreachable, .aw-stats-failed {
                color: #bb2124;
            }
            .aw-log-change, .aw-stats-changed {
                color: #f0ad4e;
            }
            .aw-status {
{% if execution.status_name == 'Failed' %}
                color: #bb2124;
{% elif execution.status_name == 'Finished' %}
                color: #22bb33;
{% endif %}
            }
            a {
                color: #0000EE;
                text-decoration: none;
            }
            a:hover {
                text-decoration: underline;
                color: #B3D8FA;
            }
            @media (prefers-color-scheme: dark ) {
                body {
                    background-color: #121212;
                    color: #fcfdff;
                }
                a {
                    color: #66B2F5;
                }
            }
        </style>
    </head>
    <body>
        <h2><b>Job</b>: {{ execution.job.name }}</h2>
        <b>Status</b>: <b><span class="aw-status">{{ execution.status_name }}</span></b><br><br>

        <b>Executed by</b>: {{ execution.user_name }}<br>
        <b>Start time</b>: {{ execution.time_created_str }}<br>
{% if execution.result is not none %}
        <b>Finish time</b>: {{ execution.result.time_fin_str }}<br>
        <b>Duration</b>: {{ execution.result.time_duration_str }}<br>
{%   if execution.result.error is not none %}
        <b>Short error message</b>: '{{ execution.result.error.short }}'<br>
        <b>Long error message</b>: '{{ execution.result.error.med }}'<br>
{%   endif %}
{%   if error_msgs|get_value:'html'|exists %}
        <br>
        <b>Execution errors</b>:<br>
{%     for msg in error_msgs|get_value:'html' %}
        {{ msg|safe }}<br>
{%     endfor %}
        <br>
{%   endif %}
{% endif %}
        <b>Job History</b>: <a href="{{ url }}/ui/jobs/log?job={{ execution.job.id }}">Link</a><br>
{% for log_attr in execution.log_file_fields %}
{%   set_var execution|get_value:log_attr as log_file %}
{%   set_var log_attr|concat:'_url' as log_url %}
{%   if log_file|file_exists %}
        <b>{{ log_attr|whitespace_char:'_'|capitalize }}</b>: <a href="{{ url }}{{ execution|get_value:log_url }}">Download</a><br>
{%   endif %}
{% endfor %}
{% if stats|exists %}
        <br><hr>
        <h3><b>Statistics</b>:</h3>
{%   for host, host_stats in stats.items %}
        <b>Host</b>: {{ host }}<br>
        <b>Stats</b>:
{%     for k, v in host_stats.items %}
{%       if k == 'unreachable' or v != 0 %}
{%         if not forloop.first %}|
{%         endif %}
{%         if k == 'unreachable' and v == 0 %}
       {{ k }}: {{ v }}
{%         else %}
        <span class="aw-stats-{{ k|remove_char:'tasks_' }}">{{ k }}: {{ v }}</span>
{%         endif %}
{%       endif %}
{%     endfor %}<br><br>
{%   endfor %}
{% endif %}
    </body>
</html>