<?php 
require_once("models/res_users.class.php");

$users = ResUsers::readAll();

if(isset($_POST['delete_id'])){

  $id = $_POST['delete_id'];
  $del = ResUsers::delete($id);
}
?>
<h3 class="mb-2">Users</h3>
<a href="create-users" class="btn btn-outline-info">+ New User</a>
    <table class="table table-stripped">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
                <th>Role</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach($users as $user){ ?>
                <tr>
                    <td><?php echo ($user['id']); ?></td>
                    <td><?php echo ($user['name']); ?></td>
                    <td><?php echo ($user['email']); ?></td>
                    <td><?php echo ($user['role']); ?></td>
                    <td>
                        <div class="d-flex gap-2">
                            <form action="user-details" method="get">
                            <input type="hidden" name="id" value="<?php echo ($user['id']); ?>">
                            <input type="submit" class="btn btn-sm btn-outline-success" value="Details">
                        </form>
                            <form action="update-users" method="get">
                            <input type="hidden" name="id" value="<?php echo ($user['id']); ?>">
                            <input type="submit" class="btn btn-sm btn-outline-info" value="Update">
                        </form>

                        <form method="post">
                            <input type="hidden" name="delete_id" value="<?php echo ($user['id']); ?>">
                            <input type="submit" class="btn btn-sm btn-outline-danger" value="Delete">
                        </form>
                        </div>
                    </td>   
                </tr>
            <?php }; ?>
        </tbody>
    </table>   
  
