{% extends "base.html" %}
{% block content %}
{# Team overview: open tasks across projects, grouped by assignee. Expects: iso_week, groups [ { assignee, points_total, capacity, over_capacity, can_edit, capacity_url, rows } ] #}

<h1 class="page-title">Team</h1>
<p class="text-muted">What everyone is currently working on, across every project you can read.</p>

<form method="get" action="/team" class="d-flex align-items-center gap-2 mb-3">
  <label class="form-label mb-0" for="team-week">Week</label>
  <input type="text" id="team-week" class="form-control form-control-sm" style="max-width: 140px;" name="week" value="{{ iso_week }}" placeholder="YYYY-Www">
  <button type="submit" class="btn btn-sm btn-outline-secondary">Go</button>
</form>

{% if not groups %}
<p class="text-muted">No open tasks found.</p>
{% endif %}

{% for group in groups %}
<div class="card mb-3">
  <div class="card-header d-flex align-items-center justify-content-between flex-wrap gap-2">
    <h3 class="card-title mb-0">{{ group.assignee }}</h3>
    <div class="d-flex align-items-center gap-2">
      {% if group.capacity is not none %}
      <span class="badge {{ 'bg-danger' if group.over_capacity else 'bg-success' }}">{{ group.points_total }} / {{ group.capacity }} pts this week</span>
      {% else %}
      <span class="badge bg-secondary">{{ group.points_total }} pts</span>
      {% endif %}
      {% if group.can_edit %}
      <a class="small" href="{{ group.capacity_url }}">set capacity</a>
      {% endif %}
    </div>
  </div>
  <div class="card-body p-0">
    {% with cols=["Task", "Project", "Board", "Status", "Priority", "Points"], rows=group.rows %}
    {% include "table.html" %}
    {% endwith %}
  </div>
</div>
{% endfor %}
{% endblock %}