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