!function(v,e,h){v(function(){v(e).on("click",".convert-envira-gallery-tab-btn",function(e){if(e.preventDefault(),window.confirm(h.bulk_confirmation_alert)){v(".envira-posttype-dropdown-error").hide(),v(".envira-convert-gallery-message").html("").removeClass("success error").hide(),v(".envira-convert-process-logs").html("").hide();const d=v(this);e=d.attr("data-converting");const i=d.attr("title"),c=v("#envira_convert_post_types_dropdown");var r=c.val();if(r){const t=new FormData;t.append("selected_posttype",r),c.attr("disabled",!0),d.attr("disabled",!0),d.html(e),fetch(h.bulk_convert_rest_url,{method:"POST",body:t,headers:{"X-WP-Nonce":h.gallery_convert_rest_nonce}}).then(e=>e.json()).then(e=>{if(e.posts){let t=e.posts,o=t.length,a=0,n=0;function l(){var e=Math.round(a/o*100);v(".envira-convert-progress-bar").css("width",e+"%"),v(".envira-convert-progress-counts").html(e+"%")}v(".envira-convert-gallery-message").addClass("success").html(h.bulk_conversion_started).show(),v(".envira-convert-process-logs").show().html("<p><strong>"+o+" "+h.found_posts_text+'</strong></p><div class="envira-convert-progress-bar-container"><div class="envira-convert-progress-bar"></div></div><div class="envira-convert-progress-counts"></div>'),l(),!function e(){if(a<o){const s=t[a],r=new FormData;r.append("post_id",s),fetch(h.process_item_rest_url,{method:"POST",body:r,headers:{"X-WP-Nonce":h.gallery_convert_rest_nonce}}).then(e=>e.json()).then(r=>{if(r.error){let e="";var t;r.edit_url&&(t=r.edit_url,e=' (<a target="_blank" href="'+t+'" target="_blank">'+h.edit_post_text+"</a>)"),0===n&&v(".envira-convert-process-logs").show().append("<p><strong>"+h.failed_conversion_logs+"</strong></p>"),v(".envira-convert-process-logs").show().append("<p><strong>"+h.post_id_text+" "+s+e+"</strong>: "+r.error+"</p>"),n++}a++,l(),e()}).catch(e=>{v(".envira-convert-gallery-message").addClass("error").html(e).show()})}else l(),v(".envira-convert-gallery-message").addClass("success").html(h.conversion_completed).show(),c.attr("disabled",!1),d.attr("disabled",!1),d.html(i)}()}else c.attr("disabled",!1),d.attr("disabled",!1),d.html(i),v(".envira-convert-gallery-message").addClass("error").html(e.message).show()}).catch(e=>{c.attr("disabled",!1),d.attr("disabled",!1),d.html(i),v(".envira-convert-gallery-message").addClass("error").html(e).show()}).finally(()=>{c.attr("disabled",!1),d.attr("disabled",!1),d.html(i)})}else v(".envira-posttype-dropdown-error").show()}})})}(jQuery,document,envira_gallery_convert);