

<?php $__env->startSection('content'); ?>
<main class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="card shadow">
                <div class="card-body">
                    <h2 class="card-title text-center">Edit Sponsor Details</h2>
                    <form method="POST" action="<?php echo e(route('sponsor.update', $sponsor->id)); ?>">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PUT'); ?>
                        <div class="mb-3">
                            <label for="fullName" class="form-label">Full Name:</label>
                            <input type="text" id="fullName" name="fullName" class="form-control" value="<?php echo e($sponsor->fullName); ?>" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="gender" class="form-label">Gender:</label>
                            <select id="gender" name="gender" class="form-select" required>
                                <option value="">Select Gender</option>
                                <option value="male" <?php echo e($sponsor->gender == 'male' ? 'selected' : ''); ?>>Male</option>
                                <option value="female" <?php echo e($sponsor->gender == 'female' ? 'selected' : ''); ?>>Female</option>
                                <option value="other" <?php echo e($sponsor->gender == 'other' ? 'selected' : ''); ?>>Other</option>
                            </select>
                        </div>
                        
                        <div class="mb-3">
                            <label for="dob" class="form-label">Date of Birth:</label>
                            <input type="text" id="dob" name="dob" class="form-control" value="<?php echo e($sponsor->dob); ?>" placeholder="DD/MM/YYYY" required>
                        </div>

                        <div class="mb-3">
    <label for="address" class="form-label">Address:</label>
    <input type="text" id="address" name="address" class="form-control" value="<?php echo e(old('address', $sponsor->address)); ?>" required>
</div>

<div class="row">
    <div class="col-md-6 mb-3">
        <label for="city" class="form-label">City:</label>
        <input type="text" id="city" name="city" class="form-control" value="<?php echo e(old('city', $sponsor->city)); ?>" required>
    </div>
    <div class="col-md-6 mb-3">
        <label for="state" class="form-label">State/Province:</label>
        <input type="text" id="state" name="state" class="form-control" value="<?php echo e(old('state', $sponsor->state)); ?>" required>
    </div>
</div>

<div class="row">
    <div class="col-md-6 mb-3">
        <label for="zip" class="form-label">Zip/Postal Code:</label>
        <input type="text" id="zip" name="zip" class="form-control" value="<?php echo e(old('zip', $sponsor->zip)); ?>" required>
    </div>
    <div class="col-md-6 mb-3">
        <label for="country" class="form-label">Country:</label>
        <input type="text" id="country" name="country" class="form-control" value="<?php echo e(old('country', $sponsor->country)); ?>" required>
    </div>
</div>

<div class="mb-3">
    <label for="phone" class="form-label">Phone Number:</label>
    <input type="tel" id="phone" name="phone" class="form-control" value="<?php echo e(old('phone', $sponsor->phone)); ?>" required>
</div>

<div class="mb-3">
    <label for="email" class="form-label">Email Address:</label>
    <input type="email" id="email" name="email" class="form-control" value="<?php echo e(old('email', $sponsor->email)); ?>" required>
</div>

<div class="mb-3">
    <label for="pan" class="form-label">PAN Card Number (for Indian nationals):</label>
    <input type="text" id="pan" name="pan" class="form-control" value="<?php echo e(old('pan', $sponsor->pan)); ?>">
</div>
<div class="mb-3">
                            <label for="student" class="form-label">Select Student:</label>
                            <select id="student" name="student[]" class="form-select" multiple required>
                                <?php $__currentLoopData = $students; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($student->id); ?>" 
                                            data-age="<?php echo e($student->student_age); ?>" 
                                            data-dob="<?php echo e($student->date_of_birth); ?>" 
                                            data-fees="<?php echo e($student->school_fees); ?>">
                                        <?php echo e($student->student_name); ?>

                                    </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>

                        <!-- Display selected students -->
                        <div class="student_id mb-3">
                            <!-- Selected students will be displayed here -->
                        </div>

                        <div class="text-center">
                            <button type="submit" class="btn btn-primary">Update</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>



    <?php $__env->startPush('scripts'); ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>

<!-- Custom JavaScript -->
<script>
    document.addEventListener("DOMContentLoaded", function () {
        const studentSelect = document.getElementById("student");
        const selectedStudentsContainer = document.querySelector(".student_id");

        // Function to add selected student details
        function addSelectedStudent(student) {
            const studentId = student.value;
            const studentName = student.textContent;
            const studentAge = student.getAttribute("data-age");
            const studentDOB = student.getAttribute("data-dob");
            const studentFees = student.getAttribute("data-fees");

            // Check if the student is already displayed
            if (!document.getElementById(`student_${studentId}`)) {
                const studentDetails = document.createElement("div");
                studentDetails.id = `student_${studentId}`;
                studentDetails.classList.add("selected-student");
                studentDetails.innerHTML = `
                    <span>Name: ${studentName}</span>
                    <br>
                    <span>Age: ${studentAge}</span>
                    <br>
                    <span>Date of Birth: ${studentDOB}</span>
                    <br>
                    <span>School Fees: ${studentFees}</span>
                    <br>
                    <button type="button" class="btn btn-sm btn-outline-danger ms-2" onclick="removeStudent('${studentId}')">X</button>
                    <input type="hidden" name="selected_students[]" value="${studentId}">
                `;

                selectedStudentsContainer.appendChild(studentDetails);
            }
        }

        // Event listener for changes in the student select dropdown
        studentSelect.addEventListener("change", function () {
            const selectedStudentOptions = Array.from(studentSelect.selectedOptions);
            selectedStudentOptions.forEach(addSelectedStudent);
        });

        // Function to remove a selected student
        window.removeStudent = function (studentId) {
            const selectedStudent = document.getElementById(`student_${studentId}`);
            if (selectedStudent) {
                selectedStudent.remove();
            }
        };

        // Function to add pre-selected students on page load
        function addPreselectedStudents() {
            const preselectedOptions = Array.from(studentSelect.selectedOptions);
            preselectedOptions.forEach(addSelectedStudent);
        }

        // Call the function to add pre-selected students on page load
        addPreselectedStudents();
    });
</script>
<?php $__env->stopPush(); ?>
</main>
<?php $__env->stopSection(); ?>




<?php echo $__env->make('layouts.header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\Users\91638\VB150\VB150\resources\views/sponsor/edit.blade.php ENDPATH**/ ?>