<?php
use App\Core\Config;
?><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= e($title) ?> — <?= e(Config::get('app.name')) ?></title>
<style>
  body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #0b0b0b; margin: 0; padding: 32px 40px; }
  .print-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 20px; }
  .print-toolbar button { font-family: inherit; font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: 6px; border: 1px solid #c3c2b7; background: #fff; cursor: pointer; }
  h1 { font-size: 19px; margin: 0 0 2px; }
  .meta { color: #52514e; font-size: 12.5px; margin-bottom: 20px; }
  table { width: 100%; border-collapse: collapse; font-size: 12px; }
  th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid #e1e0d9; }
  th { text-transform: uppercase; letter-spacing: .03em; font-size: 10px; color: #52514e; border-bottom: 1.5px solid #898781; }
  tr:nth-child(even) td { background: #f9f9f7; }
  .empty { padding: 30px; text-align: center; color: #898781; }
  @media print {
    .print-toolbar { display: none; }
    body { padding: 0; }
    tr:nth-child(even) td { background: none; }
  }
</style>
</head>
<body>
  <div class="print-toolbar">
    <button onclick="window.print()">🖨 Print</button>
    <button onclick="window.close()">Close</button>
  </div>
  <h1><?= e($title) ?></h1>
  <div class="meta"><?= e($filterSummary) ?> · <?= count($rows) ?> row(s) · Generated <?= date('d M Y, H:i') ?></div>

  <table>
    <thead>
      <tr><?php foreach ($columns as $label) : ?><th><?= e($label) ?></th><?php endforeach; ?></tr>
    </thead>
    <tbody>
      <?php foreach ($rows as $row) : ?>
        <tr>
          <?php foreach (array_keys($columns) as $key) : ?>
            <?php
              $val = $row[$key] ?? '';
              if ($key === 'is_response_breached' || $key === 'is_resolution_breached') { $val = $val ? 'Yes' : 'No'; }
            ?>
            <td><?= e((string)$val) ?></td>
          <?php endforeach; ?>
        </tr>
      <?php endforeach; ?>
      <?php if (empty($rows)) : ?>
        <tr><td colspan="<?= count($columns) ?>" class="empty">No data matches the current filters.</td></tr>
      <?php endif; ?>
    </tbody>
  </table>
</body>
</html>
