<?php

    if($_SESSION['user'] && $_SESSION['user']['connected']){

            ?>
<div class="container-fluid py-4">

  <!-- Page header -->
  <div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="fw-bold mb-0">🏢 My Properties</h4>
    <a href="index.php?p=property_add" class="btn btn-primary btn-sm">
      + Add Property
    </a>
  </div>

  <?php if (empty($_SESSION['myproperties'])): ?>
    <div class="alert alert-info text-center">
      You have no properties yet.<br>
      Click <strong>Add Property</strong> to get started.
    </div>
  <?php else: ?>

    <div class="row g-3">
      <?php foreach ($_SESSION['myproperties'] as $property): ?>

        <div class="col-12 col-md-6 col-lg-4">
          <div class="card shadow-sm h-100">

            <div class="card-body">
              <h5 class="card-title fw-semibold mb-1">
                <?= htmlspecialchars($property['name']) ?>
              </h5>

              <p class="text-muted small mb-2">
                📍 <?= htmlspecialchars($property['location']) ?>
              </p>

              <div class="small mb-3">
                🏠 Apartments: <?= (int)$property['apartments_count'] ?><br>
                🛏️ Bed Spaces: <?= (int)$property['bedspaces_count'] ?>
              </div>

              <div class="d-flex gap-2">
                <a href="index.php?p=property_view&ref=<?= $property['ref'] ?>"
                   class="btn btn-outline-primary btn-sm w-100">
                  Manage
                </a>

                <a href="index.php?p=apartment_add&property_ref=<?= $property['ref'] ?>"
                   class="btn btn-outline-success btn-sm w-100">
                  + Apartment
                </a>
              </div>
            </div>

          </div>
        </div>

      <?php endforeach; ?>
    </div>

  <?php endif; ?>

</div>
<?php
    }
    ?>
   