<div class="row">
                    <div class="col-12">
                        <div class="card">
                        <div class="card-body">
                                
                            <div class="row">
                                    <div class="col-4">
                                    <div class="alert alert-primary my-2" role="alert">
                                                <?php
                                                    $copen = "SELECT COUNT(*) as totalbuka FROM kasus_keluhan WHERE status_kasus = '0'";
                                                    $qopen = mysqli_query($data, $copen);
                                                    $fopen = mysqli_fetch_assoc($qopen);
                                                        echo '<p>Laporan Kasus Pending : <strong>'.$fopen['totalbuka'].'</strong> </p>';

                                                    $cclose = "SELECT COUNT(*) as totalclose FROM kasus_keluhan WHERE status_kasus = '1'";
                                                    $qclose = mysqli_query($data, $cclose);
                                                    $fclose = mysqli_fetch_assoc($qclose);
                                                        echo '<p>Laporan Kasus Selesai : <strong>'.$fclose['totalclose'].'</strong> </p>';
                                                   ?>
                                            </div>
                                            
                                        <div class="bg-primary text-light p-3">
                                            <h5><i class="mdi mdi-incognito"></i> Keluhan Para Member</h5>
                                        </div>
                                            <div style="overflow-y: scroll; height: 400px;">
                                                <ul class="list-group">
                                                    <?php
                                                        $skasus = "SELECT * FROM kasus_keluhan WHERE status_kasus = '0' ORDER BY DATE(tgl_kasus) DESC";
                                                        $qkasus = mysqli_query($data, $skasus);

                                                        if(mysqli_num_rows($qkasus) > 0) {
                                                            $x = 0;
                                                            $y = 0;
                                                            while($fkasus = mysqli_fetch_assoc($qkasus)) {
                                                                $userk = $fkasus['user_keluhan'];
                                                                $judulk = $fkasus['judul_keluhan'];
                                                                $wa = $fkasus['wa_mem'];
                                                                $kodek = $fkasus['kode_kasus'];
                                                                $tglk = $fkasus['tgl_kasus'];

                                                                echo '<a class="text-dark" href="dashboard.php?hal=keluhan&kodekasus='.$kodek.'">
                                                                <li class="list-group-item '; 
                                                                        if(isset($_GET['kodekasus'])) {
                                                                            $ko = mysqli_real_escape_string($data, $_GET['kodekasus']);
                                                                            if($ko == $kodek) {
                                                                                echo 'bg-info text-light';
                                                                            }
                                                                        }
                                                                echo '">
                                                                        <small><i class="mdi mdi-timelapse"></i> '.date("l, d M Y H:i:s", strtotime($tglk)).'</small>
                                                                        <h6>User: '.$userk.' #' .$kodek.' <span id="kode'.$x++.'"></span></h6>
                                                                        <h6 class="text-danger"><i class="fas fa-info-circle"></i> Kasus : '.$judulk.'</h6>
                                                                        <h6 style="font-size: 0.8rem;"><i class="fab fa-whatsapp"></i> Wa Member: '.$wa.'</h6>
                                                                </li>
                                                                </a>
                                                                
                                                                <script>
                                                                setInterval(function() {
                                                                    $("#kode'.$y++.'").load("config/notifmsg.php?codekelu='.$kodek.'");
                                                                }, 1000);
                                                                </script>';
                                                            }

                                                        } else {
                                                            echo '<li class="list-group-item"><i class="fas fa-times"></i> Tidak ada Pending Keluhan</li>';
                                                        }
                                                    ?>
                                                    
                                                </ul>
                                            </div>

                                            <div class="bg-danger text-light p-3">
                                                <h5><i class="mdi mdi-incognito"></i> Laporan Keluhan ditutup</h5>
                                            </div>
                                            <div style="overflow-y: scroll; height: 800px;">
                                                <ul class="list-group">
                                                    <?php
                                                        $skasus1 = "SELECT * FROM kasus_keluhan WHERE status_kasus = '1' ORDER BY DATE(tgl_kasus) DESC";
                                                        $qkasus1 = mysqli_query($data, $skasus1);

                                                        if(mysqli_num_rows($qkasus1) > 0) {
                                                            while($fkasus1 = mysqli_fetch_assoc($qkasus1)) {
                                                                $userk1 = $fkasus1['user_keluhan'];
                                                                $judulk1 = $fkasus1['judul_keluhan'];
                                                                $wa1 = $fkasus1['wa_mem'];
                                                                $kodek1 = $fkasus1['kode_kasus'];
                                                                $tglk1 = $fkasus1['tgl_kasus'];

                                                                echo '<a class="text-dark" href="dashboard.php?hal=keluhan&kodekasus='.$kodek1.'">
                                                                <li class="list-group-item '; 
                                                                        if(isset($_GET['kodekasus'])) {
                                                                            $ko1 = mysqli_real_escape_string($data, $_GET['kodekasus']);
                                                                            if($ko1 == $kodek1) {
                                                                                echo 'bg-info text-light';
                                                                            }
                                                                        }
                                                                echo '">
                                                                        <small><i class="mdi mdi-timelapse"></i> '.date("l, d M Y H:i:s", strtotime($tglk1)).'</small>
                                                                        <h6>User: '.$userk1.' #' .$kodek1.'</h6>
                                                                        <h6 class="text-warning"><i class="fas fa-info-circle"></i> Kasus : '.$judulk1.'</h6>
                                                                        <h6 style="font-size: 0.8rem;"><i class="fab fa-whatsapp"></i> Wa Member: '.$wa1.'</h6>
                                                                </li>
                                                                </a>

                                                                ';
                                                            }

                                                        } else {
                                                            echo '<li class="list-group-item"><i class="fas fa-times"></i> Tidak ada Pending Keluhan</li>';
                                                        }
                                                    ?>
                                                    
                                                </ul>
                                            </div>

                                    </div>

                                    <div class="col-8">
                                            
                                            <?php
                                                if(isset($_GET['kodekasus'])) {
                                                    $kodeaktif = mysqli_real_escape_string($data, $_GET['kodekasus']);

                                                    echo '<div class="bg-primary text-light p-3">
                                                    <div class="d-flex justify-content-between">
                                                    <h5 class="text-capitalize"><i class="mdi mdi-incognito mr-2"></i>';
                                                        $sname = "SELECT * FROM kasus_keluhan WHERE kode_kasus = '$kodeaktif'";
                                                        $qname = mysqli_query($data, $sname);
                                                        $fname = mysqli_fetch_assoc($qname);
                                                        $kkasu = $fname['kode_kasus'];
                                                        $wa1 = preg_replace('/^0?/', '62', $fname['wa_mem']);

                                                        echo $fname['user_keluhan'] . " #" .$fname['kode_kasus']. '<a style="color: #fff;" target="_blank" href="http://wa.me/'.$wa1.'"><i class="fab fa-whatsapp"></i> +' . $wa1.'</a> <button onclick="copyText(\'http://wa.me/'.$wa1.'\')" class="btn btn-success btn-sm watext">Copy WA</button>';

                                                    echo '</h5> ';

                                                        $ska = "SELECT status_kasus FROM kasus_keluhan WHERE kode_kasus = '$kkasu'";
                                                        $qka = mysqli_query($data, $ska);
                                                        $fka = mysqli_fetch_assoc($qka);
                                                        $stka = $fka['status_kasus'];

                                                        if($stka == '0') {
                                                            echo '<form id="ttpkasus">
                                                            <input type="hidden" name="kodemo" value="'.$fname['kode_kasus'].'" />
                                                            <button class="btn btn-sm btn-light"><i class="fas fa-times"></i> Tutup Kasus</button>
                                                        </form>';
                                                        } else {
                                                            echo '<form id="bkakasus">
                                                            <input type="hidden" name="kodemo" value="'.$fname['kode_kasus'].'" />
                                                            <button class="btn btn-sm btn-light"><i class="fas fa-check"></i> Buka Kasus</button>
                                                        </form>';
                                                        }


                                                 echo ' </div>
                                                </div>
                                                    <div id="msg-show" style="overflow-y: scroll; height: 480px;" class="bg-light p-2"></div>

                                                    <div>
                                                    </div>
                                                    <div class="my-2">
                                                        <form id="inboxkeluhan">
                                                            <input type="hidden" name="kodeak" value="'.$kodeaktif.'" />
                                                            <div class="input-group">';
                                                                $saktif = "SELECT * FROM kasus_keluhan WHERE kode_kasus = '$kodeaktif' AND status_kasus != '1'";
                                                                $qaktif = mysqli_query($data, $saktif);

                                                                if(mysqli_num_rows($qaktif) > 0) {
                                                                    echo '<input type="text" id="inboxmsgs" class="form-control" name="chatbox" placeholder="Ketik Pesan.." />
                                                                    <button type="submit" class="btn btn-primary"><i class="fas fa-paper-plane"></i></button>';
                                                                } else {
                                                                    echo '<input type="text" id="inboxmsgs" class="form-control" name="chatbox" placeholder="Kasus Ditutup.." disabled/>
                                                                    <button disabled="disabled" class="btn btn-danger"><i class="fas fa-times-circle"></i></button>';
                                                                }
                                                           echo ' </div>
                                                        </form>
                                                    </div>

                                                    <script>
                                                    
                                                        $("#inboxkeluhan").on(\'submit\', function(d) {
                                                            d.preventDefault();
                                                            $.ajax({
                                                                type: \'post\',
                                                                url: \'config/sendkeluhan.php\',
                                                                data: $("#inboxkeluhan").serialize(),
                                                                success: function() {
                                                                    $(\'#inboxmsgs\').val("");
                                                                }
                                                            });
                                                        });


                                                        setInterval(function() {
                                                            $(\'#msg-show\').load("config/tampilkeluhan.php?kode='.$kodeaktif.'");
                                                        }, 1000);

                                                    </script>
                                                    
                                                    ';
                                                } else {
                                                    echo '<h6 class="text-uppercase text-center text-secondary"><i class="fa fa-times-circle"></i>  Tidak ada Keluhan Pesan Yang dipilih!!</h6>';
                                                }
                                            ?>
                                    </div>
                            </div>
                        
                                                
                    </div>
                </div>



</div>

<script>
    $("#ttpkasus").on('submit', function(d) {
        d.preventDefault();
        if(confirm("Yakin ingin tutup Kasus??")){
        $.ajax({
            type: 'post',
            url: 'config/update-kasuskeluhan.php',
            data: $("#ttpkasus").serialize(),
            success: function(kasusinfo) {
                alert(kasusinfo);
                location.reload();
            },
        });
        } else {
            alert("Batal Tutup kasus");
        }
    });

    <?php
        if(!isset($_SESSION['nama_pengguna'])) {
        echo 'window.location.replace("/");';
        }
    ?>


    $("#bkakasus").on('submit', function(o) {
        o.preventDefault();
        if(confirm("Yakin ingin buka Kasus??")){
        $.ajax({
            type: 'post',
            url: 'config/buka-kasus.php',
            data: $("#bkakasus").serialize(),
            success: function(bukainfo) {
                alert(bukainfo);
                location.reload();
            },
        });
        } else {
            alert("Batal Buka kasus");
        }
    });

//     function copyText(datawa) {
// document.execCommand('copy', false, datawa);
// }

async function copyText(datawa) {
  try {
    await navigator.clipboard.writeText(datawa);
    /* Resolved - text copied to clipboard successfully */
  } catch (err) {
    console.error('Failed to copy: ', err);
    /* Rejected - text failed to copy to the clipboard */
  }
}

</script>