<?php
$pageTitle = 'হোম';
$pageDesc = 'তজিয়া গ্রুপ — পালিয়ে বিয়ে করা কাপলদের ভাইরাল আর্কাইভ';
require_once 'header.php';
$db = getDB();

// Stats
$totalCouples = $db->query("SELECT COUNT(*) FROM couples WHERE status='approved'")->fetchColumn();
$totalPending = $db->query("SELECT COUNT(*) FROM couples WHERE status='pending'")->fetchColumn();
$totalVideos = $db->query("SELECT COUNT(*) FROM videos")->fetchColumn();
$totalViews = $db->query("SELECT COALESCE(SUM(views),0) FROM couples")->fetchColumn();

// Featured couples
$featured = $db->query("SELECT * FROM couples WHERE status='approved' AND is_featured=1 ORDER BY created_at DESC LIMIT 6")->fetchAll();

// Latest couples
$latest = $db->query("SELECT * FROM couples WHERE status='approved' ORDER BY created_at DESC LIMIT 6")->fetchAll();

// Trending (most viewed)
$trending = $db->query("SELECT * FROM couples WHERE status='approved' ORDER BY views DESC LIMIT 6")->fetchAll();
?>

<!-- Hero Section -->
<section class="hero">
  <div class="hero-content">
    <h1>💕 <span>তজিয়া গ্রুপ</span></h1>
    <div class="hero-slider">
      <div class="hero-slide active"><?= e(getSetting('hero_text_1', 'ভালোবাসা থামানো যায় না 😎')) ?></div>
      <div class="hero-slide"><?= e(getSetting('hero_text_2', 'পরিবার মানেনি, তজিয়া গ্রুপ মানছে ❤️')) ?></div>
      <div class="hero-slide"><?= e(getSetting('hero_text_3', 'পালিয়ে বিয়ে? ইতিহাসে নাম লিখান!')) ?></div>
    </div>
    <div style="display:flex;gap:12px;justify-content:center;flex-wrap:wrap;">
      <a href="submit.php" class="btn btn-primary"><i class="fas fa-plus-circle"></i> তথ্য জমা দিন</a>
      <a href="search.php" class="btn btn-outline"><i class="fas fa-search"></i> কাপল খুঁজুন</a>
    </div>
  </div>
</section>

<!-- Image Slider -->
<section class="img-slider-section">
  <div class="img-slider-track">
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide1.jpg" alt="কাপল ১"><div class="slide-caption">ভালোবাসায় বাধা নেই 💕</div></div>
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide2.jpg" alt="কাপল ২"><div class="slide-caption">একসাথে পালানোর গল্প 🏍️</div></div>
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide3.jpg" alt="কাপল ৩"><div class="slide-caption">প্রেম মানে না বাধা 😎</div></div>
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide4.jpg" alt="কাপল ৪"><div class="slide-caption">হ্যাপি এন্ডিং সবসময় 😍</div></div>
    <!-- Duplicates for infinite scroll -->
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide1.jpg" alt="কাপল ১"><div class="slide-caption">ভালোবাসায় বাধা নেই 💕</div></div>
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide2.jpg" alt="কাপল ২"><div class="slide-caption">একসাথে পালানোর গল্প 🏍️</div></div>
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide3.jpg" alt="কাপল ৩"><div class="slide-caption">প্রেম মানে না বাধা 😎</div></div>
    <div class="img-slider-slide"><img src="<?= SITE_URL ?>/assets/images/slide4.jpg" alt="কাপল ৪"><div class="slide-caption">হ্যাপি এন্ডিং সবসময় 😍</div></div>
  </div>
</section>

<!-- Stats -->
<section class="section">
  <div class="container">
    <div class="stats reveal">
      <div class="stat-card">
        <div class="stat-icon">💑</div>
        <div class="stat-num"><span class="counter" data-target="<?= $totalCouples ?>">০</span></div>
        <div class="stat-label">মোট কাপল</div>
      </div>
      <div class="stat-card">
        <div class="stat-icon">⏳</div>
        <div class="stat-num"><span class="counter" data-target="<?= $totalPending ?>">০</span></div>
        <div class="stat-label">অপেক্ষমাণ</div>
      </div>
      <div class="stat-card">
        <div class="stat-icon">🎬</div>
        <div class="stat-num"><span class="counter" data-target="<?= $totalVideos ?>">০</span></div>
        <div class="stat-label">মোট ভিডিও</div>
      </div>
      <div class="stat-card">
        <div class="stat-icon">👀</div>
        <div class="stat-num"><span class="counter" data-target="<?= $totalViews ?>">০</span></div>
        <div class="stat-label">মোট ভিউ</div>
      </div>
    </div>
  </div>
</section>

