import{p as wt,b as bt}from"./basicLightbox.min-fae9a810.js";import{S as Lt,a as St}from"./sweetalert2-1045efc7.js";wt.GlobalWorkerOptions.workerSrc="@bundled-es-modules/pdfjs-dist/build/pdf.worker.js";const Et=function(){const z=function(d,m,q){const p={text:d,input:"password",confirmButtonText:"Ok",showCancelButton:!1,allowOutsideClick:!1,allowEscapeKey:!1,inputValidator:function(u){if(!u)return"Password is required"}};St.fire(p).then(function(u){if(u.value&&typeof m=="function"){m(u);return}})};return{initPDFUpload:function(d,{filesGrid:m=null,previewPages:q=!1,allowRotate:p=!0,isSortable:u=!1,allowPreview:_=!0,maxFiles:L=1,maxSize:F=null,fileExtensions:O=null,dropOnBody:W=!1,fileMetadataCallback:J=!1,allowProtectedFiles:j=!0},{extensionsError:K,sizeError:X,filesError:Z,tooManyInvalidAttempts:Q,fileNotSupported:Y},{filePasswordRequired:G=r=>{},fileHasPassword:N=r=>{},onFileChange:tt=r=>{},onInitMeta:et=r=>{}}){let r=[],$=[],y=0;const H=d.querySelector("[type=file]"),M=d.querySelector(".pdf_file__data"),S=d.querySelector("label.file-drag"),A=W?document.body:S,R=d.querySelector(".uploader-wrapper"),nt=document.querySelector(".pdf___more-actions"),D=m?document.querySelector(m):d.querySelector(".files-grid");H.addEventListener("change",U,!1);var at=new XMLHttpRequest;p&&ct(),at.upload&&(A.addEventListener("dragover",T,!1),A.addEventListener("dragleave",T,!1),A.addEventListener("drop",U,!1));function T(t){t.stopPropagation(),t.preventDefault(),t.type==="dragover"?S.classList.add("hover"):S.classList.remove("hover")}function U(t){T(t);var e=t.target.files||t.dataTransfer.files;[...e].forEach(n=>{const a=lt(n);a!==!1&&ot(n,a)}),P(),f()}function it(t){var e=t.name;return new RegExp("(?=.pdf)","gi").test(e)}function rt(t){return t.replace(/^.*?\.([a-zA-Z0-9]+)$/,"$1")}function st(t){return t&&t.type.split("/")[0]==="image"}function k(t){r.splice(t,1),P(),f()}async function ot(t,e){const n=r.findIndex(c=>c.id==e);if(it(t)){let c=0;V(t,E=>{var h=new Uint8Array(E.target.result);const w=pdfjsLib.getDocument(h);w.onPassword=(b,v)=>{if((v==1||v==2)&&c<3&&j){if(N(t)){k(n);return}c++,z(`Password for ${t.name}`,s=>{r[n].password=s.value,b(s.value)})}else c>3&&ArtisanApp.toastError(Q),j||ArtisanApp.toastError(Y),k(n)},w.promise.then(b=>{if(c==0&&G(t)){k(n);return}b.getMetadata().then(function(s){typeof J=="function"&&et(s)});var v=q?b.numPages:1;for(let s=1;s<=v;s++)b.getPage(s).then(function(l){y++;var o=document.createElement("div");o.className=`pdf-preview pdf-file-${e} position-relative is-loading grid-item-${y}${u?" item-sortable":""}`,o.bsToggle="tooltip",o.title=t.name,o.dataset.id=e,o.dataset.index=r.findIndex(ht=>ht.id==e),o.dataset.page=q?s:"all",o.dataset.rotation=0,o.innerHTML=`<div class="item-actions">
                                                        <button type="button" class="btn btn-primary rounded-pill preview-item p-0 action-btn${_?"":" d-none"}"></button>
                                                        <button type="button" class="btn btn-primary rounded-pill rotate-left-item p-0 action-btn${p?"":" d-none"}"></button>
                                                        <button type="button" class="btn btn-primary rounded-pill rotate-right-item p-0 action-btn${p?"":" d-none"}"></button>
                                                        <button type="button" class="btn btn-danger rounded-pill delete-item p-0 action-btn"></button>
                                                    </div>
                                                    <div class="item-pdf d-flex align-items-center justify-content-center position-relative">
                                                        <div class="file-loader"><div class="spinner-grow" role="status"><span class="sr-only">Loading...</span></div></div>
                                                        <canvas class="item-canvas" id="pdf-preview-${e}-${s}" width="150"></canvas>
                                                    </div>
                                                    <div class="content">
                                                        <p>${t.name}</p>
                                                        <span>${y}</span>
                                                    </div>`,o.querySelector(".item-actions .delete-item").addEventListener("click",B),_&&o.querySelector(".item-actions .preview-item").addEventListener("click",dt),p&&(o.querySelector(".item-actions .rotate-left-item").addEventListener("click",I),o.querySelector(".item-actions .rotate-right-item").addEventListener("click",C)),D.appendChild(o),new Tooltip(o,{});var g=document.getElementById(`pdf-preview-${e}-${s}`),mt=145/l.getViewport({scale:1}).width,x=l.getViewport({scale:mt}),yt=g.getContext("2d");g.height=x.height,g.width=x.width,g.style.height=x.height+"px",g.style.width=x.width+"px",l.render({canvasContext:yt,viewport:x}).promise.then(()=>{o.classList.remove("is-loading"),s==v&&f()})})})})}else{var a=`<div class="item-actions">
                                                        <button type="button" class="btn btn-primary rounded-pill rotate-left-item p-0 action-btn${p?"":" d-none"}"></button>
                                                        <button type="button" class="btn btn-primary rounded-pill rotate-right-item p-0 action-btn${p?"":" d-none"}"></button>
                                                        <button type="button" class="btn btn-danger rounded-pill delete-item p-0 action-btn"></button>
                                                    </div>
                                                    <div class="item-pdf overflow-hidden d-flex align-items-center justify-content-center position-relative">
                                                        <div class="file-loader"><div class="spinner-grow" role="status"><span class="sr-only">Loading...</span></div></div>`;st(t)?a+=`<img class="item-canvas" src="${URL.createObjectURL(t)}" />`:a+=`<i class="item-canvas an an-overview display-1 text-muted icon-${rt(t.name)}"></i>`,a+=`</div>
                                                    <div class="content">
                                                        <p>${t.name}</p>
                                                        <p class="fw-normal small mb-0">${ArtisanApp.humanFileSize(t.size)}</p>
                                                    </div>`;var i=document.createElement("div");i.className=`pdf-preview pdf-file-${e} position-relative grid-item-${e}${u?" item-sortable":""}`,i.bsToggle="tooltip",i.title=t.name,i.dataset.id=e,i.dataset.index=r.findIndex(c=>c.id==e),i.dataset.page=1,i.dataset.rotation=0,i.innerHTML=a,i.querySelector(".item-actions .delete-item").addEventListener("click",B),p&&(i.querySelector(".item-actions .rotate-left-item").addEventListener("click",I),i.querySelector(".item-actions .rotate-right-item").addEventListener("click",C)),D.appendChild(i),new Tooltip(i,{})}u&&Lt.create(D,{onUpdate:()=>{f()}})}function V(t,e){var n=new FileReader;n.onload=e,n.readAsArrayBuffer(t)}function dt(t){const e=t instanceof Event?t.target.closest(".pdf-preview"):t;t instanceof Event&&t.preventDefault(),Tooltip.getInstance(e).hide();const n=r[e.dataset.index];n&&V(n.file,a=>{var i=new Uint8Array(a.target.result);const c=pdfjsLib.getDocument(i);c.onPassword=(E,h)=>{h==1&&E(n.password)},c.promise.then(E=>{const h=e.dataset.page=="all"?1:parseInt(e.dataset.page,10);console.log(h),E.getPage(h).then(function(w){var v=(window.screen.availWidth/1.5>500?500:window.screen.availWidth/1.5)/w.getViewport({scale:1}).width,s=w.getViewport({scale:v}),l=document.createElement("canvas"),o=l.getContext("2d");l.height=s.height,l.width=s.width,l.style.height=s.height+"px",l.style.width=s.width+"px";const g=bt.create(`<div class="bg-white shadow pdf-preview-lightbox" id="pdf-preview-lightbox" style="transform:rotate(${e.dataset.rotation}deg)"></div>`);w.render({canvasContext:o,viewport:s}).promise.then(()=>{g.show(),document.querySelector("#pdf-preview-lightbox").appendChild(l)})})})})}function I(t){var e=t instanceof Event?t.target.closest(".pdf-preview"):t;t instanceof Event&&t.preventDefault();const n=parseInt(e.dataset.rotation);var a=n<=0?270:n-90;e.dataset.rotation=a,e.querySelector(".item-canvas").style.transform=`rotate(${a}deg)`,t instanceof Event&&f()}function C(t){var e=t instanceof Event?t.target.closest(".pdf-preview"):t;t instanceof Event&&t.preventDefault();const n=parseInt(e.dataset.rotation);var a=n==270?0:n+90;e.dataset.rotation=a,e.querySelector(".item-canvas").style.transform=`rotate(${a}deg)`,t instanceof Event&&f()}function B(t){t.preventDefault();var e=t.target.closest(".pdf-preview"),n=e.dataset.id,a=r.findIndex(i=>i.id==n);Tooltip.getInstance(e).dispose(),e.remove(),document.querySelectorAll(`.pdf-file-${n}`).length==0&&(r.splice(a,1),P()),f()}function f(){y=0,$=[],document.querySelectorAll(".pdf-preview").forEach(t=>{var e=t.dataset.id,n=r.findIndex(i=>i.id==e);t.dataset.index=n;var a=JSON.parse(JSON.stringify(t.dataset));delete a.bsOriginalTitle,a.password=r[n].password||!1,$.push(a),y++,t.querySelector(".content span")&&(t.querySelector(".content span").innerHTML=y)}),M&&(M.value=JSON.stringify($))}function P(){var e,n,a;m||(r.length==0?(R.classList.remove("d-none"),(e=d.querySelector(".add-more"))==null||e.classList.add("d-none"),(n=d.querySelector(".uploader-after > .process-button"))==null||n.classList.add("d-none"),L>1&&S.classList.remove("pt-0")):(R.classList.add("d-none"),(a=d.querySelector(".uploader-after > .process-button"))==null||a.classList.remove("d-none"),L>1&&S.classList.add("pt-0")));const t=new DataTransfer;r.forEach((i,c)=>{t.items.add(i.file)}),H.files=t.files,tt(r)}function ct(){const t=document.createElement("div");t.innerHTML=`<button type="button" class="btn btn-primary rotate-all-left"><i class="an an-flip-text"></i></button>
                                        <button type="button" class="btn btn-primary rotate-all-right"><i class="an an-flip-wording"></i></button>`,t.querySelector(".rotate-all-right").addEventListener("click",()=>{document.querySelectorAll(".pdf-preview").forEach(e=>{C(e)}),f()}),t.querySelector(".rotate-all-left").addEventListener("click",()=>{document.querySelectorAll(".pdf-preview").forEach(e=>{I(e)}),f()}),nt.appendChild(t)}function lt(t){var e,n,a;if(ft(t)){if(d.querySelector(".uploader-wrapper").classList.add("d-none"),(e=d.querySelector(".uploader-error"))==null||e.classList.add("d-none"),gt()){L!=1&&((n=d.querySelector(".add-more"))==null||n.classList.remove("d-none"));const i=pt();return r.push({id:i,file:t}),i}return!1}else return(a=d.querySelector(".uploader-error"))==null||a.classList.remove("d-none"),d.querySelector("label.file-drag").classList.remove("d-none"),!1}function pt(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}function ft(t){return ut(t)&&vt(t)}function ut(t){var e=t.name;const n=new RegExp(`(?=${O})`,"gi"),a=!O||n.test(e);return a||ArtisanApp.toastError(K),a}function vt(t){const e=!F||t.size<=F*1024*1024;return e||ArtisanApp.toastError(X),e}function gt(){const t=!L||r.length<L;return t||ArtisanApp.toastError(Z),t}}}}();window.PDFApp=Et;
