<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-gift card-icon"></i>
                    <h5 class="card-title">Gift Cards</h5>
                </div>
                <div class="card-header-actions">
                    <?php if (can('loyalty_create')): ?>
                        <a href="<?= url('loyalty/giftcards/create') ?>" class="btn btn-gold btn-sm"><i class="fas fa-plus me-1"></i>Issue Gift Card</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>Code</th>
                                <th>Customer</th>
                                <th class="text-end">Initial Value</th>
                                <th class="text-end">Balance</th>
                                <th>Expires</th>
                                <th>Status</th>
                                <th class="text-end">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (empty($giftcards)): ?>
                            <tr><td colspan="7" class="text-center py-4 text-muted">No gift cards found.</td></tr>
                            <?php else: ?>
                                <?php foreach ($giftcards as $gc): ?>
                                <tr>
                                    <td><code><?= e($gc->code) ?></code></td>
                                    <td><?= e($gc->customer_name ?? 'N/A') ?></td>
                                    <td class="text-end"><?= currency($gc->initial_value) ?></td>
                                    <td class="text-end fw-bold"><?= currency($gc->balance) ?></td>
                                    <td><?= $gc->expires_at ? date('d M Y', strtotime($gc->expires_at)) : '-' ?></td>
                                    <td>
                                        <span class="badge bg-<?= $gc->status === 'active' ? 'success' : ($gc->status === 'used' ? 'secondary' : 'danger') ?>">
                                            <?= e($gc->status) ?>
                                        </span>
                                    </td>
                                    <td class="text-end">
                                        <?php if (can('loyalty_edit')): ?>
                                            <a href="<?= url('loyalty/giftcards/edit/' . $gc->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>
