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

$seo = [
    'title' => SITE_NAME . ' | Luxury Real Estate & Investment Properties in Kigali, Rwanda',
    'description' => 'Discover Rwanda\'s most exclusive villas, apartments, land and investment properties. Buy, sell, rent and invest in Kigali with Kigali Yacu Properties.',
    'path' => '/',
];
$extraSchema = schema_local_business();

$featured = db()->query('SELECT * FROM properties WHERE is_featured = 1 ORDER BY created_at DESC LIMIT 6')->fetchAll();
$categories = array_slice(get_categories(), 0, 8);
$districts = array_slice(get_districts(), 0, 4);
$testimonials = get_testimonials(3);
$latestPosts = db()->query("SELECT * FROM blog_posts WHERE type='article' ORDER BY published_at DESC LIMIT 3")->fetchAll();
$homeHero = brand_asset('hero-villa-complex') ?: brand_asset('hero-estate-aerial') ?: 'assets/images/hero/home-hero-1.jpg';

include __DIR__ . '/includes/header.php';
?>

<section class="hero">
  <div class="hero-media">
    <img src="/<?= e($homeHero) ?>" alt="Luxury modern villa complex with pools in Kigali, Rwanda" fetchpriority="high">
  </div>
  <div class="container hero-content">
    <div class="eyebrow" style="color:var(--color-accent-light);"><?= e(t('home.eyebrow')) ?></div>
    <h1><?= e(t('home.h1')) ?></h1>
    <p class="lede"><?= e(t('home.lede')) ?></p>
    <div class="hero-cta-row">
      <a href="/properties" class="btn btn-accent btn-lg"><?= e(t('cta.explore_listings')) ?> <?= icon('arrow-right', 16) ?></a>
      <a href="/new-development" class="btn btn-outline-light btn-lg"><?= e(t('cta.explore_new_developments')) ?></a>
      <a href="/valuation" class="btn btn-outline-light btn-lg"><?= e(t('cta.request_valuation')) ?></a>
    </div>

    <div class="search-panel reveal">
      <div class="search-tabs">
        <span class="search-tab active" data-status="sale">Buy</span>
        <span class="search-tab" data-status="rent">Rent</span>
      </div>
      <form action="/properties" method="get" data-search-suggest-wrap>
        <input type="hidden" name="status" value="sale">
        <div class="field">
          <label for="q">Keyword</label>
          <input type="text" id="q" name="q" placeholder="Villa, land, district…" data-search-suggest>
        </div>
        <div class="field">
          <label for="district">District</label>
          <select id="district" name="district">
            <option value="">All Districts</option>
            <?php foreach (get_districts() as $d): ?>
              <option value="<?= e($d['slug']) ?>"><?= e($d['name']) ?></option>
            <?php endforeach; ?>
          </select>
        </div>
        <div class="field">
          <label for="type">Property Type</label>
          <select id="type" name="type">
            <option value="">All Types</option>
            <?php foreach (get_categories() as $c): ?>
              <option value="<?= e($c['slug']) ?>"><?= e($c['name']) ?></option>
            <?php endforeach; ?>
          </select>
        </div>
        <div class="field">
          <label for="max_price">Max Price (RWF)</label>
          <input type="number" id="max_price" name="max_price" placeholder="Any price">
        </div>
        <button type="submit" class="btn btn-primary"><?= icon('search', 16) ?> Search</button>
      </form>
    </div>

    <div class="hero-stats reveal">
      <?php for ($i = 1; $i <= 4; $i++): ?>
        <div class="hero-stat"><div class="num" data-counter="<?= e(site_content("home.stat{$i}_number", '0')) ?>" data-suffix="<?= e(site_content("home.stat{$i}_suffix", '')) ?>">0</div><div class="label"><?= e(site_content("home.stat{$i}_label", '')) ?></div></div>
      <?php endfor; ?>
    </div>
  </div>
</section>

<section class="section-pad">
  <div class="container">
    <div class="section-head center reveal">
      <div class="eyebrow" style="justify-content:center;"><?= e(site_content('home.featured_eyebrow', 'Featured Listings')) ?></div>
      <h2><?= e(site_content('home.featured_heading', 'Handpicked Properties This Month')) ?></h2>
      <p><?= e(site_content('home.featured_subheading', '')) ?></p>
    </div>
    <div class="grid grid-3">
      <?php foreach ($featured as $i => $p): ?>
        <div class="reveal" data-delay="<?= $i % 3 + 1 ?>"><?php include __DIR__ . '/includes/partials/property-card.php'; ?></div>
      <?php endforeach; ?>
    </div>
    <div class="text-center mt-8">
      <a href="/properties" class="btn btn-outline">View All Properties</a>
    </div>
  </div>
</section>

<section class="section-pad" style="background:var(--color-cream);">
  <div class="container">
    <div class="section-head center reveal">
      <div class="eyebrow" style="justify-content:center;"><?= e(site_content('home.category_eyebrow', 'Browse by Category')) ?></div>
      <h2><?= e(site_content('home.category_heading', 'Find the Right Property Type')) ?></h2>
      <p><?= e(site_content('home.category_subheading', '')) ?></p>
    </div>
    <div class="grid" style="grid-template-columns:repeat(4,1fr);">
      <?php foreach ($categories as $c): ?>
        <?php include __DIR__ . '/includes/partials/category-card.php'; ?>
      <?php endforeach; ?>
    </div>
  </div>
</section>

