1import{r as a,s as b,j as s,i as z,I,a1 as h,e as j,k}from"./index-DjTQOXNM.js";import{C as v}from"./Card-B__Q0keI.js";import{B as l}from"./Badge-BkLKLqR8.js";import{E as N}from"./EmptyState-hYKQQn9J.js";import{S as T}from"./search-Bd0Wr2Lg.js";import{C as q}from"./chevron-up-DZRxbFBH.js";import{I as B}from"./info-xiMQhcYN.js";import{A as y}from"./alert-circle-CuISkzY6.js";function W(){const[n,g]=a.useState("audit"),[c,w]=a.useState([]),[d,_]=a.useState([]),[r,L]=a.useState(""),[i,o]=a.useState(null),[C,m]=a.useState(!0);a.useEffect(()=>{S()},[n]);async function S(){if(m(!0),n==="audit"){const{data:e}=await b.from("audit_logs").select("*").order("created_at",{ascending:!1}).limit(100);w(e||[])}else{const{data:e}=await b.from("send_logs").select("*, email_outbox(*)").order("created_at",{ascending:!1}).limit(100);_(e||[])}m(!1)}const u=a.useMemo(()=>{if(!r)return c;const e=r.toLowerCase();return c.filter(t=>t.action.toLowerCase().includes(e)||t.entity_type.toLowerCase().includes(e)||t.actor_id.toLowerCase().includes(e))},[c,r]),x=a.useMemo(()=>{if(!r)return d;const e=r.toLowerCase();return d.filter(t=>{var p,f;return t.message.toLowerCase().includes(e)||((f=(p=t.email_outbox)==null?void 0:p.to_email)==null?void 0:f.toLowerCase().includes(e))})},[d,r]),A=e=>{switch(e){case"error":return s.jsx(y,{size:14,className:"text-mr-label-error"});case"warn":return s.jsx(y,{size:14,className:"text-mr-label-warning"});default:return s.jsx(B,{size:14,className:"text-mr-icon-blue"})}},E=e=>{switch(e){case"error":return s.jsx(l,{variant:"error",children:"Error"});case"warn":return s.jsx(l,{variant:"warning",children:"Warn"});default:return s.jsx(l,{variant:"info",children:"Info"})}};return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-h3 text-mr-label mb-1",children:"Logs & Audit"}),s.jsx("p",{className:"text-body text-mr-label-subdued",children:"Historique complet des actions et envois"})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[s.jsx("div",{className:"flex items-center gap-1 bg-mr-surface-secondary rounded-lg p-1",children:["audit","sends"].map(e=>s.jsx("button",{onClick:()=>g(e),className:z("px-4 py-2 rounded-md text-body-lg font-medium transition-all duration-200",n===e?"bg-white text-mr-label shadow-card":"text-mr-label-subdued hover:text-mr-label"),children:e==="audit"?"Audit Trail":"Envois"},e))}),s.jsxs("div",{className:"relative flex-1",children:[s.jsx(T,{size:18,className:"absolute left-3 top-1/2 -translate-y-1/2 text-mr-icon"}),s.jsx(I,{value:r,onChange:e=>L(e.target.value),placeholder:"Rechercher dans les logs...",className:"pl-10"})]})]}),C?s.jsx("div",{className:"space-y-2",children:Array.from({length:8}).map((e,t)=>s.jsx("div",{className:"h-[60px] bg-white rounded-md border border-mr-border animate-pulse"},t))}):n==="audit"?u.length===0?s.jsx(N,{icon:h,title:"Aucun log d'audit",description:"Les actions seront tracees ici"}):s.jsx("div",{className:"space-y-1",children:u.map(e=>s.jsxs(v,{className:"py-3 px-4 cursor-pointer hover:bg-mr-surface-subdued transition-colors",onClick:()=>o(i===e.id?null:e.id),children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-8 h-8 rounded-md bg-mr-surface-blue flex items-center justify-center flex-shrink-0",children:s.jsx("span",{className:"text-overline font-bold text-mr-icon-blue uppercase",children:e.actor_type.charAt(0)})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-body font-medium text-mr-label",children:e.action}),s.jsx(l,{variant:"default",children:e.entity_type})]}),s.jsxs("p",{className:"text-caption text-mr-label-subdued",children:[e.actor_type,": ",e.actor_id," - ",j(e.created_at)]})]}),i===e.id?s.jsx(q,{size:14}):s.jsx(k,{size:14})]}),i===e.id&&s.jsxs("div",{className:"mt-3 pt-3 border-t border-mr-border grid grid-cols-1 sm:grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-overline font-semibold text-mr-label-subdued uppercase mb-1",children:"Avant"}),s.jsx("pre",{className:"text-caption text-mr-label bg-mr-surface-secondary p-2 rounded overflow-x-auto max-h-[200px]",children:JSON.stringify(e.before_state,null,2)||"-"})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-overline font-semibold text-mr-label-subdued uppercase mb-1",children:"Apres"}),s.jsx("pre",{className:"text-caption text-mr-label bg-mr-surface-secondary p-2 rounded overflow-x-auto max-h-[200px]",children:JSON.stringify(e.after_state,null,2)||"-"})]})]})]},e.id))}):x.length===0?s.jsx(N,{icon:h,title:"Aucun log d'envoi",description:"Les envois seront traces ici"}):s.jsx("div",{className:"space-y-1",children:x.map(e=>{var t;return s.jsxs(v,{className:"py-3 px-4 cursor-pointer hover:bg-mr-surface-subdued transition-colors",onClick:()=>o(i===e.id?null:e.id),children:[s.jsxs("div",{className:"flex items-center gap-3",children:[A(e.level),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-body text-mr-label",children:e.message}),E(e.level)]}),s.jsxs("p",{className:"text-caption text-mr-label-subdued",children:[((t=e.email_outbox)==null?void 0:t.to_email)&&`A: ${e.email_outbox.to_email} - `,j(e.created_at)]})]}),e.email_outbox&&s.jsx(l,{variant:e.email_outbox.status==="sent"?"success":e.email_outbox.status==="failed"?"error":"default",children:e.email_outbox.status})]}),i===e.id&&e.payload&&s.jsx("div",{className:"mt-3 pt-3 border-t border-mr-border",children:s.jsx("pre",{className:"text-caption text-mr-label bg-mr-surface-secondary p-2 rounded overflow-x-auto max-h-[200px]",children:JSON.stringify(e.payload,null,2)})})]},e.id)})})]})}export{W 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.