{% extends 'base.html' %}
{% block title %}运营面板 - 用户管理{% endblock %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-3">
  <h3>用户管理</h3>
  <div>
    <a class="btn btn-outline-secondary" href="{% url 'admin_panel:dashboard' %}">返回概览</a>
    <a class="btn btn-outline-secondary" href="/admin/auth/user/">在 Django Admin 查看</a>
  </div>
</div>

<form method="get" class="row g-2 mb-3">
  <div class="col-md-4">
    <input type="text" name="q" value="{{ q }}" class="form-control" placeholder="搜索用户名或邮箱" />
  </div>
  <div class="col-md-2">
    <button class="btn btn-primary" type="submit">搜索</button>
  </div>
</form>

<div class="table-responsive">
  <table class="table table-striped">
    <thead>
      <tr>
        <th>用户名</th>
        <th>显示名</th>
        <th>邮箱</th>
        <th>状态</th>
        <th>是否运营</th>
        <th>域名数</th>
        <th>注册时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      {% for u in users %}
      <tr>
        <td>{{ u.username }}</td>
        <td>{% if u.profile %}{{ u.profile.display_name }}{% endif %}</td>
        <td>{{ u.email }}</td>
        <td>{% if u.is_active %}<span class="badge bg-success">Active</span>{% else %}<span class="badge bg-secondary">Disabled</span>{% endif %}</td>
        <td>{% if u.is_staff %}是{% else %}否{% endif %}</td>
        <td>{{ u.domain_count }}</td>
        <td>{{ u.date_joined|date:'Y-m-d H:i' }}</td>
        <td>
          <a class="btn btn-sm btn-outline-primary" href="{% url 'admin_panel:domains' %}?user_id={{ u.id }}">查看域名</a>
        </td>
      </tr>
      {% empty %}
      <tr><td colspan="8" class="text-center">暂无用户</td></tr>
      {% endfor %}
    </tbody>
  </table>
</div>
{% endblock %}