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

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

{% block topbar_title %}
Edit 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">Edit User</h5>
            <div class="text-muted small">
                Update account details or reset password.
            </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="username" class="form-label">Username</label>
                        <input type="text"
                               name="username"
                               id="username"
                               class="form-control"
                               value="{{ user.username }}"
                               required>
                    </div>
                    <div class="col-md-6">
                        <label for="email" class="form-label">Email</label>
                        <input type="email"
                               name="email"
                               id="email"
                               class="form-control"
                               value="{{ user.email }}">
                    </div>
                </div>

                <div class="row g-3 mt-1">
                    <div class="col-md-6">
                        <label for="role" class="form-label">Role</label>
                        <select name="role" id="role" class="form-control" required>
                            <option value="admin" {% if user.role == 'admin' %}selected{% endif %}>Admin</option>
                            <option value="manager" {% if user.role == 'manager' %}selected{% endif %}>Manager</option>
                            <option value="cashier" {% if user.role == 'cashier' %}selected{% endif %}>Cashier</option>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label for="phone" class="form-label">Phone</label>
                        <input type="text"
                               name="phone"
                               id="phone"
                               class="form-control"
                               value="{{ user.phone }}">
                    </div>
                </div>

                <div class="mt-3">
                    <label for="password" class="form-label">
                        New Password <span class="text-muted">(leave blank to keep current)</span>
                    </label>
                    <input type="password"
                           name="password"
                           id="password"
                           class="form-control"
                           placeholder="Enter new password (optional)">
                </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> Update User
                    </button>
                </div>
            </form>
        </div>
    </div>

</div>
{% endblock %}
