import{c3 as o,c9 as d,fp as s,fo as c,ha as y,hb as f,hc as p}from"./index-C4inJ1rU.js";function h(e){const a=e.payload_type??e.type;if(a!==o.TRACE||!e.payload)return null;try{const t=d(e.payload);let n=[];if(e._traceSnrPath!=null&&e._traceSnrPath.length>0)n=e._traceSnrPath;else if(e.raw_packet){const r=s(e.raw_packet,a);r&&r.length>0&&(n=r)}return c(t,n)}catch{return null}}function N(e){if((e.payload_type??e.type)!==o.ADVERT||!e.payload)return null;try{const t=d(e.payload),n=y(t);if(!n)return null;const r=n.publicKey.slice(0,2).toUpperCase(),l={...n,prefix:r};let i=null;return n.latitude&&n.longitude&&(i={latitude:n.latitude,longitude:n.longitude,name:n.name||`Node ${r||"??"}`,prefix:r,publicKey:n.publicKey}),{data:l,sourceNode:i}}catch{return null}}function u(e){if(!e)return null;const a=e.trim(),t=/(-?\d+\.?\d*)\s*[,\s]\s*(-?\d+\.?\d*)/,n=a.match(t);if(!n)return null;const r=parseFloat(n[1]),l=parseFloat(n[2]);return isNaN(r)||isNaN(l)||r<-90||r>90||l<-180||l>180||r===0&&l===0?null:{lat:r,lon:l}}function T(e){var t,n;if(!e.decrypted||!((t=e.channelName)!=null&&t.toLowerCase().includes("wardrive")))return null;const a=u(e.text);return a?{latitude:a.lat,longitude:a.lon,name:e.senderName||"Wardrive Ping",prefix:((n=e.senderName)==null?void 0:n.slice(0,2).toUpperCase())||"WD",nodeType:"wardrive"}:null}function C(e,a){const t=e.payload_type??e.type;if(t===o.TRACE){const n=h(e);if(n)return{kind:"trace",data:n,snrValues:n.snrValues}}if(t===o.ADVERT){const n=N(e);if(n)return{kind:"advert",data:n.data,sourceNode:n.sourceNode}}if(t===o.GRP_TXT&&a){const n=u(a.text),r=T(a);return{kind:"grp_txt",decoded:a,wardriveCoords:n,wardriveSourceNode:r}}if(t===o.CONTROL){const n=_(e);if(n)return{kind:"control",data:n}}if(t===o.ANON_REQ){const n=R(e);if(n)return{kind:"anon_req",data:n}}return{kind:"generic"}}function _(e){if((e.payload_type??e.type)!==o.CONTROL||!e.payload)return null;try{const t=d(e.payload);return f(t)}catch{return null}}function R(e){if((e.payload_type??e.type)!==o.ANON_REQ||!e.payload)return null;try{const t=d(e.payload),n=p(t);if(!n)return null;const r=n.senderPublicKey.slice(0,2).toUpperCase();return{...n,prefix:r}}catch{return null}}export{h as a,C as d,u as p};
