<?php
$roles = isset($roles) ? $roles : array();
$page_title = isset($page_title) ? $page_title : 'Role Permissions';
?>
<div class="content-wrapper">
  <section class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-sm-8">
          <h1><?php echo htmlspecialchars($page_title); ?></h1>
          <p class="report-lead">Choose a role to set View and Export access for each report.</p>
        </div>
      </div>
    </div>
  </section>
  <section class="content">
    <div class="container-fluid">
      <?php if (!empty($flash_success)) { ?>
        <div class="alert alert-success"><?php echo htmlspecialchars($flash_success); ?></div>
      <?php } ?>
      <?php if (!empty($flash_error)) { ?>
        <div class="alert alert-danger"><?php echo htmlspecialchars($flash_error); ?></div>
      <?php } ?>
      <div class="row">
        <?php foreach ($roles as $role) { ?>
          <div class="col-md-4 mb-3">
            <div class="report-card card h-100">
              <div class="card-body">
                <h5 class="mb-1"><?php echo htmlspecialchars($role->name); ?>
                  <?php if (!empty($role->is_superadmin)) { ?>
                    <span class="badge badge-info">Full access</span>
                  <?php } ?>
                </h5>
                <p class="text-muted small mb-3"><?php echo htmlspecialchars($role->description ? $role->description : '—'); ?></p>
                <a href="<?php echo base_url('index.php/permissions/edit/' . (int) $role->id); ?>" class="btn btn-primary btn-sm">
                  <i class="fas fa-key mr-1"></i> Configure
                </a>
              </div>
            </div>
          </div>
        <?php } ?>
      </div>
    </div>
  </section>
</div>
