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