{% extends "base.html" %}
{% from "macros.html" import page_header %}
{% block content %}
{% call page_header("Team", "Workload") %}
<form method="get" action="/team" class="input-group" style="width: auto;">
  <label class="input-group-text" for="team-week">Week</label>
  <input type="text" id="team-week" class="form-control" name="week" value="{{ iso_week }}" placeholder="YYYY-Www">
  <button type="submit" class="btn btn-outline-secondary">Go</button>
</form>
{% endcall %}
<p class="text-secondary">What everyone is currently working on, across every project you can read.</p>

{% if not groups %}
<div class="empty">
  <p class="empty-title">No open tasks</p>
  <p class="empty-subtitle text-secondary">Tasks in todo, in progress, or in review show up here.</p>
</div>
{% 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 d-flex align-items-center gap-2">
      <span class="avatar avatar-sm">{{ group.assignee | initials }}</span>
      {{ group.assignee }}
    </h3>
    <div class="d-flex align-items-center gap-2">
      {% if group.capacity is not none %}
      <div style="width: 8rem;">
        <div class="progress progress-sm" title="{{ group.points_total }} / {{ group.capacity }} pts this week">
          <div class="progress-bar {{ 'bg-danger' if group.over_capacity else 'bg-success' }}" style="width: {{ group.capacity_pct }}%"></div>
        </div>
      </div>
      <span class="text-secondary small">{{ group.points_total }} / {{ group.capacity }} pts this week</span>
      {% else %}
      <span class="badge bg-secondary-lt">{{ group.points_total }} pts</span>
      {% endif %}
      {% if group.can_edit %}
      <a class="btn btn-sm btn-outline-secondary" 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 %}