1import{c as Ta,dW as U,bX as te,ba as La,D as me,K as Re,b7 as Ye,cn as Ce,al as za,a as He,p as Ve,j as e,au as Pa,o as Ie,aw as ma,bB as ua,bk as xa,r as x,bj as We,q as Pe,G as _e,C as ce,a$ as pa,B as $,bw as Fa,a4 as Be,b0 as ha,S as ke,d as De,e as Ae,f as Ee,g as O,a5 as Ma,a6 as Ra,ac as Ia,ad as Ba,ae as Oa,e3 as $a,bv as Z,aH as qa,bc as Ke,F as Ua,c9 as de,c7 as Ha,bl as Va,bm as Wa,bn as Ga,bo as Xa,bp as Ya,aS as fa,aT as ga,bH as ja,aU as _a,b_ as ba,ab as Oe,b2 as Ka,s as je,ay as Se,bg as Qe,cw as Qa,an as Ze,ao as Je,ap as ea,aD as Za,aE as Ja,aa as es,aG as as,bO as ss,V as ts,X as rs,Y as ns,Z as ls,$ as os,b3 as is,f7 as cs}from"./index-Buc_AyvT.js";import{b as va,c as Na,T as Fe,d as L,e as ya,a as z}from"./table-s1x5S_tN.js";import{T as wa,a as Ca,b as $e,c as aa}from"./tabs-CgzEttYU.js";import{a as qe}from"./audit-event-labels-5eZowyZn.js";import{L as ds}from"./log-in-C3TCxqu9.js";import{D as Ge}from"./download-BbAWNje8.js";import{f as ms}from"./fetchAllRows-Cn4S5Ozm.js";import{C as us}from"./CompliancePanel-BiwGBaDS.js";import{P as Sa}from"./page-header-BUp0niUH.js";import{s as ka}from"./subDays-CTL2WxPk.js";import{f as Xe}from"./format-ztiVNJ6G.js";import{C as xs}from"./columns-3-CIoIHWD0.js";import{C as ps}from"./copy-4cl8lDkE.js";import"./move-B6PlnCNI.js";import"./calendar-clock-DjqyjCSp.js";import"./arrow-down-to-line-dVcJLG2f.js";import"./addDays-BOMG2UgM.js";import"./differenceInCalendarDays-2uulwfBb.js";import"./protectedTokens-C5zBkMiN.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const sa=Ta("CloudDownload",[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]]),Da=[{key:"acessos",label:"Acessos"},{key:"documentos",label:"Documentos"},{key:"compartilhamento",label:"Compartilhamento"},{key:"assinaturas",label:"Assinaturas"},{key:"lgpd",label:"LGPD/Titulares"},{key:"acervo",label:"Acervo fÃsico"},{key:"administracao",label:"Administração"},{key:"ia",label:"Wedoks AI"},{key:"outros",label:"Outros"}],Te=Object.fromEntries(Da.map(o=>[o.key,o.label]));function Ue(o){const t=(o||"").toLowerCase(),i=d=>t.startsWith(d);return["login_success","login_failed","logout","magic_link_sent","password_changed","password_reset_requested","trusted_device_added","login"].includes(t)||i("mfa_")?"acessos":i("ai_chat_")?"ia":i("consent_")||i("subject_")||i("titular_")||i("lgpd_")||i("dpa_")||["search_cpf","privacy_settings_updated","suboperadores_viewed"].includes(t)?"lgpd":i("autentique_")||t==="sign"||t==="certificate.used"?"assinaturas":i("public_link_")||i("whatsapp_")||t==="link_clicked"||t==="link_viewed"?"compartilhamento":i("physical_box_")?"acervo":["role_changed","profile_assigned","scope_changed","contact.merge","audit_purge","expiry_export"].includes(t)||i("department_access_")||i("ponto_")||i("ponto.")||i("export_")||i("audit_")||i("task_")?"administracao":["upload","preview","download","rename","move","trash","restore","delete","permanent_delete","batch_permanent_delete","copy","edit","index","process","ocr","document_renewed","expiry_alert_sent","portal_envio_deleted"].includes(t)||i("folder_")||i("department_")||i("validity_")||i("ai_rename")?"documentos":"outros"}const ta={login_success:{label:"Login realizado",icon:ds,color:"text-emerald-600"},login_failed:{label:"Falha de login",icon:Ye,color:"text-destructive"},logout:{label:"Logout",icon:za,color:"text-muted-foreground"},mfa_verified:{label:"MFA verificado",icon:Ce,color:"text-emerald-600"},mfa_failed:{label:"Falha no MFA",icon:Ce,color:"text-destructive"},mfa_enrolled:{label:"MFA ativado",icon:Ce,color:"text-primary"},mfa_removed:{label:"MFA removido",icon:Ce,color:"text-destructive"},trusted_device_added:{label:"Dispositivo confiável adicionado",icon:me,color:"text-primary"},consent_revoked:{label:"Termo LGPD revogado",icon:Ye,color:"text-destructive"},subject_request_created:{label:"Solicitação de titular criada",
6icon:te,color:"text-primary"},subject_request_updated:{label:"Solicitação de titular atualizada",icon:te,color:"text-primary"},subject_report:{label:"Relatório do titular",icon:te,color:"text-primary"},subject_search:{label:"Busca de titular",icon:te,color:"text-muted-foreground"},search_cpf:{label:"Busca por CPF",icon:te,color:"text-amber-600"},privacy_settings_updated:{label:"Configurações de privacidade alteradas",icon:Re,color:"text-orange-600"},suboperadores_viewed:{label:"Suboperadores consultados",icon:te,color:"text-muted-foreground"},role_changed:{label:"Papel alterado",icon:Re,color:"text-orange-600"},"contact.merge":{label:"Contatos mesclados",icon:Re,color:"text-muted-foreground"},"certificate.used":{label:"Certificado utilizado",icon:me,color:"text-emerald-600"},audit_purge:{label:"Limpeza automática da trilha",icon:La,color:"text-amber-600"},ai_chat_query:{label:"Wedoks AI â consulta",icon:te,color:"text-primary"},portal_envio_deleted:{label:"Envio de portal excluÃdo",icon:U,color:"text-destructive"}},hs=new Set(["mfa_failed","mfa_removed","role_changed","audit_purge","login_failed","consent_revoked","permanent_delete","batch_permanent_delete"]),ra=new Set;function na(o){return o.replace(/[._]/g," ").toLowerCase().replace(/^\w/,t=>t.toUpperCase())}function Le(o){const t=Ue(o),i=o||"",d=qe[i]??qe[i.toUpperCase()]??ta[i]??ta[i.toLowerCase()];t==="outros"&&!ra.has(i)&&(ra.add(i),console.warn(`[auditoria] tipo de evento sem categoria no catálogo: ${i}`));let N=(d==null?void 0:d.label)??na(i),j=(d==null?void 0:d.icon)??U,_=(d==null?void 0:d.color)??"text-muted-foreground";return i.toLowerCase().startsWith("export_")&&(N=(d==null?void 0:d.label)??`Exportação (${i.slice(7)})`,j=(d==null?void 0:d.icon)??Ge),i.toLowerCase().startsWith("ponto_")&&(N=(d==null?void 0:d.label)??`Ponto: ${na(i.slice(6)).toLowerCase()}`),{label:N,icon:j,color:_,category:Te[t],categoria:t,severidade:hs.has(i.toLowerCase())?"warning":"info"}}const fs={termos_uso:"Termos de Uso",privacidade:"Privacidade",marketing:"Comunicação",dpa:"DPA"};function Aa(o,t){return`${fs[o]??o}${t?` v${t}`:""}`}const Vs=()=>{const{hasCertification:o}=He(),{can:t,isAdmin:i}=Ve(),d=i||t("compliance","view"),N=o?"decreto":"auditoria";return d?e.jsx(Pa,{delayDuration:150,children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("nav",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(Ie,{to:"/dashboard",className:"hover:text-foreground transition-colors",children:"Painel"}),e.jsx(ma,{size:12}),e.jsx("span",{className:"text-foreground font-medium",children:"Compliance"})]}),e.jsxs(wa,{defaultValue:N,className:"w-full",children:[e.jsxs(Ca,{className:"w-full sm:w-auto transition-all",children:[o&&e.jsxs($e,{value:"decreto",className:"gap-1.5",children:[e.jsx(ua,{size:14}),"Conformidade Legal"]}),e.jsxs($e,{value:"auditoria",className:"gap-1.5",children:[e.jsx(U,{size:14}),"Auditoria"]})]}),o&&e.jsx(aa,{value:"decreto",className:"data-[state=active]:animate-in data-[state=active]:fade-in-0 duration-200",children:e.jsx(js,{})}),e.jsx(aa,{value:"auditoria",className:"data-[state=active]:animate-in data-[state=active]:fade-in-0 duration-200",children:e.jsx(Cs,{})})]})]})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx(me,{size:48,className:"text-muted-foreground/30 mb-4"}),e.jsx("h2",{className:"text-lg font-semibold mb-1",children:"Acesso restrito"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Você não tem permissão para acessar a área de Compliance."})]})},ze=({label:o,value:t,accent:i,icon:d,valueClass:N,footer:j,alert:_})=>{const A={blue:"border-l-[#3B82F6]",green:"border-l-[#10B981]",red:"border-l-[#EF4444]",purple:"border-l-[#8B5CF6]",gray:"border-l-muted-foreground/40"},h={blue:"bg-[#3B82F6]/10 text-[#3B82F6]",green:"bg-[#10B981]/10 text-[#10B981]",red:"bg-[#EF4444]/10 text-[#EF4444]",purple:"bg-[#8B5CF6]/10 text-[#8B5CF6]",gray:"bg-muted text-muted-foreground"};return e.jsxs("div",{className:`bg-card rounded-lg border border-border border-l-4 ${A[i]} p-4 relative`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:o}),_&&e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-red-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-red-500"})]})]}),e.jsx("p",{className:`text-2xl font-bold mt-1 ${N||""}`,children:t})]}),e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center ${h[i]}`,children:e.jsx(d,{size:16})})]}),j&&e.jsx("div",{className:"mt-3",children:j})]})},la=o=>o?Xe(new Date(o),"dd MMM yyyy",{locale:We}):"â",gs=[{key:"signed_by",label:"Assinado por"},{key:"responsavel",label:"Responsável"},{key:"hash",label:"Hash SHA-256"},{key:"autor",label:"Autor"},{key:"dpi",label:"Resolução (DPI)"},{key:"colorimetria",label:"Colorimetria"},{key:"software",label:"Software"},{key:"local",label:"Local digitalização"},{key:"identificador",label:"Identificador digital"}],fe=25,js=()=>{const{tenantId:o}=He(),{can:t,isAdmin:i}=Ve(),d=i||t("compliance","export"),{toast:N}=xa(),[j,_]=x.useState([]),[A,h]=x.useState(!0),[b,S]=x.useState(null),[H,re]=x.useState(""),[P,ne]=x.use
6State("all"),[E,le]=x.useState("all"),[D,ue]=x.useState("all"),[Y,ae]=x.useState([]),[v,oe]=x.useState(new Set),[V,xe]=x.useState(0),[F,be]=x.useState(null),[p,ie]=x.useState(null);x.useEffect(()=>{if(!o){_([]),h(!1);return}(async()=>{h(!0);try{const{data:n,error:m}=await je.from("documents").select("id, final_file_name, original_file_name, is_signed, signed_at, signed_by, metadata, folder_id, department_id, folders:folder_id(name, departments:department_id(name)), departments:department_id(name), document_storage(public_url, external_file_id)").eq("tenant_id",o).eq("is_signed",!0).order("created_at",{ascending:!1}).limit(1e3);if(m)throw m;const c=(n||[]).map(l=>({...l,folders:l.folders||null,departments:l.departments||null,document_storage:l.document_storage||[]}));_(c),S(new Date)}catch(n){console.error("conformidade fetch error:",n),N({title:"Erro ao carregar documentos",description:n.message,variant:"destructive"}),_([])}finally{h(!1)}})()},[o,N]);const K=s=>{var m;const n=s.metadata;return n&&typeof n=="object"&&((m=n.decreto_10278)==null?void 0:m.conformidade)===!0},M=x.useMemo(()=>j.filter(K).length,[j]),pe=j.length-M,R=j.length>0?M/j.length*100:0,he=R>=90?"#10B981":R>=70?"#F59E0B":"#EF4444",ve=x.useMemo(()=>{const s=new Set;return j.forEach(n=>{var c,l,g;const m=((l=(c=n.metadata)==null?void 0:c.decreto_10278)==null?void 0:l.tipo_documental)||((g=n.metadata)==null?void 0:g.tipo_documental);m&&s.add(String(m))}),Array.from(s).sort()},[j]),J=x.useMemo(()=>{const s=H.toLowerCase();let n=null;if(D!=="all"){const c=parseInt(D);Number.isNaN(c)?D==="ytd"&&(n=new Date(new Date().getFullYear(),0,1)):n=ka(new Date,c)}return j.filter(c=>{var I,y,r,k,T,B,G,q;const l=K(c);if(P==="conforme"&&!l||P==="nao_conforme"&&l||P==="pendente"&&c.signed_at)return!1;const g=((y=(I=c.metadata)==null?void 0:I.decreto_10278)==null?void 0:y.tipo_documental)||((r=c.metadata)==null?void 0:r.tipo_documental)||"";if(E!=="all"&&g!==E||n&&c.signed_at&&new Date(c.signed_at)<n)return!1;if(s){const X=(c.final_file_name||c.original_file_name||"").toLowerCase(),ye=((T=(k=c.folders)==null?void 0:k.name)==null?void 0:T.toLowerCase())||"",we=(((G=(B=c.folders)==null?void 0:B.departments)==null?void 0:G.name)||((q=c.departments)==null?void 0:q.name)||"").toLowerCase();if(!X.includes(s)&&!ye.includes(s)&&!we.includes(s))return!1}return!0}).sort((c,l)=>{const g=c.signed_at?new Date(c.signed_at).getTime():0;return(l.signed_at?new Date(l.signed_at).getTime():0)-g})},[j,H,P,E,D]);x.useEffect(()=>{xe(0)},[H,P,E,D]);const se=Math.max(1,Math.ceil(J.length/fe)),W=J.slice(V*fe,(V+1)*fe),Q=W.length>0&&W.every(s=>v.has(s.id)),Me=()=>{const s=new Set(v);Q?W.forEach(n=>s.delete(n.id)):W.forEach(n=>s.add(n.id)),oe(s)},Ne=s=>{const n=new Set(v);n.has(s)?n.delete(s):n.add(s),oe(n)},ee=s=>{var c,l,g,I;const n=(c=s.folders)==null?void 0:c.name,m=((g=(l=s.folders)==null?void 0:l.departments)==null?void 0:g.name)||((I=s.departments)==null?void 0:I.name);return m&&n?`${m} / ${n}`:m||n||"Sem pasta"},C=(s,...n)=>{const m=s.metadata||{},c=m.decreto_10278||{},l=m.xmp_injected||{};for(const g of n){if(c[g])return c[g];if(l[g])return l[g];if(m[g])return m[g]}return""},a=()=>{const s=J;if(s.length===0){N({title:"Nenhum documento para exportar",variant:"destructive"});return}const n=["Nome do arquivo","Pasta","Departamento","Assinado por","Data assinatura","Hash SHA-256","Responsável digitalização","DPI","Colorimetria","Software","Assunto","Autor","Tipo documental","Local digitalização","Identificador digital","Conforme Decreto","Link do sistema"].join(";"),m=s.map(y=>{var q,X,ye,we;const r=y.final_file_name||y.original_file_name||"",k=((q=y.folders)==null?void 0:q.name)||"",T=((ye=(X=y.folders)==null?void 0:X.departments)==null?void 0:ye.name)||((we=y.departments)==null?void 0:we.name)||"",B=y.signed_at?new Date(y.signed_at).toLocaleString("pt-BR"):"",G=Ea=>`"${String(Ea||"").replace(/"/g,'""')}"`;return[r,k,T,y.signed_by,B,C(y,"hash_sha256","hashSHA256"),C(y,"responsavel_digitalizacao","responsavel"),C(y,"resolucao_dpi","resolucaoDPI"),C(y,"colorimetria"),C(y,"software","softwareDigitalizacao"),C(y,"assunto"),C(y,"autor"),C(y,"tipo_documental"),C(y,"local_digitalizacao"),C(y,"identificador_digital"),K(y)?"Sim":"Não",`${window.location.origin}/dashboard/ecm?doc=${y.id}`].map(G).join(";")}),c="\uFEFF"+n+` 7`+m.join(`
8`),l=new Blob([c],{type:"text/csv;charset=utf-8;"}),g=URL.createObjectURL(l),I=document.createElement("a");I.href=g,I.download=`certificados-${new Date().toISOString().slice(0,10)}.csv`,I.click(),URL.revokeObjectURL(g),N({title:`${s.length} documento(s) exportado(s)`})},u=s=>{s&&(navigator.clipboard.writeText(s),N({title:"Hash copiado para a área de transferência"}))},f=x.useMemo(()=>{const s=[];if(P!=="all"){const n={conforme:"Conformes",nao_conforme:"Não conformes",pendente:"Pendente"};s.push({key:"conf",label:`Conformidade: ${n[P]}`,onRemove:()=>ne("all")})}if(E!=="all"&&s.push({key:"tipo",label:`Tipo: ${E}`,onRemove:()=>le("all")}),D!=="all"){const n={30:"30 dias",90:"90 dias",ytd:"Este ano"};s.push({key:"per",label:`PerÃodo: ${n[D]||D}`,onRemove:()=>ue("all")})}return H&&s.push({key:"q",label:`Busca: ${H}`,onRemove:()=>re("")}),s},[P,E,D,H]);return e.jsxs("div",{className:"space-y-6 mt-4",children:[e.jsx(Sa,{title:"Auditoria",description:"Documentos certificados conforme o Decreto 10.278/2020.",icon:e.jsx(me,{size:20,style:{color:he}}),actions:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Ãltima verificação:"," ",e.jsx("span",{className:"font-medium text-foreground",children:b?Xe(b,"dd MMM yyyy 'à s' HH:mm",{locale:We}):"â"})]})}),A?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[0,1,2].map(s=>e.jsx(Pe,{className:"h-[110px] rounded-lg"},s))}):e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx(ze,{label:"Total certificados",value:j.length,accent:"blue",icon:_e}),e.jsx(ze,{label:"Conformes",value:M,accent:"green",icon:ce,valueClass:"text-[#10B981]",footer:e.jsxs("div",{children:[e.jsx("div",{className:"h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full bg-[#10B981] transition-all",style:{width:`${R}%`}})}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1",children:[R.toFixed(0),"% do total"]})]})}),e.jsx(ze,{label:"Não conformes",value:pe,accent:"red",icon:pa,valueClass:"text-[#EF4444] font-extrabold",alert:pe>0,footer:pe>0&&e.jsxs($,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs text-[#EF4444] hover:text-[#EF4444] hover:bg-red-50 dark:hover:bg-red-950/30 gap-1",onClick:()=>ne("nao_conforme"),children:["Ver pendências ",e.jsx(Fa,{size:12})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(Be,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(ha,{placeholder:"Buscar documento, pasta ou departamento...",value:H,onChange:s=>re(s.target.value),className:"pl-9 h-9"})]}),e.jsxs(ke,{value:P,onValueChange:s=>ne(s),children:[e.jsx(De,{className:"w-[160px] h-9 text-xs",children:e.jsx(Ae,{placeholder:"Conformidade"})}),e.jsxs(Ee,{children:[e.jsx(O,{value:"all",children:"Todos"}),e.jsx(O,{value:"conforme",children:"Conformes"}),e.jsx(O,{value:"nao_conforme",children:"Não conformes"}),e.jsx(O,{value:"pendente",children:"Pendente"})]})]}),e.jsxs(ke,{value:E,onValueChange:le,children:[e.jsx(De,{className:"w-[170px] h-9 text-xs",children:e.jsx(Ae,{placeholder:"Tipo Documental"})}),e.jsxs(Ee,{children:[e.jsx(O,{value:"all",children:"Todos os tipos"}),ve.map(s=>e.jsx(O,{value:s,children:s},s))]})]}),e.jsxs(ke,{value:D,onValueChange:ue,children:[e.jsx(De,{className:"w-[160px] h-9 text-xs",children:e.jsx(Ae,{placeholder:"PerÃodo"})}),e.jsxs(Ee,{children:[e.jsx(O,{value:"all",children:"Todo perÃodo"}),e.jsx(O,{value:"30",children:"Ãltimos 30 dias"}),e.jsx(O,{value:"90",children:"Ãltimos 90 dias"}),e.jsx(O,{value:"ytd",children:"Este ano"})]})]}),e.jsx("div",{className:"flex-1"}),e.jsxs(Ma,{children:[e.jsx(Ra,{asChild:!0,children:e.jsxs($,{size:"sm",variant:"outline",className:"text-xs gap-1.5 h-9",children:[e.jsx(xs,{size:12}),"Colunas"]})}),e.jsxs(Ia,{align:"end",children:[e.jsx(Ba,{className:"text-xs",children:"Colunas opcionais"}),e.jsx(Oa,{}),gs.map(s=>e.jsx($a,{checked:Y.includes(s.key),onCheckedChange:n=>ae(m=>n?[...m,s.key]:m.filter(c=>c!==s.key)),children:s.label},s.key))]})]}),d&&e.jsxs($,{size:"sm",variant:"outline",className:"text-xs gap-1.5 h-9",onClick:a,children:[e.jsx(Ge,{size:12}),"Exportar"]})]}),f.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[f.map(s=>e.jsxs(Z,{variant:"secondary",className:"gap-1 pr-1 font-normal",children:[s.label,e.jsx("button",{onClick:s.onRemove,className:"rounded hover:bg-muted-foreground
8/20 p-0.5",children:e.jsx(qa,{size:10})})]},s.key)),e.jsx("button",{onClick:()=>{ne("all"),le("all"),ue("all"),re("")},className:"text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline",children:"Limpar tudo"})]}),e.jsx("div",{className:"bg-card rounded-lg border border-border overflow-hidden",children:A?e.jsx("div",{className:"p-4 space-y-2",children:[0,1,2,3,4].map(s=>e.jsx(Pe,{className:"h-12 w-full"},s))}):J.length===0?e.jsxs("div",{className:"text-center py-16 px-6",children:[e.jsx(me,{size:64,className:"mx-auto text-primary/40 mb-4"}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:"Nenhum documento certificado encontrado"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-5 max-w-md mx-auto",children:"Ajuste os filtros ou importe documentos para iniciar o processo de conformidade."}),e.jsx($,{asChild:!0,size:"sm",children:e.jsx(Ie,{to:"/dashboard/ecm",children:"Ir para Arquivo Digital"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs(va,{children:[e.jsx(Na,{children:e.jsxs(Fe,{children:[e.jsx(L,{className:"w-[40px] whitespace-nowrap",children:e.jsx(Ke,{checked:Q,onCheckedChange:Me})}),e.jsx(L,{className:"w-[120px] whitespace-nowrap",children:"Data"}),e.jsx(L,{children:"Documento"}),e.jsx(L,{className:"text-center w-[160px] whitespace-nowrap",children:"Conformidade"})]})}),e.jsx(ya,{children:W.map(s=>{const n=s.final_file_name||s.original_file_name||"Sem nome",m=K(s),c=ee(s);return e.jsxs(Fe,{className:"group hover:bg-muted/50 cursor-pointer",onClick:()=>ie(s),children:[e.jsx(z,{onClick:l=>l.stopPropagation(),children:e.jsx(Ke,{checked:v.has(s.id),onCheckedChange:()=>Ne(s.id)})}),e.jsx(z,{className:"text-xs text-muted-foreground tabular-nums whitespace-nowrap",children:la(s.signed_at)}),e.jsx(z,{className:"min-w-0",children:e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx(_e,{size:14,className:"text-muted-foreground shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",title:n,children:n}),e.jsxs("p",{className:"flex items-center gap-1 text-[11px] text-muted-foreground truncate",title:c,children:[e.jsx(Ua,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:c})]})]})]})}),e.jsx(z,{className:"text-center",onClick:l=>l.stopPropagation(),children:e.jsx("button",{onClick:()=>be(s),className:"inline-block hover:opacity-80 transition-opacity",children:m?e.jsxs(Z,{className:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400 cursor-pointer",children:[e.jsx(ce,{size:10,className:"mr-1"}),"Conforme"]}):e.jsxs(Z,{className:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400 cursor-pointer",children:[e.jsx(de,{size:10,className:"mr-1"}),"Não conforme"]})})})]},s.id)})})]})}),e.jsx("div",{className:"md:hidden divide-y divide-border",children:W.map(s=>{const n=s.final_file_name||s.original_file_name||"Sem nome",m=K(s);return e.jsx("button",{onClick:()=>ie(s),className:"w-full text-left p-4 hover:bg-muted/40 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:n}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:ee(s)}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:la(s.signed_at)})]}),m?e.jsxs(Z,{className:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400 shrink-0",children:[e.jsx(ce,{size:10,className:"mr-1"})," Conforme"]}):e.jsxs(Z,{className:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400 shrink-0",children:[e.jsx(de,{size:10,className:"mr-1"})," Não conforme"]})]})},s.id)})}),e.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-3 border-t border-border",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Mostrando ",W.length>0?V*fe+1:0,"â",Math.min((V+1)*fe,J.length)," de ",J.length," registros"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs($,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",disabled:V===0,onClick:()=>xe(s=>s-1),children:[e.jsx(Ha,{size:12})," Anterior"]}),e.jsxs("span",{className:"text-xs text-muted-foreground px-2",children:[V+1," / ",se]}),e.jsxs($,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",disabled:V>=se-1,onClick:()=>xe(s=>s+1),children:["Próximo ",e.jsx(ma,{size:12})]})]})]})]})}),e.jsx(Va,{open:!!F,onOpenChange:s=>!s&&be(null),children:e.jsxs(Wa,{className:"sm:max-w-lg max-w-[calc(100vw-2rem)] overflow-hidden",children:[e.jsxs(Ga,{children:[e.jsxs(Xa,{className:"flex items-center gap-2 min-w-0",children:[e.jsx(ua,{size:18,className:"text-primary shrink-0"}),e.jsx("span",{className:"truncate",children:"Conformidade â Decreto 10.278/2020"})]}),e.jsx(Ya,{children:"Metadados e status de conformidade do documento certificado."})]}),F&&e.jsxs("div",{className:"space-y-4 min-w-0",children:[e.jsxs("p",{className:"text-xs text-muted-foreground break-all",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Arquivo:"})," ",F.final_file_name||F.original_file_name]}),e.jsxs("p",{className:"text-xs text-muted-foreground break-words",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Pasta:"})," ",ee(F)]}),e.jsx(us,{metadata:F.metadata||{},isSigned:F.is_signed,signedBy:F.signed_by,signedAt:F.signed_at})]})]})}),e.jsx(fa,{open:!!p,onOpenChange:s=>!s&&ie(null),children:e.jsxs(ga,{className:Oe("w-full sm:max-w-lg overflow-y-auto border-l-4",p&&K(p)?"border-l-emerald-500":"border-l-red-500"),children:[e.jsxs(ja,{children:[e.jsx("div",{className:"flex items-center gap-2 mb-1",children:p&&K(p)?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300",children:[e.jsx(ce,{size:12}),"Conforme"]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300",children:[e.jsx(de,{size:12}),"Não conforme"]})}),e.jsxs(_a,{className:"flex items-center gap-2 text-base",children:[e.jsx(_e,{size:16,className:"text-primary"}),"Detalhes do documento"]}),e.jsx(ba,{className:"truncate",children:(p==null?void 0:p.final_file_name)||(p==null?void 0:p.original_file_name)})]}
8),p&&e.jsxs("div",{className:"space-y-4 mt-4 text-sm",children:[e.jsx(w,{label:"Pasta",value:ee(p)}),e.jsx(w,{label:"Data de assinatura",value:p.signed_at?new Date(p.signed_at).toLocaleString("pt-BR"):"â"}),e.jsx(w,{label:"Assinado por",value:p.signed_by||"â"}),e.jsx(w,{label:"Tipo documental",value:String(C(p,"tipo_documental")||"â")}),e.jsx(w,{label:"Assunto",value:String(C(p,"assunto")||"â")}),e.jsx(w,{label:"Responsável",value:String(C(p,"responsavel_digitalizacao","responsavel")||"â")}),e.jsx(w,{label:"Autor",value:String(C(p,"autor")||"â")}),e.jsx(w,{label:"Resolução (DPI)",value:String(C(p,"resolucao_dpi","resolucaoDPI")||"â")}),e.jsx(w,{label:"Colorimetria",value:String(C(p,"colorimetria")||"â")}),e.jsx(w,{label:"Software de digitalização",value:String(C(p,"software","softwareDigitalizacao")||"â")}),e.jsx(w,{label:"Local de digitalização",value:String(C(p,"local_digitalizacao")||"â")}),e.jsx(w,{label:"Identificador digital",value:String(C(p,"identificador_digital")||"â")}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Hash SHA-256"}),e.jsxs("div",{className:"flex items-start gap-2 mt-1",children:[e.jsx("code",{className:"font-mono text-[10px] break-all flex-1 bg-muted p-2 rounded",children:C(p,"hash_sha256","hashSHA256")||"â"}),!!C(p,"hash_sha256","hashSHA256")&&e.jsx($,{size:"sm",variant:"outline",className:"h-7 px-2",onClick:()=>u(String(C(p,"hash_sha256","hashSHA256"))),children:e.jsx(ps,{size:12})})]})]}),p.metadata&&typeof p.metadata=="object"&&(()=>{const s=new Set(["tipo_documental","assunto","responsavel_digitalizacao","responsavel","autor","resolucao_dpi","resolucaoDPI","colorimetria","software","softwareDigitalizacao","local_digitalizacao","identificador_digital","hash_sha256","hashSHA256"]),n=Object.entries(p.metadata).filter(([l,g])=>!s.has(l)&&g!=null&&g!==""&&(typeof g!="object"||Array.isArray(g)));if(n.length===0)return null;const m=l=>l.replace(/_/g," ").replace(/\b\w/g,g=>g.toUpperCase()),c=l=>Array.isArray(l)?l.join(", "):String(l);return e.jsxs("div",{className:"pt-3 border-t space-y-3",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground font-medium",children:"Outros metadados"}),n.map(([l,g])=>e.jsx(w,{label:m(l),value:c(g)},l))]})})(),e.jsx($,{asChild:!0,size:"sm",className:"w-full",children:e.jsx(Ie,{to:`/dashboard/ecm?doc=${p.id}`,children:"Abrir no Arquivo Digital"})})]})]})})]})},w=({label:o,value:t})=>e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:o}),e.jsx("p",{className:"mt-0.5",children:t})]}),ge=20,_s=5e3,bs={owner:"Proprietário",admin:"Administrador",member:"Membro",viewer:"Visualizador",external:"Cliente externo",super_admin:"Super admin"},oa=new Set(["role_changed","profile_assigned","scope_changed"]);function vs(o,t,i,d){const N=_=>_==null||Array.isArray(_)&&!_.length?"â":o==="role_changed"?bs[_]??String(_):o==="profile_assigned"?d[_]??"perfil":o==="scope_changed"&&Array.isArray(_)?`${_.length} departamento(s)`:String(_),j=o==="profile_assigned"&&(t!=null&&t.removed)?"sem perfil":N((t==null?void 0:t.after)??(o==="profile_assigned"?t==null?void 0:t.profile_id:void 0));return`${i||"Usuário"} · ${N(t==null?void 0:t.before)} â ${j}`}function Ns(o){return o?Array.isArray(o.termos)?o.termos.filter(t=>t==null?void 0:t.tipo):o.tipo?[{tipo:o.tipo,versao:o.versao}]:[]:[]}function ys(o){const t=[],i=new Map;for(const d of o){const N=d.event_type.toUpperCase();let j=null;if(d.event_type==="consent_accepted"&&d.user_id?j=`c:${d.user_id}`:(N==="PREVIEW"||N==="DOWNLOAD")&&d.user_id&&d.file_id&&(j=`d:${d.user_id}:${d.file_id}:${d.event_type}`),j){const _=i.get(j);if(_&&Math.abs(new Date(_.created_at).getTime()-new Date(d.created_at).getTime())<_s){_.count+=1;for(const A of d.termos)_.termos.some(h=>h.tipo===A.tipo&&h.versao===A.versao)||_.termos.push(A);continue}i.set(j,d)}t.push(d)}return t}const ia=["TRASH","DELETE","PERMANENT_DELETE","BATCH_PERMANENT_DELETE"],ca=["todos","acessos","documentos","compartilhamento","assinaturas","lgpd","acervo","administracao","ia"];function da(o){return o.event_type==="consent_accepted"&&o.termos.length?`Termos aceitos (${o.termos.map(t=>Aa(t.tipo,t.versao)).join(", ")})`:Le(o.event_type).label}const ws=({options:o,selected:t,onChange:i,grouped:d})=>{const[N,j]=x.useState(!1),_=(b,S)=>(b.count===0?1:0)-(S.count===0?1:0)||b.label.localeCompare(S.label,"pt-B
8R"),A=d?Da.map(b=>({key:b.key,label:b.label,items:o.filter(S=>S.categoria===b.key).sort(_)})).filter(b=>b.items.length):[{key:"all",label:"",items:[...o].sort(_)}],h=b=>i(t.includes(b)?t.filter(S=>S!==b):[...t,b]);return e.jsxs(Za,{open:N,onOpenChange:j,children:[e.jsx(Ja,{asChild:!0,children:e.jsxs($,{variant:"outline",size:"sm",className:"h-9 w-[240px] justify-between font-normal",children:[e.jsx("span",{className:"truncate",children:t.length===0?"Todos os tipos":`${t.length} tipo(s) selecionado(s)`}),e.jsx(es,{size:14,className:"opacity-50 shrink-0"})]})}),e.jsx(as,{className:"w-[320px] p-0",align:"start",children:e.jsxs(ss,{children:[e.jsx(ts,{placeholder:"Buscar tipo de evento..."}),e.jsxs(rs,{className:"max-h-[400px] overflow-y-auto",children:[e.jsx(ns,{children:"Nenhum tipo encontrado."}),A.map(b=>e.jsx(ls,{heading:b.label||void 0,children:b.items.map(S=>e.jsxs(os,{value:`${S.label} ${S.value}`,onSelect:()=>h(S.value),className:Oe(S.count===0&&"opacity-50"),children:[e.jsx(is,{size:14,className:Oe("mr-2",t.includes(S.value)?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1 truncate",children:S.label}),e.jsx("span",{className:"ml-2 text-xs text-muted-foreground tabular-nums",children:S.count})]},S.value))},b.key))]}),t.length>0&&e.jsx("div",{className:"border-t border-border p-1",children:e.jsx($,{variant:"ghost",size:"sm",className:"w-full h-8 text-xs",onClick:()=>i([]),children:"Limpar"})})]})})]})},Cs=()=>{const{tenantId:o}=He(),{can:t,isAdmin:i}=Ve(),d=i||t("compliance","export"),{toast:N}=xa(),[j,_]=Ka(),A=j.get("categoria"),h=A&&ca.includes(A)?A:"todos",[b,S]=x.useState([]),[H,re]=x.useState(!1),[P,ne]=x.useState("7"),[E,le]=x.useState([]),[D,ue]=x.useState(""),[Y,ae]=x.useState(0),[v,oe]=x.useState(null),[V,xe]=x.useState(null),[F,be]=x.useState({}),p=a=>{const u=new URLSearchParams(j);a==="todos"?u.delete("categoria"):u.set("categoria",a),_(u,{replace:!0}),le([]),ae(0)},ie=x.useCallback(async()=>{if(o){re(!0);try{const a=ka(new Date,parseInt(P)).toISOString(),{data:u,error:f}=await ms(()=>je.from("audit_logs").select("id, event_type, created_at, user_id, user_name, user_email, file_name, document_id, ip_address, user_agent, details, target_user_id").eq("tenant_id",o).gte("created_at",a).order("created_at",{ascending:!1}).order("id",{ascending:!1}),{max:2e4});if(f)throw f;const s=Array.from(new Set([...u.filter(r=>r.user_id&&!r.user_name).map(r=>r.user_id),...u.filter(r=>oa.has(r.event_type)&&r.target_user_id).map(r=>r.target_user_id)])),n=Array.from(new Set(u.filter(r=>r.event_type==="profile_assigned").flatMap(r=>{var k,T,B;return[(k=r.details)==null?void 0:k.before,(T=r.details)==null?void 0:T.after,(B=r.details)==null?void 0:B.profile_id]}).filter(r=>typeof r=="string"))),m={};if(n.length){const{data:r}=await je.from("permission_profiles").select("id, name").in("id",n);(r||[]).forEach(k=>{m[k.id]=k.name})}const c={};if(s.length){const{data:r}=await je.from("profiles").select("user_id, name, email").in("user_id",s);(r||[]).forEach(k=>{c[k.user_id]={name:k.name,email:k.email}})}const l=u.map(r=>{var k,T,B,G,q,X;return{event_id:r.id,event_type:r.event_type,created_at:r.created_at,user_id:r.user_id||"",user_name:r.user_name||((k=c[r.user_id])==null?void 0:k.name)||((T=c[r.user_id])==null?void 0:T.email)||"",user_email:r.user_email||((B=c[r.user_id])==null?void 0:B.email)||"",file_name:r.file_name||"",file_id:r.document_id||"",ip_address:r.ip_address||"",user_agent:r.user_agent||"",details:r.details||null,categoria:Ue(r.event_type),count:1,termos:r.event_type==="consent_accepted"?Ns(r.details):[],sistema:!r.user_id&&((G=r.details)==null?void 0:G.actor)==="system",descricao:oa.has(r.event_type)?vs(r.event_type,r.details,((q=c[r.target_user_id])==null?void 0:q.name)||((X=c[r.target_user_id])==null?void 0:X.email)||"",m):void 0}}),g=ys(l);S(g),ae(0),xe(new Date);const I=Array.from(new Set(g.map(r=>r.file_id).filter(Boolean))),y={};for(let r=0;r<I.length;r+=200){const{data:k}=await je.from("documents").select("id, departments:department_id(name), folders:folder_id(departments:department_id(name))").in("id",I.slice(r,r+200));
8(k||[]).forEach(T=>{var G,q,X;const B=((q=(G=T.folders)==null?void 0:G.departments)==null?void 0:q.name)||((X=T.departments)==null?void 0:X.name);B&&(y[T.id]=B)})}be(y)}catch(a){console.error("Audit fetch error:",a),N({title:"Erro ao buscar logs de auditoria",description:a.message,variant:"destructive"})}finally{re(!1)}}},[o,P,N]);x.useEffect(()=>{ie()},[ie]);const K=x.useMemo(()=>{const a={todos:b.length};return b.forEach(u=>{a[u.categoria]=(a[u.categoria]||0)+1}),a},[b]),M=x.useMemo(()=>h==="todos"?b:b.filter(a=>a.categoria===h),[b,h]),pe=x.useMemo(()=>{const a={};M.forEach(s=>{a[s.event_type]=(a[s.event_type]||0)+1});const u=[...Object.keys(qe),...Object.keys(a)],f=new Set;return u.filter(s=>f.has(s)?!1:(f.add(s),!0)).map(s=>({value:s,label:Le(s).label,categoria:Ue(s),count:a[s]||0})).filter(s=>h==="todos"||s.categoria===h)},[M,h]),R=x.useMemo(()=>{let a=M;if(E.length&&(a=a.filter(u=>E.includes(u.event_type))),D){const u=D.toLowerCase();a=a.filter(f=>{var s,n,m;return((s=f.file_name)==null?void 0:s.toLowerCase().includes(u))||((n=f.user_name)==null?void 0:n.toLowerCase().includes(u))||((m=f.user_email)==null?void 0:m.toLowerCase().includes(u))})}return a},[M,E,D]);x.useEffect(()=>{ae(0)},[D,E]);const he=Math.max(1,Math.ceil(R.length/ge)),ve=R.slice(Y*ge,(Y+1)*ge),J=x.useMemo(()=>{const a=f=>M.filter(s=>f.includes(s.event_type)||f.includes(s.event_type.toUpperCase())).length,u=f=>new Set(M.map(f).filter(Boolean)).size;switch(h){case"acessos":return[{label:"Logins com sucesso",value:a(["login_success"]),accent:"green",icon:ce},{label:"Falhas de login",value:a(["login_failed"]),accent:"red",icon:de},{label:"IPs distintos",value:u(f=>f.ip_address),accent:"blue",icon:U},{label:"Usuários distintos",value:u(f=>f.user_id||f.user_email),accent:"gray",icon:Se}];case"documentos":return[{label:"Uploads",value:a(["UPLOAD"]),accent:"blue",icon:U},{label:"Visualizações",value:a(["PREVIEW"]),accent:"gray",icon:Se},{label:"Downloads",value:a(["DOWNLOAD"]),accent:"purple",icon:sa},{label:"Exclusões",value:a(ia),accent:"red",icon:Qe}];case"assinaturas":return[{label:"Enviados",value:a(["autentique_sign_sent","autentique_batch_sign_sent"]),accent:"blue",icon:U},{label:"ConcluÃdos",value:a(["autentique_signed","SIGN"]),accent:"green",icon:ce},{label:"Parciais",value:a(["autentique_partially_signed"]),accent:"gray",icon:pa},{label:"Recusados",value:a(["autentique_rejected"]),accent:"red",icon:de}];case"lgpd":return[{label:"Aceites",value:a(["consent_accepted"]),accent:"green",icon:me},{label:"Revogações",value:a(["consent_revoked"]),accent:"red",icon:de},{label:"Solicitações de titulares",value:a(["subject_request_created"]),accent:"blue",icon:_e},{label:"Buscas por CPF",value:a(["search_cpf"]),accent:"purple",icon:Be}];case"todos":return[{label:"Total eventos",value:M.length,accent:"blue",icon:U},{label:"Visualizações",value:a(["PREVIEW"]),accent:"gray",icon:Se},{label:"Downloads",value:a(["DOWNLOAD"]),accent:"purple",icon:sa},{label:"Exclusões",value:a(ia),accent:"red",icon:Qe}];default:return[{label:"Total eventos",value:M.length,accent:"blue",icon:U},{label:"Usuários distintos",value:u(f=>f.user_id||f.user_email),accent:"gray",icon:Se}]}},[h,M]),se=a=>a?/iPhone|iPad/i.test(a)?"iOS":/Android/i.test(a)?"Android":/Windows/i.test(a)?"Windows":/Mac OS/i.test(a)?"macOS":/Linux/i.test(a)?"Linux":"Desconhecido":"â",W=a=>/fail/i.test(a.event_type)?"Falha":"Sucesso",Q=a=>a.termos.length?a.termos.map(u=>Aa(u.tipo,u.versao)).join(", "):"â",Me=()=>{if(R.length===0){N({title:"Nenhum evento para exportar",variant:"destructive"});return}const a=["Data/hora","Categoria","Usuário","E-mail","Ação","Ocorrências","Arquivo / descrição","ID Arquivo","IP","Dispositivo","Departamento","Termos"].join(";"),u=l=>`"${String(l??"").replace(/"/g,'""')}"`,f=R.map(l=>[new Date(l.created_at).toLocaleString("pt-BR"),Te[l.categoria],ee(l),l.user_email,da(l),l.count,l.file_name||l.descricao||"",l.file_id,l.ip_address,se(l.user_agent),F[l.file_id]||"",Q(l)==="â"?"":Q(l)].map(u).join(";")),s="\uFEFF"+a+` 9`+f.join(` 10`),n=new Blob([s],{type:"text/csv;charset=utf-8;"}),m=URL.createObjectURL(n),c=document.createElement("a");c.href=m,c.download=`auditoria-${h}-${new Date().toISOString().slice(0,10)}.csv`,c.click(),URL.revokeObjectURL(m),N({title:`${R.length} evento(s) exportado(s)`})},Ne=h!=="acessos"&&h!=="lgpd",ee=a=>a.user_name||(a.sistema?"Sistema":a.event_type.startsWith("autentique_")?"Sistema (assinatura externa)":"Não identificado"),C=a=>a.user_name?e.jsx("span",{className:"text-sm",children:a.user_name}):a.sistema?e.jsxs(Z,{variant:"outline",className:"gap-1 rounded-full font-normal text-muted-foreground",children:[e.jsx(cs,{size:10}),"Sistema"]}
10):a.event_type.startsWith("autentique_")?e.jsx("span",{className:"text-sm italic text-muted-foreground",children:"Sistema (assinatura externa)"}):e.jsx("span",{className:"text-sm italic text-muted-foreground",children:"Não identificado"});return e.jsxs("div",{className:"space-y-6 mt-4",children:[e.jsx(Sa,{title:"Auditoria",description:"Histórico completo de eventos de acesso, alterações e exclusões.",icon:e.jsx(U,{size:20,className:"text-primary"}),actions:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Ãltima verificação:"," ",e.jsx("span",{className:"font-medium text-foreground",children:V?Xe(V,"dd MMM yyyy 'à s' HH:mm",{locale:We}):"â"})]})}),i&&e.jsxs("div",{className:"rounded-lg border border-border border-l-4 border-l-primary bg-muted/40 p-4 flex flex-col sm:flex-row sm:items-center gap-3",children:[e.jsx(Qa,{size:18,className:"text-primary shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Retenção por categoria"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Cada categoria tem seu prazo (ex.: Acessos 3 anos, Assinaturas 10 anos). Aceites e revogações LGPD são mantidos enquanto a conta existir."})]}),e.jsx("a",{href:"/dashboard/privacidade?aba=config",className:"text-sm font-medium text-primary underline underline-offset-4",children:"Ver detalhes"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsx(wa,{value:h,onValueChange:p,children:e.jsx(Ca,{children:ca.map(a=>e.jsxs($e,{value:a,className:"gap-1.5",children:[a==="todos"?"Todos":Te[a],e.jsx("span",{className:"rounded-full bg-muted px-1.5 text-[10px] tabular-nums text-muted-foreground",children:K[a]||0})]},a))})})}),H&&b.length===0?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[0,1,2,3].map(a=>e.jsx(Pe,{className:"h-[90px] rounded-lg"},a))}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:J.map(a=>e.jsx(ze,{label:a.label,value:a.value,accent:a.accent,icon:a.icon},a.label))}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(Be,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(ha,{placeholder:"Buscar por arquivo ou usuário...",value:D,onChange:a=>ue(a.target.value),className:"pl-9 h-9"})]}),e.jsxs(ke,{value:P,onValueChange:ne,children:[e.jsx(De,{className:"w-[150px] h-9",children:e.jsx(Ae,{})}),e.jsxs(Ee,{children:[e.jsx(O,{value:"7",children:"Ãltimos 7 dias"}),e.jsx(O,{value:"30",children:"Ãltimos 30 dias"}),e.jsx(O,{value:"90",children:"Ãltimos 90 dias"})]})]}),e.jsx(ws,{options:pe,selected:E,onChange:le,grouped:h==="todos"}),d&&e.jsxs($,{size:"sm",variant:"outline",className:"text-xs gap-1.5 h-9",onClick:Me,children:[e.jsx(Ge,{size:12}),"Exportar CSV"]})]}),e.jsx("div",{className:"bg-card rounded-lg border border-border overflow-hidden",children:H?e.jsx("div",{className:"p-4 space-y-2",children:[0,1,2,3,4].map(a=>e.jsx(Pe,{className:"h-12 w-full"},a))}):R.length===0?e.jsxs("div",{className:"text-center py-16 px-6",children:[e.jsx(U,{size:64,className:"mx-auto text-primary/40 mb-4"}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:"Sem eventos de auditoria no perÃodo selecionado"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-md mx-auto",children:"Tente ampliar o intervalo de datas ou remover filtros."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(va,{children:[e.jsx(Na,{children:e.jsxs(Fe,{children:[e.jsx(L,{className:"py-2",children:"Data/hora"}),e.jsx(L,{className:"py-2",children:"Usuário"}),h==="acessos"?e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"py-2",children:"IP"}),e.jsx(L,{className:"py-2",children:"Dispositivo"})]}):e.jsx(L,{className:"py-2",children:"IP / Dispositivo"}),e.jsx(L,{className:"py-2",children:"Ação"}),h==="acessos"&&e.jsx(L,{className:"py-2",children:"Resultado"}),h==="lgpd"&&e.jsx(L,{className:"py-2",children:"Termo e versão"}),Ne&&e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"py-2",children:"Arquivo"}),e.jsx(L,{className:"py-2",children:"Departamento"})]})]})}),e.jsx(ya,{children:ve.map(a=>{const u=Le(a.event_type),f=u.icon;return e.jsxs(Fe,{className:"hover:bg-muted/50 cursor-pointer",onClick:()=>oe(a),children:[e.jsx(z,{className:"text-xs text-muted-foreground whitespace-nowrap py-2",children:new Date(a.created_at).toLocaleStr
10ing("pt-BR",{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"})}),e.jsx(z,{className:"py-2",children:C(a)}),h==="acessos"?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"py-2 font-mono text-xs",children:a.ip_address||"â"}),e.jsx(z,{className:"py-2 text-xs",children:se(a.user_agent)})]}):e.jsx(z,{className:"py-2",children:e.jsxs("div",{className:"text-xs",children:[e.jsx("p",{className:"font-mono",children:a.ip_address||"â"}),e.jsx("p",{className:"text-muted-foreground text-[10px]",children:se(a.user_agent)})]})}),e.jsx(z,{className:"py-2",children:e.jsxs(Z,{variant:"outline",className:`gap-1 ${u.color}`,children:[e.jsx(f,{size:10}),a.event_type==="consent_accepted"&&a.termos.length>1?"Termos aceitos":u.label,a.count>1&&e.jsxs("span",{className:"ml-1 text-muted-foreground",children:["Ã",a.count]})]})}),h==="acessos"&&e.jsx(z,{className:"py-2",children:e.jsx(Z,{variant:W(a)==="Falha"?"destructive":"secondary",children:W(a)})}),h==="lgpd"&&e.jsx(z,{className:"py-2 text-xs",children:Q(a)}),Ne&&e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"py-2",children:e.jsx("div",{className:"flex items-center gap-1.5 max-w-[220px]",children:a.file_name?e.jsxs(e.Fragment,{children:[e.jsx(_e,{size:12,className:"text-muted-foreground shrink-0"}),e.jsxs(Ze,{children:[e.jsx(Je,{asChild:!0,children:e.jsx("span",{className:"text-sm truncate",children:a.file_name})}),e.jsx(ea,{className:"max-w-md",children:e.jsx("p",{className:"text-xs",children:a.file_name})})]})]}):a.descricao?e.jsxs(Ze,{children:[e.jsx(Je,{asChild:!0,children:e.jsx("span",{className:"text-sm truncate",children:a.descricao})}),e.jsx(ea,{className:"max-w-md",children:e.jsx("p",{className:"text-xs",children:a.descricao})})]}):h==="todos"&&a.termos.length?e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:Q(a)}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"â"})})}),e.jsx(z,{className:"py-2 text-xs text-muted-foreground",children:F[a.file_id]||"â"})]})]},a.event_id)})})]})}),e.jsx("div",{className:"md:hidden divide-y divide-border",children:ve.map(a=>{const u=Le(a.event_type),f=u.icon;return e.jsxs("button",{onClick:()=>oe(a),className:"w-full text-left p-4 hover:bg-muted/40 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsxs(Z,{variant:"outline",className:`gap-1 ${u.color}`,children:[e.jsx(f,{size:10}),u.label,a.count>1&&` Ã${a.count}`]}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:new Date(a.created_at).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})})]}),e.jsx("p",{className:"text-sm truncate",children:a.file_name||a.descricao||(a.termos.length?Q(a):"â")}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:[ee(a)," · ",a.ip_address||"â"]})]},a.event_id)})}),he>1&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-border",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Y*ge+1,"â",Math.min((Y+1)*ge,R.length)," de ",R.length]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx($,{variant:"outline",size:"sm",className:"h-7 text-xs",disabled:Y===0,onClick:()=>ae(a=>a-1),children:"Anterior"}),e.jsxs("span",{className:"text-xs text-muted-foreground px-2",children:[Y+1," / ",he]}),e.jsx($,{variant:"outline",size:"sm",className:"h-7 text-xs",disabled:Y>=he-1,onClick:()=>ae(a=>a+1),children:"Próximo"})]})]})]})}),e.jsx(fa,{open:!!v,onOpenChange:a=>!a&&oe(null),children:e.jsxs(ga,{className:"w-full sm:max-w-md overflow-y-auto",children:[e.jsxs(ja,{children:[e.jsxs(_a,{className:"flex items-center gap-2 text-base",children:[e.jsx(U,{size:16,className:"text-primary"}),"Evento de auditoria"]}),e.jsx(ba,{children:v&&da(v)})]}),v&&e.jsxs("div",{className:"space-y-4 mt-4 text-sm",children:[e.jsx(w,{label:"Categoria",value:Te[v.categoria]}),e.jsx(w,{label:"Data/hora completa",value:new Date(v.created_at).toLocaleString("pt-BR")}),v.count>1&&e.jsx(w,{label:"Ocorrências agrupadas (até 5 s)",value:String(v.count)}),e.jsx(w,{label:"Usuário",value:ee(v)}),v.descricao&&e.jsx(w,{label:"Alteração",value:v.descricao}),e.jsx(w,{label:"E-mail",value:v.user_email||"â"}),e.jsx(w,{label:"IP",value:v.ip_address||"â"}),e.jsx(w,{label:"Dispositivo",value:se(v.user_agent)}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"User agent"}),e.jsx("p",{className:"text-[11px] font-mono break-all mt-1 bg-muted p-2 rounded",children:v.user_agent||"â"})]}),v.termos.length>0&&e.jsx(w,{label:"Termos",value:Q(v)}),e.jsx(w,{label:"Arquivo",value:v.file_name||"â"}),e.jsx(w,{label:"ID do arquivo",value:v.file_id||"â"}),e.jsx(w,{label:"Departamento",value:F[v.file_id]||"â"}),v.details&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Detalhes"}),e.jsx("pre",{className:"text-[10px] font-mono break-all mt-1 bg-muted p-2 rounded whitespace-pre-wrap",children:JSON.stringify(v.details,null,2)})]})]})]})})]})};export{Vs 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.