import{gH as b,iP as N,iv as p,iF as w,iY as y,bS as B,fH as e,cp as a,h9 as I,aD as d,ck as L,d2 as P,dx as D,bU as H,gZ as O,dN as W,K as F,bn as _,jD as G,eo as Q}from"./strapi-ye6TfKul.js";import{R as k}from"./RelativeTime-DGWrj7A0.js";const ee=s=>b.useEffect(s,$),$=[],q=s=>[s.firstname,s.lastname].filter(Boolean).join(" ")||s.username||s.email||"",te=({permissions:s,headers:n=[],isLoading:l=!1,tokens:o=[],onConfirmDelete:i,tokenType:r,showOwner:u=!1})=>{const[{query:x}]=N(),{formatMessage:R,locale:S}=p(),[,M]=x&&x.sort?x.sort.split(":"):[void 0,"ASC"],E=w(),{trackUsage:U}=y(),g=B(S),j=[...o].sort((t,c)=>M==="DESC"?g.compare(c.name,t.name):g.compare(t.name,c.name)),{canDelete:h,canUpdate:f,canRead:C}=s,v=t=>()=>{C&&(U("willEditTokenFromList",{tokenType:r}),E(t.toString()))};return e.jsx(a.Root,{headers:n,rows:j,isLoading:l,children:e.jsxs(a.Content,{children:[e.jsx(a.Head,{children:n.map(t=>e.jsx(a.HeaderCell,{...t},t.name))}),e.jsx(a.Empty,{}),e.jsx(a.Loading,{}),e.jsx(a.Body,{children:j.map(t=>{const c=t.name==="Read Only"?I.apiTokens.ManageAPIToken:b.Fragment;return e.jsxs(a.Row,{onClick:v(t.id),children:[e.jsx(a.Cell,{maxWidth:"25rem",children:e.jsx(d,{textColor:"neutral800",fontWeight:"bold",ellipsis:!0,children:t.name})}),e.jsx(a.Cell,{maxWidth:"25rem",children:e.jsx(d,{textColor:"neutral800",ellipsis:!0,children:t.description})}),e.jsx(a.Cell,{children:e.jsx(d,{textColor:"neutral800",children:e.jsx(k,{timestamp:new Date(t.createdAt)})})}),e.jsx(a.Cell,{children:t.lastUsedAt&&e.jsx(d,{textColor:"neutral800",children:e.jsx(k,{timestamp:new Date(t.lastUsedAt),customIntervals:[{unit:"hours",threshold:1,text:R({id:"Settings.apiTokens.lastHour",defaultMessage:"last hour"})}]})})}),u===!0&&(()=>{const T=t,m=T.kind==="admin"?T.adminUserOwner:void 0,A=m!=null&&typeof m=="object"?q(m):"";return e.jsx(a.Cell,{maxWidth:"20rem",children:e.jsx(d,{textColor:"neutral800",ellipsis:!0,children:A})})})(),f||C||h?e.jsx(a.Cell,{children:e.jsxs(L,{justifyContent:"end",children:[e.jsx(c,{children:f&&e.jsx(J,{tokenName:t.name,tokenId:t.id})}),h&&e.jsx(Z,{tokenName:t.name,onClickDelete:()=>i?.(t.id),tokenType:r})]})}):null]},t.id)})})]})})},z={edit:{id:"app.component.table.edit",defaultMessage:"Edit {target}"},read:{id:"app.component.table.read",defaultMessage:"Read {target}"}},K=({tokenName:s,tokenId:n,buttonType:l="edit",children:o})=>{const{formatMessage:i}=p();return e.jsx(Y,{tag:_,to:n.toString(),onClick:r=>r.stopPropagation(),title:i(z[l],{target:s}),variant:"ghost",size:"S",children:o})},Y=G(Q)`
  padding: 0.7rem;

  & > span {
    display: flex;
  }
`,Z=({tokenName:s,onClickDelete:n,tokenType:l})=>{const{formatMessage:o}=p(),{trackUsage:i}=y(),r=()=>{i("willDeleteToken",{tokenType:l}),n()};return e.jsx(D.Root,{children:e.jsxs(H,{paddingLeft:1,onClick:u=>u.stopPropagation(),children:[e.jsx(D.Trigger,{children:e.jsx(O,{label:o({id:"global.delete-target",defaultMessage:"Delete {target}"},{target:`${s}`}),name:"delete",variant:"ghost",children:e.jsx(W,{})})}),e.jsx(F,{onConfirm:r})]})})},J=({tokenName:s,tokenId:n})=>e.jsx(K,{tokenName:s,tokenId:n,children:e.jsx(P,{})});export{te as T,ee as u};
