1import{j as e,m as c,A as $}from"./vendor-motion-CPxq9Xvn.js";import{r as d}from"./vendor-i18n-CO3kK2bH.js";import{az as J,a1 as O,u as P,f as l,S as p,ar as N,a as h,C as M,B as x,a7 as F,ao as R}from"./index-CFAvyuXu.js";import{F as q}from"./file-text-DjkUcFVd.js";import{W as G}from"./wand-sparkles-BFRdHggN.js";import{A as B}from"./arrow-left-DY50GvQQ.js";import{C as b}from"./circle-alert-CixghSwT.js";import"./vendor-react-CQmBMThG.js";const g=[{icon:q,text:"Lendo cada palavra do seu livro com cuidadoâ¦"},{icon:l,text:"Identificando os capÃtulos do seu manuscritoâ¦"},{icon:G,text:"Organizando o conteúdo direitinho pra vocêâ¦"},{icon:p,text:"Preservando 100% do seu texto originalâ¦"},{icon:l,text:"Preparando a página do seu livroâ¦"},{icon:p,text:"Quase lá â só uns ajustes finaisâ¦"}],D={extracting:"Lendo o arquivo",cleaning:"Limpando a formatação",structuring:"Identificando capÃtulos",polishing:"Limpando o conteúdo",saving:"Salvando capÃtulos",done:"Pronto!",error:"Algo deu errado"},V={extracting:15,cleaning:30,structuring:50,polishing:75,saving:92,done:100,error:100};function Y(){const[,w]=J("/book/:id/importing"),[,m]=O(),a=w?.id,[f,k]=d.useState(0),[u,y]=d.useState(0),{data:t,error:I,isError:j,isLoading:A,refetch:S}=P({queryKey:[`/api/books/${a}/import-status`],enabled:!!a,refetchInterval:i=>{const n=i.state.data?.importJob?.status;return n==="done"||n==="error"?!1:2e3},refetchOnWindowFocus:!0});d.useEffect(()=>{const i=setInterval(()=>k(n=>(n+1)%g.length),3200);return()=>clearInterval(i)},[]),d.useEffect(()=>{if(!t?.importJob?.startedAt)return;const i=new Date(t.importJob.startedAt).getTime(),n=setInterval(()=>{y(Math.max(0,Math.floor((Date.now()-i)/1e3)))},1e3);return()=>clearInterval(n)},[t?.importJob?.startedAt]);const o=t?.importJob?.status;if(d.useEffect(()=>{if(o==="done"&&a){const i=setTimeout(()=>m(`/book/${a}/editor`),1400);return()=>clearTimeout(i)}},[o,a,m]),d.useEffect(()=>{t&&t.importJob===null&&a&&m(`/book/${a}/editor`)},[t,a,m]),!a)return e.jsx(N,{children:e.jsx("div",{className:"min-h-[60vh] flex items-center justify-center px-4",children:e.jsx("div",{className:"text-center text-muted-foreground",children:"Livro não encontrado."})})});const E=o?V[o]:10,T=Number(I?.status||0),v=j&&T===404,L=j&&!v,s=o==="error",r=o==="done",C=g[f].icon;return e.jsx(N,{children:e.jsxs("div",{className:"overflow-hidden",children:[e.jsx("div",{className:"border-b border-white/5",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-4 md:px-6 py-3 flex items-center justify-between gap-3",children:[e.jsx(h,{href:"/dashboard",children:e.jsxs("button",{className:"text-sm text-muted-foreground hover:text-white flex items-center gap-2","data-testid":"link-back-dashboard",children:[e.jsx(B,{className:"w-4 h-4"})," Voltar"]})}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(l,{className:"w-4 h-4 text-emerald-400"}),e.jsx("span",{className:"text-white font-semibold truncate max-w-[60vw]","data-testid":"text-book-title",children:t?.bookTitle||"Importando seu livro"})]}),e.jsx("div",{className:"w-16"})]})}),e.jsx("main",{className:"max-w-2xl mx-auto px-4 md:px-6 py-12 md:py-20",children:e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsxs(c.div,{animate:s?{}:{scale:[1,1.06,1],rotate:[0,2,-2,0]},transition:{duration:3.4,repeat:1/0,ease:"easeInOut"},className:"relative w-28 h-28 md:w-32 md:h-32 rounded-3xl flex items-center justify-center mb-8 "+(s?"bg-gradient-to-br from-red-500/20 to-rose-500/20 border border-red-400/30":r?"bg-gradient-to-br from-emerald-500/30 to-teal-500/30 border border-emerald-400/40":"bg-gradient-to-br from-emerald-500/20 to-teal-500/20 border border-emerald-400/30"),children:[s?e.jsx(b,{className:"w-14 h-14 text-red-400"}):r?e.jsx(M,{className:"w-14 h-14 text-emerald-400"}):e.jsx(l,{className:"w-14 h-14 text-emerald-400"}),!r&&!s&&e.jsxs(e.Fragment,{children:[e.jsx(c.div,{className:"absolute -top-2 -right-2",animate:{rotate:360},transition:{duration:6,repeat:1/0,ease:"linear"},children:e.jsx(p,{className:"w-5 h-5 text-amber-300"})}),e.jsx(c.div,{className:"absolute -bottom-2 -left-2",animate:{rotate:-360},transition:{duration:8,repeat:1/0,ease:"linear"},children:e.jsx(p,{className:"w-4 h-4 text-teal-300"})})]})]}),e.jsx("h1",{className:"text-2xl md:text-4xl font-bold text-white mb-3","data-testid":"text-headline",children:s?"Tivemos um problema na importação":r?"Tudo pronto! Abrindo seu livroâ¦":"Importando seu livro com carinho"}),!r&&!s&&e.jsx("div",{className:"h-12 flex items-center justify-center mb-6 max-w-md",children:e.jsx($,{mode:"wait",children:e.jsxs(c.div,{initial:{opacity:0,y:8}
1,animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.4},className:"flex items-center gap-2 text-muted-foreground text-base md:text-lg","data-testid":"text-rotating-message",children:[e.jsx(C,{className:"w-5 h-5 text-emerald-400 shrink-0"}),e.jsx("span",{children:g[f].text})]},f)})}),r&&e.jsxs("p",{className:"text-emerald-300 mb-6","data-testid":"text-success",children:[t?.importJob?.chaptersCount??0," capÃtulo(s) importados. Levando você pra página do livroâ¦"]}),s&&e.jsx("div",{className:"w-full max-w-md mb-6",children:e.jsx("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-4 text-left","data-testid":"error-import",children:e.jsx("p",{className:"text-sm text-red-200",children:t?.importJob?.errorMessage||"Não conseguimos terminar a importação. Tente novamente."})})}),!s&&e.jsxs("div",{className:"w-full max-w-md mb-3","data-testid":"progress-import",children:[e.jsx("div",{className:"h-2 rounded-full bg-white/5 overflow-hidden",children:e.jsx(c.div,{className:"h-full bg-gradient-to-r from-emerald-500 to-teal-400",initial:{width:"5%"},animate:{width:`${E}%`},transition:{duration:.8,ease:"easeOut"}})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{"data-testid":"text-stage",children:o?D[o]:"Iniciandoâ¦"}),!r&&e.jsx("span",{"data-testid":"text-elapsed",children:u<60?`${u}s`:`${Math.floor(u/60)}m ${u%60}s`})]})]}),!r&&!s&&e.jsx("p",{className:"text-xs text-muted-foreground max-w-md mt-4","data-testid":"text-reassurance",children:"Pode ficar tranquilo: a importação continua mesmo se você fechar essa aba. Seu livro vai estar prontinho na sua biblioteca quando terminar."}),s&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 mt-2",children:[e.jsx(h,{href:"/book/import-finished",children:e.jsx(x,{"data-testid":"button-try-again",className:"bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-400 hover:to-teal-400 text-white",children:"Tentar novamente"})}),e.jsx(h,{href:"/dashboard",children:e.jsx(x,{variant:"ghost","data-testid":"button-go-dashboard",children:"Voltar à biblioteca"})})]}),r&&e.jsx(h,{href:`/book/${a}/editor`,children:e.jsxs(x,{className:"bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-400 hover:to-teal-400 text-white","data-testid":"button-open-book",children:[e.jsx(l,{className:"w-4 h-4 mr-2"}),"Abrir meu livro agora"]})}),A&&!t&&e.jsxs("div",{className:"mt-8 flex items-center gap-2 text-sm text-muted-foreground","data-testid":"status-loading",children:[e.jsx(F,{className:"w-4 h-4 animate-spin"}),"Conectandoâ¦"]}),L&&!t&&e.jsxs("div",{className:"mt-8 w-full max-w-md rounded-2xl border border-red-400/20 bg-red-500/10 p-5 text-center","data-testid":"status-import-connection-error",children:[e.jsx(b,{className:"mx-auto mb-3 h-8 w-8 text-red-300"}),e.jsx("p",{className:"font-semibold text-white",children:"Não foi possÃvel consultar a importação"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Verifique sua conexão. O processamento continua seguro no servidor."}),e.jsxs(x,{className:"mt-4 min-h-11",onClick:()=>S(),"data-testid":"button-retry-import-status",children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),"Tentar novamente"]})]}),v&&!t&&e.jsxs("div",{className:"mt-8 w-full max-w-md rounded-2xl border border-amber-400/20 bg-amber-500/10 p-5 text-center","data-testid":"status-import-missing",children:[e.jsx(b,{className:"mx-auto mb-3 h-8 w-8 text-amber-300"}),e.jsx("p",{className:"font-semibold text-white",children:"Importação não encontrada"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Ela pode ter sido concluÃda ou substituÃda. Abra o livro para conferir."}),e.jsxs(x,{className:"mt-4 min-h-11",onClick:()=>m(`/book/${a}/editor`),"data-testid":"button-open-book-from-missing-import",children:[e.jsx(l,{className:"mr-2 h-4 w-4"}),"Abrir meu livro"]})]})]})})]})})}export{Y as default};
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.