import{r as s,s as r,_ as n,j as t,B as c,S as M}from"./main-9ymbdppi.js";import{J as F,h as B,g as z,l as K,m as U,R as k,F as q,E as J}from"./index-820.js";import{b as p,S as g,T as Y,a as j,C as G}from"./api-426.js";import{C as H}from"./index-428.js";import{P as Q}from"./index-462.js";import"./index-571.js";import"./row-591.js";import"./index-546.js";import"./index-556.js";import"./index-990.js";import"./index-768.js";const{Title:V,Paragraph:W,Text:C}=Y;function X(o){switch(o){case"active":return n("Active","easylink-automations");case"error":return n("Error","easylink-automations");case"pending":return n("Pending","easylink-automations");case"inactive":return n("Inactive","easylink-automations");default:return o.charAt(0).toUpperCase()+o.slice(1)}}function le(){const[o,y]=s.useState(!0),[l,S]=s.useState([]),[w,_]=s.useState(0),[d,b]=s.useState(1),[A,h]=s.useState(!1),[N,m]=s.useState(null),[P,x]=s.useState(null),[T,v]=s.useState([]),f=s.useCallback(async()=>{var e;try{const a=await p("connections/platforms","POST");a.success&&((e=a.data)!=null&&e.platforms)&&v(a.data.platforms)}catch(a){console.error("Failed to fetch platforms:",a)}},[]),i=s.useCallback(async()=>{try{y(!0);const e=await p("connections","POST",{page:d,per_page:20});e.success&&e.data&&(S(e.data.connections||[]),_(e.data.total||0))}catch(e){console.error("Failed to fetch connections:",e),r.error(n("Failed to load connections","easylink-automations"))}finally{y(!1)}},[d]);s.useEffect(()=>{f(),i()},[f,i]);const u=e=>{m(e||null),h(!0)},L=()=>{h(!1),m(null)},E=()=>{i()},I=async e=>{x(e);try{(await p("connections/delete","POST",{connection_id:e})).success?(r.success(n("Connection deleted","easylink-automations")),i()):r.error(n("Failed to delete connection","easylink-automations"))}catch(a){console.error("Delete error:",a),r.error(n("Failed to delete connection","easylink-automations"))}finally{x(null)}},O=e=>{var a;return((a=T.find(D=>D.slug===e))==null?void 0:a.name)||e},R=[{title:n("Name","easylink-automations"),dataIndex:"name",key:"name",render:(e,a)=>t.jsxs(g,{children:[t.jsx(F,{className:"text-[#1677ff]"}),t.jsxs("div",{children:[t.jsx(C,{strong:!0,children:e}),t.jsx("br",{}),t.jsx(C,{type:"secondary",className:"text-xs",children:O(a.platform)})]})]})},{title:n("Auth Type","easylink-automations"),dataIndex:"auth_type",key:"auth_type",width:130,render:e=>t.jsx(j,{children:e==="oauth2"?n("OAuth2","easylink-automations"):e==="basic_auth"?n("Basic Auth","easylink-automations"):e==="bearer_token"?n("Bearer","easylink-automations"):n("API Key","easylink-automations")})},{title:n("Status","easylink-automations"),dataIndex:"status",key:"status",width:120,render:e=>t.jsx(j,{color:e==="active"?"success":e==="error"?"error":e==="pending"?"warning":"default",icon:e==="active"?t.jsx(B,{className:"mr-1"}):t.jsx(z,{className:"mr-1"}),children:X(e)})},{title:n("Created","easylink-automations"),dataIndex:"created_at",key:"created_at",width:160,render:e=>new Date(e).toLocaleDateString(window.EASYLINK_AUTOMATIONS_.lang.replace("_","-"))},{title:"",key:"actions",width:100,render:(e,a)=>t.jsxs(g,{children:[t.jsx(c,{type:"text",size:"small",icon:t.jsx(K,{}),onClick:()=>u(a)}),t.jsx(Q,{title:n("Delete this connection?","easylink-automations"),description:n("Automations using this connection may stop working.","easylink-automations"),onConfirm:()=>I(a.id),okText:n("Delete","easylink-automations"),cancelText:n("Cancel","easylink-automations"),okButtonProps:{danger:!0},children:t.jsx(c,{type:"text",size:"small",danger:!0,icon:t.jsx(U,{}),loading:P===a.id})})]})}];return o&&l.length===0?t.jsx("div",{className:"flex justify-center items-center min-h-[300px]",children:t.jsx(M,{size:"large"})}):t.jsxs("div",{children:[t.jsxs("div",{className:"flex justify-between items-center mb-6",children:[t.jsxs("div",{children:[t.jsx(V,{level:3,className:"!mb-1",children:n("Connections","easylink-automations")}),t.jsx(W,{type:"secondary",className:"!mb-0",children:n("Manage your third-party app connections and API credentials.","easylink-automations")})]}),t.jsx(c,{icon:t.jsx(k,{}),type:"primary",onClick:()=>u(),children:n("New Connection","easylink-automations")})]}),l.length>0?t.jsx(G,{children:t.jsx(q,{dataSource:l,columns:R,rowKey:"id",loading:o,pagination:{current:d,total:w,pageSize:20,onChange:b,showSizeChanger:!1}})}):t.jsx(J,{description:n("No connections configured. Add a connection to start integrating.","easylink-automations"),className:"mt-12",children:t.jsx(c,{type:"primary",icon:t.jsx(k,{}),onClick:()=>u(),children:n("Add Connection","easylink-automations")})}),t.jsx(H,{open:A,editingConnection:N,onClose:L,onSuccess:E})]})}export{le as default};
