<?php 
$pageTitle = 'Record Rent Payment';
include __DIR__ . '/../layouts/header.php'; 
?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-cash-coin me-2"></i>Record Rent Payment</h2>
    <a href="<?= $this->baseUrl('/rent/payments') ?>" class="btn btn-outline-secondary">
        <i class="bi bi-arrow-left"></i> Back to Payments
    </a>
</div>

<div class="row">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-body">
                <form method="post" action="<?= $this->baseUrl('/rent/payments') ?>">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">Property <span class="text-danger">*</span></label>
                                <select name="property_id" class="form-select" required>
                                    <option value="">-- Select Property --</option>
                                    <?php foreach ($properties ?? [] as $p): ?>
                                        <option value="<?= $p['id'] ?>">
                                            <?= htmlspecialchars($p['name']) ?> 
                                            <?= !empty($p['tenant_name']) ? '— ' . htmlspecialchars($p['tenant_name']) : '' ?>
                                        </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Payment Date <span class="text-danger">*</span></label>
                                <input type="date" name="payment_date" class="form-control" value="<?= date('Y-m-d') ?>" required>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Rent Period (Month) <span class="text-danger">*</span></label>
                                <input type="month" name="period_month" class="form-control" value="<?= date('Y-m') ?>" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">Amount (KES) <span class="text-danger">*</span></label>
                                <input type="number" step="0.01" name="amount" class="form-control" required autofocus>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Payment Method</label>
                                <select name="payment_method" class="form-select">
                                    <option value="cash">Cash</option>
                                    <option value="mpesa">M-Pesa</option>
                                    <option value="bank">Bank Transfer</option>
                                    <option value="other">Other</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Reference</label>
                                <input type="text" name="reference" class="form-control" placeholder="e.g., M-Pesa code, cheque number">
                            </div>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Notes</label>
                        <textarea name="notes" class="form-control" rows="2" placeholder="Any additional information..."></textarea>
                    </div>
                    <hr>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save"></i> Save Payment
                        </button>
                        <a href="<?= $this->baseUrl('/rent/payments') ?>" class="btn btn-outline-secondary">
                            <i class="bi bi-x-circle"></i> Cancel
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="col-lg-4">
        <div class="card">
            <div class="card-body">
                <h5 class="card-title"><i class="bi bi-info-circle me-2"></i>Quick Info</h5>
                <p class="text-muted small">Select a property to record a rent payment. The payment will be saved for the selected period and linked to the tenant.</p>
                <hr>
                <p class="text-muted small mb-0"><i class="bi bi-shield-lock"></i> All payments are recorded securely.</p>
            </div>
        </div>
    </div>
</div>

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