import{i as b,j as e,a as v,r as d,u as S,B as x,T as p,I as h}from"./render-D1ZqzUbP.js";import{B as w,T as A,a as z,b as B,c as _,d as l,e as I}from"./Base-Qt2-pbvB.js";import{A as D}from"./Add-CnBbtKb6.js";import{D as L}from"./Delete-BKYo-wX-.js";import{g as j}from"./utils-VIUIl18e.js";import{G as M}from"./Grid-BihMtcd8.js";import{B as g}from"./Button-DJ_uYab0.js";import{D as E}from"./Dialog-aanaDG86.js";import"./formControlState-C1XOL3mQ.js";import"./Select-Ht3nAO4Q.js";import"./Link-4dUp4u44.js";import"./isMuiElement-BcEQvMml.js";const R=b(e.jsx("path",{d:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5M12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5m0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3"})),H=b(e.jsx("path",{d:"M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7M2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2m4.31-.78 3.15 3.15.02-.16c0-1.66-1.34-3-3-3z"})),K=b(e.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2m0 16H8V7h11z"})),F=({apiKey:f,onCancel:n,onSuccess:m})=>{const{localeMessages:o,apiBaseUrl:a}=S();return e.jsxs(x,{p:2,children:[e.jsx(p,{variant:"h6",gutterBottom:!0,children:o.confirm_deletion}),e.jsx(p,{children:o.are_you_sure_delete_key}),e.jsxs(x,{mt:2,display:"flex",justifyContent:"flex-end",children:[e.jsx(g,{onClick:n,sx:{mr:1},variant:"outlined",children:o.cancel}),e.jsx(g,{variant:"contained",color:"error",onClick:()=>{fetch(`${a}/api_keys/${f.id}/`,{method:"DELETE",headers:{"X-CSRFToken":j("csrftoken")}}).then(c=>{c.ok&&m()})},children:o.delete})]})]})},O=()=>{const[f,n]=d.useState(!1),[m,o]=d.useState(null),[a,c]=d.useState([]),[u,y]=d.useState(!1),{localeMessages:r,apiBaseUrl:C,direction:i}=S();d.useEffect(()=>{u||fetch(`${C}/api_keys/`,{method:"GET",headers:{"X-CSRFToken":j("csrftoken")}}).then(t=>t.json()).then(t=>{c(t.api_keys.map(s=>({id:s.id,key:s.key,created_by:s.created_by,created_at:s.created_at,visible:!1})))}).finally(()=>{y(!0)})},[u]);const T=()=>{fetch(`${C}/api_keys/`,{method:"POST",headers:{"X-CSRFToken":j("csrftoken")}}).then(t=>t.json()).then(t=>{t.visible=!1,c([...a,t])})},k=async t=>{try{await navigator.clipboard.writeText(t)}catch(s){console.error("Failed to copy API key:",s)}};return e.jsxs(w,{breadCrumbList:[{label:r.api_keys,href:"#"}],showOrganizationSwitcher:!1,children:[e.jsx(M,{size:12,py:2,pl:2,children:e.jsxs(x,{p:2,sx:{border:"1px solid",borderColor:"border.main",borderRadius:2,backgroundColor:"background.box",minHeight:300,width:{lg:"80%"}},children:[e.jsx(p,{children:r.api_key_intro}),e.jsx(g,{variant:"contained",startIcon:e.jsx(D,{sx:{marginLeft:i=="rtl"?1:0}}),onClick:T,sx:{marginLeft:i=="rtl"?2:0,marginY:2},children:r.add_api_key}),a.length>0&&e.jsx(A,{sx:{maxHeight:440,border:"1px solid",borderColor:"grey.300",borderRadius:1},children:e.jsxs(z,{sx:{tableLayout:"fixed",width:"100%"},children:[e.jsx(B,{children:e.jsxs(_,{children:[e.jsx(l,{dir:i,sx:{width:"50%",textAlign:i==="rtl"?"right":"left"},children:r.key}),e.jsx(l,{dir:i,sx:{width:"20%",textAlign:i==="rtl"?"right":"left"},children:r.created_by}),e.jsx(l,{dir:i,sx:{width:"20%",textAlign:i==="rtl"?"right":"left"},children:r.created_at}),e.jsx(l,{sx:{width:"10%"},children:r.actions})]})}),e.jsx(I,{children:a.map(t=>e.jsxs(_,{children:[e.jsx(l,{dir:i,sx:{textAlign:i==="rtl"?"right":"left"},children:e.jsxs(x,{sx:{display:"flex",alignItems:"center",gap:1,minWidth:0},children:[e.jsx(p,{component:"span",sx:{fontFamily:"monospace",overflowWrap:"anywhere",whiteSpace:"normal",flex:1},children:t.visible?t.key:"••••••••••••••••"}),e.jsx(h,{size:"small",onClick:()=>k(t.key),"aria-label":r.copy||"Copy",children:e.jsx(K,{fontSize:"small"})})]})}),e.jsx(l,{dir:i,sx:{textAlign:i==="rtl"?"right":"left"},children:t.created_by}),e.jsx(l,{dir:i,sx:{textAlign:i==="rtl"?"right":"left"},children:t.created_at}),e.jsxs(l,{children:[e.jsx(h,{onClick:()=>{o(e.jsx(F,{apiKey:t,onCancel:()=>n(!1),onSuccess:()=>{y(!1),n(!1)}})),n(!0)},children:e.jsx(L,{fontSize:"small"})}),t.visible?e.jsx(h,{onClick:()=>{c(a.map(s=>s.id===t.id?{...s,visible:!1}:s))},children:e.jsx(R,{fontSize:"small"})}):e.jsx(h,{onClick:()=>{c(a.map(s=>s.id===t.id?{...s,visible:!0}:s))},children:e.jsx(H,{fontSize:"small"})})]})]},t.id))})]})})]})}),e.jsx(E,{open:f,onClose:()=>n(!1),maxWidth:"sm",fullWidth:!0,children:m})]})};v({children:e.jsx(O,{})});
//# sourceMappingURL=settings_api_keys-Bo6a11Qm.js.map
