{# ── Single log line card — called in a loop by index.html ─────────── #} {%
from "partials/status_badge.html" import status_badge %} {% set p = la.parsed %}
{% set log_parts = _render_log_parts(la) %}

<div
  class="card pynmon-card log-line-card{% if p.level %} level-{{ p.level|lower }}{% endif %}"
>
  <div class="log-line-columns">
    {# ── Left column: compact badge-only metadata ── #}
    <div class="log-col-left">
      {# Timestamp + level + refs all inline, wrapping naturally #}
      <span class="line-meta">
        {% if p.timestamp %}
        <span class="meta-ts"
          >{{ p.timestamp.strftime('%Y-%m-%d %H:%M:%S.') }}{{
          p.timestamp.strftime('%f')[:3] }}{% set tz =
          p.timestamp.strftime('%z') %}{% if tz %}{{ tz[:3] }}:{{ tz[3:] }}{%
          endif %}</span
        >
        {% endif %} {% if p.level %}
        <span class="meta-level meta-level-{{ p.level|lower }}"
          >{{ p.level }}</span
        >
        {% endif %}
      </span>
      {% if p.is_valid %}
      <span class="line-refs">
        {# Bracket runners #} {% for rm in la.runner_matches %} {% if
        rm.contexts %} {% for ctx in rm.contexts %}
        <a
          href="/runners/{{ ctx.runner_id }}"
          class="ref-chip chip-runner"
          data-runner-id="{{ ctx.runner_id }}"
          title="Runner {{ ctx.runner_id }}"
        >
          <span class="material-icons">memory</span>
          {{ rm.parsed.cls_abbr }}({{ rm.parsed.partial_id }})
        </a>
        {% endfor %} {% else %}
        <span class="ref-chip chip-runner" title="No match found">
          <span class="material-icons">memory</span>
          {{ rm.parsed.cls_abbr }}({{ rm.parsed.partial_id }})
        </span>
        {% endif %} {% endfor %} {# Bracket invocation — full ID + status +
        timeline (grouped) #} {% if p.invocation_id %} {% set inv_d =
        analysis.ref_details.get('invocation:' ~ p.invocation_id, {}) if
        analysis else {} %}
        <span class="inv-chip-group">
          <a
            href="/invocations/{{ p.invocation_id }}"
            class="ref-chip chip-invocation"
            data-invocation-id="{{ p.invocation_id }}"
            title="Invocation: {{ p.invocation_id }}"
          >
            <span class="material-icons">info</span>
            {{ p.invocation_id }} {% if inv_d.status %}
            <span class="ref-badge ref-badge-{{ inv_d.status|lower }}"
              >{{ inv_d.status }}</span
            >
            {% endif %}
          </a>
          <a
            href="/invocations/timeline?{{ la.invocation_timeline_qs }}"
            class="ref-chip chip-invocation chip-timeline"
            data-invocation-id="{{ p.invocation_id }}"
            title="Timeline zoom"
          >
            <span class="material-icons">timeline</span>
          </a>
        </span>
        {% endif %} {# Bracket task #} {% if p.task_key %}
        <a
          href="/tasks/{{ p.task_key }}"
          class="ref-chip chip-task"
          data-task-key="{{ p.task_key }}"
          title="Task page"
        >
          <span class="material-icons">task</span>
          {{ p.task_key }}
        </a>
        {% endif %}
      </span>
      {% endif %}
    </div>

    {# ── Right column: message text + message-body entity badges ── #}
    <div class="log-col-right">
      {% if log_parts.message %}
      <div class="log-msg-text">{{ log_parts.message|safe }}</div>
      {% endif %} {% if la.extra_entity_refs %}
      <div class="line-refs msg-refs">
        {% for ref in la.extra_entity_refs %} {% if ref.kind in
        ('invocation','parent-invocation','child-invocation','new-invocation')
        %} {% set ref_d = analysis.ref_details.get('invocation:' ~ ref.value,
        {}) if analysis else {} %}
        <span class="inv-chip-group">
          <a
            href="/invocations/{{ ref.value }}"
            class="ref-chip chip-invocation"
            data-invocation-id="{{ ref.value }}"
            title="{{ ref.kind|replace('-',' ')|title }}: {{ ref.value }}"
          >
            <span class="material-icons">info</span>
            {% if ref.kind == 'invocation' %}{{ ref.value }}{% elif ref.kind ==
            'parent-invocation' %}Parent: {{ ref.value }}{% elif ref.kind ==
            'child-invocation' %}Child: {{ ref.value }}{% elif ref.kind ==
            'new-invocation' %}New: {{ ref.value }}{% endif %} {% if
            ref_d.status %}
            <span class="ref-badge ref-badge-{{ ref_d.status|lower }}"
              >{{ ref_d.status }}</span
            >
            {% endif %}
          </a>
          <a
            href="/invocations/timeline?{{ la.timeline_qs }}&selected={{ ref.value }}"
            class="ref-chip chip-invocation chip-timeline"
            data-invocation-id="{{ ref.value }}"
            title="Timeline"
          >
            <span class="material-icons">timeline</span>
          </a>
        </span>
        {% elif ref.kind in
        ('runner','worker','current-owner-runner','attempted-owner-runner') %}
        {% set runner_label = ref.kind|replace('-runner','')|replace('-','
        ')|title %}
        <a
          href="/runners/{{ ref.value }}"
          class="ref-chip chip-runner"
          data-runner-id="{{ ref.value }}"
          title="{{ runner_label }}: {{ ref.value }}"
        >
          <span class="material-icons">memory</span>
          {{ runner_label }}: {{ ref.value }}
        </a>
        {% elif ref.kind == 'task' %}
        <a
          href="/tasks/{{ ref.value }}"
          class="ref-chip chip-task"
          data-task-key="{{ ref.value }}"
          title="Task: {{ ref.value }}"
        >
          <span class="material-icons">task</span>
          {{ ref.value }}
        </a>
        {% elif ref.kind in ('workflow','sub-workflow','parent-workflow') %}
        <a
          href="/workflows/runs"
          class="ref-chip chip-workflow"
          title="{{ ref.kind|replace('-',' ')|title }}: {{ ref.value }}"
        >
          <span class="material-icons">account_tree</span>
          {{ ref.kind|replace('-',' ')|title }}: {{ ref.value }}
        </a>
        {% else %}
        <span class="ref-chip" title="{{ ref.kind }}: {{ ref.value }}">
          {{ ref.kind }}: {{ ref.value }}
        </span>
        {% endif %} {% endfor %}
      </div>
      {% endif %}
    </div>
  </div>
</div>
