import{i$ as x,fH as e,bL as r,iv as P,iG as C,iQ as D,iF as I,iY as V,hi as N,gH as m,fP as _,aZ as T,eo as p,a$ as h,gX as A,aP as w,aQ as y}from"./strapi-ye6TfKul.js";import{u as v,T as F}from"./Table-o5Ux62Z-.js";import{h as H,c as O}from"./apiTokens-DAwv_6wW.js";import{A as o}from"./constants-pDXhqpw2.js";import"./RelativeTime-DGWrj7A0.js";const U=[{name:"name",label:{id:"Settings.adminTokens.ListView.headers.name",defaultMessage:"Name"},sortable:!0},{name:"description",label:{id:"Settings.adminTokens.ListView.headers.description",defaultMessage:"Description"},sortable:!1},{name:"createdAt",label:{id:"Settings.adminTokens.ListView.headers.createdAt",defaultMessage:"Created at"},sortable:!1},{name:"lastUsedAt",label:{id:"Settings.adminTokens.ListView.headers.lastUsedAt",defaultMessage:"Last used"},sortable:!1},{name:"adminUserOwner",label:{id:"Settings.adminTokens.ListView.headers.owner",defaultMessage:"Owner"},sortable:!1}],R=()=>{const{formatMessage:s}=P(),{toggleNotification:t}=C(),b=x(n=>n.admin_app.permissions.settings?.["admin-tokens"]),{allowedActions:{canRead:g,canCreate:d,canDelete:L,canUpdate:S}}=D(b),u=I(),{trackUsage:i}=V(),{_unstableFormatAPIError:l}=N();m.useEffect(()=>{u({search:_.stringify({sort:"name:ASC"},{encode:!1})},{replace:!0})},[u]);const j=U.map(n=>({...n,label:s(n.label)}));v(()=>{i("willAccessTokenList",{tokenType:o})});const{data:a=[],isLoading:f,error:c}=H();m.useEffect(()=>{c&&t({type:"danger",message:l(c)})},[c,l,t]),m.useEffect(()=>{i("didAccessTokenList",{number:a.length,tokenType:o})},[a,i]);const[M]=O(),E=async n=>{try{const k=await M(n);if("error"in k){t({type:"danger",message:l(k.error)});return}i("didDeleteToken")}catch{t({type:"danger",message:s({id:"notification.error",defaultMessage:"Something went wrong"})})}};return e.jsxs(e.Fragment,{children:[e.jsx(r.Title,{children:s({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:"Admin Tokens"})}),e.jsx(T.Header,{title:s({id:"Settings.adminTokens.title",defaultMessage:"Admin Tokens"}),subtitle:s({id:"Settings.adminTokens.description",defaultMessage:"List of generated tokens to programmatically access the admin features"}),primaryAction:d&&e.jsx(p,{tag:h,"data-testid":"create-admin-token-button",startIcon:e.jsx(A,{}),size:"S",onClick:()=>i("willAddTokenFromList",{tokenType:o}),to:"/settings/admin-tokens/create",children:s({id:"Settings.adminTokens.create",defaultMessage:"Create new Admin Token"})})}),g?e.jsx(r.Main,{"aria-busy":f,children:e.jsxs(T.Content,{children:[a.length>0&&e.jsx(F,{permissions:{canRead:g,canDelete:L,canUpdate:S},headers:j,isLoading:f,onConfirmDelete:E,tokens:a,tokenType:o,showOwner:!0}),d&&a.length===0?e.jsx(w,{icon:e.jsx(y,{width:"16rem"}),content:s({id:"Settings.adminTokens.addFirstToken",defaultMessage:"Create your first Admin Token"}),action:e.jsx(p,{tag:h,variant:"secondary",startIcon:e.jsx(A,{}),to:"/settings/admin-tokens/create",children:s({id:"Settings.adminTokens.create",defaultMessage:"Create new Admin Token"})})}):null,!d&&a.length===0?e.jsx(w,{icon:e.jsx(y,{width:"16rem"}),content:s({id:"Settings.adminTokens.emptyStateLayout",defaultMessage:"You don't have any content yet..."})}):null]})}):e.jsx(r.NoPermissions,{})]})},$=()=>{const s=x(t=>t.admin_app.permissions.settings?.["admin-tokens"]?.main);return e.jsx(r.Protect,{permissions:s,children:e.jsx(R,{})})};export{R as ListView,$ as ProtectedListView};
