function e(e){return typeof e==`object`&&e?e:{}}function t(t){let n=e(t);return{pending:Array.isArray(n.pending)?n.pending:[],paired:Array.isArray(n.paired)?n.paired:[]}}function n(t){let n=e(t);return Array.isArray(n.nodes)?n.nodes:[]}function r(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+/,``).replace(/-+$/,``)}function i(e){return e.map(e=>e.displayName||e.remoteIp||e.nodeId).filter(Boolean).join(`, `)}function a(e,t){let n=t.trim();if(!n)return[];let i=r(n);return e.filter(e=>{if(e.nodeId===n||typeof e.remoteIp==`string`&&e.remoteIp===n)return!0;let t=typeof e.displayName==`string`?e.displayName:``;return!!(t&&r(t)===i||n.length>=6&&e.nodeId.startsWith(n))})}function o(e,t){let n=t.trim();if(!n)throw Error(`node required`);let r=a(e,n);if(r.length===1)return r[0]?.nodeId??``;if(r.length===0){let t=i(e);throw Error(`unknown node: ${n}${t?` (known: ${t})`:``}`)}let o=r.filter(e=>e.connected===!0),s=o.length>0?o:r;if(s.length===1)return s[0]?.nodeId??``;throw Error(`ambiguous node: ${n} (matches: ${s.map(e=>e.displayName||e.remoteIp||e.nodeId).join(`, `)})`)}function s(e,t,n={}){let r=String(t??``).trim();if(!r){if(n.allowDefault===!0&&n.pickDefaultNode){let t=n.pickDefaultNode(e);if(t)return t.nodeId}throw Error(`node required`)}return o(e,r)}function c(e,t,n={}){let r=s(e,t,n);return e.find(e=>e.nodeId===r)??{nodeId:r}}export{t as i,s as n,n as r,c as t};
