<!-- templates/accounts/create_user.html -->
{% extends 'core/base.html' %}
{% load static %}

{% block title %}Add User - SwiftPOS{% endblock %}

{% block topbar_title %}
Add User
{% endblock %}

{% block content %}
<div class="container-fluid px-0">

    <div class="d-flex flex-wrap justify-content-between align-items-center mb-3 gap-2">
        <div>
            <h5 class="mb-0">Create New User</h5>
            <div class="text-muted small">
                Set up a new cashier, manager or admin account.
            </div>
        </div>
        <a href="{% url 'user_management' %}"
           class="btn btn-outline-secondary btn-sm d-flex align-items-center gap-2">
            <i class="fas fa-arrow-left"></i> Back to Users
        </a>
    </div>

    <!-- Toast Messages -->
    <div class="swiftpos-toast-container">
        {% if messages %}
            {% for message in messages %}
                <div class="swiftpos-toast swiftpos-toast-{{ message.tags }}">
                    <div class="toast-icon">
                        {% if message.tags == 'success' %}
                            <i class="fas fa-check-circle"></i>
                        {% elif message.tags == 'error' or message.tags == 'danger' %}
                            <i class="fas fa-exclamation-circle"></i>
                        {% elif message.tags == 'warning' %}
                            <i class="fas fa-exclamation-triangle"></i>
                        {% else %}
                            <i class="fas fa-info-circle"></i>
                        {% endif %}
                    </div>
                    <div class="toast-text">
                        {{ message }}
                    </div>
                </div>
            {% endfor %}
        {% endif %}
    </div>

    <div class="card">
        <div class="card-body">
            <form method="post">
                {% csrf_token %}

                <div class="row g-3">
                    <div class="col-md-6">
                        <label for="{{ form.username.id_for_label }}" class="form-label">Username</label>
                        {{ form.username }}
                        {% if form.username.errors %}
                            <div class="text-danger mt-1 small">{{ form.username.errors }}</div>
                        {% endif %}
                    </div>

                    <div class="col-md-6">
                        <label for="{{ form.email.id_for_label }}" class="form-label">Email</label>
                        {{ form.email }}
                        {% if form.email.errors %}
                            <div class="text-danger mt-1 small">{{ form.email.errors }}</div>
                        {% endif %}
                    </div>
                </div>
                

                <div class="row g-3 mt-1">
                    <div class="col-md-6">
                        <label for="{{ form.role.id_for_label }}" class="form-label">Role</label>
                        {{ form.role }}
                        {% if form.role.errors %}
                            <div class="text-danger mt-1 small">{{ form.role.errors }}</div>
                        {% endif %}
                    </div>

                    <div class="col-md-6">
                        <label for="{{ form.phone.id_for_label }}" class="form-label">Phone</label>
                        {{ form.phone }}
                        {% if form.phone.errors %}
                            <div class="text-danger mt-1 small">{{ form.phone.errors }}</div>
                        {% endif %}
                    </div>
                </div>

                <div class="row g-3 mt-1">
                    <div class="col-md-6">
                        <label for="{{ form.first_name.id_for_label }}" class="form-label">First Name</label>
                        {{ form.first_name }}
                        {% if form.first_name.errors %}
                            <div class="text-danger mt-1 small">{{ form.first_name.errors }}</div>
                        {% endif %}
                    </div>

                    <div class="col-md-6">
                        <label for="{{ form.last_name.id_for_label }}" class="form-label">Last Name</label>
                        {{ form.last_name }}
                        {% if form.last_name.errors %}
                            <div class="text-danger mt-1 small">{{ form.last_name.errors }}</div>
                        {% endif %}
                    </div>
                </div>

                <div class="row g-3 mt-1">
                    <div class="col-md-6">
                        <label for="{{ form.password1.id_for_label }}" class="form-label">Password</label>
                        {{ form.password1 }}
                        {% if form.password1.errors %}
                            <div class="text-danger mt-1 small">{{ form.password1.errors }}</div>
                        {% endif %}
                    </div>

                    <div class="col-md-6">
                        <label for="{{ form.password2.id_for_label }}" class="form-label">Confirm Password</label>
                        {{ form.password2 }}
                        {% if form.password2.errors %}
                            <div class="text-danger mt-1 small">{{ form.password2.errors }}</div>
                        {% endif %}
                    </div>
                </div>

                <div class="mt-4 d-flex justify-content-end gap-2">
                    <a href="{% url 'user_management' %}" class="btn btn-outline-secondary btn-sm">
                        Cancel
                    </a>
                    <button type="submit" class="btn btn-primary btn-sm d-flex align-items-center gap-2">
                        <i class="fas fa-save"></i> Add User
                    </button>
                </div>
            </form>
        </div>
    </div>

</div>
{% endblock %}
