<?php $__env->startSection('title', 'Home : Careers Home'); ?>
<?php $__env->startSection('content'); ?>
    <style>
        .career-image-preview img {
            width: 100%;
            height: 149px;
            object-fit: cover;
            border-radius: 10px;
        }
        .career-video-preview video {
            width: 100%;
            height: 149px;
            object-fit: cover;
            border-radius: 10px;
        }
        .header-page-top-section-detail-left .video-preview video{
            width: 100%;
            height: 309px;
            object-fit: cover;
            border-radius: 10px;
        }
        .header-page-top-section-detail-right .image-preview img{
            width: 100%;
            height: 309px;
            object-fit: cover;
            border-radius: 10px;
        }
        .close-upload-item{
            z-index: 123456;
        }
    </style>
    <div class="middle-part-wrap careers-page-wrap">
        <div class="header-page-wrap">
            <form id="careerHomeFrm" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="id" id="id" value="<?php echo e(!empty($careerDetails) && !empty($careerDetails->id) ? $careerDetails->id : ''); ?>">
                <div class="header-page-detail">
                    <div class="scroll">
                        <div class="header-page-top-section">
                            <div class="header-page-top-section-detail-left">
                                <h4>Header Video</h4>
                                <?php
                                    $videoVisible =!empty($careerDetails) && $careerDetails->fileType == 2 && !empty($careerDetails->filePath)? '': 'none';
                                ?>
                                <div class="uploader-wrap" id="video-upload" data-type="video">
                                    <div class="uploader-button upBtnVideo">
                                        <a href="javascript:void(0);" class="file-input mainVideoCls" data-type="video">
                                            <img src="<?php echo e(asset('images/play-icon.png')); ?>"
                                                style="display:<?php echo e(!empty($careerDetails) && $careerDetails->fileType == 2 && !empty($careerDetails->filePath) ? 'none' : ''); ?>;">
                                        </a>
                                        <input type="file" id="video-file" name="video" accept="video/*"
                                            data-value="<?php echo e(!empty($careerDetails) && $careerDetails->fileType == 2 && !empty($careerDetails->filePath) ? $careerDetails->filePath : ''); ?>"
                                            style="display:none;"> 
                                    </div>
                                    <div class="uploader-text"
                                        style="display:<?php echo e(!empty($careerDetails) && $careerDetails->fileType == 2 && !empty($careerDetails->filePath) ? 'none' : ''); ?>;">
                                        <p>Upload video (under <?php echo e(config('app.videoMaxSize')); ?>MB).</p>
                                    </div>
                                    <div class="close-upload-item">
                                        <a href="javascript:void(0);" class="main-remove-video"
                                            style="display:<?php echo e($videoVisible); ?>;"><img src="<?php echo e(asset('images/close.png')); ?>"></a>
                                    </div>
                                    <div class="video-preview" style="display:<?php echo e($videoVisible); ?>;">
                                        <video
                                            <?php if(!empty($careerDetails) && $careerDetails->fileType == 2): ?> src="<?php echo e(getMedia($careerDetails->filePath)); ?>" <?php endif; ?>
                                            controls id="video-preview"></video>
                                    </div>
                                </div>
                            </div>
                            <div class="saprator">
                                <p>OR</p>
                            </div>
                            <div class="header-page-top-section-detail-right">
                                <h4>Header Image</h4>
                                <?php
                                    $imageVisible =
                                        !empty($careerDetails) &&
                                        $careerDetails->fileType == 1 &&
                                        !empty($careerDetails->filePath)
                                            ? ''
                                            : 'none';
                                ?>
                                <div class="uploader-wrap" id="image-upload" data-type="image">
                                    <div class="uploader-button">
                                        <a href="javascript:void(0);" class="file-input mainImgCls" data-type="image">
                                            <img src="<?php echo e(asset('images/image-icon.png')); ?>"
                                                style="display:<?php echo e(!empty($careerDetails) && $careerDetails->fileType == 1 && !empty($careerDetails->filePath) ? 'none' : ''); ?>;">
                                        </a>
                                        <input type="file" id="image-file" name="image" accept="image/*"
                                            data-value="<?php echo e(!empty($careerDetails) && $careerDetails->fileType == 1 && !empty($careerDetails->filePath) ? $careerDetails->filePath : ''); ?>"
                                            style="display:none;">
                                    </div>
                                    <div class="uploader-text"
                                        style="display:<?php echo e(!empty($careerDetails) && $careerDetails->fileType == 1 && !empty($careerDetails->filePath) ? 'none' : ''); ?>;">
                                        <p>Upload image (under <?php echo e(config('app.imageMaxSize')); ?>MB).</p>
                                    </div>
                                    <div class="close-upload-item">
                                        <a href="javascript:void(0);" class="main-remove-image"
                                            style="display:<?php echo e($imageVisible); ?>;"><img
                                                src="<?php echo e(asset('images/close.png')); ?>"></a>
                                    </div>
                                    <div class="image-preview" style="display:<?php echo e($imageVisible); ?>;">
                                        <img <?php if(!empty($careerDetails) && $careerDetails->fileType == 1 && !empty($careerDetails->filePath)): ?> src="<?php echo e(getMedia($careerDetails->filePath)); ?>" <?php endif; ?>
                                            id="image-preview">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="career-life-at-anser">
                            <h4>Life at ANSER</h4>
                            <div class="form-group">
                                <textarea class="form-control required" placeholder="Enter tag line here." id="lifeAtAnser" name="lifeAtAnser" maxlength="1000"><?php echo e(!empty($careerDetails) && !empty($careerDetails->lifeAtAnser)?$careerDetails->lifeAtAnser:''); ?></textarea>
                            </div>
                        </div>
                        <div class="career-middle-section-data-wrap">
                            <ul>
                                <?php
                                    $imageVisible = !empty($careerDetails)? '': 'none';
                                ?>
                                <?php for($i = 0; $i < 3; $i++): ?>
                                    <li>
                                        <div class="career-middle-section-data-detail">
                                            <h5>Section <?php echo e($i + 1); ?></h5>
                                            <input type="hidden" name="section[<?php echo e($i); ?>][section_id]" value="<?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_section_media) ? $careerDetails->careers_section_media[$i]->id : ''); ?>">
                                            <div class="form-group">
                                                <input type="text" class="form-control required" maxlength="50"
                                                    placeholder="Title here." name="section[<?php echo e($i); ?>][title]" value="<?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_section_media) ? $careerDetails->careers_section_media[$i]->title : ''); ?>">
                                            </div>
                                            <div class="form-group">
                                                <textarea class="form-control  required" placeholder="Description here." maxlength="1000"
                                                    name="section[<?php echo e($i); ?>][description]"><?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_section_media) ? $careerDetails->careers_section_media[$i]->description : ''); ?></textarea>
                                            </div>
                                            <div class="career-uploader-wrap">
                                                <div class="small-uploader-detail">
                                                    <div class="uploader-wrap"  data-type="image">
                                                        <div class="uploader-button"
                                                            id="uploader-button-<?php echo e($i); ?>">
                                                            <a href="javascript:void(0);" class="imgCls" data-type="image" style="display:<?php echo e(!empty($careerDetails)? 'none' : ''); ?>;"><img
                                                                    src="<?php echo e(asset('images/image-icon.png')); ?>"></a>
                                                            <input class="image-file careerImages" type="file"
                                                                data-type="image" id="image-file-<?php echo e($i); ?>"
                                                                name="section[<?php echo e($i); ?>][image]" data-value="<?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_section_media) ? $careerDetails->careers_section_media[$i]->image : ''); ?>"
                                                                accept="image/*" style="display:none;">
                                                        </div>
                                                        <div class="uploader-text" id="uploader-text-<?php echo e($i); ?>" style="display:<?php echo e(!empty($careerDetails)? 'none' : ''); ?>;">
                                                            <p>Upload PNG or JPEG image (under <?php echo e(config('app.imageMaxSize')); ?>MB).</p>
                                                        </div>
                                                        <div class="close-upload-item">
                                                            <a href="javascript:void(0);" class="remove-image" data-index="<?php echo e($i); ?>" style="display:<?php echo e($imageVisible); ?>;">
                                                                <img src="<?php echo e(asset('images/close.png')); ?>">
                                                            </a>
                                                        </div>
                                                        <div class="image-preview-<?php echo e($i); ?> career-image-preview"
                                                        style="display:<?php echo e($imageVisible); ?>;">
                                                            <img id="image-preview-<?php echo e($i); ?>" <?php if(!empty($careerDetails) && !empty($careerDetails->careers_section_media)): ?> src="<?php echo e(getMedia($careerDetails->careers_section_media[$i]->image)); ?>" <?php endif; ?>>
                                                        </div>
                                                    </div>
                                                    <span class="error imgMsg text-danger" style="display: none;">Image is
                                                        required.</span>
                                                </div>
                                                <div class="small-uploader-detail">
                                                    <div class="uploader-wrap" data-type="video">
                                                        <div class="uploader-button" id="uploader-button-video-<?php echo e($i); ?>">
                                                            <a href="javascript:void(0);" class="videoCls" data-type="video" style="display:<?php echo e(!empty($careerDetails)? 'none' : ''); ?>;">
                                                                <img src="<?php echo e(asset('images/play-icon.png')); ?>">
                                                            </a>
                                                            <input class="careerVideos" type="file"
                                                                id="video-file-<?php echo e($i); ?>" data-value=<?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_section_media) ? $careerDetails->careers_section_media[$i]->video : ''); ?>"
                                                                name="section[<?php echo e($i); ?>][video]"
                                                                data-type="video" accept="video/*" style="display:none;">
                                                        </div>
                                                        <div class="uploader-text"
                                                            id="uploader-text-video-<?php echo e($i); ?>" style="display:<?php echo e(!empty($careerDetails)? 'none' : ''); ?>;">
                                                            <p>Upload MP4 video (under <?php echo e(config('app.videoMaxSize')); ?>MB).</p>
                                                        </div>
                                                        <div class="close-upload-item">
                                                            <a href="javascript:void(0);" class="remove-video" data-index="<?php echo e($i); ?>" style="display:<?php echo e($imageVisible); ?>;">
                                                                <img src="<?php echo e(asset('images/close.png')); ?>">
                                                            </a>
                                                        </div>
                                                        <div class="video-preview-<?php echo e($i); ?> career-video-preview" style="display:<?php echo e($imageVisible); ?>;">
                                                            <video controls <?php if(!empty($careerDetails) && !empty($careerDetails->careers_section_media)): ?> src="<?php echo e(getMedia($careerDetails->careers_section_media[$i]->video)); ?>" <?php endif; ?>
                                                                id="video-preview-<?php echo e($i); ?>"></video>
                                                        </div>
                                                    </div>
                                                    <span class="error videoMsg text-danger" style="display: none;">Video is
                                                        required.</span>
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                <?php endfor; ?>
                            </ul>
                        </div>
                        <div class="career-life-at-anser">
                            <h4>Candidate Experience and Interview Process</h4>
                            <div class="form-group">
                                <textarea  maxlength="1000" class="form-control required" placeholder="Enter tag line here." name="experienceInterviewProcess" id="experienceInterviewProcess"><?php echo e(!empty($careerDetails)? $careerDetails->experienceInterviewProcess : ''); ?></textarea>
                            </div>
                        </div>
                        <div class="banefits-wrap">
                            <div class="banefits-top-title">
                                <h4>Benefits</h4>
                            </div>
                            <div class="banefits-list">
                                <ul>
                                    <?php for($j = 0; $j < 3; $j++): ?>
                                        <li>
                                            <div class="banefits-list-detail">
                                                <h4>Benifit</h4>
                                                <input type="hidden" name="benifit[<?php echo e($j); ?>][benefit_id]" value="<?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_benefits) ? $careerDetails->careers_benefits[$j]->id : ''); ?>">
                                                <div class="form-group">
                                                    <input type="text" maxlength="50" class="form-control required"
                                                        placeholder="Title here."
                                                        name="benifit[<?php echo e($j); ?>][benifitTitle]" value="<?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_benefits) ? $careerDetails->careers_benefits[$j]->benifitTitle : ''); ?>">
                                                </div>
                                                <div class="form-group">
                                                    <textarea class="form-control required" maxlength="1000" placeholder="Description here."
                                                        name="benifit[<?php echo e($j); ?>][benifitDescription]"><?php echo e(!empty($careerDetails) && !empty($careerDetails->careers_benefits) ? $careerDetails->careers_benefits[$j]->benifitDescription : ''); ?></textarea>
                                                </div>
                                            </div>
                                        </li>
                                    <?php endfor; ?>
                                </ul>
                            </div>
                        </div>
                        <div class="career-life-at-anser">
                            <h4>Disclaimer</h4>
                            <div class="form-group">
                                <textarea class="form-control required" placeholder="Enter tag line here." id="disclaimer" name="disclaimer" maxlength="1000"><?php echo e(!empty($careerDetails)? $careerDetails->disclaimer : ''); ?></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="submit-button">
                        <button type="submit" class="submit-btn">Update</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript" src="<?php echo asset('plugin/tinyeditor/tinymce.min.js'); ?>"></script>
    <script>
        $(document).ready(function() {
            activeLi('careers');   
            tinyEditor('lifeAtAnser');         
            tinyEditor('experienceInterviewProcess');         
            tinyEditor('disclaimer');                 
            $('input:not([type="file"])').addClass('removeSameValueAndSpace').addClass('required');
            $('textarea').addClass('removeSameValueAndSpace').addClass('required'); 
            $(document).on('click', '.mainImgCls', function(event) {
                var $this = $(this);
                console.log($this.parent().find('input[type="file"]'));
                $this.parent().find('input[type="file"]').val('');
                $this.parent().find('input[type="file"]').click();
            });

            $(document).on('click', '.mainVideoCls', function(event) {
                var $this = $(this);
                console.log($this.parent().find('input[type="file"]'));                
                $this.parent().find('input[type="file"]').val('');
                $this.parent().find('input[type="file"]').click();
            });
            $(document).on('click', '.imgCls', function(event) {
                var $this = $(this);
                console.log($this.parent().find('input[type="file"]'));
                $this.parent().find('input[type="file"]').click();
            });

            $(document).on('click', '.videoCls', function(event) {
                var $this = $(this);
                console.log($this.parent().find('input[type="file"]'));
                $this.parent().find('input[type="file"]').click();
            });

            $('#careerHomeFrm').validate({
                submitHandler: function(form) {
                    headerSubmit();
                }
            });

            $(document).on('change', 'input[type="file"]', function(event) {
                event.stopPropagation();
                var $this = $(this);
                // $this.parent().parent().find('.image-preview').show();
                // $this.parent().parent().find('.image-preview').find('img').attr('src', 'xyz');
                const type = $(this).attr('id').split('-')[0];
                var index = $(this).attr('id').split('-')[2];
                if (index != '' && index != undefined) {
                    var previewElement = `${type}-preview` + '-' + index;
                } else {
                    var previewElement = `${type}-preview`;
                }
                handleFileUpload(event, type, previewElement, index);
            });


            function handleFileUpload(event, type, previewElement, index = '') {
                var file = event.target.files[0];
                if (!file) return;
                var fileName = file.name.replace(/\s/g, "_");
                var valid = false;
                var errorMessage = '';

                if (type === 'video') {
                    valid = validateVideoFile(file);
                    if (!valid) {
                        errorMessage = `Invalid video file. Please ensure it is under ${videoMaxSize}MB and of valid format.`;
                    }
                } else if (type === 'image') {
                    valid = validateImageFile(file);
                    if (!valid) {
                        errorMessage = `Invalid image file. Please ensure it is under ${imageMaxSize}MB and of valid format.`;
                    }
                }
                
                if (valid) {
                    var reader = new FileReader();
                    reader.onload = function(e) {
                        if (type === 'video') {
                            console.log(previewElement);
                            $(`.${previewElement}`).show();
                            if (index != undefined && index != '') {
                                $(`#uploader-button-video-${index}`).hide();
                                $(`#uploader-text-video-${index}`).hide();
                            } else {
                                $(`#uploader-button-video`).hide();
                                $(`#uploader-text-video`).hide();
                            }
                            $(`.${previewElement}`).parent().find('a').show();
                            $(`#${previewElement}`).attr('src', e.target.result);
                            $(`#${type}-file-${index}`).attr('data-value', e.target.result);
                            $(`#${type}-file-${index}`).attr('data-filename', fileName);
                            $(`#${type}-file-${index}`).prop('readonly', true);
                            $('.video-preview' + index).show();
                            $(`.${previewElement}`).parent().find('img').show();
                            if(index == '' || index == 'undefined'){
                                $('.mainVideoCls').hide();                             
                                $('.mainVideoCls').parent().parent().find('.uploader-text').hide();       
                                $('.main-remove-image').hide();
                                $('.mainImgCls').show();

                                $(`#video-file`).attr('data-value', e.target.result);
                                $(`#video-file`).attr('data-filename', fileName);
                                $(`#video-file`).prop('readonly', true);

                                $(`.file-input`).closest(`[data-type="image"]`).parent().next().find('p').parent()
                                .css('display', '');
                            $(`.file-input[data-type="image"]`).find('img').attr('src',
                                "<?php echo e(asset('images/image-icon.png')); ?>").show();
                            $(`#image-preview`).attr('src', "");
                            $(`.image-preview`).hide();
                            $(`#image-file`).val('');
                            $(`#image-file`).attr('data-value', "");
                            $(`#image-file`).attr('data-filename', "");
                            $(`#image-file`).prop('readonly', false); 
                            }else{
                                $('.videoMsg').eq(index).hide();
                            }                                                      
                            // $('.remove-image').hide();

                        } else if (type === 'image') {
                            console.log('image only');
                            console.log(previewElement);
                            $(`.${previewElement}`).show();
                            if (index != undefined && index != '') {
                                $(`#uploader-button-${index}`).hide();
                                $(`#uploader-text-${index}`).hide();
                            } else {
                                $(`#uploader-button`).hide();
                                $(`#uploader-text`).hide();
                            }
                            $(`.${previewElement}`).parent().find('a').show();
                            $(`#${previewElement}`).attr('src', e.target.result);
                            $(`#${type}-file-${index}`).attr('data-value', e.target.result);
                            $(`#${type}-file-${index}`).attr('data-filename', fileName);
                            $(`#${type}-file-${index}`).prop('readonly', true);
                            $('.image-preview' + index).show();
                            $(`.${previewElement}`).parent().find('img').show();
                            if(index == '' || index == 'undefined'){
                                $('.mainImgCls').hide();                                 
                                $('.mainImgCls').parent().parent().find('.uploader-text').hide();             
                                $('.main-remove-video').hide();
                                $('.mainVideoCls').show();

                                $(`#image-file`).attr('data-value', e.target.result);
                                $(`#image-file`).attr('data-filename', fileName);
                                $(`#image-file`).prop('readonly', true);


                                $(`.file-input`).closest(`[data-type="video"]`).parent().next().find('p').parent()
                                .css('display', '');
                            $(`.file-input[data-type="video"]`).find('img').attr('src',
                                "<?php echo e(asset('images/play-icon.png')); ?>").show();
                            $(`#video-preview`).attr('src', "");
                            $(`.video-preview`).hide();
                            $(`#video-file`).val('');
                            $(`#video-file`).attr('data-value', "");
                            $(`#video-file`).attr('data-filename', "");
                            $(`#video-file`).prop('readonly', false);
                            $('.upBtnVideo').show(); 
                            }else{
                                $('.imgMsg').eq(index).hide();
                            }  
                            // $('.remove-video').hide();
                        }
                    };
                    reader.readAsDataURL(file);
                } else {
                    displayMessageModal(errorMessage, 'error');
                }
            }

            $(document).on('click', '.main-remove-video', function(event) {
                event.stopPropagation();
                const uploaderWrap = $(this).closest('.uploader-wrap');
                const fileInput = uploaderWrap.find('input[type="file"]');
                const previewElement = `${uploaderWrap.attr('data-type')}-preview`;
                $(`.${previewElement}`).hide();
                $(`#${previewElement}`).attr('src', '');
                $(fileInput).parent().show();
                $(fileInput).closest('.file-input').show();
                $(fileInput).parent().find('img').show();
                $(fileInput).parent().next().find('p').parent().show();
                $(fileInput).attr('data-value', '');
                $(fileInput).attr('data-filename', '');
                $(fileInput).prop('readonly', false);
                $(this).hide();
                $('.mainVideoCls').show();
            });

            $(document).on('click', '.remove-video', function(event) {
                event.stopPropagation();
                const uploaderWrap = $(this).closest('.uploader-wrap');
                const fileInput = uploaderWrap.find('input[type="file"]');
                var index = $(this).attr('data-index');
                const previewElement = `${uploaderWrap.attr('data-type')}-preview-${index}`;
                $(`.${previewElement}`).hide();
                $(`#${previewElement}`).attr('src', '');
                $(fileInput).parent().show();
                $(fileInput).closest('.file-input').show();
                $(fileInput).parent().find('img').show();
                $(fileInput).parent().next().find('p').parent().show();
                $(fileInput).attr('data-value', '');
                $(fileInput).attr('data-filename', '');
                $(fileInput).prop('readonly', false);
                $(this).parent().parent().find('.videoCls').show();
                $(this).hide();
            });

            $(document).on('click', '.main-remove-image', function(event) {
                event.stopPropagation();
                const uploaderWrap = $(this).closest('.uploader-wrap');
                const fileInput = uploaderWrap.find('input[type="file"]');
                const previewElement = `${uploaderWrap.attr('data-type')}-preview`;
                $(`.${previewElement}`).hide();
                $(`#${previewElement}`).attr('src', '');
                $(fileInput).parent().show();
                $(fileInput).closest('.file-input').show();
                $(fileInput).parent().find('img').show();
                $(fileInput).parent().next().find('p').parent().show();
                $(fileInput).attr('data-value', '');
                $(fileInput).attr('data-filename', '');
                $(fileInput).prop('readonly', false);
                $(this).hide();
                $('.mainImgCls').show();
            });


            $(document).on('click', '.remove-image', function(event) {
                event.stopPropagation();
                const uploaderWrap = $(this).closest('.uploader-wrap');
                const fileInput = uploaderWrap.find('input[type="file"]');
                var index = $(this).attr('data-index');
                const previewElement = `${uploaderWrap.attr('data-type')}-preview-${index}`;
                $(`.${previewElement}`).hide();
                $(`#${previewElement}`).attr('src', '');
                $(fileInput).parent().show();
                $(fileInput).closest('.file-input').show();
                $(fileInput).parent().find('img').show();
                $(fileInput).parent().next().find('p').parent().show();
                $(fileInput).attr('data-value', '');
                $(fileInput).attr('data-filename', '');
                $(fileInput).prop('readonly', false);
                $(this).parent().parent().find('.imgCls').show();
                $(this).hide();
            });

            function validateVideoFile(file) {
                const validTypes = ['video/mp4', 'video/avi', 'video/mkv'];
                const maxSize = videoMaxSize * 1024 * 1024;
                return validTypes.includes(file.type) && file.size <= maxSize;
            }

            function validateImageFile(file) {
                const validTypes = ['image/png', 'image/jpeg', 'image/gif'];
                const maxSize = imageMaxSize * 1024 * 1024;
                return validTypes.includes(file.type) && file.size <= maxSize;
            }

            $(document).on('dragover', '.uploader-wrap', function(event) {
                event.preventDefault();
                event.stopPropagation();
                $(this).addClass('dragging');
            });

            $(document).on('dragleave', '.uploader-wrap', function(event) {
                event.preventDefault();
                event.stopPropagation();
                $(this).removeClass('dragging');
            });

            $(document).on('drop', '.uploader-wrap', function(event) {
                event.preventDefault();
                event.stopPropagation();
                $(this).removeClass('dragging');
                const files = event.originalEvent.dataTransfer.files;
                if (files.length) {
                    const file = files[0];
                    const type = $(this).data('type');
                    const mockEvent = {
                        target: {
                            files: [file]
                        }
                    };
                    handleFileUpload(mockEvent, type, `${type}-preview`);
                }
            });

            function headerSubmit() {
                event.preventDefault();                
                var token = "<?php echo e(csrf_token()); ?>"; 
                var videoElement = $('#video-file');
        var imageElement = $('#image-file');  
                var videoFile = videoElement.attr('data-value');
            var imageFile = imageElement.attr('data-value');
            var isFormValid = true;
            if (!validateEditorValue('lifeAtAnser') || !validateEditorValue('experienceInterviewProcess') || !validateEditorValue('disclaimer')) {
                isFormValid = false;
                return;
            }
            if (!videoFile && !imageFile) {
                displayMessageModal('Please upload at least one video or one image file.',
                    'error');
                isFormValid = false;
                return;
            }             
                if (validateMedias() && isFormValid) {
                    var url = "<?php echo e(url('admin/saveCareersHome')); ?>";
                    var formData = new FormData($('#careerHomeFrm')[0]);
                    formData.append('_token', token);
                    $('body').prepend('<div class="loader"></div>');
                    // if (videoFile) {
                    //     originalFileName = videoElement.attr('data-filename');
                    //     formData.append('video', videoFile);
                    // } else if (imageFile) {
                    //     originalFileName = imageElement.attr('data-filename');
                    //     formData.append('image', imageFile);
                    // }
                    // formData.append('originalFileName', originalFileName);
                    $('button[type="submit"]').attr('disabled', 'disabled').css('cursor', 'not-allowed');
                    $.ajax({
                        url: url,
                        type: "POST",
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: "json",
                        data: formData,
                        success: function(response) {
                            $('.loader').remove();
                            $('button[type="submit"]').removeAttr('disabled').css('cursor', 'pointer');
                            displayMessageModal(response.message, 'success', 'selfReload');
                        },
                        error: function(error) {
                            $('.loader').remove();
                            $('button[type="submit"]').removeAttr('disabled').css('cursor', 'pointer');
                            displayMessageModal(error.responseJSON.message, 'error');
                        }
                    });
                }
            }
        });

        function validateMedias() {
            let allMediaValid = true;
            $('.careerImages').each(function(index) {
                const value = $(this).attr('data-value');
                if (!value) {
                    $('.imgMsg').eq(index).show();
                    allMediaValid = false;
                } else {
                    $('.imgMsg').eq(index).hide();
                }
            });

            $('.careerVideos').each(function(index) {
                const value = $(this).attr('data-value');
                if (!value) {
                    $('.videoMsg').eq(index).show();
                    allMediaValid = false;
                } else {
                    $('.videoMsg').eq(index).hide();
                }
            });
            return allMediaValid;
        }
        function validateEditorValue(selector) {
            const value = tinymce.get(`${selector}`).getContent();
            if (!value || value.trim() === "") {
                displayMessageModal(
                    `Please enter a description.`,
                    "error"
                );
                return false;
            }
            return true;
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/anser-backend/resources/views/careers/home.blade.php ENDPATH**/ ?>