import{r as n,u as C,j as e,B as h,I as p,f as S,a as D,c as b,G as v,H as P,J as I,T as x,K as L,M as T,N as k,O as F,P as $,Q as U,A as O,R as H}from"./index-f9c70843.js";import{I as N}from"./input-ae70f3cc.js";function M({children:i,data:l,onCloseModal:r}){const[c,m]=n.useState(!1),[s,t]=n.useState((l==null?void 0:l.apikeyname)??""),[d,y]=n.useState(""),[u,f]=n.useState(!1),[A,j]=n.useState(!0),K=C(o=>o.setSuccessData),a=n.useRef(null);n.useEffect(()=>{c?(f(!1),g()):r()},[c]);function g(){t(""),y("")}const _=async()=>{var o,w;d&&(await navigator.clipboard.writeText(d),(o=a==null?void 0:a.current)==null||o.focus(),(w=a==null?void 0:a.current)==null||w.select(),K({title:v}),j(!1),setTimeout(()=>{j(!0)},3e3))};function R(){P(s).then(o=>{y(o.api_key)}).catch(o=>{})}function E(){u?m(!1):(f(!0),R())}return e.jsxs(h,{onSubmit:E,size:"small-h-full",open:c,setOpen:m,children:[e.jsx(h.Trigger,{children:i}),e.jsxs(h.Header,{description:u?e.jsxs(e.Fragment,{children:[" ","Please save this secret key somewhere safe and accessible. For security reasons,"," ",e.jsx("strong",{children:"you won't be able to view it again"})," through your account. If you lose this secret key, you'll need to generate a new one."]}):e.jsx(e.Fragment,{children:"Create a secret API Key to use Langflow API."}),children:[e.jsx("span",{className:"pr-2",children:"Create API Key"}),e.jsx(p,{name:"Key",className:"h-6 w-6 pl-1 text-foreground","aria-hidden":"true"})]}),e.jsx(h.Content,{children:u?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-full",children:e.jsx(N,{ref:a,readOnly:!0,value:d})}),e.jsx(S,{onClick:()=>{_()},variant:"none",size:"none",children:A?e.jsx(p,{name:"Copy",className:"h-4 w-4"}):e.jsx(p,{name:"Check",className:"h-4 w-4"})})]})}):e.jsx(D,{name:"apikey",children:e.jsx("div",{className:"flex items-center justify-between gap-2",children:e.jsx(b,{asChild:!0,children:e.jsx(N,{id:"primary-input",value:s,ref:a,onChange:({target:{value:o}})=>{t(o)},placeholder:"Insert a name for your API Key"})})})})}),e.jsx(h.Footer,{submit:{label:u?"Done":"Create Secret Key"}})]})}const Y=({selectedRows:i,fetchApiKeys:l,userId:r})=>e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex w-full items-center justify-between gap-4 space-y-0.5",children:[e.jsxs("div",{className:"flex w-full flex-col",children:[e.jsxs("h2",{className:"flex items-center text-lg font-semibold tracking-tight",children:["Langflow API",e.jsx(p,{name:"Key",className:"ml-2 h-5 w-5 text-primary"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:I})]}),e.jsx("div",{className:"flex flex-shrink-0 items-center gap-2",children:e.jsx(M,{data:r,onCloseModal:l,children:e.jsxs(S,{"data-testid":"api-key-button-store",variant:"primary",children:[e.jsx(p,{name:"Plus",className:"w-4"}),"Add New"]})})})]})}),z=Y,B=()=>[{headerCheckboxSelection:!0,checkboxSelection:!0,showDisabledCheckboxes:!0,headerName:"Name",field:"name",cellRenderer:x,flex:2},{headerName:"Key",field:"api_key",cellRenderer:x,flex:1},{headerName:"Created",field:"created_at",cellRenderer:x,flex:1},{headerName:"Last Used",field:"last_used_at",cellRenderer:x,flex:1},{headerName:"Total Uses",field:"total_uses",cellRenderer:x,flex:1,resizable:!1}],G=(i,l,r,c)=>({fetchApiKeys:()=>{l(!0),L().then(s=>{r.current=s.api_keys.map(t=>({...t,name:t.name&&t.name!==""?t.name:"Untitled",last_used_at:t.last_used_at??"Never"})),c(s.user_id),l(!1)}).catch(s=>{l(!1)})}}),V=G,J=(i,l,r,c)=>({handleDeleteKey:()=>{Promise.all(i.map(s=>T(s))).then(()=>{l(),r({title:i.length===1?k:F})}).catch(s=>{var t,d;c({title:i.length===1?$:U,list:[(d=(t=s==null?void 0:s.response)==null?void 0:t.data)==null?void 0:d.detail]})})}}),Q=J;function X(){const[i,l]=n.useState(!0),[r,c]=n.useState([]),m=C(a=>a.setSuccessData),s=C(a=>a.setErrorData),{userData:t}=n.useContext(O),[d,y]=n.useState(""),u=n.useRef([]);n.useEffect(()=>{f()},[t]);const{fetchApiKeys:f}=V(t,l,u,y);function A(){f()}const{handleDeleteKey:j}=Q(r,A,m,s),K=B();return e.jsxs("div",{className:"flex h-full w-full flex-col justify-between gap-6",children:[e.jsx(z,{selectedRows:r,fetchApiKeys:f,userId:d}),e.jsx("div",{className:"flex h-full w-full flex-col justify-between",children:e.jsx(H,{onDelete:j,overlayNoRowsTemplate:"No data available",onSelectionChanged:a=>{c(a.api.getSelectedRows().map(g=>g.id))},rowSelection:"multiple",suppressRowClickSelection:!0,pagination:!0,columnDefs:K,rowData:u.current},"apiKeys")})]})}export{X as default};
