<!-- Subscription List -->
<h2 style="margin: 30px 0 15px 0; color: #333;">
    📋 Daftar Subscription
    <?php if($stats['filtered'] !== $stats['total']): ?>
        (<?php echo e($stats['filtered']); ?> dari <?php echo e($stats['total']); ?> subscription)
    <?php endif; ?>
    <?php if($totalPages > 0): ?>
        - Halaman <?php echo e($currentPage); ?> dari <?php echo e($totalPages); ?>

    <?php endif; ?>
</h2>

<?php if($totalPages > 1): ?>
<!-- Pagination Top -->
<?php echo $__env->make('admin.partials.pagination', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php endif; ?>

<?php if(empty($subscriptionsArray)): ?>
    <div class="no-results">
        <h3>🔍 Tidak ada subscription yang ditemukan</h3>
        <p>Coba ubah filter atau kata kunci pencarian Anda.</p>
    </div>
<?php else: ?>
    <div class="table-responsive">
        <table>
            <thead>
                <tr>
                    <th>ID Subscription</th>
                    <th>Status</th>
                    <th>Tanggal Kadaluarsa</th>
                    <th>Sisa Waktu</th>
                    <th>Catatan</th>
                    <th>Aksi</th>
                </tr>
            </thead>
            <tbody>
                <?php $currentTime = time() * 1000; ?>
                <?php $__currentLoopData = $subscriptionsArray; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $id => $subscription): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $isActive = $subscription['active'] ?? false;
                        $expiresAt = $subscription['expiresAt'] ?? 0;
                        $note = $subscription['note'] ?? '-';
                        $expiryDate = date('d/m/Y H:i', $expiresAt / 1000);
                        $isExpired = $currentTime > $expiresAt;

                        // Calculate remaining time
                        $remainingTime = '';
                        if ($expiresAt > 0) {
                            $diff = $expiresAt - $currentTime;
                            if ($diff > 0) {
                                $days = floor($diff / (24 * 60 * 60 * 1000));
                                $hours = floor(($diff % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
                                $remainingTime = $days . ' hari ' . $hours . ' jam';
                            } else {
                                $remainingTime = 'Sudah kadaluarsa';
                            }
                        }

                        $statusClass = ($isActive && !$isExpired) ? 'status-active' : 'status-expired';
                        $statusText = ($isActive && !$isExpired) ? '✅ Aktif' : '❌ Nonaktif/Expired';

                        // Highlight search results
                        $displayId = $id;
                        $displayNote = $note;
                        if (!empty($searchQuery)) {
                            $displayId = preg_replace('/(' . preg_quote($searchQuery, '/') . ')/i', '<span class="highlight">$1</span>', $displayId);
                            $displayNote = preg_replace('/(' . preg_quote($searchQuery, '/') . ')/i', '<span class="highlight">$1</span>', $displayNote);
                        }
                    ?>

                    <tr>
                        <td><strong><?php echo $displayId; ?></strong></td>
                        <td class="<?php echo e($statusClass); ?>"><?php echo e($statusText); ?></td>
                        <td><?php echo e($expiryDate); ?></td>
                        <td><?php echo e($remainingTime); ?></td>
                        <td><?php echo $displayNote; ?></td>
                        <td>
                            <div class="action-buttons">
                                <button class="btn btn-info btn-sm" onclick="editSubscription('<?php echo e($id); ?>', <?php echo e($expiresAt); ?>, <?php echo e($isActive ? 'true' : 'false'); ?>, '<?php echo e(addslashes($note)); ?>')">
                                    ✏️ Edit
                                </button>

                                <?php if($isActive && !$isExpired): ?>
                                    <form method="POST" style="display: inline;" onsubmit="return confirm('Yakin ingin menonaktifkan subscription ini?')" action="<?php echo e(route('admin.panel.post')); ?>">
                                        <?php echo csrf_field(); ?>
                                        <input type="hidden" name="action" value="deactivate">
                                        <input type="hidden" name="deactivate_id" value="<?php echo e($id); ?>">
                                        <button type="submit" class="btn btn-warning btn-sm">⏸️ Nonaktifkan</button>
                                    </form>
                                <?php endif; ?>

                                <button class="btn btn-success btn-sm" onclick="showExtendModal('<?php echo e($id); ?>')">
                                    ⏰ Perpanjang
                                </button>

                                <form method="POST" style="display: inline;" onsubmit="return confirm('PERHATIAN: Ini akan menghapus subscription secara permanen! Yakin ingin melanjutkan?')" action="<?php echo e(route('admin.panel.post')); ?>">
                                    <?php echo csrf_field(); ?>
                                    <input type="hidden" name="action" value="delete">
                                    <input type="hidden" name="delete_id" value="<?php echo e($id); ?>">
                                    <button type="submit" class="btn btn-danger btn-sm">🗑️ Hapus</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
<?php endif; ?>

<?php if($totalPages > 1): ?>
<!-- Pagination Bottom -->
<?php echo $__env->make('admin.partials.pagination', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php endif; ?>
<?php /**PATH D:\laragon\www\admin\resources\views\admin\partials\subscription-list.blade.php ENDPATH**/ ?>