{% extends "themis/base.html" %}

{% block title %}Set New Password — {{ themis_app_name }}{% endblock %}

{% block content %}
<div class="flex justify-center items-center min-h-[60vh]">
    <div class="card bg-base-200 shadow-xl w-full max-w-md">
        <div class="card-body">
            {% if validlink %}
            <h2 class="card-title text-2xl justify-center mb-4">Set New Password</h2>

            {% if form.errors %}
            <div class="alert alert-error mb-4">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 shrink-0" fill="none"
                     viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                          d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
                <div>
                    {% for field in form %}
                        {% for error in field.errors %}
                        <p>{{ error }}</p>
                        {% endfor %}
                    {% endfor %}
                    {% for error in form.non_field_errors %}
                    <p>{{ error }}</p>
                    {% endfor %}
                </div>
            </div>
            {% endif %}

            <form method="post">
                {% csrf_token %}

                <div class="form-control mb-4">
                    <label class="label" for="id_new_password1">
                        <span class="label-text">New password</span>
                    </label>
                    <input type="password" name="new_password1" id="id_new_password1"
                           class="input input-bordered w-full" autofocus required>
                    {% if form.new_password1.help_text %}
                    <label class="label">
                        <span class="label-text-alt text-base-content/60">{{ form.new_password1.help_text }}</span>
                    </label>
                    {% endif %}
                </div>

                <div class="form-control mb-6">
                    <label class="label" for="id_new_password2">
                        <span class="label-text">Confirm new password</span>
                    </label>
                    <input type="password" name="new_password2" id="id_new_password2"
                           class="input input-bordered w-full" required>
                </div>

                <div class="form-control mt-2">
                    <button type="submit" class="btn btn-primary w-full">Set Password</button>
                </div>
            </form>

            {% else %}
            <div class="text-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-16 w-16 text-error mx-auto mb-4" fill="none"
                     viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                          d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
                <h2 class="card-title text-2xl justify-center mb-2">Invalid Reset Link</h2>
                <p class="text-base-content/70 mb-6">
                    This password reset link is invalid or has expired.
                    Please request a new one.
                </p>
                <a href="{% url 'account_reset_password' %}" class="btn btn-primary">Request New Link</a>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
