{% extends "base.html" %}
{% import "macros/ui.html" as m %}
{% block title %}{{ ws_name }} — Actions{% endblock %}
{% block nav_workspaces %}btn-active{% endblock %}

{% block content %}
{{ m::ws_tabs(ws_name=ws_name, active=ws_active_tab, ws_envs=ws_envs, ws_has_clusters=ws_has_clusters, ws_has_workflows=ws_has_workflows, current_env=current_env) }}

<div class="flex items-center justify-between mb-4">
  <div>
    <h2 class="text-xl font-bold font-mono mb-1">Actions
      <span class="text-base-content/30 font-normal text-sm ml-2">{{ ws_name }}</span>
    </h2>
    <p class="text-base-content/50 text-sm">
      Orchestrator jobs matching <code class="font-mono">{{ ws_name }}</code>.
    </p>
  </div>
  <a href="/ui/workspaces/{{ ws_name }}/modes" class="btn btn-sm btn-outline btn-primary gap-1.5">
    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
        d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/>
      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
        d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
    </svg>
    Run Mode
  </a>
</div>

{% if jobs %}
<div class="overflow-x-auto">
  <table class="table table-sm w-full font-mono text-xs">
    <thead>
      <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Status</th>
        <th>Created</th>
        <th>Started</th>
        <th>Completed</th>
      </tr>
    </thead>
    <tbody>
      {% for job in jobs %}
      <tr class="hover">
        <td class="text-base-content/40 truncate max-w-[120px]" title="{{ job.id }}">
          {{ job.id | truncate(length=12, end="…") }}
        </td>
        <td>{{ job.name }}</td>
        <td>
          {% if job.status == "Running" %}
            <span class="badge badge-warning badge-xs">running</span>
          {% elif job.status == "Completed" %}
            <span class="badge badge-success badge-xs">done</span>
          {% elif job.status == "Failed" %}
            <span class="badge badge-error badge-xs">failed</span>
          {% elif job.status == "Cancelled" %}
            <span class="badge badge-ghost badge-xs">cancelled</span>
          {% else %}
            <span class="badge badge-ghost badge-xs">{{ job.status | lower }}</span>
          {% endif %}
        </td>
        <td class="text-base-content/50">{{ job.created_at }}</td>
        <td class="text-base-content/50">{% if job.started_at %}{{ job.started_at }}{% else %}—{% endif %}</td>
        <td class="text-base-content/50">{% if job.completed_at %}{{ job.completed_at }}{% else %}—{% endif %}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>
{% else %}
<div class="alert">
  <span class="text-sm">No actions found for <code class="font-mono">{{ ws_name }}</code>.</span>
</div>
{% endif %}
{% endblock %}
