<?= $this->extend('admin/layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex justify-content-between align-items-center mb-3">
    <p class="text-muted mb-0"><?= count($tenants) ?> hotel(s) on the platform.</p>
    <a href="<?= site_url('admin/tenants/new') ?>" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i>Onboard Hotel</a>
</div>

<div class="card">
    <div class="table-responsive">
        <table class="table mb-0 align-middle">
            <thead>
            <tr>
                <th>Hotel</th>
                <th>Slug</th>
                <th>Plan</th>
                <th>Subscription</th>
                <th>Status</th>
                <th>Onboarded</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            <?php if (empty($tenants)): ?>
                <tr><td colspan="7" class="text-center text-muted py-4">No hotels onboarded yet.</td></tr>
            <?php endif; ?>
            <?php foreach ($tenants as $t): ?>
                <tr>
                    <td><a href="<?= site_url('admin/tenants/' . $t->id) ?>" class="text-decoration-none fw-semibold"><?= esc($t->hotel_name) ?></a></td>
                    <td class="text-muted"><?= esc($t->slug) ?></td>
                    <td><?= $t->subscription ? esc($t->subscription->plan_name) : '<span class="text-muted">— none —</span>' ?></td>
                    <td>
                        <?php if ($t->subscription):
                            $badge = (new \Config\Lookups())->subscriptionStatuses[$t->subscription->status]['badge'] ?? 'secondary'; ?>
                            <span class="badge bg-<?= $badge ?>"><?= esc(ucfirst($t->subscription->status)) ?></span>
                        <?php else: ?>
                            <span class="text-muted">—</span>
                        <?php endif; ?>
                    </td>
                    <td><span class="badge bg-<?= $t->status === 'active' ? 'success' : 'danger' ?>"><?= esc(ucfirst($t->status)) ?></span></td>
                    <td class="text-muted small"><?= esc(date('d M Y', strtotime($t->created_at))) ?></td>
                    <td class="text-end"><a href="<?= site_url('admin/tenants/' . $t->id) ?>" class="btn btn-sm btn-outline-primary">Manage</a></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<?= $this->endSection() ?>
