Загрузка данных


{% extends "base.html" %}
{% block title %}{{ 'Архив стажёров' if show_archive else 'Активные стажёры' }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-3">
  <h4 class="mb-0">{{ 'Архив стажёров' if show_archive else 'Активные стажёры' }}</h4>
  
  <!-- Переключатель Активные / Архив -->
  <div class="btn-group">
    <a href="{{ url_for('interns.list_interns') }}" class="btn btn-outline-primary {% if not show_archive %}active{% endif %}">
      Активные
    </a>
    <a href="{{ url_for('interns.list_interns', archive=1) }}" class="btn btn-outline-secondary {% if show_archive %}active{% endif %}">
      Архив
    </a>
  </div>
</div>

{% if current_user.is_center %}
<form method="get" class="card stat-card mb-3">
  <input type="hidden" name="archive" value="{{ '1' if show_archive else '0' }}">
  <div class="card-body d-flex gap-3 align-items-end">
    <div style="min-width:240px">
      <label class="form-label small mb-1">Фильтр по наставнику</label>
      <select name="mentor_id" class="form-select" onchange="this.form.submit()">
        <option value="">Все наставники</option>
        {% for m in mentors %}
          <option value="{{ m.id }}" {% if selected_mentor == m.id %}selected{% endif %}>{{ m.full_name }}</option>
        {% endfor %}
      </select>
    </div>
  </div>
</form>
{% endif %}

<div class="card stat-card">
  <div class="table-responsive">
    <table class="table table-hover mb-0 align-middle">
      <thead class="table-light">
        <tr>
          <th>ФИО</th>
          <th>Направление</th>
          <th>Тип</th>
          <th>Наставник</th>
          <th>Период</th>
          <th class="text-end">Действия</th>
        </tr>
      </thead>
      <tbody>
        {% for i in interns %}
        <tr class="{% if show_archive %}table-secondary opacity-75{% endif %}">
          <td class="fw-semibold">{{ i.full_name }}</td>
          <td>{{ i.direction or '—' }}</td>
          <td>
            {% if i.internship_type == 'online' %}
              <span class="badge bg-info text-dark">Дистанционно</span>
            {% else %}
              <span class="badge bg-secondary">Очно</span>
            {% endif %}
          </td>
          <td>{{ i.mentor.full_name if i.mentor else '—' }}</td>
          <td class="text-muted small">
            {{ i.start_date.strftime('%d.%m.%Y') }}
            {% if i.end_date %} — {{ i.end_date.strftime('%d.%m.%Y') }}{% endif %}
          </td>
          <td class="text-end">
            <div class="d-flex gap-1 justify-content-end">
              <a class="btn btn-sm btn-outline-primary" href="{{ url_for('interns.detail', intern_id=i.id) }}">
                Календарь
              </a>
              
              {% if show_archive and current_user.is_center %}
                <!-- Кнопка восстановления для архивных -->
                <form method="post" action="{{ url_for('interns.restore_intern', intern_id=i.id) }}">
                  <button type="submit" class="btn btn-sm btn-success" title="Вернуть в активные">
                    <i class="bi bi-arrow-counterclockwise"></i>
                  </button>
                </form>
              {% elif not show_archive and current_user.is_center %}
                <!-- Кнопка архивации для активных -->
                <form method="post" action="{{ url_for('interns.archive_intern', intern_id=i.id) }}" onsubmit="return confirm('Отправить в архив?');">
                  <button type="submit" class="btn btn-sm btn-outline-danger" title="В архив">
                    <i class="bi bi-archive"></i>
                  </button>
                </form>
              {% endif %}
            </div>
          </td>
        </tr>
        {% else %}
        <tr>
          <td colspan="6" class="text-center text-muted py-4">
            {{ 'В архиве пока пусто' if show_archive else 'Нет активных стажёров' }}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div>
{% endblock %}