1import{r as o,j as e}from"./vendor-react-O1HtssjF.js";import{a as ge,u as Ne,b as v}from"./vendor-query-C57Ujfuk.js";import{b as ve,u as ye,d as we,e as y,A as X,f as r,c as Ce,g as S,h as E,T as be,i as Te,j as De,k as Fe}from"./index-BdhET6SP.js";import{Q as Ae}from"./QueryErrorState-DlGSMgX9.js";import{u as Se,a as Ee,P as ze}from"./Paginacao-CZw70aUF.js";import{I as Ie}from"./input-jXmaS0ZY.js";import{L as c}from"./label-GEiHkTUb.js";import{R as Pe,a as K}from"./radio-group-DtqDDeer.js";import{R as qe}from"./rich-text-editor-JhPpeRwZ.js";import{i as U}from"./authUtils-BpmAmtz3.js";import{T as H}from"./textarea-B--0-Y5V.js";import{D as G,a as V,b as W,c as Z,d as J,e as Y,f as z}from"./dialog-CD-2aigv.js";import{A as Le,a as ke,b as Oe,c as Re,d as Me,e as $e,f as Be,g as _e,h as Qe}from"./alert-dialog-DQU_qQrQ.js";import{g as I}from"./error-messages-DvyZ16QK.js";import{L as x,S as ee,P as se,U as Xe,F as w,c as Ke,d as Ue,B as He,D as Ge,e as Ve,f as te,g as We}from"./vendor-icons-qfsiYizf.js";import{f as ae,p as ie}from"./vendor-datefns-RsZNnTnu.js";import"./vendor-radix-AQo14B1u.js";import"./vendor-openai-PX4_LG7y.js";import"./index-j6K_NCap.js";import"./with-selector-BF2ZDh00.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},p=new t.Error().stack;p&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[p]="bf97bc58-d143-4443-a8c7-f4df04837754",t._sentryDebugIdIdentifier="sentry-dbid-bf97bc58-d143-4443-a8c7-f4df04837754")}catch{}})();const P=[".csv",".pdf",".doc",".docx",".xls",".xlsx"],Ze=10*1024*1024;function Je(t){return t?t.includes("spreadsheet")||t.includes("csv")||t.includes("excel")?e.jsx(We,{className:"h-4 w-4 text-green-600"}):t.includes("pdf")?e.jsx(w,{className:"h-4 w-4 text-red-600"}):t.includes("word")||t.includes("document")?e.jsx(w,{className:"h-4 w-4 text-blue-600"}):e.jsx(te,{className:"h-4 w-4"}):e.jsx(te,{className:"h-4 w-4"})}function re(t){return t?t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`:"-"}function Ns(){const{isAuthenticated:t,isLoading:p}=ve(),[,q]=ye(),{toast:a}=we(),C=ge(),[le,h]=o.useState(!1),[ne,L]=o.useState(!1),[f,b]=o.useState(""),[l,d]=o.useState(null),[m,k]=o.useState("text"),[j,O]=o.useState(""),[T,R]=o.useState(""),[n,u]=o.useState(null),[M,g]=o.useState(null),{data:$=[],isLoading:oe,isError:ce,error:de,refetch:me}=Ne({queryKey:["/api/templates"],enabled:t}),ue=Se(88),B=Ee($,ue),N=v({mutationFn:async s=>y("POST","/api/templates",s),onSuccess:()=>{C.invalidateQueries({queryKey:["/api/templates"]}),a({title:"Template criado com sucesso!"}),A(),h(!1)},onError:s=>{if(U(s)){a({title:"Sessão expirada",description:"Fazendo login novamente...",variant:"destructive"}),setTimeout(()=>{window.location.href="/login"},1500);return}a({title:"Erro ao criar template",description:I(s),variant:"destructive"})}}),D=v({mutationFn:async s=>(await y("POST","/api/templates/analyze",{content:s})).json(),onSuccess:s=>{d(s)},onError:s=>{a({title:"Erro ao analisar documento",description:I(s),variant:"destructive"})}}),F=v({mutationFn:async()=>{if(l)return y("POST","/api/templates",{description:l.suggestedName||l.detectedType,type:"text",content:l.template})},onSuccess:()=>{C.invalidateQueries({queryKey:["/api/templates"]}),a({title:"Template salvo!"}),L(!1),b(""),d(null)},onError:s=>{a({title:"Erro ao salvar template",variant:"destructive"})}}),xe=v({mutationFn:async s=>y("DELETE",`/api/templates/${s}`),onSuccess:()=>{C.invalidateQueries({queryKey:["/api/templates"]}),a({title:"Template excluÃdo com sucesso!"})},onError:s=>{if(U(s)){a({title:"Sessão expirada",description:"Fazendo login novamente...",variant:"destructive"}),setTimeout(()=>{window.location.href="/login"},1500);return}a({title:"Erro ao excluir template",description:I(s),variant:"destructive"})}}),A=()=>{k("text"),O(""),R(""),u(null),g(null)},pe=s=>{var _,Q;const i=(_=s.target.files)==null?void 0:_[0];if(g(null),!i){u(null);return}const je="."+((Q=i.name.split(".").pop())==null?void 0:Q.toLowerCase());if(!P.includes(je)){g(`Formato não permitido. Formatos aceitos: ${P.join(", ")}`),u(null),s.target.value="";return}if(i.size>Ze){g("Arquivo excede o limite de 10MB"),u(null),s.target.value="";return}u(i)},he=async()=>
1{if(!j.trim()){a({title:"Erro",description:"Descrição é obrigatória",variant:"destructive"});return}if(m==="text"&&!T.trim()){a({title:"Erro",description:"Conteúdo do template é obrigatório",variant:"destructive"});return}if(m==="file"&&!n){a({title:"Erro",description:"Arquivo é obrigatório",variant:"destructive"});return}if(m==="text")N.mutate({description:j,type:"text",content:T});else if(n){const s=new FileReader;s.onload=()=>{const i=s.result.split(",")[1];N.mutate({description:j,type:"file",fileName:n.name,fileData:i,mimeType:n.type,fileSize:n.size})},s.readAsDataURL(n)}},fe=(s,i)=>{window.open(`/api/templates/${s}/download`,"_blank")};return p?e.jsx(X,{children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(x,{className:"h-8 w-8 animate-spin text-muted-foreground"})})}):t?e.jsx(X,{children:e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-page-title",children:"Templates"}),e.jsx("p",{className:"text-muted-foreground",children:"Gerencie seus templates para geração de artefatos"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(G,{open:ne,onOpenChange:s=>{L(s),s||(b(""),d(null))},children:[e.jsx(V,{asChild:!0,children:e.jsxs(r,{variant:"outline",children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Criar por exemplo"]})}),e.jsxs(W,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[e.jsxs(Z,{children:[e.jsx(J,{children:"Criar template por exemplo"}),e.jsx(Y,{children:"Cole um documento existente. A IA detecta a estrutura e gera um template reutilizável."})]}),l?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-muted/50 space-y-1",children:[e.jsxs("p",{className:"text-sm font-medium",children:["Tipo detectado: ",e.jsx("span",{className:"text-primary",children:l.detectedType})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.description})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Template gerado (editável)"}),e.jsx(H,{value:l.template,onChange:s=>d({...l,template:s.target.value}),className:"min-h-[300px] font-mono text-xs"})]}),e.jsxs(z,{className:"gap-2",children:[e.jsx(r,{variant:"outline",onClick:()=>d(null),children:"Refazer análise"}),e.jsxs(r,{onClick:()=>F.mutate(),disabled:F.isPending,children:[F.isPending?e.jsx(x,{className:"h-4 w-4 animate-spin mr-2"}):null,"Salvar template"]})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:"Documento de exemplo"}),e.jsx(H,{placeholder:"Cole aqui uma ata de reunião, status report, plano de ação ou qualquer outro documento...",value:f,onChange:s=>b(s.target.value),className:"min-h-[250px] font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Ce(f.length,"caractere","caracteres")})]}),e.jsx(z,{children:e.jsxs(r,{onClick:()=>D.mutate(f),disabled:f.trim().length<50||D.isPending,children:[D.isPending?e.jsx(x,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ee,{className:"h-4 w-4 mr-2"}),"Analisar com IA"]})})]})]})]}),e.jsxs(G,{open:le,onOpenChange:s=>{h(s),s||A()},children:[e.jsx(V,{asChild:!0,children:e.jsxs(r,{"data-testid":"button-create-template",children:[e.jsx(se,{className:"mr-2 h-4 w-4"}),"Novo Template"]})}),e.jsxs(W,{className:"max-w-2xl",children:[e.jsxs(Z,{children:[e.jsx(J,{children:"Criar Novo Template"}),e.jsx(Y,{children:"Adicione um template para ser usado na geração de artefatos"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"description",children:"Descrição"}),e.jsx(Ie,{id:"description",placeholder:"Ex: Modelo de ata de reunião",value:j,onChange:s=>O(s.target.value),"data-testid":"input-template-description"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(c,{children:"Tipo de Template"}),e.jsxs(Pe,{value:m,onValueChange:s=>k(s),className:"flex gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(K,{value:"text",id:"type-text","data-testid":"radio-type-text"}),e.jsx(c,{htmlFor:"type-text",className:"cursor-pointer",children:"Texto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(K,{value:"file",id:"type-file","data-testid":"radio-type-file"}),e.jsx(c,{htmlFor:"type-file",className:"cursor-pointer",children:"Arquivo"})]})]})]}),m==="text"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"content",children:"Conteúdo do Template"}),e.jsx(qe,{value:T,onChange:R,placeholder:"Digite o formato/estrutura do seu template aqui...","data-testid":"rte-template-content"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"file",children:"Arquivo do Template"}),e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-6 text-center",children:[e.jsx("input",{id:"file",type:"file",accept:P.join(","),onChange:pe,className:"hidden","data-testid":"input-template-file"}),e.jsxs("label",{htmlFor:"file",className:"cursor-pointer flex flex-col items-center gap-2",children:[e.jsx(Xe,{className:"h-8 w-8 text-muted-foreground"}),n?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:n.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:re(n.size)})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Clique para selecionar ou arraste um arquivo"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Formatos: CSV, PDF, DOC, DOCX, XLS, XLSX (máx. 10MB)"})]})]})]}),M&&e.jsx("p",{className:"text-sm text-destructive",children:M})]})]}),e.jsxs(z,{children:[e.jsx(r,{variant:"outline",onClick:()=>{h(!1),A()},"data-testid":"button-cancel-template",children:"Cancelar"}),e.jsxs(r,{onClick:he,disabled:N.isPending,"data-testid":"button-save-template",children:[N.isPending&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Salvar Template"]})]})]})]})]})]}),oe?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(x,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):ce?e.jsx(S,{children:e.jsx(E,{className:"py-4",children:e.jsx(Ae,{error:de,recurso:"os templates",onRetry:()=>me()})})}):$.length===0?e.jsx(S,{children:e.jsxs(E,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(w,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"Nenhum template cadastrado"}),e.jsx("p",{className:"text-muted-foreground text-center mb-4",children:"Crie seu primeiro template para usar na geração de artefatos"}),e.jsxs(r,{onClick:()=>h(!0),"data-testid":"button-create-first-template",children:[e.jsx(se,{className:"mr-2 h-4 w-4"}),"Criar Template"]})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-3",children:B.itens.map(s=>e.jsx(S,{"data-testid":`card-template-${s.id}`,children:e.jsxs(E,{className:"flex items-center justify-between gap-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-4 flex-1 min-w-0",children:[e.jsx("div",{className:"flex-shrink-0 h-10 w-10 rounded-md bg-muted flex items-center justify-center",children:s.type==="text"?e.jsx(w,{className:"h-5 w-5 text-muted-foreground"}):Je(s.mimeType)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate","data-testid":`text-template-description-${s.id}`,children:s.description}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground flex-wrap",children:[e.jsx("span",{className:"inline-flex items-center gap-1",children:s.type==="text"?"Texto":s.fileName||"Arquivo"}),s.createdAt&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ke,{className:"h-3 w-3"}),ae(new Date(s.createdAt),"dd/MM/yyyy",{locale:ie})]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ue,{className:"h-3 w-3"}),ae(new Date(s.createdAt),"HH:mm",{locale:ie})]})]}),s.type==="file"&&s.fileSize&&e.jsx("span",{children:re(s.fileSize)}),s.placeholders&&s.placeholders.length>0&&e.jsxs(be,{children:[e.jsx(Te,{asChild:!0,children:e.jsxs(De,{variant:"secondary",className:"gap-1 cursor-help",children:[e.jsx(He,{className:"h-3 w-3"}),s.placeholders.length," placeholder",s.placeholders.length!==1?"s":""]})}),e.jsxs(Fe,{className:"max-w-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:"Placeholders detectados:"}),e.jsxs("ul",{className:"text-xs space-y-0.5",children:[s.placeholders.slice(0,10).map(i=>e.jsx("li",{className:"font-mono",children:`{{${i}}}`},i)),s.placeholders.length>10&&e.jsxs("li",{className:"text-muted-foreground",children:["...e mais ",s.placeholders.length-10]})]})]})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.type==="file"&&s.fileName&&e.jsxs(r,{variant:"outline",size:"sm",onClick:()=>fe(s.id,s.fileName),"data-testid":`button-download-template-${s.id}`,children:[e.jsx(Ge,{className:"h-4 w-4 mr-1"}),"Baixar"]}),e.jsxs(Le,{children:[e.jsx(ke,{asChild:!0,children:e.jsx(r,{variant:"outline",size:"icon","data-testid":`button-delete-template-${s.id}`,children:e.jsx(Ve,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(Oe,{children:[e.jsxs(Re,{children:[e.jsx(Me,{children:"Excluir template?"}),e.jsx($e,{children:"Esta ação não pode ser desfeita. O template será permanentemente excluÃdo."})]}),e.jsxs(Be,{children:[e.jsx(_e,{children:"Cancelar"}),e.jsx(Qe,{onClick:()=>xe.mutate(s.id),className:"bg-destructive text-destructive-foreground","data-testid":`button-confirm-delete-template-${s.id}`,children:"Excluir"})]})]})]})]})]})},s.id))}),e.jsx(ze,{estado:B,rotulo:"templates"})]})]})}):(q("/"),null)}export{Ns as default}; 2//# sourceMappingURL=templates-CtIDgrWg.js.map
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.