
<?php $__env->startSection('title', 'Manage Trip'); ?>
<?php $__env->startSection('content'); ?>
<div class="page-inner mt-5 pt-5">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header project-details-card-header py-2 d-flex align-items-center justify-content-between">
                    <div>
                        <h4 class="project-details-card-header-title mb-0">Trip List</h4>
                    </div>
                    <div>
                        <a href="<?php echo e(route('trip.create')); ?>" class="btn btn-primary btn-sm" title="Add">
                            <span class="btn-label">
                                <i class='bx bx-plus'></i>
                            </span>
                            Add Trip
                        </a>
                        <button class="btn btn-black btn-sm" title="Go Back" onclick="history.back();">
                            <span class="btn-label">
                                <i class="fas fa-reply"></i>
                            </span>
                            Go Back
                        </button>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <div id="add-row_wrapper" class="dataTables_wrapper container-fluid dt-bootstrap4">
                            <div class="row">
                                <div class="col-sm-12">
                                    <table id="add-row" class="display table table-striped table-hover basic-datatables" role="grid" aria-describedby="add-row_info">
                                        <thead>
                                            <tr>
                                                <th>Sl</th>
                                                <th>Passenger</th>
                                                <th>Airline</th>
                                                <th>Departure</th>
                                                <th>Status</th>
                                                <th class="text-end">Change Status</th>
                                                <th class="text-end">Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $__empty_1 = true; $__currentLoopData = $trips; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $trip): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                            <tr>
                                                <td><?php echo e($index + 1); ?></td>

                                                <td>
                                                    Name: <?php echo e($trip->passenger->title); ?>

                                                    <?php echo e($trip->passenger->first_name); ?>

                                                    <?php echo e($trip->passenger->last_name); ?> <br>
                                                    Passport: <?php echo e($trip->passenger->passport_no); ?> <br>
                                                    Validity: <?php echo e($trip->passenger->passport_expiry?->format('d F Y') ?? '-'); ?> <br>
                                                    Email: <?php echo e($trip->passenger->email); ?> <br>
                                                    Phone: <?php echo e($trip->passenger->mobile_no); ?> <br>
                                                    PNR: <?php echo e($trip->passenger->pnr); ?>

                                                </td>
                                                <td>
                                                    <?php echo e($trip->company->name ?? '-'); ?> <br>
                                                    <?php echo e($trip->departureAirport->name ?? '-'); ?>

                                                    <br>
                                                    <?php echo e(strtoupper(\Carbon\Carbon::parse($trip->departure_date)->format('D, M d, Y'))); ?>

                                                    <br>
                                                    <?php echo e(\Carbon\Carbon::createFromFormat('H:i:s', $trip->departure_time)->format('h:i A')); ?>

                                                </td>
                                                <td>
                                                    <?php echo e(strtoupper(\Carbon\Carbon::parse($trip->departure_date)->format('D, M d, Y'))); ?>

                                                    <br>
                                                    <?php echo e($trip->departureAirportState->state ?? '-'); ?>

                                                    (<?php echo e($trip->departureAirportCode->code ?? '-'); ?>)
                                                    to
                                                    <?php echo e($trip->arrivalAirportState->state ?? '-'); ?>

                                                    (<?php echo e($trip->arrivalAirportCode->code ?? '-'); ?>)
                                                </td>
                                                <td id="status-badge-<?php echo e($trip->id); ?>">
                                                    <?php if($trip->status == 'On Hold'): ?>
                                                    <span class="badge badge-warning">On Hold</span>
                                                    <?php elseif($trip->status == 'Confirmed'): ?>
                                                    <span class="badge badge-success">Confirmed</span>
                                                    <?php elseif($trip->status == 'Booking'): ?>
                                                    <span class="badge badge-info">Booking</span>
                                                    <?php elseif($trip->status == 'Cancelled'): ?>
                                                    <span class="badge badge-danger">Cancelled</span>
                                                    <?php elseif($trip->status == 'Payment-Pending'): ?>
                                                    <span class="badge badge-warning">Payment Pending</span>
                                                    <?php endif; ?>
                                                </td>
                                                <td>
                                                    <div class="btn-list d-flex justify-content-center gap-1">
                                                        <a href="javascript:void(0)" class="btn btn-warning btn-sm openStatusModal" data-id="<?php echo e($trip->id); ?>" data-status="<?php echo e($trip->status); ?>" title="Change Status">
                                                            <i class="far fa-edit"></i>
                                                        </a>
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="btn-list d-flex justify-content-center gap-1">
                                                        <a href="<?php echo e(route('trip.edit', $trip->id)); ?>" class="btn btn-primary btn-sm" title="Edit">
                                                        <i class="far fa-edit"></i>
                                                        </a>

                                                        <form action="<?php echo e(route('trip.delete', $trip->id)); ?>" method="POST">
                                                            <?php echo csrf_field(); ?>
                                                            <?php echo method_field('delete'); ?>
                                                            <button type="submit" class="btn btn-danger btn-sm delete_sweet_alert" title="Delete">
                                                                <i class="far fa-trash-alt"></i>
                                                            </button>
                                                        </form>
                                                    </div>
                                                </td>
                                            </tr>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                            <tr>
                                                <td colspan="7" class="text-center text-muted">
                                                    No records found
                                                </td>
                                            </tr>
                                            <?php endif; ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="statusModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">

            <div class="modal-header">
                <h5 class="modal-title">Change Trip Status</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <input type="hidden" id="trip_id">

                <label>Status</label>
                <select id="trip_status" class="form-control select2">
                    <option value="On Hold">On Hold</option>
                    <option value="Confirmed">Confirmed</option>
                    <option value="Cancelled">Cancelled</option>
                    <option value="Booking">Booking</option>
                    <option value="Payment-Pending">Payment Pending</option>
                </select>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button type="button" id="saveStatusBtn" class="btn btn-primary">
                    Update Status
                </button>
            </div>

        </div>
    </div>
