import{D as _,r as m,Q as C,E as N,q as v,e as o,j as e,f as l,B as p,F as A,ah as D,aA as F,S as I,n as y,o as x}from"./main-few-lands-burn.js";import{u as T}from"./useconne-CMpp5FfF.js";import{l as E}from"./useflows-BpG3C9m1.js";import{h as M,d as S}from"./index-oNbYxbiS.js";import{c as b}from"./mutative-C6xjlr6O.js";import{F as u}from"./index-D1WPCLK6.js";import{M as w}from"./index-CB2KTxNj.js";import{I as q}from"./index-DAhFlZRY.js";import{a as L}from"./utilscss-IoKwGUy7.js";import{T as $,S as j}from"./index-ubWv-fhI.js";import{D as g,P as k}from"./index-XyHDR-91.js";import{L as h}from"./index-DkD03DCM.js";import{A as P}from"./index-IEoBB6Ih.js";import"./lodash-YpNkAOPN.js";import"./useclosa-m-cf8k_D.js";import"./context-Ba3TiTex.js";import"./index-Cj8-kItB.js";import"./index-BcDJZYeX.js";import"./usebreak-DJkppNCB.js";import"./paginati-DuhDnQhP.js";function U(){const a=_(),{messageApi:s}=m.useContext(C),{isPending:c,mutateAsync:i}=N({mutationFn:async t=>v(`connections/${t}/delete`),mutationKey:["delete_connection"],onError:t=>{s?.warning(t.data)},onSuccess:({data:t})=>{a.setQueryData(["connections","all","all"],n=>n&&{...n,data:n.data.filter(({id:r})=>r!==t)})}});return{deleteConnection:i,isConnectionDeleting:c}}function B(){const a=_(),{messageApi:s}=m.useContext(C),{isPending:c,mutateAsync:i}=N({mutationFn:async({connectionId:t,connectionName:n})=>v(`connections/${t}/update`,{connection_name:n}),mutationKey:["update_connection"],onError:t=>{typeof t.data=="string"&&s?.error(t.data)},onSuccess:({data:t})=>{a.setQueryData(["connections","all","all"],n=>n&&b(n,r=>{const d=r.data.findIndex(f=>f.id===t.id);d!==-1&&(r.data[d].connection_name=t.connection_name)})),s?.success(o("Connection updated successfully"))}});return{isConnectionUpdating:c,updateConnection:i}}function O({connection:a,isOpen:s,onClose:c}){const[i]=u.useForm(),{isConnectionUpdating:t,updateConnection:n}=B();m.useEffect(()=>{s&&a&&i.setFieldsValue({connectionName:a.connection_name})},[s,a,i]);const r=async f=>{await n({connectionId:a.id,connectionName:f.connectionName}),c(),i.resetFields()},d=()=>{i.resetFields(),c()};return e(w,{destroyOnClose:!0,footer:!1,maskClosable:!1,onCancel:d,open:s,title:o("Edit Connection Name"),width:500,children:l(u,{form:i,layout:"vertical",onFinish:r,children:[e(u.Item,{label:o("Connection Name"),name:"connectionName",rules:[{message:o("Connection name is required"),required:!0},{max:255,message:o("Connection name cannot exceed 255 characters")}],children:e(q,{placeholder:o("Enter connection name")})}),e(u.Item,{className:"mb-0",children:l("div",{className:"flex justify-end gap-2",children:[e(p,{onClick:d,children:o("Cancel")}),e(p,{htmlType:"submit",loading:t,type:"primary",children:o("Update")})]})})]})})}function Q({connection:a}){const[s,c]=m.useState(!1),i=()=>{c(!0)},t=()=>{c(!1)};return l(A,{children:[e(p,{icon:e(D,{}),onClick:i,title:o("Edit connection")}),e(O,{connection:a,isOpen:s,onClose:t})]})}const R="_avatar_6vzbc_1",z={avatar:R},K=()=>({avatar:a=>L({bdr:`1px solid ${F(a,-100)}*`,bg:`${a}*`,h:"40px*",p:"6px*",w:"40px*"})}),{Text:V,Title:Y}=$;function fe(){const{connections:a,isConnectionLoading:s}=T(),{deleteConnection:c}=U(),{messageApi:i}=m.useContext(C),t=async n=>{await c(n),i?.success("Connection deleted successfully")};return l("div",{className:"p-6",children:[e(Y,{level:3,children:o("Connections")}),e(g,{className:"mt-3"}),e(h,{dataSource:a,itemLayout:"horizontal",loading:s,renderItem:n=>{const r=E(n.app_slug);return e(h.Item,{actions:[e(A,{children:l("div",{className:"space-x-2",children:[l(V,{className:"inline-flex flex-col text-right",type:"secondary",children:[e("span",{children:M(n.created_at,new Date)}),e("small",{children:S(`${y.DATE_FORMAT} | ${y.TIME_FORMAT}`,n.created_at)})]}),l("div",{className:"inline-flex w-60 justify-end space-x-2",children:[e(Q,{connection:n}),e(k,{cancelText:o("No"),description:o("Are you sure to delete this connection?"),icon:e(x,{color:"red"}),okText:o("Yes"),onConfirm:()=>t(n.id),title:o("Delete the connection"),children:e(p,{icon:e(x,{}),title:o("Delete connection")})},"delete")]})]})})],children:e(j,{active:!0,avatar:!0,loading:s,title:!1,children:e(h.Item.Meta,{avatar:e(P,{className:z.avatar,css:K().avatar(r?.color),src:r?.logoUrl}),description:l(I,{className:"text-xs",split:e(g,{type:"vertical"}),children:[e("span",{children:r?.name}),n.account_name&&e("span",{children:n.account_name})]}),title:n.connection_name})})})}})]})}export{fe as default};
