import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{b as t,g as n,w as r}from"./control-ui-core-pH6nakZ-.js";import{Ht as i,qt as a}from"./control-ui-core-Br5DB0Zj.js";import{n as o,t as s}from"./platform-label-BHGXql4m.js";function c(e){if(e.connected)return;let r=e.environment;if(r?.lastConnectedAtMs===void 0)return a(`newSession.neverConnected`);if(r.lastDisconnectedAtMs!==void 0){let t=n(Math.max(0,e.nowMs-r.lastDisconnectedAtMs))??a(`common.justNow`);return a(`newSession.offlineFor`,{duration:t})}let i=r.lastSeenAtMs??r.lastConnectedAtMs;return a(`newSession.lastSeen`,{time:t(i)})}function l(e,t={}){let n=e?.issues?.find(e=>e.code===`update-required`),r=c({environment:e,connected:t.connected??!0,nowMs:t.nowMs??Date.now()}),i=n?a(`newSession.nodeUpdateRequired`,{updateCommand:n.updateCommand,restartCommand:n.headlessReconnectCommand}):r,s=i?[i]:[];e?.platform&&s.push(o(e.platform));for(let t of e?.capabilities??[]){let e=t.split(`.`,1)[0]?.toLowerCase(),n=e?u[e]:void 0,r=n?a(n):void 0;if(r&&!s.includes(r)&&s.push(r),s.length>=4)break}return s}var u;function d(){return(d=e((()=>{i(),r(),s(),u={camera:`newSession.capabilityCamera`,location:`newSession.capabilityLocation`,talk:`newSession.capabilityTalk`,screen:`newSession.capabilityScreenCapture`,canvas:`newSession.capabilityCanvas`,microphone:`newSession.capabilityVoice`,voice:`newSession.capabilityVoice`}})))()}function f(e,t,n){let r=new Map;for(let[n,i]of e.entries()){let e=t(i);r.set(e,[...r.get(e)??[],n])}let i=e.map(()=>void 0);for(let t of r.values()){if(t.length<2)continue;let r=n.at(-1);if(!r)continue;let a=n.find(n=>{let i=t.map(t=>n(e[t])??r(e[t]));return i.every(e=>e!==void 0)&&new Set(i).size===t.length})??r;for(let n of t)i[n]=a(e[n])??r(e[n])}return i}function p(){return(p=e((()=>{})))()}function m(e,t){let n=e.issues?.find(e=>e.code===`update-required`);if(n)return a(`newSession.nodeUpdateRequired`,{updateCommand:n.updateCommand,restartCommand:n.headlessReconnectCommand});if(e.status!==`available`)return a(`newSession.deviceUnavailable`);if(e.sessionHost!==!0)return a(`newSession.sessionHostingDisabled`);let r=t.requiredNodeCommands.find(t=>!e.invocableCommands?.includes(t));if(r)return`${a(`pluginsPage.enableAction`)} ${r}: gateway.nodes.commands.allow.`;if(t.consumesWorkerSlot)return e.workerSlots?e.workerSlots.available===0?a(`newSession.deviceNoSlots`):void 0:a(`newSession.deviceCapacityUnavailable`)}function h(e,t=_,n){let r=(e??[]).flatMap(e=>{if(e.type!==`node`||!e.id.startsWith(`node:`))return[];let r=e.id.slice(5).trim();if(!r)return[];let i=n??m(e,t),a=l(e,{connected:e.status===`available`}),o=+((e.issues?.length??0)>0||e.status!==`available`),s=i&&!a.includes(i)?[...a.slice(0,o),i,...a.slice(o)].slice(0,4):a;return[{deviceId:r,label:e.label??r,facts:n?[n]:s,workerSlots:e.workerSlots,capabilities:e.capabilities,invocableCommands:e.invocableCommands,selectable:i===void 0,...i?{disabledReason:i}:{}}]}).toSorted((e,t)=>e.label.localeCompare(t.label)||e.deviceId.localeCompare(t.deviceId)),i=f(r,e=>e.label,[e=>e.deviceId.slice(0,8)]),a=[];for(let[e,t]of r.entries()){let n=i[e];a.push(n?{...t,subtitle:n}:t)}return a}function g(e,t,n){if(n)return n;let r=new Set((e??[]).filter(e=>e.type===`node`&&e.sessionHost===!0).map(e=>e.id));if(r.size===0){let t=(e??[]).find(e=>e.issues?.some(e=>e.code===`update-required`));return t?m(t,_):a(`newSession.noSessionHosts`)}return t.some(e=>e.selectable)?void 0:t.find(e=>r.has(`node:${e.deviceId}`))?.disabledReason}var _;function v(){return(v=e((()=>{i(),d(),_={requiredNodeCommands:[],consumesWorkerSlot:!0}})))()}export{p as a,f as i,h as n,g as r,v as t};
//# sourceMappingURL=device-placement-CSrN9cIf.js.map