<?php 
$pageTitle = 'Overdraft Settings';
include __DIR__ . '/../layouts/header.php'; 
?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-sliders me-2"></i>Overdraft Limit for <?= htmlspecialchars($client['full_name']) ?></h2>
    <a href="<?= $this->baseUrl('/clients') ?>" class="btn btn-outline-secondary">
        <i class="bi bi-arrow-left"></i> Back to Clients
    </a>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-body">
                <h5 class="card-title">Current Status</h5>
                <table class="table table-sm">
                    <tr><th>Current Balance:</th><td class="<?= $client['balance'] < 0 ? 'text-danger fw-bold' : '' ?>"><?= number_format($client['balance'], 2) ?> KES</td></tr>
                    <tr><th>Current Overdraft Limit:</th><td><?= number_format($client['overdraft_limit'], 2) ?> KES</td></tr>
                </table>
                <?php if ($client['balance'] < 0): ?>
                <div class="alert alert-warning">
                    <i class="bi bi-exclamation-triangle"></i> Client is currently overdrawn by <?= number_format(abs($client['balance']), 2) ?> KES.
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card">
            <div class="card-body">
                <form method="post" action="<?= $this->baseUrl('/clients/' . $client['id'] . '/overdraft') ?>">
                    <div class="mb-3">
                        <label class="form-label">Overdraft Limit (KES)</label>
                        <input type="number" step="0.01" name="overdraft_limit" class="form-control" 
                               value="<?= $client['overdraft_limit'] ?>" required>
                        <small class="text-muted">Maximum negative balance allowed. Set to 0 to disallow overdraft.</small>
                    </div>
                    <hr>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save"></i> Save Limit
                        </button>
                        <a href="<?= $this->baseUrl('/clients') ?>" class="btn btn-outline-secondary">
                            <i class="bi bi-x-circle"></i> Cancel
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php include __DIR__ . '/../layouts/footer.php'; ?>