<?php
$title = "Submission Reviews";

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

<div class="container mt-4">

<h2>
Reviews — Submission #<?= (int)$submission['id'] ?>
</h2>

<p class="text-muted">
<?= ar_h($submission['title_en'] ?? $submission['title_ar'] ?? $submission['title'] ?? '') ?>
</p>

<hr>

<?php if (empty($reviews)): ?>

<div class="alert alert-info">
No reviews are available yet.
</div>

<?php endif; ?>

<?php foreach ($reviews as $i => $r): ?>

<div class="card mb-4 shadow-sm">

<div class="card-header d-flex justify-content-between align-items-center">
<strong>
Blind Review <?= $i + 1 ?> — Round <?= (int)($r['round_no'] ?? 1) ?>
</strong>

<span class="badge bg-dark">
Reviewer identity hidden
</span>
</div>

<div class="card-body">

<div class="row mb-3">

<div class="col-md-4">
<strong>Overall Score</strong>
<div class="fs-4">
<?= ar_h($r['overall_score'] ?? $r['score'] ?? '-') ?>
</div>
</div>

<div class="col-md-4">
<strong>Recommendation</strong>
<div>
<span class="badge bg-secondary">
<?= ar_h($r['recommendation'] ?? '-') ?>
</span>
</div>
</div>

<div class="col-md-4">
<strong>Date</strong>
<div>
<?= ar_h($r['submitted_at'] ?? '-') ?>
</div>
</div>

</div>

<h5>Criteria Scores</h5>

<?php
$list =
    $criteriaScores[(int)$r['id']]
    ?? [];
?>

<?php if (!empty($list)): ?>

<table class="table table-sm table-bordered">
<thead>
<tr>
<th>Criterion</th>
<th>Score</th>
<th>Max</th>
<th>Weight</th>
<th>Review File</th>
</tr>
</thead>

<tbody>

<?php foreach ($list as $c): ?>

<tr>
<td>
<?= ar_h($c['title_en'] ?? $c['title_ar'] ?? '') ?>
</td>
<td>
<?= ar_h($c['score'] ?? '') ?>
</td>
<td>
<?= ar_h($c['max_score'] ?? '') ?>
</td>
<td>
<?= ar_h($c['weight'] ?? '') ?>
</td>
<td>

<?php if (!empty($file)): ?>

<a
href="/easychair/<?= htmlspecialchars($file) ?>"
target="_blank"
>

Download

</a>

<?php else: ?>

—

<?php endif; ?>

</td>
</tr>

<?php endforeach; ?>

</tbody>
</table>

<?php else: ?>

<p class="text-muted">
No detailed criteria scores available.
</p>

<?php endif; ?>

<h5>Comments to Author</h5>

<div class="border rounded p-3 bg-light">
<?= nl2br(ar_h($r['comments_to_author'] ?? 'No comments provided.')) ?>
</div>

<?php
$file =
    $r['review_file_path']
    ?? null;
?>

<?php if (!empty($file)): ?>

<div class="mt-3">

<a
href="/easychair/<?= htmlspecialchars($file) ?>"
target="_blank"
class="btn btn-outline-primary btn-sm"
>

Download Reviewer File

</a>

</div>

<?php else: ?>

<div class="text-muted mt-2">

No review file attached

</div>

<?php endif; ?>~

</div>
</div>

<?php endforeach; ?>

<a
href="/easychair/author/submission?id=<?= (int)$submission['id'] ?>"
class="btn btn-secondary"
>
Back
</a>

</div>
