{% extends 'base.html' %}

{% block content %}
<div class="container-fluid mt-0">
    <h1>Edit User</h1>
    <form method="POST" action="{{ url_for('update_user') }}">
        <input type="hidden" name="user_id" value="{{ user.user_id }}" />
        <div class="form-group">
            <label for="name">Name:</label>
            <input type="text" id="name" name="name" value="{{ user.name }}" required class="form-control" />
        </div>
        <div class="form-group">
            <label for="surname">Surname:</label>
            <input type="text" id="surname" name="surname" value="{{ user.surname }}" required class="form-control" />
        </div>
        <div class="form-group">
            <label for="email">Email (required for backend admins):</label>
            <input type="email" id="email" name="email" value="{{ user.email }}" class="form-control" />
        </div>
        <div class="form-group">
            <label for="role_id">Role:</label>
            <select id="role_id" name="role_id" class="form-control">
                {% for role in roles %}
                <option value="{{ role.role_id }}" {% if role.role_id == user.role_id %}selected{% endif %}>{{ role.role_name }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="mb-3 form-check">
            <input type="checkbox" id="disabled" name="disabled" {% if user.disabled %}checked{% endif %}
                class="form-check-input" />
            <label for="disabled" class="form-check-label">Tick to disable user</label>
        </div>
        <div class="form-group">
            <label for="card_UUID">Card UUID:</label>
            <input type="text" id="card_UUID" name="card_UUID" value="{% if user.card_UUID is not none %}{{user.card_UUID}}{%endif%}" pattern="[0-9A-Fa-f]{0}|[0-9A-Fa-f]{8}" class="form-control" />
            <small class="form-text text-muted">Please enter either 8 hexadecimal characters or leave it empty.</small>
        </div>
        <input type="submit" value="Update User" class="btn btn-primary" />
    </form>
</div>
{% endblock %}
