<?php
// Dapatkan semua folder dalam folder pemenang (urutan terbaru)
$folders = array_filter(glob(__DIR__ . '/pemenang/*'), 'is_dir');
usort($folders, function($a, $b) {
    return filemtime($b) - filemtime($a);  // Urutkan folder berdasarkan tanggal terbaru
});

// Ambil folder terbaru
$latest_folder = isset($folders[0]) ? basename($folders[0]) : '';  // Folder terbaru

// Tentukan path file winners.txt berdasarkan folder terbaru
$file_path = __DIR__ . "/pemenang/$latest_folder/winners.txt";

// Cek apakah file ada dan dapat dibaca
if (file_exists($file_path)) {
    $winners = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
} else {
    $winners = []; // Jika file tidak ada, tampilkan array kosong
    echo "<p style='color: red;'>File $file_path tidak ditemukan atau kosong!</p>";
}
?>

<!DOCTYPE html>
<html lang="id">
<head>
<link rel="icon" href="/event/favicon.ico" sizes="any">
<link rel="icon" type="image/png" sizes="32x32" href="/event/assets/favicon-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/event/assets/favicon-16.png">
<link rel="apple-touch-icon" sizes="180x180" href="/event/assets/apple-touch-icon.png">

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Rewards Harian | Hadiahkamu</title>
  <meta name="description" content="Cek apakah kamu termasuk 100 member terpilih yang mendapatkan Voucher Gratis Hari ini! Klaim sekarang sebelum kehabisan.">
  <style>
    body {
      font-family: 'Poppins', sans-serif;
      background-color: #333;
      color: #fff;
      margin: 0;
      padding: 0;
    }

    .promo-container {
      max-width: 1200px;
      margin: 20px auto;
      padding: 30px;
      background: linear-gradient(to right, #ff0000, #ff6347);
      border-radius: 12px;
      box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    }

    h1, h2, h3 {
      text-align: center;
      font-weight: 700;
      color: #fff;
    }

    .cta-button {
      background-color: #ff0000;
      color: white;
      padding: 16px 40px;
      border: none;
      border-radius: 50px;
      font-size: 1.2rem;
      text-transform: uppercase;
      text-decoration: none;
      display: inline-block;
      margin: 20px auto;
      box-shadow: 0 6px 15px rgba(0,0,0,0.3);
      transition: 0.3s ease;
    }

    .cta-button:hover {
      background-color: #ff6347;
      transform: scale(1.05);
    }

    .button-container {
      display: flex;
      justify-content: center;
      gap: 25px;
      flex-wrap: wrap;
    }

    .winner-container {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
      gap: 15px;
      padding: 20px;
    }

    .winner-card {
      background-color: #fff;
      color: #ff0000;
      padding: 15px;
      border-radius: 10px;
      text-align: center;
      font-weight: bold;
      box-shadow: 0 4px 10px rgba(0,0,0,0.4);
      transition: 0.3s;
    }

    .winner-card:hover {
      background-color: #ff0000;
      color: #fff;
      transform: scale(1.05);
    }

    .share-buttons {
      display: flex;
      justify-content: center;
      gap: 20px;
      flex-wrap: wrap;
      margin-top: 20px;
    }

    .share-button {
      background-color: #ff0000;
      padding: 12px 25px;
      border-radius: 50px;
      color: white;
      text-transform: uppercase;
      font-size: 1rem;
      cursor: pointer;
      text-decoration: none;
      transition: background-color 0.3s ease;
    }

    .share-button:hover {
      background-color: #ff6347;
    }

    @media (max-width: 768px) {
      .cta-button {
        width: 100%;
      }

      .winner-container {
        grid-template-columns: repeat(3, 1fr); /* 3 kolom pada layar kecil */
      }
    }

    @media (max-width: 576px) {
      .cta-button {
        width: 100%;
        margin: 10px 0;
      }

      .share-buttons {
        flex-direction: column;
        gap: 15px;
      }

      .share-button {
        width: 100%;
        padding: 14px;
      }

      .button-container {
        display: flex;
        justify-content: center;
        width: 100%;
      }
    }
  </style>
</head>
<body>

<div class="promo-container">
  <img src="/images/rewards.webp" alt="Voucher Harian" style="width: 100%; border-radius: 12px;">
</div>

<div class="promo-container">
  <h1>Voucher Harian Rp 38.000</h1>
  <p style="text-align: center; font-size: 1.2rem;">Hanya untuk 100 member pilihan. Waktu Klaim Pukul 14.00 WIB - 23.00 WIB</p>
  <div class="button-container">
    <a href="https://cutt.ly/rrXEBcrX" class="cta-button">JOIN EVENT</a>
  </div>
</div>

<div class="promo-container" style="background-color: #002b5e;">
  <h3>Status Promo: <span style="color:#00ff99;">Masih Tersedia</span></h3>
  <p style="text-align:center;">Sedang Di Proses Pemenang >> <?= date('d M Y') ?></p>
</div>

<div class="promo-container">
  <h2>100 Member Terpilih</h2>
  <div class="winner-container">
    <?php foreach ($winners as $name): ?>
      <div class="winner-card">***<?= substr(htmlspecialchars($name), 0, 4) ?>***</div>
    <?php endforeach; ?>
  </div>
</div>

<!-- Share Buttons Section -->
<div class="promo-container">
  <h3 style="text-align: center;">Bagikan Promo Ini ke Temanmu!</h3>
  <div class="share-buttons">
    <a href="https://www.facebook.com/QQMILANPAGE" class="share-button" target="_blank">Facebook</a>
    <a href="https://api.whatsapp.com/" class="share-button" target="_blank">WhatsApp</a>
  </div>
</div>

</body>
</html>
