import{a3 as I,a4 as N,r as v,k as f,L as y,d as A,u as E,N as V,e as n,i as r,t as o,h as e,q as m,y as H,f as D,F as _,z as u,D as T,x as B,a2 as P,o as c,a1 as z,_ as L}from"./index-D92x6h1h.js";const $={total:0,ok:0,fail:0,ignore:0,active:null};function C(i){const t=i;return{total:typeof t.total=="number"?t.total:0,ok:typeof t.ok=="number"?t.ok:0,fail:typeof t.fail=="number"?t.fail:0,ignore:typeof t.ignore=="number"?t.ignore:0,active:typeof t.active=="string"&&t.active?t.active:null}}function G(i){return i.active!==null}function O(i){return i.ok+i.fail+i.ignore}const U=I("serviceMapper",()=>{const i=v({...$}),t=v(!1),l=v(null),s=v(new Map),d=v(new Set),k=f(()=>G(i.value)),p=f(()=>O(i.value)),g=f(()=>{const a=i.value.total;return a<=0?0:Math.min(1,p.value/a)}),S=f(()=>{const a=i.value.active;return a?s.value.get(a)??null:null});async function M(){l.value=null;try{const a=await y("service/mapper/status",{});i.value=C(a)}catch(a){l.value=a instanceof Error?a.message:`Failed to load: ${String(a)}`}}function w(a){i.value=C(a),F()}async function F(){const a=i.value.active;if(a&&!s.value.has(a)&&!d.value.has(a)){d.value.add(a);try{const h=(await y("idnode/load",{uuid:a})).entries?.[0]?.text;if(typeof h=="string"&&h){const b=new Map(s.value);b.set(a,h),s.value=b}}catch{}finally{d.value.delete(a)}}}async function x(){if(!t.value){t.value=!0,l.value=null;try{await y("service/mapper/stop",{})}catch(a){l.value=a instanceof Error?a.message:`Failed to stop: ${String(a)}`}finally{t.value=!1}}}return N.on("servicemapper",w),{status:i,stopping:t,error:l,isActive:k,processed:p,progressFraction:g,activeServiceName:S,fetchInitial:M,stop:x}}),j={class:"service-mapper"},q={class:"service-mapper__card"},Y={class:"service-mapper__card-header"},J={class:"service-mapper__card-title"},K={class:"service-mapper__card-header-actions"},Q=["disabled"],R=["aria-label","aria-pressed"],W={class:"service-mapper__status-body"},X={key:0,class:"service-mapper__idle"},Z={class:"service-mapper__active"},ee={class:"service-mapper__progress"},te={class:"service-mapper__progress-track"},se={class:"service-mapper__progress-text"},ae={class:"service-mapper__counters"},re={class:"service-mapper__counter"},oe={class:"service-mapper__counter"},ie={class:"service-mapper__counter"},ne={class:"service-mapper__counter"},ce={key:2,class:"service-mapper__error"},le="status_service_mapper",pe=A({__name:"ServiceMapperView",setup(i){const{t}=E(),l=P(),s=U();function d(){l.toggle(le).catch(()=>{})}return V(()=>{s.fetchInitial().catch(()=>{})}),(k,p)=>{const g=B("tooltip");return c(),n("div",j,[r("section",q,[r("header",Y,[r("h2",J,o(e(t)("Service Mapping Status")),1),r("div",K,[e(s).isActive?(c(),n("button",{key:0,type:"button",class:"service-mapper__btn service-mapper__btn--stop",disabled:e(s).stopping,onClick:p[0]||(p[0]=S=>e(s).stop())},o(e(s).stopping?e(t)("Stopping…"):e(t)("Stop")),9,Q)):m("",!0),H((c(),n("button",{type:"button",class:"service-mapper__help","aria-label":e(t)("Help"),"aria-pressed":e(l).isOpen.value,onClick:d},[D(e(z),{size:16,"stroke-width":2})],8,R)),[[g,e(t)("Help"),void 0,{bottom:!0}]])])]),r("div",W,[e(s).isActive?(c(),n(_,{key:1},[r("p",Z,[u(o(e(t)("Mapping in progress — currently checking"))+" ",1),r("strong",null,o(e(s).activeServiceName??e(s).status.active),1)]),r("div",ee,[r("div",te,[r("div",{class:"service-mapper__progress-fill",style:T({width:(e(s).progressFraction*100).toFixed(1)+"%"})},null,4)]),r("p",se,o(e(t)("{0} / {1} processed ({2}%)",e(s).processed,e(s).status.total,Math.round(e(s).progressFraction*100))),1)])],64)):(c(),n("p",X,[r("strong",null,o(e(t)("Idle.")),1),e(s).status.total>0?(c(),n(_,{key:0},[u(o(e(t)("Last run mapped {0} of {1} services",e(s).status.ok,e(s).status.total))+" ",1),e(s).status.fail>0?(c(),n(_,{key:0},[u(o(e(t)(", {0} failed",e(s).status.fail)),1)],64)):m("",!0),e(s).status.ignore>0?(c(),n(_,{key:1},[u(o(e(t)(", {0} ignored",e(s).status.ignore)),1)],64)):m("",!0),p[1]||(p[1]=u(". ",-1))],64)):(c(),n(_,{key:1},[u(o(e(t)("Open Configuration → Channel/EPG → Channels or Configuration → DVB Inputs → Services to start mapping.")),1)],64))])),r("dl",ae,[r("div",re,[r("dt",null,o(e(t)("Mapped")),1),r("dd",null,o(e(s).status.ok),1)]),r("div",oe,[r("dt",null,o(e(t)("Failed")),1),r("dd",null,o(e(s).status.fail),1)]),r("div",ie,[r("dt",null,o(e(t)("Ignored")),1),r("dd",null,o(e(s).status.ignore),1)]),r("div",ne,[r("dt",null,o(e(t)("Total")),1),r("dd",null,o(e(s).status.total),1)])]),e(s).error?(c(),n("p",ce,o(e(s).error),1)):m("",!0)])])])}}}),ve=L(pe,[["__scopeId","data-v-733dee59"]]);export{ve as default};
