<?php require dirname(__DIR__) . '/layouts/app.php'; ?>
<?php $isEdit = !empty($payment['id']); ?>
<section class="page-heading"><div><p class="eyebrow">Location longue duree</p><h1><?= $isEdit ? 'Modifier paiement' : 'Ajouter paiement' ?></h1></div><a class="button-link secondary" href="<?= url('/long-rentals/payments') ?>">Retour</a></section>
<?php require __DIR__ . '/nav.php'; ?>
<?php if (!empty($errors)): ?><div class="alert alert-error"><?php foreach ($errors as $error): ?><div><?= e($error) ?></div><?php endforeach; ?></div><?php endif; ?>
<form class="form-panel" method="post" action="<?= url($isEdit ? '/long-rentals/payments/update' : '/long-rentals/payments/store') ?>"><input type="hidden" name="_token" value="<?= csrf_token() ?>"><?php if ($isEdit): ?><input type="hidden" name="id" value="<?= (int) $payment['id'] ?>"><?php endif; ?><div class="form-grid"><label>Contrat <select name="contract_id" required><option value="">Choisir</option><?php foreach ($contracts as $contract): ?><option value="<?= (int) $contract['id'] ?>" data-rent="<?= e((string) $contract['monthly_rent']) ?>" <?= (int) $payment['contract_id'] === (int) $contract['id'] ? 'selected' : '' ?>>#<?= (int) $contract['id'] ?> - <?= e($contract['tenant_name']) ?> - <?= e($contract['property_title']) ?> - <?= number_format((float) $contract['monthly_rent'], 2, ',', ' ') ?></option><?php endforeach; ?></select></label><label>Mois paye <input type="month" name="paid_month" value="<?= e($payment['paid_month']) ?>" required></label><label>Loyer du mois <input type="number" min="0" step="0.01" name="due_amount" value="<?= e((string) $payment['due_amount']) ?>" required></label><label>Montant paye <input type="number" min="0" step="0.01" name="amount_paid" value="<?= e((string) $payment['amount_paid']) ?>"></label><label>Date paiement <input type="date" name="payment_date" value="<?= e($payment['payment_date'] ?? '') ?>"></label></div><label class="full-field">Notes <textarea name="notes" rows="5"><?= e($payment['notes']) ?></textarea></label><div class="form-actions"><button><?= $isEdit ? 'Enregistrer' : 'Ajouter' ?></button></div></form>
<?php require dirname(__DIR__) . '/layouts/app_footer.php'; ?>
