1import{r as l,_ as W,u as X,j as e}from"./vendor-react-547455f2.js";import{V as Z,D as S,B as ee,d as te,_ as se,l as re,q as ae,H as ie,N as le,A as ne}from"./vendor-ui-d9311857.js";import{a as D}from"./api-ef87b1f4.js";import"./index-fb32e9a3.js";import"./vendor-router-fe73b9f8.js";const oe=l.lazy(()=>W(()=>import("./StreamsMonitoringCharts-f40a1fc9.js"),["assets/StreamsMonitoringCharts-f40a1fc9.js","assets/vendor-react-547455f2.js","assets/CartesianChart-ff7af3c5.js","assets/vendor-ui-d9311857.js","assets/BarChart-dd36ef9a.js","assets/CartesianGrid-684b098b.js"])),L=6,ue=({radioId:h})=>{const{t:r}=X(),[i,C]=l.useState(null),[p,f]=l.useState(!0),[R,F]=l.useState(!1),[$,B]=l.useState(new Date),[k,I]=l.useState(!0),y=l.useRef(!1),m=l.useRef(!0),j=l.useRef(!1),d=l.useCallback(async()=>{if(j.current)return;const t=!y.current;j.current=!0;try{t?f(!0):F(!0);const n=await D.get(`/streams?radio_id=${h}`),c=Array.isArray(n.data)?n.data:[],M=[];for(let a=0;a<c.length;a+=L){const s=c.slice(a,a+L),b=await Promise.all(s.map(async o=>{try{const u=await D.get(`/metrics/streams/${o.id}`);return{stream:o,runtime:u.data}}catch{return{stream:o,runtime:null}}}));M.push(...b)}const N={};let x=0,A=0,_=0,v=0,E=0,w=0,U=0,T=0,P=0;const J=M.map(({stream:a,runtime:s})=>{const b=(a.protocol||"unknown").toLowerCase();N[b]=(N[b]||0)+1;const o=Math.max(0,(s==null?void 0:s.listeners)||0);A+=o,typeof(s==null?void 0:s.cpu)=="number"&&(_+=s.cpu,v+=1),typeof(s==null?void 0:s.memory)=="number"&&(E+=s.memory,w+=1),typeof(s==null?void 0:s.uptime)=="number"&&(U+=s.uptime,T+=1),typeof(s==null?void 0:s.requestsPerMinute)=="number"&&(P+=s.requestsPerMinute);const u=((s==null?void 0:s.status)||"").toLowerCase(),z=(s==null?void 0:s.encoderConnected)||u==="online"||u==="running"||o>0;return z&&(x+=1),{id:a.id,name:a.tag||`Stream ${a.id}`,protocol:a.protocol||"unknown",listeners:o,status:z?"active":"inactive"}}).sort((a,s)=>s.listeners-a.listeners),g=c.length,K=T>0?Number((U/T).toFixed(1)):g>0?Number((x/g*100).toFixed(1)):0,Q={streams:{total:g,active:x,inactive:Math.max(0,g-x),byProtocol:N},listeners:{total:A,byStream:J},performance:{uptime:K,memoryUsage:w>0?Number((E/w).toFixed(1)):0,cpuUsage:v>0?Number((_/v).toFixed(1)):0,requestsPerMinute:Math.round(P)},recentActivity:c.filter(a=>!!a.created_at).sort((a,s)=>new Date(s.created_at||0).getTime()-new Date(a.created_at||0).getTime()).slice(0,6).map((a,s)=>({id:a.id||s,type:"created",message:r("streams.monitoringTab.activity.messages.streamAvailable"),timestamp:a.created_at||new Date().toISOString(),streamName:a.tag}))};if(!m.current)return;C(Q),B(new Date),y.current=!0}catch(n){if(!m.current)return;console.error(r("streams.monitoringTab.toasts.loadError"),n),Z.error(r("streams.monitoringTab.toasts.loadError"),{id:"stream-monitoring-error"})}finally{if(j.current=!1,!m.current)return;f(!1),F(!1)}},[h,r]);l.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]),l.useEffect(()=>{y.current=!1,C(null),f(!0),d()},[h,d]),l.useEffect(()=>{if(!k)return;const t=setInterval(d,3e4);return()=>clearInterval(t)},[k,d]);const q=t=>{const n=Math.floor(t),c=Math.floor((t-n)*60);return`${n}h ${c}m`},O=t=>{switch(t){case"created":return e.jsx(ne,{className:"text-green-500",size:16});case"deleted":return e.jsx(S,{className:"text-red-500",size:16});case"error":return e.jsx(S,{className:"text-orange-500",size:16});default:return e.jsx(le,{className:"text-blue-500",size:16})}},V=t=>{switch(t){case"created":return"bg-green-100 dark:bg-green-900/20 text-green-800 dark:text-green-400";case"deleted":return"bg-red-100 dark:bg-red-900/20 text-red-800 dark:text-red-400";case"error":return"bg-orange-100 dark:bg-orange-900/20 text-orange-800 dark:text-orange-400";default:return"bg-blue-100 dark:bg-blue-900/20 text-blue-800 dark:text-blue-400"}};if(p)return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 dark:bg-gray-700 rounded w-1/4 mb-4"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6",children:[1,2,3,4].map(t=>e.jsx("div",{className:"h-32 bg-gray-200 dark:bg-gray-700 rounded-lg"},t))}),e.jsx("div",{className:"h-64 bg-gray-200 dark:bg-gray-700 rounded-lg"})]})});if(!i)return e.jsx("div",{className:"flex min-h-[420px] items-center justify-center",children:e.jsxs("div",{className:"w-full rounded-lg border border-stroke bg-white p-8 text-center dark:border-strokedark dark:bg-boxdark",children:[e.jsx(S,{className:"mx-auto mb-4 text-red-500",size:48}),e.jsx("h3",{className:"mb-2 text-lg font-semibold text-black dark:text-white",children:r("streams.monitoringTab.errors.loadTitle")}),e.jsx("p",{className:"mb-4 text-gray-600 dark:text-gray-400",children:r("streams.monitoringTab.errors.loadDescription")}),e.jsx("button",{onClick:d,className:"inline-flex items-center justify-center rounded-lg border border-blue-700/25 bg-blue-600 px-4 py-2.5 text-sm font-semibold text-white shadow-sm transition-all hover:bg-blue-700 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 dark:ring-offset-boxdark",children:r("streams.monitoringTab.actions.retry")})]})});const H=Object.entries(i.streams.byProtocol).map(([t,n])=>({name:t.toUpperCase(),value:n,color:t==="icecast"?"#3B82F6":t==="shoutcast"?"#8B5CF6":t==="webrtc"?"#10B981":"#F59E0B"})),Y=i.listeners.byStream.slice(0,8).map(t=>({name:t.name.length>16?`${t.name.slice(0,16)}â¦`:t.name,listeners:t.listeners})),G=i.streams.total>0?Math.round(i.streams.active/i.streams.total*100):0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-black dark:text-white",children:r("streams.monitoringTab.header.title")}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:r("streams.monitoringTab.header.lastUpdate",{time:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).format($)})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("input",{type:"checkbox",checked:k,onChange:t=>I(t.target.checked),className:"rounded"}),r("streams.monitoringTab.actions.autoRefresh")]}),e.jsxs("button",{onClick:d,disabled:p||R,className:"flex items-center gap-2 px-3 py-2 bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white text-sm rounded-lg transition-colors",children:[e.jsx(ee,{size:14,className:p||R?"animate-spin":""}),r("streams.monitoringTab.actions.refresh")]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsx("div",{className:"rounded-lg border border-stroke bg-white dark:border-strokedark dark:bg-boxdark p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:r("streams.monitoringTab.cards.activeStreams")}),e.jsxs("p",{className:"text-2xl font-bold text-black dark:text-white",children:[i.streams.active,"/",i.streams.total]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-500 mt-1",children:r("streams.monitoringTab.cards.activePercentage",{percent:G})})]}),e.jsx("div",{className:"p-3 bg-green-100 dark:bg-green-900/20 rounded-full",children:e.jsx(te,{className:"text-green-600 dark:text-green-400",size:24})})]})}),e.jsx("div",{className:"rounded-lg border border-stroke bg-white dark:border-strokedark dark:bg-boxdark p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:r("streams.monitoringTab.cards.totalListeners")}),e.jsx("p",{className:"text-2xl font-bold text-black dark:text-white",children:i.listeners.total.toLocaleStr
1ing()}),e.jsxs("p",{className:"text-xs text-green-600 dark:text-green-400 mt-1 flex items-center gap-1",children:[e.jsx(se,{size:12}),r("streams.monitoringTab.cards.monitoredStreams",{count:i.listeners.byStream.length})]})]}),e.jsx("div",{className:"p-3 bg-blue-100 dark:bg-blue-900/20 rounded-full",children:e.jsx(re,{className:"text-blue-600 dark:text-blue-400",size:24})})]})}),e.jsx("div",{className:"rounded-lg border border-stroke bg-white dark:border-strokedark dark:bg-boxdark p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:r("streams.monitoringTab.cards.uptime")}),e.jsxs("p",{className:"text-2xl font-bold text-black dark:text-white",children:[i.performance.uptime,"%"]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-500 mt-1",children:q(24*i.performance.uptime/100)})]}),e.jsx("div",{className:"p-3 bg-purple-100 dark:bg-purple-900/20 rounded-full",children:e.jsx(ae,{className:"text-purple-600 dark:text-purple-400",size:24})})]})}),e.jsx("div",{className:"rounded-lg border border-stroke bg-white dark:border-strokedark dark:bg-boxdark p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:r("streams.monitoringTab.cards.cpuUsage")}),e.jsxs("p",{className:"text-2xl font-bold text-black dark:text-white",children:[i.performance.cpuUsage,"%"]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-500 mt-1",children:r("streams.monitoringTab.cards.avgRam",{memory:i.performance.memoryUsage})})]}),e.jsx("div",{className:"p-3 bg-orange-100 dark:bg-orange-900/20 rounded-full",children:e.jsx(ie,{className:"text-orange-600 dark:text-orange-400",size:24})})]})})]}),e.jsx(l.Suspense,{fallback:e.jsx("div",{className:"h-[320px] animate-pulse rounded-lg bg-gray-100 dark:bg-gray-800"}),children:e.jsx(oe,{listenersByStreamData:Y,protocolData:H})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"rounded-lg border border-stroke bg-white dark:border-strokedark dark:bg-boxdark p-6",children:[e.jsx("h4",{className:"text-lg font-semibold text-black dark:text-white mb-4",children:r("streams.monitoringTab.sections.detailedStreams")}),e.jsx("div",{className:"space-y-3",children:i.listeners.byStream.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-3 h-3 rounded-full ${t.status==="active"?"bg-green-500":"bg-gray-400"}`}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-black dark:text-white",children:t.name}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 uppercase",children:t.protocol})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"font-semibold text-black dark:text-white",children:t.listeners}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-500",children:r("streams.monitoringTab.labels.listeners")})]})]},t.id))})]}),e.jsxs("div",{className:"rounded-lg border border-stroke bg-white dark:border-strokedark dark:bg-boxdark p-6",children:[e.jsx("h4",{className:"text-lg font-semibold text-black dark:text-white mb-4",children:r("streams.monitoringTab.sections.recentActivity")}),e.jsx("div",{className:"space-y-3",children:i.recentActivity.length===0?e.jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-lg text-sm text-gray-500 dark:text-gray-400",children:r("streams.monitoringTab.activity.empty")}):i.recentActivity.map(t=>e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[O(t.type),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-black dark:text-white",children:t.message}),t.streamName&&e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:r("streams.monitoringTab.labels.streamPrefix",{name:t.streamName})}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-500",children:new Date(t.timestamp).toLocaleStr
1ing()})]}),e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${V(t.type)}`,children:r(`streams.monitoringTab.activity.types.${t.type}`)})]},t.id))})]})]})]})};export{ue as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.