<?= $this->extend('layouts/mobile') ?>

<?= $this->section('header') ?>
<?= view('layouts/_inner_header', ['title' => $title ?? 'Notifications']) ?>
<?= $this->endSection() ?>

<?= $this->section('content') ?>
<?php
$items        = $items ?? [];
$unreadCount  = (int) ($unreadCount ?? 0);
$emptyMessage = $emptyMessage ?? \App\Services\NotificationService::MSG_EMPTY;
?>
<?php if ($unreadCount > 0): ?>
    <form method="post" action="<?= site_url('notifications/read-all') ?>" class="notification-toolbar">
        <?= csrf_field() ?>
        <button class="text-link-btn" type="submit">Mark all as read</button>
    </form>
<?php endif; ?>

<?php if ($items === []): ?>
    <p class="analytics-empty"><?= esc($emptyMessage) ?></p>
<?php else: ?>
    <ul class="notification-list">
        <?php foreach ($items as $item): ?>
            <li>
                <form method="post" action="<?= site_url('notifications/' . (int) $item['id'] . '/open') ?>">
                    <?= csrf_field() ?>
                    <button type="submit" class="notification-row<?= empty($item['is_read']) ? ' is-unread' : '' ?>">
                        <span class="notification-title"><?= esc($item['title']) ?></span>
                        <span class="notification-message"><?= esc($item['message']) ?></span>
                        <span class="notification-meta"><?= esc($item['created_label']) ?></span>
                    </button>
                </form>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>
<?= $this->endSection() ?>
