<?php
$rows = $rows ?? [];

function dec_h($v) {
    return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
}
?>

<h3 class="mb-4">Chair Decision Board</h3>

<?php if(isset($_GET['msg']) && $_GET['msg']=='updated'): ?>
<div class="alert alert-success">
Decision updated successfully.
</div>
<?php endif; ?>

<div class="card border-0 shadow-sm" style="border-radius:20px;">
<div class="card-body">

<table class="table table-bordered table-hover align-middle">
<thead class="table-light">
<tr>
<th>ID</th>
<th>Title</th>
<th>Stage</th>
<th>Reviews</th>
<th>Avg Score</th>
<th>Current Decision</th>
<th>Make Decision</th>
</tr>
</thead>
<tbody>

<?php foreach($rows as $row): ?>
<tr>
<td><?= (int)$row['id'] ?></td>

<td>
<strong><?= dec_h($row['title'] ?? '') ?></strong>
<div class="text-muted small"><?= dec_h($row['status'] ?? '') ?></div>
</td>

<td>
<span class="badge bg-secondary">
<?= dec_h($row['stage'] ?? '-') ?>
</span>
</td>

<td class="text-center">
<?= (int)($row['reviews_count'] ?? 0) ?>
</td>

<td class="text-center">
<?= dec_h($row['avg_score'] ?? '-') ?>
</td>

<td>
<?= dec_h($row['decision'] ?? '—') ?>
</td>

<td>
<form method="POST" action="/easychair/admin/decisions/make" class="d-flex gap-2">
<input type="hidden" name="submission_id" value="<?= (int)$row['id'] ?>">

<select name="decision" class="form-select form-select-sm" required>
<option value="">Select</option>
<option value="accepted">Accept</option>
<option value="revision_required">Revision Required</option>
<option value="rejected">Reject</option>
</select>

<button class="btn btn-sm btn-primary">Apply</button>
</form>
</td>

</tr>
<?php endforeach; ?>

<?php if(empty($rows)): ?>
<tr>
<td colspan="7" class="text-center text-muted py-4">
No submissions found for decision board.
</td>
</tr>
<?php endif; ?>

</tbody>
</table>

</div>
</div>
