<style>
    .fontsL {
        font-size: 10px;
        text-wrap: nowrap;
    }
</style>
<!-- <?php foreach ($driverslist as $j => $d) {
            echo "<pre>";
            print_r($d);
            echo "</pre>";
        ?>
<?php } ?> -->
<div class="row">
    <div class="col-md-7 my-2">
        <h3 class="fmon">Drivers</h3>
    </div>
    <div class="col-md-5 my-2">
        <div class="row">
            <div class="col-md-6">
                <a href="<?php echo base_url('drivers'); ?>" class="btn btnC w-100">New Drivers</a>
            </div>
            <div class="col-md-6">
                <a href="<?php echo base_url('drivers/approveddrivers'); ?>" class="btn btnC2 w-100">Approved
                    Drivers</a>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12 table-responsive">
        <table class="table table-striped" id="drivertable">
            <thead class="thead-dark">
                <tr>
                    <th scope="col">Name</th>
                    <th scope="col">Email</th>
                    <th scope="col">Phone</th>
                    <th scope="col">Driving License</th>
                    <th scope="col">Profile Image</th>
                    <th scope="col">Front Driving License</th>
                    <th scope="col">Back Driving License</th>
                    <th scope="col">Car Color</th>
                    <th scope="col">Make</th>
                    <th scope="col">Model</th>
                    <th scope="col">License Plate</th>
                    <th scope="col">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($driverslist as $j => $d) { ?>


                    <tr>
                        <td><?php echo $d['firstName'] . " " . $d['lastName']; ?></td>
                        <td><?php echo $d['email'] ?: 'N/A'; ?></td>
                        <td><?php echo $d['phoneNumber'] ?: 'N/A'; ?></td>
                        <td><?php echo $d['vahical']['drivingLicense'] ?: 'N/A'; ?></td>
                        <!-- Profile Image -->
                        <td>
                            <?php if (!empty($d['image'])) { ?>
                                <img src="<?php echo $d['image']; ?>" alt="Profile Image" width="50" height="50">
                            <?php } else { ?>
                                N/A
                            <?php } ?>
                        </td>


                        <!-- Front Driving License -->
                        <td>
                            <?php if (!empty($d['vahical']['drivingFrontUrl'])) { ?>
                                <a class="btn btn-success fontsL" href="<?php echo $d['vahical']['drivingFrontUrl']; ?>"
                                    target="_blank">View Front License</a>
                            <?php } else { ?>
                                N/A
                            <?php } ?>
                        </td>

                        <!-- Back Driving License -->
                        <td>
                            <?php if (!empty($d['vahical']['drivingBackUrl'])) { ?>
                                <a class="btn btn-success fontsL" href="<?php echo $d['vahical']['drivingBackUrl']; ?>"
                                    target="_blank">View Back License</a>
                            <?php } else { ?>
                                N/A
                            <?php } ?>
                        </td>

                        <td><?php echo $d['vahical']['color'] ?: 'N/A'; ?></td>
                        <td><?php echo $d['vahical']['make'] ?: 'N/A'; ?></td>
                        <td><?php echo $d['vahical']['model'] ?: 'N/A'; ?></td>
                        <td><?php echo $d['vahical']['tagNumber'] ?: 'N/A'; ?></td>

                        <td>
                            <div class="dropdown">
                                <button class="btn btnelep" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                    <img src="<?php echo base_url() ?>/assets/images/ellep.png" alt="">
                                </button>
                                <ul class="dropdown-menu">
                                    <?php if ($d['isApproved']) { ?>
                                        <li><a class="dropdown-item"
                                                href="<?php echo base_url('drivers/rejectDriver/') . $j; ?>">Disable</a></li>
                                    <?php } else { ?>
                                        <li><a class="dropdown-item"
                                                href="<?php echo base_url('drivers/approveDriver/') . $j; ?>">Approve</a></li>
                                    <?php } ?>
                                    <li><a class="dropdown-item"
                                            href="<?php echo base_url('drivers/view_driver_info/') . $j; ?>">View</a></li>
                                    <li><a class="dropdown-item"
                                            href="<?php echo base_url('drivers/edit_driver_info/') . $j; ?>">Edit</a></li>
                                    <li><a class="dropdown-item"
                                            href="<?php echo base_url('drivers/deletedriver/') . $j; ?>">Delete</a></li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
</div>

<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>
<script>
    $(document).ready(function() {
        $('#drivertable').DataTable();
    });
</script>