<?php require_once __DIR__ . '/../header.php'; ?>

<div class="content-wrapper">
<section class="content pt-3">
<div class="container-fluid pb-5">

<div class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4">
    <div>
        <h3 class="mb-1 fw-bold">
            <i class="bi bi-bell-fill me-2 text-primary"></i>
            <?= __('admin.notifications','Notifications') ?>
        </h3>
        <p class="text-muted mb-0 small"><?= __('admin.notifications_subtitle','Unread system notifications') ?></p>
    </div>
    <div class="d-flex gap-2">
        <form method="post" action="/admin/notifications/read-all">
            <?= \Core\System\Csrf::field() ?>
            <button class="btn btn-outline-primary btn-sm">
                <i class="bi bi-check2-all me-1"></i><?= __('admin.mark_all_read','Mark all as read') ?>
            </button>
        </form>
        <form method="post" action="/admin/notifications/archive-all">
            <?= \Core\System\Csrf::field() ?>
            <button class="btn btn-outline-danger btn-sm">
                <i class="bi bi-archive me-1"></i><?= __('admin.archive_all','Archive all') ?>
            </button>
        </form>
    </div>
</div>

<div class="card border-0 shadow-sm">
    <div class="card-header bg-white border-bottom d-flex justify-content-between align-items-center py-3">
        <h6 class="mb-0 fw-semibold">
            <i class="bi bi-list-ul me-2 text-muted"></i><?= __('admin.notifications','Notifications') ?>
        </h6>
        <span class="badge bg-secondary rounded-pill"><?= count($notifications??[]) ?></span>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light">
                    <tr>
                        <th class="ps-3"><?= __('admin.notification','Notification') ?></th>
                        <th><?= __('admin.date','Date') ?></th>
                        <th class="text-end pe-3"><?= __('actions.actions','Actions') ?></th>
                    </tr>
                </thead>
                <tbody>
                <?php if(empty($notifications)): ?>
                <tr><td colspan="3" class="text-center py-5 text-muted">
                    <i class="bi bi-bell-slash display-4 d-block mb-2 opacity-50"></i>
                    <?= __('admin.no_notifications','No notifications') ?>
                </td></tr>
                <?php else: foreach($notifications as $n): ?>
                <tr class="<?= $n['is_read']?'':'table-warning' ?>">
                    <td class="ps-3">
                        <?php if(!$n['is_read']): ?>
                        <span class="badge bg-primary me-2" style="font-size:.6rem">NEW</span>
                        <?php endif; ?>
                        <a href="<?= htmlspecialchars((new \Core\App\Controllers\Admin\NotificationController())->resolveLink($n),ENT_QUOTES,'UTF-8') ?>"
                           class="text-decoration-none <?= $n['is_read']?'text-muted':'fw-semibold' ?>">
                            <?= __($n['title'],$n['title']) ?>
                        </a>
                    </td>
                    <td class="text-muted small"><?= date('d/m/Y H:i',strtotime($n['created_at'])) ?></td>
                    <td class="text-end pe-3">
                        <?php if(!$n['is_read']): ?>
                        <form method="post" action="/admin/notifications/read/<?= (int)$n['id'] ?>" class="d-inline">
                            <?= \Core\System\Csrf::field() ?>
                            <button class="btn btn-sm btn-outline-primary">
                                <i class="bi bi-check2 me-1"></i><?= __('admin.mark_read','Mark read') ?>
                            </button>
                        </form>
                        <?php endif; ?>
                        <form method="post" action="/admin/notifications/archive/<?= (int)$n['id'] ?>" class="d-inline">
                            <?= \Core\System\Csrf::field() ?>
                            <button class="btn btn-sm btn-outline-danger">
                                <i class="bi bi-archive"></i>
                            </button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

</div></section></div>
<?php require_once __DIR__ . '/../footer.php'; ?>
