<?php require dirname(__DIR__) . '/layouts/app.php'; ?>

<section class="page-heading">
    <div>
        <p class="eyebrow">Gestion Locative Longue Duree</p>
        <h1>Biens Longue Duree</h1>
    </div>
    <a class="button-link" href="<?= url('/long-rentals/contracts/create') ?>">Associer un bien</a>
</section>

<?php require __DIR__ . '/nav.php'; ?>
<?php if (!empty($notice)): ?><div class="alert alert-success"><?= e($notice) ?></div><?php endif; ?>

<form class="filter-panel client-filter" method="get">
    <label>Recherche <input name="search" value="<?= e($search) ?>" placeholder="Bien, ville, adresse, locataire"></label>
    <label>Statut
        <select name="status">
            <option value="">Tous</option>
            <option value="occupied" <?= $status === 'occupied' ? 'selected' : '' ?>>Occupe</option>
            <option value="available" <?= $status === 'available' ? 'selected' : '' ?>>Disponible</option>
        </select>
    </label>
    <button>Filtrer</button>
</form>

<section class="table-panel">
    <table>
        <thead>
            <tr>
                <th>Bien</th>
                <th>Ville</th>
                <th>Adresse</th>
                <th>Statut</th>
                <th>Locataire(s)</th>
                <th>Loyer actif</th>
                <th>Periode active</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($properties as $property): ?>
                <?php $isOccupied = (int) $property['has_active_contract'] === 1; ?>
                <tr>
                    <td><?= e($property['title']) ?></td>
                    <td><?= e(trim(($property['city'] ?? '') . ' ' . ($property['district'] ?? ''))) ?></td>
                    <td><?= e($property['address'] ?: '-') ?></td>
                    <td><span class="status-pill <?= $isOccupied ? 'status-occupied' : 'status-available' ?>"><?= $isOccupied ? 'Occupe' : 'Disponible' ?></span></td>
                    <td><?= e($property['tenant_names'] ?: '-') ?></td>
                    <td><?= number_format((float) $property['active_monthly_rent'], 2, ',', ' ') ?></td>
                    <td><?= e($property['active_start_date'] ?: '-') ?> / <?= e($property['active_end_date'] ?: '-') ?></td>
                </tr>
            <?php endforeach; ?>
            <?php if (!$properties): ?><tr><td colspan="7">Aucun bien longue duree.</td></tr><?php endif; ?>
        </tbody>
    </table>
</section>

<?php require dirname(__DIR__) . '/partials/pagination.php'; ?>
<?php require dirname(__DIR__) . '/layouts/app_footer.php'; ?>
