
<?php $__env->startSection('pageTitle', isset($pageTitle) ? $pageTitle : 'Page Title Here'); ?>
<?php $__env->startSection('content'); ?>

<div class="page-header">
    <div class="row">
        <div class="col-md-6 col-sm-12">
            <div class="title">
                <h4>Edit Office Department</h4>
            </div>
            <nav aria-label="breadcrumb" role="navigation">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a href="<?php echo e(route('admin.dashboard')); ?>">Home</a>
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">
                        Edit Office Department
                    </li>
                </ol>
            </nav>
        </div>
        <div class="col-md-6 col-sm-12 text-right">
            <a href="<?php echo e(route('admin.office_department')); ?>" class="btn btn-primary">View all office department</a>
        </div>
    </div>
</div>

<form action="<?php echo e(route('admin.update_office_department',['officeDepartment_id' => $officeDepartment->id])); ?>" method="POST" autocomplete="off" enctype="multipart/form-data" id="updateOfficeDepartmentForm">
    <?php echo csrf_field(); ?>
    <div class="row">
        <div class="col-md-9">
            <div class="card card-box mb-2">
                <div class="card-body">
                    <div class="form-group">
                        <label for="office">Office Department:</label>
                        <select id="office" class="form-control" disabled>
                            <?php $__currentLoopData = $offices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $office): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($office->id); ?>"
                                <?php echo e($office->id == $officeDepartment->office_department_id ? 'selected' : ''); ?>>
                                <?php echo e($office->description); ?>

                            </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="office_department_name"><b>Office Department Head Name</b>: </label>
                        <input type="text" name="office_department_name" placeholder="Enter Office Department Head Name" class="form-control" value="<?php echo e($officeDepartment->office_admin_name); ?>">
                        <span class="text-danger error-text office_department_name_error"></span>
                    </div>
                    <div class="form-group">
                        <label for="office_department_position"><b>Faculty Description</b>: </label>
                        <input type="text" name="office_department_position" placeholder="Enter office department description" class="form-control" value="<?php echo e($officeDepartment->office_admin_description); ?>">
                        <span class="text-danger error-text office_department_position_error"></span>
                    </div>
                    <div class="form-group">
                        <label for="office_department_email"><b>Office Department Email</b>: </label>
                        <input type="email" name="office_department_email" placeholder="Enter Office Department email" class="form-control" value="<?php echo e($officeDepartment->office_admin_email); ?>">
                        <span class="text-danger error-text office_department_email_error"></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card card-box mb-2">
                <div class="card-body">
                    <div class="form-group">
                        <label for="office_head_image"><b>Office head image</b>:</label>
                        <input type="file" name="office_head_image" class="form-control-file form-control" height="auto">
                        <span class="text-danger error-text office_head_image_error"></span>
                    </div>
                    <div class="d-block mb-3" style="max-width:200px">
                        <img src="/images/office_admins/<?php echo e($officeDepartment    ->office_admin_image); ?>" alt="" class="img-thumbnail" id="office_head_image_preview">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="mb-3">
        <button type="submit" class="btn btn-primary">Update Faculty</button>
    </div>
</form>

<?php $__env->stopSection(); ?>
<?php $__env->startPush('scripts'); ?>
<script>
    document.addEventListener("DOMContentLoaded", function() {
        const inputFile = document.querySelector('input[type="file"][name="office_head_image"]');
        const previewImage = document.getElementById("office_head_image_preview");

        inputFile.addEventListener("change", function(event) {
            const file = event.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    previewImage.src = e.target.result;
                };
                reader.readAsDataURL(file);
            }
        });


    });
    $(document).ready(function() {
        $('#updateOfficeDepartmentForm').submit(function(e) {
            e.preventDefault(); // Prevent default form submission

            var form = this;
            // var errorElement = $(form).find('span.text-danger');

            // Reset error message
            // errorElement.text('');
            var formData = new FormData(form);
            $.ajax({
                url: $(form).attr('action'),
                method: $(form).attr('method'),
                data: formData,
                processData: false,
                contentType: false,
                dataType: 'json',
                beforeSend: function() {
                    $(form).find('span.error-text').text('');
                },
                success: function(data) {
                    try {
                        if (data.status === 1) {
                            form.reset();
                            $('img#office_head_image_preview').attr('src', '');
                            toastr.success(data.message);

                            // Update all instances of the site logo
                            // $('img.site_logo').each(function() {
                            //     $(this).attr('src', '/' + data.image_path + '?' + new Date().getTime());
                            // });
                        } else {
                            toastr.error(data.message);
                        }
                    } catch (e) {
                        console.error('Parsing error:', e);
                        toastr.error('Unexpected response format.');
                    }
                },
                error: function(data) {
                    $.each(data.responseJSON.errors, function(prefix, val) {
                        $(form).find('span.' + prefix + '_error').text(val[0]);
                    });
                }
            });
        });
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('back.layout.page-layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/pcdsedup/public_html/resources/views/back/pages/offices/edit_office_department.blade.php ENDPATH**/ ?>