<?php include __DIR__ . '/../../layouts/header.php'; ?>
<?php include __DIR__ . '/../../layouts/sidebar.php'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h2 class="mb-0"><?= __('notifications') ?></h2>
    <button class="btn btn-primary rounded-pill px-4"><i class="fas fa-paper-plane"></i> Send Notification</button>
</div>

<div class="table-container">
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th><?= __('id') ?></th>
                    <th>Receiver</th>
                    <th>Title</th>
                    <th>Message</th>
                    <th><?= __('date') ?></th>
                    <th>Read Status</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($notifications)): ?>
                    <tr>
                        <td colspan="6" class="text-center py-5 text-muted"><?= __('no_data_found') ?></td>
                    </tr>
                <?php else: ?>
                    <?php foreach ($notifications as $notif): ?>
                        <tr>
                            <td class="text-secondary fw-semibold">#<?= htmlspecialchars($notif['id']) ?></td>
                            <td>
                                <span class="badge badge-light text-dark border fw-normal">
                                    <?= htmlspecialchars(ucfirst($notif['receiver_type'])) ?>: <?= htmlspecialchars($notif['receiver_name']) ?>
                                </span>
                            </td>
                            <td><div class="fw-bold text-dark"><?= htmlspecialchars($notif['title']) ?></div></td>
                            <td style="max-width: 250px;" class="text-truncate text-secondary" title="<?= htmlspecialchars($notif['body']) ?>">
                                <?= htmlspecialchars($notif['body']) ?>
                            </td>
                            <td class="text-secondary"><?= date('M d, Y h:i A', strtotime($notif['created_at'])) ?></td>
                            <td>
                                <?php if ($notif['is_read']): ?>
                                    <span class="badge badge-success">Read</span>
                                <?php else: ?>
                                    <span class="badge badge-warning">Unread</span>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>

    <?php if ($totalPages > 1): ?>
    <div class="d-flex justify-content-end mt-4">
        <ul class="pagination mb-0 gap-2">
            <li class="page-item <?= $page <= 1 ? 'disabled' : '' ?>">
                <a class="page-link rounded-circle border-0 text-secondary bg-light" href="?page=notifications&p=<?= $page - 1 ?>" style="width:40px; height:40px; display:flex; align-items:center; justify-content:center;"><i class="fas <?= isRTL() ? 'fa-chevron-right' : 'fa-chevron-left' ?>"></i></a>
            </li>
            <?php for ($i = 1; $i <= $totalPages; $i++): ?>
                <li class="page-item <?= $i == $page ? 'active' : '' ?>">
                    <a class="page-link rounded-circle border-0 <?= $i == $page ? 'bg-primary text-white' : 'text-secondary bg-light' ?>" href="?page=notifications&p=<?= $i ?>" style="width:40px; height:40px; display:flex; align-items:center; justify-content:center;"><?= $i ?></a>
                </li>
            <?php endfor; ?>
            <li class="page-item <?= $page >= $totalPages ? 'disabled' : '' ?>">
                <a class="page-link rounded-circle border-0 text-secondary bg-light" href="?page=notifications&p=<?= $page + 1 ?>" style="width:40px; height:40px; display:flex; align-items:center; justify-content:center;"><i class="fas <?= isRTL() ? 'fa-chevron-left' : 'fa-chevron-right' ?>"></i></a>
            </li>
        </ul>
    </div>
    <?php endif; ?>
</div>

<?php include __DIR__ . '/../../layouts/footer.php'; ?>
