<?php
/**
 * @var array $notifications
 * @var array $breadcrumbs
 * @var \Johncms\Notifications\Notification $item
 */

$this->layout(
    'system::layout/default',
    [
        'title'      => __('Notifications'),
        'page_title' => __('Notifications'),
    ]
);
?>
<?php if (! empty($data['message'])): ?>
    <?= $this->fetch(
        'system::app/alert',
        [
            'alert_type' => 'alert-success',
            'alert'      => $data['message'],
        ]
    ) ?>
<?php endif; ?>
<?php if (empty($data['notifications']) && empty($data['total'])): ?>
    <div class="alert alert-success">
        <?= __('All notifications have already been read') ?>
    </div>
<?php elseif (! empty($data['notifications'])): ?>
    <div class="small-full-width list-items overflow-hidden border-top">
        <?php foreach ($data['notifications'] as $notification): ?>
            <a href="<?= $notification['url'] ?>" class="list-item d-flex border-bottom pl-lg-0">
                <div class="flex-grow-1 item-content">
                    <div class="item-name"><?= $notification['name'] ?></div>
                    <?php if (! empty($notification['description'])): ?>
                        <div class="item-desc"><?= $notification['description'] ?></div>
                    <?php endif; ?>
                </div>
                <?php if (! empty($notification['counter'])): ?>
                    <div class="icon-right d-flex align-items-center pr-0">
                        <div class="badge badge-danger badge-pill"><?= $notification['counter'] ?></div>
                    </div>
                <?php endif; ?>
                <div class="icon-right">
                    <svg class="icon">
                        <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>#chevron-right"/>
                    </svg>
                </div>
            </a>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
<?php if ($data['total'] > 0): ?>
    <div class="list-items mb-3">
        <?php foreach ($data['items'] as $item): ?>
            <div class="new_post-item without_avatar">
                <div class="post-body">
                    <div class="small text-muted"><?= $item->created_at ?></div>
                    <div>
                        <?= $item->message ?>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
    <div>
        <div><?= __('Total') ?>: <?= $data['total'] ?></div>
        <!-- Page switching -->
        <?php if ($data['total'] > $user->config->kmess): ?>
            <div class="mt-1"><?= $data['pagination'] ?></div>
        <?php endif ?>
    </div>
    <div class="mb-2 mt-2">
        <form action="/notifications/clear/" method="post">
            <button type="submit" name="clear" value="1" class="btn btn-outline-primary"><?= __('Clear notifications') ?></button>
        </form>
    </div>
<?php endif; ?>
<div>
    <a href="/notifications/settings/"><?= __('Settings') ?></a>
</div>
