{% macro user_form(roles, errors, form_data, include_credentials=False, disable_role=False) %}
    {% if include_credentials %}
    <div class="mb-3">
        <label for="login" class="form-label">Логин <span style="color: var(--error);">*</span></label>
        <div class="input-icon-wrapper">
            <i class="fas fa-user input-icon"></i>
            <input type="text"
                   class="form-control form-control-icon {% if errors.get('login') %}is-invalid{% endif %}"
                   id="login" name="login"
                   value="{{ form_data.get('login', '') }}"
                   placeholder="Не менее 5 символов, только латинские буквы и цифры">
        </div>
        {% if errors.get('login') %}
        <div class="invalid-feedback d-block">
            {% for e in errors['login'] %}<div>{{ e }}</div>{% endfor %}
        </div>
        {% endif %}
    </div>

    <div class="mb-3">
        <label for="password" class="form-label">Пароль <span style="color: var(--error);">*</span></label>
        <div class="input-icon-wrapper">
            <i class="fas fa-lock input-icon"></i>
            <input type="password"
                   class="form-control form-control-icon {% if errors.get('password') %}is-invalid{% endif %}"
                   id="password" name="password"
                   placeholder="Не менее 8 символов">
        </div>
        {% if errors.get('password') %}
        <div class="invalid-feedback d-block">
            {% for e in errors['password'] %}<div>{{ e }}</div>{% endfor %}
        </div>
        {% endif %}
    </div>
    {% endif %}

    <div class="mb-3">
        <label for="last_name" class="form-label">Фамилия <span style="color: var(--error);">*</span></label>
        <input type="text"
               class="form-control {% if errors.get('last_name') %}is-invalid{% endif %}"
               id="last_name" name="last_name"
               value="{{ form_data.get('last_name', '') }}"
               placeholder="Введите фамилию">
        {% if errors.get('last_name') %}
        <div class="invalid-feedback d-block">
            {% for e in errors['last_name'] %}<div>{{ e }}</div>{% endfor %}
        </div>
        {% endif %}
    </div>

    <div class="mb-3">
        <label for="first_name" class="form-label">Имя <span style="color: var(--error);">*</span></label>
        <input type="text"
               class="form-control {% if errors.get('first_name') %}is-invalid{% endif %}"
               id="first_name" name="first_name"
               value="{{ form_data.get('first_name', '') }}"
               placeholder="Введите имя">
        {% if errors.get('first_name') %}
        <div class="invalid-feedback d-block">
            {% for e in errors['first_name'] %}<div>{{ e }}</div>{% endfor %}
        </div>
        {% endif %}
    </div>

    <div class="mb-3">
        <label for="middle_name" class="form-label">Отчество</label>
        <input type="text"
               class="form-control"
               id="middle_name" name="middle_name"
               value="{{ form_data.get('middle_name', '') }}"
               placeholder="Введите отчество (необязательно)">
    </div>

    <div class="mb-4">
        <label for="role_id" class="form-label">Роль
            {% if disable_role %}
            <span style="color: var(--text-muted); font-size: 0.8rem;">(недоступно для изменения)</span>
            {% endif %}
        </label>
        <select class="form-control form-select-custom" id="role_id" name="role_id"
                {% if disable_role %}disabled{% endif %}>
            <option value="">— Без роли —</option>
            {% for role in roles %}
            <option value="{{ role.id }}"
                {% if form_data.get('role_id') is not none and form_data.get('role_id')|string == role.id|string %}selected{% endif %}>
                {{ role.name }}
            </option>
            {% endfor %}
        </select>
        {% if disable_role %}
        <input type="hidden" name="role_id" value="{{ form_data.get('role_id', '') }}">
        {% endif %}
    </div>
{% endmacro %}
