import{aA as S,j as e,P as d,a as M,w as C,z as D,ak as N,b as V,bp as _,v as F,r as o,ar as R,B as T,ag as A,a_ as h,ai as y,af as w,s as x}from"./strapi-D_Y4QZhh.js";import{u as v,T as B}from"./Table-LYoPHvd8.js";import{u as U,a as H}from"./apiTokens-CXk70gRh.js";import{A as r}from"./constants-Q2dfXdfa.js";const z=[{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}],G=()=>{const{formatMessage:s}=M(),{toggleNotification:a}=C(),L=S(t=>t.admin_app.permissions.settings?.["api-tokens"]),{allowedActions:{canRead:u,canCreate:c,canDelete:b,canUpdate:j}}=D(L),p=N(),{trackUsage:i}=V(),m=_("ListView",t=>t.startSection),{_unstableFormatAPIError:l}=F();o.useEffect(()=>{m("apiTokens")},[m]),o.useEffect(()=>{p({search:R.stringify({sort:"name:ASC"},{encode:!1})})},[p]);const P=z.map(t=>({...t,label:s(t.label)}));v(()=>{i("willAccessTokenList",{tokenType:r})});const{data:n=[],isLoading:k,error:g}=U();o.useEffect(()=>{g&&a({type:"danger",message:l(g)})},[g,l,a]),o.useEffect(()=>{i("didAccessTokenList",{number:n.length,tokenType:r})},[n,i]);const[E]=H(),I=async t=>{try{const f=await E(t);if("error"in f){a({type:"danger",message:l(f.error)});return}i("didDeleteToken")}catch{a({type:"danger",message:s({id:"notification.error",defaultMessage:"Something went wrong"})})}};return e.jsxs(e.Fragment,{children:[e.jsx(d.Title,{children:s({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:"API Tokens"})}),e.jsx(T.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:c&&e.jsx(A,{tag:h,"data-testid":"create-api-token-button",startIcon:e.jsx(y,{}),size:"S",onClick:()=>i("willAddTokenFromList",{tokenType:r}),to:"/settings/api-tokens/create",children:s({id:"Settings.apiTokens.create",defaultMessage:"Create new API Token"})})}),u?e.jsx(d.Main,{"aria-busy":k,children:e.jsxs(T.Content,{children:[n.length>0&&e.jsx(B,{permissions:{canRead:u,canDelete:b,canUpdate:j},headers:P,isLoading:k,onConfirmDelete:I,tokens:n,tokenType:r}),c&&n.length===0?e.jsx(w,{icon:e.jsx(x,{width:"16rem"}),content:s({id:"Settings.apiTokens.addFirstToken",defaultMessage:"Add your first API Token"}),action:e.jsx(A,{tag:h,variant:"secondary",startIcon:e.jsx(y,{}),to:"/settings/api-tokens/create",children:s({id:"Settings.apiTokens.addNewToken",defaultMessage:"Add new API Token"})})}):null,!c&&n.length===0?e.jsx(w,{icon:e.jsx(x,{width:"16rem"}),content:s({id:"Settings.apiTokens.emptyStateLayout",defaultMessage:"You don’t have any content yet..."})}):null]})}):e.jsx(d.NoPermissions,{})]})},K=()=>{const s=S(a=>a.admin_app.permissions.settings?.["api-tokens"].main);return e.jsx(d.Protect,{permissions:s,children:e.jsx(G,{})})};export{G as ListView,K as ProtectedListView};
