<?php
/**
 * Expected vars:
 * $columns - associative label => key OR list of keys with same labels
 * $rows
 * $table_id (optional)
 * $empty_message (optional)
 */
if (!isset($columns) || !is_array($columns)) {
    $columns = array();
}
if (!isset($rows)) {
    $rows = array();
}
$table_id = isset($table_id) ? $table_id : 'reportTable';
$this->load->helper('report');
?>
<?php if (!empty($rows)) { ?>
<div class="report-datatable-wrap">
  <table id="<?php echo htmlspecialchars($table_id); ?>" class="table table-bordered table-striped table-hover table-sm table-report js-report-datatable" data-page-length="25" style="width:100%">
    <thead>
      <tr>
        <?php foreach ($columns as $label => $key) {
            if (is_int($label)) {
                $label = $key;
            }
            echo '<th>' . htmlspecialchars($label) . '</th>';
        } ?>
      </tr>
    </thead>
    <tbody>
      <?php
      foreach ($rows as $row) {
          echo '<tr>';
          foreach ($columns as $label => $key) {
              if (is_int($label)) {
                  $key = $label;
              }
              $val = report_cell($row, $key);
              echo '<td>' . htmlspecialchars((string) $val) . '</td>';
          }
          echo '</tr>';
      }
      ?>
    </tbody>
  </table>
</div>
<?php } else { ?>
  <div class="report-empty">
    <i class="fas fa-table"></i>
    <?php echo isset($empty_message) ? htmlspecialchars($empty_message) : 'No data loaded yet. Set filters and click Search to preview results, then export PDF if needed.'; ?>
  </div>
<?php } ?>
