@extends('Admin.layouts.master')

@section('content')
@php 
  $currentPage = 'manage_cms';
@endphp
        <div class="layout-px-spacing">
            <div class="middle-content container-xxl p-0">
                <div class="row layout-top-spacing ">
                    <div class="top-tabel">
                        <div class="row">
                            <div class="col-md-12 left d-flex align-items-center justify-content-between"
                                style="gap: 15px;">
                                <a class="d-flex align-items-center justify-content-center pl-2"
                                    href="{{ route('manage.aboutUs')}}">
                                    <img class="back-btn" src="{{ asset('public/assets/img/left-arrow.svg')}}">
                                    <h6 class="card-title p-0">Edit Details for customer</h6>
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="col-xl-12 col-lg-12 col-sm-12  layout-spacing">
                        <div class="widget-content widget-content-area br-8 position-btn p-0">
                            <div class="view-details">
                                <div class="simple-tab">
                                    <div class="tab-content" id="myTabContent">
                                        <div class="tab-pane fade show active" id="home-tab-pane" role="tabpanel"
                                            aria-labelledby="home-tab" tabindex="0">
                                            <form id="about_us_form">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <input type="hidden" name="about_custom_id" value="{{ $edit_aboutUs_cust['id'] }}">
                                                    <div id="terms-quill-edit"  value="{{ $edit_aboutUs_cust['description'] }}"  name="about_us" class="editor-quill" style="height: 300px;">{!! $edit_aboutUs_cust['description'] !!}</div>
                                                    <input type="hidden" id="about_us" name="about_us" value="{{ $edit_aboutUs_cust['description'] }}" />  
                                                </div>                                                
                                                <div class="col-md-12">
                                                    <button  type="submit" id="update_about_us" class="download-btn-custom mt-3 custom-width-10" >
                                                        <span>Update</span>
                                                    </button>
                                                </div>
                                            </div>
                                        </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
 
<!-- END MAIN CONTAINER -->



@endsection
@section('section_script')
<script>
    var quill = new Quill('#terms-quill-edit', {
        theme: 'snow'
    });

    // Listen for changes and update the hidden input with the HTML content
    quill.on('text-change', function() {
            var htmlContent = quill.root.innerHTML;
            document.getElementById('privacy_policy').value = htmlContent;
        });
</script>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"></script>
<script>
    $('#update_about_us').on("click", function (e) {
    
    $.validator.addMethod("quillNotEmpty", function(value, element) {
        var quill = new Quill('#terms-quill-edit');
        return quill.getText().trim().length > 0;
    }, "Please enter about us ");
        $('#about_us_form').validate({
            ignore: [],
            debug: false,
            rules: {
                about_us: {
                    required: true,
                    quillNotEmpty: true
                }
            },
            messages: {
                about_us: {
                    required: "Please Enter about us for customer"
                }
            },
            errorClass: 'error-message',
            submitHandler: function (form) {
                var quillContent = quill.root.innerHTML;
                $('#about_us').val(quillContent);base_url = url_path;
                var formData = new FormData(form);

                $.ajaxSetup({
                    headers: {
                        "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                    },
                });
                    $.ajax({
                        url: base_url + '/aboutus_cust_update',
                        type: 'POST',
                        data: formData,
                        processData: false,
                        contentType: false,
                        success: function (response) {
                            if (response.status == 200) {
                                toastr.success('About Us Customer Data Updated Successfully');
                                setTimeout(function () {
                                    window.location.href = base_url + "/manage-about-us";
                                }, 1000);
                            } else {
                                toastr.error("Something went wrong");
                            }
                        },
                    });
            }
        });
    });
    </script>
@endsection