{% extends 'base.html' %}
{% block content %}
<div class="toolbar">
  <div>
    <h1>{{ t('job_states.title', 'Jobstatus je Asset') }}</h1>
    <p class="muted">{{ t('job_states.description', 'Aktueller kompakter Jobstatus pro Asset und Job. Die vollständige Historie bleibt in den einzelnen Jobs erhalten.') }}</p>
  </div>
  <div class="toolbar-actions">
    <a class="button button-secondary" href="/software">← {{ t('job_states.back', 'Zur Jobübersicht') }}</a>
  </div>
</div>

<section class="panel">
  <div class="table-scroll management-table-scroll">
    <table class="data-table" data-storage-key="asset-job-states">
      <thead>
        <tr>
          <th>{{ t('common.assets', 'Assets') }}</th>
          <th>{{ t('job_states.job', 'Job') }}</th>
          <th>{{ t('jobs.type', 'Job-Art') }}</th>
          <th>{{ t('software.status', 'Status') }}</th>
          <th>{{ t('assets.job_filter.last_execution', 'Letzte Ausführung') }}</th>
          <th>{{ t('assets.job_filter.last_success', 'Letzter Erfolg') }}</th>
          <th>{{ t('job_states.revision', 'Letzte Revision') }}</th>
          <th>{{ t('job_states.success_revision', 'Erfolgsrevision') }}</th>
          <th>{{ t('job_states.execution_count', 'Ausführungen') }}</th>
          <th>{{ t('job_states.last_job', 'Letzter Job') }}</th>
          <th>{{ t('job_states.updated_at', 'Aktualisiert') }}</th>
        </tr>
      </thead>
      <tbody>
      {% for row in job_states %}
        {% set state = row.state %}
        <tr>
          <td><a href="/assets/{{ row.asset.id }}?inventory_tab=software">{{ row.asset.name }}</a></td>
          <td>{{ row.job_label }}</td>
          <td>{{ t(row.job_type_key, row.job_type_fallback) }}</td>
          <td><span class="job-status job-status-{{ state.last_status }}">{{ t('software.status.' ~ state.last_status, state.last_status) }}</span></td>
          <td>{% if row.last_execution %}<time class="local-time" datetime="{{ utc_iso(row.last_execution) }}" data-utc="{{ utc_iso(row.last_execution) }}">{{ row.last_execution }}</time>{% else %}<span class="muted">—</span>{% endif %}</td>
          <td>{% if state.last_success_at %}<time class="local-time" datetime="{{ utc_iso(state.last_success_at) }}" data-utc="{{ utc_iso(state.last_success_at) }}">{{ state.last_success_at }}</time>{% else %}<span class="muted">—</span>{% endif %}</td>
          <td>{% if state.definition_revision is not none %}{{ state.definition_revision }}{% else %}<span class="muted">—</span>{% endif %}</td>
          <td>{% if state.last_success_revision is not none %}{{ state.last_success_revision }}{% else %}<span class="muted">—</span>{% endif %}</td>
          <td>{{ state.execution_count }}</td>
          <td>{% if state.last_job_id %}<a href="/jobs/{{ state.last_job_id }}"><code>{{ state.last_job_id }}</code></a>{% else %}<span class="muted">—</span>{% endif %}</td>
          <td>{% if state.updated_at %}<time class="local-time" datetime="{{ utc_iso(state.updated_at) }}" data-utc="{{ utc_iso(state.updated_at) }}">{{ state.updated_at }}</time>{% else %}<span class="muted">—</span>{% endif %}</td>
        </tr>
      {% else %}
        <tr><td colspan="11" class="empty-state">{{ t('job_states.empty', 'Noch keine Jobstatusdaten vorhanden.') }}</td></tr>
      {% endfor %}
      </tbody>
    </table>
  </div>
</section>
{% endblock %}
