<div class="row g-2 justify-content-center">

    <?php
    //     include '../../webgets.php';
    //     $page = file_get_html('https://178.128.51.10/database/papatogel/image/pasarantogel/');
    //     $findimgtogel = $page->find('a');
    // echo '<div class="row">';
    //     foreach($findimgtogel as $togelimg) {
    //         $findsrc = $togelimg->href;
    //         $gamename = trim(str_replace('.webp', '', $findsrc));
    //         if(strpos($findsrc, '.webp') !== false) {

    //             echo '<div class="col-lg-4 mb-2">
    //                     <div class="card-game rounded">
    //                         <img src="https://178.128.51.10/database/papatogel/image/pasarantogel/'.$findsrc.'" class="rounded img-fluid d-block mx-auto" />
    //                         <h6 style="font-size: 0.8rem;" class="bg-warning bg-gradient my-1 rounded d-block mx-auto text-center text-dark fw-bold p-2 text-uppercase"><i class="fas fa-info-circle"></i> Livedraw '.$gamename.'</h6>
    //                         <h6 style="font-size: 0.8rem;" class="bg-warning bg-gradient my-1 rounded d-block mx-auto text-center text-dark fw-bold p-2 text-uppercase"><i class="fas fa-info-circle"></i> Prediksi '.$gamename.'</h6>
    //                         <h6 style="font-size: 0.8rem;" class="bg-warning bg-gradient my-1 rounded d-block mx-auto text-center text-dark fw-bold p-2 text-uppercase"><i class="fas fa-clock"></i> Result '.$gamename.'</h6>
    //                     </div>
    //             </div>';
    //         }
    //     }
    // echo '</div>';

    include '../../data.php';

    function timeindo($jamnya)
    {
        $hari = date("l", strtotime($jamnya));

        switch ($hari) {
            case 'Monday':
                return 'Senin';
                break;

            case 'Tuesday':
                return 'Selasa';
                break;

            case 'Wednesday':
                return 'Rabu';
                break;

            case 'Thursday':
                return 'Kamis';
                break;

            case 'Friday':
                return 'Jumat';
                break;

            case 'Saturday':
                return 'Sabtu';
                break;

            case 'Sunday':
                return 'Minggu';
                break;
        }
    }

    $sgames = "SELECT rl.res_pasaran, rl.res_angka, rl.res_jam, p.gambar_pasaran FROM ( SELECT res_pasaran, MAX(res_jam) AS res_jam FROM result_lotto WHERE res_angka != 'xxxx' AND res_angka != '' GROUP BY res_pasaran ) AS latest JOIN result_lotto rl ON latest.res_pasaran = rl.res_pasaran AND latest.res_jam = rl.res_jam JOIN pasaran_web p ON rl.res_pasaran = p.nama_pasaranweb ORDER BY rl.res_jam DESC";
    $qgames = mysqli_query($data, $sgames);

    if (mysqli_num_rows($qgames) > 0) {

        while ($fgames = mysqli_fetch_assoc($qgames)) {
            $pasaran = $fgames['res_pasaran'];
            $pangka = $fgames['res_angka'];
            $resjam = $fgames['res_jam'];
            $gambar = empty($fgames['gambar_pasaran']) ? 'images/icon-market/' . $pasaran . '.webp' : $fgames['gambar_pasaran'];

            // echo '<!-- Mobile -->
            // <div class="col-lg-12 d-md-none mb-3">
            // <div style="background: linear-gradient(rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.6)), url(\'images/icon-market/'.$pasaran.'.webp\')  center center no-repeat; background-size: cover;" class="card-game position-relative border-game rounded">
            //     <span data-bs-toggle="modal" data-bs-target="#infopas'.$pasaran.'" class="info-market"><i class="fas fa-info-circle"></i></span>
            //         <h4 class="text-center text-uppercase fw-bold">'.$pasaran.'</h4>
            //         <div class="res-pasaran">

            //                     <h3 class="my-2 rounded">'.$pangka.'</h3>
            //                     <p>Result : '.timeindo($resjam).', '.date("d-m-Y", strtotime($resjam)).'</p>
            //                 </div>
            //         <div class="d-flex justify-content-between">
            //                 <button onclick="openLivedraw(\''.$pasaran.'\')" type="button" class="btn-small border-0"><i class="fas fa-info-circle"></i> Livedraw</button>
            //                 <a href="?page=prediksi-mobile&pre='.$pasaran.'" class="btn-small"><i class="fas fa-list"></i> Prediksi</a>
            //                 <a href="?page=data-keluaran-togel&pasar='.$pasaran.'" class="btn-small"><i class="fas fa-eye"></i> keluaran</a>
            //         </div>
            //         </div>
            // </div>
            //      <!-- /Mobile -->

            echo '<div class="col-lg-3 mb-1">
                    <div class="card-game position-relative">
                        <span data-bs-toggle="modal" data-bs-target="#infopas' . $pasaran . '" class="info-market"><i class="fas fa-info-circle"></i></span>
                        <img src="' . $gambar . '" width="160px" height="160px" class="animate__animated animate__tada rounded img-fluid d-block mx-auto" />

                            <div class="res-pasaran">
                            <p class="text-uppercase text-pasar">' . $pasaran . '</p>

                                <div class="bg-angka rounded">
                                    <h3 class="my-2">' . $pangka . '</h3>
                                </div>
                                <p class="">Result : ' . timeindo($resjam) . ', ' . date("d-m-Y", strtotime($resjam)) . '</p>
                            </div>

                        <h6 onclick="openLivedraw(\'' . $pasaran . '\')" style="font-size: 0.8rem; cursor: pointer;" class="bg-warning bg-gradient my-1 rounded d-block mx-auto text-center text-dark fw-bold p-2 text-uppercase"><i class="fas fa-info-circle"></i> Livedraw ' . $pasaran . '</h6>
                        <a href="?page=prediksi-togel&pasaran=' . $pasaran . '"><h6 style="font-size: 0.8rem;" class="bg-warning bg-gradient my-1 rounded d-block mx-auto text-center text-dark fw-bold p-2 text-uppercase"><i class="fas fa-info-circle"></i> Prediksi ' . $pasaran . '</h6></a>
                        <a href="?page=data-keluaran-togel&pasar=' . $pasaran . '"><h6 style="font-size: 0.8rem;" class="bg-warning bg-gradient my-1 rounded d-block mx-auto text-center text-dark fw-bold p-2 text-uppercase"><i class="fas fa-clock"></i> Result ' . $pasaran . '</h6></a>
                    </div>
            </div>';

            $ginfopas = "SELECT * FROM pasaran_web WHERE nama_pasaranweb = '$pasaran'";
            $qinfopas = mysqli_query($data, $ginfopas);

            if (mysqli_num_rows($qinfopas) > 0) {
                $finfo = mysqli_fetch_assoc($qinfopas);
                $namapas = $finfo['nama_pasaranweb'];
                $predtex = $finfo['prediksi_texts'];
                $jamtutup = $finfo['jam_tutuppas'];
                $jamundi = $finfo['jam_undipass'];
                $linkld = $finfo['link_livedraw'];

                echo '<!-- Popup info pasaran -->
                <div class="modal fade" id="infopas' . $namapas . '" tabindex="-1">
                  <div class="modal-dialog">
                    <div class="modal-content text-dark">
                      <div class="modal-header">
                        <h5 class="modal-title text-uppercase fw-bold">Info ' . $namapas . '</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                      </div>
                      <div class="modal-body">

                      <div class="row">
                            <div class="col-lg-4 mb-2">
                                <img src="images/icon-market/' . $namapas . '.webp" class="d-block mx-auto img-thumbnail" />
                            </div>

                            <div class="col-lg-8 mb-2 align-self-center">
                                    <table class="table table-bordered table-sm">
                                        <tbody>
                                            <tr>
                                                <td class="align-middle">
                                                    <h6 class="info-ttp">Tutup Pasaran:</h6>
                                                </td>
                                                <td class="align-middle">
                                                    <h6 class="info-ttp">' . $jamtutup . ' WIB</h6>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td class="align-middle">
                                                    <h6 class="info-ttp">Result Pasaran:</h6>
                                                </td>
                                                <td class="align-middle">
                                                    <h6 class="info-ttp">' . $jamundi . ' WIB</h6>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td class="align-middle" colspan="2">
                                                    <h6 class="info-ttp">Link Resmi : <a target="_blank" rel="nofollow" class="text-danger" href="' . $linkld . '"><i class="fas fa-eye"></i> KLIK DISINI</a></h6>
                                                </td>
                                            </tr>

                                        </tbody>
                                    </table>
                            </div>
                      </div>


                        ' . html_entity_decode($predtex) . '

                      </div>
                    </div>
                  </div>
                </div>';
            }
        }
    } else {
        echo '<div class="col-lg-12">
            <p>Pasaran Togel saat ini tidak tersedia!!</p>
        </div>';
    }

    ?>
</div>