<?php $__env->startSection('title', 'Employee'); ?>
<?php $__env->startSection('description', 'Employee'); ?>
<?php $__env->startSection('keywords', 'Employee'); ?>
<?php $__env->startSection('content'); ?>
<style>
    .form-fields{
        width:50%;
    }
    .form-fields .sustainability-left-box {
        width: 100%;
    }

    .form-fields .sustainability-right-box {
        width: 100%;
    }
</style>
<div class="middle-part-wrap sustainability-page-wrap">
    <div class="header-page-wrap">
        <form id="addForm">
            <?php echo csrf_field(); ?>
            <div class="sustainability-wrap">
                <div class="scroll">
                    <div class="leadership-top-header">
                        <h3>Sustainability</h3>
                    </div>
                    <div class="sustainability-top-header">
                        <div class="sustainability-left-box full-width">
                            <h4>Header Title</h4>
                            <div class="form-group small-textarea">
                                <input type="text" class="form-control" name="banner_title" id="banner_title" placeholder="Title here." value="<?php echo e(!empty($details) ? $details->banner_title : ''); ?>">
                            </div> 
                        </div>
                        <div class="sustainability-top-header no-space d-flex">
                            <div class="sustainability-left-box">
                                <h4>Header Text</h4>
                                <div class="form-group big-textarea">
                                    <textarea class="form-control" placeholder="Description here." name="banner_description" id="banner_description"><?php echo e(!empty($details) ? $details->banner_description : ''); ?></textarea>
                                </div>
                            </div>
                            <div class="sustainability-right-box">
                                <h4>Header Table</h4>
                                <div class="form-group">
                                    <textarea class="form-control" placeholder="Description here." name="banner_table" id="banner_table"><?php echo e(!empty($details) ? $details->banner_table : ''); ?></textarea>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="sustainability-top-header full-width">
                        <div class="sustainability-left-box">
                            <h4>Organizational Boundary</h4>
                            <div class="form-group small-textarea">
                                <input type="text" class="form-control"  value="<?php echo e(!empty($details) ? $details->organizational_boundary_title : ''); ?>" name="organizational_boundary_title" id="organizational_boundary_title" placeholder="Title here.">
                            </div>
                            <div class="form-group big-textarea">
                                <textarea class="form-control" placeholder="Description here." name="organizational_boundary_description" id="organizational_boundary_description">
                                    <?php echo e(!empty($details) ? $details->organizational_boundary_description : ''); ?>

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



                    <div class="sustainability-top-header mt-10">
                        <div class="sustainability-left-box full-width">
                            <h4>Operational Title</h4>
                            <div class="form-group small-textarea">
                                <input type="text" class="form-control" name="operational_boundary_title" value="<?php echo e(!empty($details) ? $details->operational_boundary_title : ''); ?>" id="operational_boundary_title" placeholder="Title here.">
                            </div> 
                        </div>
                        <div class="sustainability-top-header no-space d-flex">
                            <div class="sustainability-left-box">
                                <h4>Operational Boundary Text</h4>
                                <div class="form-group big-textarea">
                                    <textarea class="form-control" placeholder="Description here." name="operational_boundary_description1" id="operational_boundary_description1">
                                        <?php echo e(!empty($details) ? $details->operational_boundary_description1 : ''); ?>

                                    </textarea>
                                </div>
                            </div>
                            <div class="sustainability-right-box">
                                <h4>Operational Boundary Table</h4>
                                <div class="form-group">
                                    <textarea class="form-control" placeholder="Description here." name="operational_boundary_table1" id="operational_boundary_table1">
                                        <?php echo e(!empty($details) ? $details->operational_boundary_table1 : ''); ?>

                                    </textarea>
                                </div>
                            </div>
                        </div>
                        <div class="sustainability-top-header no-space d-flex mt-10">
                            <div class="sustainability-left-box">
                                <h4>Operational Boundary Text</h4>
                                <div class="form-group big-textarea">
                                    <textarea class="form-control" placeholder="Description here." name="operational_boundary_description2" id="operational_boundary_description2">
                                    <?php echo e(!empty($details) ? $details->operational_boundary_description2 : ''); ?>

                                    </textarea>
                                </div>
                            </div>
                            <div class="sustainability-right-box">
                                <h4>Operational Boundary Table</h4>
                                <div class="form-group">
                                    <textarea class="form-control" placeholder="Description here." name="operational_boundary_table2" id="operational_boundary_table2">
                                    <?php echo e(!empty($details) ? $details->operational_boundary_table2 : ''); ?>

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

                    <div class="sustainability-top-header mt-10">
                        <div class="sustainability-left-box full-width">
                            <h4>Emissions Title</h4>
                            <div class="form-group small-textarea">
                                <input type="text" class="form-control" name="emission_title" value="<?php echo e(!empty($details) ? $details->emission_title : ''); ?>" id="emission_title"  placeholder="Title here.">
                            </div>
                        </div>
                        <div class="sustainability-right-box full-width">
                            <h4>Emissions Text</h4>
                            <div class="form-group">
                                <textarea class="form-control" placeholder="Description here." name="emission_description" id="emission_description">
                                <?php echo e(!empty($details) ? $details->emission_description : ''); ?>

                                </textarea>
                            </div>
                        </div>
                    </div>
                    <div class="sustainability-top-header full-width mb-10">
                        <div class="sustainability-left-box">
                            <h4>Sources</h4>
                            <div class="form-group big-textarea">
                                <textarea class="form-control" placeholder="Add Sources here." name="sources_description" id="sources_description">
                                <?php echo e(!empty($details) ? $details->sources_description : ''); ?>

                                </textarea>
                            </div>
                        </div>
                    </div>
                    
                </div>
                <div class="submit-button">
                    <button type="submit" class="submit-btn">ADD NOW</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="<?php echo asset('plugin/tinyeditor/tinymce.min.js'); ?>"></script>
