<?php require_once __DIR__.'/layout/header.php'; ?>
<?php require_once __DIR__.'/layout/sidebar.php'; ?>

<style>

/* ===== MAIN ===== */
.main {
  margin-left: 200px;
  padding: 24px;
}

h1 {
  margin-top: 0;
}

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.company-switcher {
  font-size: 14px;
}

.company-switcher select {
  padding: 4px 6px;
}

/* ===== TABLE ===== */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

th, td {
  padding: 12px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

th {
  background: #fafafa;
  font-size: 12px;
  text-transform: uppercase;
  color: #6b7280;
}

tr:hover {
  background: #f9fafb;
}

.level {
  font-size: 12px;
  color: #6b7280;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: #fff;
  cursor: pointer;
}

.btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

</style>

<main class="main">

<div class="topbar">

<h1>Roles</h1>

<div class="company-switcher">
<span>Company:</span>

<select>
<option selected>Acme Mining</option>
<option>Beta Resources</option>
<option>Gamma Operations</option>
</select>

</div>

</div>


<table>

<thead>

<tr>
<th>Role Name</th>
<th>Key</th>
<th>Hierarchy Level</th>
<th>Description</th>
<th>Actions</th>
</tr>

</thead>

<tbody>

<tr>
<td>Super Admin</td>
<td>super_admin</td>
<td><span class="level">Level 1 (Highest)</span></td>
<td>Full system access</td>
<td><button class="btn">Edit</button></td>
</tr>

<tr>
<td>Platform Admin</td>
<td>platform_admin</td>
<td><span class="level">Level 2</span></td>
<td>Manage platform-wide settings</td>
<td><button class="btn">Edit</button></td>
</tr>

<tr>
<td>Company Owner</td>
<td>company_owner</td>
<td><span class="level">Level 3</span></td>
<td>Owns and manages a company</td>
<td><button class="btn">Edit</button></td>
</tr>

<tr>
<td>Company Admin</td>
<td>company_admin</td>
<td><span class="level">Level 4</span></td>
<td>Manages company users and modules</td>
<td><button class="btn">Edit</button></td>
</tr>

<tr>
<td>User</td>
<td>user</td>
<td><span class="level">Level 5</span></td>
<td>Standard system user</td>
<td><button class="btn">Edit</button></td>
</tr>

<tr>
<td>Viewer</td>
<td>viewer</td>
<td><span class="level">Level 6 (Lowest)</span></td>
<td>Read-only access</td>
<td><button class="btn">Edit</button></td>
</tr>

</tbody>

</table>

</main>


<script>

/* ================= CSRF ================= */

let CSRF_TOKEN = null

fetch('/auth/csrf_token.php', { credentials: 'include' })

.then(r => r.json())

.then(d => CSRF_TOKEN = d.csrf_token)


function csrfFetch(url, options = {}) {

return fetch(url, {

...options,

credentials: 'include',

headers: {

...(options.headers || {}),

'X-CSRF-Token': CSRF_TOKEN

}

})

}

</script>


<?php require_once __DIR__.'/layout/footer.php'; ?>