</div>

<?php $__env->stopSection(); ?>
<?php $__env->startPush('script'); ?>
<script>
let statusModal = new bootstrap.Modal(document.getElementById('statusModal'));

// Open modal
$('.openStatusModal').on('click', function () {
    let tripId = $(this).data('id');
    let status = $(this).data('status');

    $('#trip_id').val(tripId);
    $('#trip_status').val(status).trigger('change');

    statusModal.show();
});

// Save status
$('#saveStatusBtn').on('click', function () {

    let tripId = $('#trip_id').val();
    let status = $('#trip_status').val();

    Swal.fire({
        title: 'Update Status?',
        icon: 'warning',
        showCancelButton: true,
        confirmButtonText: 'Yes, update'
    }).then((result) => {

        if (result.isConfirmed) {
            $.ajax({
                url: `/admin/trip/${tripId}/change-status`,
                type: 'POST',
                data: {
                    _token: '<?php echo e(csrf_token()); ?>',
                    status: status
                },
                success: function (res) {

                    // Badge HTML
                    let badgeHtml = '';
                    if (res.status === 'On Hold') {
                        badgeHtml = '<span class="badge badge-warning">On Hold</span>';
                    } else if (res.status === 'Confirmed') {
                        badgeHtml = '<span class="badge badge-success">Confirmed</span>';
                    } else if (res.status === 'Booking') {
                        badgeHtml = '<span class="badge badge-info">Booking</span>';
                    } else if (res.status === 'Cancelled') {
                        badgeHtml = '<span class="badge badge-danger">Cancelled</span>';
                    } else if (res.status === 'Payment-Pending') {
                        badgeHtml = '<span class="badge badge-warning">Payment Pending</span>';
                    }

                    // Update badge
                    $('#status-badge-' + tripId).html(badgeHtml);

                    // Update button data-status
                    $('.openStatusModal[data-id="' + tripId + '"]')
                        .data('status', res.status);

                    statusModal.hide();

                    Swal.fire({
                        icon: 'success',
                        title: 'Updated',
                        text: res.message,
                        timer: 1200,
                        showConfirmButton: false
                    });
                }
            });
        }
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\xampp\htdocs\view-trip-final\resources\views/backend/trip/index.blade.php ENDPATH**/ ?>