import{iv as b,gk as B,iG as $,hi as k,gH as v,fH as e,g1 as f,cs as H,bZ as _,ck as P,ah as Q,bU as q,aD as g,cz as Z,cI as D,jD as z,c$ as G,iP as N,hk as J,hU as Y,dJ as V,f6 as K,i$ as O,bL as L,iQ as W,aZ as A,af as h,cp as l,gZ as X,cy as ee,bM as E}from"./strapi-ye6TfKul.js";import{u as se,g as T,b as te,a as ae}from"./getActionTypesDefaultMessages-DP4LeCgl.js";import{g as ie}from"./users-DLc-PG84.js";const w=()=>{const{formatDate:s}=b();return n=>{const a=B(n),o=s(a,{dateStyle:"long"}),t=s(a,{timeStyle:"medium",hourCycle:"h24"});return`${o}, ${t}`}},ne=({handleClose:s,logId:i})=>{const{toggleNotification:n}=$(),{_unstableFormatAPIError:a}=k(),{data:o,error:t,isLoading:d}=se(i);v.useEffect(()=>{t&&(n({type:"danger",message:a(t)}),s())},[t,a,s,n]);const u=w(),c=o&&"date"in o?u(o.date):"";return e.jsx(f.Root,{defaultOpen:!0,onOpenChange:s,children:e.jsxs(f.Content,{children:[e.jsx(f.Header,{children:e.jsx(H,{label:c,id:"title",children:e.jsx(_,{isCurrent:!0,children:c})})}),e.jsx(f.Body,{children:e.jsx(oe,{isLoading:d,data:o,formattedDate:c})})]})})},oe=({isLoading:s,data:i,formattedDate:n})=>{const{formatMessage:a}=b();if(s)return e.jsx(P,{padding:7,justifyContent:"center",alignItems:"center",children:e.jsx(Q,{children:"Loading content..."})});const{action:o,user:t,payload:d}=i;return e.jsxs(e.Fragment,{children:[e.jsx(q,{marginBottom:3,children:e.jsx(g,{variant:"delta",id:"title",children:a({id:"Settings.permissions.auditLogs.details",defaultMessage:"Log Details"})})}),e.jsxs(Z.Root,{gap:4,gridCols:2,paddingTop:4,paddingBottom:4,paddingLeft:6,paddingRight:6,marginBottom:4,background:"neutral100",hasRadius:!0,children:[e.jsx(j,{actionLabel:a({id:"Settings.permissions.auditLogs.action",defaultMessage:"Action"}),actionName:a({id:`Settings.permissions.auditLogs.${o}`,defaultMessage:T(o)},{model:d?.model})}),e.jsx(j,{actionLabel:a({id:"Settings.permissions.auditLogs.date",defaultMessage:"Date"}),actionName:n}),e.jsx(j,{actionLabel:a({id:"Settings.permissions.auditLogs.user",defaultMessage:"User"}),actionName:t?.displayName||"-"}),e.jsx(j,{actionLabel:a({id:"Settings.permissions.auditLogs.userId",defaultMessage:"User ID"}),actionName:t?.id.toString()||"-"})]}),e.jsxs(D.Root,{children:[e.jsx(D.Label,{children:a({id:"Settings.permissions.auditLogs.payload",defaultMessage:"Payload"})}),e.jsx(re,{value:JSON.stringify(d,null,2),disabled:!0})]})]})},re=z(G)`
  max-width: 100%;
  overflow: scroll;
`,j=({actionLabel:s,actionName:i})=>e.jsxs(P,{direction:"column",alignItems:"baseline",gap:1,children:[e.jsx(g,{textColor:"neutral600",variant:"sigma",children:s}),e.jsx(g,{textColor:"neutral600",children:i})]}),de=({canReadAuditLogs:s,canReadUsers:i})=>{const{toggleNotification:n}=$(),{_unstableFormatAPIError:a}=k(),[{query:o}]=N(),{data:t,error:d,isError:u,isLoading:c}=J({},{skip:!i,refetchOnMountOrArgChange:!0});v.useEffect(()=>{d&&n({type:"danger",message:a(d)})},[d,n,a]);const{data:y,isLoading:S,isError:C,error:p}=te(o,{refetchOnMountOrArgChange:!0,skip:!s});return v.useEffect(()=>{p&&n({type:"danger",message:a(p)})},[p,n,a]),{auditLogs:y,users:t?.users??[],isLoading:c||S,hasError:C||u}},U=s=>{const{formatMessage:i}=b(),n=Y(s.name),a=i({id:"Settings.permissions.auditLogs.filter.aria-label",defaultMessage:"Search and select an option to filter"}),o=t=>{n.onChange(s.name,t)};return e.jsx(V,{"aria-label":a,value:n.value,onChange:o,children:s.options?.map(t=>{const d=typeof t=="string"?t:t.value,u=typeof t=="string"?t:t.label;return e.jsx(K,{value:d,children:u},d)})})},le=({formatMessage:s,users:i,canReadUsers:n})=>{const a=[{label:s({id:"components.FilterOptions.FILTER_TYPES.$eq",defaultMessage:"is"}),value:"$eq"},{label:s({id:"components.FilterOptions.FILTER_TYPES.$ne",defaultMessage:"is not"}),value:"$ne"}],o=[{input:U,label:s({id:"Settings.permissions.auditLogs.action",defaultMessage:"Action"}),name:"action",operators:a,options:Object.keys(ae).map(t=>({label:s({id:`Settings.permissions.auditLogs.${t}`,defaultMessage:T(t)},{model:void 0}),value:t})),type:"enumeration"},{label:s({id:"Settings.permissions.auditLogs.date",defaultMessage:"Date"}),name:"date",type:"datetime"}];return n&&i?[...o,{input:U,label:s({id:"Settings.permissions.auditLogs.user",defaultMessage:"User"}),mainField:{name:"id",type:"integer"},name:"user",operators:a,options:i.map(t=>({label:ie(t),value:t.id.toString()})),type:"relation"}]:o},ue=()=>{const{formatMessage:s}=b(),i=O(r=>r.admin_app.permissions.settings),{allowedActions:{canRead:n,canReadUsers:a},isLoading:o}=W({...i?.auditLogs,readUsers:i?.users.read||[]}),[{query:t},d]=N(),{auditLogs:u,users:c,isLoading:y,hasError:S}=de({canReadAuditLogs:n,canReadUsers:a}),C=w(),p=le({formatMessage:s,users:c,canReadUsers:a}),M=[{name:"action",label:s({id:"Settings.permissions.auditLogs.action",defaultMessage:"Action"}),sortable:!0},{name:"date",label:s({id:"Settings.permissions.auditLogs.date",defaultMessage:"Date"}),sortable:!0},{name:"user",label:s({id:"Settings.permissions.auditLogs.user",defaultMessage:"User"}),sortable:!1,cellFormatter:({user:r})=>r?r.displayName:""}];if(S)return e.jsx(L.Error,{});const R=y||o,{results:I=[]}=u??{};return e.jsxs(L.Main,{"aria-busy":R,children:[e.jsx(L.Title,{children:s({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:s({id:"global.auditLogs",defaultMessage:"Audit Logs"})})}),e.jsx(A.Header,{title:s({id:"global.auditLogs",defaultMessage:"Audit Logs"}),subtitle:s({id:"Settings.permissions.auditLogs.listview.header.subtitle",defaultMessage:"Logs of all the activities that happened in your environment"})}),e.jsx(A.Action,{startActions:e.jsxs(h.Root,{options:p,children:[e.jsx(h.Trigger,{}),e.jsx(h.Popover,{zIndex:499}),e.jsx(h.List,{})]})}),e.jsxs(A.Content,{children:[e.jsx(l.Root,{rows:I,headers:M,isLoading:R,children:e.jsxs(l.Content,{children:[e.jsx(l.Head,{children:M.map(r=>e.jsx(l.HeaderCell,{...r},r.name))}),e.jsx(l.Empty,{}),e.jsx(l.Loading,{}),e.jsx(l.Body,{children:I.map(r=>e.jsxs(l.Row,{onClick:()=>d({id:r.id},"push",!0),children:[M.map(x=>{const{name:m,cellFormatter:F}=x;switch(m){case"action":return e.jsx(l.Cell,{children:e.jsx(g,{textColor:"neutral800",children:s({id:`Settings.permissions.auditLogs.${r.action}`,defaultMessage:T(r.action)},{model:r.payload?.model??""})})},m);case"date":return e.jsx(l.Cell,{children:e.jsx(g,{textColor:"neutral800",children:C(r.date)})},m);case"user":return e.jsx(l.Cell,{children:e.jsx(g,{textColor:"neutral800",children:F?F(r,x):"-"})},m);default:return e.jsx(l.Cell,{children:e.jsx(g,{textColor:"neutral800",children:r[m]||"-"})},m)}}),e.jsx(l.Cell,{onClick:x=>x.stopPropagation(),children:e.jsx(P,{justifyContent:"end",children:e.jsx(X,{onClick:()=>d({id:r.id},"push",!0),withTooltip:!1,label:s({id:"app.component.table.view",defaultMessage:"{target} details"},{target:`${r.action} action`}),variant:"ghost",children:e.jsx(ee,{})})})})]},r.id))})]})}),e.jsxs(E.Root,{...u?.pagination,children:[e.jsx(E.PageSize,{}),e.jsx(E.Links,{})]})]}),t?.id&&e.jsx(ne,{handleClose:()=>d({id:""},"remove",!0),logId:t.id.toString()})]})},pe=()=>{const s=O(i=>i.admin_app.permissions.settings?.auditLogs?.main);return e.jsx(L.Protect,{permissions:s,children:e.jsx(ue,{})})};export{ue as ListPage,pe as ProtectedListPage};
