<?php require dirname(__DIR__) . '/layouts/app.php'; ?>
<section class="page-heading"><div><p class="eyebrow">Location longue duree</p><h1>Contrats</h1></div><a class="button-link" href="<?= url('/long-rentals/contracts/create') ?>">Ajouter</a></section>
<?php require __DIR__ . '/nav.php'; ?>
<?php if (!empty($notice)): ?><div class="alert alert-success"><?= e($notice) ?></div><?php endif; ?>
<section class="stat-grid compact-stats"><article class="stat-card"><span>Locataires actifs</span><strong><?= $summary['activeTenants'] ?></strong></article><article class="stat-card"><span>Loyers mensuels actifs</span><strong><?= number_format($summary['monthlyRent'], 2, ',', ' ') ?></strong></article><article class="stat-card"><span>Loyers en attente</span><strong><?= number_format($summary['pendingRent'], 2, ',', ' ') ?></strong></article></section>
<form class="filter-panel reservation-filter" method="get"><label>Du <input type="date" name="from" value="<?= e($from) ?>"></label><label>Au <input type="date" name="to" value="<?= e($to) ?>"></label><label>Statut <select name="status"><option value="">Tous</option><?php foreach (long_contract_statuses() as $key => $label): ?><option value="<?= e($key) ?>" <?= $status === $key ? 'selected' : '' ?>><?= e($label) ?></option><?php endforeach; ?></select></label><button>Filtrer</button></form>
<section class="table-panel"><table><thead><tr><th>Locataire</th><th>Bien</th><th>Debut</th><th>Fin</th><th>Loyer</th><th>Caution</th><th>Statut</th><th>Actions</th></tr></thead><tbody><?php foreach ($contracts as $contract): ?><tr><td><?= e($contract['tenant_name']) ?></td><td><?= e($contract['property_title']) ?></td><td><?= e($contract['start_date']) ?></td><td><?= e($contract['end_date'] ?: '-') ?></td><td><?= number_format((float) $contract['monthly_rent'], 2, ',', ' ') ?></td><td><?= number_format((float) $contract['deposit_amount'], 2, ',', ' ') ?></td><td><?= e(long_contract_statuses()[$contract['status']] ?? $contract['status']) ?></td><td class="actions"><a href="<?= url('/long-rentals/payments/create?contract_id=' . $contract['id']) ?>">Paiement</a><a href="<?= url('/long-rentals/contracts/edit?id=' . $contract['id']) ?>">Modifier</a><form method="post" action="<?= url('/long-rentals/contracts/delete') ?>" onsubmit="return confirm('Supprimer ce contrat ?');"><input type="hidden" name="_token" value="<?= csrf_token() ?>"><input type="hidden" name="id" value="<?= (int) $contract['id'] ?>"><button class="link-danger">Supprimer</button></form></td></tr><?php endforeach; ?><?php if (!$contracts): ?><tr><td colspan="8">Aucun contrat.</td></tr><?php endif; ?></tbody></table></section>
<?php require dirname(__DIR__) . '/partials/pagination.php'; ?>
<?php require dirname(__DIR__) . '/layouts/app_footer.php'; ?>
