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

<section class="page-heading">
    <div>
        <p class="eyebrow"><?= e(property_types()[$property['type']] ?? $property['type']) ?></p>
        <h1><?= e($property['title']) ?></h1>
    </div>
    <div class="heading-actions">
        <?php if (Auth::can('properties.edit')): ?>
            <a class="button-link" href="<?= url('/properties/edit?id=' . $property['id']) ?>">Modifier</a>
        <?php endif; ?>
        <a class="button-link secondary" href="<?= url('/properties') ?>">Retour</a>
    </div>
</section>

<section class="detail-layout">
    <article class="detail-panel">
        <span class="status-pill status-<?= e($property['status']) ?>">
            <?= e(property_statuses()[$property['status']] ?? $property['status']) ?>
        </span>
        <dl>
            <dt>Ville</dt>
            <dd><?= e($property['city']) ?></dd>
            <dt>Quartier</dt>
            <dd><?= e($property['district'] ?: '-') ?></dd>
            <dt>Adresse</dt>
            <dd><?= e($property['address'] ?: '-') ?></dd>
            <dt>Prix par nuit</dt>
            <dd><?= number_format((float) $property['price_per_night'], 2, ',', ' ') ?></dd>
            <dt>Chambres</dt>
            <dd><?= (int) $property['bedrooms'] ?></dd>
            <dt>Salles de bain</dt>
            <dd><?= (int) $property['bathrooms'] ?></dd>
            <dt>Capacite</dt>
            <dd><?= (int) $property['max_guests'] ?> personne(s)</dd>
        </dl>
        <p><?= nl2br(e($property['description'] ?: 'Aucune description.')) ?></p>
    </article>

    <article class="detail-panel">
        <h2>Photos</h2>
        <div class="photo-grid">
            <?php foreach ($photos as $photo): ?>
                <figure>
                    <img src="<?= url('/' . $photo['photo_path']) ?>" alt="Photo du bien">
                    <?php if (Auth::can('properties.edit')): ?>
                        <form method="post" action="<?= url('/properties/photo/delete') ?>" onsubmit="return confirm('Supprimer cette photo ?');">
                            <input type="hidden" name="_token" value="<?= csrf_token() ?>">
                            <input type="hidden" name="id" value="<?= (int) $photo['id'] ?>">
                            <button class="link-danger" type="submit">Supprimer</button>
                        </form>
                    <?php endif; ?>
                </figure>
            <?php endforeach; ?>
            <?php if (empty($photos)): ?>
                <p class="muted">Aucune photo ajoutee.</p>
            <?php endif; ?>
        </div>
    </article>
</section>

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