<div class="sa-card mb-8">
    <div class="flex justify-between items-center mb-6">
        <h3 class="text-xl font-bold">Platform Subscriptions</h3>
        <div class="text-xs text-muted">Real-time revenue tracking</div>
    </div>

    <div class="table-wrapper">
        <table>
            <thead>
                <tr>
                    <th>Tenant</th>
                    <th>Plan</th>
                    <th>Status</th>
                    <th>Amount</th>
                    <th>Billing Cycle</th>
                    <th>Started</th>
                    <th class="text-right">Action</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($subscriptions as $s): ?>
                <tr>
                    <td>
                        <div class="font-bold"><?= e($s['business_name'] ?? 'N/A') ?></div>
                        <div class="text-xs text-muted">ID: #<?= $s['tenant_id'] ?></div>
                    </td>
                    <td>
                        <span class="badge badge-info"><?= e($s['plan_name']) ?></span>
                    </td>
                    <td>
                        <?php
                        $statusBadge = [
                            'active' => 'badge-success',
                            'pending' => 'badge-warning',
                            'cancelled' => 'badge-danger',
                            'expired' => 'badge-danger',
                            'past_due' => 'badge-danger'
                        ];
                        $badgeClass = $statusBadge[$s['status']] ?? 'badge-muted';
                        ?>
                        <span class="badge <?= $badgeClass ?>">
                            <?= e($s['status']) ?>
                        </span>
                    </td>
                    <td class="font-bold text-lg">GH₵<?= number_format($s['amount'], 2) ?></td>
                    <td><span class="text-xs uppercase tracking-wider"><?= e($s['billing_cycle']) ?></span></td>
                    <td><?= date('M j, Y', strtotime($s['created_at'])) ?></td>
                    <td class="text-right">
                        <?php if ($s['status'] === 'pending'): ?>
                        <form action="<?= APP_URL ?>/superadmin/subscriptions/<?= $s['id'] ?>/approve" method="POST" style="display:inline;" onsubmit="return confirm('Approve this subscription and activate the tenant?');">
                            <?= Security::csrfField() ?>
                            <button type="submit" class="btn btn-ghost btn-sm text-primary-color">Approve</button>
                        </form>
                        <?php endif; ?>
                        <?php if ($s['status'] === 'active'): ?>
                        <form action="<?= APP_URL ?>/superadmin/subscriptions/<?= $s['id'] ?>/cancel" method="POST" style="display:inline;" onsubmit="return confirm('Cancel this subscription?');">
                            <?= Security::csrfField() ?>
                            <button type="submit" class="btn btn-ghost btn-sm text-danger">Cancel</button>
                        </form>
                        <?php endif; ?>
                        <a href="<?= APP_URL ?>/superadmin/tenants/<?= $s['tenant_id'] ?>" class="btn btn-ghost btn-sm">View Tenant</a>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php if (empty($subscriptions)): ?>
                <tr>
                    <td colspan="7" class="text-center p-8 text-muted italic">No subscriptions tracked on the platform yet.</td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
