<?php

$overdue =
    (
        $a['status'] === 'assigned'
        &&
        !empty($a['due_date'])
        &&
        strtotime($a['due_date']) < time()
    );

?>

<?php if ($overdue): ?>

<span class="badge bg-danger">

Overdue

</span>

<?php else: ?>

<span class="badge bg-success">

<?= htmlspecialchars($a['status']) ?>

</span>

<button
class="btn btn-outline-primary btn-sm"
onclick="suggestReviewers(<?= (int)$submission['id'] ?>)"
>
Suggest Reviewers
</button>

<?php endif; ?>
<script>

function suggestReviewers(submissionId)
{
    fetch(
        '/easychair/admin/reviewer-suggest?submission_id='
        + submissionId
    )
    .then(
        r => r.json()
    )
    .then(
        data =>
        {

            if (!data.length) {

                alert(
                    "No reviewers available."
                );

                return;

            }

            let message =
                "Suggested Reviewers:\n\n";

            data.forEach(

                r =>
                {

                    message +=

                        r.name

                        + " (load: "

                        + r.load

                        + ")\n";

                }

            );

            alert(message);

        }

    );
}

</script>
