{% extends "base.html" %}
{% import "macros/ui.html" as m %}
{% block title %}{{ ws_name }} · Clusters{% 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) }}

{% if clusters %}
  {% if clusters.items %}
  <div class="overflow-x-auto">
    <table class="table table-sm font-mono">
      <thead>
        <tr class="text-base-content/50 text-xs uppercase tracking-wider">
          <th>Name</th>
          <th>Status</th>
          <th>Version</th>
          <th>Nodes</th>
          <th>Location</th>
          <th>Labels</th>
        </tr>
      </thead>
      <tbody>
        {% for cl in clusters.items %}
        <tr class="hover">
          <td class="font-semibold text-primary">{{ cl.name }}</td>
          <td>
            {% if cl.status == "running" %}
              <span class="badge badge-success badge-sm">running</span>
            {% elif cl.status == "provisioning" or cl.status == "creating" %}
              <span class="badge badge-warning badge-sm">{{ cl.status }}</span>
            {% elif cl.status == "deleting" %}
              <span class="badge badge-error badge-sm">deleting</span>
            {% else %}
              <span class="badge badge-ghost badge-sm">{{ cl.status | default(value="—") }}</span>
            {% endif %}
          </td>
          <td class="text-base-content/60 text-xs">{{ cl.kubernetes_version | default(value="—") }}</td>
          <td class="text-base-content/60">{{ cl.nodes_count | default(value="—") }}</td>
          <td class="text-base-content/50 text-xs">
            {% if cl.location %}{{ cl.location }}{% else %}—{% endif %}
          </td>
          <td>
            {% if cl.labels %}
              {% for k, v in cl.labels %}
              <span class="badge badge-ghost badge-xs">{{ k }}={{ v }}</span>
              {% endfor %}
            {% endif %}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  <p class="text-xs text-base-content/30 mt-3">{{ clusters.total | default(value=clusters.items | length) }} cluster(s) — live status</p>
  {% else %}
  <div class="alert">
    <span class="text-sm">No clusters found for this workspace.</span>
  </div>
  {% endif %}
{% else %}
<div class="alert alert-warning">
  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
      d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-2.194-.833-2.964 0L3.232 16.5c-.77.833.192 2.5 1.732 2.5z"/>
  </svg>
  <span>Cluster data unavailable — orchestrator may not be reachable or no cluster provider is configured.</span>
</div>
{% endif %}
{% endblock %}
