import{b1 as p,j as e,S as i,h as u,aB as x}from"./vendor-ClLR6ncd.js";import{E as f,i as y,n as l,L as j}from"./index-OtVJl4GC.js";import{E as g}from"./Messages-BRmQDxrZ.js";import{S as w}from"./SyncingMessage-Y9_Q8a92.js";import{T as S,V as q}from"./highlightSearch-BTHB3jgf.js";import{D as C,F as b}from"./DownloadAsCsv-BEhuLI3h.js";import{u as K}from"./useColumnVisSortingSearchState-OMxoUysL.js";import"./lodash-ZyeDnt0e.js";import{R,S as D,c as F}from"./filterFunctions-DEb2TGMk.js";import{R as v}from"./RefreshDataButton-BMv_Vwgi.js";import{D as V}from"./CellWithTooltip-B3oIcdYt.js";import{B as L}from"./Box-Co2WcNPC.js";import"./usePrevious-BP64N3hu.js";import"./WithMeasure-BDk9QPMF.js";import"./TableRow-CGDSOtFZ.js";import"./TableSortLabel-BJFq2axQ.js";import"./DirtySearchInput-D-NMdA6o.js";import"./useDirtyStateInput-CLFyv7KP.js";import"./TypographyWithTooltip-BFAG3Va9.js";const T=["admin","requests"];function E(){return f(T,async()=>{const s=await y({url:"/requests"})||{requests:{}};return[].concat(...Object.keys(s.requests).map(t=>s.requests[t].map(r=>({...r,backend:t,duration:r.duration/1e9,finished:new Date(Math.round(r.finished/1e6)).toLocaleString(),started:new Date(Math.round(r.started/1e6)).toLocaleString(),id:Object.values(r).join(";")}))))})}const o=[{header:"Server",accessorKey:"backend",size:90},{header:"Status",accessorKey:"statusCode",size:90},{header:"Method",accessorKey:"method",size:90},{header:"URL",accessorKey:"uri"},{header:"Source",accessorKey:"source"},{header:"Started",accessorKey:"started"},{header:"Finished",accessorKey:"finished"},{header:"Duration (s)",accessorKey:"duration",size:125}].map(s=>({...s,cell:V})),I=Object.assign({},...o.map(({accessorKey:s,header:t})=>({[s]:t})));function z({requests:s}){const{resetTableState:t,columnVisibility:r,sortingState:d,searchInput:a,setColumnVisibility:n,setSortingState:m,setSearchInput:c}=K({columns:o}),{value:h}=l();return e.jsxs(L,{sx:{flexGrow:1,display:"flex",flexDirection:"column"},children:[e.jsxs(i,{direction:"row",justifyContent:"space-between",sx:{pb:2},children:[e.jsxs(i,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(b,{accessorKey2header:I,columnVisibility:r,setColumnVisibility:n}),e.jsx(R,{resetTableState:t})]}),e.jsx(D,{searchInput:a,setSearchInput:c,initRowsLength:s.length})]}),e.jsx(x,{sx:{flexGrow:1,display:"flex",flexDirection:"column"},children:e.jsx(q,{globalFilterFn:F,sortingState:d,setSortingState:m,columnVisibility:r,setColumnVisibility:n,searchInput:a,setSearchInput:c,rows:s,columns:o,dense:h})})]})}function se(){const s=E(),{title:t}=p(),{value:r}=l();return s.isLoading?e.jsx("div",{style:{display:"flex",alignItems:"center",flexGrow:1},children:e.jsx(j,{})}):e.jsxs(i,{spacing:r?1:2,sx:{flexGrow:1},children:[e.jsxs(i,{direction:"row",justifyContent:"space-between",children:[e.jsxs(i,{direction:"row",spacing:4,children:[e.jsx(u,{variant:"h4",children:t}),e.jsx(w,{isFetching:s.isFetching,entityKind:"requests"})]}),e.jsxs(i,{direction:"row",spacing:2,children:[e.jsx(v,{disabled:s.isFetching,onClick:s.refetch}),e.jsx(C,{filenamePrefix:"requests",rows:s.data,columns:o})]})]}),s.isError?e.jsx(g,{error:s.error,resetError:()=>{}}):s.data.length===0?e.jsx(u,{children:"There are no requests"}):e.jsx(S,{children:e.jsx(z,{requests:s.data})})]})}export{se as default};
