1import{a as e,j as t}from"./influencer-discovery-market-DZSHIEBk.js";import{a,b as s,c as r,d as n}from"./card-Ca7HXSXJ.js";import{z as l,B as i,X as o,a_ as d,aG as c}from"./appEntry-BOm-xWeQ.js";import{B as m}from"./badge-ULglNPoF.js";import{I as u}from"./input-DxgUdknR.js";import{S as x}from"./skeleton-Dy5fyRLq.js";import{S as p,a as g,b as h,c as j,d as f}from"./select-CnttHTvy.js";import{C as _,a as y,b as v}from"./collapsible-Cp0w5VJ9.js";import{A as b}from"./animated-border-card-CNDI4ILE.js";import{A as N,a as w}from"./AdminSectionHeader-CbeAwgtO.js";import{u as S}from"./useQuery-DsaHvTXb.js";import{u as F}from"./useMutation-bR2URRHE.js";import{a as C}from"./adminSettingsService-D2aP76Vc.js";import{s as D}from"./csvSecurity-CsY4UDVz.js";import{d as A}from"./downloadBlob-CTQYDB02.js";import{F as z}from"./file-text-D9ddVy5J.js";import{D as I}from"./download-BNr4jEtJ.js";import{F as E}from"./funnel-_7wSIa0Q.js";import{C as O}from"./chevron-left-zmDrVFQh.js";import{C as k}from"./chevron-right-BlJo470F.js";import{f as V}from"./format-Sh1zmB1Q.js";import{S as $}from"./settings-BlXT1d-7.js";import{T as M}from"./timer-Dlaube8J.js";import{F as P}from"./flag-C5ZHu8lu.js";import{f as T}from"./formatDistanceToNow-D6EixuHK.js";import{C as U}from"./chevron-down-Cllw_H8_.js";import"./app-DMaOIODN.js";import"./index-jVOyRz7F.js";import"./chevron-up-DLDZc2pY.js";import"./index-6cg7cHMr.js";import"./useReducedMotion-PPWOB0MJ.js";import"./refresh-cw-C5gCrq7P.js";import"./adminToolErrorLogService-_w1PT12q.js";import"./en-US-REEyzlXW.js";import"./toDate-CUevgFSb.js";import"./isValid-BiFBYI82.js";import"./endOfMonth-CB_qPPkW.js";const J={all:["audit-log"],list:e=>[...J.all,"list",e]},L=["update","admin","status"].join("_"),R=new Set(["delete_feature_flag","delete_setting",L]),H=new Set(["create_setting","create_feature_flag","toggle_feature_flag","update_feature_flag","update_setting","update_cron_job","run_cron_job_manually","update_user"]);function q(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function B(e,t=""){const a=new Map;if(!q(e))return a.set(t||"value",e),a;for(const[s,r]of Object.entries(e)){const e=t?`${t}.${s}`:s;if(q(r))for(const[t,s]of B(r,e))a.set(t,s);else a.set(e,r)}return a}const K={page:1,actionFilter:"all",entityFilter:"all",entityIdFilter:"",adminSearch:"",textSearch:"",datePreset:"7d",customStartDate:"",customEndDate:"",expandedId:null};function Q(e,t){return{...e,...t,page:1}}function Z(e,t){switch(t.type){case"set_page":{const a="function"==typeof t.page?t.page(e.page):t.page;return{...e,page:a}}case"set_action_filter":return Q(e,{actionFilter:t.value});case"set_entity_filter":return Q(e,{entityFilter:t.value});case"set_entity_id_filter":return Q(e,{entityIdFilter:t.value});case"set_admin_search":return Q(e,{adminSearch:t.value});case"set_text_search":return Q(e,{textSearch:t.value});case"set_date_preset":return Q(e,{datePreset:t.value});case"set_custom_start_date":return Q(e,{customStartDate:t.value});case"set_custom_end_date":return Q(e,{customEndDate:t.value});case"set_expanded_id":return{...e,expandedId:t.value};case"clear_filters":return{...e,actionFilter:"all",entityFilter:"all",entityIdFilter:"",adminSearch:"",textSearch:"",datePreset:"7d",customStartDate:"",customEndDate:"",page:1};default:return e}}const G={toggle_feature_flag:{label:"Toggle Feature Flag",icon:t.jsx(P,{className:"size-3"}),color:"text-purple-500"},create_feature_flag:{label:"Create Feature Flag",icon:t.jsx(P,{className:"size-3"}),color:"text-green-500"},update_feature_flag:{label:"Update Feature Flag",icon:t.jsx(P,{className:"size-3"}),color:"text-amber-500"},delete_feature_flag:{label:"Delete Feature Flag",icon:t.jsx(P,{className:"size-3"}),color:"text-red-500"},update_cron_job:{label:"Update Cron Job",icon:t.jsx(M,{className:"size-3"}),color:"text-blue-500"},run_cron_job_manually:{label:"Manual Cron Run",icon:t.jsx(M,{className:"size-3"}),color:"text-yellow-500"},create_setting:{label:"Create Setting",icon:t.jsx($,{className:"size-3"}),color:"text-green-500"},update_setting:{label:"Update Setting",icon:t.jsx($,{className:"size-3"}),color:"text-cyan-500"},delete_setting:{label:"Delete Setting",icon:t.jsx($,{className:"size-3"}),color:"text-red-500"},update_user:{label:"Update User",icon:t.jsx(c,{className:"size-3"}),color:"text-indigo-500"},[L]:{label:"Admin Status Change",icon:t.jsx(d,{className:"size-3"}),color:"text-amber-500"}},W={high:"border-red-500/30 bg-red-500/10 text-red-500",medium:"border-amber-500/30 bg-amber-500/10 text-amber-500",low:"border-blue-500/30 bg-blue-500/10 text-blue-500"};function X(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)} risk`}function Y(e){return void 0===e?"â":null===e?"null":"object"==typeof e?JSON.stringify(e):String(e)}function ee(e,t=!1){if(e)return`${e}T${t?"23:59:59.999":"00:00:00.000"}Z`}function te({entry:e,expanded:a,onToggle:s}){const r=G[e.action]??{label:e.action,icon:t.jsx(z,{className:"size-3"}),color:"text-muted-foreground"},n=(l=e.action,R.has(l)?"high":H.has(l)?"medium":"low");var l;const i=function(e){if(!e.entity_id&&"cron_job"!==e.entity_type)return null;switch(e.entity_type){case"user":return`/admin/settings/users/${encodeURIComponent(e.entity_id??"")}`;case"feature_flag":return`/admin/settings/flags?search=${encodeURIComponent(e.entity_id??"")}`;case"setting":return`/admin/settings/system?search=${encodeURIComponent(e.entity_id??"")}`;case"cron_job":return"/admin/settings/cron";default:return null}}(e),o=function(e,t){const a=B(e),s=B(t);return Array.from(new Set([...a.keys(),...s.keys()])).sort().flatMap(e=>JSON.stringify(a.get(e))===JSON.stringify(s.get(e))?[]:[{path:e,oldValue:a.get(e),newValue:s.get(e)}])}(e.old_value,e.new_value);return t.jsx(_,{open:a,onOpenChange:s,children:t.jsxs("div",{className:`\n rounded-lg border border-border/50\n ${a?"ring-2 ring-[var(--channel-analytics-accent)]/20":""}\n transition-all\n `,children:[t.jsx(y,{asChild:!0,children:t.jsxs("div",{className:"flex items-center gap-4 p-4 cursor-pointer hover:bg-muted/30 transition-colors",children:[t.jsx("div",{className:`h-8 w-8 rounded-lg bg-muted/50 flex items-center justify-center ${r.color}`,children:r.icon}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"font-medium",children:r.label}),e.entity_id&&(i?t.jsx("a",{href:i,className:"text-xs font-mono bg-muted/50 px-1.5 py-0.5 rounded hover:text-[var(--channel-analytics-accent)]",onClick:e=>e.stopPropagation(),children:e.entity_id}):t.jsx("code",{className:"text-xs font-mono bg-muted/50 px-1.5 py-0.5 rounded",children:e.entity_id})),t.jsx(m,{variant:"outline",className:`text-xs ${W[n]}`,children:X(n)})]}),t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-1",children:[t.jsxs("span",{children:["by ",e.admin_name]}),t.jsx("span",{children:"â¢"}),t.jsx("span",{children:T(new Date(e.created_at),{addSuffix:!0})})]})]}),t.jsx(m,{variant:"outline",className:"text-xs",children:e.entity_type}),a?t.jsx(U,{className:"size-4"}):t.jsx(k,{className:"size-4"})]})}),t.jsx(v,{children:t.jsxs("div",{className:"px-4 pb-4 pt-2 border-t border-border/30",children:[o.length>0&&t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Field Changes"}),t.jsx("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:t.jsxs("table",{className:"w-full text-xs",children:[t.jsx("thead",{className:"bg-muted/40 text-muted-foreground",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Field"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Previous"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"New"})]})}),t.jsx("tbody",{children:o.map(e=>t.jsxs("tr",{className:"border-t border-border/40",children:[t.jsx("td",{className:"px-3 py-2 font-mono",children:e.path}),t.jsx("td",{className:"px-3 py-2 text-red-500",children:Y(e.oldValue)}),t.jsx("td",{className:"px-3 py-2 text-green-500",children:Y(e.newValue)})]},e.path))})]})})]}),t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[null!==e.old_value&&void 0!==e.old_value&&t.jsxs("div",{children:[t.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Previous Value"}),t.jsx("pre",{className:"text-xs bg-red-500/5 border border-red-500/20 rounded-lg p-2 overflow-x-auto",children:JSON.stringify(e.old_value,null,2)})]}),null!==e.new_value&&void 0!==e.new_value&&t.jsxs("div",{children:[t.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"New Value"}),t.jsx("pre",{className:"text-xs bg-green-500/5 border border-green-500/20 rounded-lg p-2 overflow-x-auto",children:JSON.stringify(e.new_value,null,2)})]})]}),t.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:t.jsxs("span",{children:["Timestamp: ",V(new Date(e.created_at),"PPpp")]})})]})})]})})}function ae(){const[d,c]=e.useReducer(Z,K),{page:m,actionFilter:_,entityFilter:y,entity
1IdFilter:v,adminSearch:$,textSearch:M,datePreset:P,customStartDate:T,customEndDate:U,expandedId:L}=d,R=e.useMemo(()=>"custom"===P?null:function(e,t=new Date){const a=new Date(t);return"24h"===e&&a.setHours(a.getHours()-24),"7d"===e&&a.setDate(a.getDate()-7),"30d"===e&&a.setDate(a.getDate()-30),{startDate:a.toISOString(),endDate:t.toISOString()}}(P),[P]),H={..."all"!==_&&{action:_},..."all"!==y&&{entity_type:y},...v.trim()&&{entity_id:v.trim()},...$.trim()&&{admin_search:$.trim()},...M.trim()&&{text_search:M.trim()},..."custom"===P&&ee(T)&&{start_date:ee(T)},..."custom"===P&&ee(U,!0)&&{end_date:ee(U,!0)},..."custom"!==P&&R&&{start_date:R.startDate,end_date:R.endDate}},{data:q,isLoading:B,isError:Q,error:W,refetch:X}=function(e,t=20,a){const s=(e-1)*t;return S({queryKey:J.list({...a,limit:t,offset:s}),queryFn:()=>C.getAuditLog({...a,limit:t,offset:s}),staleTime:3e4})}(m,20,H),Y=function(){const e=l();return F({mutationFn:async e=>{const{entries:t}=await C.getAuditLog({...e,limit:1e3,offset:0});return t},onSuccess:()=>{e.invalidateQueries({queryKey:J.all})}})}(),ae=q?.entries??[],se=q?.total??0,re=Math.ceil(se/20),ne=W instanceof Error?W.message:"Unknown audit log error",le="all"!==_||"all"!==y||""!==v.trim()||""!==$.trim()||""!==M.trim()||"7d"!==P||""!==T||""!==U;return t.jsxs("div",{className:"p-6 space-y-6",children:[t.jsx(N,{icon:z,title:"Audit Log",description:t.jsxs(t.Fragment,{children:[se," total entries"]}),actions:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-sm text-muted-foreground",children:"Runbook: docs/admin-panel/audit-log.md"}),t.jsx(w,{onRefresh:()=>X(),isLoading:B}),t.jsxs(i,{variant:"outline",onClick:async()=>{const e=[["Timestamp","Admin","Action","Entity Type","Entity ID","Old Value","New Value"],...(await Y.mutateAsync(H)).map(e=>[e.created_at,e.admin_name||e.admin_id,e.action,e.entity_type,e.entity_id||"",e.old_value?JSON.stringify(e.old_value):"",e.new_value?JSON.stringify(e.new_value):""])].map(e=>D(e)).join("\n");A(`audit-log-export-${V(new Date,"yyyy-MM-dd-HHmm")}.csv`,e)},disabled:Y.isPending||0===ae.length,children:[t.jsx(I,{className:"size-4 mr-2"}),"Export"]})]})}),t.jsx(b,{children:t.jsx(a,{className:"p-4",children:t.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{className:"size-4 text-muted-foreground"}),t.jsx("span",{className:"text-sm font-medium",children:"Filters"})]}),t.jsxs(p,{value:_,onValueChange:e=>{c({type:"set_action_filter",value:e})},children:[t.jsx(g,{className:"w-[180px]",children:t.jsx(h,{placeholder:"All Actions"})}),t.jsxs(j,{children:[t.jsx(f,{value:"all",children:"All Actions"}),Object.entries(G).map(([e,{label:a}])=>t.jsx(f,{value:e,children:a},e))]})]}),t.jsxs(p,{value:y,onValueChange:e=>{c({type:"set_entity_filter",value:e})},children:[t.jsx(g,{className:"w-[180px]",children:t.jsx(h,{placeholder:"All Entities"})}),t.jsxs(j,{children:[t.jsx(f,{value:"all",children:"All Entities"}),t.jsx(f,{value:"feature_flag",children:"Feature Flags"}),t.jsx(f,{value:"cron_job",children:"Cron Jobs"}),t.jsx(f,{value:"setting",children:"Settings"}),t.jsx(f,{value:"user",children:"Users"})]})]}),t.jsxs("label",{htmlFor:"audit-log-entity-id",className:"grid gap-1 text-xs text-muted-foreground",children:["Entity ID",t.jsx(u,{id:"audit-log-entity-id",value:v,onChange:e=>{c({type:"set_entity_id_filter",value:e.target.value})},className:"w-[220px]",placeholder:"maintenance_mode"})]}),t.jsxs("label",{htmlFor:"audit-log-admin-search",className:"grid gap-1 text-xs text-muted-foreground",children:["Admin",t.jsx(u,{id:"audit-log-admin-search",value:$,onChange:e=>{c({type:"set_admin_search",value:e.target.value})},className:"w-[200px]",placeholder:"Name, email, or id"})]}),t.jsxs("label",{htmlFor:"audit-log-text-search",className:"grid gap-1 text-xs text-muted-foreground",children:["Search",t.jsx(u,{id:"audit-log-text-search",value:M,onChange:e=>{c({type:"set_text_search",value:e.target.value})},className:"w-[220px]",placeholder:"Action, metadata, values"})]}),t.jsxs(p,{value:P,onValueChange:e=>{c({type:"set_date_preset",value:e})},children:[t.jsx(g,{className:"w-[150px]",children:t.jsx(h,{placeholder:"Date range"})}),t.jsxs(j,{children:[t.jsx(f,{value:"24h",children:"Last 24 hours"}),t.jsx(f,{value:"7d",children:"Last 7 days"}),t.jsx(f,{value:"30d",children:"Last 30 days"}),t.jsx(f,{value:"custom",children:"Custom"})]})]}),"custom"===P&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{htmlFor:"audit-log-start-date",className:"grid gap-1 text-xs text-muted-foreground",children:["Start Date",t.jsx(u,{id:"audit-log-start-date",type:"date",value:T,onChange:e=>{c({type:"set_custom_start_date",value:e.target.value})},className:"w-[160px]"})]}),t.jsxs("label",{htmlFor:"audit-log-end-date",className:"grid gap-1 text-xs text-muted-foreground",children:["End Date",t.jsx(u,{id:"audit-log-end-date",type:"date",value:U,onChange:e=>{c({type:"set_custom_end_date",value:e.target.value})},className:"w-[160px]"})]})]}),t.jsx(i,{variant:"outline",size:"sm",onClick:()=>c({type:"set_page",page:1}),children:"Apply filters"}),le&&t.jsxs(i,{variant:"ghost",size:"sm",onClick:()=>{c({type:"clear_filters"})},children:[t.jsx(o,{className:"size-4 mr-1"}),"Clear"]})]})})}),t.jsxs(b,{children:[t.jsxs(s,{className:"pb-4",children:[t.jsxs(r,{className:"flex items-center gap-2",children:[t.jsx(z,{className:"size-5 text-[var(--channel-analytics-accent)]"}),"Recent Activity"]}),t.jsx(n,{children:"Admin actions are automatically logged here"})]}),t.jsxs(a,{children:[B?t.jsx("div",{className:"space-y-3",children:[...Array(5)].map((e,a)=>t.jsx(x,{className:"h-20 w-full"},a))}):Q?t.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/40 bg-destructive/10 p-4 text-sm",children:[t.jsx("p",{className:"font-medium text-destructive",children:"Audit log query failed"}),t.jsx("p",{className:"mt-1 text-muted-foreground",children:ne})]}):0===ae.length?t.jsx("div",{className:"py-12 text-center text-muted-foreground",children:le?"No entries match your filters":"No audit log entries yet"}):t.jsx("div",{className:"space-y-3",children:ae.map(e=>t.jsx(te,{entry:e,expanded:L===e.id,onToggle:()=>c({type:"set_expanded_id",value:L===e.id?null:e.id})},e.id))}),re>1&&t.jsxs("div",{className:"flex items-center justify-between mt-6 pt-4 border-t border-border/50",children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Page ",m," of ",re]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(i,{variant:"outline",size:"sm",onClick:()=>c({type:"set_page",page:e=>Math.max(1,e-1)}),disabled:1===m,children:[t.jsx(O,{className:"size-4 mr-1"}),"Previous"]}),t.jsxs(i,{variant:"outline",size:"sm",onClick:()=>c({type:"set_page",page:e=>Math.min(re,e+1)}),disabled:m===re,children:["Next",t.jsx(k,{className:"size-4 ml-1"})]})]})]})]})]})]})}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.