<?php
session_start();
if (!isset($_SESSION['username'])) { header("location:login"); exit; }
include 'master.php';
?>
        <div class="page-wrapper">
            <div class="page-content-wrapper">
                <div class="page-content">
                    <div class="page-breadcrumb d-none d-md-flex align-items-center mb-3">
                        <div class="breadcrumb-title pr-3">KYC</div>
                        <div class="pl-3">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb mb-0 p-0">
                                    <li class="breadcrumb-item"><a href="./">Dashboard</a></li>
                                    <li class="breadcrumb-item active" aria-current="page">KYC Submissions</li>
                                </ol>
                            </nav>
                        </div>
                    </div><br>

                    <?php if (!empty($_GET['updated'])): ?>
                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                        KYC status updated successfully.
                        <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
                    </div>
                    <?php endif; ?>

                    <div class="card">
                        <div class="card-body">
                            <div class="card-title"><h4 class="mb-0">KYC Submissions</h4></div>
                            <hr/>
                            <div class="table-responsive">
                                <table id="example" class="table table-striped table-bordered" style="width:100%">
                                    <thead>
                                        <tr>
                                            <th>S/N</th>
                                            <th>Name</th>
                                            <th>Email</th>
                                            <th>Document</th>
                                            <th>Status</th>
                                            <th>Date</th>
                                            <th class="text-center">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    $res = $conn->query("SELECT * FROM kyc_submissions ORDER BY id DESC");
                                    $i = 1;
                                    if (!$res || $res->num_rows == 0) {
                                        echo "<tr><td colspan='7' style='color:red;text-align:center;'>No KYC submissions yet</td></tr>";
                                    } else {
                                        foreach ($res as $row) {
                                            $sBadge = ['Pending'=>'warning','Approved'=>'success','Rejected'=>'danger'][$row['status']] ?? 'secondary';
                                    ?>
                                        <tr>
                                            <td><?php echo $i; ?></td>
                                            <td><?php echo htmlspecialchars($row['full_name']); ?></td>
                                            <td><?php echo htmlspecialchars($row['user_email']); ?></td>
                                            <td><?php echo htmlspecialchars($row['document_type']); ?></td>
                                            <td><span class="badge badge-<?php echo $sBadge; ?>"><?php echo htmlspecialchars($row['status']); ?></span></td>
                                            <td><?php echo $row['date_added']; ?></td>
                                            <td class="text-center">
                                                <a href="view-kyc?id=<?php echo $row['id']; ?>" class="btn btn-primary btn-sm">Review</a>
                                            </td>
                                        </tr>
                                    <?php $i++; } } ?>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th>S/N</th><th>Name</th><th>Email</th><th>Document</th><th>Status</th><th>Date</th><th class="text-center">Action</th>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="overlay toggle-btn-mobile"></div>
        <a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>

<script>
    $(document).ready(function () { $('#example').DataTable(); });
</script>
<?php include 'footer.php'; ?>
