<style>
.notification-management-header {
    background: linear-gradient(135deg, #72A565 0%, #91A134 100%);
    color: white;
    padding: 2rem;
    border-radius: 15px;
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.notification-stats-card {
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border-left: 4px solid #667eea;
}

.notification-stats-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.notification-table-card {
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    overflow: hidden;
}

.notification-table-card .card-header {
    background: linear-gradient(135deg, #72A565 0%, #91A134 100%);
    color: white;
    padding: 1.25rem 1.5rem;
    border: none;
}

.notification-table-card table thead {
    background: #f7fafc;
}

.notification-table-card table thead th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    color: #4a5568;
    border: none;
    padding: 1rem;
}

.notification-table-card table tbody tr {
    transition: all 0.3s ease;
    border-bottom: 1px solid #e2e8f0;
}

.notification-table-card table tbody tr:hover {
    background: #f7fafc;
    transform: scale(1.01);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.notification-table-card table tbody td {
    padding: 1.25rem 1rem;
    vertical-align: middle;
}

.badge-modern {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 500;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.badge-primary-modern {
    background: linear-gradient(135deg, #72A565 0%, #91A134 100%);
    color: white;
}

.btn-modern {
    border-radius: 10px;
    padding: 0.6rem 1.5rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.btn-modern:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.btn-modern-primary {
    background: linear-gradient(135deg, #72A565 0%, #91A134 100%);
    border: none;
    color: white;
}

.stats-number {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #72A565 0%, #91A134 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.filter-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #72A565 0%, #91A134 100%);
    color: white;
    margin-bottom: 1rem;
}

.message-preview {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
</style>

<!-- Header Section -->
<div class="notification-management-header">
    <div class="row align-items-center">
        <div class="col-md-6">
            <h2 class="mb-2">
                <i class="fa-solid fa-bell"></i> Notification Management
            </h2>
            <p class="mb-0 opacity-75">Send push notifications to users and manage notification history</p>
        </div>
        <div class="col-md-6 text-end">
            <a href="<?php echo base_url('Promotion/addNotification'); ?>" class="btn btn-light btn-modern">
                <i class="fa-solid fa-plus"></i> Send New Notification
            </a>
        </div>
    </div>
</div>

<!-- Statistics Card -->
<div class="row mb-4">
    <div class="col-md-4">
        <div class="notification-stats-card">
            <div class="d-flex align-items-center">
                <div class="flex-shrink-0">
                    <div class="filter-icon">
                        <i class="fa-solid fa-bell"></i>
                    </div>
                </div>
                <div class="flex-grow-1 ms-3">
                    <p class="text-muted mb-1 small">Total Notifications</p>
                    <h3 class="stats-number mb-0"><?php echo !empty($promotions) ? count($promotions) : 0; ?></h3>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Notifications Table -->
<div class="notification-table-card">
    <div class="card-header">
        <h5 class="mb-0">
            <i class="fa-solid fa-table"></i> Notifications List
        </h5>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover mb-0" id="notificationsTable">
                <thead>
                    <tr>
                        <th>Date & Time</th>
                        <th>Title</th>
                        <th>Message</th>
                        <th class="text-center">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if (!empty($promotions)) {
                        foreach ($promotions as $id => $notification) {
                            $time = isset($notification['time']) ? $notification['time'] : 0;
                            $dateTime = $time > 0 ? date('Y-m-d H:i:s', $time / 1000) : 'N/A';
                            $title = isset($notification['title']) ? $notification['title'] : 'Unknown';
                            $message = isset($notification['message']) ? $notification['message'] : '';
                    ?>
                    <tr>
                        <td>
                            <i class="fa-solid fa-calendar text-primary me-2"></i>
                            <?php echo htmlspecialchars($dateTime); ?>
                        </td>
                        <td><strong><?php echo htmlspecialchars($title); ?></strong></td>
                        <td>
                            <div class="message-preview" title="<?php echo htmlspecialchars($message); ?>">
                                <?php echo htmlspecialchars($message); ?>
                            </div>
                        </td>
                        <td>
                            <div class="d-flex gap-2 justify-content-center">
                                <a href="<?php echo base_url('Promotion/editNotification/' . $id); ?>" class="btn btn-sm btn-info btn-modern" title="Edit">
                                    <i class="fa-solid fa-edit"></i> Edit
                                </a>
                                <a href="<?php echo base_url('Promotion/deleteNotification/' . $id); ?>" 
                                    class="btn btn-sm btn-danger btn-modern" 
                                    title="Delete"
                                    onclick="return confirm('Are you sure you want to delete this notification?');">
                                    <i class="fa-solid fa-trash"></i> Delete
                                </a>
                            </div>
                        </td>
                    </tr>
                    <?php
                        }
                    } else {
                    ?>
                    <tr>
                        <td colspan="4" class="text-center py-5">
                            <i class="fa-solid fa-bell fa-3x text-muted mb-3"></i>
                            <p class="text-muted">No notifications found</p>
                            <a href="<?php echo base_url('Promotion/addNotification'); ?>" class="btn btn-modern btn-modern-primary">
                                <i class="fa-solid fa-plus"></i> Send First Notification
                            </a>
                        </td>
                    </tr>
                    <?php
                    }
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>
<script>
$(document).ready(function() {
    $('#notificationsTable').DataTable({
        "order": [[ 0, "desc" ]],
        "pageLength": 25,
        "language": {
            "search": "<i class='fa-solid fa-search'></i> Search:",
            "lengthMenu": "Show _MENU_ notifications per page",
            "info": "Showing _START_ to _END_ of _TOTAL_ notifications",
            "infoEmpty": "No notifications found",
            "infoFiltered": "(filtered from _MAX_ total notifications)"
        }
    });
});
</script>
