
<?php $__env->startSection('title', 'Add Passenger'); ?>
<?php $__env->startPush('style'); ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/themes/material_blue.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Dropify/0.2.2/css/dropify.min.css" />
<style>
    .dropify-wrapper {
        border-radius: 5px;
        border: 1px dashed #3b71ca;
    }

    .dropify-wrapper .dropify-message p {
        font-weight: 500;
        color: #3b71ca;
    }

    .dropify-wrapper .dropify-message span.file-icon {
        color: #3b71ca;
    }

    .invalid-feedback {
        display: block;
        font-weight: 500;
    }

</style>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="page-inner">
        <div class="row">
            <div class="col-md-12">
                <div class="card card-round">
                    <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"><i class='bx bx-plus'></i> Add Passenger</h4>
                        </div>
                        <div>
                            <a href="<?php echo e(route('passenger.index')); ?>" class="btn btn-primary btn-sm" title="List">
                                <span class="btn-label">
                                    <i class="fas fa-users"></i>
                                </span>
                                Passenger List
                            </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">
                        <form id="passengerForm" action="<?php echo e(route('passenger.store')); ?>" method="POST">
                            <?php echo csrf_field(); ?>

                            <div class="row mb-3">
                                <div class="col-md-2">
                                    <label>Title</label>
                                    <select name="title" class="form-control">
                                        <option value="MR" <?php echo e(old('title')=='MR'?'selected':''); ?>>MR</option>
                                        <option value="MRS" <?php echo e(old('title')=='MRS'?'selected':''); ?>>MRS</option>
                                        <option value="MS" <?php echo e(old('title')=='MS'?'selected':''); ?>>MS</option>
                                    </select>
                                    <?php $__errorArgs = ['title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <small class="text-danger"><?php echo e($message); ?></small> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="col-md-5">
                                    <label>Given Name / First Name</label>
                                    <input type="text" name="first_name" class="form-control" value="<?php echo e(old('first_name')); ?>" required>
                                    <?php $__errorArgs = ['first_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <small class="text-danger"><?php echo e($message); ?></small> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="col-md-5">
                                    <label>Surname / Last Name</label>
                                    <input type="text" name="last_name" class="form-control" value="<?php echo e(old('last_name')); ?>" required>
                                    <?php $__errorArgs = ['last_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <small class="text-danger"><?php echo e($message); ?></small> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>

                            <div class="row mb-3">
                                <div class="col-md-4">
                                    <label>Mobile No</label>
                                    <input type="text" name="mobile_no" class="form-control" value="<?php echo e(old('mobile_no')); ?>" required>
                                    <?php $__errorArgs = ['mobile_no'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <small class="text-danger"><?php echo e($message); ?></small> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="col-md-4">
                                    <label>Email</label>
                                    <input type="email" name="email" class="form-control" value="<?php echo e(old('email')); ?>">
                                    <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <small class="text-danger"><?php echo e($message); ?></small> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="col-md-4">
                                    <label>Date of Birth</label>
                                    <input type="text" name="date_of_birth" class="flat_date form-control" value="<?php echo e(old('date_of_birth')); ?>" placeholder="YYYY-MM-DD">
                                    <?php $__errorArgs = ['date_of_birth'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <small class="text-danger"><?php echo e($message); ?></small> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>

                            <h6>Passport Details</h6>

                            <div class="row mb-3">
                                <div class="col-md-4">
                                    <label>Passport No</label>
                                    <input type="text" name="passport_no" class="form-control" value="<?php echo e(old('passport_no')); ?>">
                                </div>

                                <div class="col-lg-4">
                                    <label class="form-label">Nationality</label>
                                    <select name="nationality_id" class="form-control select2" data-placeholder="Select Nationality">
                                        <option value=""></option>
                                        <?php $__currentLoopData = $coutries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $country): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($country->id); ?>" <?php echo e(old('nationality_id') == $country->id ? 'selected' : ''); ?>>
                                            <?php echo e($country->name); ?>

                                        </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <?php $__errorArgs = ['nationality_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <small class="text-danger"><?php echo e($message); ?></small>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="col-md-4">
                                    <label>Passport Expiry</label>
                                    <input type="text" name="passport_expiry" class="flat_date form-control" value="<?php echo e(old('passport_expiry')); ?>" placeholder="YYYY-MM-DD">
                                </div>
                            </div>

                            <div class="col-12 text-end mt-3">
                                <button type="submit" id="saveBtn" class="btn btn-info">
                                    <i class="fas fa-save me-1"></i>
                                    <span class="btn-text">Save Passenger</span>
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('script'); ?>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Dropify/0.2.2/js/dropify.min.js"></script>
<script>
    flatpickr(".flat_date", {
        dateFormat: "Y-m-d"
        , minDate: "today"
    });
</script>
<script>
    $(document).ready(function() {
        $('.select2').each(function() {
            $(this).select2({
                placeholder: $(this).data('placeholder')
                , allowClear: true
                , width: '100%'
                , theme: 'bootstrap'
            });
        });
    });

</script>
<script>
document.getElementById('passengerForm').addEventListener('submit', function (e) {
    e.preventDefault();

    let form = this;
    let formData = new FormData(form);

    Swal.fire({
        title: 'Saving Passenger',
        text: 'Please wait...',
        allowOutsideClick: false,
        didOpen: () => {
            Swal.showLoading();
        }
    });

    fetch(form.action, {
        method: 'POST',
        headers: {
            'X-CSRF-TOKEN': document.querySelector('input[name="_token"]').value,
            'Accept': 'application/json'
        },
        body: formData
    })
    .then(async response => {
        if (!response.ok) {
            const data = await response.json();
            throw data;
        }
        return response.json();
    })
    .then(data => {
        Swal.fire({
            icon: 'success',
            title: 'Success',
            text: data.message,
            timer: 1800,
            showConfirmButton: false
        }).then(() => {
            window.location.href = data.redirect;
        });
    })
    .catch(error => {
        let msg = 'Something went wrong';

        if (error.errors) {
            msg = Object.values(error.errors).map(e => e[0]).join('\n');
        } else if (error.message) {
            msg = error.message;
        }

        Swal.fire({
            icon: 'error',
            title: 'Error',
            text: msg
        });
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/u973467024/domains/mhjohn.xyz/public_html/view-trip/resources/views/backend/passenger/show.blade.php ENDPATH**/ ?>