<?php use function App\Core\e; $section = 'abonelikler'; $money = static fn ($v) => number_format((float) $v, 2, ',', '.') . ' TRY'; ?>
<div class="panel zpanel zpanel-app">
    <?php require BASE_PATH . '/app/Views/zpanel/_sidebar.php'; ?>
    <section class="panel-body zpanel-main">
        <div class="zpanel-head"><div><p class="eyebrow">ZPanel</p><h1>Paketler / Abonelikler</h1><p class="muted">Creator paketleri ve abonelik durumlari. Manuel abonelik guncelleme TODO.</p></div></div>
        <section class="zpanel-card"><div class="zpanel-card-head"><h2>Creator paketleri</h2></div><div class="table-scroll"><table class="zpanel-table">
            <thead><tr><th>Paket</th><th>Sahip</th><th>Fiyatlar</th><th>Status</th><th>Aktif abone</th></tr></thead><tbody>
            <?php foreach (($packages ?? []) as $package): ?><tr><td><strong><?= e($package['name'] ?? '-') ?></strong><span class="muted block"><?= e($package['slug'] ?? '') ?></span></td><td><?= e($package['creator_name'] ?? $package['creator_username'] ?? '-') ?></td><td><?= e($money($package['price_monthly'] ?? $package['price'] ?? 0)) ?> / <?= e($money($package['price_6_month'] ?? 0)) ?> / <?= e($money($package['price_12_month'] ?? 0)) ?></td><td><span class="status-pill"><?= e($package['status'] ?? (!empty($package['is_active']) ? 'active' : 'inactive')) ?></span></td><td><?= e((string) ($package['active_subscribers'] ?? 0)) ?></td></tr><?php endforeach; ?>
            <?php if (empty($packages)): ?><tr><td colspan="5">Paket kaydi yok.</td></tr><?php endif; ?>
            </tbody></table></div></section>
        <section class="zpanel-card"><div class="zpanel-card-head"><h2>Abonelikler</h2></div><div class="table-scroll"><table class="zpanel-table">
            <thead><tr><th>Abone</th><th>Creator</th><th>Paket</th><th>Status</th><th>Baslangic</th><th>Bitis</th></tr></thead><tbody>
            <?php foreach (($subscriptions ?? []) as $sub): ?><tr><td><?= e($sub['subscriber_username'] ?? '-') ?></td><td><?= e($sub['creator_username'] ?? '-') ?></td><td><?= e($sub['package_name'] ?? '-') ?></td><td><span class="status-pill"><?= e($sub['status'] ?? '-') ?></span></td><td><?= e($sub['starts_at'] ?? '') ?></td><td><?= e($sub['ends_at'] ?? '') ?></td></tr><?php endforeach; ?>
            <?php if (empty($subscriptions)): ?><tr><td colspan="6">Abonelik kaydi yok.</td></tr><?php endif; ?>
            </tbody></table></div></section>
    </section>
</div>
