<?php $isEdit = !empty($type); $title = $isEdit ? 'Edit Loan Type' : 'New Loan Type'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><?= $title ?></h1>
    <a href="<?= $baseUrl ?>/loans/types" class="glass-btn"><i class="fas fa-arrow-left mr-1"></i>Back</a>
</div>
<div class="glass-card">
    <form method="POST" action="<?= $baseUrl ?>/loans/types/<?= $isEdit ? $type->id . '/update' : 'store' ?>">
        <div class="row">
            <div class="col-md-8 form-group">
                <label style="color:rgba(255,255,255,0.7);">Name *</label>
                <input type="text" name="name" class="form-control glass-input" value="<?= htmlspecialchars($type->name ?? '') ?>" required>
            </div>
            <div class="col-md-4 form-group">
                <label style="color:rgba(255,255,255,0.7);">Interest Rate (%) *</label>
                <input type="number" step="0.01" name="interest_rate" class="form-control glass-input" value="<?= htmlspecialchars($type->interest_rate ?? '0') ?>" required>
            </div>
        </div>
        <div class="form-group">
            <label style="color:rgba(255,255,255,0.7);">Description</label>
            <textarea name="description" class="form-control glass-input" rows="2"><?= htmlspecialchars($type->description ?? '') ?></textarea>
        </div>
        <div class="row">
            <div class="col-md-3 form-group">
                <label style="color:rgba(255,255,255,0.7);">Min Amount (GHS) *</label>
                <input type="number" step="0.01" name="min_amount" class="form-control glass-input" value="<?= htmlspecialchars($type->min_amount ?? '0') ?>" required>
            </div>
            <div class="col-md-3 form-group">
                <label style="color:rgba(255,255,255,0.7);">Max Amount (GHS) *</label>
                <input type="number" step="0.01" name="max_amount" class="form-control glass-input" value="<?= htmlspecialchars($type->max_amount ?? '0') ?>" required>
            </div>
            <div class="col-md-3 form-group">
                <label style="color:rgba(255,255,255,0.7);">Min Duration (months) *</label>
                <input type="number" min="1" name="min_duration_months" class="form-control glass-input" value="<?= (int)($type->min_duration_months ?? 1) ?>" required>
            </div>
            <div class="col-md-3 form-group">
                <label style="color:rgba(255,255,255,0.7);">Max Duration (months) *</label>
                <input type="number" min="1" name="max_duration_months" class="form-control glass-input" value="<?= (int)($type->max_duration_months ?? 12) ?>" required>
            </div>
        </div>
        <div class="custom-control custom-checkbox mb-3">
            <input type="checkbox" class="custom-control-input" id="is_active" name="is_active" value="1" <?= ($type->is_active ?? 1) ? 'checked' : '' ?>>
            <label class="custom-control-label" for="is_active" style="color:rgba(255,255,255,0.7);">Active</label>
        </div>
        <div class="text-right">
            <a href="<?= $baseUrl ?>/loans/types" class="glass-btn mr-2">Cancel</a>
            <button type="submit" class="glass-btn glass-btn-primary"><?= $isEdit ? 'Update' : 'Create' ?></button>
        </div>
    </form>
</div>
