'use strict';function f(a){return new Promise(b=>{b(JSON.parse(a))})}function h(a){return new Promise((b,e)=>{var c=new XMLHttpRequest;c.onreadystatechange=function(){4===c.readyState&&(2===Math.floor(c.status/100)?b(c.responseText):e(c.statusText))};c.open("GET",a,!0);c.send()})};function l(){this.c=document.createElement("div");var a=document.createElement("div");a.classList.add("popin-overlay");this.c.appendChild(a);a=document.createElement("div");a.classList.add("popin-container");this.c.appendChild(a);this.b=document.createElement("div");this.b.className="popin-img";this.f=document.createElement("img");this.f.src="/images/loading.svg";this.b.appendChild(this.f);a.appendChild(this.b);a.addEventListener("click",(()=>{this.c.remove()}).bind(this));this.b.addEventListener("click",
a=>a.stopPropagation());this.a=new XMLHttpRequest;this.a.responseType="blob";this.a.onreadystatechange=(()=>{4===this.a.readyState&&(2===Math.floor(this.a.status/100)&&this.a.response?this.f.src=window.URL.createObjectURL(this.a.response):console.error("Cannot get resource",this.a.status))}).bind(this)};function m(a){this.data=void 0;this.error=null;var b=this;this.a=new Promise(e=>{h("/book/"+a+"/info.json").then(f).then(a=>{b.data={title:a.title,g:a.author,identifier:a.identifier,h:a.pageCount};e(b)}).catch(c=>{console.error("Cannot get data from book "+a,c);b.data=null;this.error=c;e(b)})});this.b=()=>{}}
function n(a,b,e,c){var d=document.createElement("label"),k=document.createElement("span");a:{switch(c){case "text":case "number":var g=document.createElement("input");g.type=c;g.value=e||("text"==c?"":0);g.name=a;a=g;break a}a=null}k.textContent=b;d.appendChild(k);d.appendChild(a);return d};window.displayCover=function(a){var b=new l;document.body.appendChild(b.c);a="/book/"+a+"/read/1.png";0!==b.a.readyState&&4!==b.a.readyState&&b.a.abort();b.a.open("GET",a,!0);b.a.send()};
window.editDocument=function(a){var b=new l;a=new m(a);document.body.appendChild(b.c);a.a.then(a=>{var c=document.createDocumentFragment();if(a.error){var d=document.createElement("div");d.className="error";d.textContent=a.error;c.appendChild(d)}else c.appendChild(n("title","Titre",a.data.title,"text")),c.appendChild(n("author","Auteur",a.data.g,"text")),c.appendChild(n("pageCount","Nombre de pages",a.data.h,"number")),c.appendChild(n("identifier","Identifiant",a.data.identifier,"text"));b.f.remove();
b.b.className="popin-dom";b.b.appendChild(c)});a.b=()=>{b.c.remove()}};
