jQuery(document).ready(function () {
    // if ( jQuery('#first_name').val() != '' || jQuery('#last_name').val() != '' || jQuery('#dob').val() != '') {     
    //     jQuery("#first_name").prop("readonly", true);
    //     jQuery("#last_name").prop("readonly", true);
    //     jQuery("#dob").prop("readonly", true);
    // }


    // jQuery(function () {
    //     jQuery('[data-toggle="tooltip"]').tooltip()
    // })
    var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-toggle="tooltip"]'))
    var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl)
    })


    jQuery('#imageUpload').on('change', function () {
        var fileInput = jQuery('#imageUpload')[0].files;
        console.log(fileInput);
        if (fileInput.length > 0) {
            var formData = new FormData();

            formData.append('profile-image', fileInput[0]);
            formData.append('action', 'handle_profile_image_upload');

            jQuery.ajax({
                type: 'POST',
                url: '/wp-admin/admin-ajax.php',
                data: formData,
                processData: false,
                contentType: false,
                success: function (response) {
                    window.location.reload();
                }
            });
        }
    });


    // Delete Image
    jQuery(document).on('click', '.remove-btn', function() {
         
         jQuery('.preloader').fadeIn('500');
           
        var dataId = jQuery(this).attr('data-image_id');
        var post_id = jQuery(this).attr('data-post_id');
        var image_status = jQuery(this).attr('data-image_status');
        var img_count = jQuery('#img_count').val();
        var field_id = jQuery(this).attr('data-field_index');
        // console.log('field_id=='+field_id);
        
        var confirmed = confirm("Are you sure you want to Delete Image");
         
        if (confirmed) {
            $(this).closest('.wrapper-thumb').remove();
            jQuery.ajax({
                type: "POST",
                url: "/wp-admin/admin-ajax.php",
                dataType: 'json',
                data: {
                    action: 'legal_documents_image_delete',
                    dataId: dataId,
                    post_id: post_id,
                    image_status: image_status,
                    img_count:img_count,
                    field_id:field_id
                },
                success: function (files) {
                     var img_count = files['img_count'];
                      if (img_count > 5) {
                     jQuery('#file-input').prop('disabled', true);
                     }else{
                      jQuery('#file-input').removeAttr('disabled');
                     }                    
                    jQuery('#img_count').val(img_count);
                    
                    jQuery('.preloader').fadeOut('200');
                }

            });
            
        } 
        
    });
    // Delete Image


    jQuery('.mysidebar').click(function () {
        jQuery('.profile-sidebar').addClass('show');

    })
    jQuery('.menu-closes').click(function () {
        jQuery('.profile-sidebar').removeClass('show');

    })


    // My reviews
    var id = [];
    jQuery('.rating-value').each(function () {
        id.push(parseInt(jQuery(this).val())); // Use .text() to get the text content of the element
    });
    console.log(id);

    jQuery.each(id, function (index, value) {
        setStars(value);
    });

    function setStars(rating) {
        jQuery('.star_set_' + rating).css('color', '#ccc'); // Reset all stars
        jQuery('.star_set_' + rating).slice(0, rating).css('color', 'gold'); // Highlight up to the selected rating
    }


    jQuery(document).on('click', '.btn_orange', function () { 
        var value_update = jQuery(this).data('value_update');
        var client_id = jQuery(this).data('client_id');
        var theap_id = jQuery(this).data('theap_id');
        var id = jQuery(this).data('id');

        var confirmed = confirm("Are you sure Approved this Review");
        if (confirmed) {
            jQuery.ajax({
                type: "POST",
                url: "/wp-admin/admin-ajax.php",
                data: {
                    action: 'approved_review_therapist',
                    id: id,
                    client_id: client_id,
                    theap_id: theap_id,
                    value_update: value_update,

                },
                success: function (data) {
                    console.log(data);
                    window.location.reload();
                }
            });
        }
    })

    jQuery('.sub-menu #menu-item-538').on('click',function(){
        jQuery('#menu-item-538 a').attr('target', '_blank');
           
   })

})