import{r as x,a as Ms,u as qe,L as ne,b as Fe,m as Te,O as Es,N as Rs,c as Re,B as As,R as Is,d as _,e as $s}from"./router-D9WH5XEU.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))i(a);new MutationObserver(a=>{for(const c of a)if(c.type==="childList")for(const t of c.addedNodes)t.tagName==="LINK"&&t.rel==="modulepreload"&&i(t)}).observe(document,{childList:!0,subtree:!0});function l(a){const c={};return a.integrity&&(c.integrity=a.integrity),a.referrerPolicy&&(c.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?c.credentials="include":a.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function i(a){if(a.ep)return;a.ep=!0;const c=l(a);fetch(a.href,c)}})();var ds={exports:{}},Ae={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Ts=x,Ls=Symbol.for("react.element"),Ds=Symbol.for("react.fragment"),qs=Object.prototype.hasOwnProperty,Fs=Ts.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ps={key:!0,ref:!0,__self:!0,__source:!0};function hs(s,n,l){var i,a={},c=null,t=null;l!==void 0&&(c=""+l),n.key!==void 0&&(c=""+n.key),n.ref!==void 0&&(t=n.ref);for(i in n)qs.call(n,i)&&!Ps.hasOwnProperty(i)&&(a[i]=n[i]);if(s&&s.defaultProps)for(i in n=s.defaultProps,n)a[i]===void 0&&(a[i]=n[i]);return{$$typeof:Ls,type:s,key:c,ref:t,props:a,_owner:Fs.current}}Ae.Fragment=Ds;Ae.jsx=hs;Ae.jsxs=hs;ds.exports=Ae;var e=ds.exports,us,Be=Ms;us=Be.createRoot,Be.hydrateRoot;const ms={overview:"M4 13h6V4H4zm0 7h6v-4H4zm10 0h6v-9h-6zm0-16v4h6V4z",library:"M3 5h18v14H3zM7 5v14M17 5v14M3 9.5h4M3 14.5h4M17 9.5h4M17 14.5h4",people:"M15 19v-1.2a3.3 3.3 0 0 0-3.3-3.3H6.8A3.3 3.3 0 0 0 3.5 17.8V19M9.2 11a3.2 3.2 0 1 0 0-6.4 3.2 3.2 0 0 0 0 6.4ZM17 10.6a3 3 0 0 0-1.4-5.7M20.5 19v-1.2a3.3 3.3 0 0 0-2.4-3.2",person:"M18 20v-1.5a4 4 0 0 0-4-4h-4a4 4 0 0 0-4 4V20M12 10.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Z",tv:"M4 5h16v10H4zM9 19h6M12 15v4M8 2.5 12 5l4-2.5",sliders:"M4 7h10M18 7h2M4 17h2m4 0h10M14 4v6M6 14v6",clock:"M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM12 7.2V12l3 1.8",pulse:"M3 12h3.5L9 19l5-14 2.5 7H21",chart:"M4 19V9m5 10V5m5 14v-7m5 7V3",chip:"M8 8h8v8H8zM4.5 4.5h15v15h-15zM9 2v2.5M15 2v2.5M9 19.5V22M15 19.5V22M2 9h2.5M2 15h2.5M19.5 9H22M19.5 15H22",database:"M12 8.2c4.4 0 8-1.2 8-2.6S16.4 3 12 3 4 4.2 4 5.6s3.6 2.6 8 2.6ZM4 5.6v12.8C4 19.8 7.6 21 12 21s8-1.2 8-2.6V5.6M4 12c0 1.4 3.6 2.6 8 2.6s8-1.2 8-2.6",download:"M12 3.5v10m0 0 4-4m-4 4-4-4M4.5 18h15",upload:"M12 16V4m0 0L8 8m4-4 4 4M5 13v6h14v-6",sync:"M3.5 12a8.5 8.5 0 0 1 14.6-6M20.5 12a8.5 8.5 0 0 1-14.6 6M18 2.5V6h-3.5M6 21.5V18h3.5",search:"M10.5 17a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13Zm4.6-1.9L20 20",star:"m12 3.2 2.6 5.4 5.9.8-4.3 4.1 1 5.9-5.2-2.8-5.2 2.8 1-5.9L3.5 9.4l5.9-.8L12 3.2Z",sparkle:"m10 3 1.5 4.3L16 8.8l-4.5 1.5L10 14.6 8.5 10.3 4 8.8l4.5-1.5L10 3ZM17.5 14l.9 2.4 2.6.9-2.6.9-.9 2.4-.9-2.4-2.6-.9 2.6-.9.9-2.4Z",bell:"M6.2 9.5a5.8 5.8 0 1 1 11.6 0c0 4.6 2.2 5.9 2.2 5.9H4s2.2-1.3 2.2-5.9M10 19.5a2 2 0 0 0 4 0",shield:"m12 3 7.5 3v5.4c0 5-3.2 8.2-7.5 9.6-4.3-1.4-7.5-4.6-7.5-9.6V6L12 3Zm-2.6 8.7 1.9 1.9 3.6-3.6",wrench:"m14.5 6.5 3-3 3 3-3 3M9 15l-5.5 5.5M13 4a5 5 0 0 0 6.5 6.5L10 20l-6-6 9.5-9.5Z",play:"M8 5.2v13.6L19 12 8 5.2ZM4 5v14",list:"M4 7h16M4 12h16M4 17h10",inbox:"M4 7h16v13H4zM8 4h8v3M8 12h8M8 16h5",history:"M3.5 12a8.5 8.5 0 1 0 2.8-6.3M3.5 4v4h4M12 7.5V12l3 1.8",check:"m5 12.5 4.5 4.5L19 7.5",alert:"M12 8.5v5m0 3.2h.01M10.3 4.4 2.7 17.5a2 2 0 0 0 1.7 3h15.2a2 2 0 0 0 1.7-3L13.7 4.4a2 2 0 0 0-3.4 0Z",power:"M12 3v9M7.5 6.2a7.5 7.5 0 1 0 9 0",key:"M14.5 3a6.5 6.5 0 1 0 3.4 12L19 14h2v-2h2V9.5l-2.5-2.5A6.5 6.5 0 0 0 14.5 3Zm-2.6 4.6a1.6 1.6 0 1 1-2.3 2.3 1.6 1.6 0 0 1 2.3-2.3Z",captions:"M4 5.5h16v13H4zM7 15h5m3 0h2M7 11h3m2 0h5",journey:"M4 6h5v5h6v7h5M7 3 4 6l3 3m10 6 3 3-3 3",plug:"M9 3v6M15 3v6M6.5 9h11v3.5a5.5 5.5 0 0 1-11 0zM12 18v3",calendar:"M4 6h16v15H4zM8 3v5M16 3v5M4 11h16",trash:"M4 7h16M9 7V4.5h6V7M6.5 7l1 13h9l1-13M10 11v5M14 11v5",plus:"M12 5v14M5 12h14",close:"M6 6l12 12M18 6 6 18",caret:"m6 9 6 6 6-6",external:"M14 4h6v6M20 4l-9 9M18 14v5.5H4.5V6H10",refresh:"M3.5 12a8.5 8.5 0 0 1 14.6-6M20.5 12a8.5 8.5 0 0 1-14.6 6M18 2.5V6h-3.5M6 21.5V18h3.5",filter:"M3.5 5.5h17l-6.5 7.5V20l-4-2v-5L3.5 5.5Z",menu:"M4 7h16M4 12h16M4 17h16",globe:"M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM3.5 9h17M3.5 15h17M12 3a14 14 0 0 1 0 18 14 14 0 0 1 0-18Z",logout:"M15 17l5-5-5-5M20 12H9M12 4H5v16h7"};function te({name:s,className:n}){const l=ms[s];return l?e.jsx("svg",{className:n??"ico",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",preserveAspectRatio:"xMidYMid meet","aria-hidden":"true",children:e.jsx("path",{d:l})}):null}function Ie({name:s,tone:n}){return ms[s]?e.jsx("span",{className:"glyph","data-tone":n,children:e.jsx(te,{name:s})}):null}const fe=[{id:"everyday",label:"Everyday",defaultCollapsed:!1,items:[{id:"overview",path:"/admin",label:"Overview",title:"Overview",intro:"What the gateway is doing right now.",icon:"overview"},{id:"activity",path:"/admin/activity",label:"Activity",title:"Activity",intro:"Every administrative event, newest first.",icon:"bell",badge:"notifications"},{id:"accounts",path:"/admin/accounts",label:"Users",title:"Memby users",intro:"Who uses Memby, and the devices they are signed in on.",icon:"people"},{id:"requests",path:"/admin/requests",label:"Media requests",title:"Media requests",intro:"Who can ask for something the library does not have.",icon:"inbox"},{id:"media-reports",path:"/admin/media-reports",label:"Media reports",title:"Media reports",intro:"Problems viewers reported with a film or episode.",icon:"alert"},{id:"updates",path:"/admin/updates",label:"App updates",title:"App updates",intro:"Publish an optional or a required client update.",icon:"upload"},{id:"logs",path:"/admin/logs",label:"Server logs",title:"Server logs",intro:"Structured gateway events as they happen.",icon:"list"}]},{id:"people",label:"Devices & access",defaultCollapsed:!0,items:[{id:"account",path:"/admin/accounts/:userId",label:"User",title:"User",intro:"Devices, recommendation setup and synced settings for one person.",icon:"person",hidden:!0},{id:"settings-history",path:"/admin/accounts/:userId/settings",label:"Settings history",title:"Settings history",intro:"Every change to one person's synced settings, and which devices took it.",icon:"sliders",hidden:!0},{id:"clients",path:"/admin/clients",label:"Devices",title:"Devices",intro:"Which sets have reported in, what they are running and what their build understands.",icon:"tv"},{id:"logins",path:"/admin/logins",label:"Sign-ins",title:"Sign-in history",intro:"Every connection attempt: who, which television, from where, and whether it got in.",icon:"key"},{id:"device",path:"/admin/devices/:deviceId",label:"Device",title:"Device",intro:"One television: how often it connects, at what times, and from which addresses.",icon:"tv",hidden:!0}]},{id:"content",label:"Content & discovery",defaultCollapsed:!0,items:[{id:"library",path:"/admin/library",label:"Library",title:"Library",intro:"Import and inspect the catalogue Memby ranks.",icon:"library"},{id:"hero",path:"/admin/hero",label:"Home hero",title:"Home hero",intro:"Choose films or television shows for the launcher spotlight while recent releases fill the remaining places.",icon:"star"},{id:"recommendations",path:"/admin/recommendations",label:"For You",title:"For You",intro:"The prepared pools personalised rows are drawn from.",icon:"sparkle"},{id:"ratings",path:"/admin/ratings",label:"Movie ratings",title:"Movie ratings",intro:"Optional MDBList scores on films and shows.",icon:"star"},{id:"inspector",path:"/admin/inspector",label:"Score inspector",title:"Score inspector",intro:"Re-run the ranker for one person and read every component.",icon:"search"}]},{id:"experience",label:"Viewing experience",defaultCollapsed:!0,items:[{id:"features",path:"/admin/features",label:"Features",title:"Features",intro:"Roll out, stop and recover optional behaviour with no app release.",icon:"sliders"},{id:"playback",path:"/admin/playback",label:"Playback",title:"Playback",intro:"Presentation policy sent with every playback launch.",icon:"play"},{id:"subtitles",path:"/admin/subtitles",label:"Subtitles",title:"Subtitles",intro:"Which providers a viewer may fetch a missing subtitle from.",icon:"captions"},{id:"credits",path:"/admin/credits",label:"Credits detection",title:"Credits detection",intro:"Control predictive scanning and review every completed credits scan.",icon:"clock"}]},{id:"operations",label:"Operations",defaultCollapsed:!0,items:[{id:"tasks",path:"/admin/tasks",label:"Scheduled tasks",title:"Scheduled tasks",intro:"What the gateway does in the background, when it last ran and whether it worked.",icon:"clock"},{id:"imports",path:"/admin/imports",label:"Imports",title:"Imports",intro:"Catalogue synchronisation history.",icon:"database"},{id:"maintenance",path:"/admin/maintenance",label:"Maintenance",title:"Maintenance",intro:"Take Memby offline for every television.",icon:"wrench"},{id:"integrations",path:"/admin/integrations",label:"Integrations",title:"Integrations",intro:"Send administrative events to Discord and, in time, elsewhere.",icon:"plug"}]},{id:"insights",label:"Insights",defaultCollapsed:!0,items:[{id:"views",path:"/admin/views",label:"Views",title:"App views",intro:"Home-screen visits, viewers and the times Memby is used.",icon:"overview"},{id:"searches",path:"/admin/searches",label:"Searches",title:"Searches",intro:"What the household has been looking for, and what it searched just now.",icon:"search"},{id:"journeys",path:"/admin/journeys",label:"Journeys",title:"User journeys",intro:"How viewers move through Memby, use features and complete flows.",icon:"journey"},{id:"engagement",path:"/admin/engagement",label:"Row engagement",title:"Row engagement",intro:"Impressions, focus, dwell and selections per launcher row.",icon:"chart"}]}],Os=fe.flatMap(s=>s.items),Bs=fe.flatMap(s=>s.items.filter(n=>!n.hidden).map(n=>({...n,group:s.label??""})));class Ue extends Error{constructor(n,l){super(n),this.status=l,this.name="ApiError"}}const Us=5*60*1e3;let ps=Date.now();for(const s of["pointerdown","pointermove","keydown","wheel","scroll"])window.addEventListener(s,()=>{ps=Date.now()},{passive:!0});const Vs=()=>Date.now()-ps({}));throw new Ue(i.error??`Request failed (${l.status})`,l.status)}if(l.status!==204)return await l.json()}function Se(s){const n=new URLSearchParams;for(const[i,a]of Object.entries(s))a==null||a===""||a===!1||n.set(i,String(a));const l=n.toString();return l?`?${l}`:""}const F={get:s=>Ce(s),post:(s,n)=>Ce(s,{method:"POST",body:n===void 0?void 0:JSON.stringify(n)}),put:(s,n)=>Ce(s,{method:"PUT",body:n===void 0?void 0:JSON.stringify(n)}),del:s=>Ce(s,{method:"DELETE"})},Ws=3e4,xs=x.createContext(null);function zs({children:s}){var u;const[n,l]=x.useState(),[i,a]=x.useState(!1),[c,t]=x.useState(""),[o,d]=x.useState(""),[r,j]=x.useState(!0),w=x.useRef(0),p=x.useCallback(async()=>{const v=++w.current;try{const b=await F.get("/admin/api/status");if(v!==w.current)return;l(b),a(!0),d("")}catch(b){if(v!==w.current)return;a(!1),d(b instanceof Error?b.message:String(b))}finally{v===w.current&&(t(new Date().toISOString()),j(!1))}},[]),m=x.useCallback(async v=>{var b;await F.post("/admin/api/maintenance",{enabled:v,message:((b=n==null?void 0:n.maintenance)==null?void 0:b.message)??""}),await p()},[p,(u=n==null?void 0:n.maintenance)==null?void 0:u.message]);x.useEffect(()=>{p();let v;const b=()=>{window.clearInterval(v),v=document.hidden?void 0:window.setInterval(()=>void p(),Ws)},S=()=>{b(),document.hidden||p()};return b(),document.addEventListener("visibilitychange",S),()=>{window.clearInterval(v),document.removeEventListener("visibilitychange",S)}},[p]);const f=x.useMemo(()=>{var v;return{status:n,version:(n==null?void 0:n.serverVersion)??"",currentUser:((v=n==null?void 0:n.currentUser)==null?void 0:v.trim())||"Administrator",online:i,checkedAt:c,error:o,loading:r,reload:p,setMaintenance:m}},[n,i,c,o,r,p,m]);return e.jsx(xs.Provider,{value:f,children:s})}function ie(){const s=x.useContext(xs);if(!s)throw new Error("useGateway used outside GatewayProvider");return s}function Hs(s,n){const l=s.label.toLowerCase(),i=s.group.toLowerCase();return l.startsWith(n)?4:l.includes(n)?3:i.includes(n)?2:`${s.title} ${s.intro}`.toLowerCase().includes(n)?1:0}function Ks(){const s=qe(),{status:n}=ie(),[l,i]=x.useState(!1),[a,c]=x.useState(""),[t,o]=x.useState(0),d=x.useRef(null),r=x.useRef(null),j=x.useMemo(()=>{const p=a.trim().toLowerCase();return[...Bs,...((n==null?void 0:n.requestUsers)??[]).map(f=>({id:`user-${f.id}`,path:`/admin/accounts/${encodeURIComponent(f.id)}`,label:f.username||"Unnamed user",title:`User: ${f.username||"Unnamed user"}`,intro:"Open this user’s devices and settings.",group:"Users",icon:"people"})),...((n==null?void 0:n.clients)??[]).map(f=>({id:`device-${f.deviceId}`,path:`/admin/devices/${encodeURIComponent(f.deviceId)}`,label:f.deviceName||"Unnamed device",title:`Device: ${f.deviceName||"Unnamed device"}`,intro:`${f.username||"Unknown user"} · ${f.version||"unknown version"}`,group:"Devices",icon:"tv"}))].map((f,u)=>({item:f,rank:p?Hs(f,p):1,index:u})).filter(f=>f.rank>0).sort((f,u)=>u.rank-f.rank||f.index-u.index).map(({item:f,rank:u})=>({item:f,rank:u}))},[a,n]);x.useEffect(()=>o(0),[a]),x.useEffect(()=>{const p=m=>{var f;(f=d.current)!=null&&f.contains(m.target)||i(!1)};return document.addEventListener("pointerdown",p),()=>document.removeEventListener("pointerdown",p)},[]),x.useEffect(()=>{const p=m=>{var u,v;if(m.key!=="S"||!m.shiftKey||m.ctrlKey||m.metaKey||m.altKey)return;const f=document.activeElement;f&&(f.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(f.tagName))||(m.preventDefault(),(u=r.current)==null||u.focus(),(v=r.current)==null||v.select())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[]);const w=p=>{var m;i(!1),c(""),(m=r.current)==null||m.blur(),s(p)};return e.jsxs("div",{className:"omni",ref:d,"data-open":l||void 0,children:[e.jsxs("div",{className:"omni-input",children:[e.jsx(te,{name:"search"}),e.jsx("input",{ref:r,type:"search",value:a,placeholder:"Search pages, users and devices…","aria-label":"Search pages, users and devices","aria-expanded":l,onFocus:()=>i(!0),onChange:p=>{c(p.target.value),i(!0)},onKeyDown:p=>{var m;if(p.key==="Escape")c(""),i(!1),(m=r.current)==null||m.blur();else if(p.key==="ArrowDown")p.preventDefault(),o(f=>Math.min(f+1,j.length-1));else if(p.key==="ArrowUp")p.preventDefault(),o(f=>Math.max(f-1,0));else if(p.key==="Enter"){const f=j[t];if(!f)return;p.preventDefault(),w(f.item.path)}}}),e.jsx("span",{className:"omni-key",children:"⇧S"})]}),l?e.jsx("div",{className:"omni-panel",role:"listbox",children:j.length===0?e.jsx("p",{className:"empty",children:"No pages, users or devices match that search."}):j.map((p,m)=>e.jsxs("a",{className:m===t?"omni-item on":"omni-item",href:p.item.path,role:"option","aria-selected":m===t,onPointerEnter:()=>o(m),onClick:f=>{f.preventDefault(),w(p.item.path)},children:[p.item.icon?e.jsx(te,{name:p.item.icon}):null,e.jsxs("span",{children:[e.jsx("b",{children:p.item.label}),e.jsx("small",{children:p.item.intro})]}),e.jsx("span",{className:"omni-group",children:p.item.group})]},p.item.id))}):null]})}const N=s=>(s??0).toLocaleString(),O=s=>s?new Date(s).toLocaleString():"—";function be(s){if(!s)return"0s";if(s<1e3)return`${Math.round(s)}ms`;const n=Math.round(s/1e3);if(n<60)return`${n}s`;const l=Math.floor(n/60);return l<60?`${l}m ${n%60}s`:`${Math.floor(l/60)}h ${l%60}m`}function Le(s){if(!s||s<=0)return"on request only";if(s<60)return`every ${s}s`;const n=Math.round(s/60);if(n<60)return`every ${n} min`;const l=Math.round(n/60);return l<48?l===1?"hourly":`every ${l} hours`:`every ${Math.round(l/24)} days`}function ye(s){const n=["B","KB","MB","GB"];let l=Number(s??0),i=0;for(;l>=1024&&iString(s??"?").trim().split(/\s+/).slice(0,2).map(n=>n[0]??"").join("").toUpperCase(),Me=s=>`${Math.round((s??0)*100)}%`;function pe(s){if(!s)return"—";const n=Date.now()-new Date(s).getTime();if(n<0)return"just now";const l=Math.floor(n/1e3);if(l<45)return"just now";const i=Math.floor(l/60);if(i<60)return`${i} min ago`;const a=Math.floor(i/60);if(a<24)return`${a}h ago`;const c=Math.floor(a/24);return c<30?`${c}d ago`:new Date(s).toLocaleDateString()}const vs=15*60*1e3,Gs=3*60*60*1e3,Ne=s=>!!s&&Date.now()-new Date(s).getTime(){var b;try{const S=await F.get(`/admin/api/notifications?limit=${_e}`);l(S.events),a(S.unread),t(S.types),w.current=Math.max(w.current,((b=S.events[0])==null?void 0:b.id)??0),j("")}catch(S){j(S instanceof Error?S.message:String(S))}},[]),m=x.useCallback(b=>{w.current=Math.max(w.current,b.id),l(S=>S.some(h=>h.id===b.id)?S:[b,...S].sort((h,g)=>g.id-h.id).slice(0,_e)),b.readAt||a(S=>S+1),t(S=>S.some(h=>h.type===b.type)?S.map(h=>h.type===b.type?{...h,count:h.count+1}:h):[...S,{type:b.type,count:1}])},[]);x.useEffect(()=>{p()},[p]),x.useEffect(()=>{let b=null,S,h=!1;return(()=>{h||(b=new EventSource(`/admin/api/notifications/stream?after=${w.current}`),b.addEventListener("open",()=>{d(!0),window.clearInterval(S),S=void 0}),b.addEventListener("admin",E=>{try{m(JSON.parse(E.data))}catch{}}),b.addEventListener("error",()=>{d(!1),S===void 0&&(S=window.setInterval(()=>void p(),Zs))}))})(),()=>{h=!0,b==null||b.close(),window.clearInterval(S)}},[m,p]);const f=x.useCallback(async b=>{const S=b.filter(h=>h>0);if(S.length!==0){l(h=>h.map(g=>S.includes(g.id)&&!g.readAt?{...g,readAt:new Date().toISOString()}:g));try{const h=await F.post("/admin/api/notifications/read",{ids:S});a(h.unread)}catch{p()}}},[p]),u=x.useCallback(async()=>{a(0),l(b=>b.map(S=>S.readAt?S:{...S,readAt:new Date().toISOString()}));try{const b=await F.post("/admin/api/notifications/read",{all:!0});a(b.unread)}catch{p()}},[p]),v=x.useMemo(()=>({events:n,unread:i,types:c,connected:o,error:r,markRead:f,markAllRead:u,reload:p}),[n,i,c,o,r,f,u,p]);return e.jsx(bs.Provider,{value:v,children:s})}function Oe(){const s=x.useContext(bs);if(!s)throw new Error("useNotifications used outside NotificationProvider");return s}function fs(s){return s.severity==="error"?"bad":s.severity==="warning"?"warn":"info"}function gs(s){return s.startsWith("auth.")?"key":s.startsWith("device.")?"tv":s.startsWith("admin.")?"shield":s.startsWith("task.")?"clock":s.startsWith("integration.")?"plug":s.startsWith("library.")?"library":s.startsWith("emby.")?"globe":s.startsWith("server.")?"power":"bell"}function We(s){return{"auth.login":"Signed in","auth.login_failed":"Sign-in refused","auth.logout":"Signed out","device.registered":"New device","device.removed":"Device removed","device.renamed":"Device renamed","admin.sign_in":"Admin sign-in","server.started":"Server started","server.maintenance":"Maintenance","task.completed":"Task finished","task.failed":"Task failed","integration.failed":"Integration failed","integration.test":"Integration test","library.sync":"Library sync","emby.unreachable":"Emby unreachable","emby.recovered":"Emby recovered"}[s]??s.replace(/[._]/g," ")}const ze=99;function Ys(){const{events:s,unread:n,connected:l,markRead:i,markAllRead:a}=Oe(),[c,t]=x.useState(!1),o=x.useRef(null);return x.useEffect(()=>{const d=j=>{var w;(w=o.current)!=null&&w.contains(j.target)||t(!1)},r=j=>{j.key==="Escape"&&t(!1)};return document.addEventListener("pointerdown",d),document.addEventListener("keydown",r),()=>{document.removeEventListener("pointerdown",d),document.removeEventListener("keydown",r)}},[]),x.useEffect(()=>{if(!c)return;const d=s.filter(r=>!r.readAt).map(r=>r.id);d.length>0&&i(d)},[c]),e.jsxs("div",{className:"bell",ref:o,"data-open":c||void 0,children:[e.jsxs("button",{type:"button",className:"bell-button","aria-label":n>0?`Activity, ${n} unread`:"Activity","aria-expanded":c,onClick:()=>t(d=>!d),children:[e.jsx(te,{name:"bell"}),n>0?e.jsx("span",{className:"bell-badge",children:n>ze?`${ze}+`:n}):null]}),c?e.jsxs("div",{className:"bell-panel",children:[e.jsxs("div",{className:"bell-head",children:[e.jsx("b",{children:"Activity"}),e.jsxs("div",{className:"row tight",children:[l?null:e.jsx("span",{className:"tag","data-tone":"warn",children:"reconnecting"}),n>0?e.jsx("button",{type:"button","data-variant":"quiet","data-size":"sm",onClick:()=>void a(),children:"Mark all read"}):null]})]}),e.jsx("div",{className:"bell-list",children:s.length===0?e.jsx("p",{className:"empty",children:"Nothing has happened yet."}):s.slice(0,20).map(d=>{const r=e.jsxs(e.Fragment,{children:[e.jsx(Ie,{name:gs(d.type),tone:fs(d)}),e.jsxs("span",{className:"bell-body",children:[e.jsx("b",{children:d.title||d.type}),d.summary?e.jsx("p",{children:d.summary}):null,e.jsx("time",{dateTime:d.occurredAt,children:pe(d.occurredAt)})]})]});return d.link?e.jsx(ne,{className:"bell-item","data-unread":!d.readAt||void 0,to:d.link,onClick:()=>t(!1),children:r},d.id):e.jsx("div",{className:"bell-item","data-unread":!d.readAt||void 0,children:r},d.id)})}),e.jsx("div",{className:"bell-foot",children:e.jsx(ne,{to:"/admin/activity",onClick:()=>t(!1),children:"All activity"})})]}):null]})}function U({title:s,intro:n,actions:l,crumbs:i,icon:a}){var o;const c=Fe(),t=a??((o=Os.find(d=>Te({path:d.path,end:!0},c.pathname)))==null?void 0:o.icon);return e.jsxs("header",{className:"page-head",children:[i?e.jsx("nav",{className:"crumbs",children:i}):null,e.jsxs("div",{className:"page-head-row",children:[e.jsxs("div",{className:"page-head-title",children:[t?e.jsx("span",{className:"page-head-icon","aria-hidden":"true",children:e.jsx(te,{name:t})}):null,e.jsxs("div",{className:"page-head-text",children:[e.jsx("h1",{children:s}),n?e.jsx("p",{children:n}):null]})]}),l?e.jsx("div",{className:"page-head-actions",children:l}):null]})]})}function A({title:s,intro:n,icon:l,tone:i,actions:a,footer:c,children:t}){return e.jsxs("section",{className:"card",children:[s?e.jsxs("div",{className:"card-head",children:[l?e.jsx(Ie,{name:l,tone:i}):null,e.jsxs("div",{className:"card-head-text",children:[e.jsx("h2",{children:s}),n?e.jsx("p",{children:n}):null]}),a?e.jsx("div",{className:"card-head-actions",children:a}):null]}):null,t,c?e.jsx("div",{className:"card-foot",children:c}):null]})}function oe({cols:s,children:n}){return e.jsx("div",{className:"grid","data-cols":s,children:n})}function ae({tiles:s}){return e.jsx("div",{className:"tiles",children:s.map(n=>e.jsxs("div",{className:"tile",children:[n.icon?e.jsx(Ie,{name:n.icon,tone:n.tone}):null,e.jsx("b",{className:n.small?"small":void 0,children:n.value}),e.jsx("span",{children:n.label})]},n.label))})}function M({children:s,tone:n}){return e.jsx("span",{className:"tag","data-tone":n,children:s})}function se({children:s,tone:n}){return e.jsx("span",{className:"chip","data-tone":n,children:s})}function Z({children:s}){return e.jsx("p",{className:"empty",children:s})}function X({columns:s,children:n}){return e.jsx("tr",{children:e.jsx("td",{colSpan:s,className:"muted",children:e.jsx("p",{className:"empty",children:n})})})}function ue({children:s,tone:n}){return e.jsx("p",{className:"note","data-tone":n,children:s})}function R({children:s,onClick:n,variant:l,size:i,disabled:a,busy:c,icon:t,type:o="button",title:d}){return e.jsxs("button",{type:o,className:"","data-variant":l,"data-size":i,disabled:a||c,onClick:n,title:d,children:[c?e.jsx("span",{className:"spinner"}):t?e.jsx(te,{name:t}):null,s]})}function D({label:s,hint:n,children:l,grow:i}){return e.jsxs("label",{className:i?"field grow":"field",children:[e.jsx("span",{children:s}),l,n?e.jsx("small",{children:n}):null]})}function z({label:s,hint:n,checked:l,onChange:i,disabled:a}){return e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:l,disabled:a,onChange:c=>i(c.target.checked)}),e.jsx("span",{className:"switch"}),e.jsxs("span",{className:"check-body",children:[e.jsx("b",{children:s}),n?e.jsx("p",{children:n}):null]})]})}function Ee({value:s,options:n,onChange:l}){return e.jsx("div",{className:"segments",role:"group",children:n.map(i=>e.jsx("button",{type:"button","aria-pressed":i.value===s,onClick:()=>l(i.value),children:i.label},String(i.value)))})}function G({children:s}){return e.jsx("div",{className:"table-wrap",children:s})}function ys({data:s,labelOf:n,valueOf:l,toneOf:i,title:a}){if(s.length===0)return e.jsx(Z,{children:"Nothing in this window."});const c=s.map(o=>l(o)),t=Math.max(1,...c);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bars",children:s.map((o,d)=>{const r=l(o);return e.jsx("div",{className:"bar","data-tone":i==null?void 0:i(o),"data-empty":r===0||void 0,style:{height:`${Math.max(2,r/t*100)}%`},title:a?a(o):`${n(o,d)}: ${r}`},d)})}),e.jsxs("div",{className:"bars-axis",children:[e.jsx("span",{children:n(s[0],0)}),e.jsx("span",{children:n(s[s.length-1],s.length-1)})]})]})}function Xs({value:s,total:n,tone:l}){const i=n>0?Math.min(1,s/n):0;return e.jsx("div",{className:"meter","data-tone":l,children:e.jsx("div",{style:{width:`${i*100}%`}})})}function B({message:s,onDismiss:n}){return s?e.jsxs("div",{className:"banner",role:"alert",children:[e.jsx(te,{name:"alert"}),e.jsx("span",{children:s}),n?e.jsx("button",{type:"button",onClick:n,"aria-label":"Dismiss",children:e.jsx(te,{name:"close"})}):null]}):null}function W({rows:s=3}){return e.jsxs("div",{className:"loading-page","aria-busy":"true","aria-label":"Loading",children:[e.jsxs("div",{className:"loading-heading",children:[e.jsx("span",{className:"skeleton"}),e.jsx("span",{className:"skeleton"})]}),e.jsx("div",{className:"loading-tiles",children:Array.from({length:4},(n,l)=>e.jsx("span",{className:"skeleton"},l))}),Array.from({length:s},(n,l)=>e.jsxs("section",{className:"loading-card",children:[e.jsx("span",{className:"skeleton"}),e.jsx("span",{className:"skeleton"}),e.jsx("span",{className:"skeleton"})]},l))]})}function he({title:s,body:n,confirmLabel:l="Confirm",destructive:i,busy:a,onConfirm:c,onCancel:t}){const o=x.useId(),d=x.useRef(null);return x.useEffect(()=>{var j;(j=d.current)==null||j.focus();const r=w=>{w.key==="Escape"&&t()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[t]),e.jsx("div",{className:"scrim",onPointerDown:r=>r.target===r.currentTarget&&t(),children:e.jsxs("div",{className:"dialog",role:"dialog","aria-modal":"true","aria-labelledby":o,ref:d,tabIndex:-1,children:[e.jsx("h2",{id:o,children:s}),e.jsx("p",{children:n}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx(R,{onClick:t,variant:"quiet",children:"Cancel"}),e.jsx(R,{onClick:c,variant:i?"danger":"primary",busy:a,children:l})]})]})})}function He({rows:s}){return e.jsx("div",{className:"kv",children:s.map(n=>e.jsxs("div",{className:"kv-row",children:[e.jsx("span",{children:n.label}),e.jsx("span",{children:n.value})]},n.label))})}function ws({tiles:s}){return e.jsx("div",{className:"tiles plain",children:s.map(n=>e.jsxs("div",{className:"tile",children:[e.jsx("b",{className:n.small?"small":void 0,children:n.value}),e.jsx("span",{children:n.label})]},n.label))})}function Qs({open:s,onNavigate:n}){const{unread:l}=Oe(),i=Fe(),[a,c]=x.useState(()=>{try{return JSON.parse(localStorage.getItem("memby-admin-nav")??"{}")}catch{return{}}}),t=d=>{try{localStorage.setItem("memby-admin-nav",JSON.stringify(d))}catch{}};x.useEffect(()=>{const d=fe.find(r=>r.items.some(j=>Te({path:j.path,end:!0},i.pathname)));d&&c(r=>{const j={...r};return fe.forEach(w=>{w.collapsible!==!1&&(j[w.id]=w.id!==d.id)}),t(j),j})},[i.pathname]);const o=(d,r=!1)=>{c(j=>{const w={...j},p=!(j[d]??r);return fe.forEach(m=>{m.collapsible!==!1&&(w[m.id]=m.id===d?p:!0)}),t(w),w})};return e.jsx("nav",{className:"rail",id:"rail","data-open":s||void 0,"aria-label":"Console sections",children:fe.map(d=>{const r=d.items.filter(m=>!m.hidden);if(r.length===0)return null;const j=r.some(m=>Te({path:m.path,end:!0},i.pathname)),w=d.collapsible!==!1,p=j||!w||!(a[d.id]??d.defaultCollapsed??!1);return e.jsxs("div",{className:"rail-group",children:[d.label&&w?e.jsxs("button",{type:"button",className:"rail-head","aria-expanded":p,onClick:()=>o(d.id,d.defaultCollapsed),children:[d.label,e.jsx(te,{name:"caret",className:"ico caret"})]}):d.label?e.jsx("div",{className:"rail-head rail-head-static",children:d.label}):null,p?r.map(m=>e.jsx(Rs,{to:m.path,end:m.path==="/admin",onClick:n,className:({isActive:f})=>f?"on":"","aria-current":void 0,children:({isActive:f})=>e.jsxs("span",{style:{display:"contents"},ref:u=>{const v=u==null?void 0:u.parentElement;v&&(f?v.setAttribute("aria-current","page"):v.removeAttribute("aria-current"))},children:[m.icon?e.jsx(te,{name:m.icon}):null,m.label,m.badge==="notifications"&&l>0?e.jsx("span",{className:"rail-badge",children:l>99?"99+":l}):null]})},m.id)):null]},d.id)})})}function en(){var g,E;const{version:s,currentUser:n,online:l,loading:i,status:a,setMaintenance:c}=ie(),[t,o]=x.useState(!1),[d,r]=x.useState(!1),[j,w]=x.useState(!1),[p,m]=x.useState(!1),f=Fe(),u=!!((g=a==null?void 0:a.maintenance)!=null&&g.enabled),v=x.useRef(null),b=((E=Array.from(n.trim())[0])==null?void 0:E.toLocaleUpperCase("en-NZ"))||"A",S=a&&l&&!u?"ok":a||!i?"bad":"checking",h=async()=>{if(!(j||!a)){w(!0);try{await c(!u)}finally{w(!1)}}};return x.useEffect(()=>o(!1),[f.pathname]),x.useEffect(()=>{if(!d)return;const C=y=>{var L;(L=v.current)!=null&&L.contains(y.target)||r(!1)},V=y=>{y.key==="Escape"&&r(!1)};return document.addEventListener("mousedown",C),window.addEventListener("keydown",V),()=>{document.removeEventListener("mousedown",C),window.removeEventListener("keydown",V)}},[d]),x.useEffect(()=>{if(!t)return;const C=document.body.style.overflow;document.body.style.overflow="hidden";const V=y=>{y.key==="Escape"&&o(!1)};return window.addEventListener("keydown",V),()=>{document.body.style.overflow=C,window.removeEventListener("keydown",V)}},[t]),e.jsxs(e.Fragment,{children:[e.jsx("a",{className:"skip",href:"#main",children:"Skip to content"}),e.jsxs("header",{className:"topbar",children:[e.jsxs("a",{className:"topbar-brand",href:"/admin",children:[e.jsx("span",{className:"brand-mark","aria-hidden":"true",children:"M"}),e.jsx("span",{className:"brand-word",children:"Memby Gateway"})]}),e.jsx("button",{type:"button",className:"rail-toggle","aria-label":"Sections","aria-expanded":t,"aria-controls":"rail",onClick:()=>o(C=>!C),children:e.jsx(te,{name:"menu"})}),e.jsx("div",{className:"topbar-spacer"}),e.jsxs("div",{className:"topbar-tools",children:[e.jsx(Ks,{}),e.jsxs("span",{className:"topbar-version",children:["gateway ",s||"unknown"]}),e.jsx("button",{type:"button",className:"topbar-status","data-tone":S,"aria-pressed":u,disabled:!a||!l||j,title:a?u?"Bring Memby back online":l?"Take Memby offline":"Memby is not responding":"Checking Memby status","aria-label":u?"Memby is offline. Bring it online":a&&l?"Memby is online. Take it offline":i?"Checking Memby status":"Memby is not responding",onClick:()=>u?void h():m(!0),children:e.jsx("span",{className:"dot","aria-hidden":"true"})}),e.jsx(Ys,{}),e.jsxs("div",{className:"account-menu","data-open":d||void 0,ref:v,children:[e.jsxs("button",{type:"button",className:"account-trigger","aria-haspopup":"menu","aria-expanded":d,"aria-label":`Signed in as ${n}`,onClick:()=>r(C=>!C),children:[e.jsx("span",{className:"account-avatar","aria-hidden":"true",children:b}),e.jsx("span",{className:"account-name",children:n}),e.jsx(te,{name:"caret",className:"ico account-caret"})]}),d?e.jsxs("div",{className:"account-panel",role:"menu",children:[e.jsxs("div",{className:"account-identity",children:[e.jsx("span",{className:"account-avatar account-avatar-large","aria-hidden":"true",children:b}),e.jsxs("span",{children:[e.jsx("small",{children:"Signed in as"}),e.jsx("b",{children:n})]})]}),e.jsx("form",{method:"post",action:"/admin/logout",children:e.jsxs("button",{type:"submit",role:"menuitem",children:[e.jsx(te,{name:"logout"}),"Log out"]})})]}):null]})]})]}),t?e.jsx("button",{type:"button",className:"rail-scrim","aria-label":"Close sections",onClick:()=>o(!1)}):null,e.jsx(Qs,{open:t,onNavigate:()=>o(!1)}),e.jsx("main",{className:"page",id:"main",children:e.jsx(Es,{})}),p?e.jsx(he,{title:"Take Memby offline?",body:"Every television will stop working immediately. Viewers will see the maintenance message configured on the Maintenance page, while this console remains available.",confirmLabel:"Go offline",destructive:!0,busy:j,onConfirm:()=>{m(!1),h()},onCancel:()=>m(!1)}):null]})}const ks=x.createContext(null),sn=5e3;function nn({children:s}){const[n,l]=x.useState([]),i=x.useRef(1),a=x.useCallback(d=>{l(r=>r.filter(j=>j.id!==d))},[]),c=x.useCallback((d,r="ok")=>{const j=i.current++;l(w=>[...w,{id:j,message:d,tone:r}]),window.setTimeout(()=>a(j),sn)},[a]),t=x.useCallback(async(d,r)=>{try{const j=await d();return r&&c(r,"ok"),j}catch(j){c(j instanceof Error?j.message:String(j),"bad");return}},[c]),o=x.useMemo(()=>({show:c,wrap:t}),[c,t]);return e.jsxs(ks.Provider,{value:o,children:[s,e.jsx("div",{className:"toasts",role:"status","aria-live":"polite",children:n.map(d=>e.jsxs("div",{className:"toast","data-tone":d.tone,children:[e.jsx(te,{name:d.tone==="bad"?"alert":"check"}),e.jsx("span",{children:d.message}),e.jsx("button",{type:"button",onClick:()=>a(d.id),"aria-label":"Dismiss",children:e.jsx(te,{name:"close"})})]},d.id))})]})}function Q(){const s=x.useContext(ks);if(!s)throw new Error("useToast used outside ToastProvider");return s}function J(s,n={}){const{pollMs:l,enabled:i=!0}=n,[a,c]=x.useState(),[t,o]=x.useState(""),[d,r]=x.useState(i),[j,w]=x.useState(!1),p=x.useRef(0),m=x.useRef(!1),f=x.useCallback(async()=>{if(!i)return;const u=++p.current;m.current&&w(!0);try{const v=await F.get(s);if(u!==p.current)return;c(v),o(""),m.current=!0}catch(v){if(u!==p.current)return;o(v instanceof Error?v.message:String(v))}finally{u===p.current&&(r(!1),w(!1))}},[s,i]);return x.useEffect(()=>(m.current=!1,r(!0),f(),()=>{p.current+=1}),[f]),x.useEffect(()=>{if(!l||!i)return;let u;const v=()=>{window.clearInterval(u),u=document.hidden?void 0:window.setInterval(()=>void f(),l)},b=()=>{v(),document.hidden||f()};return v(),document.addEventListener("visibilitychange",b),()=>{window.clearInterval(u),document.removeEventListener("visibilitychange",b)}},[l,i,f]),{data:a,error:t,loading:d,refreshing:j,reload:f,set:c}}function Y(){const[s,n]=x.useState(null),l=x.useRef(!0);x.useEffect(()=>()=>{l.current=!1},[]);const i=x.useCallback(async(a,c)=>{n(a);try{return await c(),!0}finally{l.current&&n(null)}},[]);return{busy:s,run:i}}function tn(){var v,b,S,h,g;const{status:s,error:n,loading:l}=ie(),i=J("/admin/api/runtime",{pollMs:3e4}),a=J("/admin/api/views",{pollMs:6e4});if(l||!s)return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Overview",intro:"What the gateway is doing right now."}),e.jsx(B,{message:n}),e.jsx(W,{})]});const c=s.features??{features:[],revision:0,safeMode:!1},t=c.features??[],o=s.clients??[],d=o.filter(E=>Ne(E.lastSeen)).length,r=s.updatePolicy??{},j=!!r.minimumVersion&&r.minimumVersion===r.latestVersion,w=s.playbackPolicy,p=s.mdblist,m=s.forYou,f=(s.runs??[]).slice(0,5),u=i.data;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Overview",intro:"What the gateway is doing right now."}),e.jsx(B,{message:n}),e.jsx(ae,{tiles:[{label:"items in the library",value:N(s.library.total),icon:"library",tone:"data"},{label:"people signed in",value:N((s.requestUsers??[]).length),icon:"people",tone:"note"},{label:`devices · ${d} active now`,value:N(o.length),icon:"tv",tone:"info"},{label:`visits today · ${((v=a.data)==null?void 0:v.lastWeek.visits)??0} this time last week`,value:N((b=a.data)==null?void 0:b.today.visits),icon:"overview",tone:"data"},{label:`viewers today · ${((S=a.data)==null?void 0:S.lastWeek.viewers)??0} this time last week`,value:N((h=a.data)==null?void 0:h.today.viewers),icon:"people",tone:"note"},{label:"optional features on",value:`${t.filter(E=>E.enabled).length} / ${t.length}`,icon:"sliders",tone:"ok"},{label:"last import",value:O(s.library.lastSynced),small:!0,icon:"clock"}]}),e.jsxs(oe,{cols:"2",children:[e.jsx(A,{title:"What televisions are being told",intro:"The answers the gateway is giving every set right now.",icon:"tv",tone:"info",children:e.jsx(He,{rows:[{label:"Availability",value:(g=s.maintenance)!=null&&g.enabled?e.jsx(M,{tone:"bad",children:"offline for maintenance"}):e.jsx(M,{tone:"ok",children:"online"})},{label:"Feature control plane",value:c.safeMode?e.jsx(M,{tone:"warn",children:"safe mode · optional features off"}):e.jsxs(M,{tone:"ok",children:["revision r",N(c.revision)]})},{label:"App update prompt",value:r.enabled?e.jsxs(M,{tone:j?"warn":"ok",children:[j?"required · ":"optional · ",r.latestVersion]}):e.jsx(M,{children:"off"})},{label:"Catalogue import",value:s.syncRunning?e.jsx(M,{tone:"warn",children:"running"}):e.jsxs(M,{children:["every ",s.syncEvery]})},{label:"Playback preroll",value:(w==null?void 0:w.prerollEnabled)===!1?e.jsx(M,{children:"off"}):e.jsxs(M,{tone:"ok",children:[((w==null?void 0:w.prerollDurationMs)??6500)/1e3,"s"]})}]})}),e.jsx(A,{title:"Services",intro:"The services this gateway leans on, and whether they answered.",icon:"wrench",tone:"note",children:e.jsx(He,{rows:[{label:"Movies (Radarr)",value:s.radarrReady?e.jsx(M,{tone:"ok",children:"ready"}):e.jsx(M,{children:"not configured"})},{label:"Series (Sonarr)",value:s.sonarrReady?e.jsx(M,{tone:"ok",children:"ready"}):e.jsx(M,{children:"not configured"})},{label:"MDBList ratings",value:p!=null&&p.enabled?e.jsxs(M,{tone:"ok",children:[N(p.cachedTitles)," titles stored"]}):e.jsx(M,{children:p!=null&&p.apiKeyConfigured?"off · key saved":"off · no key"})},{label:"For You pools",value:s.forYouRunning?e.jsx(M,{tone:"warn",children:"rebuilding"}):e.jsxs(M,{children:[N((m==null?void 0:m.candidates)??0)," ranked candidates"]})},{label:"Recommendation profiles",value:e.jsx("span",{className:"mono",children:N((m==null?void 0:m.profiles)??0)})}]})})]}),e.jsxs(oe,{cols:"2",children:[e.jsx(A,{title:"Latest imports",intro:"The last few catalogue synchronisations.",icon:"sync",tone:"data",actions:e.jsx(ne,{to:"/admin/imports",children:"All imports"}),children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Started"}),e.jsx("th",{children:"Kind"}),e.jsx("th",{children:"Status"}),e.jsx("th",{className:"num",children:"Written"})]})}),e.jsx("tbody",{children:f.length===0?e.jsx(X,{columns:4,children:"No imports have run yet."}):f.map(E=>e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",children:O(E.startedAt)}),e.jsx("td",{children:E.kind}),e.jsx("td",{children:e.jsx(M,{tone:E.status==="success"?"ok":E.status==="running"?"warn":"bad",children:E.status})}),e.jsx("td",{className:"num",children:N(E.itemsUpserted)})]},E.id||E.startedAt))})]})})}),e.jsx(A,{title:"Process",intro:"The container the gateway is served from.",icon:"chip",tone:"info",children:u?e.jsxs(e.Fragment,{children:[e.jsx(ws,{tiles:[{label:"goroutines",value:N(u.goroutines)},{label:"heap in use",value:ye(u.heapInuse)},{label:"reserved",value:ye(u.sys)},{label:"collections",value:N(u.numGc)}]}),e.jsxs("p",{className:"hint",children:["Next collection at ",ye(u.nextGc)," · memory limit"," ",u.memoryLimit>0&&u.memoryLimit`/admin/api/notifications${Se({days:a,type:t,severity:d,unread:j,limit:f,offset:p*f})}`,[a,t,d,j,p]),{data:v,error:b,loading:S,reload:h}=J(u),g=async()=>{await l(),await h()};return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Activity",intro:"Every administrative event the gateway has published: sign-ins, devices, scheduled tasks, integrations and the server itself. The same feed the bell and every integration read from.",actions:s>0?e.jsx(R,{onClick:()=>void g(),icon:"check",children:"Mark all read"}):void 0}),e.jsx(B,{message:b}),e.jsx(ae,{tiles:[{label:"Events in window",value:N((v==null?void 0:v.total)??0),icon:"bell",tone:"info"},{label:"Unread",value:N(s),icon:"alert",tone:s>0?"warn":void 0},{label:"Kinds seen",value:N((v==null?void 0:v.types.length)??0),icon:"list",tone:"note"},{label:"Live feed",value:n?"connected":"reconnecting",small:!0,icon:"pulse",tone:n?"ok":"warn"}]}),e.jsxs("div",{className:"filters",children:[e.jsx(D,{label:"Window",children:e.jsx(Ee,{value:a,options:an.map(E=>({value:E.value,label:E.label})),onChange:E=>{c(E),m(0)}})}),e.jsx(D,{label:"Kind",children:e.jsxs("select",{value:t,onChange:E=>{o(E.target.value),m(0)},children:[e.jsx("option",{value:"",children:"Everything"}),((v==null?void 0:v.types)??[]).map(E=>e.jsxs("option",{value:E.type,children:[We(E.type)," (",E.count,")"]},E.type))]})}),e.jsx(D,{label:"Severity",children:e.jsxs("select",{value:d,onChange:E=>{r(E.target.value),m(0)},children:[e.jsx("option",{value:"",children:"Any"}),e.jsx("option",{value:"info",children:"Information"}),e.jsx("option",{value:"warning",children:"Warning"}),e.jsx("option",{value:"error",children:"Error"})]})}),e.jsx(D,{label:"Read state",children:e.jsxs("select",{value:j?"unread":"",onChange:E=>{w(E.target.value==="unread"),m(0)},children:[e.jsx("option",{value:"",children:"All"}),e.jsx("option",{value:"unread",children:"Unread only"})]})}),e.jsx("div",{className:"filter-actions",children:e.jsx(R,{variant:"quiet",size:"sm",icon:"refresh",onClick:()=>{h(),i()},children:"Refresh"})})]}),S?e.jsx(W,{}):e.jsx(A,{title:"Events",icon:"bell",tone:"info",footer:((v==null?void 0:v.total)??0)>f?e.jsxs(e.Fragment,{children:[e.jsx(R,{size:"sm",disabled:p===0,onClick:()=>m(p-1),children:"Newer"}),e.jsx(R,{size:"sm",disabled:(p+1)*f>=((v==null?void 0:v.total)??0),onClick:()=>m(p+1),children:"Older"})]}):void 0,children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nowrap",children:"When"}),e.jsx("th",{children:"Kind"}),e.jsx("th",{children:"What happened"}),e.jsx("th",{children:"Who"}),e.jsx("th",{children:"What"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:((v==null?void 0:v.events.length)??0)===0?e.jsx(X,{columns:6,children:"Nothing has happened in this window."}):v==null?void 0:v.events.map(E=>e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",title:O(E.occurredAt),children:pe(E.occurredAt)}),e.jsx("td",{className:"nowrap",children:e.jsxs("span",{className:"row tight",children:[e.jsx(Ie,{name:gs(E.type),tone:fs(E)}),We(E.type)]})}),e.jsxs("td",{children:[e.jsx("b",{children:E.title}),E.summary?e.jsx("div",{className:"muted",children:E.summary}):null]}),e.jsx("td",{className:"muted nowrap",children:E.actor||"—"}),e.jsx("td",{className:"muted nowrap",children:E.target||"—"}),e.jsxs("td",{className:"nowrap",children:[E.readAt?null:e.jsx(M,{tone:"ok",children:"new"}),E.link?e.jsx(ne,{className:"table-row-link",to:E.link,children:"Open"}):null]})]},E.id))})]})})})]})}function ln(){const{data:s,error:n,loading:l}=J("/admin/api/accounts",{pollMs:6e4}),i=(s==null?void 0:s.accounts)??[],a=i.flatMap(o=>o.devices??[]),c=i.filter(o=>{var d;return(d=o.recommendations)==null?void 0:d.completed}).length,t=i.filter(o=>{var d,r;return((d=o.recommendations)==null?void 0:d.prompted)&&!((r=o.recommendations)!=null&&r.completed)}).length;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Memby users",intro:"Who uses Memby, and the devices they are signed in on."}),e.jsx(B,{message:n}),e.jsx(ue,{tone:"info",children:"This is the Memby user list, not the Emby user directory. A person appears here only after signing in to the Memby app. Removing access signs their Memby devices out and does not delete or change their Emby account."}),l?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"Memby users",value:N(i.length),icon:"people",tone:"note"},{label:"signed-in devices",value:N(a.length),icon:"tv",tone:"info"},{label:"active in the last quarter hour",value:N(a.filter(o=>Ne(o.lastSeen)).length),icon:"pulse",tone:"ok"},{label:"recommendation setups completed",value:N(c),icon:"check",tone:"ok"},{label:"setup prompts queued",value:N(t),icon:"sparkle",tone:"note"}]}),e.jsx("section",{className:"card flush",children:i.length===0?e.jsx(Z,{children:"No one has signed in to Memby yet. Emby-only accounts are intentionally not listed here."}):i.map(o=>{var p,m;const d=o.devices??[],r=d.filter(f=>Ne(f.lastSeen)).length,j=(p=o.recommendations)!=null&&p.completed?{label:"personalised",tone:"ok"}:(m=o.recommendations)!=null&&m.prompted?{label:"prompt queued",tone:"warn"}:{label:"not invited",tone:void 0},w=Pe(o.lastSeen);return e.jsxs(ne,{className:"list-row",to:`/admin/accounts/${encodeURIComponent(o.id)}`,children:[e.jsxs("span",{className:"list-main",children:[e.jsx("span",{className:"avatar",children:js(o.username)}),e.jsxs("span",{children:[e.jsxs("span",{className:"list-title",children:[o.username||"Unnamed user",e.jsx("span",{className:"dot-state","data-tone":w.tone,title:w.label})]}),e.jsxs("span",{className:"list-meta",children:[N(d.length)," device",d.length===1?"":"s",r?` · ${r} active now`:""," · last seen ",O(o.lastSeen)]})]})]}),e.jsxs("span",{className:"list-actions",children:[e.jsx(M,{tone:j.tone,children:j.label}),e.jsx("span",{className:"crumb",children:"Manage"})]})]},o.id)})})]})]})}function $e(s){const n=String(s??"").replace("#","");return n.length!==8?`#${n}`:`#${n.slice(2)}${n.slice(0,2)}`}function on(){const{userId:s=""}=Re(),n=qe(),{wrap:l}=Q(),{busy:i,run:a}=Y(),c=`/admin/api/accounts/${encodeURIComponent(s)}`,{data:t,error:o,loading:d,reload:r}=J("/admin/api/accounts",{pollMs:3e4}),[j,w]=x.useState(null),[p,m]=x.useState(null),[f,u]=x.useState(null),[v,b]=x.useState(null),[S,h]=x.useState(null),g=((t==null?void 0:t.accounts)??[]).find(I=>I.id===s),E=(t==null?void 0:t.catalogue)??[],C=(t==null?void 0:t.themes)??[];x.useEffect(()=>{var I;j===null&&g&&w({...((I=g.settings)==null?void 0:I.preferences)??{}})},[g,j]),x.useEffect(()=>{f===null&&g&&u({...g.notifications})},[g,f]),x.useEffect(()=>{if(p!==null||!g)return;const I=g.themes??[];m(I.length===0?C.map(T=>T.id):I)},[g,p,C]);const V=x.useMemo(()=>{const I=[];for(const T of E){let H=I.find(k=>k.name===T.area);H||I.push(H={name:T.area,definitions:[]}),H.definitions.push(T)}return I},[E]),y=(I,T,H,k)=>a(I,async()=>{const q=await l(T,H);b(null),q!==void 0&&(k==null||k()),await r()});if(d)return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"User",crumbs:e.jsx(ne,{to:"/admin/accounts",children:"← All users"})}),e.jsx(W,{})]});if(!g)return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"User",crumbs:e.jsx(ne,{to:"/admin/accounts",children:"← All users"})}),e.jsx(B,{message:o}),e.jsx(A,{children:e.jsx(Z,{children:"This user is no longer signed in to Memby."})})]});const L=g.devices??[],ee=L.filter(I=>Ne(I.lastSeen)).length,re=g.settings??{},K=g.recommendations??{};return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:g.username||"Unnamed user",intro:`Memby user · ${N(L.length)} device${L.length===1?"":"s"} · last seen ${O(g.lastSeen)}`,crumbs:e.jsx(ne,{to:"/admin/accounts",children:"← All users"}),actions:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"avatar",children:js(g.username)}),ee?e.jsxs(M,{tone:"ok",children:[ee," active now"]}):e.jsx(M,{children:"idle"}),e.jsx(se,{children:g.id})]})}),e.jsx(B,{message:o}),e.jsxs(oe,{cols:"wide",children:[e.jsx(A,{title:"Devices",intro:"Every build a set has been seen running is listed under it. Signing one out revokes its Memby session, drops that history and removes it from Emby's own device list. Its Emby account is not changed.",icon:"tv",tone:"info",children:L.length===0?e.jsx(Z,{children:"No devices are signed in to this user."}):e.jsx("div",{className:"list",children:L.map(I=>{const T=Pe(I.lastSeen);return e.jsxs("div",{className:"list-item",children:[e.jsxs("div",{className:"list-body",children:[e.jsxs("b",{children:[e.jsx("span",{className:"dot-state","data-tone":T.tone,title:T.label})," ",e.jsx(ne,{className:"table-row-link",to:`/admin/devices/${encodeURIComponent(I.id)}`,children:I.name||"Memby TV"})]}),e.jsxs("p",{children:[I.version?`Memby ${I.version}`:"Legacy Memby client"," · ",T.label," · last seen ",O(I.lastSeen)," · signed in ",O(I.signedInAt)]}),(I.versions??[]).length>0?e.jsx("div",{className:"chips",children:(I.versions??[]).map(H=>e.jsxs(se,{tone:H.version===I.version?"ok":void 0,children:[H.version,H.version===I.version?" · now":""]},H.version))}):null]}),e.jsxs("div",{className:"list-actions",children:[e.jsx(R,{size:"sm",disabled:!I.id,onClick:()=>h({id:I.id,name:I.name}),children:"Rename"}),e.jsx(R,{size:"sm",variant:"danger",disabled:!I.id,onClick:()=>b({kind:"remove-device",deviceId:I.id,name:I.name}),children:"Sign out"})]})]},I.id||I.name)})})}),e.jsxs(A,{title:"Recommendation setup",intro:"The prompt appears the next time this person opens Memby on any of their televisions.",icon:"sparkle",tone:"note",footer:K.completed?e.jsx(R,{busy:i==="reset-rec",onClick:()=>b({kind:"reset-recommendations"}),children:"Clear stored choices"}):K.prompted?e.jsx(R,{onClick:()=>b({kind:"cancel-prompt"}),children:"Cancel prompt"}):e.jsx(R,{variant:"primary",busy:i==="prompt",onClick:()=>void y("prompt",()=>F.put(`${c}/recommendations/prompt`),"Setup prompt queued."),children:"Send setup prompt"}),children:[e.jsx("div",{className:"row tight",children:K.completed?e.jsx(M,{tone:"ok",children:"completed"}):K.prompted?e.jsx(M,{tone:"warn",children:"prompt queued"}):e.jsx(M,{children:"not invited"})}),e.jsx(cn,{prompt:K})]})]}),e.jsx(A,{title:"Notifications",intro:"Choose what this person sees across every television. Changes apply through the gateway within a few seconds and do not require an app release.",icon:"bell",tone:"note",actions:f!=null&&f.enabled?e.jsx(M,{tone:"ok",children:"enabled"}):e.jsx(M,{children:"muted"}),footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:i==="notifications",onClick:()=>void y("notifications",()=>F.put(`${c}/notifications`,f),"Notification settings saved.",()=>u(null)),children:"Save notifications"}),e.jsx(R,{onClick:()=>{u(null),r()},children:"Discard changes"})]}),children:f?e.jsxs("div",{className:"checks columns",children:[e.jsx(z,{label:"All notifications",hint:"The master switch. Turning this off hides every optional notification below.",checked:f.enabled,onChange:I=>u(T=>T&&{...T,enabled:I})}),e.jsx(z,{label:"My Shows return dates",hint:"Remind this person when a followed show is about to return.",checked:f.showReturnAlerts,disabled:!f.enabled,onChange:I=>u(T=>T&&{...T,showReturnAlerts:I})}),e.jsx(z,{label:"Sonarr television alerts",hint:"New episodes, additions and cancellation news supplied by Sonarr.",checked:f.sonarrAlerts,disabled:!f.enabled,onChange:I=>u(T=>T&&{...T,sonarrAlerts:I})}),e.jsx(z,{label:"Radarr film alerts",hint:"Notify this person when Radarr imports a new film.",checked:f.radarrAlerts,disabled:!f.enabled,onChange:I=>u(T=>T&&{...T,radarrAlerts:I})}),e.jsx(z,{label:"Optional app updates",hint:"Offer new app versions to this person. Mandatory compatibility updates are always enforced.",checked:f.updateAlerts,disabled:!f.enabled,onChange:I=>u(T=>T&&{...T,updateAlerts:I})}),e.jsx(z,{label:"Library activity",hint:"Show alerts after the Memby library catalogue is refreshed.",checked:f.libraryAlerts,disabled:!f.enabled,onChange:I=>u(T=>T&&{...T,libraryAlerts:I})}),e.jsx(z,{label:"Service status",hint:"Memby deployment and Emby outage or recovery notices. Maintenance mode itself still applies.",checked:f.systemAlerts,disabled:!f.enabled,onChange:I=>u(T=>T&&{...T,systemAlerts:I})})]}):null}),e.jsx(A,{title:"Settings",intro:"These live on the server and follow the person, so a change here reaches every television they use — usually within a few seconds, and on the next launch for a set that is switched off.",icon:"sliders",tone:"ok",actions:re.saved?e.jsxs(M,{tone:re.source==="admin"?"warn":"ok",children:["r",N(re.revision)," · ",re.source||"device"," · ",O(re.updatedAt)]}):e.jsx(M,{children:"defaults · never synced"}),footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:i==="push",onClick:()=>void y("push",()=>F.put(`${c}/preferences`,{preferences:j??{}}),"Pushed to their televisions.",()=>w(null)),children:"Push to their televisions"}),e.jsx(R,{onClick:()=>{w(null),r()},children:"Discard changes"}),e.jsx(R,{onClick:()=>b({kind:"reset-preferences"}),children:"Restore defaults"}),e.jsx(ne,{className:"crumb",to:`/admin/accounts/${encodeURIComponent(s)}/settings`,children:"History and rollback →"})]}),children:V.map(I=>e.jsxs("div",{className:"group",children:[e.jsx("p",{className:"group-label",children:I.name}),I.definitions.map(T=>e.jsx(dn,{definition:T,value:j==null?void 0:j[T.key],onChange:H=>w(k=>({...k??{},[T.key]:H}))},T.key))]},I.name))}),e.jsx(A,{title:"Colour schemes",intro:"Which palettes this person may choose between in Settings → Appearance. Tick everything to leave them unrestricted. Their current choice is an ordinary setting above; withdrawing it here puts them back on Midnight.",icon:"sparkle",tone:"note",actions:(g.themes??[]).length===0?e.jsx(M,{children:"all schemes"}):e.jsxs(M,{tone:"note",children:[N((g.themes??[]).length)," of ",N(C.length)]}),footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:i==="themes",onClick:()=>(p??[]).length===0?b({kind:"no-themes"}):void y("themes",()=>F.put(`${c}/themes`,{themes:p??[]}),"Colour schemes saved.",()=>m(null)),children:"Save colour schemes"}),e.jsx(R,{onClick:()=>m(C.map(I=>I.id)),children:"Allow all"}),e.jsxs("span",{className:"hint",children:["Seasonal themes are not listed. They apply to every television in the house for their dates and nobody can decline one — the only switch is ",e.jsx("em",{children:"Seasonal themes"})," on the features page."]})]}),children:e.jsx("div",{className:"checks columns",children:C.map(I=>{var T,H,k;return e.jsxs("label",{className:"check",children:[e.jsx("input",{type:"checkbox",checked:(p??[]).includes(I.id),onChange:q=>m($=>q.target.checked?[...$??[],I.id]:($??[]).filter(P=>P!==I.id))}),e.jsx("span",{className:"switch"}),e.jsx("span",{className:"swatch",style:{"--swatch-surface":$e((T=I.palette)==null?void 0:T.surface),"--swatch-accent":$e((H=I.palette)==null?void 0:H.accent),"--swatch-hairline":$e((k=I.palette)==null?void 0:k.hairline)},children:e.jsx("i",{})}),e.jsxs("span",{className:"check-body",children:[e.jsx("b",{children:I.name}),e.jsx("p",{children:I.description})]})]},I.id)})})}),e.jsx(A,{title:"Remove Memby access",intro:"Signs every one of this person's Memby devices out. Their Emby account, viewing history and library permissions are untouched.",icon:"alert",tone:"bad",children:e.jsx(R,{variant:"danger",onClick:()=>b({kind:"remove-account"}),children:"Remove Memby access"})}),S?e.jsx(hn,{initial:S.name,busy:i==="rename",onCancel:()=>h(null),onConfirm:I=>void y("rename",()=>F.put(`${c}/devices/${encodeURIComponent(S.id)}`,{deviceName:I}),"Device renamed.",()=>h(null))}):null,v?e.jsx(un,{pending:v,busy:i,username:g.username,onCancel:()=>b(null),onConfirm:()=>{switch(v.kind){case"remove-device":return void y("remove-device",()=>F.del(`${c}/devices/${encodeURIComponent(v.deviceId)}`),"Device signed out.");case"remove-account":return void y("remove-account",()=>F.del(`${c}/sessions`),"Memby access removed.",()=>n("/admin/accounts"));case"reset-recommendations":case"cancel-prompt":return void y("reset-rec",()=>F.del(`${c}/recommendations`),"Recommendation choices cleared.");case"reset-preferences":return void y("reset-prefs",()=>F.del(`${c}/preferences`),"Defaults restored.",()=>w(null));case"no-themes":return void y("themes",()=>F.put(`${c}/themes`,{themes:[]}),"Colour schemes saved.",()=>m(null))}}}):null]})}function cn({prompt:s}){const n=s.ratings??[],l=[["Genres",s.genres],["Studios",s.studios],["Actors",s.actors],["Actresses",s.actresses],["Directors",s.directors],["Types",s.contentTypes]],i=[...n.map(a=>e.jsxs(se,{tone:"warn",children:[a.title," · ",N(a.rating)," ★"]},`r:${a.title}`)),...l.flatMap(([a,c])=>(c??[]).map(t=>e.jsxs(se,{children:[a,": ",t]},`${a}:${t}`)))];return i.length===0?e.jsx(Z,{children:"No recommendation selections have been saved."}):e.jsx("div",{className:"chips",children:i})}function dn({definition:s,value:n,onChange:l}){if(s.kind==="toggle")return e.jsx(z,{label:s.name,hint:s.description,checked:!!n,onChange:l});if(s.kind==="choice"||s.kind==="number"){const a=s.unit??"",c=s.kind==="number"?(s.numbers??[]).map(t=>({value:String(t),label:t===0?"No limit":a?`${t} ${a}`:String(t)})):s.options??[];return e.jsx(D,{label:s.name,hint:s.description,children:e.jsx("select",{value:String(n??""),onChange:t=>l(s.kind==="number"?Number(t.target.value):t.target.value),children:c.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})})}if(s.kind==="multi"){const a=Array.isArray(n)?n:[],c=[...a,...(s.options??[]).map(t=>t.value).filter(t=>!a.includes(t))];return e.jsxs("div",{className:"field",children:[e.jsx("span",{children:s.name}),e.jsx("small",{children:s.description}),e.jsx("div",{className:"checks",children:c.map(t=>{const o=(s.options??[]).find(d=>d.value===t);return o?e.jsx(z,{label:o.label,checked:a.includes(t),onChange:d=>l(d?[...a,t]:a.filter(r=>r!==t))},t):null})})]})}const i=Array.isArray(n)?n:[];return e.jsx(D,{label:s.name,hint:s.description,children:e.jsx("textarea",{spellCheck:!1,placeholder:"One row id per line",value:i.join(` `),onChange:a=>l(a.target.value.split(` `).map(c=>c.trim()).filter(Boolean))})})}function hn({initial:s,busy:n,onConfirm:l,onCancel:i}){const[a,c]=x.useState(s||"Memby TV");return e.jsx("div",{className:"scrim",onPointerDown:t=>t.target===t.currentTarget&&i(),children:e.jsxs("div",{className:"dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h2",{children:"Name this device"}),e.jsx("p",{children:"The name a viewer sees in Settings → Devices, and what the console calls it."}),e.jsx(D,{label:"Device name",children:e.jsx("input",{type:"text",value:a,autoFocus:!0,maxLength:80,onChange:t=>c(t.target.value)})}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx(R,{variant:"quiet",onClick:i,children:"Cancel"}),e.jsx(R,{variant:"primary",busy:n,disabled:!a.trim(),onClick:()=>l(a.trim()),children:"Rename"})]})]})})}function un({pending:s,busy:n,username:l,onConfirm:i,onCancel:a}){const t={"remove-device":{title:"Sign this device out of Memby?",body:"Its Emby account will not be changed. The set can sign in again at any time.",label:"Sign out",destructive:!0},"remove-account":{title:`Remove Memby access for ${l||"this user"}?`,body:"Every Memby device will be signed out. Their Emby account, viewing history and library permissions are untouched.",label:"Remove access",destructive:!0},"reset-recommendations":{title:"Clear this person's stored recommendation choices?",body:"Viewing history remains intact; only the explicit setup answers are removed.",label:"Clear",destructive:!0},"cancel-prompt":{title:"Cancel this person's queued recommendation prompt?",body:"They will not be invited to set up recommendations on their next launch.",label:"Cancel prompt",destructive:!1},"reset-preferences":{title:"Restore the Memby defaults for this person?",body:"Their televisions will pick the change up the next time they check in.",label:"Restore defaults",destructive:!0},"no-themes":{title:"Allow this person no colour schemes?",body:"They will be left on Midnight with nothing to choose between.",label:"Save anyway",destructive:!0}}[s.kind];return e.jsx(he,{title:t.title,body:t.body,confirmLabel:t.label,destructive:t.destructive,busy:!!n,onConfirm:i,onCancel:a})}function mn(s,n){if(s.kind==="toggle")return n?"On":"Off";if(s.kind==="choice"){const i=(s.options??[]).find(a=>a.value===n);return i?i.label:String(n??"")}if(s.kind==="number")return Number(n)===0&&s.unit?"No limit":s.unit?`${n} ${s.unit}`:String(n??"");const l=Array.isArray(n)?n:[];return l.length===0?"None":l.map(i=>{var a;return((a=(s.options??[]).find(c=>c.value===i))==null?void 0:a.label)??i}).join(", ")}function pn(){const{userId:s=""}=Re(),{wrap:n}=Q(),{busy:l,run:i}=Y(),a=`/admin/api/accounts/${encodeURIComponent(s)}`,{data:c,error:t,loading:o,reload:d}=J(`${a}/preferences/history`,{pollMs:3e4}),[r,j]=x.useState(new Set),[w,p]=x.useState(null),m=(c==null?void 0:c.username)||"this account",f=(c==null?void 0:c.devices)??[],u=(c==null?void 0:c.revisions)??[],v=(c==null?void 0:c.catalogue)??[],b=h=>j(g=>{const E=new Set(g);return E.has(h)?E.delete(h):E.add(h),E}),S=h=>i("restore",async()=>{await n(()=>F.post(`${a}/preferences/revisions/${h}/restore`),`Restored r${h}.`),p(null),await d()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Settings history",intro:`Every change to ${m}'s synced settings, and which of their televisions has taken it.`,crumbs:e.jsxs(ne,{to:`/admin/accounts/${encodeURIComponent(s)}`,children:["← ",m]})}),e.jsx(B,{message:t}),o?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(A,{title:"Where each device has got to",intro:"A set takes a change by fetching it, which it does within a few seconds of being told — so anything still behind is switched off, mid-film, or cannot reach the gateway.",icon:"tv",tone:"info",actions:c!=null&&c.saved?e.jsxs(M,{tone:c.currentSource==="admin"?"warn":"ok",children:["now on r",N(c.currentRevision)," · ",c.currentSource||"device"]}):e.jsx(M,{children:"defaults · never synced"}),children:f.length===0?e.jsx(Z,{children:"No television has been signed in to this account."}):e.jsx("div",{className:"list",children:f.map(h=>{const g=h.never?void 0:h.behind?"bad":"ok";return e.jsxs("div",{className:"list-item",children:[e.jsxs("div",{className:"list-body",children:[e.jsxs("b",{children:[e.jsx("span",{className:"dot-state","data-tone":g})," ",h.name||"Memby TV"," ",h.signedOut?e.jsx(M,{children:"signed out"}):null]}),e.jsxs("p",{children:[h.never?"Has not fetched these settings yet":`Holding r${N(h.revision)} · taken ${O(h.ackedAt)}`,h.clientVersion?` · Memby ${h.clientVersion}`:"",h.signedOut?"":` · last seen ${O(h.lastSeen)}`]})]}),e.jsx("div",{className:"list-actions",children:h.never?e.jsx(M,{children:"never taken one"}):h.behind?e.jsxs(M,{tone:"bad",children:[N(h.behind)," behind"]}):e.jsx(M,{tone:"ok",children:"up to date"})})]},h.deviceId||h.name)})})}),e.jsx(A,{title:"Change history",intro:"Restoring puts an earlier version back as a new change, so the televisions notice it and the version it replaced stays here to return to.",icon:"history",tone:"note",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"When"}),e.jsx("th",{className:"num",children:"Rev"}),e.jsx("th",{children:"Changed by"}),e.jsx("th",{children:"What changed"}),e.jsx("th",{className:"num",children:"Taken by"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:u.length===0?e.jsx(X,{columns:6,children:"Nothing has been changed on this account yet."}):u.flatMap(h=>{const g=r.has(h.revision),E=h.acks??[],C=h.changes??[],V=[e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",children:O(h.createdAt)}),e.jsxs("td",{className:"num nowrap",children:["r",N(h.revision)," ",h.current?e.jsx(M,{tone:"ok",children:"current"}):null]}),e.jsxs("td",{className:"nowrap",children:[e.jsx(M,{tone:h.source==="admin"?"warn":"ok",children:h.author}),h.restoredFrom?e.jsxs("span",{className:"muted",children:[" restored r",N(h.restoredFrom)]}):null]}),e.jsx("td",{className:"muted",children:h.initial?e.jsx("span",{className:"muted",children:"First recorded settings"}):C.length===0?e.jsx("span",{className:"muted",children:"No visible change"}):e.jsx("div",{className:"chips",children:C.map((y,L)=>e.jsxs(se,{children:[y.name,": ",y.before," → ",y.after]},`${y.name}:${L}`))})}),e.jsx("td",{className:"num",children:E.length===0?e.jsx("span",{className:"muted",children:"—"}):e.jsx("span",{title:E.map(y=>y.deviceName||y.deviceId).join(", "),children:N(E.length)})}),e.jsx("td",{className:"num nowrap",children:e.jsxs("span",{className:"list-actions",children:[e.jsx(R,{size:"sm",onClick:()=>b(h.revision),children:g?"Hide":"Show"}),h.current?null:e.jsx(R,{size:"sm",onClick:()=>p(h.revision),children:"Restore"})]})})]},h.revision)];return g&&V.push(e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"muted",children:e.jsx("div",{className:"chips",children:v.map(y=>{var L;return e.jsxs(se,{children:[y.name,":"," ",mn(y,(L=h.preferences)==null?void 0:L[y.key])]},y.key)})})})},`${h.revision}:detail`)),V})})]})})})]}),w!==null?e.jsx(he,{title:`Restore revision ${w}?`,body:"It goes out as a new change, so every one of their televisions will pick it up — and the current version stays in this history to return to.",confirmLabel:"Restore",busy:l==="restore",onConfirm:()=>void S(w),onCancel:()=>p(null)}):null]})}function xn({client:s}){const n=s.versions??[];return n.length===0?e.jsx("span",{className:"muted",children:"—"}):e.jsx("span",{className:"versions",children:n.map(l=>e.jsx(se,{tone:l.version===s.version?"ok":void 0,children:l.version},l.version))})}function jn(){const{status:s,error:n,loading:l}=ie(),i=(s==null?void 0:s.clients)??[],a=i.filter(t=>(t.capabilities??[]).includes("server_features_v1")),c=new Set(i.map(t=>t.version).filter(Boolean));return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Devices",intro:"Which sets have reported in, what they are running and what their build understands."}),e.jsx(B,{message:n}),l?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"devices known",value:N(i.length),icon:"tv",tone:"info"},{label:"active in the last quarter hour",value:N(i.filter(t=>Ne(t.lastSeen)).length),icon:"pulse",tone:"ok"},{label:"reporting their capabilities",value:N(a.length),icon:"sliders",tone:"ok"},{label:"app builds in service",value:N(c.size),icon:"download",tone:"note"}]}),e.jsx(A,{title:"Devices",intro:"Every request carries what that build understands. A feature is only presented to a device that declares its contract, which is what lets an older set keep working while a new one gets the new behaviour. Status is whether the set is reporting that list at all; a build old enough to say nothing is served the fallback.",icon:"tv",tone:"info",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Device"}),e.jsx("th",{children:"Person"}),e.jsx("th",{children:"App"}),e.jsx("th",{children:"Builds seen"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Last seen"})]})}),e.jsx("tbody",{children:i.length===0?e.jsx(X,{columns:6,children:"No devices have signed in yet."}):i.map(t=>{const o=(t.capabilities??[]).includes("server_features_v1"),d=Pe(t.lastSeen);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("span",{className:"row tight",children:[e.jsx("span",{className:"dot-state","data-tone":d.tone,title:d.label}),e.jsx(ne,{className:"table-row-link",to:`/admin/devices/${encodeURIComponent(t.deviceId)}`,children:t.deviceName||"Memby TV"})]})}),e.jsx("td",{className:"muted",children:t.username}),e.jsx("td",{className:"mono",children:t.version||"legacy"}),e.jsx("td",{children:e.jsx(xn,{client:t})}),e.jsx("td",{children:e.jsx(M,{tone:o?"ok":"warn",children:o?"reported":"missing"})}),e.jsx("td",{className:"nowrap muted",children:O(t.lastSeen)})]},`${t.deviceId}:${t.username}`)})})]})})})]})]})}const Ke={user:"",q:"",ip:"",outcome:"",from:"",to:""},vn=[{value:1,label:"Today"},{value:7,label:"7 days"},{value:30,label:"30 days"},{value:0,label:"All"}];function bn(){var h,g,E,C,V,y;const[s,n]=x.useState("log"),[l,i]=x.useState(7),[a,c]=x.useState(Ke),[t,o]=x.useState(0),d=100,r=x.useMemo(()=>Se({...a,days:a.from?void 0:l||void 0,limit:d,offset:t*d}),[a,l,t]),j=J(`/admin/api/logins${r}`,{enabled:s==="log"}),w=J(`/admin/api/logins/devices${r}`,{enabled:s==="devices"}),p=((h=j.data)==null?void 0:h.users)??((g=w.data)==null?void 0:g.users)??[],m=((E=j.data)==null?void 0:E.totals)??((C=w.data)==null?void 0:C.totals),f=((V=j.data)==null?void 0:V.retentionDays)??((y=w.data)==null?void 0:y.retentionDays)??90,u=s==="log"?j.loading:w.loading,v=s==="log"?j.error:w.error,b=L=>{c(ee=>({...ee,...L})),o(0)},S=Object.entries(a).some(([,L])=>L!=="")||!!a.from;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Sign-in history",intro:"Every connection attempt, kept as history rather than as the latest state of a device. A television that has since been removed still appears here, because it still connected.",actions:e.jsx(Ee,{value:s,options:[{value:"log",label:"Log"},{value:"devices",label:"By device"}],onChange:n})}),e.jsx(B,{message:v}),m?e.jsx(ae,{tiles:[{label:"Successful sign-ins",value:N(m.logins),icon:"key",tone:"ok"},{label:"Refused",value:N(m.failures),icon:"shield",tone:m.failures>0?"warn":void 0},{label:"Televisions",value:N(m.devices),icon:"tv",tone:"info"},{label:"People",value:N(m.users),icon:"people",tone:"note"},{label:"Addresses",value:N(m.addresses),icon:"globe",tone:"data"},{label:"History kept",value:`${f} days`,small:!0,icon:"clock"}]}):null,e.jsxs("div",{className:"filters",children:[e.jsx(D,{label:"Window",children:e.jsx(Ee,{value:a.from?-1:l,options:vn.map(L=>({value:L.value,label:L.label})),onChange:L=>{i(L),b({from:"",to:""})}})}),e.jsx(D,{label:"Person",children:e.jsxs("select",{value:a.user,onChange:L=>b({user:L.target.value}),children:[e.jsx("option",{value:"",children:"Anyone"}),p.map(L=>e.jsx("option",{value:L.id,children:L.username||L.id},L.id))]})}),e.jsx(D,{label:"Outcome",children:e.jsxs("select",{value:a.outcome,onChange:L=>b({outcome:L.target.value}),children:[e.jsx("option",{value:"",children:"Both"}),e.jsx("option",{value:"success",children:"Got in"}),e.jsx("option",{value:"failure",children:"Refused"})]})}),e.jsx(D,{label:"Address",children:e.jsx("input",{type:"text",value:a.ip,placeholder:"10.0.0.4",onChange:L=>b({ip:L.target.value})})}),e.jsx(D,{label:"From",children:e.jsx("input",{type:"date",value:a.from,onChange:L=>b({from:L.target.value})})}),e.jsx(D,{label:"To",children:e.jsx("input",{type:"date",value:a.to,onChange:L=>b({to:L.target.value})})}),e.jsx(D,{label:"Search",grow:!0,children:e.jsx("input",{type:"search",value:a.q,placeholder:"Name, device or address",onChange:L=>b({q:L.target.value})})}),e.jsx("div",{className:"filter-actions",children:S?e.jsx(R,{variant:"quiet",size:"sm",onClick:()=>{c(Ke),o(0)},children:"Clear"}):null})]}),u?e.jsx(W,{}):s==="log"?e.jsx(fn,{data:j.data,page:t,limit:d,onPage:o}):e.jsx(gn,{data:w.data})]})}function fn({data:s,page:n,limit:l,onPage:i}){if(!s)return null;const a=s.events.length,c=s.total===0?0:n*l+1;return e.jsxs(e.Fragment,{children:[e.jsxs(oe,{cols:"wide",children:[e.jsx(A,{title:"Attempts per day",intro:"Grouped in the household's own timezone, so an evening sign-in stays on the day it happened.",icon:"chart",tone:"info",children:e.jsx(ys,{data:s.days,labelOf:t=>t.day,valueOf:t=>t.logins+t.failures,toneOf:t=>t.failures>t.logins?"bad":void 0,title:t=>`${t.day}: ${t.logins} in, ${t.failures} refused, ${t.devices} televisions`})}),e.jsx(A,{title:"Where from",icon:"globe",tone:"data",children:s.addresses.length===0?e.jsx(Z,{children:"No addresses in this window."}):e.jsx("div",{className:"list",children:s.addresses.slice(0,8).map(t=>e.jsxs("div",{className:"list-item",children:[e.jsxs("div",{className:"list-body",children:[e.jsx("b",{className:"mono",children:t.ipAddress}),e.jsxs("p",{children:[N(t.logins)," in",t.failures>0?` · ${N(t.failures)} refused`:""]})]}),t.failures>0&&t.logins===0?e.jsx(M,{tone:"bad",children:"only refused"}):null]},t.ipAddress))})})]}),e.jsx(A,{title:"Attempts",intro:"Uncollapsed and newest first: this is what to read when somebody says a television will not sign in.",icon:"key",tone:"ok",actions:e.jsx("span",{className:"filter-summary",children:s.total===0?"nothing matches":`${N(c)}–${N(c+a-1)} of ${N(s.total)}`}),footer:s.total>l?e.jsxs(e.Fragment,{children:[e.jsx(R,{size:"sm",disabled:n===0,onClick:()=>i(n-1),children:"Newer"}),e.jsx(R,{size:"sm",disabled:(n+1)*l>=s.total,onClick:()=>i(n+1),children:"Older"})]}):void 0,children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nowrap",children:"When"}),e.jsx("th",{children:"Person"}),e.jsx("th",{children:"Television"}),e.jsx("th",{className:"nowrap",children:"Address"}),e.jsx("th",{children:"Build"}),e.jsx("th",{children:"Outcome"})]})}),e.jsx("tbody",{children:s.events.length===0?e.jsx(X,{columns:6,children:"No sign-in attempts match these filters."}):s.events.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",children:O(t.occurredAt)}),e.jsx("td",{children:t.username||e.jsx("span",{className:"quiet",children:"unknown"})}),e.jsx("td",{children:t.deviceId?e.jsx(ne,{className:"table-row-link",to:`/admin/devices/${encodeURIComponent(t.deviceId)}`,children:t.deviceName||t.deviceId}):e.jsx("span",{className:"quiet",children:"—"})}),e.jsx("td",{className:"mono nowrap",children:t.ipAddress||"—"}),e.jsx("td",{className:"mono",children:t.clientVersion||"—"}),e.jsx("td",{className:"nowrap",children:t.success?t.newDevice?e.jsx(M,{tone:"info",children:"first sign-in"}):e.jsx(M,{tone:"ok",children:"got in"}):e.jsx(M,{tone:"bad",children:t.failureReason||"refused"})})]},t.id))})]})})})]})}function gn({data:s}){return s?e.jsx(A,{title:"Televisions",intro:"Grouped from the history, not from the session list — a set whose session has expired still connected, and this is the record of it.",icon:"tv",tone:"info",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Television"}),e.jsx("th",{children:"Person"}),e.jsx("th",{className:"num",children:"Today"}),e.jsx("th",{className:"num",children:"Sign-ins"}),e.jsx("th",{className:"num",children:"Refused"}),e.jsx("th",{className:"num",children:"Addresses"}),e.jsx("th",{className:"nowrap",children:"Last address"}),e.jsx("th",{className:"nowrap",children:"Last sign-in"}),e.jsx("th",{children:"Build"})]})}),e.jsx("tbody",{children:s.devices.length===0?e.jsx(X,{columns:9,children:"No television has connected in this window."}):s.devices.map(n=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx(ne,{className:"table-row-link",to:`/admin/devices/${encodeURIComponent(n.deviceId)}`,children:n.deviceName||n.deviceId})}),e.jsx("td",{className:"muted",children:n.username||"—"}),e.jsx("td",{className:"num",children:n.loginsToday>0?N(n.loginsToday):"—"}),e.jsx("td",{className:"num",children:N(n.logins)}),e.jsx("td",{className:"num",children:n.failures>0?e.jsx("span",{className:"mono",children:N(n.failures)}):"—"}),e.jsx("td",{className:"num",children:N(n.distinctIps)}),e.jsx("td",{className:"mono nowrap",children:n.lastIp||"—"}),e.jsx("td",{className:"nowrap muted",children:n.lastLogin?O(n.lastLogin):"—"}),e.jsx("td",{className:"mono",children:n.clientVersion||"—"})]},n.deviceId))})]})})}):null}const yn=[{value:1,label:"Today"},{value:7,label:"7 days"},{value:30,label:"30 days"},{value:0,label:"All"}];function wn(){const{deviceId:s=""}=Re(),[n,l]=x.useState(7),i=x.useMemo(()=>`/admin/api/logins/devices/${encodeURIComponent(s)}${Se({days:n||void 0,limit:200})}`,[s,n]),{data:a,error:c,loading:t}=J(i,{enabled:!!s}),o=a==null?void 0:a.summary,d=(o==null?void 0:o.deviceName)||s;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:d,intro:"One television's whole relationship with the gateway.",crumbs:e.jsxs(e.Fragment,{children:[e.jsx(ne,{to:"/admin/clients",children:"Devices"}),e.jsx("span",{children:"/"}),e.jsx(ne,{to:"/admin/logins",children:"Sign-ins"}),e.jsx("span",{children:"/"}),e.jsx("span",{children:d})]}),actions:e.jsx(Ee,{value:n,options:yn.map(r=>({value:r.value,label:r.label})),onChange:l})}),e.jsx(B,{message:c}),t?e.jsx(W,{}):a?e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"Sign-ins today",value:N((o==null?void 0:o.loginsToday)??0),icon:"clock",tone:"ok"},{label:"Sign-ins in total",value:N((o==null?void 0:o.logins)??0),icon:"key",tone:"info"},{label:"Refused",value:N((o==null?void 0:o.failures)??0),icon:"shield",tone:((o==null?void 0:o.failures)??0)>0?"warn":void 0},{label:"Addresses seen",value:N((o==null?void 0:o.distinctIps)??0),icon:"globe",tone:"data"},{label:"First seen",value:o!=null&&o.firstLogin?O(o.firstLogin):"—",small:!0,icon:"history"},{label:"Last seen",value:o!=null&&o.lastLogin?O(o.lastLogin):"—",small:!0,icon:"pulse",tone:"note"}]}),e.jsxs(oe,{cols:"wide",children:[e.jsx(A,{title:"Connections per day",icon:"chart",tone:"info",children:e.jsx(ys,{data:a.days,labelOf:r=>r.day,valueOf:r=>r.logins+r.failures,toneOf:r=>r.failures>r.logins?"bad":void 0,title:r=>`${r.day}: ${r.logins} in${r.failures?`, ${r.failures} refused`:""}`})}),e.jsxs("div",{className:"stack",children:[e.jsx(A,{title:"Identity",icon:"tv",tone:"info",children:e.jsxs("div",{className:"list",children:[e.jsx("div",{className:"list-item",children:e.jsxs("div",{className:"list-body",children:[e.jsx("b",{children:"Person"}),e.jsx("p",{children:(o==null?void 0:o.username)||"unknown"})]})}),e.jsx("div",{className:"list-item",children:e.jsxs("div",{className:"list-body",children:[e.jsx("b",{children:"Device id"}),e.jsx("p",{className:"mono",children:a.deviceId})]})}),e.jsx("div",{className:"list-item",children:e.jsxs("div",{className:"list-body",children:[e.jsx("b",{children:"Running"}),e.jsx("p",{className:"mono",children:(o==null?void 0:o.clientVersion)||"unknown"})]})})]})}),e.jsx(A,{title:"Builds",intro:"Kept per television rather than per session, so it survives a sign-out.",icon:"upload",tone:"note",children:a.versions.length===0?e.jsx(Z,{children:"No build history for this television."}):e.jsx("div",{className:"list",children:a.versions.map(r=>e.jsx("div",{className:"list-item",children:e.jsxs("div",{className:"list-body",children:[e.jsx("b",{className:"mono",children:r.version}),e.jsxs("p",{children:[O(r.firstSeen)," → ",O(r.lastSeen)]})]})},r.version))})})]})]}),e.jsx(A,{title:"Addresses",icon:"globe",tone:"data",children:a.addresses.length===0?e.jsx(Z,{children:"No addresses recorded in this window."}):e.jsx("div",{className:"chips",children:a.addresses.map(r=>e.jsxs(se,{tone:r.failures>0?"warn":"data",children:[r.ipAddress," · ",N(r.logins),r.failures>0?` (+${N(r.failures)} refused)`:""]},r.ipAddress))})}),e.jsx(A,{title:"Every attempt",icon:"key",tone:"ok",actions:e.jsxs("span",{className:"filter-summary",children:[N(a.total)," in this window"]}),children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nowrap",children:"When"}),e.jsx("th",{children:"Person"}),e.jsx("th",{className:"nowrap",children:"Address"}),e.jsx("th",{children:"Build"}),e.jsx("th",{children:"Method"}),e.jsx("th",{children:"Outcome"})]})}),e.jsx("tbody",{children:a.events.length===0?e.jsx(X,{columns:6,children:"This television has not connected in the selected window."}):a.events.map(r=>e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",children:O(r.occurredAt)}),e.jsx("td",{children:r.username||e.jsx("span",{className:"quiet",children:"unknown"})}),e.jsx("td",{className:"mono nowrap",children:r.ipAddress||"—"}),e.jsx("td",{className:"mono",children:r.clientVersion||"—"}),e.jsx("td",{className:"muted",children:r.method}),e.jsx("td",{className:"nowrap",children:r.success?r.newDevice?e.jsx(M,{tone:"info",children:"first sign-in"}):e.jsx(M,{tone:"ok",children:"got in"}):e.jsx(M,{tone:"bad",children:r.failureReason||"refused"})})]},r.id))})]})})})]}):null]})}function kn(){const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),[o,d]=x.useState(!1),r=(s==null?void 0:s.library.byType)??{},j=!!(s!=null&&s.syncRunning),w=p=>t(p,async()=>{await a(()=>F.post("/admin/api/sync",{kind:p}),p==="full"?"Full re-import started.":"Import started."),d(!1),await i()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Library",intro:"Import and inspect the catalogue Memby ranks."}),e.jsx(B,{message:n}),l||!s?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"items",value:N(s.library.total),icon:"library",tone:"data"},...Object.keys(r).sort().map(p=>({label:p,value:N(r[p]),icon:"list"})),{label:"last import",value:O(s.library.lastSynced),small:!0,icon:"clock"}]}),e.jsx(A,{title:"Import the catalogue",intro:"Emby's catalogue is copied here so search and the recommendation candidate pool can be answered from one indexed table. Watched, favourite and resume state is deliberately not stored — that is per person and still comes from Emby live.",icon:"library",tone:"data",footer:e.jsx("span",{className:"hint",children:j?"Import running…":`An incremental import runs automatically every ${s.syncEvery}.`}),children:e.jsxs("div",{className:"row",children:[e.jsx(R,{variant:"primary",icon:"sync",disabled:j,busy:c==="incremental",onClick:()=>void w("incremental"),children:"Sync new items"}),e.jsx(R,{icon:"database",disabled:j,onClick:()=>d(!0),children:"Full re-import"})]})})]}),o?e.jsx(he,{title:"Re-import the entire library?",body:"A full pass mark-and-sweeps the catalogue and can take several minutes on a large library. Televisions keep reading the current table throughout.",confirmLabel:"Re-import",busy:c==="full",onConfirm:()=>void w("full"),onCancel:()=>d(!1)}):null]})}const Nn={imdb:"IMDb",tomatoes:"Rotten Tomatoes",audience:"Rotten Tomatoes Audience",metacritic:"Metacritic",letterboxd:"Letterboxd",rogerebert:"Roger Ebert",tmdb:"TMDb",trakt:"Trakt",mal:"MyAnimeList",anilist:"AniList",anidb:"AniDB",kitsu:"Kitsu",score:"MDBList Score",score_average:"MDBList Average"};function Sn(){const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),[o,d]=x.useState(!1),[r,j]=x.useState(""),[w,p]=x.useState(!1),[m,f]=x.useState([]),[u,v]=x.useState(!1),b=s==null?void 0:s.mdblist;x.useEffect(()=>{u||!b||(d(b.enabled),f(b.sources??[]))},[b,u]);const S=()=>t("save",async()=>{await a(()=>F.post("/admin/api/mdblist-settings",{enabled:o,apiKey:r.trim(),clearApiKey:w,sources:m}),"Ratings settings saved."),j(""),p(!1),v(!1),await i()}),h=(b==null?void 0:b.cachedTitles)??0;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Movie ratings",intro:"Optional MDBList scores on films and shows."}),e.jsx(B,{message:n}),l||!b?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"titles stored",value:N(h),icon:"database",tone:"data"},{label:"due to be re-checked",value:N(b.staleTitles),icon:"sync",tone:"warn"},{label:"sources shown",value:N((b.sources??[]).length),icon:"star",tone:"note"},{label:"API key",value:b.apiKeyConfigured?"saved":"not set",small:!0,icon:"key",tone:b.apiKeyConfigured?"ok":void 0}]}),e.jsxs(oe,{cols:"2",children:[e.jsxs(A,{title:"MDBList connection",intro:"The key stays on this server and a failure never blocks a television. Every rating fetched is stored here permanently and re-checked about once a month, so browsing the library costs nothing after the first look at a title.",icon:"star",tone:"note",actions:o?e.jsxs(M,{tone:"ok",children:["on · ",m.length," sources"]}):e.jsx(M,{children:b.apiKeyConfigured?"off · key saved":"off · no key"}),children:[e.jsx(z,{label:"Show external ratings on televisions",hint:"Off leaves the stored ratings in place.",checked:o,onChange:g=>{d(g),v(!0)}}),e.jsx(D,{label:"API key",hint:"Leave blank to keep the key that is already saved.",children:e.jsx("input",{type:"password",autoComplete:"new-password",value:r,placeholder:b.apiKeyConfigured?"Saved key (leave blank to keep)":"Paste an API key",onChange:g=>j(g.target.value)})}),e.jsx(z,{label:"Remove the saved key",checked:w,onChange:p})]}),e.jsx(A,{title:"Sources shown on televisions",intro:"A title with none of these has no ratings strip at all, which is the honest answer — nothing stands in for a score that was never fetched.",icon:"list",tone:"data",children:(b.availableSources??[]).length===0?e.jsx(Z,{children:"No rating sources are available."}):e.jsx("div",{className:"checks columns",children:(b.availableSources??[]).map(g=>e.jsx(z,{label:Nn[g]??g,checked:m.includes(g),onChange:E=>{v(!0),f(C=>E?[...C,g]:C.filter(V=>V!==g))}},g))})})]}),e.jsx(A,{children:e.jsxs("div",{className:"row",children:[e.jsx(R,{variant:"primary",busy:c==="save",onClick:()=>void S(),children:"Save ratings settings"}),e.jsx("span",{className:"hint",children:h?"Ratings are fetched as televisions browse, never on the request path.":"No ratings stored yet. They are saved as televisions browse the library."})]})})]})]})}function Cn(){var w;const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),o=(s==null?void 0:s.requestUsers)??[],d=((w=s==null?void 0:s.requestPolicy)==null?void 0:w.allowedUserIds)??[],r=x.useMemo(()=>new Map(((s==null?void 0:s.requestUsage)??[]).map(p=>[p.userId,p])),[s==null?void 0:s.requestUsage]),j=p=>t(`access-${p}`,async()=>{const m=d.includes(p)?d.filter(f=>f!==p):[...d,p];await a(()=>F.post("/admin/api/request-policy",{allowedUserIds:m}),m.includes(p)?"Request access granted.":"Request access removed."),await i()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Media requests",intro:"Who can ask for something the library does not have."}),e.jsx(B,{message:n}),l?e.jsx(W,{rows:2}):e.jsxs(e.Fragment,{children:[e.jsx(A,{title:"Where a request goes",intro:"Movies follow Radarr’s policy. Series follow the dedicated Sonarr request policy: monitored as normal, with backlog searching only when an operator enables it under Integrations.",icon:"inbox",tone:"info",actions:e.jsxs(e.Fragment,{children:[e.jsxs(M,{tone:s!=null&&s.radarrReady?"ok":"bad",children:["Movies ",s!=null&&s.radarrReady?"ready":"not configured"]}),e.jsxs(M,{tone:s!=null&&s.sonarrReady?"ok":"bad",children:["Series ",s!=null&&s.sonarrReady?"ready":"not configured"]})]}),children:!(s!=null&&s.radarrReady)&&!(s!=null&&s.sonarrReady)?e.jsx(Z,{children:"Neither Radarr nor Sonarr is configured, so a request would have nowhere to go. The button stays hidden on every television until one of them is."}):null}),e.jsx(A,{title:"Request access and activity",intro:"One button grants or removes access. A recorded request has already been sent to Radarr or Sonarr; Memby does not duplicate their download state.",icon:"people",tone:"note",children:o.length===0?e.jsx(Z,{children:"No one has signed in yet."}):e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"User"}),e.jsx("th",{children:"Last seen"}),e.jsx("th",{className:"num",children:"Sent to services"}),e.jsx("th",{children:"Last request"}),e.jsx("th",{children:"Access"})]})}),e.jsx("tbody",{children:o.map(p=>{const m=r.get(p.id),f=d.includes(p.id);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("b",{children:p.username})}),e.jsx("td",{className:"muted nowrap",children:O(p.lastSeen)}),e.jsx("td",{className:"num",children:(m==null?void 0:m.requests)??0}),e.jsx("td",{className:"muted nowrap",children:m!=null&&m.lastRequest?O(m.lastRequest):"—"}),e.jsx("td",{children:e.jsx(R,{size:"sm",variant:f?"quiet":"primary",busy:c===`access-${p.id}`,onClick:()=>void j(p.id),children:f?"Remove access":"Give access"})})]},p.id)})})]})})})]})]})}function Mn(){const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),[o,d]=x.useState(!1),r=s==null?void 0:s.forYou,j=!!(s!=null&&s.forYouRunning),w=(p,m,f)=>t(m,async()=>{await a(()=>F.post("/admin/api/for-you",{action:p}),f),d(!1),await i()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"For You",intro:"The prepared pools personalised rows are drawn from."}),e.jsx(B,{message:n}),l?e.jsx(W,{rows:2}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"Tracearr sessions",value:N((r==null?void 0:r.tracearrSessions)??0),icon:"play",tone:"info"},{label:"user profiles",value:N((r==null?void 0:r.profiles)??0),icon:"people",tone:"note"},{label:"ranked candidates",value:N((r==null?void 0:r.candidates)??0),icon:"sparkle",tone:"note"},{label:"last full import",value:O(r==null?void 0:r.lastFullImport),small:!0,icon:"clock"}]}),e.jsx(A,{title:"Pool maintenance",intro:"Prepared pools refresh in the background; these are the manual versions of the same work. A rebuild is safe at any time — televisions read the last finished pool until a new one lands.",icon:"sparkle",tone:"note",footer:e.jsx("span",{className:"hint",children:j?"For You maintenance running…":"Prepared pools normally refresh in the background."}),children:e.jsxs("div",{className:"row",children:[e.jsx(R,{variant:"primary",icon:"download",disabled:j,busy:c==="import",onClick:()=>void w("incremental-import","import","Import started."),children:"Import recent sessions"}),e.jsx(R,{icon:"database",disabled:j,onClick:()=>d(!0),children:"Full Tracearr backfill"}),e.jsx(R,{icon:"sync",disabled:j,busy:c==="rebuild",onClick:()=>void w("rebuild-all","rebuild","Rebuild started."),children:"Rebuild all pools"})]})}),e.jsx(A,{title:"Reading a person's scores",intro:"The inspector re-runs the shared weighted scorer over one person's prepared pool, after Emby permission and parental-control filtering, and shows every component and evidence reason behind the order.",icon:"search",tone:"info",actions:e.jsx(ne,{to:"/admin/inspector",children:"Open the inspector"}),children:e.jsx(e.Fragment,{})})]}),o?e.jsx(he,{title:"Backfill all Tracearr history?",body:"Every session is re-read and every active user's pool is rebuilt. It is safe at any time — televisions keep reading the last finished pool — but on a long history it takes a while.",confirmLabel:"Backfill",busy:c==="full",onConfirm:()=>void w("full-import","full","Backfill started."),onCancel:()=>d(!1)}):null]})}const En=[["Genre","genres"],["Studio","studios"],["Actor","actors"],["Director","directors"],["Franchise","franchises"],["Runtime","runtimeRanges"],["Age rating","ageRatings"],["Community rating","communityRatings"],["Release period","releasePeriods"],["Content type","contentTypes"]];function Rn(s){return s?En.flatMap(([n,l])=>Object.entries(s[l]??{}).map(([i,a])=>({dimension:n,name:i,weight:a.weight??0,evidence:a.evidence??0}))).sort((n,l)=>Math.abs(l.weight)-Math.abs(n.weight)):[]}const Ge=s=>`${s>=0?"+":""}${s.toFixed(3)}`;function An(){const{status:s}=ie(),{wrap:n}=Q(),{busy:l,run:i}=Y(),[a,c]=x.useState(""),[t,o]=x.useState("default"),[d,r]=x.useState("0"),[j,w]=x.useState(""),[p,m]=x.useState(null),[f,u]=x.useState("Choose a person to inspect their recommendations."),[v,b]=x.useState(""),S=(s==null?void 0:s.requestUsers)??[],h=()=>i("run",async()=>{if(!a){b("Choose a person to pressure-test.");return}b(""),u("Running the permission check and the scorer…");const y=new URLSearchParams({userId:a,context:t,minutes:d||"0",limit:"100"});j&&y.set("at",new Date(j).toISOString());const L=await n(()=>F.get(`/admin/api/recommendations?${y.toString()}`));L?(m(L),u(`Scored at ${new Date().toLocaleTimeString()}.`)):u("Pressure test failed.")}),g=Rn((p==null?void 0:p.profile)??null).slice(0,24),E=(p==null?void 0:p.actions)??[],C=(p==null?void 0:p.items)??[],V=(p==null?void 0:p.profileMeta)??{};return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Score inspector",intro:"Re-run the ranker for one person and read every component."}),e.jsx(B,{message:v}),e.jsx(A,{title:"Run a pressure test",intro:"Nothing is changed by running this. It scores the person's prepared pool as the launcher would, in the context you choose.",icon:"search",tone:"info",footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:l==="run",onClick:()=>void h(),children:"Run pressure test"}),e.jsx("span",{className:"hint",children:f})]}),children:e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"Person",children:e.jsxs("select",{value:a,onChange:y=>c(y.target.value),children:[e.jsx("option",{value:"",children:"Choose a person…"}),S.map(y=>e.jsx("option",{value:y.id,children:y.username},y.id))]})}),e.jsx(D,{label:"Context",children:e.jsxs("select",{value:t,onChange:y=>o(y.target.value),children:[e.jsx("option",{value:"default",children:"Default"}),e.jsx("option",{value:"bedtime",children:"One episode before bed"}),e.jsx("option",{value:"hidden",children:"Hidden library"}),e.jsx("option",{value:"new-releases",children:"Recent new releases"})]})}),e.jsx(D,{label:"Available minutes",children:e.jsx("input",{type:"number",min:0,max:360,value:d,onChange:y=>r(y.target.value)})}),e.jsx(D,{label:"Evaluate at",children:e.jsx("input",{type:"datetime-local",value:j,onChange:y=>w(y.target.value)})})]})}),p?e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"prepared pool",value:N(p.poolCandidates),icon:"database",tone:"data"},{label:"permission eligible",value:N(p.permissionEligible),icon:"shield",tone:"ok"},{label:"ranked result",value:N(C.length),icon:"sparkle",tone:"note"},{label:"source events",value:N(V.sourceEvents??0),icon:"pulse",tone:"info"},{label:"algorithm",value:V.algorithmVersion||"—",small:!0,icon:"chip"},{label:"pool built",value:O(V.poolBuiltAt),small:!0,icon:"clock"}]}),e.jsxs(A,{title:"Profile evidence",intro:"The strongest learned affinities, and every explicit action this person has taken.",icon:"sparkle",tone:"note",children:[g.length===0?e.jsx(Z,{children:"No repeated affinity evidence yet; cold-start priors apply."}):e.jsx("div",{className:"chips",children:g.map(y=>e.jsxs(se,{tone:y.weight<0?"bad":void 0,children:[y.dimension,": ",y.name," ",Ge(y.weight)," · n=",N(y.evidence)]},`${y.dimension}:${y.name}`))}),E.length===0?e.jsx(Z,{children:"No explicit recommendation actions."}):e.jsx("div",{className:"chips",children:E.map((y,L)=>e.jsxs(se,{tone:"ok",children:[y.action,": ",y.title||y.itemId]},`${y.action}:${L}`))})]}),C.length===0?e.jsx(A,{children:e.jsx(Z,{children:"No candidates survived this context, the explicit exclusions and the permission filter."})}):e.jsx(oe,{children:C.map((y,L)=>{const ee=y.explanation??{},re=Object.entries(ee.components??{}).sort((T,H)=>Math.abs(H[1])-Math.abs(T[1])),K=y.exposure??{},I=[y.type,y.year,y.runtimeMinutes?`${y.runtimeMinutes} min`:null,...y.genres??[]].filter(Boolean).join(" · ");return e.jsxs(A,{title:`#${L+1} · ${y.title}`,intro:I,actions:e.jsx(se,{tone:"ok",children:Number(ee.total??0).toFixed(3)}),children:[e.jsxs("p",{className:"hint",children:[y.preparedReason||"No legacy prepared explanation",y.compatibilityLabel?` · ${y.compatibilityLabel}`:""]}),e.jsxs("div",{className:"chips",children:[(ee.reasonCodes??[]).map(T=>e.jsx(se,{tone:"ok",children:T},T)),re.map(([T,H])=>e.jsxs(se,{tone:H<0?"bad":void 0,children:[T,"=",Ge(H)]},T))]}),e.jsxs("details",{children:[e.jsx("summary",{className:"muted",children:"Pool, row and exposure detail"}),e.jsxs("p",{className:"hint",children:["Base rank ",N(y.baseRank??0)," · base ",Number(y.baseScore??0).toFixed(3)," · affinity ",Number(y.affinityScore??0).toFixed(3)," · compatibility"," ",Number(y.compatibilityScore??0).toFixed(3)," · impressions"," ",N(K.impressions??0)," · focuses ",N(K.focuses??0)," · selects"," ",N(K.selects??0)]}),e.jsx("div",{className:"chips",children:(y.eligibleRows??[]).map(T=>e.jsx(se,{tone:"ok",children:T},T))}),y.preparedEvidenceTitle?e.jsxs("p",{className:"hint",children:["Prepared evidence: ",y.preparedEvidenceTitle]}):null]})]},`${L}:${y.title}`)})})]}):null]})}const In=4,je=[{id:"home",label:"Home",type:"films and television shows"},{id:"movies",label:"Movies",type:"films"},{id:"tv_shows",label:"TV Shows",type:"television shows"}],ge=()=>({pinnedItems:[],primeSubtitle:""}),De=[{value:1,short:"Mon",label:"Monday"},{value:2,short:"Tue",label:"Tuesday"},{value:3,short:"Wed",label:"Wednesday"},{value:4,short:"Thu",label:"Thursday"},{value:5,short:"Fri",label:"Friday"},{value:6,short:"Sat",label:"Saturday"},{value:0,short:"Sun",label:"Sunday"}];function Ze(s){const n=s.getTimezoneOffset()*6e4;return new Date(s.getTime()-n).toISOString().slice(0,16)}function Je(s){return!!(s&&Number.isFinite(new Date(s).getTime())&&new Date(s).getFullYear()>=2e3)}function $n(s){return s.frequency??"once"}function Tn(s){if(s.frequency==="daily")return`Every day · ${s.startTime}–${s.endTime}`;if(s.frequency==="weekly"){const n=De.filter(i=>(s.weekdays??[]).includes(i.value));return`${(n.length===7?"Every day":n.map(i=>i.short).join(", "))||"No days selected"} · ${s.startTime}–${s.endTime}`}return`${s.startAt?new Date(s.startAt).toLocaleString():"Start missing"} → ${s.endAt?new Date(s.endAt).toLocaleString():"End missing"}`}function Ye(s,n){const l=new Date;l.setMinutes(Math.ceil(l.getMinutes()/30)*30,0,0);const i=new Date(l.getTime()+2*60*60*1e3),a=n==="home"||n==="movies"&&s.type==="Movie"||n==="tv_shows"&&s.type==="Series";return{id:crypto.randomUUID(),itemId:s.id,startAt:l.toISOString(),endAt:i.toISOString(),priority:0,enabled:!0,placements:[a?n:"home"]}}function Ln(){var I,T,H;const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a,show:c}=Q(),{busy:t,run:o}=Y(),[d,r]=x.useState("home"),[j,w]=x.useState({home:ge(),movies:ge(),tv_shows:ge()}),[p,m]=x.useState(!1),[f,u]=x.useState(""),[v,b]=x.useState(null),[S,h]=x.useState([]),[g,E]=x.useState(null),C=s==null?void 0:s.heroPolicy;x.useEffect(()=>{var k,q,$;p||!C||(w({home:((k=C.placements)==null?void 0:k.home)??{pinnedItems:C.pinnedItems??[],primeSubtitle:C.primeSubtitle??""},movies:((q=C.placements)==null?void 0:q.movies)??ge(),tv_shows:(($=C.placements)==null?void 0:$.tv_shows)??ge()}),h(C.schedules??[]))},[C,p]);const V=()=>o("search",async()=>{const k=f.trim();if(!k)return;const q=await a(()=>F.get(`/admin/api/hero/search?q=${encodeURIComponent(k)}`));q&&b(q.items??[])}),y=j[d],L=y.pinnedItems??[],ee=k=>{w(q=>({...q,[d]:{...q[d],...k}})),m(!0)},re=k=>{if(!L.some(q=>q.id===k.id)){if(L.length>=In){c("Remove a pinned title before adding another.","bad");return}ee({pinnedItems:[...L,k]})}},K=()=>o("save",async()=>{await a(()=>F.post("/admin/api/hero-policy",{placements:Object.fromEntries(Object.entries(j).map(([k,q])=>[k,{pinnedItemIds:(q.pinnedItems??[]).map($=>$.id),primeSubtitle:q.primeSubtitle.trim()}])),schedules:S}),"Hero saved."),m(!1),await i()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Featured content",intro:"Manage an independent, backend-resolved hero for Home, Movies and TV Shows."}),e.jsx(B,{message:n}),l?e.jsx(W,{rows:2}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:je.map(k=>{var le;const q=j[k.id],$=S.filter(me=>me.enabled&&(me.placements??["home"]).includes(k.id)).sort((me,Cs)=>Cs.priority-me.priority)[0],P=(q.pinnedItems??[]).length?"Manual":$?"Schedule ready":"Automatic",ce=(le=C==null?void 0:C.items)==null?void 0:le.find(me=>me.id===($==null?void 0:$.itemId)),de=(q.pinnedItems??[]).map(me=>me.name).join(", ")||(ce==null?void 0:ce.name)||($==null?void 0:$.itemId)||"Resolved for each viewer";return e.jsx(A,{title:k.label,intro:`${P} · ${de}`,tone:k.id===d?"info":void 0,children:e.jsxs(R,{size:"sm",variant:"quiet",onClick:()=>r(k.id),children:["Manage ",k.label]})},k.id)})}),e.jsx("div",{className:"tabs",role:"tablist","aria-label":"Hero placement",children:je.map(k=>e.jsx(R,{variant:d===k.id?"primary":"quiet",onClick:()=>r(k.id),children:k.label},k.id))}),e.jsxs(A,{title:`${(I=je.find(k=>k.id===d))==null?void 0:I.label} hero`,intro:`Pinned ${(T=je.find(k=>k.id===d))==null?void 0:T.type} lead this section only. Empty places use this placement’s automatic selection.`,icon:"star",tone:"note",footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:t==="save",onClick:()=>void K(),children:"Save hero"}),e.jsx(R,{onClick:()=>{ee({pinnedItems:[]})},children:"Clear pins"}),p?e.jsx("span",{className:"hint",children:"Unsaved changes."}):null]}),children:[L.length===0?e.jsx(Z,{children:"No titles are pinned. The hero is entirely release-aware and automatic."}):e.jsx("div",{className:"hero-pins",children:L.map((k,q)=>e.jsxs("div",{className:"hero-pin",children:[e.jsx("span",{className:"hero-pin-order",children:q+1}),e.jsxs("span",{children:[e.jsx("b",{children:k.name}),e.jsxs("small",{children:[k.type,k.year?` · ${k.year}`:""]})]}),e.jsx(R,{size:"sm",icon:"clock",onClick:()=>E(Ye(k,d)),children:"Schedule"}),e.jsx(R,{variant:"quiet",size:"sm",icon:"close",title:`Remove ${k.name}`,onClick:()=>ee({pinnedItems:L.filter($=>$.id!==k.id)})})]},k.id))}),e.jsx(D,{label:"Prime-card subtitle",hint:"Optional wording under the large first card. Leave blank to use Memby's natural release or rating reason.",children:e.jsx("input",{type:"text",maxLength:160,value:y.primeSubtitle,placeholder:"Leave blank for the automatic reason",onChange:k=>{ee({primeSubtitle:k.target.value})}})})]}),e.jsx(A,{title:"Hero schedule",intro:"The gateway applies these rules in server time. Manual pins win first; otherwise the highest-priority active schedule wins, followed by Memby’s automatic hero.",icon:"clock",tone:"info",actions:e.jsx(M,{tone:"info",children:(C==null?void 0:C.timeZone)||"server local time"}),footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:t==="save",onClick:()=>void K(),children:"Save schedule"}),e.jsx("span",{className:"hint",children:"Daily and weekly rules repeat until you switch them off."})]}),children:S.length===0?e.jsx(Z,{children:"No scheduled heroes yet. Use Schedule beside a pinned or searched title."}):e.jsx("div",{className:"hero-schedule-list",children:[...S].sort((k,q)=>Number(q.enabled)-Number(k.enabled)||q.priority-k.priority).map(k=>{const q=[...(C==null?void 0:C.items)??[],...L,...v??[]].find($=>$.id===k.itemId);return e.jsxs("article",{className:"hero-schedule","data-enabled":k.enabled||void 0,children:[e.jsxs("div",{className:"hero-schedule-time",children:[e.jsx("b",{children:k.frequency==="weekly"?"Weekly":k.frequency==="daily"?"Daily":"Once"}),e.jsx("span",{children:k.frequency?k.startTime:k.startAt?new Date(k.startAt).toLocaleDateString():"—"})]}),e.jsxs("div",{className:"hero-schedule-main",children:[e.jsxs("div",{className:"hero-schedule-title",children:[e.jsx("h3",{children:(q==null?void 0:q.name)??k.itemId}),e.jsx(M,{tone:k.enabled?"ok":void 0,children:k.enabled?"enabled":"paused"})]}),e.jsx("p",{children:Tn(k)}),e.jsxs("div",{className:"chips",children:[(k.placements??["home"]).map($=>{var P;return e.jsx("span",{className:"chip",children:(P=je.find(ce=>ce.id===$))==null?void 0:P.label},$)}),k.priority!==0?e.jsxs("span",{className:"chip",children:["Priority ",k.priority]}):null]})]}),e.jsxs("div",{className:"hero-schedule-actions",children:[e.jsx(R,{size:"sm",onClick:()=>E({...k}),children:"Edit"}),e.jsx(R,{size:"sm",variant:"quiet",onClick:()=>{h($=>$.map(P=>P.id===k.id?{...P,enabled:!P.enabled}:P)),m(!0)},children:k.enabled?"Pause":"Enable"}),e.jsx(R,{size:"sm",variant:"quiet",onClick:()=>{h($=>$.filter(P=>P.id!==k.id)),m(!0)},children:"Remove"})]})]},k.id)})})}),e.jsxs(A,{title:"Find a title",intro:`Search the imported Emby catalogue. Add a result to the selected ${(H=je.find(k=>k.id===d))==null?void 0:H.label} placement; switch tabs to show it in more than one section.`,icon:"search",tone:"info",children:[e.jsxs("div",{className:"field-row",children:[e.jsx(D,{label:"Title",grow:!0,children:e.jsx("input",{type:"search",value:f,placeholder:"Search films and television shows",onChange:k=>u(k.target.value),onKeyDown:k=>{k.key==="Enter"&&V()}})}),e.jsx(R,{busy:t==="search",icon:"search",onClick:()=>void V(),children:"Search"})]}),v===null?null:v.length===0?e.jsx(Z,{children:"No playable films or series matched that search."}):e.jsx(oe,{children:v.map(k=>e.jsx(A,{title:k.name,intro:`${k.type||"Title"} · ${k.year||"Year unknown"}`,children:e.jsxs("div",{className:"row",children:[e.jsx(R,{size:"sm",icon:"plus",disabled:L.some(q=>q.id===k.id)||d==="movies"&&k.type!=="Movie"||d==="tv_shows"&&k.type!=="Series",onClick:()=>re(k),children:L.some(q=>q.id===k.id)?"Pinned":"Add to hero"}),e.jsx(R,{size:"sm",icon:"clock",onClick:()=>E(Ye(k,d)),children:"Schedule"})]})},k.id))})]})]}),g?e.jsx(Dn,{schedule:g,item:[...(C==null?void 0:C.items)??[],...L,...v??[]].find(k=>k.id===g.itemId),timeZone:(C==null?void 0:C.timeZone)||"server local time",isNew:!S.some(k=>k.id===g.id),onCancel:()=>E(null),onSave:k=>{h(q=>q.some($=>$.id===k.id)?q.map($=>$.id===k.id?k:$):[...q,k]),E(null),m(!0)}}):null]})}function Dn({schedule:s,item:n,timeZone:l,isNew:i,onSave:a,onCancel:c}){const[t,o]=x.useState({...s,weekdays:[...s.weekdays??[]]}),d=$n(t),r=u=>{const v=new Date,b=new Date(v.getTime()+2*60*60*1e3);o(S=>{var h;return u==="once"?{...S,frequency:void 0,startAt:Je(S.startAt)?S.startAt:v.toISOString(),endAt:Je(S.endAt)?S.endAt:b.toISOString()}:{...S,frequency:u,startTime:S.startTime||"18:00",endTime:S.endTime||"22:00",weekdays:u==="weekly"?(h=S.weekdays)!=null&&h.length?S.weekdays:[1,2,3,4,5]:[]}})},j=t.placements??["home"],w=u=>u==="home"||u==="movies"&&(n==null?void 0:n.type)==="Movie"||u==="tv_shows"&&(n==null?void 0:n.type)==="Series",p=!!(t.startAt&&t.endAt&&new Date(t.endAt)>new Date(t.startAt)),m=!!(t.startTime&&t.endTime&&t.startTime!==t.endTime&&(d!=="weekly"||(t.weekdays??[]).length>0)),f=d==="once"?p:m;return e.jsx("div",{className:"scrim",onPointerDown:u=>u.target===u.currentTarget&&c(),children:e.jsxs("div",{className:"dialog hero-schedule-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"hero-schedule-title",children:[e.jsxs("div",{className:"hero-schedule-dialog-head",children:[e.jsx("span",{className:"hero-schedule-kicker",children:"Hero schedule"}),e.jsx("h2",{id:"hero-schedule-title",children:(n==null?void 0:n.name)??t.itemId}),e.jsxs("p",{children:["Choose exactly when this title can lead the selected sections. Times use ",l,"."]})]}),e.jsx("div",{className:"schedule-frequency",role:"group","aria-label":"Schedule frequency",children:["once","daily","weekly"].map(u=>e.jsxs("button",{type:"button","aria-pressed":d===u,onClick:()=>r(u),children:[e.jsx("b",{children:u==="once"?"One time":u==="daily"?"Every day":"Weekly"}),e.jsx("span",{children:u==="once"?"A date range":u==="daily"?"Same time daily":"Choose days"})]},u))}),d==="once"?e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"Starts",children:e.jsx("input",{type:"datetime-local",value:t.startAt?Ze(new Date(t.startAt)):"",onChange:u=>o(v=>({...v,startAt:u.target.value?new Date(u.target.value).toISOString():void 0}))})}),e.jsx(D,{label:"Ends",children:e.jsx("input",{type:"datetime-local",value:t.endAt?Ze(new Date(t.endAt)):"",onChange:u=>o(v=>({...v,endAt:u.target.value?new Date(u.target.value).toISOString():void 0}))})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"Starts each time",children:e.jsx("input",{type:"time",value:t.startTime??"",onChange:u=>o(v=>({...v,startTime:u.target.value}))})}),e.jsx(D,{label:"Ends each time",hint:"An earlier end time continues into the following day.",children:e.jsx("input",{type:"time",value:t.endTime??"",onChange:u=>o(v=>({...v,endTime:u.target.value}))})})]}),d==="weekly"?e.jsxs("div",{className:"schedule-days",children:[e.jsxs("div",{className:"schedule-days-head",children:[e.jsx("b",{children:"Days"}),e.jsxs("div",{children:[e.jsx("button",{type:"button",onClick:()=>o(u=>({...u,weekdays:[1,2,3,4,5]})),children:"Weekdays"}),e.jsx("button",{type:"button",onClick:()=>o(u=>({...u,weekdays:[6,0]})),children:"Weekend"}),e.jsx("button",{type:"button",onClick:()=>o(u=>({...u,weekdays:De.map(v=>v.value)})),children:"Every day"})]})]}),e.jsx("div",{className:"schedule-day-grid",children:De.map(u=>{const v=(t.weekdays??[]).includes(u.value);return e.jsx("button",{type:"button","aria-pressed":v,title:u.label,onClick:()=>o(b=>({...b,weekdays:v?(b.weekdays??[]).filter(S=>S!==u.value):[...b.weekdays??[],u.value]})),children:u.short},u.value)})})]}):null]}),e.jsxs("div",{className:"schedule-options",children:[e.jsxs("div",{children:[e.jsx("span",{className:"schedule-option-label",children:"Show in"}),e.jsx("div",{className:"schedule-placement-grid",children:je.map(u=>e.jsx(z,{label:u.label,checked:j.includes(u.id),disabled:!w(u.id),onChange:v=>o(b=>{const S=b.placements??["home"],h=v?[...S,u.id]:S.filter(g=>g!==u.id);return{...b,placements:h.length?[...new Set(h)]:S}})},u.id))})]}),e.jsx(D,{label:"Priority",hint:"Higher rules win when schedules overlap.",children:e.jsx("input",{type:"number",min:-1e3,max:1e3,step:10,value:t.priority,onChange:u=>o(v=>({...v,priority:Number(u.target.value)}))})})]}),e.jsx(z,{label:"Schedule enabled",hint:"Pause it without losing its days and times.",checked:t.enabled,onChange:u=>o(v=>({...v,enabled:u}))}),e.jsxs("div",{className:"dialog-actions",children:[e.jsx(R,{variant:"quiet",onClick:c,children:"Cancel"}),e.jsx(R,{variant:"primary",disabled:!f,onClick:()=>a(t),children:i?"Add rule":"Save rule"})]})]})})}function qn(){const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),[o,d]=x.useState(null),r=s==null?void 0:s.features,j=(r==null?void 0:r.features)??[],w=(s==null?void 0:s.clients)??[],p=(r==null?void 0:r.revision)??0,m=(b,S,h,g)=>t(S,async()=>{await a(()=>F.post("/admin/api/features",{action:b,expectedRevision:p,overrides:g??{}}),h),d(null),await i()}),f=w.filter(b=>(b.capabilities??[]).includes("server_features_v1")).length,u=!!(r!=null&&r.safeMode),v=(b,S)=>({...Object.fromEntries(j.filter(h=>h.source==="override").map(h=>[h.key,h.enabled])),[b]:S});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Features",intro:"Roll out, stop and recover optional behaviour with no app release."}),e.jsx(B,{message:n}),l||!r?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(A,{title:"Control plane",intro:"Every optional feature has a safe default, an explicit override and a remote recovery path. Safe mode turns all of them off at once; sign-in, browsing and playback are never optional.",icon:"sliders",tone:"ok",actions:e.jsx(R,{variant:u?void 0:"danger",busy:c==="safe",onClick:()=>u?void m("leave-safe-mode","safe","Safe mode ended."):d({action:"safe-mode",title:"Enable safe mode?",body:"Every optional feature is disabled immediately on every television. Core sign-in, browsing and playback remain available.",label:"Enable safe mode"}),children:u?"Leave safe mode":"Enable safe mode"}),children:e.jsx(ws,{tiles:[{label:"features active",value:`${j.filter(b=>b.enabled).length} / ${j.length}`},{label:"explicit overrides",value:N(j.filter(b=>b.source==="override").length)},{label:"televisions reporting the control plane",value:`${f} / ${w.length}`},{label:"published revision",value:`r${N(p)}`}]})}),e.jsx(oe,{cols:"2",children:j.length===0?e.jsx(A,{title:"Nothing registered",icon:"sliders",children:e.jsx(Z,{children:"No server features are registered."})}):j.map(b=>e.jsxs(A,{title:b.name,intro:b.description,actions:e.jsx(M,{tone:b.enabled?"ok":void 0,children:b.enabled?"active":"off"}),footer:e.jsxs("span",{className:"hint",children:["↳ ",b.recovery]}),children:[e.jsx(z,{label:b.enabled?"On":"Off",hint:"Changing this applies the feature policy to every compatible television.",checked:b.enabled,disabled:c===b.key,onChange:S=>d({action:"feature",key:b.key,enabled:S,title:`${S?"Turn on":"Turn off"} ${b.name}?`,body:`${S?"Enable":"Disable"} this feature for every compatible television. ${b.recovery}`,label:S?"Turn on":"Turn off"})}),e.jsxs("div",{className:"chips",children:[e.jsx(se,{children:b.key}),e.jsxs(se,{children:["protocol ",N(b.minimumProtocol),"+"]}),e.jsx(se,{tone:b.compatible?"ok":"warn",children:b.compatible?"server compatible":"compatibility blocked"}),e.jsx(se,{tone:"note",children:b.area})]})]},b.key))}),e.jsx(A,{children:e.jsxs("div",{className:"row",children:[e.jsx(R,{disabled:!r.canRollback,onClick:()=>d({action:"rollback",title:"Roll back one revision?",body:"The previous published feature revision is restored on every television.",label:"Roll back"}),children:"Roll back one revision"}),e.jsx(R,{onClick:()=>d({action:"reset",title:"Clear every override?",body:"All features return to their safe software defaults.",label:"Clear overrides"}),children:"Clear all overrides"}),e.jsx("span",{className:"spacer"}),u?e.jsx(M,{tone:"warn",children:"safe mode · optional features off"}):e.jsxs(M,{tone:"ok",children:["live · revision r",N(p)]})]})})]}),o?e.jsx(he,{title:o.title,body:o.body,confirmLabel:o.label,destructive:o.action!=="rollback",busy:c===o.action,onConfirm:()=>void m(o.action==="feature"?"save":o.action,o.action==="feature"?o.key??"feature":o.action,`${o.label} done.`,o.action==="feature"&&o.key?v(o.key,!!o.enabled):void 0),onCancel:()=>d(null)}):null]})}function Fn(){const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a,show:c}=Q(),{busy:t,run:o}=Y(),[d,r]=x.useState(!0),[j,w]=x.useState("6.5"),[p,m]=x.useState(!1);x.useEffect(()=>{var u,v;p||!s||(r(((u=s.playbackPolicy)==null?void 0:u.prerollEnabled)!==!1),w(String((((v=s.playbackPolicy)==null?void 0:v.prerollDurationMs)??6500)/1e3)))},[s,p]);const f=()=>o("save",async()=>{const u=Number(j);if(!Number.isFinite(u)||u<1||u>30){c("The preroll duration must be between 1 and 30 seconds.","bad");return}await a(()=>F.post("/admin/api/playback-policy",{prerollEnabled:d,prerollDurationMs:Math.round(u*1e3)}),"Playback policy saved."),m(!1),await i()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Playback",intro:"Presentation policy sent with every playback launch."}),e.jsx(B,{message:n}),l?e.jsx(W,{rows:1}):e.jsxs(A,{title:"Upcoming-show preroll",intro:"Sent with every playback launch. A change applies to the next title opened on every gateway-connected television; no app release is required.",icon:"play",tone:"info",actions:d?e.jsxs(M,{tone:"ok",children:["on · ",j,"s"]}):e.jsx(M,{children:"off"}),footer:e.jsx(R,{variant:"primary",busy:t==="save",onClick:()=>void f(),children:"Save playback policy"}),children:[e.jsx(z,{label:"Show the preroll before a title starts",checked:d,onChange:u=>{r(u),m(!0)}}),e.jsx("div",{className:"fields",children:e.jsx(D,{label:"Duration",hint:"Between 1 and 30 seconds. The stream is already playing behind it.",children:e.jsx("input",{type:"number",min:1,max:30,step:.5,value:j,onChange:u=>{w(u.target.value),m(!0)}})})})]})]})}function Pn(){const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),[o,d]=x.useState(null),[r,j]=x.useState(null),[w,p]=x.useState(!1),m=s==null?void 0:s.subtitles,f=m==null?void 0:m.stored;x.useEffect(()=>{o||!m||d({bazarr:m.bazarrEnabled,openSubtitles:m.openSubtitlesEnabled,key:"",clearKey:!1,username:m.openSubtitlesUsername??"",password:"",clearLogin:!1})},[m,o]);const u=h=>d(g=>g&&{...g,...h}),v=()=>t("save",async()=>{o&&(await a(()=>F.post("/admin/api/subtitle-settings",{bazarrEnabled:o.bazarr,openSubtitlesEnabled:o.openSubtitles,openSubtitlesApiKey:o.key.trim(),clearOpenSubtitlesApiKey:o.clearKey,openSubtitlesUsername:o.username.trim(),openSubtitlesPassword:o.password,clearOpenSubtitlesLogin:o.clearLogin}),"Subtitle settings saved."),d(null),await i())}),b=()=>t("test",async()=>{j(null);const h=await a(()=>F.post("/admin/api/subtitle-test"));j((h==null?void 0:h.results)??[])}),S=()=>t("clear",async()=>{await a(()=>F.post("/admin/api/subtitle-settings",{action:"clear-stored"}),"Stored subtitles deleted."),p(!1),await i()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Subtitles",intro:"Which providers a viewer may fetch a missing subtitle from."}),e.jsx(B,{message:n}),l||!m||!o?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"offered on televisions",value:m.available?"yes":"no",small:!0,icon:"captions",tone:m.available?"ok":void 0},{label:"providers on",value:N((m.bazarrEnabled&&m.bazarrConfigured?1:0)+(m.openSubtitlesEnabled?1:0)),icon:"list",tone:"note"},{label:"subtitles held",value:N((f==null?void 0:f.count)??0),icon:"database",tone:"data"},{label:"last fetched",value:O(f==null?void 0:f.latest),small:!0,icon:"clock"}]}),e.jsxs(oe,{cols:"2",children:[e.jsx(A,{title:"Bazarr",intro:"Bazarr writes the subtitle file beside the media file, so Emby finds it and the track behaves like one that was always there. Its address is deployment configuration; this switch only decides whether viewers may use it.",icon:"wrench",tone:"data",actions:m.bazarrConfigured?o.bazarr?e.jsx(M,{tone:"ok",children:"on"}):e.jsx(M,{children:"off"}):e.jsx(M,{children:"not configured"}),footer:e.jsx("span",{className:"hint",children:m.bazarrConfigured?`Configured at ${m.bazarrUrl}`:"Set MEMBY_BAZARR_URL and MEMBY_BAZARR_API_KEY to use Bazarr."}),children:e.jsx(z,{label:"Offer Bazarr in the player",hint:"Off leaves every subtitle it has already written in place.",checked:o.bazarr,disabled:!m.bazarrConfigured,onChange:h=>u({bazarr:h})})}),e.jsxs(A,{title:"OpenSubtitles",intro:"OpenSubtitles hands back a file rather than writing one, so Memby keeps what it fetches and serves it to the television itself. Titles are matched on their IMDb or TMDb id, which is exact — there is no guessing at a name.",icon:"captions",tone:"note",actions:m.openSubtitlesEnabled?e.jsx(M,{tone:m.openSubtitlesAccount?"ok":"warn",children:m.openSubtitlesAccount?"on · signed in":"on · anonymous"}):e.jsx(M,{children:m.openSubtitlesKeyConfigured?"off · key saved":"off · no key"}),children:[e.jsx(z,{label:"Offer OpenSubtitles in the player",hint:"Needs an API key. It cannot be switched on without one.",checked:o.openSubtitles,onChange:h=>u({openSubtitles:h})}),e.jsx(D,{label:"API key",hint:"From your consumer at opensubtitles.com. Leave blank to keep the saved key.",children:e.jsx("input",{type:"password",autoComplete:"new-password",value:o.key,placeholder:m.openSubtitlesKeyConfigured?"Saved key (leave blank to keep)":"Paste an API key",onChange:h=>u({key:h.target.value})})}),e.jsx(z,{label:"Remove the saved key",checked:o.clearKey,onChange:h=>u({clearKey:h})}),e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"Account username",hint:"Optional, and the difference between a working feature and one that stops after a few files: without an account, downloads come out of the small anonymous allowance.",children:e.jsx("input",{type:"text",autoComplete:"off",value:o.username,placeholder:"Not signed in",onChange:h=>u({username:h.target.value})})}),e.jsx(D,{label:"Account password",hint:"Leave blank to keep the saved one.",children:e.jsx("input",{type:"password",autoComplete:"new-password",value:o.password,onChange:h=>u({password:h.target.value})})})]}),e.jsx(z,{label:"Sign out and forget the account",checked:o.clearLogin,onChange:h=>u({clearLogin:h})})]})]}),e.jsxs(A,{children:[e.jsxs("div",{className:"row",children:[e.jsx(R,{variant:"primary",busy:c==="save",onClick:()=>void v(),children:"Save subtitle settings"}),e.jsx(R,{busy:c==="test",icon:"pulse",onClick:()=>void b(),children:"Test the providers"}),e.jsx("span",{className:"hint",children:m.featureEnabled?"A change applies to the next title opened; no app release is required.":"Downloading subtitles is switched off on the Features page, so nothing here is offered."})]}),r===null?null:r.length===0?e.jsx(Z,{children:"No provider is switched on, so there was nothing to ask."}):e.jsx("div",{className:"list",children:r.map(h=>e.jsxs("div",{className:"list-item",children:[e.jsxs("div",{className:"list-body",children:[e.jsx("b",{children:h.provider}),e.jsx("p",{children:h.message})]}),e.jsx("div",{className:"list-actions",children:e.jsx(M,{tone:h.ok?"ok":"bad",children:h.ok?"reachable":"not reachable"})})]},h.provider))})]}),e.jsx(A,{title:"Subtitles Memby is holding",intro:"Only files fetched from a provider that cannot write beside the media file are kept here; they are served to televisions as ordinary tracks on every later playback. Emptying this is safe — each one can be fetched again, at the cost of the download allowance that fetched it.",icon:"database",tone:"data",actions:f!=null&&f.count?e.jsxs(M,{tone:"data",children:[N(f.count)," files · ",ye(f.bytes)]}):e.jsx(M,{children:"nothing held"}),footer:e.jsx(R,{variant:"danger",disabled:!(f!=null&&f.count),onClick:()=>p(!0),children:"Delete every stored subtitle"}),children:e.jsx(e.Fragment,{})})]}),w?e.jsx(he,{title:"Delete every stored subtitle?",body:"Each one can be fetched again, at the cost of the download allowance that fetched it. Subtitles Bazarr wrote beside the media are untouched — those belong to Emby.",confirmLabel:"Delete",destructive:!0,busy:c==="clear",onConfirm:()=>void S(),onCancel:()=>p(!1)}):null]})}function On(){var H;const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),[o,d]=x.useState(null),[r,j]=x.useState(!1),[w,p]=x.useState(!1),[m,f]=x.useState(""),[u,v]=x.useState(""),[b,S]=x.useState(!1),[h,g]=x.useState(null),[E,C]=x.useState(""),V=x.useRef(""),y=s==null?void 0:s.updatePolicy;x.useEffect(()=>{o||!y||d({version:y.latestVersion??"",url:y.downloadUrl??"",notes:y.notes??"",retireBelow:y.retireBelowVersion??"",required:!!y.minimumVersion&&y.minimumVersion===y.latestVersion,destructive:!!y.retireBelowVersion&&y.retireBelowVersion===y.latestVersion})},[y,o]),x.useEffect(()=>{let k=!0;const q=async()=>{try{const P=await F.get("/admin/api/release-builder");if(!k)return;g(P),C(""),P.state==="succeeded"&&P.finishedAt&&V.current!==P.finishedAt&&(V.current=P.finishedAt,d(null),await i())}catch(P){if(!k)return;C(P instanceof Error?P.message:"The release builder is unavailable.")}};q();const $=window.setInterval(()=>void q(),3e3);return()=>{k=!1,window.clearInterval($)}},[i]);const L=k=>t(k?"save":"off",async()=>{o&&(await a(()=>F.post("/admin/api/update-policy",{enabled:k,latestVersion:o.version.trim(),downloadUrl:o.url.trim(),notes:o.notes.trim(),required:o.required,destructive:o.destructive,retireBelowVersion:o.retireBelow.trim()}),k?"Update policy saved.":"Update prompts turned off."),j(!1),d(null),await i())}),ee=!!(y!=null&&y.minimumVersion)&&(y==null?void 0:y.minimumVersion)===(y==null?void 0:y.latestVersion),re=!!(y!=null&&y.retireBelowVersion)&&(y==null?void 0:y.retireBelowVersion)===(y==null?void 0:y.latestVersion),K=k=>d(q=>q&&{...q,...k}),I=()=>t("release",async()=>{const k=await a(()=>F.post("/admin/api/release-builder",{tag:m.trim(),notes:u.trim(),mandatory:b}),"Memby release started.");k&&(g(k),C(""),p(!1))}),T=(h==null?void 0:h.state)==="succeeded"?"ok":(h==null?void 0:h.state)==="failed"?"bad":(h==null?void 0:h.state)==="running"?"warn":void 0;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"App updates",intro:"Publish an optional or a required client update."}),e.jsx(B,{message:n}),e.jsx(B,{message:E}),e.jsxs(A,{title:"Build and publish",intro:"Build the latest tagged Android app in Docker, sign it with Memby's existing certificate, verify it, and publish it to televisions. The builder runs separately from the gateway.",icon:"download",tone:"data",actions:e.jsx(M,{tone:T,children:(h==null?void 0:h.state)??"checking"}),footer:e.jsx(R,{variant:"primary",busy:c==="release"||(h==null?void 0:h.state)==="running",disabled:!!E,onClick:()=>b?p(!0):void I(),children:m.trim()?`Build ${m.trim()}`:"Build latest release"}),children:[e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"GitHub tag override",hint:"Leave blank for the latest semantic tag. An exact tag bypasses discovery or repeats that tag; the gateway still refuses downgrades.",children:e.jsx("input",{type:"text",value:m,disabled:(h==null?void 0:h.state)==="running",placeholder:"v0.2.64 (blank uses latest)",onChange:k=>f(k.target.value)})}),e.jsx(D,{label:"Release notes",hint:"Leave blank to use this version's CHANGELOG entry.",children:e.jsx("input",{type:"text",value:u,disabled:(h==null?void 0:h.state)==="running",placeholder:"What's new on the television",onChange:k=>v(k.target.value)})})]}),e.jsx(z,{label:"Make this update required",hint:"Older televisions cannot dismiss the update prompt. You will confirm before the build starts.",checked:b,disabled:(h==null?void 0:h.state)==="running",onChange:S}),h!=null&&h.message?e.jsx(ue,{tone:T,children:h.message}):null,(H=h==null?void 0:h.logs)!=null&&H.length?e.jsx("pre",{className:"code",children:h.logs.join(` `)}):null,e.jsxs(ue,{children:["Command-line fallback: ",e.jsx("code",{children:(h==null?void 0:h.fallback)??"docker compose run --rm --build memby-builder release"})]})]}),l||!o?e.jsx(W,{rows:1}):e.jsxs(A,{title:"Update policy",intro:"Televisions check on every launch. An optional update is a prompt the viewer can dismiss; a required one covers the home screen until they update, so it needs a download URL that actually works.",icon:"download",tone:"info",actions:y!=null&&y.enabled?e.jsxs(M,{tone:ee?"warn":"ok",children:[re?"sign-out · ":ee?"required · ":"optional · ",y.latestVersion]}):e.jsx(M,{children:"off"}),footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:c==="save",onClick:()=>o.required?j(!0):void L(!0),children:"Save policy"}),e.jsx(R,{busy:c==="off",onClick:()=>void L(!1),children:"Turn prompts off"})]}),children:[e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"Latest version",children:e.jsx("input",{type:"text",value:o.version,placeholder:"0.2.63",onChange:k=>K({version:k.target.value})})}),e.jsx(D,{label:"APK URL",children:e.jsx("input",{type:"text",value:o.url,placeholder:"https://nas/memby/memby-0.2.63.apk",onChange:k=>K({url:k.target.value})})})]}),e.jsx(D,{label:"What's new",hint:"Shown on the television above the update button.",children:e.jsx("input",{type:"text",value:o.notes,placeholder:"One line the viewer reads",onChange:k=>K({notes:k.target.value})})}),e.jsx(D,{label:"Sign out builds below",hint:"The destructive compatibility floor. Leave blank to keep every supported viewer signed in.",children:e.jsx("input",{type:"text",value:o.retireBelow,placeholder:"0.2.44",onChange:k=>K({retireBelow:k.target.value})})}),e.jsx(z,{label:"Require this update",hint:"Blocks the home screen on every television below this version.",checked:o.required,onChange:k=>K({required:k})}),e.jsx(z,{label:"Set the destructive floor to this update",hint:"Deletes sessions on every older television when it next uses Memby, then shows the required update screen.",checked:o.destructive,onChange:k=>K(k?{destructive:!0,required:!0,retireBelow:o.version.trim()}:{destructive:!1,retireBelow:o.retireBelow.trim()===o.version.trim()?"":o.retireBelow})})]}),r&&o?e.jsx(he,{title:o.destructive?"Sign every older television out?":"Require this update?",body:o.destructive?"This deletes sessions on every older television and forces viewers to sign in again after updating.":"Required updates block the home screen on every television below this version until they update.",confirmLabel:"Publish",destructive:o.destructive,busy:c==="save",onConfirm:()=>void L(!0),onCancel:()=>j(!1)}):null,w?e.jsx(he,{title:"Build a required update?",body:"When this signed APK is published, every older television will be blocked until it installs the update.",confirmLabel:"Build and publish",busy:c==="release",onConfirm:()=>void I(),onCancel:()=>p(!1)}):null]})}const Bn=2e4,Un=3e3,Vn=[{value:60,label:"Every minute"},{value:300,label:"Every 5 minutes"},{value:600,label:"Every 10 minutes"},{value:900,label:"Every 15 minutes"},{value:1800,label:"Every 30 minutes"},{value:3600,label:"Hourly"},{value:10800,label:"Every 3 hours"},{value:21600,label:"Every 6 hours"},{value:43200,label:"Every 12 hours"},{value:86400,label:"Daily"},{value:604800,label:"Weekly"}];function _n(s){const n=[...Vn];for(const l of[s.defaultIntervalSeconds,s.intervalSeconds])l>0&&!n.some(i=>i.value===l)&&n.push({value:l,label:Le(l).replace(/^every /,"Every ")});return n.sort((l,i)=>l.value-i.value)}function Xe(s){return s==="failed"?"bad":s==="running"?"info":s==="skipped"?"warn":"ok"}function Wn(){const{wrap:s}=Q(),{busy:n,run:l}=Y(),[i,a]=x.useState(!1),{data:c,error:t,loading:o,reload:d}=J("/admin/api/tasks?limit=60",{pollMs:i?Un:Bn}),r=(c==null?void 0:c.tasks)??[],j=r.some(g=>g.running);j!==i&&a(j);const w=g=>l(g.id,async()=>{await s(()=>F.post(`/admin/api/tasks/${encodeURIComponent(g.id)}/run`),`${g.name} started.`),await d()}),p=(g,E)=>l(`${g.id}:enabled`,async()=>{await s(()=>F.put(`/admin/api/tasks/${encodeURIComponent(g.id)}`,{enabled:E}),E?`${g.name} switched on.`:`${g.name} switched off.`),await d()}),m=(g,E)=>l(`${g.id}:interval`,async()=>{await s(()=>F.put(`/admin/api/tasks/${encodeURIComponent(g.id)}`,{intervalSeconds:E}),`${g.name} now runs ${Le(E)}.`),await d()}),f=g=>l(`${g.id}:interval`,async()=>{await s(()=>F.put(`/admin/api/tasks/${encodeURIComponent(g.id)}`,{intervalSeconds:0}),`${g.name} back to its default cadence.`),await d()}),u=r.filter(g=>{var E;return((E=g.lastRun)==null?void 0:E.status)==="failed"}).length,v=r.filter(g=>g.defaultIntervalSeconds>0&&g.intervalSeconds!==g.defaultIntervalSeconds).length,b=r.filter(g=>!g.enabled).length,S=(c==null?void 0:c.groups)??[],h=r.filter(g=>!g.group);return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Scheduled tasks",intro:"The gateway's background work: what it does, when it last ran, how long it took and whether it worked. Every one of these can be started by hand."}),e.jsx(B,{message:t}),o?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"Tasks",value:N(r.length),icon:"clock",tone:"info"},{label:"Running now",value:N(r.filter(g=>g.running).length),icon:"pulse",tone:j?"ok":void 0},{label:"Last run failed",value:N(u),icon:"alert",tone:u>0?"bad":void 0},{label:"Switched off",value:N(b),icon:"power",tone:b>0?"warn":void 0},{label:"Retimed",value:N(v),icon:"clock",tone:v>0?"note":void 0}]}),u>0?e.jsx(ue,{tone:"bad",children:"A failed task publishes an administrative event, so the failure is in the activity feed and wherever your integrations send it — you did not have to be looking at this page."}):null,[...S,...h.length>0?[""]:[]].map(g=>{const E=r.filter(C=>C.group===g);return E.length===0?null:e.jsx(A,{title:g||"Other",icon:g==="System"?"chip":g==="Analytics"?"chart":"wrench",tone:g==="System"?"info":g==="Analytics"?"data":"note",children:e.jsx("div",{className:"list",children:E.map(C=>{var V;return e.jsxs("div",{className:"list-item",children:[e.jsxs("div",{className:"list-body",children:[e.jsxs("b",{children:[C.name," ",C.running?e.jsx(M,{tone:"info",children:"running"}):null,C.enabled?null:e.jsx(M,{tone:"warn",children:"off"}),C.defaultIntervalSeconds>0&&C.intervalSeconds!==C.defaultIntervalSeconds?e.jsx(M,{tone:"note",children:"retimed"}):null]}),e.jsx("p",{children:C.description}),e.jsxs("p",{className:"quiet",children:[Le(C.intervalSeconds),C.enabled&&C.nextRun?` · next ${pe(C.nextRun).replace(" ago","")}`:"",C.lastRun?e.jsxs(e.Fragment,{children:[" · last ",e.jsx("span",{title:O(C.lastRun.startedAt),children:pe(C.lastRun.startedAt)}),` in ${be(C.lastRun.durationMs)}`,C.lastRun.detail?` — ${C.lastRun.detail}`:""]}):" · never run"]}),(V=C.lastRun)!=null&&V.error?e.jsx("p",{className:"mono",style:void 0,children:e.jsx(M,{tone:"bad",children:C.lastRun.error})}):null]}),e.jsxs("div",{className:"list-actions",children:[C.lastRun?e.jsx(M,{tone:Xe(C.lastRun.status),children:C.lastRun.status}):e.jsx(M,{children:"never run"}),e.jsx("select",{"aria-label":`How often ${C.name} runs`,value:C.intervalSeconds,disabled:n===`${C.id}:interval`||C.running,onChange:y=>void m(C,Number(y.target.value)),children:_n(C).map(y=>e.jsxs("option",{value:y.value,children:[y.label,y.value===C.defaultIntervalSeconds?" (default)":""]},y.value))}),C.defaultIntervalSeconds>0&&C.intervalSeconds!==C.defaultIntervalSeconds?e.jsx(R,{size:"sm",icon:"refresh",busy:n===`${C.id}:interval`,onClick:()=>void f(C),children:"Default"}):null,e.jsx(z,{label:"",checked:C.enabled,disabled:n===`${C.id}:enabled`,onChange:y=>void p(C,y)}),e.jsx(R,{size:"sm",icon:"play",busy:n===C.id,disabled:C.running,onClick:()=>void w(C),children:"Run now"})]})]},C.id)})})},g||"other")}),e.jsx(A,{title:"Recent runs",intro:"Every task together and in order, which is what shows two jobs interfering with each other.",icon:"history",tone:"note",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nowrap",children:"Started"}),e.jsx("th",{children:"Task"}),e.jsx("th",{children:"Trigger"}),e.jsx("th",{children:"Result"}),e.jsx("th",{className:"num",children:"Took"}),e.jsx("th",{children:"Detail"})]})}),e.jsx("tbody",{children:((c==null?void 0:c.runs.length)??0)===0?e.jsx(X,{columns:6,children:"No task has run yet."}):c==null?void 0:c.runs.map(g=>{var E;return e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",title:O(g.startedAt),children:pe(g.startedAt)}),e.jsx("td",{children:((E=r.find(C=>C.id===g.taskId))==null?void 0:E.name)??g.taskId}),e.jsx("td",{className:"muted",children:g.trigger}),e.jsx("td",{children:e.jsx(M,{tone:Xe(g.status),children:g.status})}),e.jsx("td",{className:"num muted",children:be(g.durationMs)}),e.jsx("td",{className:"muted",children:g.error||g.detail||"—"})]},g.id)})})]})})})]})]})}const zn={id:"",name:"Discord",url:"",enabled:!0,events:[]};function Hn(){const{wrap:s,show:n}=Q(),{busy:l,run:i}=Y(),{data:a,error:c,loading:t,reload:o}=J("/admin/api/integrations",{pollMs:6e4}),[d,r]=x.useState(null),[j,w]=x.useState(null),p=(a==null?void 0:a.catalogue)??[],m=(a==null?void 0:a.integrations)??[],f=S=>r({id:S.id,name:S.name,url:"",enabled:S.enabled,events:S.events??[]}),u=()=>i("save",async()=>{if(!d)return;await s(()=>F.post("/admin/api/integrations",d),d.id?"Integration saved.":"Integration added.")&&(r(null),await o())}),v=S=>i("remove",async()=>{await s(()=>F.del(`/admin/api/integrations/${encodeURIComponent(S.id)}`),`${S.name} removed.`),w(null),await o()}),b=S=>i(`test:${S.id}`,async()=>{const h=await s(()=>F.post(`/admin/api/integrations/${encodeURIComponent(S.id)}/test`));h&&n(h.message,h.ok?"ok":"bad"),await o()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Integrations",intro:"Send administrative events to somewhere you already look. Events pass through the gateway's own event layer, so nothing about authentication or scheduled tasks knows Discord exists — and a second kind of destination is a change here rather than everywhere.",actions:e.jsx(R,{variant:"primary",icon:"plus",onClick:()=>r(zn),children:"Add a webhook"})}),e.jsx(B,{message:c}),e.jsx(Kn,{}),e.jsx(Gn,{}),e.jsx(Zn,{}),((a==null?void 0:a.dropped)??0)>0?e.jsxs(ue,{tone:"warn",children:[N((a==null?void 0:a.dropped)??0)," events could not be queued for delivery. The queue is deliberately lossy — a slow endpoint must never hold up a television signing in — but a number growing here means a destination is not keeping up."]}):null,t?e.jsx(W,{}):m.length===0&&!d?e.jsx(A,{title:"Nothing configured",icon:"plug",tone:"note",children:e.jsx(Z,{children:"No destinations yet. A Discord webhook takes about a minute: in Discord, open a channel's settings → Integrations → Webhooks → New Webhook, copy its URL, and paste it here."})}):m.map(S=>e.jsx(Jn,{integration:S,catalogue:p,busy:l,onEdit:()=>f(S),onTest:()=>void b(S),onRemove:()=>w(S)},S.id)),d?e.jsx(Yn,{draft:d,catalogue:p,busy:l==="save",onChange:r,onSave:()=>void u(),onCancel:()=>r(null)}):null,j?e.jsx(he,{title:`Remove ${j.name}?`,body:"The webhook address and its delivery history go with it. Events already published stay in the activity feed.",confirmLabel:"Remove",destructive:!0,busy:l==="remove",onConfirm:()=>void v(j),onCancel:()=>w(null)}):null]})}function Kn(){const{wrap:s}=Q(),{busy:n,run:l}=Y(),{data:i,error:a,loading:c,reload:t}=J("/admin/api/arr-integrations"),o=d=>l("arr-integrations",async()=>{i&&(await s(()=>F.post("/admin/api/arr-integrations",{sonarrEnabled:d.sonarrEnabled??i.sonarrEnabled,radarrEnabled:d.radarrEnabled??i.radarrEnabled}),"Integration settings saved."),await t())});return e.jsxs(A,{title:"Sonarr and Radarr",intro:"Turn either service off without removing its address, API key or request policy. Disabled services are not offered for Memby requests.",icon:"plug",tone:"info",children:[e.jsx(B,{message:a??""}),c?e.jsx(W,{rows:2}):e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Sonarr enabled",hint:i!=null&&i.sonarrConfigured?"Off stops Memby sending or looking up TV requests through Sonarr.":"Sonarr is not configured.",checked:!!(i!=null&&i.sonarrEnabled),disabled:!(i!=null&&i.sonarrConfigured)||n==="arr-integrations",onChange:d=>void o({sonarrEnabled:d})}),e.jsx(z,{label:"Radarr enabled",hint:i!=null&&i.radarrConfigured?"Off stops Memby sending or looking up film requests through Radarr.":"Radarr is not configured.",checked:!!(i!=null&&i.radarrEnabled),disabled:!(i!=null&&i.radarrConfigured)||n==="arr-integrations",onChange:d=>void o({radarrEnabled:d})})]})]})}function Gn(){const{wrap:s}=Q(),{busy:n,run:l}=Y(),{data:i,error:a,loading:c,reload:t}=J("/admin/api/sonarr-request-policy"),[o,d]=x.useState(0),[r,j]=x.useState(!1);x.useEffect(()=>{i&&(d(i.qualityProfileId),j(i.searchImmediately))},[i]);const w=()=>l("sonarr-request-policy",async()=>{await s(()=>F.post("/admin/api/sonarr-request-policy",{qualityProfileId:o,searchImmediately:r}),"Sonarr TV request policy saved."),await t()}),p=i==null?void 0:i.profiles.find(m=>m.id===o);return e.jsxs(A,{title:"Sonarr TV requests",intro:"The policy Memby uses when a viewer requests a television series. The series remains monitored; searching its existing episodes is an explicit choice.",icon:"tv",tone:i!=null&&i.configured?"ok":"warn",actions:i!=null&&i.configured?e.jsx(M,{tone:"ok",children:"configured"}):e.jsx(M,{tone:"warn",children:"needs attention"}),footer:e.jsx(R,{variant:"primary",busy:n==="sonarr-request-policy",disabled:c||o<=0,onClick:()=>void w(),children:"Save Sonarr policy"}),children:[e.jsx(B,{message:a??(i==null?void 0:i.error)??""}),c?e.jsx(W,{rows:2}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fields",children:e.jsx(D,{label:"Request quality profile",hint:"Memby stores this Sonarr profile ID. 720p is the recommended safe default; Memby will never fall back to Any.",children:e.jsxs("select",{value:o,onChange:m=>d(Number(m.target.value)),disabled:!(i!=null&&i.profiles.length),children:[e.jsx("option",{value:0,children:"Choose a quality profile…"}),i==null?void 0:i.profiles.map(m=>e.jsxs("option",{value:m.id,children:[m.name,m.recommended?" — recommended (720p)":""]},m.id))]})})}),e.jsx(z,{label:"Search for episodes immediately after request",hint:"Off adds and monitors the series without searching its backlog. Enable only when requests should start an immediate episode search.",checked:r,onChange:j}),p?e.jsxs(ue,{tone:"info",children:["Requested series will use ",e.jsx("b",{children:p.name})," (profile ID ",p.id,"), be monitored using Memby’s existing all-episodes strategy, and ",r?"start an immediate search.":"not start an immediate search."]}):null]})]})}function Zn(){const{wrap:s}=Q(),{busy:n,run:l}=Y(),{data:i,error:a,loading:c,reload:t}=J("/admin/api/radarr-request-policy"),[o,d]=x.useState(0),[r,j]=x.useState(!1);x.useEffect(()=>{i&&(d(i.qualityProfileId),j(i.searchImmediately))},[i]);const w=()=>l("radarr-request-policy",async()=>{await s(()=>F.post("/admin/api/radarr-request-policy",{qualityProfileId:o,searchImmediately:r}),"Radarr movie request policy saved."),await t()}),p=i==null?void 0:i.profiles.find(m=>m.id===o);return e.jsxs(A,{title:"Radarr movie requests",intro:"The policy Memby uses when a viewer requests a film. The film remains monitored; an immediate Radarr search is an explicit choice.",icon:"tv",tone:i!=null&&i.configured?"ok":"warn",actions:i!=null&&i.configured?e.jsx(M,{tone:"ok",children:"configured"}):e.jsx(M,{tone:"warn",children:"needs attention"}),footer:e.jsx(R,{variant:"primary",busy:n==="radarr-request-policy",disabled:c||o<=0,onClick:()=>void w(),children:"Save Radarr policy"}),children:[e.jsx(B,{message:a??(i==null?void 0:i.error)??""}),c?e.jsx(W,{rows:2}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fields",children:e.jsx(D,{label:"Request quality profile",hint:"Memby stores this Radarr profile ID. 720p is the recommended safe default; Memby will never fall back to Any.",children:e.jsxs("select",{value:o,onChange:m=>d(Number(m.target.value)),disabled:!(i!=null&&i.profiles.length),children:[e.jsx("option",{value:0,children:"Choose a quality profile…"}),i==null?void 0:i.profiles.map(m=>e.jsxs("option",{value:m.id,children:[m.name,m.recommended?" — recommended (720p)":""]},m.id))]})})}),e.jsx(z,{label:"Search for the film immediately after request",hint:"Off adds and monitors the film without asking Radarr to search. Enable only when requests should start an immediate search.",checked:r,onChange:j}),p?e.jsxs(ue,{tone:"info",children:["Requested films will use ",e.jsx("b",{children:p.name})," (profile ID ",p.id,"), remain monitored, and ",r?"start an immediate search.":"not start an immediate search."]}):null]})]})}function Jn({integration:s,catalogue:n,busy:l,onEdit:i,onTest:a,onRemove:c}){const t=s.health,o=!t.lastFailure||t.lastSuccess&&t.lastSuccess>t.lastFailure,d=s.events??[];return e.jsxs(A,{title:s.name,intro:s.hint?`Discord webhook ${s.hint}`:"Discord webhook",icon:"plug",tone:s.enabled?"ok":"warn",actions:e.jsxs(e.Fragment,{children:[s.enabled?e.jsx(M,{tone:"ok",children:"on"}):e.jsx(M,{tone:"warn",children:"off"}),t.deliveries>0?e.jsx(M,{tone:o?"ok":"bad",children:o?"delivering":"failing"}):e.jsx(M,{children:"never used"}),e.jsx(R,{size:"sm",icon:"pulse",busy:l===`test:${s.id}`,onClick:a,children:"Test"}),e.jsx(R,{size:"sm",onClick:i,children:"Edit"}),e.jsx(R,{size:"sm",variant:"danger",icon:"trash",onClick:c,title:"Remove"})]}),children:[e.jsxs("div",{className:"list",children:[e.jsx("div",{className:"list-item",children:e.jsxs("div",{className:"list-body",children:[e.jsx("b",{children:"Events sent"}),e.jsx("p",{children:d.length===0?"None selected — this destination is configured but will never post anything.":d.map(r=>{var j;return((j=n.find(w=>w.type===r))==null?void 0:j.label)??r}).join(", ")})]})}),e.jsxs("div",{className:"list-item",children:[e.jsxs("div",{className:"list-body",children:[e.jsx("b",{children:"Last delivered"}),e.jsx("p",{children:t.lastSuccess?O(t.lastSuccess):"never"})]}),e.jsx("div",{className:"list-actions",children:t.deliveries>0?e.jsxs("span",{className:"quiet",children:[N(t.deliveries)," attempts, ",N(t.failures)," failed"]}):null})]}),t.lastFailure?e.jsx("div",{className:"list-item",children:e.jsxs("div",{className:"list-body",children:[e.jsx("b",{children:"Last failure"}),e.jsxs("p",{children:[O(t.lastFailure),t.lastError?` — ${t.lastError}`:""]})]})}):null]}),s.deliveries.length>0?e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nowrap",children:"Attempted"}),e.jsx("th",{children:"Event"}),e.jsx("th",{children:"Result"}),e.jsx("th",{className:"num",children:"Took"})]})}),e.jsx("tbody",{children:s.deliveries.map(r=>e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",title:O(r.attemptedAt),children:pe(r.attemptedAt)}),e.jsx("td",{className:"muted",children:r.eventType}),e.jsx("td",{children:r.success?e.jsx(M,{tone:"ok",children:r.statusCode||"ok"}):e.jsx(M,{tone:"bad",children:r.error||r.statusCode||"failed"})}),e.jsx("td",{className:"num muted",children:be(r.durationMs)})]},r.id))})]})}):e.jsx(G,{children:e.jsx("table",{children:e.jsx("tbody",{children:e.jsx(X,{columns:4,children:"Nothing has been delivered through this webhook yet."})})})})]})}function Yn({draft:s,catalogue:n,busy:l,onChange:i,onSave:a,onCancel:c}){const t=[...new Set(n.map(d=>d.group))],o=(d,r)=>i({...s,events:r?[...s.events,d]:s.events.filter(j=>j!==d)});return e.jsxs(A,{title:s.id?`Edit ${s.name}`:"New Discord webhook",icon:"plug",tone:"info",footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"primary",busy:l,onClick:a,children:s.id?"Save":"Add"}),e.jsx(R,{variant:"quiet",onClick:c,children:"Cancel"}),e.jsx("span",{className:"spacer"}),s.events.length===0?e.jsx("span",{className:"quiet",children:"Nothing selected — this destination would never post."}):e.jsxs("span",{className:"quiet",children:[s.events.length," events selected"]})]}),children:[e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"Name",hint:"What this destination is called in the console.",children:e.jsx("input",{type:"text",value:s.name,onChange:d=>i({...s,name:d.target.value})})}),e.jsx(D,{label:"Webhook address",hint:s.id?"Leave blank to keep the address already saved — it is a credential and is never sent back to this page.":"Discord → channel settings → Integrations → Webhooks → New Webhook → Copy Webhook URL.",children:e.jsx("input",{type:"url",value:s.url,placeholder:s.id?"unchanged":"https://discord.com/api/webhooks/…",onChange:d=>i({...s,url:d.target.value})})})]}),e.jsx(z,{label:"Enabled",hint:"Off keeps the configuration and stops the posts.",checked:s.enabled,onChange:d=>i({...s,enabled:d})}),t.map(d=>e.jsxs("div",{children:[e.jsx("div",{className:"card-head",style:void 0,children:e.jsx("div",{className:"card-head-text",children:e.jsx("h2",{children:d})})}),n.filter(r=>r.group===d).map(r=>e.jsx(z,{label:r.label,hint:r.description,checked:s.events.includes(r.type),onChange:j=>o(r.type,j)},r.type))]},d))]})}function Xn(){var u;const{status:s,error:n,loading:l,reload:i}=ie(),{wrap:a}=Q(),{busy:c,run:t}=Y(),[o,d]=x.useState(""),[r,j]=x.useState(!1),[w,p]=x.useState(!1),m=!!((u=s==null?void 0:s.maintenance)!=null&&u.enabled);x.useEffect(()=>{var v;!w&&s&&d(((v=s.maintenance)==null?void 0:v.message)??"")},[s,w]);const f=v=>t(v?"on":"off",async()=>{await a(()=>F.post("/admin/api/maintenance",{enabled:v,message:o}),v?"Memby is offline for every television.":"Memby is back online."),j(!1),p(!1),await i()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Maintenance",intro:"Take Memby offline for every television."}),e.jsx(B,{message:n}),l?e.jsx(W,{rows:1}):e.jsx(A,{title:"Gateway availability",intro:"Takes Memby offline for every television, independently of Emby. Sign-in and all content calls answer 503 with the message below, and the television shows it in place of the launcher rows. This console keeps working.",icon:"power",tone:m?"bad":"warn",actions:m?e.jsx(M,{tone:"bad",children:"offline"}):e.jsx(M,{tone:"ok",children:"online"}),footer:e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"danger",disabled:m,onClick:()=>j(!0),children:"Go offline"}),e.jsx(R,{disabled:!m,busy:c==="off",onClick:()=>void f(!1),children:"Bring back online"})]}),children:e.jsx(D,{label:"Message shown on the television",hint:"Say what is happening and when it will be back. It is the only thing the viewer is told.",children:e.jsx("input",{type:"text",value:o,placeholder:"Back shortly — upgrading the server",onChange:v=>{d(v.target.value),p(!0)}})})}),r?e.jsx(he,{title:"Take Memby offline?",body:"Every television will stop working immediately and show your message in place of the launcher. This console keeps working.",confirmLabel:"Go offline",destructive:!0,busy:c==="on",onConfirm:()=>void f(!0),onCancel:()=>j(!1)}):null]})}function Qn(){const{status:s,error:n,loading:l}=ie(),i=(s==null?void 0:s.runs)??[];return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Imports",intro:"Catalogue synchronisation history."}),e.jsx(B,{message:n}),l?e.jsx(W,{rows:1}):e.jsx(A,{title:"Synchronisation history",intro:"A full import mark-and-sweeps the catalogue; an incremental one asks Emby for what changed, with a minute of overlap so nothing falls between two runs.",icon:"sync",tone:"data",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Started"}),e.jsx("th",{children:"Kind"}),e.jsx("th",{children:"Trigger"}),e.jsx("th",{children:"Status"}),e.jsx("th",{className:"num",children:"Seen"}),e.jsx("th",{className:"num",children:"Written"}),e.jsx("th",{className:"num",children:"Removed"}),e.jsx("th",{children:"Notes"})]})}),e.jsx("tbody",{children:i.length===0?e.jsx(X,{columns:8,children:"Nothing has been imported yet."}):i.map(a=>e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",children:O(a.startedAt)}),e.jsx("td",{children:a.kind}),e.jsx("td",{className:"muted",children:a.trigger}),e.jsx("td",{children:e.jsx(M,{tone:a.status==="success"?"ok":a.status==="running"?"warn":"bad",children:a.status})}),e.jsx("td",{className:"num",children:N(a.itemsSeen)}),e.jsx("td",{className:"num",children:N(a.itemsUpserted)}),e.jsx("td",{className:"num",children:N(a.itemsRemoved)}),e.jsx("td",{className:"muted",children:a.error||""})]},a.id||a.startedAt))})]})})})]})}const Qe={TRACE:5,DEBUG:10,INFO:20,WARN:30,ERROR:40},es=2e4,et=5e3,we=48,st=31,ss=8,nt=["component","user","device","client","protocol","method","path","status","duration","version","gateway_version"],ns=new Map(nt.map((s,n)=>[s,n])),tt=new Intl.DateTimeFormat(void 0,{dateStyle:"short",timeStyle:"medium"}),ts=new WeakMap;function ke(s){const n=ts.get(s);if(n)return n;const l=Object.entries(s.attributes??{}).sort((a,c)=>{const t=ns.get(a[0])??(a[0]==="error"?1e3:100),o=ns.get(c[0])??(c[0]==="error"?1e3:100);return t-o||a[0].localeCompare(c[0])}),i={fields:l,summary:l.map(([a,c])=>`${a}=${String(c)}`).join(" "),haystack:[s.message,...l.flat()].join(" ").toLowerCase(),occurred:tt.format(new Date(s.occurredAt))};return ts.set(s,i),i}const it=s=>s.replace(/_/g," "),at=x.memo(function({event:n,index:l,onInspect:i}){const a=ke(n);return e.jsxs("div",{className:"logline","data-level":n.level,"data-virtual":"true",style:{transform:`translateY(${l*we}px)`},children:[e.jsxs("time",{title:n.occurredAt,children:[a.occurred,e.jsxs("small",{children:["#",n.sequence]})]}),e.jsx("span",{className:"lvl",children:n.level}),e.jsx("span",{className:"msg",title:n.message,children:n.message}),e.jsx("button",{type:"button",className:"logattrs-button",title:a.summary||"No structured details",onClick:()=>i(n.sequence),children:a.summary||"View record"})]})});function rt(){var q;const[s,n]=x.useState([]),[l,i]=x.useState(0),[a,c]=x.useState(!1),[t,o]=x.useState("INFO"),[d,r]=x.useState(""),[j,w]=x.useState(""),[p,m]=x.useState({top:0,height:600}),[f,u]=x.useState(null),v=x.useDeferredValue(d.trim().toLowerCase()),b=x.useRef(0),S=x.useRef(!1),h=x.useRef(0),g=x.useRef(null),E=x.useRef(!0),C=x.useRef(void 0),V=x.useCallback(async()=>{if(a||S.current||document.hidden)return;S.current=!0;const $=h.current,P=[];let ce=0;try{let de=0,le;do le=await F.get(`/admin/api/events?after=${b.current}&limit=1000`),b.current=le.next||b.current,ce+=le.dropped||0,P.push(...le.events??[]),de+=1;while(le.hasMore&&de<20);w("")}catch(de){w(de instanceof Error?de.message:String(de))}finally{P.length>0&&$===h.current&&n(de=>{const le=de.concat(P);return le.length>es?le.slice(le.length-es):le}),ce>0&&$===h.current&&i(de=>de+ce),S.current=!1}},[a]);x.useEffect(()=>{if(a)return;let $;const P=()=>{window.clearInterval($),$=document.hidden?void 0:window.setInterval(()=>void V(),et)},ce=()=>{P(),document.hidden||V()};return V(),P(),document.addEventListener("visibilitychange",ce),()=>{window.clearInterval($),document.removeEventListener("visibilitychange",ce)}},[V,a]);const y=x.useMemo(()=>{const $=Qe[t]??20;return s.filter(P=>(Qe[P.level]??0)>=$&&(!v||ke(P).haystack.includes(v)))},[s,t,v]),L=((q=y.at(-1))==null?void 0:q.sequence)??0,ee=Math.max(0,p.top-st),re=Math.ceil(p.height/we)+ss*2,K=Math.min(Math.max(0,Math.floor(ee/we)-ss),Math.max(0,y.length-re)),I=y.slice(K,K+re),T=x.useMemo(()=>s.find($=>$.sequence===f),[s,f]);x.useLayoutEffect(()=>{const $=g.current;!$||!E.current||($.scrollTop=$.scrollHeight,m({top:$.scrollTop,height:$.clientHeight}))},[L,v,t]),x.useEffect(()=>()=>window.cancelAnimationFrame(C.current??0),[]);const H=()=>{const $=g.current;$&&(E.current=$.scrollHeight-$.scrollTop-$.clientHeight{m({top:$.scrollTop,height:$.clientHeight})}))},k=()=>{const $=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),P=document.createElement("a");P.href=URL.createObjectURL($),P.download=`memby-events-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,P.click(),window.setTimeout(()=>URL.revokeObjectURL(P.href),1e3)};return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Server logs",intro:"Structured gateway events as they happen."}),e.jsx(B,{message:j}),e.jsxs(A,{children:[e.jsxs("div",{className:"filters",children:[e.jsx(D,{label:"Level",children:e.jsxs("select",{value:t,onChange:$=>o($.target.value),children:[e.jsx("option",{value:"DEBUG",children:"Debug and above"}),e.jsx("option",{value:"INFO",children:"Info and above"}),e.jsx("option",{value:"WARN",children:"Warnings and errors"}),e.jsx("option",{value:"ERROR",children:"Errors only"})]})}),e.jsx(D,{label:"Filter",grow:!0,children:e.jsx("input",{type:"search",value:d,placeholder:"Person, television, title, component, path…",onChange:$=>r($.target.value)})}),e.jsxs("div",{className:"filter-actions",children:[e.jsx(R,{onClick:()=>c($=>!$),icon:a?"play":"clock",children:a?"Resume":"Pause"}),e.jsx(R,{onClick:()=>{h.current+=1,n([]),i(0),u(null)},children:"Clear view"}),e.jsx(R,{onClick:k,icon:"download",children:"Export JSON"})]})]}),e.jsxs("div",{className:"logview",ref:g,onScroll:H,role:"log","aria-label":"Server events",children:[e.jsxs("div",{className:"loghead","aria-hidden":"true",children:[e.jsx("span",{children:"Time"}),e.jsx("span",{children:"Level"}),e.jsx("span",{children:"Event"}),e.jsx("span",{children:"Details"})]}),y.length===0?e.jsx("p",{className:"empty",children:s.length===0?"Waiting for server events…":"No events match this filter."}):e.jsx("div",{className:"logbody",style:{height:`${y.length*we}px`},children:I.map(($,P)=>e.jsx(at,{event:$,index:K+P,onInspect:u},$.sequence))})]}),e.jsxs("p",{className:"hint",children:[N(s.length)," retained · ",N(y.length)," matching",y.length?` · ${N(I.length)} rows mounted`:"",l?` · ${N(l)} overwritten before delivery`:"",a?" · paused":""]}),T?e.jsxs("section",{className:"log-inspector","aria-label":`Log record ${T.sequence}`,children:[e.jsxs("div",{className:"log-inspector-head",children:[e.jsxs("div",{children:[e.jsx("b",{children:T.message}),e.jsxs("span",{children:[ke(T).occurred," · ",T.level," · record #",T.sequence]})]}),e.jsx(R,{size:"sm",variant:"quiet",onClick:()=>u(null),children:"Close"})]}),ke(T).fields.length?e.jsx("dl",{children:ke(T).fields.map(([$,P])=>e.jsxs(x.Fragment,{children:[e.jsx("dt",{children:it($)}),e.jsx("dd",{children:String(P)})]},$))}):e.jsx(ue,{children:"No structured details were attached to this record."})]}):null]})]})}const is=["home","movies","shows","favorites","search","recent_searches","genre_browse","for_you","for_you_time","recommendation","continue","latest","my_shows","details","playback","notifications","profiles","settings"];function xe(s){const n=String(s||"—").replaceAll("_"," ");return n==="favorites"?"Favourites":n==="abandoned"?"Abandoned / interrupted":n}function lt(){const[s,n]=x.useState(30),[l,i]=x.useState(""),a=qe(),c=x.useMemo(()=>`/admin/api/journeys${Se({days:s,userId:l})}`,[s,l]),{data:t,error:o,loading:d}=J(c),r=t==null?void 0:t.stats,j=(t==null?void 0:t.users)??[],w=(t==null?void 0:t.actions)??[],p=(t==null?void 0:t.paths)??[],m=p[0],f=x.useMemo(()=>{const u=new Map(((t==null?void 0:t.features)??[]).map(b=>[b.feature,b])),v=new Map(is.map((b,S)=>[b,S]));return[...new Set([...is,...u.keys()])].map(b=>({name:b,stat:u.get(b)})).sort((b,S)=>{var g,E;const h=(((g=S.stat)==null?void 0:g.uses)??0)-(((E=b.stat)==null?void 0:E.uses)??0);return h||(v.get(b.name)??Number.MAX_SAFE_INTEGER)-(v.get(S.name)??Number.MAX_SAFE_INTEGER)})},[t==null?void 0:t.features]);return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"User journeys",intro:"How viewers move through Memby, use features and complete flows."}),e.jsx(B,{message:o}),e.jsx(A,{title:"Journey health",intro:"Server-derived foreground visits, completion and interruption. Search text, content titles and setting values are never stored.",icon:"people",tone:"info",actions:e.jsxs(e.Fragment,{children:[e.jsx(D,{label:"Window",children:e.jsxs("select",{value:s,onChange:u=>n(Number(u.target.value)),children:[e.jsx("option",{value:1,children:"24 hours"}),e.jsx("option",{value:7,children:"7 days"}),e.jsx("option",{value:30,children:"30 days"}),e.jsx("option",{value:90,children:"90 days"})]})}),e.jsx(D,{label:"User",children:e.jsxs("select",{value:l,onChange:u=>{const v=u.target.value;i(v),v&&a(`/admin/journeys/${encodeURIComponent(v)}`)},children:[e.jsx("option",{value:"",children:"All users"}),j.map(u=>e.jsx("option",{value:u.userId,children:u.username||u.userId},u.userId))]})})]}),children:d?e.jsx(W,{rows:1}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:"journeys",value:N(r==null?void 0:r.journeys),icon:"list",tone:"data"},{label:"viewers",value:N(r==null?void 0:r.viewers),icon:"people",tone:"info"},{label:"completion",value:Me(r==null?void 0:r.completionRate),icon:"check",tone:"ok"},{label:"abandoned",value:N(r==null?void 0:r.abandoned),icon:"alert",tone:"note"},{label:"active now",value:N(r==null?void 0:r.active),icon:"pulse",tone:"info"},{label:"average steps",value:((r==null?void 0:r.averageSteps)??0).toFixed(1),icon:"chart"},{label:"average visit",value:be(r==null?void 0:r.averageTimeMs),small:!0,icon:"clock"},{label:"history kept",value:`${(t==null?void 0:t.retentionDays)??90} days`,small:!0,icon:"clock"}]}),e.jsxs("div",{className:"summary-grid",children:[e.jsxs("div",{className:"summary",children:[e.jsxs("div",{className:"summary-head",children:[e.jsx("b",{children:"Visit completion"}),e.jsx("strong",{children:Me(r==null?void 0:r.completionRate)})]}),e.jsx(Xs,{value:(r==null?void 0:r.completed)??0,total:(r==null?void 0:r.journeys)??0}),e.jsxs("p",{children:[N(r==null?void 0:r.completed)," completed · ",N(r==null?void 0:r.abandoned)," abandoned ·"," ",N(r==null?void 0:r.active)," active"]})]}),e.jsxs("div",{className:"summary",children:[e.jsx("div",{className:"summary-head",children:e.jsx("b",{children:"Most common route"})}),e.jsx("strong",{style:void 0,children:m?`${xe(m.from)} → ${xe(m.to)}`:"Not enough data"}),e.jsx("p",{children:m?`${N(m.count)} times in this window`:"Journeys will appear here as viewers move through Memby."})]})]})]})}),e.jsxs(oe,{cols:"2",children:[e.jsx(A,{title:"What people do",intro:"Actions show total use and how many separate visits included them.",icon:"chart",tone:"info",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Action"}),e.jsx("th",{className:"num",children:"Uses"}),e.jsx("th",{className:"num",children:"Visits"})]})}),e.jsx("tbody",{children:w.length===0?e.jsx(X,{columns:3,children:"No significant actions in this window."}):w.map(u=>e.jsxs("tr",{children:[e.jsxs("td",{children:[e.jsx("b",{children:xe(u.action)}),e.jsx("span",{className:"table-sub",children:xe(u.category)})]}),e.jsx("td",{className:"num",children:N(u.events)}),e.jsx("td",{className:"num",children:N(u.journeys)})]},`${u.category}:${u.action}`))})]})})}),e.jsx(A,{title:"Where people go",intro:"The most common steps between screens, including where quiet visits ended.",icon:"list",tone:"note",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Route"}),e.jsx("th",{className:"num",children:"Times"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx(X,{columns:2,children:"No repeated paths in this window."}):p.map((u,v)=>e.jsxs("tr",{children:[e.jsxs("td",{children:[xe(u.from)," ",e.jsx("span",{className:"route-arrow",children:"→"})," ",xe(u.to)]}),e.jsx("td",{className:"num",children:N(u.count)})]},`${u.from}:${u.to}:${v}`))})]})})})]}),e.jsx(A,{title:"Feature use",intro:"Rare and unused features are shown against Memby's major feature catalogue.",icon:"pulse",tone:"data",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Feature"}),e.jsx("th",{className:"num",children:"Uses"}),e.jsx("th",{children:"Last used"}),e.jsx("th",{children:"Status"})]})}),e.jsx("tbody",{children:f.map(({name:u,stat:v})=>{const b=(v==null?void 0:v.uses)??0;return e.jsxs("tr",{children:[e.jsx("td",{children:xe(u)}),e.jsx("td",{className:"num",children:N(b)}),e.jsx("td",{className:"muted nowrap",children:v?O(v.lastUsedAt):"—"}),e.jsx("td",{children:b===0?e.jsx(M,{tone:"warn",children:"not used"}):b<3?e.jsx(M,{tone:"note",children:"rare"}):e.jsx(M,{tone:"ok",children:"used"})})]},u)})})]})})}),l?null:e.jsx(A,{title:"Inspect a viewer",intro:"Choose a person above to open their dedicated session and viewing-journey timeline.",icon:"journey",tone:"info",children:e.jsx("p",{className:"empty",children:"A viewing journey follows one intent through to playback, so two films watched in a single app session appear as two separate journeys."})})]})}const ve=s=>{const n=String(s||"—").replaceAll("_"," ");return n==="favorites"?"Favourites":n},Ns=s=>ve((s==null?void 0:s.target)||(s==null?void 0:s.screen)||(s==null?void 0:s.source)||(s==null?void 0:s.feature)),as=s=>s.itemName?`${ve(s.itemType)} · ${s.itemName}`:s.source&&s.target?`${ve(s.source)} → ${ve(s.target)}`:Ns(s),ot=s=>({journey_start:"Opened Memby",home_open:"Opened Memby",journey_end:"Finished session",screen_view:"Viewed",select:"Selected",open:"Opened",close:"Closed",request:s.category==="playback"?"Started watching":"Requested",stop:"Stopped watching",start:"Started",complete:"Completed"})[s.action]??ve(s.action);function ct(s){var l;const n=(l=[...s].reverse().find(i=>i.outcome))==null?void 0:l.outcome;return n==="success"||n==="completed"?{label:ve(n),tone:"ok"}:n==="failure"||n==="cancelled"||n==="abandoned"?{label:ve(n),tone:"note"}:s.some(i=>i.action==="stop"&&i.category==="playback")?{label:"watched",tone:"ok"}:{label:"left before playback ended",tone:"warn"}}function dt(s){const n=s.reduce((l,i,a)=>(i.category==="playback"&&i.action==="request"&&l.push(a),l),[]);return n.length===0?[s]:n.map((l,i)=>s.slice(i===0?0:l,n[i+1]??s.length))}function ht(){var d,r;const{userId:s=""}=Re(),n=x.useMemo(()=>`/admin/api/journeys${Se({days:90,userId:s})}`,[s]),{data:l,error:i,loading:a}=J(n),c=((r=(d=l==null?void 0:l.users)==null?void 0:d.find(j=>j.userId===s))==null?void 0:r.username)||s,t=x.useMemo(()=>{const j=new Map;for(const w of(l==null?void 0:l.events)??[])j.set(w.journeyId,[...j.get(w.journeyId)??[],w]);return[...j.values()].map(w=>w.sort((p,m)=>p.sequence-m.sequence)).sort((w,p)=>{var m,f;return(((m=p[0])==null?void 0:m.occurredAt)??"").localeCompare(((f=w[0])==null?void 0:f.occurredAt)??"")})},[l==null?void 0:l.events]),o=t.flatMap(j=>dt(j).map((w,p)=>{var m;return{events:w,key:`${(m=j[0])==null?void 0:m.journeyId}:${p}`}}));return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:`${c}'s journeys`,intro:"Each app session is shown as the viewing journeys it contains: entry, selection, playback outcome.",icon:"journey",crumbs:e.jsx(ne,{className:"crumb",to:"/admin/journeys",children:"Journeys"})}),e.jsx(B,{message:i}),a?e.jsx(W,{}):e.jsx(A,{title:"Viewing journeys",intro:`${t.length} app session${t.length===1?"":"s"} · ${o.length} viewing journey${o.length===1?"":"s"} in the last 90 days.`,icon:"journey",tone:"info",children:e.jsx("div",{className:"visits",children:o.length===0?e.jsx("p",{className:"empty",children:"No journeys recorded for this viewer."}):o.map((j,w)=>{const p=j.events,m=p[0],f=[...p].reverse().find(v=>v.itemName||v.action==="select"||v.category==="playback"&&v.action==="request"),u=ct(p);return e.jsxs("article",{className:"visit",children:[e.jsxs("header",{children:[e.jsxs("div",{children:[e.jsx("b",{children:O(m==null?void 0:m.occurredAt)}),e.jsxs("span",{children:["Journey ",w+1," · ",p.length," recorded steps"]})]}),e.jsx(M,{tone:u.tone,children:u.label})]}),e.jsxs("div",{className:"journey-answers",children:[e.jsxs("div",{className:"journey-answer","data-kind":"entry",children:[e.jsx(te,{name:"journey"}),e.jsx("span",{children:"Entered from"}),e.jsx("b",{children:Ns(m)})]}),e.jsxs("div",{className:"journey-answer","data-kind":"selection",children:[e.jsx(te,{name:"play"}),e.jsx("span",{children:"Selected"}),e.jsx("b",{children:f?as(f):"Nothing selected"})]}),e.jsxs("div",{className:"journey-answer","data-kind":"outcome",children:[e.jsx(te,{name:u.tone==="ok"?"check":"clock"}),e.jsx("span",{children:"Outcome"}),e.jsx("b",{children:u.label})]})]}),e.jsx("ol",{className:"journey-timeline",children:p.map(v=>e.jsxs("li",{children:[e.jsx("span",{className:"timeline-dot","data-action":v.action}),e.jsxs("div",{children:[e.jsx("b",{children:ot(v)}),e.jsx("span",{children:as(v)})]}),e.jsx("time",{children:O(v.occurredAt)})]},`${v.journeyId}:${v.sequence}`))})]},j.key)})})})]})}function rs(s){const n=String(s||"—").replaceAll("_"," ");return n==="favorites"?"Favourites":n==="abandoned"?"Abandoned / interrupted":n}function ut(){const[s,n]=x.useState(30),{data:l,error:i,loading:a}=J(`/admin/api/analytics?days=${s}`),c=(l==null?void 0:l.rows)??[];return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Row engagement",intro:"Impressions, focus, dwell and selections per launcher row."}),e.jsx(B,{message:i}),e.jsx(A,{title:"Launcher rows",intro:"Impressions are rows drawn, focuses are rows the D-pad reached, and dwell is how long it stayed there. Open rate is what a row was worth.",icon:"chart",tone:"info",actions:e.jsx(D,{label:"Window",children:e.jsxs("select",{value:s,onChange:t=>n(Number(t.target.value)),children:[e.jsx("option",{value:1,children:"24 hours"}),e.jsx("option",{value:7,children:"7 days"}),e.jsx("option",{value:30,children:"30 days"}),e.jsx("option",{value:90,children:"90 days"})]})}),children:a?e.jsx(W,{rows:1}):e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Row"}),e.jsx("th",{children:"Kind"}),e.jsx("th",{className:"num",children:"Dwell"}),e.jsx("th",{className:"num",children:"Impressions"}),e.jsx("th",{className:"num",children:"Focuses"}),e.jsx("th",{className:"num",children:"Opened"}),e.jsx("th",{className:"num",children:"Open rate"}),e.jsx("th",{className:"num",children:"Viewers"})]})}),e.jsx("tbody",{children:c.length===0?e.jsx(X,{columns:8,children:"No events in this window."}):c.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:rs(t.rowId)}),e.jsx("td",{className:"muted",children:rs(t.rowKind)}),e.jsx("td",{className:"num",children:be(t.dwellMs)}),e.jsx("td",{className:"num",children:N(t.impressions)}),e.jsx("td",{className:"num",children:N(t.focuses)}),e.jsx("td",{className:"num",children:N(t.selects)}),e.jsx("td",{className:"num",children:Me(t.selectRate)}),e.jsx("td",{className:"num",children:N(t.viewers)})]},`${t.rowId}:${t.rowKind}`))})]})})})]})}function mt(){const[s,n]=x.useState(7),{data:l,error:i,loading:a}=J(`/admin/api/searches?days=${s}`),c=(l==null?void 0:l.terms)??[],t=(l==null?void 0:l.recent)??[],o=l==null?void 0:l.totals;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Searches",intro:"What the household has been looking for, and what it searched just now."}),e.jsx(B,{message:i}),e.jsx(ae,{tiles:[{label:"searches",value:N((o==null?void 0:o.searches)??0),icon:"search",tone:"info"},{label:"distinct queries",value:N((o==null?void 0:o.queries)??0),icon:"list",tone:"data"},{label:"viewers searching",value:N((o==null?void 0:o.viewers)??0),icon:"people",tone:"note"},{label:"history kept",value:`${(l==null?void 0:l.retentionDays)??30} days`,small:!0,icon:"clock"}]}),a?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(A,{title:"What the house looks for",intro:"Queries the search tab ran, grouped without regard to case and labelled with the most recent spelling. Instant search asks from the second character, so a title typed slowly leaves its prefixes here too.",icon:"search",tone:"info",actions:e.jsx(D,{label:"Window",children:e.jsxs("select",{value:s,onChange:d=>n(Number(d.target.value)),children:[e.jsx("option",{value:1,children:"24 hours"}),e.jsx("option",{value:7,children:"7 days"}),e.jsx("option",{value:30,children:"30 days"})]})}),children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Query"}),e.jsx("th",{className:"num",children:"Searches"}),e.jsx("th",{className:"num",children:"Viewers"}),e.jsx("th",{children:"Last searched"})]})}),e.jsx("tbody",{children:c.length===0?e.jsx(X,{columns:4,children:"Nothing searched in this window."}):c.map(d=>e.jsxs("tr",{children:[e.jsx("td",{children:d.query}),e.jsx("td",{className:"num",children:N(d.searches)}),e.jsx("td",{className:"num",children:N(d.viewers)}),e.jsx("td",{className:"muted nowrap",children:O(d.lastAt)})]},d.query))})]})})}),e.jsx(A,{title:"As it happened",intro:"The log, newest first — the query exactly as it was typed, and who typed it. This is the one to read when somebody says search is not finding something.",icon:"history",tone:"note",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"When"}),e.jsx("th",{children:"Viewer"}),e.jsx("th",{children:"Query"})]})}),e.jsx("tbody",{children:t.length===0?e.jsx(X,{columns:3,children:"No searches in this window."}):t.map((d,r)=>e.jsxs("tr",{children:[e.jsx("td",{className:"muted nowrap",children:O(d.occurredAt)}),e.jsx("td",{children:d.username||e.jsx(M,{tone:"warn",children:d.userId||"unknown"})}),e.jsx("td",{children:d.query})]},`${d.occurredAt}:${r}`))})]})})})]})]})}function ls(s,n){if(n===0)return s>0?"new this week":"no change";const l=Math.round((s-n)/n*100);return`${l>0?"+":""}${l}% vs last week`}function pt(){const{data:s,error:n,loading:l}=J("/admin/api/views",{pollMs:6e4}),i=(s==null?void 0:s.daily)??[],a=(s==null?void 0:s.hourly)??[];return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Views",intro:"How often people reach Memby’s home screen. This measures app use, not playback streams."}),e.jsx(B,{message:n}),l?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[e.jsx(ae,{tiles:[{label:ls((s==null?void 0:s.today.visits)??0,(s==null?void 0:s.lastWeek.visits)??0),value:N(s==null?void 0:s.today.visits),icon:"overview",tone:"data"},{label:ls((s==null?void 0:s.today.viewers)??0,(s==null?void 0:s.lastWeek.viewers)??0),value:N(s==null?void 0:s.today.viewers),icon:"people",tone:"note"},{label:"busiest time today",value:(s==null?void 0:s.busiestHour)||"—",small:!0,icon:"clock",tone:"info"}]}),e.jsx(A,{title:"Visits by day",intro:"One visit is a signed-in home-screen opening. Viewers are distinct household profiles.",icon:"chart",tone:"data",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Day"}),e.jsx("th",{className:"num",children:"Visits"}),e.jsx("th",{className:"num",children:"Viewers"})]})}),e.jsx("tbody",{children:i.length===0?e.jsx(X,{columns:3,children:"No home-screen visits yet."}):i.map(c=>e.jsxs("tr",{children:[e.jsx("td",{children:c.label}),e.jsx("td",{className:"num",children:N(c.visits)}),e.jsx("td",{className:"num",children:N(c.viewers)})]},c.label))})]})})}),e.jsx(A,{title:"Today by hour",intro:"Local New Zealand time. Use this to see when the household is opening Memby.",icon:"clock",tone:"info",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Hour"}),e.jsx("th",{className:"num",children:"Visits"}),e.jsx("th",{className:"num",children:"Viewers"})]})}),e.jsx("tbody",{children:a.length===0?e.jsx(X,{columns:3,children:"No home-screen visits yet today."}):a.map(c=>e.jsxs("tr",{children:[e.jsx("td",{children:c.label}),e.jsx("td",{className:"num",children:N(c.visits)}),e.jsx("td",{className:"num",children:N(c.viewers)})]},c.label))})]})})})]})]})}const xt=s=>s.mediaType==="episode"?`${s.seriesTitle} S${String(s.seasonNumber).padStart(2,"0")}E${String(s.episodeNumber).padStart(2,"0")}`:s.title;function jt(){var a;const s=J("/admin/api/media-reports",{pollMs:15e3}),{busy:n,run:l}=Y(),i=(c,t)=>l(`${c.id}-${t}`,async()=>{await F.post(`/admin/api/media-reports/${c.id}/status`,{status:t}),await s.reload()});return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Media reports",intro:"Viewer-reported problems and the individual replacement searches they asked Memby to start."}),s.loading?e.jsx(W,{rows:4}):e.jsx(A,{title:"Open and recent reports",intro:"A replacement always targets one film or one episode. Existing files stay in place while Radarr or Sonarr applies its normal import policy.",icon:"inbox",children:(a=s.data)!=null&&a.reports.length?e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Media"}),e.jsx("th",{children:"Report"}),e.jsx("th",{children:"Viewer"}),e.jsx("th",{children:"Replacement"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Reported"}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:s.data.reports.map(c=>e.jsxs("tr",{children:[e.jsxs("td",{children:[e.jsx("b",{children:xt(c)}),e.jsx("br",{}),e.jsx("span",{className:"muted",children:c.title})]}),e.jsxs("td",{children:[c.reason.replaceAll("_"," "),c.comment?e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("span",{className:"muted",children:c.comment})]}):null]}),e.jsxs("td",{children:[c.reportedByUsername,e.jsx("br",{}),e.jsx("span",{className:"muted",children:c.reportedByDevice||"Unknown device"})]}),e.jsx("td",{children:e.jsx(M,{tone:c.replacementRequested?"note":void 0,children:c.replacementRequested?c.replacementStatus||"Requested":"Not requested"})}),e.jsx("td",{children:e.jsx(M,{tone:c.status==="resolved"?"ok":c.status==="dismissed"?void 0:"warn",children:c.status})}),e.jsx("td",{className:"nowrap muted",children:O(c.createdAt)}),e.jsxs("td",{children:[e.jsx(R,{size:"sm",variant:"quiet",busy:n===`${c.id}-acknowledged`,onClick:()=>void i(c,"acknowledged"),children:"Acknowledge"})," ",e.jsx(R,{size:"sm",variant:"quiet",busy:n===`${c.id}-resolved`,onClick:()=>void i(c,"resolved"),children:"Resolve"})," ",e.jsx(R,{size:"sm",variant:"quiet",busy:n===`${c.id}-dismissed`,onClick:()=>void i(c,"dismissed"),children:"Dismiss"})]})]},c.id))})]})}):e.jsx(Z,{children:"No media problems have been reported."})})]})}const vt=s=>s==="detected"?"ok":s==="failed"?"bad":s==="no_match"?"warn":"info",bt=s=>s==="no_match"?"no match":s,os=s=>({"live-playback":"Live playback","tracearr-next":"Next episode","tracearr-binge-prefetch":"Binge look-ahead","multi-user-demand":"Multiple viewers"}[s]??s)||"Unknown",cs=(s,n)=>s>0&&n>0?`S${String(s).padStart(2,"0")}E${String(n).padStart(2,"0")}`:"Episode";function ft(){var u,v,b,S;const s=J("/admin/api/credits?limit=150",{pollMs:15e3}),{wrap:n}=Q(),{busy:l,run:i}=Y(),[a,c]=x.useState(),[t,o]=x.useState(!1);x.useEffect(()=>{!t&&s.data&&c(s.data.settings)},[s.data,t]);const d=h=>{c(g=>g&&{...g,...h}),o(!0)},r=()=>{a&&i("save",async()=>{const h=await n(()=>F.put("/admin/api/credits",a),"Credits scanning settings saved.");h&&(s.set(h),c(h.settings),o(!1))})},j=((u=s.data)==null?void 0:u.history)??[],w=((v=s.data)==null?void 0:v.pending)??[],p=j.filter(h=>h.outcome==="detected").length,m=j.filter(h=>h.outcome==="no_match").length,f=j.filter(h=>h.outcome==="failed").length;return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Credits detection",intro:"Control how far ahead Memby scans and see why each episode was selected, what the detector found, and when it may be tried again."}),e.jsx(B,{message:s.error}),s.loading||!a?e.jsx(W,{}):e.jsxs(e.Fragment,{children:[(b=s.data)!=null&&b.enabled?null:e.jsx(ue,{tone:"warn",children:"Credits detection is disabled in the gateway environment. These settings will be retained for the next time it is enabled."}),e.jsx(ae,{tiles:[{label:"Waiting candidates",value:N((S=s.data)==null?void 0:S.queueDepth),icon:"clock",tone:w.length?"info":void 0},{label:"Detected in this history",value:N(p),icon:"check",tone:"ok"},{label:"No match",value:N(m),icon:"search",tone:m?"warn":void 0},{label:"Failed",value:N(f),icon:"alert",tone:f?"bad":void 0}]}),e.jsxs(oe,{cols:"wide",children:[e.jsx(A,{title:"Candidate controls",intro:"The worker remains single-file and scans one episode at a time. These values control what is allowed to wait and how far prediction looks ahead.",icon:"sliders",tone:"note",footer:e.jsx(R,{variant:"primary",icon:"check",busy:l==="save",disabled:!t,onClick:r,children:"Save settings"}),children:e.jsxs("div",{className:"fields",children:[e.jsx(D,{label:"Candidate limit",hint:"Maximum episodes waiting in the priority queue. Stronger candidates displace weaker ones when it is full.",children:e.jsx("input",{type:"number",min:1,max:100,value:a.candidateLimit,onChange:h=>d({candidateLimit:Number(h.target.value)})})}),e.jsx(D,{label:"Ordinary look-ahead",hint:"Episodes prepared ahead of a normally paced viewer.",children:e.jsx("input",{type:"number",min:1,max:10,value:a.prefetchEpisodes,onChange:h=>d({prefetchEpisodes:Number(h.target.value)})})}),e.jsx(D,{label:"Maximum look-ahead",hint:"Upper bound for fast binge viewing; must not be below the ordinary look-ahead.",children:e.jsx("input",{type:"number",min:a.prefetchEpisodes,max:20,value:a.maxPrefetch,onChange:h=>d({maxPrefetch:Number(h.target.value)})})}),e.jsx(D,{label:"Retry delay (hours)",hint:"After any speculative attempt, keep that episode out of refreshes for this long. Set 0 to allow every refresh.",children:e.jsx("input",{type:"number",min:0,max:720,value:a.retryHours,onChange:h=>d({retryHours:Number(h.target.value)})})})]})}),e.jsxs(A,{title:"How selection works",icon:"sparkle",tone:"data",children:[e.jsx("p",{className:"muted",children:"Recent viewing predicts the next few episodes. Priority favours a programme playing now, then the next episode, fast viewing, and episodes several people are approaching."}),e.jsx("p",{className:"muted",children:"A completed speculative attempt enters the retry delay even when no marker was found. Live playback can still raise an immediate candidate because somebody is waiting for it."})]})]}),e.jsx(A,{title:"Waiting candidates",intro:"The exact worker order after marker checks and retry cooldowns. A refresh may replace this list as household viewing changes.",icon:"list",tone:"info",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Episode"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{className:"num",children:"Priority"}),e.jsx("th",{className:"num",children:"Viewers"}),e.jsx("th",{children:"Demand seen"}),e.jsx("th",{children:"Item ID"})]})}),e.jsx("tbody",{children:w.length===0?e.jsx(X,{columns:6,children:"No episodes are waiting to be scanned."}):w.map(h=>e.jsxs("tr",{children:[e.jsx("td",{children:cs(h.season,h.episode)}),e.jsx("td",{children:e.jsx(M,{tone:"info",children:os(h.reason)})}),e.jsx("td",{className:"num",children:N(h.priority)}),e.jsx("td",{className:"num",children:N(h.userCount)}),e.jsx("td",{className:"nowrap muted",title:O(h.lastViewed),children:pe(h.lastViewed)}),e.jsx("td",{className:"mono muted",children:h.itemId})]},h.itemId))})]})})}),e.jsx(A,{title:"Scan history",intro:"Completed worker attempts, newest first. Repeated item IDs make an ineffective retry delay visible immediately.",icon:"history",tone:"note",children:e.jsx(G,{children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Finished"}),e.jsx("th",{children:"Programme"}),e.jsx("th",{children:"Selected because"}),e.jsx("th",{children:"Result"}),e.jsx("th",{children:"Marker"}),e.jsx("th",{children:"Evidence"}),e.jsx("th",{className:"num",children:"Took"})]})}),e.jsx("tbody",{children:j.length===0?e.jsx(X,{columns:7,children:"No credits scans have completed yet."}):j.map(h=>e.jsxs("tr",{children:[e.jsx("td",{className:"nowrap muted",title:O(h.finishedAt),children:pe(h.finishedAt)}),e.jsxs("td",{children:[e.jsx("b",{children:h.seriesName||h.itemName||h.itemId}),e.jsxs("span",{className:"table-sub",children:[cs(h.season,h.episode),h.itemName&&h.seriesName?` · ${h.itemName}`:""]})]}),e.jsxs("td",{children:[e.jsx(M,{tone:"info",children:os(h.reason)}),e.jsxs("span",{className:"table-sub",children:["priority ",h.priority]})]}),e.jsxs("td",{children:[e.jsx(M,{tone:vt(h.outcome),children:bt(h.outcome)}),h.error?e.jsx("span",{className:"table-sub",children:h.error}):null]}),e.jsx("td",{className:"nowrap",children:h.markerMs>0?be(h.markerMs):"—"}),e.jsxs("td",{className:"muted",children:[h.method||"visual",h.confidence>0?` · ${Me(h.confidence)}`:"",h.frames>0?` · ${h.frames} frames`:""]}),e.jsx("td",{className:"num muted",children:be(h.durationMs)})]},h.id))})]})})})]})]})}function gt(){return e.jsx(U,{title:"No such page",intro:"That address is not part of the console. Use the search in the bar above, or the sections on the left."})}function yt(){return e.jsx(As,{children:e.jsx(zs,{children:e.jsx(Js,{children:e.jsx(nn,{children:e.jsx(Is,{children:e.jsxs(_,{path:"/admin",element:e.jsx(en,{}),children:[e.jsx(_,{index:!0,element:e.jsx(tn,{})}),e.jsx(_,{path:"activity",element:e.jsx(rn,{})}),e.jsx(_,{path:"accounts",element:e.jsx(ln,{})}),e.jsx(_,{path:"accounts/:userId",element:e.jsx(on,{})}),e.jsx(_,{path:"accounts/:userId/settings",element:e.jsx(pn,{})}),e.jsx(_,{path:"clients",element:e.jsx(jn,{})}),e.jsx(_,{path:"logins",element:e.jsx(bn,{})}),e.jsx(_,{path:"devices/:deviceId",element:e.jsx(wn,{})}),e.jsx(_,{path:"library",element:e.jsx(kn,{})}),e.jsx(_,{path:"ratings",element:e.jsx(Sn,{})}),e.jsx(_,{path:"requests",element:e.jsx(Cn,{})}),e.jsx(_,{path:"recommendations",element:e.jsx(Mn,{})}),e.jsx(_,{path:"inspector",element:e.jsx(An,{})}),e.jsx(_,{path:"hero",element:e.jsx(Ln,{})}),e.jsx(_,{path:"features",element:e.jsx(qn,{})}),e.jsx(_,{path:"playback",element:e.jsx(Fn,{})}),e.jsx(_,{path:"subtitles",element:e.jsx(Pn,{})}),e.jsx(_,{path:"credits",element:e.jsx(ft,{})}),e.jsx(_,{path:"updates",element:e.jsx(On,{})}),e.jsx(_,{path:"tasks",element:e.jsx(Wn,{})}),e.jsx(_,{path:"integrations",element:e.jsx(Hn,{})}),e.jsx(_,{path:"maintenance",element:e.jsx(Xn,{})}),e.jsx(_,{path:"imports",element:e.jsx(Qn,{})}),e.jsx(_,{path:"logs",element:e.jsx(rt,{})}),e.jsx(_,{path:"journeys",element:e.jsx(lt,{})}),e.jsx(_,{path:"journeys/:userId",element:e.jsx(ht,{})}),e.jsx(_,{path:"views",element:e.jsx(pt,{})}),e.jsx(_,{path:"engagement",element:e.jsx(ut,{})}),e.jsx(_,{path:"searches",element:e.jsx(mt,{})}),e.jsx(_,{path:"media-reports",element:e.jsx(jt,{})}),e.jsx(_,{path:"overview",element:e.jsx($s,{to:"/admin",replace:!0})}),e.jsx(_,{path:"*",element:e.jsx(gt,{})})]})})})})})})}const Ss=document.getElementById("root");if(!Ss)throw new Error("the console has no root element to render into");us(Ss).render(e.jsx(x.StrictMode,{children:e.jsx(yt,{})}));