{% extends "base.html" %}
{% import "macros/ui.html" as m %}

{% block title %}Actions — Ontoref{% endblock title %}
{% block nav_actions %}active{% endblock nav_actions %}
{% block nav_group_reflect %}active{% endblock nav_group_reflect %}
{% block mob_nav_actions %}active{% endblock mob_nav_actions %}

{% block content %}
<div class="mb-6 flex items-center justify-between">
  <h1 class="text-xl font-bold">Quick Actions</h1>
  <span class="text-xs text-base-content/40 font-mono">Runnable tasks and workflows</span>
</div>

{% if not actions or actions | length == 0 %}
{{ m::empty_state(message="No quick actions configured — add quick_actions to .ontoref/config.ncl") }}
{% else %}

{% set grouped = actions | group_by(attribute="category") %}
{% for cat, cat_actions in grouped %}
<section class="mb-8">
  <h2 class="text-sm font-semibold uppercase tracking-wider text-base-content/50 mb-3">
    {% if cat == "docs" %}Documentation
    {% elif cat == "sync" %}Synchronization
    {% elif cat == "analysis" %}Analysis
    {% elif cat == "test" %}Testing
    {% else %}{{ cat | title }}{% endif %}
  </h2>
  <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
    {% for action in cat_actions %}
    <div class="card bg-base-200 border border-base-content/10 hover:border-base-content/20 transition-colors">
      <div class="card-body p-4 gap-3">
        <div class="flex items-start gap-3">
          <div class="flex-shrink-0 w-9 h-9 rounded-lg bg-base-300 flex items-center justify-center text-primary">
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              {% if action.icon == "book-open" %}
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                    d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"/>
              {% elif action.icon == "refresh" %}
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                    d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
              {% elif action.icon == "code" %}
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                    d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
              {% else %}
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                    d="M13 10V3L4 14h7v7l9-11h-7z"/>
              {% endif %}
            </svg>
          </div>
          <div class="flex-1 min-w-0">
            <h3 class="font-semibold text-sm leading-tight">{{ action.label }}</h3>
            <p class="text-xs text-base-content/50 font-mono mt-0.5">mode: {{ action.mode }}</p>
          </div>
        </div>

        <div class="flex flex-wrap gap-1">
          {% for actor in action.actors %}
          <span class="badge badge-xs
            {% if actor == "developer" %}badge-primary
            {% elif actor == "agent" %}badge-secondary
            {% elif actor == "ci" %}badge-accent
            {% else %}badge-ghost{% endif %}">{{ actor }}</span>
          {% endfor %}
        </div>

        {% if not current_role or current_role == "admin" %}
        <div class="card-actions justify-end pt-1">
          <form hx-post="{{ base_url }}/actions/run"
                hx-target="this"
                hx-swap="outerHTML">
            <input type="hidden" name="action_id" value="{{ action.id }}">
            <button type="submit" class="btn btn-xs btn-primary gap-1">
              <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
            </button>
          </form>
        </div>
        {% endif %}
      </div>
    </div>
    {% endfor %}
  </div>
</section>
{% endfor %}

{% endif %}
{% endblock content %}
