import{ab as v,a0 as _,ad as j,r as m,j as s,L as S,x as p,af as x,B as w,ar as y,z as N,Q as k}from"./index-Dbk1Plmn.js";import{u as Q}from"./use_entities-CosQTZoS.js";import{P as I}from"./page_shell-C0CL85dt.js";import{D as A}from"./data-table-B-cqS3KC.js";import{s as B,a as E}from"./query_loading-BFETHugg.js";import{Q as F}from"./query_refresh_indicator-1_XqkpX1.js";function P(i){return v("/unsubscribe",{subscription_id:i})}function C(){const i=_();return j({mutationFn:a=>P(a),onSuccess:()=>{i.invalidateQueries({queryKey:["subscriptions"]}),i.invalidateQueries({queryKey:["entities"]}),i.invalidateQueries({queryKey:["stats"]})}})}function b(i){return i.entity_id??i.id??""}function o(i){const a=i.snapshot;return a&&typeof a=="object"?a:{}}function R(i,a){return i?a>0?"outline":"default":"destructive"}function T(){var h;const[i,a]=m.useState(null),d=C(),l=Q({entity_type:"subscription",limit:100,offset:0,sort_by:"last_observation_at",sort_order:"desc",include_snapshots:!0}),f=((h=l.data)==null?void 0:h.entities)??[],g=m.useMemo(()=>[{id:"subscription_id",header:"Subscription",accessorFn:e=>String(o(e).subscription_id??b(e)),cell:({row:e})=>{const t=o(e.original),r=String(t.subscription_id??""),n=b(e.original);return s.jsxs("div",{className:"space-y-1",children:[s.jsx(S,{to:`/entities/${encodeURIComponent(n)}`,className:"font-medium text-primary hover:underline",children:r?p(r,16):p(n,12)}),r?s.jsx("p",{className:"font-mono text-[11px] text-muted-foreground",title:r,children:r}):null]})}},{id:"delivery",header:"Delivery",accessorFn:e=>String(o(e).delivery_method??"—"),cell:({row:e})=>{const t=o(e.original);return s.jsx(x,{variant:"secondary",children:String(t.delivery_method??"—")})}},{id:"status",header:"Status",cell:({row:e})=>{const t=o(e.original),r=!!t.active,n=typeof t.consecutive_failures=="number"?t.consecutive_failures:0,c=r?n>0?"degraded":"active":"inactive";return s.jsx(x,{variant:R(r,n),children:c})}},{id:"filters",header:"Watches",cell:({row:e})=>{const t=o(e.original),r=Array.isArray(t.watch_entity_types)?t.watch_entity_types:[],n=Array.isArray(t.watch_entity_ids)?t.watch_entity_ids:[],c=Array.isArray(t.watch_event_types)?t.watch_event_types:[],u=[];return r.length&&u.push(`${r.length} type(s)`),n.length&&u.push(`${n.length} id(s)`),c.length&&u.push(`${c.length} event(s)`),s.jsx("span",{className:"text-sm text-muted-foreground",children:u.length?u.join(" · "):"—"})}},{id:"webhook",header:"Webhook / sync",cell:({row:e})=>{const t=o(e.original),r=typeof t.webhook_url=="string"?t.webhook_url:"",n=typeof t.sync_peer_id=="string"?t.sync_peer_id:"";return s.jsxs("div",{className:"max-w-[240px] space-y-1 text-xs text-muted-foreground",children:[r?s.jsx("p",{className:"truncate font-mono",title:r,children:r}):s.jsx("p",{children:"—"}),n?s.jsxs("p",{className:"truncate",title:n,children:["loop skip: ",s.jsx("span",{className:"font-mono",children:p(n,20)})]}):null]})}},{id:"failures",header:"Failures",accessorFn:e=>o(e).consecutive_failures??0,cell:({getValue:e})=>String(e())},{id:"last_delivered",header:"Last delivered",accessorFn:e=>String(o(e).last_delivered_at??"—"),cell:({getValue:e})=>s.jsx("span",{className:"text-sm",children:e()})},{id:"actions",header:"",cell:({row:e})=>{const t=o(e.original),r=String(t.subscription_id??""),n=!!t.active;return!r||!n?n?null:s.jsx("span",{className:"text-xs text-muted-foreground",children:"inactive"}):s.jsx(w,{variant:"outline",size:"sm",disabled:d.isPending&&i===r,onClick:()=>{window.confirm(`Deactivate subscription ${r}?`)&&(a(r),d.mutate(r,{onSuccess:()=>y.success("Subscription deactivated"),onError:c=>y.error(c.message),onSettled:()=>a(null)}))},children:"Unsubscribe"})}}],[i,d.isPending]);return s.jsx(I,{title:"Subscriptions",description:"Substrate event subscriptions (webhook or SSE). Secrets are redacted after creation.",actions:E(l)?s.jsx(F,{label:"Refreshing"}):void 0,children:B(l)?s.jsx(N,{}):l.error?s.jsx(k,{title:"Could not load subscriptions",children:l.error.message}):s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Rows are ",s.jsx("code",{className:"text-xs",children:"subscription"})," entities. Create subscriptions via MCP"," ",s.jsx("code",{className:"text-xs",children:"subscribe"})," or ",s.jsx("code",{className:"text-xs",children:"POST /subscribe"}),"."]}),s.jsx(A,{columns:g,data:f})]})})}export{T as default};
