import{r as b,a as h,cw as S,cx as E,j as e,u as M,ak as B,b as w,aU as I,bx as a,T as g,e as L,g as A,bn as y,a8 as U,I as $,bc as N,bo as P,ah as F,k as O,ag as H}from"./strapi-BZkmC8So.js";const V=s=>b.useEffect(s,W),W=[],q=["years","months","days","hours","minutes","seconds"],v=b.forwardRef(({timestamp:s,customIntervals:n=[],...l},i)=>{const{formatRelativeTime:d,formatDate:o,formatTime:c}=h(),u=S({start:s,end:Date.now()}),x=q.find(r=>u[r]>0&&Object.keys(u).includes(r)),j=E(s)?-u[x]:u[x],m=n.find(r=>u[r.unit]<r.threshold),p=m?m.text:d(j,x,{numeric:"auto"});return e.jsx("time",{ref:i,dateTime:s.toISOString(),role:"time",title:`${o(s)} ${c(s)}`,...l,children:p})}),X=({permissions:s,headers:n=[],isLoading:l=!1,tokens:i=[],onConfirmDelete:d,tokenType:o})=>{const[{query:c}]=M(),{formatMessage:u,locale:x}=h(),[,j]=c&&c.sort?c.sort.split(":"):[void 0,"ASC"],m=B(),{trackUsage:p}=w(),r=I(x),f=[...i].sort((t,k)=>j==="DESC"?r.compare(k.name,t.name):r.compare(t.name,k.name)),{canDelete:C,canUpdate:T,canRead:D}=s,R=t=>()=>{D&&(p("willEditTokenFromList",{tokenType:o}),m(t.toString()))};return e.jsx(a.Root,{headers:n,rows:f,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:f.map(t=>e.jsxs(a.Row,{onClick:R(t.id),children:[e.jsx(a.Cell,{maxWidth:"25rem",children:e.jsx(g,{textColor:"neutral800",fontWeight:"bold",ellipsis:!0,children:t.name})}),e.jsx(a.Cell,{maxWidth:"25rem",children:e.jsx(g,{textColor:"neutral800",ellipsis:!0,children:t.description})}),e.jsx(a.Cell,{children:e.jsx(g,{textColor:"neutral800",children:e.jsx(v,{timestamp:new Date(t.createdAt)})})}),e.jsx(a.Cell,{children:t.lastUsedAt&&e.jsx(g,{textColor:"neutral800",children:e.jsx(v,{timestamp:new Date(t.lastUsedAt),customIntervals:[{unit:"hours",threshold:1,text:u({id:"Settings.apiTokens.lastHour",defaultMessage:"last hour"})}]})})}),T||D||C?e.jsx(a.Cell,{children:e.jsxs(L,{justifyContent:"end",children:[T&&e.jsx(J,{tokenName:t.name,tokenId:t.id}),C&&e.jsx(_,{tokenName:t.name,onClickDelete:()=>d?.(t.id),tokenType:o})]})}):null]},t.id))})]})})},z={edit:{id:"app.component.table.edit",defaultMessage:"Edit {target}"},read:{id:"app.component.table.read",defaultMessage:"Read {target}"}},G=({tokenName:s,tokenId:n,buttonType:l="edit",children:i})=>{const{formatMessage:d}=h();return e.jsx(Q,{tag:F,to:n.toString(),onClick:o=>o.stopPropagation(),title:d(z[l],{target:s}),variant:"ghost",size:"S",children:i})},Q=O(H)`
  padding: 0.7rem;

  & > span {
    display: flex;
  }
`,_=({tokenName:s,onClickDelete:n,tokenType:l})=>{const{formatMessage:i}=h(),{trackUsage:d}=w(),o=()=>{d("willDeleteToken",{tokenType:l}),n()};return e.jsx(y.Root,{children:e.jsxs(U,{paddingLeft:1,onClick:c=>c.stopPropagation(),children:[e.jsx(y.Trigger,{children:e.jsx($,{label:i({id:"global.delete-target",defaultMessage:"Delete {target}"},{target:`${s}`}),name:"delete",variant:"ghost",children:e.jsx(N,{})})}),e.jsx(P,{onConfirm:o})]})})},J=({tokenName:s,tokenId:n})=>e.jsx(G,{tokenName:s,tokenId:n,children:e.jsx(A,{})});export{X as T,V as u};
