<?php require dirname(__DIR__) . '/layouts/app.php'; ?>
<?php $isEdit = !empty($contract['id']); ?>
<section class="page-heading"><div><p class="eyebrow">Location longue duree</p><h1><?= $isEdit ? 'Modifier contrat' : 'Ajouter contrat' ?></h1></div><a class="button-link secondary" href="<?= url('/long-rentals/contracts') ?>">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/contracts/update' : '/long-rentals/contracts/store') ?>"><input type="hidden" name="_token" value="<?= csrf_token() ?>"><?php if ($isEdit): ?><input type="hidden" name="id" value="<?= (int) $contract['id'] ?>"><?php endif; ?><div class="form-grid"><label>Locataire <select name="tenant_id" required><option value="">Choisir</option><?php foreach ($tenants as $tenant): ?><option value="<?= (int) $tenant['id'] ?>" <?= (int) $contract['tenant_id'] === (int) $tenant['id'] ? 'selected' : '' ?>><?= e($tenant['full_name']) ?></option><?php endforeach; ?></select></label><label>Bien <select name="property_id" required><option value="">Choisir</option><?php foreach ($properties as $property): ?><option value="<?= (int) $property['id'] ?>" <?= (int) $contract['property_id'] === (int) $property['id'] ? 'selected' : '' ?>><?= e($property['title']) ?></option><?php endforeach; ?></select></label><label>Date debut <input type="date" name="start_date" value="<?= e($contract['start_date']) ?>" required></label><label>Date fin <input type="date" name="end_date" value="<?= e($contract['end_date']) ?>"></label><label>Loyer mensuel <input type="number" min="0" step="0.01" name="monthly_rent" value="<?= e((string) $contract['monthly_rent']) ?>" required></label><label>Caution <input type="number" min="0" step="0.01" name="deposit_amount" value="<?= e((string) $contract['deposit_amount']) ?>"></label><label>Statut <select name="status"><?php foreach (long_contract_statuses() as $key => $label): ?><option value="<?= e($key) ?>" <?= $contract['status'] === $key ? 'selected' : '' ?>><?= e($label) ?></option><?php endforeach; ?></select></label></div><label class="full-field">Observations <textarea name="observations" rows="5"><?= e($contract['observations']) ?></textarea></label><div class="form-actions"><button><?= $isEdit ? 'Enregistrer' : 'Ajouter' ?></button></div></form>
<?php require dirname(__DIR__) . '/layouts/app_footer.php'; ?>
