1import{o as F}from"./rolldown-runtime-ChpBd9eV.js";import{La as U,Ma as V,Ta as H,da as T}from"./chat-page-evUfHQgD.js";import{Ic as Y,Qc as G,Sc as z,Tc as $,bc as S,bn as a,cc as q,lc as L,lu as J,ml as Q,vc as W,xc as X}from"./market-core-DitXLvJ-.js";var c=F(U(),1),e=H(),C={info:{bg:"bg-blue-500/20",text:"text-blue-400",icon:Y},success:{bg:"bg-green-500/20",text:"text-green-400",icon:W},warning:{bg:"bg-yellow-500/20",text:"text-yellow-400",icon:q},error:{bg:"bg-red-500/20",text:"text-red-400",icon:L}},N={[a.ORG_CREATED]:"Organization Created",[a.ORG_UPDATED]:"Organization Updated",[a.ORG_SETTINGS_CHANGED]:"Settings Changed",[a.MEMBER_INVITED]:"Member Invited",[a.MEMBER_JOINED]:"Member Joined",[a.MEMBER_REMOVED]:"Member Removed",[a.MEMBER_SUSPENDED]:"Member Suspended",[a.MEMBER_REACTIVATED]:"Member Reactivated",[a.ROLE_CHANGED]:"Role Changed",[a.RULE_BREACH]:"Rule Breach",[a.DAILY_LOSS_LIMIT_HIT]:"Daily Loss Limit Hit",[a.MAX_DRAWDOWN_HIT]:"Max Drawdown Hit",[a.PHASE_ADVANCED]:"Phase Advanced",[a.PHASE_FAILED]:"Phase Failed",[a.PAYOUT_REQUESTED]:"Payout Requested",[a.PAYOUT_APPROVED]:"Payout Approved",[a.PAYOUT_DENIED]:"Payout Denied",[a.PAYOUT_COMPLETED]:"Payout Completed"},A=t=>{const i=["rule_breach","daily_loss_limit_hit","max_drawdown_hit","phase_failed"],n=["member_removed","member_suspended","payout_denied"],d=["phase_advanced","payout_approved","payout_completed","member_joined"];return i.includes(t)?"error":n.includes(t)?"warning":d.includes(t)?"success":"info"},f=t=>t?(t.toDate?t.toDate():new Date(t)).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}):"-",K=({log:t,onViewDetails:i})=>{const n=C[A(t.eventType)],d=n.icon;return(0,e.jsxs)("tr",{className:"border-b border-slate-700/50 hover:bg-slate-800/50 transition-colors cursor-pointer",onClick:()=>i(t),children:[(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center ${n.bg}`,children:(0,e.jsx)(d,{className:`w-4 h-4 ${n.text}`})})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("span",{className:"font-medium text-white",children:N[t.eventType]||t.eventType})}),(0,e.jsx)("td",{className:"px-4 py-3 text-slate-400",children:t.performedByName||t.performedBy?.slice(0,8)+"..."}),(0,e.jsx)("td",{className:"px-4 py-3 text-slate-400",children:t.targetName||(t.targetId?t.targetId.slice(0,8)+"...":"-")}),(0,e.jsx)("td",{className:"px-4 py-3 text-slate-500 text-sm",children:f(t.timestamp)})]})},Z=({log:t,onClose:i})=>{if(!t)return null;const n=C[A(t.eventType)],d=n.icon;return(0,e.jsx)(T.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4",onClick:i,children:(0,e.jsxs)(T.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:"bg-slate-800 rounded-xl border border-slate-700 w-full max-w-lg shadow-2xl",onClick:u=>u.stopPropagation(),children:[(0,e.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-slate-700",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${n.bg}`,children:(0,e.jsx)(d,{className:`w-5 h-5 ${n.text}`})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-lg font-semibold text-white",children:N[t.eventType]||t.eventType}),(0,e.jsx)("p",{className:"text-sm text-slate-400",children:f(t.timestamp)})]})]}),(0,e.jsx)("button",{onClick:i,className:"p-1 hover:bg-slate-700 rounded-lg transition-colors",children:(0,e.jsx)(Q,{className:"w-5 h-5 text-slate-400"})})]}),(0,e.jsxs)("div",{className:"p-4 space-y-4",children:[(0,e.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 uppercase tracking-wider mb-1",children:"Performed By"}),(0,e.jsx)("p",{className:"text-white",children:t.performedByName||t.performedBy})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 uppercase tracking-wider mb-1",children:"Target"}),(0,e.jsx)("p",{className:"text-white",children:t.targetName||t.targetId||"-"})]})]}),t.metadata&&Object.keys(t.metadata).length>0&&(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 uppercase tracking-wider mb-2",children:"Details"}),(0,e.jsx)("div",{className:"bg-slate-900 rounded-lg p-3 overflow-x-auto",children:(0,e.jsx)("pre",{className:"text-sm text-slate-300 whitespace-pre-wrap",children:JSON.stringify(t.metadata,null,2)})})]}),t.ip&&(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 uppercase tracking-wider mb-1",children:"IP Address"}),(0,e.jsx)("p",{className:"text-slate-300 font-mono text-sm",children:t.ip})]})]})]})})},ae=()=>{const t=V(),{currentOrg:i,hasPermission:n,fetchAuditLogs:d}=J(),[u,R]=(0,c.useState)([]),[M,y]=(0,c.useState)(!0),[w,E]=(0,c.useState)(null),[b,I]=(0,c.useState)(""),[j,P]=(0,c.useState)("all"),[x,k]=(0,c.useState)("7d"),[m,_]=(0,c.useState)(1),v=25;(0,c.useEffect)(()=>{i?.id&&O()},[i?.id]);const O=async()=>{y(!0);try{R(await d(i.id,500)||[])}catch(s){console.error("Failed to load audit logs:",s)}y(!1)},p=(0,c.useMemo)(()=>{let s=u;if(x!=="all"){const l=new Date,o=x==="1d"?1:x==="7d"?7:x==="30d"?30:90,h=new Date(l.getTime()-o*24*60*60*1e3);s=s.filter(r=>(r.timestamp?.toDate?r.timestamp.toDate():new Date(r.timestamp))>=h)}if(b){const l=b.toLowerCase();s=s.filter(o=>o.eventType?.toLowerCase().includes(l)||o.performedByName?.toLowerCase().includes(l)||o.targetName?.toLowerCase().includes(l))}return j!=="all"&&(s=s.filter(l=>l.eventType===j)),s},[u,b,j,x]),D=(0,c.useMemo)(()=>{const s=(m-1)*v;return p.slice(s,s+v)},[p,m]),g=Math.ceil(p.length/v),B=()=>{const s=[["Timestamp","Event","Performed By","Target","Details"],...p.map(r=>[f(r.timestamp),N[r.eventType]||r.eventType,r.performedByName||r.performedBy,r.targetName||r.targetId||"",JSON.stringify(r.metadata||{})])].map(r=>r.join(",")).join(` 2`),l=new Blob([s],{type:"text/csv"}),o=URL.createObjectURL(l),h=document.createElement("a");h.href=o,h.download=`audit-logs-${new Date().toISOString().split("T")[0]}.csv`,h.click()};return n("view_audit_logs")?(0,e.jsxs)("div",{className:"min-h-screen overflow-y-auto bg-slate-900",children:[(0,e.jsx)("div",{className:"bg-slate-800 border-b border-slate-700 px-6 py-4",children:(0,e.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-4",children:[(0,e.jsx)("button",{onClick:()=>t("/org/dashboard"),className:"p-2 hover:bg-slate-700 rounded-lg transition-colors",children:(0,e.jsx)(S,{className:"w-5 h-5 text-slate-400"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Audit Logs"}),(0,e.jsxs)("p",{className:"text-sm text-slate-400",children:["Compliance tracking for ",i?.name]})]})]}),(0,e.jsxs)("button",{onClick:B,className:"px-4 py-2 text-slate-300 hover:text-white border border-slate-600 hover:border-slate-500 rounded-lg text-sm font-medium flex items-center gap-2 transition-colors",children:[(0,e.jsx)($,{className:"w-4 h-4"}),"Export CSV"]})]})}),(0,e.jsxs)("div",{className:"p-6",children:[(0,e.jsx)("div",{className:"bg-slate-800 rounded-xl border border-slate-700 p-4 mb-6",children:(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,e.jsxs)("div",{className:"relative flex-1 min-w-[200px]",children:[(0,e.jsx)(G,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),(0,e.jsx)("input",{type:"text",placeholder:"Search logs...",value:b,onChange:s=>I(s.target.value),className:"w-full pl-10 pr-4 py-2 bg-slate-900 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:border-blue-500"})]}),(0,e.jsxs)("select",{value:j,onChange:s=>P(s.target.value),className:"px-4 py-2 bg-slate-900 border border-slate-600 rounded-lg text-slate-300 focus:outline-none focus:border-blue-500",children:[(0,e.jsx)("option",{value:"all",children:"All Events"}),Object.entries(N).map(([s,l])=>(0,e.jsx)("option",{value:s,children:l},s))]}),(0,e.jsxs)("select",{value:x,onChange:s=>k(s.target.value),className:"px-4 py-2 bg-slate-900 border border-slate-600 rounded-lg text-slate-300 focus:outline-none focus:border-blue-500",children:[(0,e.jsx)("option",{value:"1d",children:"Last 24 hours"}),(0,e.jsx)("option",{value:"7d",children:"Last 7 days"}),(0,e.jsx)("option",{value:"30d",children:"Last 30 days"}),(0,e.jsx)("option",{value:"90d",children:"Last 90 days"})]}),(0,e.jsxs)("span",{className:"text-sm text-slate-400",children:[p.length," logs"]})]})}),(0,e.jsxs)("div",{className:"bg-slate-800 rounded-xl border border-slate-700 overflow-hidden",children:[(0,e.jsx)("div",{className:"overflow-x-auto",children:(0,e.jsxs)("table",{className:"w-full",children:[(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{className:"border-b border-slate-700 text-left",children:[(0,e.jsx)("th",{className:"px-4 py-3 w-12"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-400 uppercase tracking-wider",children:"Event"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-400 uppercase tracking-wider",children:"Performed By"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-400 uppercase tracking-wider",children:"Target"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-400 uppercase tracking-wider",children:"Timestamp"})]})}),(0,e.jsx)("tbody",{children:M?[...Array(10)].map((s,l)=>(0,e.jsxs)("tr",{className:"border-b border-slate-700/50 animate-pulse",children:[(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"w-8 h-8 bg-slate-700 rounded-lg"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-700 rounded w-32"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-700 rounded w-24"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-700 rounded w-20"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-700 rounded w-28"})})]},l)):D.length===0?(0,e.jsx)("tr",{children:(0,e.jsxs)("td",{colSpan:5,className:"px-4 py-12 text-center",children:[(0,e.jsx)(z,{className:"w-12 h-12 text-slate-600 mx-auto mb-3"}),(0,e.jsx)("p",{className:"text-slate-400",children:"No audit logs found"})]})}):D.map(s=>(0,e.jsx)(K,{log:s,onViewDetails:E},s.id))})]})}),g>1&&(0,e.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-t border-slate-700",children:[(0,e.jsxs)("span",{className:"text-sm text-slate-400",children:["Page ",m," of ",g]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("button",{onClick:()=>_(s=>Math.max(1,s-1)),disabled:m===1,className:"p-2 hover:bg-slate-700 rounded-lg disabled:opacity-50 disabled:cursor-not-allowed",children:(0,e.jsx)(S,{className:"w-4 h-4 text-slate-400"})}),(0,e.jsx)("button",{onClick:()=>_(s=>Math.min(g,s+1)),disabled:m===g,className:"p-2 hover:bg-slate-700 rounded-lg disabled:opacity-50 disabled:cursor-not-allowed",children:(0,e.jsx)(X,{className:"w-4 h-4 text-slate-400"})})]})]})]})]}),w&&(0,e.jsx)(Z,{log:w,onClose:()=>E(null)})]}):(0,e.jsx)("div",{className:"min-h-screen bg-slate-900 flex items-center justify-center p-8",children:(0,e.jsxs)("div",{className:"text-center",children:[(0,e.jsx)(L,{className:"w-16 h-16 text-red-400 mx-auto mb-4"}),(0,e.jsx)("h1",{className:"text-2xl font-bold text-white mb-2",children:"Access Denied"}),(0,e.jsx)("p",{className:"text-slate-400 mb-6",children:"You don't have permission to view audit logs."}),(0,e.jsx)("button",{onClick:()=>
2t("/org/dashboard"),className:"px-6 py-3 bg-blue-600 hover:bg-blue-500 text-white rounded-xl font-medium",children:"Back to Dashboard"})]})})};export{ae 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.