{% extends 'base.html' %}
{% load form_tags %}
{% block title %}{{ title }}{% endblock %}

{% block content %}
<div class="space-y-4">
  <div class="flex items-center justify-between">
    <h1 class="text-2xl font-bold">{{ title }}</h1>
    <a href="{% url 'accounts:user_list' %}" class="btn btn-ghost btn-sm">Back to Users</a>
  </div>

  <div class="card max-w-3xl border border-base-300 bg-base-100">
    <div class="card-body">
      <form method="post" class="space-y-3">
        {% csrf_token %}
        {% for hidden in form.hidden_fields %}
          {{ hidden }}
        {% endfor %}
        {% if form.non_field_errors %}
          <div class="alert alert-error">{{ form.non_field_errors }}</div>
        {% endif %}
        {% if auto_username %}
          <div class="alert alert-info">
            Username will be generated automatically when you save this account.
          </div>
        {% endif %}
        {% for field in form.visible_fields %}
          <div class="form-control">
            <label class="label" for="{{ field.id_for_label }}">
              <span class="label-text">{{ field.label }}</span>
            </label>
            {{ field|daisyui }}
            {% if field.help_text %}
              <span class="label-text-alt mt-1 opacity-70">{{ field.help_text }}</span>
            {% endif %}
            {% for error in field.errors %}
              <span class="text-error text-sm mt-1">{{ error }}</span>
            {% endfor %}
          </div>
        {% endfor %}
        <div class="flex justify-end gap-2 pt-2">
          <a href="{% url 'accounts:user_list' %}" class="btn btn-ghost">Cancel</a>
          <button type="submit" class="btn btn-primary">Save Account</button>
        </div>
      </form>
    </div>
  </div>
</div>
{% endblock %}
