import{r as u,j as s,L as h,af as m,B as f,ar as x,z as g,Q as j}from"./index-Dbk1Plmn.js";import{u as v,a as y}from"./use_peers-N5QIk_vW.js";import{P as N}from"./page_shell-C0CL85dt.js";import{D as P}from"./data-table-B-cqS3KC.js";import{s as _,a as S}from"./query_loading-BFETHugg.js";import{Q as b}from"./query_refresh_indicator-1_XqkpX1.js";function R(a,n){return a?n>0?"outline":"default":"destructive"}function L(){var d;const[a,n]=u.useState(null),t=v(),i=y(),l=((d=t.data)==null?void 0:d.peers)??[],p=u.useMemo(()=>[{id:"name",header:"Peer",accessorFn:e=>e.peer_name,cell:({row:e})=>s.jsxs("div",{className:"space-y-1",children:[s.jsx(h,{to:`/peers/${encodeURIComponent(e.original.peer_id)}`,className:"font-medium text-primary hover:underline",children:e.original.peer_name}),s.jsx("p",{className:"font-mono text-[11px] text-muted-foreground",title:e.original.peer_id,children:e.original.peer_id})]})},{id:"url",header:"URL",accessorKey:"peer_url",cell:({getValue:e})=>s.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs block",title:String(e()),children:String(e())})},{id:"direction",header:"Direction",cell:({row:e})=>s.jsx(m,{variant:"secondary",children:e.original.direction})},{id:"types",header:"Entity types",cell:({row:e})=>{var r;return s.jsx("span",{className:"text-xs text-muted-foreground",children:((r=e.original.entity_types)==null?void 0:r.join(", "))||"—"})}},{id:"scope",header:"Scope",cell:({row:e})=>s.jsx("span",{className:"text-sm",children:e.original.sync_scope})},{id:"status",header:"Status",cell:({row:e})=>{const r=!!e.original.active,o=e.original.consecutive_failures??0,c=r?o>0?"degraded":"active":"inactive";return s.jsx(m,{variant:R(r,o),children:c})}},{id:"last_sync",header:"Last sync",cell:({row:e})=>s.jsx("span",{className:"text-sm text-muted-foreground",children:e.original.last_sync_at??"—"})},{id:"actions",header:"",cell:({row:e})=>{const r=e.original.peer_id;return!e.original.active?s.jsx("span",{className:"text-xs text-muted-foreground",children:"inactive"}):s.jsx(f,{variant:"outline",size:"sm",disabled:i.isPending&&a===r,onClick:()=>{window.confirm(`Remove peer ${e.original.peer_name} (${r})?`)&&(n(r),i.mutate(r,{onSuccess:()=>x.success("Peer removed"),onError:c=>x.error(c.message),onSettled:()=>n(null)}))},children:"Remove"})}}],[a,i.isPending]);return s.jsx(N,{title:"Peers",description:"Cross-instance Neotoma sync configuration (Phase 5). Shared secrets are never shown after creation.",actions:S(t)?s.jsx(b,{label:"Refreshing"}):void 0,children:_(t)?s.jsx(g,{}):t.error?s.jsx(j,{title:"Could not load peers",children:t.error.message}):s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Configure peers via MCP ",s.jsx("code",{className:"text-xs",children:"add_peer"})," or"," ",s.jsx("code",{className:"text-xs",children:"POST /peers"}),". Inbound sync uses"," ",s.jsx("code",{className:"text-xs",children:"POST /sync/webhook"})," with HMAC verification."]}),l.length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:"No peers configured."}):s.jsx(P,{columns:p,data:l})]})})}export{L as default};