<section class="section-pad">
  <div class="container">
    <div class="section-head reveal" style="display:flex;justify-content:space-between;align-items:flex-end;flex-wrap:wrap;gap:var(--space-4);max-width:none;">
      <div>
        <div class="eyebrow"><?= e(site_content('home.locations_eyebrow', 'Investment Locations')) ?></div>
        <h2 style="margin-bottom:0;"><?= e(site_content('home.locations_heading', 'Where Kigali is Growing')) ?></h2>
      </div>
      <a href="/investment-locations" class="btn btn-outline">All Locations</a>
    </div>
    <div class="grid grid-4">
      <?php foreach ($districts as $i => $d): ?>
        <div class="reveal" data-delay="<?= $i + 1 ?>"><?php include __DIR__ . '/includes/partials/district-card.php'; ?></div>
      <?php endforeach; ?>
    </div>
  </div>
</section>

<section class="section-pad theme-dark" style="background:var(--color-black);color:var(--color-white);">
  <div class="container">
    <div class="section-head center reveal">
      <div class="eyebrow" style="justify-content:center;color:var(--color-accent-light);"><?= e(site_content('home.why_eyebrow', 'Why Kigali Yacu')) ?></div>
      <h2 style="color:#fff;"><?= e(site_content('home.why_heading', 'Built on Trust, Backed by Data')) ?></h2>
      <p style="color:var(--color-fog);"><?= e(site_content('home.why_subheading', '')) ?></p>
    </div>
    <div class="grid grid-4">
      <?php foreach (content_blocks('home', 'why_choose_us') as $i => $item): ?>
        <div class="reveal" data-delay="<?= $i + 1 ?>" style="text-align:center;">
          <div class="icon-wrap" style="width:64px;height:64px;border-radius:999px;background:rgba(200,16,46,0.10);display:flex;align-items:center;justify-content:center;color:var(--color-accent-light);margin:0 auto var(--space-4);"><?= icon($item['icon'], 28) ?></div>
          <h3 style="color:#fff;font-size:var(--fs-md);"><?= e($item['title']) ?></h3>
          <p style="color:var(--color-fog);font-size:var(--fs-sm);"><?= e($item['description']) ?></p>
        </div>
      <?php endforeach; ?>
    </div>
  </div>
</section>

<section class="section-pad" style="background:var(--color-cream);">
  <div class="container">
    <div class="section-head center reveal">
      <div class="eyebrow" style="justify-content:center;"><?= e(site_content('home.testimonials_eyebrow', 'Client Stories')) ?></div>
      <h2><?= e(site_content('home.testimonials_heading', 'Trusted by Buyers Across the Globe')) ?></h2>
    </div>
    <div class="grid grid-3">
      <?php foreach ($testimonials as $i => $t): ?>
        <div class="testimonial-card reveal" data-delay="<?= $i + 1 ?>">
          <div class="stars"><?php for ($s = 0; $s < (int)$t['rating']; $s++) echo '★'; ?></div>
          <p class="quote">"<?= e($t['quote']) ?>"</p>
          <div class="person">
            <?= avatar_html($t['name'], 'sm', $t['photo']) ?>
            <div>
              <div class="name"><?= e($t['name']) ?></div>
              <div class="role"><?= e($t['role']) ?></div>
            </div>
          </div>
        </div>
      <?php endforeach; ?>
    </div>
  </div>
</section>

<section class="section-pad">
  <div class="container">
    <div class="section-head reveal" style="display:flex;justify-content:space-between;align-items:flex-end;flex-wrap:wrap;gap:var(--space-4);max-width:none;">
      <div>
        <div class="eyebrow"><?= e(site_content('home.blog_eyebrow', 'Market Insights')) ?></div>
        <h2 style="margin-bottom:0;"><?= e(site_content('home.blog_heading', 'Latest From Our Journal')) ?></h2>
      </div>
      <a href="/blog" class="btn btn-outline">Visit the Blog</a>
    </div>
    <div class="grid grid-3">
      <?php foreach ($latestPosts as $i => $post): ?>
        <a href="/blog/<?= e($post['slug']) ?>" class="post-card reveal" data-delay="<?= $i + 1 ?>">
          <div class="media-frame rounded-lg"><img src="/<?= e($post['cover_image']) ?>" alt="<?= e($post['title']) ?>" loading="lazy" width="400" height="250"></div>
          <div class="body">
            <div class="meta"><span><?= e($post['category']) ?></span><span><?= time_ago_or_date($post['published_at']) ?></span></div>
            <h3><?= e($post['title']) ?></h3>
            <p class="excerpt"><?= e($post['excerpt']) ?></p>
          </div>
        </a>
      <?php endforeach; ?>
    </div>
  </div>
</section>

<section class="section-pad-sm">
  <div class="container">
    <div class="cta-band reveal">
      <div class="eyebrow" style="justify-content:center;color:var(--color-accent-light);"><?= e(site_content('home.cta_eyebrow', 'Ready When You Are')) ?></div>
      <h2><?= e(site_content('home.cta_heading', 'Have a Property to Sell or Rent Out?')) ?></h2>
      <p style="color:var(--color-fog);max-width:52ch;margin-inline:auto;"><?= e(site_content('home.cta_text', '')) ?></p>
      <div class="actions">
        <a href="/valuation" class="btn btn-accent">Request a Free Valuation</a>
        <a href="/list-your-property" class="btn btn-outline-light">List Your Property</a>
      </div>
    </div>
  </div>
</section>

<?php include __DIR__ . '/includes/footer.php'; ?>
