import{b1 as L,r as d,j as e,S as l,h as f,H as N,aB as R}from"./vendor-ClLR6ncd.js";import{T as U}from"./lodash-ZyeDnt0e.js";import{d as W,i as j,n as T,L as k,o as B,E as D}from"./index-OtVJl4GC.js";import{E as G}from"./Messages-BRmQDxrZ.js";import{T as I,V as O}from"./highlightSearch-BTHB3jgf.js";import{D as Q,F as M}from"./DownloadAsCsv-BEhuLI3h.js";import{u as P}from"./useColumnVisSortingSearchState-OMxoUysL.js";import{R as q,S as z,a as H}from"./filterFunctions-DEb2TGMk.js";import{D as S}from"./DatePicker-Cs8Kn9kZ.js";import{M as K}from"./MultipleSelectWithCheckboxes-BT7l66Wa.js";import{f as _,C as J}from"./model-Dfrorm_S.js";import{B as X}from"./Box-Co2WcNPC.js";import"./WithMeasure-BDk9QPMF.js";import"./TableRow-CGDSOtFZ.js";import"./TableSortLabel-BJFq2axQ.js";import"./DirtySearchInput-D-NMdA6o.js";import"./useDirtyStateInput-CLFyv7KP.js";import"./PureDateInput-CU8ZdDwn.js";import"./InputAdornment-CFoDSQyQ.js";import"./DialogContent-DR8Wx7Lo.js";import"./MenuItem-CCerWMyq.js";import"./dividerClasses-DvO85-mA.js";import"./TypographyWithTooltip-BFAG3Va9.js";import"./Link-BLwKPJFF.js";const v={eventName:"Name",eventTime:"Time",user:"User",remote:"Remote",databaseName:"Database",target:"Target"};function Y(){return W(async({usernames:t,eventTypes:a,startDate:r,endDate:s})=>{const i=await j({url:"/auditLog",params:{limit:1e3,startDate:r,endDate:s,users:t.join(","),events:a.join(",")}}),o=_(i.names,[],!1,!1);return{rows:i.values.map(n=>Object.assign({},...n.map((u,c)=>({[o[c].header]:o[c].accessorFn(n)})))),columns:i.names.filter(n=>v[n]).map(n=>({sortingFn:"queryResponseSortingByValue",enableGlobalFilter:!0,accessorKey:n,header:v[n],cell:J}))}})}function Z({rows:t,columns:a}){const{resetTableState:r,columnVisibility:s,sortingState:i,searchInput:o,setColumnVisibility:n,setSortingState:u,setSearchInput:c}=P({columns:a}),{value:m}=T();return e.jsxs(X,{sx:{flexGrow:1,display:"flex",flexDirection:"column"},children:[e.jsxs(l,{direction:"row",justifyContent:"space-between",sx:{pb:m?0:2},children:[e.jsxs(l,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(M,{accessorKey2header:Object.assign({},...a.map(({accessorKey:p,header:x})=>({[p]:x}))),columnVisibility:s,setColumnVisibility:n}),e.jsx(q,{resetTableState:r})]}),e.jsx(z,{searchInput:o,setSearchInput:c,initRowsLength:t.length})]}),e.jsx(R,{sx:{flexGrow:1,display:"flex",flexDirection:"column"},children:e.jsx(O,{globalFilterFn:H,sortingState:i,setSortingState:u,columnVisibility:s,setColumnVisibility:n,searchInput:o,setSearchInput:c,rows:t,columns:a,dense:m})})]})}const h=[];function E({selected:t,setSelected:a,query:r,label:s}){return d.useEffect(()=>{!Array.isArray(t)&&Array.isArray(r.data)&&a(r.data.map(({value:i})=>i))},[r.data,a,t]),e.jsx(K,{sx:{width:"200px"},label:s,disabled:r.isLoading,options:r.data||h,selected:t||h,setSelected:a})}function $({selectedUsernames:t,setSelectedUsernames:a}){const r=D(["usernames"],async()=>[{label:"unknown",value:"UNKNOWN"}].concat((await j({url:"/users"})).map(s=>({label:s,value:s}))));return e.jsx(E,{label:"Usernames",query:r,selected:t,setSelected:a})}function ee({selectedEventTypes:t,setSelectedEventTypes:a}){const r=D(["eventtypes"],async()=>(await j({url:"/auditLog/eventTypes"})).map(({class:s,label:i})=>({label:i.slice(1,-1),value:s})));return e.jsx(E,{label:"Event types",query:r,selected:t,setSelected:a})}const te=t=>t&&t.add(1,"day").subtract(1,"second"),C=t=>t&&t.utc(!0).format();function De(){var y,b,g,w;const t=Y(),{value:a}=T(),{title:r}=L(),[s,i]=d.useState(),[o,n]=d.useState(),[u,c]=d.useState(null),[m,p]=d.useState(null),x=()=>{t.mutate({usernames:s,eventTypes:o,startDate:C(u),endDate:C(te(m))})},V=!s||s.length===0||!o||s.length===0;return e.jsxs(l,{spacing:B(),sx:{flexGrow:1},children:[e.jsxs(l,{direction:"row",justifyContent:"space-between",children:[e.jsx(l,{direction:"row",spacing:4,children:e.jsx(f,{variant:"h4",children:r})}),e.jsx(l,{direction:"row",spacing:2,children:e.jsx(Q,{filenamePrefix:"audit-log",rows:(((y=t.data)==null?void 0:y.rows)||h).map(A=>U(A,({originalValue:F})=>F||"")),columns:(b=t.data)==null?void 0:b.columns})})]}),e.jsxs(l,{spacing:a?1:2,children:[e.jsxs(l,{sx:{rowGap:2,columnGap:2},direction:"row",flexWrap:"wrap",alignItems:"center",children:[e.jsx($,{selectedUsernames:s,setSelectedUsernames:i}),e.jsx(ee,{selectedEventTypes:o,setSelectedEventTypes:n}),e.jsx(S,{date:u,setDate:c,label:"Start date"}),e.jsx(S,{date:m,setDate:p,label:"End date"})]}),e.jsx(N,{variant:"contained",onClick:x,disabled:V,children:"View Audit Log"})]}),t.isError?e.jsx(G,{error:t.error,resetError:()=>{}}):t.isLoading?e.jsx(k,{}):t.data?t.data.length===0?e.jsx(f,{children:"There are no audit logs for selected filters"}):e.jsx(I,{children:e.jsx(Z,{rows:(g=t.data)==null?void 0:g.rows,columns:(w=t.data)==null?void 0:w.columns})}):e.jsx(f,{children:'Select from each input above and click "View Audit Log" to get the audit'})]})}export{De as default};
