1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8206],{68206:(e,t,n)=>{n.r(t),n.d(t,{default:()=>W});var r=n(16927),o=n(45526),a=n(67684),i=n(62701),s=n(20294),l=n(85993),c=n(95531),u=n(37876),d=n(14232),f=n(81485),h=n(40248);function g(e){return"".concat("https://api.mindomax.com/v1","/file-folder/files/").concat(e,"/reading-position")}function m(e){if(!e)return null;var t=Number(e.page),n=Number(e.client_updated_at_ms);if(!Number.isInteger(t)||t<1||!Number.isFinite(n)||n<0)return null;var r=Number(e.page_count);return{page:t,page_count:Number.isInteger(r)&&r>=1?r:null,client_updated_at_ms:n}}function p(e){if(!e)return null;try{return m(JSON.parse(localStorage.getItem(e)))}catch(e){return null}}function x(e,t){if(e)try{localStorage.setItem(e,JSON.stringify(t))}catch(e){}}var v=n(2425),b=n(98778);function y(){var e=new Uint8Array(20);return crypto.getRandomValues(e),Array.from(e,function(e){return e.toString(16).padStart(2,"0")}).join("")}function w(e){var t=e.pdfDocument,o=e.pageNumber,f=e.zoom,h=e.activeTool,g=e.drawColor,m=e.strokeWidth,p=e.annotations,x=e.onAnnotationAdd,w=e.onAnnotationDelete,_=e.selectedId,j=e.onSelect,k=e.fontSize,N=e.onAnnotationUpdate,C=(0,v.B)().t,P=(0,d.useRef)(null),S=(0,d.useRef)(null),E=(0,d.useRef)(null),D=(0,d.useRef)(null),A=(0,d.useRef)(null),L=(0,s._)((0,d.useState)({width:0,height:0}),2),z=L[0],T=L[1],R=(0,s._)((0,d.useState)(!1),2),F=R[0],M=R[1],B=(0,s._)((0,d.useState)([]),2),Y=B[0],I=B[1],U=(0,s._)((0,d.useState)(null),2),W=U[0],X=U[1],O=(0,s._)((0,d.useState)(null),2),H=O[0],V=O[1],K=(0,d.useRef)(null);(0,d.useEffect)(function(){if(t&&S.current){var e=!1;return(0,r._)(function(){var a,i,s,l,u,d,h,g,m;return(0,c.YH)(this,function(p){switch(p.label){case 0:return p.trys.push([0,3,,4]),[4,t.getPage(o)];case 1:if(a=p.sent(),e)return[2];return s=(i=a.getViewport({scale:2*f})).width/2,l=i.height/2,(u=S.current).width=i.width,u.height=i.height,u.style.width=s+"px",u.style.height=l+"px",T({width:s,height:l}),K.current&&K.current.cancel(),d=u.getContext("2d"),K.current=h=a.render({canvasContext:d,viewport:i}),(0,r._)(function(){var t,r,o,i,s,l;return(0,c.YH)(this,function(c){switch(c.label){case 0:if(!(o=E.current)||e)return[2];return null==(t=D.current)||t.cancel(),D.current=null,null==(r=A.current)||r.call(A),A.current=null,o.replaceChildren(),[4,n.e(8233).then(n.bind(n,53553))];case 1:if(i=c.sent().TextLayer,e)return[2];return s=a.getViewport({scale:f}),o.style.setProperty("--scale-factor",String(s.scale)),o.style.setProperty("--user-unit",String(s.userUnit||1)),D.current=l=new i({textContentSource:a.streamTextContent({includeMarkedContent:!0,disableNormalization:!0}),container:o,viewport:s}),[4,l.render()];case 2:var u,d,h,g,m,p,x,v;if(c.sent(),e||D.current!==l)return[2];return u=o,(d=document.createElement("div")).className="endOfContent",u.append(d),g={signal:(h=new AbortController).signal},m="undefined"!=typeof navigator&&/firefox/i.test(navigator.userAgent),p=!1,x=null,v=function(){u.append(d),d.style.width="",d.style.height="",d.style.userSelect="",u.classList.remove("selecting")},u.addEventListener("mousedown",function(){return u.classList.add("selecting")},g),document.addEventListener("pointerdown",function(){p=!0},g),document.addEventListener("pointerup",function(){p=!1,v()},g),window.addEventListener("blur",function(){p=!1,v()},g),document.addEventListener("keyup",function(){p||v()},g),document.addEventListener("selectionchange",function(){var e,t=document.getSelection();if(!t||0===t.rangeCount)return void v();for(var n=!1,r=0;r<t.rangeCount;r++)t.getRangeAt(r).intersectsNode(u)&&(n=!0);if(!n)return void v();if(u.classList.add("selecting"),!m){var o=t.getRangeAt(0),a=x&&(0===o.compareBoundaryPoints(Range.END_TO_END,x)||0===o.compareBoundaryPoints(Range.START_TO_END,x)),i=a?o.startContainer:o.endContainer;if(i.nodeType===Node.TEXT_NODE&&(i=i.parentNode),!a&&0===o.endOffset)do{for(;i&&i!==u&&!i.previousSibling;)i=i.parentNode;if(!i||i===u)break;i=i.previousSibling}while(!i.childNodes.length);i&&i!==u&&(null==(e=i.parentElement)?void 0:e.closest(".textLayer"))===u&&(d.style.width=u.style.width,d.style.height=u.style.height,d.style.userSelect="text",i.parentElement.insertBefore(d,a?i:i.nextSibling)),x=o.cloneRange()}},g),A.current=function(){h.abort(),d.remove(),u.classList.remove("selecting")},[2]}})})().catch(function(){}),[4,h.promise];case 2:return p.sent(),[3,4];case 3:if("RenderingCancelledException"===(g=p.sent()).name||(null==(m=g.message)?void 0:m.includes("destroy")))return[2];throw g;case 4:return[2]}})})(),function(){var t,n;e=!0,null==(t=D.current)||t.cancel(),D.current=null,null==(n=A.current)||n.call(A),A.current=null}}},[t,o,f]);var Z=(0,d.useCallback)(function(e){if("text"===h&&!W&&"TEXTAREA"!==e.target.tagName){var t=P.current;if(t){var n=t.getBoundingClientRect();X({x:(e.clientX-n.left)/n.width,y:(e.clientY-n.top)/n.height,text:""})}}},[h,W]),J=(0,d.useCallback)(function(e){if("draw"===h){var t=e.currentTarget,n=t.getBoundingClientRect(),r=(e.clientX-n.left)/n.width,o=(e.clientY-n.top)/n.height;M(!0),I([{x:r,y:o}]),t.setPointerCapture(e.pointerId)}},[h]),G=(0,d.useCallback)(function(e){if(F){var t=e.currentTarget.getBoundingClientRect(),n=(e.clientX-t.left)/t.width,r=(e.clientY-t.top)/t.height;I(function(e){return(0,l._)(e).concat([{x:n,y:r}])})}},[F]),q=(0,d.useCallback)(function(){if(F){if(M(!1),Y.length<2)return void I([]);x({annotation_ugid:y(),page_number:o,annotation_type:"drawing",color:g,data:{points:Y,strokeWidth:m}}),I([])}},[F,Y,g,m,o,x]),$=(0,d.useCallback)(function(){if(!W||!W.text.trim())return void X(null);x({annotation_ugid:y(),page_number:o,annotation_type:"text",color:g,data:{x:W.x,y:W.y,text:W.text,fontSize:k}}),X(null)},[W,g,k,o,x]),Q=function(e){return!e||e.length<2?"":e.map(function(e,t){return"".concat(0===t?"M":"L"," ").concat(e.x," ").concat(e.y)}).join(" ")},ee=function(e,t){e.stopPropagation(),"select"===h&&j(_===t?null:t)};(0,d.useEffect)(function(){var e=function(e){("Delete"===e.key||"Backspace"===e.key)&&_&&(["INPUT","TEXTAREA"].includes(e.target.tagName)||(e.preventDefault(),w(_),j(null)))};return window.addEventListener("keydown",e),function(){return window.removeEventListener("keydown",e)}},[_,w,j]);var et=(0,d.useCallback)(function(e,t){"select"===h&&(e.preventDefault(),e.stopPropagation(),V({ugid:t.annotation_ugid,startX:e.clientX,startY:e.clientY,origX:t.data.x,origY:t.data.y,moved:!1}))},[h]);(0,d.useEffect)(function(){if(H){var e=function(e){var t=P.current;if(t){var n=t.getBoundingClientRect(),r=(e.clientX-H.startX)/n.width,o=(e.clientY-H.startY)/n.height;(Math.abs(r)>.005||Math.abs(o)>.005)&&V(function(e){return(0,i._)((0,a._)({},e),{currentX:Math.max(0,Math.min(.95,e.origX+r)),currentY:Math.max(0,Math.min(.95,e.origY+o)),moved:!0})})}},t=function(){H.moved&&void 0!==H.currentX?N(H.ugid,{x:H.currentX,y:H.currentY}):j(_===H.ugid?null:H.ugid),V(null)};return window.addEventListener("pointermove",e),window.addEventListener("pointerup",t),function(){window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",t)}}},[H,N,j,_]);var en="draw"===h?"all":"none",er=m>=.04,eo="draw"===h?"none":"auto";return(0,u.jsxs)("div",{ref:P,className:"relative inline-block max-w-full",style:{width:z.width||"auto",height:z.height||"auto",cursor:"text"===h?"text":"default",touchAction:eo},onClick:Z,children:[(0,u.jsx)("canvas",{ref:S,className:"block"}),(0,u.jsx)("div",{ref:E,className:"textLayer ".concat("select"===h?"":"pointer-events-none")}),(0,u.jsxs)("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",className:"absolute top-0 left-0 w-full h-full",style:{pointerEvents:en},onPointerDown:J,onPointerMove:G,onPointerUp:q,children:[(p||[]).filter(function(e){return"drawing"===e.annotation_type}).map(function(e){return(0,u.jsx)("path",{d:Q(e.data.points),fill:"none",stroke:e.color,strokeWidth:e.data.strokeWidth||.003,strokeLinecap:"round",strokeLinejoin:"round",opacity:(e.data.strokeWidth||0)>=.04?.4:1,className:"cursor-pointer",style:{filter:_===e.annotation_ugid?"drop-shadow(0 0 0.005px #3B82F6)":"none",pointerEvents:"select"===h?"all":"none"},onClick:function(t){return ee(t,e.annotation_ugid)}},e.annotation_ugid)}),F&&Y.length>1&&(0,u.jsx)("path",{d:Q(Y),fill:"none",stroke:g,strokeWidth:m,strokeLinecap:"round",strokeLinejoin:"round",opacity:er?.4:.7})]}),(p||[]).filter(function(e){return"text"===e.annotation_type}).map(function(e){var t=H&&H.ugid===e.annotation_ugid&&H.moved,n=t?H.currentX:e.data.x,r=t?H.currentY:e.data.y,o=_===e.annotation_ugid&&"select"===h;return(0,u.jsxs)("div",{dir:"auto",className:"absolute select-none",style:{left:100*n+"%",top:100*r+"%",color:e.color,fontSize:(e.data.fontSize||.025)*z.height+"px",lineHeight:1.2,zIndex:o?20:10,pointerEvents:"select"===h?"auto":"none",outline:o?"2px solid #3B82F6":"none",whiteSpace:"pre-wrap",maxWidth:(1-n)*100+"%",cursor:"select"===h?"grab":"default"},onPointerDown:function(t){return et(t,e)},children:[o&&(0,u.jsx)("button",{className:"absolute -top-8 left-0 bg-red-500 hover:bg-red-600 text-white rounded-full w-7 h-7 flex items-center justify-center shadow-lg",style:{zIndex:30},onPointerDown:function(e){return e.stopPropagation()},onClick:function(t){t.stopPropagation(),w(e.annotation_ugid),j(null)},children:(0,u.jsx)(b.b6i,{size:16})}),e.data.text]},e.annotation_ugid)}),W&&(0,u.jsx)("textarea",{dir:"auto",className:"absolute border-2 border-blue-400 rounded outline-none resize-none",style:{left:100*W.x+"%",top:100*W.y+"%",color:g,fontSize:k*z.height+"px",lineHeight:1.2,zIndex:20,minWidth:"120px",minHeight:"40px",maxWidth:(1-W.x)*100+"%",backgroundColor:"rgba(255, 255, 255, 0.9)",padding:"4px 6px"},autoFocus:!0,value:W.text,onChange:function(e){return X(function(t){return(0,i._)((0,a._)({},t),{text:e.target.value})})},onBlur:$,onKeyDown:function(e){"Enter"!==e.key||e.shiftKey||(e.preventDefault(),$()),"Escape"===e.key&&X(null)},placeholder:C("folders.pdfTextPlaceholder")})]})}var _=["#FFFF00","#00FF00","#00BFFF","#A855F7","#EF4444"],j=[.1,.15,.2,.25,.3,.4,.5,.75,1,1.25,1.5,1.75,2,2.25,2.5,2.75,3],k=function(e){var t=j.filter(function(t){return t<e-.001});return t.length?t[t.length-1]:j[0]},N=function(e){var t=j.find(function(t){return t>e+.001});return null!=t?t:j[j.length-1]},C=[{value:.002,px:4},{value:.006,px:8},{value:.015,px:14},{value:.04,px:22}],P=[{value:.015,label:"S"},{value:.025,label:"M"},{value:.035,label:"L"},{value:.05,label:"XL"}];function S(e){var t=e.currentPage,n=e.numPages,r=e.zoom,o=e.activeTool,a=e.drawColor,i=e.strokeWidth,s=e.isDirty,l=e.onPageChange,c=e.onZoomChange,d=e.onToolChange,f=e.onColorChange,h=e.onStrokeWidthChange,g=e.onSave,m=e.onClose,p=e.onDownload,x=e.onDeleteSelected,y=e.hasSelection,w=e.fileName,j=e.onAddPageBefore,S=e.onAddPageAfter,E=e.fontSize,D=e.onFontSizeChange,A=e.onUndo,L=e.canUndo,z=e.onDeleteCurrentPage,T=e.canDeletePage,R=e.onTogglePageManager,F=(0,v.B)().t;return(0,u.jsxs)("div",{className:"bg-gray-800 border-b border-gray-700",children:[(0,u.jsxs)("div",{className:"flex items-center justify-between flex-wrap px-1.5 sm:px-3 py-1 sm:py-2 gap-1 sm:gap-2",children:[(0,u.jsx)("div",{className:"text-sm text-gray-300 truncate max-w-[160px] hidden sm:block",title:w,children:w}),(0,u.jsxs)("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[(0,u.jsx)("button",{onClick:function(){return l(t-1)},disabled:t<=1,className:"p-1 sm:p-1 rounded hover:bg-gray-700 text-gray-400 hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:(0,u.jsx)(b.E_E,{size:20})}),(0,u.jsxs)("span",{className:"text-xs text-gray-300 min-w-[36px] sm:min-w-[60px] text-center",children:[(0,u.jsxs)("span",{className:"hidden sm:inline",children:[F("folders.pdfPage")," "]}),t,"/",n]}),(0,u.jsx)("button",{onClick:function(){return l(t+1)},disabled:t>=n,className:"p-1 sm:p-1 rounded hover:bg-gray-700 text-gray-400 hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:(0,u.jsx)(b.xVu,{size:20})})]}),(0,u.jsxs)("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[(0,u.jsx)("button",{onClick:function(){return c(k(r))},disabled:r<=.1,className:"p-1 sm:p-1 rounded hover:bg-gray-700 text-gray-400 hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:(0,u.jsx)(b.f5Z,{size:18})}),(0,u.jsxs)("span",{className:"text-xs text-gray-300 min-w-[32px] sm:min-w-[40px] text-center",children:[Math.round(100*r),"%"]}),(0,u.jsx)("button",{onClick:function(){return c(N(r))},disabled:r>=3,className:"p-1 sm:p-1 rounded hover:bg-gray-700 text-gray-400 hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:(0,u.jsx)(b.gff,{size:18})})]}),(0,u.jsxs)("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[(0,u.jsx)("button",{onClick:A,disabled:!L,className:"p-1 sm:p-1.5 rounded transition-colors ".concat(L?"hover:bg-gray-700 text-gray-400 hover:text-white":"text-gray-500 cursor-not-allowed"),title:F("folders.pdfUndo"),children:(0,u.jsx)(b.omt,{size:18})}),(0,u.jsx)("button",{onClick:g,disabled:!s,className:"p-1 sm:p-1.5 rounded transition-colors ".concat(s?"bg-blue-600 text-white hover:bg-blue-700":"text-gray-500 cursor-not-allowed"),title:F("folders.pdfSave"),children:(0,u.jsx)(b.rZB,{size:18})}),(0,u.jsx)("button",{onClick:p,className:"p-1 sm:p-1.5 rounded hover:bg-gray-700 text-gray-400 hover:text-white transition-colors",title:F("folders.download"),children:(0,u.jsx)(b.E5v,{size:18})}),(0,u.jsx)("button",{onClick:m,className:"p-1 sm:p-1.5 rounded hover:bg-gray-700 text-gray-400 hover:text-white transition-colors",children:(0,u.jsx)(b.m6K,{size:18})})]})]}),(0,u.jsxs)("div",{className:"flex items-center px-1.5 sm:px-3 py-1 gap-1 sm:gap-2 border-t border-gray-700/50 flex-wrap",children:[(0,u.jsxs)("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[(0,u.jsx)("button",{onClick:function(){return d("select")},className:"p-1.5 rounded transition-colors ".concat("select"===o?"bg-blue-600 text-white":"hover:bg-gray-700 text-gray-400 hover:text-white"),title:F("folders.pdfSelect"),children:(0,u.jsx)(b.g9Y,{size:18})}),(0,u.jsx)("button",{onClick:function(){return d("draw")},className:"p-1.5 rounded transition-colors ".concat("draw"===o?"bg-blue-600 text-white":"hover:bg-gray-700 text-gray-400 hover:text-white"),title:F("folders.pdfDraw"),children:(0,u.jsx)(b.Cbc,{size:18})}),(0,u.jsx)("button",{onClick:function(){return d("text")},className:"p-1.5 rounded transition-colors ".concat("text"===o?"bg-blue-600 text-white":"hover:bg-gray-700 text-gray-400 hover:text-white"),title:F("folders.pdfText"),children:(0,u.jsx)(b.Gfv,{size:18})})]}),R&&(0,u.jsxs)("div",{className:"flex items-center gap-0.5 sm:gap-1 border-l border-gray-600 pl-1.5 sm:pl-2",children:[(0,u.jsx)("button",{onClick:j,className:"p-1 rounded hover:bg-gray-700 text-gray-400 hover:text-white transition-colors",title:F("folders.pdfAddPageBefore"),children:(0,u.jsx)(b.ruO,{size:16,className:"sm:w-[18px] sm:h-[18px]"})}),(0,u.jsx)("button",{onClick:S,className:"p-1 rounded hover:bg-gray-700 text-gray-400 hover:text-white transition-colors",title:F("folders.pdfAddPageAfter"),children:(0,u.jsx)(b.ruO,{size:16,className:"sm:w-[18px] sm:h-[18px]",style:{transform:"scaleX(-1)"}})}),(0,u.jsx)("button",{onClick:z,disabled:!T,className:"p-1 rounded hover:bg-red-600/30 text-gray-400 hover:text-red-400 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:F("folders.pdfDeletePage"),children:(0,u.jsx)(b.kgr,{size:16,className:"sm:w-[18px] sm:h-[18px]"})}),(0,u.jsx)("button",{onClick:R,className:"p-1 rounded hover:bg-gray-700 text-gray-400 hover:text-white transition-colors",title:F("folders.pdfPageManager"),children:(0,u.jsx)(b.R6h,{size:16,className:"sm:w-[18px] sm:h-[18px]"})})]}),("draw"===o||"text"===o)&&(0,u.jsx)("div",{className:"flex items-center gap-0.5 sm:gap-1 border-l border-gray-600 pl-1.5 sm:pl-2",children:_.map(function(e){return(0,u.jsx)("button",{onClick:function(){return f(e)},className:"w-5 h-5 rounded-full border-2 transition-all ".concat(a===e?"border-white scale-110":"border-gray-600 hover:border-gray-400"),style:{backgroundColor:e}},e)})}),"draw"===o&&(0,u.jsx)("div",{className:"flex items-center gap-1 sm:gap-1.5 border-l border-gray-600 pl-1.5 sm:pl-2",children:C.map(function(e){return(0,u.jsx)("button",{onClick:function(){return h(e.va
1lue)},className:"flex items-center justify-center w-6 h-6 sm:w-7 sm:h-7 rounded transition-all ".concat(i===e.value?"bg-gray-600 ring-1 ring-white":"hover:bg-gray-700"),children:(0,u.jsx)("span",{className:"rounded-full bg-gray-300",style:{width:e.px,height:e.px}})},e.value)})}),"text"===o&&(0,u.jsx)("div",{className:"flex items-center gap-0.5 sm:gap-1 border-l border-gray-600 pl-1.5 sm:pl-2",children:P.map(function(e){return(0,u.jsx)("button",{onClick:function(){return D(e.value)},className:"px-1.5 py-0.5 rounded text-xs transition-all ".concat(E===e.value?"bg-gray-600 text-white ring-1 ring-white":"text-gray-400 hover:bg-gray-700 hover:text-white"),children:e.label},e.value)})}),y&&(0,u.jsx)("button",{onClick:x,className:"p-1.5 rounded hover:bg-red-600/30 text-red-400 hover:text-red-300 transition-colors border-l border-gray-600 pl-1.5 sm:pl-2",title:"Delete",children:(0,u.jsx)(b.b6i,{size:18})})]})]})}var E=n(45267);function D(e){var t=e.pdfDocument,n=e.numPages,f=e.currentPage,h=e.onPageSelect,g=e.onDeletePage,m=e.onReorderPages,p=e.onClose,x=(0,v.B)().t,y=(0,s._)((0,d.useState)({}),2),w=y[0],_=y[1],j=(0,s._)((0,d.useState)(function(){return Array.from({length:n},function(e,t){return t+1})}),2),k=j[0],N=j[1],C=(0,s._)((0,d.useState)(null),2),P=C[0],S=C[1],D=(0,s._)((0,d.useState)(null),2),A=D[0],L=D[1],z=(0,s._)((0,d.useState)(!1),2),T=z[0],R=z[1],F=(0,d.useRef)(null),M=(0,d.useRef)({}),B=(0,d.useRef)(null),Y=(0,d.useRef)(!1);(0,d.useEffect)(function(){N(Array.from({length:n},function(e,t){return t+1}))},[n]),(0,d.useEffect)(function(){if(t){var e=!1;return(0,r._)(function(){var r,s,l,u,d;return(0,c.YH)(this,function(f){switch(f.label){case 0:r=function(n){var r,u,d,f;return(0,c.YH)(this,function(c){switch(c.label){case 0:if(e)return[2,{v:void 0}];c.label=1;case 1:return c.trys.push([1,4,,5]),[4,t.getPage(n)];case 2:return u=(r=c.sent()).getViewport({scale:.3}),s.width=u.width,s.height=u.height,l.clearRect(0,0,s.width,s.height),[4,r.render({canvasContext:l,viewport:u}).promise];case 3:return c.sent(),d=s.toDataURL(),e||_(function(e){return(0,i._)((0,a._)({},e),(0,o._)({},n,d))}),[3,5];case 4:if(null==(f=c.sent().message)?void 0:f.includes("destroy"))return[2,{v:void 0}];return[3,5];case 5:return[2]}})},l=(s=document.createElement("canvas")).getContext("2d"),u=1,f.label=1;case 1:if(!(u<=n))return[3,4];return[5,(0,c.Ju)(r(u))];case 2:if(d=f.sent(),"object"===(0,E._)(d))return[2,d.v];f.label=3;case 3:return u++,[3,1];case 4:return[2]}})})(),function(){e=!0}}},[t,n]);var I=k.some(function(e,t){return e!==t+1}),U=(0,d.useCallback)(function(e){e<=0||N(function(t){var n,r=(0,l._)(t);return n=[r[e],r[e-1]],r[e-1]=n[0],r[e]=n[1],r})},[]),W=(0,d.useCallback)(function(e){N(function(t){if(e>=t.length-1)return t;var n,r=(0,l._)(t);return n=[r[e+1],r[e]],r[e]=n[0],r[e+1]=n[1],r})},[]),X=(0,d.useCallback)(function(){return(0,r._)(function(){return(0,c.YH)(this,function(e){switch(e.label){case 0:if(!I)return p(),[2];R(!0),e.label=1;case 1:return e.trys.push([1,,3,4]),[4,m(k)];case 2:return e.sent(),[3,4];case 3:return R(!1),[7];case 4:return[2]}})})()},[I,k,m,p]),O=(0,d.useCallback)(function(e){return(0,r._)(function(){return(0,c.YH)(this,function(t){switch(t.label){case 0:if(n<=1)return[2];R(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,g(e)];case 2:return t.sent(),[3,4];case 3:return R(!1),[7];case 4:return[2]}})})()},[n,g]),H=(0,d.useCallback)(function(e,t){e.preventDefault(),S(t),L(t)},[]),V=(0,d.useCallback)(function(e){if(null!==P&&F.current){var t=F.current.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top+F.current.scrollTop,o=P,a=1/0,i=!0,l=!1,c=void 0;try{for(var u,d=Object.entries(M.current)[Symbol.iterator]();!(i=(u=d.next()).done);i=!0){var f=(0,s._)(u.value,2),h=f[0],g=f[1];if(g){var m=g.getBoundingClientRect(),p=m.left+m.width/2-t.left,x=m.top+m.height/2-t.top+F.current.scrollTop,v=Math.abs(n-p)+Math.abs(r-x);
1v<a&&(a=v,o=parseInt(h))}}}catch(e){l=!0,c=e}finally{try{i||null==d.return||d.return()}finally{if(l)throw c}}L(o)}},[P]),K=(0,d.useCallback)(function(){null!==P&&null!==A&&P!==A&&N(function(e){var t=(0,l._)(e),n=(0,s._)(t.splice(P,1),1)[0];return t.splice(A,0,n),t}),S(null),L(null)},[P,A]),Z=(0,d.useCallback)(function(e,t){"mouse"!==e.pointerType||0!==e.button||T||(B.current={index:t,x:e.clientX,y:e.clientY},Y.current=!1)},[T]);return(0,d.useEffect)(function(){var e=function(e){var t=B.current;t&&(Math.abs(e.clientX-t.x)+Math.abs(e.clientY-t.y)<6||(B.current=null,Y.current=!0,S(t.index),L(t.index)))},t=function(){B.current=null};return window.addEventListener("pointermove",e),window.addEventListener("pointerup",t),function(){window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",t)}},[]),(0,d.useEffect)(function(){if(null!==P){var e=function(){return K()};return window.addEventListener("pointerup",e),window.addEventListener("pointermove",V),function(){window.removeEventListener("pointerup",e),window.removeEventListener("pointermove",V)}}},[P,K,V]),(0,d.useEffect)(function(){var e=document.body.style.overflow;return document.body.style.overflow="hidden",function(){document.body.style.overflow=e}},[]),(0,u.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,u.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:p}),(0,u.jsxs)("div",{className:"relative w-full h-full sm:h-auto sm:max-h-[85vh] sm:max-w-3xl sm:mx-4 bg-gray-900 sm:rounded-2xl flex flex-col overflow-hidden",children:[(0,u.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-700",children:[(0,u.jsx)("h2",{className:"text-white text-sm font-medium",children:x("folders.pdfPageManager")}),(0,u.jsxs)("div",{className:"flex items-center gap-2",children:[I&&(0,u.jsxs)("button",{onClick:X,disabled:T,className:"flex items-center gap-1 px-3 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-xs rounded-lg transition-colors disabled:opacity-50",children:[(0,u.jsx)(b.g9_,{size:16}),x("folders.pdfApplyChanges")]}),(0,u.jsx)("button",{onClick:p,className:"p-1.5 rounded-lg hover:bg-gray-700 text-gray-400 hover:text-white transition-colors",children:(0,u.jsx)(b.m6K,{size:20})})]})]}),(0,u.jsx)("div",{ref:F,className:"flex-1 overflow-auto p-3 sm:p-4",onPointerMove:null!==P?V:void 0,children:(0,u.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:k.map(function(e,t){var r=P===t,o=A===t&&null!==P&&P!==t,a=e===f,i=w[e];return(0,u.jsxs)("div",{ref:function(e){M.current[t]=e},className:"\n relative group rounded-lg overflow-hidden border-2 transition-all\n ".concat(a?"border-blue-500":"border-gray-700 hover:border-gray-500","\n ").concat(r?"opacity-50 scale-95":"","\n ").concat(o?"ring-2 ring-blue-400":"","\n ").concat(T?"pointer-events-none opacity-60":"","\n "),children:[(0,u.jsx)("div",{className:"aspect-[1/1.41] bg-gray-800 flex items-center justify-center select-none ".concat(null!==P?"cursor-grabbing":"cursor-pointer"),onPointerDown:function(e){return Z(e,t)},onClick:function(){if(Y.current){Y.current=!1;return}h(e)},children:i?(0,u.jsx)("img",{src:i,alt:"".concat(e),className:"w-full h-full object-contain bg-white",draggable:!1}):(0,u.jsx)("div",{className:"w-full h-full bg-gray-800 flex items-center justify-center",children:(0,u.jsx)("div",{className:"w-6 h-6 border-2 border-gray-600 border-t-blue-500 rounded-full animate-spin"})})}),(0,u.jsx)("div",{className:"absolute bottom-1 left-1 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded",children:t+1}),(0,u.jsx)("div",{className:"absolute top-0 right-0 flex flex-col gap-0.5 p-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:n>1&&(0,u.jsx)("button",{onClick:function(t){t.stopPropagation(),O(e)},className:"w-6 h-6 flex items-center justify-center bg-red-500/90 hover:bg-red-600 text-white rounded transition-colors",title:x("folders.pdfDeletePage"),children:(0,u.jsx)(b.b6i,{size:14})})}),(0,u.jsxs)("div",{className:"absolute top-0 left-0 flex flex-col gap-0.5 p-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:[(0,u.jsx)("button",{onClick:function(e){e.stopPropagation(),U(t)},disabled:0===t,className:"w-6 h-6 flex items-center justify-center bg-gray-700/90 hover:bg-gray-600 text-white rounded disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:x("folders.pdfMoveUp"),children:(0,u.jsx)(b.rAP,{size:16})}),(0,u.jsx)("button",{onClick:function(e){e.stopPropagation(),W(t)},disabled:t===k.length-1,className:"w-6 h-6 flex items-center justify-center bg-gray-700/90 hover:bg-gray-600 text-white rounded disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:x("folders.pdfMoveDown"),children:(0,u.jsx)(b.WnU,{size:16})})]}),(0,u.jsx)("div",{className:"hidden sm:flex absolute bottom-1 right-1 w-6 h-6 items-center justify-center bg-gray-700/90 hover:bg-gray-600 text-white rounded cursor-grab opacity-0 group-hover:opacity-100 transition-opacity",onPointerDown:function(e){return H(e,t)},title:"Drag to reorder",children:(0,u.jsx)(b.LUV,{size:14})})]},"".concat(e,"-").concat(t))})})})]})]})}var A=n(89099),L=n(97685),z=n(34550),T=n(84128),R=n(24471),F=n(96470),M=n(99377);function B(e){var t=e.file,n=e.currentPage,o=e.onClose,a=e.extractPageBase64,i=(0,v.B)().t,f=(0,A.useRouter)(),g=f.locale||"en",m="fa"===g||"ar"===g,p=(0,s._)((0,d.useState)([]),2),x=p[0],y=p[1],w=(0,s._)((0,d.useState)(""),2),_=w[0],j=w[1],k=(0,s._)((0,d.useState)(!1),2),N=k[0],C=k[1],P=(0,s._)((0,d.useState)("en"),2),S=P[0],E=P[1],D=(0,d.useRef)(null),B=(0,d.useRef)(null),Y=(0,d.useRef)(null);(0,d.useEffect)(function(){E(localStorage.getItem("Mindo_AI_Lang")||g||"en")},[g]),(0,d.useEffect)(function(){if(null==t?void 0:t.file_ugid){var e=!1;return(0,z.A)("".concat("https://api.mindomax.com/v1","/aitutor/pdf-chat/").concat(t.file_ugid),{method:"GET"}).then(function(t){var n,r,o=t.response;e||y(((null==o||null==(r=o.data)||null==(n=r.data)?void 0:n.messages)||[]).map(function(e,t){return{id:"h".concat(t),role:"model"===e.role?"assistant":"user",content:e.content,pageNumber:e.page_number,timestamp:e.time_created||new Date}}))}).catch(function(){}),function(){e=!0}}},[null==t?void 0:t.file_ugid]),(0,d.useEffect)(function(){var e;null==(e=D.current)||e.scrollIntoView({behavior:"smooth"})},[x,N]);var I=(0,d.useCallback)(function(e){L.Ay.custom(function(t){return(0,u.jsx)("div",{className:"".concat(t.visible?"animate-enter":"animate-leave"," w-auto"),style:{direction:m?"rtl":"ltr"},children:(0,u.jsxs)("div",{className:"bg-toast-bg backdrop-blur-xl shadow-2xl rounded-3xl pointer-events-auto flex ring-1 ring-black ring-opacity-5 border border-toast-border",children:[(0,u.jsx)("div",{className:"p-2",children:(0,u.jsxs)("div",{className:"flex items-start",children:[(0,u.jsx)("div",{className:"flex-shrink-0 pt-0.5",children:(0,u.jsx)("div",{className:"h-6 w-6 rounded-full bg-red-500/20 flex items-center justify-center",children:(0,u.jsx)("svg",{className:"h-4 w-4 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,u.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})}),(0,u.jsx)("div",{className:"".concat(m?"mr-2":"ml-2"," flex-1"),children:(0,u.jsx)("p",{className:"text-xs text-white",children:e})})]})}),(0,u.jsx)("div",{className:"flex border-l border-toast-border",children:(0,u.jsx)("button",{onClick:function(){return L.Ay.dismiss(t.id)}
1,className:"w-full border border-transparent rounded-none rounded-r-3xl p-2 flex items-center justify-center text-sm font-medium text-blue-400 hover:text-blue-300 focus:outline-none",children:(0,u.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,u.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})})]})})},{duration:5e3,position:"top-center"})},[m]),U=(0,d.useCallback)(function(e){L.Ay.custom(function(t){return(0,u.jsx)("div",{className:"".concat(t.visible?"animate-enter":"animate-leave"," w-auto"),style:{direction:m?"rtl":"ltr"},children:(0,u.jsxs)("div",{className:"bg-toast-bg backdrop-blur-xl shadow-2xl rounded-3xl pointer-events-auto flex ring-1 ring-black ring-opacity-5 border border-toast-border",children:[(0,u.jsx)("div",{className:"p-2",children:(0,u.jsxs)("div",{className:"flex items-start",children:[(0,u.jsx)("div",{className:"flex-shrink-0 pt-0.5",children:(0,u.jsx)("div",{className:"h-6 w-6 rounded-full bg-amber-500/20 flex items-center justify-center",children:(0,u.jsx)("svg",{className:"h-4 w-4 text-amber-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,u.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})})}),(0,u.jsxs)("div",{className:"".concat(m?"mr-2":"ml-2"," flex-1"),children:[(0,u.jsx)("p",{className:"text-xs font-medium text-white",children:i("panel.test.aiTutor.limits.title")}),(0,u.jsx)("p",{className:"mt-0.5 text-xs text-blue-300 whitespace-pre-line",children:(0,F.A)(i,g,e)}),!(null==e?void 0:e.isPremium)&&(0,u.jsx)("div",{className:"mt-2",children:(0,u.jsx)("button",{onClick:function(){f.push("/home/subscription"),L.Ay.dismiss(t.id)},className:"bg-gradient-to-r from-blue-600 to-blue-500 text-white text-xs font-medium px-3 py-1.5 rounded-2xl hover:from-blue-700 hover:to-blue-600 transition-all duration-200",children:i("panel.test.aiTutor.limits.viewPremiumPlans")})})]})]})}),(0,u.jsx)("div",{className:"flex border-l border-toast-border",children:(0,u.jsx)("button",{onClick:function(){return L.Ay.dismiss(t.id)},className:"w-full border border-transparent rounded-none rounded-r-3xl p-2 flex items-center justify-center text-sm font-medium text-blue-400 hover:text-blue-300 focus:outline-none",children:(0,u.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,u.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})})]})})},{duration:8e3,position:"top-center"})},[m,g,f,i]),W=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return(0,r._)(function(){var r,o,s,u,d,f;return(0,c.YH)(this,function(c){switch(c.label){case 0:if(!(r=(e||_).trim())||N)return[2];o=n,j(""),y(function(e){return(0,l._)(e).concat([{id:Date.now(),role:"user",content:r,pageNumber:o,timestamp:new Date}])}),C(!0),c.label=1;case 1:return c.trys.push([1,4,5,6]),[4,a()];case 2:if(!(u=c.sent()))throw Error(i("panel.test.aiTutor.errors.connectionError"));return[4,(0,z.A)("".concat("https://api.mindomax.com/v1","/aitutor/chat"),{method:"POST",body:{fileUgid:t.file_ugid,pageNumber:o,pdfPage:u,message:r,locale:S}})];case 3:return(null==(d=c.sent().response)?void 0:d.status)===200&&(null==d||null==(s=d.data)?void 0:s.data)&&y(function(e){return(0,l._)(e).concat([{id:Date.now()+1,role:"assistant",content:d.data.data.reply,pageNumber:o,timestamp:new Date}])}),[3,6];case 4:return console.error("PDF Tutor error:",f=c.sent()),429===f.status&&"RATE_LIMIT_EXCEEDED"===f.message?U(f.data):I(f.message||i("panel.test.aiTutor.errors.connectionError")),[3,6];case 5:return C(!1),[7];case 6:return[2]}})})()},X=x.map(function(e,t){return"assistant"===e.role?t:-1}).filter(function(e){return -1!==e}).pop();return(0,u.jsxs)("div",{className:"fixed inset-0 z-[75] max-lg:h-[100dvh] lg:static lg:z-auto lg:w-[380px] lg:flex-shrink-0 flex flex-col bg-[#0A192F] lg:border-l lg:border-gray-700",style:{direction:m?"rtl":"ltr",paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"env(safe-area-inset-bottom, 0px)"},children:[(0,u.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-gray-700 flex-shrink-0",children:[(0,u.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,u.jsx)("div",{className:"w-7 h-7 rounded-xl bg-gradient-to-br from-blue-500 to-cyan-500 flex items-center justify-center flex-shrink-0",children:(0,u.jsx)(h.kRY,{size:15,className:"text-white"})}),(0,u.jsx)("span",{className:"text-sm text-white/90 font-medium truncate",children:i("folders.pdfTutorTitle")}),(0,u.jsxs)("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-blue-500/20 text-blue-300 border border-blue-500/30 flex-shrink-0",children:[i("folders.pdfPage")," ",n]})]}),(0,u.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,u.jsx)("button",{onClick:function(){return(0,r._)(function(){return(0,c.YH)(this,function(e){switch(e.label){case 0:if(0===x.length||!window.confirm(i("folders.pdfTutorClearConfirm")))return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,(0,z.A)("".concat("https://api.mindomax.com/v1","/aitutor/pdf-chat/").concat(t.file_ugid),{method:"DELETE"})];case 2:return e.sent(),y([]),[3,4];case 3:return I(e.sent().message||i("panel.test.aiTutor.errors.connectionError")),[3,4];case 4:return[2]}})})()},disabled:0===x.length,className:"p-1.5 rounded hover:bg-red-600/30 text-gray-400 hover:text-red-400 disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:i("folders.pdfTutorClear"),children:(0,u.jsx)(b.ZKV,{size:18})}),(0,u.jsx)("button",{onClick:o,className:"p-1.5 rounded hover:bg-gray-700 text-gray-400 hover:text-white transition-colors",children:(0,u.jsx)(b.m6K,{size:18})})]})]}),(0,u.jsxs)("div",{ref:B,className:"flex-1 overflow-y-auto overflow-x-hidden px-3 py-4 space-y-4",style:{minHeight:0,WebkitOverflowScrolling:"touch",overscrollBehavior:"contain"},children:[0!==x.length||N?x.map(function(e,t){return(0,u.jsxs)("div",{children:["user"===e.role&&e.pageNumber?(0,u.jsx)("div",{className:"flex mb-1 ".concat(m?"justify-start":"justify-end"),children:(0,u.jsxs)("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-gray-700/60 text-gray-400",children:[i("folders.pdfPage")," ",e.pageNumber]})}):null,(0,u.jsx)(T.A,{message:e,isFarsi:m,aiLanguage:S,isGlassy:!1,isLastAiMessage:t===X,onSuggestionClick:function(e){return W(e)}})]},e.id)}):(0,u.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[(0,u.jsx)("div",{className:"w-12 h-12 rounded-full bg-blue-500/10 flex items-center justify-center mb-4",children:(0,u.jsx)(h.kRY,{size:22,className:"text-blue-400"})}),(0,u.jsx)("p",{className:"text-sm text-white/40 font-light",children:i("folders.pdfTutorEmpty")})]}),N&&(0,u.jsxs)("div",{className:"flex items-start gap-3 ".concat(m?"flex-row-reverse":""),children:[(0,u.jsx)("div",{className:"w-8 h-8 rounded-xl flex items-center justify-center flex-shrink-0 bg-gradient-to-br from-blue-500 to-cyan-500 shadow-lg shadow-blue-500/20",children:(0,u.jsx)(h.kRY,{size:16,className:"text-white"})}),(0,u.jsx)("div",{className:"rounded-2xl px-4 py-3 bg-[#1E3A5F]/50 border border-[#1E3A5F]",children:(0,u.jsxs)("div",{className:"flex gap-1.5",children:[(0,u.jsx)("span",{className:"w-2 h-2 rounded-full animate-bounce bg-blue-400",style:{animationDelay:"0ms"}}),(0,u.jsx)("span",{className:"w-2 h-2 rounded-full animate-bounce bg-cyan-400",style:{animationDelay:"150ms"}}),(0,u.jsx)("span",{className:"w-2 h-2 rounded-full animate-bounce bg-blue-400",style:{animationDelay:"300ms"}})]})})]}),(0,u.jsx)("div",{ref:D})]}),(0,u.jsx)(M.A,{containerRef:B}),(0,u.jsx)("div",{className:"flex-shrink-0 border-t border-gray-700",children:(0,u.jsx)(R.A,{ref:Y,value:_,onCh
1ange:j,onSend:function(){return W()},onKeyDown:function(e){"Enter"!==e.key||e.shiftKey||(e.preventDefault(),W())},isLoading:N,isFarsi:m,isGlassy:!1})})]})}function Y(e){return"".concat("https://api.mindomax.com/v1","/file-folder/files/").concat(e,"/proxy")}function I(e){return"".concat("https://api.mindomax.com/v1","/file-folder/files/").concat(e,"/annotations")}function U(){var e=localStorage.getItem("Mindo_Tok");return{Authorization:"Bearer ".concat(e)}}function W(e){var t,b,y,_,j,k,N,C,P,E,A,L,z,T,R,F,W,X,O,H,V,K=e.file,Z=e.onClose,J=(e.onDownload,e.docPreview),G=void 0!==J&&J,q=(0,v.B)().t,$=(0,s._)((0,d.useState)(null),2),Q=$[0],ee=$[1],et=(0,s._)((0,d.useState)(null),2),en=et[0],er=et[1],eo=(0,s._)((0,d.useState)(1),2),ea=eo[0],ei=eo[1],es=(0,s._)((0,d.useState)(1),2),el=es[0],ec=es[1],eu=(0,s._)((0,d.useState)(function(){var e=localStorage.getItem("Mindo_Pdf_Tool");return["select","draw","text"].includes(e)?e:"select"}),2),ed=eu[0],ef=eu[1],eh=(0,s._)((0,d.useState)(function(){var e=localStorage.getItem("Mindo_Pdf_Color");return e&&/^#[0-9A-Fa-f]{6}$/.test(e)?e:"#FFFF00"}),2),eg=eh[0],em=eh[1],ep=(0,s._)((0,d.useState)(function(){var e=parseFloat(localStorage.getItem("Mindo_Pdf_Stroke"));return isFinite(e)&&e>0?e:.006}),2),ex=ep[0],ev=ep[1],eb=(0,s._)((0,d.useState)(function(){var e=parseFloat(localStorage.getItem("Mindo_Pdf_FontSize"));return isFinite(e)&&e>0?e:.025}),2),ey=eb[0],ew=eb[1],e_=(0,s._)((0,d.useState)({}),2),ej=e_[0],ek=e_[1],eN=(0,s._)((0,d.useState)([]),2),eC=eN[0],eP=eN[1],eS=(0,s._)((0,d.useState)(!1),2),eE=eS[0],eD=eS[1],eA=(0,s._)((0,d.useState)(null),2),eL=eA[0],ez=eA[1],eT=(0,s._)((0,d.useState)(!1),2),eR=eT[0],eF=eT[1],eM=(0,s._)((0,d.useState)(!1),2),eB=eM[0],eY=eM[1],eI=(0,s._)((0,d.useState)(function(){return window.innerWidth>=1024}),2),eU=eI[0],eW=eI[1],eX=(0,d.useRef)(null),eO=(0,d.useRef)(!1),eH=(0,d.useRef)({buf:null,page:0,base64:null});(0,d.useEffect)(function(){localStorage.setItem("Mindo_Pdf_Tool",ed),localStorage.setItem("Mindo_Pdf_Color",eg),localStorage.setItem("Mindo_Pdf_Stroke",String(ex)),localStorage.setItem("Mindo_Pdf_FontSize",String(ey))},[ed,eg,ex,ey]);var eV=(b=(t=(0,s._)((0,d.useState)(null),2))[0],y=t[1],j=(_=(0,s._)((0,d.useState)(0),2))[0],k=_[1],C=(N=(0,s._)((0,d.useState)(!1),2))[0],P=N[1],A=(E=(0,s._)((0,d.useState)(null),2))[0],L=E[1],z=(0,d.useRef)(null),(0,d.useEffect)(function(){if(Q){var e=!1;return y(null),k(0),P(!0),L(null),(0,r._)(function(){var t,r,o,a;return(0,c.YH)(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,4,5]),[4,n.e(8233).then(n.bind(n,53553))];case 1:return(t=i.sent()).GlobalWorkerOptions.workerSrc="/pdf.worker.min.mjs",z.current=r=t.getDocument({data:Q.slice(0)}),[4,r.promise];case 2:if(o=i.sent(),e)return r.destroy(),[2];return y(o),k(o.numPages),[3,5];case 3:return a=i.sent(),e||L(a.message),[3,5];case 4:return e||P(!1),[7];case 5:return[2]}})})(),function(){e=!0,z.current&&(z.current.destroy(),z.current=null)}}},[Q]),{pdfDocument:b,numPages:j,loading:C,error:A}),eK=eV.pdfDocument,eZ=eV.numPages,eJ=eV.loading,eG=eV.error;R=(T={fileUgid:null==K?void 0:K.file_ugid,numPages:eZ,currentPage:ea,setCurrentPage:ei}).fileUgid,F=T.numPages,W=T.currentPage,X=T.setCurrentPage,O=(0,d.useRef)(null),(H=(0,d.useRef)(F)).current=F,V=function(e,t){if(H.current){var n=Math.min(Math.max(1,t),H.current);e.shownPage=n,X(n)}},(0,d.useEffect)(function(){if(R){var e=function(){try{return localStorage.getItem("Mindo_Tok")}catch(e){return null}}(),t=e?function(e){try{var t=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(atob(t)).ugid||null}catch(e){return null}}(e):null,n={key:t?"".concat("Mindo_Pdf_Pos_").concat(t,"_").concat(R):null,record:null,restored:!1,moved:!1,shownPage:1,pending:null,timer:null};n.record=p(n.key),O.current=n;var r=function(e,t){if(t&&t.page===e.page&&t.client_updated_at_ms!==e.client_updated_at_ms){n.record===e&&(n.record=t);var r=p(n.key);r&&r.page===e.page&&r.client_updated_at_ms===e.client_updated_at_ms&&x(n.key,t)}},o=function(t,n){if(e){var o={page:t.page,client_updated_at_ms:t.client_updated_at_ms};t.page_count&&(o.page_count=t.page_count);try{fetch(g(R),{method:"PUT",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(o),keepalive:n}).then(function(e){return e.ok?e.json():null}).then(function(e){return r(t,m(e&&e.data))}).catch(function(){})}catch(e){}}};n.flush=function(e){clearTimeout(n.timer),n.timer=null;var t=n.pending;t&&(n.pending=null,o(t,e))};var s=new AbortController;e&&fetch(g(R),{headers:{Authorization:"Bearer ".concat(e)},signal:s.signal}).then(function(e){return e.ok?e.json():null}).then(function(e){if(e&&O.current===n){var t=m(e.data),r=n.record,s=t&&(!r||t.client_updated_at_ms>r.client_updated_at_ms);if(s&&n.moved){var l=(0,i._)((0,a._)({},n.record),{client_updated_at_ms:t.client_updated_at_ms+1});n.record=l,x(n.key,l),n.pending?n.pending=l:o(l,!1)}else s?(n.record=t,x(n.key,t),n.restored&&V(n,t.page)):r&&!n.moved&&(!t||r.client_updated_at_ms>t.client_updated_at_ms)&&o(r,!1)}}).catch(function(){});var l=function(){"hidden"===document.visibilityState&&n.flush(!0)},c=function(){return n.flush(!0)};return document.addEventListener("visibilitychange",l),window.addEventListener("pagehide",c),function(){s.abort(),document.removeEventListener("visibilitychange",l),window.removeEventListener("pagehide",c),n.flush(!0),O.current===n&&(O.current=null)}}},[R]),(0,d.useLayoutEffect)(function(){var e=O.current;e&&!e.restored&&F&&(e.restored=!0,e.record&&V(e,e.record.page))},[F]),(0,d.useEffect)(function(){var e=O.current;if(e&&e.restored&&W!==e.shownPage){e.shownPage=W,e.moved=!0;var t=e.record?e.record.client_updated_at_ms:0,n={page:W,page_count:H.current||null,client_updated_at_ms:Math.max(Date.now(),t+1)};
1e.record=n,x(e.key,n),e.pending=n,clearTimeout(e.timer),e.timer=setTimeout(function(){return e.flush(!1)},2e3)}},[W]);var eq=(0,d.useRef)(!1);(0,d.useEffect)(function(){if(eK&&eX.current){var e=null,t=function(){e=requestAnimationFrame(function(){return(0,r._)(function(){var e,t,n,r,o;return(0,c.YH)(this,function(a){switch(a.label){case 0:if(a.trys.push([0,2,,3]),eq.current||!eX.current)return[2];return[4,eK.getPage(1)];case 1:if(e=a.sent().getViewport({scale:1}).width,!(t=eX.current)||0===t.clientWidth)return[2];return n=getComputedStyle(t),o=(r=t.clientWidth-parseFloat(n.paddingLeft)-parseFloat(n.paddingRight))<e?Math.max(.1,r/e):1,ec(function(e){return Math.abs(e-o)>.01?o:e}),[3,3];case 2:return a.sent(),[3,3];case 3:return[2]}})})()})};t();var n=new ResizeObserver(t);return n.observe(eX.current),function(){e&&cancelAnimationFrame(e),n.disconnect()}}},[eK]);var e$=(0,d.useCallback)(function(e){eq.current=!0,ec(e)},[]);(0,d.useEffect)(function(){if(K){var e=U();fetch(G?"".concat(Y(K.file_ugid),"?preview=pdf"):Y(K.file_ugid),{headers:e}).then(function(e){if(!e.ok)throw Error("Failed to load PDF");return e.arrayBuffer()}).then(function(e){return ee(e)}).catch(function(e){return er(e.message)})}},[K]),(0,d.useEffect)(function(){if(K){var e=U();fetch(I(K.file_ugid),{headers:e}).then(function(e){return e.json()}).then(function(e){var t;if(null==(t=e.data)?void 0:t.annotations){var n={};e.data.annotations.forEach(function(e){n[e.page_number]||(n[e.page_number]=[]),n[e.page_number].push(e)}),ek(n)}}).catch(function(){})}},[K]);var eQ=(0,d.useCallback)(function(e){eP(function(t){return(0,l._)(t.slice(-49)).concat([e])})},[]),e0=(0,d.useCallback)(function(e){ek(function(t){eQ(t);var n=e.page_number;return(0,i._)((0,a._)({},t),(0,o._)({},n,(0,l._)(t[n]||[]).concat([e])))}),eD(!0),ez(null)},[eQ]),e1=(0,d.useCallback)(function(e){ek(function(t){eQ(t);var n={};for(var r in t){var o=t[r].filter(function(t){return t.annotation_ugid!==e});o.length>0&&(n[r]=o)}return n}),eD(!0),ez(null)},[eQ]),e2=(0,d.useCallback)(function(e,t){ek(function(n){eQ(n);var r={};for(var o in n)r[o]=n[o].map(function(n){return n.annotation_ugid===e?(0,i._)((0,a._)({},n),{data:(0,a._)({},n.data,t)}):n});return r}),eD(!0)},[eQ]),e4=(0,d.useCallback)(function(){eP(function(e){return 0===e.length?e:(ek(e[e.length-1]),eD(!0),ez(null),e.slice(0,-1))})},[]),e5=(0,d.useCallback)(function(e){return(0,r._)(function(){var t,n,r,o,l,u;return(0,c.YH)(this,function(c){switch(c.label){case 0:if(!Q)return[2];return[4,f.PDFDocument.load(Q.slice(0))];case 1:return t=c.sent(),n="before"===e?ea-1:ea,o=(r=t.getPage(Math.min(ea-1,t.getPageCount()-1)).getSize()).width,l=r.height,t.insertPage(n,[o,l]),[4,t.save()];case 2:return u=c.sent(),ek(function(e){var t={},r=!0,o=!1,l=void 0;try{for(var c,u=Object.entries(e)[Symbol.iterator]();!(r=(c=u.next()).done);r=!0)!function(){var e=(0,s._)(c.value,2),r=e[0],o=e[1],l=parseInt(r),u=l>=n+1?l+1:l;t[u]=o.map(function(e){return(0,i._)((0,a._)({},e),{page_number:u})})}()}catch(e){o=!0,l=e}finally{try{r||null==u.return||u.return()}finally{if(o)throw l}}return t}),ee(u.buffer),ei(n+1),eD(!0),eO.current=!0,[2]}})})()},[Q,ea]),e3=(0,d.useCallback)(function(e){return(0,r._)(function(){var t;return(0,c.YH)(this,function(n){switch(n.label){case 0:if(!Q||eZ<=1)return[2];return[4,f.PDFDocument.load(Q.slice(0))];case 1:return(t=n.sent()).removePage(e-1),ek(function(t){eQ(t);var n={},r=!0,o=!1,l=void 0;try{for(var c,u=Object.entries(t)[Symbol.iterator]();!(r=(c=u.next()).done);r=!0)!function(){var t=(0,s._)(c.value,2),r=t[0],o=t[1],l=parseInt(r);if(l!==e){var u=l>e?l-1:l;n[u]=o.map(function(e){return(0,i._)((0,a._)({},e),{page_number:u})})}}()}catch(e){o=!0,l=e}finally{try{r||null==u.return||u.return()}finally{if(o)throw l}}return n}),[4,t.save()];case 2:return ee(n.sent().buffer),ei(function(t){var n=eZ-1;return t>n?n:t>e?t-1:t===e&&t===eZ?n:t}),eD(!0),eO.current=!0,[2]}})})()},[Q,eZ,eQ]),e6=(0,d.useCallback)(function(e){return(0,r._)(function(){var t,n,r;return(0,c.YH)(this,function(o){switch(o.label){case 0:if(!Q||e.every(function(e,t){return e===t+1}))return[2];return[4,f.PDFDocument.load(Q.slice(0))];case 1:return t=o.sent(),[4,f.PDFDocument.create()];case 2:return n=o.sent(),r=e.map(function(e){return e-1}),[4,n.copyPages(t,r)];
1case 3:return o.sent().forEach(function(e){return n.addPage(e)}),ek(function(t){eQ(t);var n={};return e.forEach(function(e,r){var o=r+1;t[e]&&(n[o]=t[e].map(function(e){return(0,i._)((0,a._)({},e),{page_number:o})}))}),n}),[4,n.save()];case 4:return ee(o.sent().buffer),ei(function(t){var n=e.indexOf(t);return n>=0?n+1:1}),eD(!0),eO.current=!0,[2]}})})()},[Q,eQ]),e7=(0,d.useCallback)(function(){return(0,r._)(function(){var e,t,n,r,o,a,i,l;return(0,c.YH)(this,function(c){switch(c.label){case 0:if(!Q)return[2,null];if((e=eH.current).buf===Q&&e.page===ea&&e.base64)return[2,e.base64];return[4,f.PDFDocument.load(Q.slice(0))];case 1:return t=c.sent(),[4,f.PDFDocument.create()];case 2:return[4,(n=c.sent()).copyPages(t,[ea-1])];case 3:return r=s._.apply(void 0,[c.sent(),1])[0],n.addPage(r),[4,n.save()];case 4:for(o=c.sent(),a="",i=0;i<o.length;i+=32768)a+=String.fromCharCode.apply(null,o.subarray(i,i+32768));return eH.current={buf:Q,page:ea,base64:l=btoa(a)},[2,l]}})})()},[Q,ea]),e8=(0,d.useCallback)(function(){return(0,r._)(function(){var e,t;return(0,c.YH)(this,function(n){switch(n.label){case 0:if(!K||eR)return[2];eF(!0),n.label=1;case 1:if(n.trys.push([1,5,6,7]),!(!G&&eO.current&&Q))return[3,3];return(e=new FormData).append("file",new Blob([Q],{type:"application/pdf"}),K.original_filename),[4,fetch("".concat("https://api.mindomax.com/v1","/file-folder/files/").concat(K.file_ugid,"/content"),{method:"PUT",headers:U(),body:e})];case 2:if(!n.sent().ok)throw Error("Failed to save PDF");eO.current=!1,n.label=3;case 3:return t=Object.values(ej).flat(),[4,fetch(I(K.file_ugid),{method:"PUT",headers:(0,i._)((0,a._)({},U()),{"Content-Type":"application/json"}),body:JSON.stringify({annotations:t})})];case 4:if(!n.sent().ok)throw Error("Failed to save");return eD(!1),[3,7];case 5:return console.error("Save error:",n.sent()),[3,7];case 6:return eF(!1),[7];case 7:return[2]}})})()},[K,ej,eR,Q]),e9=(0,d.useCallback)(function(){return(0,r._)(function(){var e,t,n,r,o,a,i,l,u,d,h,g,m,p,x,v,b,y,w,_,j,k,N,C,P,S,E,D,A,L,z,T,R,F,M,B;return(0,c.YH)(this,function(c){switch(c.label){case 0:if(!Q)return[2];return[4,f.PDFDocument.load(Q.slice(0))];case 1:return[4,(e=c.sent()).embedFont(f.StandardFonts.Helvetica)];case 2:t=c.sent(),n=e.getPages(),r=!0,o=!1,a=void 0;try{for(i=Object.entries(ej)[Symbol.iterator]();!(r=(l=i.next()).done);r=!0)if(d=(u=(0,s._)(l.value,2))[0],h=u[1],!((g=parseInt(d)-1)<0)&&!(g>=n.length)){x=(p=(m=n[g]).getSize()).width,v=p.height,b=!0,y=!1,w=void 0;try{for(_=h[Symbol.iterator]();!(b=(j=_.next()).done);b=!0){if(P=(k=j.value).color||"#FFFF00",S=parseInt(P.slice(1,3),16)/255,E=parseInt(P.slice(3,5),16)/255,D=parseInt(P.slice(5,7),16)/255,"drawing"===k.annotation_type&&(null==(N=k.data.points)?void 0:N.length)>1)for(T=1,A=(k.data.strokeWidth||.003)*x,L=(k.data.strokeWidth||0)>=.04?.4:1,z=k.data.points;T<z.length;T++)m.drawLine({start:{x:z[T-1].x*x,y:v-z[T-1].y*v},end:{x:z[T].x*x,y:v-z[T].y*v},thickness:A,color:(0,f.rgb)(S,E,D),opacity:L});"text"===k.annotation_type&&(null==(C=k.data)?void 0:C.text)&&(R=(k.data.fontSize||.025)*v,m.drawText(k.data.text,{x:k.data.x*x,y:v-k.data.y*v-R,size:R,color:(0,f.rgb)(S,E,D),font:t}))}}catch(e){y=!0,w=e}finally{try{b||null==_.return||_.return()}finally{if(y)throw w}}}}catch(e){o=!0,a=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw a}}return[4,e.save()];case 3:return F=new Blob([c.sent()],{type:"application/pdf"}),M=URL.createObjectURL(F),(B=document.createElement("a")).href=M,B.download=(null==K?void 0:K.original_filename)||"document.pdf",B.click(),URL.revokeObjectURL(M),[2]}})})()},[Q,ej,K]),te=(0,d.useCallback)(function(){(!eE||window.confirm(q("folders.pdfUnsavedChanges")))&&Z()},[eE,Z,q]),tt=(0,d.useCallback)(function(e){e>=1&&e<=eZ&&(ei(e),ez(null))},[eZ]);(0,d.useEffect)(function(){var e=function(e){var t=e.target.tagName;"INPUT"!==t&&"TEXTAREA"!==t&&("ArrowLeft"===e.key||"ArrowUp"===e.key?(e.preventDefault(),ei(function(e){return Math.max(1,e-1)}),ez(null)):("ArrowRight"===e.key||"ArrowDown"===e.key)&&(e.preventDefault(),ei(function(e){return Math.min(eZ,e+1)}),ez(null)))};return window.addEventListener("keydown",e),function(){return window.removeEventListener("keydown",e)}},[eZ]);var tn=(0,d.useRef)(null),tr=(0,d.useRef)(ed);return(tr.current=ed,(0,d.useEffect)(function(){var e=eX.current;if(e){var t=function(e){1===e.touches.length&&"draw"!==tr.current&&(tn.current={x:e.touches[0].clientX,y:e.touches[0].clientY})},n=function(e){if(tn.current){var t=e.changedTouches[0],n=t.clientX-tn.current.x,r=t.clientY-tn.current.y;tn.current=null,Math.abs(n)>60&&Math.abs(n)>1.5*Math.abs(r)&&(n>0?ei(function(e){return Math.max(1,e-1)}):ei(function(e){return Math.min(eZ,e+1)}),ez(null))}};return e.addEventListener("touchstart",t,{passive:!0}),e.addEventListener("touchend",n,{passive:!0}),function(){e.removeEventListener("touchstart",t),e.removeEventListener("touchend",n)}}},[eZ]),en||eG)?(0,u.jsxs)("div",{className:"flex flex-col h-full bg-gray-900",children:[(0,u.jsx)(S,{currentPage:1,numPages:0,zoom:el,activeTool:ed,drawColor:eg,strokeWidth:ex,isDirty:!1,onPageChange:function(){},onZoomChange:e$,onToolChange:ef,onColorChange:em,onStrokeWidthChange:ev,onSave:function(){},onClose:Z,onDownload:e9,hasSelection:!1,onDeleteSelected:function(){},fileName:null==K?void 0:K.original_filename,onAddPageBefore:function(){},onAddPageAfter:function(){},fontSize:ey,onFontSizeChange:ew,onUndo:function(){},canUndo:!1}),(0,u.jsx)("div",{className:"flex-1 flex items-center justify-center text-gray-400",children:(0,u.jsx)("p",{children:en||eG})})]}):eJ||!eK?(0,u.jsxs)("div",{className:"flex flex-col h-full bg-gray-900",children:[(0,u.jsx)(S,{currentPage:1,numPages:0,zoom:el,activeTool:ed,drawColor:eg,strokeWidth:ex,isDirty:!1,onPageChange:function(){},onZoomChange:e$,onToolChange:ef,onColorChange:em,onStrokeWidthChange:ev,onSave:function(){},onClose:Z,onDownload:e9,hasSelection:!1,onDeleteSelected:function(){},fileName:null==K?void 0:K.original_filename,onAddPageBefore:function(){},onAddPageAfter:function(){},fontSize:ey,onFontSizeChange:ew,onUndo:function(){},canUndo:!1}),(0,u.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,u.jsx)("div",{className:"w-8 h-8 border-2 border-gray-600 border-t-blue-500 rounded-full animate-spin"})})]}):(0,u.jsxs)("div",{className:"flex flex-col h-full bg-gray-900",children:[(0,u.jsx)(S,{currentPage:ea,numPages:eZ,zoom:el,activeTool:ed,drawColor:eg,strokeWidth:ex,isDirty:e
1E,onPageChange:tt,onZoomChange:e$,onToolChange:ef,onColorChange:em,onStrokeWidthChange:ev,onSave:e8,onClose:te,onDownload:e9,hasSelection:!!eL,onDeleteSelected:function(){eL&&e1(eL)},fileName:null==K?void 0:K.original_filename,onAddPageBefore:function(){return e5("before")},onAddPageAfter:function(){return e5("after")},fontSize:ey,onFontSizeChange:ew,onUndo:e4,canUndo:eC.length>0,onDeleteCurrentPage:function(){return e3(ea)},canDeletePage:eZ>1,onTogglePageManager:G?null:function(){return eY(function(e){return!e})}}),(0,u.jsxs)("div",{className:"flex-1 flex overflow-hidden relative",children:[(0,u.jsx)("div",{ref:eX,className:"flex-1 overflow-auto flex justify-center p-1 sm:p-4 bg-gray-900",children:(0,u.jsx)(w,{pdfDocument:eK,pageNumber:ea,zoom:el,activeTool:ed,drawColor:eg,strokeWidth:ex,annotations:ej[ea]||[],onAnnotationAdd:e0,onAnnotationDelete:e1,selectedId:eL,onSelect:ez,fontSize:ey,onAnnotationUpdate:e2})}),(0,u.jsx)(M.A,{containerRef:eX,disabled:"select"!==ed}),!eU&&(0,u.jsxs)("button",{onClick:function(){return eW(!0)},className:"absolute bottom-5 left-1/2 -translate-x-1/2 lg:left-auto lg:translate-x-0 lg:right-6 z-20 flex items-center gap-2 px-5 py-3 rounded-full bg-gradient-to-r from-blue-600 to-cyan-500 hover:from-blue-500 hover:to-cyan-400 text-white text-sm sm:text-base font-bold shadow-xl shadow-blue-500/30 whitespace-nowrap transition-all",style:{marginBottom:"env(safe-area-inset-bottom, 0px)"},children:[(0,u.jsx)(h.kRY,{size:20,className:"flex-shrink-0"}),q("folders.pdfTutorAskPage")]}),eU&&(0,u.jsx)(B,{file:K,currentPage:ea,onClose:function(){return eW(!1)},extractPageBase64:e7})]}),eB&&!G&&(0,u.jsx)(D,{pdfDocument:eK,numPages:eZ,currentPage:ea,onPageSelect:function(e){tt(e),eY(!1)},onDeletePage:e3,onReorderPages:function(e){return(0,r._)(function(){return(0,c.YH)(this,function(t){switch(t.label){case 0:return[4,e6(e)];case 1:return t.sent(),eY(!1),[2]}})})()},onClose:function(){return eY(!1)}})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.