1import{j as e,M as E,N as P,ab as R,H as f,D as B,q as M,s as O,u as z,y as A,z as H,B as T,am as $,U as q,V as U,W as o}from"./ui-CfRm5DTA.js";import{a7 as V,a4 as F,ag as W,Z,aL as G,r as t,L as J}from"./icons-CoWim_VM.js";import{B as K}from"./breadcrumb-BPzsIiKz.js";import{a as x,A as p}from"./api-TVx_5Nik.js";import{P as Q}from"./page-header-C_yrDXSw.js";import{C as X}from"./confirm-dialog-vrDTVcTM.js";import"./index-CO7lCi65.js";function Y({integration:n,connections:c,onConnect:d,onDelete:m,onRename:r}){return e.jsx(E,{className:"py-0",children:e.jsxs(P,{className:"p-0",children:[e.jsx("div",{className:"p-6 py-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"relative h-12 w-12 shrink-0 bg-muted rounded-lg p-2",children:n.icon&&e.jsx("img",{src:n.icon,alt:n.name,width:48,height:48,className:"w-full h-full object-contain"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h3",{className:"text-lg font-semibold",children:n.name}),e.jsx(R,{variant:"secondary",children:n.plan})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[n.description,n.docs&&e.jsxs("a",{href:n.docs,target:"_blank",className:"ml-2 inline-flex items-center text-blue-600 hover:underline",children:["Learn more ",e.jsx(V,{className:"w-4 h-4 ml-1"})]})]})]})]}),e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>d(n),children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"New Connection"]})]})}),c.length>0&&e.jsx("div",{className:"divide-y border-t",children:c.map(i=>e.jsx("div",{className:"p-4 hover:bg-muted/50",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("span",{className:"font-medium",children:i.name})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"ghost",size:"sm",className:"text-destructive",onClick:()=>m(i.connection_id),children:e.jsx(W,{className:"h-4 w-4 mr-2"})}),e.jsxs(B,{modal:!1,children:[e.jsx(M,{asChild:!0,children:e.jsx(f,{variant:"ghost",size:"sm",children:e.jsx(Z,{className:"h-4 w-4"})})}),e.jsx(O,{align:"end",children:e.jsxs(z,{onClick:()=>r(i),children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),"Rename"]})})]})]})]})},i.connection_id))})]})},n.id)}function ee({isOpen:n,onClose:c,onSubmit:d,currentName:m,isSubmitting:r}){const[i,l]=t.useState(m),u=h=>{h.preventDefault(),d(i)};return e.jsx(A,{open:n,onOpenChange:c,children:e.jsxs(H,{children:[e.jsx(T,{children:e.jsx($,{children:"Rename Connection"})}),e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"name",children:"Name"}),e.jsx(U,{id:"name",value:i,onChange:h=>l(h.target.value),placeholder:"Enter connection name",required:!0})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(f,{type:"button",variant:"outline",onClick:c,children:"Cancel"}),e.jsxs(f,{type:"submit",children:[r&&e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})]})]})]})})}function oe(){const[n,c]=t.useState(!0),[d,m]=t.useState([]),[r,i]=t.useState([]),[l,u]=t.useState(null),[h,N]=t.useState(!1),[b,j]=t.useState(!1),[se,v]=t.useState(!1),[g,D]=t.useState(null),y=t.useCallback(async()=>{try{const s=await x.list(p.connections);s!=null&&s.result&&i(s.result)}catch{}},[]),w=t.useCallback(async()=>{try{const s=await x.list(p.integrations);s&&m(s.filter(a=>a.type==="oauth"))}catch{}},[]);t.useEffect(()=>{(async()=>{c(!0),await Promise.all([w(),y()]),c(!1)})()},[y,w]);const S=async s=>{try{const a=await x.list(`${p.connections}/${s.id}/connect`,{redirect_uri:window.location.href});a&&a.url?window.open(a.url,"_self"):o.error(`Unable to connect to ${s.name}. Please try again or contact support`)}catch(a){o.error(a.message)}},k=async()=>{if(g){v(!0);try{await x.delete(p.connections,g),i(r.filter(s=>s.connection_id!==g)),o.success("Connection deleted successfully"),j(!1)}catch(s){o.error(s.message)}finally{v(!1)}}},I=s=>{j(!0),D(s)},L=s=>{u(s)},_=async s=>{N(!0);try{await x.patch(p.connections,s.connection_id,{name:s.name}),i(a=>a.map(C=>C.connection_id===s.connection_id?{...C,name:s.name}:C)),o.success("Connection updated successfully"),u(null)}catch(a){o.error(a.message)}finally{N(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(K,{items:[{label:"Settings",href:"/settings"},{label:"Connections"}]}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(Q,{title:"Connections",description:"Connect with cloud storage, spreadsheet providers for automatic data transfer",link:"https://agenty.com/integrations"}),e.jsx("div",{className:"grid gap-4 grid-cols-1",children:d.map(s=>e.jsx(Y,{integration:s,onConnect:S,connections:r.filter(a=>a.type===s.id),onDelete:I,onRename:L},s.id))})]}),l&&e.jsx(ee,{isOpen:!!l,onClose:()=>u(null),onSubmit:s=>_({...l,name:s}),currentName:(l==null?void 0:l.name)||"",isSubmitting:h}),e.jsx(X,{open:b,onOpenChange:j,title:"Delete Connection",description:"Are you sure to delete this connection?",onConfirm:k,confirmLabel:"Delete",variant:"destructive"})]})}
1export{oe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.