<div class="row">
    <div class="col-12">
        <div class="card glass-card">
            <div class="card-header">
                <div class="card-header-left">
                    <i class="fas fa-id-card card-icon"></i>
                    <h5 class="card-title">Memberships</h5>
                </div>
                <div class="card-header-actions">
                    <?php if (can('loyalty_create')): ?>
                        <a href="<?= url('loyalty/memberships/create') ?>" class="btn btn-gold btn-sm"><i class="fas fa-plus me-1"></i>Add Membership</a>
                    <?php endif; ?>
                </div>
            </div>
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover align-middle mb-0">
                        <thead>
                            <tr>
                                <th>Customer</th>
                                <th>Plan</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                                <th>Status</th>
                                <th class="text-end">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (empty($memberships)): ?>
                            <tr><td colspan="6" class="text-center py-4 text-muted">No memberships found.</td></tr>
                            <?php else: ?>
                                <?php foreach ($memberships as $m): ?>
                                <tr>
                                    <td><?= e($m->customer_name ?? 'N/A') ?></td>
                                    <td><?= e($m->plan_name ?? 'Standard') ?></td>
                                    <td><?= date('d M Y', strtotime($m->start_date)) ?></td>
                                    <td><?= $m->end_date ? date('d M Y', strtotime($m->end_date)) : '-' ?></td>
                                    <td>
                                        <span class="badge bg-<?= $m->status === 'active' ? 'success' : ($m->status === 'expired' ? 'danger' : 'secondary') ?>">
                                            <?= e($m->status) ?>
                                        </span>
                                    </td>
                                    <td class="text-end">
                                        <?php if (can('loyalty_edit')): ?>
                                            <a href="<?= url('loyalty/memberships/edit/' . $m->id) ?>" class="btn btn-sm btn-ghost"><i class="fas fa-edit"></i></a>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
