<?php
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/seo.php';

$slug = $_GET['slug'] ?? '';
$district = get_district_by_slug($slug);
if (!$district) { http_response_code(404); include __DIR__ . '/../404.php'; exit; }

$stmt = db()->prepare('SELECT * FROM properties WHERE district_id = ? ORDER BY is_featured DESC, created_at DESC');
$stmt->execute([$district['id']]);
$properties = $stmt->fetchAll();

$seo = [
    'title' => $district['name'] . ' Property & Investment Guide | ' . SITE_NAME,
    'description' => $district['summary'] . ' Browse verified listings and investment data for ' . $district['name'] . ', Kigali.',
    'path' => '/district/' . $district['slug'],
    'image' => rtrim(SITE_URL, '/') . '/' . $district['hero_image'],
];
$extraSchema = schema_breadcrumb([
    ['name' => 'Investment Locations', 'url' => '/investment-locations'],
    ['name' => $district['name'], 'url' => '/district/' . $district['slug']],
]);
include __DIR__ . '/../includes/header.php';
?>
<section class="hero" style="min-height:60vh;">
  <div class="hero-media"><img src="/<?= e($district['hero_image']) ?>" alt="<?= e($district['name']) ?> investment district in Kigali" fetchpriority="high"></div>
  <div class="container hero-content">
    <div class="eyebrow" style="color:var(--color-accent-light);">Investment Location</div>
    <h1><?= e($district['name']) ?></h1>
    <p class="lede"><?= e($district['summary']) ?></p>
    <div class="hero-stats">
      <div class="hero-stat"><div class="num"><?= count($properties) ?></div><div class="label">Active Listings</div></div>
      <div class="hero-stat"><div class="num" style="font-size:var(--fs-lg);"><?= e($district['avg_price_indicator']) ?></div><div class="label">Price Positioning</div></div>
      <div class="hero-stat"><div class="num" style="font-size:var(--fs-lg);"><?= e($district['growth_indicator']) ?></div><div class="label">Growth Outlook</div></div>
    </div>
  </div>
</section>

<section class="section-pad">
  <div class="container">
    <?= breadcrumb_html([
        ['name' => 'Investment Locations', 'url' => '/investment-locations'],
        ['name' => $district['name'], 'url' => '/district/' . $district['slug']],
    ]) ?>
    <div class="grid grid-2" style="grid-template-columns:2fr 1fr;gap:var(--space-9);align-items:start;">
      <div class="article-body">
        <h2>About <?= e($district['name']) ?></h2>
        <p><?= e($district['description']) ?></p>
      </div>
      <div class="map-frame">
        <iframe src="https://maps.google.com/maps?q=<?= $district['lat'] ?>,<?= $district['lng'] ?>&z=13&output=embed" loading="lazy" title="<?= e($district['name']) ?> map"></iframe>
      </div>
    </div>
  </div>
</section>

<section class="section-pad-sm" style="background:var(--color-cream);">
  <div class="container">
    <div class="section-head" style="max-width:none;">
      <div class="eyebrow">Listings in <?= e($district['name']) ?></div>
      <h2>Available Properties</h2>
    </div>
    <?php if (empty($properties)): ?>
      <div class="form-card text-center">
        <h3>No active listings in <?= e($district['name']) ?> right now</h3>
        <p class="text-muted">New opportunities in this district are added regularly.</p>
        <a href="/vip-alerts" class="btn btn-accent mt-4">Get Notified First</a>
      </div>
    <?php else: ?>
      <div class="grid grid-3">
        <?php foreach ($properties as $p): ?>
          <?php include __DIR__ . '/../includes/partials/property-card.php'; ?>
        <?php endforeach; ?>
      </div>
    <?php endif; ?>
  </div>
</section>
<?php include __DIR__ . '/../includes/footer.php'; ?>
