<?php
require_once("models/res_roles.class.php");
$roles = ResRoles::readAll();


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

  $id = $_POST['delete_id'];
  $del = ResRoles::delete($id);
}

?>

<div class="bg-secondary rounded h-100 p-4">

    <h2 class="mb-4">Roles</h2>
    <a href="role-create" class="btn btn-outline-info">Create a new role</a>
    <table class="table table-stripped">
        <thead>
            <tr>
                <th scope="col">ID</th>
                <th scope="col">Name</th>
                <th scope="col">Action</th>

            </tr>
        </thead>
        <tbody>
            <?php foreach ($roles as $role) { ?>
                <tr>
                    <td><?php echo $role["id"] ?></td>
                    <td><?php echo $role["name"] ?></td>
            <td>
              <div class="d-flex">

                <form action="role-edit" method="get" class="me-1">
                  <input type="hidden" name="id" value="<?php echo $role['id']; ?>">
                  <input type="submit" value="Edit" class="btn btn-outline-info">
                </form>
                <form method="post">
                  <input type="hidden" name="delete_id" value="<?php echo $role['id']; ?>">
                  <input type="submit" value="Delete" class="btn btn-outline-danger">
                </form>
              </div>
            </td>

                </tr>

            <?php } ?>
        </tbody>
    </table>
</div>