<?php include app()->basePath('app/Views/partials/header.php'); ?>

<section class="panel">
    <div class="section-head clean-head">
        <div>
            <p class="eyebrow">Comunicacao</p>
            <h1>Notificacoes</h1>
            <p>Alertas internos da plataforma.</p>
        </div>
        <form method="post" action="/notifications/read-all">
            <?= csrf_field() ?>
            <button class="ghost-button" type="submit">Marcar todas como lidas</button>
        </form>
    </div>

    <div class="notification-list">
        <?php if (!$notifications): ?>
            <div class="sub-panel"><p>Nenhuma notificacao.</p></div>
        <?php endif; ?>

        <?php foreach ($notifications as $notification): ?>
            <article class="notification-card <?= empty($notification['read_at']) ? 'unread' : '' ?>">
                <div>
                    <strong><?= e($notification['title']) ?></strong>
                    <p><?= e($notification['body']) ?></p>
                    <span class="muted"><?= e(format_date($notification['created_at'])) ?></span>
                </div>
                <div class="row-actions">
                    <?php if (!empty($notification['url'])): ?>
                        <a class="mini-button" href="<?= e($notification['url']) ?>">Abrir</a>
                    <?php endif; ?>
                    <?php if (empty($notification['read_at'])): ?>
                        <form method="post" action="/notifications/read">
                            <?= csrf_field() ?>
                            <input type="hidden" name="id" value="<?= e((string) $notification['id']) ?>">
                            <button class="mini-button" type="submit">Lida</button>
                        </form>
                    <?php endif; ?>
                </div>
            </article>
        <?php endforeach; ?>
    </div>
</section>

<?php include app()->basePath('app/Views/partials/footer.php'); ?>
