<!-- register.html -->
{% extends "users/login/base.html" %}
{% load static %}

{% block form %}
<div class="card-header bg-primary text-white">
    <h3 class="mb-0"><i class="bi bi-box-arrow-in-right me-2"></i>用户注册</h3>
</div>
<div class="card-body p-4">
                    <form method="post" class="needs-validation" novalidate>
                        {% csrf_token %}
                        
                        <!-- 全局错误提示 -->
                        {% if form.non_field_errors %}
                        <div class="alert alert-danger alert-dismissible fade show" role="alert">
                            {% for error in form.non_field_errors %}
                                {{ error }}
                            {% endfor %}
                            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                        </div>
                        {% endif %}

                        <!-- 用户名 -->
                        <div class="mb-3">
                            <label for="{{ form.username.id_for_label }}" class="form-label">
                                <i class="bi bi-person-circle me-1"></i>用户名
                            </label>
                            <input type="text" 
                                   name="{{ form.username.name }}" 
                                   class="form-control form-control-lg {% if form.username.errors %}is-invalid{% endif %}" 
                                   id="{{ form.username.id_for_label }}"
                                   placeholder="请输入用户名"
                                   required>
                            {% for error in form.username.errors %}
                                <div class="invalid-feedback">{{ error }}</div>
                            {% endfor %}
                        </div>

                        <!-- 邮箱 -->
                        <div class="mb-3">
                            <label for="{{ form.email.id_for_label }}" class="form-label">
                                <i class="bi bi-envelope me-1"></i>邮箱
                            </label>
                            <input type="email" 
                                   name="{{ form.email.name }}" 
                                   class="form-control form-control-lg {% if form.email.errors %}is-invalid{% endif %}" 
                                   id="{{ form.email.id_for_label }}"
                                   placeholder="example@domain.com"
                                   required>
                            {% for error in form.email.errors %}
                                <div class="invalid-feedback">{{ error }}</div>
                            {% endfor %}
                        </div>

                        <!-- 密码 -->
                        <div class="mb-3">
                            <label for="{{ form.password.id_for_label }}" class="form-label">
                                <i class="bi bi-lock me-1"></i>密码
                            </label>
                            <input type="password" 
                                   name="{{ form.password.name }}" 
                                   class="form-control form-control-lg {% if form.password.errors %}is-invalid{% endif %}" 
                                   id="{{ form.password.id_for_label }}"
                                   placeholder="至少8位字符"
                                   required>
                            {% for error in form.password.errors %}
                                <div class="invalid-feedback">{{ error }}</div>
                            {% endfor %}
                        </div>

                        <!-- 确认密码 -->
                        <div class="mb-3">
                            <label for="{{ form.password_confirm.id_for_label }}" class="form-label">
                                <i class="bi bi-shield-check me-1"></i>确认密码
                            </label>
                            <input type="password" 
                                   name="{{ form.password_confirm.name }}" 
                                   class="form-control form-control-lg {% if form.password_confirm.errors %}is-invalid{% endif %}" 
                                   id="{{ form.password_confirm.id_for_label }}"
                                   placeholder="请再次输入密码"
                                   required>
                            {% for error in form.password_confirm.errors %}
                                <div class="invalid-feedback">{{ error }}</div>
                            {% endfor %}
                        </div>

                        <!-- 验证码 -->
                        <div class="mb-4">
                            <label class="form-label">
                                <i class="bi bi-shield-lock me-1"></i>验证码
                            </label>
                            <div class="d-flex align-items-center gap-3">
                                <div class="flex-grow-1">
                                    {{ form.captcha }}
                                </div>
                            </div>
                            {% for error in form.captcha.errors %}
                                <div class="invalid-feedback d-block">{{ error }}</div>
                            {% endfor %}
                        </div>

                        <div class="d-grid gap-2 mt-4">
                            <button type="submit" class="btn btn-primary btn-lg">
                                <i class="bi bi-person-check me-2"></i>立即注册
                            </button>
                        </div>

                        <div class="mt-4 text-center">
                            <span class="text-muted">已有账号？</span>
                            <a href="{% url 'users:login' %}" class="text-decoration-none ms-2">
                                <i class="bi bi-box-arrow-in-right me-1"></i>立即登录
                            </a>
                        </div>
                    </form>
                </div>
{% endblock %}

