<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="row justify-content-center">
    <div class="col-lg-7">
        <div class="card">
            <div class="card-header d-flex align-items-center gap-2">
                <i class="bi bi-receipt-cutoff" style="color: var(--brand);"></i> Log Expense
            </div>
            <div class="card-body">
                <form action="<?= site_url('expenses') ?>" method="post">
                    <?= csrf_field() ?>

                    <div class="row g-3 mb-3">
                        <div class="col-md-6">
                            <label class="form-label small fw-semibold">Category</label>
                            <select class="form-select" name="category" required>
                                <?php foreach ($lookups->expenseCategories as $key => $meta): ?>
                                    <option value="<?= esc($key) ?>"><?= esc($meta['label']) ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label small fw-semibold">Date</label>
                            <input type="date" class="form-control" name="expense_date" value="<?= date('Y-m-d') ?>" required>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label small fw-semibold">Description</label>
                        <input type="text" class="form-control" name="description" required placeholder="e.g. ECG electricity bill — July">
                    </div>

                    <div class="mb-3">
                        <label class="form-label small fw-semibold">Amount (GHS)</label>
                        <input type="number" step="0.01" min="0.01" class="form-control" name="amount" required>
                        <div class="form-text">Expenses under the manager-set auto-approval threshold are approved immediately; larger ones need a manager's sign-off.</div>
                    </div>

                    <div class="mb-4">
                        <label class="form-label small fw-semibold">Notes <span class="text-muted fw-normal">(optional)</span></label>
                        <textarea class="form-control" name="notes" rows="2" placeholder="Any extra context..."></textarea>
                    </div>

                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary"><i class="bi bi-check2 me-1"></i>Log Expense</button>
                        <a href="<?= site_url('expenses') ?>" class="btn btn-outline-secondary">Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?= $this->endSection() ?>