<script>
$(document).ready(function(){
    $('body').prepend('<div class="loader"></div>');
    tinyEditor('banner_description');
    tinyEditor('banner_table');
    tinyEditor('organizational_boundary_description');
    tinyEditor('operational_boundary_description1');
    tinyEditor('operational_boundary_table1');
    tinyEditor('operational_boundary_description2');
    tinyEditor('operational_boundary_table2');
    tinyEditor('operational_boundary_description2');
    tinyEditor('emission_description');
    tinyEditor('sources_description');
    
    console.log("XXX");
    $('#addForm').validate({
        rules: {
            banner_title: {
                required: true
            },
            organizational_boundary_title: {
                required: true
            },
            operational_boundary_title: {
                required: true
            },
        },
        messages: {
            banner_title: {
                required: "Please enter title."
            },
            organizational_boundary_title: {
                required: "Please enter title."
            },
            operational_boundary_title: {
                required: "Please enter titl."
            },
        },
        submitHandler: function(form) {
            save();
        }
    });
});
function save(){
    
    var isValid = true;
    
    var tinymceFields = [
        'banner_description',
        'banner_table',
        'organizational_boundary_description',
        'operational_boundary_description1',
        'operational_boundary_table1',
        'operational_boundary_description2',
        'operational_boundary_table2',
        'emission_description',
        'sources_description'
    ];

    // Clear all existing TinyMCE error messages
    $('.tinymce-error').remove();

    // Loop through each TinyMCE field and validate
    tinymceFields.forEach(function(field) {
        if (!validateEditorValue(field, 'This field is required.')) {
            isValid = false;
        }
        // Attach keyup event to remove error message on key press
        tinymce.get(field).on('keyup', function () {
            if (tinymce.get(field).getContent().trim() !== "") {
                $('#' + field).closest('.form-group').find('.tinymce-error').remove();
            }
        });
    });
    if (!isValid) {
        return false;
    }
    
    var formData = new FormData($('#addForm')[0]);
    $('body').prepend('<div class="loader"></div>');                    
    $('button[type="submit"]').attr('disabled', 'disabled').css('cursor', 'not-allowed');
    $.ajax({
        url: "<?php echo e(url('admin/sustainability/save')); ?>",
        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 validateEditorValue(selector, errorMessage) {
    const value = tinymce.get(selector).getContent();
    if (!value || value.trim() === "") {
        $('#' + selector).closest('.form-group').find('.tinymce-error').remove();
        $('#' + selector).closest('.form-group').append('<span class="tinymce-error" style="color:red;">' + errorMessage + '</span>');
        return false;
    }
    $('#' + selector).closest('.form-group').find('.tinymce-error').remove();
    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/sustainability.blade.php ENDPATH**/ ?>