import{e as C,j as e,n as _,r as a,B as h,T as f,I as x}from"./render-CsAa6Dr_.js";import{B as M,T as S,b as T,c as k,d as b,e as t,f as v}from"./Base-BSqEL6Lb.js";import{A}from"./Add-vjzxrvRJ.js";import{D as B}from"./Delete-DK39hE54.js";import{g,G as I}from"./utils-B_PI31II.js";import{B as p}from"./Button-DRzV9gyj.js";import{b as D}from"./Dialog-DXg9g5Sc.js";import"./SwitchBase-Bk6NkRGa.js";const L=C(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"})),z=C(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"})),j=localStorage.getItem("apiBaseUrl"),E=({apiKey:o,onCancel:r,onSuccess:c})=>e.jsxs(h,{p:2,children:[e.jsx(f,{variant:"h6",gutterBottom:!0,children:localeMessages.confirm_deletion}),e.jsx(f,{children:localeMessages.are_you_sure_delete_key}),e.jsxs(h,{mt:2,display:"flex",justifyContent:"flex-end",children:[e.jsx(p,{onClick:r,sx:{mr:1},variant:"outlined",children:localeMessages.cancel}),e.jsx(p,{variant:"contained",color:"error",onClick:()=>{fetch(`${j}/api_keys/${o.id}/`,{method:"DELETE",headers:{"X-CSRFToken":g("csrftoken")}}).then(d=>{d.ok&&c()})},children:localeMessages.delete})]})]}),R=()=>{const[o,r]=a.useState(!1),[c,d]=a.useState(null),[l,n]=a.useState([]),[m,u]=a.useState(!1);a.useEffect(()=>{m||fetch(`${j}/api_keys/`,{method:"GET",headers:{"X-CSRFToken":g("csrftoken")}}).then(s=>s.json()).then(s=>{n(s.api_keys.map(i=>({id:i.id,key:i.key,created_by:i.created_by,created_at:i.created_at,visible:!1})))}).finally(()=>{u(!0)})},[m]);const y=()=>{fetch(`${j}/api_keys/`,{method:"POST",headers:{"X-CSRFToken":g("csrftoken")}}).then(s=>s.json()).then(s=>{s.visible=!1,n([...l,s])})};return e.jsxs(M,{breadCrumbList:[{label:localeMessages.api_keys,href:"#"}],showOrganizationSwitcher:!1,children:[e.jsx(I,{size:12,py:2,pl:2,children:e.jsxs(h,{p:2,sx:{border:"1px solid",borderColor:"grey.300",borderRadius:1,backgroundColor:"background.paper",minHeight:300,width:{lg:"80%"}},children:[e.jsx(f,{children:localeMessages.api_key_intro}),e.jsx(p,{variant:"contained",startIcon:e.jsx(A,{sx:{marginLeft:direction=="rtl"?1:0}}),onClick:y,sx:{marginLeft:direction=="rtl"?2:0,marginY:2},children:localeMessages.add_api_key}),l.length>0&&e.jsx(S,{sx:{maxHeight:440,border:"1px solid",borderColor:"grey.300",borderRadius:1},children:e.jsxs(T,{children:[e.jsx(k,{children:e.jsxs(b,{children:[e.jsx(t,{dir:direction,sx:{textAlign:direction==="rtl"?"right":"left"},children:localeMessages.key}),e.jsx(t,{dir:direction,sx:{textAlign:direction==="rtl"?"right":"left"},children:localeMessages.created_by}),e.jsx(t,{dir:direction,sx:{textAlign:direction==="rtl"?"right":"left"},children:localeMessages.created_at}),e.jsx(t,{sx:{width:"100px"},children:localeMessages.actions})]})}),e.jsx(v,{children:l.map(s=>e.jsxs(b,{children:[e.jsx(t,{dir:direction,sx:{textAlign:direction==="rtl"?"right":"left"},children:s.visible?s.key:"••••••••••••••••"}),e.jsx(t,{dir:direction,sx:{textAlign:direction==="rtl"?"right":"left"},children:s.created_by}),e.jsx(t,{dir:direction,sx:{textAlign:direction==="rtl"?"right":"left"},children:s.created_at}),e.jsxs(t,{children:[e.jsx(x,{onClick:()=>{d(e.jsx(E,{apiKey:s,onCancel:()=>r(!1),onSuccess:()=>{u(!1),r(!1)}})),r(!0)},children:e.jsx(B,{fontSize:"small"})}),s.visible?e.jsx(x,{onClick:()=>{n(l.map(i=>i.id===s.id?{...i,visible:!1}:i))},children:e.jsx(L,{fontSize:"small"})}):e.jsx(x,{onClick:()=>{n(l.map(i=>i.id===s.id?{...i,visible:!0}:i))},children:e.jsx(z,{fontSize:"small"})})]})]},s.id))})]})})]})}),e.jsx(D,{open:o,onClose:()=>r(!1),maxWidth:"sm",fullWidth:!0,children:c})]})};_({children:e.jsx(R,{})});
//# sourceMappingURL=settings_api_keys-DxMHPqpw.js.map