<?php if ($featured): ?>
<!-- Featured Couples -->
<section class="section">
  <div class="container">
    <h2 class="section-title reveal">⭐ ফিচার্ড কাপল</h2>
    <div class="card-grid">
      <?php foreach ($featured as $c): ?>
      <a href="couple.php?id=<?= $c['id'] ?>" class="couple-card reveal">
        <?php if ($c['photo']): ?>
          <img class="card-img" src="<?= UPLOAD_URL . e($c['photo']) ?>" alt="<?= e($c['boy_name']) ?> ❤ <?= e($c['girl_name']) ?>">
        <?php else: ?>
          <div class="card-img" style="background:var(--gradient);display:flex;align-items:center;justify-content:center;font-size:3rem;">💑</div>
        <?php endif; ?>
        <div class="card-body">
          <div class="card-title"><?= e($c['boy_name']) ?> ❤ <?= e($c['girl_name']) ?></div>
          <div class="card-meta">
            <?php if ($c['district']): ?><span><i class="fas fa-map-marker-alt"></i> <?= e($c['district']) ?></span><?php endif; ?>
            <?php if ($c['marriage_date']): ?><span><i class="fas fa-calendar"></i> <?= bnDate($c['marriage_date']) ?></span><?php endif; ?>
          </div>
          <?php if ($c['funny_title']): ?><span class="card-badge"><?= e($c['funny_title']) ?></span><?php endif; ?>
          <?php if ($c['short_story']): ?><p class="card-story"><?= e(truncate($c['short_story'], 80)) ?></p><?php endif; ?>
        </div>
      </a>
      <?php endforeach; ?>
    </div>
  </div>
</section>
<?php endif; ?>

<!-- Latest Couples -->
<section class="section">
  <div class="container">
    <h2 class="section-title reveal">🆕 সর্বশেষ কাপল</h2>
    <?php if ($latest): ?>
    <div class="card-grid">
      <?php foreach ($latest as $c): ?>
      <a href="couple.php?id=<?= $c['id'] ?>" class="couple-card reveal">
        <?php if ($c['photo']): ?>
          <img class="card-img" data-src="<?= UPLOAD_URL . e($c['photo']) ?>" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='220'%3E%3Crect fill='%231a1a2e' width='300' height='220'/%3E%3C/svg%3E" alt="<?= e($c['boy_name']) ?>">
        <?php else: ?>
          <div class="card-img" style="background:var(--gradient);display:flex;align-items:center;justify-content:center;font-size:3rem;">💑</div>
        <?php endif; ?>
        <div class="card-body">
          <div class="card-title"><?= e($c['boy_name']) ?> ❤ <?= e($c['girl_name']) ?></div>
          <div class="card-meta">
            <?php if ($c['district']): ?><span><i class="fas fa-map-marker-alt"></i> <?= e($c['district']) ?></span><?php endif; ?>
            <?php if ($c['marriage_date']): ?><span><i class="fas fa-calendar"></i> <?= bnDate($c['marriage_date']) ?></span><?php endif; ?>
            <span><i class="fas fa-eye"></i> <?= bnNum($c['views']) ?></span>
          </div>
          <?php if ($c['funny_title']): ?><span class="card-badge"><?= e($c['funny_title']) ?></span><?php endif; ?>
        </div>
      </a>
      <?php endforeach; ?>
    </div>
    <?php else: ?>
    <p style="text-align:center;color:var(--text-muted);">এখনো কোনো কাপল যোগ হয়নি। প্রথম হোন! 🎉</p>
    <?php endif; ?>
  </div>
</section>

<?php if ($trending): ?>
<!-- Trending -->
<section class="section">
  <div class="container">
    <h2 class="section-title reveal">🔥 ট্রেন্ডিং কাপল</h2>
    <div class="card-grid">
      <?php foreach ($trending as $c): ?>
      <a href="couple.php?id=<?= $c['id'] ?>" class="couple-card reveal">
        <?php if ($c['photo']): ?>
          <img class="card-img" data-src="<?= UPLOAD_URL . e($c['photo']) ?>" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='220'%3E%3Crect fill='%231a1a2e' width='300' height='220'/%3E%3C/svg%3E" alt="<?= e($c['boy_name']) ?>">
        <?php else: ?>
          <div class="card-img" style="background:var(--gradient);display:flex;align-items:center;justify-content:center;font-size:3rem;">💑</div>
        <?php endif; ?>
        <div class="card-body">
          <div class="card-title"><?= e($c['boy_name']) ?> ❤ <?= e($c['girl_name']) ?></div>
          <div class="card-meta">
            <?php if ($c['district']): ?><span><i class="fas fa-map-marker-alt"></i> <?= e($c['district']) ?></span><?php endif; ?>
            <span><i class="fas fa-eye"></i> <?= bnNum($c['views']) ?> ভিউ</span>
          </div>
          <?php if ($c['funny_title']): ?><span class="card-badge"><?= e($c['funny_title']) ?></span><?php endif; ?>
        </div>
      </a>
      <?php endforeach; ?>
    </div>
  </div>
</section>
<?php endif; ?>

<?php require_once 'footer.php'; ?>
