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