<?php
include "header.php";
include "sidebar.php";
?>
<?php
            error_reporting(0);
            if (!empty($_GET['notif'])) {
              if ($_GET['notif'] == 1) {
                echo '
                  <script>
                    Swal.fire({
                      icon: "success",
                      title: "Sukses",
                      text: "",
                      showConfirmButton: false,
                      timer: 2000
                    });
                  </script>
                ';
              }
            }
			?>
            <div class="main-panel">
    <div class="content">
        <div class="panel-header bg-primary-gradient">
            <div class="page-inner py-1">
                <div class="d-flex align-items-left align-items-md-center flex-column flex-md-row">
                    <div>
                        <h2 class="text-white pb-2 fw-bold">Permintaan KYC</h2>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <!-- Invoice List Table -->
                <div class="card-body">
                    <div class="table-responsive">
                        <label for="searchInput">Search:</label>
                        <input type="text" id="searchInput" class="form-control" placeholder="Type to search">
                        <script>
                            $(document).ready(function () {
                                var table = $('#basic-datatables').DataTable();

                                $('#searchInput').on('keyup', function () {
                                    table.search(this.value).draw();
                                });
                            });
                        </script>

                        <table id="basic-datatables" class="display table table-striped table-hover">
                            <thead>
                        <tr class="bg-info">
                            <th class="text-center" style="vertical-align: middle;">#</th>
                            
                            <th class="text-center" style="vertical-align: middle;">Date</th>
                            <th class="text-center" style="vertical-align: middle;">Username</th>
                            <th class="text-center" style="vertical-align: middle;">Data</th>
                            <th class="text-center" style="vertical-align: middle;">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $sql = "
                            SELECT k.*, u.status_kyc 
                            FROM tb_kyc k 
                            JOIN tb_user u ON k.name = u.full_name 
                            WHERE k.terms = 1 AND u.status_kyc = 0 
                            ORDER BY k.id DESC
                        ";
                        
                        $sql_1 = mysqli_query($conn, $sql) or die(mysqli_error($conn));
                        $no = 0;
                        
                        
                        if (mysqli_num_rows($sql_1) == 0) {
                          echo "<tr><td colspan='5' class='text-center'>Tidak ada data untuk ditampilkan.</td></tr>";
                      } else {
                          while ($s1 = mysqli_fetch_array($sql_1)) {
                              
                            $no++;
                            // Ambil kolom yang diperlukan
                            $IDuser = $s1['name'];
                                
                        ?>
                        <tr>
                            <td class="text-center" style="vertical-align: middle; font-size: 14px;"><?php echo $no; ?>
                            </td>
                            
                            <td class="text-center"
                                style="vertical-align: middle; white-space: normal; font-size: 14px;">
                                <?php echo date('Y-m-d', strtotime($s1['created_at'])); ?><br><?php echo date('H:i:s', strtotime($s1['created_at'])); ?>
                            </td>
                            
                            <td class="text-right"
                                style="vertical-align: middle; white-space: normal; font-size: 14px; text-align: right;">
                                <?php echo $s1['name']; ?></td>
                            <td class="text-center" style="vertical-align: middle; white-space: normal; font-size: 14px;">
                            <a href="/uploads/<?= $s1['user_identification'];?>"
                            class="btn btn-primary btn-sm">Lihat</a>
                            </td>
                            <td class="text-center"
                                style="vertical-align: middle; white-space: nowrap; font-size: 14px;">
                                <a href="/office/tools/proses_kyc.php?cuid=<?php echo $s1['name']; ?>"
                                    class="btn btn-primary btn-sm">Terima</a>
                                
                            </td>
                        </tr>
                        <?php 
                      }} ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        const searchInput = document.getElementById('search');
        const dataTable = document.getElementById('default-datatable');
        const tableBody = dataTable.getElementsByTagName('tbody')[0];
        const rows = tableBody.getElementsByTagName('tr');

        searchInput.addEventListener('input', function () {
            const searchText = searchInput.value.toLowerCase();

            for (let i = 0; i < rows.length; i++) {
                const rowData = rows[i].textContent.toLowerCase();

                if (rowData.includes(searchText)) {
                    rows[i].style.display = '';
                } else {
                    rows[i].style.display = 'none';
                }
            }
        });
    });
</script>


    <?php include "footer.php";?>