define("xwiki-pdf-export-messages",{keys:"core.export.pdf.options.title export.pdf.options.template export.pdf.options.template.hint export.pdf.options.loadFailure export.pdf.generator.checking export.pdf.generator.unavailable export.pdf.generator.checkFailed export.pdf.modal.close export.pdf.inProgress export.pdf.failed export.pdf.lastError export.pdf.canceling export.pdf.canceled export.pdf.cancelFailed export.pdf.loading export.pdf.pageReadyTimeout cancel".split(" ")});
define("xwiki-pdf-export-config",["jquery"],function(c){try{return JSON.parse(c("#pdfExportConfig").text())}catch(l){return console.error(l),{}}});
require("jquery xwiki-meta xwiki-pdf-export-config xwiki-l10n!xwiki-pdf-export-messages xwiki-job-runner bootstrap".split(" "),function(c,l,h,e,u){const k=function(b){let a=c([]);b.cssClass?a=c("\x3cspan\x3e\x3c/span\x3e").addClass(b.cssClass):b.url&&(a=c("\x3cimg/\x3e").attr("src",b.url));return a.addClass("icon")},d=c('\n    \x3cform class\x3d"modal xform" id\x3d"pdfExportOptions" tabindex\x3d"-1" role\x3d"dialog"\n        aria-labelledby\x3d"pdfExportOptionsTitle"\x3e\n      \x3cdiv class\x3d"modal-dialog" role\x3d"document"\x3e\n        \x3cdiv class\x3d"modal-content"\x3e\n          \x3cdiv class\x3d"modal-header"\x3e\n            \x3cbutton type\x3d"button" class\x3d"close" data-dismiss\x3d"modal"\x3e\n              \x3cspan aria-hidden\x3d"true"\x3e\x26times;\x3c/span\x3e\n            \x3c/button\x3e\n            \x3ch4 class\x3d"modal-title" id\x3d"pdfExportOptionsTitle"\x3e\x3c/h4\x3e\n          \x3c/div\x3e\n          \x3cdiv class\x3d"modal-body"\x3e\n            \x3cdiv class\x3d"alert alert-progress"\x3e\x3c/div\x3e\n          \x3c/div\x3e\n          \x3cdiv class\x3d"modal-footer"\x3e\n            \x3cbutton type\x3d"button" class\x3d"btn btn-default" data-dismiss\x3d"modal"\x3e\x3c/button\x3e\n          \x3c/div\x3e\n        \x3c/div\x3e\n      \x3c/div\x3e\n    \x3c/form\x3e\n  ');d.find("button.close").attr({title:e["export.pdf.modal.close"],
"aria-label":e["export.pdf.modal.close"]});d.find(".modal-title").text(e["core.export.pdf.options.title"]).prepend(k(h.icons.pdf));d.find(".btn-default").text(e.cancel);d.on("shown.bs.modal",function(){d.add(".modal-backdrop.in").addClass("fade")});const m=c('\n    \x3cdl\x3e\n      \x3cdt\x3e\n        \x3clabel for\x3d"pdfTemplate"\x3e\x3c/label\x3e\n        \x3cspan class\x3d"xHint"\x3e\x3c/span\x3e\n      \x3c/dt\x3e\n      \x3cdd\x3e\n        \x3cselect id\x3d"pdfTemplate" name\x3d"pdftemplate"\x3e\x3c/select\x3e\n      \x3c/dd\x3e\n    \x3c/dl\x3e\n  ');
m.find("label").text(e["export.pdf.options.template"]);m.find(".xHint").text(e["export.pdf.options.template.hint"]);if(Array.isArray(h.templates)){const b=m.find("select");h.templates.forEach(a=>{c("\x3coption\x3e\x3c/option\x3e").text(a.label).attr("value",a.value).appendTo(b)});b.find("option").first().attr("selected","selected")}const v=function(){if(!h.serverSide)return Promise.resolve();c("body").css("cursor","wait");const b=d.find(".modal-body \x3e .alert").text(e["export.pdf.generator.checking"]).prepend(k(h.icons.spinner));
return fetch(XWiki.currentDocument.getURL("get",c.param({outputSyntax:"plain",sheet:"XWiki.PDFExport.WebHome",data:"serverSidePrintingAvailable"}))).then(a=>a.json()).then(a=>{if(!a.serverSidePrintingAvailable)return Promise.reject(e["export.pdf.generator.unavailable"])}).catch(a=>{b.removeClass("alert-progress").addClass("alert-danger").text(a||e["export.pdf.generator.checkFailed"]).prepend(k(h.icons.error));return Promise.reject(a)}).finally(()=>{c("body").css("cursor","")})},x=function(b,a){d.data("selection",
a);d.removeClass("fade").modal();d.data("state")||(d.attr("data-state","loading"),v().then(()=>w(b),()=>{}))},w=function(b){const a=d.find(".modal-body \x3e .alert").text(e["export.pdf.loading"]).prepend(k(h.icons.spinner));c("\x3cdiv\x3e\x3c/div\x3e").load(b+" #pdfExportOptions",function(){const f=c(this).find("#pdfExportOptions");f.length?(f.find(".buttons").appendTo(d.find(".modal-footer").empty()),f.find("#comments, #attachments").closest("dt").hide().parent().css("margin-bottom","0"),f.find("dl").prepend(m.contents()),
d.attr("action",f.attr("action")),d.find(".modal-body").empty().append(f.contents()),d.attr("data-state","loaded")):a.removeClass("alert-progress").addClass("alert-danger").text(e["export.pdf.options.loadFailure"]).prepend(k(h.icons.error))})};let n=!1;const y=function(b){let a,f;n=new Promise((g,q)=>{a=g;f=q});b.push({name:"outputSyntax",value:"plain"},{name:"sheet",value:"XWiki.PDFExport.WebHome"},{name:"action",value:"export"},{name:"form_token",value:l.form_token},{name:"pdfQueryString",value:window.location.search.substring(1)},
{name:"pdfHash",value:window.location.hash.substring(1)});return Promise.resolve((new u({createStatusRequest:function(g){a(g);return{url:XWiki.currentDocument.getURL("get"),data:{outputSyntax:"plain",sheet:"XWiki.PDFExport.WebHome",data:"jobStatus",jobId:g.join("/")}}}})).run(XWiki.currentDocument.getURL("get"),b)).catch(g=>{f();return Promise.reject(g)}).finally(()=>{n=!1})},z=b=>Promise.resolve(c.post(XWiki.currentDocument.getURL("get"),{outputSyntax:"plain",sheet:"XWiki.PDFExport.WebHome",action:"cancel",
form_token:l.form_token,jobId:b.join("/")})),B=function(b){return new Promise((a,f)=>{const g=c("\x3ciframe/\x3e").css({visibility:"hidden",width:c(window).width()}).on("load",()=>{g[0].contentWindow.require(["xwiki-page-ready"],function(r){setTimeout(()=>{g.remove();f(e["export.pdf.pageReadyTimeout"])},1E3*h.pageReadyTimeout);r.afterPageReady(()=>{r.afterPageReady(()=>{const A=document.title;document.title=g[0].contentDocument.title;g[0].contentWindow.print();g.remove();document.title=A;a()})})})}),
q=XWiki.currentDocument.getURL("export",c.param({format:"html-print",xpage:"get",outputSyntax:"plain",async:!0,sheet:"XWiki.PDFExport.Sheet",jobId:b.join("/")})+"\x26"+window.location.search.substring(1))+window.location.hash;g.attr("src",q).appendTo(c("body"))})},C=function(b){return y(b).then(a=>{if(!a.canceled){if(a.failed||h.serverSide&&!a.pdfFileURL)return Promise.reject(a.lastError);if(a.pdfFileURL)window.location.href=a.pdfFileURL;else return a.lastError&&new XWiki.widgets.Notification(e.get("export.pdf.lastError",
a.lastError),"warning",{timeout:10}),B(a.id)}})};d.on("submit",b=>{b.preventDefault();c("body").css("cursor","wait");const a=new XWiki.widgets.Notification(e["export.pdf.inProgress"],"inprogress");d.find(".modal-footer input[type\x3dsubmit]").prop("disabled",!0);b=d.serializeArray().concat(d.data("selection"));C(b).then(()=>{a.hide()}).catch(f=>{let g=e["export.pdf.failed"];f&&(g+=`: ${f}`);a.replace(new XWiki.widgets.Notification(g,"error"))}).finally(()=>{d.find(".modal-footer input[type\x3dsubmit]").prop("disabled",
!1);c("body").css("cursor","")})});d.on("click","a.secondary.button",b=>{b.preventDefault();d.modal("hide")});d.on("hide.bs.modal",b=>{if(d.find(".modal-header button.close").prop("disabled"))return b.preventDefault();if(n){const a=new XWiki.widgets.Notification(e["export.pdf.canceling"],"inprogress");d.find(".modal-header button.close").prop("disabled",!0);d.find(".modal-footer a.secondary.button").addClass("disabled");n.then(z).then(()=>{a.replace(new XWiki.widgets.Notification(e["export.pdf.canceled"],
"done"))}).catch(()=>{a.replace(new XWiki.widgets.Notification(e["export.pdf.cancelFailed"],"error"))}).finally(()=>{d.find(".modal-header button.close").prop("disabled",!1);d.find(".modal-footer a.secondary.button").removeClass("disabled")});return b.preventDefault()}});const t=function(b,a,f,g){b.preventDefault();b.stopPropagation();a.one("hidden.bs.modal",()=>{a.addClass("fade");x(f,g)}).removeClass("fade").modal("hide")},p=c("#exportTreeModal").on("show.bs.modal",b=>{if("org.xwiki.platform.export.pdf.exportFormats"===
p.data("config").id)c(document).on("submit.export.pdf","form#export-modal-form",a=>{const f=c(a.target);t(a,p,p.data("config").url,f.serializeArray())})});p.on("hide.bs.modal",b=>{c(document).off("submit.export.pdf")});c(".xwiki-select.xwiki-export-formats").on("xwiki:select:updated",function(b){const a=c(this).find(".xwiki-select-option-selected input[name\x3dexportFormat]");"org.xwiki.platform.export.pdf.exportFormats"!==a.val()||c("#exportTreeModal").length||t(b,c("#exportModal"),a.attr("data-url"),
[{name:"pages",value:XWiki.Model.serialize(XWiki.currentDocument.documentReference)}])})});