<?php $__env->startSection('title', 'TVKu - Subscription Management'); ?>

<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="header">
        <h1>🎬 TVKu - Subscription Management</h1>
        <p>Panel administrasi untuk mengelola langganan pengguna</p>
        <div style="margin-top: 15px;">
            <a href="<?php echo e(route('admin.logout')); ?>" style="color: #ecf0f1; text-decoration: none;">🚪 Logout</a>
        </div>
    </div>

    <div class="content">
        <?php if(session('success')): ?>
            <div class="success">✅ <?php echo e(session('success')); ?></div>
        <?php endif; ?>

        <?php if(session('error')): ?>
            <div class="error">❌ <?php echo e(session('error')); ?></div>
        <?php endif; ?>

        <!-- Stats Section -->
        <div class="stats">
            <div class="stat-card">
                <div class="stat-number"><?php echo e($stats['total']); ?></div>
                <div>Total Subscription</div>
            </div>
            <div class="stat-card">
                <div class="stat-number"><?php echo e($stats['active']); ?></div>
                <div>Aktif</div>
            </div>
            <div class="stat-card">
                <div class="stat-number"><?php echo e($stats['expired']); ?></div>
                <div>Expired/Nonaktif</div>
            </div>
            <div class="stat-card">
                <div class="stat-number"><?php echo e($stats['filtered']); ?></div>
                <div>Hasil Pencarian</div>
            </div>
        </div>

        <!-- Search Section -->
        <div class="search-container">
            <h2 class="search-title">🔍 Pencarian & Filter Subscription</h2>
            <form method="GET" id="searchForm" action="<?php echo e(route('admin.panel')); ?>">
                <input type="hidden" name="page" value="1">

                <div class="search-grid">
                    <div class="form-group">
                        <label for="search">Cari berdasarkan ID atau Catatan:</label>
                        <input type="text" id="search" name="search"
                               value="<?php echo e($searchQuery); ?>"
                               placeholder="Ketik ID subscription atau kata kunci...">
                    </div>

                    <div class="form-group">
                        <label for="status">Filter Status:</label>
                        <select id="status" name="status">
                            <option value="">Semua Status</option>
                            <option value="active" <?php echo e($searchStatus === 'active' ? 'selected' : ''); ?>>✅ Aktif</option>
                            <option value="inactive" <?php echo e($searchStatus === 'inactive' ? 'selected' : ''); ?>>❌ Tidak Aktif</option>
                            <option value="expired" <?php echo e($searchStatus === 'expired' ? 'selected' : ''); ?>>⏰ Expired</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="sort">Urutkan berdasarkan:</label>
                        <select id="sort" name="sort">
                            <option value="id" <?php echo e($searchSort === 'id' ? 'selected' : ''); ?>>ID (A-Z)</option>
                            <option value="expiry" <?php echo e($searchSort === 'expiry' ? 'selected' : ''); ?>>Tanggal Kadaluarsa ↗</option>
                            <option value="expiry_desc" <?php echo e($searchSort === 'expiry_desc' ? 'selected' : ''); ?>>Tanggal Kadaluarsa ↘</option>
                            <option value="status" <?php echo e($searchSort === 'status' ? 'selected' : ''); ?>>Status</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-success">🔍 Cari</button>
                        <a href="<?php echo e(route('admin.panel')); ?>" class="btn btn-warning">🔄 Reset</a>
                    </div>
                </div>
            </form>

            <?php if($searchQuery || $searchStatus): ?>
            <div class="search-results">
                📊 Menampilkan <strong><?php echo e($stats['filtered']); ?></strong> dari <strong><?php echo e($stats['total']); ?></strong> subscription
                <?php if($searchQuery): ?>
                    | Pencarian: "<strong><?php echo e($searchQuery); ?></strong>"
                <?php endif; ?>
                <?php if($searchStatus): ?>
                    | Status: <strong>
                    <?php switch($searchStatus):
                        case ('active'): ?> ✅ Aktif <?php break; ?>
                        <?php case ('inactive'): ?> ❌ Tidak Aktif <?php break; ?>
                        <?php case ('expired'): ?> ⏰ Expired <?php break; ?>
                    <?php endswitch; ?>
                    </strong>
                <?php endif; ?>
            </div>
            <?php endif; ?>
        </div>

        <?php echo $__env->make('admin.partials.subscription-form', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php echo $__env->make('admin.partials.subscription-list', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php echo $__env->make('admin.partials.info-box', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php echo $__env->make('admin.partials.extend-modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('additional_js'); ?>
<script>
// JavaScript functions yang diperlukan untuk form
function editSubscription(id, expiresAt, active, note) {
    document.getElementById('subscription_id').value = id;
    document.getElementById('is_update').value = '1';
    document.getElementById('active').value = active ? '1' : '0';
    document.getElementById('note').value = note;
    document.getElementById('submitBtn').textContent = '💾 Update Subscription';
    document.getElementById('subscription_id').scrollIntoView();
}

function resetForm() {
    document.getElementById('subscriptionForm').reset();
    document.getElementById('is_update').value = '0';
    document.getElementById('submitBtn').textContent = '💾 Simpan Subscription';
}

function showExtendModal(subscriptionId) {
    document.getElementById('extend_id').value = subscriptionId;
    document.getElementById('extend_display_id').value = subscriptionId;
    document.getElementById('extendModal').style.display = 'block';
}

function closeExtendModal() {
    document.getElementById('extendModal').style.display = 'none';
}

// Close modal when clicking outside
window.onclick = function(event) {
    var modal = document.getElementById('extendModal');
    if (event.target == modal) {
        modal.style.display = 'none';
    }
}
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/codexgen.my.id/laravel/resources/views/admin/panel.blade.php ENDPATH**/ ?>