<?php  
    function getResultByCode($code) {
    $cacheDir  = __DIR__ . '/cache/togel';
    $cacheFile = $cacheDir . "/cache_$code.txt";

    if (file_exists($cacheFile)) {
        return file_get_contents($cacheFile);
    }

    return '----';

  
    $url = "https://sengtulus.site/history/result-mobile/" . $code;  
  
    $ch = curl_init();  
    curl_setopt_array($ch, [  
        CURLOPT_URL => $url,  
        CURLOPT_RETURNTRANSFER => true,  
        CURLOPT_FOLLOWLOCATION => true,  
        CURLOPT_SSL_VERIFYPEER => false,  
        CURLOPT_USERAGENT => 'Mozilla/5.0',  
        CURLOPT_TIMEOUT => 5 // penting  
    ]);  
  
    $html = curl_exec($ch);  
    curl_close($ch);  
  
    $result = '----';  
  
    if ($html) {  
        if (preg_match('/<td[^>]*>\s*<a[^>]*>(\d{4})<\/a>\s*<\/td>/', $html, $match)) {  
            $result = $match[1];  
        } elseif (preg_match('/<td[^>]*>\s*(\d{4})\s*<\/td>/', $html, $match)) {  
            $result = $match[1];  
        }  
    }  
  
    file_put_contents($cacheFile, $result);  
    return $result;  
}  
  
function togelTheme($pasaran) {  
    $p = strtolower($pasaran);  
  
    if (strpos($p, 'bull') !== false) return 'theme-bull';  
    if (strpos($p, 'sydney') !== false) return 'theme-sydney';  
    if (strpos($p, 'singapore') !== false) return 'theme-singapore';  
    if (strpos($p, 'psco') !== false) return 'theme-pcso';  
    if (strpos($p, 'taiwan') !== false) return 'theme-taiwan';  
    if (strpos($p, 'hongkong') !== false) return 'theme-hongkong';  
    if (strpos($p, '4d-macau') !== false) return 'theme-macau';
    if (strpos($p, 'oregon') !== false) return 'theme-oregon';  
  
    return 'theme-singapore';  
}  
  
$togelList = [  
 [  
    'nama' => 'HONGKONG',  
    'kode' => 'p23530',  
    'logo' => '../../uploads/game_pic/provider/togel/hongkong.jpg'  
  ],  
  [  
    'nama' => '4D-MACAU',  
    'kode' => 'm17',  
    'logo' => '../../uploads/game_pic/provider/togel/totomacau.jpg'  
  ],  
  [  
    'nama' => 'SYDNEY',  
    'kode' => 'p23517',  
    'logo' => '../../uploads/game_pic/provider/togel/sydney.jpg'  
  ],  
  [  
    'nama' => 'SINGAPORE',  
    'kode' => 'p23521',  
    'logo' => '../../uploads/game_pic/provider/togel/singapore.jpg'  
  ],  
  [  
    'nama' => 'OREGON 4',  
    'kode' => 'p23514',  
    'logo' => '../../uploads/game_pic/provider/togel/oregon.jpg'  
  ],  
  [  
    'nama' => 'PSCO',  
    'kode' => 'p23526',  
    'logo' => '../../uploads/game_pic/provider/togel/psco.jpg'  
  ],  
  [  
    'nama' => 'BULLSEYE',  
    'kode' => 'p23516',  
    'logo' => '../../uploads/game_pic/provider/togel/bullseye.jpg'  
  ],  
  [  
    'nama' => 'TAIWAN',  
    'kode' => 'p23527',  
    'logo' => '../../uploads/game_pic/provider/togel/taiwan.jpg'  
  ],  
];  
$jadwalUndian= [  
  'HONGKONG' => '23:00',  
  '4D TOTO MACAU' => '23:07',  
  'SYDNEY' => '13:55',  
  'SINGAPORE' => '17:45',  
  'OREGON 4' => '04:00',  
  'PSCO' => '20:10',  
  'BULLSEYE' => '12:10',  
  'TAIWAN' => '20:45',  
];  
?>  
  
<?php  
foreach ($togelList as &$togel) {  
    if (isset($togel['kode'])) {  
        $togel['angka'] = getResultByCode($togel['kode']);  
    }  
}  
unset($togel);  
?>  
  
<section class="togel-section">  
  <div class="container">  
  
    <div class="togel-scroll">  
  
     <?php foreach ($togelList as $togel): ?>  
  
    <div class="togel-card <?= togelTheme($togel['nama']); ?>"  
         data-close="<?= $jadwalUndian[$togel['nama']] ?? '23:59'; ?>">  
            <div class="togel-top">  
              <span class="togel-title"><?= $togel['nama']; ?></span>  
              <img src="<?= $togel['logo']; ?>" class="togel-logo">  
            </div>  
      
      
            <div class="togel-number"><?= $togel['angka']; ?></div>  
            <div class="togel-timer">  
              <div><strong class="day">00</strong><span>Hari</span></div>  
              <div><strong class="hour">00</strong><span>Jam</span></div>  
              <div><strong class="minute">00</strong><span>Menit</span></div>  
              <div><strong class="second">00</strong><span>Detik</span></div>  
            </div>  
      
            <button class="togel-btn">Bet</button>  
          </div>  
      
          <?php endforeach; ?>  
      
        </div>  
      </div>  
    </section>  
      

  
 <style>  
