1import{v as A,u as S,j as e,W as C,X as w,q as P,r as c,S as v,B as j,c as k,t as I,a as O,g as R,Y as D}from"./index-_aijvlUq.js";import{P as L}from"./PageHeader-DCofr6qo.js";import{T as W,a as m,b as U,c as z,d as h,e as V}from"./Table-Yng-lqpt.js";import{E as M}from"./EmptyState-CPGKooqj.js";import{B}from"./Badge-DJIi163x.js";import{M as _}from"./MobileListSkeleton-BxuyWDCs.js";const N={list(s={}){const i=Object.fromEntries(Object.entries(s).filter(([,t])=>t!==""&&t!=null));return A.get("/audit",{params:i})}},F={member:s=>`/members/${s}`};function J({action:s,beforeValue:i,afterValue:t}){let r=null,a=null;try{r=i?JSON.parse(i):null}catch{}try{a=t?JSON.parse(t):null}catch{}if(s==="VIEW")return e.jsx("p",{className:"text-xs text-gray-400 italic",children:"No changes recorded."});const n=s==="UPDATE"||s==="DELETE",x=s==="UPDATE"||s==="CREATE",p=s==="UPDATE"&&r&&a?Object.keys({...r,...a}).filter(o=>JSON.stringify(r[o])!==JSON.stringify(a[o])):null;function u(o,l){return o?e.jsx("pre",{className:"text-xs text-gray-700 whitespace-pre-wrap break-all",children:Object.entries(o).map(([b,f])=>e.jsxs("span",{className:l?.includes(b)?"bg-yellow-100":"",children:[e.jsxs("span",{className:"text-gray-400",children:[b,": "]}),JSON.stringify(f),` 2`]},b))}):e.jsx("span",{className:"text-gray-400 text-xs",children:"â"})}return s==="UPDATE"&&p?.length>0?e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-xs",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase tracking-wide mb-1",children:"Before"}),u(r,p)]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase tracking-wide mb-1",children:"After"}),u(a,p)]})]}):e.jsxs("div",{className:"text-xs",children:[n&&r&&e.jsxs("div",{className:"mb-2",children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase tracking-wide mb-1",children:s==="DELETE"?"Deleted record":"Before"}),u(r,null)]}),x&&a&&e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase tracking-wide mb-1",children:s==="CREATE"?"Created record":"After"}),u(a,null)]})]})}function $({entry:s,isExpanded:i,onToggle:t}){const r=S(),a=s.beforeValue||s.afterValue,n=F[s.resourceType];return e.jsxs(e.Fragment,{children:[e.jsxs(W,{onClick:a?t:void 0,children:[e.jsx(m,{children:e.jsx(B,{color:C[s.action]??"gray",children:s.action})}),e.jsx(m,{className:"text-gray-900",children:s.resourceType}),e.jsx(m,{className:"font-mono text-xs",children:n?e.jsxs("button",{type:"button",onClick:x=>{x.stopPropagation(),r(n(s.resourceId))},className:"text-band-600 hover:underline",children:[s.resourceId?.slice(0,8),"â¦"]}):e.jsxs("span",{className:"text-gray-500",children:[s.resourceId?.slice(0,8),"â¦"]})}),e.jsx(m,{className:"text-gray-700",children:s.actorLabel||s.actorRole||"â"}),e.jsx(m,{className:"text-gray-500",children:e.jsx("span",{title:P(s.occurredAt),children:w(s.occurredAt)})}),a&&e.jsx(m,{className:"text-gray-300 text-xs w-4",children:i?"â²":"â¼"}),!a&&e.jsx(m,{})]}),i&&a&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-3 bg-gray-50 border-t border-gray-100",children:e.jsx(J,{action:s.action,beforeValue:s.beforeValue,afterValue:s.afterValue})})})]})}const H=[{value:"CREATE",label:"CREATE"},{value:"UPDATE",label:"UPDATE"},{value:"DELETE",label:"DELETE"},{value:"VIEW",label:"VIEW"}],q=[{value:"member",label:"Member"}];function X(){const[s,i]=c.useState([]),[t,r]=c.useState({page:1,limit:20,total:0,totalPages:1}),[a,n]=c.useState({action:"",resourceType:""}),[x,p]=c.useState(!0),[u,o]=c.useState(null),[l,b]=c.useState(null);async function f(d=1){p(!0),o(null);try{const g=await N.list({page:d,limit:20,...a});i(g.entries),r(g.pagination)}catch(g){o(g.message)}finally{p(!1)}}return c.useEffect(()=>{f(1)},[a.action,a.resourceType]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(v,{placeholder:"All actions",options:H,value:a.action,onChange:d=>n(g=>({...g,action:d.target.value})),className:"w-40"}),e.jsx(v,{placeholder:"All resources",options:q,value:a.resourceType,onChange:d=>n(g=>({...g,resourceType:d.target.value})),className:"w-40"}),(a.action||a.resourceType)&&e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>n({action:"",resourceType:""}),children:"Clear"}),e.jsx(j,{variant:"secondary",size:"sm",onClick:()=>f(t.page),className:"ml-auto",children:"Refresh"})]}),u&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:u}),x?e.jsx("div",{className:"flex justify-center py-16",children:e.jsxs("svg",{className:"animate-spin motion-reduce:!animate-spin h-8 w-8 text-band-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):s.length===0?e.jsx(M,{title:"No audit entries",description:"Actions will appear here as they occur."}):e.jsxs(e.Fragment,{children:[e.jsxs(U,{children:[e.jsx(z,{children:e.jsxs("tr",{children:[e.jsx(h,{children:"Action"}),e.jsx(h,{children:"Resource"}),e.jsx(h,{children:"ID"}),e.jsx(h,{children:"Actor"}),e.jsx(h,{children:"When"}),e.jsx(h,{})]})}),e.jsx(V,{children:s.map(d=>
2e.jsx($,{entry:d,isExpanded:l===d.id,onToggle:()=>b(g=>g===d.id?null:d.id)},d.id))})]}),t.totalPages>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4 text-sm text-gray-600",children:[e.jsxs("span",{children:[(t.page-1)*t.limit+1,"â",Math.min(t.page*t.limit,t.total)," of ",t.total]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{variant:"secondary",size:"sm",disabled:t.page<=1,onClick:()=>f(t.page-1),children:"Previous"}),e.jsx(j,{variant:"secondary",size:"sm",disabled:t.page>=t.totalPages,onClick:()=>f(t.page+1),children:"Next"})]})]})]})]})}const y={CREATE:{bg:"var(--bb-success-soft)",fg:"var(--bb-success-ink)"},UPDATE:{bg:"var(--bb-info-soft)",fg:"var(--bb-info-ink)"},DELETE:{bg:"var(--bb-danger-soft)",fg:"var(--bb-danger-ink)"},VIEW:{bg:"var(--bb-surface-sunken)",fg:"var(--bb-fg-muted)"}},Y=["CREATE","UPDATE","DELETE","VIEW"];function K(s){if(!s)return"";const i=new Date(s),t=Date.now()-i.getTime(),r=Math.round(t/6e4);if(r<1)return"just now";if(r<60)return`${r}m ago`;const a=Math.round(r/60);if(a<24)return`${a}h ago`;const n=Math.round(a/24);return n<14?`${n}d ago`:i.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function G(){const{showError:s}=k(),[i,t]=c.useState([]),[r,a]=c.useState({page:1,limit:20,total:0,totalPages:1}),[n,x]=c.useState(""),[p,u]=c.useState(!0);c.useEffect(()=>{o(1)},[n]);async function o(l=1){u(!0);try{const b=await N.list({page:l,limit:20,action:n});t(b.entries||[]),a(b.pagination||{page:l,limit:20,total:0,totalPages:1})}catch(b){s(b?.message||I("audit log"))}finally{u(!1)}}return e.jsxs("div",{style:{paddingBottom:24},children:[e.jsxs("div",{role:"tablist","aria-label":"Filter by action",style:{display:"flex",gap:6,overflowX:"auto",padding:"var(--bb-space-3) var(--bb-space-4)",background:"var(--bb-bg)"},children:[e.jsx(E,{active:!n,onClick:()=>x(""),label:"All"}),Y.map(l=>e.jsx(E,{active:n===l,onClick:()=>x(l),label:l.toLowerCase()},l))]}),p?e.jsx(_,{variant:"music",count:6}):i.length===0?e.jsx("div",{style:{margin:"var(--bb-space-4)",padding:"var(--bb-space-6)",background:"var(--bb-surface)",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-lg)",textAlign:"center",color:"var(--bb-fg-muted)"},children:"No audit entries."}):e.jsxs(e.Fragment,{children:[e.jsx("ul",{"data-testid":"mobile-audit-list",style:{listStyle:"none",margin:0,padding:0,background:"var(--bb-surface)"},children:i.map(l=>e.jsx(Q,{entry:l},l.id))}),r.totalPages>1&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"var(--bb-space-4)",fontSize:13,color:"var(--bb-fg-muted)"},children:[e.jsxs("span",{children:["Page ",r.page," of ",r.totalPages]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(T,{disabled:r.page<=1,onClick:()=>o(r.page-1),children:"Prev"}),e.jsx(T,{disabled:r.page>=r.totalPages,onClick:()=>o(r.page+1),children:"Next"})]})]})]})]})}function Q({entry:s}){const i=y[s.action]||y.VIEW;return e.jsxs("li",{style:{display:"flex",alignItems:"flex-start",gap:"var(--bb-space-3)",padding:"12px var(--bb-space-4)",borderTop:"1px solid var(--bb-border-soft)",minHeight:68},children:[e.jsx("span",{style:{display:"inline-flex",alignItems:"center",padding:"3px 8px",borderRadius:"var(--bb-radius-pill)",background:i.bg,color:i.fg,fontSize:10,fontWeight:700,letterSpacing:"0.05em",flexShrink:0,marginTop:2},children:s.action}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontSize:14,fontWeight:600,color:"var(--bb-fg)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s.resourceType,s.resourceId&&e.jsxs("span",{style:{color:"var(--bb-fg-subtle)",fontWeight:400},children:[" ","· ",s.resourceId.slice(0,8),"â¦"]})]}),e.jsxs("div",{style:{marginTop:2,fontSize:12,color:"var(--bb-fg-muted)"},children:[s.actorLabel||s.actorRole||"â",e.jsxs("span",{style:{marginLeft:6},children:["· ",K(s.occurredAt)]})]})]})]})}function E({active:s,onClick:i,label:t}){return e.jsx("button",{type:"button",role:"tab","aria-selected":s,onClick:i,style:{flex:"0 0 auto",minHeight:44,padding:"0 16px",fontSize:13,fontWeight:600,borderRadius:"var(--bb-radius-pill)",border:"1px solid",borderColor:s?"var(--bb-primary)":"var(--bb-border-soft)",background:s?"var(--bb-primary)":"var(--bb-surface)",color:s?"#fff":"var(--bb-fg-muted)",cursor:"pointer",display:"inline-flex",alignItems:"center",fontFamily:"inherit",textTransform:"capitalize"},children:t})}function T({disabled:s,onClick:i,children:t}){return e.jsx("button",{type:"button",disabled:s,onClick:i,style:{minHeight:44,padding:"0 12px",border:"1px solid var(--bb-border)",borderRadius:"var(--bb-radius-md)",background:"var(--bb-surface)",color:s?"var(--bb-fg-subtle)":"var(--bb-fg-body)",fontSize:13,fontWeight:600,cursor:s?"not-allowed":"pointer",fontFamily:"inherit"},children:t})}function ie(){const{canAny:s}=O(),i=R();return s("audit:read")?i?e.jsx(G,{}):e.jsxs("div",{children:[e.jsx(L,{title:"Audit Log",subtitle:"Track all changes to membership data",breadcrumbs:[{label:"Home",to:"/"},{label:"Settings"},{label:"Audit Log"}]}),e.jsx(X,{})]}):e.jsx(D,{to:"/members",replace:!0})}export{ie as AuditLogPage};
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.