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