/* ================= TOGEL SECTION ================= */  
.togel-section {  
  margin: 12px 0;  
}  
  
.togel-header {  
  display: flex;  
  justify-content: space-between;  
  align-items: center;  
  margin-bottom: 8px;  
}  
  
.togel-header h5 {  
  color: #fff;  
  font-size: 15px;  
}  
  
/* ================= SCROLL / GRID ================= */  
.container {  
  max-width: 420px;     /* lebar maksimal layout */  
  margin: 0 auto;       /* center ke tengah */  
  padding: 0 10px;  
}  
  
.togel-scroll {  
  display: grid;  
  grid-template-columns: repeat(2, 1fr);  
  gap: 10px;  
  justify-content: center; /* center grid */  
}  
  
/* sembunyikan scrollbar */  
.togel-scroll::-webkit-scrollbar {  
  width: 0;  
  height: 0;  
}  
  
  
/* ================= CARD BASE ================= */  
.togel-card {  
  width: 100%; /* penuh dalam grid */  
  padding: 14px;  
  border-radius: 8px;  
  color: #fff;  
  position: relative;  
  min-height: 150px;  
  
  box-shadow:  
    inset 0 1px 0 rgba(255,255,255,.08),  
    0 8px 18px rgba(0,0,0,.4);  
}  
/* grain overlay */  
.togel-card::after {  
  content: "";  
  position: absolute;  
  inset: 0;  
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");  
  pointer-events: none;  
}  
  
/* ================= COLOR VARIANT ================= */
/* ================= AUTO THEME PASARAN ================= */

/* Wuhan – red wine */
.togel-card.theme-wuhan {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #6a2b2b 0%, #2a1212 60%, #120707 100%);
}

/* HK – dark blue */
.togel-card.theme-macau {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #2c3f63 0%, #121e34 60%, #070c16 100%);
}

/* Bullseye – purple */
.togel-card.theme-bull {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #4e2f6a 0%, #241238 60%, #0f0716 100%);
}

/* Sydney – teal */
.togel-card.theme-sydney {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #2a5e5e 0%, #133535 60%, #071616 100%);
}

/* Singapore – gold brown */
.togel-card.theme-singapore {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #6a5330 0%, #3a2a16 60%, #161007 100%);
}


/* PCSO – dark red */
.togel-card.theme-pcso {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #6a2f2f 0%, #351515 60%, #160707 100%);
}

/* Taiwan – steel blue */
.togel-card.theme-taiwan {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #3a4f6a 0%, #1b273a 60%, #0a0f16 100%);
}

/* Hongkong – maroon */
.togel-card.theme-hongkong {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #5a2a2a 0%, #2a1414 60%, #120707 100%);
}

/* Macau P1–P6 – emerald variants */
.togel-card.theme-macau-p1 {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .10), transparent 35%),
    linear-gradient(145deg, #3a4f6a 0%, #1b273a 60%, #0a0f16 100%);
}


/* Oregon – dark gray */
.togel-card.theme-oregon {
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, .08), transparent 35%),
    linear-gradient(145deg, #444 0%, #222 60%, #0f0f0f 100%);
}
/* ================= TOP ================= */  
.togel-top {  
  display: flex;  
  justify-content: space-between;  
  align-items: center;  
}  
  
.togel-title {  
  font-size: 11px;  
  letter-spacing: .5px;  
  opacity: .85;  
}  
  
.togel-logo {  
  width: 53px;  
  height: 53px;  
  border-radius: 50%;  
  background: rgba(255,255,255,.9);  
  padding: 2px;  
}  
  
/* ================= NUMBER ================= */  
.togel-number {  
  font-size: 24px;  
  font-weight: 700;  
  margin: 8px 0;  
  letter-spacing: 1px;  
}  
  
.togel-number::after {  
  content: "";  
  display: block;  
  height: 1px;  
  margin-top: 6px;  
  background: linear-gradient(to right, transparent, rgba(255,255,255,.2), transparent);  
}  
  
/* ================= TIMER ================= */  
.togel-timer {  
  display: flex;  
  gap: 5px;  
  margin-top: 6px;  
}  
  
.togel-timer div {  
  background: rgba(0,0,0,.35);  
  border-radius: 6px;  
  padding: 4px 5px;  
  min-width: 36px;  
  text-align: center;  
  font-size: 9px;  
}  
  
.togel-timer strong {  
  display: block;  
  font-size: 12px;  
  font-weight: 600;  
}  
  
/* ================= BUTTON ================= */  
.togel-btn {  
  width: 100%;  
  margin-top: 35px;  
  padding: 7px;  
  border-radius: 6px;  
  background: linear-gradient(  
    to bottom,  
    rgba(255,255,255,.18),  
    rgba(255,255,255,.08)  
  );  
  color: #fff;  
  border: none;  
  font-size: 12px;  
  font-weight: 600;  
  cursor: pointer;  
  transition: all .2s ease;  
}  
  
.togel-btn:hover {  
  background: linear-gradient(  
    to bottom,  
    rgba(255,255,255,.28),  
    rgba(255,255,255,.12)  
  );  
}  
</style>