import{t as B,A as D,r as t,j as e}from"./vendor-react.js";import{s as L}from"./service.js";import{c as H}from"./main.js";import{B as d}from"./button.js";import{I as k}from"./input.js";import{C as I,a as P}from"./card.js";import{S as K}from"./skeleton.js";import{T as M,a as V,b as z,c as l,d as G,e as i}from"./table.js";import{S as J,a as _,b as q,c as F,d as x}from"./select.js";import{w as O,t as Q,J as U,b as W}from"./vendor-icons.js";import"./vendor-monaco.js";import"./vendor-ui.js";function ne(){const{t:a}=B(),[f]=D(),{currentNamespace:E}=H(),[n,g]=t.useState(f.get("serviceName")||""),[v,b]=t.useState(f.get("groupName")||""),[h,u]=t.useState([]),[S,C]=t.useState(!1),[p,j]=t.useState(0),[r,c]=t.useState(1),[o,R]=t.useState(10),w=async()=>{if(n.trim()){C(!0);try{const T=(await L.listSubscribers({namespaceId:E,serviceName:n.trim(),groupName:v.trim()||void 0,pageNo:r,pageSize:o})).data;u(T.pageItems||[]),j(T.totalCount||0)}catch{u([]),j(0)}finally{C(!1)}}};t.useEffect(()=>{n.trim()&&w()},[r,o]);const N=()=>{c(1),w()},A=()=>{g(""),b(""),u([]),j(0),c(1)},y=Math.max(1,Math.ceil(p/o));return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:a("service.subscriberTitle")}),e.jsx(I,{className:"py-0",children:e.jsx(P,{className:"py-4",children:e.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:a("service.serviceName")}),e.jsx(k,{placeholder:a("service.serviceName"),value:n,onChange:s=>g(s.target.value),className:"w-[200px]",onKeyDown:s=>s.key==="Enter"&&N()})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:a("service.groupName")}),e.jsx(k,{placeholder:a("service.groupName"),value:v,onChange:s=>b(s.target.value),className:"w-[200px]",onKeyDown:s=>s.key==="Enter"&&N()})]}),e.jsxs(d,{onClick:N,className:"gap-2",children:[e.jsx(O,{className:"h-4 w-4"}),a("common.search")]}),e.jsxs(d,{variant:"outline",onClick:A,className:"gap-2",children:[e.jsx(Q,{className:"h-4 w-4"}),a("common.reset")]})]})})}),e.jsx(I,{className:"py-0",children:e.jsx(P,{className:"p-0",children:S&&h.length===0?e.jsx("div",{className:"p-6 space-y-4",children:Array.from({length:5}).map((s,m)=>e.jsx(K,{className:"h-12 w-full"},m))}):h.length===0?e.jsx("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:e.jsx("p",{className:"text-lg",children:a("common.noData")})}):e.jsxs(M,{className:S?"opacity-50 pointer-events-none":"",children:[e.jsx(V,{children:e.jsxs(z,{children:[e.jsx(l,{className:"pl-6",children:a("service.groupName")}),e.jsx(l,{children:a("service.serviceName")}),e.jsx(l,{children:a("service.subscriberName")}),e.jsx(l,{children:a("service.subscribeCount")}),e.jsx(l,{className:"pr-6",children:a("service.clusters")})]})}),e.jsx(G,{children:h.map((s,m)=>e.jsxs(z,{children:[e.jsx(i,{className:"pl-6",children:s.groupName}),e.jsx(i,{children:s.serviceName}),e.jsx(i,{className:"font-medium",children:s.subscriberName}),e.jsx(i,{children:s.subscribeCount}),e.jsx(i,{className:"pr-6",children:s.clusters||"-"})]},m))})]})})}),p>0&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:a("service.totalSubscribers",{total:p})}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:a("common.pageSize")}),e.jsxs(J,{value:o.toString(),onValueChange:s=>{R(parseInt(s,10)),c(1)},children:[e.jsx(_,{className:"w-[80px]",children:e.jsx(q,{})}),e.jsxs(F,{children:[e.jsx(x,{value:"10",children:"10"}),e.jsx(x,{value:"20",children:"20"}),e.jsx(x,{value:"50",children:"50"}),e.jsx(x,{value:"100",children:"100"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{variant:"outline",size:"sm",onClick:()=>c(r-1),disabled:r<=1,children:e.jsx(U,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-sm text-muted-foreground min-w-[80px] text-center",children:[r," / ",y]}),e.jsx(d,{variant:"outline",size:"sm",onClick:()=>c(r+1),disabled:r>=y,children:e.jsx(W,{className:"h-4 w-4"})})]})]})]})]})}export{ne as default};
