<?php $title = 'Contribution Types'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><i class="fas fa-tags mr-2"></i>Contribution Types</h1>
    <a href="<?= $baseUrl ?>/contribution-types/create" class="glass-btn glass-btn-primary"><i class="fas fa-plus mr-1"></i>New Type</a>
</div>

<div class="glass-card p-0">
    <?php if (!empty($types)): ?>
    <div class="glass-table">
        <table class="table">
            <thead><tr>
                <th>Name</th><th>Amount (GHS)</th><th>Frequency</th><th>Mandatory</th><th>Active</th><th>Members</th><th>Actions</th>
            </tr></thead>
            <tbody>
                <?php foreach ($types as $t): ?>
                <tr>
                    <td><strong><?= htmlspecialchars($t->name) ?></strong>
                        <?php if ($t->description): ?>
                        <br><small style="color: rgba(255,255,255,0.4);"><?= htmlspecialchars($t->description) ?></small>
                        <?php endif; ?>
                    </td>
                    <td><?= number_format($t->amount, 2) ?></td>
                    <td><?= htmlspecialchars(ucfirst($t->frequency)) ?><?= $t->duration_months ? ' <span style="color:rgba(255,255,255,0.4);">(' . (int)$t->duration_months . ' mo)</span>' : '' ?></td>
                    <td><?= $t->is_mandatory ? '<span class="glass-badge" style="background:rgba(231,74,59,0.2);color:#e74a3b;">Mandatory</span>' : '<span style="color:rgba(255,255,255,0.3);">Optional</span>' ?></td>
                    <td><?= $t->is_active ? '<span class="glass-badge" style="background:rgba(28,200,138,0.2);color:#1cc88a;">Active</span>' : '<span class="glass-badge" style="background:rgba(231,74,59,0.2);color:#e74a3b;">Inactive</span>' ?></td>
                    <td><a href="<?= $baseUrl ?>/contribution-types/<?= $t->id ?>/members" class="glass-btn btn-sm">Manage</a></td>
                    <td>
                        <a href="<?= $baseUrl ?>/contribution-types/<?= $t->id ?>/edit" class="glass-btn btn-sm"><i class="fas fa-edit"></i></a>
                        <form method="POST" action="<?= $baseUrl ?>/contribution-types/<?= $t->id ?>/delete" style="display:inline;" onsubmit="return confirm('Delete this contribution type? This cannot be undone.');">
                            <button type="submit" class="glass-btn btn-sm" style="border-color: rgba(231,74,59,0.3); color: #e74a3b;"><i class="fas fa-trash"></i></button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php else: ?>
    <div class="empty-state"><i class="fas fa-tags"></i><p>No contribution types defined. Create one to get started.</p></div>
    <?php endif; ?>
</div>