<?php $title = 'Loan 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-hand-holding-usd mr-2"></i>Loan Types</h1>
    <a href="<?= $baseUrl ?>/loans/types/create" class="glass-btn glass-btn-primary"><i class="fas fa-plus mr-1"></i>New Loan 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>Interest</th><th>Min Amount</th><th>Max Amount</th><th>Duration</th><th>Status</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->interest_rate, 1) ?>%</td>
                    <td>GHS <?= number_format($t->min_amount, 2) ?></td>
                    <td>GHS <?= number_format($t->max_amount, 2) ?></td>
                    <td><?= $t->min_duration_months ?> - <?= $t->max_duration_months ?> mo</td>
                    <td><?= $t->is_active ? '<span class="badge badge-success">Active</span>' : '<span class="badge badge-secondary">Inactive</span>' ?></td>
                    <td>
                        <a href="<?= $baseUrl ?>/loans/types/<?= $t->id ?>/edit" class="glass-btn btn-sm"><i class="fas fa-edit"></i></a>
                        <form method="POST" action="<?= $baseUrl ?>/loans/types/<?= $t->id ?>/delete" style="display:inline;" onsubmit="return confirm('Delete this loan type?');">
                            <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-hand-holding-usd"></i><p>No loan types defined yet</p></div>
    <?php endif; ?>
</div>
