!function(){"use strict";var t=window.wp.i18n;jQuery(document).ready(function(e){window.jsPDF=window.jspdf.jsPDF;var a=e("#wpbody");a&&a.append('<div class="mf-pdf-wrapper"><div class="mfContentToMakePdf"></div></div>');var r={export_btn:e(".metform-pdf-export-btn")};e.extend(r,{init:function(){this.getEntryData()},getEntryData:function(){var a=this;this.export_btn.on("click",function(r){r.preventDefault(),r.stopPropagation(),r.target.dataset.nonce?(r.target.classList.add("loading"),jQuery.ajax({url:ajaxurl,type:"POST",data:{action:"metform_pdf_get_entry",entry_id:r.target.dataset.id,_wpnonce:r.target.dataset.nonce},success:function(t){var o=e(".mfContentToMakePdf");o&&o.html(t),a.makePdf(r,o[0])},error:function(t,e,a){console.error("Error: "+a),r.target.classList.remove("loading")}})):alert((0,t.__)("Please update MetForm Free too.","metform-pro"))})},makePdf:function(a,r){r.style.width="1000px",r.style.padding="30px",r.style.backgroundColor="#fff",r.style.boxSizing="border-box";var o=r.querySelector("table");o&&(o.style.width="100%",o.style.borderCollapse="collapse"),r.querySelectorAll("img").forEach(function(t){var e=t.getAttribute("src");e&&e.startsWith("image/")&&t.setAttribute("src","data:"+e)}),html2canvas(r,{scale:2,useCORS:!0,logging:!1,width:1e3,windowWidth:1e3,backgroundColor:"#ffffff"}).then(function(t){for(var e=t.toDataURL("image/png",1),r=190*t.height/t.width,o=new jsPDF({orientation:"portrait",unit:"mm",format:"a4",compress:!0}),n=Math.ceil(r/277),i=0;i<n;i++){i>0&&o.addPage();var d=-277*i;o.addImage(e,"PNG",10,10+d,190,r,void 0,"FAST")}o.save("Entry#".concat(a.target.dataset.id,".pdf"))}).catch(function(e){console.error("Error generating PDF:",e),alert((0,t.__)("Failed to generate PDF. Please try again.","metform-pro"))}).finally(function(){a.target.classList.remove("loading"),r.style.width="",r.style.padding="",r.style.backgroundColor="",r.style.boxSizing="";var t=r.querySelector("table");t&&(t.style.width="",t.style.borderCollapse="");var o=e(".mfContentToMakePdf");o&&o.html("")})}}).init()})}();