<?php $emails = $di->mailQueueTable->selectLast($num); ?>
<?php if ($emails) : ?>
<?php
$e = array_reduce($emails, function ($_, $item) {$_[$item->recipients] = $item->recipients; return $_;}, array());
$users = array();
foreach ($di->userTable->findByEmail($e) as $user) {
    $users[$user->email] = $user;
}
?>
<div class="admin-last">
    <h2><?php __e('Last %s Emails', $num); ?></h2>
    <div class="am-grid-container">
        <table class="am-grid grid-no-highlight">
            <?php foreach ($emails as $n): ?>
            <tr class="am-grid-row">
                <td><div style="padding-bottom:.4em"><?php p($n->subject) ?></div>
                <?php if(isset($users[$n->recipients])) : ?>
                <a class="link" href="<?php p($this->userUrl($users[$n->recipients]->user_id)) ?>"
                   data-tooltip-url="<?php echo $this->url("admin-users/card?id={$users[$n->recipients]->user_id}") ?>"><?php p($n->recipients) ?></a>
                <?php else : ?>
                <span><?php p($n->recipients) ?></span>
                <?php endif; ?>
                <br/>
                <time class="widget-time" datetime="<?= date('c', amstrtotime($n->added)) ?>" title="<?php p(amDatetime($n->added)) ?>">&#x1f550; <?= $this->getElapsedTime($n->added) ?></time>
                </td>
            </tr>
            <?php endforeach ?>
        </table>
    </div>
</div>
<?php else: ?>
<div class="widget-nodata">
    <h2><?php __e('Last %s Emails', $num); ?></h2>
    <p><?php __e('No data to display yet') ?></p>
</div>
<?php endif; ?>