{% extends "base.html" %}

{% block title %}Управление пользователями{% endblock %}

{% block content %}







<!--<form action="/users/create" method="post">
    <label>Логин:</label>
    <input type="text" name="username" required>

    <label>Пароль:</label>
    <input type="password" name="password" required>

    <label>Роль:</label>
    <select name="role">
        <option value="user">Пользователь</option>
        <option value="admin">Администратор</option>
    </select>

    <button type="submit">Создать</button>
</form>-->


<div class="intro-y box p-5">
    <h2 class="text-lg font-medium mr-auto">Add Users</h2>
    <div class="overflow-x-auto mt-5">
        <form action="/users/create" method="post">
            <div class="mt-3">
                <label class="block">Login</label>
                <input type="text" class="input w-full border mt-2" name="username" placeholder="username">
            </div>
            
            <div class="mt-3">
                <label class="block">Password</label>
                <input type="password" class="input w-full border mt-2" name="password" placeholder="secret">
            </div>
            
            <div class="mt-3">
                <label class="block">Role:</label>
                <select class="input w-full border mt-2" name="role">
                    <option value="user">User</option>
                    <option value="admin">Admin</option>
                </select>
            </div>
            
            <div class="mt-5">
                <button type="submit" class="button bg-theme-1 text-white w-full">Register</button>
            </div>
        </form>
    </div>
</div>

<div class="intro-y box mt-5">

 <div class="overflow-x-auto">
    <h2 class="text-lg font-medium mr-auto">
                       User list
                    </h2>
     <table class="table">
         <thead>
             <tr>
                 <th class="border-b-2 whitespace-no-wrap">ID</th>
                 <th class="border-b-2 whitespace-no-wrap">Login</th>
                 <th class="border-b-2 whitespace-no-wrap">Role</th>
                 <th class="border-b-2 whitespace-no-wrap">Actions</th>
             </tr>
         </thead>
         <tbody>
             {% for user in users %}
             <tr>
                 <td class="border-b">{{ user.id }}</td>
                 <td class="border-b">{{ user.username }}</td>
                 <td class="border-b">{{ user.role }}</td>
                 <td class="border-b"> 
                    <form action="/users/update_password" method="post">
                        <input type="hidden" name="user_id" value="{{ user.id }}">
                        <input type="password" class="input w-full border mt-2" name="new_password" placeholder="New password" required>
                        <button type="submit"  class="button bg-theme-1 text-white mt-5" >Refresh password</button>
                    </form>
             </tr>
            
              {% endfor %}
         </tbody>
     </table>
    
 </div>

 </div>

{% endblock %}
