diff --git a/docs/wireframes/howl-bot-widgets.html b/docs/wireframes/howl-bot-widgets.html new file mode 100644 index 00000000..95a00a6d --- /dev/null +++ b/docs/wireframes/howl-bot-widgets.html @@ -0,0 +1,1161 @@ + + + + + +HOWL Bot Widget Wireframes — pymc_console + + + + +

🤖 HOWL Bot Widget Wireframes

+

First-draft SVG sketches for inline companion chat widgets — pymc_console

+ + + + + +
+

Tier 1 — Rich Visual Widgets

+ + +
+
+

WeatherWidget

+

iOS-style weather card with condition gradient, large temp, detail pills, hi/lo bar, tomorrow preview.

+

wx gwx

+
+
+
+
🤖
+
+ HowlBot 🤖 bot +
+
+ + + + + + + + + + + + + + + + 🤖 + + Portland, OR + + ☀️ + 75° + Sunny + + + + 💨 NW 10 + + 💧 45% + + 👁️ 10mi + + 📊 30.12 + + + + + L 55° + + + + + H 78° + + + + + Tomorrow + ☁️ + Cloudy 70° / 58° + + +
+
+ + +
+
+

WeatherMultidayWidget

+

Horizontal scrollable day forecast cards. Each day: abbreviation, emoji, hi/lo temps.

+

wx 3 gwx 5

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + + + + + Mon + ☀️ + 75° + 55° + + + Tue + + 68° + 52° + + + Wed + 🌧️ + 62° + 48° + + + Thu + ☁️ + 65° + 50° + + + Fri + ☀️ + 72° + 54° + + + + + +
+
+ + +
+
+

WeatherHourlyWidget

+

Horizontal hour pills: time, emoji, temp, precip%. Optional signal score overlay.

+

wx hourly

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + + + + + 10AM + 🌦️ + 49° + 26% + + + + 11AM + ☁️ + 51° + 12% + + + + 12PM + + 54° + 5% + + + + 1PM + ☀️ + 57° + + + + + 2PM + ☀️ + 59° + + + + + 3PM + ☀️ + 58° + + + + +
+
+ + +
+
+

AqiWidget

+

Arc gauge with AQI value + EPA color. Category label. Pollutant breakdown pills below.

+

aqi

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + + + + + + + + 🤖 + Portland, OR + + + + + + + + + + 42 + Good + + + + + PM2.5: 10 + + PM10: 15 + + O₃: 28 + + NO₂: 5 + + CO: 200 + + + + Good + Mod + USG + Unhl + VUnhl + Haz + + +
+
+ + +
+
+

SolarWidget

+

Key-value grid for solar indices. K-Index gets color coding (green→red).

+

solar

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + + ☀️ Solar Conditions + + + + + A-Index + 5 + + + K-Index + 2 + + + + + Sunspots + 120 + + + X-Ray Flux + C1.5 + + + Solar Flux + 150 + + + Signal Noise + S3 + + +
+
+ + +
+
+

HfCondWidget

+

Two-column day/night HF band conditions. Each band as a colored status pill.

+

hfcond

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + 📡 HF Band Conditions + + + ☀️ DAY + + 80m–40m + + Good + + + 30m–20m + + Good + + + 17m–15m + + Fair + + + + 🌙 NIGHT + + 80m–40m + + Poor + + + 30m–20m + + Poor + + + 17m–15m + + Poor + + +
+
+ + +
+
+

SunWidget

+

Sun arc SVG showing current position along the rise→set trajectory. Daylight + remaining readout.

+

sun

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + + + + + + 🤖 + + + + + + + + + + + ☀️ + + 🌅 6:42a + 🌇 7:15p + + + + + ☀️ 12h 33m + + ⏳ 5h 22m left + + Az 245° Alt 35° + + +
+
+ + +
+
+

MoonWidget

+

Large moon phase emoji + illumination ring. Rise/set, next full/new moon dates.

+

moon

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + + + + + + 🤖 + + + + + + + 🌖 + + 68% + + + + Waning Gibbous + + Rise + Mon 6:47 PM + Set + Tue 3:43 AM + + + + 🌕 Full + Mon Sep 7 9:15p + 🌑 New + Sun Sep 21 3:30a + + +
+
+ + +
+
+

SatPassWidget

+

Satellite pass arc with compass directions. Rise→peak→set timeline. Max elevation callout.

+

satpass

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + + 🛰️ ISS + Mon 15 · 12m 15s pass + + + + + + + + + + + + + 75° + + NW + N + SE + + + + + + + 6:42 PM + + + 6:54 PM + + +
+
+ + +
+
+

AuroraWidget

+

KP index with color scale gauge. Probability bar + location. Aurora-themed gradient.

+

aurora

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + + + + + + + 🤖 + + 🌌 Aurora Forecast · Seattle + Mar 15 2PM + + + 3.2 + KP Index + + Quiet + + + + + + + + 0 + 3 + 5 + 7 + 9 + + + + Probability + 18% + + + + + +
+
+ + +
+
+

PathWidget

+

Reuses existing CompanionPathMap auto-expanded. Hop badges with confidence indicators above the map.

+

path decode

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + 🗺️ Path Decode + + + + + AB + → Hilltop + 🎯 + + + + + CD + → MtHood + 📍 + + + + + EF + → ? + + + + + + CompanionPathMap + + + + + + + + +
+
+ + +
+
+

TestWidget

+

Signal quality card with SNR bars, hop count, path, distance. Clean data-box layout.

+

test t

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + 📶 Link Test + + + + + + + + + + + +6.5 + SNR dB + -82 dBm + + + + + Echo phrase + "Hello mesh!" + + + + + Hops + 3 + + + Path + AB → CD → EF + + + Distance + 14.2 km + + +
+
+ + +
+
+

StatsWidget

+

Two modes: summary counts (cmds/replies/top) or leaderboard with micro bar chart.

+

stats

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + 📊 Bot Stats (24h) + + + + Commands + 42 + + + Replies + 40 + + + Top Cmd + wx (15) + + + + + Top Users + + 1. + NodeAlpha + + + 8 + + 2. + BetaNode + + + 5 + + 3. + GammaRepeater + + + 3 + + +
+
+ + +
+
+

SportsWidget

+

Game score cards stacked vertically. Live games pulse, final games badge, scheduled show time.

+

sports scores

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + 🏆 Scores + + + + + + + + + + 🏈 + SEA 24 + + SF 17 + + 4th · 8:42 + + + + + + SEA 5 + + OAK 3 + + Final + + W + + +
+
+ +
+ + + + + +
+

Tier 2 — Enhanced Text Widgets

+ + +
+
+

WeatherAlertWidget

+

Amber/red gradient banner. Severity-colored left border. Expandable truncation for long alerts.

+

⚠️ alert response

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + + + + + + + + 🤖 + + + ⚠️ + + WIND ADVISORY + + + + + NW winds 25-35 mph with gusts to + + + 50 mph until 6PM PST + + + + tap to expand › + +
+
+ + +
+
+

AlertWidget

+

Standalone NWS alert card (from alert command). Red variant for severe.

+

alert

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + 🤖 + + 🚨 + + TORNADO WARNING + + Take shelter immediately. Tornado + confirmed in your area until 4:30 PM. + +
+
+ + +
+
+

JokeWidget

+

Card with emoji header. Two-part jokes: setup visible, delivery revealed on tap with a subtle slide animation.

+

joke dadjoke

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + + 🎭 + + Joke + + Why do programmers prefer + dark mode? + + + Because light attracts bugs! 🐛 + + + +
+
+ + +
+
+

DiceWidget

+

Dice emoji + die type label, individual results in circles, total. Supports mixed dice.

+

dice roll

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + + 🎲 + 2d6 + + + + + 3 + + + + + + 5 + + = + + + 8 + + +
+
+ + +
+
+

CatFactWidget

+

Subtle cat-themed card with paw print motif. Fact text + trailing emoji preserved.

+

catfact meow

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + 🤖 + + 🐾 + + 🐱 + + Cat Fact + + Cats can rotate their ears 180° + independently to pinpoint sounds. 👂 + +
+
+ +
+ + + + + +
+

Tier 3 — Styled Bot Text Fallback

+ + +
+
+

BotTextWidget

+

For ping, magic8, and any unclassified bot response. Visually distinct from normal bubbles with subtle bot indicator + glass card treatment.

+

ping magic8 fallback

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + 🤖 bot response + Pong! + + + + + + 🤖 bot response + 🎱 Signs point to yes + +
+
+ +
+ + + + + +
+

Unified Container — BotWidgetContainer

+ +
+
+

Container Anatomy

+

Every widget sits inside this container. Provides: glass card, 🤖 badge, consistent padding, rounded corners matching ChatBubble's rounded-2xl rounded-tl-md.

+

Replaces ChatBubble's inner <div> — avatar + sender name row stays from the existing layout.

+
+
+
+
🤖
+ HowlBot 🤖 bot +
+ + + + + + + 🤖 bot + + + + + Widget Content Area + SVGs · Custom Fonts · Canvas · HTML + + + padding 16px + + radius-inset (12px) · bg-surface/80 · backdrop-blur · ring-edge-subtle + +
+
+ +
+ +

+ HOWL Bot Wireframes v0.1 — First-draft sketches for collaboration. All colors reference pymc_console CSS variables (sys-*, zinc-*). + Open this file in a browser to preview. +

+ + + diff --git a/frontend/dist/VERSION b/frontend/dist/VERSION index 2d41f236..caef596e 100644 --- a/frontend/dist/VERSION +++ b/frontend/dist/VERSION @@ -1 +1 @@ -0.9.312 +0.9.313 diff --git a/frontend/dist/assets/AnalyzerFilterPanel-6rdoNUd9.js b/frontend/dist/assets/AnalyzerFilterPanel-DRXSWRku.js similarity index 98% rename from frontend/dist/assets/AnalyzerFilterPanel-6rdoNUd9.js rename to frontend/dist/assets/AnalyzerFilterPanel-DRXSWRku.js index 5522d445..1994d859 100644 --- a/frontend/dist/assets/AnalyzerFilterPanel-6rdoNUd9.js +++ b/frontend/dist/assets/AnalyzerFilterPanel-DRXSWRku.js @@ -1,4 +1,4 @@ -import{e as U,c_ as J,ao as q,aa as G,cE as Q,cs as V,r as d,j as n,bM as K,B as Y}from"./index-BXuscHlA.js";import{c as Z}from"./node-types-DcVrjPZe.js";import{C as W}from"./circle-question-mark-BRhEuEaL.js";import{F as ee}from"./funnel-H6zOOlsG.js";import{S as te}from"./search-CJVt1qRW.js";/** +import{e as U,c_ as J,ao as q,aa as G,cE as Q,cs as V,r as d,j as n,bM as K,B as Y}from"./index-BBBuaCQs.js";import{c as Z}from"./node-types-DJyFsA81.js";import{C as W}from"./circle-question-mark-CI9cD3nq.js";import{F as ee}from"./funnel-C8NxsG5E.js";import{S as te}from"./search-Dk9GWMDh.js";/** * @license lucide-react v0.559.0 - ISC * * This source code is licensed under the ISC license. diff --git a/frontend/dist/assets/AutoConfigureDialog-BYa3iJhA.js b/frontend/dist/assets/AutoConfigureDialog-2NSNWjfu.js similarity index 98% rename from frontend/dist/assets/AutoConfigureDialog-BYa3iJhA.js rename to frontend/dist/assets/AutoConfigureDialog-2NSNWjfu.js index 3b85498c..231746ed 100644 --- a/frontend/dist/assets/AutoConfigureDialog-BYa3iJhA.js +++ b/frontend/dist/assets/AutoConfigureDialog-2NSNWjfu.js @@ -1 +1 @@ -import{r as f,ef as Q,j as e,a7 as X,aa as Z,c3 as M,cs as U,cE as V,ew as G,eB as ee,aC as ae,aK as se,aD as te,a2 as J,bY as ne,B as w,c as g,aE as le}from"./index-BXuscHlA.js";import{C as ie}from"./PageLayout-DMlJphZf.js";import{W as re}from"./wand-sparkles-BtQTQ8OM.js";import{A as oe}from"./arrow-right-BLOvRmAV.js";const ce={0:"1-byte",1:"2-byte",2:"3-byte"};function de(s){return ce[s]??`${s+1}-byte`}function ke({nodeName:s,publicKey:a,pathHashMode:r}){const[c,n]=f.useState(null),[o,m]=f.useState(null);f.useEffect(()=>{let l=!1;return(async()=>{try{const p=await Q();if(l)return;if(p.success&&p.data){const h=p.data;n(Array.isArray(h.configured)?h.configured:[]),m(Array.isArray(h.configured_companions)?h.configured_companions:[])}}catch{}})(),()=>{l=!0}},[]);const y=l=>{var p;return((p=l.settings)==null?void 0:p.node_name)||l.name};return e.jsxs(ie,{neomorphic:!0,children:[e.jsx(X,{icon:e.jsx(Z,{}),title:"Node Information"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 sm:gap-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Repeater Name"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:e.jsxs("div",{children:[e.jsx("p",{className:"type-data text-fg-primary truncate font-mono",title:s,children:s}),a&&e.jsx("div",{className:"mt-1 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:a})})]})}),r!=null&&e.jsxs("div",{className:"mt-4",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Path Hash Size"}),e.jsx("p",{className:"type-data text-fg-primary mt-0.5 font-mono",children:de(r)})]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Room Servers"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:c===null?e.jsx("span",{className:"type-data text-fg-muted",children:"—"}):c.length===0?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-muted",children:"None"})]}):c.map(l=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-primary truncate",title:y(l),children:y(l)})]}),(l.public_key||l.identity_key)&&e.jsx("div",{className:"mt-1 pl-5 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:l.public_key||l.identity_key})})]},l.name))})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Companions"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:o===null?e.jsx("span",{className:"type-data text-fg-muted",children:"—"}):o.length===0?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(V,{className:"w-3.5 h-3.5 text-sys-cyan flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-muted",children:"None"})]}):o.map(l=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(V,{className:"w-3.5 h-3.5 text-sys-cyan flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-primary truncate",title:y(l),children:y(l)})]}),(l.public_key||l.identity_key)&&e.jsx("div",{className:"mt-1 pl-5 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:l.public_key||l.identity_key})})]},l.name))})]})]})]})}const j=168,S={sparse:50,light:200,moderate:500,dense:1e3},me={sparse:{bucketCapacity:3,refillTokens:1,refillIntervalHours:1,minIntervalSeconds:15,violationThreshold:2,basePenaltyMinutes:30,penaltyMultiplier:2,maxPenaltyHours:12,violationDecayHours:2,ewmaAlpha:.15,hysteresisMinutes:8},light:{bucketCapacity:2,refillTokens:1,refillIntervalHours:1,minIntervalSeconds:20,violationThreshold:2,basePenaltyMinutes:60,penaltyMultiplier:3,maxPenaltyHours:24,violationDecayHours:2,ewmaAlpha:.12,hysteresisMinutes:6},moderate:{bucketCapacity:2,refillTokens:1,refillIntervalHours:2,minIntervalSeconds:30,violationThreshold:1,basePenaltyMinutes:120,penaltyMultiplier:4,maxPenaltyHours:48,violationDecayHours:4,ewmaAlpha:.1,hysteresisMinutes:5},dense:{bucketCapacity:1,refillTokens:1,refillIntervalHours:4,minIntervalSeconds:60,violationThreshold:1,basePenaltyMinutes:180,penaltyMultiplier:4,maxPenaltyHours:72,violationDecayHours:6,ewmaAlpha:.08,hysteresisMinutes:3},congested:{bucketCapacity:1,refillTokens:1,refillIntervalHours:8,minIntervalSeconds:120,violationThreshold:1,basePenaltyMinutes:360,penaltyMultiplier:4,maxPenaltyHours:168,violationDecayHours:12,ewmaAlpha:.03,hysteresisMinutes:2}};function pe(s){return si.type===4))==null?void 0:h.count)??0,c=a.drop_reasons??[],n=((N=c.find(i=>i.reason==="advert rate limit exceeded"))==null?void 0:N.count)??0,o=c.filter(i=>i.reason.startsWith("advert penalty box")).reduce((i,d)=>i+d.count,0),m=((_=c.find(i=>i.reason==="Duplicate"))==null?void 0:_.count)??0;let y=0;try{const i=await G("/api/advert_rate_limit_stats");i.success&&i.data&&(y=i.data.tracked_pubkeys??Object.keys(i.data.bucket_states??{}).length)}catch{y=Math.max(1,Math.round(r/j/12))}const l=a.total_packets/j,p=r/j;return{hours:j,totalPackets:a.total_packets,transmittedPackets:a.transmitted_packets,droppedPackets:a.dropped_packets,packetsPerHour:l,advertsPerHour:p,advertPercent:a.total_packets>0?r/a.total_packets*100:0,advertCount:r,trackedSources:Math.max(1,y),advertsPerSourcePerHour:p/Math.max(1,y),rateLimitDrops:n,penaltyBoxDrops:o,duplicateDrops:m,meshDensity:pe(l)}}function ue(s){const a=me[s.meshDensity],r=s.packetsPerHour/60,c=Math.max(.01,B(r*.2)),n=Math.max(c+.01,B(r*.5)),o=Math.max(n+.01,B(r*.9));return{tokenBucket:{enabled:!0,bucket_capacity:a.bucketCapacity,refill_tokens:a.refillTokens,refill_interval_seconds:a.refillIntervalHours*3600,min_interval_seconds:a.minIntervalSeconds},penaltyBox:{enabled:!0,violation_threshold:a.violationThreshold,base_penalty_seconds:a.basePenaltyMinutes*60,penalty_multiplier:a.penaltyMultiplier,max_penalty_seconds:a.maxPenaltyHours*3600,violation_decay_seconds:a.violationDecayHours*3600},adaptive:{enabled:!0,ewma_alpha:a.ewmaAlpha,hysteresis_seconds:a.hysteresisMinutes*60,thresholds:{quiet_max:c,normal_max:n,busy_max:o}}}}async function ye(s){const a=await xe(),r=ue(a);return{analysis:a,recommended:r,current:{tokenBucket:s.tokenBucket??null,penaltyBox:s.penaltyBox??null,adaptive:s.adaptive??null}}}function B(s){return Math.round(s*100)/100}function k(s){if(s<60)return`${s}s`;if(s<3600)return`${Math.floor(s/60)}m`;const a=s/3600;return a===Math.floor(a)?`${a}h`:`${a.toFixed(1)}h`}function A(s){return s.toLocaleString(void 0,{maximumFractionDigits:1})}const he={sparse:"Sparse",light:"Light",moderate:"Moderate",dense:"Dense",congested:"Congested"},fe={sparse:"text-sys-green",light:"text-sys-cyan",moderate:"text-sys-blue",dense:"text-sys-amber",congested:"text-sys-red"},ge={rate_limit_enabled:!1,bucket_capacity:10,refill_tokens:5,refill_interval_seconds:3600,min_interval_seconds:0,penalty_enabled:!1,violation_threshold:5,base_penalty_seconds:1800,penalty_multiplier:2,max_penalty_seconds:86400,violation_decay_seconds:21600,adaptive_enabled:!1,ewma_alpha:.1,hysteresis_seconds:300,quiet_max:2,normal_max:6,busy_max:10},Ne=["rate_limit_enabled","bucket_capacity","refill_tokens","refill_interval_seconds","min_interval_seconds","penalty_enabled","violation_threshold","base_penalty_seconds","penalty_multiplier","max_penalty_seconds","violation_decay_seconds","adaptive_enabled","ewma_alpha","hysteresis_seconds","quiet_max","normal_max","busy_max"];function D({title:s,enabled:a,defaultOpen:r=!1,children:c}){const[n,o]=f.useState(r);return e.jsxs("div",{className:"bg-subtle-fill radius-inner overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>o(!n),className:"w-full flex items-center justify-between px-4 py-3 hover:bg-subtle-fill-hover transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"type-label text-fg-muted",children:s}),e.jsx("span",{className:g("type-data-xs px-1.5 py-0.5 rounded-full font-medium uppercase tracking-wide",a?"bg-sys-green/15 text-sys-green":"bg-sys-red/15 text-sys-red"),children:a?"On":"Off"})]}),e.jsx(le,{className:g("w-4 h-4 text-fg-muted transition-transform",n&&"rotate-180")})]}),n&&e.jsx("div",{className:"px-4 pb-4 pt-1 space-y-1",children:c})]})}function u({label:s,current:a,recommended:r,format:c=n=>String(n)}){const n=a!=null?c(a):"—",o=c(r),m=a!=null&&n!==o;return e.jsxs("div",{className:"flex items-center justify-between gap-2 py-1",children:[e.jsx("span",{className:"type-body-sm text-fg-muted flex-1 min-w-0 truncate",children:s}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("span",{className:g("data-box data-box-compact",m?"text-fg-muted line-through opacity-60":"text-fg-secondary"),children:n}),m&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-3 h-3 text-fg-muted"}),e.jsx("span",{className:"data-box data-box-compact text-sys-blue font-medium",children:o})]})]})]})}function we({open:s,onClose:a,currentConfig:r,onApplied:c}){var C,H,P,T,I,R,E,L,$,z,F,O,q,Y;const[n,o]=f.useState("idle"),[m,y]=f.useState(null),[l,p]=f.useState(null),h=f.useCallback(async()=>{o("analyzing"),p(null);try{const t=await ye(r);y(t),o("ready")}catch(t){p(t instanceof Error?t.message:"Analysis failed"),o("error")}},[r]),N=f.useCallback(async()=>{if(!m)return;o("applying"),p(null);const{tokenBucket:t,penaltyBox:b,adaptive:v}=m.recommended,K={rate_limit_enabled:t.enabled,bucket_capacity:t.bucket_capacity,refill_tokens:t.refill_tokens,refill_interval_seconds:t.refill_interval_seconds,min_interval_seconds:t.min_interval_seconds,penalty_enabled:b.enabled,violation_threshold:b.violation_threshold,base_penalty_seconds:b.base_penalty_seconds,penalty_multiplier:b.penalty_multiplier,max_penalty_seconds:b.max_penalty_seconds,violation_decay_seconds:b.violation_decay_seconds,adaptive_enabled:v.enabled,ewma_alpha:v.ewma_alpha,hysteresis_seconds:v.hysteresis_seconds,quiet_max:v.thresholds.quiet_max,normal_max:v.thresholds.normal_max,busy_max:v.thresholds.busy_max};try{const W=await ee(K);W.success?(o("applied"),c==null||c()):(p(W.error||"Failed to apply settings"),o("error"))}catch{p("Failed to apply settings"),o("error")}},[m,c]),_=f.useCallback(()=>{a(),setTimeout(()=>{o("idle"),y(null),p(null)},300)},[a]);s&&n==="idle"&&h();const i=m==null?void 0:m.analysis,d=m==null?void 0:m.recommended,x=m==null?void 0:m.current;return e.jsxs(ae,{open:s,onClose:_,size:"lg",children:[e.jsx(se,{icon:e.jsx(re,{size:20}),title:"Auto-Configure",onClose:_}),e.jsxs(te,{className:"flex flex-col gap-5 max-h-[70vh] overflow-y-auto",children:[n==="analyzing"&&e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-12",children:[e.jsx(J,{className:"w-6 h-6 text-sys-blue animate-spin"}),e.jsx("p",{className:"type-body-sm text-fg-muted",children:"Analyzing 7 days of mesh traffic…"})]}),n==="error"&&e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-8",children:[e.jsx(ne,{className:"w-6 h-6 text-sys-amber"}),e.jsx("p",{className:"type-body-sm text-fg-secondary",children:l}),e.jsx(w,{plain:!0,onClick:h,className:"text-sys-blue",children:"Retry"})]}),(n==="ready"||n==="applying"||n==="applied")&&i&&d&&x&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("div",{className:"type-micro mb-3",children:"7-DAY ANALYSIS"}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Pkts/hr"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:A(i.packetsPerHour)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Adverts/hr"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:A(i.advertsPerHour)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Sources"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:i.trackedSources})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Density"}),e.jsx("div",{className:g("data-box data-box-fill data-box-left",fe[i.meshDensity]),children:he[i.meshDensity]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(D,{title:"Token Bucket of Shame",enabled:d.tokenBucket.enabled,defaultOpen:!0,children:[e.jsx(u,{label:"Bucket Capacity",current:(C=x.tokenBucket)==null?void 0:C.bucket_capacity,recommended:d.tokenBucket.bucket_capacity,format:t=>`${t} tokens`}),e.jsx(u,{label:"Refill Tokens",current:(H=x.tokenBucket)==null?void 0:H.refill_tokens,recommended:d.tokenBucket.refill_tokens,format:t=>`${t} tokens`}),e.jsx(u,{label:"Refill Interval",current:(P=x.tokenBucket)==null?void 0:P.refill_interval_seconds,recommended:d.tokenBucket.refill_interval_seconds,format:t=>k(t)}),e.jsx(u,{label:"Min Interval",current:(T=x.tokenBucket)==null?void 0:T.min_interval_seconds,recommended:d.tokenBucket.min_interval_seconds,format:t=>`${t}s`})]}),e.jsxs(D,{title:"Jail",enabled:d.penaltyBox.enabled,children:[e.jsx(u,{label:"Violation Threshold",current:(I=x.penaltyBox)==null?void 0:I.violation_threshold,recommended:d.penaltyBox.violation_threshold,format:t=>`${t} violations`}),e.jsx(u,{label:"Base Penalty",current:(R=x.penaltyBox)==null?void 0:R.base_penalty_seconds,recommended:d.penaltyBox.base_penalty_seconds,format:t=>k(t)}),e.jsx(u,{label:"Multiplier",current:(E=x.penaltyBox)==null?void 0:E.penalty_multiplier,recommended:d.penaltyBox.penalty_multiplier,format:t=>`${t}×`}),e.jsx(u,{label:"Max Penalty",current:(L=x.penaltyBox)==null?void 0:L.max_penalty_seconds,recommended:d.penaltyBox.max_penalty_seconds,format:t=>k(t)}),e.jsx(u,{label:"Violation Decay",current:($=x.penaltyBox)==null?void 0:$.violation_decay_seconds,recommended:d.penaltyBox.violation_decay_seconds,format:t=>k(t)})]}),e.jsxs(D,{title:"Adaptive Tiers",enabled:d.adaptive.enabled,children:[e.jsx(u,{label:"EWMA α",current:(z=x.adaptive)==null?void 0:z.ewma_alpha,recommended:d.adaptive.ewma_alpha}),e.jsx(u,{label:"Hysteresis",current:(F=x.adaptive)==null?void 0:F.hysteresis_seconds,recommended:d.adaptive.hysteresis_seconds,format:t=>k(t)}),e.jsx(u,{label:"Quiet Max",current:(O=x.adaptive)==null?void 0:O.thresholds.quiet_max,recommended:d.adaptive.thresholds.quiet_max,format:t=>`${t} pkts/min`}),e.jsx(u,{label:"Normal Max",current:(q=x.adaptive)==null?void 0:q.thresholds.normal_max,recommended:d.adaptive.thresholds.normal_max,format:t=>`${t} pkts/min`}),e.jsx(u,{label:"Busy Max",current:(Y=x.adaptive)==null?void 0:Y.thresholds.busy_max,recommended:d.adaptive.thresholds.busy_max,format:t=>`${t} pkts/min`})]})]}),e.jsxs("div",{className:g("flex justify-between gap-4 pt-1",n==="applied"?"items-center":"items-end"),children:[n==="applied"?e.jsx("span",{className:"type-body-sm text-zinc-500",children:"Settings applied"}):e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Analyzed"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[A(i.totalPackets)," packets"]})]}),e.jsx("div",{className:"flex items-center gap-2",children:n==="applied"?e.jsx(w,{color:"primary",onClick:_,children:"Done"}):e.jsxs(e.Fragment,{children:[e.jsx(w,{plain:!0,onClick:_,children:"Cancel"}),e.jsx(w,{color:"primary",onClick:N,disabled:n==="applying",children:n==="applying"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Applying…"]}):"Apply All"})]})})]})]})]})]})}export{we as A,ke as N,ge as S,Ne as a}; +import{r as f,ef as Q,j as e,a7 as X,aa as Z,c3 as M,cs as U,cE as V,ew as G,eB as ee,aC as ae,aK as se,aD as te,a2 as J,bY as ne,B as w,c as g,aE as le}from"./index-BBBuaCQs.js";import{C as ie}from"./PageLayout-CRsVqzTw.js";import{W as re}from"./wand-sparkles-C15_vEeB.js";import{A as oe}from"./arrow-right-BNRZQuRI.js";const ce={0:"1-byte",1:"2-byte",2:"3-byte"};function de(s){return ce[s]??`${s+1}-byte`}function ke({nodeName:s,publicKey:a,pathHashMode:r}){const[c,n]=f.useState(null),[o,m]=f.useState(null);f.useEffect(()=>{let l=!1;return(async()=>{try{const p=await Q();if(l)return;if(p.success&&p.data){const h=p.data;n(Array.isArray(h.configured)?h.configured:[]),m(Array.isArray(h.configured_companions)?h.configured_companions:[])}}catch{}})(),()=>{l=!0}},[]);const y=l=>{var p;return((p=l.settings)==null?void 0:p.node_name)||l.name};return e.jsxs(ie,{neomorphic:!0,children:[e.jsx(X,{icon:e.jsx(Z,{}),title:"Node Information"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 sm:gap-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Repeater Name"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:e.jsxs("div",{children:[e.jsx("p",{className:"type-data text-fg-primary truncate font-mono",title:s,children:s}),a&&e.jsx("div",{className:"mt-1 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:a})})]})}),r!=null&&e.jsxs("div",{className:"mt-4",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Path Hash Size"}),e.jsx("p",{className:"type-data text-fg-primary mt-0.5 font-mono",children:de(r)})]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Room Servers"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:c===null?e.jsx("span",{className:"type-data text-fg-muted",children:"—"}):c.length===0?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-muted",children:"None"})]}):c.map(l=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-primary truncate",title:y(l),children:y(l)})]}),(l.public_key||l.identity_key)&&e.jsx("div",{className:"mt-1 pl-5 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:l.public_key||l.identity_key})})]},l.name))})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Companions"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:o===null?e.jsx("span",{className:"type-data text-fg-muted",children:"—"}):o.length===0?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(V,{className:"w-3.5 h-3.5 text-sys-cyan flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-muted",children:"None"})]}):o.map(l=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(V,{className:"w-3.5 h-3.5 text-sys-cyan flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-primary truncate",title:y(l),children:y(l)})]}),(l.public_key||l.identity_key)&&e.jsx("div",{className:"mt-1 pl-5 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:l.public_key||l.identity_key})})]},l.name))})]})]})]})}const j=168,S={sparse:50,light:200,moderate:500,dense:1e3},me={sparse:{bucketCapacity:3,refillTokens:1,refillIntervalHours:1,minIntervalSeconds:15,violationThreshold:2,basePenaltyMinutes:30,penaltyMultiplier:2,maxPenaltyHours:12,violationDecayHours:2,ewmaAlpha:.15,hysteresisMinutes:8},light:{bucketCapacity:2,refillTokens:1,refillIntervalHours:1,minIntervalSeconds:20,violationThreshold:2,basePenaltyMinutes:60,penaltyMultiplier:3,maxPenaltyHours:24,violationDecayHours:2,ewmaAlpha:.12,hysteresisMinutes:6},moderate:{bucketCapacity:2,refillTokens:1,refillIntervalHours:2,minIntervalSeconds:30,violationThreshold:1,basePenaltyMinutes:120,penaltyMultiplier:4,maxPenaltyHours:48,violationDecayHours:4,ewmaAlpha:.1,hysteresisMinutes:5},dense:{bucketCapacity:1,refillTokens:1,refillIntervalHours:4,minIntervalSeconds:60,violationThreshold:1,basePenaltyMinutes:180,penaltyMultiplier:4,maxPenaltyHours:72,violationDecayHours:6,ewmaAlpha:.08,hysteresisMinutes:3},congested:{bucketCapacity:1,refillTokens:1,refillIntervalHours:8,minIntervalSeconds:120,violationThreshold:1,basePenaltyMinutes:360,penaltyMultiplier:4,maxPenaltyHours:168,violationDecayHours:12,ewmaAlpha:.03,hysteresisMinutes:2}};function pe(s){return si.type===4))==null?void 0:h.count)??0,c=a.drop_reasons??[],n=((N=c.find(i=>i.reason==="advert rate limit exceeded"))==null?void 0:N.count)??0,o=c.filter(i=>i.reason.startsWith("advert penalty box")).reduce((i,d)=>i+d.count,0),m=((_=c.find(i=>i.reason==="Duplicate"))==null?void 0:_.count)??0;let y=0;try{const i=await G("/api/advert_rate_limit_stats");i.success&&i.data&&(y=i.data.tracked_pubkeys??Object.keys(i.data.bucket_states??{}).length)}catch{y=Math.max(1,Math.round(r/j/12))}const l=a.total_packets/j,p=r/j;return{hours:j,totalPackets:a.total_packets,transmittedPackets:a.transmitted_packets,droppedPackets:a.dropped_packets,packetsPerHour:l,advertsPerHour:p,advertPercent:a.total_packets>0?r/a.total_packets*100:0,advertCount:r,trackedSources:Math.max(1,y),advertsPerSourcePerHour:p/Math.max(1,y),rateLimitDrops:n,penaltyBoxDrops:o,duplicateDrops:m,meshDensity:pe(l)}}function ue(s){const a=me[s.meshDensity],r=s.packetsPerHour/60,c=Math.max(.01,B(r*.2)),n=Math.max(c+.01,B(r*.5)),o=Math.max(n+.01,B(r*.9));return{tokenBucket:{enabled:!0,bucket_capacity:a.bucketCapacity,refill_tokens:a.refillTokens,refill_interval_seconds:a.refillIntervalHours*3600,min_interval_seconds:a.minIntervalSeconds},penaltyBox:{enabled:!0,violation_threshold:a.violationThreshold,base_penalty_seconds:a.basePenaltyMinutes*60,penalty_multiplier:a.penaltyMultiplier,max_penalty_seconds:a.maxPenaltyHours*3600,violation_decay_seconds:a.violationDecayHours*3600},adaptive:{enabled:!0,ewma_alpha:a.ewmaAlpha,hysteresis_seconds:a.hysteresisMinutes*60,thresholds:{quiet_max:c,normal_max:n,busy_max:o}}}}async function ye(s){const a=await xe(),r=ue(a);return{analysis:a,recommended:r,current:{tokenBucket:s.tokenBucket??null,penaltyBox:s.penaltyBox??null,adaptive:s.adaptive??null}}}function B(s){return Math.round(s*100)/100}function k(s){if(s<60)return`${s}s`;if(s<3600)return`${Math.floor(s/60)}m`;const a=s/3600;return a===Math.floor(a)?`${a}h`:`${a.toFixed(1)}h`}function A(s){return s.toLocaleString(void 0,{maximumFractionDigits:1})}const he={sparse:"Sparse",light:"Light",moderate:"Moderate",dense:"Dense",congested:"Congested"},fe={sparse:"text-sys-green",light:"text-sys-cyan",moderate:"text-sys-blue",dense:"text-sys-amber",congested:"text-sys-red"},ge={rate_limit_enabled:!1,bucket_capacity:10,refill_tokens:5,refill_interval_seconds:3600,min_interval_seconds:0,penalty_enabled:!1,violation_threshold:5,base_penalty_seconds:1800,penalty_multiplier:2,max_penalty_seconds:86400,violation_decay_seconds:21600,adaptive_enabled:!1,ewma_alpha:.1,hysteresis_seconds:300,quiet_max:2,normal_max:6,busy_max:10},Ne=["rate_limit_enabled","bucket_capacity","refill_tokens","refill_interval_seconds","min_interval_seconds","penalty_enabled","violation_threshold","base_penalty_seconds","penalty_multiplier","max_penalty_seconds","violation_decay_seconds","adaptive_enabled","ewma_alpha","hysteresis_seconds","quiet_max","normal_max","busy_max"];function D({title:s,enabled:a,defaultOpen:r=!1,children:c}){const[n,o]=f.useState(r);return e.jsxs("div",{className:"bg-subtle-fill radius-inner overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>o(!n),className:"w-full flex items-center justify-between px-4 py-3 hover:bg-subtle-fill-hover transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"type-label text-fg-muted",children:s}),e.jsx("span",{className:g("type-data-xs px-1.5 py-0.5 rounded-full font-medium uppercase tracking-wide",a?"bg-sys-green/15 text-sys-green":"bg-sys-red/15 text-sys-red"),children:a?"On":"Off"})]}),e.jsx(le,{className:g("w-4 h-4 text-fg-muted transition-transform",n&&"rotate-180")})]}),n&&e.jsx("div",{className:"px-4 pb-4 pt-1 space-y-1",children:c})]})}function u({label:s,current:a,recommended:r,format:c=n=>String(n)}){const n=a!=null?c(a):"—",o=c(r),m=a!=null&&n!==o;return e.jsxs("div",{className:"flex items-center justify-between gap-2 py-1",children:[e.jsx("span",{className:"type-body-sm text-fg-muted flex-1 min-w-0 truncate",children:s}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("span",{className:g("data-box data-box-compact",m?"text-fg-muted line-through opacity-60":"text-fg-secondary"),children:n}),m&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-3 h-3 text-fg-muted"}),e.jsx("span",{className:"data-box data-box-compact text-sys-blue font-medium",children:o})]})]})]})}function we({open:s,onClose:a,currentConfig:r,onApplied:c}){var C,H,P,T,I,R,E,L,$,z,F,O,q,Y;const[n,o]=f.useState("idle"),[m,y]=f.useState(null),[l,p]=f.useState(null),h=f.useCallback(async()=>{o("analyzing"),p(null);try{const t=await ye(r);y(t),o("ready")}catch(t){p(t instanceof Error?t.message:"Analysis failed"),o("error")}},[r]),N=f.useCallback(async()=>{if(!m)return;o("applying"),p(null);const{tokenBucket:t,penaltyBox:b,adaptive:v}=m.recommended,K={rate_limit_enabled:t.enabled,bucket_capacity:t.bucket_capacity,refill_tokens:t.refill_tokens,refill_interval_seconds:t.refill_interval_seconds,min_interval_seconds:t.min_interval_seconds,penalty_enabled:b.enabled,violation_threshold:b.violation_threshold,base_penalty_seconds:b.base_penalty_seconds,penalty_multiplier:b.penalty_multiplier,max_penalty_seconds:b.max_penalty_seconds,violation_decay_seconds:b.violation_decay_seconds,adaptive_enabled:v.enabled,ewma_alpha:v.ewma_alpha,hysteresis_seconds:v.hysteresis_seconds,quiet_max:v.thresholds.quiet_max,normal_max:v.thresholds.normal_max,busy_max:v.thresholds.busy_max};try{const W=await ee(K);W.success?(o("applied"),c==null||c()):(p(W.error||"Failed to apply settings"),o("error"))}catch{p("Failed to apply settings"),o("error")}},[m,c]),_=f.useCallback(()=>{a(),setTimeout(()=>{o("idle"),y(null),p(null)},300)},[a]);s&&n==="idle"&&h();const i=m==null?void 0:m.analysis,d=m==null?void 0:m.recommended,x=m==null?void 0:m.current;return e.jsxs(ae,{open:s,onClose:_,size:"lg",children:[e.jsx(se,{icon:e.jsx(re,{size:20}),title:"Auto-Configure",onClose:_}),e.jsxs(te,{className:"flex flex-col gap-5 max-h-[70vh] overflow-y-auto",children:[n==="analyzing"&&e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-12",children:[e.jsx(J,{className:"w-6 h-6 text-sys-blue animate-spin"}),e.jsx("p",{className:"type-body-sm text-fg-muted",children:"Analyzing 7 days of mesh traffic…"})]}),n==="error"&&e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-8",children:[e.jsx(ne,{className:"w-6 h-6 text-sys-amber"}),e.jsx("p",{className:"type-body-sm text-fg-secondary",children:l}),e.jsx(w,{plain:!0,onClick:h,className:"text-sys-blue",children:"Retry"})]}),(n==="ready"||n==="applying"||n==="applied")&&i&&d&&x&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("div",{className:"type-micro mb-3",children:"7-DAY ANALYSIS"}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Pkts/hr"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:A(i.packetsPerHour)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Adverts/hr"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:A(i.advertsPerHour)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Sources"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:i.trackedSources})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Density"}),e.jsx("div",{className:g("data-box data-box-fill data-box-left",fe[i.meshDensity]),children:he[i.meshDensity]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(D,{title:"Token Bucket of Shame",enabled:d.tokenBucket.enabled,defaultOpen:!0,children:[e.jsx(u,{label:"Bucket Capacity",current:(C=x.tokenBucket)==null?void 0:C.bucket_capacity,recommended:d.tokenBucket.bucket_capacity,format:t=>`${t} tokens`}),e.jsx(u,{label:"Refill Tokens",current:(H=x.tokenBucket)==null?void 0:H.refill_tokens,recommended:d.tokenBucket.refill_tokens,format:t=>`${t} tokens`}),e.jsx(u,{label:"Refill Interval",current:(P=x.tokenBucket)==null?void 0:P.refill_interval_seconds,recommended:d.tokenBucket.refill_interval_seconds,format:t=>k(t)}),e.jsx(u,{label:"Min Interval",current:(T=x.tokenBucket)==null?void 0:T.min_interval_seconds,recommended:d.tokenBucket.min_interval_seconds,format:t=>`${t}s`})]}),e.jsxs(D,{title:"Jail",enabled:d.penaltyBox.enabled,children:[e.jsx(u,{label:"Violation Threshold",current:(I=x.penaltyBox)==null?void 0:I.violation_threshold,recommended:d.penaltyBox.violation_threshold,format:t=>`${t} violations`}),e.jsx(u,{label:"Base Penalty",current:(R=x.penaltyBox)==null?void 0:R.base_penalty_seconds,recommended:d.penaltyBox.base_penalty_seconds,format:t=>k(t)}),e.jsx(u,{label:"Multiplier",current:(E=x.penaltyBox)==null?void 0:E.penalty_multiplier,recommended:d.penaltyBox.penalty_multiplier,format:t=>`${t}×`}),e.jsx(u,{label:"Max Penalty",current:(L=x.penaltyBox)==null?void 0:L.max_penalty_seconds,recommended:d.penaltyBox.max_penalty_seconds,format:t=>k(t)}),e.jsx(u,{label:"Violation Decay",current:($=x.penaltyBox)==null?void 0:$.violation_decay_seconds,recommended:d.penaltyBox.violation_decay_seconds,format:t=>k(t)})]}),e.jsxs(D,{title:"Adaptive Tiers",enabled:d.adaptive.enabled,children:[e.jsx(u,{label:"EWMA α",current:(z=x.adaptive)==null?void 0:z.ewma_alpha,recommended:d.adaptive.ewma_alpha}),e.jsx(u,{label:"Hysteresis",current:(F=x.adaptive)==null?void 0:F.hysteresis_seconds,recommended:d.adaptive.hysteresis_seconds,format:t=>k(t)}),e.jsx(u,{label:"Quiet Max",current:(O=x.adaptive)==null?void 0:O.thresholds.quiet_max,recommended:d.adaptive.thresholds.quiet_max,format:t=>`${t} pkts/min`}),e.jsx(u,{label:"Normal Max",current:(q=x.adaptive)==null?void 0:q.thresholds.normal_max,recommended:d.adaptive.thresholds.normal_max,format:t=>`${t} pkts/min`}),e.jsx(u,{label:"Busy Max",current:(Y=x.adaptive)==null?void 0:Y.thresholds.busy_max,recommended:d.adaptive.thresholds.busy_max,format:t=>`${t} pkts/min`})]})]}),e.jsxs("div",{className:g("flex justify-between gap-4 pt-1",n==="applied"?"items-center":"items-end"),children:[n==="applied"?e.jsx("span",{className:"type-body-sm text-zinc-500",children:"Settings applied"}):e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Analyzed"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[A(i.totalPackets)," packets"]})]}),e.jsx("div",{className:"flex items-center gap-2",children:n==="applied"?e.jsx(w,{color:"primary",onClick:_,children:"Done"}):e.jsxs(e.Fragment,{children:[e.jsx(w,{plain:!0,onClick:_,children:"Cancel"}),e.jsx(w,{color:"primary",onClick:N,disabled:n==="applying",children:n==="applying"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Applying…"]}):"Apply All"})]})})]})]})]})]})}export{we as A,ke as N,ge as S,Ne as a}; diff --git a/frontend/dist/assets/BasemapLayer-CSNA1nZg.js b/frontend/dist/assets/BasemapLayer-hjkVmX-W.js similarity index 95% rename from frontend/dist/assets/BasemapLayer-CSNA1nZg.js rename to frontend/dist/assets/BasemapLayer-hjkVmX-W.js index 86a0e1cb..78a92a2e 100644 --- a/frontend/dist/assets/BasemapLayer-CSNA1nZg.js +++ b/frontend/dist/assets/BasemapLayer-hjkVmX-W.js @@ -1 +1 @@ -import{r as o}from"./index-BXuscHlA.js";import{u as w}from"./maplibre-gl-CfjETxh6.js";const C={light:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",dark:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"},x={light:"basemap-light-",dark:"basemap-dark-"},k={};async function E(i){if(k[i])return k[i];const t=await(await fetch(C[i])).json();return k[i]=t,t}function R({mode:i}){const{current:l}=w(),[t,b]=o.useState(null),u=o.useRef({light:!1,dark:!1}),m=o.useRef({light:[],dark:[]});o.useEffect(()=>{const e=()=>{var a;const s=(a=l==null?void 0:l.getMap)==null?void 0:a.call(l);s&&!t&&b(s)};e();const r=setInterval(e,50),c=setTimeout(()=>clearInterval(r),5e3);return()=>{clearInterval(r),clearTimeout(c)}},[l,t]);const g=o.useCallback(async(e,r,c)=>{var L,I;if(u.current[r])return;const s=x[r],a=await E(r),d=[];for(const[y,f]of Object.entries(a.sources||{})){const n=s+y;e.getSource(n)||e.addSource(n,f)}const v=(I=(((L=e.getStyle())==null?void 0:L.layers)||[]).find(y=>!y.id.startsWith("basemap-light-")&&!y.id.startsWith("basemap-dark-")))==null?void 0:I.id;for(const y of a.layers||[]){const f=s+y.id;if(d.push(f),e.getLayer(f))continue;const n={...y,id:f};"source"in n&&typeof n.source=="string"&&(n.source=s+n.source),n.layout||(n.layout={}),n.layout.visibility=c?"visible":"none";try{e.addLayer(n,v)}catch(S){console.warn(`[BasemapLayer] Failed to add layer ${f}:`,S)}}m.current[r]=d,u.current[r]=!0},[]),h=o.useCallback((e,r,c)=>{const s=m.current[r],a=c?"visible":"none";for(const d of s)if(e.getLayer(d))try{e.setLayoutProperty(d,"visibility",a)}catch{}},[]),p=o.useCallback(e=>{var s;const c=(((s=e.getStyle())==null?void 0:s.layers)||[]).filter(a=>!a.id.startsWith("basemap-light-")&&!a.id.startsWith("basemap-dark-"));for(const a of c)try{e.moveLayer(a.id)}catch{}},[]);return o.useEffect(()=>{if(!t)return;const e=r=>{t.hasImage(r.id)||t.addImage(r.id,{width:1,height:1,data:new Uint8Array([0,0,0,0])})};return t.on("styleimagemissing",e),()=>{t.off("styleimagemissing",e)}},[t]),o.useEffect(()=>{if(!t)return;let e=!1;const r=async()=>{if(!e)try{await Promise.all([g(t,"light",i==="light"),g(t,"dark",i==="dark")]),e||p(t)}catch(s){console.error("[BasemapLayer] Setup error:",s)}};t.isStyleLoaded()?r():(t.once("style.load",r),t.once("load",()=>{!e&&!u.current.light&&r()}));const c=()=>{e||setTimeout(()=>{!e&&u.current.light&&u.current.dark&&p(t)},100)};return t.on("styledata",c),()=>{e=!0,t.off("styledata",c)}},[t,g,p,i]),o.useEffect(()=>{t&&(!u.current.light||!u.current.dark||(h(t,"light",i==="light"),h(t,"dark",i==="dark")))},[t,i,h]),null}export{R as B}; +import{r as o}from"./index-BBBuaCQs.js";import{u as w}from"./maplibre-gl-BGrZ3ia8.js";const C={light:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",dark:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"},x={light:"basemap-light-",dark:"basemap-dark-"},k={};async function E(i){if(k[i])return k[i];const t=await(await fetch(C[i])).json();return k[i]=t,t}function R({mode:i}){const{current:l}=w(),[t,b]=o.useState(null),u=o.useRef({light:!1,dark:!1}),m=o.useRef({light:[],dark:[]});o.useEffect(()=>{const e=()=>{var a;const s=(a=l==null?void 0:l.getMap)==null?void 0:a.call(l);s&&!t&&b(s)};e();const r=setInterval(e,50),c=setTimeout(()=>clearInterval(r),5e3);return()=>{clearInterval(r),clearTimeout(c)}},[l,t]);const g=o.useCallback(async(e,r,c)=>{var L,I;if(u.current[r])return;const s=x[r],a=await E(r),d=[];for(const[y,f]of Object.entries(a.sources||{})){const n=s+y;e.getSource(n)||e.addSource(n,f)}const v=(I=(((L=e.getStyle())==null?void 0:L.layers)||[]).find(y=>!y.id.startsWith("basemap-light-")&&!y.id.startsWith("basemap-dark-")))==null?void 0:I.id;for(const y of a.layers||[]){const f=s+y.id;if(d.push(f),e.getLayer(f))continue;const n={...y,id:f};"source"in n&&typeof n.source=="string"&&(n.source=s+n.source),n.layout||(n.layout={}),n.layout.visibility=c?"visible":"none";try{e.addLayer(n,v)}catch(S){console.warn(`[BasemapLayer] Failed to add layer ${f}:`,S)}}m.current[r]=d,u.current[r]=!0},[]),h=o.useCallback((e,r,c)=>{const s=m.current[r],a=c?"visible":"none";for(const d of s)if(e.getLayer(d))try{e.setLayoutProperty(d,"visibility",a)}catch{}},[]),p=o.useCallback(e=>{var s;const c=(((s=e.getStyle())==null?void 0:s.layers)||[]).filter(a=>!a.id.startsWith("basemap-light-")&&!a.id.startsWith("basemap-dark-"));for(const a of c)try{e.moveLayer(a.id)}catch{}},[]);return o.useEffect(()=>{if(!t)return;const e=r=>{t.hasImage(r.id)||t.addImage(r.id,{width:1,height:1,data:new Uint8Array([0,0,0,0])})};return t.on("styleimagemissing",e),()=>{t.off("styleimagemissing",e)}},[t]),o.useEffect(()=>{if(!t)return;let e=!1;const r=async()=>{if(!e)try{await Promise.all([g(t,"light",i==="light"),g(t,"dark",i==="dark")]),e||p(t)}catch(s){console.error("[BasemapLayer] Setup error:",s)}};t.isStyleLoaded()?r():(t.once("style.load",r),t.once("load",()=>{!e&&!u.current.light&&r()}));const c=()=>{e||setTimeout(()=>{!e&&u.current.light&&u.current.dark&&p(t)},100)};return t.on("styledata",c),()=>{e=!0,t.off("styledata",c)}},[t,g,p,i]),o.useEffect(()=>{t&&(!u.current.light||!u.current.dark||(h(t,"light",i==="light"),h(t,"dark",i==="dark")))},[t,i,h]),null}export{R as B}; diff --git a/frontend/dist/assets/ChatBubble-BOvXH6C3.js b/frontend/dist/assets/ChatBubble-B1RvK-PR.js similarity index 96% rename from frontend/dist/assets/ChatBubble-BOvXH6C3.js rename to frontend/dist/assets/ChatBubble-B1RvK-PR.js index 5fb72df6..59ab4cd9 100644 --- a/frontend/dist/assets/ChatBubble-BOvXH6C3.js +++ b/frontend/dist/assets/ChatBubble-B1RvK-PR.js @@ -1 +1 @@ -import{r as B,j as e,c as s}from"./index-BXuscHlA.js";import{e as M,g as W,a as E,b as S,f as g,c as b}from"./chat-utils-LE1iz0ua.js";const v=["","text-[42px]","text-[36px]","text-[30px]"],O=B.memo(function({senderName:x,text:n,timestamp:d,nameAccessory:y,bubbleAccessory:c,className:o,isOutgoing:N,status:t,onRetry:m,onRetryAsFlood:h,retryAttempt:p,maxRetries:l,signed:w,echoCount:r,bubbleVariant:V="accent",onMentionClick:f}){const{emoji:u,cleanName:j}=M(x),k=W(j),C=E(x),a=S(n);return N?e.jsxs("div",{className:s("group flex flex-col items-end w-full p-2",o),children:[e.jsxs("div",{className:"flex items-end gap-1.5 max-w-[80%]",children:[c,a>0?e.jsx("p",{className:s("leading-none",v[a]),children:n.trim()}):e.jsx("div",{className:s("inline-block px-3.5 py-2.5","rounded-2xl rounded-br-md",t==="failed"?"bg-sys-red depth-raised-soft":"bg-sys-blue depth-raised-soft"),children:e.jsx("p",{className:"text-sm text-white leading-relaxed tracking-wide whitespace-pre-wrap break-words",children:g(n,{isOutgoing:!0,onMentionClick:f})})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5 mt-0.5 mr-1",children:[r!=null&&r>0&&e.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-sys-green tabular-nums font-medium",children:[e.jsxs("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("path",{d:"M17 1l4 4-4 4"}),e.jsx("path",{d:"M3 11V9a4 4 0 0 1 4-4h14"}),e.jsx("path",{d:"M7 23l-4-4 4-4"}),e.jsx("path",{d:"M21 13v2a4 4 0 0 1-4 4H3"})]}),r]}),t==="confirmed"&&e.jsxs("svg",{className:"w-3 h-3 text-sys-green",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("polyline",{points:"3 12 8 17 14 6"}),e.jsx("polyline",{points:"10 12 15 17 21 6"})]}),t==="sent"&&e.jsx("svg",{className:"w-3 h-3 text-fg-muted",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),t==="pending"&&e.jsx("svg",{className:"w-3 h-3 text-chat-timestamp animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),t==="retrying"&&e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-3 h-3 text-sys-amber animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),p!=null&&l!=null&&e.jsxs("span",{className:"text-[10px] text-sys-amber font-medium tabular-nums",children:["Retry ",p,"/",l]})]}),t==="unconfirmed"&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-sys-amber flex-shrink-0"}),t==="failed"&&e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"w-3 h-3 text-sys-red",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),l!=null&&l>0&&e.jsxs("span",{className:"text-[10px] text-sys-red/70",children:["after ",l," ",l===1?"retry":"retries"]}),m&&e.jsx("button",{onClick:m,className:"text-[10px] font-medium text-sys-red hover:text-sys-red/80 underline underline-offset-2 transition-colors",children:"Retry"}),h&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] text-fg-muted/50",children:"·"}),e.jsx("button",{onClick:h,className:"text-[10px] font-medium text-sys-amber hover:text-sys-amber/80 underline underline-offset-2 transition-colors",children:"Flood"})]})]}),e.jsx("span",{className:"text-[10px] text-chat-timestamp tabular-nums",children:b(d)})]})]}):e.jsxs("div",{className:s("group flex items-start gap-4 w-full p-2",o),children:[e.jsxs("div",{className:"flex-shrink-0 w-9 flex flex-col items-center gap-1",children:[e.jsx("div",{className:s("clay-avatar w-9 h-9",u?"text-lg":"text-white text-[13px] font-bold tracking-tight"),style:{"--avatar-color":k},children:u||C}),e.jsx("span",{className:"text-xs text-chat-timestamp tabular-nums h-4 leading-4",children:b(d)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 -mt-[3px] mb-1",children:[e.jsx("span",{className:"text-[13px] font-normal text-chat-incoming-name truncate leading-tight tabular-nums",children:j}),w&&e.jsxs("svg",{className:"w-3.5 h-3.5 text-sys-green flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("title",{children:"Ed25519 signed message"}),e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"}),e.jsx("polyline",{points:"9 12 11 14 15 10"})]}),y]}),e.jsxs("div",{className:"flex items-end gap-1.5",children:[a>0?e.jsx("p",{className:s("leading-none",v[a]),children:n.trim()}):e.jsx("div",{className:s("inline-block px-3.5 py-2.5 max-w-full","rounded-2xl rounded-tl-md","bg-chat-incoming depth-raised-soft"),children:e.jsx("p",{className:"text-sm text-fg-primary leading-relaxed tracking-wide whitespace-pre-wrap break-words",children:g(n,{onMentionClick:f})})}),c]})]})]})});function T({text:i}){return e.jsx("div",{className:"flex justify-center my-1",children:e.jsx("span",{className:s("px-3 py-1 rounded-full","bg-subtle-fill text-[11px] text-fg-muted/80 font-medium","ring-1 ring-edge-subtle"),children:i})})}export{O as C,T as S}; +import{r as B,j as e,c as s}from"./index-BBBuaCQs.js";import{e as M,g as W,a as E,b as S,f as g,c as b}from"./chat-utils-DP6LcfMx.js";const v=["","text-[42px]","text-[36px]","text-[30px]"],O=B.memo(function({senderName:x,text:n,timestamp:d,nameAccessory:y,bubbleAccessory:c,className:o,isOutgoing:N,status:t,onRetry:m,onRetryAsFlood:h,retryAttempt:p,maxRetries:l,signed:w,echoCount:r,bubbleVariant:V="accent",onMentionClick:f}){const{emoji:u,cleanName:j}=M(x),k=W(j),C=E(x),a=S(n);return N?e.jsxs("div",{className:s("group flex flex-col items-end w-full p-2",o),children:[e.jsxs("div",{className:"flex items-end gap-1.5 max-w-[80%]",children:[c,a>0?e.jsx("p",{className:s("leading-none",v[a]),children:n.trim()}):e.jsx("div",{className:s("inline-block px-3.5 py-2.5","rounded-2xl rounded-br-md",t==="failed"?"bg-sys-red depth-raised-soft":"bg-sys-blue depth-raised-soft"),children:e.jsx("p",{className:"text-sm text-white leading-relaxed tracking-wide whitespace-pre-wrap break-words",children:g(n,{isOutgoing:!0,onMentionClick:f})})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5 mt-0.5 mr-1",children:[r!=null&&r>0&&e.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-sys-green tabular-nums font-medium",children:[e.jsxs("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("path",{d:"M17 1l4 4-4 4"}),e.jsx("path",{d:"M3 11V9a4 4 0 0 1 4-4h14"}),e.jsx("path",{d:"M7 23l-4-4 4-4"}),e.jsx("path",{d:"M21 13v2a4 4 0 0 1-4 4H3"})]}),r]}),t==="confirmed"&&e.jsxs("svg",{className:"w-3 h-3 text-sys-green",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("polyline",{points:"3 12 8 17 14 6"}),e.jsx("polyline",{points:"10 12 15 17 21 6"})]}),t==="sent"&&e.jsx("svg",{className:"w-3 h-3 text-fg-muted",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),t==="pending"&&e.jsx("svg",{className:"w-3 h-3 text-chat-timestamp animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),t==="retrying"&&e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-3 h-3 text-sys-amber animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),p!=null&&l!=null&&e.jsxs("span",{className:"text-[10px] text-sys-amber font-medium tabular-nums",children:["Retry ",p,"/",l]})]}),t==="unconfirmed"&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-sys-amber flex-shrink-0"}),t==="failed"&&e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"w-3 h-3 text-sys-red",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),l!=null&&l>0&&e.jsxs("span",{className:"text-[10px] text-sys-red/70",children:["after ",l," ",l===1?"retry":"retries"]}),m&&e.jsx("button",{onClick:m,className:"text-[10px] font-medium text-sys-red hover:text-sys-red/80 underline underline-offset-2 transition-colors",children:"Retry"}),h&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] text-fg-muted/50",children:"·"}),e.jsx("button",{onClick:h,className:"text-[10px] font-medium text-sys-amber hover:text-sys-amber/80 underline underline-offset-2 transition-colors",children:"Flood"})]})]}),e.jsx("span",{className:"text-[10px] text-chat-timestamp tabular-nums",children:b(d)})]})]}):e.jsxs("div",{className:s("group flex items-start gap-4 w-full p-2",o),children:[e.jsxs("div",{className:"flex-shrink-0 w-9 flex flex-col items-center gap-1",children:[e.jsx("div",{className:s("clay-avatar w-9 h-9",u?"text-lg":"text-white text-[13px] font-bold tracking-tight"),style:{"--avatar-color":k},children:u||C}),e.jsx("span",{className:"text-xs text-chat-timestamp tabular-nums h-4 leading-4",children:b(d)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 -mt-[3px] mb-1",children:[e.jsx("span",{className:"text-[13px] font-normal text-chat-incoming-name truncate leading-tight tabular-nums",children:j}),w&&e.jsxs("svg",{className:"w-3.5 h-3.5 text-sys-green flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("title",{children:"Ed25519 signed message"}),e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"}),e.jsx("polyline",{points:"9 12 11 14 15 10"})]}),y]}),e.jsxs("div",{className:"flex items-end gap-1.5",children:[a>0?e.jsx("p",{className:s("leading-none",v[a]),children:n.trim()}):e.jsx("div",{className:s("inline-block px-3.5 py-2.5 max-w-full","rounded-2xl rounded-tl-md","bg-chat-incoming depth-raised-soft"),children:e.jsx("p",{className:"text-sm text-fg-primary leading-relaxed tracking-wide whitespace-pre-wrap break-words",children:g(n,{onMentionClick:f})})}),c]})]})]})});function T({text:i}){return e.jsx("div",{className:"flex justify-center my-1",children:e.jsx("span",{className:s("px-3 py-1 rounded-full","bg-subtle-fill text-[11px] text-fg-muted/80 font-medium","ring-1 ring-edge-subtle"),children:i})})}export{O as C,T as S}; diff --git a/frontend/dist/assets/CollisionExplorerModal-B3e6xvEX.js b/frontend/dist/assets/CollisionExplorerModal-qV7zoTO2.js similarity index 96% rename from frontend/dist/assets/CollisionExplorerModal-B3e6xvEX.js rename to frontend/dist/assets/CollisionExplorerModal-qV7zoTO2.js index 9b892fb7..55687d98 100644 --- a/frontend/dist/assets/CollisionExplorerModal-B3e6xvEX.js +++ b/frontend/dist/assets/CollisionExplorerModal-qV7zoTO2.js @@ -1 +1 @@ -import{r as c,a6 as L,ch as S,ab as H,j as e,aC as k,bY as R,aD as B,c$ as E,b$ as T,c as N,ao as D,V as M,a3 as P,a0 as _,a1 as z,cs as I,cE as W}from"./index-BXuscHlA.js";import{M as $,S as F,L as Y,a as q}from"./maplibre-gl-CfjETxh6.js";import{B as A}from"./BasemapLayer-CSNA1nZg.js";import{M as U}from"./map-pin-BI3SkGEK.js";import{S as V}from"./share-2-B7Nq-Teh.js";const G={version:8,sources:{},layers:[],glyphs:"https://tiles.basemaps.cartocdn.com/fonts/{fontstack}/{range}.pbf"};function w({node:o,isHovered:v,onHover:f}){const[g,p]=c.useState(!1),y=c.useCallback(async d=>{d.stopPropagation(),await P(o.hash),p(!0),setTimeout(()=>p(!1),2e3)},[o.hash]),h=o.contactType.toLowerCase(),m=h.includes("room")||h.includes("server"),l=h==="companion"||h==="client";let n=V,r="text-sys-blue";return m?(n=I,r="text-signal-fair"):l?(n=W,r="text-fg-muted"):o.isNeighbor&&(r="text-sys-green"),e.jsxs("div",{className:N("flex items-center gap-3 px-3 py-2.5 radius-inner transition-base cursor-pointer",v?"bg-sys-blue/10":"hover:bg-subtle-fill"),onMouseEnter:()=>f(o.hash),onMouseLeave:()=>f(null),children:[e.jsx(n,{className:N("w-4 h-4 flex-shrink-0",r)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"type-label text-fg-primary truncate",children:o.name}),o.isNeighbor&&e.jsx(M,{color:"green",compact:!0,children:"NBR"}),o.isRepeater&&e.jsx(M,{color:"zinc",compact:!0,children:"RPT"}),o.isHub&&e.jsx(M,{color:"indigo",compact:!0,children:"HUB"})]}),e.jsxs("button",{onClick:y,className:N("mt-1 inline-flex items-center gap-1 type-data-xs px-1.5 py-0.5 rounded","border transition-all cursor-pointer",g?"border-sys-green/50 bg-sys-green/10 text-sys-green":"border-edge-subtle bg-subtle/50 text-fg-muted hover:border-edge-strong"),title:`Copy: ${o.hash}`,children:[o.hash.slice(0,12),"…",g?e.jsx(_,{className:"w-2.5 h-2.5"}):e.jsx(z,{className:"w-2.5 h-2.5 opacity-50"})]})]})]})}function C({nodes:o,hoveredHash:v,onHover:f}){const g=E(),p=c.useRef(null),y=T(),[h,m]=c.useState(!1),l=c.useMemo(()=>o.filter(a=>a.latitude!=null&&a.longitude!=null&&(a.latitude!==0||a.longitude!==0)),[o]),n=c.useMemo(()=>{if(l.length===0)return null;let a=1/0,s=-1/0,t=1/0,i=-1/0;for(const x of l)a=Math.min(a,x.longitude),s=Math.max(s,x.longitude),t=Math.min(t,x.latitude),i=Math.max(i,x.latitude);const u=.01;if(i-tn?{longitude:(n[0][0]+n[1][0])/2,latitude:(n[0][1]+n[1][1])/2}:{longitude:0,latitude:0},[n]),d=c.useMemo(()=>{if(l.length<2)return null;const a=[];for(let s=0;s{var s;const a=(s=p.current)==null?void 0:s.getMap();if(!a||!n){m(!0);return}a.fitBounds(n,{padding:{top:50,bottom:50,left:50,right:50},maxZoom:13,duration:0}),setTimeout(()=>m(!0),50)},[n]),b=y&&h;return l.length===0?e.jsx("div",{className:"h-full flex items-center justify-center bg-subtle/30 radius-inner",children:e.jsxs("div",{className:"text-center text-fg-secondary p-4",children:[e.jsx(U,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No location data available"})]})}):e.jsxs("div",{className:"h-full w-full relative radius-inner overflow-hidden bg-elevated",children:[e.jsx("div",{className:N("absolute inset-0 flex items-center justify-center z-10","transition-opacity duration-200 pointer-events-none",b?"opacity-0":"opacity-100 bg-elevated"),children:e.jsx("div",{className:"w-5 h-5 border-2 border-text-muted/30 border-t-text-muted rounded-full animate-spin"})}),e.jsx("div",{className:N("h-full w-full transition-opacity duration-200",b?"opacity-100":"opacity-0"),children:e.jsxs($,{ref:p,initialViewState:{longitude:r.longitude,latitude:r.latitude,zoom:10},style:{height:"100%",width:"100%"},mapStyle:G,attributionControl:!1,onLoad:j,children:[e.jsx(A,{mode:g}),d&&e.jsx(F,{id:"collision-edges",type:"geojson",data:d,children:e.jsx(Y,{id:"collision-edges-line",type:"line",paint:{"line-color":"#3B3F4A","line-width":2,"line-opacity":.8},layout:{"line-cap":"round","line-join":"round"}})}),l.map(a=>{const s=a.hash===v,t=D(a.hash);return e.jsx(q,{longitude:a.longitude,latitude:a.latitude,anchor:"center",children:e.jsx("div",{className:"cursor-pointer transition-all duration-150",onMouseEnter:()=>f(a.hash),onMouseLeave:()=>f(null),style:{pointerEvents:"auto"},children:e.jsxs(M,{color:"amber",filled:!0,className:"type-data-xs shadow-lg",children:[t,s&&e.jsx("span",{className:"ml-1 opacity-75 font-sans",children:a.name})]})})},a.hash)})]})})]})}function J({isOpen:o,prefix:v,candidateHashes:f,onClose:g}){const p=L(),y=S(),h=H(),[m,l]=c.useState(null),n=c.useMemo(()=>new Set(h.map(s=>s.hash)),[h]),r=(p==null?void 0:p.neighbors)??{},d=c.useMemo(()=>{const s=t=>{if(r[t])return r[t];if(!t.startsWith("0x")&&r["0x"+t])return r["0x"+t];if(t.startsWith("0x")&&r[t.slice(2)])return r[t.slice(2)]};return f.map(t=>{var u;const i=s(t);return{hash:t,name:(i==null?void 0:i.node_name)||(i==null?void 0:i.name)||`Unknown (${t.slice(0,8)}…)`,contactType:(i==null?void 0:i.contact_type)||"",isRepeater:(i==null?void 0:i.is_repeater)||((u=i==null?void 0:i.contact_type)==null?void 0:u.toLowerCase())==="repeater"||!1,isNeighbor:n.has(t)||n.has("0x"+t)||n.has(t.replace(/^0x/,"")),isHub:y.has(t),latitude:i==null?void 0:i.latitude,longitude:i==null?void 0:i.longitude}}).sort((t,i)=>t.isNeighbor!==i.isNeighbor?t.isNeighbor?-1:1:t.isHub!==i.isHub?t.isHub?-1:1:t.name.localeCompare(i.name))},[f,r,n,y]),j=c.useMemo(()=>d.some(s=>s.latitude!=null&&s.longitude!=null&&(s.latitude!==0||s.longitude!==0)),[d]),b=c.useCallback(s=>{l(s)},[]),a=j?"4xl":"lg";return o?e.jsxs(k,{open:o,onClose:g,size:a,motionPlus:!0,className:j?"sm:h-[500px] sm:max-h-[600px]":"",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-edge-subtle",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 radius-inner bg-signal-fair/10",children:e.jsx(R,{className:"w-5 h-5 text-signal-fair"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"type-micro",children:["Prefix Collision: ",e.jsx("span",{className:"font-mono text-sys-blue",children:v})]}),e.jsxs("p",{className:"text-xs text-fg-secondary",children:[d.length," nodes share this prefix"]})]})]}),e.jsx("button",{onClick:g,className:"sm:hidden min-h-[44px] min-w-[44px] px-3 flex items-center justify-center text-[15px] font-medium text-sys-blue active:text-sys-blue/70 transition-base radius-inner active:bg-subtle-fill",children:"Done"}),e.jsx("button",{onClick:g,className:"hidden sm:flex items-center justify-center p-2 text-fg-muted hover:text-fg-primary transition-base radius-inner hover:bg-subtle","aria-label":"Close",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs(B,{className:"p-0 overflow-hidden flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"sm:hidden flex-1 overflow-y-auto",children:[j&&e.jsx("div",{className:"h-64 p-2 border-b border-edge-subtle",children:e.jsx(C,{nodes:d,hoveredHash:m,onHover:b})}),e.jsx("div",{className:"p-2",children:d.map(s=>e.jsx(w,{node:s,isHovered:m===s.hash,onHover:b},s.hash))})]}),j?e.jsxs("div",{className:"hidden sm:grid sm:grid-cols-[280px_minmax(400px,1fr)] flex-1 overflow-hidden sm:min-w-[700px]",children:[e.jsx("div",{className:"overflow-y-auto border-r border-edge-subtle",children:e.jsx("div",{className:"p-2",children:d.map(s=>e.jsx(w,{node:s,isHovered:m===s.hash,onHover:b},s.hash))})}),e.jsx("div",{className:"overflow-hidden p-2",children:e.jsx(C,{nodes:d,hoveredHash:m,onHover:b})})]}):e.jsx("div",{className:"hidden sm:block flex-1 overflow-y-auto",children:e.jsx("div",{className:"p-2",children:d.map(s=>e.jsx(w,{node:s,isHovered:m===s.hash,onHover:b},s.hash))})})]})]}):null}const ee=c.memo(J);export{ee as C}; +import{r as c,a6 as L,ch as S,ab as H,j as e,aC as k,bY as R,aD as B,c$ as E,b$ as T,c as N,ao as D,V as M,a3 as P,a0 as _,a1 as z,cs as I,cE as W}from"./index-BBBuaCQs.js";import{M as $,S as F,L as Y,a as q}from"./maplibre-gl-BGrZ3ia8.js";import{B as A}from"./BasemapLayer-hjkVmX-W.js";import{M as U}from"./map-pin-stXuybQm.js";import{S as V}from"./share-2-WwVAp6Bf.js";const G={version:8,sources:{},layers:[],glyphs:"https://tiles.basemaps.cartocdn.com/fonts/{fontstack}/{range}.pbf"};function w({node:o,isHovered:v,onHover:f}){const[g,p]=c.useState(!1),y=c.useCallback(async d=>{d.stopPropagation(),await P(o.hash),p(!0),setTimeout(()=>p(!1),2e3)},[o.hash]),h=o.contactType.toLowerCase(),m=h.includes("room")||h.includes("server"),l=h==="companion"||h==="client";let n=V,r="text-sys-blue";return m?(n=I,r="text-signal-fair"):l?(n=W,r="text-fg-muted"):o.isNeighbor&&(r="text-sys-green"),e.jsxs("div",{className:N("flex items-center gap-3 px-3 py-2.5 radius-inner transition-base cursor-pointer",v?"bg-sys-blue/10":"hover:bg-subtle-fill"),onMouseEnter:()=>f(o.hash),onMouseLeave:()=>f(null),children:[e.jsx(n,{className:N("w-4 h-4 flex-shrink-0",r)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"type-label text-fg-primary truncate",children:o.name}),o.isNeighbor&&e.jsx(M,{color:"green",compact:!0,children:"NBR"}),o.isRepeater&&e.jsx(M,{color:"zinc",compact:!0,children:"RPT"}),o.isHub&&e.jsx(M,{color:"indigo",compact:!0,children:"HUB"})]}),e.jsxs("button",{onClick:y,className:N("mt-1 inline-flex items-center gap-1 type-data-xs px-1.5 py-0.5 rounded","border transition-all cursor-pointer",g?"border-sys-green/50 bg-sys-green/10 text-sys-green":"border-edge-subtle bg-subtle/50 text-fg-muted hover:border-edge-strong"),title:`Copy: ${o.hash}`,children:[o.hash.slice(0,12),"…",g?e.jsx(_,{className:"w-2.5 h-2.5"}):e.jsx(z,{className:"w-2.5 h-2.5 opacity-50"})]})]})]})}function C({nodes:o,hoveredHash:v,onHover:f}){const g=E(),p=c.useRef(null),y=T(),[h,m]=c.useState(!1),l=c.useMemo(()=>o.filter(a=>a.latitude!=null&&a.longitude!=null&&(a.latitude!==0||a.longitude!==0)),[o]),n=c.useMemo(()=>{if(l.length===0)return null;let a=1/0,s=-1/0,t=1/0,i=-1/0;for(const x of l)a=Math.min(a,x.longitude),s=Math.max(s,x.longitude),t=Math.min(t,x.latitude),i=Math.max(i,x.latitude);const u=.01;if(i-tn?{longitude:(n[0][0]+n[1][0])/2,latitude:(n[0][1]+n[1][1])/2}:{longitude:0,latitude:0},[n]),d=c.useMemo(()=>{if(l.length<2)return null;const a=[];for(let s=0;s{var s;const a=(s=p.current)==null?void 0:s.getMap();if(!a||!n){m(!0);return}a.fitBounds(n,{padding:{top:50,bottom:50,left:50,right:50},maxZoom:13,duration:0}),setTimeout(()=>m(!0),50)},[n]),b=y&&h;return l.length===0?e.jsx("div",{className:"h-full flex items-center justify-center bg-subtle/30 radius-inner",children:e.jsxs("div",{className:"text-center text-fg-secondary p-4",children:[e.jsx(U,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No location data available"})]})}):e.jsxs("div",{className:"h-full w-full relative radius-inner overflow-hidden bg-elevated",children:[e.jsx("div",{className:N("absolute inset-0 flex items-center justify-center z-10","transition-opacity duration-200 pointer-events-none",b?"opacity-0":"opacity-100 bg-elevated"),children:e.jsx("div",{className:"w-5 h-5 border-2 border-text-muted/30 border-t-text-muted rounded-full animate-spin"})}),e.jsx("div",{className:N("h-full w-full transition-opacity duration-200",b?"opacity-100":"opacity-0"),children:e.jsxs($,{ref:p,initialViewState:{longitude:r.longitude,latitude:r.latitude,zoom:10},style:{height:"100%",width:"100%"},mapStyle:G,attributionControl:!1,onLoad:j,children:[e.jsx(A,{mode:g}),d&&e.jsx(F,{id:"collision-edges",type:"geojson",data:d,children:e.jsx(Y,{id:"collision-edges-line",type:"line",paint:{"line-color":"#3B3F4A","line-width":2,"line-opacity":.8},layout:{"line-cap":"round","line-join":"round"}})}),l.map(a=>{const s=a.hash===v,t=D(a.hash);return e.jsx(q,{longitude:a.longitude,latitude:a.latitude,anchor:"center",children:e.jsx("div",{className:"cursor-pointer transition-all duration-150",onMouseEnter:()=>f(a.hash),onMouseLeave:()=>f(null),style:{pointerEvents:"auto"},children:e.jsxs(M,{color:"amber",filled:!0,className:"type-data-xs shadow-lg",children:[t,s&&e.jsx("span",{className:"ml-1 opacity-75 font-sans",children:a.name})]})})},a.hash)})]})})]})}function J({isOpen:o,prefix:v,candidateHashes:f,onClose:g}){const p=L(),y=S(),h=H(),[m,l]=c.useState(null),n=c.useMemo(()=>new Set(h.map(s=>s.hash)),[h]),r=(p==null?void 0:p.neighbors)??{},d=c.useMemo(()=>{const s=t=>{if(r[t])return r[t];if(!t.startsWith("0x")&&r["0x"+t])return r["0x"+t];if(t.startsWith("0x")&&r[t.slice(2)])return r[t.slice(2)]};return f.map(t=>{var u;const i=s(t);return{hash:t,name:(i==null?void 0:i.node_name)||(i==null?void 0:i.name)||`Unknown (${t.slice(0,8)}…)`,contactType:(i==null?void 0:i.contact_type)||"",isRepeater:(i==null?void 0:i.is_repeater)||((u=i==null?void 0:i.contact_type)==null?void 0:u.toLowerCase())==="repeater"||!1,isNeighbor:n.has(t)||n.has("0x"+t)||n.has(t.replace(/^0x/,"")),isHub:y.has(t),latitude:i==null?void 0:i.latitude,longitude:i==null?void 0:i.longitude}}).sort((t,i)=>t.isNeighbor!==i.isNeighbor?t.isNeighbor?-1:1:t.isHub!==i.isHub?t.isHub?-1:1:t.name.localeCompare(i.name))},[f,r,n,y]),j=c.useMemo(()=>d.some(s=>s.latitude!=null&&s.longitude!=null&&(s.latitude!==0||s.longitude!==0)),[d]),b=c.useCallback(s=>{l(s)},[]),a=j?"4xl":"lg";return o?e.jsxs(k,{open:o,onClose:g,size:a,motionPlus:!0,className:j?"sm:h-[500px] sm:max-h-[600px]":"",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-edge-subtle",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 radius-inner bg-signal-fair/10",children:e.jsx(R,{className:"w-5 h-5 text-signal-fair"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"type-micro",children:["Prefix Collision: ",e.jsx("span",{className:"font-mono text-sys-blue",children:v})]}),e.jsxs("p",{className:"text-xs text-fg-secondary",children:[d.length," nodes share this prefix"]})]})]}),e.jsx("button",{onClick:g,className:"sm:hidden min-h-[44px] min-w-[44px] px-3 flex items-center justify-center text-[15px] font-medium text-sys-blue active:text-sys-blue/70 transition-base radius-inner active:bg-subtle-fill",children:"Done"}),e.jsx("button",{onClick:g,className:"hidden sm:flex items-center justify-center p-2 text-fg-muted hover:text-fg-primary transition-base radius-inner hover:bg-subtle","aria-label":"Close",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs(B,{className:"p-0 overflow-hidden flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"sm:hidden flex-1 overflow-y-auto",children:[j&&e.jsx("div",{className:"h-64 p-2 border-b border-edge-subtle",children:e.jsx(C,{nodes:d,hoveredHash:m,onHover:b})}),e.jsx("div",{className:"p-2",children:d.map(s=>e.jsx(w,{node:s,isHovered:m===s.hash,onHover:b},s.hash))})]}),j?e.jsxs("div",{className:"hidden sm:grid sm:grid-cols-[280px_minmax(400px,1fr)] flex-1 overflow-hidden sm:min-w-[700px]",children:[e.jsx("div",{className:"overflow-y-auto border-r border-edge-subtle",children:e.jsx("div",{className:"p-2",children:d.map(s=>e.jsx(w,{node:s,isHovered:m===s.hash,onHover:b},s.hash))})}),e.jsx("div",{className:"overflow-hidden p-2",children:e.jsx(C,{nodes:d,hoveredHash:m,onHover:b})})]}):e.jsx("div",{className:"hidden sm:block flex-1 overflow-y-auto",children:e.jsx("div",{className:"p-2",children:d.map(s=>e.jsx(w,{node:s,isHovered:m===s.hash,onHover:b},s.hash))})})]})]}):null}const ee=c.memo(J);export{ee as C}; diff --git a/frontend/dist/assets/Companion-D7qg2oJ_.js b/frontend/dist/assets/Companion-COB2_jIT.js similarity index 98% rename from frontend/dist/assets/Companion-D7qg2oJ_.js rename to frontend/dist/assets/Companion-COB2_jIT.js index 1cea02d2..6086bd7a 100644 --- a/frontend/dist/assets/Companion-D7qg2oJ_.js +++ b/frontend/dist/assets/Companion-COB2_jIT.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CompanionPathMap-D1qZh3TG.js","assets/index-BXuscHlA.js","assets/usePipelineStore-DPecx6Zm.js","assets/node-types-DcVrjPZe.js","assets/car-2b6my27b.js","assets/map-pin-off-C9sYl_IQ.js","assets/index-oOga43RI.css","assets/maplibre-gl-B1CfjdFi.css","assets/CompanionEchoMap-yp80-T_o.js"])))=>i.map(i=>d[i]); -import{aX as rn,fB as gs,aZ as Zs,a_ as ln,aY as Ct,a$ as ea,r as n,b0 as on,b1 as xe,b4 as Ce,aT as X,b8 as q,b5 as he,bi as cn,b9 as jt,bd as St,be as _t,bj as dn,bf as Se,bg as ot,bk as un,bh as fe,bl as ys,bm as mn,bn as pn,bo as at,bp as hn,bq as xn,br as fn,aW as Ze,b6 as gn,fD as yn,d7 as Te,fE as ta,bt as bn,bu as ae,bv as vn,bC as jn,dk as wn,dl as Nn,bE as kn,fF as Cn,bs as $e,bD as it,bx as Sn,fG as Rt,bG as bs,fH as ct,b2 as qe,bz as sa,bA as _n,bB as Rn,d5 as vs,d8 as js,fC as In,bF as En,b3 as Mn,bb as Pn,bc as Tn,bw as aa,d3 as na,e as ne,j as e,c as P,a0 as be,fI as $n,cZ as de,fJ as se,cE as ye,cs as dt,aa as ze,bM as ut,f2 as _e,f3 as Re,f4 as Ie,d as ge,fK as Dn,fL as Fn,m as ue,fM as Ln,cT as nt,aC as je,aK as Ee,dK as He,aD as we,a2 as oe,bY as Be,eJ as Me,B,fN as An,fO as mt,au as On,Q as zn,fP as Hn,_ as ra,ca as Bn,V as De,fQ as Gn,dy as Kn,fR as It,fS as Un,fT as qn,bI as wt,fU as Vn,fV as Wn,fW as Qn,dJ as Yn,a1 as Et,ef as Xn,fX as Jn,fY as Zn,fZ as la,f_ as er,a8 as tr,f$ as sr,g0 as oa,fq as ar,g1 as nr,g2 as rr,I as pe,C as ws,g3 as ia,g4 as lr,g5 as or,g6 as ir,g7 as cr,g8 as dr,g9 as ur,ga as mr,gb as pr,gc as hr,gd as xr,a6 as fr,ge as gr,gf as yr,gg as br,gh as vr,gi as jr,gj as wr,gk as Nr,gl as kr,gm as Cr,gn as Sr,eE as _r}from"./index-BXuscHlA.js";import{P as Ns,a as ks,B as Cs,C as Ss}from"./PageLayout-DMlJphZf.js";import{e as Mt,g as Pt,a as Tt}from"./chat-utils-LE1iz0ua.js";import{c as _s,S as Rr,a as Ir}from"./SignalIndicator-BF1HzGJb.js";import{b as Er,F as Mr,y as Pr,R as Tr,T as $r,w as Dr,A as Fr,M as ca}from"./map-pin-BI3SkGEK.js";import{p as Lr,a as et,c as Y,f as Xe,b as Ar,L as Or,S as Je,s as zr,u as Hr,d as Br}from"./element-movement-ZK9X4oe-.js";import{s as Gr}from"./use-text-value-CdBb507Q.js";import{F as Kr}from"./use-tree-walker-xrBElaqd.js";import{a as tt}from"./index-B4UKVGqH.js";import{S as Rs}from"./search-CJVt1qRW.js";import{S as Ur}from"./share-2-B7Nq-Teh.js";import{R as Ge,L as qr}from"./route-UTIYmyNh.js";import{R as da}from"./rotate-ccw-uSJHrUFu.js";import{T as Ke}from"./trash-2-DkPl8dK5.js";import{H as Fe}from"./hash-DBIzIiTF.js";import{C as Vr}from"./check-check-Fg2_6eLa.js";import{P as Ue}from"./plus-CIt9Nb3C.js";import{S as Wr,C as Qr}from"./ChatBubble-BOvXH6C3.js";import{p as Yr}from"./payload-detail-D2Lkrhq2.js";import{A as Xr}from"./arrow-down-BPIAXplQ.js";import{C as Jr}from"./chevron-right-CLnbP5Ct.js";import{C as ua}from"./circle-alert-DJxbJjtU.js";import{f as Zr,c as el,a as tl,M as sl}from"./variants-C1ClDTMR.js";import{C as ma}from"./clock-CGjCxSm0.js";import{A as pa}from"./activity-Ce_CBMP-.js";import{T as ha}from"./thermometer-CU7DE0EK.js";import{S as al}from"./shield-check-DBrfhN2q.js";import{W as Is}from"./wand-sparkles-BtQTQ8OM.js";import{C as nl}from"./compass-BX0gjJ7U.js";import{G as Es}from"./git-branch-nBxx_Zec.js";import{F as re,L as le,D as ke}from"./fieldset-0901dxi_.js";import{C as xa}from"./ConfirmModal-LQhUAumX.js";import{K as fa}from"./key-round-BPCLbGFL.js";import{F as ga,P as rl}from"./pencil-C-PJWgte.js";var ll=Object.defineProperty,ol=(t,s,a)=>s in t?ll(t,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[s]=a,Ms=(t,s,a)=>(ol(t,typeof s!="symbol"?s+"":s,a),a),ee=(t=>(t[t.Open=0]="Open",t[t.Closed=1]="Closed",t))(ee||{}),rt=(t=>(t[t.Pointer=0]="Pointer",t[t.Other=1]="Other",t))(rt||{}),U=(t=>(t[t.OpenMenu=0]="OpenMenu",t[t.CloseMenu=1]="CloseMenu",t[t.GoToItem=2]="GoToItem",t[t.Search=3]="Search",t[t.ClearSearch=4]="ClearSearch",t[t.RegisterItems=5]="RegisterItems",t[t.UnregisterItems=6]="UnregisterItems",t[t.SetButtonElement=7]="SetButtonElement",t[t.SetItemsElement=8]="SetItemsElement",t[t.SortItems=9]="SortItems",t[t.MarkButtonAsMoved=10]="MarkButtonAsMoved",t))(U||{});function Ps(t,s=a=>a){let a=t.activeItemIndex!==null?t.items[t.activeItemIndex]:null,r=ea(s(t.items.slice()),i=>i.dataRef.current.domRef.current),l=a?r.indexOf(a):null;return l===-1&&(l=null),{items:r,activeItemIndex:l}}let il={1(t){if(t.menuState===1)return t;let s=t.buttonElement?et.Tracked(Ar(t.buttonElement)):t.buttonPositionState;return{...t,activeItemIndex:null,pendingFocus:{focus:Y.Nothing},menuState:1,buttonPositionState:s}},0(t,s){return t.menuState===0?t:{...t,__demoMode:!1,pendingFocus:s.focus,menuState:0,buttonPositionState:et.Idle}},2:(t,s)=>{var a,r,l,i,o;if(t.menuState===1)return t;let x={...t,searchQuery:"",activationTrigger:(a=s.trigger)!=null?a:1,__demoMode:!1};if(s.focus===Y.Nothing)return{...x,activeItemIndex:null};if(s.focus===Y.Specific)return{...x,activeItemIndex:t.items.findIndex(c=>c.id===s.id)};if(s.focus===Y.Previous){let c=t.activeItemIndex;if(c!==null){let f=t.items[c].dataRef.current.domRef,y=Xe(s,{resolveItems:()=>t.items,resolveActiveIndex:()=>t.activeItemIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(y!==null){let b=t.items[y].dataRef.current.domRef;if(((r=f.current)==null?void 0:r.previousElementSibling)===b.current||((l=b.current)==null?void 0:l.previousElementSibling)===null)return{...x,activeItemIndex:y}}}}else if(s.focus===Y.Next){let c=t.activeItemIndex;if(c!==null){let f=t.items[c].dataRef.current.domRef,y=Xe(s,{resolveItems:()=>t.items,resolveActiveIndex:()=>t.activeItemIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(y!==null){let b=t.items[y].dataRef.current.domRef;if(((i=f.current)==null?void 0:i.nextElementSibling)===b.current||((o=b.current)==null?void 0:o.nextElementSibling)===null)return{...x,activeItemIndex:y}}}}let p=Ps(t),j=Xe(s,{resolveItems:()=>p.items,resolveActiveIndex:()=>p.activeItemIndex,resolveId:c=>c.id,resolveDisabled:c=>c.dataRef.current.disabled});return{...x,...p,activeItemIndex:j}},3:(t,s)=>{let a=t.searchQuery!==""?0:1,r=t.searchQuery+s.value.toLowerCase(),l=(t.activeItemIndex!==null?t.items.slice(t.activeItemIndex+a).concat(t.items.slice(0,t.activeItemIndex+a)):t.items).find(o=>{var x;return((x=o.dataRef.current.textValue)==null?void 0:x.startsWith(r))&&!o.dataRef.current.disabled}),i=l?t.items.indexOf(l):-1;return i===-1||i===t.activeItemIndex?{...t,searchQuery:r}:{...t,searchQuery:r,activeItemIndex:i,activationTrigger:1}},4(t){return t.searchQuery===""?t:{...t,searchQuery:"",searchActiveItemIndex:null}},5:(t,s)=>{let a=t.items.concat(s.items.map(l=>l)),r=t.activeItemIndex;return t.pendingFocus.focus!==Y.Nothing&&(r=Xe(t.pendingFocus,{resolveItems:()=>a,resolveActiveIndex:()=>t.activeItemIndex,resolveId:l=>l.id,resolveDisabled:l=>l.dataRef.current.disabled})),{...t,items:a,activeItemIndex:r,pendingFocus:{focus:Y.Nothing},pendingShouldSort:!0}},6:(t,s)=>{let a=t.items,r=[],l=new Set(s.items);for(let[i,o]of a.entries())if(l.has(o.id)&&(r.push(i),l.delete(o.id),l.size===0))break;if(r.length>0){a=a.slice();for(let i of r.reverse())a.splice(i,1)}return{...t,items:a,activationTrigger:1}},7:(t,s)=>t.buttonElement===s.element?t:{...t,buttonElement:s.element},8:(t,s)=>t.itemsElement===s.element?t:{...t,itemsElement:s.element},9:t=>t.pendingShouldSort?{...t,...Ps(t),pendingShouldSort:!1}:t,10(t){return t.buttonPositionState.kind!=="Tracked"?t:{...t,buttonPositionState:et.Moved}}};class $t extends rn{constructor(s){super(s),Ms(this,"actions",{registerItem:gs(()=>{let a=[],r=new Set;return[(l,i)=>{r.has(i)||(r.add(i),a.push({id:l,dataRef:i}))},()=>(r.clear(),this.send({type:5,items:a.splice(0)}))]}),unregisterItem:gs(()=>{let a=[];return[r=>a.push(r),()=>this.send({type:6,items:a.splice(0)})]})}),Ms(this,"selectors",{activeDescendantId(a){var r;let l=a.activeItemIndex,i=a.items;return l===null||(r=i[l])==null?void 0:r.id},isActive(a,r){var l;let i=a.activeItemIndex,o=a.items;return i!==null?((l=o[i])==null?void 0:l.id)===r:!1},shouldScrollIntoView(a,r){return a.__demoMode||a.menuState!==0||a.activationTrigger===0?!1:this.isActive(a,r)},didButtonMove(a){return a.buttonPositionState.kind==="Moved"}}),this.on(5,()=>{this.disposables.requestAnimationFrame(()=>{this.send({type:9})})});{let a=this.state.id,r=Zs.get(null);this.disposables.add(r.on(ln.Push,l=>{!r.selectors.isTop(l,a)&&this.state.menuState===0&&this.send({type:1})})),this.on(0,()=>r.actions.push(a)),this.on(1,()=>r.actions.pop(a))}this.disposables.group(a=>{this.on(1,r=>{r.buttonElement&&(a.dispose(),a.add(Lr(r.buttonElement,r.buttonPositionState,()=>{this.send({type:10})})))})})}static new({id:s,__demoMode:a=!1}){return new $t({id:s,__demoMode:a,menuState:a?0:1,buttonElement:null,itemsElement:null,items:[],searchQuery:"",activeItemIndex:null,activationTrigger:1,pendingShouldSort:!1,pendingFocus:{focus:Y.Nothing},buttonPositionState:et.Idle})}reduce(s,a){return Ct(a.type,il,s,a)}}const ya=n.createContext(null);function Dt(t){let s=n.useContext(ya);if(s===null){let a=new Error(`<${t} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(a,ba),a}return s}function ba({id:t,__demoMode:s=!1}){let a=n.useMemo(()=>$t.new({id:t,__demoMode:s}),[]);return on(()=>a.dispose()),a}let cl=n.Fragment;function dl(t,s){let a=n.useId(),{__demoMode:r=!1,...l}=t,i=ba({id:a,__demoMode:r}),[o,x,p]=he(i,S=>[S.menuState,S.itemsElement,S.buttonElement]),j=Ce(s),c=Zs.get(null),f=he(c,n.useCallback(S=>c.selectors.isTop(S,a),[c,a]));jn(f,[p,x],(S,h)=>{var _;i.send({type:U.CloseMenu}),wn(h,Nn.Loose)||(S.preventDefault(),(_=i.state.buttonElement)==null||_.focus())});let y=X(()=>{i.send({type:U.CloseMenu})}),b=Se({open:o===ee.Open,close:y}),d={ref:j},N=fe();return ae.createElement(Fr,null,ae.createElement(ya.Provider,{value:i},ae.createElement(kn,{value:Ct(o,{[ee.Open]:at.Open,[ee.Closed]:at.Closed})},N({ourProps:d,theirProps:l,slot:b,defaultTag:cl,name:"Menu"}))))}let ul="button";function ml(t,s){let a=Dt("Menu.Button"),r=n.useId(),{id:l=`headlessui-menu-button-${r}`,disabled:i=!1,autoFocus:o=!1,...x}=t,p=n.useRef(null),j=Er(),c=Ce(s,p,Mr(),X(m=>a.send({type:U.SetButtonElement,element:m}))),f=X(m=>{switch(m.key){case q.Space:case q.Enter:case q.ArrowDown:m.preventDefault(),m.stopPropagation(),a.send({type:U.OpenMenu,focus:{focus:Y.First}});break;case q.ArrowUp:m.preventDefault(),m.stopPropagation(),a.send({type:U.OpenMenu,focus:{focus:Y.Last}});break}}),y=X(m=>{switch(m.key){case q.Space:m.preventDefault();break}}),[b,d,N]=he(a,m=>[m.menuState,m.buttonElement,m.itemsElement]),S=b===ee.Open;Or(S,{trigger:d,action:n.useCallback(m=>{if(d!=null&&d.contains(m.target))return Je.Ignore;let I=m.target.closest('[role="menuitem"]:not([data-disabled])');return cn(I)?Je.Select(I):N!=null&&N.contains(m.target)?Je.Ignore:Je.Close},[d,N]),close:n.useCallback(()=>a.send({type:U.CloseMenu}),[]),select:n.useCallback(m=>m.click(),[])});let h=zr(m=>{var I;i||(b===ee.Open?(jt.flushSync(()=>a.send({type:U.CloseMenu})),(I=p.current)==null||I.focus({preventScroll:!0})):(m.preventDefault(),a.send({type:U.OpenMenu,focus:{focus:Y.Nothing},trigger:rt.Pointer})))}),{isFocusVisible:_,focusProps:E}=St({autoFocus:o}),{isHovered:R,hoverProps:w}=_t({isDisabled:i}),{pressed:C,pressProps:T}=dn({disabled:i}),v=Se({open:b===ee.Open,active:C||b===ee.Open,disabled:i,hover:R,focus:_,autofocus:o}),u=ot(j(),{ref:c,id:l,type:un(t,p.current),"aria-haspopup":"menu","aria-controls":N==null?void 0:N.id,"aria-expanded":b===ee.Open,disabled:i||void 0,autoFocus:o,onKeyDown:f,onKeyUp:y},h,E,w,T);return fe()({ourProps:u,theirProps:x,slot:v,defaultTag:ul,name:"Menu.Button"})}let pl="div",hl=bs.RenderStrategy|bs.Static;function xl(t,s){let a=n.useId(),{id:r=`headlessui-menu-items-${a}`,anchor:l,portal:i=!1,modal:o=!0,transition:x=!1,...p}=t,j=Pr(l),c=Dt("Menu.Items"),[f,y]=Tr(j),b=$r(),[d,N]=n.useState(null),S=Ce(s,j?f:null,X(L=>c.send({type:U.SetItemsElement,element:L})),N),[h,_]=he(c,L=>[L.menuState,L.buttonElement]),E=ys(_),R=ys(d);j&&(i=!0);let w=mn(),[C,T]=pn(x,d,w!==null?(w&at.Open)===at.Open:h===ee.Open);hn(C,_,()=>{c.send({type:U.CloseMenu})});let v=he(c,L=>L.__demoMode),u=v?!1:o&&h===ee.Open;xn(u,R);let m=v?!1:o&&h===ee.Open;fn(m,{allowed:n.useCallback(()=>[_,d],[_,d])});let I=he(c,c.selectors.didButtonMove)?!1:C;n.useEffect(()=>{let L=d;L&&h===ee.Open&&(Ze(L)||L.focus({preventScroll:!0}))},[h,d]),Kr(h===ee.Open,{container:d,accept(L){return L.getAttribute("role")==="menuitem"?NodeFilter.FILTER_REJECT:L.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(L){L.setAttribute("role","none")}});let g=gn(),$=X(L=>{var V,ie,F;switch(g.dispose(),L.key){case q.Space:if(c.state.searchQuery!=="")return L.preventDefault(),L.stopPropagation(),c.send({type:U.Search,value:L.key});case q.Enter:if(L.preventDefault(),L.stopPropagation(),c.state.activeItemIndex!==null){let{dataRef:D}=c.state.items[c.state.activeItemIndex];(ie=(V=D.current)==null?void 0:V.domRef.current)==null||ie.click()}c.send({type:U.CloseMenu}),ta(c.state.buttonElement);break;case q.ArrowDown:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.Next});case q.ArrowUp:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.Previous});case q.Home:case q.PageUp:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.First});case q.End:case q.PageDown:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.Last});case q.Escape:L.preventDefault(),L.stopPropagation(),jt.flushSync(()=>c.send({type:U.CloseMenu})),(F=c.state.buttonElement)==null||F.focus({preventScroll:!0});break;case q.Tab:L.preventDefault(),L.stopPropagation(),jt.flushSync(()=>c.send({type:U.CloseMenu})),yn(c.state.buttonElement,L.shiftKey?Te.Previous:Te.Next);break;default:L.key.length===1&&(c.send({type:U.Search,value:L.key}),g.setTimeout(()=>c.send({type:U.ClearSearch}),350));break}}),k=X(L=>{switch(L.key){case q.Space:L.preventDefault();break}}),H=Se({open:h===ee.Open}),te=ot(j?b():{},{"aria-activedescendant":he(c,c.selectors.activeDescendantId),"aria-labelledby":he(c,L=>{var V;return(V=L.buttonElement)==null?void 0:V.id}),id:r,onKeyDown:$,onKeyUp:k,role:"menu",tabIndex:h===ee.Open?0:void 0,ref:S,style:{...p.style,...y,"--button-width":Dr(C,_,!0).width},...bn(T)}),W=fe();return ae.createElement(vn,{enabled:i?t.static||C:!1,ownerDocument:E},W({ourProps:te,theirProps:p,slot:H,defaultTag:pl,features:hl,visible:I,name:"Menu.Items"}))}let fl=n.Fragment;function gl(t,s){let a=n.useId(),{id:r=`headlessui-menu-item-${a}`,disabled:l=!1,...i}=t,o=Dt("Menu.Item"),x=he(o,I=>o.selectors.isActive(I,r)),p=n.useRef(null),j=Ce(s,p),c=he(o,I=>o.selectors.shouldScrollIntoView(I,r));$e(()=>{if(c)return Sn().requestAnimationFrame(()=>{var I,g;(g=(I=p.current)==null?void 0:I.scrollIntoView)==null||g.call(I,{block:"nearest"})})},[c,p]);let f=Gr(p),y=n.useRef({disabled:l,domRef:p,get textValue(){return f()}});$e(()=>{y.current.disabled=l},[y,l]),$e(()=>(o.actions.registerItem(r,y),()=>o.actions.unregisterItem(r)),[y,r]);let b=X(()=>{o.send({type:U.CloseMenu})}),d=X(I=>{if(l)return I.preventDefault();o.send({type:U.CloseMenu}),ta(o.state.buttonElement)}),N=X(()=>{if(l)return o.send({type:U.GoToItem,focus:Y.Nothing});o.send({type:U.GoToItem,focus:Y.Specific,id:r})}),S=Hr(),h=X(I=>S.update(I)),_=X(I=>{S.wasMoved(I)&&(l||x||o.send({type:U.GoToItem,focus:Y.Specific,id:r,trigger:rt.Pointer}))}),E=X(I=>{S.wasMoved(I)&&(l||x&&o.state.activationTrigger===rt.Pointer&&o.send({type:U.GoToItem,focus:Y.Nothing}))}),[R,w]=it(),[C,T]=Rt(),v=Se({active:x,focus:x,disabled:l,close:b}),u={id:r,ref:j,role:"menuitem",tabIndex:l===!0?void 0:-1,"aria-disabled":l===!0?!0:void 0,"aria-labelledby":R,"aria-describedby":C,disabled:void 0,onClick:d,onFocus:N,onPointerEnter:h,onMouseEnter:h,onPointerMove:_,onMouseMove:_,onPointerLeave:E,onMouseLeave:E},m=fe();return ae.createElement(w,null,ae.createElement(T,null,m({ourProps:u,theirProps:i,slot:v,defaultTag:fl,name:"Menu.Item"})))}let yl="div";function bl(t,s){let[a,r]=it(),l=t,i={ref:s,"aria-labelledby":a,role:"group"},o=fe();return ae.createElement(r,null,o({ourProps:i,theirProps:l,slot:{},defaultTag:yl,name:"Menu.Section"}))}let vl="header";function jl(t,s){let a=n.useId(),{id:r=`headlessui-menu-heading-${a}`,...l}=t,i=Cn();$e(()=>i.register(r),[r,i.register]);let o={id:r,ref:s,role:"presentation",...i.props};return fe()({ourProps:o,theirProps:l,slot:{},defaultTag:vl,name:"Menu.Heading"})}let wl="div";function Nl(t,s){let a=t,r={ref:s,role:"separator"};return fe()({ourProps:r,theirProps:a,slot:{},defaultTag:wl,name:"Menu.Separator"})}let kl=xe(dl),va=xe(ml),ja=xe(xl),Nt=xe(gl),Cl=xe(bl),Sl=xe(jl),wa=xe(Nl),_l=Object.assign(kl,{Button:va,Items:ja,Item:Nt,Section:Cl,Heading:Sl,Separator:wa});var Rl=(t=>(t[t.RegisterOption=0]="RegisterOption",t[t.UnregisterOption=1]="UnregisterOption",t))(Rl||{});let Il={0(t,s){let a=[...t.options,{id:s.id,element:s.element,propsRef:s.propsRef}];return{...t,options:ea(a,r=>r.element.current)}},1(t,s){let a=t.options.slice(),r=t.options.findIndex(l=>l.id===s.id);return r===-1?t:(a.splice(r,1),{...t,options:a})}},Ft=n.createContext(null);Ft.displayName="RadioGroupDataContext";function Lt(t){let s=n.useContext(Ft);if(s===null){let a=new Error(`<${t} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(a,Lt),a}return s}let At=n.createContext(null);At.displayName="RadioGroupActionsContext";function Ot(t){let s=n.useContext(At);if(s===null){let a=new Error(`<${t} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(a,Ot),a}return s}function El(t,s){return Ct(s.type,Il,t,s)}let Ml="div";function Pl(t,s){let a=n.useId(),r=sa(),{id:l=`headlessui-radiogroup-${a}`,value:i,form:o,name:x,onChange:p,by:j,disabled:c=r||!1,defaultValue:f,tabIndex:y=0,...b}=t,d=Br(j),[N,S]=n.useReducer(El,{options:[]}),h=N.options,[_,E]=it(),[R,w]=Rt(),C=n.useRef(null),T=Ce(C,s),v=_n(f),[u,m]=Rn(i,p,v),I=n.useMemo(()=>h.find(D=>!D.propsRef.current.disabled),[h]),g=n.useMemo(()=>h.some(D=>d(D.propsRef.current.value,u)),[h,u]),$=X(D=>{var A;if(c||d(D,u))return!1;let O=(A=h.find(G=>d(G.propsRef.current.value,D)))==null?void 0:A.propsRef.current;return O!=null&&O.disabled?!1:(m==null||m(D),!0)}),k=X(D=>{if(!C.current)return;let A=h.filter(O=>O.propsRef.current.disabled===!1).map(O=>O.element.current);switch(D.key){case q.Enter:In(D.currentTarget);break;case q.ArrowLeft:case q.ArrowUp:if(D.preventDefault(),D.stopPropagation(),vs(A,Te.Previous|Te.WrapAround)===js.Success){let O=h.find(G=>Ze(G.element.current));O&&$(O.propsRef.current.value)}break;case q.ArrowRight:case q.ArrowDown:if(D.preventDefault(),D.stopPropagation(),vs(A,Te.Next|Te.WrapAround)===js.Success){let O=h.find(G=>Ze(G.element.current));O&&$(O.propsRef.current.value)}break;case q.Space:{D.preventDefault(),D.stopPropagation();let O=h.find(G=>Ze(G.element.current));O&&$(O.propsRef.current.value)}break}}),H=X(D=>(S({type:0,...D}),()=>S({type:1,id:D.id}))),te=n.useMemo(()=>({value:u,firstOption:I,containsCheckedOption:g,disabled:c,compare:d,tabIndex:y,...N}),[u,I,g,c,d,y,N]),W=n.useMemo(()=>({registerOption:H,change:$}),[H,$]),L={ref:T,id:l,role:"radiogroup","aria-labelledby":_,"aria-describedby":R,onKeyDown:k},V=Se({value:u}),ie=n.useCallback(()=>{if(v!==void 0)return $(v)},[$,v]),F=fe();return ae.createElement(w,{name:"RadioGroup.Description"},ae.createElement(E,{name:"RadioGroup.Label"},ae.createElement(At.Provider,{value:W},ae.createElement(Ft.Provider,{value:te},x!=null&&ae.createElement(En,{disabled:c,data:{[x]:u||"on"},overrides:{type:"radio",checked:u!=null},form:o,onReset:ie}),F({ourProps:L,theirProps:b,slot:V,defaultTag:Ml,name:"RadioGroup"})))))}let Tl="div";function $l(t,s){var a;let r=Lt("RadioGroup.Option"),l=Ot("RadioGroup.Option"),i=n.useId(),{id:o=`headlessui-radiogroup-option-${i}`,value:x,disabled:p=r.disabled||!1,autoFocus:j=!1,...c}=t,f=n.useRef(null),y=Ce(f,s),[b,d]=it(),[N,S]=Rt(),h=aa({value:x,disabled:p});$e(()=>l.registerOption({id:o,element:f,propsRef:h}),[o,l,f,h]);let _=X(g=>{var $;if(na(g.currentTarget))return g.preventDefault();l.change(x)&&(($=f.current)==null||$.focus())}),E=((a=r.firstOption)==null?void 0:a.id)===o,{isFocusVisible:R,focusProps:w}=St({autoFocus:j}),{isHovered:C,hoverProps:T}=_t({isDisabled:p}),v=r.compare(r.value,x),u=ot({ref:y,id:o,role:"radio","aria-checked":v?"true":"false","aria-labelledby":b,"aria-describedby":N,"aria-disabled":p?!0:void 0,tabIndex:p?-1:v||!r.containsCheckedOption&&E?r.tabIndex:-1,onClick:p?void 0:_,autoFocus:j},w,T),m=Se({checked:v,disabled:p,active:R,hover:C,focus:R,autofocus:j}),I=fe();return ae.createElement(S,{name:"RadioGroup.Description"},ae.createElement(d,{name:"RadioGroup.Label"},I({ourProps:u,theirProps:c,slot:m,defaultTag:Tl,name:"RadioGroup.Option"})))}let Dl="span";function Fl(t,s){var a;let r=Lt("Radio"),l=Ot("Radio"),i=n.useId(),o=Mn(),x=sa(),{id:p=o||`headlessui-radio-${i}`,value:j,disabled:c=r.disabled||x||!1,autoFocus:f=!1,...y}=t,b=n.useRef(null),d=Ce(b,s),N=Pn(),S=Tn(),h=aa({value:j,disabled:c});$e(()=>l.registerOption({id:p,element:b,propsRef:h}),[p,l,b,h]);let _=X(I=>{var g;if(na(I.currentTarget))return I.preventDefault();l.change(j)&&((g=b.current)==null||g.focus())}),{isFocusVisible:E,focusProps:R}=St({autoFocus:f}),{isHovered:w,hoverProps:C}=_t({isDisabled:c}),T=((a=r.firstOption)==null?void 0:a.id)===p,v=r.compare(r.value,j),u=ot({ref:d,id:p,role:"radio","aria-checked":v?"true":"false","aria-labelledby":N,"aria-describedby":S,"aria-disabled":c?!0:void 0,tabIndex:c?-1:v||!r.containsCheckedOption&&T?r.tabIndex:-1,autoFocus:f,onClick:c?void 0:_},R,C),m=Se({checked:v,disabled:c,hover:w,focus:E,autofocus:f});return fe()({ourProps:u,theirProps:y,slot:m,defaultTag:Dl,name:"Radio"})}let Ll=xe(Pl),Al=xe($l),pt=xe(Fl),Ol=qe,zl=ct,Hl=Object.assign(Ll,{Option:Al,Radio:pt,Label:Ol,Description:zl});/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CompanionPathMap-CBbQCUOF.js","assets/index-BBBuaCQs.js","assets/usePipelineStore-CSy1PGRp.js","assets/node-types-DJyFsA81.js","assets/car-DhqwLgdJ.js","assets/map-pin-off-CmyDNImL.js","assets/index-BsosE29f.css","assets/maplibre-gl-B1CfjdFi.css","assets/CompanionEchoMap-DRaPu98w.js"])))=>i.map(i=>d[i]); +import{aX as rn,fB as gs,aZ as Zs,a_ as ln,aY as Ct,a$ as ea,r as n,b0 as on,b1 as xe,b4 as Ce,aT as X,b8 as q,b5 as he,bi as cn,b9 as jt,bd as St,be as _t,bj as dn,bf as Se,bg as ot,bk as un,bh as fe,bl as ys,bm as mn,bn as pn,bo as at,bp as hn,bq as xn,br as fn,aW as Ze,b6 as gn,fD as yn,d7 as Te,fE as ta,bt as bn,bu as ae,bv as vn,bC as jn,dk as wn,dl as Nn,bE as kn,fF as Cn,bs as $e,bD as it,bx as Sn,fG as Rt,bG as bs,fH as ct,b2 as qe,bz as sa,bA as _n,bB as Rn,d5 as vs,d8 as js,fC as In,bF as En,b3 as Mn,bb as Pn,bc as Tn,bw as aa,d3 as na,e as ne,j as e,c as P,a0 as be,fI as $n,cZ as de,fJ as se,cE as ye,cs as dt,aa as ze,bM as ut,f2 as _e,f3 as Re,f4 as Ie,d as ge,fK as Dn,fL as Fn,m as ue,fM as Ln,cT as nt,aC as je,aK as Ee,dK as He,aD as we,a2 as oe,bY as Be,eJ as Me,B,fN as An,fO as mt,au as On,Q as zn,fP as Hn,_ as ra,ca as Bn,V as De,fQ as Gn,dy as Kn,fR as It,fS as Un,fT as qn,bI as wt,fU as Vn,fV as Wn,fW as Qn,dJ as Yn,a1 as Et,ef as Xn,fX as Jn,fY as Zn,fZ as la,f_ as er,a8 as tr,f$ as sr,g0 as oa,fq as ar,g1 as nr,g2 as rr,I as pe,C as ws,g3 as ia,g4 as lr,g5 as or,g6 as ir,g7 as cr,g8 as dr,g9 as ur,ga as mr,gb as pr,gc as hr,gd as xr,a6 as fr,ge as gr,gf as yr,gg as br,gh as vr,gi as jr,gj as wr,gk as Nr,gl as kr,gm as Cr,gn as Sr,eE as _r}from"./index-BBBuaCQs.js";import{P as Ns,a as ks,B as Cs,C as Ss}from"./PageLayout-CRsVqzTw.js";import{e as Mt,g as Pt,a as Tt}from"./chat-utils-DP6LcfMx.js";import{c as _s,S as Rr,a as Ir}from"./SignalIndicator-CkqfZLem.js";import{b as Er,F as Mr,y as Pr,R as Tr,T as $r,w as Dr,A as Fr,M as ca}from"./map-pin-stXuybQm.js";import{p as Lr,a as et,c as Y,f as Xe,b as Ar,L as Or,S as Je,s as zr,u as Hr,d as Br}from"./element-movement-BGm_uaZd.js";import{s as Gr}from"./use-text-value-2q1EQ-Jk.js";import{F as Kr}from"./use-tree-walker-DG6CClPS.js";import{a as tt}from"./index-CQClum6j.js";import{S as Rs}from"./search-Dk9GWMDh.js";import{S as Ur}from"./share-2-WwVAp6Bf.js";import{R as Ge,L as qr}from"./route-C2e8nQdR.js";import{R as da}from"./rotate-ccw-CyEc4qm2.js";import{T as Ke}from"./trash-2-DUN81fPu.js";import{H as Fe}from"./hash-DtZ8UW82.js";import{C as Vr}from"./check-check-DtG4GBQp.js";import{P as Ue}from"./plus-BnP2OnZA.js";import{S as Wr,C as Qr}from"./ChatBubble-B1RvK-PR.js";import{p as Yr}from"./payload-detail-XcpxSMLm.js";import{A as Xr}from"./arrow-down-38Jxseaf.js";import{C as Jr}from"./chevron-right-DMF-_TsK.js";import{C as ua}from"./circle-alert-pRjy9QOw.js";import{f as Zr,c as el,a as tl,M as sl}from"./variants-WXnHxSXf.js";import{C as ma}from"./clock-DV9Z95kG.js";import{A as pa}from"./activity-cShCNfEo.js";import{T as ha}from"./thermometer-CAAFHFt7.js";import{S as al}from"./shield-check-D4vepuXj.js";import{W as Is}from"./wand-sparkles-C15_vEeB.js";import{C as nl}from"./compass-DD46PLB1.js";import{G as Es}from"./git-branch-DoAYRXX_.js";import{F as re,L as le,D as ke}from"./fieldset-jctZAIVU.js";import{C as xa}from"./ConfirmModal-DGG0Ux0s.js";import{K as fa}from"./key-round-BlimCcTG.js";import{F as ga,P as rl}from"./pencil-BkH6oVA6.js";var ll=Object.defineProperty,ol=(t,s,a)=>s in t?ll(t,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[s]=a,Ms=(t,s,a)=>(ol(t,typeof s!="symbol"?s+"":s,a),a),ee=(t=>(t[t.Open=0]="Open",t[t.Closed=1]="Closed",t))(ee||{}),rt=(t=>(t[t.Pointer=0]="Pointer",t[t.Other=1]="Other",t))(rt||{}),U=(t=>(t[t.OpenMenu=0]="OpenMenu",t[t.CloseMenu=1]="CloseMenu",t[t.GoToItem=2]="GoToItem",t[t.Search=3]="Search",t[t.ClearSearch=4]="ClearSearch",t[t.RegisterItems=5]="RegisterItems",t[t.UnregisterItems=6]="UnregisterItems",t[t.SetButtonElement=7]="SetButtonElement",t[t.SetItemsElement=8]="SetItemsElement",t[t.SortItems=9]="SortItems",t[t.MarkButtonAsMoved=10]="MarkButtonAsMoved",t))(U||{});function Ps(t,s=a=>a){let a=t.activeItemIndex!==null?t.items[t.activeItemIndex]:null,r=ea(s(t.items.slice()),i=>i.dataRef.current.domRef.current),l=a?r.indexOf(a):null;return l===-1&&(l=null),{items:r,activeItemIndex:l}}let il={1(t){if(t.menuState===1)return t;let s=t.buttonElement?et.Tracked(Ar(t.buttonElement)):t.buttonPositionState;return{...t,activeItemIndex:null,pendingFocus:{focus:Y.Nothing},menuState:1,buttonPositionState:s}},0(t,s){return t.menuState===0?t:{...t,__demoMode:!1,pendingFocus:s.focus,menuState:0,buttonPositionState:et.Idle}},2:(t,s)=>{var a,r,l,i,o;if(t.menuState===1)return t;let x={...t,searchQuery:"",activationTrigger:(a=s.trigger)!=null?a:1,__demoMode:!1};if(s.focus===Y.Nothing)return{...x,activeItemIndex:null};if(s.focus===Y.Specific)return{...x,activeItemIndex:t.items.findIndex(c=>c.id===s.id)};if(s.focus===Y.Previous){let c=t.activeItemIndex;if(c!==null){let f=t.items[c].dataRef.current.domRef,y=Xe(s,{resolveItems:()=>t.items,resolveActiveIndex:()=>t.activeItemIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(y!==null){let b=t.items[y].dataRef.current.domRef;if(((r=f.current)==null?void 0:r.previousElementSibling)===b.current||((l=b.current)==null?void 0:l.previousElementSibling)===null)return{...x,activeItemIndex:y}}}}else if(s.focus===Y.Next){let c=t.activeItemIndex;if(c!==null){let f=t.items[c].dataRef.current.domRef,y=Xe(s,{resolveItems:()=>t.items,resolveActiveIndex:()=>t.activeItemIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(y!==null){let b=t.items[y].dataRef.current.domRef;if(((i=f.current)==null?void 0:i.nextElementSibling)===b.current||((o=b.current)==null?void 0:o.nextElementSibling)===null)return{...x,activeItemIndex:y}}}}let p=Ps(t),j=Xe(s,{resolveItems:()=>p.items,resolveActiveIndex:()=>p.activeItemIndex,resolveId:c=>c.id,resolveDisabled:c=>c.dataRef.current.disabled});return{...x,...p,activeItemIndex:j}},3:(t,s)=>{let a=t.searchQuery!==""?0:1,r=t.searchQuery+s.value.toLowerCase(),l=(t.activeItemIndex!==null?t.items.slice(t.activeItemIndex+a).concat(t.items.slice(0,t.activeItemIndex+a)):t.items).find(o=>{var x;return((x=o.dataRef.current.textValue)==null?void 0:x.startsWith(r))&&!o.dataRef.current.disabled}),i=l?t.items.indexOf(l):-1;return i===-1||i===t.activeItemIndex?{...t,searchQuery:r}:{...t,searchQuery:r,activeItemIndex:i,activationTrigger:1}},4(t){return t.searchQuery===""?t:{...t,searchQuery:"",searchActiveItemIndex:null}},5:(t,s)=>{let a=t.items.concat(s.items.map(l=>l)),r=t.activeItemIndex;return t.pendingFocus.focus!==Y.Nothing&&(r=Xe(t.pendingFocus,{resolveItems:()=>a,resolveActiveIndex:()=>t.activeItemIndex,resolveId:l=>l.id,resolveDisabled:l=>l.dataRef.current.disabled})),{...t,items:a,activeItemIndex:r,pendingFocus:{focus:Y.Nothing},pendingShouldSort:!0}},6:(t,s)=>{let a=t.items,r=[],l=new Set(s.items);for(let[i,o]of a.entries())if(l.has(o.id)&&(r.push(i),l.delete(o.id),l.size===0))break;if(r.length>0){a=a.slice();for(let i of r.reverse())a.splice(i,1)}return{...t,items:a,activationTrigger:1}},7:(t,s)=>t.buttonElement===s.element?t:{...t,buttonElement:s.element},8:(t,s)=>t.itemsElement===s.element?t:{...t,itemsElement:s.element},9:t=>t.pendingShouldSort?{...t,...Ps(t),pendingShouldSort:!1}:t,10(t){return t.buttonPositionState.kind!=="Tracked"?t:{...t,buttonPositionState:et.Moved}}};class $t extends rn{constructor(s){super(s),Ms(this,"actions",{registerItem:gs(()=>{let a=[],r=new Set;return[(l,i)=>{r.has(i)||(r.add(i),a.push({id:l,dataRef:i}))},()=>(r.clear(),this.send({type:5,items:a.splice(0)}))]}),unregisterItem:gs(()=>{let a=[];return[r=>a.push(r),()=>this.send({type:6,items:a.splice(0)})]})}),Ms(this,"selectors",{activeDescendantId(a){var r;let l=a.activeItemIndex,i=a.items;return l===null||(r=i[l])==null?void 0:r.id},isActive(a,r){var l;let i=a.activeItemIndex,o=a.items;return i!==null?((l=o[i])==null?void 0:l.id)===r:!1},shouldScrollIntoView(a,r){return a.__demoMode||a.menuState!==0||a.activationTrigger===0?!1:this.isActive(a,r)},didButtonMove(a){return a.buttonPositionState.kind==="Moved"}}),this.on(5,()=>{this.disposables.requestAnimationFrame(()=>{this.send({type:9})})});{let a=this.state.id,r=Zs.get(null);this.disposables.add(r.on(ln.Push,l=>{!r.selectors.isTop(l,a)&&this.state.menuState===0&&this.send({type:1})})),this.on(0,()=>r.actions.push(a)),this.on(1,()=>r.actions.pop(a))}this.disposables.group(a=>{this.on(1,r=>{r.buttonElement&&(a.dispose(),a.add(Lr(r.buttonElement,r.buttonPositionState,()=>{this.send({type:10})})))})})}static new({id:s,__demoMode:a=!1}){return new $t({id:s,__demoMode:a,menuState:a?0:1,buttonElement:null,itemsElement:null,items:[],searchQuery:"",activeItemIndex:null,activationTrigger:1,pendingShouldSort:!1,pendingFocus:{focus:Y.Nothing},buttonPositionState:et.Idle})}reduce(s,a){return Ct(a.type,il,s,a)}}const ya=n.createContext(null);function Dt(t){let s=n.useContext(ya);if(s===null){let a=new Error(`<${t} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(a,ba),a}return s}function ba({id:t,__demoMode:s=!1}){let a=n.useMemo(()=>$t.new({id:t,__demoMode:s}),[]);return on(()=>a.dispose()),a}let cl=n.Fragment;function dl(t,s){let a=n.useId(),{__demoMode:r=!1,...l}=t,i=ba({id:a,__demoMode:r}),[o,x,p]=he(i,S=>[S.menuState,S.itemsElement,S.buttonElement]),j=Ce(s),c=Zs.get(null),f=he(c,n.useCallback(S=>c.selectors.isTop(S,a),[c,a]));jn(f,[p,x],(S,h)=>{var _;i.send({type:U.CloseMenu}),wn(h,Nn.Loose)||(S.preventDefault(),(_=i.state.buttonElement)==null||_.focus())});let y=X(()=>{i.send({type:U.CloseMenu})}),b=Se({open:o===ee.Open,close:y}),d={ref:j},N=fe();return ae.createElement(Fr,null,ae.createElement(ya.Provider,{value:i},ae.createElement(kn,{value:Ct(o,{[ee.Open]:at.Open,[ee.Closed]:at.Closed})},N({ourProps:d,theirProps:l,slot:b,defaultTag:cl,name:"Menu"}))))}let ul="button";function ml(t,s){let a=Dt("Menu.Button"),r=n.useId(),{id:l=`headlessui-menu-button-${r}`,disabled:i=!1,autoFocus:o=!1,...x}=t,p=n.useRef(null),j=Er(),c=Ce(s,p,Mr(),X(m=>a.send({type:U.SetButtonElement,element:m}))),f=X(m=>{switch(m.key){case q.Space:case q.Enter:case q.ArrowDown:m.preventDefault(),m.stopPropagation(),a.send({type:U.OpenMenu,focus:{focus:Y.First}});break;case q.ArrowUp:m.preventDefault(),m.stopPropagation(),a.send({type:U.OpenMenu,focus:{focus:Y.Last}});break}}),y=X(m=>{switch(m.key){case q.Space:m.preventDefault();break}}),[b,d,N]=he(a,m=>[m.menuState,m.buttonElement,m.itemsElement]),S=b===ee.Open;Or(S,{trigger:d,action:n.useCallback(m=>{if(d!=null&&d.contains(m.target))return Je.Ignore;let I=m.target.closest('[role="menuitem"]:not([data-disabled])');return cn(I)?Je.Select(I):N!=null&&N.contains(m.target)?Je.Ignore:Je.Close},[d,N]),close:n.useCallback(()=>a.send({type:U.CloseMenu}),[]),select:n.useCallback(m=>m.click(),[])});let h=zr(m=>{var I;i||(b===ee.Open?(jt.flushSync(()=>a.send({type:U.CloseMenu})),(I=p.current)==null||I.focus({preventScroll:!0})):(m.preventDefault(),a.send({type:U.OpenMenu,focus:{focus:Y.Nothing},trigger:rt.Pointer})))}),{isFocusVisible:_,focusProps:E}=St({autoFocus:o}),{isHovered:R,hoverProps:w}=_t({isDisabled:i}),{pressed:C,pressProps:T}=dn({disabled:i}),v=Se({open:b===ee.Open,active:C||b===ee.Open,disabled:i,hover:R,focus:_,autofocus:o}),u=ot(j(),{ref:c,id:l,type:un(t,p.current),"aria-haspopup":"menu","aria-controls":N==null?void 0:N.id,"aria-expanded":b===ee.Open,disabled:i||void 0,autoFocus:o,onKeyDown:f,onKeyUp:y},h,E,w,T);return fe()({ourProps:u,theirProps:x,slot:v,defaultTag:ul,name:"Menu.Button"})}let pl="div",hl=bs.RenderStrategy|bs.Static;function xl(t,s){let a=n.useId(),{id:r=`headlessui-menu-items-${a}`,anchor:l,portal:i=!1,modal:o=!0,transition:x=!1,...p}=t,j=Pr(l),c=Dt("Menu.Items"),[f,y]=Tr(j),b=$r(),[d,N]=n.useState(null),S=Ce(s,j?f:null,X(L=>c.send({type:U.SetItemsElement,element:L})),N),[h,_]=he(c,L=>[L.menuState,L.buttonElement]),E=ys(_),R=ys(d);j&&(i=!0);let w=mn(),[C,T]=pn(x,d,w!==null?(w&at.Open)===at.Open:h===ee.Open);hn(C,_,()=>{c.send({type:U.CloseMenu})});let v=he(c,L=>L.__demoMode),u=v?!1:o&&h===ee.Open;xn(u,R);let m=v?!1:o&&h===ee.Open;fn(m,{allowed:n.useCallback(()=>[_,d],[_,d])});let I=he(c,c.selectors.didButtonMove)?!1:C;n.useEffect(()=>{let L=d;L&&h===ee.Open&&(Ze(L)||L.focus({preventScroll:!0}))},[h,d]),Kr(h===ee.Open,{container:d,accept(L){return L.getAttribute("role")==="menuitem"?NodeFilter.FILTER_REJECT:L.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(L){L.setAttribute("role","none")}});let g=gn(),$=X(L=>{var V,ie,F;switch(g.dispose(),L.key){case q.Space:if(c.state.searchQuery!=="")return L.preventDefault(),L.stopPropagation(),c.send({type:U.Search,value:L.key});case q.Enter:if(L.preventDefault(),L.stopPropagation(),c.state.activeItemIndex!==null){let{dataRef:D}=c.state.items[c.state.activeItemIndex];(ie=(V=D.current)==null?void 0:V.domRef.current)==null||ie.click()}c.send({type:U.CloseMenu}),ta(c.state.buttonElement);break;case q.ArrowDown:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.Next});case q.ArrowUp:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.Previous});case q.Home:case q.PageUp:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.First});case q.End:case q.PageDown:return L.preventDefault(),L.stopPropagation(),c.send({type:U.GoToItem,focus:Y.Last});case q.Escape:L.preventDefault(),L.stopPropagation(),jt.flushSync(()=>c.send({type:U.CloseMenu})),(F=c.state.buttonElement)==null||F.focus({preventScroll:!0});break;case q.Tab:L.preventDefault(),L.stopPropagation(),jt.flushSync(()=>c.send({type:U.CloseMenu})),yn(c.state.buttonElement,L.shiftKey?Te.Previous:Te.Next);break;default:L.key.length===1&&(c.send({type:U.Search,value:L.key}),g.setTimeout(()=>c.send({type:U.ClearSearch}),350));break}}),k=X(L=>{switch(L.key){case q.Space:L.preventDefault();break}}),H=Se({open:h===ee.Open}),te=ot(j?b():{},{"aria-activedescendant":he(c,c.selectors.activeDescendantId),"aria-labelledby":he(c,L=>{var V;return(V=L.buttonElement)==null?void 0:V.id}),id:r,onKeyDown:$,onKeyUp:k,role:"menu",tabIndex:h===ee.Open?0:void 0,ref:S,style:{...p.style,...y,"--button-width":Dr(C,_,!0).width},...bn(T)}),W=fe();return ae.createElement(vn,{enabled:i?t.static||C:!1,ownerDocument:E},W({ourProps:te,theirProps:p,slot:H,defaultTag:pl,features:hl,visible:I,name:"Menu.Items"}))}let fl=n.Fragment;function gl(t,s){let a=n.useId(),{id:r=`headlessui-menu-item-${a}`,disabled:l=!1,...i}=t,o=Dt("Menu.Item"),x=he(o,I=>o.selectors.isActive(I,r)),p=n.useRef(null),j=Ce(s,p),c=he(o,I=>o.selectors.shouldScrollIntoView(I,r));$e(()=>{if(c)return Sn().requestAnimationFrame(()=>{var I,g;(g=(I=p.current)==null?void 0:I.scrollIntoView)==null||g.call(I,{block:"nearest"})})},[c,p]);let f=Gr(p),y=n.useRef({disabled:l,domRef:p,get textValue(){return f()}});$e(()=>{y.current.disabled=l},[y,l]),$e(()=>(o.actions.registerItem(r,y),()=>o.actions.unregisterItem(r)),[y,r]);let b=X(()=>{o.send({type:U.CloseMenu})}),d=X(I=>{if(l)return I.preventDefault();o.send({type:U.CloseMenu}),ta(o.state.buttonElement)}),N=X(()=>{if(l)return o.send({type:U.GoToItem,focus:Y.Nothing});o.send({type:U.GoToItem,focus:Y.Specific,id:r})}),S=Hr(),h=X(I=>S.update(I)),_=X(I=>{S.wasMoved(I)&&(l||x||o.send({type:U.GoToItem,focus:Y.Specific,id:r,trigger:rt.Pointer}))}),E=X(I=>{S.wasMoved(I)&&(l||x&&o.state.activationTrigger===rt.Pointer&&o.send({type:U.GoToItem,focus:Y.Nothing}))}),[R,w]=it(),[C,T]=Rt(),v=Se({active:x,focus:x,disabled:l,close:b}),u={id:r,ref:j,role:"menuitem",tabIndex:l===!0?void 0:-1,"aria-disabled":l===!0?!0:void 0,"aria-labelledby":R,"aria-describedby":C,disabled:void 0,onClick:d,onFocus:N,onPointerEnter:h,onMouseEnter:h,onPointerMove:_,onMouseMove:_,onPointerLeave:E,onMouseLeave:E},m=fe();return ae.createElement(w,null,ae.createElement(T,null,m({ourProps:u,theirProps:i,slot:v,defaultTag:fl,name:"Menu.Item"})))}let yl="div";function bl(t,s){let[a,r]=it(),l=t,i={ref:s,"aria-labelledby":a,role:"group"},o=fe();return ae.createElement(r,null,o({ourProps:i,theirProps:l,slot:{},defaultTag:yl,name:"Menu.Section"}))}let vl="header";function jl(t,s){let a=n.useId(),{id:r=`headlessui-menu-heading-${a}`,...l}=t,i=Cn();$e(()=>i.register(r),[r,i.register]);let o={id:r,ref:s,role:"presentation",...i.props};return fe()({ourProps:o,theirProps:l,slot:{},defaultTag:vl,name:"Menu.Heading"})}let wl="div";function Nl(t,s){let a=t,r={ref:s,role:"separator"};return fe()({ourProps:r,theirProps:a,slot:{},defaultTag:wl,name:"Menu.Separator"})}let kl=xe(dl),va=xe(ml),ja=xe(xl),Nt=xe(gl),Cl=xe(bl),Sl=xe(jl),wa=xe(Nl),_l=Object.assign(kl,{Button:va,Items:ja,Item:Nt,Section:Cl,Heading:Sl,Separator:wa});var Rl=(t=>(t[t.RegisterOption=0]="RegisterOption",t[t.UnregisterOption=1]="UnregisterOption",t))(Rl||{});let Il={0(t,s){let a=[...t.options,{id:s.id,element:s.element,propsRef:s.propsRef}];return{...t,options:ea(a,r=>r.element.current)}},1(t,s){let a=t.options.slice(),r=t.options.findIndex(l=>l.id===s.id);return r===-1?t:(a.splice(r,1),{...t,options:a})}},Ft=n.createContext(null);Ft.displayName="RadioGroupDataContext";function Lt(t){let s=n.useContext(Ft);if(s===null){let a=new Error(`<${t} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(a,Lt),a}return s}let At=n.createContext(null);At.displayName="RadioGroupActionsContext";function Ot(t){let s=n.useContext(At);if(s===null){let a=new Error(`<${t} /> is missing a parent component.`);throw Error.captureStackTrace&&Error.captureStackTrace(a,Ot),a}return s}function El(t,s){return Ct(s.type,Il,t,s)}let Ml="div";function Pl(t,s){let a=n.useId(),r=sa(),{id:l=`headlessui-radiogroup-${a}`,value:i,form:o,name:x,onChange:p,by:j,disabled:c=r||!1,defaultValue:f,tabIndex:y=0,...b}=t,d=Br(j),[N,S]=n.useReducer(El,{options:[]}),h=N.options,[_,E]=it(),[R,w]=Rt(),C=n.useRef(null),T=Ce(C,s),v=_n(f),[u,m]=Rn(i,p,v),I=n.useMemo(()=>h.find(D=>!D.propsRef.current.disabled),[h]),g=n.useMemo(()=>h.some(D=>d(D.propsRef.current.value,u)),[h,u]),$=X(D=>{var A;if(c||d(D,u))return!1;let O=(A=h.find(G=>d(G.propsRef.current.value,D)))==null?void 0:A.propsRef.current;return O!=null&&O.disabled?!1:(m==null||m(D),!0)}),k=X(D=>{if(!C.current)return;let A=h.filter(O=>O.propsRef.current.disabled===!1).map(O=>O.element.current);switch(D.key){case q.Enter:In(D.currentTarget);break;case q.ArrowLeft:case q.ArrowUp:if(D.preventDefault(),D.stopPropagation(),vs(A,Te.Previous|Te.WrapAround)===js.Success){let O=h.find(G=>Ze(G.element.current));O&&$(O.propsRef.current.value)}break;case q.ArrowRight:case q.ArrowDown:if(D.preventDefault(),D.stopPropagation(),vs(A,Te.Next|Te.WrapAround)===js.Success){let O=h.find(G=>Ze(G.element.current));O&&$(O.propsRef.current.value)}break;case q.Space:{D.preventDefault(),D.stopPropagation();let O=h.find(G=>Ze(G.element.current));O&&$(O.propsRef.current.value)}break}}),H=X(D=>(S({type:0,...D}),()=>S({type:1,id:D.id}))),te=n.useMemo(()=>({value:u,firstOption:I,containsCheckedOption:g,disabled:c,compare:d,tabIndex:y,...N}),[u,I,g,c,d,y,N]),W=n.useMemo(()=>({registerOption:H,change:$}),[H,$]),L={ref:T,id:l,role:"radiogroup","aria-labelledby":_,"aria-describedby":R,onKeyDown:k},V=Se({value:u}),ie=n.useCallback(()=>{if(v!==void 0)return $(v)},[$,v]),F=fe();return ae.createElement(w,{name:"RadioGroup.Description"},ae.createElement(E,{name:"RadioGroup.Label"},ae.createElement(At.Provider,{value:W},ae.createElement(Ft.Provider,{value:te},x!=null&&ae.createElement(En,{disabled:c,data:{[x]:u||"on"},overrides:{type:"radio",checked:u!=null},form:o,onReset:ie}),F({ourProps:L,theirProps:b,slot:V,defaultTag:Ml,name:"RadioGroup"})))))}let Tl="div";function $l(t,s){var a;let r=Lt("RadioGroup.Option"),l=Ot("RadioGroup.Option"),i=n.useId(),{id:o=`headlessui-radiogroup-option-${i}`,value:x,disabled:p=r.disabled||!1,autoFocus:j=!1,...c}=t,f=n.useRef(null),y=Ce(f,s),[b,d]=it(),[N,S]=Rt(),h=aa({value:x,disabled:p});$e(()=>l.registerOption({id:o,element:f,propsRef:h}),[o,l,f,h]);let _=X(g=>{var $;if(na(g.currentTarget))return g.preventDefault();l.change(x)&&(($=f.current)==null||$.focus())}),E=((a=r.firstOption)==null?void 0:a.id)===o,{isFocusVisible:R,focusProps:w}=St({autoFocus:j}),{isHovered:C,hoverProps:T}=_t({isDisabled:p}),v=r.compare(r.value,x),u=ot({ref:y,id:o,role:"radio","aria-checked":v?"true":"false","aria-labelledby":b,"aria-describedby":N,"aria-disabled":p?!0:void 0,tabIndex:p?-1:v||!r.containsCheckedOption&&E?r.tabIndex:-1,onClick:p?void 0:_,autoFocus:j},w,T),m=Se({checked:v,disabled:p,active:R,hover:C,focus:R,autofocus:j}),I=fe();return ae.createElement(S,{name:"RadioGroup.Description"},ae.createElement(d,{name:"RadioGroup.Label"},I({ourProps:u,theirProps:c,slot:m,defaultTag:Tl,name:"RadioGroup.Option"})))}let Dl="span";function Fl(t,s){var a;let r=Lt("Radio"),l=Ot("Radio"),i=n.useId(),o=Mn(),x=sa(),{id:p=o||`headlessui-radio-${i}`,value:j,disabled:c=r.disabled||x||!1,autoFocus:f=!1,...y}=t,b=n.useRef(null),d=Ce(b,s),N=Pn(),S=Tn(),h=aa({value:j,disabled:c});$e(()=>l.registerOption({id:p,element:b,propsRef:h}),[p,l,b,h]);let _=X(I=>{var g;if(na(I.currentTarget))return I.preventDefault();l.change(j)&&((g=b.current)==null||g.focus())}),{isFocusVisible:E,focusProps:R}=St({autoFocus:f}),{isHovered:w,hoverProps:C}=_t({isDisabled:c}),T=((a=r.firstOption)==null?void 0:a.id)===p,v=r.compare(r.value,j),u=ot({ref:d,id:p,role:"radio","aria-checked":v?"true":"false","aria-labelledby":N,"aria-describedby":S,"aria-disabled":c?!0:void 0,tabIndex:c?-1:v||!r.containsCheckedOption&&T?r.tabIndex:-1,autoFocus:f,onClick:c?void 0:_},R,C),m=Se({checked:v,disabled:c,hover:w,focus:E,autofocus:f});return fe()({ourProps:u,theirProps:y,slot:m,defaultTag:Dl,name:"Radio"})}let Ll=xe(Pl),Al=xe($l),pt=xe(Fl),Ol=qe,zl=ct,Hl=Object.assign(Ll,{Option:Al,Radio:pt,Label:Ol,Description:zl});/** * @license lucide-react v0.559.0 - ISC * * This source code is licensed under the ISC license. @@ -69,4 +69,4 @@ import{aX as rn,fB as gs,aZ as Zs,a_ as ln,aY as Ct,a$ as ea,r as n,b0 as on,b1 * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. - */const uo=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],mo=ne("user-plus",uo),Ve={sm:{radio:"h-4 w-4",dot:"h-1.5 w-1.5",text:"text-sm",descText:"text-xs",padding:"py-2 px-3",segmentPadding:"py-1.5 px-2.5"},md:{radio:"h-5 w-5",dot:"h-2 w-2",text:"text-sm",descText:"text-xs",padding:"py-3 px-4",segmentPadding:"py-2 px-3"},lg:{radio:"h-6 w-6",dot:"h-2.5 w-2.5",text:"text-base",descText:"text-sm",padding:"py-4 px-5",segmentPadding:"py-2.5 px-4"}};function ka({checked:t,size:s,disabled:a}){const r=Ve[s];return e.jsx("span",{className:P("relative flex shrink-0 items-center justify-center rounded-full border-2 transition-all duration-150",r.radio,t?"border-sys-blue bg-sys-blue":"border-edge-subtle bg-subtle",!t&&!a&&"group-hover:border-edge-strong",a&&"opacity-50"),children:t&&e.jsx("span",{className:P(r.dot,"rounded-full bg-white")})})}function po({option:t,size:s}){const a=Ve[s];return e.jsx(pt,{value:t.value,disabled:t.disabled,className:"group flex items-start gap-3 cursor-pointer ring-focus rounded-lg",children:({checked:r,disabled:l})=>e.jsxs(e.Fragment,{children:[e.jsx(ka,{checked:r,size:s,disabled:l}),e.jsxs("div",{className:"flex-1 min-w-0 select-none",children:[e.jsx(qe,{className:P(a.text,"font-medium cursor-pointer",l?"text-fg-muted":"text-fg-primary"),children:t.label}),t.description&&e.jsx(ct,{className:P(a.descText,"text-fg-muted mt-0.5"),children:t.description})]})]})})}function ho({option:t,size:s}){const a=Ve[s];return e.jsx(pt,{value:t.value,disabled:t.disabled,className:P("group relative flex cursor-pointer ring-focus","radius-inset border-2 transition-all duration-150",a.padding),children:({checked:r,disabled:l})=>e.jsxs(e.Fragment,{children:[e.jsx("span",{className:P("absolute inset-0 radius-inset transition-colors",r?"border-sys-blue bg-sys-blue/5":"border-edge-subtle bg-subtle",!r&&!l&&"group-hover:border-edge-strong group-hover:bg-elevated",l&&"opacity-50"),style:{borderWidth:"inherit"}}),e.jsxs("div",{className:"relative flex items-start gap-3 w-full",children:[t.icon&&e.jsx("span",{className:P("shrink-0",r?"text-sys-blue":"text-fg-muted"),children:t.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(qe,{className:P(a.text,"font-medium cursor-pointer",l?"text-fg-muted":r?"text-sys-blue":"text-fg-primary"),children:t.label}),t.description&&e.jsx(ct,{className:P(a.descText,"text-fg-muted mt-0.5"),children:t.description})]}),e.jsx(ka,{checked:r,size:s,disabled:l})]})]})})}function xo({option:t,size:s,isFirst:a,isLast:r}){const l=Ve[s];return e.jsx(pt,{value:t.value,disabled:t.disabled,className:P("group relative flex items-center justify-center cursor-pointer ring-focus","transition-all duration-150",l.segmentPadding,a&&"rounded-l-lg",r&&"rounded-r-lg"),children:({checked:i,disabled:o})=>e.jsxs(e.Fragment,{children:[e.jsx("span",{className:P("absolute inset-0 transition-colors",i?"bg-sys-blue":"bg-transparent",!i&&!o&&"group-hover:bg-subtle-fill",a&&"rounded-l-lg",r&&"rounded-r-lg",o&&"opacity-50")}),e.jsxs(qe,{className:P("relative z-10 font-medium cursor-pointer select-none",l.text,i?"text-white":o?"text-fg-muted":"text-fg-primary"),children:[t.icon&&e.jsx("span",{className:"mr-1.5 inline-flex",children:t.icon}),t.label]})]})})}function fo({label:t,description:s,options:a,value:r,onChange:l,size:i="md",variant:o="simple",orientation:x="vertical",name:p,disabled:j,className:c}){const f=Ve[i];return e.jsxs(Hl,{value:r,onChange:l,name:p,disabled:j,className:P("space-y-3",c),children:[t&&e.jsx(qe,{className:P(f.text,"font-medium text-fg-primary"),children:t}),s&&e.jsx(ct,{className:P(f.descText,"text-fg-muted -mt-1"),children:s}),o==="segmented"?e.jsx("div",{className:"inline-flex rounded-lg bg-subtle-fill-strong p-0.5",children:a.map((y,b)=>e.jsx(xo,{option:y,size:i,isFirst:b===0,isLast:b===a.length-1},y.value))}):e.jsx("div",{className:P(o==="card"&&x==="horizontal"&&"grid grid-cols-2 gap-3 sm:grid-cols-3",o==="card"&&x==="vertical"&&"space-y-3",o==="simple"&&x==="horizontal"&&"flex flex-wrap gap-4",o==="simple"&&x==="vertical"&&"space-y-2"),children:a.map(y=>o==="card"?e.jsx(ho,{option:y,size:i},y.value):e.jsx(po,{option:y,size:i},y.value))})]})}function Ne({children:t,className:s,onClick:a,disabled:r=!1,destructive:l=!1,icon:i,trailing:o,href:x,checked:p}){const j=e.jsxs(e.Fragment,{children:[(i||p!==void 0)&&e.jsx("span",{className:P("flex-shrink-0 w-4 h-4 flex items-center justify-center","text-fg-muted",l&&"text-sys-red","group-data-[focus]:text-white"),children:p!==void 0?p?e.jsx(be,{className:"h-4 w-4 text-sys-blue group-data-[focus]:text-white"}):null:i}),e.jsx("span",{className:"flex-1 truncate",children:t}),o&&e.jsx("span",{className:"flex-shrink-0 text-fg-muted group-data-[focus]:text-white/70 text-xs",children:o})]}),c=P("group flex items-center gap-2 w-full","px-3 py-2 radius-control cursor-default","text-sm text-left","transition-colors","focus:outline-none",r?"opacity-50 cursor-not-allowed":[l?["text-sys-red","data-[focus]:bg-sys-red data-[focus]:text-white"]:["text-fg-primary","data-[focus]:bg-sys-blue data-[focus]:text-white"]],s);return x&&!r?e.jsx(Nt,{children:e.jsx("a",{href:x,className:c,children:j})}):e.jsx(Nt,{disabled:r,children:e.jsx("button",{type:"button",onClick:a,disabled:r,className:c,children:j})})}function go({className:t}){return e.jsx(wa,{className:P("my-1 h-px bg-border-subtle",t)})}const yo=100,bo=101,vo=102,jo=103,wo=104,No=115,ko=116,Co=117,So=120,_o=125,Ro=128,Io=136;function Eo(t){const s=new $n(t),a=[];for(;s.getRemainingBytesCount()>=2;){const r=s.readUInt8(),l=s.readUInt8();if(r===0&&l===0)break;switch(l){case yo:a.push({channel:r,type:l,value:s.readUInt32BE()});break;case bo:a.push({channel:r,type:l,value:s.readInt16BE()});break;case vo:a.push({channel:r,type:l,value:s.readUInt8()});break;case jo:a.push({channel:r,type:l,value:s.readInt16BE()/10});break;case wo:a.push({channel:r,type:l,value:s.readUInt8()/2});break;case No:a.push({channel:r,type:l,value:s.readUInt16BE()/10});break;case ko:a.push({channel:r,type:l,value:s.readInt16BE()/100});break;case Co:a.push({channel:r,type:l,value:s.readInt16BE()/1e3});break;case So:a.push({channel:r,type:l,value:s.readUInt8()});break;case _o:a.push({channel:r,type:l,value:s.readUInt16BE()});break;case Ro:a.push({channel:r,type:l,value:s.readUInt16BE()});break;case Io:a.push({channel:r,type:l,value:{latitude:s.readInt24BE()/1e4,longitude:s.readInt24BE()/1e4,altitude:s.readInt24BE()/100}});break;default:return a}}return a}const Ca="pymc_companion_contacts_micro",Sa="pymc_companion_favorites",yt=56;function $s(){try{return localStorage.getItem(Ca)==="1"}catch{return!1}}function Mo(t){try{localStorage.setItem(Ca,t?"1":"0")}catch{}}function Po(){try{const t=localStorage.getItem(Sa);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function To(t){try{localStorage.setItem(Sa,JSON.stringify([...t]))}catch{}}function $o({name:t,pubkey:s,advType:a,size:r="md",signal:l}){const i=(a??0)&15,o=r==="sm"?"w-5 h-5":"w-6 h-6",x=r==="sm"?"size-3":"size-3.5";if(i===2){const f=l&&l.rssi!==0,y=f?`RSSI: ${l.rssi} dBm · SNR: ${l.snr.toFixed(1)} dB${l.rtt_ms!=null?` · RTT: ${l.rtt_ms} ms`:""}`:void 0;return e.jsx("div",{className:P(o,"relative rounded-full flex items-center justify-center flex-shrink-0 ring-[1.5px]",f?"ring-transparent":"ring-sys-blue"),title:y,children:f?e.jsx(Rr,{rssi:l.rssi,snr:l.snr,compact:!0,showValues:!1}):e.jsx(ze,{className:P(x,"text-sys-blue")})})}if(i===3)return e.jsx("div",{className:P(o,"relative rounded-full flex items-center justify-center flex-shrink-0 ring-[1.5px] ring-sys-pink"),children:e.jsx(dt,{className:P(x,"text-sys-pink")})});if(!t)return e.jsx("div",{className:P(o,"relative rounded-full bg-sys-blue/12 flex items-center justify-center flex-shrink-0"),children:e.jsx("span",{className:"text-sys-blue font-mono text-[10px] font-bold",children:s.slice(0,4)})});const{emoji:p}=Mt(t),j=Pt(t),c=Tt(t);return e.jsx("div",{className:P(o,"relative clay-avatar",p?"text-base":"text-white text-[11px] font-bold"),style:{"--avatar-color":j},children:p||c})}const Ds=[{key:"companion",label:"Companions",icon:ye,color:"text-sys-blue"},{key:"room",label:"Room Servers",icon:dt,color:"text-sys-pink"},{key:"repeater",label:"Repeaters",icon:ze,color:"text-sys-blue"}];function Do(t){const s=(t.adv_type??0)&15;return s===3?"room":s===2?"repeater":"companion"}const Fo=4e3,Lo=5e3,Ao=2e3,Oo=8,zo=n.forwardRef(function({contact:s,isActive:a,unread:r,lastMsg:l,isFav:i,microContent:o,onSelect:x,onShowDetails:p,onShareContact:j,onResetPath:c,onRemoveContact:f,onPingContact:y,repeaterNeighborHashes:b,repeaterSignal:d,toggleFavorite:N},S){const h=Dn(s.public_key),_=Fn(s.public_key),[E,R]=n.useState(!1),[w,C]=n.useState(!1),T=n.useRef(null),[v,u]=n.useState("idle"),m=n.useRef(!1),I=n.useRef(null),[g,$]=n.useState({w:0,h:0});n.useEffect(()=>{if(h)m.current=!0,u("idle");else if(m.current){m.current=!1;const F=se.getState().pingResults.get(s.public_key),D=F!=null&&F.rssi!==0;u(D?"success":"failed")}},[h,s.public_key]),n.useEffect(()=>{if(v==="idle")return;const D=setTimeout(()=>u("idle"),v==="success"?Lo:Ao);return()=>clearTimeout(D)},[v]);const k=(h||v!=="idle")&&!E;n.useEffect(()=>{if(!k)return;const F=I.current;if(!F)return;const D=()=>{const O=F.offsetWidth,G=F.offsetHeight;$(Q=>Q.w===O&&Q.h===G?Q:{w:O,h:G})};D();const A=new ResizeObserver(D);return A.observe(F),()=>A.disconnect()},[k]);const H=n.useCallback(()=>{R(!0),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>R(!1),Fo)},[]),te=n.useCallback(()=>{R(!1),T.current&&clearTimeout(T.current)},[]),W=n.useCallback(async()=>{f&&(T.current&&clearTimeout(T.current),C(!0),await f(s.public_key),C(!1),R(!1))},[f,s.public_key]),L=n.useMemo(()=>{const F=_&&_.rssi!==0,D=d&&d.rssi!==0;if(!F&&!D)return null;if(F&&!D)return{rssi:_.rssi,snr:_.snr_db,rtt_ms:_.rtt_ms};if(!F&&D)return{rssi:d.rssi,snr:d.snr};const A=d.advertCount,O=3,G=A+O;return{rssi:Math.round((d.rssi*A+_.rssi*O)/G),snr:(d.snr*A+_.snr_db*O)/G,rtt_ms:_.rtt_ms}},[_,d]),V=n.useCallback(F=>{I.current=F,typeof S=="function"?S(F):S&&(S.current=F)},[S]),ie=E?"":v==="success"?"bg-sys-green/5":v==="failed"?"bg-sys-red/5":h?"bg-sys-blue/5":a?"bg-sys-blue":"hover:bg-elevated";return e.jsxs(ue.div,{ref:V,layout:"position",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,className:P("group relative w-full flex items-center gap-2.5 px-2.5 py-[3px] radius-inner overflow-hidden","transition-[background-color,box-shadow] duration-150",ie),children:[e.jsx(ge,{children:k&&g.w>0&&(v!=="idle"?e.jsx(ue.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{opacity:{duration:.15}},className:P("absolute inset-0 radius-inner ring-2 ring-inset pointer-events-none z-[2]",v==="success"?"ring-sys-green":"ring-sys-red")},`ping-${v}`):e.jsx(Ln,{borderRadius:Oo,width:g.w,height:g.h,color:"blue"},"ping-crawl"))}),e.jsxs("div",{className:"grid flex-1 min-w-0 [&>*]:col-start-1 [&>*]:row-start-1",children:[e.jsxs("div",{className:P("flex items-center gap-2.5",E&&!o&&"invisible pointer-events-none"),children:[e.jsxs("button",{onClick:()=>x({type:"contact",id:s.public_key}),className:"flex items-center gap-2.5 flex-1 min-w-0 text-left",children:[e.jsxs("div",{className:"relative",children:[e.jsx($o,{name:s.name,pubkey:s.public_key,advType:s.adv_type,signal:L}),r>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 h-2.5 w-2.5 rounded-full bg-sys-red ring-2 ring-body"})]}),!o&&e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("span",{className:P("text-sm truncate flex-1",a?"text-white font-medium":i?"text-sys-amber font-bold":"text-fg-primary font-medium"),children:s.name||s.public_key.slice(0,12)+"…"})}),v==="success"&&_?e.jsxs("div",{className:"text-[11px] text-sys-green font-medium truncate tabular-nums",children:[_.rssi," dBm · ",_.snr_db.toFixed(1)," dB",_.rtt_ms!=null&&` · ${_.rtt_ms} ms`]}):v==="failed"?e.jsx("div",{className:"text-[11px] text-sys-red font-medium truncate",children:"No response"}):l?e.jsx("div",{className:P("text-[11px] truncate",a?"text-white/70":"text-fg-muted"),children:l.text}):null]})]}),!o&&e.jsx("div",{className:"relative flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center",children:e.jsx(_l,{as:"div",className:"absolute inset-0",children:({open:F})=>e.jsxs(e.Fragment,{children:[e.jsx(va,{className:P("absolute inset-0 flex items-center justify-center rounded transition-[opacity,background-color] duration-100","focus:outline-none",a?"hover:bg-white/15":"hover:bg-subtle-fill",F?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":"Contact options",children:e.jsx(Wl,{className:P("h-3.5 w-3.5 transition-colors",a?"text-white/60 hover:text-white":"text-fg-muted hover:text-sys-blue")})}),e.jsxs(ja,{anchor:"right start",transition:!0,className:P("min-w-[10rem] max-w-[20rem]","radius-inset p-1 ml-1","surface-elevated","focus:outline-none z-50","transition-[opacity,transform]","data-[closed]:opacity-0 data-[closed]:scale-[0.98] data-[closed]:translate-x-[-4px]","data-[enter]:duration-150 data-[leave]:duration-100","data-[enter]:ease-out data-[leave]:ease-in"),children:[e.jsx(Ne,{icon:e.jsx(nt,{className:"w-4 h-4"}),onClick:()=>{p==null||p({type:"contact",id:s.public_key})},children:"Details"}),j&&e.jsx(Ne,{icon:e.jsx(Ur,{className:"w-4 h-4"}),onClick:()=>j(s.public_key),children:"Share"}),e.jsx(Ne,{icon:e.jsx(Ge,{className:"w-4 h-4"}),onClick:()=>x({type:"contact",id:s.public_key}),children:"Set Path"}),c&&e.jsx(Ne,{icon:e.jsx(da,{className:"w-4 h-4"}),onClick:()=>c(s.public_key),children:"Reset Path"}),y&&e.jsx(Ne,{icon:e.jsx(ql,{className:"w-4 h-4"}),onClick:()=>y(s.public_key),disabled:!(b!=null&&b.has(s.public_key)),children:"Ping"}),f&&e.jsx(Ne,{icon:e.jsx(Ke,{className:"w-4 h-4"}),destructive:!0,onClick:H,children:"Remove Contact"}),e.jsx(go,{}),e.jsx(Ne,{icon:e.jsx(io,{className:P("w-4 h-4 group-data-[focus]:text-white group-data-[focus]:fill-white",i?"text-sys-amber fill-sys-amber":"text-fg-muted")}),onClick:()=>N(s.public_key),children:i?"Unfavorite":"Favorite"})]})]})})})]}),!o&&e.jsx("div",{className:P("flex items-center gap-1.5 self-center",!E&&"invisible pointer-events-none"),children:w?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("div",{className:"w-3.5 h-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:te,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-zinc-500/80 hover:bg-zinc-500 depth-stroke-raised transition-colors",children:e.jsx("span",{className:"text-[11px] font-semibold text-white",children:"Cancel"})}),e.jsx("button",{onClick:W,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-sys-red/80 hover:bg-sys-red depth-stroke-raised transition-colors",children:e.jsx(Ke,{className:"w-4 h-4 text-white"})})]})})]})]},s.public_key)}),Fs={excellent:4,good:3,fair:2,weak:1,poor:0};function Ls(t,s,a){const r=s==null?void 0:s.get(t),l=r&&r.rssi!==0,i=a==null?void 0:a.get(t),o=i&&typeof i.rssi=="number"&&i.rssi!==0;if(!l&&!o)return null;if(o&&!l)return i.rssi;if(!o&&l)return r.rssi;const x=r.advertCount,p=3;return Math.round((r.rssi*x+i.rssi*p)/(x+p))}function Ho(t,s,a,r,l){return[...t].sort((i,o)=>{const x=s.has(i.public_key)?0:1,p=s.has(o.public_key)?0:1;if(x!==p)return x-p;if(a){const j=a.get(i.public_key),c=j&&j.length>0?j[j.length-1].timestamp:0,f=a.get(o.public_key),y=f&&f.length>0?f[f.length-1].timestamp:0;if(c!==y)return y-c}if(r){const j=Ls(i.public_key,r,l),c=Ls(o.public_key,r,l);if(j!=null&&c==null)return-1;if(j==null&&c!=null)return 1;if(j!=null&&c!=null){const f=Fs[_s(j)]??0,y=Fs[_s(c)]??0;if(f!==y)return y-f}}return(i.name||"").localeCompare(o.name||"")})}const Bo=n.memo(n.forwardRef(function({contacts:s,selectedConversation:a,unreadMap:r,messages:l,onSelect:i,onShowDetails:o,onShareContact:x,onResetPath:p,onRemoveContact:j,onPingContact:c,repeaterNeighborHashes:f,repeaterSignalMap:y,isLoading:b,splitPercent:d=50,onMicroChange:N,className:S},h){const[_,E]=n.useState($s),[R,w]=n.useState($s),[C,T]=n.useState(""),[v,u]=n.useState(!1),[m,I]=n.useState(Po),g=n.useRef(null),$=n.useRef(null),k=n.useCallback(D=>{$.current=D,typeof h=="function"?h(D):h&&(h.current=D)},[h]),H=n.useCallback(()=>{E(D=>{const A=!D;Mo(A);const O=$.current;if(A&&w(!0),O){let G=0;const Q=O.parentElement;if(A)G=(Q==null?void 0:Q.offsetWidth)??O.offsetWidth;else if(Q){const We=Q.style.width;Q.style.width="var(--companion-side)",G=Q.offsetWidth,Q.style.width=We}const ht=A?yt:Math.round(d/100*G);tt(O,{width:`${ht}px`},{...de.layoutResize,onComplete(){O.style.width=A?`${yt}px`:`${d}%`,A||w(!1)}})}return N==null||N(A),A})},[d,N]),te=n.useCallback(D=>{I(A=>{const O=new Set(A);return O.has(D)?O.delete(D):O.add(D),To(O),O})},[]),W=v||C.length>0,L=n.useMemo(()=>{const D=new Set,A=s.filter(G=>D.has(G.public_key)?!1:(D.add(G.public_key),!0));if(!C.trim())return A;const O=C.toLowerCase();return A.filter(G=>{var Q;return((Q=G.name)==null?void 0:Q.toLowerCase().includes(O))||G.public_key.toLowerCase().includes(O)})},[s,C]),V=se(D=>D.pingResults),ie=n.useMemo(()=>{const D=new Map;for(const A of Ds)D.set(A.key,[]);for(const A of L)D.get(Do(A)).push(A);return Ds.map(A=>({...A,items:Ho(D.get(A.key),m,l,A.key==="repeater"?y:void 0,A.key==="repeater"?V:void 0)})).filter(A=>A.items.length>0)},[L,m,l,y,V]),F=(a==null?void 0:a.type)==="contact"?a.id:null;return e.jsxs("div",{ref:k,className:P("flex-shrink-0 overflow-hidden flex flex-col h-full",S),style:{width:_?yt:`${d}%`},children:[e.jsx("div",{className:P("flex items-center border-b border-edge-subtle flex-shrink-0",R?"justify-center p-2":"gap-2 px-3 py-2"),children:R?e.jsx("button",{onClick:H,className:"p-1 hover:bg-subtle-fill rounded transition-colors",title:"Expand contacts",children:e.jsx(to,{className:"w-3.5 h-3.5 text-fg-muted"})}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide flex-shrink-0",children:"Contacts"}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto flex-shrink-0",children:[e.jsx("button",{onClick:()=>{W?(T(""),u(!1)):(u(!0),setTimeout(()=>{var D;return(D=g.current)==null?void 0:D.focus()},50))},className:P("p-1 rounded transition-colors flex-shrink-0",W?"bg-sys-blue/10 text-sys-blue":"hover:bg-subtle-fill text-fg-muted"),title:W?"Close search":"Search contacts",children:e.jsx(Rs,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:H,className:"p-1 hover:bg-subtle-fill rounded transition-colors flex-shrink-0",title:"Collapse contacts",children:e.jsx(Zl,{className:"w-3.5 h-3.5 text-fg-muted"})})]})]})}),!R&&W&&e.jsxs("div",{className:"relative px-2.5 py-2 border-b border-edge-subtle/50 flex-shrink-0",children:[e.jsx(Rs,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-muted pointer-events-none"}),e.jsx("input",{ref:g,type:"text",value:C,onChange:D=>T(D.target.value),onFocus:()=>u(!0),onBlur:()=>u(!1),placeholder:"Search contacts…",className:"w-full pl-8 pr-8 py-1.5 text-sm radius-inner bg-input-bg border border-input-border text-fg-primary placeholder:text-fg-muted/50 ring-focus-inset hover:border-edge-strong transition-colors",autoFocus:!0}),e.jsx("button",{onClick:()=>{T(""),u(!1)},className:"absolute right-5 top-1/2 -translate-y-1/2 p-0.5 hover:bg-subtle-fill rounded",children:e.jsx(ut,{className:"w-3.5 h-3.5 text-fg-muted"})})]}),b&&e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("div",{className:"w-5 h-5 animate-spin rounded-full border-2 border-sys-blue border-t-transparent"})}),!b&&e.jsxs("div",{className:P("flex-1 overflow-y-auto min-h-0",R?"px-0":"px-1.5"),style:{contain:"layout style paint"},children:[ie.map(D=>{const A=D.icon;return e.jsxs(_e,{defaultOpen:!0,className:"mb-1",children:[e.jsxs(Re,{className:P("px-2 py-1 flex items-center gap-1.5 w-full","text-left radius-inner hover:bg-subtle-fill-strong transition-colors"),children:[e.jsx(A,{className:P("w-3.5 h-3.5",D.color)}),!R&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:D.label}),e.jsx("span",{className:"type-data-xs text-fg-muted/50 ml-auto",children:D.items.length})]})]}),e.jsx(Ie,{children:e.jsx(ge,{initial:!1,mode:"popLayout",children:D.items.map(O=>e.jsx(zo,{contact:O,isActive:F===O.public_key,unread:r.get(O.public_key)??0,lastMsg:(()=>{const G=l.get(O.public_key);return G&&G.length>0?G[G.length-1]:void 0})(),isFav:m.has(O.public_key),microContent:R,onSelect:i,onShowDetails:o,onShareContact:x,onResetPath:p,onRemoveContact:j,onPingContact:c,repeaterNeighborHashes:f,repeaterSignal:y==null?void 0:y.get(O.public_key),toggleFavorite:te},O.public_key))})})]},D.key)}),L.length===0&&e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-sm text-fg-muted",children:C?"No matches":"No contacts yet"})})]})]})}));function Go({open:t,onClose:s}){const a=se(u=>u.discoverImportableChannels),r=se(u=>u.getEmptyChannelSlots),l=se(u=>u.importChannel),i=se(u=>u.refreshChannels),[o,x]=n.useState("discover"),[p,j]=n.useState([]),[c,f]=n.useState([]),[y,b]=n.useState(null),d=n.useRef(!1);n.useEffect(()=>{if(!t)return;x("discover"),j([]),f([]),b(null),d.current=!1;let u=!1;return(async()=>{try{const[m,I]=await Promise.all([a(),r()]);if(u)return;if(f(I),m.length===0){b("No channels found in repeater history. Decoded messages may still be loading."),x("select");return}I.length===0&&b("No empty channel slots on device. Delete a channel first to make room."),j(m.map(g=>({name:g.name,alreadyOnDevice:g.alreadyOnDevice,selected:!g.alreadyOnDevice,status:"pending"}))),x("select")}catch(m){u||(b(m instanceof Error?m.message:"Discovery failed"),x("select"))}})(),()=>{u=!0}},[t,a,r]);const N=n.useCallback(u=>{j(m=>m.map(I=>I.name===u&&!I.alreadyOnDevice?{...I,selected:!I.selected}:I))},[]),S=n.useCallback(()=>{j(u=>u.map(m=>m.alreadyOnDevice?m:{...m,selected:!0}))},[]),h=n.useCallback(()=>{j(u=>u.map(m=>m.alreadyOnDevice?m:{...m,selected:!1}))},[]),_=n.useMemo(()=>p.filter(u=>!u.alreadyOnDevice).length,[p]),E=n.useMemo(()=>p.filter(u=>u.selected&&!u.alreadyOnDevice).length,[p]),R=n.useMemo(()=>p.filter(u=>u.status==="done").length,[p]),w=n.useMemo(()=>p.filter(u=>u.status==="failed").length,[p]),C=n.useCallback(async()=>{x("import"),d.current=!1;const u=p.filter(I=>I.selected&&!I.alreadyOnDevice),m=[...c];for(const I of u){if(d.current)break;const g=m.shift();if(g===void 0){j(k=>k.map(H=>H.name===I.name&&H.status==="pending"?{...H,status:"failed"}:H));continue}j(k=>k.map(H=>H.name===I.name?{...H,status:"sending"}:H)),await new Promise(k=>setTimeout(k,150));const $=await l(I.name,g);j(k=>k.map(H=>H.name===I.name?{...H,status:$?"done":"failed"}:H)),$||m.unshift(g),d.current||await new Promise(k=>setTimeout(k,300))}await i(),x("complete")},[p,c,l,i]),T=n.useCallback(()=>{d.current=!0},[]),v=u=>{switch(u){case"pending":return e.jsx(Na,{className:"w-3.5 h-3.5 text-fg-muted"});case"sending":return e.jsx(oe,{className:"w-3.5 h-3.5 text-sys-blue animate-spin"});case"done":return e.jsx(be,{className:"w-3.5 h-3.5 text-sys-green"});case"failed":return e.jsx(ut,{className:"w-3.5 h-3.5 text-sys-red"})}};return e.jsxs(je,{open:t,onClose:o==="import"?()=>{}:s,size:"sm",children:[e.jsx(Ee,{icon:e.jsx(He,{className:"w-5 h-5"}),title:"Import Channels",onClose:o==="import"?void 0:s}),e.jsxs(we,{className:"!py-3 !px-0",children:[o==="discover"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-8 px-6",children:[e.jsx(oe,{className:"w-6 h-6 text-sys-blue animate-spin"}),e.jsx("p",{className:"text-sm text-fg-secondary",children:"Scanning repeater history…"}),e.jsx("p",{className:"text-[11px] text-fg-muted",children:"Waiting for decoded messages"})]}),o==="select"&&e.jsxs(e.Fragment,{children:[y&&e.jsxs("div",{className:"flex items-start gap-2 mx-4 mb-3 p-2.5 radius-inner bg-sys-amber/8 border border-sys-amber/20",children:[e.jsx(Be,{className:"w-3.5 h-3.5 text-sys-amber flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-fg-secondary",children:y})]}),p.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 pb-2 border-b border-edge-subtle",children:[e.jsxs("span",{className:"text-[11px] text-fg-muted",children:[_," discoverable · ",c.length," slot",c.length!==1?"s":""," free"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:S,className:"text-[11px] text-sys-blue hover:underline",children:"All"}),e.jsx("span",{className:"text-fg-muted/40",children:"·"}),e.jsx("button",{onClick:h,className:"text-[11px] text-sys-blue hover:underline",children:"None"})]})]}),e.jsx("div",{className:"max-h-[320px] overflow-y-auto",children:p.map(u=>e.jsxs("button",{onClick:()=>N(u.name),disabled:u.alreadyOnDevice,className:P("w-full flex items-center gap-3 px-4 py-2 transition-colors",u.alreadyOnDevice?"opacity-40 cursor-default":"hover:bg-subtle-fill"),children:[e.jsx("div",{className:P("w-4 h-4 rounded border flex items-center justify-center flex-shrink-0 transition-colors",u.alreadyOnDevice?"border-fg-muted/30 bg-fg-muted/10":u.selected?"border-sys-blue bg-sys-blue":"border-edge-subtle"),children:(u.selected||u.alreadyOnDevice)&&e.jsx(be,{className:"w-3 h-3 text-white"})}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Fe,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"text-sm text-fg-primary truncate",children:u.name})]}),u.alreadyOnDevice&&e.jsx("span",{className:"text-[10px] text-fg-muted bg-subtle-fill px-1.5 py-0.5 rounded flex-shrink-0",children:"on device"})]},u.name))})]})]}),(o==="import"||o==="complete")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 pb-2 border-b border-edge-subtle",children:[e.jsx("span",{className:"text-[11px] text-fg-muted",children:o==="import"?"Importing channels…":"Import complete"}),e.jsxs("span",{className:"text-[11px] tabular-nums text-fg-secondary",children:[R+w," / ",p.filter(u=>u.selected&&!u.alreadyOnDevice).length]})]}),e.jsx("div",{className:"max-h-[320px] overflow-y-auto",children:p.filter(u=>u.selected&&!u.alreadyOnDevice).map(u=>e.jsxs("div",{className:P("flex items-center gap-3 px-4 py-2",u.status==="sending"&&"bg-sys-blue/5",u.status==="done"&&"bg-sys-green/5",u.status==="failed"&&"bg-sys-red/5"),children:[e.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:v(u.status)}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Fe,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:P("text-sm truncate",u.status==="done"?"text-fg-primary":"text-fg-secondary"),children:u.name})]}),e.jsx("span",{className:P("text-[10px] flex-shrink-0",u.status==="sending"&&"text-sys-blue",u.status==="done"&&"text-sys-green",u.status==="failed"&&"text-sys-red",u.status==="pending"&&"text-fg-muted"),children:u.status==="sending"?"sending…":u.status==="done"?"added":u.status==="failed"?"failed":"waiting"})]},u.name))})]})]}),e.jsxs(Me,{children:[o==="select"&&e.jsxs(e.Fragment,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Cancel"}),e.jsxs(B,{color:"primary",onClick:C,disabled:E===0||c.length===0,children:[e.jsx(He,{className:"w-4 h-4"}),"Import ",E," ",E===1?"Channel":"Channels"]})]}),o==="import"&&e.jsx(B,{plain:!0,onClick:T,children:"Stop"}),o==="complete"&&e.jsxs(e.Fragment,{children:[w>0&&e.jsxs("span",{className:"text-xs text-sys-red flex items-center gap-1 mr-auto",children:[e.jsx(Be,{className:"w-3.5 h-3.5"}),w," failed"]}),e.jsxs(B,{color:"primary",onClick:s,children:[e.jsx(Vr,{className:"w-4 h-4"}),"Done — ",R," imported"]})]})]})]})}const Ko=4e3;function Uo(t){const s=t.frequency_hz/1e3,a=t.bandwidth_hz/1e3;return`${s} · SF${t.spreading_factor} · ${a}k`}const qo=n.forwardRef(function({channel:s,isActive:a,unread:r,lastMsg:l,isLoadingMessages:i,selfInfo:o,onSelect:x,onDeleteChannel:p},j){const[c,f]=n.useState(!1),[y,b]=n.useState(!1),d=n.useRef(null),N=n.useCallback(()=>{f(!0),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>f(!1),Ko)},[]),S=n.useCallback(()=>{f(!1),d.current&&clearTimeout(d.current)},[]),h=n.useCallback(async()=>{p&&(d.current&&clearTimeout(d.current),b(!0),await p(s.index),b(!1),f(!1))},[p,s.index]),_=s.name.toLowerCase()==="public",E=p&&!_;return e.jsx(ue.div,{ref:j,layout:"position",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,className:P("group w-full flex items-center gap-2.5 px-2.5 py-1 radius-inner","transition-[background-color] duration-150",c?"":a?"bg-sys-blue":"hover:bg-subtle-fill-strong"),children:e.jsxs("div",{className:"grid flex-1 min-w-0 [&>*]:col-start-1 [&>*]:row-start-1",children:[e.jsxs("div",{className:P("flex items-center gap-2.5 min-w-0",c&&"invisible pointer-events-none"),children:[e.jsx("button",{onClick:()=>x({type:"channel",id:String(s.index)}),className:"flex items-center gap-2.5 flex-1 min-w-0 text-left",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:P("text-sm flex-shrink-0",a?"text-white font-semibold":l?"text-fg-primary font-semibold":"text-fg-secondary font-normal"),children:s.name}),_&&o&&e.jsx("span",{className:P("text-[9px] font-medium px-1.5 py-px rounded-full whitespace-nowrap truncate",a?"text-white/80 bg-white/15":"text-fg-muted/70 bg-subtle-fill"),children:Uo(o)})]}),l&&e.jsx("div",{className:P("text-[11px] truncate pl-2",a?"text-white/70":"text-fg-muted"),children:l.text})]})}),e.jsx("div",{className:"flex items-center flex-shrink-0",children:i?e.jsx("span",{className:"h-1.5 w-6 rounded-full bg-fg-muted/20 animate-pulse"}):E?e.jsxs("div",{className:"relative w-[18px] h-[18px] flex items-center justify-center",children:[r>0&&e.jsx("span",{className:"absolute inset-0 flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-sys-red text-white text-[10px] font-bold leading-none group-hover:invisible transition-[visibility] duration-100",children:r>99?"99+":r}),e.jsx("button",{onClick:N,className:P("absolute inset-0 flex items-center justify-center rounded opacity-0 group-hover:opacity-100 transition-[opacity,background-color] duration-100",a?"hover:bg-white/15":"hover:bg-subtle-fill"),title:"Remove channel",children:e.jsx(Ke,{className:P("w-3 h-3 transition-colors",a?"text-white/60 hover:text-white":"text-fg-muted hover:text-sys-red")})})]}):r>0?e.jsx("span",{className:"min-w-[18px] h-[18px] px-1 rounded-full bg-sys-red text-white text-[10px] font-bold flex items-center justify-center leading-none",children:r>99?"99+":r}):null})]}),e.jsx("div",{className:P("flex items-center gap-1.5 self-center",!c&&"invisible pointer-events-none"),children:y?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("div",{className:"w-3.5 h-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:S,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-zinc-500/80 hover:bg-zinc-500 depth-stroke-raised transition-colors",children:e.jsx("span",{className:"text-[11px] font-semibold text-white",children:"Cancel"})}),e.jsx("button",{onClick:h,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-sys-red/80 hover:bg-sys-red depth-stroke-raised transition-colors",children:e.jsx(Ke,{className:"w-4 h-4 text-white"})})]})})]})})}),Vo=n.memo(n.forwardRef(function({channels:s,selectedConversation:a,unreadMap:r,messages:l,onSelect:i,onAddChannel:o,onDeleteChannel:x,className:p},j){const c=An(),f=mt(),[y,b]=n.useState(!1),d=n.useMemo(()=>{const S=new Set,h=s.filter(_=>S.has(_.index)?!1:(S.add(_.index),!0));return h.sort((_,E)=>{const R=_.name.toLowerCase()==="public",w=E.name.toLowerCase()==="public";if(R&&!w)return-1;if(!R&&w)return 1;const C=l.get(`ch:${_.index}`),T=C&&C.length>0?C[C.length-1].timestamp:0,v=l.get(`ch:${E.index}`),u=v&&v.length>0?v[v.length-1].timestamp:0;return T!==u?u-T:_.name.localeCompare(E.name)}),h},[s,l]),N=(a==null?void 0:a.type)==="channel"?a.id:null;return e.jsxs("div",{ref:j,className:P("flex-1 min-w-0 overflow-hidden flex flex-col h-full",p),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-edge-subtle flex-shrink-0 overflow-hidden whitespace-nowrap",children:[e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide flex-shrink-0",children:"Channels"}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto flex-shrink-0",children:[e.jsx("button",{onClick:()=>b(!0),className:"p-1 rounded hover:bg-subtle-fill transition-colors flex-shrink-0",title:"Import channels from repeater history",children:e.jsx(He,{className:"w-3.5 h-3.5 text-fg-muted"})}),o&&e.jsx("button",{onClick:o,className:"p-1 rounded hover:bg-subtle-fill transition-colors flex-shrink-0",title:"Add channel",children:e.jsx(Ue,{className:"w-3.5 h-3.5 text-fg-muted"})})]})]}),e.jsx(Go,{open:y,onClose:()=>b(!1)}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 px-1.5 py-1",style:{contain:"layout style paint"},children:d.length===0?e.jsxs("div",{className:"px-1.5 py-4 space-y-2",children:[e.jsx("p",{className:"text-sm text-fg-muted",children:"No channels"}),o&&e.jsxs("button",{onClick:o,className:"inline-flex items-center gap-1.5 px-2 py-1.5 text-xs font-medium text-sys-blue hover:bg-sys-blue/8 rounded transition-colors",children:[e.jsx(Ue,{className:"w-3.5 h-3.5"}),"Add Channel"]})]}):e.jsx(ge,{initial:!1,mode:"popLayout",children:d.map(S=>e.jsx(qo,{channel:S,isActive:N===String(S.index),unread:r.get(`ch:${S.index}`)??0,lastMsg:(()=>{const h=l.get(`ch:${S.index}`);return h&&h.length>0?h[h.length-1]:void 0})(),isLoadingMessages:c,selfInfo:f,onSelect:i,onDeleteChannel:x},S.index))})})]})}));function Wo(t,s){const a=new Map;for(const[r,l]of t){const i=l.decoded;if(!(i!=null&&i.decrypted)||i.senderName!==s)continue;const o=i.timestamp??l.timestamp,x=Math.floor(o/30),p=`${i.text}:${x}`;a.has(p)||a.set(p,r)}return a}function Qo(t){const s=mt(),a=On(),r=zn(),l=s==null?void 0:s.node_name,i=n.useMemo(()=>l?Wo(a,l):new Map,[a,l]);return n.useMemo(()=>{const o=new Map;if(!l||i.size===0)return o;const x=new Map;for(const c of t){if(!c.is_outgoing||!c.is_channel)continue;const f=Math.floor(c.timestamp/30);let y=!1;for(const b of[f-1,f,f+1]){const d=i.get(`${c.text}:${b}`);if(d){const N=x.get(d)??[];N.push(c.id),x.set(d,N),y=!0;break}}}if(x.size===0)return o;const p=new Set(x.keys()),j=new Map;for(const c of r)p.has(c.packet_hash)&&j.set(c.packet_hash,(j.get(c.packet_hash)??0)+1);for(const[c,f]of x){const y=j.get(c)??0,b=Math.max(0,y-1);for(const d of f)o.set(d,b)}return o},[t,l,i,r])}const Yo=n.lazy(()=>ra(()=>import("./CompanionPathMap-D1qZh3TG.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(t=>({default:t.CompanionPathMap}))),Xo=n.lazy(()=>ra(()=>import("./CompanionEchoMap-yp80-T_o.js"),__vite__mapDeps([8,1,2,3,5,6,7])).then(t=>({default:t.CompanionEchoMap}))),As=e.jsx("div",{className:"rounded-lg bg-elevated flex items-center justify-center",style:{aspectRatio:"16 / 10"},children:e.jsx("div",{className:"w-4 h-4 border-2 border-fg-muted/30 border-t-fg-muted rounded-full animate-spin"})});function Jo(t){const s=new Date(t*1e3),r=Math.floor((new Date().getTime()-s.getTime())/864e5);return r===0?"Today":r===1?"Yesterday":s.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Zo(t){const s=new Date(t*1e3);return`${s.getFullYear()}-${s.getMonth()}-${s.getDate()}`}function ei(t){const s=new Map;for(const a of t)a.name&&s.set(a.public_key,a.name);return s}function ti(t){const s=new Map;for(const a of t)s.set(a.public_key,a);return s}function si(t){if(!t)return[];const s=[];for(let a=0;ar.public_key.startsWith(t));return(a==null?void 0:a.name)||null}function ni(t,s){return t.is_outgoing?"You":t.sender_name?t.sender_name:s.get(t.sender_key)??t.sender_key.slice(0,8)}const ri=n.memo(function({msg:s,contact:a,contacts:r,selfInfo:l,echoCount:i,channelName:o,children:x}){const[p,j]=n.useState(!1),[c,f]=n.useState(!1),[y,b]=n.useState(0),d=n.useRef(null),N=s.path_len,S=!s.is_outgoing,h=S&&N!=null,_=s.is_outgoing&&s.is_channel&&(i??0)>0,E=(o==null?void 0:o.toLowerCase().includes("wardrive"))??!1,R=n.useMemo(()=>E&&S?Yr(s.text):null,[E,S,s.text]),w=h||_,C=n.useMemo(()=>{const $=[];if(s.path_hops&&s.path_hops.length>0)$.push({hops:s.path_hops,snr:s.path_snr,rssi:s.path_rssi});else if(S&&(a!=null&&a.out_path)){const k=si(a.out_path);k.length>0&&$.push({hops:k})}if(s.alternate_paths)for(const k of s.alternate_paths)$.push(k);return $},[s.path_hops,s.path_snr,s.path_rssi,s.alternate_paths,S,a==null?void 0:a.out_path]),T=y1,m=(v==null?void 0:v.snr)??s.msg_snr,I=()=>{f(!0),j($=>!$)},g=n.useCallback($=>{var k;$.propertyName==="grid-template-rows"&&(p?(k=d.current)==null||k.scrollIntoView({block:"nearest",behavior:"smooth"}):f(!1))},[p]);return e.jsxs("div",{ref:d,className:P("rounded-xl px-2 py-1 -mx-2 transition-colors duration-150",w&&"hover:bg-subtle-fill cursor-pointer"),onClick:()=>w&&I(),children:[x,w&&e.jsx("div",{className:"grid transition-[grid-template-rows] duration-300 ease-[cubic-bezier(0.83,0,0.17,1)]",style:{gridTemplateRows:p?"1fr":"0fr"},onTransitionEnd:g,children:e.jsxs("div",{className:"overflow-hidden",children:[c&&h&&e.jsxs("div",{className:"mt-1.5 ml-13 space-y-1",children:[u&&e.jsx("div",{className:"flex items-center gap-1 flex-wrap",onClick:$=>$.stopPropagation(),children:C.map(($,k)=>e.jsxs("button",{onClick:()=>b(k),className:P("flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] transition-colors",k===T?"bg-sys-blue/15 text-sys-blue font-semibold":"bg-subtle-fill text-fg-muted hover:text-fg-secondary"),children:[e.jsx(Ge,{className:"w-2.5 h-2.5"}),$.hops.length||N,$.snr!=null&&e.jsxs("span",{className:"ml-0.5 opacity-70",children:[$.snr>0?"+":"",$.snr.toFixed(1)]})]},k))}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx(Ge,{className:"w-3 h-3 text-fg-muted flex-shrink-0"}),N===0&&!v?e.jsx("span",{className:"text-[10px] text-fg-muted font-medium",children:"Direct"}):v&&v.hops.length>0?v.hops.map(($,k)=>{const H=ai($,r);return e.jsxs("span",{className:"contents",children:[k>0&&e.jsx(Jr,{className:"w-2.5 h-2.5 text-fg-muted/50 flex-shrink-0"}),e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded bg-subtle-fill text-[10px]",children:[e.jsx("span",{className:"font-mono text-fg-primary",children:$}),H&&e.jsxs("span",{className:"text-fg-muted",children:["(",H,")"]})]})]},k)}):e.jsxs("span",{className:"text-[10px] text-fg-muted font-medium",children:[N," hop",N>1?"s":""]}),m!=null&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] text-fg-muted ml-0.5",children:[e.jsx(Ir,{className:"w-2.5 h-2.5"}),m>0?"+":"",m.toFixed(1),"dB"]}),(v==null?void 0:v.rssi)!=null&&e.jsxs("span",{className:"text-[10px] text-fg-muted",children:[v.rssi,"dBm"]})]}),v&&v.hops.length>=1&&e.jsx(n.Suspense,{fallback:As,children:e.jsx(Yo,{hops:v.hops,contacts:r,selfInfo:l,snr:m,wardriveCoords:R??void 0,wardriveSenderName:s.sender_name})})]}),c&&_&&e.jsx("div",{className:"mt-1.5",children:e.jsx(n.Suspense,{fallback:As,children:e.jsx(Xo,{text:s.text,timestamp:s.timestamp,contacts:r})})})]})})]})}),li=n.memo(function({messages:s,contacts:a,className:r,conversationKey:l,onRetry:i,onRetryAsFlood:o,onMentionClick:x,historyLoading:p,historyExhausted:j,onLoadOlder:c,channelName:f}){const y=n.useRef(null),b=n.useRef(null),[d,N]=n.useState(!1),S=n.useRef(s.length),h=n.useRef(0),_=n.useRef(l);n.useEffect(()=>{if(l!==_.current){_.current=l,S.current=s.length,h.current=0,N(!1);const m=y.current;m&&(m.scrollTop=m.scrollHeight)}},[l,s.length]);const E=n.useMemo(()=>ei(a),[a]),R=n.useMemo(()=>ti(a),[a]),w=mt(),C=Qo(s);n.useEffect(()=>{var I;const m=y.current;if(m){if(s.length>S.current&&h.current>0){const g=m.scrollHeight-h.current;if(g>0&&m.scrollTop<200){m.scrollTop+=g,S.current=s.length,h.current=0;return}}S.current=s.length,d||(I=b.current)==null||I.scrollIntoView({behavior:"smooth"})}},[s.length,d]);const T=n.useCallback(()=>{const m=y.current;if(!m)return;const I=m.scrollHeight-m.scrollTop-m.clientHeight;N(I>100),m.scrollTop<80&&c&&!p&&!j&&(h.current=m.scrollHeight,c())},[c,p,j]),v=n.useCallback(()=>{var m;(m=b.current)==null||m.scrollIntoView({behavior:"smooth"}),N(!1)},[]);let u="";return e.jsxs("div",{className:P("relative flex flex-col",r),children:[e.jsxs("div",{ref:y,onScroll:T,className:"flex-1 overflow-y-auto min-h-0 px-4 py-3",children:[p&&e.jsx("div",{className:"flex items-center justify-center py-3",children:e.jsx(oe,{className:"w-4 h-4 text-fg-muted animate-spin"})}),s.length===0?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("p",{className:"text-sm text-fg-muted",children:j?"No messages yet":"Loading messages…"})}):s.map(m=>{const I=Zo(m.timestamp),g=I!==u;u=I;const $=m.is_outgoing?m.failed?"failed":m.confirmed?"confirmed":m.unconfirmed?"unconfirmed":(m.retryAttempt??0)>0?"retrying":m.sent?"sent":"pending":void 0,k=m.is_channel&&m.channel_idx!=null?`ch:${m.channel_idx}`:m.sender_key;return e.jsxs("div",{children:[g&&e.jsx(Wr,{text:Jo(m.timestamp)}),e.jsx(ri,{msg:m,contact:R.get(m.sender_key),contacts:a,selfInfo:w,echoCount:C.get(m.id),channelName:f,children:e.jsx(Qr,{senderName:ni(m,E),text:m.text,timestamp:m.timestamp,isOutgoing:m.is_outgoing,status:$,onRetry:i&&m.failed?()=>i(k,m.id):void 0,onRetryAsFlood:o&&m.failed&&!m.is_channel?()=>o(k,m.id):void 0,retryAttempt:m.retryAttempt,maxRetries:m.maxRetries,echoCount:C.get(m.id),signed:!m.is_outgoing&&m.txt_type===Hn.SignedPlain,bubbleVariant:"subtle",onMentionClick:x})})]},m.id)}),e.jsx("div",{ref:b})]}),e.jsx("button",{onClick:v,className:P("absolute bottom-4 right-4 w-8 h-8 rounded-full bg-sys-blue flex items-center justify-center shadow-lg","hover:bg-sys-blue/90 transition-all duration-200",d?"opacity-100 translate-y-0":"opacity-0 translate-y-2 pointer-events-none"),children:e.jsx(Xr,{className:"w-4 h-4 text-white"})})]})}),oi=6,ii=n.memo(function({onSend:s,disabled:a,placeholder:r="Type a message…",className:l,mentionNames:i=[]}){const[o,x]=n.useState(""),[p,j]=n.useState(!1),c=n.useRef(null),[f,y]=n.useState(null),[b,d]=n.useState(-1),[N,S]=n.useState(0),h=n.useMemo(()=>{if(f==null)return[];const v=f.toLowerCase();return i.filter(u=>u.toLowerCase().includes(v)).slice(0,oi)},[f,i]),_=h.length>0;n.useEffect(()=>{S(0)},[h]);const E=n.useCallback(()=>{y(null),d(-1),S(0)},[]),R=n.useCallback(v=>{var k;if(b<0)return;const u=o.slice(0,b),m=((k=c.current)==null?void 0:k.selectionStart)??o.length,I=o.slice(m),g=`@[${v}] `,$=u+g+I;x($),E(),requestAnimationFrame(()=>{var te,W;const H=u.length+g.length;(te=c.current)==null||te.setSelectionRange(H,H),(W=c.current)==null||W.focus()})},[o,b,E]),w=n.useCallback(async()=>{var u;const v=o.trim();!v||p||a||(j(!0),E(),x(""),await s(v),j(!1),(u=c.current)==null||u.focus())},[o,p,a,s,E]),C=n.useCallback(v=>{const u=v.target.value;x(u);const m=v.target.selectionStart??u.length,I=u.slice(0,m),g=I.lastIndexOf("@");if(g>=0){const $=g>0?I[g-1]:" ";if(/\s/.test($)||g===0){const k=I.slice(g+1);if(!k.includes(" ")&&!k.includes("[")){y(k),d(g);return}}}E()},[E]),T=n.useCallback(v=>{if(_){if(v.key==="ArrowDown"){v.preventDefault(),S(u=>(u+1)%h.length);return}if(v.key==="ArrowUp"){v.preventDefault(),S(u=>(u-1+h.length)%h.length);return}if(v.key==="Enter"||v.key==="Tab"){v.preventDefault(),R(h[N]);return}if(v.key==="Escape"){v.preventDefault(),E();return}}v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),w())},[w,_,h,N,R,E]);return e.jsxs("div",{className:P("relative flex items-center gap-2 p-3 border-t border-edge-subtle",l),children:[_&&e.jsx("div",{className:"absolute bottom-full left-3 right-3 mb-1 radius-inset surface-elevated depth-raised overflow-hidden z-50",children:h.map((v,u)=>{const m=Pt(v),{emoji:I,cleanName:g}=Mt(v),$=Tt(v);return e.jsxs("button",{onMouseDown:k=>{k.preventDefault(),R(v)},className:P("w-full flex items-center gap-2.5 px-3 py-1.5 text-left transition-colors",u===N?"bg-sys-blue/10":"hover:bg-subtle-fill"),children:[e.jsx("div",{className:P("clay-avatar w-5 h-5",I?"text-xs":"text-white text-[9px] font-bold"),style:{"--avatar-color":m},children:I||$}),e.jsx("span",{className:"text-sm text-fg-primary truncate",children:g})]},v)})}),e.jsx("input",{ref:c,type:"text",value:o,onChange:C,onKeyDown:T,onBlur:()=>{setTimeout(E,150)},placeholder:r,disabled:a,className:"flex-1 min-w-0 w-full px-4 py-3 text-sm radius-inner bg-input-bg border border-input-border text-fg-primary placeholder:text-fg-muted/50 ring-focus-inset hover:border-edge-strong transition-colors"}),e.jsx("button",{onClick:w,disabled:!o.trim()||p||a,className:P("flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center transition-colors",o.trim()&&!a?"clay-send text-white":"bg-subtle-fill text-fg-muted cursor-not-allowed"),children:e.jsx(Bn,{className:"w-4.5 h-4.5 -translate-x-[0.5px] translate-y-[0.5px]",strokeWidth:2.5})})]})}),Ht="pymc_companion_room_pwd_";function ci(t){try{return localStorage.getItem(`${Ht}${t}`)}catch{return null}}function di(t,s){try{localStorage.setItem(`${Ht}${t}`,s)}catch{}}function Os(t){try{localStorage.removeItem(`${Ht}${t}`)}catch{}}const ui=n.memo(function({contact:s,loginStatus:a,onLogin:r,className:l}){const[i,o]=n.useState(""),[x,p]=n.useState(!0),[j,c]=n.useState(null),[f,y]=n.useState(!1),b=n.useRef(null),d=n.useRef(!0),N=s.public_key,S=n.useRef(N);S.current!==N&&(S.current=N,y(!1),c(null),o("")),n.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]),n.useEffect(()=>{if(f||a==="success")return;const R=ci(N);if(!R){y(!0);return}y(!0),(async()=>{const w=await r(N,R);d.current&&(w||(Os(N),c("Saved password rejected — please re-enter.")))})()},[N,f,a,r]);const h=n.useCallback(async()=>{c(null);const R=await r(N,i);d.current&&(R?x&&i?di(N,i):Os(N):c("Login failed — check your password and try again."))},[N,i,x,r]),_=n.useCallback(R=>{R.key==="Enter"&&(R.preventDefault(),h())},[h]),E=a==="pending";return E&&!i?e.jsxs("div",{className:P("flex-1 flex flex-col items-center justify-center gap-3",l),children:[e.jsx(oe,{className:"w-6 h-6 text-sys-pink animate-spin"}),e.jsxs("p",{className:"text-sm text-fg-muted",children:["Connecting to ",s.name||"room server","…"]})]}):e.jsx(ue.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2},className:P("flex-1 flex flex-col items-center justify-center px-6",l),children:e.jsxs("div",{className:"w-full max-w-xs space-y-5",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center ring-[1.5px] ring-sys-pink bg-sys-pink/8",children:e.jsx(dt,{className:"size-7 text-sys-pink"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"type-body font-medium text-fg-primary",children:s.name||"Room Server"}),e.jsx("p",{className:"text-xs text-fg-muted mt-1",children:"Enter the room password to join, or try logging in without one — some servers allow open access."})]})]}),(j||a==="failed")&&e.jsxs("div",{className:"flex items-start gap-2 p-2.5 rounded-lg bg-sys-red/8 border border-sys-red/15",children:[e.jsx(ua,{className:"w-3.5 h-3.5 text-sys-red flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-[11px] text-sys-red leading-relaxed",children:j||"Login failed — check your password and try again."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{ref:b,type:"password",value:i,onChange:R=>o(R.target.value),onKeyDown:_,placeholder:"Room password",disabled:E,autoFocus:!0,className:"w-full surface-input rounded-lg px-3 py-2.5 text-sm text-fg-primary placeholder:text-fg-muted/50 focus:outline-none focus:ring-1 focus:ring-sys-pink/40"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:x,onChange:R=>p(R.target.checked),disabled:E,className:"surface-checkbox w-3.5 h-3.5 rounded accent-sys-pink"}),e.jsx("span",{className:"text-xs text-fg-muted",children:"Remember password"})]}),e.jsxs(B,{color:"pink",className:"w-full justify-center",disabled:E,onClick:h,children:[E?e.jsx(oe,{"data-slot":"icon",className:"animate-spin"}):e.jsx(kt,{"data-slot":"icon"}),E?"Connecting…":"Login"]})]}),e.jsx("p",{className:"text-[10px] text-fg-muted/60 text-center leading-relaxed",children:"The server determines your permissions based on the password. Admin and guest passwords grant different access levels."})]})})});function zs(t,s){return[t,s].sort().join("-")}function st(t){return t.substring(0,2)}function mi(t){var a,r;const s=(r=(a=t.traceQuality)==null?void 0:a.composite)==null?void 0:r.mean;return s!=null&&s!==0?Math.max(.1,s+20):Math.max(.1,t.strength*20)}function pi(t,s,a,r){const{edgeMap:l}=a;if(l.size===0)return null;const i=new Map;for(const[,w]of l){const C=w.fromHash,T=w.toHash;i.has(C)||i.set(C,[]),i.has(T)||i.set(T,[]),i.get(C).push({neighbor:T,edge:w}),i.get(T).push({neighbor:C,edge:w})}const o=new Set(i.keys()),x=Hs(t,o),p=Hs(s,o);if(!x||!p||x===p)return null;const j=new Map,c=new Map,f=new Set,y=[];for(j.set(x,0),c.set(x,null),y.push({node:x,cost:0});y.length>0;){y.sort((T,v)=>T.cost-v.cost);const w=y.shift();if(f.has(w.node))continue;if(f.add(w.node),w.node===p)break;const C=i.get(w.node)??[];for(const{neighbor:T,edge:v}of C){if(f.has(T))continue;const u=mi(v),m=w.cost+1/u,I=j.get(T)??1/0;m{var $,k;const T=st(w),v=N.get(T);let u=0;const m=b[C],I=zs(m,w),g=l.get(I);return(k=($=g==null?void 0:g.traceQuality)==null?void 0:$.composite)!=null&&k.mean?u=g.traceQuality.composite.mean:(g==null?void 0:g.avgSnr)!=null&&(u=g.avgSnr),{hash:w,prefix:T,name:(v==null?void 0:v.name)||null,snr:u}});let _=0,E=0;for(let w=0;w0?_/E:0;return{hops:S.map(st),confidence:R,via:h}}function Hs(t,s){if(s.has(t))return t;const a=st(t);let r=null,l=0;for(const i of s)if(i.startsWith(a)||t.startsWith(i.substring(0,2))){let o=0;const x=Math.min(t.length,i.length);for(let p=0;pl&&(l=o,r=i)}return r}function Bs(t){switch(t&15){case 1:return"Companion";case 2:return"Repeater";case 3:return"Room Server";default:return"Unknown"}}function Gs(t){switch(t&15){case 1:return"blue";case 2:return"green";case 3:return"indigo";default:return"zinc"}}function hi(t){return(t&15)===2}const Ks=n.memo(function({contact:s,channel:a,contacts:r=[],selfPubKey:l,embedded:i=!1,onResetPath:o,onRequestStatus:x,onRequestTelemetry:p,onLoginToRepeater:j,onLogoutFromRepeater:c,onGetNeighbours:f,onTraceContactPath:y,onDiscoverPath:b,onExportContact:d,onSetContactPath:N,className:S}){const[h,_]=n.useState({}),E=(s==null?void 0:s.public_key)??null,[R,w]=n.useState(E);if(E!==R&&(w(E),_({})),!s&&!a)return i?null:e.jsx("div",{className:P("flex items-center justify-center h-full",S),children:e.jsx("p",{className:"text-sm text-fg-muted",children:"Select a conversation"})});async function C(m,I){_($=>({...$,[m]:"loading"}));const g=await I();_($=>({...$,[m]:g?"done":"error"})),setTimeout(()=>_($=>({...$,[m]:"idle"})),2e3)}const T=a?e.jsxs("div",{className:"space-y-4",children:[!i&&e.jsxs("div",{className:"flex flex-col items-center gap-2 pb-3 border-b border-edge-subtle",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-sys-indigo/15 flex items-center justify-center shadow-md",children:e.jsx(Fe,{className:"size-7 text-sys-indigo"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"type-body font-medium text-fg-primary",children:a.name}),e.jsxs(De,{color:"indigo",children:["Channel ",a.index]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted w-20",children:"Index"}),e.jsx("span",{className:"font-mono text-fg-primary",children:a.index})]}),e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted w-20",children:"Type"}),e.jsx("span",{className:"text-fg-primary",children:"Broadcast"})]})]}),e.jsx("div",{className:"pt-2 border-t border-edge-subtle",children:e.jsx("p",{className:"type-data-xs text-fg-muted/70",children:"Channel messages are broadcast-encrypted. Sender identity is not available due to MeshCore protocol limitations."})})]}):null,v=s?e.jsxs("div",{className:"space-y-4",children:[!i&&e.jsxs("div",{className:"flex flex-col items-center gap-2 pb-3 border-b border-edge-subtle",children:[e.jsx(bi,{contact:s}),e.jsxs("div",{className:"text-center",children:[e.jsxs("h3",{className:"type-body font-medium text-fg-primary flex items-center justify-center gap-1",children:[s.name||"Unknown",e.jsx(qs,{pubkey:s.public_key})]}),e.jsx(De,{color:Gs(s.adv_type),children:Bs(s.adv_type)})]})]}),i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{color:Gs(s.adv_type),children:Bs(s.adv_type)}),e.jsx(qs,{pubkey:s.public_key})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted w-20",children:"Public Key"}),e.jsx("span",{className:"font-mono text-fg-primary break-all text-[10px]",children:s.public_key})]}),e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx(Ge,{className:"w-3.5 h-3.5 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted",children:"Path Length"}),e.jsx("span",{className:"text-fg-primary ml-auto",children:s.out_path_len})]}),(s.gps_lat!==0||s.gps_lon!==0)&&e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx(ca,{className:"w-3.5 h-3.5 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted",children:"GPS"}),e.jsxs("span",{className:"text-fg-primary ml-auto font-mono text-[10px]",children:[s.gps_lat.toFixed(5),", ",s.gps_lon.toFixed(5)]})]}),(s.lastmod>0||s.last_advert_timestamp>0)&&e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx(ma,{className:"w-3.5 h-3.5 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted",children:"Last Heard"}),e.jsx("span",{className:"text-fg-primary ml-auto",children:new Date((s.lastmod||s.last_advert_timestamp)*1e3).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),s.last_advert_timestamp>0&&e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted",children:"Last Advert"}),e.jsx("span",{className:"text-fg-primary ml-auto",children:new Date(s.last_advert_timestamp*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})]}),e.jsx(ji,{contact:s,contacts:r,selfPubKey:l,onSetContactPath:N,onDiscoverPath:b,actionState:h,setActionState:_,runAction:C}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-edge-subtle",children:[e.jsxs(B,{color:h.reset==="done"?"success":h.reset==="error"?"danger":"primary",outline:!0,className:"w-full justify-center",disabled:h.reset==="loading",onClick:()=>C("reset",()=>o(s.public_key)),children:[e.jsx(da,{"data-slot":"icon"}),h.reset==="loading"?"Resetting…":h.reset==="done"?"Reset!":"Reset Path"]}),e.jsxs(B,{color:h.status==="done"?"success":h.status==="error"?"danger":"primary",outline:!0,className:"w-full justify-center",disabled:h.status==="loading",onClick:()=>C("status",()=>x(s.public_key)),children:[e.jsx(pa,{"data-slot":"icon"}),h.status==="loading"?"Requesting…":"Request Status"]}),e.jsxs(B,{color:h.telemetry==="done"?"success":h.telemetry==="error"?"danger":"primary",outline:!0,className:"w-full justify-center",disabled:h.telemetry==="loading",onClick:()=>C("telemetry",()=>p(s.public_key)),children:[e.jsx(ha,{"data-slot":"icon"}),h.telemetry==="loading"?"Requesting…":"Request Telemetry"]})]}),d&&e.jsxs(B,{color:"primary",outline:!0,className:"w-full justify-center",onClick:()=>d(s.public_key),children:[e.jsx(zt,{"data-slot":"icon"}),"Export Contact"]}),hi(s.adv_type)&&e.jsxs(e.Fragment,{children:[e.jsx(wi,{pubkey:s.public_key,onLogin:j,onLogout:c,actionState:h,runAction:C}),e.jsx(Ni,{pubkey:s.public_key,onGetNeighbours:f,actionState:h,runAction:C}),e.jsx(ki,{pubkey:s.public_key,contact:s,onTrace:y,actionState:h,runAction:C})]}),e.jsx(xi,{pubkey:s.public_key}),e.jsx(yi,{pubkey:s.public_key})]}):null,u=T??v;return i?e.jsx("div",{className:S,children:u}):e.jsx("div",{className:P("flex flex-col h-full overflow-y-auto",S),children:e.jsx(ge,{mode:"wait",children:a?e.jsx(ue.div,{variants:Zr,initial:"hidden",animate:"visible",exit:"exit",className:"p-4",children:T},`ch-${a.index}`):s?e.jsx(ue.div,{variants:el,initial:"hidden",animate:"visible",exit:"exit",className:"p-4",children:v},`contact-${s.public_key}`):null})})});function Us(t){const s=Math.floor(t/86400),a=Math.floor(t%86400/3600),r=Math.floor(t%3600/60);return s>0?`${s}d ${a}h`:a>0?`${a}h ${r}m`:`${r}m`}function xi({pubkey:t}){const s=Wn(t);return s?e.jsxs(_e,{defaultOpen:!0,className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(pa,{className:"w-3.5 h-3.5 text-sys-green"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Status"})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(Z,{label:"Battery",value:`${(s.battMilliVolts/1e3).toFixed(2)}V`}),e.jsx(Z,{label:"Noise Floor",value:`${s.noiseFloor} dBm`}),e.jsx(Z,{label:"Last RSSI",value:`${s.lastRssi} dBm`}),e.jsx(Z,{label:"Last SNR",value:`${(s.lastSnr/4).toFixed(1)} dB`}),e.jsx(Z,{label:"Uptime",value:Us(s.totalUpTimeSecs)}),e.jsx(Z,{label:"Air Time",value:Us(s.totalAirTimeSecs)}),e.jsx(Z,{label:"TX Queue",value:String(s.currTxQueueLen)}),e.jsx(Z,{label:"Packets Rx",value:String(s.nPacketsRecv)}),e.jsx(Z,{label:"Packets Tx",value:String(s.nPacketsSent)}),e.jsx(Z,{label:"Flood Rx/Tx",value:`${s.nRecvFlood}/${s.nSentFlood}`}),e.jsx(Z,{label:"Direct Rx/Tx",value:`${s.nRecvDirect}/${s.nSentDirect}`}),e.jsx(Z,{label:"Dups (D/F)",value:`${s.nDirectDups}/${s.nFloodDups}`}),s.errEvents>0&&e.jsx(Z,{label:"Errors",value:String(s.errEvents)})]})})]}):null}function Z({label:t,value:s}){return e.jsxs("div",{className:"flex items-center justify-between type-data-xs",children:[e.jsx("span",{className:"text-fg-muted",children:t}),e.jsx("span",{className:"text-fg-primary font-mono text-[10px]",children:s})]})}function fi(t){switch(t){case 100:return"Generic";case 101:return"Luminosity";case 102:return"Presence";case 103:return"Temperature";case 104:return"Humidity";case 115:return"Pressure";case 116:return"Voltage";case 117:return"Current";case 120:return"Percentage";case 125:return"Concentration";case 128:return"Power";case 136:return"GPS";default:return`Type ${t}`}}function gi(t){switch(t){case 103:return"°C";case 104:return"%";case 115:return" hPa";case 116:return"V";case 117:return"A";case 120:return"%";case 125:return" ppm";case 128:return"W";default:return""}}function yi({pubkey:t}){const s=Qn(t);if(!s)return null;const a=Eo(s.lppSensorData);return a.length===0?null:e.jsxs(_e,{defaultOpen:!0,className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(ha,{className:"w-3.5 h-3.5 text-sys-amber"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Telemetry"})]}),e.jsx(Ie,{children:e.jsx("div",{className:"space-y-1.5 py-1",children:a.map((r,l)=>typeof r.value=="object"?e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Z,{label:`Ch${r.channel} GPS Lat`,value:r.value.latitude.toFixed(5)}),e.jsx(Z,{label:`Ch${r.channel} GPS Lon`,value:r.value.longitude.toFixed(5)}),e.jsx(Z,{label:`Ch${r.channel} GPS Alt`,value:`${r.value.altitude.toFixed(1)}m`})]},l):e.jsx(Z,{label:`Ch${r.channel} ${fi(r.type)}`,value:`${typeof r.value=="number"?r.value.toFixed(r.type===103||r.type===116?2:0):r.value}${gi(r.type)}`},l))})})]})}function bi({contact:t}){const{emoji:s}=Mt(t.name||""),a=Pt(t.name||t.public_key),r=t.name?Tt(t.name):t.public_key.slice(0,2).toUpperCase();return(t.adv_type&15)===2?e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center shadow-md ring-[1.5px] ring-sys-blue",children:e.jsx(ze,{className:"size-7 text-sys-blue"})}):(t.adv_type&15)===3?e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center shadow-md ring-[1.5px] ring-sys-pink",children:e.jsx(dt,{className:"size-7 text-sys-pink"})}):e.jsx("div",{className:P("w-14 h-14 clay-avatar",s?"text-2xl":"text-white text-lg font-bold"),style:{"--avatar-color":a},children:s||r})}function qs({pubkey:t}){return Gn().get(t)!==!0?null:e.jsx("span",{title:"Ed25519 verified identity",children:e.jsx(al,{className:"w-4 h-4 text-sys-green flex-shrink-0"})})}const bt=64;function vi(t){if(!t)return[];const s=[];for(let a=0;a0,w=vi(t.out_path),C=n.useCallback(async()=>{if(!r)return;const u=c.split(",").map(g=>g.trim()).filter(Boolean);if(u.length===0){b("Enter at least one hop");return}if(u.length>bt){b(`Max ${bt} hops`);return}if(!u.every(g=>/^[0-9a-fA-F]{1,2}$/.test(g))){b("Each hop must be 1-2 hex characters");return}b(null),o(g=>({...g,path:"loading"}));const I=await r(t.public_key,u);o(g=>({...g,path:I?"done":"error"})),I&&j(!1),setTimeout(()=>o(g=>({...g,path:"idle"})),2e3)},[r,c,t.public_key,o]),T=n.useCallback(()=>{if(!a){h("Self identity not available");return}const u=pi(a,t.public_key,_,s);u?(N(u),h(null)):(N(null),h("No route found in topology"))},[a,t.public_key,_,s]),v=n.useCallback(async()=>{if(!r||!d)return;o(m=>({...m,path:"loading"}));const u=await r(t.public_key,d.hops);o(m=>({...m,path:u?"done":"error"})),u&&(N(null),h(null)),setTimeout(()=>o(m=>({...m,path:"idle"})),2e3)},[r,d,t.public_key,o]);return e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(Ge,{className:"w-3.5 h-3.5 text-sys-blue"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Path"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-muted font-mono",children:R?`${E} hop${E>1?"s":""}`:"direct"})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-2 py-1",children:[w.length>0&&e.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[e.jsx("span",{className:"text-fg-muted type-data-xs",children:"Route"}),w.map((u,m)=>e.jsx("span",{className:"px-1 py-0.5 rounded bg-subtle-fill font-mono text-[10px] text-fg-primary",children:u},m))]}),d&&e.jsxs("div",{className:"space-y-1.5 p-2 rounded-md bg-sys-green/5 border border-sys-green/20",children:[e.jsxs("div",{className:"flex items-center gap-1 type-data-xs text-sys-green",children:[e.jsx(Is,{className:"w-3 h-3"}),e.jsxs("span",{children:["Auto-route (",d.via.length," hop",d.via.length!==1?"s":"",", ",Math.round(d.confidence*100),"% confidence)"]})]}),e.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:d.via.map((u,m)=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1 py-0.5 rounded bg-subtle-fill text-[10px]",children:[e.jsx("span",{className:"font-mono text-fg-primary",children:u.prefix}),u.name&&e.jsxs("span",{className:"text-fg-muted",children:["(",u.name,")"]}),u.snr!==0&&e.jsx("span",{className:P("font-mono",lt(u.snr)),children:u.snr.toFixed(1)})]},m))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(B,{color:i.path==="done"?"success":"primary",outline:!0,className:"flex-1 justify-center text-xs",disabled:i.path==="loading",onClick:v,children:[e.jsx(be,{"data-slot":"icon"}),i.path==="loading"?"Saving…":"Accept"]}),e.jsxs(B,{plain:!0,className:"text-xs",onClick:()=>{N(null),h(null)},children:[e.jsx(ut,{"data-slot":"icon"}),"Dismiss"]})]})]}),S&&!d&&e.jsx("p",{className:"text-[9px] text-sys-amber",children:S}),r&&!d&&e.jsx("div",{className:"flex items-center gap-2",children:p?e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx("input",{type:"text",value:c,onChange:u=>{f(u.target.value),b(null)},placeholder:"e.g. a3, f7, 1b",className:"w-full surface-input rounded-md px-2 py-1 text-[10px] font-mono text-fg-primary placeholder:text-fg-muted/50"}),e.jsxs("p",{className:"text-[9px] text-fg-muted/60",children:["Comma-separated hex hop bytes (max ",bt,")"]}),y&&e.jsx("p",{className:"text-[9px] text-sys-red",children:y}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(B,{color:i.path==="done"?"success":i.path==="error"?"danger":"primary",outline:!0,className:"flex-1 justify-center text-xs",disabled:i.path==="loading"||!c.trim(),onClick:C,children:[e.jsx(lo,{"data-slot":"icon"}),i.path==="loading"?"Saving…":"Save"]}),e.jsx(B,{plain:!0,className:"text-xs",onClick:()=>{j(!1),b(null)},children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{j(!0),f(w.length>0?w.join(", "):""),b(null)},className:"text-[10px] text-sys-blue hover:text-sys-blue/80 transition-colors",children:"Edit path…"}),a&&_.edgeMap.size>0&&e.jsxs("button",{onClick:T,className:"inline-flex items-center gap-0.5 text-[10px] text-sys-indigo hover:text-sys-indigo/80 transition-colors",children:[e.jsx(Is,{className:"w-3 h-3"}),"Auto-route"]}),l&&e.jsxs("button",{onClick:()=>x("discover",()=>l(t.public_key)),disabled:i.discover==="loading",className:P("inline-flex items-center gap-0.5 text-[10px] transition-colors disabled:opacity-50",i.discover==="error"?"text-sys-red":"text-sys-green hover:text-sys-green/80"),children:[e.jsx(nl,{className:"w-3 h-3"}),i.discover==="loading"?"Discovering…":i.discover==="done"?"Discovered!":i.discover==="error"?"Failed":"Discover"]})]})})]})})]})}function wi({pubkey:t,onLogin:s,onLogout:a,actionState:r,runAction:l}){const[i,o]=n.useState(""),x=It(t);return s?e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(kt,{className:"w-3.5 h-3.5 text-sys-amber"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Login"}),x!=="idle"&&e.jsx(De,{color:x==="success"?"green":x==="failed"?"red":"amber",className:"ml-auto text-[9px]",children:x})]}),e.jsx(Ie,{children:e.jsx("div",{className:"space-y-1.5 py-1",children:x==="success"&&a?e.jsxs(B,{color:r.logout==="done"?"success":r.logout==="error"?"danger":"primary",outline:!0,className:"w-full justify-center text-xs",disabled:r.logout==="loading",onClick:()=>l("logout",()=>a(t)),children:[e.jsx(Un,{"data-slot":"icon"}),r.logout==="loading"?"Disconnecting…":"Disconnect"]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",value:i,onChange:p=>o(p.target.value),placeholder:"Repeater password",className:"w-full surface-input rounded-md px-2 py-1 text-[10px] text-fg-primary placeholder:text-fg-muted/50"}),e.jsxs(B,{color:x==="failed"?"danger":"primary",outline:!0,className:"w-full justify-center text-xs",disabled:r.login==="loading"||!i.trim(),onClick:()=>l("login",()=>s(t,i)),children:[e.jsx(kt,{"data-slot":"icon"}),r.login==="loading"?"Logging in…":"Login"]})]})})})]}):null}function Ni({pubkey:t,onGetNeighbours:s,actionState:a,runAction:r}){const l=qn(t),i=It(t);return s?e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(wt,{className:"w-3.5 h-3.5 text-sys-green"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Neighbours"}),l&&e.jsx("span",{className:"ml-auto text-[10px] text-fg-muted",children:l.total})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs(B,{color:"primary",outline:!0,className:"w-full justify-center text-xs",disabled:a.neighbours==="loading"||i!=="success",onClick:()=>r("neighbours",()=>s(t)),children:[e.jsx(wt,{"data-slot":"icon"}),a.neighbours==="loading"?"Loading…":"Get Neighbours"]}),i!=="success"&&e.jsx("p",{className:"text-[9px] text-fg-muted/60",children:"Login required to query neighbours"}),l&&l.neighbours.length>0&&e.jsx("div",{className:"space-y-1",children:[...l.neighbours].sort((o,x)=>x.snr-o.snr).map((o,x)=>e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-primary font-mono text-[10px] w-16 truncate",children:o.name||o.prefixHex.slice(0,8)}),e.jsx("span",{className:"text-fg-muted text-[9px]",children:Si(o.heardAgo)}),e.jsxs("div",{className:"flex-1 flex items-center gap-1 ml-auto",children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-subtle-fill overflow-hidden",children:e.jsx("div",{className:P("h-full rounded-full",Ci(o.snr)),style:{width:`${Math.min(100,Math.max(5,(o.snr+20)/35*100))}%`}})}),e.jsx("span",{className:P("font-mono text-[9px] w-8 text-right",lt(o.snr)),children:o.snr.toFixed(1)})]})]},x))})]})})]}):null}function ki({pubkey:t,contact:s,onTrace:a,actionState:r,runAction:l}){const i=Vn(t);if(!a)return null;const o=s.out_path_len>0;return e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(Es,{className:"w-3.5 h-3.5 text-sys-indigo"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Trace"}),i&&e.jsxs("span",{className:"ml-auto text-[10px] text-fg-muted",children:[i.pathLen," hops"]})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs(B,{color:"primary",outline:!0,className:"w-full justify-center text-xs",disabled:r.trace==="loading"||!o,onClick:()=>l("trace",()=>a(t)),children:[e.jsx(Es,{"data-slot":"icon"}),r.trace==="loading"?"Tracing…":"Trace Path"]}),!o&&e.jsx("p",{className:"text-[9px] text-fg-muted/60",children:"Direct neighbour — no path to trace"}),i&&i.hops.length>0&&e.jsxs("div",{className:"space-y-1",children:[i.hops.map((x,p)=>e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted text-[9px] w-3",children:p+1}),e.jsx("span",{className:"px-1 py-0.5 rounded bg-subtle-fill font-mono text-[10px] text-fg-primary",children:x.hash}),x.name&&e.jsx("span",{className:"text-fg-muted text-[10px] truncate",children:x.name}),e.jsxs("span",{className:P("font-mono text-[10px] ml-auto",lt(x.snr)),children:[x.snr.toFixed(1)," dB"]})]},p)),e.jsxs("div",{className:"flex items-center justify-between type-data-xs pt-1 border-t border-edge-subtle",children:[e.jsx("span",{className:"text-fg-muted",children:"Last SNR"}),e.jsxs("span",{className:P("font-mono text-[10px]",lt(i.lastSnr)),children:[i.lastSnr.toFixed(1)," dB"]})]})]})]})})]})}function lt(t){return t>5?"text-sys-green":t>0?"text-sys-amber":"text-sys-red"}function Ci(t){return t>5?"bg-sys-green":t>0?"bg-sys-amber":"bg-sys-red"}function Si(t){return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}d`}const Vs=128,Ws=/^[0-9a-fA-F]+$/;function _i({open:t,onClose:s}){const a=se(k=>k.exportPrivateKey),r=se(k=>k.importPrivateKey),[l,i]=n.useState("export"),[o,x]=n.useState(null),[p,j]=n.useState(!1),[c,f]=n.useState(!1),[y,b]=n.useState(""),[d,N]=n.useState(!1),[S,h]=n.useState(!1),[_,E]=n.useState(!1),[R,w]=n.useState(!1),[C,T]=n.useState(null),[v,u]=n.useState(!1);t!==v&&(u(t),t&&(i("export"),x(null),j(!1),f(!1),b(""),N(!1),h(!1),E(!1),w(!1),T(null)));const m=n.useCallback(async()=>{j(!0),T(null),w(!1);try{const k=await a();k==="disabled"?w(!0):x(k.hex)}catch(k){T(k instanceof Error?k.message:"Export failed")}finally{j(!1)}},[a]),I=n.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),f(!0),setTimeout(()=>f(!1),2e3)}catch{T("Failed to copy to clipboard")}},[o]),g=y.length===Vs&&Ws.test(y),$=n.useCallback(async()=>{h(!1),N(!0),T(null),w(!1);try{await r(y)==="disabled"?w(!0):E(!0)}catch(k){T(k instanceof Error?k.message:"Import failed")}finally{N(!1)}},[r,y]);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{open:t,onClose:s,size:"md",children:[e.jsx(Ee,{icon:e.jsx(fa,{className:"w-5 h-5"}),title:"Key Management",onClose:s}),e.jsxs(we,{children:[R&&e.jsxs("div",{className:"flex items-start gap-2.5 p-3 mb-4 rounded-lg bg-sys-amber/10 border border-sys-amber/20",children:[e.jsx(Yn,{className:"w-4 h-4 text-sys-amber flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"type-body-sm font-medium text-sys-amber",children:"Key operations disabled"}),e.jsx("p",{className:"type-data-xs text-fg-muted mt-0.5",children:"This device's firmware has disabled private key export/import. This is a security setting configured at build time and cannot be changed remotely."})]})]}),e.jsx("div",{className:"flex gap-1 mb-4 p-0.5 rounded-lg bg-subtle-fill",children:["export","import"].map(k=>e.jsxs("button",{onClick:()=>{i(k),T(null)},className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 px-3 rounded-md text-sm font-medium transition-colors",l===k?"bg-surface text-fg-primary shadow-sm":"text-fg-muted hover:text-fg-secondary"),children:[k==="export"?e.jsx(He,{className:"w-3.5 h-3.5"}):e.jsx(zt,{className:"w-3.5 h-3.5"}),k==="export"?"Export":"Import"]},k))}),l==="export"&&e.jsx("div",{className:"space-y-4",children:o?e.jsxs(re,{children:[e.jsx(le,{children:"Private Key (64 bytes)"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"p-3 rounded-lg bg-subtle-fill border border-edge-subtle font-mono text-xs break-all select-all leading-relaxed",children:o}),e.jsx("button",{onClick:I,className:"absolute top-2 right-2 p-1.5 rounded-md hover:bg-subtle-fill-strong transition-colors",title:"Copy to clipboard",children:c?e.jsx(be,{className:"w-3.5 h-3.5 text-sys-green"}):e.jsx(Et,{className:"w-3.5 h-3.5 text-fg-muted"})})]}),e.jsx(ke,{children:e.jsxs("span",{className:"flex items-start gap-1.5 mt-1",children:[e.jsx(Be,{className:"w-3 h-3 text-sys-amber flex-shrink-0 mt-0.5"}),"This key controls your mesh identity. Never share it."]})})]}):e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"type-body-sm text-fg-muted mb-3",children:"Export your device's private key for backup. Keep it secret — anyone with this key can impersonate your mesh identity."}),e.jsx(B,{color:"primary",onClick:m,disabled:p||R,children:p?"Exporting…":"Export Private Key"})]})}),l==="import"&&e.jsx("div",{className:"space-y-4",children:_?e.jsxs("div",{className:"text-center py-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-sys-green/10 mx-auto mb-3 flex items-center justify-center",children:e.jsx(be,{className:"w-5 h-5 text-sys-green"})}),e.jsx("p",{className:"type-body-sm font-medium text-fg-primary",children:"Key imported successfully"}),e.jsx("p",{className:"type-data-xs text-fg-muted mt-1",children:"The device identity has been updated. You may need to reconnect."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(re,{children:[e.jsx(le,{children:"Private Key (128 hex characters)"}),e.jsx("textarea",{value:y,onChange:k=>b(k.target.value.replace(/\s/g,"")),placeholder:"Paste your 128-character hex private key here…",rows:3,className:"w-full p-3 rounded-lg bg-subtle-fill border border-edge-subtle font-mono text-xs resize-none focus:outline-none focus:ring-2 focus:ring-sys-blue/50 placeholder:text-fg-muted/40"}),e.jsxs(ke,{children:[y.length>0&&!g&&e.jsx("span",{className:"text-sys-red",children:Ws.test(y)?`${y.length}/${Vs} characters`:"Invalid characters — hex only (0-9, a-f)"}),y.length>0&&g&&e.jsx("span",{className:"text-sys-green",children:"Valid key format ✓"})]})]}),e.jsxs("div",{className:"flex items-start gap-2.5 p-3 rounded-lg bg-sys-red/5 border border-sys-red/10",children:[e.jsx(Be,{className:"w-4 h-4 text-sys-red flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"type-data-xs text-fg-muted",children:["Importing a key ",e.jsx("strong",{className:"text-fg-secondary",children:"permanently replaces"})," the device's current identity. All existing contacts will see you as a new node."]})]})]})}),C&&e.jsx("p",{className:"type-data-xs text-sys-red mt-3",children:C})]}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Close"}),l==="import"&&!_&&e.jsx(B,{color:"danger",onClick:()=>h(!0),disabled:!g||d||R,children:d?"Importing…":"Import Key"})]})]}),e.jsx(xa,{isOpen:S,title:"Replace Device Identity?",message:"This will permanently replace the device's Ed25519 private key. The current identity cannot be recovered unless you have a backup. Continue?",confirmLabel:"Replace Key",cancelLabel:"Cancel",variant:"danger",onConfirm:$,onCancel:()=>h(!1)})]})}function _a(t){return t.settings??{}}const Ra="pymc_companion_recent_regions",Bt=8;function Ia(){try{const t=localStorage.getItem(Ra);return t?JSON.parse(t).slice(0,Bt):[]}catch{return[]}}function Ri(t){try{localStorage.setItem(Ra,JSON.stringify(t.slice(0,Bt)))}catch{}}function Ii(t){const s=Ia().filter(r=>r!==t);s.unshift(t);const a=s.slice(0,Bt);return Ri(a),a}function Qs(t){return t.toLowerCase().replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Ei({open:t,onClose:s,mode:a,identity:r,onSave:l}){const i=a==="edit"&&r,[o,x]=n.useState(""),[p,j]=n.useState(""),[c,f]=n.useState(""),[y,b]=n.useState(!1),[d,N]=n.useState(""),[S,h]=n.useState(5e3),[_,E]=n.useState("0.0.0.0"),[R,w]=n.useState(!1),[C,T]=n.useState(null),[v,u]=n.useState(""),m=`${t}-${(r==null?void 0:r.name)??""}-${a}`;if(m!==v)if(u(m),T(null),w(!1),b(!1),i){const g=_a(r);x(r.name),j(""),f(r.identity_key??""),N(g.node_name??r.name),h(g.tcp_port??5e3),E(g.bind_address??"0.0.0.0")}else x(""),j(""),f(""),N(""),h(5e3),E("0.0.0.0");const I=n.useCallback(async()=>{var g,$;if(!i&&!o.trim()){T("Name is required");return}w(!0),T(null);try{if(i){const k={name:r.name,new_name:p,identity_key:c,type:"companion",settings:{node_name:d,tcp_port:S,bind_address:_}},H=await nr(k);if(!H.success&&!((g=H.data)!=null&&g.message))throw new Error(H.error||"Failed")}else{const k={name:o.trim(),identity_key:c,type:"companion",settings:{node_name:d||o.trim(),tcp_port:S??5e3,bind_address:_||"0.0.0.0"}},H=await rr(k);if(!H.success&&!(($=H.data)!=null&&$.message))throw new Error(H.error||"Failed")}await l(),s()}catch(k){T(k instanceof Error?k.message:"Operation failed")}finally{w(!1)}},[i,r,o,p,c,d,S,_,l,s]);return e.jsxs(je,{open:t,onClose:s,size:"md",children:[e.jsx(Ee,{icon:i?void 0:e.jsx(ye,{className:"w-5 h-5"}),title:i?"Edit Companion":"Add Companion",onClose:s}),e.jsx(we,{children:e.jsxs("div",{className:"space-y-5",children:[i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{color:r.registered?"green":"red",children:r.registered?"Active":"Inactive"}),r.hash&&e.jsx("span",{className:"type-data-xs text-fg-muted",children:r.hash})]}),i?e.jsxs(e.Fragment,{children:[e.jsxs(re,{children:[e.jsx(le,{children:"Current Name"}),e.jsx(pe,{value:r.name,disabled:!0})]}),e.jsxs(re,{children:[e.jsxs(le,{children:["New Name ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(Optional)"})]}),e.jsx(pe,{value:p,onChange:g=>j(g.target.value),placeholder:"Leave empty to keep current name"})]})]}):e.jsxs(re,{children:[e.jsx(le,{children:"Name"}),e.jsx(pe,{value:o,onChange:g=>x(g.target.value),placeholder:"e.g., TestCompanion",autoFocus:!0})]}),e.jsxs(re,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(le,{children:["Identity Key ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(Optional)"})]}),e.jsx("button",{type:"button",onClick:()=>b(g=>!g),className:"type-data-xs text-fg-muted underline hover:text-fg-secondary",children:y?"Hide":"Show"})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx(pe,{value:c,onChange:g=>f(g.target.value),placeholder:i?"Leave empty to keep current key":"Leave empty to auto-generate",className:"font-mono"}),e.jsx(ke,{children:"32 or 64 bytes hex."})]})]}),e.jsxs(re,{children:[e.jsx(le,{children:"Node Name"}),e.jsx(pe,{value:d,onChange:g=>N(g.target.value),placeholder:"Display name"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(re,{children:[e.jsx(le,{children:"TCP Port"}),e.jsx(pe,{type:"number",min:1,max:65535,value:S,onChange:g=>h(parseInt(g.target.value,10)||5e3)})]}),e.jsxs(re,{children:[e.jsx(le,{children:"Bind Address"}),e.jsx(pe,{value:_,onChange:g=>E(g.target.value),placeholder:"0.0.0.0"})]})]}),C&&e.jsx("p",{className:"type-data-xs text-sys-red",children:C})]})}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Cancel"}),e.jsx(B,{color:"primary",onClick:I,disabled:R,children:R?"Saving…":i?"Save":"Create"})]})]})}function Mi(){const t=sr(),s=oa(),{setFloodScope:a,clearFloodScope:r}=se.getState(),[l,i]=n.useState(""),[o,x]=n.useState(!1),[p,j]=n.useState(Ia),[c,f]=n.useState(null),y=n.useRef(null),b=l.trim()?Qs(l.trim()):"",d=n.useCallback(async h=>{const _=Qs(h);if(!_)return;x(!0),f(null),i(""),j(Ii(_)),await a(_)||f("Failed to set transport key on device"),x(!1)},[a]),N=n.useCallback(async()=>{x(!0),f(null),await r()||f("Failed to clear transport key on device"),x(!1)},[r]),S=n.useCallback(h=>{h.key==="Enter"&&b&&(h.preventDefault(),d(b))},[b,d]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5 p-3 rounded-lg bg-sys-blue/5 border border-sys-blue/10",children:[e.jsx(nt,{className:"w-4 h-4 text-sys-blue flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"type-data-xs text-fg-muted",children:["A transport key filters which flood packets the companion device forwards. Set a region name to derive a SHA-256 transport key from ",e.jsx("code",{className:"text-fg-secondary",children:"#name"}),". Only one transport key can be active at a time."]})]}),e.jsx("div",{className:"bg-subtle-fill radius-inner p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ga,{className:"w-4 h-4 text-fg-muted"}),e.jsx("span",{className:"type-body-sm text-fg-muted",children:"Active Transport Key"})]}),t?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sys-green/10 text-sys-green type-data font-medium",children:[e.jsx(ca,{className:"w-3.5 h-3.5"}),"#",t]}),e.jsx("button",{onClick:N,disabled:o||!s,className:"p-1.5 rounded-lg hover:bg-sys-red/10 transition-colors disabled:opacity-50",title:"Clear transport key",children:o?e.jsx(oe,{className:"w-3.5 h-3.5 text-fg-muted animate-spin"}):e.jsx(ut,{className:"w-3.5 h-3.5 text-fg-muted hover:text-sys-red"})})]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-subtle-fill-strong text-fg-muted type-data",children:[e.jsx(ar,{className:"w-3.5 h-3.5"}),"Global (no filter)"]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"type-label text-fg-muted block mb-2",children:"Set Region"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-fg-muted/50 type-data",children:"#"}),e.jsx("input",{ref:y,type:"text",value:l,onChange:h=>i(h.target.value),onKeyDown:S,placeholder:"e.g., south-bay",disabled:!s,className:"w-full pl-7 pr-3 py-2 rounded-lg bg-subtle-fill border border-edge-subtle text-sm text-fg-primary placeholder:text-fg-muted/40 focus:outline-none focus:ring-2 focus:ring-sys-blue/50 disabled:opacity-50"})]}),e.jsxs(B,{color:"primary",onClick:()=>d(b),disabled:!b||o||!s,children:[o?e.jsx(oe,{"data-slot":"icon",className:"animate-spin"}):null,"Set"]})]}),b&&b!==l.trim().toLowerCase()&&e.jsxs("p",{className:"type-data-xs text-fg-muted mt-1",children:["Will set as ",e.jsxs("span",{className:"font-mono text-fg-secondary",children:["#",b]})]})]}),p.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ma,{className:"w-3.5 h-3.5 text-fg-muted/50"}),e.jsx("span",{className:"type-label text-fg-muted",children:"Recent Regions"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(h=>e.jsx("button",{onClick:()=>d(h),disabled:o||!s,className:P("inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-medium transition-colors","disabled:opacity-50 disabled:cursor-not-allowed",h===t?"bg-sys-green/10 text-sys-green":"bg-subtle-fill hover:bg-subtle-fill-strong text-fg-secondary"),children:e.jsxs("span",{className:"font-mono",children:["#",h]})},h))})]}),!s&&e.jsx("p",{className:"type-data-xs text-sys-amber",children:"Companion device is not connected. Connect to a companion to manage transport keys."}),c&&e.jsx("p",{className:"type-data-xs text-sys-red",children:c})]})}function Ys({open:t,onClose:s,onRefresh:a}){const[r,l]=n.useState("companions"),[i,o]=n.useState(null),[x,p]=n.useState(!0),[j,c]=n.useState(!1),[f,y]=n.useState("create"),[b,d]=n.useState(null),[N,S]=n.useState(null),[h,_]=n.useState(!1),[E,R]=n.useState(!1),w=n.useRef(!0);n.useEffect(()=>(w.current=!0,()=>{w.current=!1}),[]);const[C,T]=n.useState(!1);t!==C&&(T(t),t&&l("companions"));const v=n.useCallback(async()=>{p(!0);try{const F=await Xn();w.current&&F.success&&F.data&&o(F.data)}catch{}finally{w.current&&p(!1)}},[]);n.useEffect(()=>{t&&v()},[t,v]);const u=(i==null?void 0:i.configured_companions)??[],m=n.useCallback(async()=>{await v(),a==null||a()},[v,a]),I=n.useCallback(async()=>{if(N){_(!0);try{await Jn(N.name,"companion"),await m()}catch{}finally{w.current&&(_(!1),S(null))}}},[N,m]),g=Zn(),$=la(),{setCompanionPaused:k}=se.getState(),[H,te]=n.useState({});n.useEffect(()=>{if(!(i!=null&&i.configured_companions))return;const F={};for(const D of i.configured_companions)F[D.name]=er(D.name);te(F)},[i]);const W=n.useCallback(F=>F===$?g:H[F]??!1,[$,g,H]),[L,V]=n.useState(null),ie=n.useCallback(async(F,D)=>{V(F);try{await k(F,!D),te(A=>({...A,[F]:!D}))}finally{w.current&&V(null)}},[k]);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{open:t,onClose:s,size:"md",children:[e.jsx(Ee,{icon:e.jsx(ye,{className:"w-5 h-5"}),title:"Companion Configuration",onClose:s}),e.jsxs(we,{children:[e.jsx("div",{className:"flex gap-1 mb-4 p-0.5 rounded-lg bg-subtle-fill",children:[["companions","Companions",ye],["transport","Transport Key",ga]].map(([F,D,A])=>e.jsxs("button",{onClick:()=>l(F),className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 px-3 rounded-md text-sm font-medium transition-colors",r===F?"bg-surface text-fg-primary shadow-sm":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx(A,{className:"w-3.5 h-3.5"}),D]},F))}),r==="companions"&&e.jsx(e.Fragment,{children:x?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(oe,{className:"w-5 h-5 animate-spin text-sys-blue mr-2"}),e.jsx("span",{className:"text-sm text-fg-muted",children:"Loading…"})]}):u.length>0?e.jsx("div",{className:"space-y-3",children:u.map(F=>{const D=_a(F),A=W(F.name),O=!A&&F.registered,G=L===F.name;return e.jsxs("div",{className:P("bg-subtle-fill radius-inner p-3 hover:bg-subtle-fill-strong transition-base",A&&"opacity-60"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:P("h-2 w-2 rounded-full flex-shrink-0",O?"bg-sys-green":A?"bg-fg-muted":"bg-sys-red")}),e.jsx("h3",{className:"type-body-sm text-fg-primary font-medium truncate flex-1",children:F.name}),e.jsx(De,{color:O?"green":A?"zinc":"red",children:A?"Paused":O?"Active":"Inactive"}),e.jsx(B,{color:"primary",plain:!0,onClick:()=>{d(F),y("edit"),c(!0)},children:e.jsx(rl,{"data-slot":"icon"})}),e.jsx(tr,{enabled:!A,onChange:Q=>ie(F.name,Q),size:"sm",disabled:G,status:G?"loading":"idle",tooltip:A?"Resume connection":"Pause connection",dangerOff:!0}),e.jsx(B,{color:"danger",plain:!0,onClick:()=>S(F),children:e.jsx(Ke,{"data-slot":"icon"})})]}),e.jsxs("div",{className:"mt-1.5 type-data-xs text-fg-muted pl-5",children:[D.node_name||F.name," · Port ",D.tcp_port??5e3," · ",D.bind_address||"0.0.0.0"]})]},F.name)})}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-subtle-fill mx-auto mb-3 flex items-center justify-center",children:e.jsx(ye,{className:"w-5 h-5 text-fg-muted/50"})}),e.jsx("p",{className:"text-sm text-fg-muted",children:"No companions configured"})]})}),r==="transport"&&e.jsx(Mi,{})]}),e.jsxs(Me,{children:[r==="companions"&&e.jsx(B,{plain:!0,onClick:()=>R(!0),title:"Key Management",children:e.jsx(fa,{"data-slot":"icon"})}),e.jsx("div",{className:"flex-1"}),e.jsx(B,{plain:!0,onClick:s,children:"Close"}),r==="companions"&&e.jsxs(B,{color:"primary",onClick:()=>{d(null),y("create"),c(!0)},children:[e.jsx(Ue,{"data-slot":"icon"})," Add Companion"]})]})]}),e.jsx(Ei,{open:j,onClose:()=>c(!1),mode:f,identity:b,onSave:m}),e.jsx(xa,{isOpen:!!N,title:"Delete Companion",message:`Delete '${N==null?void 0:N.name}'? A service restart is required.`,confirmLabel:h?"Deleting…":"Delete",cancelLabel:"Cancel",variant:"danger",onConfirm:I,onCancel:()=>S(null)}),e.jsx(_i,{open:E,onClose:()=>R(!1)})]})}const Pi=n.memo(function({companions:s,selected:a,onSelect:r}){return s.length<2?null:e.jsx("select",{value:a??"",onChange:l=>r(l.target.value),className:"px-2 py-1 text-sm bg-transparent border border-edge-subtle radius-inner text-fg-primary focus:outline-none focus:ring-1 focus:ring-sys-blue/40",children:s.map(l=>e.jsx("option",{value:l.companion_name,children:l.node_name||l.companion_name},l.companion_name))})}),Oe=[{value:"Chat Node",label:"Companions"},{value:"Room Server",label:"Room Servers"},{value:"Repeater",label:"Repeaters"}],Ti=[{value:"all",label:"All time"},{value:"24h",label:"Last 24 hours"},{value:"7d",label:"Last 7 days"},{value:"30d",label:"Last 30 days"}];function $i(t){switch(t){case"24h":return 24;case"7d":return 168;case"30d":return 720;default:return}}function Di({open:t,onClose:s,companionName:a,onImport:r}){const[l,i]=n.useState(()=>new Set(Oe.map(R=>R.value))),[o,x]=n.useState("all"),[p,j]=n.useState(""),[c,f]=n.useState(!1),[y,b]=n.useState(null),[d,N]=n.useState(t);t!==d&&(N(t),t&&(i(new Set(Oe.map(R=>R.value))),x("all"),j(""),f(!1),b(null)));const S=l.size===Oe.length;function h(R){i(w=>{const C=new Set(w);return C.has(R)?C.delete(R):C.add(R),C})}function _(){i(S?new Set:new Set(Oe.map(R=>R.value)))}const E=n.useCallback(async()=>{if(!(l.size===0||c)){f(!0),b(null);try{const R={types:[...l],hours:$i(o)},w=parseInt(p,10);w>0&&(R.limit=w);const C=await r(R);b(C)}finally{f(!1)}}},[l,o,p,c,r]);return e.jsxs(je,{open:t,onClose:s,size:"sm",children:[e.jsx(Ee,{title:"Import repeater contacts",onClose:s}),e.jsx(we,{children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("p",{className:"text-sm text-fg-secondary",children:["Seed ",e.jsx("strong",{className:"text-fg-primary",children:a})," with contacts from the repeater's adverts. Results are ordered by most recent first."]}),e.jsxs(re,{children:[e.jsx(le,{children:"Contact types"}),e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsx(ws,{checked:S,indeterminate:l.size>0&&!S,onChange:_,label:"All types",size:"sm"}),e.jsx("div",{className:"ml-6 space-y-1.5",children:Oe.map(R=>e.jsx(ws,{checked:l.has(R.value),onChange:()=>h(R.value),label:R.label,size:"sm"},R.value))})]})]}),e.jsx(fo,{label:"Recency",value:o,onChange:x,options:Ti,orientation:"horizontal",size:"sm"}),e.jsxs(re,{children:[e.jsxs(le,{children:["Import at most ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(optional)"})]}),e.jsx(pe,{type:"number",min:1,value:p,onChange:R=>j(R.target.value),placeholder:"No limit",className:"mt-1"}),e.jsx(ke,{children:"Leave empty for no cap."})]}),y&&e.jsxs("p",{className:"text-sm text-sys-green font-medium",children:["Imported ",y.added," new contact",y.added!==1?"s":""," (",y.total," total)"]})]})}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Cancel"}),e.jsx(B,{color:"primary",onClick:E,disabled:c||l.size===0,children:c?e.jsxs(e.Fragment,{children:[e.jsx(oe,{"data-slot":"icon",className:"animate-spin"}),"Importing…"]}):"Import"})]})]})}const Fi=["alameda","alpine","amador","butte","calaveras","colusa","contracosta","contra-costa","delnorte","del-norte","eldorado","el-dorado","fresno","glenn","humboldt","imperial","inyo","kern","kings","lake","lassen","losangeles","los-angeles","la-county","madera","marin","mariposa","mendocino","merced","modoc","mono","monterey","napa","nevada","orange","oc","placer","plumas","riverside","sacramento","sac","sanbenito","san-benito","sanbernardino","san-bernardino","sandiego","san-diego","sd","sanfrancisco","san-francisco","sf","sanjoaquin","san-joaquin","sanluisobispo","san-luis-obispo","slo","sanmateo","san-mateo","santabarbara","santa-barbara","sb","santaclara","santa-clara","santacruz","santa-cruz","shasta","sierra","siskiyou","solano","sonoma","stanislaus","sutter","tehama","trinity","tulare","tuolumne","ventura","yolo","yuba","losangeles","los-angeles","la","hollywood","westhollywood","west-hollywood","weho","beverlyhills","beverly-hills","santamonica","santa-monica","culvercity","culver-city","marinadelrey","marina-del-rey","venice","venicebeach","venice-beach","malibu","palisades","pacificpalisades","pacific-palisades","brentwood","westwood","westla","west-la","dtla","downtown","downtownla","downtown-la","koreatown","ktown","silverlake","silver-lake","losfeliz","los-feliz","echopark","echo-park","eastla","east-la","boyleheights","boyle-heights","highlandpark","highland-park","eaglerock","eagle-rock","pasadena","southpasadena","south-pasadena","glendale","burbank","tolucalake","toluca-lake","studiocity","studio-city","shermanoaks","sherman-oaks","encino","tarzana","reseda","vannuys","van-nuys","northhollywood","north-hollywood","noho","woodlandhills","woodland-hills","calabasas","topanga","agourahills","agoura-hills","thousandoaks","thousand-oaks","simivalley","simi-valley","simi","moorpark","camarillo","oxnard","porthueneme","port-hueneme","ventura","ojai","sfv","sfvalley","sf-valley","thevalley","the-valley","sanfernando","san-fernando","sanfernandovalley","san-fernando-valley","pacoima","sylmar","sunland","tujunga","sunlandtujunga","lakeviewterrace","lakeview-terrace","shadowhills","shadow-hills","chatsworth","northridge","granadahills","granada-hills","missionhills","mission-hills","panoramacity","panorama-city","arleta","sunvalley","sun-valley","santaclarita","santa-clarita","scv","valencia","newhall","saugus","canyoncountry","canyon-country","castaic","stevenson","stevensonranch","stevenson-ranch","acton","agua-dulce","aguadulce","palmdale","lancaster","antelopevalley","antelope-valley","av","avmesh","av-mesh","quartz-hill","quartzhill","littlerock","little-rock","pearblossom","pear-blossom","lakelosangeles","lake-los-angeles","highdesert","high-desert","hd","hdmesh","hd-mesh","victorville","hesperia","applevalley","apple-valley","barstow","adelanto","phelan","pinon-hills","pinonhills","wrightwood","bigbear","big-bear","lakeisabella","lake-isabella","inlandempire","inland-empire","ie","riverside","corona","moreno-valley","morenovalley","fontana","ontario","rancho","ranchocucamonga","rancho-cucamonga","upland","claremont","pomona","azusa","glendora","covina","westcovina","west-covina","diamondbar","diamond-bar","chino","chinohills","chino-hills","sanbernardinocity","rialto","colton","redlands","yuciapa","yucaipa","beaumont","banning","hemet","perris","menifee","temecula","murrieta","wildomar","lakeland","lakeelsinore","lake-elsinore","orangecounty","orange-county","oc","anaheim","fullerton","santaana","santa-ana","irvine","costamesa","costa-mesa","newportbeach","newport-beach","newport","huntingtonbeach","huntington-beach","hb","surfcity","surf-city","lagunabeach","laguna-beach","lagunaniguel","laguna-niguel","sanclemente","san-clemente","danapoint","dana-point","missionviejo","mission-viejo","lakeforest","lake-forest","rsm","ranchosantamargarita","rancho-santa-margarita","alisoviejo","aliso-viejo","tustin","orange","yorbalinda","yorba-linda","brea","lahabra","la-habra","placentia","buenapark","buena-park","cypress","losalamitojos","sealbeach","seal-beach","gardengrove","garden-grove","westminster","stanton","fountainvalley","sandiego","san-diego","sd","sdmesh","sd-mesh","lajolla","la-jolla","pacificbeach","pacific-beach","pb","missionbeach","mission-beach","oceanbeach","ocean-beach","ob","pointloma","point-loma","coronado","hillcrest","northpark","north-park","southpark","south-park","normalheights","normal-heights","cityheights","city-heights","lamesa","la-mesa","elcajon","el-cajon","santee","lakeside","poway","ramona","julian","alpine","escondido","sanmarcos","san-marcos","vista","oceanside","carlsbad","encinitas","delmar","del-mar","solanabeanch","solana-beach","chulavista","chula-vista","nationalcity","national-city","imperialbeach","imperial-beach","ib","southbay","south-bay","torrance","gardena","hawthorne","lawndale","redondo","redondobeach","hermosa","hermosabeach","manhattan","manhattanbeach","manhattan-beach","elsegundo","el-segundo","palosverdes","palos-verdes","pv","ranchopalosverdes","rancho-palos-verdes","sanpedro","san-pedro","wilmington","carson","compton","longbeach","long-beach","lb","signalhill","signal-hill","lakewood","cerritos","artesia","lamirada","la-mirada","norwalk","whittier","lahabra","la-habra-heights","downey","bellflower","paramount","southgate","south-gate","lynwood","bellgardens","bell-gardens","cudahy","huntingtonpark","maywood","vernon","commerce","montebello","picorivera","pico-rivera","montereypark","monterey-park","alhambra","sanmarinno","san-marino","arcadia","monrovia","duarte","azusa","irwindale","baldwinpark","baldwin-park","elmonbte","el-monte","southelmonte","south-el-monte","rosemead","temple-city","templecity","sangabriel","san-gabriel","santabarbara","santa-barbara","sb","goleta","carpinteria","montecito","islavista","isla-vista","iv","ucsb","slo","sanluisobispo","san-luis-obispo","morrobay","morro-bay","pismobeach","pismo-beach","pismo","shellbeach","shell-beach","arroyogrande","arroyo-grande","groverbeach","grover-beach","oceano","santamaria","santa-maria","lompoc","vandenberg","solvang","buellton","losalamos","los-alamos","atascadero","pasorobles","paso-robles","paso","cambria","cayucos","sansiemon","san-simeon","hearst","fresno","clovis","visalia","tulare","hanford","porterville","bakersfield","bako","delano","wasco","shafter","taft","tehachapi","stockton","tracy","manteca","lodi","modesto","turlock","merced","madera","chowchilla","losabnos","los-banos","sacramento","sac","sactown","westsacramento","west-sacramento","westsac","elkgrove","elk-grove","folsom","ranchocordova","rancho-cordova","roseville","rocklin","lincoln","citrus-heights","citrusheights","fair-oaks","fairoaks","carmichael","orangevale","davis","woodland","dixon","vacaville","fairfield","vallejo","bayarea","bay-area","sfbay","sf-bay","sanfrancisco","san-francisco","sf","sfmesh","sf-mesh","oakland","eastbay","east-bay","berkeley","emeryville","alameda","sanleandro","san-leandro","hayward","fremont","unioncity","union-city","newark","milpitas","sanjose","san-jose","sj","campbell","saratoga","losgartos","los-gatos","sunnyvale","santaclara","santa-clara","cupertino","mountainview","mountain-view","paloalto","palo-alto","menlopark","menlo-park","atherton","redwoodcity","redwood-city","sancarlos","san-carlos","belmont","sanmateo","san-mateo","fostercity","foster-city","burlingame","sanbruno","san-bruno","southsanfrancisco","ssf","dalycity","daly-city","pacifica","halfmoonbay","half-moon-bay","hmb","santacruz","santa-cruz","capitola","scottsvalley","scotts-valley","watsonville","aptos","soquel","concord","walnutcreek","walnut-creek","pleasant-hill","pleasanthill","martinez","antioch","pittsburg","brentwood","oakley","discovery-bay","livermore","pleasanton","dublin","sanramon","san-ramon","danville","richmond","sanpablo","san-pablo","pinole","hercules","napa","sonoma","petaluma","santarosa","santa-rosa","rohnertpark","novato","sanrafael","san-rafael","sausalito","tiburon","millvalley","mill-valley","redding","chico","oroville","paradise","reddingbluff","redbluff","red-bluff","shasta","mtshasta","mt-shasta","eureka","arcata","fortuna","mckibleyville","ukiah","fortbragg","fort-bragg","willits","yreka","weed","dunsmuir","tahoe","laketahoe","lake-tahoe","southlaketahoe","south-lake-tahoe","truckee","squaw","squawvalley","squaw-valley","northstar","mammoth","mammothlakes","mammoth-lakes","bishopca","bishop","placerville","tahoe-city","tahoecity","kings-beach","kingsbeach","incline","inclinevillage","incline-village","maricopa","pima","pinal","yavapai","yuma","mohave","coconino","cochise","navajo","apache","gila","santacruzaz","graham","lapaz","la-paz","greenlee","arizona","az","azmesh","az-mesh","phoenix","phx","phoenixmesh","phoenix-mesh","scottsdale","tempe","mesa","gilbert","chandler","glendale","peoria","surprize","avondale","goodyear","buckeye","litchfieldpark","litchfield-park","tolleson","laveen","paradisevalley","paradise-valley","pv","carefree","cavekreek","cave-creek","fountainhills","fountain-hills","rioverde","rio-verde","queencreek","queen-creek","santan","san-tan","santanvalley","ahwatukee","southmountain","south-mountain","anthem","newriver","new-river","apachejunction","apache-junction","aj","goldcanyon","gold-canyon","tucson","tucsomesh","tucson-mesh","orovalley","oro-valley","marana","catalina","catalinafoothills","saddlebrooke","casagrande","casa-grande","eloy","coolidge","florence","sierravista","sierra-vista","bisbee","tombstone","benson","douglas","nogales","tubac","greenvalley","green-valley","sahuarita","flagstaff","flag","flagmesh","sedona","cottonwood","clarkdale","prescott","prescottvalley","prescott-valley","dewey","chino-valley","chinovalley","williams","grandcanyon","grand-canyon","tusayan","page","marble-canyon","showlow","show-low","pinetop","pinetoplakeside","lakeside","snowflake","taylor","payson","pine","strawberry","camp-verde","campverde","winslow","holbrook","stjohns","springerville","eagar","yuma","yumamesh","fortuna-foothills","sanluisaz","san-luis","lakehavasu","lake-havasu","havasu","havasucity","lake-havasu-city","bullheadcity","bullhead-city","bullhead","laughlin","kingman","goldenkvalley","golden-valley","parker","quartzsite","wickenburg","lasvegas","las-vegas","vegas","vegasmesh","vegas-mesh","lv","henderson","boulder-city","bouldercity","northlasvegas","north-las-vegas","nlv","summerlin","enterprise","pahrump","mesquite","reno","sparks","carsoncity","carson-city","incline","bajacalifornia","baja-california","baja","bajamesh","tijuana","tj","mexicali","ensenada","tecate","rosarito","sanfelipe","san-felipe","sanluis","sanluisriocoalorado","brabant","flevoland","gelderland","noordbrabant","noordholland","zuid-holland","zuidholland","zeeland","twente","alkmaar","almere","amsterdam","amstelland","capelleaandenijssel","denhaag","dordrecht","drechtsteden","eindhoven","haarlem","hellevoetsluis","hilversum","katwijk","lelystad","maassluis","middelburg","rijnmond","rotterdam","tilburg","utrecht","vlissingen","voorburg","voorne-putten","walcheren","west-friesland","zaandam","zaanstreek-waterland","024-bot","afrithonbot","ai","amradio","analyser","angrynerds","bemesh","bot","buch","burgernet","chat","chatgpt","dares","dekroeg","dtis","emergency","english","evenvroegopstaan","fosdem","gezellig","gmr","gmrbot","goedemorgen","gyverbot","haagscourant","hackerspacenijmegen","hamradio","hamradionederland","hetweerinjegemeente","hsnl","jokes","kanalen","koffie","linux","meshcore","nerd","nl-alert","nl-prio","noodkanaal","nsagov","pi4hm","pi4utr","pingbot","sensemakers","sports","survival","test","testing","uitdagingen","valleibot","valleirug","vleesboek","wardrive","weer","swl","qso","qrz","cq","dx","sstv","aprs","winlink","aredn","hamnet","emcomm","emcommplanning","races","ares","auxcomm","simplex","repeater","uhf","vhf","2m","70cm","440"],Li=new Set(Fi);function Ai(){return crypto.getRandomValues(new Uint8Array(16))}function Xs(t){return Array.from(t).map(s=>s.toString(16).padStart(2,"0")).join("")}function vt(t){const s=t.replace(/\s/g,"");if(s.length!==32||!/^[0-9a-fA-F]+$/.test(s))return null;const a=new Uint8Array(16);for(let r=0;r<16;r++)a[r]=parseInt(s.slice(r*2,r*2+2),16);return a}async function Oi(t){const a=`#${ia(t)}`,r=new TextEncoder().encode(a);return(await lr(r)).slice(0,16)}const Js=[{key:"create-private",label:"Create Private",icon:qr,desc:"Generate a new private channel with a random key"},{key:"join-private",label:"Join Private",icon:Yl,desc:"Join an existing private channel using a shared key"},{key:"join-hashtag",label:"Join Hashtag",icon:Fe,desc:"Join a public hashtag channel (key derived from name)"}];function zi({open:t,onClose:s,channels:a,onAddChannel:r}){var I;const[l,i]=n.useState("join-hashtag"),[o,x]=n.useState(""),[p,j]=n.useState(""),[c,f]=n.useState(null),[y,b]=n.useState(!1),[d,N]=n.useState(""),[S,h]=n.useState(!1),[_,E]=n.useState(t);t!==_&&(E(t),t&&(i("join-hashtag"),x(""),j(""),f(null),b(!1),N(""),h(!1)));const R=n.useMemo(()=>a.length===0?0:Math.max(...a.map(g=>g.index))+1,[a]),w=n.useMemo(()=>l!=="join-hashtag"?"":ia(o),[l,o]),C=n.useMemo(()=>{if(!o.trim())return null;const g=l==="join-hashtag"&&w?`#${w}`:o.trim();return a.find($=>$.name===g)??null},[o,l,w,a]),T=n.useMemo(()=>l==="join-hashtag"&&w?Li.has(w):!1,[l,w]),v=n.useMemo(()=>{if(!o.trim()||C)return!1;switch(l){case"create-private":return o.trim().length>0&&o.trim().length<=32;case"join-private":return o.trim().length>0&&vt(p)!==null;case"join-hashtag":return w.length>0;default:return!1}},[l,o,p,w,C]),u=n.useCallback(async()=>{c&&(await navigator.clipboard.writeText(Xs(c)),h(!0),setTimeout(()=>h(!1),2e3))},[c]),m=n.useCallback(async()=>{if(!(!v||y)){b(!0),N("");try{let g,$;switch(l){case"create-private":{g=Ai(),$=o.trim();break}case"join-private":{const H=vt(p);if(!H){N("Invalid hex key (must be 32 hex chars = 16 bytes)");return}g=H,$=o.trim();break}case"join-hashtag":{g=await Oi(o),$=`#${w}`;break}default:return}if(await r(R,$,g)){if(l==="create-private"){f(g);return}s()}else N("Failed to add channel — device may be unreachable")}catch(g){N(g instanceof Error?g.message:"Unknown error")}finally{b(!1)}}},[v,y,l,o,p,w,R,r,s]);return e.jsxs(je,{open:t,onClose:s,size:"sm",children:[e.jsx(Ee,{title:"Add Channel",onClose:s}),e.jsx(we,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-1 p-0.5 radius-inner bg-zinc-950/5",children:Js.map(g=>{const $=g.icon,k=l===g.key;return e.jsxs("button",{onClick:()=>{i(g.key),N(""),f(null)},className:P("flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors",k?"bg-surface text-fg-primary shadow-sm":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx($,{className:"w-3.5 h-3.5"}),g.label]},g.key)})}),e.jsx("p",{className:"text-xs text-fg-muted",children:(I=Js.find(g=>g.key===l))==null?void 0:I.desc}),c&&l==="create-private"&&e.jsxs("div",{className:"p-3 radius-inner bg-sys-green/8 border border-sys-green/20 space-y-2",children:[e.jsx("p",{className:"text-xs text-sys-green font-medium",children:"Channel created! Share this key with others:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 text-[11px] font-mono text-fg-primary bg-zinc-950/10 px-2 py-1 rounded break-all",children:Xs(c)}),e.jsx("button",{onClick:u,className:"p-1.5 rounded hover:bg-subtle-fill transition-colors flex-shrink-0",title:"Copy key",children:S?e.jsx(be,{className:"w-3.5 h-3.5 text-sys-green"}):e.jsx(Et,{className:"w-3.5 h-3.5 text-fg-muted"})})]}),e.jsx("p",{className:"text-[11px] text-fg-muted",children:"Save this key — it cannot be recovered later."})]}),e.jsxs(re,{children:[e.jsx(le,{children:l==="join-hashtag"?"Hashtag name":"Channel name"}),e.jsx(pe,{type:"text",value:o,onChange:g=>x(g.target.value),placeholder:l==="join-hashtag"?"e.g. south-bay":"e.g. My Channel",maxLength:32,className:"mt-1",disabled:!!c}),l==="join-hashtag"&&w&&w!==o&&e.jsxs(ke,{className:"mt-1",children:["Will be registered as ",e.jsxs("code",{className:"text-fg-primary font-mono text-[11px]",children:["#",w]})]}),l==="join-hashtag"&&T&&e.jsx(ke,{className:"mt-1 text-sys-green",children:"Known region channel"})]}),C&&e.jsxs("div",{className:"flex items-start gap-2 p-2.5 radius-inner bg-sys-red/8 border border-sys-red/20",children:[e.jsx(Be,{className:"w-3.5 h-3.5 text-sys-red flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs text-fg-secondary",children:["Channel ",e.jsx("strong",{className:"text-fg-primary",children:C.name})," already exists at slot ",C.index,". Remove it first to re-add."]})]}),l==="join-private"&&e.jsxs(re,{children:[e.jsxs(le,{children:["Channel key ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(32 hex chars)"})]}),e.jsx(pe,{type:"text",value:p,onChange:g=>j(g.target.value),placeholder:"e.g. a1b2c3d4e5f6...",maxLength:32,className:"mt-1 font-mono text-xs"}),p&&!vt(p)&&e.jsx(ke,{className:"mt-1 text-sys-red",children:"Must be exactly 32 hex characters (16 bytes)"})]}),e.jsxs("p",{className:"text-[11px] text-fg-muted",children:["Will be assigned to channel slot ",e.jsx("strong",{className:"text-fg-primary",children:R})]}),d&&e.jsx("p",{className:"text-xs text-sys-red font-medium",children:d})]})}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:c?"Done":"Cancel"}),!c&&e.jsx(B,{color:"primary",onClick:m,disabled:!v||y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-4 h-4 animate-spin"}),"Adding…"]}):l==="create-private"?"Create Channel":"Join Channel"})]})]})}const Hi=202,Bi=/^[0-9a-fA-F]+$/;function Gi(t){const s=t.replace(/\s/g,"");return s.length>=Hi&&s.length%2===0&&Bi.test(s)}const Ki=n.memo(function({open:s,onClose:a,contacts:r,exportPubKey:l,onExport:i,onImport:o}){const[x,p]=n.useState(l?"export":"import"),[j,c]=n.useState(l??""),[f,y]=n.useState(""),[b,d]=n.useState(""),[N,S]=n.useState(!1),[h,_]=n.useState(!1),[E,R]=n.useState(!1),[w,C]=n.useState(null),[T,v]=n.useState(!1),u=n.useRef(null);n.useEffect(()=>{s&&(p(l?"export":"import"),c(l??""),y(""),d(""),S(!1),_(!1),R(!1),C(null),v(!1))},[s,l]);const m=n.useCallback(()=>{a()},[a]),I=n.useCallback(async()=>{if(!j)return;S(!0),C(null),y("");const k=await i(j);S(!1),k?y(k):C("Failed to export contact advert")},[j,i]),g=n.useCallback(async()=>{if(f)try{await navigator.clipboard.writeText(f),R(!0),setTimeout(()=>R(!1),2e3)}catch{C("Failed to copy to clipboard")}},[f]),$=n.useCallback(async()=>{const k=b.replace(/\s/g,"");if(!Gi(k)){C("Invalid hex — must be at least 202 hex characters (101 bytes)");return}_(!0),C(null);const H=await o(k);_(!1),H?(v(!0),d(""),setTimeout(()=>m(),1500)):C("Import failed — check the hex string and try again")},[b,o,m]);return e.jsxs(je,{open:s,onClose:m,children:[e.jsx(or,{children:"Contact Import / Export"}),e.jsxs(we,{children:[e.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg bg-subtle-fill mb-4",children:[e.jsxs("button",{onClick:()=>{p("export"),C(null)},className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 rounded-md text-xs font-medium transition-colors",x==="export"?"bg-surface shadow-sm text-fg-primary":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),"Export"]}),e.jsxs("button",{onClick:()=>{p("import"),C(null)},className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 rounded-md text-xs font-medium transition-colors",x==="import"?"bg-surface shadow-sm text-fg-primary":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx(He,{className:"w-3.5 h-3.5"}),"Import"]})]}),x==="export"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-fg-muted mb-1",children:"Select contact"}),e.jsxs("select",{value:j,onChange:k=>{c(k.target.value),y(""),C(null)},className:"w-full surface-input rounded-lg px-3 py-2 text-sm text-fg-primary",children:[e.jsx("option",{value:"",children:"Choose a contact…"}),r.map(k=>e.jsx("option",{value:k.public_key,children:k.name||k.public_key.slice(0,12)},k.public_key))]})]}),e.jsx(B,{color:"primary",outline:!0,className:"w-full justify-center",disabled:!j||N,onClick:I,children:N?"Exporting…":"Export Advert"}),f&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{readOnly:!0,value:f,rows:4,className:"w-full surface-input rounded-lg px-3 py-2 text-[10px] font-mono text-fg-primary break-all resize-none"}),e.jsxs(B,{color:E?"success":"primary",outline:!0,className:"w-full justify-center",onClick:g,children:[E?e.jsx(be,{"data-slot":"icon"}):e.jsx(Et,{"data-slot":"icon"}),E?"Copied!":"Copy to Clipboard"]})]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-fg-muted mb-1",children:"Paste advert hex string"}),e.jsx("textarea",{ref:u,value:b,onChange:k=>{d(k.target.value),C(null),v(!1)},placeholder:"Paste exported advert hex here…",rows:4,className:"w-full surface-input rounded-lg px-3 py-2 text-[10px] font-mono text-fg-primary break-all resize-none placeholder:text-fg-muted/50"}),e.jsx("p",{className:"text-[10px] text-fg-muted/70 mt-1",children:"Minimum 101 bytes (202 hex characters): 32B pubkey + 4B timestamp + 64B signature + appData"})]}),T&&e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-sys-green/10 text-sys-green text-xs font-medium",children:[e.jsx(be,{className:"w-3.5 h-3.5"}),"Contact imported successfully"]}),e.jsx(B,{color:"primary",outline:!0,className:"w-full justify-center",disabled:!b.trim()||h,onClick:$,children:h?"Importing…":"Import Contact"})]}),w&&e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 mt-3 rounded-lg bg-sys-red/10 text-sys-red text-xs",children:[e.jsx(ua,{className:"w-3.5 h-3.5 flex-shrink-0"}),w]})]}),e.jsx(Me,{children:e.jsx(B,{plain:!0,onClick:m,children:"Close"})})]})});function Cc(){var us,ms,ps,hs,xs,fs;const t=ir(),s=la(),a=cr(),r=dr(),l=ur(),i=mr(),o=mt(),x=pr(),p=hr(),j=xr(),c=fr(),f=n.useMemo(()=>{if(l.length===0)return r;const M=new Set(r.map(z=>z.public_key));return[...r,...l.filter(z=>!M.has(z.public_key))]},[r,l]),y=n.useMemo(()=>{const M=new Set;if(!(c!=null&&c.neighbors))return M;const z=[];for(const[K,J]of Object.entries(c.neighbors))J.zero_hop&&z.push((K.startsWith("0x")?K.slice(2):K).toLowerCase());for(const K of f){const J=K.public_key.toLowerCase();for(const ce of z)if(J===ce||J.startsWith(ce)){M.add(K.public_key);break}}return M},[c==null?void 0:c.neighbors,f]),b=n.useMemo(()=>{const M=new Map;if(!(c!=null&&c.neighbors))return M;const z=[];for(const[K,J]of Object.entries(c.neighbors))J.zero_hop&&J.rssi!=null&&J.snr!=null&&J.rssi!==0&&z.push({hash:(K.startsWith("0x")?K.slice(2):K).toLowerCase(),rssi:J.rssi,snr:J.snr,advertCount:J.advert_count??1});if(z.length===0)return M;for(const K of f){const J=K.public_key.toLowerCase();for(const ce of z)if(J===ce.hash||J.startsWith(ce.hash)){M.set(K.public_key,{rssi:ce.rssi,snr:ce.snr,advertCount:ce.advertCount});break}}return M},[c==null?void 0:c.neighbors,f]),d=gr(),N=yr(),S=oa(),h=br(),_=vr(),E=jr(),R=wr(),w=Nr(),[C,T]=kr(),[v,u]=n.useState(!1),[m,I]=n.useState(!1),[g,$]=n.useState(!1),[k,H]=n.useState(!1),[te,W]=n.useState(null),[L,V]=n.useState(!1),[ie,F]=n.useState(!1),[D,A]=n.useState(!0),O="pymc_companion_contacts_micro",G="pymc_companion_split",[Q,ht]=n.useState(()=>{try{return localStorage.getItem(O)==="1"}catch{return!1}}),We=25,Gt=75,[xt,Kt]=n.useState(()=>{try{const M=Number(localStorage.getItem(G));return M>=We&&M<=Gt?M:50}catch{return 50}}),Qe=n.useRef(null),Le=n.useRef(null),Ut=n.useRef(null),Ye=n.useRef(!1),Ae=n.useRef(xt);Ae.current=xt;const Ea=n.useCallback(M=>{M.preventDefault(),M.target.setPointerCapture(M.pointerId),Ye.current=!0},[]),Ma=n.useCallback(M=>{if(!Ye.current||!Qe.current)return;const z=Qe.current.getBoundingClientRect(),K=Math.round(Math.min(Gt,Math.max(We,(M.clientX-z.left)/z.width*100)));Ae.current=K,Le.current&&(Le.current.style.width=`${K}%`)},[]),qt=n.useCallback(()=>{if(!Ye.current)return;Ye.current=!1;const M=Ae.current;Kt(M);try{localStorage.setItem(G,String(M))}catch{}},[]),Pa=n.useCallback(()=>{Ae.current=50,Le.current&&tt(Le.current,{width:"50%"},de.layoutResize),Kt(50);try{localStorage.setItem(G,String(50))}catch{}},[]),Ta=n.useCallback(M=>{ht(M);const z=Qe.current,K=Ut.current;if(!z)return;const J=z.getBoundingClientRect().width;z.style.width=M?"var(--companion-side-micro)":"var(--companion-side)";const ce=z.getBoundingClientRect().width;if(z.style.width=`${J}px`,K){const sn=M?56:Ae.current/100*ce,an=K.offsetWidth,nn=Math.max(0,ce-sn-12);K.style.flex="none",K.style.width=`${an}px`,tt(K,{width:`${nn}px`},{...de.layoutResize,onComplete(){K.style.flex="",K.style.width=""}})}tt(z,{width:`${ce}px`},{...de.layoutResize,onComplete(){z.style.width=M?"var(--companion-side-micro)":"var(--companion-side)"}})},[]),{selectCompanion:$a,selectConversation:ve,sendMessage:Vt,sendChannelMessage:Wt,retryMessage:Da,retryMessageAsFlood:Fa,resetPath:ft,shareContact:La,removeContact:Aa,addChannel:Oa,requestStatus:Qt,requestTelemetry:Yt,loginToRepeater:gt,logoutFromRepeater:Xt,getNeighbours:Jt,traceContactPath:Zt,discoverPath:es,pingContact:za,markAsRead:ts,fetchCompanions:ss,seedFromRepeater:Ha,exportContactAdvert:Ba,importContactAdvert:Ga,setContactPath:as,deleteChannel:Ka,loadOlderMessages:Ua}=se.getState(),qa=n.useCallback(M=>{ve(M),window.innerWidth>=1280?V(!0):F(!0)},[ve]),ns=se(M=>M.messages),rs=se(M=>M.unreadMap);n.useEffect(()=>{ts()},[d,ts]),n.useEffect(()=>{const M=C.get("dm");M&&f.length>0&&f.find(K=>K.public_key===M)&&(ve({type:"contact",id:M}),T({},{replace:!0}))},[C,f,ve,T]);const Va=n.useMemo(()=>{const M=new Set;for(const z of f)z.name&&M.add(z.name);for(const z of N)z.sender_name&&!z.is_outgoing&&M.add(z.sender_name);return[...M].sort((z,K)=>z.localeCompare(K))},[f,N]),ls=n.useMemo(()=>{const M=new Map;for(const z of f)z.name&&M.set(z.name.toLowerCase(),z.public_key);for(const z of N)if(z.sender_name&&z.sender_key&&z.sender_key!=="unknown"&&!z.is_outgoing){const K=z.sender_name.toLowerCase();M.has(K)||M.set(K,z.sender_key)}return M},[f,N]),Wa=n.useCallback(M=>{const z=ls.get(M.toLowerCase());z&&(ve({type:"contact",id:z}),V(!0))},[ls,ve]),Qa=n.useCallback(async M=>d?d.type==="channel"?Wt(Number(d.id),M):Vt(d.id,M):!1,[d,Vt,Wt]),Ya=S&&!h,os=E!=null&&(E.adv_type&15)===3,is=It(os?E.public_key:null),Xa=os&&is!=="success",cs=Cr(),[me,Pe]=n.useState("idle"),Ja=n.useCallback(async()=>{Pe("flood-sending");const M=await se.getState().sendFloodAdvert();Pe(M?"flood-done":"idle"),M&&setTimeout(()=>Pe(z=>z==="flood-done"?"idle":z),2e3)},[]),Za=n.useCallback(async()=>{Pe("zero-sending");const M=await se.getState().sendZeroHopAdvert();Pe(M?"zero-done":"idle"),M&&setTimeout(()=>Pe(z=>z==="zero-done"?"idle":z),2e3)},[]),en=e.jsxs("div",{className:"flex items-center gap-2",children:[S&&a&&e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsxs("button",{onClick:Ja,disabled:me!=="idle"&&me!=="zero-done",className:P("inline-flex items-center gap-2 px-3.5 py-2 rounded-xl text-xs font-semibold transition-all duration-150","bg-surface depth-raised-soft hover:depth-raised active:depth-inset","disabled:opacity-50 disabled:cursor-not-allowed",me==="flood-done"?"text-sys-green":"text-fg-secondary hover:text-fg-primary"),title:"A Flood Advert will announce your presence and broadcast your node ID and name anywhere a repeater will repeat it",children:[me==="flood-sending"?e.jsx(oe,{className:"w-4 h-4 animate-spin"}):e.jsx(no,{className:"w-4 h-4"}),e.jsx("span",{children:me==="flood-done"?"Sent!":"Flood Advert"})]}),e.jsxs("button",{onClick:Za,disabled:me!=="idle"&&me!=="flood-done",className:P("inline-flex items-center gap-2 px-3.5 py-2 rounded-xl text-xs font-semibold transition-all duration-150","bg-surface depth-raised-soft hover:depth-raised active:depth-inset","disabled:opacity-50 disabled:cursor-not-allowed",me==="zero-done"?"text-sys-green":"text-fg-secondary hover:text-fg-primary"),title:"A Local Advert, or “Zero Hop” advert will not be repeated by local repeaters, but will be heard by those within range",children:[me==="zero-sending"?e.jsx(oe,{className:"w-4 h-4 animate-spin"}):e.jsx(Na,{className:"w-4 h-4"}),e.jsx("span",{children:me==="zero-done"?"Sent!":"Local Advert"})]})]}),e.jsx("button",{onClick:()=>Sr.getState().toggleFocusMode(),className:"hidden lg:flex p-1.5 hover:bg-subtle-fill rounded transition-colors",title:cs?"Collapse view":"Expand view",children:cs?e.jsx(tl,{className:"w-4 h-4 text-fg-muted"}):e.jsx(sl,{className:"w-4 h-4 text-fg-muted"})})]}),tn=e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 flex-shrink-0",children:[e.jsx(ge,{children:j.length>0&&e.jsx(ue.div,{layout:!0,initial:{opacity:0,scale:.9,width:0},animate:{opacity:1,scale:1,width:"auto"},exit:{opacity:0,scale:.9,width:0},transition:de.fade,className:"flex items-center gap-1 overflow-hidden",children:j.map(M=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-sys-green/10 text-[11px] text-sys-green font-medium whitespace-nowrap",children:[e.jsx(ze,{className:"w-2.5 h-2.5"}),M.name]},M.pubHex))},"advert-notifs")}),e.jsx(ge,{children:!S&&e.jsxs(ue.span,{initial:{opacity:0,scale:.9,width:0},animate:{opacity:1,scale:1,width:"auto"},exit:{opacity:0,scale:.9,width:0},transition:de.fade,className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-sys-amber/10 text-[11px] text-sys-amber font-medium whitespace-nowrap overflow-hidden",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5 flex-shrink-0",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-sys-amber opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-sys-amber"})]}),"Reconnecting…"]},"disconnected")}),a&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>I(!0),disabled:x,className:"data-box flex items-center gap-1 cursor-pointer hover:bg-subtle-fill-strong transition-colors disabled:opacity-50",title:p>0?`${p} contacts seeded from repeater — click to refresh`:"Seed contacts from repeater adverts",children:[x?e.jsx(oe,{className:"w-3.5 h-3.5 text-sys-blue animate-spin"}):e.jsx(mo,{className:"w-3.5 h-3.5 text-sys-blue"}),p>0&&e.jsxs("span",{className:"text-sys-blue",children:["+",p]})]}),e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:`${f.length} contacts${p>0?` (${p} from repeater)`:""}`,children:[e.jsx(wt,{className:"w-3.5 h-3.5 text-fg-secondary"}),e.jsx("span",{children:f.length})]}),e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:`${a.channels_count} channels`,children:[e.jsx(Fe,{className:"w-3.5 h-3.5 text-fg-secondary"}),e.jsx("span",{children:a.channels_count})]})]}),e.jsx(Pi,{companions:t,selected:s,onSelect:$a}),e.jsx(B,{plain:!0,onClick:()=>u(!0),title:"Companion configuration",children:e.jsx(_r,{"data-slot":"icon"})})]});if(t.length===0&&!h)return e.jsxs(Ns,{children:[e.jsx(ks,{title:"Companion",icon:e.jsx(ye,{}),controls:e.jsxs(B,{color:"primary",outline:!0,onClick:()=>u(!0),children:[e.jsx(Ue,{"data-slot":"icon"}),"Add Companion"]})}),e.jsx(Cs,{ready:!0,children:e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-subtle-fill mx-auto mb-4 flex items-center justify-center",children:e.jsx(ye,{className:"w-7 h-7 text-fg-muted/50"})}),e.jsx("p",{className:"type-body text-fg-muted mb-1",children:"No companions configured"}),e.jsx("p",{className:"type-body-sm text-fg-muted/70 mb-4",children:"Add a companion to start messaging mesh contacts"}),e.jsxs(B,{color:"primary",outline:!0,onClick:()=>u(!0),children:[e.jsx(Ue,{"data-slot":"icon"}),"Add Companion"]})]})}),e.jsx(Ys,{open:v,onClose:()=>u(!1),onRefresh:ss})]});const ds=d?d.type==="channel"?((us=i.find(M=>String(M.index)===d.id))==null?void 0:us.name)??"Channel":((ms=f.find(M=>M.public_key===d.id))==null?void 0:ms.name)??d.id.slice(0,8):null;return e.jsxs(Ns,{children:[e.jsx(ks,{title:(o==null?void 0:o.node_name)||"Companion",icon:e.jsx(ye,{}),leading:en,controls:tn}),e.jsx(Cs,{children:e.jsxs("div",{className:"companion-layout flex gap-4",style:{height:"calc(100vh - 11rem)",minHeight:400},children:[e.jsxs("div",{ref:Qe,className:P("flex-shrink-0 flex h-full overflow-hidden radius-inner bg-surface/80 backdrop-blur-lg depth-raised",D?"":"hidden md:flex"),style:{width:Q?"var(--companion-side-micro)":"var(--companion-side)"},children:[e.jsx(Bo,{ref:Le,contacts:f,selectedConversation:d,unreadMap:rs,messages:ns,onSelect:M=>{ve(M),window.innerWidth<768&&A(!1)},onShowDetails:qa,onShareContact:La,onResetPath:ft,onRemoveContact:Aa,onPingContact:za,repeaterNeighborHashes:y,repeaterSignalMap:b,isLoading:h,splitPercent:xt,onMicroChange:Ta}),e.jsx("div",{className:"group/divider flex-shrink-0 self-stretch flex items-center justify-center w-3 cursor-col-resize select-none touch-none",onPointerDown:Ea,onPointerMove:Ma,onPointerUp:qt,onPointerCancel:qt,onDoubleClick:Pa,children:e.jsx("div",{className:"w-px h-full my-2 bg-edge-subtle/50 group-hover/divider:bg-sys-blue/50 group-active/divider:bg-sys-blue transition-colors"})}),e.jsx(Vo,{ref:Ut,channels:i,selectedConversation:d,unreadMap:rs,messages:ns,onSelect:M=>{ve(M),window.innerWidth<768&&A(!1)},onAddChannel:()=>$(!0),onDeleteChannel:Ka})]}),e.jsxs(Ss,{noPadding:!0,radius:"sm",className:"flex-1 flex flex-col min-w-0 overflow-hidden relative",children:[e.jsx(ge,{children:_&&e.jsxs(ue.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:de.fade,className:"flex items-center justify-center gap-2 px-3 py-1.5 bg-sys-red/10 border-b border-sys-red/20",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-sys-red flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-sys-red font-medium truncate",children:_})]},"error-banner")}),!D&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-edge-subtle md:hidden",children:[e.jsx("button",{onClick:()=>A(!0),className:"p-1 hover:bg-subtle-fill rounded transition-colors",children:e.jsx(Gl,{className:"w-4 h-4 text-fg-secondary"})}),e.jsx("span",{className:"text-sm text-fg-primary font-medium truncate flex-1",children:ds}),d&&e.jsx("button",{onClick:()=>F(!0),className:"p-1 hover:bg-subtle-fill rounded transition-colors",title:"Details",children:e.jsx(nt,{className:"w-4 h-4 text-fg-muted"})})]}),e.jsxs("div",{className:"hidden md:flex items-center justify-between px-3 py-1.5 border-b border-edge-subtle",children:[e.jsx("span",{className:"text-sm text-fg-primary font-medium truncate",children:ds??"Select a conversation"}),e.jsx(ge,{children:d&&e.jsx(ue.button,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,onClick:()=>{window.innerWidth>=1280?V(M=>!M):F(!0)},className:"p-1 hover:bg-subtle-fill rounded transition-colors",title:L?"Hide detail panel":"Show details",children:L&&window.innerWidth>=1280?e.jsx(Ts,{className:"w-4 h-4 text-fg-muted"}):e.jsx(nt,{className:"w-4 h-4 text-fg-muted"})},"ctx-toggle")})]}),Xa&&E?e.jsx(ui,{contact:E,loginStatus:is,onLogin:gt}):e.jsxs(e.Fragment,{children:[e.jsx(li,{messages:N,contacts:f,className:"flex-1 min-h-0",conversationKey:d?d.type==="channel"?`ch:${d.id}`:d.id:void 0,onRetry:Da,onRetryAsFlood:Fa,onMentionClick:Wa,historyLoading:R,historyExhausted:d?w.get(d.type==="channel"?`ch:${d.id}`:d.id)??!1:!0,onLoadOlder:d?()=>Ua(d.type==="channel"?`ch:${d.id}`:d.id):void 0,channelName:(d==null?void 0:d.type)==="channel"?(ps=i.find(M=>String(M.index)===d.id))==null?void 0:ps.name:void 0}),d&&e.jsx(ii,{onSend:Qa,disabled:!Ya,mentionNames:Va,placeholder:d.type==="channel"?`Message ${((hs=i.find(M=>String(M.index)===d.id))==null?void 0:hs.name)??"channel"}`:`Message ${((xs=f.find(M=>M.public_key===d.id))==null?void 0:xs.name)??"contact"}`})]})]}),e.jsx(ue.div,{initial:!1,animate:{width:L&&d?"var(--companion-context)":"0px",opacity:L&&d?1:0},transition:de.layoutResize,className:"hidden xl:block flex-shrink-0 overflow-hidden",style:{pointerEvents:L&&d?"auto":"none"},children:d&&e.jsxs(Ss,{neomorphic:!0,noPadding:!0,radius:"sm",className:"h-full relative",children:[e.jsx(ge,{children:L&&e.jsx(ue.button,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,onClick:()=>V(!1),className:"absolute top-2 left-2 z-10 p-1 hover:bg-subtle-fill rounded-lg transition-colors",title:"Hide detail panel",children:e.jsx(Ts,{className:"w-4 h-4 text-fg-muted"})},"ctx-close")}),e.jsx(Ks,{contact:d.type==="contact"?E:null,channel:d.type==="channel"?i.find(M=>String(M.index)===d.id)??null:null,contacts:f,selfPubKey:(o==null?void 0:o.public_key)??null,onResetPath:ft,onRequestStatus:Qt,onRequestTelemetry:Yt,onLoginToRepeater:gt,onLogoutFromRepeater:Xt,onGetNeighbours:Jt,onTraceContactPath:Zt,onDiscoverPath:es,onExportContact:M=>{W(M),H(!0)},onSetContactPath:as})]})})]})}),e.jsx(Ys,{open:v,onClose:()=>u(!1),onRefresh:ss}),e.jsx(Di,{open:m,onClose:()=>I(!1),companionName:s??"companion",onImport:Ha}),e.jsx(Ki,{open:k,onClose:()=>{H(!1),W(null)},contacts:f,exportPubKey:te,onExport:Ba,onImport:Ga}),e.jsx(zi,{open:g,onClose:()=>$(!1),channels:i,onAddChannel:Oa}),e.jsxs(je,{open:ie,onClose:()=>F(!1),size:"md",children:[e.jsx(Ee,{icon:(d==null?void 0:d.type)==="channel"?e.jsx(Fe,{className:"w-5 h-5"}):E&&(E.adv_type&15)===2?e.jsx(ze,{className:"w-5 h-5"}):e.jsx(ye,{className:"w-5 h-5"}),title:(d==null?void 0:d.type)==="channel"?((fs=i.find(M=>String(M.index)===d.id))==null?void 0:fs.name)??"Channel":(E==null?void 0:E.name)||"Contact Details",onClose:()=>F(!1)}),e.jsx(we,{className:"max-h-[70vh] overflow-y-auto",children:e.jsx(Ks,{embedded:!0,contact:(d==null?void 0:d.type)==="contact"?E:null,channel:(d==null?void 0:d.type)==="channel"?i.find(M=>String(M.index)===d.id)??null:null,contacts:f,selfPubKey:(o==null?void 0:o.public_key)??null,onResetPath:ft,onRequestStatus:Qt,onRequestTelemetry:Yt,onLoginToRepeater:gt,onLogoutFromRepeater:Xt,onGetNeighbours:Jt,onTraceContactPath:Zt,onDiscoverPath:es,onExportContact:M=>{W(M),H(!0)},onSetContactPath:as})})]})]})}export{Cc as default}; + */const uo=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],mo=ne("user-plus",uo),Ve={sm:{radio:"h-4 w-4",dot:"h-1.5 w-1.5",text:"text-sm",descText:"text-xs",padding:"py-2 px-3",segmentPadding:"py-1.5 px-2.5"},md:{radio:"h-5 w-5",dot:"h-2 w-2",text:"text-sm",descText:"text-xs",padding:"py-3 px-4",segmentPadding:"py-2 px-3"},lg:{radio:"h-6 w-6",dot:"h-2.5 w-2.5",text:"text-base",descText:"text-sm",padding:"py-4 px-5",segmentPadding:"py-2.5 px-4"}};function ka({checked:t,size:s,disabled:a}){const r=Ve[s];return e.jsx("span",{className:P("relative flex shrink-0 items-center justify-center rounded-full border-2 transition-all duration-150",r.radio,t?"border-sys-blue bg-sys-blue":"border-edge-subtle bg-subtle",!t&&!a&&"group-hover:border-edge-strong",a&&"opacity-50"),children:t&&e.jsx("span",{className:P(r.dot,"rounded-full bg-white")})})}function po({option:t,size:s}){const a=Ve[s];return e.jsx(pt,{value:t.value,disabled:t.disabled,className:"group flex items-start gap-3 cursor-pointer ring-focus rounded-lg",children:({checked:r,disabled:l})=>e.jsxs(e.Fragment,{children:[e.jsx(ka,{checked:r,size:s,disabled:l}),e.jsxs("div",{className:"flex-1 min-w-0 select-none",children:[e.jsx(qe,{className:P(a.text,"font-medium cursor-pointer",l?"text-fg-muted":"text-fg-primary"),children:t.label}),t.description&&e.jsx(ct,{className:P(a.descText,"text-fg-muted mt-0.5"),children:t.description})]})]})})}function ho({option:t,size:s}){const a=Ve[s];return e.jsx(pt,{value:t.value,disabled:t.disabled,className:P("group relative flex cursor-pointer ring-focus","radius-inset border-2 transition-all duration-150",a.padding),children:({checked:r,disabled:l})=>e.jsxs(e.Fragment,{children:[e.jsx("span",{className:P("absolute inset-0 radius-inset transition-colors",r?"border-sys-blue bg-sys-blue/5":"border-edge-subtle bg-subtle",!r&&!l&&"group-hover:border-edge-strong group-hover:bg-elevated",l&&"opacity-50"),style:{borderWidth:"inherit"}}),e.jsxs("div",{className:"relative flex items-start gap-3 w-full",children:[t.icon&&e.jsx("span",{className:P("shrink-0",r?"text-sys-blue":"text-fg-muted"),children:t.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(qe,{className:P(a.text,"font-medium cursor-pointer",l?"text-fg-muted":r?"text-sys-blue":"text-fg-primary"),children:t.label}),t.description&&e.jsx(ct,{className:P(a.descText,"text-fg-muted mt-0.5"),children:t.description})]}),e.jsx(ka,{checked:r,size:s,disabled:l})]})]})})}function xo({option:t,size:s,isFirst:a,isLast:r}){const l=Ve[s];return e.jsx(pt,{value:t.value,disabled:t.disabled,className:P("group relative flex items-center justify-center cursor-pointer ring-focus","transition-all duration-150",l.segmentPadding,a&&"rounded-l-lg",r&&"rounded-r-lg"),children:({checked:i,disabled:o})=>e.jsxs(e.Fragment,{children:[e.jsx("span",{className:P("absolute inset-0 transition-colors",i?"bg-sys-blue":"bg-transparent",!i&&!o&&"group-hover:bg-subtle-fill",a&&"rounded-l-lg",r&&"rounded-r-lg",o&&"opacity-50")}),e.jsxs(qe,{className:P("relative z-10 font-medium cursor-pointer select-none",l.text,i?"text-white":o?"text-fg-muted":"text-fg-primary"),children:[t.icon&&e.jsx("span",{className:"mr-1.5 inline-flex",children:t.icon}),t.label]})]})})}function fo({label:t,description:s,options:a,value:r,onChange:l,size:i="md",variant:o="simple",orientation:x="vertical",name:p,disabled:j,className:c}){const f=Ve[i];return e.jsxs(Hl,{value:r,onChange:l,name:p,disabled:j,className:P("space-y-3",c),children:[t&&e.jsx(qe,{className:P(f.text,"font-medium text-fg-primary"),children:t}),s&&e.jsx(ct,{className:P(f.descText,"text-fg-muted -mt-1"),children:s}),o==="segmented"?e.jsx("div",{className:"inline-flex rounded-lg bg-subtle-fill-strong p-0.5",children:a.map((y,b)=>e.jsx(xo,{option:y,size:i,isFirst:b===0,isLast:b===a.length-1},y.value))}):e.jsx("div",{className:P(o==="card"&&x==="horizontal"&&"grid grid-cols-2 gap-3 sm:grid-cols-3",o==="card"&&x==="vertical"&&"space-y-3",o==="simple"&&x==="horizontal"&&"flex flex-wrap gap-4",o==="simple"&&x==="vertical"&&"space-y-2"),children:a.map(y=>o==="card"?e.jsx(ho,{option:y,size:i},y.value):e.jsx(po,{option:y,size:i},y.value))})]})}function Ne({children:t,className:s,onClick:a,disabled:r=!1,destructive:l=!1,icon:i,trailing:o,href:x,checked:p}){const j=e.jsxs(e.Fragment,{children:[(i||p!==void 0)&&e.jsx("span",{className:P("flex-shrink-0 w-4 h-4 flex items-center justify-center","text-fg-muted",l&&"text-sys-red","group-data-[focus]:text-white"),children:p!==void 0?p?e.jsx(be,{className:"h-4 w-4 text-sys-blue group-data-[focus]:text-white"}):null:i}),e.jsx("span",{className:"flex-1 truncate",children:t}),o&&e.jsx("span",{className:"flex-shrink-0 text-fg-muted group-data-[focus]:text-white/70 text-xs",children:o})]}),c=P("group flex items-center gap-2 w-full","px-3 py-2 radius-control cursor-default","text-sm text-left","transition-colors","focus:outline-none",r?"opacity-50 cursor-not-allowed":[l?["text-sys-red","data-[focus]:bg-sys-red data-[focus]:text-white"]:["text-fg-primary","data-[focus]:bg-sys-blue data-[focus]:text-white"]],s);return x&&!r?e.jsx(Nt,{children:e.jsx("a",{href:x,className:c,children:j})}):e.jsx(Nt,{disabled:r,children:e.jsx("button",{type:"button",onClick:a,disabled:r,className:c,children:j})})}function go({className:t}){return e.jsx(wa,{className:P("my-1 h-px bg-border-subtle",t)})}const yo=100,bo=101,vo=102,jo=103,wo=104,No=115,ko=116,Co=117,So=120,_o=125,Ro=128,Io=136;function Eo(t){const s=new $n(t),a=[];for(;s.getRemainingBytesCount()>=2;){const r=s.readUInt8(),l=s.readUInt8();if(r===0&&l===0)break;switch(l){case yo:a.push({channel:r,type:l,value:s.readUInt32BE()});break;case bo:a.push({channel:r,type:l,value:s.readInt16BE()});break;case vo:a.push({channel:r,type:l,value:s.readUInt8()});break;case jo:a.push({channel:r,type:l,value:s.readInt16BE()/10});break;case wo:a.push({channel:r,type:l,value:s.readUInt8()/2});break;case No:a.push({channel:r,type:l,value:s.readUInt16BE()/10});break;case ko:a.push({channel:r,type:l,value:s.readInt16BE()/100});break;case Co:a.push({channel:r,type:l,value:s.readInt16BE()/1e3});break;case So:a.push({channel:r,type:l,value:s.readUInt8()});break;case _o:a.push({channel:r,type:l,value:s.readUInt16BE()});break;case Ro:a.push({channel:r,type:l,value:s.readUInt16BE()});break;case Io:a.push({channel:r,type:l,value:{latitude:s.readInt24BE()/1e4,longitude:s.readInt24BE()/1e4,altitude:s.readInt24BE()/100}});break;default:return a}}return a}const Ca="pymc_companion_contacts_micro",Sa="pymc_companion_favorites",yt=56;function $s(){try{return localStorage.getItem(Ca)==="1"}catch{return!1}}function Mo(t){try{localStorage.setItem(Ca,t?"1":"0")}catch{}}function Po(){try{const t=localStorage.getItem(Sa);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function To(t){try{localStorage.setItem(Sa,JSON.stringify([...t]))}catch{}}function $o({name:t,pubkey:s,advType:a,size:r="md",signal:l}){const i=(a??0)&15,o=r==="sm"?"w-5 h-5":"w-6 h-6",x=r==="sm"?"size-3":"size-3.5";if(i===2){const f=l&&l.rssi!==0,y=f?`RSSI: ${l.rssi} dBm · SNR: ${l.snr.toFixed(1)} dB${l.rtt_ms!=null?` · RTT: ${l.rtt_ms} ms`:""}`:void 0;return e.jsx("div",{className:P(o,"relative rounded-full flex items-center justify-center flex-shrink-0 ring-[1.5px]",f?"ring-transparent":"ring-sys-blue"),title:y,children:f?e.jsx(Rr,{rssi:l.rssi,snr:l.snr,compact:!0,showValues:!1}):e.jsx(ze,{className:P(x,"text-sys-blue")})})}if(i===3)return e.jsx("div",{className:P(o,"relative rounded-full flex items-center justify-center flex-shrink-0 ring-[1.5px] ring-sys-pink"),children:e.jsx(dt,{className:P(x,"text-sys-pink")})});if(!t)return e.jsx("div",{className:P(o,"relative rounded-full bg-sys-blue/12 flex items-center justify-center flex-shrink-0"),children:e.jsx("span",{className:"text-sys-blue font-mono text-[10px] font-bold",children:s.slice(0,4)})});const{emoji:p}=Mt(t),j=Pt(t),c=Tt(t);return e.jsx("div",{className:P(o,"relative clay-avatar",p?"text-base":"text-white text-[11px] font-bold"),style:{"--avatar-color":j},children:p||c})}const Ds=[{key:"companion",label:"Companions",icon:ye,color:"text-sys-blue"},{key:"room",label:"Room Servers",icon:dt,color:"text-sys-pink"},{key:"repeater",label:"Repeaters",icon:ze,color:"text-sys-blue"}];function Do(t){const s=(t.adv_type??0)&15;return s===3?"room":s===2?"repeater":"companion"}const Fo=4e3,Lo=5e3,Ao=2e3,Oo=8,zo=n.forwardRef(function({contact:s,isActive:a,unread:r,lastMsg:l,isFav:i,microContent:o,onSelect:x,onShowDetails:p,onShareContact:j,onResetPath:c,onRemoveContact:f,onPingContact:y,repeaterNeighborHashes:b,repeaterSignal:d,toggleFavorite:N},S){const h=Dn(s.public_key),_=Fn(s.public_key),[E,R]=n.useState(!1),[w,C]=n.useState(!1),T=n.useRef(null),[v,u]=n.useState("idle"),m=n.useRef(!1),I=n.useRef(null),[g,$]=n.useState({w:0,h:0});n.useEffect(()=>{if(h)m.current=!0,u("idle");else if(m.current){m.current=!1;const F=se.getState().pingResults.get(s.public_key),D=F!=null&&F.rssi!==0;u(D?"success":"failed")}},[h,s.public_key]),n.useEffect(()=>{if(v==="idle")return;const D=setTimeout(()=>u("idle"),v==="success"?Lo:Ao);return()=>clearTimeout(D)},[v]);const k=(h||v!=="idle")&&!E;n.useEffect(()=>{if(!k)return;const F=I.current;if(!F)return;const D=()=>{const O=F.offsetWidth,G=F.offsetHeight;$(Q=>Q.w===O&&Q.h===G?Q:{w:O,h:G})};D();const A=new ResizeObserver(D);return A.observe(F),()=>A.disconnect()},[k]);const H=n.useCallback(()=>{R(!0),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>R(!1),Fo)},[]),te=n.useCallback(()=>{R(!1),T.current&&clearTimeout(T.current)},[]),W=n.useCallback(async()=>{f&&(T.current&&clearTimeout(T.current),C(!0),await f(s.public_key),C(!1),R(!1))},[f,s.public_key]),L=n.useMemo(()=>{const F=_&&_.rssi!==0,D=d&&d.rssi!==0;if(!F&&!D)return null;if(F&&!D)return{rssi:_.rssi,snr:_.snr_db,rtt_ms:_.rtt_ms};if(!F&&D)return{rssi:d.rssi,snr:d.snr};const A=d.advertCount,O=3,G=A+O;return{rssi:Math.round((d.rssi*A+_.rssi*O)/G),snr:(d.snr*A+_.snr_db*O)/G,rtt_ms:_.rtt_ms}},[_,d]),V=n.useCallback(F=>{I.current=F,typeof S=="function"?S(F):S&&(S.current=F)},[S]),ie=E?"":v==="success"?"bg-sys-green/5":v==="failed"?"bg-sys-red/5":h?"bg-sys-blue/5":a?"bg-sys-blue":"hover:bg-elevated";return e.jsxs(ue.div,{ref:V,layout:"position",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,className:P("group relative w-full flex items-center gap-2.5 px-2.5 py-[3px] radius-inner overflow-hidden","transition-[background-color,box-shadow] duration-150",ie),children:[e.jsx(ge,{children:k&&g.w>0&&(v!=="idle"?e.jsx(ue.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{opacity:{duration:.15}},className:P("absolute inset-0 radius-inner ring-2 ring-inset pointer-events-none z-[2]",v==="success"?"ring-sys-green":"ring-sys-red")},`ping-${v}`):e.jsx(Ln,{borderRadius:Oo,width:g.w,height:g.h,color:"blue"},"ping-crawl"))}),e.jsxs("div",{className:"grid flex-1 min-w-0 [&>*]:col-start-1 [&>*]:row-start-1",children:[e.jsxs("div",{className:P("flex items-center gap-2.5",E&&!o&&"invisible pointer-events-none"),children:[e.jsxs("button",{onClick:()=>x({type:"contact",id:s.public_key}),className:"flex items-center gap-2.5 flex-1 min-w-0 text-left",children:[e.jsxs("div",{className:"relative",children:[e.jsx($o,{name:s.name,pubkey:s.public_key,advType:s.adv_type,signal:L}),r>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 h-2.5 w-2.5 rounded-full bg-sys-red ring-2 ring-body"})]}),!o&&e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("span",{className:P("text-sm truncate flex-1",a?"text-white font-medium":i?"text-sys-amber font-bold":"text-fg-primary font-medium"),children:s.name||s.public_key.slice(0,12)+"…"})}),v==="success"&&_?e.jsxs("div",{className:"text-[11px] text-sys-green font-medium truncate tabular-nums",children:[_.rssi," dBm · ",_.snr_db.toFixed(1)," dB",_.rtt_ms!=null&&` · ${_.rtt_ms} ms`]}):v==="failed"?e.jsx("div",{className:"text-[11px] text-sys-red font-medium truncate",children:"No response"}):l?e.jsx("div",{className:P("text-[11px] truncate",a?"text-white/70":"text-fg-muted"),children:l.text}):null]})]}),!o&&e.jsx("div",{className:"relative flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center",children:e.jsx(_l,{as:"div",className:"absolute inset-0",children:({open:F})=>e.jsxs(e.Fragment,{children:[e.jsx(va,{className:P("absolute inset-0 flex items-center justify-center rounded transition-[opacity,background-color] duration-100","focus:outline-none",a?"hover:bg-white/15":"hover:bg-subtle-fill",F?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":"Contact options",children:e.jsx(Wl,{className:P("h-3.5 w-3.5 transition-colors",a?"text-white/60 hover:text-white":"text-fg-muted hover:text-sys-blue")})}),e.jsxs(ja,{anchor:"right start",transition:!0,className:P("min-w-[10rem] max-w-[20rem]","radius-inset p-1 ml-1","surface-elevated","focus:outline-none z-50","transition-[opacity,transform]","data-[closed]:opacity-0 data-[closed]:scale-[0.98] data-[closed]:translate-x-[-4px]","data-[enter]:duration-150 data-[leave]:duration-100","data-[enter]:ease-out data-[leave]:ease-in"),children:[e.jsx(Ne,{icon:e.jsx(nt,{className:"w-4 h-4"}),onClick:()=>{p==null||p({type:"contact",id:s.public_key})},children:"Details"}),j&&e.jsx(Ne,{icon:e.jsx(Ur,{className:"w-4 h-4"}),onClick:()=>j(s.public_key),children:"Share"}),e.jsx(Ne,{icon:e.jsx(Ge,{className:"w-4 h-4"}),onClick:()=>x({type:"contact",id:s.public_key}),children:"Set Path"}),c&&e.jsx(Ne,{icon:e.jsx(da,{className:"w-4 h-4"}),onClick:()=>c(s.public_key),children:"Reset Path"}),y&&e.jsx(Ne,{icon:e.jsx(ql,{className:"w-4 h-4"}),onClick:()=>y(s.public_key),disabled:!(b!=null&&b.has(s.public_key)),children:"Ping"}),f&&e.jsx(Ne,{icon:e.jsx(Ke,{className:"w-4 h-4"}),destructive:!0,onClick:H,children:"Remove Contact"}),e.jsx(go,{}),e.jsx(Ne,{icon:e.jsx(io,{className:P("w-4 h-4 group-data-[focus]:text-white group-data-[focus]:fill-white",i?"text-sys-amber fill-sys-amber":"text-fg-muted")}),onClick:()=>N(s.public_key),children:i?"Unfavorite":"Favorite"})]})]})})})]}),!o&&e.jsx("div",{className:P("flex items-center gap-1.5 self-center",!E&&"invisible pointer-events-none"),children:w?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("div",{className:"w-3.5 h-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:te,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-zinc-500/80 hover:bg-zinc-500 depth-stroke-raised transition-colors",children:e.jsx("span",{className:"text-[11px] font-semibold text-white",children:"Cancel"})}),e.jsx("button",{onClick:W,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-sys-red/80 hover:bg-sys-red depth-stroke-raised transition-colors",children:e.jsx(Ke,{className:"w-4 h-4 text-white"})})]})})]})]},s.public_key)}),Fs={excellent:4,good:3,fair:2,weak:1,poor:0};function Ls(t,s,a){const r=s==null?void 0:s.get(t),l=r&&r.rssi!==0,i=a==null?void 0:a.get(t),o=i&&typeof i.rssi=="number"&&i.rssi!==0;if(!l&&!o)return null;if(o&&!l)return i.rssi;if(!o&&l)return r.rssi;const x=r.advertCount,p=3;return Math.round((r.rssi*x+i.rssi*p)/(x+p))}function Ho(t,s,a,r,l){return[...t].sort((i,o)=>{const x=s.has(i.public_key)?0:1,p=s.has(o.public_key)?0:1;if(x!==p)return x-p;if(a){const j=a.get(i.public_key),c=j&&j.length>0?j[j.length-1].timestamp:0,f=a.get(o.public_key),y=f&&f.length>0?f[f.length-1].timestamp:0;if(c!==y)return y-c}if(r){const j=Ls(i.public_key,r,l),c=Ls(o.public_key,r,l);if(j!=null&&c==null)return-1;if(j==null&&c!=null)return 1;if(j!=null&&c!=null){const f=Fs[_s(j)]??0,y=Fs[_s(c)]??0;if(f!==y)return y-f}}return(i.name||"").localeCompare(o.name||"")})}const Bo=n.memo(n.forwardRef(function({contacts:s,selectedConversation:a,unreadMap:r,messages:l,onSelect:i,onShowDetails:o,onShareContact:x,onResetPath:p,onRemoveContact:j,onPingContact:c,repeaterNeighborHashes:f,repeaterSignalMap:y,isLoading:b,splitPercent:d=50,onMicroChange:N,className:S},h){const[_,E]=n.useState($s),[R,w]=n.useState($s),[C,T]=n.useState(""),[v,u]=n.useState(!1),[m,I]=n.useState(Po),g=n.useRef(null),$=n.useRef(null),k=n.useCallback(D=>{$.current=D,typeof h=="function"?h(D):h&&(h.current=D)},[h]),H=n.useCallback(()=>{E(D=>{const A=!D;Mo(A);const O=$.current;if(A&&w(!0),O){let G=0;const Q=O.parentElement;if(A)G=(Q==null?void 0:Q.offsetWidth)??O.offsetWidth;else if(Q){const We=Q.style.width;Q.style.width="var(--companion-side)",G=Q.offsetWidth,Q.style.width=We}const ht=A?yt:Math.round(d/100*G);tt(O,{width:`${ht}px`},{...de.layoutResize,onComplete(){O.style.width=A?`${yt}px`:`${d}%`,A||w(!1)}})}return N==null||N(A),A})},[d,N]),te=n.useCallback(D=>{I(A=>{const O=new Set(A);return O.has(D)?O.delete(D):O.add(D),To(O),O})},[]),W=v||C.length>0,L=n.useMemo(()=>{const D=new Set,A=s.filter(G=>D.has(G.public_key)?!1:(D.add(G.public_key),!0));if(!C.trim())return A;const O=C.toLowerCase();return A.filter(G=>{var Q;return((Q=G.name)==null?void 0:Q.toLowerCase().includes(O))||G.public_key.toLowerCase().includes(O)})},[s,C]),V=se(D=>D.pingResults),ie=n.useMemo(()=>{const D=new Map;for(const A of Ds)D.set(A.key,[]);for(const A of L)D.get(Do(A)).push(A);return Ds.map(A=>({...A,items:Ho(D.get(A.key),m,l,A.key==="repeater"?y:void 0,A.key==="repeater"?V:void 0)})).filter(A=>A.items.length>0)},[L,m,l,y,V]),F=(a==null?void 0:a.type)==="contact"?a.id:null;return e.jsxs("div",{ref:k,className:P("flex-shrink-0 overflow-hidden flex flex-col h-full",S),style:{width:_?yt:`${d}%`},children:[e.jsx("div",{className:P("flex items-center border-b border-edge-subtle flex-shrink-0",R?"justify-center p-2":"gap-2 px-3 py-2"),children:R?e.jsx("button",{onClick:H,className:"p-1 hover:bg-subtle-fill rounded transition-colors",title:"Expand contacts",children:e.jsx(to,{className:"w-3.5 h-3.5 text-fg-muted"})}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide flex-shrink-0",children:"Contacts"}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto flex-shrink-0",children:[e.jsx("button",{onClick:()=>{W?(T(""),u(!1)):(u(!0),setTimeout(()=>{var D;return(D=g.current)==null?void 0:D.focus()},50))},className:P("p-1 rounded transition-colors flex-shrink-0",W?"bg-sys-blue/10 text-sys-blue":"hover:bg-subtle-fill text-fg-muted"),title:W?"Close search":"Search contacts",children:e.jsx(Rs,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:H,className:"p-1 hover:bg-subtle-fill rounded transition-colors flex-shrink-0",title:"Collapse contacts",children:e.jsx(Zl,{className:"w-3.5 h-3.5 text-fg-muted"})})]})]})}),!R&&W&&e.jsxs("div",{className:"relative px-2.5 py-2 border-b border-edge-subtle/50 flex-shrink-0",children:[e.jsx(Rs,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-muted pointer-events-none"}),e.jsx("input",{ref:g,type:"text",value:C,onChange:D=>T(D.target.value),onFocus:()=>u(!0),onBlur:()=>u(!1),placeholder:"Search contacts…",className:"w-full pl-8 pr-8 py-1.5 text-sm radius-inner bg-input-bg border border-input-border text-fg-primary placeholder:text-fg-muted/50 ring-focus-inset hover:border-edge-strong transition-colors",autoFocus:!0}),e.jsx("button",{onClick:()=>{T(""),u(!1)},className:"absolute right-5 top-1/2 -translate-y-1/2 p-0.5 hover:bg-subtle-fill rounded",children:e.jsx(ut,{className:"w-3.5 h-3.5 text-fg-muted"})})]}),b&&e.jsx("div",{className:"flex items-center justify-center flex-1",children:e.jsx("div",{className:"w-5 h-5 animate-spin rounded-full border-2 border-sys-blue border-t-transparent"})}),!b&&e.jsxs("div",{className:P("flex-1 overflow-y-auto min-h-0",R?"px-0":"px-1.5"),style:{contain:"layout style paint"},children:[ie.map(D=>{const A=D.icon;return e.jsxs(_e,{defaultOpen:!0,className:"mb-1",children:[e.jsxs(Re,{className:P("px-2 py-1 flex items-center gap-1.5 w-full","text-left radius-inner hover:bg-subtle-fill-strong transition-colors"),children:[e.jsx(A,{className:P("w-3.5 h-3.5",D.color)}),!R&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:D.label}),e.jsx("span",{className:"type-data-xs text-fg-muted/50 ml-auto",children:D.items.length})]})]}),e.jsx(Ie,{children:e.jsx(ge,{initial:!1,mode:"popLayout",children:D.items.map(O=>e.jsx(zo,{contact:O,isActive:F===O.public_key,unread:r.get(O.public_key)??0,lastMsg:(()=>{const G=l.get(O.public_key);return G&&G.length>0?G[G.length-1]:void 0})(),isFav:m.has(O.public_key),microContent:R,onSelect:i,onShowDetails:o,onShareContact:x,onResetPath:p,onRemoveContact:j,onPingContact:c,repeaterNeighborHashes:f,repeaterSignal:y==null?void 0:y.get(O.public_key),toggleFavorite:te},O.public_key))})})]},D.key)}),L.length===0&&e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-sm text-fg-muted",children:C?"No matches":"No contacts yet"})})]})]})}));function Go({open:t,onClose:s}){const a=se(u=>u.discoverImportableChannels),r=se(u=>u.getEmptyChannelSlots),l=se(u=>u.importChannel),i=se(u=>u.refreshChannels),[o,x]=n.useState("discover"),[p,j]=n.useState([]),[c,f]=n.useState([]),[y,b]=n.useState(null),d=n.useRef(!1);n.useEffect(()=>{if(!t)return;x("discover"),j([]),f([]),b(null),d.current=!1;let u=!1;return(async()=>{try{const[m,I]=await Promise.all([a(),r()]);if(u)return;if(f(I),m.length===0){b("No channels found in repeater history. Decoded messages may still be loading."),x("select");return}I.length===0&&b("No empty channel slots on device. Delete a channel first to make room."),j(m.map(g=>({name:g.name,alreadyOnDevice:g.alreadyOnDevice,selected:!g.alreadyOnDevice,status:"pending"}))),x("select")}catch(m){u||(b(m instanceof Error?m.message:"Discovery failed"),x("select"))}})(),()=>{u=!0}},[t,a,r]);const N=n.useCallback(u=>{j(m=>m.map(I=>I.name===u&&!I.alreadyOnDevice?{...I,selected:!I.selected}:I))},[]),S=n.useCallback(()=>{j(u=>u.map(m=>m.alreadyOnDevice?m:{...m,selected:!0}))},[]),h=n.useCallback(()=>{j(u=>u.map(m=>m.alreadyOnDevice?m:{...m,selected:!1}))},[]),_=n.useMemo(()=>p.filter(u=>!u.alreadyOnDevice).length,[p]),E=n.useMemo(()=>p.filter(u=>u.selected&&!u.alreadyOnDevice).length,[p]),R=n.useMemo(()=>p.filter(u=>u.status==="done").length,[p]),w=n.useMemo(()=>p.filter(u=>u.status==="failed").length,[p]),C=n.useCallback(async()=>{x("import"),d.current=!1;const u=p.filter(I=>I.selected&&!I.alreadyOnDevice),m=[...c];for(const I of u){if(d.current)break;const g=m.shift();if(g===void 0){j(k=>k.map(H=>H.name===I.name&&H.status==="pending"?{...H,status:"failed"}:H));continue}j(k=>k.map(H=>H.name===I.name?{...H,status:"sending"}:H)),await new Promise(k=>setTimeout(k,150));const $=await l(I.name,g);j(k=>k.map(H=>H.name===I.name?{...H,status:$?"done":"failed"}:H)),$||m.unshift(g),d.current||await new Promise(k=>setTimeout(k,300))}await i(),x("complete")},[p,c,l,i]),T=n.useCallback(()=>{d.current=!0},[]),v=u=>{switch(u){case"pending":return e.jsx(Na,{className:"w-3.5 h-3.5 text-fg-muted"});case"sending":return e.jsx(oe,{className:"w-3.5 h-3.5 text-sys-blue animate-spin"});case"done":return e.jsx(be,{className:"w-3.5 h-3.5 text-sys-green"});case"failed":return e.jsx(ut,{className:"w-3.5 h-3.5 text-sys-red"})}};return e.jsxs(je,{open:t,onClose:o==="import"?()=>{}:s,size:"sm",children:[e.jsx(Ee,{icon:e.jsx(He,{className:"w-5 h-5"}),title:"Import Channels",onClose:o==="import"?void 0:s}),e.jsxs(we,{className:"!py-3 !px-0",children:[o==="discover"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-8 px-6",children:[e.jsx(oe,{className:"w-6 h-6 text-sys-blue animate-spin"}),e.jsx("p",{className:"text-sm text-fg-secondary",children:"Scanning repeater history…"}),e.jsx("p",{className:"text-[11px] text-fg-muted",children:"Waiting for decoded messages"})]}),o==="select"&&e.jsxs(e.Fragment,{children:[y&&e.jsxs("div",{className:"flex items-start gap-2 mx-4 mb-3 p-2.5 radius-inner bg-sys-amber/8 border border-sys-amber/20",children:[e.jsx(Be,{className:"w-3.5 h-3.5 text-sys-amber flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-fg-secondary",children:y})]}),p.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 pb-2 border-b border-edge-subtle",children:[e.jsxs("span",{className:"text-[11px] text-fg-muted",children:[_," discoverable · ",c.length," slot",c.length!==1?"s":""," free"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:S,className:"text-[11px] text-sys-blue hover:underline",children:"All"}),e.jsx("span",{className:"text-fg-muted/40",children:"·"}),e.jsx("button",{onClick:h,className:"text-[11px] text-sys-blue hover:underline",children:"None"})]})]}),e.jsx("div",{className:"max-h-[320px] overflow-y-auto",children:p.map(u=>e.jsxs("button",{onClick:()=>N(u.name),disabled:u.alreadyOnDevice,className:P("w-full flex items-center gap-3 px-4 py-2 transition-colors",u.alreadyOnDevice?"opacity-40 cursor-default":"hover:bg-subtle-fill"),children:[e.jsx("div",{className:P("w-4 h-4 rounded border flex items-center justify-center flex-shrink-0 transition-colors",u.alreadyOnDevice?"border-fg-muted/30 bg-fg-muted/10":u.selected?"border-sys-blue bg-sys-blue":"border-edge-subtle"),children:(u.selected||u.alreadyOnDevice)&&e.jsx(be,{className:"w-3 h-3 text-white"})}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Fe,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"text-sm text-fg-primary truncate",children:u.name})]}),u.alreadyOnDevice&&e.jsx("span",{className:"text-[10px] text-fg-muted bg-subtle-fill px-1.5 py-0.5 rounded flex-shrink-0",children:"on device"})]},u.name))})]})]}),(o==="import"||o==="complete")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 pb-2 border-b border-edge-subtle",children:[e.jsx("span",{className:"text-[11px] text-fg-muted",children:o==="import"?"Importing channels…":"Import complete"}),e.jsxs("span",{className:"text-[11px] tabular-nums text-fg-secondary",children:[R+w," / ",p.filter(u=>u.selected&&!u.alreadyOnDevice).length]})]}),e.jsx("div",{className:"max-h-[320px] overflow-y-auto",children:p.filter(u=>u.selected&&!u.alreadyOnDevice).map(u=>e.jsxs("div",{className:P("flex items-center gap-3 px-4 py-2",u.status==="sending"&&"bg-sys-blue/5",u.status==="done"&&"bg-sys-green/5",u.status==="failed"&&"bg-sys-red/5"),children:[e.jsx("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:v(u.status)}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Fe,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:P("text-sm truncate",u.status==="done"?"text-fg-primary":"text-fg-secondary"),children:u.name})]}),e.jsx("span",{className:P("text-[10px] flex-shrink-0",u.status==="sending"&&"text-sys-blue",u.status==="done"&&"text-sys-green",u.status==="failed"&&"text-sys-red",u.status==="pending"&&"text-fg-muted"),children:u.status==="sending"?"sending…":u.status==="done"?"added":u.status==="failed"?"failed":"waiting"})]},u.name))})]})]}),e.jsxs(Me,{children:[o==="select"&&e.jsxs(e.Fragment,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Cancel"}),e.jsxs(B,{color:"primary",onClick:C,disabled:E===0||c.length===0,children:[e.jsx(He,{className:"w-4 h-4"}),"Import ",E," ",E===1?"Channel":"Channels"]})]}),o==="import"&&e.jsx(B,{plain:!0,onClick:T,children:"Stop"}),o==="complete"&&e.jsxs(e.Fragment,{children:[w>0&&e.jsxs("span",{className:"text-xs text-sys-red flex items-center gap-1 mr-auto",children:[e.jsx(Be,{className:"w-3.5 h-3.5"}),w," failed"]}),e.jsxs(B,{color:"primary",onClick:s,children:[e.jsx(Vr,{className:"w-4 h-4"}),"Done — ",R," imported"]})]})]})]})}const Ko=4e3;function Uo(t){const s=t.frequency_hz/1e3,a=t.bandwidth_hz/1e3;return`${s} · SF${t.spreading_factor} · ${a}k`}const qo=n.forwardRef(function({channel:s,isActive:a,unread:r,lastMsg:l,isLoadingMessages:i,selfInfo:o,onSelect:x,onDeleteChannel:p},j){const[c,f]=n.useState(!1),[y,b]=n.useState(!1),d=n.useRef(null),N=n.useCallback(()=>{f(!0),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>f(!1),Ko)},[]),S=n.useCallback(()=>{f(!1),d.current&&clearTimeout(d.current)},[]),h=n.useCallback(async()=>{p&&(d.current&&clearTimeout(d.current),b(!0),await p(s.index),b(!1),f(!1))},[p,s.index]),_=s.name.toLowerCase()==="public",E=p&&!_;return e.jsx(ue.div,{ref:j,layout:"position",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,className:P("group w-full flex items-center gap-2.5 px-2.5 py-1 radius-inner","transition-[background-color] duration-150",c?"":a?"bg-sys-blue":"hover:bg-subtle-fill-strong"),children:e.jsxs("div",{className:"grid flex-1 min-w-0 [&>*]:col-start-1 [&>*]:row-start-1",children:[e.jsxs("div",{className:P("flex items-center gap-2.5 min-w-0",c&&"invisible pointer-events-none"),children:[e.jsx("button",{onClick:()=>x({type:"channel",id:String(s.index)}),className:"flex items-center gap-2.5 flex-1 min-w-0 text-left",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:P("text-sm flex-shrink-0",a?"text-white font-semibold":l?"text-fg-primary font-semibold":"text-fg-secondary font-normal"),children:s.name}),_&&o&&e.jsx("span",{className:P("text-[9px] font-medium px-1.5 py-px rounded-full whitespace-nowrap truncate",a?"text-white/80 bg-white/15":"text-fg-muted/70 bg-subtle-fill"),children:Uo(o)})]}),l&&e.jsx("div",{className:P("text-[11px] truncate pl-2",a?"text-white/70":"text-fg-muted"),children:l.text})]})}),e.jsx("div",{className:"flex items-center flex-shrink-0",children:i?e.jsx("span",{className:"h-1.5 w-6 rounded-full bg-fg-muted/20 animate-pulse"}):E?e.jsxs("div",{className:"relative w-[18px] h-[18px] flex items-center justify-center",children:[r>0&&e.jsx("span",{className:"absolute inset-0 flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-sys-red text-white text-[10px] font-bold leading-none group-hover:invisible transition-[visibility] duration-100",children:r>99?"99+":r}),e.jsx("button",{onClick:N,className:P("absolute inset-0 flex items-center justify-center rounded opacity-0 group-hover:opacity-100 transition-[opacity,background-color] duration-100",a?"hover:bg-white/15":"hover:bg-subtle-fill"),title:"Remove channel",children:e.jsx(Ke,{className:P("w-3 h-3 transition-colors",a?"text-white/60 hover:text-white":"text-fg-muted hover:text-sys-red")})})]}):r>0?e.jsx("span",{className:"min-w-[18px] h-[18px] px-1 rounded-full bg-sys-red text-white text-[10px] font-bold flex items-center justify-center leading-none",children:r>99?"99+":r}):null})]}),e.jsx("div",{className:P("flex items-center gap-1.5 self-center",!c&&"invisible pointer-events-none"),children:y?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("div",{className:"w-3.5 h-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:S,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-zinc-500/80 hover:bg-zinc-500 depth-stroke-raised transition-colors",children:e.jsx("span",{className:"text-[11px] font-semibold text-white",children:"Cancel"})}),e.jsx("button",{onClick:h,className:"flex-1 flex items-center justify-center py-1 radius-inner bg-sys-red/80 hover:bg-sys-red depth-stroke-raised transition-colors",children:e.jsx(Ke,{className:"w-4 h-4 text-white"})})]})})]})})}),Vo=n.memo(n.forwardRef(function({channels:s,selectedConversation:a,unreadMap:r,messages:l,onSelect:i,onAddChannel:o,onDeleteChannel:x,className:p},j){const c=An(),f=mt(),[y,b]=n.useState(!1),d=n.useMemo(()=>{const S=new Set,h=s.filter(_=>S.has(_.index)?!1:(S.add(_.index),!0));return h.sort((_,E)=>{const R=_.name.toLowerCase()==="public",w=E.name.toLowerCase()==="public";if(R&&!w)return-1;if(!R&&w)return 1;const C=l.get(`ch:${_.index}`),T=C&&C.length>0?C[C.length-1].timestamp:0,v=l.get(`ch:${E.index}`),u=v&&v.length>0?v[v.length-1].timestamp:0;return T!==u?u-T:_.name.localeCompare(E.name)}),h},[s,l]),N=(a==null?void 0:a.type)==="channel"?a.id:null;return e.jsxs("div",{ref:j,className:P("flex-1 min-w-0 overflow-hidden flex flex-col h-full",p),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-edge-subtle flex-shrink-0 overflow-hidden whitespace-nowrap",children:[e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide flex-shrink-0",children:"Channels"}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto flex-shrink-0",children:[e.jsx("button",{onClick:()=>b(!0),className:"p-1 rounded hover:bg-subtle-fill transition-colors flex-shrink-0",title:"Import channels from repeater history",children:e.jsx(He,{className:"w-3.5 h-3.5 text-fg-muted"})}),o&&e.jsx("button",{onClick:o,className:"p-1 rounded hover:bg-subtle-fill transition-colors flex-shrink-0",title:"Add channel",children:e.jsx(Ue,{className:"w-3.5 h-3.5 text-fg-muted"})})]})]}),e.jsx(Go,{open:y,onClose:()=>b(!1)}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 px-1.5 py-1",style:{contain:"layout style paint"},children:d.length===0?e.jsxs("div",{className:"px-1.5 py-4 space-y-2",children:[e.jsx("p",{className:"text-sm text-fg-muted",children:"No channels"}),o&&e.jsxs("button",{onClick:o,className:"inline-flex items-center gap-1.5 px-2 py-1.5 text-xs font-medium text-sys-blue hover:bg-sys-blue/8 rounded transition-colors",children:[e.jsx(Ue,{className:"w-3.5 h-3.5"}),"Add Channel"]})]}):e.jsx(ge,{initial:!1,mode:"popLayout",children:d.map(S=>e.jsx(qo,{channel:S,isActive:N===String(S.index),unread:r.get(`ch:${S.index}`)??0,lastMsg:(()=>{const h=l.get(`ch:${S.index}`);return h&&h.length>0?h[h.length-1]:void 0})(),isLoadingMessages:c,selfInfo:f,onSelect:i,onDeleteChannel:x},S.index))})})]})}));function Wo(t,s){const a=new Map;for(const[r,l]of t){const i=l.decoded;if(!(i!=null&&i.decrypted)||i.senderName!==s)continue;const o=i.timestamp??l.timestamp,x=Math.floor(o/30),p=`${i.text}:${x}`;a.has(p)||a.set(p,r)}return a}function Qo(t){const s=mt(),a=On(),r=zn(),l=s==null?void 0:s.node_name,i=n.useMemo(()=>l?Wo(a,l):new Map,[a,l]);return n.useMemo(()=>{const o=new Map;if(!l||i.size===0)return o;const x=new Map;for(const c of t){if(!c.is_outgoing||!c.is_channel)continue;const f=Math.floor(c.timestamp/30);let y=!1;for(const b of[f-1,f,f+1]){const d=i.get(`${c.text}:${b}`);if(d){const N=x.get(d)??[];N.push(c.id),x.set(d,N),y=!0;break}}}if(x.size===0)return o;const p=new Set(x.keys()),j=new Map;for(const c of r)p.has(c.packet_hash)&&j.set(c.packet_hash,(j.get(c.packet_hash)??0)+1);for(const[c,f]of x){const y=j.get(c)??0,b=Math.max(0,y-1);for(const d of f)o.set(d,b)}return o},[t,l,i,r])}const Yo=n.lazy(()=>ra(()=>import("./CompanionPathMap-CBbQCUOF.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(t=>({default:t.CompanionPathMap}))),Xo=n.lazy(()=>ra(()=>import("./CompanionEchoMap-DRaPu98w.js"),__vite__mapDeps([8,1,2,3,5,6,7])).then(t=>({default:t.CompanionEchoMap}))),As=e.jsx("div",{className:"rounded-lg bg-elevated flex items-center justify-center",style:{aspectRatio:"16 / 10"},children:e.jsx("div",{className:"w-4 h-4 border-2 border-fg-muted/30 border-t-fg-muted rounded-full animate-spin"})});function Jo(t){const s=new Date(t*1e3),r=Math.floor((new Date().getTime()-s.getTime())/864e5);return r===0?"Today":r===1?"Yesterday":s.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Zo(t){const s=new Date(t*1e3);return`${s.getFullYear()}-${s.getMonth()}-${s.getDate()}`}function ei(t){const s=new Map;for(const a of t)a.name&&s.set(a.public_key,a.name);return s}function ti(t){const s=new Map;for(const a of t)s.set(a.public_key,a);return s}function si(t){if(!t)return[];const s=[];for(let a=0;ar.public_key.startsWith(t));return(a==null?void 0:a.name)||null}function ni(t,s){return t.is_outgoing?"You":t.sender_name?t.sender_name:s.get(t.sender_key)??t.sender_key.slice(0,8)}const ri=n.memo(function({msg:s,contact:a,contacts:r,selfInfo:l,echoCount:i,channelName:o,children:x}){const[p,j]=n.useState(!1),[c,f]=n.useState(!1),[y,b]=n.useState(0),d=n.useRef(null),N=s.path_len,S=!s.is_outgoing,h=S&&N!=null,_=s.is_outgoing&&s.is_channel&&(i??0)>0,E=(o==null?void 0:o.toLowerCase().includes("wardrive"))??!1,R=n.useMemo(()=>E&&S?Yr(s.text):null,[E,S,s.text]),w=h||_,C=n.useMemo(()=>{const $=[];if(s.path_hops&&s.path_hops.length>0)$.push({hops:s.path_hops,snr:s.path_snr,rssi:s.path_rssi});else if(S&&(a!=null&&a.out_path)){const k=si(a.out_path);k.length>0&&$.push({hops:k})}if(s.alternate_paths)for(const k of s.alternate_paths)$.push(k);return $},[s.path_hops,s.path_snr,s.path_rssi,s.alternate_paths,S,a==null?void 0:a.out_path]),T=y1,m=(v==null?void 0:v.snr)??s.msg_snr,I=()=>{f(!0),j($=>!$)},g=n.useCallback($=>{var k;$.propertyName==="grid-template-rows"&&(p?(k=d.current)==null||k.scrollIntoView({block:"nearest",behavior:"smooth"}):f(!1))},[p]);return e.jsxs("div",{ref:d,className:P("rounded-xl px-2 py-1 -mx-2 transition-colors duration-150",w&&"hover:bg-subtle-fill cursor-pointer"),onClick:()=>w&&I(),children:[x,w&&e.jsx("div",{className:"grid transition-[grid-template-rows] duration-300 ease-[cubic-bezier(0.83,0,0.17,1)]",style:{gridTemplateRows:p?"1fr":"0fr"},onTransitionEnd:g,children:e.jsxs("div",{className:"overflow-hidden",children:[c&&h&&e.jsxs("div",{className:"mt-1.5 ml-13 space-y-1",children:[u&&e.jsx("div",{className:"flex items-center gap-1 flex-wrap",onClick:$=>$.stopPropagation(),children:C.map(($,k)=>e.jsxs("button",{onClick:()=>b(k),className:P("flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] transition-colors",k===T?"bg-sys-blue/15 text-sys-blue font-semibold":"bg-subtle-fill text-fg-muted hover:text-fg-secondary"),children:[e.jsx(Ge,{className:"w-2.5 h-2.5"}),$.hops.length||N,$.snr!=null&&e.jsxs("span",{className:"ml-0.5 opacity-70",children:[$.snr>0?"+":"",$.snr.toFixed(1)]})]},k))}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx(Ge,{className:"w-3 h-3 text-fg-muted flex-shrink-0"}),N===0&&!v?e.jsx("span",{className:"text-[10px] text-fg-muted font-medium",children:"Direct"}):v&&v.hops.length>0?v.hops.map(($,k)=>{const H=ai($,r);return e.jsxs("span",{className:"contents",children:[k>0&&e.jsx(Jr,{className:"w-2.5 h-2.5 text-fg-muted/50 flex-shrink-0"}),e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded bg-subtle-fill text-[10px]",children:[e.jsx("span",{className:"font-mono text-fg-primary",children:$}),H&&e.jsxs("span",{className:"text-fg-muted",children:["(",H,")"]})]})]},k)}):e.jsxs("span",{className:"text-[10px] text-fg-muted font-medium",children:[N," hop",N>1?"s":""]}),m!=null&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] text-fg-muted ml-0.5",children:[e.jsx(Ir,{className:"w-2.5 h-2.5"}),m>0?"+":"",m.toFixed(1),"dB"]}),(v==null?void 0:v.rssi)!=null&&e.jsxs("span",{className:"text-[10px] text-fg-muted",children:[v.rssi,"dBm"]})]}),v&&v.hops.length>=1&&e.jsx(n.Suspense,{fallback:As,children:e.jsx(Yo,{hops:v.hops,contacts:r,selfInfo:l,snr:m,wardriveCoords:R??void 0,wardriveSenderName:s.sender_name})})]}),c&&_&&e.jsx("div",{className:"mt-1.5",children:e.jsx(n.Suspense,{fallback:As,children:e.jsx(Xo,{text:s.text,timestamp:s.timestamp,contacts:r})})})]})})]})}),li=n.memo(function({messages:s,contacts:a,className:r,conversationKey:l,onRetry:i,onRetryAsFlood:o,onMentionClick:x,historyLoading:p,historyExhausted:j,onLoadOlder:c,channelName:f}){const y=n.useRef(null),b=n.useRef(null),[d,N]=n.useState(!1),S=n.useRef(s.length),h=n.useRef(0),_=n.useRef(l);n.useEffect(()=>{if(l!==_.current){_.current=l,S.current=s.length,h.current=0,N(!1);const m=y.current;m&&(m.scrollTop=m.scrollHeight)}},[l,s.length]);const E=n.useMemo(()=>ei(a),[a]),R=n.useMemo(()=>ti(a),[a]),w=mt(),C=Qo(s);n.useEffect(()=>{var I;const m=y.current;if(m){if(s.length>S.current&&h.current>0){const g=m.scrollHeight-h.current;if(g>0&&m.scrollTop<200){m.scrollTop+=g,S.current=s.length,h.current=0;return}}S.current=s.length,d||(I=b.current)==null||I.scrollIntoView({behavior:"smooth"})}},[s.length,d]);const T=n.useCallback(()=>{const m=y.current;if(!m)return;const I=m.scrollHeight-m.scrollTop-m.clientHeight;N(I>100),m.scrollTop<80&&c&&!p&&!j&&(h.current=m.scrollHeight,c())},[c,p,j]),v=n.useCallback(()=>{var m;(m=b.current)==null||m.scrollIntoView({behavior:"smooth"}),N(!1)},[]);let u="";return e.jsxs("div",{className:P("relative flex flex-col",r),children:[e.jsxs("div",{ref:y,onScroll:T,className:"flex-1 overflow-y-auto min-h-0 px-4 py-3",children:[p&&e.jsx("div",{className:"flex items-center justify-center py-3",children:e.jsx(oe,{className:"w-4 h-4 text-fg-muted animate-spin"})}),s.length===0?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("p",{className:"text-sm text-fg-muted",children:j?"No messages yet":"Loading messages…"})}):s.map(m=>{const I=Zo(m.timestamp),g=I!==u;u=I;const $=m.is_outgoing?m.failed?"failed":m.confirmed?"confirmed":m.unconfirmed?"unconfirmed":(m.retryAttempt??0)>0?"retrying":m.sent?"sent":"pending":void 0,k=m.is_channel&&m.channel_idx!=null?`ch:${m.channel_idx}`:m.sender_key;return e.jsxs("div",{children:[g&&e.jsx(Wr,{text:Jo(m.timestamp)}),e.jsx(ri,{msg:m,contact:R.get(m.sender_key),contacts:a,selfInfo:w,echoCount:C.get(m.id),channelName:f,children:e.jsx(Qr,{senderName:ni(m,E),text:m.text,timestamp:m.timestamp,isOutgoing:m.is_outgoing,status:$,onRetry:i&&m.failed?()=>i(k,m.id):void 0,onRetryAsFlood:o&&m.failed&&!m.is_channel?()=>o(k,m.id):void 0,retryAttempt:m.retryAttempt,maxRetries:m.maxRetries,echoCount:C.get(m.id),signed:!m.is_outgoing&&m.txt_type===Hn.SignedPlain,bubbleVariant:"subtle",onMentionClick:x})})]},m.id)}),e.jsx("div",{ref:b})]}),e.jsx("button",{onClick:v,className:P("absolute bottom-4 right-4 w-8 h-8 rounded-full bg-sys-blue flex items-center justify-center shadow-lg","hover:bg-sys-blue/90 transition-all duration-200",d?"opacity-100 translate-y-0":"opacity-0 translate-y-2 pointer-events-none"),children:e.jsx(Xr,{className:"w-4 h-4 text-white"})})]})}),oi=6,ii=n.memo(function({onSend:s,disabled:a,placeholder:r="Type a message…",className:l,mentionNames:i=[]}){const[o,x]=n.useState(""),[p,j]=n.useState(!1),c=n.useRef(null),[f,y]=n.useState(null),[b,d]=n.useState(-1),[N,S]=n.useState(0),h=n.useMemo(()=>{if(f==null)return[];const v=f.toLowerCase();return i.filter(u=>u.toLowerCase().includes(v)).slice(0,oi)},[f,i]),_=h.length>0;n.useEffect(()=>{S(0)},[h]);const E=n.useCallback(()=>{y(null),d(-1),S(0)},[]),R=n.useCallback(v=>{var k;if(b<0)return;const u=o.slice(0,b),m=((k=c.current)==null?void 0:k.selectionStart)??o.length,I=o.slice(m),g=`@[${v}] `,$=u+g+I;x($),E(),requestAnimationFrame(()=>{var te,W;const H=u.length+g.length;(te=c.current)==null||te.setSelectionRange(H,H),(W=c.current)==null||W.focus()})},[o,b,E]),w=n.useCallback(async()=>{var u;const v=o.trim();!v||p||a||(j(!0),E(),x(""),await s(v),j(!1),(u=c.current)==null||u.focus())},[o,p,a,s,E]),C=n.useCallback(v=>{const u=v.target.value;x(u);const m=v.target.selectionStart??u.length,I=u.slice(0,m),g=I.lastIndexOf("@");if(g>=0){const $=g>0?I[g-1]:" ";if(/\s/.test($)||g===0){const k=I.slice(g+1);if(!k.includes(" ")&&!k.includes("[")){y(k),d(g);return}}}E()},[E]),T=n.useCallback(v=>{if(_){if(v.key==="ArrowDown"){v.preventDefault(),S(u=>(u+1)%h.length);return}if(v.key==="ArrowUp"){v.preventDefault(),S(u=>(u-1+h.length)%h.length);return}if(v.key==="Enter"||v.key==="Tab"){v.preventDefault(),R(h[N]);return}if(v.key==="Escape"){v.preventDefault(),E();return}}v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),w())},[w,_,h,N,R,E]);return e.jsxs("div",{className:P("relative flex items-center gap-2 p-3 border-t border-edge-subtle",l),children:[_&&e.jsx("div",{className:"absolute bottom-full left-3 right-3 mb-1 radius-inset surface-elevated depth-raised overflow-hidden z-50",children:h.map((v,u)=>{const m=Pt(v),{emoji:I,cleanName:g}=Mt(v),$=Tt(v);return e.jsxs("button",{onMouseDown:k=>{k.preventDefault(),R(v)},className:P("w-full flex items-center gap-2.5 px-3 py-1.5 text-left transition-colors",u===N?"bg-sys-blue/10":"hover:bg-subtle-fill"),children:[e.jsx("div",{className:P("clay-avatar w-5 h-5",I?"text-xs":"text-white text-[9px] font-bold"),style:{"--avatar-color":m},children:I||$}),e.jsx("span",{className:"text-sm text-fg-primary truncate",children:g})]},v)})}),e.jsx("input",{ref:c,type:"text",value:o,onChange:C,onKeyDown:T,onBlur:()=>{setTimeout(E,150)},placeholder:r,disabled:a,className:"flex-1 min-w-0 w-full px-4 py-3 text-sm radius-inner bg-input-bg border border-input-border text-fg-primary placeholder:text-fg-muted/50 ring-focus-inset hover:border-edge-strong transition-colors"}),e.jsx("button",{onClick:w,disabled:!o.trim()||p||a,className:P("flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center transition-colors",o.trim()&&!a?"clay-send text-white":"bg-subtle-fill text-fg-muted cursor-not-allowed"),children:e.jsx(Bn,{className:"w-4.5 h-4.5 -translate-x-[0.5px] translate-y-[0.5px]",strokeWidth:2.5})})]})}),Ht="pymc_companion_room_pwd_";function ci(t){try{return localStorage.getItem(`${Ht}${t}`)}catch{return null}}function di(t,s){try{localStorage.setItem(`${Ht}${t}`,s)}catch{}}function Os(t){try{localStorage.removeItem(`${Ht}${t}`)}catch{}}const ui=n.memo(function({contact:s,loginStatus:a,onLogin:r,className:l}){const[i,o]=n.useState(""),[x,p]=n.useState(!0),[j,c]=n.useState(null),[f,y]=n.useState(!1),b=n.useRef(null),d=n.useRef(!0),N=s.public_key,S=n.useRef(N);S.current!==N&&(S.current=N,y(!1),c(null),o("")),n.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]),n.useEffect(()=>{if(f||a==="success")return;const R=ci(N);if(!R){y(!0);return}y(!0),(async()=>{const w=await r(N,R);d.current&&(w||(Os(N),c("Saved password rejected — please re-enter.")))})()},[N,f,a,r]);const h=n.useCallback(async()=>{c(null);const R=await r(N,i);d.current&&(R?x&&i?di(N,i):Os(N):c("Login failed — check your password and try again."))},[N,i,x,r]),_=n.useCallback(R=>{R.key==="Enter"&&(R.preventDefault(),h())},[h]),E=a==="pending";return E&&!i?e.jsxs("div",{className:P("flex-1 flex flex-col items-center justify-center gap-3",l),children:[e.jsx(oe,{className:"w-6 h-6 text-sys-pink animate-spin"}),e.jsxs("p",{className:"text-sm text-fg-muted",children:["Connecting to ",s.name||"room server","…"]})]}):e.jsx(ue.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2},className:P("flex-1 flex flex-col items-center justify-center px-6",l),children:e.jsxs("div",{className:"w-full max-w-xs space-y-5",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center ring-[1.5px] ring-sys-pink bg-sys-pink/8",children:e.jsx(dt,{className:"size-7 text-sys-pink"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"type-body font-medium text-fg-primary",children:s.name||"Room Server"}),e.jsx("p",{className:"text-xs text-fg-muted mt-1",children:"Enter the room password to join, or try logging in without one — some servers allow open access."})]})]}),(j||a==="failed")&&e.jsxs("div",{className:"flex items-start gap-2 p-2.5 rounded-lg bg-sys-red/8 border border-sys-red/15",children:[e.jsx(ua,{className:"w-3.5 h-3.5 text-sys-red flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-[11px] text-sys-red leading-relaxed",children:j||"Login failed — check your password and try again."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{ref:b,type:"password",value:i,onChange:R=>o(R.target.value),onKeyDown:_,placeholder:"Room password",disabled:E,autoFocus:!0,className:"w-full surface-input rounded-lg px-3 py-2.5 text-sm text-fg-primary placeholder:text-fg-muted/50 focus:outline-none focus:ring-1 focus:ring-sys-pink/40"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:x,onChange:R=>p(R.target.checked),disabled:E,className:"surface-checkbox w-3.5 h-3.5 rounded accent-sys-pink"}),e.jsx("span",{className:"text-xs text-fg-muted",children:"Remember password"})]}),e.jsxs(B,{color:"pink",className:"w-full justify-center",disabled:E,onClick:h,children:[E?e.jsx(oe,{"data-slot":"icon",className:"animate-spin"}):e.jsx(kt,{"data-slot":"icon"}),E?"Connecting…":"Login"]})]}),e.jsx("p",{className:"text-[10px] text-fg-muted/60 text-center leading-relaxed",children:"The server determines your permissions based on the password. Admin and guest passwords grant different access levels."})]})})});function zs(t,s){return[t,s].sort().join("-")}function st(t){return t.substring(0,2)}function mi(t){var a,r;const s=(r=(a=t.traceQuality)==null?void 0:a.composite)==null?void 0:r.mean;return s!=null&&s!==0?Math.max(.1,s+20):Math.max(.1,t.strength*20)}function pi(t,s,a,r){const{edgeMap:l}=a;if(l.size===0)return null;const i=new Map;for(const[,w]of l){const C=w.fromHash,T=w.toHash;i.has(C)||i.set(C,[]),i.has(T)||i.set(T,[]),i.get(C).push({neighbor:T,edge:w}),i.get(T).push({neighbor:C,edge:w})}const o=new Set(i.keys()),x=Hs(t,o),p=Hs(s,o);if(!x||!p||x===p)return null;const j=new Map,c=new Map,f=new Set,y=[];for(j.set(x,0),c.set(x,null),y.push({node:x,cost:0});y.length>0;){y.sort((T,v)=>T.cost-v.cost);const w=y.shift();if(f.has(w.node))continue;if(f.add(w.node),w.node===p)break;const C=i.get(w.node)??[];for(const{neighbor:T,edge:v}of C){if(f.has(T))continue;const u=mi(v),m=w.cost+1/u,I=j.get(T)??1/0;m{var $,k;const T=st(w),v=N.get(T);let u=0;const m=b[C],I=zs(m,w),g=l.get(I);return(k=($=g==null?void 0:g.traceQuality)==null?void 0:$.composite)!=null&&k.mean?u=g.traceQuality.composite.mean:(g==null?void 0:g.avgSnr)!=null&&(u=g.avgSnr),{hash:w,prefix:T,name:(v==null?void 0:v.name)||null,snr:u}});let _=0,E=0;for(let w=0;w0?_/E:0;return{hops:S.map(st),confidence:R,via:h}}function Hs(t,s){if(s.has(t))return t;const a=st(t);let r=null,l=0;for(const i of s)if(i.startsWith(a)||t.startsWith(i.substring(0,2))){let o=0;const x=Math.min(t.length,i.length);for(let p=0;pl&&(l=o,r=i)}return r}function Bs(t){switch(t&15){case 1:return"Companion";case 2:return"Repeater";case 3:return"Room Server";default:return"Unknown"}}function Gs(t){switch(t&15){case 1:return"blue";case 2:return"green";case 3:return"indigo";default:return"zinc"}}function hi(t){return(t&15)===2}const Ks=n.memo(function({contact:s,channel:a,contacts:r=[],selfPubKey:l,embedded:i=!1,onResetPath:o,onRequestStatus:x,onRequestTelemetry:p,onLoginToRepeater:j,onLogoutFromRepeater:c,onGetNeighbours:f,onTraceContactPath:y,onDiscoverPath:b,onExportContact:d,onSetContactPath:N,className:S}){const[h,_]=n.useState({}),E=(s==null?void 0:s.public_key)??null,[R,w]=n.useState(E);if(E!==R&&(w(E),_({})),!s&&!a)return i?null:e.jsx("div",{className:P("flex items-center justify-center h-full",S),children:e.jsx("p",{className:"text-sm text-fg-muted",children:"Select a conversation"})});async function C(m,I){_($=>({...$,[m]:"loading"}));const g=await I();_($=>({...$,[m]:g?"done":"error"})),setTimeout(()=>_($=>({...$,[m]:"idle"})),2e3)}const T=a?e.jsxs("div",{className:"space-y-4",children:[!i&&e.jsxs("div",{className:"flex flex-col items-center gap-2 pb-3 border-b border-edge-subtle",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-sys-indigo/15 flex items-center justify-center shadow-md",children:e.jsx(Fe,{className:"size-7 text-sys-indigo"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"type-body font-medium text-fg-primary",children:a.name}),e.jsxs(De,{color:"indigo",children:["Channel ",a.index]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted w-20",children:"Index"}),e.jsx("span",{className:"font-mono text-fg-primary",children:a.index})]}),e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted w-20",children:"Type"}),e.jsx("span",{className:"text-fg-primary",children:"Broadcast"})]})]}),e.jsx("div",{className:"pt-2 border-t border-edge-subtle",children:e.jsx("p",{className:"type-data-xs text-fg-muted/70",children:"Channel messages are broadcast-encrypted. Sender identity is not available due to MeshCore protocol limitations."})})]}):null,v=s?e.jsxs("div",{className:"space-y-4",children:[!i&&e.jsxs("div",{className:"flex flex-col items-center gap-2 pb-3 border-b border-edge-subtle",children:[e.jsx(bi,{contact:s}),e.jsxs("div",{className:"text-center",children:[e.jsxs("h3",{className:"type-body font-medium text-fg-primary flex items-center justify-center gap-1",children:[s.name||"Unknown",e.jsx(qs,{pubkey:s.public_key})]}),e.jsx(De,{color:Gs(s.adv_type),children:Bs(s.adv_type)})]})]}),i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{color:Gs(s.adv_type),children:Bs(s.adv_type)}),e.jsx(qs,{pubkey:s.public_key})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted w-20",children:"Public Key"}),e.jsx("span",{className:"font-mono text-fg-primary break-all text-[10px]",children:s.public_key})]}),e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx(Ge,{className:"w-3.5 h-3.5 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted",children:"Path Length"}),e.jsx("span",{className:"text-fg-primary ml-auto",children:s.out_path_len})]}),(s.gps_lat!==0||s.gps_lon!==0)&&e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx(ca,{className:"w-3.5 h-3.5 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted",children:"GPS"}),e.jsxs("span",{className:"text-fg-primary ml-auto font-mono text-[10px]",children:[s.gps_lat.toFixed(5),", ",s.gps_lon.toFixed(5)]})]}),(s.lastmod>0||s.last_advert_timestamp>0)&&e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx(ma,{className:"w-3.5 h-3.5 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted",children:"Last Heard"}),e.jsx("span",{className:"text-fg-primary ml-auto",children:new Date((s.lastmod||s.last_advert_timestamp)*1e3).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),s.last_advert_timestamp>0&&e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted",children:"Last Advert"}),e.jsx("span",{className:"text-fg-primary ml-auto",children:new Date(s.last_advert_timestamp*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})]}),e.jsx(ji,{contact:s,contacts:r,selfPubKey:l,onSetContactPath:N,onDiscoverPath:b,actionState:h,setActionState:_,runAction:C}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-edge-subtle",children:[e.jsxs(B,{color:h.reset==="done"?"success":h.reset==="error"?"danger":"primary",outline:!0,className:"w-full justify-center",disabled:h.reset==="loading",onClick:()=>C("reset",()=>o(s.public_key)),children:[e.jsx(da,{"data-slot":"icon"}),h.reset==="loading"?"Resetting…":h.reset==="done"?"Reset!":"Reset Path"]}),e.jsxs(B,{color:h.status==="done"?"success":h.status==="error"?"danger":"primary",outline:!0,className:"w-full justify-center",disabled:h.status==="loading",onClick:()=>C("status",()=>x(s.public_key)),children:[e.jsx(pa,{"data-slot":"icon"}),h.status==="loading"?"Requesting…":"Request Status"]}),e.jsxs(B,{color:h.telemetry==="done"?"success":h.telemetry==="error"?"danger":"primary",outline:!0,className:"w-full justify-center",disabled:h.telemetry==="loading",onClick:()=>C("telemetry",()=>p(s.public_key)),children:[e.jsx(ha,{"data-slot":"icon"}),h.telemetry==="loading"?"Requesting…":"Request Telemetry"]})]}),d&&e.jsxs(B,{color:"primary",outline:!0,className:"w-full justify-center",onClick:()=>d(s.public_key),children:[e.jsx(zt,{"data-slot":"icon"}),"Export Contact"]}),hi(s.adv_type)&&e.jsxs(e.Fragment,{children:[e.jsx(wi,{pubkey:s.public_key,onLogin:j,onLogout:c,actionState:h,runAction:C}),e.jsx(Ni,{pubkey:s.public_key,onGetNeighbours:f,actionState:h,runAction:C}),e.jsx(ki,{pubkey:s.public_key,contact:s,onTrace:y,actionState:h,runAction:C})]}),e.jsx(xi,{pubkey:s.public_key}),e.jsx(yi,{pubkey:s.public_key})]}):null,u=T??v;return i?e.jsx("div",{className:S,children:u}):e.jsx("div",{className:P("flex flex-col h-full overflow-y-auto",S),children:e.jsx(ge,{mode:"wait",children:a?e.jsx(ue.div,{variants:Zr,initial:"hidden",animate:"visible",exit:"exit",className:"p-4",children:T},`ch-${a.index}`):s?e.jsx(ue.div,{variants:el,initial:"hidden",animate:"visible",exit:"exit",className:"p-4",children:v},`contact-${s.public_key}`):null})})});function Us(t){const s=Math.floor(t/86400),a=Math.floor(t%86400/3600),r=Math.floor(t%3600/60);return s>0?`${s}d ${a}h`:a>0?`${a}h ${r}m`:`${r}m`}function xi({pubkey:t}){const s=Wn(t);return s?e.jsxs(_e,{defaultOpen:!0,className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(pa,{className:"w-3.5 h-3.5 text-sys-green"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Status"})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(Z,{label:"Battery",value:`${(s.battMilliVolts/1e3).toFixed(2)}V`}),e.jsx(Z,{label:"Noise Floor",value:`${s.noiseFloor} dBm`}),e.jsx(Z,{label:"Last RSSI",value:`${s.lastRssi} dBm`}),e.jsx(Z,{label:"Last SNR",value:`${(s.lastSnr/4).toFixed(1)} dB`}),e.jsx(Z,{label:"Uptime",value:Us(s.totalUpTimeSecs)}),e.jsx(Z,{label:"Air Time",value:Us(s.totalAirTimeSecs)}),e.jsx(Z,{label:"TX Queue",value:String(s.currTxQueueLen)}),e.jsx(Z,{label:"Packets Rx",value:String(s.nPacketsRecv)}),e.jsx(Z,{label:"Packets Tx",value:String(s.nPacketsSent)}),e.jsx(Z,{label:"Flood Rx/Tx",value:`${s.nRecvFlood}/${s.nSentFlood}`}),e.jsx(Z,{label:"Direct Rx/Tx",value:`${s.nRecvDirect}/${s.nSentDirect}`}),e.jsx(Z,{label:"Dups (D/F)",value:`${s.nDirectDups}/${s.nFloodDups}`}),s.errEvents>0&&e.jsx(Z,{label:"Errors",value:String(s.errEvents)})]})})]}):null}function Z({label:t,value:s}){return e.jsxs("div",{className:"flex items-center justify-between type-data-xs",children:[e.jsx("span",{className:"text-fg-muted",children:t}),e.jsx("span",{className:"text-fg-primary font-mono text-[10px]",children:s})]})}function fi(t){switch(t){case 100:return"Generic";case 101:return"Luminosity";case 102:return"Presence";case 103:return"Temperature";case 104:return"Humidity";case 115:return"Pressure";case 116:return"Voltage";case 117:return"Current";case 120:return"Percentage";case 125:return"Concentration";case 128:return"Power";case 136:return"GPS";default:return`Type ${t}`}}function gi(t){switch(t){case 103:return"°C";case 104:return"%";case 115:return" hPa";case 116:return"V";case 117:return"A";case 120:return"%";case 125:return" ppm";case 128:return"W";default:return""}}function yi({pubkey:t}){const s=Qn(t);if(!s)return null;const a=Eo(s.lppSensorData);return a.length===0?null:e.jsxs(_e,{defaultOpen:!0,className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(ha,{className:"w-3.5 h-3.5 text-sys-amber"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Telemetry"})]}),e.jsx(Ie,{children:e.jsx("div",{className:"space-y-1.5 py-1",children:a.map((r,l)=>typeof r.value=="object"?e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(Z,{label:`Ch${r.channel} GPS Lat`,value:r.value.latitude.toFixed(5)}),e.jsx(Z,{label:`Ch${r.channel} GPS Lon`,value:r.value.longitude.toFixed(5)}),e.jsx(Z,{label:`Ch${r.channel} GPS Alt`,value:`${r.value.altitude.toFixed(1)}m`})]},l):e.jsx(Z,{label:`Ch${r.channel} ${fi(r.type)}`,value:`${typeof r.value=="number"?r.value.toFixed(r.type===103||r.type===116?2:0):r.value}${gi(r.type)}`},l))})})]})}function bi({contact:t}){const{emoji:s}=Mt(t.name||""),a=Pt(t.name||t.public_key),r=t.name?Tt(t.name):t.public_key.slice(0,2).toUpperCase();return(t.adv_type&15)===2?e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center shadow-md ring-[1.5px] ring-sys-blue",children:e.jsx(ze,{className:"size-7 text-sys-blue"})}):(t.adv_type&15)===3?e.jsx("div",{className:"w-14 h-14 rounded-full flex items-center justify-center shadow-md ring-[1.5px] ring-sys-pink",children:e.jsx(dt,{className:"size-7 text-sys-pink"})}):e.jsx("div",{className:P("w-14 h-14 clay-avatar",s?"text-2xl":"text-white text-lg font-bold"),style:{"--avatar-color":a},children:s||r})}function qs({pubkey:t}){return Gn().get(t)!==!0?null:e.jsx("span",{title:"Ed25519 verified identity",children:e.jsx(al,{className:"w-4 h-4 text-sys-green flex-shrink-0"})})}const bt=64;function vi(t){if(!t)return[];const s=[];for(let a=0;a0,w=vi(t.out_path),C=n.useCallback(async()=>{if(!r)return;const u=c.split(",").map(g=>g.trim()).filter(Boolean);if(u.length===0){b("Enter at least one hop");return}if(u.length>bt){b(`Max ${bt} hops`);return}if(!u.every(g=>/^[0-9a-fA-F]{1,2}$/.test(g))){b("Each hop must be 1-2 hex characters");return}b(null),o(g=>({...g,path:"loading"}));const I=await r(t.public_key,u);o(g=>({...g,path:I?"done":"error"})),I&&j(!1),setTimeout(()=>o(g=>({...g,path:"idle"})),2e3)},[r,c,t.public_key,o]),T=n.useCallback(()=>{if(!a){h("Self identity not available");return}const u=pi(a,t.public_key,_,s);u?(N(u),h(null)):(N(null),h("No route found in topology"))},[a,t.public_key,_,s]),v=n.useCallback(async()=>{if(!r||!d)return;o(m=>({...m,path:"loading"}));const u=await r(t.public_key,d.hops);o(m=>({...m,path:u?"done":"error"})),u&&(N(null),h(null)),setTimeout(()=>o(m=>({...m,path:"idle"})),2e3)},[r,d,t.public_key,o]);return e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(Ge,{className:"w-3.5 h-3.5 text-sys-blue"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Path"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-muted font-mono",children:R?`${E} hop${E>1?"s":""}`:"direct"})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-2 py-1",children:[w.length>0&&e.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[e.jsx("span",{className:"text-fg-muted type-data-xs",children:"Route"}),w.map((u,m)=>e.jsx("span",{className:"px-1 py-0.5 rounded bg-subtle-fill font-mono text-[10px] text-fg-primary",children:u},m))]}),d&&e.jsxs("div",{className:"space-y-1.5 p-2 rounded-md bg-sys-green/5 border border-sys-green/20",children:[e.jsxs("div",{className:"flex items-center gap-1 type-data-xs text-sys-green",children:[e.jsx(Is,{className:"w-3 h-3"}),e.jsxs("span",{children:["Auto-route (",d.via.length," hop",d.via.length!==1?"s":"",", ",Math.round(d.confidence*100),"% confidence)"]})]}),e.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:d.via.map((u,m)=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1 py-0.5 rounded bg-subtle-fill text-[10px]",children:[e.jsx("span",{className:"font-mono text-fg-primary",children:u.prefix}),u.name&&e.jsxs("span",{className:"text-fg-muted",children:["(",u.name,")"]}),u.snr!==0&&e.jsx("span",{className:P("font-mono",lt(u.snr)),children:u.snr.toFixed(1)})]},m))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(B,{color:i.path==="done"?"success":"primary",outline:!0,className:"flex-1 justify-center text-xs",disabled:i.path==="loading",onClick:v,children:[e.jsx(be,{"data-slot":"icon"}),i.path==="loading"?"Saving…":"Accept"]}),e.jsxs(B,{plain:!0,className:"text-xs",onClick:()=>{N(null),h(null)},children:[e.jsx(ut,{"data-slot":"icon"}),"Dismiss"]})]})]}),S&&!d&&e.jsx("p",{className:"text-[9px] text-sys-amber",children:S}),r&&!d&&e.jsx("div",{className:"flex items-center gap-2",children:p?e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx("input",{type:"text",value:c,onChange:u=>{f(u.target.value),b(null)},placeholder:"e.g. a3, f7, 1b",className:"w-full surface-input rounded-md px-2 py-1 text-[10px] font-mono text-fg-primary placeholder:text-fg-muted/50"}),e.jsxs("p",{className:"text-[9px] text-fg-muted/60",children:["Comma-separated hex hop bytes (max ",bt,")"]}),y&&e.jsx("p",{className:"text-[9px] text-sys-red",children:y}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(B,{color:i.path==="done"?"success":i.path==="error"?"danger":"primary",outline:!0,className:"flex-1 justify-center text-xs",disabled:i.path==="loading"||!c.trim(),onClick:C,children:[e.jsx(lo,{"data-slot":"icon"}),i.path==="loading"?"Saving…":"Save"]}),e.jsx(B,{plain:!0,className:"text-xs",onClick:()=>{j(!1),b(null)},children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{j(!0),f(w.length>0?w.join(", "):""),b(null)},className:"text-[10px] text-sys-blue hover:text-sys-blue/80 transition-colors",children:"Edit path…"}),a&&_.edgeMap.size>0&&e.jsxs("button",{onClick:T,className:"inline-flex items-center gap-0.5 text-[10px] text-sys-indigo hover:text-sys-indigo/80 transition-colors",children:[e.jsx(Is,{className:"w-3 h-3"}),"Auto-route"]}),l&&e.jsxs("button",{onClick:()=>x("discover",()=>l(t.public_key)),disabled:i.discover==="loading",className:P("inline-flex items-center gap-0.5 text-[10px] transition-colors disabled:opacity-50",i.discover==="error"?"text-sys-red":"text-sys-green hover:text-sys-green/80"),children:[e.jsx(nl,{className:"w-3 h-3"}),i.discover==="loading"?"Discovering…":i.discover==="done"?"Discovered!":i.discover==="error"?"Failed":"Discover"]})]})})]})})]})}function wi({pubkey:t,onLogin:s,onLogout:a,actionState:r,runAction:l}){const[i,o]=n.useState(""),x=It(t);return s?e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(kt,{className:"w-3.5 h-3.5 text-sys-amber"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Login"}),x!=="idle"&&e.jsx(De,{color:x==="success"?"green":x==="failed"?"red":"amber",className:"ml-auto text-[9px]",children:x})]}),e.jsx(Ie,{children:e.jsx("div",{className:"space-y-1.5 py-1",children:x==="success"&&a?e.jsxs(B,{color:r.logout==="done"?"success":r.logout==="error"?"danger":"primary",outline:!0,className:"w-full justify-center text-xs",disabled:r.logout==="loading",onClick:()=>l("logout",()=>a(t)),children:[e.jsx(Un,{"data-slot":"icon"}),r.logout==="loading"?"Disconnecting…":"Disconnect"]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"password",value:i,onChange:p=>o(p.target.value),placeholder:"Repeater password",className:"w-full surface-input rounded-md px-2 py-1 text-[10px] text-fg-primary placeholder:text-fg-muted/50"}),e.jsxs(B,{color:x==="failed"?"danger":"primary",outline:!0,className:"w-full justify-center text-xs",disabled:r.login==="loading"||!i.trim(),onClick:()=>l("login",()=>s(t,i)),children:[e.jsx(kt,{"data-slot":"icon"}),r.login==="loading"?"Logging in…":"Login"]})]})})})]}):null}function Ni({pubkey:t,onGetNeighbours:s,actionState:a,runAction:r}){const l=qn(t),i=It(t);return s?e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(wt,{className:"w-3.5 h-3.5 text-sys-green"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Neighbours"}),l&&e.jsx("span",{className:"ml-auto text-[10px] text-fg-muted",children:l.total})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs(B,{color:"primary",outline:!0,className:"w-full justify-center text-xs",disabled:a.neighbours==="loading"||i!=="success",onClick:()=>r("neighbours",()=>s(t)),children:[e.jsx(wt,{"data-slot":"icon"}),a.neighbours==="loading"?"Loading…":"Get Neighbours"]}),i!=="success"&&e.jsx("p",{className:"text-[9px] text-fg-muted/60",children:"Login required to query neighbours"}),l&&l.neighbours.length>0&&e.jsx("div",{className:"space-y-1",children:[...l.neighbours].sort((o,x)=>x.snr-o.snr).map((o,x)=>e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-primary font-mono text-[10px] w-16 truncate",children:o.name||o.prefixHex.slice(0,8)}),e.jsx("span",{className:"text-fg-muted text-[9px]",children:Si(o.heardAgo)}),e.jsxs("div",{className:"flex-1 flex items-center gap-1 ml-auto",children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-subtle-fill overflow-hidden",children:e.jsx("div",{className:P("h-full rounded-full",Ci(o.snr)),style:{width:`${Math.min(100,Math.max(5,(o.snr+20)/35*100))}%`}})}),e.jsx("span",{className:P("font-mono text-[9px] w-8 text-right",lt(o.snr)),children:o.snr.toFixed(1)})]})]},x))})]})})]}):null}function ki({pubkey:t,contact:s,onTrace:a,actionState:r,runAction:l}){const i=Vn(t);if(!a)return null;const o=s.out_path_len>0;return e.jsxs(_e,{className:"pt-2 border-t border-edge-subtle",children:[e.jsxs(Re,{className:"px-0 py-1 flex items-center gap-1.5 w-full text-left",children:[e.jsx(Es,{className:"w-3.5 h-3.5 text-sys-indigo"}),e.jsx("span",{className:"type-data-xs text-fg-muted uppercase tracking-wide",children:"Trace"}),i&&e.jsxs("span",{className:"ml-auto text-[10px] text-fg-muted",children:[i.pathLen," hops"]})]}),e.jsx(Ie,{children:e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs(B,{color:"primary",outline:!0,className:"w-full justify-center text-xs",disabled:r.trace==="loading"||!o,onClick:()=>l("trace",()=>a(t)),children:[e.jsx(Es,{"data-slot":"icon"}),r.trace==="loading"?"Tracing…":"Trace Path"]}),!o&&e.jsx("p",{className:"text-[9px] text-fg-muted/60",children:"Direct neighbour — no path to trace"}),i&&i.hops.length>0&&e.jsxs("div",{className:"space-y-1",children:[i.hops.map((x,p)=>e.jsxs("div",{className:"flex items-center gap-2 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted text-[9px] w-3",children:p+1}),e.jsx("span",{className:"px-1 py-0.5 rounded bg-subtle-fill font-mono text-[10px] text-fg-primary",children:x.hash}),x.name&&e.jsx("span",{className:"text-fg-muted text-[10px] truncate",children:x.name}),e.jsxs("span",{className:P("font-mono text-[10px] ml-auto",lt(x.snr)),children:[x.snr.toFixed(1)," dB"]})]},p)),e.jsxs("div",{className:"flex items-center justify-between type-data-xs pt-1 border-t border-edge-subtle",children:[e.jsx("span",{className:"text-fg-muted",children:"Last SNR"}),e.jsxs("span",{className:P("font-mono text-[10px]",lt(i.lastSnr)),children:[i.lastSnr.toFixed(1)," dB"]})]})]})]})})]})}function lt(t){return t>5?"text-sys-green":t>0?"text-sys-amber":"text-sys-red"}function Ci(t){return t>5?"bg-sys-green":t>0?"bg-sys-amber":"bg-sys-red"}function Si(t){return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}d`}const Vs=128,Ws=/^[0-9a-fA-F]+$/;function _i({open:t,onClose:s}){const a=se(k=>k.exportPrivateKey),r=se(k=>k.importPrivateKey),[l,i]=n.useState("export"),[o,x]=n.useState(null),[p,j]=n.useState(!1),[c,f]=n.useState(!1),[y,b]=n.useState(""),[d,N]=n.useState(!1),[S,h]=n.useState(!1),[_,E]=n.useState(!1),[R,w]=n.useState(!1),[C,T]=n.useState(null),[v,u]=n.useState(!1);t!==v&&(u(t),t&&(i("export"),x(null),j(!1),f(!1),b(""),N(!1),h(!1),E(!1),w(!1),T(null)));const m=n.useCallback(async()=>{j(!0),T(null),w(!1);try{const k=await a();k==="disabled"?w(!0):x(k.hex)}catch(k){T(k instanceof Error?k.message:"Export failed")}finally{j(!1)}},[a]),I=n.useCallback(async()=>{if(o)try{await navigator.clipboard.writeText(o),f(!0),setTimeout(()=>f(!1),2e3)}catch{T("Failed to copy to clipboard")}},[o]),g=y.length===Vs&&Ws.test(y),$=n.useCallback(async()=>{h(!1),N(!0),T(null),w(!1);try{await r(y)==="disabled"?w(!0):E(!0)}catch(k){T(k instanceof Error?k.message:"Import failed")}finally{N(!1)}},[r,y]);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{open:t,onClose:s,size:"md",children:[e.jsx(Ee,{icon:e.jsx(fa,{className:"w-5 h-5"}),title:"Key Management",onClose:s}),e.jsxs(we,{children:[R&&e.jsxs("div",{className:"flex items-start gap-2.5 p-3 mb-4 rounded-lg bg-sys-amber/10 border border-sys-amber/20",children:[e.jsx(Yn,{className:"w-4 h-4 text-sys-amber flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"type-body-sm font-medium text-sys-amber",children:"Key operations disabled"}),e.jsx("p",{className:"type-data-xs text-fg-muted mt-0.5",children:"This device's firmware has disabled private key export/import. This is a security setting configured at build time and cannot be changed remotely."})]})]}),e.jsx("div",{className:"flex gap-1 mb-4 p-0.5 rounded-lg bg-subtle-fill",children:["export","import"].map(k=>e.jsxs("button",{onClick:()=>{i(k),T(null)},className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 px-3 rounded-md text-sm font-medium transition-colors",l===k?"bg-surface text-fg-primary shadow-sm":"text-fg-muted hover:text-fg-secondary"),children:[k==="export"?e.jsx(He,{className:"w-3.5 h-3.5"}):e.jsx(zt,{className:"w-3.5 h-3.5"}),k==="export"?"Export":"Import"]},k))}),l==="export"&&e.jsx("div",{className:"space-y-4",children:o?e.jsxs(re,{children:[e.jsx(le,{children:"Private Key (64 bytes)"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"p-3 rounded-lg bg-subtle-fill border border-edge-subtle font-mono text-xs break-all select-all leading-relaxed",children:o}),e.jsx("button",{onClick:I,className:"absolute top-2 right-2 p-1.5 rounded-md hover:bg-subtle-fill-strong transition-colors",title:"Copy to clipboard",children:c?e.jsx(be,{className:"w-3.5 h-3.5 text-sys-green"}):e.jsx(Et,{className:"w-3.5 h-3.5 text-fg-muted"})})]}),e.jsx(ke,{children:e.jsxs("span",{className:"flex items-start gap-1.5 mt-1",children:[e.jsx(Be,{className:"w-3 h-3 text-sys-amber flex-shrink-0 mt-0.5"}),"This key controls your mesh identity. Never share it."]})})]}):e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"type-body-sm text-fg-muted mb-3",children:"Export your device's private key for backup. Keep it secret — anyone with this key can impersonate your mesh identity."}),e.jsx(B,{color:"primary",onClick:m,disabled:p||R,children:p?"Exporting…":"Export Private Key"})]})}),l==="import"&&e.jsx("div",{className:"space-y-4",children:_?e.jsxs("div",{className:"text-center py-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-sys-green/10 mx-auto mb-3 flex items-center justify-center",children:e.jsx(be,{className:"w-5 h-5 text-sys-green"})}),e.jsx("p",{className:"type-body-sm font-medium text-fg-primary",children:"Key imported successfully"}),e.jsx("p",{className:"type-data-xs text-fg-muted mt-1",children:"The device identity has been updated. You may need to reconnect."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(re,{children:[e.jsx(le,{children:"Private Key (128 hex characters)"}),e.jsx("textarea",{value:y,onChange:k=>b(k.target.value.replace(/\s/g,"")),placeholder:"Paste your 128-character hex private key here…",rows:3,className:"w-full p-3 rounded-lg bg-subtle-fill border border-edge-subtle font-mono text-xs resize-none focus:outline-none focus:ring-2 focus:ring-sys-blue/50 placeholder:text-fg-muted/40"}),e.jsxs(ke,{children:[y.length>0&&!g&&e.jsx("span",{className:"text-sys-red",children:Ws.test(y)?`${y.length}/${Vs} characters`:"Invalid characters — hex only (0-9, a-f)"}),y.length>0&&g&&e.jsx("span",{className:"text-sys-green",children:"Valid key format ✓"})]})]}),e.jsxs("div",{className:"flex items-start gap-2.5 p-3 rounded-lg bg-sys-red/5 border border-sys-red/10",children:[e.jsx(Be,{className:"w-4 h-4 text-sys-red flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"type-data-xs text-fg-muted",children:["Importing a key ",e.jsx("strong",{className:"text-fg-secondary",children:"permanently replaces"})," the device's current identity. All existing contacts will see you as a new node."]})]})]})}),C&&e.jsx("p",{className:"type-data-xs text-sys-red mt-3",children:C})]}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Close"}),l==="import"&&!_&&e.jsx(B,{color:"danger",onClick:()=>h(!0),disabled:!g||d||R,children:d?"Importing…":"Import Key"})]})]}),e.jsx(xa,{isOpen:S,title:"Replace Device Identity?",message:"This will permanently replace the device's Ed25519 private key. The current identity cannot be recovered unless you have a backup. Continue?",confirmLabel:"Replace Key",cancelLabel:"Cancel",variant:"danger",onConfirm:$,onCancel:()=>h(!1)})]})}function _a(t){return t.settings??{}}const Ra="pymc_companion_recent_regions",Bt=8;function Ia(){try{const t=localStorage.getItem(Ra);return t?JSON.parse(t).slice(0,Bt):[]}catch{return[]}}function Ri(t){try{localStorage.setItem(Ra,JSON.stringify(t.slice(0,Bt)))}catch{}}function Ii(t){const s=Ia().filter(r=>r!==t);s.unshift(t);const a=s.slice(0,Bt);return Ri(a),a}function Qs(t){return t.toLowerCase().replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Ei({open:t,onClose:s,mode:a,identity:r,onSave:l}){const i=a==="edit"&&r,[o,x]=n.useState(""),[p,j]=n.useState(""),[c,f]=n.useState(""),[y,b]=n.useState(!1),[d,N]=n.useState(""),[S,h]=n.useState(5e3),[_,E]=n.useState("0.0.0.0"),[R,w]=n.useState(!1),[C,T]=n.useState(null),[v,u]=n.useState(""),m=`${t}-${(r==null?void 0:r.name)??""}-${a}`;if(m!==v)if(u(m),T(null),w(!1),b(!1),i){const g=_a(r);x(r.name),j(""),f(r.identity_key??""),N(g.node_name??r.name),h(g.tcp_port??5e3),E(g.bind_address??"0.0.0.0")}else x(""),j(""),f(""),N(""),h(5e3),E("0.0.0.0");const I=n.useCallback(async()=>{var g,$;if(!i&&!o.trim()){T("Name is required");return}w(!0),T(null);try{if(i){const k={name:r.name,new_name:p,identity_key:c,type:"companion",settings:{node_name:d,tcp_port:S,bind_address:_}},H=await nr(k);if(!H.success&&!((g=H.data)!=null&&g.message))throw new Error(H.error||"Failed")}else{const k={name:o.trim(),identity_key:c,type:"companion",settings:{node_name:d||o.trim(),tcp_port:S??5e3,bind_address:_||"0.0.0.0"}},H=await rr(k);if(!H.success&&!(($=H.data)!=null&&$.message))throw new Error(H.error||"Failed")}await l(),s()}catch(k){T(k instanceof Error?k.message:"Operation failed")}finally{w(!1)}},[i,r,o,p,c,d,S,_,l,s]);return e.jsxs(je,{open:t,onClose:s,size:"md",children:[e.jsx(Ee,{icon:i?void 0:e.jsx(ye,{className:"w-5 h-5"}),title:i?"Edit Companion":"Add Companion",onClose:s}),e.jsx(we,{children:e.jsxs("div",{className:"space-y-5",children:[i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{color:r.registered?"green":"red",children:r.registered?"Active":"Inactive"}),r.hash&&e.jsx("span",{className:"type-data-xs text-fg-muted",children:r.hash})]}),i?e.jsxs(e.Fragment,{children:[e.jsxs(re,{children:[e.jsx(le,{children:"Current Name"}),e.jsx(pe,{value:r.name,disabled:!0})]}),e.jsxs(re,{children:[e.jsxs(le,{children:["New Name ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(Optional)"})]}),e.jsx(pe,{value:p,onChange:g=>j(g.target.value),placeholder:"Leave empty to keep current name"})]})]}):e.jsxs(re,{children:[e.jsx(le,{children:"Name"}),e.jsx(pe,{value:o,onChange:g=>x(g.target.value),placeholder:"e.g., TestCompanion",autoFocus:!0})]}),e.jsxs(re,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(le,{children:["Identity Key ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(Optional)"})]}),e.jsx("button",{type:"button",onClick:()=>b(g=>!g),className:"type-data-xs text-fg-muted underline hover:text-fg-secondary",children:y?"Hide":"Show"})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx(pe,{value:c,onChange:g=>f(g.target.value),placeholder:i?"Leave empty to keep current key":"Leave empty to auto-generate",className:"font-mono"}),e.jsx(ke,{children:"32 or 64 bytes hex."})]})]}),e.jsxs(re,{children:[e.jsx(le,{children:"Node Name"}),e.jsx(pe,{value:d,onChange:g=>N(g.target.value),placeholder:"Display name"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(re,{children:[e.jsx(le,{children:"TCP Port"}),e.jsx(pe,{type:"number",min:1,max:65535,value:S,onChange:g=>h(parseInt(g.target.value,10)||5e3)})]}),e.jsxs(re,{children:[e.jsx(le,{children:"Bind Address"}),e.jsx(pe,{value:_,onChange:g=>E(g.target.value),placeholder:"0.0.0.0"})]})]}),C&&e.jsx("p",{className:"type-data-xs text-sys-red",children:C})]})}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Cancel"}),e.jsx(B,{color:"primary",onClick:I,disabled:R,children:R?"Saving…":i?"Save":"Create"})]})]})}function Mi(){const t=sr(),s=oa(),{setFloodScope:a,clearFloodScope:r}=se.getState(),[l,i]=n.useState(""),[o,x]=n.useState(!1),[p,j]=n.useState(Ia),[c,f]=n.useState(null),y=n.useRef(null),b=l.trim()?Qs(l.trim()):"",d=n.useCallback(async h=>{const _=Qs(h);if(!_)return;x(!0),f(null),i(""),j(Ii(_)),await a(_)||f("Failed to set transport key on device"),x(!1)},[a]),N=n.useCallback(async()=>{x(!0),f(null),await r()||f("Failed to clear transport key on device"),x(!1)},[r]),S=n.useCallback(h=>{h.key==="Enter"&&b&&(h.preventDefault(),d(b))},[b,d]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5 p-3 rounded-lg bg-sys-blue/5 border border-sys-blue/10",children:[e.jsx(nt,{className:"w-4 h-4 text-sys-blue flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"type-data-xs text-fg-muted",children:["A transport key filters which flood packets the companion device forwards. Set a region name to derive a SHA-256 transport key from ",e.jsx("code",{className:"text-fg-secondary",children:"#name"}),". Only one transport key can be active at a time."]})]}),e.jsx("div",{className:"bg-subtle-fill radius-inner p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ga,{className:"w-4 h-4 text-fg-muted"}),e.jsx("span",{className:"type-body-sm text-fg-muted",children:"Active Transport Key"})]}),t?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sys-green/10 text-sys-green type-data font-medium",children:[e.jsx(ca,{className:"w-3.5 h-3.5"}),"#",t]}),e.jsx("button",{onClick:N,disabled:o||!s,className:"p-1.5 rounded-lg hover:bg-sys-red/10 transition-colors disabled:opacity-50",title:"Clear transport key",children:o?e.jsx(oe,{className:"w-3.5 h-3.5 text-fg-muted animate-spin"}):e.jsx(ut,{className:"w-3.5 h-3.5 text-fg-muted hover:text-sys-red"})})]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-subtle-fill-strong text-fg-muted type-data",children:[e.jsx(ar,{className:"w-3.5 h-3.5"}),"Global (no filter)"]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"type-label text-fg-muted block mb-2",children:"Set Region"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-fg-muted/50 type-data",children:"#"}),e.jsx("input",{ref:y,type:"text",value:l,onChange:h=>i(h.target.value),onKeyDown:S,placeholder:"e.g., south-bay",disabled:!s,className:"w-full pl-7 pr-3 py-2 rounded-lg bg-subtle-fill border border-edge-subtle text-sm text-fg-primary placeholder:text-fg-muted/40 focus:outline-none focus:ring-2 focus:ring-sys-blue/50 disabled:opacity-50"})]}),e.jsxs(B,{color:"primary",onClick:()=>d(b),disabled:!b||o||!s,children:[o?e.jsx(oe,{"data-slot":"icon",className:"animate-spin"}):null,"Set"]})]}),b&&b!==l.trim().toLowerCase()&&e.jsxs("p",{className:"type-data-xs text-fg-muted mt-1",children:["Will set as ",e.jsxs("span",{className:"font-mono text-fg-secondary",children:["#",b]})]})]}),p.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ma,{className:"w-3.5 h-3.5 text-fg-muted/50"}),e.jsx("span",{className:"type-label text-fg-muted",children:"Recent Regions"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(h=>e.jsx("button",{onClick:()=>d(h),disabled:o||!s,className:P("inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-medium transition-colors","disabled:opacity-50 disabled:cursor-not-allowed",h===t?"bg-sys-green/10 text-sys-green":"bg-subtle-fill hover:bg-subtle-fill-strong text-fg-secondary"),children:e.jsxs("span",{className:"font-mono",children:["#",h]})},h))})]}),!s&&e.jsx("p",{className:"type-data-xs text-sys-amber",children:"Companion device is not connected. Connect to a companion to manage transport keys."}),c&&e.jsx("p",{className:"type-data-xs text-sys-red",children:c})]})}function Ys({open:t,onClose:s,onRefresh:a}){const[r,l]=n.useState("companions"),[i,o]=n.useState(null),[x,p]=n.useState(!0),[j,c]=n.useState(!1),[f,y]=n.useState("create"),[b,d]=n.useState(null),[N,S]=n.useState(null),[h,_]=n.useState(!1),[E,R]=n.useState(!1),w=n.useRef(!0);n.useEffect(()=>(w.current=!0,()=>{w.current=!1}),[]);const[C,T]=n.useState(!1);t!==C&&(T(t),t&&l("companions"));const v=n.useCallback(async()=>{p(!0);try{const F=await Xn();w.current&&F.success&&F.data&&o(F.data)}catch{}finally{w.current&&p(!1)}},[]);n.useEffect(()=>{t&&v()},[t,v]);const u=(i==null?void 0:i.configured_companions)??[],m=n.useCallback(async()=>{await v(),a==null||a()},[v,a]),I=n.useCallback(async()=>{if(N){_(!0);try{await Jn(N.name,"companion"),await m()}catch{}finally{w.current&&(_(!1),S(null))}}},[N,m]),g=Zn(),$=la(),{setCompanionPaused:k}=se.getState(),[H,te]=n.useState({});n.useEffect(()=>{if(!(i!=null&&i.configured_companions))return;const F={};for(const D of i.configured_companions)F[D.name]=er(D.name);te(F)},[i]);const W=n.useCallback(F=>F===$?g:H[F]??!1,[$,g,H]),[L,V]=n.useState(null),ie=n.useCallback(async(F,D)=>{V(F);try{await k(F,!D),te(A=>({...A,[F]:!D}))}finally{w.current&&V(null)}},[k]);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{open:t,onClose:s,size:"md",children:[e.jsx(Ee,{icon:e.jsx(ye,{className:"w-5 h-5"}),title:"Companion Configuration",onClose:s}),e.jsxs(we,{children:[e.jsx("div",{className:"flex gap-1 mb-4 p-0.5 rounded-lg bg-subtle-fill",children:[["companions","Companions",ye],["transport","Transport Key",ga]].map(([F,D,A])=>e.jsxs("button",{onClick:()=>l(F),className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 px-3 rounded-md text-sm font-medium transition-colors",r===F?"bg-surface text-fg-primary shadow-sm":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx(A,{className:"w-3.5 h-3.5"}),D]},F))}),r==="companions"&&e.jsx(e.Fragment,{children:x?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(oe,{className:"w-5 h-5 animate-spin text-sys-blue mr-2"}),e.jsx("span",{className:"text-sm text-fg-muted",children:"Loading…"})]}):u.length>0?e.jsx("div",{className:"space-y-3",children:u.map(F=>{const D=_a(F),A=W(F.name),O=!A&&F.registered,G=L===F.name;return e.jsxs("div",{className:P("bg-subtle-fill radius-inner p-3 hover:bg-subtle-fill-strong transition-base",A&&"opacity-60"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:P("h-2 w-2 rounded-full flex-shrink-0",O?"bg-sys-green":A?"bg-fg-muted":"bg-sys-red")}),e.jsx("h3",{className:"type-body-sm text-fg-primary font-medium truncate flex-1",children:F.name}),e.jsx(De,{color:O?"green":A?"zinc":"red",children:A?"Paused":O?"Active":"Inactive"}),e.jsx(B,{color:"primary",plain:!0,onClick:()=>{d(F),y("edit"),c(!0)},children:e.jsx(rl,{"data-slot":"icon"})}),e.jsx(tr,{enabled:!A,onChange:Q=>ie(F.name,Q),size:"sm",disabled:G,status:G?"loading":"idle",tooltip:A?"Resume connection":"Pause connection",dangerOff:!0}),e.jsx(B,{color:"danger",plain:!0,onClick:()=>S(F),children:e.jsx(Ke,{"data-slot":"icon"})})]}),e.jsxs("div",{className:"mt-1.5 type-data-xs text-fg-muted pl-5",children:[D.node_name||F.name," · Port ",D.tcp_port??5e3," · ",D.bind_address||"0.0.0.0"]})]},F.name)})}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-subtle-fill mx-auto mb-3 flex items-center justify-center",children:e.jsx(ye,{className:"w-5 h-5 text-fg-muted/50"})}),e.jsx("p",{className:"text-sm text-fg-muted",children:"No companions configured"})]})}),r==="transport"&&e.jsx(Mi,{})]}),e.jsxs(Me,{children:[r==="companions"&&e.jsx(B,{plain:!0,onClick:()=>R(!0),title:"Key Management",children:e.jsx(fa,{"data-slot":"icon"})}),e.jsx("div",{className:"flex-1"}),e.jsx(B,{plain:!0,onClick:s,children:"Close"}),r==="companions"&&e.jsxs(B,{color:"primary",onClick:()=>{d(null),y("create"),c(!0)},children:[e.jsx(Ue,{"data-slot":"icon"})," Add Companion"]})]})]}),e.jsx(Ei,{open:j,onClose:()=>c(!1),mode:f,identity:b,onSave:m}),e.jsx(xa,{isOpen:!!N,title:"Delete Companion",message:`Delete '${N==null?void 0:N.name}'? A service restart is required.`,confirmLabel:h?"Deleting…":"Delete",cancelLabel:"Cancel",variant:"danger",onConfirm:I,onCancel:()=>S(null)}),e.jsx(_i,{open:E,onClose:()=>R(!1)})]})}const Pi=n.memo(function({companions:s,selected:a,onSelect:r}){return s.length<2?null:e.jsx("select",{value:a??"",onChange:l=>r(l.target.value),className:"px-2 py-1 text-sm bg-transparent border border-edge-subtle radius-inner text-fg-primary focus:outline-none focus:ring-1 focus:ring-sys-blue/40",children:s.map(l=>e.jsx("option",{value:l.companion_name,children:l.node_name||l.companion_name},l.companion_name))})}),Oe=[{value:"Chat Node",label:"Companions"},{value:"Room Server",label:"Room Servers"},{value:"Repeater",label:"Repeaters"}],Ti=[{value:"all",label:"All time"},{value:"24h",label:"Last 24 hours"},{value:"7d",label:"Last 7 days"},{value:"30d",label:"Last 30 days"}];function $i(t){switch(t){case"24h":return 24;case"7d":return 168;case"30d":return 720;default:return}}function Di({open:t,onClose:s,companionName:a,onImport:r}){const[l,i]=n.useState(()=>new Set(Oe.map(R=>R.value))),[o,x]=n.useState("all"),[p,j]=n.useState(""),[c,f]=n.useState(!1),[y,b]=n.useState(null),[d,N]=n.useState(t);t!==d&&(N(t),t&&(i(new Set(Oe.map(R=>R.value))),x("all"),j(""),f(!1),b(null)));const S=l.size===Oe.length;function h(R){i(w=>{const C=new Set(w);return C.has(R)?C.delete(R):C.add(R),C})}function _(){i(S?new Set:new Set(Oe.map(R=>R.value)))}const E=n.useCallback(async()=>{if(!(l.size===0||c)){f(!0),b(null);try{const R={types:[...l],hours:$i(o)},w=parseInt(p,10);w>0&&(R.limit=w);const C=await r(R);b(C)}finally{f(!1)}}},[l,o,p,c,r]);return e.jsxs(je,{open:t,onClose:s,size:"sm",children:[e.jsx(Ee,{title:"Import repeater contacts",onClose:s}),e.jsx(we,{children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("p",{className:"text-sm text-fg-secondary",children:["Seed ",e.jsx("strong",{className:"text-fg-primary",children:a})," with contacts from the repeater's adverts. Results are ordered by most recent first."]}),e.jsxs(re,{children:[e.jsx(le,{children:"Contact types"}),e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsx(ws,{checked:S,indeterminate:l.size>0&&!S,onChange:_,label:"All types",size:"sm"}),e.jsx("div",{className:"ml-6 space-y-1.5",children:Oe.map(R=>e.jsx(ws,{checked:l.has(R.value),onChange:()=>h(R.value),label:R.label,size:"sm"},R.value))})]})]}),e.jsx(fo,{label:"Recency",value:o,onChange:x,options:Ti,orientation:"horizontal",size:"sm"}),e.jsxs(re,{children:[e.jsxs(le,{children:["Import at most ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(optional)"})]}),e.jsx(pe,{type:"number",min:1,value:p,onChange:R=>j(R.target.value),placeholder:"No limit",className:"mt-1"}),e.jsx(ke,{children:"Leave empty for no cap."})]}),y&&e.jsxs("p",{className:"text-sm text-sys-green font-medium",children:["Imported ",y.added," new contact",y.added!==1?"s":""," (",y.total," total)"]})]})}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:"Cancel"}),e.jsx(B,{color:"primary",onClick:E,disabled:c||l.size===0,children:c?e.jsxs(e.Fragment,{children:[e.jsx(oe,{"data-slot":"icon",className:"animate-spin"}),"Importing…"]}):"Import"})]})]})}const Fi=["alameda","alpine","amador","butte","calaveras","colusa","contracosta","contra-costa","delnorte","del-norte","eldorado","el-dorado","fresno","glenn","humboldt","imperial","inyo","kern","kings","lake","lassen","losangeles","los-angeles","la-county","madera","marin","mariposa","mendocino","merced","modoc","mono","monterey","napa","nevada","orange","oc","placer","plumas","riverside","sacramento","sac","sanbenito","san-benito","sanbernardino","san-bernardino","sandiego","san-diego","sd","sanfrancisco","san-francisco","sf","sanjoaquin","san-joaquin","sanluisobispo","san-luis-obispo","slo","sanmateo","san-mateo","santabarbara","santa-barbara","sb","santaclara","santa-clara","santacruz","santa-cruz","shasta","sierra","siskiyou","solano","sonoma","stanislaus","sutter","tehama","trinity","tulare","tuolumne","ventura","yolo","yuba","losangeles","los-angeles","la","hollywood","westhollywood","west-hollywood","weho","beverlyhills","beverly-hills","santamonica","santa-monica","culvercity","culver-city","marinadelrey","marina-del-rey","venice","venicebeach","venice-beach","malibu","palisades","pacificpalisades","pacific-palisades","brentwood","westwood","westla","west-la","dtla","downtown","downtownla","downtown-la","koreatown","ktown","silverlake","silver-lake","losfeliz","los-feliz","echopark","echo-park","eastla","east-la","boyleheights","boyle-heights","highlandpark","highland-park","eaglerock","eagle-rock","pasadena","southpasadena","south-pasadena","glendale","burbank","tolucalake","toluca-lake","studiocity","studio-city","shermanoaks","sherman-oaks","encino","tarzana","reseda","vannuys","van-nuys","northhollywood","north-hollywood","noho","woodlandhills","woodland-hills","calabasas","topanga","agourahills","agoura-hills","thousandoaks","thousand-oaks","simivalley","simi-valley","simi","moorpark","camarillo","oxnard","porthueneme","port-hueneme","ventura","ojai","sfv","sfvalley","sf-valley","thevalley","the-valley","sanfernando","san-fernando","sanfernandovalley","san-fernando-valley","pacoima","sylmar","sunland","tujunga","sunlandtujunga","lakeviewterrace","lakeview-terrace","shadowhills","shadow-hills","chatsworth","northridge","granadahills","granada-hills","missionhills","mission-hills","panoramacity","panorama-city","arleta","sunvalley","sun-valley","santaclarita","santa-clarita","scv","valencia","newhall","saugus","canyoncountry","canyon-country","castaic","stevenson","stevensonranch","stevenson-ranch","acton","agua-dulce","aguadulce","palmdale","lancaster","antelopevalley","antelope-valley","av","avmesh","av-mesh","quartz-hill","quartzhill","littlerock","little-rock","pearblossom","pear-blossom","lakelosangeles","lake-los-angeles","highdesert","high-desert","hd","hdmesh","hd-mesh","victorville","hesperia","applevalley","apple-valley","barstow","adelanto","phelan","pinon-hills","pinonhills","wrightwood","bigbear","big-bear","lakeisabella","lake-isabella","inlandempire","inland-empire","ie","riverside","corona","moreno-valley","morenovalley","fontana","ontario","rancho","ranchocucamonga","rancho-cucamonga","upland","claremont","pomona","azusa","glendora","covina","westcovina","west-covina","diamondbar","diamond-bar","chino","chinohills","chino-hills","sanbernardinocity","rialto","colton","redlands","yuciapa","yucaipa","beaumont","banning","hemet","perris","menifee","temecula","murrieta","wildomar","lakeland","lakeelsinore","lake-elsinore","orangecounty","orange-county","oc","anaheim","fullerton","santaana","santa-ana","irvine","costamesa","costa-mesa","newportbeach","newport-beach","newport","huntingtonbeach","huntington-beach","hb","surfcity","surf-city","lagunabeach","laguna-beach","lagunaniguel","laguna-niguel","sanclemente","san-clemente","danapoint","dana-point","missionviejo","mission-viejo","lakeforest","lake-forest","rsm","ranchosantamargarita","rancho-santa-margarita","alisoviejo","aliso-viejo","tustin","orange","yorbalinda","yorba-linda","brea","lahabra","la-habra","placentia","buenapark","buena-park","cypress","losalamitojos","sealbeach","seal-beach","gardengrove","garden-grove","westminster","stanton","fountainvalley","sandiego","san-diego","sd","sdmesh","sd-mesh","lajolla","la-jolla","pacificbeach","pacific-beach","pb","missionbeach","mission-beach","oceanbeach","ocean-beach","ob","pointloma","point-loma","coronado","hillcrest","northpark","north-park","southpark","south-park","normalheights","normal-heights","cityheights","city-heights","lamesa","la-mesa","elcajon","el-cajon","santee","lakeside","poway","ramona","julian","alpine","escondido","sanmarcos","san-marcos","vista","oceanside","carlsbad","encinitas","delmar","del-mar","solanabeanch","solana-beach","chulavista","chula-vista","nationalcity","national-city","imperialbeach","imperial-beach","ib","southbay","south-bay","torrance","gardena","hawthorne","lawndale","redondo","redondobeach","hermosa","hermosabeach","manhattan","manhattanbeach","manhattan-beach","elsegundo","el-segundo","palosverdes","palos-verdes","pv","ranchopalosverdes","rancho-palos-verdes","sanpedro","san-pedro","wilmington","carson","compton","longbeach","long-beach","lb","signalhill","signal-hill","lakewood","cerritos","artesia","lamirada","la-mirada","norwalk","whittier","lahabra","la-habra-heights","downey","bellflower","paramount","southgate","south-gate","lynwood","bellgardens","bell-gardens","cudahy","huntingtonpark","maywood","vernon","commerce","montebello","picorivera","pico-rivera","montereypark","monterey-park","alhambra","sanmarinno","san-marino","arcadia","monrovia","duarte","azusa","irwindale","baldwinpark","baldwin-park","elmonbte","el-monte","southelmonte","south-el-monte","rosemead","temple-city","templecity","sangabriel","san-gabriel","santabarbara","santa-barbara","sb","goleta","carpinteria","montecito","islavista","isla-vista","iv","ucsb","slo","sanluisobispo","san-luis-obispo","morrobay","morro-bay","pismobeach","pismo-beach","pismo","shellbeach","shell-beach","arroyogrande","arroyo-grande","groverbeach","grover-beach","oceano","santamaria","santa-maria","lompoc","vandenberg","solvang","buellton","losalamos","los-alamos","atascadero","pasorobles","paso-robles","paso","cambria","cayucos","sansiemon","san-simeon","hearst","fresno","clovis","visalia","tulare","hanford","porterville","bakersfield","bako","delano","wasco","shafter","taft","tehachapi","stockton","tracy","manteca","lodi","modesto","turlock","merced","madera","chowchilla","losabnos","los-banos","sacramento","sac","sactown","westsacramento","west-sacramento","westsac","elkgrove","elk-grove","folsom","ranchocordova","rancho-cordova","roseville","rocklin","lincoln","citrus-heights","citrusheights","fair-oaks","fairoaks","carmichael","orangevale","davis","woodland","dixon","vacaville","fairfield","vallejo","bayarea","bay-area","sfbay","sf-bay","sanfrancisco","san-francisco","sf","sfmesh","sf-mesh","oakland","eastbay","east-bay","berkeley","emeryville","alameda","sanleandro","san-leandro","hayward","fremont","unioncity","union-city","newark","milpitas","sanjose","san-jose","sj","campbell","saratoga","losgartos","los-gatos","sunnyvale","santaclara","santa-clara","cupertino","mountainview","mountain-view","paloalto","palo-alto","menlopark","menlo-park","atherton","redwoodcity","redwood-city","sancarlos","san-carlos","belmont","sanmateo","san-mateo","fostercity","foster-city","burlingame","sanbruno","san-bruno","southsanfrancisco","ssf","dalycity","daly-city","pacifica","halfmoonbay","half-moon-bay","hmb","santacruz","santa-cruz","capitola","scottsvalley","scotts-valley","watsonville","aptos","soquel","concord","walnutcreek","walnut-creek","pleasant-hill","pleasanthill","martinez","antioch","pittsburg","brentwood","oakley","discovery-bay","livermore","pleasanton","dublin","sanramon","san-ramon","danville","richmond","sanpablo","san-pablo","pinole","hercules","napa","sonoma","petaluma","santarosa","santa-rosa","rohnertpark","novato","sanrafael","san-rafael","sausalito","tiburon","millvalley","mill-valley","redding","chico","oroville","paradise","reddingbluff","redbluff","red-bluff","shasta","mtshasta","mt-shasta","eureka","arcata","fortuna","mckibleyville","ukiah","fortbragg","fort-bragg","willits","yreka","weed","dunsmuir","tahoe","laketahoe","lake-tahoe","southlaketahoe","south-lake-tahoe","truckee","squaw","squawvalley","squaw-valley","northstar","mammoth","mammothlakes","mammoth-lakes","bishopca","bishop","placerville","tahoe-city","tahoecity","kings-beach","kingsbeach","incline","inclinevillage","incline-village","maricopa","pima","pinal","yavapai","yuma","mohave","coconino","cochise","navajo","apache","gila","santacruzaz","graham","lapaz","la-paz","greenlee","arizona","az","azmesh","az-mesh","phoenix","phx","phoenixmesh","phoenix-mesh","scottsdale","tempe","mesa","gilbert","chandler","glendale","peoria","surprize","avondale","goodyear","buckeye","litchfieldpark","litchfield-park","tolleson","laveen","paradisevalley","paradise-valley","pv","carefree","cavekreek","cave-creek","fountainhills","fountain-hills","rioverde","rio-verde","queencreek","queen-creek","santan","san-tan","santanvalley","ahwatukee","southmountain","south-mountain","anthem","newriver","new-river","apachejunction","apache-junction","aj","goldcanyon","gold-canyon","tucson","tucsomesh","tucson-mesh","orovalley","oro-valley","marana","catalina","catalinafoothills","saddlebrooke","casagrande","casa-grande","eloy","coolidge","florence","sierravista","sierra-vista","bisbee","tombstone","benson","douglas","nogales","tubac","greenvalley","green-valley","sahuarita","flagstaff","flag","flagmesh","sedona","cottonwood","clarkdale","prescott","prescottvalley","prescott-valley","dewey","chino-valley","chinovalley","williams","grandcanyon","grand-canyon","tusayan","page","marble-canyon","showlow","show-low","pinetop","pinetoplakeside","lakeside","snowflake","taylor","payson","pine","strawberry","camp-verde","campverde","winslow","holbrook","stjohns","springerville","eagar","yuma","yumamesh","fortuna-foothills","sanluisaz","san-luis","lakehavasu","lake-havasu","havasu","havasucity","lake-havasu-city","bullheadcity","bullhead-city","bullhead","laughlin","kingman","goldenkvalley","golden-valley","parker","quartzsite","wickenburg","lasvegas","las-vegas","vegas","vegasmesh","vegas-mesh","lv","henderson","boulder-city","bouldercity","northlasvegas","north-las-vegas","nlv","summerlin","enterprise","pahrump","mesquite","reno","sparks","carsoncity","carson-city","incline","bajacalifornia","baja-california","baja","bajamesh","tijuana","tj","mexicali","ensenada","tecate","rosarito","sanfelipe","san-felipe","sanluis","sanluisriocoalorado","brabant","flevoland","gelderland","noordbrabant","noordholland","zuid-holland","zuidholland","zeeland","twente","alkmaar","almere","amsterdam","amstelland","capelleaandenijssel","denhaag","dordrecht","drechtsteden","eindhoven","haarlem","hellevoetsluis","hilversum","katwijk","lelystad","maassluis","middelburg","rijnmond","rotterdam","tilburg","utrecht","vlissingen","voorburg","voorne-putten","walcheren","west-friesland","zaandam","zaanstreek-waterland","024-bot","afrithonbot","ai","amradio","analyser","angrynerds","bemesh","bot","buch","burgernet","chat","chatgpt","dares","dekroeg","dtis","emergency","english","evenvroegopstaan","fosdem","gezellig","gmr","gmrbot","goedemorgen","gyverbot","haagscourant","hackerspacenijmegen","hamradio","hamradionederland","hetweerinjegemeente","hsnl","jokes","kanalen","koffie","linux","meshcore","nerd","nl-alert","nl-prio","noodkanaal","nsagov","pi4hm","pi4utr","pingbot","sensemakers","sports","survival","test","testing","uitdagingen","valleibot","valleirug","vleesboek","wardrive","weer","swl","qso","qrz","cq","dx","sstv","aprs","winlink","aredn","hamnet","emcomm","emcommplanning","races","ares","auxcomm","simplex","repeater","uhf","vhf","2m","70cm","440"],Li=new Set(Fi);function Ai(){return crypto.getRandomValues(new Uint8Array(16))}function Xs(t){return Array.from(t).map(s=>s.toString(16).padStart(2,"0")).join("")}function vt(t){const s=t.replace(/\s/g,"");if(s.length!==32||!/^[0-9a-fA-F]+$/.test(s))return null;const a=new Uint8Array(16);for(let r=0;r<16;r++)a[r]=parseInt(s.slice(r*2,r*2+2),16);return a}async function Oi(t){const a=`#${ia(t)}`,r=new TextEncoder().encode(a);return(await lr(r)).slice(0,16)}const Js=[{key:"create-private",label:"Create Private",icon:qr,desc:"Generate a new private channel with a random key"},{key:"join-private",label:"Join Private",icon:Yl,desc:"Join an existing private channel using a shared key"},{key:"join-hashtag",label:"Join Hashtag",icon:Fe,desc:"Join a public hashtag channel (key derived from name)"}];function zi({open:t,onClose:s,channels:a,onAddChannel:r}){var I;const[l,i]=n.useState("join-hashtag"),[o,x]=n.useState(""),[p,j]=n.useState(""),[c,f]=n.useState(null),[y,b]=n.useState(!1),[d,N]=n.useState(""),[S,h]=n.useState(!1),[_,E]=n.useState(t);t!==_&&(E(t),t&&(i("join-hashtag"),x(""),j(""),f(null),b(!1),N(""),h(!1)));const R=n.useMemo(()=>a.length===0?0:Math.max(...a.map(g=>g.index))+1,[a]),w=n.useMemo(()=>l!=="join-hashtag"?"":ia(o),[l,o]),C=n.useMemo(()=>{if(!o.trim())return null;const g=l==="join-hashtag"&&w?`#${w}`:o.trim();return a.find($=>$.name===g)??null},[o,l,w,a]),T=n.useMemo(()=>l==="join-hashtag"&&w?Li.has(w):!1,[l,w]),v=n.useMemo(()=>{if(!o.trim()||C)return!1;switch(l){case"create-private":return o.trim().length>0&&o.trim().length<=32;case"join-private":return o.trim().length>0&&vt(p)!==null;case"join-hashtag":return w.length>0;default:return!1}},[l,o,p,w,C]),u=n.useCallback(async()=>{c&&(await navigator.clipboard.writeText(Xs(c)),h(!0),setTimeout(()=>h(!1),2e3))},[c]),m=n.useCallback(async()=>{if(!(!v||y)){b(!0),N("");try{let g,$;switch(l){case"create-private":{g=Ai(),$=o.trim();break}case"join-private":{const H=vt(p);if(!H){N("Invalid hex key (must be 32 hex chars = 16 bytes)");return}g=H,$=o.trim();break}case"join-hashtag":{g=await Oi(o),$=`#${w}`;break}default:return}if(await r(R,$,g)){if(l==="create-private"){f(g);return}s()}else N("Failed to add channel — device may be unreachable")}catch(g){N(g instanceof Error?g.message:"Unknown error")}finally{b(!1)}}},[v,y,l,o,p,w,R,r,s]);return e.jsxs(je,{open:t,onClose:s,size:"sm",children:[e.jsx(Ee,{title:"Add Channel",onClose:s}),e.jsx(we,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-1 p-0.5 radius-inner bg-zinc-950/5",children:Js.map(g=>{const $=g.icon,k=l===g.key;return e.jsxs("button",{onClick:()=>{i(g.key),N(""),f(null)},className:P("flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs font-medium rounded transition-colors",k?"bg-surface text-fg-primary shadow-sm":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx($,{className:"w-3.5 h-3.5"}),g.label]},g.key)})}),e.jsx("p",{className:"text-xs text-fg-muted",children:(I=Js.find(g=>g.key===l))==null?void 0:I.desc}),c&&l==="create-private"&&e.jsxs("div",{className:"p-3 radius-inner bg-sys-green/8 border border-sys-green/20 space-y-2",children:[e.jsx("p",{className:"text-xs text-sys-green font-medium",children:"Channel created! Share this key with others:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 text-[11px] font-mono text-fg-primary bg-zinc-950/10 px-2 py-1 rounded break-all",children:Xs(c)}),e.jsx("button",{onClick:u,className:"p-1.5 rounded hover:bg-subtle-fill transition-colors flex-shrink-0",title:"Copy key",children:S?e.jsx(be,{className:"w-3.5 h-3.5 text-sys-green"}):e.jsx(Et,{className:"w-3.5 h-3.5 text-fg-muted"})})]}),e.jsx("p",{className:"text-[11px] text-fg-muted",children:"Save this key — it cannot be recovered later."})]}),e.jsxs(re,{children:[e.jsx(le,{children:l==="join-hashtag"?"Hashtag name":"Channel name"}),e.jsx(pe,{type:"text",value:o,onChange:g=>x(g.target.value),placeholder:l==="join-hashtag"?"e.g. south-bay":"e.g. My Channel",maxLength:32,className:"mt-1",disabled:!!c}),l==="join-hashtag"&&w&&w!==o&&e.jsxs(ke,{className:"mt-1",children:["Will be registered as ",e.jsxs("code",{className:"text-fg-primary font-mono text-[11px]",children:["#",w]})]}),l==="join-hashtag"&&T&&e.jsx(ke,{className:"mt-1 text-sys-green",children:"Known region channel"})]}),C&&e.jsxs("div",{className:"flex items-start gap-2 p-2.5 radius-inner bg-sys-red/8 border border-sys-red/20",children:[e.jsx(Be,{className:"w-3.5 h-3.5 text-sys-red flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs text-fg-secondary",children:["Channel ",e.jsx("strong",{className:"text-fg-primary",children:C.name})," already exists at slot ",C.index,". Remove it first to re-add."]})]}),l==="join-private"&&e.jsxs(re,{children:[e.jsxs(le,{children:["Channel key ",e.jsx("span",{className:"text-fg-muted font-normal",children:"(32 hex chars)"})]}),e.jsx(pe,{type:"text",value:p,onChange:g=>j(g.target.value),placeholder:"e.g. a1b2c3d4e5f6...",maxLength:32,className:"mt-1 font-mono text-xs"}),p&&!vt(p)&&e.jsx(ke,{className:"mt-1 text-sys-red",children:"Must be exactly 32 hex characters (16 bytes)"})]}),e.jsxs("p",{className:"text-[11px] text-fg-muted",children:["Will be assigned to channel slot ",e.jsx("strong",{className:"text-fg-primary",children:R})]}),d&&e.jsx("p",{className:"text-xs text-sys-red font-medium",children:d})]})}),e.jsxs(Me,{children:[e.jsx(B,{plain:!0,onClick:s,children:c?"Done":"Cancel"}),!c&&e.jsx(B,{color:"primary",onClick:m,disabled:!v||y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-4 h-4 animate-spin"}),"Adding…"]}):l==="create-private"?"Create Channel":"Join Channel"})]})]})}const Hi=202,Bi=/^[0-9a-fA-F]+$/;function Gi(t){const s=t.replace(/\s/g,"");return s.length>=Hi&&s.length%2===0&&Bi.test(s)}const Ki=n.memo(function({open:s,onClose:a,contacts:r,exportPubKey:l,onExport:i,onImport:o}){const[x,p]=n.useState(l?"export":"import"),[j,c]=n.useState(l??""),[f,y]=n.useState(""),[b,d]=n.useState(""),[N,S]=n.useState(!1),[h,_]=n.useState(!1),[E,R]=n.useState(!1),[w,C]=n.useState(null),[T,v]=n.useState(!1),u=n.useRef(null);n.useEffect(()=>{s&&(p(l?"export":"import"),c(l??""),y(""),d(""),S(!1),_(!1),R(!1),C(null),v(!1))},[s,l]);const m=n.useCallback(()=>{a()},[a]),I=n.useCallback(async()=>{if(!j)return;S(!0),C(null),y("");const k=await i(j);S(!1),k?y(k):C("Failed to export contact advert")},[j,i]),g=n.useCallback(async()=>{if(f)try{await navigator.clipboard.writeText(f),R(!0),setTimeout(()=>R(!1),2e3)}catch{C("Failed to copy to clipboard")}},[f]),$=n.useCallback(async()=>{const k=b.replace(/\s/g,"");if(!Gi(k)){C("Invalid hex — must be at least 202 hex characters (101 bytes)");return}_(!0),C(null);const H=await o(k);_(!1),H?(v(!0),d(""),setTimeout(()=>m(),1500)):C("Import failed — check the hex string and try again")},[b,o,m]);return e.jsxs(je,{open:s,onClose:m,children:[e.jsx(or,{children:"Contact Import / Export"}),e.jsxs(we,{children:[e.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg bg-subtle-fill mb-4",children:[e.jsxs("button",{onClick:()=>{p("export"),C(null)},className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 rounded-md text-xs font-medium transition-colors",x==="export"?"bg-surface shadow-sm text-fg-primary":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),"Export"]}),e.jsxs("button",{onClick:()=>{p("import"),C(null)},className:P("flex-1 flex items-center justify-center gap-1.5 py-1.5 rounded-md text-xs font-medium transition-colors",x==="import"?"bg-surface shadow-sm text-fg-primary":"text-fg-muted hover:text-fg-secondary"),children:[e.jsx(He,{className:"w-3.5 h-3.5"}),"Import"]})]}),x==="export"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-fg-muted mb-1",children:"Select contact"}),e.jsxs("select",{value:j,onChange:k=>{c(k.target.value),y(""),C(null)},className:"w-full surface-input rounded-lg px-3 py-2 text-sm text-fg-primary",children:[e.jsx("option",{value:"",children:"Choose a contact…"}),r.map(k=>e.jsx("option",{value:k.public_key,children:k.name||k.public_key.slice(0,12)},k.public_key))]})]}),e.jsx(B,{color:"primary",outline:!0,className:"w-full justify-center",disabled:!j||N,onClick:I,children:N?"Exporting…":"Export Advert"}),f&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{readOnly:!0,value:f,rows:4,className:"w-full surface-input rounded-lg px-3 py-2 text-[10px] font-mono text-fg-primary break-all resize-none"}),e.jsxs(B,{color:E?"success":"primary",outline:!0,className:"w-full justify-center",onClick:g,children:[E?e.jsx(be,{"data-slot":"icon"}):e.jsx(Et,{"data-slot":"icon"}),E?"Copied!":"Copy to Clipboard"]})]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-fg-muted mb-1",children:"Paste advert hex string"}),e.jsx("textarea",{ref:u,value:b,onChange:k=>{d(k.target.value),C(null),v(!1)},placeholder:"Paste exported advert hex here…",rows:4,className:"w-full surface-input rounded-lg px-3 py-2 text-[10px] font-mono text-fg-primary break-all resize-none placeholder:text-fg-muted/50"}),e.jsx("p",{className:"text-[10px] text-fg-muted/70 mt-1",children:"Minimum 101 bytes (202 hex characters): 32B pubkey + 4B timestamp + 64B signature + appData"})]}),T&&e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-sys-green/10 text-sys-green text-xs font-medium",children:[e.jsx(be,{className:"w-3.5 h-3.5"}),"Contact imported successfully"]}),e.jsx(B,{color:"primary",outline:!0,className:"w-full justify-center",disabled:!b.trim()||h,onClick:$,children:h?"Importing…":"Import Contact"})]}),w&&e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 mt-3 rounded-lg bg-sys-red/10 text-sys-red text-xs",children:[e.jsx(ua,{className:"w-3.5 h-3.5 flex-shrink-0"}),w]})]}),e.jsx(Me,{children:e.jsx(B,{plain:!0,onClick:m,children:"Close"})})]})});function Cc(){var us,ms,ps,hs,xs,fs;const t=ir(),s=la(),a=cr(),r=dr(),l=ur(),i=mr(),o=mt(),x=pr(),p=hr(),j=xr(),c=fr(),f=n.useMemo(()=>{if(l.length===0)return r;const M=new Set(r.map(z=>z.public_key));return[...r,...l.filter(z=>!M.has(z.public_key))]},[r,l]),y=n.useMemo(()=>{const M=new Set;if(!(c!=null&&c.neighbors))return M;const z=[];for(const[K,J]of Object.entries(c.neighbors))J.zero_hop&&z.push((K.startsWith("0x")?K.slice(2):K).toLowerCase());for(const K of f){const J=K.public_key.toLowerCase();for(const ce of z)if(J===ce||J.startsWith(ce)){M.add(K.public_key);break}}return M},[c==null?void 0:c.neighbors,f]),b=n.useMemo(()=>{const M=new Map;if(!(c!=null&&c.neighbors))return M;const z=[];for(const[K,J]of Object.entries(c.neighbors))J.zero_hop&&J.rssi!=null&&J.snr!=null&&J.rssi!==0&&z.push({hash:(K.startsWith("0x")?K.slice(2):K).toLowerCase(),rssi:J.rssi,snr:J.snr,advertCount:J.advert_count??1});if(z.length===0)return M;for(const K of f){const J=K.public_key.toLowerCase();for(const ce of z)if(J===ce.hash||J.startsWith(ce.hash)){M.set(K.public_key,{rssi:ce.rssi,snr:ce.snr,advertCount:ce.advertCount});break}}return M},[c==null?void 0:c.neighbors,f]),d=gr(),N=yr(),S=oa(),h=br(),_=vr(),E=jr(),R=wr(),w=Nr(),[C,T]=kr(),[v,u]=n.useState(!1),[m,I]=n.useState(!1),[g,$]=n.useState(!1),[k,H]=n.useState(!1),[te,W]=n.useState(null),[L,V]=n.useState(!1),[ie,F]=n.useState(!1),[D,A]=n.useState(!0),O="pymc_companion_contacts_micro",G="pymc_companion_split",[Q,ht]=n.useState(()=>{try{return localStorage.getItem(O)==="1"}catch{return!1}}),We=25,Gt=75,[xt,Kt]=n.useState(()=>{try{const M=Number(localStorage.getItem(G));return M>=We&&M<=Gt?M:50}catch{return 50}}),Qe=n.useRef(null),Le=n.useRef(null),Ut=n.useRef(null),Ye=n.useRef(!1),Ae=n.useRef(xt);Ae.current=xt;const Ea=n.useCallback(M=>{M.preventDefault(),M.target.setPointerCapture(M.pointerId),Ye.current=!0},[]),Ma=n.useCallback(M=>{if(!Ye.current||!Qe.current)return;const z=Qe.current.getBoundingClientRect(),K=Math.round(Math.min(Gt,Math.max(We,(M.clientX-z.left)/z.width*100)));Ae.current=K,Le.current&&(Le.current.style.width=`${K}%`)},[]),qt=n.useCallback(()=>{if(!Ye.current)return;Ye.current=!1;const M=Ae.current;Kt(M);try{localStorage.setItem(G,String(M))}catch{}},[]),Pa=n.useCallback(()=>{Ae.current=50,Le.current&&tt(Le.current,{width:"50%"},de.layoutResize),Kt(50);try{localStorage.setItem(G,String(50))}catch{}},[]),Ta=n.useCallback(M=>{ht(M);const z=Qe.current,K=Ut.current;if(!z)return;const J=z.getBoundingClientRect().width;z.style.width=M?"var(--companion-side-micro)":"var(--companion-side)";const ce=z.getBoundingClientRect().width;if(z.style.width=`${J}px`,K){const sn=M?56:Ae.current/100*ce,an=K.offsetWidth,nn=Math.max(0,ce-sn-12);K.style.flex="none",K.style.width=`${an}px`,tt(K,{width:`${nn}px`},{...de.layoutResize,onComplete(){K.style.flex="",K.style.width=""}})}tt(z,{width:`${ce}px`},{...de.layoutResize,onComplete(){z.style.width=M?"var(--companion-side-micro)":"var(--companion-side)"}})},[]),{selectCompanion:$a,selectConversation:ve,sendMessage:Vt,sendChannelMessage:Wt,retryMessage:Da,retryMessageAsFlood:Fa,resetPath:ft,shareContact:La,removeContact:Aa,addChannel:Oa,requestStatus:Qt,requestTelemetry:Yt,loginToRepeater:gt,logoutFromRepeater:Xt,getNeighbours:Jt,traceContactPath:Zt,discoverPath:es,pingContact:za,markAsRead:ts,fetchCompanions:ss,seedFromRepeater:Ha,exportContactAdvert:Ba,importContactAdvert:Ga,setContactPath:as,deleteChannel:Ka,loadOlderMessages:Ua}=se.getState(),qa=n.useCallback(M=>{ve(M),window.innerWidth>=1280?V(!0):F(!0)},[ve]),ns=se(M=>M.messages),rs=se(M=>M.unreadMap);n.useEffect(()=>{ts()},[d,ts]),n.useEffect(()=>{const M=C.get("dm");M&&f.length>0&&f.find(K=>K.public_key===M)&&(ve({type:"contact",id:M}),T({},{replace:!0}))},[C,f,ve,T]);const Va=n.useMemo(()=>{const M=new Set;for(const z of f)z.name&&M.add(z.name);for(const z of N)z.sender_name&&!z.is_outgoing&&M.add(z.sender_name);return[...M].sort((z,K)=>z.localeCompare(K))},[f,N]),ls=n.useMemo(()=>{const M=new Map;for(const z of f)z.name&&M.set(z.name.toLowerCase(),z.public_key);for(const z of N)if(z.sender_name&&z.sender_key&&z.sender_key!=="unknown"&&!z.is_outgoing){const K=z.sender_name.toLowerCase();M.has(K)||M.set(K,z.sender_key)}return M},[f,N]),Wa=n.useCallback(M=>{const z=ls.get(M.toLowerCase());z&&(ve({type:"contact",id:z}),V(!0))},[ls,ve]),Qa=n.useCallback(async M=>d?d.type==="channel"?Wt(Number(d.id),M):Vt(d.id,M):!1,[d,Vt,Wt]),Ya=S&&!h,os=E!=null&&(E.adv_type&15)===3,is=It(os?E.public_key:null),Xa=os&&is!=="success",cs=Cr(),[me,Pe]=n.useState("idle"),Ja=n.useCallback(async()=>{Pe("flood-sending");const M=await se.getState().sendFloodAdvert();Pe(M?"flood-done":"idle"),M&&setTimeout(()=>Pe(z=>z==="flood-done"?"idle":z),2e3)},[]),Za=n.useCallback(async()=>{Pe("zero-sending");const M=await se.getState().sendZeroHopAdvert();Pe(M?"zero-done":"idle"),M&&setTimeout(()=>Pe(z=>z==="zero-done"?"idle":z),2e3)},[]),en=e.jsxs("div",{className:"flex items-center gap-2",children:[S&&a&&e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsxs("button",{onClick:Ja,disabled:me!=="idle"&&me!=="zero-done",className:P("inline-flex items-center gap-2 px-3.5 py-2 rounded-xl text-xs font-semibold transition-all duration-150","bg-surface depth-raised-soft hover:depth-raised active:depth-inset","disabled:opacity-50 disabled:cursor-not-allowed",me==="flood-done"?"text-sys-green":"text-fg-secondary hover:text-fg-primary"),title:"A Flood Advert will announce your presence and broadcast your node ID and name anywhere a repeater will repeat it",children:[me==="flood-sending"?e.jsx(oe,{className:"w-4 h-4 animate-spin"}):e.jsx(no,{className:"w-4 h-4"}),e.jsx("span",{children:me==="flood-done"?"Sent!":"Flood Advert"})]}),e.jsxs("button",{onClick:Za,disabled:me!=="idle"&&me!=="flood-done",className:P("inline-flex items-center gap-2 px-3.5 py-2 rounded-xl text-xs font-semibold transition-all duration-150","bg-surface depth-raised-soft hover:depth-raised active:depth-inset","disabled:opacity-50 disabled:cursor-not-allowed",me==="zero-done"?"text-sys-green":"text-fg-secondary hover:text-fg-primary"),title:"A Local Advert, or “Zero Hop” advert will not be repeated by local repeaters, but will be heard by those within range",children:[me==="zero-sending"?e.jsx(oe,{className:"w-4 h-4 animate-spin"}):e.jsx(Na,{className:"w-4 h-4"}),e.jsx("span",{children:me==="zero-done"?"Sent!":"Local Advert"})]})]}),e.jsx("button",{onClick:()=>Sr.getState().toggleFocusMode(),className:"hidden lg:flex p-1.5 hover:bg-subtle-fill rounded transition-colors",title:cs?"Collapse view":"Expand view",children:cs?e.jsx(tl,{className:"w-4 h-4 text-fg-muted"}):e.jsx(sl,{className:"w-4 h-4 text-fg-muted"})})]}),tn=e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 flex-shrink-0",children:[e.jsx(ge,{children:j.length>0&&e.jsx(ue.div,{layout:!0,initial:{opacity:0,scale:.9,width:0},animate:{opacity:1,scale:1,width:"auto"},exit:{opacity:0,scale:.9,width:0},transition:de.fade,className:"flex items-center gap-1 overflow-hidden",children:j.map(M=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-sys-green/10 text-[11px] text-sys-green font-medium whitespace-nowrap",children:[e.jsx(ze,{className:"w-2.5 h-2.5"}),M.name]},M.pubHex))},"advert-notifs")}),e.jsx(ge,{children:!S&&e.jsxs(ue.span,{initial:{opacity:0,scale:.9,width:0},animate:{opacity:1,scale:1,width:"auto"},exit:{opacity:0,scale:.9,width:0},transition:de.fade,className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-sys-amber/10 text-[11px] text-sys-amber font-medium whitespace-nowrap overflow-hidden",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5 flex-shrink-0",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-sys-amber opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-sys-amber"})]}),"Reconnecting…"]},"disconnected")}),a&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>I(!0),disabled:x,className:"data-box flex items-center gap-1 cursor-pointer hover:bg-subtle-fill-strong transition-colors disabled:opacity-50",title:p>0?`${p} contacts seeded from repeater — click to refresh`:"Seed contacts from repeater adverts",children:[x?e.jsx(oe,{className:"w-3.5 h-3.5 text-sys-blue animate-spin"}):e.jsx(mo,{className:"w-3.5 h-3.5 text-sys-blue"}),p>0&&e.jsxs("span",{className:"text-sys-blue",children:["+",p]})]}),e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:`${f.length} contacts${p>0?` (${p} from repeater)`:""}`,children:[e.jsx(wt,{className:"w-3.5 h-3.5 text-fg-secondary"}),e.jsx("span",{children:f.length})]}),e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:`${a.channels_count} channels`,children:[e.jsx(Fe,{className:"w-3.5 h-3.5 text-fg-secondary"}),e.jsx("span",{children:a.channels_count})]})]}),e.jsx(Pi,{companions:t,selected:s,onSelect:$a}),e.jsx(B,{plain:!0,onClick:()=>u(!0),title:"Companion configuration",children:e.jsx(_r,{"data-slot":"icon"})})]});if(t.length===0&&!h)return e.jsxs(Ns,{children:[e.jsx(ks,{title:"Companion",icon:e.jsx(ye,{}),controls:e.jsxs(B,{color:"primary",outline:!0,onClick:()=>u(!0),children:[e.jsx(Ue,{"data-slot":"icon"}),"Add Companion"]})}),e.jsx(Cs,{ready:!0,children:e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-subtle-fill mx-auto mb-4 flex items-center justify-center",children:e.jsx(ye,{className:"w-7 h-7 text-fg-muted/50"})}),e.jsx("p",{className:"type-body text-fg-muted mb-1",children:"No companions configured"}),e.jsx("p",{className:"type-body-sm text-fg-muted/70 mb-4",children:"Add a companion to start messaging mesh contacts"}),e.jsxs(B,{color:"primary",outline:!0,onClick:()=>u(!0),children:[e.jsx(Ue,{"data-slot":"icon"}),"Add Companion"]})]})}),e.jsx(Ys,{open:v,onClose:()=>u(!1),onRefresh:ss})]});const ds=d?d.type==="channel"?((us=i.find(M=>String(M.index)===d.id))==null?void 0:us.name)??"Channel":((ms=f.find(M=>M.public_key===d.id))==null?void 0:ms.name)??d.id.slice(0,8):null;return e.jsxs(Ns,{children:[e.jsx(ks,{title:(o==null?void 0:o.node_name)||"Companion",icon:e.jsx(ye,{}),leading:en,controls:tn}),e.jsx(Cs,{children:e.jsxs("div",{className:"companion-layout flex gap-4",style:{height:"calc(100vh - 11rem)",minHeight:400},children:[e.jsxs("div",{ref:Qe,className:P("flex-shrink-0 flex h-full overflow-hidden radius-inner bg-surface/80 backdrop-blur-lg depth-raised",D?"":"hidden md:flex"),style:{width:Q?"var(--companion-side-micro)":"var(--companion-side)"},children:[e.jsx(Bo,{ref:Le,contacts:f,selectedConversation:d,unreadMap:rs,messages:ns,onSelect:M=>{ve(M),window.innerWidth<768&&A(!1)},onShowDetails:qa,onShareContact:La,onResetPath:ft,onRemoveContact:Aa,onPingContact:za,repeaterNeighborHashes:y,repeaterSignalMap:b,isLoading:h,splitPercent:xt,onMicroChange:Ta}),e.jsx("div",{className:"group/divider flex-shrink-0 self-stretch flex items-center justify-center w-3 cursor-col-resize select-none touch-none",onPointerDown:Ea,onPointerMove:Ma,onPointerUp:qt,onPointerCancel:qt,onDoubleClick:Pa,children:e.jsx("div",{className:"w-px h-full my-2 bg-edge-subtle/50 group-hover/divider:bg-sys-blue/50 group-active/divider:bg-sys-blue transition-colors"})}),e.jsx(Vo,{ref:Ut,channels:i,selectedConversation:d,unreadMap:rs,messages:ns,onSelect:M=>{ve(M),window.innerWidth<768&&A(!1)},onAddChannel:()=>$(!0),onDeleteChannel:Ka})]}),e.jsxs(Ss,{noPadding:!0,radius:"sm",className:"flex-1 flex flex-col min-w-0 overflow-hidden relative",children:[e.jsx(ge,{children:_&&e.jsxs(ue.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:de.fade,className:"flex items-center justify-center gap-2 px-3 py-1.5 bg-sys-red/10 border-b border-sys-red/20",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-sys-red flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-sys-red font-medium truncate",children:_})]},"error-banner")}),!D&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-edge-subtle md:hidden",children:[e.jsx("button",{onClick:()=>A(!0),className:"p-1 hover:bg-subtle-fill rounded transition-colors",children:e.jsx(Gl,{className:"w-4 h-4 text-fg-secondary"})}),e.jsx("span",{className:"text-sm text-fg-primary font-medium truncate flex-1",children:ds}),d&&e.jsx("button",{onClick:()=>F(!0),className:"p-1 hover:bg-subtle-fill rounded transition-colors",title:"Details",children:e.jsx(nt,{className:"w-4 h-4 text-fg-muted"})})]}),e.jsxs("div",{className:"hidden md:flex items-center justify-between px-3 py-1.5 border-b border-edge-subtle",children:[e.jsx("span",{className:"text-sm text-fg-primary font-medium truncate",children:ds??"Select a conversation"}),e.jsx(ge,{children:d&&e.jsx(ue.button,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,onClick:()=>{window.innerWidth>=1280?V(M=>!M):F(!0)},className:"p-1 hover:bg-subtle-fill rounded transition-colors",title:L?"Hide detail panel":"Show details",children:L&&window.innerWidth>=1280?e.jsx(Ts,{className:"w-4 h-4 text-fg-muted"}):e.jsx(nt,{className:"w-4 h-4 text-fg-muted"})},"ctx-toggle")})]}),Xa&&E?e.jsx(ui,{contact:E,loginStatus:is,onLogin:gt}):e.jsxs(e.Fragment,{children:[e.jsx(li,{messages:N,contacts:f,className:"flex-1 min-h-0",conversationKey:d?d.type==="channel"?`ch:${d.id}`:d.id:void 0,onRetry:Da,onRetryAsFlood:Fa,onMentionClick:Wa,historyLoading:R,historyExhausted:d?w.get(d.type==="channel"?`ch:${d.id}`:d.id)??!1:!0,onLoadOlder:d?()=>Ua(d.type==="channel"?`ch:${d.id}`:d.id):void 0,channelName:(d==null?void 0:d.type)==="channel"?(ps=i.find(M=>String(M.index)===d.id))==null?void 0:ps.name:void 0}),d&&e.jsx(ii,{onSend:Qa,disabled:!Ya,mentionNames:Va,placeholder:d.type==="channel"?`Message ${((hs=i.find(M=>String(M.index)===d.id))==null?void 0:hs.name)??"channel"}`:`Message ${((xs=f.find(M=>M.public_key===d.id))==null?void 0:xs.name)??"contact"}`})]})]}),e.jsx(ue.div,{initial:!1,animate:{width:L&&d?"var(--companion-context)":"0px",opacity:L&&d?1:0},transition:de.layoutResize,className:"hidden xl:block flex-shrink-0 overflow-hidden",style:{pointerEvents:L&&d?"auto":"none"},children:d&&e.jsxs(Ss,{neomorphic:!0,noPadding:!0,radius:"sm",className:"h-full relative",children:[e.jsx(ge,{children:L&&e.jsx(ue.button,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:de.fade,onClick:()=>V(!1),className:"absolute top-2 left-2 z-10 p-1 hover:bg-subtle-fill rounded-lg transition-colors",title:"Hide detail panel",children:e.jsx(Ts,{className:"w-4 h-4 text-fg-muted"})},"ctx-close")}),e.jsx(Ks,{contact:d.type==="contact"?E:null,channel:d.type==="channel"?i.find(M=>String(M.index)===d.id)??null:null,contacts:f,selfPubKey:(o==null?void 0:o.public_key)??null,onResetPath:ft,onRequestStatus:Qt,onRequestTelemetry:Yt,onLoginToRepeater:gt,onLogoutFromRepeater:Xt,onGetNeighbours:Jt,onTraceContactPath:Zt,onDiscoverPath:es,onExportContact:M=>{W(M),H(!0)},onSetContactPath:as})]})})]})}),e.jsx(Ys,{open:v,onClose:()=>u(!1),onRefresh:ss}),e.jsx(Di,{open:m,onClose:()=>I(!1),companionName:s??"companion",onImport:Ha}),e.jsx(Ki,{open:k,onClose:()=>{H(!1),W(null)},contacts:f,exportPubKey:te,onExport:Ba,onImport:Ga}),e.jsx(zi,{open:g,onClose:()=>$(!1),channels:i,onAddChannel:Oa}),e.jsxs(je,{open:ie,onClose:()=>F(!1),size:"md",children:[e.jsx(Ee,{icon:(d==null?void 0:d.type)==="channel"?e.jsx(Fe,{className:"w-5 h-5"}):E&&(E.adv_type&15)===2?e.jsx(ze,{className:"w-5 h-5"}):e.jsx(ye,{className:"w-5 h-5"}),title:(d==null?void 0:d.type)==="channel"?((fs=i.find(M=>String(M.index)===d.id))==null?void 0:fs.name)??"Channel":(E==null?void 0:E.name)||"Contact Details",onClose:()=>F(!1)}),e.jsx(we,{className:"max-h-[70vh] overflow-y-auto",children:e.jsx(Ks,{embedded:!0,contact:(d==null?void 0:d.type)==="contact"?E:null,channel:(d==null?void 0:d.type)==="channel"?i.find(M=>String(M.index)===d.id)??null:null,contacts:f,selfPubKey:(o==null?void 0:o.public_key)??null,onResetPath:ft,onRequestStatus:Qt,onRequestTelemetry:Yt,onLoginToRepeater:gt,onLogoutFromRepeater:Xt,onGetNeighbours:Jt,onTraceContactPath:Zt,onDiscoverPath:es,onExportContact:M=>{W(M),H(!0)},onSetContactPath:as})})]})]})}export{Cc as default}; diff --git a/frontend/dist/assets/CompanionEchoMap-yp80-T_o.js b/frontend/dist/assets/CompanionEchoMap-DRaPu98w.js similarity index 94% rename from frontend/dist/assets/CompanionEchoMap-yp80-T_o.js rename to frontend/dist/assets/CompanionEchoMap-DRaPu98w.js index 2731e140..61c4cce0 100644 --- a/frontend/dist/assets/CompanionEchoMap-yp80-T_o.js +++ b/frontend/dist/assets/CompanionEchoMap-DRaPu98w.js @@ -1 +1 @@ -import{r as i,c$ as K,a6 as T,Q as Y,fO as D,au as I,cB as J,g7 as Q,Z as q,O as X,j as a,c as V,V as k,cE as ee}from"./index-BXuscHlA.js";import{M as te,S as ne,L as se,a as R}from"./maplibre-gl-CfjETxh6.js";import{useSrcHashResolverMap as ae,useDiscoveredNodes as oe}from"./usePipelineStore-DPecx6Zm.js";import{M as re}from"./map-pin-off-C9sYl_IQ.js";import"./node-types-DcVrjPZe.js";const le={light:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",dark:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"},A=X.amber,O=q[400],U=i.memo(function({prefix:c,name:o,isLocal:f,color:n}){const[r,u]=i.useState(!1);return a.jsx("div",{onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),style:{pointerEvents:"auto"},children:a.jsxs(k,{color:n,filled:!0,className:V("type-data-xs shadow-lg border border-current/30 transition-all duration-150 cursor-default",r&&"relative z-50"),children:[f&&a.jsx(ee,{className:"w-2.5 h-2.5 mr-0.5"}),c&&a.jsx("span",{className:"font-mono",children:c}),r&&o&&a.jsx("span",{className:c?"ml-0.5 opacity-75":"",children:o})]})})});function N(p,c){return p==null||c==null?!1:p!==0||c!==0}function ie(p,c,o){var u;const f=p.toUpperCase(),n=c.find(l=>l.public_key.toUpperCase().startsWith(f));if(n&&N(n.gps_lat,n.gps_lon))return{name:n.name||null,lat:n.gps_lat,lng:n.gps_lon,hasGps:!0};if(o.neighbors){const l=Object.entries(o.neighbors).find(([t])=>t.toUpperCase().startsWith(f));if(l){const[,t]=l;if(N(t.latitude,t.longitude))return{name:t.node_name||t.name||null,lat:t.latitude,lng:t.longitude,hasGps:!0}}}const r=o.srcHashMap.get(f);if(r){const l=o.discoveredNodes.get(r);if(l&&N(l.latitude,l.longitude))return{name:l.name||null,lat:l.latitude,lng:l.longitude,hasGps:!0};if(o.neighbors){const t=o.neighbors[r];if(t&&N(t.latitude,t.longitude))return{name:t.node_name||t.name||null,lat:t.latitude,lng:t.longitude,hasGps:!0}}}return{name:(n==null?void 0:n.name)||(r?((u=o.discoveredNodes.get(r))==null?void 0:u.name)??null:null),lat:0,lng:0,hasGps:!1}}function ce(p,c,o,f){const n=Math.floor(c/30);for(const r of[n-1,n,n+1])for(const[u,l]of o){const t=l.decoded;if(!(t!=null&&t.decrypted)||t.senderName!==f)continue;const v=t.timestamp??l.timestamp;if(Math.floor(v/30)===r&&t.text===p)return u}return null}function ue(p,c){const o=new Set,f=[];for(const n of c){if(n.packet_hash!==p||n.packet_origin==="tx_local")continue;const r=n.original_path??n.forwarded_path;if(!r||r.length===0)continue;const u=r[r.length-1].toUpperCase();o.has(u)||(o.add(u),f.push({prefix:u,snr:n.snr}))}return f}function he({text:p,timestamp:c,contacts:o,className:f}){const n=i.useRef(null),r=K(),u=T(),l=Y(),[t,v]=i.useState(!1),m=D(),C=I(),z=u==null?void 0:u.neighbors,E=ae(),B=oe(),M=J(),g=Q(),w=(m==null?void 0:m.node_name)??(g==null?void 0:g.node_name)??null,F=i.useMemo(()=>({neighbors:z,srcHashMap:E,discoveredNodes:B}),[z,E,B]),d=i.useMemo(()=>{const e=(m==null?void 0:m.node_name)||(g==null?void 0:g.node_name)||(g==null?void 0:g.companion_name)||"Me";return m&&N(m.latitude,m.longitude)?{prefix:m.public_key.slice(0,2).toUpperCase(),name:e,lat:m.latitude,lng:m.longitude}:M&&N(M.latitude,M.longitude)?{prefix:"",name:e,lat:M.latitude,lng:M.longitude}:null},[m,g,M]),L=i.useMemo(()=>w?ce(p,c,C,w):null,[p,c,C,w]),G=i.useMemo(()=>L?ue(L,l):[],[L,l]),j=i.useMemo(()=>G.map(e=>{const s=ie(e.prefix,o,F);return{prefix:e.prefix,snr:e.snr,...s}}),[G,o,F]),y=i.useMemo(()=>j.filter(e=>e.hasGps),[j]),$=i.useMemo(()=>j.filter(e=>!e.hasGps),[j]),_=i.useMemo(()=>{if(!d||y.length===0)return[];const e=[d.lng,d.lat];return y.map(s=>{const h=[s.lng,s.lat];return{from:e,to:h,midpoint:[(e[0]+h[0])/2,(e[1]+h[1])/2]}})},[d,y]),W=i.useMemo(()=>_.map(e=>({type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e.from,e.to]}}]})),[_]),H=i.useMemo(()=>{if(typeof document>"u")return{amber:A,zinc:O};const e=getComputedStyle(document.documentElement),s=e.getPropertyValue("--sys-amber").trim(),h=e.getPropertyValue("--zinc-400").trim();return{amber:s.startsWith("#")?s:A,zinc:h.startsWith("#")?h:O}},[]),x=i.useMemo(()=>{if(!d||y.length===0)return null;let e=d.lat,s=d.lat,h=d.lng,S=d.lng;for(const b of y)b.lats&&(s=b.lat),b.lngS&&(S=b.lng);return[[h,e],[S,s]]},[d,y]),Z=i.useCallback(()=>{var s;const e=(s=n.current)==null?void 0:s.getMap();e&&x&&e.fitBounds(x,{padding:{top:40,bottom:44,left:56,right:56},maxZoom:14,duration:0}),v(!0)},[x]);if(!x||!d)return null;const P=[(x[0][0]+x[1][0])/2,(x[0][1]+x[1][1])/2];return a.jsxs("div",{className:V("relative rounded-lg overflow-hidden",f),style:{aspectRatio:"16 / 10"},children:[!t&&a.jsx("div",{className:"absolute inset-0 bg-subtle-fill flex items-center justify-center pointer-events-none z-10",children:a.jsx("div",{className:"w-4 h-4 border-2 border-fg-muted/30 border-t-fg-muted rounded-full animate-spin"})}),a.jsx("div",{className:"h-full w-full transition-opacity duration-200",style:{opacity:t?1:0},children:a.jsxs(te,{ref:n,initialViewState:{longitude:P[0],latitude:P[1],zoom:10},onLoad:Z,style:{height:"100%",width:"100%"},mapStyle:le[r],attributionControl:!1,interactive:!1,children:[_.map((e,s)=>a.jsx(ne,{id:`cecho-${s}`,type:"geojson",data:W[s],lineMetrics:!0,children:a.jsx(se,{id:`cecho-line-${s}`,type:"line",paint:{"line-width":2,"line-gradient":["interpolate",["linear"],["line-progress"],0,H.amber,1,H.zinc]},layout:{"line-cap":"round","line-join":"round"}})},`cecho-${s}`)),a.jsx(R,{longitude:d.lng,latitude:d.lat,anchor:"center",children:a.jsx(U,{prefix:d.prefix,name:d.name,isLocal:!0,color:"amber"})}),y.map((e,s)=>a.jsx(R,{longitude:e.lng,latitude:e.lat,anchor:"center",children:a.jsx(U,{prefix:e.prefix,name:e.name,isLocal:!1,color:"zinc"})},`cecho-node-${e.prefix}-${s}`))]})}),$.length>0&&a.jsx("div",{className:"absolute bottom-1.5 left-1.5 z-10 flex items-center gap-1 flex-wrap max-w-[60%]",children:$.map((e,s)=>a.jsxs(k,{color:"zinc",className:"type-data-xs shadow-sm opacity-70",children:[a.jsx(re,{className:"w-2 h-2 mr-0.5"}),e.prefix,e.name&&a.jsx("span",{className:"ml-0.5 opacity-60",children:e.name})]},`cecho-unmap-${e.prefix}-${s}`))}),a.jsx("div",{className:"absolute bottom-1.5 right-1.5 z-10",children:a.jsxs(k,{color:"green",className:"type-data-xs shadow-sm",children:[j.length," echo",j.length!==1?"es":""]})})]})}export{he as CompanionEchoMap}; +import{r as i,c$ as K,a6 as T,Q as Y,fO as D,au as I,cB as J,g7 as Q,Z as q,O as X,j as a,c as V,V as k,cE as ee}from"./index-BBBuaCQs.js";import{M as te,S as ne,L as se,a as R}from"./maplibre-gl-BGrZ3ia8.js";import{useSrcHashResolverMap as ae,useDiscoveredNodes as oe}from"./usePipelineStore-CSy1PGRp.js";import{M as re}from"./map-pin-off-CmyDNImL.js";import"./node-types-DJyFsA81.js";const le={light:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",dark:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"},A=X.amber,O=q[400],U=i.memo(function({prefix:c,name:o,isLocal:f,color:n}){const[r,u]=i.useState(!1);return a.jsx("div",{onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),style:{pointerEvents:"auto"},children:a.jsxs(k,{color:n,filled:!0,className:V("type-data-xs shadow-lg border border-current/30 transition-all duration-150 cursor-default",r&&"relative z-50"),children:[f&&a.jsx(ee,{className:"w-2.5 h-2.5 mr-0.5"}),c&&a.jsx("span",{className:"font-mono",children:c}),r&&o&&a.jsx("span",{className:c?"ml-0.5 opacity-75":"",children:o})]})})});function N(p,c){return p==null||c==null?!1:p!==0||c!==0}function ie(p,c,o){var u;const f=p.toUpperCase(),n=c.find(l=>l.public_key.toUpperCase().startsWith(f));if(n&&N(n.gps_lat,n.gps_lon))return{name:n.name||null,lat:n.gps_lat,lng:n.gps_lon,hasGps:!0};if(o.neighbors){const l=Object.entries(o.neighbors).find(([t])=>t.toUpperCase().startsWith(f));if(l){const[,t]=l;if(N(t.latitude,t.longitude))return{name:t.node_name||t.name||null,lat:t.latitude,lng:t.longitude,hasGps:!0}}}const r=o.srcHashMap.get(f);if(r){const l=o.discoveredNodes.get(r);if(l&&N(l.latitude,l.longitude))return{name:l.name||null,lat:l.latitude,lng:l.longitude,hasGps:!0};if(o.neighbors){const t=o.neighbors[r];if(t&&N(t.latitude,t.longitude))return{name:t.node_name||t.name||null,lat:t.latitude,lng:t.longitude,hasGps:!0}}}return{name:(n==null?void 0:n.name)||(r?((u=o.discoveredNodes.get(r))==null?void 0:u.name)??null:null),lat:0,lng:0,hasGps:!1}}function ce(p,c,o,f){const n=Math.floor(c/30);for(const r of[n-1,n,n+1])for(const[u,l]of o){const t=l.decoded;if(!(t!=null&&t.decrypted)||t.senderName!==f)continue;const v=t.timestamp??l.timestamp;if(Math.floor(v/30)===r&&t.text===p)return u}return null}function ue(p,c){const o=new Set,f=[];for(const n of c){if(n.packet_hash!==p||n.packet_origin==="tx_local")continue;const r=n.original_path??n.forwarded_path;if(!r||r.length===0)continue;const u=r[r.length-1].toUpperCase();o.has(u)||(o.add(u),f.push({prefix:u,snr:n.snr}))}return f}function he({text:p,timestamp:c,contacts:o,className:f}){const n=i.useRef(null),r=K(),u=T(),l=Y(),[t,v]=i.useState(!1),m=D(),C=I(),z=u==null?void 0:u.neighbors,E=ae(),B=oe(),M=J(),g=Q(),w=(m==null?void 0:m.node_name)??(g==null?void 0:g.node_name)??null,F=i.useMemo(()=>({neighbors:z,srcHashMap:E,discoveredNodes:B}),[z,E,B]),d=i.useMemo(()=>{const e=(m==null?void 0:m.node_name)||(g==null?void 0:g.node_name)||(g==null?void 0:g.companion_name)||"Me";return m&&N(m.latitude,m.longitude)?{prefix:m.public_key.slice(0,2).toUpperCase(),name:e,lat:m.latitude,lng:m.longitude}:M&&N(M.latitude,M.longitude)?{prefix:"",name:e,lat:M.latitude,lng:M.longitude}:null},[m,g,M]),L=i.useMemo(()=>w?ce(p,c,C,w):null,[p,c,C,w]),G=i.useMemo(()=>L?ue(L,l):[],[L,l]),j=i.useMemo(()=>G.map(e=>{const s=ie(e.prefix,o,F);return{prefix:e.prefix,snr:e.snr,...s}}),[G,o,F]),y=i.useMemo(()=>j.filter(e=>e.hasGps),[j]),$=i.useMemo(()=>j.filter(e=>!e.hasGps),[j]),_=i.useMemo(()=>{if(!d||y.length===0)return[];const e=[d.lng,d.lat];return y.map(s=>{const h=[s.lng,s.lat];return{from:e,to:h,midpoint:[(e[0]+h[0])/2,(e[1]+h[1])/2]}})},[d,y]),W=i.useMemo(()=>_.map(e=>({type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e.from,e.to]}}]})),[_]),H=i.useMemo(()=>{if(typeof document>"u")return{amber:A,zinc:O};const e=getComputedStyle(document.documentElement),s=e.getPropertyValue("--sys-amber").trim(),h=e.getPropertyValue("--zinc-400").trim();return{amber:s.startsWith("#")?s:A,zinc:h.startsWith("#")?h:O}},[]),x=i.useMemo(()=>{if(!d||y.length===0)return null;let e=d.lat,s=d.lat,h=d.lng,S=d.lng;for(const b of y)b.lats&&(s=b.lat),b.lngS&&(S=b.lng);return[[h,e],[S,s]]},[d,y]),Z=i.useCallback(()=>{var s;const e=(s=n.current)==null?void 0:s.getMap();e&&x&&e.fitBounds(x,{padding:{top:40,bottom:44,left:56,right:56},maxZoom:14,duration:0}),v(!0)},[x]);if(!x||!d)return null;const P=[(x[0][0]+x[1][0])/2,(x[0][1]+x[1][1])/2];return a.jsxs("div",{className:V("relative rounded-lg overflow-hidden",f),style:{aspectRatio:"16 / 10"},children:[!t&&a.jsx("div",{className:"absolute inset-0 bg-subtle-fill flex items-center justify-center pointer-events-none z-10",children:a.jsx("div",{className:"w-4 h-4 border-2 border-fg-muted/30 border-t-fg-muted rounded-full animate-spin"})}),a.jsx("div",{className:"h-full w-full transition-opacity duration-200",style:{opacity:t?1:0},children:a.jsxs(te,{ref:n,initialViewState:{longitude:P[0],latitude:P[1],zoom:10},onLoad:Z,style:{height:"100%",width:"100%"},mapStyle:le[r],attributionControl:!1,interactive:!1,children:[_.map((e,s)=>a.jsx(ne,{id:`cecho-${s}`,type:"geojson",data:W[s],lineMetrics:!0,children:a.jsx(se,{id:`cecho-line-${s}`,type:"line",paint:{"line-width":2,"line-gradient":["interpolate",["linear"],["line-progress"],0,H.amber,1,H.zinc]},layout:{"line-cap":"round","line-join":"round"}})},`cecho-${s}`)),a.jsx(R,{longitude:d.lng,latitude:d.lat,anchor:"center",children:a.jsx(U,{prefix:d.prefix,name:d.name,isLocal:!0,color:"amber"})}),y.map((e,s)=>a.jsx(R,{longitude:e.lng,latitude:e.lat,anchor:"center",children:a.jsx(U,{prefix:e.prefix,name:e.name,isLocal:!1,color:"zinc"})},`cecho-node-${e.prefix}-${s}`))]})}),$.length>0&&a.jsx("div",{className:"absolute bottom-1.5 left-1.5 z-10 flex items-center gap-1 flex-wrap max-w-[60%]",children:$.map((e,s)=>a.jsxs(k,{color:"zinc",className:"type-data-xs shadow-sm opacity-70",children:[a.jsx(re,{className:"w-2 h-2 mr-0.5"}),e.prefix,e.name&&a.jsx("span",{className:"ml-0.5 opacity-60",children:e.name})]},`cecho-unmap-${e.prefix}-${s}`))}),a.jsx("div",{className:"absolute bottom-1.5 right-1.5 z-10",children:a.jsxs(k,{color:"green",className:"type-data-xs shadow-sm",children:[j.length," echo",j.length!==1?"es":""]})})]})}export{he as CompanionEchoMap}; diff --git a/frontend/dist/assets/CompanionPathMap-D1qZh3TG.js b/frontend/dist/assets/CompanionPathMap-CBbQCUOF.js similarity index 95% rename from frontend/dist/assets/CompanionPathMap-D1qZh3TG.js rename to frontend/dist/assets/CompanionPathMap-CBbQCUOF.js index 2c2b0626..84849cab 100644 --- a/frontend/dist/assets/CompanionPathMap-D1qZh3TG.js +++ b/frontend/dist/assets/CompanionPathMap-CBbQCUOF.js @@ -1 +1 @@ -import{r,c$ as X,a6 as I,cB as ee,g7 as te,Z,O as J,j as n,c as K,V as H,cE as ne}from"./index-BXuscHlA.js";import{M as se,S as C,L as U,a as G}from"./maplibre-gl-CfjETxh6.js";import{useSrcHashResolverMap as oe,useDiscoveredNodes as ae}from"./usePipelineStore-DPecx6Zm.js";import{C as le}from"./car-2b6my27b.js";import{M as ie}from"./map-pin-off-C9sYl_IQ.js";import"./node-types-DcVrjPZe.js";const re={light:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",dark:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"},ce=Z[500],D=J.orange,T=J.green,ue=r.memo(function({prefix:a,name:o,isLocal:u,color:s}){const[m,b]=r.useState(!1);return n.jsx("div",{onMouseEnter:()=>b(!0),onMouseLeave:()=>b(!1),style:{pointerEvents:"auto"},children:n.jsxs(H,{color:s,filled:!0,className:K("type-data-xs shadow-lg border border-current/30 transition-all duration-150 cursor-default",m&&"relative z-50"),children:[u&&n.jsx(ne,{className:"w-2.5 h-2.5 mr-0.5"}),a&&n.jsx("span",{className:"font-mono",children:a}),m&&o&&n.jsx("span",{className:a?"ml-0.5 opacity-75":"",children:o})]})})});function L(d,a){return d==null||a==null?!1:d!==0||a!==0}function de(d,a,o){var s;const u=[];for(const m of d){const b=m.toUpperCase(),p=a.find(c=>c.public_key.toUpperCase().startsWith(b));if(p&&L(p.gps_lat,p.gps_lon)){u.push({prefix:m,name:p.name||null,lat:p.gps_lat,lng:p.gps_lon,isLocal:!1,hasGps:!0});continue}if(o.neighbors){const c=Object.entries(o.neighbors).find(([i])=>i.toUpperCase().startsWith(b));if(c){const[,i]=c;if(L(i.latitude,i.longitude)){u.push({prefix:m,name:i.node_name||i.name||null,lat:i.latitude,lng:i.longitude,isLocal:!1,hasGps:!0});continue}}}const N=o.srcHashMap.get(b);if(N){const c=o.discoveredNodes.get(N);if(c&&L(c.latitude,c.longitude)){u.push({prefix:m,name:c.name||null,lat:c.latitude,lng:c.longitude,isLocal:!1,hasGps:!0});continue}if(o.neighbors){const i=o.neighbors[N];if(i&&L(i.latitude,i.longitude)){u.push({prefix:m,name:i.node_name||i.name||null,lat:i.latitude,lng:i.longitude,isLocal:!1,hasGps:!0});continue}}}u.push({prefix:m,name:(p==null?void 0:p.name)||(N?((s=o.discoveredNodes.get(N))==null?void 0:s.name)??null:null),lat:0,lng:0,isLocal:!1,hasGps:!1})}return u}function me(d,a,o,u){const s=(a==null?void 0:a.node_name)||u||(o==null?void 0:o.name)||"Me";if(a&&L(a.latitude,a.longitude)){const m=a.public_key.slice(0,2).toUpperCase();return[...d,{prefix:m,name:s,lat:a.latitude,lng:a.longitude,isLocal:!0,hasGps:!0}]}return o&&L(o.latitude,o.longitude)?[...d,{prefix:"",name:s,lat:o.latitude,lng:o.longitude,isLocal:!0,hasGps:!0}]:d}function be({hops:d,contacts:a,selfInfo:o,snr:u,wardriveCoords:s,wardriveSenderName:m,className:b}){const p=r.useRef(null),N=X(),c=I(),[i,Y]=r.useState(!1),w=c==null?void 0:c.neighbors,z=oe(),R=ae(),B=ee(),M=te(),$=r.useMemo(()=>({neighbors:w,srcHashMap:z,discoveredNodes:R}),[w,z,R]),k=(M==null?void 0:M.node_name)??(M==null?void 0:M.companion_name)??null,h=r.useMemo(()=>{const e=de(d,a,$);return me(e,o,B,k)},[d,a,$,o,B,k]),g=r.useMemo(()=>h.filter(e=>e.hasGps),[h]),F=r.useMemo(()=>h.filter(e=>!e.hasGps),[h]),S=r.useMemo(()=>{const e=[];if(g.length<2)return e;const t=[];for(let l=0;lS.map(e=>({type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e.from,e.to]}}]})),[S]),O=r.useMemo(()=>{if(typeof document>"u")return ce;const e=getComputedStyle(document.documentElement).getPropertyValue("--zinc-400").trim();return e.startsWith("#")?e:Z[400]},[]),v=r.useMemo(()=>{if(!s||g.length===0)return null;const e=[s.lon,s.lat],t=g[0];return{from:e,to:[t.lng,t.lat]}},[s,g]),P=r.useMemo(()=>v?{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[v.from,v.to]}}]}:null,[v]),A=r.useMemo(()=>{if(typeof document>"u")return{orange:D,green:T};const e=getComputedStyle(document.documentElement),t=e.getPropertyValue("--sys-orange").trim(),l=e.getPropertyValue("--sys-green").trim();return{orange:t.startsWith("#")?t:D,green:l.startsWith("#")?l:T}},[]),j=r.useMemo(()=>{if(g.length<2&&!s||g.length+(s?1:0)<2)return null;let t=1/0,l=-1/0,x=1/0,y=-1/0;for(const f of g)f.latl&&(l=f.lat),f.lngy&&(y=f.lng);return s&&(s.latl&&(l=s.lat),s.lony&&(y=s.lon)),[[x,t],[y,l]]},[g,s]),Q=r.useCallback(()=>{var t;const e=(t=p.current)==null?void 0:t.getMap();e&&j&&e.fitBounds(j,{padding:{top:40,bottom:44,left:56,right:56},maxZoom:14,duration:0}),Y(!0)},[j]);if(!j)return null;const W=[(j[0][0]+j[1][0])/2,(j[0][1]+j[1][1])/2];return n.jsxs("div",{className:K("relative rounded-lg overflow-hidden",b),style:{aspectRatio:"16 / 10"},children:[!i&&n.jsx("div",{className:"absolute inset-0 bg-subtle-fill flex items-center justify-center pointer-events-none z-10",children:n.jsx("div",{className:"w-4 h-4 border-2 border-fg-muted/30 border-t-fg-muted rounded-full animate-spin"})}),n.jsx("div",{className:"h-full w-full transition-opacity duration-200",style:{opacity:i?1:0},children:n.jsxs(se,{ref:p,initialViewState:{longitude:W[0],latitude:W[1],zoom:10},onLoad:Q,style:{height:"100%",width:"100%"},mapStyle:re[N],attributionControl:!1,interactive:!1,children:[P&&n.jsx(C,{id:"cwd-edge",type:"geojson",data:P,lineMetrics:!0,children:n.jsx(U,{id:"cwd-edge-line",type:"line",paint:{"line-width":2,"line-gradient":["interpolate",["linear"],["line-progress"],0,A.orange,1,A.green]},layout:{"line-cap":"round","line-join":"round"}})}),s&&n.jsx(G,{longitude:s.lon,latitude:s.lat,anchor:"center",children:n.jsx("div",{className:"flex items-center",style:{pointerEvents:"auto"},children:n.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-full bg-sys-orange text-white shadow-lg border-2 border-sys-orange/50",children:n.jsx(le,{className:"w-4 h-4",strokeWidth:2.5})})})}),S.map((e,t)=>n.jsx(C,{id:`cedge-${t}`,type:"geojson",data:q[t],children:n.jsx(U,{id:`cedge-line-${t}`,type:"line",paint:{"line-color":O,"line-width":2,"line-opacity":.85},layout:{"line-cap":"round","line-join":"round"}})},`cedge-${t}`)),S.map((e,t)=>n.jsx(G,{longitude:e.midpoint[0],latitude:e.midpoint[1],anchor:"center",children:n.jsx("span",{className:"w-4.5 h-4.5 rounded-full flex items-center justify-center font-mono font-extrabold tabular-nums shadow-md pointer-events-none",style:{backgroundColor:O,color:"#fff",fontSize:"10px",lineHeight:1,textShadow:"0 1px 1px rgba(0,0,0,0.4)"},children:e.hopNumber})},`chop-${t}`)),g.map((e,t)=>{const l=t===0,x=t===g.length-1,y=e.isLocal?"amber":l?"green":x?"amber":"zinc";return n.jsx(G,{longitude:e.lng,latitude:e.lat,anchor:"center",children:n.jsx(ue,{prefix:e.prefix,name:e.name,isLocal:e.isLocal,color:y})},`cnode-${e.prefix}-${t}`)})]})}),F.length>0&&n.jsx("div",{className:"absolute bottom-1.5 left-1.5 z-10 flex items-center gap-1 flex-wrap max-w-[60%]",children:F.map((e,t)=>n.jsxs(H,{color:"zinc",className:"type-data-xs shadow-sm opacity-70",children:[n.jsx(ie,{className:"w-2 h-2 mr-0.5"}),e.prefix,e.name&&n.jsx("span",{className:"ml-0.5 opacity-60",children:e.name})]},`cunmap-${e.prefix}-${t}`))}),u!=null&&n.jsx("div",{className:"absolute bottom-1.5 right-1.5 z-10",children:n.jsxs(H,{color:"zinc",className:"type-data-xs shadow-sm",children:[u>0?"+":"",u.toFixed(1)," dB"]})})]})}export{be as CompanionPathMap}; +import{r,c$ as X,a6 as I,cB as ee,g7 as te,Z,O as J,j as n,c as K,V as H,cE as ne}from"./index-BBBuaCQs.js";import{M as se,S as C,L as U,a as G}from"./maplibre-gl-BGrZ3ia8.js";import{useSrcHashResolverMap as oe,useDiscoveredNodes as ae}from"./usePipelineStore-CSy1PGRp.js";import{C as le}from"./car-DhqwLgdJ.js";import{M as ie}from"./map-pin-off-CmyDNImL.js";import"./node-types-DJyFsA81.js";const re={light:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",dark:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"},ce=Z[500],D=J.orange,T=J.green,ue=r.memo(function({prefix:a,name:o,isLocal:u,color:s}){const[m,b]=r.useState(!1);return n.jsx("div",{onMouseEnter:()=>b(!0),onMouseLeave:()=>b(!1),style:{pointerEvents:"auto"},children:n.jsxs(H,{color:s,filled:!0,className:K("type-data-xs shadow-lg border border-current/30 transition-all duration-150 cursor-default",m&&"relative z-50"),children:[u&&n.jsx(ne,{className:"w-2.5 h-2.5 mr-0.5"}),a&&n.jsx("span",{className:"font-mono",children:a}),m&&o&&n.jsx("span",{className:a?"ml-0.5 opacity-75":"",children:o})]})})});function L(d,a){return d==null||a==null?!1:d!==0||a!==0}function de(d,a,o){var s;const u=[];for(const m of d){const b=m.toUpperCase(),p=a.find(c=>c.public_key.toUpperCase().startsWith(b));if(p&&L(p.gps_lat,p.gps_lon)){u.push({prefix:m,name:p.name||null,lat:p.gps_lat,lng:p.gps_lon,isLocal:!1,hasGps:!0});continue}if(o.neighbors){const c=Object.entries(o.neighbors).find(([i])=>i.toUpperCase().startsWith(b));if(c){const[,i]=c;if(L(i.latitude,i.longitude)){u.push({prefix:m,name:i.node_name||i.name||null,lat:i.latitude,lng:i.longitude,isLocal:!1,hasGps:!0});continue}}}const N=o.srcHashMap.get(b);if(N){const c=o.discoveredNodes.get(N);if(c&&L(c.latitude,c.longitude)){u.push({prefix:m,name:c.name||null,lat:c.latitude,lng:c.longitude,isLocal:!1,hasGps:!0});continue}if(o.neighbors){const i=o.neighbors[N];if(i&&L(i.latitude,i.longitude)){u.push({prefix:m,name:i.node_name||i.name||null,lat:i.latitude,lng:i.longitude,isLocal:!1,hasGps:!0});continue}}}u.push({prefix:m,name:(p==null?void 0:p.name)||(N?((s=o.discoveredNodes.get(N))==null?void 0:s.name)??null:null),lat:0,lng:0,isLocal:!1,hasGps:!1})}return u}function me(d,a,o,u){const s=(a==null?void 0:a.node_name)||u||(o==null?void 0:o.name)||"Me";if(a&&L(a.latitude,a.longitude)){const m=a.public_key.slice(0,2).toUpperCase();return[...d,{prefix:m,name:s,lat:a.latitude,lng:a.longitude,isLocal:!0,hasGps:!0}]}return o&&L(o.latitude,o.longitude)?[...d,{prefix:"",name:s,lat:o.latitude,lng:o.longitude,isLocal:!0,hasGps:!0}]:d}function be({hops:d,contacts:a,selfInfo:o,snr:u,wardriveCoords:s,wardriveSenderName:m,className:b}){const p=r.useRef(null),N=X(),c=I(),[i,Y]=r.useState(!1),w=c==null?void 0:c.neighbors,z=oe(),R=ae(),B=ee(),M=te(),$=r.useMemo(()=>({neighbors:w,srcHashMap:z,discoveredNodes:R}),[w,z,R]),k=(M==null?void 0:M.node_name)??(M==null?void 0:M.companion_name)??null,h=r.useMemo(()=>{const e=de(d,a,$);return me(e,o,B,k)},[d,a,$,o,B,k]),g=r.useMemo(()=>h.filter(e=>e.hasGps),[h]),F=r.useMemo(()=>h.filter(e=>!e.hasGps),[h]),S=r.useMemo(()=>{const e=[];if(g.length<2)return e;const t=[];for(let l=0;lS.map(e=>({type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e.from,e.to]}}]})),[S]),O=r.useMemo(()=>{if(typeof document>"u")return ce;const e=getComputedStyle(document.documentElement).getPropertyValue("--zinc-400").trim();return e.startsWith("#")?e:Z[400]},[]),v=r.useMemo(()=>{if(!s||g.length===0)return null;const e=[s.lon,s.lat],t=g[0];return{from:e,to:[t.lng,t.lat]}},[s,g]),P=r.useMemo(()=>v?{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[v.from,v.to]}}]}:null,[v]),A=r.useMemo(()=>{if(typeof document>"u")return{orange:D,green:T};const e=getComputedStyle(document.documentElement),t=e.getPropertyValue("--sys-orange").trim(),l=e.getPropertyValue("--sys-green").trim();return{orange:t.startsWith("#")?t:D,green:l.startsWith("#")?l:T}},[]),j=r.useMemo(()=>{if(g.length<2&&!s||g.length+(s?1:0)<2)return null;let t=1/0,l=-1/0,x=1/0,y=-1/0;for(const f of g)f.latl&&(l=f.lat),f.lngy&&(y=f.lng);return s&&(s.latl&&(l=s.lat),s.lony&&(y=s.lon)),[[x,t],[y,l]]},[g,s]),Q=r.useCallback(()=>{var t;const e=(t=p.current)==null?void 0:t.getMap();e&&j&&e.fitBounds(j,{padding:{top:40,bottom:44,left:56,right:56},maxZoom:14,duration:0}),Y(!0)},[j]);if(!j)return null;const W=[(j[0][0]+j[1][0])/2,(j[0][1]+j[1][1])/2];return n.jsxs("div",{className:K("relative rounded-lg overflow-hidden",b),style:{aspectRatio:"16 / 10"},children:[!i&&n.jsx("div",{className:"absolute inset-0 bg-subtle-fill flex items-center justify-center pointer-events-none z-10",children:n.jsx("div",{className:"w-4 h-4 border-2 border-fg-muted/30 border-t-fg-muted rounded-full animate-spin"})}),n.jsx("div",{className:"h-full w-full transition-opacity duration-200",style:{opacity:i?1:0},children:n.jsxs(se,{ref:p,initialViewState:{longitude:W[0],latitude:W[1],zoom:10},onLoad:Q,style:{height:"100%",width:"100%"},mapStyle:re[N],attributionControl:!1,interactive:!1,children:[P&&n.jsx(C,{id:"cwd-edge",type:"geojson",data:P,lineMetrics:!0,children:n.jsx(U,{id:"cwd-edge-line",type:"line",paint:{"line-width":2,"line-gradient":["interpolate",["linear"],["line-progress"],0,A.orange,1,A.green]},layout:{"line-cap":"round","line-join":"round"}})}),s&&n.jsx(G,{longitude:s.lon,latitude:s.lat,anchor:"center",children:n.jsx("div",{className:"flex items-center",style:{pointerEvents:"auto"},children:n.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-full bg-sys-orange text-white shadow-lg border-2 border-sys-orange/50",children:n.jsx(le,{className:"w-4 h-4",strokeWidth:2.5})})})}),S.map((e,t)=>n.jsx(C,{id:`cedge-${t}`,type:"geojson",data:q[t],children:n.jsx(U,{id:`cedge-line-${t}`,type:"line",paint:{"line-color":O,"line-width":2,"line-opacity":.85},layout:{"line-cap":"round","line-join":"round"}})},`cedge-${t}`)),S.map((e,t)=>n.jsx(G,{longitude:e.midpoint[0],latitude:e.midpoint[1],anchor:"center",children:n.jsx("span",{className:"w-4.5 h-4.5 rounded-full flex items-center justify-center font-mono font-extrabold tabular-nums shadow-md pointer-events-none",style:{backgroundColor:O,color:"#fff",fontSize:"10px",lineHeight:1,textShadow:"0 1px 1px rgba(0,0,0,0.4)"},children:e.hopNumber})},`chop-${t}`)),g.map((e,t)=>{const l=t===0,x=t===g.length-1,y=e.isLocal?"amber":l?"green":x?"amber":"zinc";return n.jsx(G,{longitude:e.lng,latitude:e.lat,anchor:"center",children:n.jsx(ue,{prefix:e.prefix,name:e.name,isLocal:e.isLocal,color:y})},`cnode-${e.prefix}-${t}`)})]})}),F.length>0&&n.jsx("div",{className:"absolute bottom-1.5 left-1.5 z-10 flex items-center gap-1 flex-wrap max-w-[60%]",children:F.map((e,t)=>n.jsxs(H,{color:"zinc",className:"type-data-xs shadow-sm opacity-70",children:[n.jsx(ie,{className:"w-2 h-2 mr-0.5"}),e.prefix,e.name&&n.jsx("span",{className:"ml-0.5 opacity-60",children:e.name})]},`cunmap-${e.prefix}-${t}`))}),u!=null&&n.jsx("div",{className:"absolute bottom-1.5 right-1.5 z-10",children:n.jsxs(H,{color:"zinc",className:"type-data-xs shadow-sm",children:[u>0?"+":"",u.toFixed(1)," dB"]})})]})}export{be as CompanionPathMap}; diff --git a/frontend/dist/assets/Configuration-D3Mywae8.js b/frontend/dist/assets/Configuration-BPseYNxI.js similarity index 98% rename from frontend/dist/assets/Configuration-D3Mywae8.js rename to frontend/dist/assets/Configuration-BPseYNxI.js index cb052c21..c54eccf7 100644 --- a/frontend/dist/assets/Configuration-D3Mywae8.js +++ b/frontend/dist/assets/Configuration-BPseYNxI.js @@ -1,5 +1,5 @@ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/latin-400-BcR6IdUc.css","assets/latin-500-DCnAHIrw.css","assets/latin-600-CnkPk-vb.css","assets/latin-700-UC1i-VSI.css"])))=>i.map(i=>d[i]); -import{e as ke,r as a,j as e,c as m,ev as Is,cT as oe,a2 as U,a0 as J,bM as Z,aE as Ke,ew as ze,ex as os,ey as as,_ as De,a8 as xe,E as jt,S as vt,ez as Nt,a7 as X,cu as cs,eA as wt,B as L,V as ns,eB as Ks,bY as Le,X as Ws,eC as kt,a6 as _t,dK as Os,c3 as St,c7 as ls,dV as Xs,eD as Ct,eE as zs,eF as Tt,eG as Ft,eH as Et,aa as Rt,eI as Je,I as Mt,a1 as Dt,a3 as At}from"./index-BXuscHlA.js";import{g as Pt,a as Lt,c as It,r as Kt,s as Ot,b as zt,u as Vt,d as $t}from"./system-Cg9xmEP7.js";import{C as Ht}from"./ConfirmModal-LQhUAumX.js";import{S as qt,A as Bt,a as Gt,N as Ut}from"./AutoConfigureDialog-BYa3iJhA.js";import{W as rs}from"./wand-sparkles-BtQTQ8OM.js";import{P as is,F as Vs}from"./pencil-C-PJWgte.js";import{i as Wt,g as Xt,s as Yt,a as Jt,k as Qt}from"./keycap-sfx-ByZp-njj.js";import{C as Y,P as Zt,a as ea,B as sa}from"./PageLayout-DMlJphZf.js";import{T as Ys}from"./trash-2-DkPl8dK5.js";import{R as ta}from"./rotate-ccw-uSJHrUFu.js";import{S as aa}from"./shield-CqMKRbQ8.js";import{R as na}from"./repeat-D9BSaUJP.js";import{G as la}from"./git-branch-nBxx_Zec.js";import{C as ra}from"./clock-CGjCxSm0.js";import{C as Js}from"./chevron-right-CLnbP5Ct.js";import{R as se,C as me}from"./Grid-CJ1-9ZY4.js";import{A as ia}from"./antenna-D8uvYVBM.js";import{P as $s}from"./plus-CIt9Nb3C.js";import{K as Hs}from"./key-round-BPCLbGFL.js";import"./arrow-right-BLOvRmAV.js";/** +import{e as ke,r as a,j as e,c as m,ev as Is,cT as oe,a2 as U,a0 as J,bM as Z,aE as Ke,ew as ze,ex as os,ey as as,_ as De,a8 as xe,E as jt,S as vt,ez as Nt,a7 as X,cu as cs,eA as wt,B as L,V as ns,eB as Ks,bY as Le,X as Ws,eC as kt,a6 as _t,dK as Os,c3 as St,c7 as ls,dV as Xs,eD as Ct,eE as zs,eF as Tt,eG as Ft,eH as Et,aa as Rt,eI as Je,I as Mt,a1 as Dt,a3 as At}from"./index-BBBuaCQs.js";import{g as Pt,a as Lt,c as It,r as Kt,s as Ot,b as zt,u as Vt,d as $t}from"./system-DzUDH5_v.js";import{C as Ht}from"./ConfirmModal-DGG0Ux0s.js";import{S as qt,A as Bt,a as Gt,N as Ut}from"./AutoConfigureDialog-2NSNWjfu.js";import{W as rs}from"./wand-sparkles-C15_vEeB.js";import{P as is,F as Vs}from"./pencil-BkH6oVA6.js";import{i as Wt,g as Xt,s as Yt,a as Jt,k as Qt}from"./keycap-sfx-ByZp-njj.js";import{C as Y,P as Zt,a as ea,B as sa}from"./PageLayout-CRsVqzTw.js";import{T as Ys}from"./trash-2-DUN81fPu.js";import{R as ta}from"./rotate-ccw-CyEc4qm2.js";import{S as aa}from"./shield-B8h1r8Cv.js";import{R as na}from"./repeat-o5vMN1bP.js";import{G as la}from"./git-branch-DoAYRXX_.js";import{C as ra}from"./clock-DV9Z95kG.js";import{C as Js}from"./chevron-right-DMF-_TsK.js";import{R as se,C as me}from"./Grid-Bush3dl2.js";import{A as ia}from"./antenna-C2XIp6Jd.js";import{P as $s}from"./plus-BnP2OnZA.js";import{K as Hs}from"./key-round-BlimCcTG.js";import"./arrow-right-BNRZQuRI.js";/** * @license lucide-react v0.559.0 - ISC * * This source code is licensed under the ISC license. diff --git a/frontend/dist/assets/ConfirmModal-LQhUAumX.js b/frontend/dist/assets/ConfirmModal-DGG0Ux0s.js similarity index 91% rename from frontend/dist/assets/ConfirmModal-LQhUAumX.js rename to frontend/dist/assets/ConfirmModal-DGG0Ux0s.js index ebc7823d..9a990650 100644 --- a/frontend/dist/assets/ConfirmModal-LQhUAumX.js +++ b/frontend/dist/assets/ConfirmModal-DGG0Ux0s.js @@ -1 +1 @@ -import{r as d,j as s,aC as x,aK as m,bY as g,c as C,aD as f,eJ as j,B as o}from"./index-BXuscHlA.js";const u={danger:"text-sys-red",warning:"text-sys-indigo",default:"text-sys-blue"},p={danger:"danger",warning:"warning",default:"primary"};function N({isOpen:n,title:r="Confirm",message:l,confirmLabel:t="Confirm",cancelLabel:i="Cancel",variant:a="default",onConfirm:c,onCancel:e}){return s.jsxs(x,{open:n,onClose:e,size:"sm",children:[s.jsx(m,{icon:s.jsx(g,{className:C("w-5 h-5",u[a])}),title:r,onClose:e}),s.jsx(f,{children:s.jsx("p",{className:"text-sm text-fg-secondary",children:l})}),s.jsxs(j,{children:[s.jsx(o,{color:"muted",onClick:e,className:"flex-1",children:i}),s.jsx(o,{color:p[a],onClick:c,className:"flex-1",children:t})]})]})}const y=d.memo(N);export{y as C}; +import{r as d,j as s,aC as x,aK as m,bY as g,c as C,aD as f,eJ as j,B as o}from"./index-BBBuaCQs.js";const u={danger:"text-sys-red",warning:"text-sys-indigo",default:"text-sys-blue"},p={danger:"danger",warning:"warning",default:"primary"};function N({isOpen:n,title:r="Confirm",message:l,confirmLabel:t="Confirm",cancelLabel:i="Cancel",variant:a="default",onConfirm:c,onCancel:e}){return s.jsxs(x,{open:n,onClose:e,size:"sm",children:[s.jsx(m,{icon:s.jsx(g,{className:C("w-5 h-5",u[a])}),title:r,onClose:e}),s.jsx(f,{children:s.jsx("p",{className:"text-sm text-fg-secondary",children:l})}),s.jsxs(j,{children:[s.jsx(o,{color:"muted",onClick:e,className:"flex-1",children:i}),s.jsx(o,{color:p[a],onClick:c,className:"flex-1",children:t})]})]})}const y=d.memo(N);export{y as C}; diff --git a/frontend/dist/assets/Contacts-DvfgLHt9.js b/frontend/dist/assets/Contacts-DvfgLHt9.js new file mode 100644 index 00000000..2fbe8bc5 --- /dev/null +++ b/frontend/dist/assets/Contacts-DvfgLHt9.js @@ -0,0 +1,23 @@ +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ContactsMapMapLibre-Bb14UZ5D.js","assets/index-BBBuaCQs.js","assets/consumer-registry-04zc6uvW.js","assets/link-scoring-CxJumM6l.js","assets/ConfirmModal-DGG0Ux0s.js","assets/variants-WXnHxSXf.js","assets/git-branch-DoAYRXX_.js","assets/database-D4A6B9uV.js","assets/useMapViewStore-KZ-iYEhb.js","assets/index-CyH5wAaG.js","assets/index-CQClum6j.js","assets/target-CjK6GJds.js","assets/funnel-C8NxsG5E.js","assets/plus-BnP2OnZA.js","assets/compass-DD46PLB1.js","assets/zap-DDG9zYwX.js","assets/max-ju7hW25D.js","assets/trash-2-DUN81fPu.js","assets/wifi-off-NffUdBle.js","assets/wifi-752FYPBg.js","assets/circle-alert-pRjy9QOw.js","assets/clock-DV9Z95kG.js","assets/chevron-right-DMF-_TsK.js","assets/payload-detail-XcpxSMLm.js","assets/LightSparkline-Bon5FLNi.js","assets/badge-colors-Dl76Mz8m.js","assets/map-pin-stXuybQm.js","assets/node-types-DJyFsA81.js","assets/BasemapLayer-hjkVmX-W.js","assets/easing-Bdhj1KpK.js","assets/usePipelineStore-CSy1PGRp.js","assets/PageLayout-CRsVqzTw.js","assets/listbox-iaAoqLDr.js","assets/element-movement-BGm_uaZd.js","assets/use-text-value-2q1EQ-Jk.js","assets/frozen-D91afNsn.js","assets/MqttModeBadge-Bl-vewzA.js","assets/chat-utils-DP6LcfMx.js","assets/SignalIndicator-CkqfZLem.js","assets/CollisionExplorerModal-qV7zoTO2.js","assets/share-2-WwVAp6Bf.js","assets/circle-question-mark-CI9cD3nq.js","assets/map-pin-off-CmyDNImL.js","assets/activity-cShCNfEo.js","assets/search-Dk9GWMDh.js","assets/index-BsosE29f.css","assets/maplibre-gl-B1CfjdFi.css","assets/ContactsMapMapLibre-BwWOEply.css"])))=>i.map(i=>d[i]); +import{e as xe,ar as cs,j as e,r as n,_ as is,cp as He,cq as Ie,ao as W,a0 as Ce,cr as ls,cs as me,aa as de,c3 as ds,az as Oe,ct as ye,a2 as ze,cu as ms,ac as xs,cv as us,cw as ps,cx as hs,ab as fs,cy as gs,cz as js,ad as bs,aA as ys,ae as Ne,cA as Ns,cB as vs,cC as ws,cD as Cs,bI as ee,cE as $e,Y as ks,I as Ms,bM as Ss,c as we}from"./index-BBBuaCQs.js";import{useDiscoveredNodes as Ps}from"./usePipelineStore-CSy1PGRp.js";import{c as ke}from"./node-types-DJyFsA81.js";import{P as _s,a as Rs,B as Ls}from"./PageLayout-CRsVqzTw.js";import{L as Ts,a as le}from"./listbox-iaAoqLDr.js";import{T as Fe,M as $s}from"./MqttModeBadge-Bl-vewzA.js";import{u as Fs,e as Es,f as Hs,r as Is}from"./consumer-registry-04zc6uvW.js";import{e as Os,g as zs,a as Ds}from"./chat-utils-DP6LcfMx.js";import{b as Bs}from"./SignalIndicator-CkqfZLem.js";import{C as As}from"./CollisionExplorerModal-qV7zoTO2.js";import{E as qs,T as Vs}from"./target-CjK6GJds.js";import{S as Us}from"./share-2-WwVAp6Bf.js";import{C as De}from"./circle-question-mark-CI9cD3nq.js";import{M as Ws}from"./map-pin-off-CmyDNImL.js";import{A as Be}from"./activity-cShCNfEo.js";import{T as Gs}from"./trash-2-DUN81fPu.js";import{C as Qs}from"./ConfirmModal-DGG0Ux0s.js";import{M as Xs}from"./map-pin-stXuybQm.js";import{S as Ys}from"./search-Dk9GWMDh.js";import{C as Zs}from"./clock-DV9Z95kG.js";/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Js=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],Ks=xe("arrow-up-down",Js);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const et=[["path",{d:"M4 12V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2",key:"jrl274"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 16h2v6",key:"1bxocy"}],["path",{d:"M10 22h4",key:"ceow96"}],["rect",{x:"2",y:"16",width:"4",height:"6",rx:"2",key:"r45zd0"}]],st=xe("file-digit",et);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const tt=[["path",{d:"M2 5h20",key:"1fs1ex"}],["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M9 19h6",key:"456am0"}]],at=xe("list-filter",tt);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const nt=[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]],Ae=xe("ruler",nt);class rt extends n.Component{constructor(l){super(l),this.state={hasError:!1}}static getDerivedStateFromError(l){return{hasError:!0,error:l}}render(){var l;return this.state.hasError?e.jsx("div",{className:"map-container-16-9 flex items-center justify-center rounded-2xl surface-base",role:"alert","aria-live":"assertive",children:e.jsxs("div",{className:"text-center text-fg-muted p-4",children:[e.jsx("p",{className:"text-lg mb-2",children:"Map failed to load"}),e.jsx("p",{className:"text-sm text-fg-muted",children:((l=this.state.error)==null?void 0:l.message)||"Unknown error"}),e.jsx("p",{className:"text-xs text-fg-muted mt-2",children:"Try refreshing the page or check your browser's WebGL support."})]})}):this.props.children}}const ot=n.lazy(()=>is(()=>import("./ContactsMapMapLibre-Bb14UZ5D.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47]))),Ee=()=>e.jsx("div",{className:"map-container-16-9 flex items-center justify-center rounded-2xl surface-base",role:"status","aria-live":"polite","aria-label":"Loading map",children:e.jsxs("div",{className:"text-fg-muted flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-sys-blue border-t-transparent rounded-full animate-spin","aria-hidden":"true"}),e.jsx("span",{children:"Loading map..."})]})});function ct({neighbors:o,localNode:l,localHash:g,onRemoveNode:u,selectedNodeHash:j,onNodeSelected:N,highlightedEdgeKey:c,highlightedGhost:T}){return cs()===!1?e.jsx(Ee,{}):e.jsx(rt,{children:e.jsx(n.Suspense,{fallback:e.jsx(Ee,{}),children:e.jsx(ot,{neighbors:o,localNode:l,localHash:g,onRemoveNode:u,selectedNodeHash:j,onNodeSelected:N,highlightedEdgeKey:c,highlightedGhost:T})})})}function it({hash:o,className:l="",size:g="sm",collisionInfo:u,isViterbiResolved:j}){const N=He(),c=Ie(),[T,$]=n.useState(!1),w=n.useMemo(()=>W(o),[o]),p=n.useMemo(()=>u!==void 0?u:w?N.find(P=>P.prefix===w)??null:null,[w,N,u]),C=j??(c.totalPaths>0&&c.avgPathConfidence>=.7),D=n.useCallback(P=>{P.preventDefault(),P.stopPropagation(),$(!0)},[]),B=n.useCallback(()=>{$(!1)},[]);if(!p)return null;const A=g==="sm"?"w-3.5 h-3.5":"w-4 h-4",q=C?"text-sys-cyan hover:text-sys-cyan hover:bg-sys-cyan/10 focus:ring-sys-cyan/50":"text-signal-fair hover:text-sys-indigo hover:bg-signal-fair/10 focus:ring-signal-fair/50",S=C?`Prefix conflict resolved by Viterbi HMM (${(c.avgPathConfidence*100).toFixed(0)}% confidence)`:`Prefix conflict: ${p.candidateCount} nodes share prefix "${w}"`;return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:D,className:`inline-flex items-center justify-center p-0.5 rounded focus:outline-none focus:ring-2 transition-colors cursor-pointer touch-manipulation ${q} ${l}`,title:S,"aria-label":`View prefix conflict for ${w}${C?" (Viterbi resolved)":""}`,children:C?e.jsxs("span",{className:"relative",children:[e.jsx(qs,{className:A}),e.jsx(Ce,{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 text-sys-green"})]}):e.jsx(st,{className:A})}),T&&e.jsx(As,{isOpen:!0,prefix:p.prefix,candidateHashes:p.candidateHashes,onClose:B})]})}const lt=n.memo(it),qe=[{target:"Contacts",fn:"name",minStage:1,when:Es},{target:"Contacts",fn:"traceLinks.directed",minStage:2,when:Hs}];Is(qe);function dt(o){return o<1e3?`${Math.round(o)}m`:`${(o/1e3).toFixed(1)}km`}function mt({hash:o,contact:l,isHub:g,isNeighbor:u,distance:j,centrality:N,neighborSignal:c,collisionInfo:T,isViterbiResolved:$,pingingHash:w,pingResult:p,pingError:C,isMobile:D,metaSummary:B,metaTooltip:A,onRowClick:q,onPing:S,onRemove:P}){Fs(qe);const _=l.latitude&&l.longitude&&l.latitude!==0&&l.longitude!==0,H=l.node_name||l.name||"Unknown",I=u&&c,se=ke(l),{isRepeater:v,isCompanion:G,isRoomServer:R,isClient:Q,label:b}=se,te=u?`${b} — Direct RF contact (zero-hop neighbor)`:`${b} — Flood routing (multi-hop via mesh)`,ae=n.useCallback(()=>q(o),[q,o]);return e.jsxs("div",{className:`contacts-grid-row ${g?"bg-sys-amber/5 border-l-2 border-l-sys-amber":""} ${_?"cursor-pointer":""}`,onClick:ae,children:[e.jsxs("div",{className:"contacts-col-node flex items-center gap-2 min-w-0",children:[I&&(c==null?void 0:c.avgSnr)!==null?e.jsx("div",{className:`w-2 h-2 rounded-full flex-shrink-0 self-center ${ls(c.avgSnr)}`}):e.jsx("div",{className:"w-2 flex-shrink-0"}),e.jsx("div",{className:"w-6 h-6 flex items-center justify-center flex-shrink-0",title:te,children:(()=>{if(R&&v)return e.jsxs("div",{className:"relative w-5 h-5",children:[e.jsx(me,{className:"w-5 h-5 absolute inset-0 text-sys-pink"}),e.jsx(Us,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-sys-teal"})]});if(R)return e.jsx(me,{className:"w-5 h-5 text-sys-pink"});if(v)return e.jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center ring-[1.5px] ring-sys-blue",children:e.jsx(de,{className:"w-3.5 h-3.5 text-sys-blue"})});if((G||Q)&&H!=="Unknown"){const{emoji:F,cleanName:ue}=Os(H);return e.jsx("div",{className:"w-6 h-6 clay-avatar",style:{"--avatar-color":zs(ue)},children:F?e.jsx("span",{className:"text-sm leading-none",children:F}):e.jsx("span",{className:"text-white text-[9px] font-bold tracking-tighter",children:Ds(H)})})}return e.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center bg-zinc-500/20",children:e.jsx(De,{className:"w-3.5 h-3.5 text-sys-amber"})})})()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 overflow-hidden",children:[e.jsx("span",{className:"roster-title truncate",title:H,children:H}),u&&e.jsx("span",{className:"contact-tag contact-tag--nbr",children:"NBR"}),g&&e.jsx("span",{className:"contact-tag contact-tag--hub",children:"HUB"}),v&&e.jsx("span",{className:"contact-tag contact-tag--rpt",children:"RPT"}),R&&e.jsx("span",{className:"contact-tag contact-tag--room",children:"ROOM"}),G&&e.jsx("span",{className:"contact-tag contact-tag--comp",children:"COMP"}),Q&&e.jsx("span",{className:"contact-tag contact-tag--client",children:"CLIENT"}),D&&e.jsx("span",{className:"contact-tag contact-tag--mobile",children:"MOB"}),!_&&e.jsx(Ws,{className:"w-3 h-3 flex-shrink-0 text-fg-muted/50"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx(ds,{copy:!0,size:"compact",truncate:[8,6],children:o}),e.jsx(lt,{hash:o,collisionInfo:T,isViterbiResolved:$}),B&&e.jsx("span",{className:"contact-meta",title:A,children:B})]})]})]}),e.jsxs("div",{className:"contacts-col-signal flex items-center justify-end gap-2",children:[I&&(c==null?void 0:c.avgRssi)!==null&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Bs,{rssi:c.avgRssi,className:"w-3.5 h-3.5"}),e.jsx("span",{className:"type-data-xs text-fg-muted",children:Math.round(c.avgRssi)})]}),I&&(c==null?void 0:c.avgSnr)!==null&&e.jsxs("span",{className:"type-data-xs text-fg-muted",children:[c.avgSnr.toFixed(1)," dB"]})]}),e.jsx("div",{className:"contacts-col-distance flex items-center justify-end gap-1 text-fg-muted",children:j!=null&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"w-3 h-3"}),e.jsx("span",{className:"type-data-xs",children:dt(j)})]})}),e.jsx("div",{className:"contacts-col-centrality flex items-center justify-end gap-1",children:N>0&&e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"w-3 h-3 text-sys-indigo"}),e.jsxs("span",{className:"type-data-xs text-fg-muted",children:[(N*100).toFixed(0),"%"]})]})}),e.jsx("div",{className:"contacts-col-seen flex items-center justify-end",children:e.jsx("span",{className:"type-data-xs text-fg-primary whitespace-nowrap",children:l.last_seen?Oe(l.last_seen):"—"})}),e.jsxs("div",{className:"contacts-col-actions flex items-center justify-end gap-1",children:[u&&e.jsx(e.Fragment,{children:p?e.jsxs("div",{className:`flex items-center gap-1 ${ye(p)?"text-sys-green":"text-fg-muted"}`,title:`RTT: ${p.rtt_ms.toFixed(0)}ms${ye(p)?` · SNR: ${p.snr_db.toFixed(1)}dB · RSSI: ${p.rssi}dBm`:""}`,children:[e.jsx(Ce,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"type-data-xs hidden sm:inline",children:ye(p)?`${p.snr_db.toFixed(1)}dB`:`${(p.rtt_ms/1e3).toFixed(1)}s`})]}):C?e.jsxs("span",{className:"text-sys-red text-xs font-medium",title:C,children:[e.jsx("span",{className:"hidden sm:inline",children:C}),e.jsx("span",{className:"sm:hidden",children:"✗"})]}):e.jsx("button",{onClick:F=>S(o,F),disabled:w!==null,className:"p-1 sm:p-1.5 radius-inner text-fg-muted/50 hover:text-sys-blue hover:bg-sys-blue/10 transition-base disabled:opacity-50 disabled:cursor-not-allowed",title:"Ping neighbor for updated signal info",children:w===o?e.jsx(ze,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4 animate-spin"}):e.jsx(Vs,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})}),e.jsx("button",{onClick:F=>{F.stopPropagation(),P(o,H)},className:"p-1 sm:p-1.5 radius-inner text-fg-muted/50 hover:text-sys-red hover:bg-sys-red/10 transition-base",title:"Remove contact",children:e.jsx(Gs,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})]})]})}const xt=n.memo(mt),ut=6371e3,pt=[{field:"lastHeard",icon:Zs,label:"Recent"},{field:"distance",icon:Ae,label:"Distance"},{field:"centrality",icon:Be,label:"Centrality"}];function ht(o){switch(o){case"room_server":return"room";case"repeater":return"repeater";case"companion":return"companion";case"unknown":return"companion"}}function ft(o){const l=ke(o);return ht(l.type)}function ve(o,l){const{color:g="primary",border:u=!1}=l??{};return we("flex items-center gap-1.5 px-2 py-1.5 text-sm radius-inner transition-base",o?g==="success"?"bg-sys-green/20 text-sys-green":"bg-sys-blue/20 text-sys-blue":"text-fg-muted hover:text-fg-secondary hover-bg",u&&(o?g==="success"?"border border-sys-green/30":"border border-sys-blue/30":"border border-transparent"))}function gt(o,l,g,u){const j=(g-o)*Math.PI/180,N=(u-l)*Math.PI/180,c=Math.sin(j/2)*Math.sin(j/2)+Math.cos(o*Math.PI/180)*Math.cos(g*Math.PI/180)*Math.sin(N/2)*Math.sin(N/2),T=2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c));return ut*T}function jt(){var Le,Te;const{stats:o}=ms(),l=xs(),g=us(),u=ps(),j=hs(),N=fs(),c=gs(),T=js(),$=bs(),w=ys(),p=Ne[$],C=He(),D=Ie(),B=Ns(),A=D.totalPaths>0&&D.avgPathConfidence>=.7,q=n.useMemo(()=>{const s=new Map;for(const a of C)s.set(a.prefix,a);return s},[C]),[S,P]=n.useState(null),[_,H]=n.useState("lastHeard"),[I,se]=n.useState("desc"),[v,G]=n.useState(""),[R,Q]=n.useState(!1),[b,te]=n.useState(new Set),[ae,F]=n.useState(!1),[ue,Me]=n.useState(null),[pe,Se]=n.useState(null),[Ve,he]=n.useState(new Map),[Ue,X]=n.useState(new Map),[k,We]=n.useState(25),[V,ne]=n.useState(25),fe=n.useRef(null),Y=n.useMemo(()=>(o==null?void 0:o.neighbors)??{},[o==null?void 0:o.neighbors]),ge=Ps(),re=n.useMemo(()=>{if(ge.size===0)return Y;const s=new Set;for(const t of Object.keys(Y))s.add((t.startsWith("0x")?t.slice(2):t).toLowerCase());let a=null;for(const[t,r]of ge){const i=(t.startsWith("0x")?t.slice(2):t).toLowerCase();s.has(i)||(a||(a={...Y}),a[t]={last_seen:r.lastSeen,name:r.name??void 0,node_name:r.name??void 0,latitude:r.latitude,longitude:r.longitude,is_repeater:r.nodeType==="repeater",contact_type:r.nodeType==="repeater"?"Repeater":r.nodeType==="companion"?"Companion":r.nodeType==="room_server"?"Room Server":void 0})}return a??Y},[Y,ge]),O=n.useMemo(()=>{const a=Date.now()/1e3-p.minutes*60;return Object.fromEntries(Object.entries(re).filter(([t,r])=>l.has(t)?!1:(r.last_seen??0)>=a))},[re,l,p.minutes]),L=vs(),z=o==null?void 0:o.local_hash,Ge=n.useMemo(()=>{const s=new Map;if(!z||c.size===0)return s;for(const[a,t]of c)if(a.endsWith(`→${z}`)&&t.hops.length>1){const r=a.split("→")[0],i=t.hops[t.hops.length-1];s.set(r,i)}return s},[c,z]),Qe=n.useMemo(()=>{const s=new Map;if(!z||c.size===0)return s;const a=new Map;for(const[t,r]of Object.entries(re)){const i=(t.startsWith("0x")?t.slice(2):t).toLowerCase();a.set(i,r)}for(const[t,r]of c){if(!t.endsWith(`→${z}`)||r.hops.length===0)continue;const i=t.split("→")[0],d=r.hops[0];let h=null;for(const[f,y]of a)if(f.startsWith(d.toLowerCase())){h=y.node_name??y.name??null;break}s.set(i,{prefix:d,name:h,hopCount:r.hopCount})}return s},[c,z,re]),oe=n.useMemo(()=>{const s=new Map;if(!(L!=null&&L.latitude)||!(L!=null&&L.longitude))return s;for(const[a,t]of Object.entries(O))t.latitude&&t.longitude&&t.latitude!==0&&t.longitude!==0?s.set(a,gt(L.latitude,L.longitude,t.latitude,t.longitude)):s.set(a,null);return s},[O,L]),{neighborHashSet:ce,neighborSignalMap:Xe}=n.useMemo(()=>{const s=new Set,a=new Map;for(const t of N)s.add(t.hash),a.set(t.hash,{avgRssi:t.avgRssi,avgSnr:t.avgSnr});return{neighborHashSet:s,neighborSignalMap:a}},[N]),Pe=n.useMemo(()=>{const s=v.toLowerCase().trim(),a=s==="neighbor"||s==="neighbors",t=R||a,r=b.size>0;return Object.fromEntries(Object.entries(O).filter(([i,d])=>{if(r){const y=ft(d);if(!b.has(y))return!1}if(t&&!ce.has(i))return!1;if(a||!s)return!0;const h=(d.node_name||d.name||"").toLowerCase(),f=W(i).toLowerCase();return h.includes(s)||f.includes(s)||i.toLowerCase().includes(s)}))},[O,v,R,ce,b]),x=n.useMemo(()=>{const s=Object.entries(Pe),a=v.toLowerCase().trim(),t=/^[0-9a-f]{2}(?:[0-9a-f]{2}){0,2}$/i.test(a);return s.sort(([r,i],[d,h])=>{if(t){const y=W(r).toLowerCase(),E=W(d).toLowerCase(),M=y===a,U=E===a;if(M&&!U)return-1;if(U&&!M)return 1}let f=0;switch(_){case"lastHeard":f=(i.last_seen||0)-(h.last_seen||0);break;case"distance":{const y=oe.get(r)??null,E=oe.get(d)??null;y===null&&E===null?f=0:y===null?f=1:E===null?f=-1:f=y-E;break}case"centrality":{const y=j.get(r)||0,E=j.get(d)||0;f=y-E;break}}return I==="desc"?-f:f})},[Pe,_,I,oe,j,v]),m=n.useMemo(()=>{let s=0,a=0,t=0,r=0,i=0;for(const[,d]of x){const h=ke(d),f=d.latitude&&d.longitude&&d.latitude!==0&&d.longitude!==0;switch(h.type){case"room_server":t++;break;case"repeater":a++;break;case"companion":s++;break;case"unknown":i++;break}f&&r++}return{companions:s,repeaters:a,roomServers:t,total:x.length,withLocation:r,unknown:i}},[x]),Ye=n.useMemo(()=>new Set(u),[u]),_e=n.useMemo(()=>k===0?x:x.slice(0,V),[x,V,k]);n.useEffect(()=>{ne(k||x.length)},[_,I,v,R,b,k,x.length]),n.useEffect(()=>{const s=a=>{a.target.closest("[data-dropdown]")||F(!1)};return document.addEventListener("click",s),()=>document.removeEventListener("click",s)},[]),n.useEffect(()=>{if(k===0)return;const s=new IntersectionObserver(a=>{a[0].isIntersecting&&VMath.min(t+k,x.length))},{threshold:.1,rootMargin:"100px"});return fe.current&&s.observe(fe.current),()=>s.disconnect()},[k,V,x.length]);const Ze=n.useCallback(s=>{We(s),ne(s||x.length)},[x.length]),Je=n.useCallback(s=>{_===s?se(a=>a==="desc"?"asc":"desc"):(H(s),se("desc"))},[_]),Ke=n.useCallback(s=>{const a=O[s];a!=null&&a.latitude&&(a!=null&&a.longitude)&&a.latitude!==0&&a.longitude!==0&&Me(s)},[O]),es=n.useCallback(()=>{Me(null)},[]),ss=n.useCallback((s,a)=>{P({hash:s,name:a})},[]),Re=ws((Te=(Le=o==null?void 0:o.config)==null?void 0:Le.mesh)==null?void 0:Te.path_hash_mode),ts=n.useCallback(async(s,a)=>{if(a.stopPropagation(),!pe){Se(s),he(t=>{const r=new Map(t);return r.delete(s),r}),X(t=>{const r=new Map(t);return r.delete(s),r});try{const r=`0x${W(s,Re)}`,i=await Cs(r,30);i.success&&i.data?(he(d=>new Map(d).set(s,i.data)),setTimeout(()=>{he(d=>{const h=new Map(d);return h.delete(s),h})},1e4)):(X(d=>new Map(d).set(s,i.error||"Ping failed")),setTimeout(()=>{X(d=>{const h=new Map(d);return h.delete(s),h})},5e3))}catch(t){const r=t instanceof Error?t.message:"Ping failed";X(i=>new Map(i).set(s,r)),setTimeout(()=>{X(i=>{const d=new Map(i);return d.delete(s),d})},5e3)}finally{Se(null)}}},[pe,Re]);return e.jsxs(_s,{children:[e.jsx(Rs,{title:"Contacts",icon:e.jsx(ee,{}),subtitle:e.jsx($s,{}),controls:e.jsxs("div",{className:"flex items-center gap-3 sm:gap-5",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Total:"}),e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:`${m.total} discovered node${m.total!==1?"s":""} on the mesh network`,children:[e.jsx(ee,{className:"w-3.5 h-3.5 text-fg-secondary"}),e.jsx("span",{children:m.total})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Types:"}),m.repeaters>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Repeaters",children:[e.jsx(de,{className:"w-3.5 h-3.5 text-sys-blue"}),e.jsx("span",{children:m.repeaters})]}),m.companions>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Companions",children:[e.jsx($e,{className:"w-3.5 h-3.5 text-fg-muted"}),e.jsx("span",{children:m.companions})]}),m.roomServers>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Room Servers",children:[e.jsx(me,{className:"w-3.5 h-3.5 text-sys-pink"}),e.jsx("span",{children:m.roomServers})]}),m.withLocation>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"With GPS location",children:[e.jsx(Xs,{className:"w-3.5 h-3.5 text-sys-green"}),e.jsx("span",{children:m.withLocation})]}),m.unknown>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Unknown type",children:[e.jsx(De,{className:"w-3.5 h-3.5 text-sys-amber"}),e.jsx("span",{children:m.unknown})]})]})]}),e.jsxs("div",{className:"flex sm:hidden items-center gap-1.5",children:[e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(ee,{className:"w-3 h-3 text-fg-secondary"}),e.jsx("span",{children:m.total})]}),m.repeaters>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(de,{className:"w-3 h-3 text-sys-blue"}),e.jsx("span",{children:m.repeaters})]}),m.companions>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx($e,{className:"w-3 h-3 text-fg-muted"}),e.jsx("span",{children:m.companions})]}),m.roomServers>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(me,{className:"w-3 h-3 text-sys-pink"}),e.jsx("span",{children:m.roomServers})]}),e.jsx(Fe,{ranges:Ne,selectedIndex:$,onSelect:w,size:"sm"})]}),e.jsx("div",{className:"hidden sm:block",children:e.jsx(Fe,{ranges:Ne,selectedIndex:$,onSelect:w})})]})}),e.jsxs(Ls,{children:[e.jsx(ct,{neighbors:O,localNode:L??void 0,localHash:z,onRemoveNode:g,selectedNodeHash:ue,onNodeSelected:es}),e.jsxs(ks,{noPadding:!0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 px-3 sm:px-4 py-2.5 border-b border-edge-subtle",children:[e.jsx("span",{className:"icon-md flex items-center justify-center text-icon-card-title flex-shrink-0",children:e.jsx(ee,{})}),e.jsx("span",{className:"type-micro flex-shrink-0 mr-auto hidden sm:block",children:"Discovered Contacts"}),e.jsx(Ms,{type:"search",size:"sm",value:v,onChange:s=>G(s.target.value),placeholder:"Search...",leadingIcon:e.jsx(Ys,{className:"w-3.5 h-3.5"}),trailingIcon:v?e.jsx("button",{onClick:()=>{G(""),(v.toLowerCase().trim()==="neighbor"||v.toLowerCase().trim()==="neighbors")&&Q(!1)},className:"text-fg-muted hover:text-fg-secondary",children:e.jsx(Ss,{className:"w-3 h-3"})}):void 0,className:"w-24 sm:w-32 xl:w-44","aria-label":"Search contacts"}),e.jsx("div",{className:"h-4 w-px bg-border-subtle flex-shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsxs("div",{className:"relative","data-dropdown":!0,children:[e.jsxs("button",{onClick:()=>F(!ae),className:ve(b.size>0,{border:!0}),title:"Filter by contact type",children:[e.jsx(at,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:"Filter"}),b.size>0&&e.jsx("span",{className:"tabular-nums text-xs bg-sys-blue/30 px-1 rounded",children:b.size})]}),ae&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 surface-elevated radius-inner py-1 min-w-[140px]",children:[[{key:"repeater",label:"Repeaters"},{key:"companion",label:"Companions"},{key:"room",label:"Rooms"}].map(({key:s,label:a})=>e.jsxs("button",{onClick:()=>{te(t=>{const r=new Set(t);return r.has(s)?r.delete(s):r.add(s),r})},className:"w-full px-3 py-1.5 text-sm text-left hover-bg transition-base flex items-center gap-2",children:[e.jsx("span",{className:we("w-4 h-4 flex items-center justify-center radius-badge border",b.has(s)?"bg-sys-blue border-sys-blue text-white":"border-edge-subtle"),children:b.has(s)&&e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("span",{className:b.has(s)?"text-fg-primary":"text-fg-secondary",children:a})]},s)),b.size>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-edge-subtle my-1"}),e.jsx("button",{onClick:()=>te(new Set),className:"w-full px-3 py-1.5 text-sm text-left text-fg-muted hover:text-fg-secondary hover-bg transition-base",children:"Clear filters"})]})]})]}),ce.size>0&&e.jsxs("button",{onClick:()=>Q(!R),className:ve(R,{color:"success",border:!0}),title:R?"Show all contacts":"Show only MeshCore neighbors (direct RF contact)",children:[e.jsx(de,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:"Neighbors"})]})]}),e.jsx("div",{className:"h-4 w-px bg-border-subtle flex-shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[pt.map(({field:s,icon:a,label:t})=>e.jsxs("button",{onClick:()=>Je(s),className:ve(_===s),title:`Sort by ${t.toLowerCase()}`,children:[e.jsx(a,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:t}),_===s&&e.jsx(Ks,{className:we("w-3 h-3",I==="asc"&&"rotate-180")})]},s)),e.jsx("div",{className:"h-4 w-px bg-border-subtle"}),e.jsxs(Ts,{value:k,onChange:Ze,className:"w-auto min-w-[50px] [&_button]:py-1 [&_button]:px-2 [&_button]:text-xs [&_button]:min-h-0","aria-label":"Items per page",children:[e.jsx(le,{value:25,children:"25"}),e.jsx(le,{value:50,children:"50"}),e.jsx(le,{value:100,children:"100"}),e.jsx(le,{value:0,children:"All"})]})]})]}),x.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hidden sm:grid contacts-grid-header border-b border-edge-subtle/50 px-3 py-2 type-micro text-fg-muted",children:[e.jsx("div",{className:"contacts-col-node",children:"Node"}),e.jsx("div",{className:"contacts-col-signal text-right",children:"Signal"}),e.jsx("div",{className:"contacts-col-distance text-right",children:"Distance"}),e.jsx("div",{className:"contacts-col-centrality text-right",children:"Centrality"}),e.jsx("div",{className:"contacts-col-seen text-right",children:"Last Seen"}),e.jsx("div",{className:"contacts-col-actions"})]}),e.jsx("div",{className:"divide-y divide-edge-subtle/30",style:{contain:"layout paint"},children:_e.map(([s,a])=>{const t=W(s),r=Ye.has(s),i=ce.has(s),d=oe.get(s)??null,h=j.get(s)||0,f=i?Xe.get(s):void 0,y=t?q.get(t)??null:null,E=T.has(s),M=i?null:Qe.get(s)??null,U=Ge.get(s)??null,je=B.get(s);let Z=null;if(je&&je.length>0){const ie=je.reduce((rs,os)=>rs+os.count,0);ie>0&&(Z=ie/24)}const be=a.first_seen?Oe(a.first_seen).replace(/ ago$/i,""):null,J=[],K=[];if(M){const ie=M.name??M.prefix;J.push(`→${ie} +${M.hopCount}`),K.push(`Gateway: ${M.name??M.prefix} (${M.hopCount} hop${M.hopCount!==1?"s":""})`)}U&&(J.push(`↙${U}`),K.push(`Last forwarder: ${U}`)),Z!==null&&(J.push(`${Z<1?"<1":Math.round(Z)}/hr`),K.push(`Packet rate: ${Z.toFixed(1)}/hr`)),be&&(J.push(be),K.push(`First seen: ${be} ago`));const as=J.join(" · "),ns=K.join(` +`);return e.jsx(xt,{hash:s,contact:a,isHub:r,isNeighbor:i,distance:d,centrality:h,neighborSignal:f,collisionInfo:y,isViterbiResolved:A,pingingHash:pe,pingResult:Ve.get(s),pingError:Ue.get(s),isMobile:E,metaSummary:as,metaTooltip:ns,onRowClick:Ke,onPing:ts,onRemove:ss},s)})}),k>0&&V0&&Vne(s=>Math.min(s+k,x.length)),className:"text-sys-blue hover:text-sys-blue/80 transition-base",children:"Load more"})]})]}):e.jsxs("div",{className:"roster-empty",children:[e.jsx(ee,{className:"roster-empty-icon"}),e.jsx("div",{className:"type-label text-fg-secondary",children:"No Contacts Discovered"}),e.jsx("div",{className:"type-data-xs text-fg-muted mt-1",children:"Contacts will appear here as they advertise on the mesh network."})]})]})]}),e.jsx(Qs,{isOpen:!!S,title:"Remove Contact",message:`Remove ${(S==null?void 0:S.name)||"this contact"} from the contacts list? The node will reappear if it advertises again.`,confirmLabel:"Remove",cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{S&&g(S.hash),P(null)},onCancel:()=>P(null)})]})}const zt=Object.freeze(Object.defineProperty({__proto__:null,default:jt},Symbol.toStringTag,{value:"Module"}));export{zt as C,lt as P,Ae as R}; diff --git a/frontend/dist/assets/Contacts-oNWWqGGm.js b/frontend/dist/assets/Contacts-oNWWqGGm.js deleted file mode 100644 index ae6a6552..00000000 --- a/frontend/dist/assets/Contacts-oNWWqGGm.js +++ /dev/null @@ -1,23 +0,0 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ContactsMapMapLibre-C-KGlqHC.js","assets/index-BXuscHlA.js","assets/consumer-registry-BcsoNpAo.js","assets/link-scoring-DpRWqfZk.js","assets/ConfirmModal-LQhUAumX.js","assets/variants-C1ClDTMR.js","assets/git-branch-nBxx_Zec.js","assets/database-fpkElipK.js","assets/useMapViewStore-ytvVAAgR.js","assets/index-CX3eVGcW.js","assets/index-B4UKVGqH.js","assets/target-EqctFMYZ.js","assets/funnel-H6zOOlsG.js","assets/plus-CIt9Nb3C.js","assets/compass-BX0gjJ7U.js","assets/zap-B33m-gOd.js","assets/max-Dyc3Msy6.js","assets/trash-2-DkPl8dK5.js","assets/wifi-off-Cvh7sDFt.js","assets/wifi-DC7bSB9p.js","assets/circle-alert-DJxbJjtU.js","assets/clock-CGjCxSm0.js","assets/chevron-right-CLnbP5Ct.js","assets/LightSparkline-P0XSkll2.js","assets/badge-colors-Dl76Mz8m.js","assets/map-pin-BI3SkGEK.js","assets/node-types-DcVrjPZe.js","assets/BasemapLayer-CSNA1nZg.js","assets/easing-CYf147KM.js","assets/usePipelineStore-DPecx6Zm.js","assets/PageLayout-DMlJphZf.js","assets/listbox-CbV6sKJY.js","assets/element-movement-ZK9X4oe-.js","assets/use-text-value-CdBb507Q.js","assets/frozen-tEvmWu2u.js","assets/MqttModeBadge-CLfWxKNd.js","assets/chat-utils-LE1iz0ua.js","assets/SignalIndicator-BF1HzGJb.js","assets/CollisionExplorerModal-B3e6xvEX.js","assets/share-2-B7Nq-Teh.js","assets/circle-question-mark-BRhEuEaL.js","assets/map-pin-off-C9sYl_IQ.js","assets/activity-Ce_CBMP-.js","assets/search-CJVt1qRW.js","assets/index-oOga43RI.css","assets/maplibre-gl-B1CfjdFi.css","assets/ContactsMapMapLibre-BwWOEply.css"])))=>i.map(i=>d[i]); -import{e as xe,ar as cs,j as e,r as n,_ as is,cp as He,cq as Ie,ao as W,a0 as Ce,cr as ls,cs as me,aa as de,c3 as ds,az as Oe,ct as ye,a2 as ze,cu as ms,ac as xs,cv as us,cw as ps,cx as hs,ab as fs,cy as gs,cz as js,ad as bs,aA as ys,ae as Ne,cA as Ns,cB as vs,cC as ws,cD as Cs,bI as ee,cE as $e,Y as ks,I as Ms,bM as Ss,c as we}from"./index-BXuscHlA.js";import{useDiscoveredNodes as Ps}from"./usePipelineStore-DPecx6Zm.js";import{c as ke}from"./node-types-DcVrjPZe.js";import{P as _s,a as Rs,B as Ls}from"./PageLayout-DMlJphZf.js";import{L as Ts,a as le}from"./listbox-CbV6sKJY.js";import{T as Fe,M as $s}from"./MqttModeBadge-CLfWxKNd.js";import{u as Fs,e as Es,f as Hs,r as Is}from"./consumer-registry-BcsoNpAo.js";import{e as Os,g as zs,a as Ds}from"./chat-utils-LE1iz0ua.js";import{b as Bs}from"./SignalIndicator-BF1HzGJb.js";import{C as As}from"./CollisionExplorerModal-B3e6xvEX.js";import{E as qs,T as Vs}from"./target-EqctFMYZ.js";import{S as Us}from"./share-2-B7Nq-Teh.js";import{C as De}from"./circle-question-mark-BRhEuEaL.js";import{M as Ws}from"./map-pin-off-C9sYl_IQ.js";import{A as Be}from"./activity-Ce_CBMP-.js";import{T as Gs}from"./trash-2-DkPl8dK5.js";import{C as Qs}from"./ConfirmModal-LQhUAumX.js";import{M as Xs}from"./map-pin-BI3SkGEK.js";import{S as Ys}from"./search-CJVt1qRW.js";import{C as Zs}from"./clock-CGjCxSm0.js";/** - * @license lucide-react v0.559.0 - ISC - * - * This source code is licensed under the ISC license. - * See the LICENSE file in the root directory of this source tree. - */const Js=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],Ks=xe("arrow-up-down",Js);/** - * @license lucide-react v0.559.0 - ISC - * - * This source code is licensed under the ISC license. - * See the LICENSE file in the root directory of this source tree. - */const et=[["path",{d:"M4 12V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2",key:"jrl274"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 16h2v6",key:"1bxocy"}],["path",{d:"M10 22h4",key:"ceow96"}],["rect",{x:"2",y:"16",width:"4",height:"6",rx:"2",key:"r45zd0"}]],st=xe("file-digit",et);/** - * @license lucide-react v0.559.0 - ISC - * - * This source code is licensed under the ISC license. - * See the LICENSE file in the root directory of this source tree. - */const tt=[["path",{d:"M2 5h20",key:"1fs1ex"}],["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M9 19h6",key:"456am0"}]],at=xe("list-filter",tt);/** - * @license lucide-react v0.559.0 - ISC - * - * This source code is licensed under the ISC license. - * See the LICENSE file in the root directory of this source tree. - */const nt=[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]],Ae=xe("ruler",nt);class rt extends n.Component{constructor(l){super(l),this.state={hasError:!1}}static getDerivedStateFromError(l){return{hasError:!0,error:l}}render(){var l;return this.state.hasError?e.jsx("div",{className:"map-container-16-9 flex items-center justify-center rounded-2xl surface-base",role:"alert","aria-live":"assertive",children:e.jsxs("div",{className:"text-center text-fg-muted p-4",children:[e.jsx("p",{className:"text-lg mb-2",children:"Map failed to load"}),e.jsx("p",{className:"text-sm text-fg-muted",children:((l=this.state.error)==null?void 0:l.message)||"Unknown error"}),e.jsx("p",{className:"text-xs text-fg-muted mt-2",children:"Try refreshing the page or check your browser's WebGL support."})]})}):this.props.children}}const ot=n.lazy(()=>is(()=>import("./ContactsMapMapLibre-C-KGlqHC.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46]))),Ee=()=>e.jsx("div",{className:"map-container-16-9 flex items-center justify-center rounded-2xl surface-base",role:"status","aria-live":"polite","aria-label":"Loading map",children:e.jsxs("div",{className:"text-fg-muted flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-sys-blue border-t-transparent rounded-full animate-spin","aria-hidden":"true"}),e.jsx("span",{children:"Loading map..."})]})});function ct({neighbors:o,localNode:l,localHash:g,onRemoveNode:u,selectedNodeHash:j,onNodeSelected:N,highlightedEdgeKey:c,highlightedGhost:T}){return cs()===!1?e.jsx(Ee,{}):e.jsx(rt,{children:e.jsx(n.Suspense,{fallback:e.jsx(Ee,{}),children:e.jsx(ot,{neighbors:o,localNode:l,localHash:g,onRemoveNode:u,selectedNodeHash:j,onNodeSelected:N,highlightedEdgeKey:c,highlightedGhost:T})})})}function it({hash:o,className:l="",size:g="sm",collisionInfo:u,isViterbiResolved:j}){const N=He(),c=Ie(),[T,$]=n.useState(!1),w=n.useMemo(()=>W(o),[o]),p=n.useMemo(()=>u!==void 0?u:w?N.find(P=>P.prefix===w)??null:null,[w,N,u]),C=j??(c.totalPaths>0&&c.avgPathConfidence>=.7),D=n.useCallback(P=>{P.preventDefault(),P.stopPropagation(),$(!0)},[]),B=n.useCallback(()=>{$(!1)},[]);if(!p)return null;const A=g==="sm"?"w-3.5 h-3.5":"w-4 h-4",q=C?"text-sys-cyan hover:text-sys-cyan hover:bg-sys-cyan/10 focus:ring-sys-cyan/50":"text-signal-fair hover:text-sys-indigo hover:bg-signal-fair/10 focus:ring-signal-fair/50",S=C?`Prefix conflict resolved by Viterbi HMM (${(c.avgPathConfidence*100).toFixed(0)}% confidence)`:`Prefix conflict: ${p.candidateCount} nodes share prefix "${w}"`;return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:D,className:`inline-flex items-center justify-center p-0.5 rounded focus:outline-none focus:ring-2 transition-colors cursor-pointer touch-manipulation ${q} ${l}`,title:S,"aria-label":`View prefix conflict for ${w}${C?" (Viterbi resolved)":""}`,children:C?e.jsxs("span",{className:"relative",children:[e.jsx(qs,{className:A}),e.jsx(Ce,{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 text-sys-green"})]}):e.jsx(st,{className:A})}),T&&e.jsx(As,{isOpen:!0,prefix:p.prefix,candidateHashes:p.candidateHashes,onClose:B})]})}const lt=n.memo(it),qe=[{target:"Contacts",fn:"name",minStage:1,when:Es},{target:"Contacts",fn:"traceLinks.directed",minStage:2,when:Hs}];Is(qe);function dt(o){return o<1e3?`${Math.round(o)}m`:`${(o/1e3).toFixed(1)}km`}function mt({hash:o,contact:l,isHub:g,isNeighbor:u,distance:j,centrality:N,neighborSignal:c,collisionInfo:T,isViterbiResolved:$,pingingHash:w,pingResult:p,pingError:C,isMobile:D,metaSummary:B,metaTooltip:A,onRowClick:q,onPing:S,onRemove:P}){Fs(qe);const _=l.latitude&&l.longitude&&l.latitude!==0&&l.longitude!==0,H=l.node_name||l.name||"Unknown",I=u&&c,se=ke(l),{isRepeater:v,isCompanion:G,isRoomServer:R,isClient:Q,label:b}=se,te=u?`${b} — Direct RF contact (zero-hop neighbor)`:`${b} — Flood routing (multi-hop via mesh)`,ae=n.useCallback(()=>q(o),[q,o]);return e.jsxs("div",{className:`contacts-grid-row ${g?"bg-sys-amber/5 border-l-2 border-l-sys-amber":""} ${_?"cursor-pointer":""}`,onClick:ae,children:[e.jsxs("div",{className:"contacts-col-node flex items-center gap-2 min-w-0",children:[I&&(c==null?void 0:c.avgSnr)!==null?e.jsx("div",{className:`w-2 h-2 rounded-full flex-shrink-0 self-center ${ls(c.avgSnr)}`}):e.jsx("div",{className:"w-2 flex-shrink-0"}),e.jsx("div",{className:"w-6 h-6 flex items-center justify-center flex-shrink-0",title:te,children:(()=>{if(R&&v)return e.jsxs("div",{className:"relative w-5 h-5",children:[e.jsx(me,{className:"w-5 h-5 absolute inset-0 text-sys-pink"}),e.jsx(Us,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-sys-teal"})]});if(R)return e.jsx(me,{className:"w-5 h-5 text-sys-pink"});if(v)return e.jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center ring-[1.5px] ring-sys-blue",children:e.jsx(de,{className:"w-3.5 h-3.5 text-sys-blue"})});if((G||Q)&&H!=="Unknown"){const{emoji:F,cleanName:ue}=Os(H);return e.jsx("div",{className:"w-6 h-6 clay-avatar",style:{"--avatar-color":zs(ue)},children:F?e.jsx("span",{className:"text-sm leading-none",children:F}):e.jsx("span",{className:"text-white text-[9px] font-bold tracking-tighter",children:Ds(H)})})}return e.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center bg-zinc-500/20",children:e.jsx(De,{className:"w-3.5 h-3.5 text-sys-amber"})})})()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 overflow-hidden",children:[e.jsx("span",{className:"roster-title truncate",title:H,children:H}),u&&e.jsx("span",{className:"contact-tag contact-tag--nbr",children:"NBR"}),g&&e.jsx("span",{className:"contact-tag contact-tag--hub",children:"HUB"}),v&&e.jsx("span",{className:"contact-tag contact-tag--rpt",children:"RPT"}),R&&e.jsx("span",{className:"contact-tag contact-tag--room",children:"ROOM"}),G&&e.jsx("span",{className:"contact-tag contact-tag--comp",children:"COMP"}),Q&&e.jsx("span",{className:"contact-tag contact-tag--client",children:"CLIENT"}),D&&e.jsx("span",{className:"contact-tag contact-tag--mobile",children:"MOB"}),!_&&e.jsx(Ws,{className:"w-3 h-3 flex-shrink-0 text-fg-muted/50"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx(ds,{copy:!0,size:"compact",truncate:[8,6],children:o}),e.jsx(lt,{hash:o,collisionInfo:T,isViterbiResolved:$}),B&&e.jsx("span",{className:"contact-meta",title:A,children:B})]})]})]}),e.jsxs("div",{className:"contacts-col-signal flex items-center justify-end gap-2",children:[I&&(c==null?void 0:c.avgRssi)!==null&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Bs,{rssi:c.avgRssi,className:"w-3.5 h-3.5"}),e.jsx("span",{className:"type-data-xs text-fg-muted",children:Math.round(c.avgRssi)})]}),I&&(c==null?void 0:c.avgSnr)!==null&&e.jsxs("span",{className:"type-data-xs text-fg-muted",children:[c.avgSnr.toFixed(1)," dB"]})]}),e.jsx("div",{className:"contacts-col-distance flex items-center justify-end gap-1 text-fg-muted",children:j!=null&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"w-3 h-3"}),e.jsx("span",{className:"type-data-xs",children:dt(j)})]})}),e.jsx("div",{className:"contacts-col-centrality flex items-center justify-end gap-1",children:N>0&&e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"w-3 h-3 text-sys-indigo"}),e.jsxs("span",{className:"type-data-xs text-fg-muted",children:[(N*100).toFixed(0),"%"]})]})}),e.jsx("div",{className:"contacts-col-seen flex items-center justify-end",children:e.jsx("span",{className:"type-data-xs text-fg-primary whitespace-nowrap",children:l.last_seen?Oe(l.last_seen):"—"})}),e.jsxs("div",{className:"contacts-col-actions flex items-center justify-end gap-1",children:[u&&e.jsx(e.Fragment,{children:p?e.jsxs("div",{className:`flex items-center gap-1 ${ye(p)?"text-sys-green":"text-fg-muted"}`,title:`RTT: ${p.rtt_ms.toFixed(0)}ms${ye(p)?` · SNR: ${p.snr_db.toFixed(1)}dB · RSSI: ${p.rssi}dBm`:""}`,children:[e.jsx(Ce,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"type-data-xs hidden sm:inline",children:ye(p)?`${p.snr_db.toFixed(1)}dB`:`${(p.rtt_ms/1e3).toFixed(1)}s`})]}):C?e.jsxs("span",{className:"text-sys-red text-xs font-medium",title:C,children:[e.jsx("span",{className:"hidden sm:inline",children:C}),e.jsx("span",{className:"sm:hidden",children:"✗"})]}):e.jsx("button",{onClick:F=>S(o,F),disabled:w!==null,className:"p-1 sm:p-1.5 radius-inner text-fg-muted/50 hover:text-sys-blue hover:bg-sys-blue/10 transition-base disabled:opacity-50 disabled:cursor-not-allowed",title:"Ping neighbor for updated signal info",children:w===o?e.jsx(ze,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4 animate-spin"}):e.jsx(Vs,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})}),e.jsx("button",{onClick:F=>{F.stopPropagation(),P(o,H)},className:"p-1 sm:p-1.5 radius-inner text-fg-muted/50 hover:text-sys-red hover:bg-sys-red/10 transition-base",title:"Remove contact",children:e.jsx(Gs,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})]})]})}const xt=n.memo(mt),ut=6371e3,pt=[{field:"lastHeard",icon:Zs,label:"Recent"},{field:"distance",icon:Ae,label:"Distance"},{field:"centrality",icon:Be,label:"Centrality"}];function ht(o){switch(o){case"room_server":return"room";case"repeater":return"repeater";case"companion":return"companion";case"unknown":return"companion"}}function ft(o){const l=ke(o);return ht(l.type)}function ve(o,l){const{color:g="primary",border:u=!1}=l??{};return we("flex items-center gap-1.5 px-2 py-1.5 text-sm radius-inner transition-base",o?g==="success"?"bg-sys-green/20 text-sys-green":"bg-sys-blue/20 text-sys-blue":"text-fg-muted hover:text-fg-secondary hover-bg",u&&(o?g==="success"?"border border-sys-green/30":"border border-sys-blue/30":"border border-transparent"))}function gt(o,l,g,u){const j=(g-o)*Math.PI/180,N=(u-l)*Math.PI/180,c=Math.sin(j/2)*Math.sin(j/2)+Math.cos(o*Math.PI/180)*Math.cos(g*Math.PI/180)*Math.sin(N/2)*Math.sin(N/2),T=2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c));return ut*T}function jt(){var Le,Te;const{stats:o}=ms(),l=xs(),g=us(),u=ps(),j=hs(),N=fs(),c=gs(),T=js(),$=bs(),w=ys(),p=Ne[$],C=He(),D=Ie(),B=Ns(),A=D.totalPaths>0&&D.avgPathConfidence>=.7,q=n.useMemo(()=>{const s=new Map;for(const a of C)s.set(a.prefix,a);return s},[C]),[S,P]=n.useState(null),[_,H]=n.useState("lastHeard"),[I,se]=n.useState("desc"),[v,G]=n.useState(""),[R,Q]=n.useState(!1),[b,te]=n.useState(new Set),[ae,F]=n.useState(!1),[ue,Me]=n.useState(null),[pe,Se]=n.useState(null),[Ve,he]=n.useState(new Map),[Ue,X]=n.useState(new Map),[k,We]=n.useState(25),[V,ne]=n.useState(25),fe=n.useRef(null),Y=n.useMemo(()=>(o==null?void 0:o.neighbors)??{},[o==null?void 0:o.neighbors]),ge=Ps(),re=n.useMemo(()=>{if(ge.size===0)return Y;const s=new Set;for(const t of Object.keys(Y))s.add((t.startsWith("0x")?t.slice(2):t).toLowerCase());let a=null;for(const[t,r]of ge){const i=(t.startsWith("0x")?t.slice(2):t).toLowerCase();s.has(i)||(a||(a={...Y}),a[t]={last_seen:r.lastSeen,name:r.name??void 0,node_name:r.name??void 0,latitude:r.latitude,longitude:r.longitude,is_repeater:r.nodeType==="repeater",contact_type:r.nodeType==="repeater"?"Repeater":r.nodeType==="companion"?"Companion":r.nodeType==="room_server"?"Room Server":void 0})}return a??Y},[Y,ge]),O=n.useMemo(()=>{const a=Date.now()/1e3-p.minutes*60;return Object.fromEntries(Object.entries(re).filter(([t,r])=>l.has(t)?!1:(r.last_seen??0)>=a))},[re,l,p.minutes]),L=vs(),z=o==null?void 0:o.local_hash,Ge=n.useMemo(()=>{const s=new Map;if(!z||c.size===0)return s;for(const[a,t]of c)if(a.endsWith(`→${z}`)&&t.hops.length>1){const r=a.split("→")[0],i=t.hops[t.hops.length-1];s.set(r,i)}return s},[c,z]),Qe=n.useMemo(()=>{const s=new Map;if(!z||c.size===0)return s;const a=new Map;for(const[t,r]of Object.entries(re)){const i=(t.startsWith("0x")?t.slice(2):t).toLowerCase();a.set(i,r)}for(const[t,r]of c){if(!t.endsWith(`→${z}`)||r.hops.length===0)continue;const i=t.split("→")[0],d=r.hops[0];let h=null;for(const[f,y]of a)if(f.startsWith(d.toLowerCase())){h=y.node_name??y.name??null;break}s.set(i,{prefix:d,name:h,hopCount:r.hopCount})}return s},[c,z,re]),oe=n.useMemo(()=>{const s=new Map;if(!(L!=null&&L.latitude)||!(L!=null&&L.longitude))return s;for(const[a,t]of Object.entries(O))t.latitude&&t.longitude&&t.latitude!==0&&t.longitude!==0?s.set(a,gt(L.latitude,L.longitude,t.latitude,t.longitude)):s.set(a,null);return s},[O,L]),{neighborHashSet:ce,neighborSignalMap:Xe}=n.useMemo(()=>{const s=new Set,a=new Map;for(const t of N)s.add(t.hash),a.set(t.hash,{avgRssi:t.avgRssi,avgSnr:t.avgSnr});return{neighborHashSet:s,neighborSignalMap:a}},[N]),Pe=n.useMemo(()=>{const s=v.toLowerCase().trim(),a=s==="neighbor"||s==="neighbors",t=R||a,r=b.size>0;return Object.fromEntries(Object.entries(O).filter(([i,d])=>{if(r){const y=ft(d);if(!b.has(y))return!1}if(t&&!ce.has(i))return!1;if(a||!s)return!0;const h=(d.node_name||d.name||"").toLowerCase(),f=W(i).toLowerCase();return h.includes(s)||f.includes(s)||i.toLowerCase().includes(s)}))},[O,v,R,ce,b]),x=n.useMemo(()=>{const s=Object.entries(Pe),a=v.toLowerCase().trim(),t=/^[0-9a-f]{2}(?:[0-9a-f]{2}){0,2}$/i.test(a);return s.sort(([r,i],[d,h])=>{if(t){const y=W(r).toLowerCase(),E=W(d).toLowerCase(),M=y===a,U=E===a;if(M&&!U)return-1;if(U&&!M)return 1}let f=0;switch(_){case"lastHeard":f=(i.last_seen||0)-(h.last_seen||0);break;case"distance":{const y=oe.get(r)??null,E=oe.get(d)??null;y===null&&E===null?f=0:y===null?f=1:E===null?f=-1:f=y-E;break}case"centrality":{const y=j.get(r)||0,E=j.get(d)||0;f=y-E;break}}return I==="desc"?-f:f})},[Pe,_,I,oe,j,v]),m=n.useMemo(()=>{let s=0,a=0,t=0,r=0,i=0;for(const[,d]of x){const h=ke(d),f=d.latitude&&d.longitude&&d.latitude!==0&&d.longitude!==0;switch(h.type){case"room_server":t++;break;case"repeater":a++;break;case"companion":s++;break;case"unknown":i++;break}f&&r++}return{companions:s,repeaters:a,roomServers:t,total:x.length,withLocation:r,unknown:i}},[x]),Ye=n.useMemo(()=>new Set(u),[u]),_e=n.useMemo(()=>k===0?x:x.slice(0,V),[x,V,k]);n.useEffect(()=>{ne(k||x.length)},[_,I,v,R,b,k,x.length]),n.useEffect(()=>{const s=a=>{a.target.closest("[data-dropdown]")||F(!1)};return document.addEventListener("click",s),()=>document.removeEventListener("click",s)},[]),n.useEffect(()=>{if(k===0)return;const s=new IntersectionObserver(a=>{a[0].isIntersecting&&VMath.min(t+k,x.length))},{threshold:.1,rootMargin:"100px"});return fe.current&&s.observe(fe.current),()=>s.disconnect()},[k,V,x.length]);const Ze=n.useCallback(s=>{We(s),ne(s||x.length)},[x.length]),Je=n.useCallback(s=>{_===s?se(a=>a==="desc"?"asc":"desc"):(H(s),se("desc"))},[_]),Ke=n.useCallback(s=>{const a=O[s];a!=null&&a.latitude&&(a!=null&&a.longitude)&&a.latitude!==0&&a.longitude!==0&&Me(s)},[O]),es=n.useCallback(()=>{Me(null)},[]),ss=n.useCallback((s,a)=>{P({hash:s,name:a})},[]),Re=ws((Te=(Le=o==null?void 0:o.config)==null?void 0:Le.mesh)==null?void 0:Te.path_hash_mode),ts=n.useCallback(async(s,a)=>{if(a.stopPropagation(),!pe){Se(s),he(t=>{const r=new Map(t);return r.delete(s),r}),X(t=>{const r=new Map(t);return r.delete(s),r});try{const r=`0x${W(s,Re)}`,i=await Cs(r,30);i.success&&i.data?(he(d=>new Map(d).set(s,i.data)),setTimeout(()=>{he(d=>{const h=new Map(d);return h.delete(s),h})},1e4)):(X(d=>new Map(d).set(s,i.error||"Ping failed")),setTimeout(()=>{X(d=>{const h=new Map(d);return h.delete(s),h})},5e3))}catch(t){const r=t instanceof Error?t.message:"Ping failed";X(i=>new Map(i).set(s,r)),setTimeout(()=>{X(i=>{const d=new Map(i);return d.delete(s),d})},5e3)}finally{Se(null)}}},[pe,Re]);return e.jsxs(_s,{children:[e.jsx(Rs,{title:"Contacts",icon:e.jsx(ee,{}),subtitle:e.jsx($s,{}),controls:e.jsxs("div",{className:"flex items-center gap-3 sm:gap-5",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Total:"}),e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:`${m.total} discovered node${m.total!==1?"s":""} on the mesh network`,children:[e.jsx(ee,{className:"w-3.5 h-3.5 text-fg-secondary"}),e.jsx("span",{children:m.total})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Types:"}),m.repeaters>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Repeaters",children:[e.jsx(de,{className:"w-3.5 h-3.5 text-sys-blue"}),e.jsx("span",{children:m.repeaters})]}),m.companions>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Companions",children:[e.jsx($e,{className:"w-3.5 h-3.5 text-fg-muted"}),e.jsx("span",{children:m.companions})]}),m.roomServers>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Room Servers",children:[e.jsx(me,{className:"w-3.5 h-3.5 text-sys-pink"}),e.jsx("span",{children:m.roomServers})]}),m.withLocation>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"With GPS location",children:[e.jsx(Xs,{className:"w-3.5 h-3.5 text-sys-green"}),e.jsx("span",{children:m.withLocation})]}),m.unknown>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Unknown type",children:[e.jsx(De,{className:"w-3.5 h-3.5 text-sys-amber"}),e.jsx("span",{children:m.unknown})]})]})]}),e.jsxs("div",{className:"flex sm:hidden items-center gap-1.5",children:[e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(ee,{className:"w-3 h-3 text-fg-secondary"}),e.jsx("span",{children:m.total})]}),m.repeaters>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(de,{className:"w-3 h-3 text-sys-blue"}),e.jsx("span",{children:m.repeaters})]}),m.companions>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx($e,{className:"w-3 h-3 text-fg-muted"}),e.jsx("span",{children:m.companions})]}),m.roomServers>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(me,{className:"w-3 h-3 text-sys-pink"}),e.jsx("span",{children:m.roomServers})]}),e.jsx(Fe,{ranges:Ne,selectedIndex:$,onSelect:w,size:"sm"})]}),e.jsx("div",{className:"hidden sm:block",children:e.jsx(Fe,{ranges:Ne,selectedIndex:$,onSelect:w})})]})}),e.jsxs(Ls,{children:[e.jsx(ct,{neighbors:O,localNode:L??void 0,localHash:z,onRemoveNode:g,selectedNodeHash:ue,onNodeSelected:es}),e.jsxs(ks,{noPadding:!0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 px-3 sm:px-4 py-2.5 border-b border-edge-subtle",children:[e.jsx("span",{className:"icon-md flex items-center justify-center text-icon-card-title flex-shrink-0",children:e.jsx(ee,{})}),e.jsx("span",{className:"type-micro flex-shrink-0 mr-auto hidden sm:block",children:"Discovered Contacts"}),e.jsx(Ms,{type:"search",size:"sm",value:v,onChange:s=>G(s.target.value),placeholder:"Search...",leadingIcon:e.jsx(Ys,{className:"w-3.5 h-3.5"}),trailingIcon:v?e.jsx("button",{onClick:()=>{G(""),(v.toLowerCase().trim()==="neighbor"||v.toLowerCase().trim()==="neighbors")&&Q(!1)},className:"text-fg-muted hover:text-fg-secondary",children:e.jsx(Ss,{className:"w-3 h-3"})}):void 0,className:"w-24 sm:w-32 xl:w-44","aria-label":"Search contacts"}),e.jsx("div",{className:"h-4 w-px bg-border-subtle flex-shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsxs("div",{className:"relative","data-dropdown":!0,children:[e.jsxs("button",{onClick:()=>F(!ae),className:ve(b.size>0,{border:!0}),title:"Filter by contact type",children:[e.jsx(at,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:"Filter"}),b.size>0&&e.jsx("span",{className:"tabular-nums text-xs bg-sys-blue/30 px-1 rounded",children:b.size})]}),ae&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 surface-elevated radius-inner py-1 min-w-[140px]",children:[[{key:"repeater",label:"Repeaters"},{key:"companion",label:"Companions"},{key:"room",label:"Rooms"}].map(({key:s,label:a})=>e.jsxs("button",{onClick:()=>{te(t=>{const r=new Set(t);return r.has(s)?r.delete(s):r.add(s),r})},className:"w-full px-3 py-1.5 text-sm text-left hover-bg transition-base flex items-center gap-2",children:[e.jsx("span",{className:we("w-4 h-4 flex items-center justify-center radius-badge border",b.has(s)?"bg-sys-blue border-sys-blue text-white":"border-edge-subtle"),children:b.has(s)&&e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("span",{className:b.has(s)?"text-fg-primary":"text-fg-secondary",children:a})]},s)),b.size>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-edge-subtle my-1"}),e.jsx("button",{onClick:()=>te(new Set),className:"w-full px-3 py-1.5 text-sm text-left text-fg-muted hover:text-fg-secondary hover-bg transition-base",children:"Clear filters"})]})]})]}),ce.size>0&&e.jsxs("button",{onClick:()=>Q(!R),className:ve(R,{color:"success",border:!0}),title:R?"Show all contacts":"Show only MeshCore neighbors (direct RF contact)",children:[e.jsx(de,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:"Neighbors"})]})]}),e.jsx("div",{className:"h-4 w-px bg-border-subtle flex-shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[pt.map(({field:s,icon:a,label:t})=>e.jsxs("button",{onClick:()=>Je(s),className:ve(_===s),title:`Sort by ${t.toLowerCase()}`,children:[e.jsx(a,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:t}),_===s&&e.jsx(Ks,{className:we("w-3 h-3",I==="asc"&&"rotate-180")})]},s)),e.jsx("div",{className:"h-4 w-px bg-border-subtle"}),e.jsxs(Ts,{value:k,onChange:Ze,className:"w-auto min-w-[50px] [&_button]:py-1 [&_button]:px-2 [&_button]:text-xs [&_button]:min-h-0","aria-label":"Items per page",children:[e.jsx(le,{value:25,children:"25"}),e.jsx(le,{value:50,children:"50"}),e.jsx(le,{value:100,children:"100"}),e.jsx(le,{value:0,children:"All"})]})]})]}),x.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hidden sm:grid contacts-grid-header border-b border-edge-subtle/50 px-3 py-2 type-micro text-fg-muted",children:[e.jsx("div",{className:"contacts-col-node",children:"Node"}),e.jsx("div",{className:"contacts-col-signal text-right",children:"Signal"}),e.jsx("div",{className:"contacts-col-distance text-right",children:"Distance"}),e.jsx("div",{className:"contacts-col-centrality text-right",children:"Centrality"}),e.jsx("div",{className:"contacts-col-seen text-right",children:"Last Seen"}),e.jsx("div",{className:"contacts-col-actions"})]}),e.jsx("div",{className:"divide-y divide-edge-subtle/30",style:{contain:"layout paint"},children:_e.map(([s,a])=>{const t=W(s),r=Ye.has(s),i=ce.has(s),d=oe.get(s)??null,h=j.get(s)||0,f=i?Xe.get(s):void 0,y=t?q.get(t)??null:null,E=T.has(s),M=i?null:Qe.get(s)??null,U=Ge.get(s)??null,je=B.get(s);let Z=null;if(je&&je.length>0){const ie=je.reduce((rs,os)=>rs+os.count,0);ie>0&&(Z=ie/24)}const be=a.first_seen?Oe(a.first_seen).replace(/ ago$/i,""):null,J=[],K=[];if(M){const ie=M.name??M.prefix;J.push(`→${ie} +${M.hopCount}`),K.push(`Gateway: ${M.name??M.prefix} (${M.hopCount} hop${M.hopCount!==1?"s":""})`)}U&&(J.push(`↙${U}`),K.push(`Last forwarder: ${U}`)),Z!==null&&(J.push(`${Z<1?"<1":Math.round(Z)}/hr`),K.push(`Packet rate: ${Z.toFixed(1)}/hr`)),be&&(J.push(be),K.push(`First seen: ${be} ago`));const as=J.join(" · "),ns=K.join(` -`);return e.jsx(xt,{hash:s,contact:a,isHub:r,isNeighbor:i,distance:d,centrality:h,neighborSignal:f,collisionInfo:y,isViterbiResolved:A,pingingHash:pe,pingResult:Ve.get(s),pingError:Ue.get(s),isMobile:E,metaSummary:as,metaTooltip:ns,onRowClick:Ke,onPing:ts,onRemove:ss},s)})}),k>0&&V0&&Vne(s=>Math.min(s+k,x.length)),className:"text-sys-blue hover:text-sys-blue/80 transition-base",children:"Load more"})]})]}):e.jsxs("div",{className:"roster-empty",children:[e.jsx(ee,{className:"roster-empty-icon"}),e.jsx("div",{className:"type-label text-fg-secondary",children:"No Contacts Discovered"}),e.jsx("div",{className:"type-data-xs text-fg-muted mt-1",children:"Contacts will appear here as they advertise on the mesh network."})]})]})]}),e.jsx(Qs,{isOpen:!!S,title:"Remove Contact",message:`Remove ${(S==null?void 0:S.name)||"this contact"} from the contacts list? The node will reappear if it advertises again.`,confirmLabel:"Remove",cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{S&&g(S.hash),P(null)},onCancel:()=>P(null)})]})}const zt=Object.freeze(Object.defineProperty({__proto__:null,default:jt},Symbol.toStringTag,{value:"Module"}));export{zt as C,lt as P,Ae as R}; diff --git a/frontend/dist/assets/ContactsMapMapLibre-Bb14UZ5D.js b/frontend/dist/assets/ContactsMapMapLibre-Bb14UZ5D.js new file mode 100644 index 00000000..701da10d --- /dev/null +++ b/frontend/dist/assets/ContactsMapMapLibre-Bb14UZ5D.js @@ -0,0 +1,130 @@ +import{e as Mr,an as ka,r as R,gz as Ca,cu as Sa,dp as Ea,dq as Ma,j as p,aC as _o,dr as Ba,aD as To,m as Xt,a0 as Yn,dK as Ro,c as Or,a2 as q0,O as ar,Z as kn,gA as J0,gB as jo,gC as Da,cj as _a,cq as Ta,cs as Ra,dV as Io,ap as Lo,aE as Vs,d as Sr,b as En,B as Nt,dG as ja,cl as ps,E as Ws,S as Ys,dx as No,t as $s,c$ as Fo,aa as Po,bM as Mn,bI as ki,gD as Qo,Q as Ia,a6 as La,dF as Na,gE as Fa,az as Oo,bT as Ci,bV as Pa,a1 as X0,a3 as As,cn as Qa,b9 as Oa,f1 as zo,gF as za,gG as Ha,dH as Ga,dI as Ua,gH as Va,gI as Wa,aR as Ho,V as gt,gJ as Ya,gK as Go,gL as $a,ao as Er,bP as Uo,dw as Ka,gM as Vo,gN as Wo,cb as Za,gx as qa,ce as Ja,du as Yo,dy as Xa,ab as Au,gO as eu,fd as tu,gP as gs,ga as ru,fJ as nu,gQ as su}from"./index-BBBuaCQs.js";import{u as Hr,S as zr,L as Jt,M as iu,b as ou}from"./maplibre-gl-BGrZ3ia8.js";import{u as $o,r as Ko,e as Si,f as Ei,g as lu}from"./consumer-registry-04zc6uvW.js";import{L as V0,c as au}from"./link-scoring-CxJumM6l.js";import{C as uu}from"./ConfirmModal-DGG0Ux0s.js";import{s as cu,a as fu,M as hu}from"./variants-WXnHxSXf.js";import{G as Ds}from"./git-branch-DoAYRXX_.js";import{D as du}from"./database-D4A6B9uV.js";import{H as mu,A as y0,D as Mi,p as pu,c as gu,u as gn}from"./useMapViewStore-KZ-iYEhb.js";import{E as Zo}from"./target-CjK6GJds.js";import{F as yu}from"./funnel-C8NxsG5E.js";import{P as xu}from"./plus-BnP2OnZA.js";import{C as wu}from"./compass-DD46PLB1.js";import{Z as vu}from"./zap-DDG9zYwX.js";import{b as bu,e as ku,a as qo,m as Bi,E as Cu,u as Su,G as Eu,g as Mu,d as Bu,f as Du}from"./max-ju7hW25D.js";import{T as _u}from"./trash-2-DUN81fPu.js";import{W as Tu}from"./wifi-off-NffUdBle.js";import{W as Ru}from"./wifi-752FYPBg.js";import{C as ju}from"./circle-alert-pRjy9QOw.js";import{C as Jo}from"./clock-DV9Z95kG.js";import{C as Iu}from"./chevron-right-DMF-_TsK.js";import{p as Lu}from"./payload-detail-XcpxSMLm.js";import{L as Nu}from"./LightSparkline-Bon5FLNi.js";import{P as Xo,R as Fu}from"./Contacts-DvfgLHt9.js";import{H as $0,C as ur,N as Pu,a as Qu}from"./badge-colors-Dl76Mz8m.js";import{M as Ou}from"./map-pin-stXuybQm.js";import{c as Di}from"./node-types-DJyFsA81.js";import{B as zu}from"./BasemapLayer-hjkVmX-W.js";import{a as Al,b as _s,c as Hu}from"./easing-Bdhj1KpK.js";import"./index-CyH5wAaG.js";import"./index-CQClum6j.js";import"./usePipelineStore-CSy1PGRp.js";import"./PageLayout-CRsVqzTw.js";import"./listbox-iaAoqLDr.js";import"./element-movement-BGm_uaZd.js";import"./use-text-value-2q1EQ-Jk.js";import"./frozen-D91afNsn.js";import"./MqttModeBadge-Bl-vewzA.js";import"./chat-utils-DP6LcfMx.js";import"./SignalIndicator-CkqfZLem.js";import"./CollisionExplorerModal-qV7zoTO2.js";import"./share-2-WwVAp6Bf.js";import"./circle-question-mark-CI9cD3nq.js";import"./map-pin-off-CmyDNImL.js";import"./activity-cShCNfEo.js";import"./search-Dk9GWMDh.js";/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Gu=[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]],Ts=Mr("boxes",Gu);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Uu=[["path",{d:"M9 10h.01",key:"qbtxuw"}],["path",{d:"M15 10h.01",key:"1qmjsl"}],["path",{d:"M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z",key:"uwwb07"}]],el=Mr("ghost",Uu);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Vu=[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]],Wu=Mr("map",Vu);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Yu=[["path",{d:"m8 3 4 8 5-5 5 15H2L8 3z",key:"otkl63"}]],$u=Mr("mountain",Yu);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Ku=[["polygon",{points:"3 11 22 2 13 21 11 13 3 11",key:"1ltx0t"}]],Zu=Mr("navigation",Ku);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const qu=[["path",{d:"M6 8.32a7.43 7.43 0 0 1 0 7.36",key:"9iaqei"}],["path",{d:"M9.46 6.21a11.76 11.76 0 0 1 0 11.58",key:"1yha7l"}],["path",{d:"M12.91 4.1a15.91 15.91 0 0 1 .01 15.8",key:"4iu2gk"}],["path",{d:"M16.37 2a20.16 20.16 0 0 1 0 20",key:"sap9u2"}]],tl=Mr("nfc",qu);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Ju=[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]],Xu=Mr("sigma",Ju);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Ac=[["polyline",{points:"14.5 17.5 3 6 3 3 6 3 17.5 14.5",key:"1hfsw2"}],["line",{x1:"13",x2:"19",y1:"19",y2:"13",key:"1vrmhu"}],["line",{x1:"16",x2:"20",y1:"16",y2:"20",key:"1bron3"}],["line",{x1:"19",x2:"21",y1:"21",y2:"19",key:"13pww6"}],["polyline",{points:"14.5 6.5 18 3 21 3 21 6 17.5 9.5",key:"hbey2j"}],["line",{x1:"5",x2:"9",y1:"14",y2:"18",key:"1hf58s"}],["line",{x1:"7",x2:"4",y1:"17",y2:"20",key:"pidxm4"}],["line",{x1:"3",x2:"5",y1:"19",y2:"21",key:"1pehsh"}]],ec=Mr("swords",Ac);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const tc=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],rc=Mr("trending-down",tc);/** + * @license lucide-react v0.559.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const nc=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],sc=Mr("wrench",nc);function ic(a,u){return u.filter(y=>y.nodes.includes(a)).sort((y,x)=>x.avgCertainCount-y.avgCertainCount)}function oc(a,u,d){const y=ic(a,u),x=new Set,b=[];for(const E of y)for(const F of E.edgeKeys)if(!x.has(F)){x.add(F);const B=d.get(F);b.push({key:F,certainCount:(B==null?void 0:B.certainCount)??0})}return b.sort((E,F)=>F.certainCount-E.certainCount),{loops:y,highlightedEdgeKeys:x,sortedEdges:b}}function lc(a){const u=new Map;for(const d of a)for(const y of d.edgeKeys){const x=u.get(y)??[];x.push(d),u.set(y,x)}return u}const _0={MAX_THICKNESS_AT:300,MIN_VALIDATIONS:5},ac=6,_i=1;function Rs(a,u){const d=Math.max(_0.MIN_VALIDATIONS,Math.min(a,_0.MAX_THICKNESS_AT)),y=Math.log(_0.MIN_VALIDATIONS),x=Math.log(_0.MAX_THICKNESS_AT),E=(Math.log(d)-y)/(x-y);return _i+(ac-_i)*E}const uc=cc(fc);function cc(a){return function(u,d,y=d){if(!((d=+d)>=0))throw new RangeError("invalid rx");if(!((y=+y)>=0))throw new RangeError("invalid ry");let{data:x,width:b,height:E}=u;if(!((b=Math.floor(b))>=0))throw new RangeError("invalid width");if(!((E=Math.floor(E!==void 0?E:x.length/b))>=0))throw new RangeError("invalid height");if(!b||!E||!d&&!y)return u;const F=d&&a(d),B=y&&a(y),k=x.slice();return F&&B?(Qn(F,k,x,b,E),Qn(F,x,k,b,E),Qn(F,k,x,b,E),On(B,x,k,b,E),On(B,k,x,b,E),On(B,x,k,b,E)):F?(Qn(F,x,k,b,E),Qn(F,k,x,b,E),Qn(F,x,k,b,E)):B&&(On(B,x,k,b,E),On(B,k,x,b,E),On(B,x,k,b,E)),u}}function Qn(a,u,d,y,x){for(let b=0,E=y*x;b{if(!((F-=B)>=E))return;let k=u*b[E];const j=B*u,Q=j+B;for(let z=E,Y=E+j;z{if(!((b-=E)>=x))return;let F=a*y[x];const B=E*a;for(let k=x,j=x+B;k=y&&++d;return d}function mc(a,u,d){let y;for(;;){const x=bu(a,u,d);if(x===y||x===0||!isFinite(x))return[a,u];x>0?(a=Math.floor(a/x)*x,u=Math.ceil(u/x)*x):x<0&&(a=Math.ceil(a*x)/x,u=Math.floor(u*x)/x),y=x}}function pc(a){return Math.max(1,Math.ceil(Math.log(dc(a))/Math.LN2)+1)}var gc=Array.prototype,rl=gc.slice;function yc(a,u){return a-u}function xc(a){for(var u=0,d=a.length,y=a[d-1][1]*a[0][0]-a[d-1][0]*a[0][1];++u()=>a;function wc(a,u){for(var d=-1,y=u.length,x;++dy!=Y>y&&d<(z-k)*(y-j)/(Y-j)+k&&(x=-x)}return x}function bc(a,u,d){var y;return kc(a,u,d)&&Cc(a[y=+(a[0]===u[0])],d[y],u[y])}function kc(a,u,d){return(u[0]-a[0])*(d[1]-a[1])===(d[0]-a[0])*(u[1]-a[1])}function Cc(a,u,d){return a<=u&&u<=d||d<=u&&u<=a}function Sc(){}var Qr=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function Ti(){var a=1,u=1,d=pc,y=B;function x(k){var j=d(k);if(Array.isArray(j))j=j.slice().sort(yc);else{const Q=ku(k,Ec);for(j=qo(...mc(Q[0],Q[1],j),j);j[j.length-1]>=Q[1];)j.pop();for(;j[1]b(k,Q))}function b(k,j){const Q=j==null?NaN:+j;if(isNaN(Q))throw new Error(`invalid value: ${j}`);var z=[],Y=[];return E(k,Q,function(U){y(U,k,Q),xc(U)>0?z.push([U]):Y.push(U)}),Y.forEach(function(U){for(var q=0,sA=z.length,X;q=j,Qr[K<<2].forEach(uA);++U0&&Y0&&U=0&&Q>=0))throw new Error("invalid size");return a=j,u=Q,x},x.thresholds=function(k){return arguments.length?(d=typeof k=="function"?k:Array.isArray(k)?sn(rl.call(k)):sn(k),x):d},x.smooth=function(k){return arguments.length?(y=k?B:Sc,x):y===B},x}function Ec(a){return isFinite(a)?a:NaN}function yn(a,u){return a==null?!1:+a>=u}function ys(a){return a==null||isNaN(a=+a)?-1/0:a}function Ri(a,u,d,y){const x=y-u,b=d-u,E=isFinite(x)||isFinite(b)?x/b:Math.sign(x)/Math.sign(b);return isNaN(E)?a:a+E-.5}function Mc(a){return a[0]}function Bc(a){return a[1]}function Dc(){return 1}function _c(){var a=Mc,u=Bc,d=Dc,y=960,x=500,b=20,E=2,F=b*3,B=y+F*2>>E,k=x+F*2>>E,j=sn(20);function Q(K){var oA=new Float32Array(B*k),uA=Math.pow(2,-E),kA=-1;for(const LA of K){var lA=(a(LA,++kA,K)+F)*uA,aA=(u(LA,kA,K)+F)*uA,BA=+d(LA,kA,K);if(BA&&lA>=0&&lA=0&&aAlA*kA))(oA).map((lA,aA)=>(lA.value=+uA[aA],Y(lA)))}z.contours=function(K){var oA=Q(K),uA=Ti().size([B,k]),kA=Math.pow(2,2*E),lA=aA=>{aA=+aA;var BA=Y(uA.contour(oA,aA*kA));return BA.value=aA,BA};return Object.defineProperty(lA,"max",{get:()=>Bi(oA)/kA}),lA};function Y(K){return K.coordinates.forEach(U),K}function U(K){K.forEach(q)}function q(K){K.forEach(sA)}function sA(K){K[0]=K[0]*Math.pow(2,E)-F,K[1]=K[1]*Math.pow(2,E)-F}function X(){return F=b*3,B=y+F*2>>E,k=x+F*2>>E,z}return z.x=function(K){return arguments.length?(a=typeof K=="function"?K:sn(+K),z):a},z.y=function(K){return arguments.length?(u=typeof K=="function"?K:sn(+K),z):u},z.weight=function(K){return arguments.length?(d=typeof K=="function"?K:sn(+K),z):d},z.size=function(K){if(!arguments.length)return[y,x];var oA=+K[0],uA=+K[1];if(!(oA>=0&&uA>=0))throw new Error("invalid size");return y=oA,x=uA,X()},z.cellSize=function(K){if(!arguments.length)return 1<=1))throw new Error("invalid cell size");return E=Math.floor(Math.log(K)/Math.LN2),X()},z.thresholds=function(K){return arguments.length?(j=typeof K=="function"?K:Array.isArray(K)?sn(rl.call(K)):sn(K),z):j},z.bandwidth=function(K){if(!arguments.length)return Math.sqrt(b*(b+1));if(!((K=+K)>=0))throw new Error("invalid bandwidth");return b=(Math.sqrt(4*K*K+1)-1)/2,X()},z}function js(){const a=ka();return R.useMemo(()=>Ca.getPackets(),[a])}function T0({label:a,icon:u,status:d,detail:y}){return p.jsxs("div",{className:Or("flex items-center gap-3 py-3 px-4 radius-inset transition-base",d==="active"&&"bg-sys-blue/10",d==="complete"&&"bg-sys-blue/10 ring-2 ring-inset ring-sys-blue",d==="pending"&&"opacity-40"),children:[p.jsx("div",{className:Or("w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 transition-all duration-300",d==="active"&&"bg-sys-blue/20",d==="complete"&&"bg-sys-blue/20",d==="pending"&&"bg-subtle-fill"),children:d==="complete"?p.jsx(Yn,{className:"w-4 h-4 text-sys-blue"}):d==="active"?p.jsx(q0,{className:"w-4 h-4 animate-spin text-sys-blue"}):p.jsx("span",{className:"text-fg-muted",children:u})}),p.jsxs("div",{className:"flex-1 min-w-0",children:[p.jsx("div",{className:Or("text-sm font-medium transition-colors",d==="active"&&"text-sys-blue",d==="complete"&&"text-sys-blue",d==="pending"&&"text-fg-muted"),children:a}),y&&d!=="pending"&&p.jsx("div",{className:"text-xs text-fg-muted mt-0.5 truncate",children:y})]})]})}function Tc({isOpen:a,onClose:u}){const{packetCacheState:d,triggerDeepAnalysis:y}=Sa(),x=Ea(),b=Ma(),E=d.packetCount,[F,B]=R.useState("fetching");R.useEffect(()=>{a&&y()},[a,y]),R.useEffect(()=>{if(a){if(d.isTopologyLoading)B("fetching");else if(x)B("analyzing"),setTimeout(()=>B("building"),500),setTimeout(()=>B("discovering"),1e3);else if(b>0&&!d.isTopologyLoading){B("complete");const U=setTimeout(()=>{u()},1500);return()=>clearTimeout(U)}}},[a,d.isTopologyLoading,x,b,u]);const k=F==="complete",j=d.loadProgress,Q=R.useMemo(()=>{if(j&&j.target>0){const U=(j.loaded/1e3).toFixed(1),q=(j.target/1e3).toFixed(1);return`Loading... ${U}k / ${q}k packets (${j.percent}%)`}return E>0?`${E.toLocaleString()} packets loaded`:"Connecting to database..."},[j,E]),z=U=>{const q=["fetching","analyzing","building","discovering","complete"],sA=q.indexOf(F),X=q.indexOf(U);return X{};return p.jsx(_o,{open:a,onClose:Y,size:"sm",bottomSheet:!1,children:p.jsx(Ba,{isLoading:!k,borderRadius:16,children:p.jsx(To,{className:"p-6 radius-card overflow-hidden",children:k?p.jsxs("div",{className:"flex flex-col items-center py-6",children:[p.jsx(Xt.div,{variants:cu,initial:"hidden",animate:"visible",className:"w-16 h-16 rounded-full flex items-center justify-center mb-4 bg-sys-blue/20",children:p.jsx(Yn,{className:"w-8 h-8 text-sys-blue"})}),p.jsx("h3",{className:"type-micro text-sys-blue",children:"Ready!"}),p.jsx("button",{onClick:u,className:"mt-3 sm:hidden min-h-[44px] min-w-[44px] px-4 flex items-center justify-center text-[15px] font-medium text-sys-blue active:text-sys-blue/70 transition-base radius-inner active:bg-subtle-fill",children:"Done"})]}):p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"flex items-center gap-3 mb-5",children:[p.jsx("div",{className:"w-10 h-10 radius-inset flex items-center justify-center bg-sys-blue/15",children:p.jsx(Ds,{className:"w-5 h-5 text-sys-blue"})}),p.jsxs("div",{children:[p.jsx("h3",{className:"type-micro",children:"Deep Analysis"}),p.jsx("p",{className:"text-xs text-fg-muted",children:"Building mesh topology"})]})]}),p.jsxs("div",{className:"space-y-2",children:[p.jsx(T0,{label:"Fetching Packets",icon:p.jsx(Ro,{className:"w-4 h-4"}),status:z("fetching"),detail:Q}),p.jsx(T0,{label:"Analyzing Database",icon:p.jsx(du,{className:"w-4 h-4"}),status:z("analyzing"),detail:"Processing packet paths"}),p.jsx(T0,{label:"Building Topology",icon:p.jsx(Ds,{className:"w-4 h-4"}),status:z("building"),detail:"Computing mesh edges"}),p.jsx(T0,{label:"Discovering Nodes",icon:p.jsx(el,{className:"w-4 h-4"}),status:z("discovering"),detail:"Viterbi HMM ghost detection"})]}),p.jsx("p",{className:"text-xs text-fg-muted text-center mt-5",children:"This may take a few seconds..."})]})})})})}const Rc=R.memo(Tc),nl=16,Is=24,jc=nl,Ic=5,Cn={nodeFill:ar.blue,nodeStroke:"rgba(255,255,255,0.9)",nodeColor:ar.indigo,localColor:ar.amber,hubColor:ar.purple,gatewayColor:ar.indigo,mobileColor:ar.orange,roomServerColor:ar.pink,neighborColor:ar.amber,edges:{rest:kn[700],restBright:kn[600],restDim:kn[800],hoverDirect:"#6FBCBD",hoverLoop:"#8B7BAD",hoverStandard:kn[400],hoverNeighbor:ar.amber,neighborRest:kn[500],neighborHover:ar.amber,highlight:"#FFD700"},edgeOpacity:.82};function Ks(){if(typeof window>"u")return Cn;const a=J0(),u=jo();return{nodeFill:a.nodeFill,nodeStroke:a.nodeStroke,nodeColor:Cn.nodeColor,localColor:a.localColor,hubColor:a.hubColor,gatewayColor:a.gatewayColor,mobileColor:a.mobileColor,roomServerColor:a.roomColor,neighborColor:a.neighborColor,edges:{rest:u.rest,restBright:u.restBright,restDim:u.restDim,hoverDirect:u.hoverDirect,hoverLoop:u.hoverLoop,hoverStandard:u.hoverStandard,hoverNeighbor:u.hoverNeighbor,neighborRest:Cn.edges.neighborRest,neighborHover:Cn.edges.neighborHover,highlight:u.highlight},edgeOpacity:Cn.edgeOpacity}}const R0=2e3,j0=750,Lc="#00FF00",Nc=500,ji=500,Ii=250,Fc=150,sl=200,Pc=En.snappy;function zn({color:a,ring:u}){const d=jc-2;return p.jsx("span",{className:"shrink-0 rounded-full","aria-hidden":"true",style:{width:d,height:d,backgroundColor:u?"transparent":a,border:u?`${Ic-1}px solid ${a}`:void 0,boxSizing:"border-box"}})}function xs({color:a,pattern:u="solid"}){return p.jsx("svg",{className:"shrink-0","aria-hidden":"true",width:18,height:6,viewBox:"0 0 18 6",children:p.jsx("line",{x1:0,y1:3,x2:18,y2:3,stroke:a,strokeWidth:3,strokeLinecap:"round",strokeDasharray:u==="dashed"?"5,3":u==="dotted"?"2,3":void 0})})}function lr({indicator:a,label:u,tooltip:d}){return p.jsxs("div",{className:"flex items-center gap-1.5",children:[a,p.jsx("span",{className:"text-fg-secondary",children:u}),d&&p.jsx(Lo,{content:d,delay:sl,children:p.jsx("span",{className:"cursor-help text-[11px] text-fg-muted opacity-75 hover:opacity-100 transition-opacity",children:"ⓘ"})})]})}function Qc(a){return`legend-section-${a.toLowerCase().replace(/\s+/g,"-")}`}function ws({title:a,tooltip:u,isOpen:d,onToggle:y,showDivider:x,children:b}){const E=Qc(a);return p.jsxs("div",{className:x?"mt-2 pt-2 border-t border-edge-subtle":"",children:[p.jsxs("button",{type:"button",onClick:y,"aria-expanded":d,"aria-controls":E,className:"group w-full flex items-center justify-between py-1 min-h-[44px] sm:min-h-0 font-medium text-fg-secondary hover:text-fg-primary transition-colors",children:[p.jsxs("span",{className:"flex items-center gap-1",children:[a,p.jsx(Lo,{content:u,delay:sl,children:p.jsx("span",{className:"cursor-help text-[11px] text-fg-muted opacity-75 group-hover:opacity-100 transition-opacity",children:"ⓘ"})})]}),p.jsx(Xt.span,{animate:{rotate:d?0:-90},transition:{duration:.15},"aria-hidden":"true",children:p.jsx(Vs,{className:"w-3 h-3 text-fg-muted"})})]}),p.jsx(Sr,{initial:!1,children:d&&p.jsx(Xt.div,{id:E,role:"region","aria-label":a,initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:Pc,className:"overflow-hidden",children:p.jsx("div",{className:"flex flex-col gap-1 pt-1.5",children:b})})})]})}function Li({label:a,value:u,color:d}){return p.jsxs("div",{className:"flex justify-between tabular-nums text-fg-muted",children:[p.jsx("span",{children:a}),p.jsx("span",{className:d?"":"text-fg-secondary",style:d?{color:d}:void 0,children:u})]})}function Ni({icon:a,color:u,title:d,subtitle:y}){return p.jsx("div",{className:"mt-1.5 pt-1.5 border-t border-edge-subtle",children:p.jsxs("div",{className:"flex items-center gap-1.5",children:[p.jsx("span",{className:"shrink-0",style:{color:u},children:a}),p.jsxs("div",{className:"flex flex-col min-w-0",children:[p.jsx("span",{className:"font-medium truncate",style:{color:u},children:d}),p.jsx("span",{className:"text-[10px] leading-tight text-fg-muted",children:y})]})]})})}function Oc(a){return a.some(([,u])=>{var y;const d=(y=u.contact_type)==null?void 0:y.toLowerCase();return d==="room server"||d==="room_server"||d==="room"||d==="server"})}function zc(a){let u=0;for(const d of a.txDelayRecommendations.values())d.networkRole==="backbone"&&u++;return u}function Hc({showTopology:a,validatedPolylineCount:u,filteredNeighborCount:d,hasLocalNode:y,meshTopology:x,zeroHopNeighbors:b,neighborsWithLocation:E,basemapMode:F="dark"}){const B=Da(),k=_a(),j=Ta(),Q=k.filter(uA=>uA.isLikelyReal).length,z=zc(x),Y=b.size>0,[U,q]=R.useState(!0),[sA,X]=R.useState(!0),[K,oA]=R.useState(!0);return p.jsxs("div",{className:"map-control-surface p-2.5 text-xs",children:[p.jsxs(ws,{title:"Nodes",tooltip:"Node type shown by shape + color. Yellow = direct RF neighbor.",isOpen:U,onToggle:()=>q(uA=>!uA),children:[p.jsx(lr,{indicator:p.jsx(zn,{color:B.nodeFill}),label:"Node",tooltip:"Standard mesh node. Repeater, client, or companion device."}),p.jsx(lr,{indicator:p.jsx(zn,{color:B.hubColor}),label:"Hub",tooltip:"Network hub (≥10% of last-hop traffic)."}),Oc(E)&&p.jsx(lr,{indicator:p.jsx(Ra,{className:"w-3 h-3 shrink-0",style:{color:B.roomColor},strokeWidth:2.5}),label:"Room",tooltip:"Room Server identity for client sync."}),p.jsx(lr,{indicator:p.jsx(mu,{className:"w-3 h-3 shrink-0",style:{color:B.localColor},strokeWidth:2.5}),label:"Local",tooltip:"Your repeater running pyMC_Repeater."}),Y&&p.jsx(lr,{indicator:p.jsx(zn,{color:B.neighborColor}),label:"Neighbor",tooltip:"Zero-hop direct RF contact."}),x.gatewayNodes.length>0&&p.jsx(lr,{indicator:p.jsx(zn,{color:B.gatewayColor}),label:"Gateway",tooltip:"Significant forwarder (7-10% traffic)."}),z>0&&p.jsx(lr,{indicator:p.jsx(zn,{color:B.hubColor}),label:"Backbone",tooltip:"Critical relay with high centrality."}),x.mobileNodes.length>0&&p.jsx(lr,{indicator:p.jsx(zn,{color:B.mobileColor,ring:!0}),label:"Mobile",tooltip:"Volatile node that appears/disappears."}),Q>0&&p.jsx(lr,{indicator:p.jsx(el,{className:"w-3 h-3 shrink-0",style:{color:B.ghostColor},strokeWidth:2.5}),label:`Ghost (${Q})`,tooltip:"Unknown repeater from Viterbi analysis."})]}),Y&&p.jsxs(ws,{title:"Link Quality",tooltip:"Neighbor edge colors based on bidirectional balance.",isOpen:sA,onToggle:()=>X(uA=>!uA),showDivider:!0,children:[p.jsx(lr,{indicator:p.jsx(xs,{color:V0.YELLOW,pattern:"solid"}),label:"2-Way",tooltip:"33-67% balanced. Ideal bidirectional link."}),p.jsx(lr,{indicator:p.jsx(xs,{color:V0.GREEN,pattern:"dashed"}),label:"Listener",tooltip:">67% listener. They hear us well."}),p.jsx(lr,{indicator:p.jsx(xs,{color:V0.RED,pattern:"dotted"}),label:"Loud",tooltip:"<33% listener. They route more to us."})]}),a&&u>0&&p.jsxs(ws,{title:"Topology",tooltip:"Links with 5+ validations. Thickness = strength.",isOpen:K,onToggle:()=>oA(uA=>!uA),showDivider:!0,children:[p.jsx(Li,{label:"Nodes",value:d+(y?1:0)}),x.hubNodes.length>0&&p.jsx(Li,{label:"Hubs",value:x.hubNodes.length,color:Cn.hubColor}),x.loops.length>0&&p.jsx(Ni,{icon:p.jsx(Io,{className:"w-3 h-3"}),color:Cn.edges.hoverLoop,title:`${x.loops.length} ${x.loops.length===1?"Loop":"Loops"}`,subtitle:"Redundant paths"}),j.totalPaths>0&&p.jsx(Ni,{icon:p.jsx(Zo,{className:"w-3 h-3"}),color:B.ghostColor,title:`${j.totalPaths.toLocaleString()} Viterbi`,subtitle:"HMM decoded paths"})]})]})}const Fi={repeater:"blue",companion:"cyan",room_server:"pink",hubs:"indigo",direct:"green"},I0={repeater:"Repeaters",companion:"Companions",room_server:"Rooms",hubs:"Hubs",direct:"Direct"},Pi={repeater:"Repeater nodes (mesh relays)",companion:"Companion devices (clients)",room_server:"Room server nodes",hubs:"Hub nodes and their connections",direct:"Zero-hop (direct RF) neighbors"},Gc=["repeater","companion","room_server"],Qi=["hubs","direct"],Hn="!p-2.5 sm:!p-1.5 !rounded-md min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 shrink-0 flex items-center justify-center",L0="!p-2.5 sm:!p-1.5 !rounded-none min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 shrink-0 flex items-center justify-center",Uc=()=>typeof window>"u"?!1:window.innerWidth<640;function Vc({mapRef:a,showNeighborLines:u,onToggleNeighborLines:d,hasNeighborPolylines:y,nodeFilters:x,onToggleFilter:b,onToggleAll:E,filterCounts:F,showCoverage:B,onToggleCoverage:k,showMinCut:j=!1,onToggleMinCut:Q,hasMinCutData:z=!1,show3DTerrain:Y,onToggle3DTerrain:U,basemapMode:q,onToggleBasemap:sA,isFullscreen:X,onToggleFullscreen:K,showLinkQuality:oA=!1,onToggleLinkQuality:uA,hasTraceLinks:kA=!1}){const[lA,aA]=R.useState(()=>!Uc()),BA=()=>{var FA,UA;(UA=(FA=a.current)==null?void 0:FA.getMap())==null||UA.zoomIn()},EA=()=>{var FA,UA;(UA=(FA=a.current)==null?void 0:FA.getMap())==null||UA.zoomOut()},bA=()=>{var UA;const FA=(UA=a.current)==null?void 0:UA.getMap();FA&&FA.easeTo({bearing:0,pitch:0,duration:300})},fA="w-4 h-4",IA=q==="light"?"#525252":"var(--fg-secondary)",LA=x.length>=y0.length;return p.jsx(p.Fragment,{children:p.jsxs("div",{className:"absolute top-3 right-3 z-[600] flex flex-col gap-2 sm:top-4 sm:right-4 max-w-[calc(100vw-1.5rem)] sm:max-w-none pr-[env(safe-area-inset-right)]",children:[p.jsxs("div",{className:"map-control-surface flex flex-nowrap items-center gap-0.5 sm:gap-1 p-1 overflow-hidden",children:[y&&p.jsx(Nt,{plain:!0,color:u?"warning":"muted",onClick:d,title:u?"Hide edge lines":"Show edge lines","aria-label":u?"Hide edge lines":"Show edge lines","aria-pressed":u,className:Hn,"data-tint":u?"warning":void 0,children:p.jsx(ja,{className:fA})}),p.jsx(Nt,{plain:!0,color:"muted",onClick:()=>aA(FA=>!FA),title:lA?"Hide node filters":"Show node filters","aria-label":lA?"Collapse node filters":"Expand node filters","aria-expanded":lA,className:Hn,children:p.jsx(yu,{className:fA})}),p.jsx(Sr,{initial:!1,children:lA&&p.jsxs(Xt.div,{className:"flex items-center gap-0.5 flex-nowrap overflow-x-auto scrollbar-none max-w-[50vw] sm:max-w-none sm:overflow-visible",role:"group","aria-label":"Node type filters",initial:{width:0,opacity:0},animate:{width:"auto",opacity:1},exit:{width:0,opacity:0},transition:{duration:.2,ease:[.4,0,.2,1]},children:[p.jsx(ps,{color:LA?"green":"zinc",customColor:LA?void 0:IA,onClick:E,title:"Show all nodes","aria-pressed":LA,"aria-label":"Show all node types",className:"shrink-0",children:"All"}),Gc.map(FA=>{const UA=F[FA];if(UA===0)return null;const vA=!LA&&x.includes(FA);return p.jsx(ps,{color:vA?Fi[FA]:"zinc",customColor:vA?void 0:IA,onClick:()=>b(FA),title:Pi[FA],"aria-pressed":vA,"aria-label":`${I0[FA]} (${UA})`,className:"shrink-0",children:I0[FA]},FA)}),Qi.some(FA=>F[FA]>0)&&p.jsx("span",{className:"mx-0.5 h-3 w-px bg-[var(--map-ui-border,var(--edge-subtle))] hidden sm:block shrink-0","aria-hidden":"true"}),Qi.map(FA=>{const UA=F[FA];if(UA===0)return null;const vA=!LA&&x.includes(FA);return p.jsx(ps,{color:vA?Fi[FA]:"zinc",customColor:vA?void 0:IA,onClick:()=>b(FA),title:Pi[FA],"aria-pressed":vA,"aria-label":`${I0[FA]} (${UA})`,className:"shrink-0",children:I0[FA]},FA)})]})}),z&&Q&&p.jsx(Nt,{plain:!0,color:j?"primary":"muted",onClick:Q,title:j?"Hide community partition":"Show community partition","aria-label":j?"Hide community partition":"Show community partition","aria-pressed":j,className:Hn,"data-tint":j?"primary":void 0,children:p.jsx(Ts,{className:fA})}),p.jsx(Nt,{plain:!0,color:q==="light"?"primary":"muted",onClick:sA,title:q==="light"?"Switch to dark map":"Switch to light map","aria-label":q==="light"?"Switch to dark map":"Switch to light map","aria-pressed":q==="light",className:Hn,"data-tint":q==="light"?"primary":void 0,children:q==="light"?p.jsx(Ws,{className:fA}):p.jsx(Ys,{className:fA})}),p.jsx(Nt,{plain:!0,color:Y?"success":"muted",onClick:U,title:Y?"Disable 3D terrain":"Enable 3D terrain","aria-label":Y?"Disable 3D terrain":"Enable 3D terrain","aria-pressed":Y,className:Hn,"data-tint":Y?"success":void 0,children:p.jsx($u,{className:fA})}),p.jsx(Nt,{plain:!0,color:"muted",onClick:K,title:X?"Exit fullscreen":"Fullscreen","aria-label":X?"Exit fullscreen":"Enter fullscreen","aria-pressed":X,className:Hn,children:X?p.jsx(fu,{className:fA}):p.jsx(hu,{className:fA})})]}),p.jsxs("div",{className:"map-control-surface flex flex-col items-stretch !overflow-hidden self-end !p-0",children:[p.jsx(Nt,{plain:!0,color:"muted",onClick:BA,title:"Zoom in","aria-label":"Zoom in",className:L0,children:p.jsx(xu,{className:fA})}),p.jsx("div",{className:"h-px bg-border-subtle","aria-hidden":"true"}),p.jsx(Nt,{plain:!0,color:"muted",onClick:EA,title:"Zoom out","aria-label":"Zoom out",className:L0,children:p.jsx(No,{className:fA})}),p.jsx("div",{className:"h-px bg-border-subtle","aria-hidden":"true"}),p.jsx(Nt,{plain:!0,color:"muted",onClick:bA,title:"Reset bearing to north","aria-label":"Reset bearing to north",className:L0,children:p.jsx(wu,{className:fA})})]}),kA&&uA&&p.jsx("div",{className:"map-control-surface flex flex-col items-stretch !overflow-hidden self-end !p-0",children:p.jsx(Nt,{plain:!0,color:oA?"success":"muted",onClick:uA,title:oA?"Hide link quality overlay":"Show link quality overlay","aria-label":oA?"Hide link quality overlay":"Show link quality overlay","aria-pressed":oA,className:L0,"data-tint":oA?"success":void 0,children:p.jsx(tl,{className:fA})})})]})})}const Wc="#4ADE80",Yc="#16A34A",$c="rgba(10, 26, 10, 1)",Kc="rgba(220, 252, 231, 1)",xn="DeepAnalysis",Zc=700,Oi="abcdefghijklmnopqrstuvwxyz0123456789";function qc(){return Oi[Math.floor(Math.random()*Oi.length)]}function Jc({isActive:a,hasAnalyzed:u,isLoading:d,onClick:y,basemapMode:x="dark"}){const b=x==="light",E=b?Yc:Wc,[F,B]=R.useState(!1),[k,j]=R.useState(xn),Q=R.useRef(!1),z=R.useRef(null),[Y]=R.useState(()=>{var X;return typeof window<"u"&&(((X=window.matchMedia)==null?void 0:X.call(window,"(hover: hover)").matches)??!1)}),U=F&&!a&&!d&&Y;R.useEffect(()=>{if(F&&!a&&!d&&!Q.current){Q.current=!0;const X=performance.now(),K=oA=>{const uA=oA-X,kA=Math.min(uA/Zc,1),lA=Math.floor(kA*xn.length);let aA="";for(let BA=0;BA{z.current&&cancelAnimationFrame(z.current)}},[F,a,d]);const q=d?"Analyzing...":k,sA=d?"Analyzing packet history":u?a?"Hide topology edges":"Show topology edges":"Load full packet history and build topology";return p.jsxs("button",{onClick:y,onMouseEnter:()=>Y&&B(!0),onMouseLeave:()=>Y&&B(!1),onPointerEnter:()=>Y&&B(!0),onPointerLeave:()=>Y&&B(!1),disabled:d,className:`map-tool-btn flex items-center gap-2 w-full text-left radius-inner transition-base ${d?"cursor-wait":""}`,style:{padding:"0.5rem 0.625rem",...a&&{backgroundColor:b?Kc:$c}},title:sA,"aria-label":sA,"aria-pressed":a,children:[d?p.jsx(q0,{className:"w-3.5 h-3.5 shrink-0 animate-spin",style:{color:E}}):p.jsx(Ds,{className:`w-3.5 h-3.5 shrink-0 transition-colors ${a?"":"text-fg-secondary"}`,style:{...a&&{color:E},...U&&{color:E}}}),p.jsx("span",{className:`${a?"":"text-fg-secondary"}`,"aria-hidden":"true",style:{fontFamily:"ui-monospace, SFMono-Regular, monospace",fontSize:"0.6875rem",fontWeight:a||U?700:500,letterSpacing:"-0.01em",lineHeight:1,...a&&{color:E},...U&&{color:E}},children:q})]})}const Xc=ar.teal,Af="#0D7377",ef="rgba(10, 36, 32, 1)",tf="rgba(204, 251, 241, 1)",zi="LiveTrace",rf=400,Hi=100;function nf({isActive:a,onClick:u,basemapMode:d="dark"}){const y=d==="light",x=y?Af:Xc,[b,E]=R.useState(!1),[F,B]=R.useState(0),k=R.useRef(!1),j=R.useRef(null),[Q,z]=R.useState(0),Y=R.useRef(!1),[U]=R.useState(()=>{var K;return typeof window<"u"&&(((K=window.matchMedia)==null?void 0:K.call(window,"(hover: hover)").matches)??!1)}),q=b&&!a&&U;R.useEffect(()=>{q&&!Y.current&&(Y.current=!0,z(1),setTimeout(()=>z(2),Hi),setTimeout(()=>z(3),Hi*2)),b||(Y.current=!1,z(0))},[q,b]),R.useEffect(()=>{if(b&&!a&&!k.current){k.current=!0;const K=performance.now(),oA=uA=>{const kA=uA-K,lA=Math.min(kA/rf,1);B(lA),lA<1&&(j.current=requestAnimationFrame(oA))};j.current=requestAnimationFrame(oA)}return b||(j.current&&(cancelAnimationFrame(j.current),j.current=null),k.current=!1,B(0)),()=>{j.current&&cancelAnimationFrame(j.current)}},[b,a]);const sA=K=>{if(a)return x;if(!q)return;const oA=zi.length,uA=F*(oA+2);return K>=uA-2&&KU&&E(!0),onMouseLeave:()=>U&&E(!1),onPointerEnter:()=>U&&E(!0),onPointerLeave:()=>U&&E(!1),className:"map-tool-btn flex items-center gap-2 w-full text-left radius-inner transition-base",style:{padding:"0.5rem 0.625rem",...a&&{backgroundColor:y?tf:ef}},title:a?"Disable live packet tracing (reduces CPU usage)":"Enable live packet tracing","aria-label":X,"aria-pressed":a,children:[p.jsx(vu,{className:`w-3.5 h-3.5 shrink-0 ${a?"":"text-fg-secondary"}`,fill:Q===1?"#FFFFFF":Q===3?x:"none",stroke:Q===1||Q===2?"#FFFFFF":a||q?x:"currentColor",style:{transition:"fill 0.05s, stroke 0.05s"}}),p.jsx("span",{className:`${a?"":"text-fg-secondary"}`,"aria-hidden":"true",style:{fontFamily:"ui-monospace, SFMono-Regular, monospace",fontSize:"0.6875rem",fontWeight:a||q?700:500,letterSpacing:"-0.01em",lineHeight:1},children:zi.split("").map((K,oA)=>p.jsx("span",{style:{color:sA(oA)||void 0},children:K},oA))})]})}const Gi=.2,sf="rgba(26, 20, 8, 1)",of="rgba(254, 243, 199, 1)",vs=.01,bs=1,Ui="#fe8019",lf="'Wardrive', serif",Ls=1.45,af=Ls*1.1,uf=80;function cf({isActive:a,onClick:u,brightness:d=.7,onBrightnessChange:y,basemapMode:x="dark"}){const b=x==="light",[E,F]=R.useState(!1),[B,k]=R.useState(!1),[j]=R.useState(()=>{var K;return typeof window<"u"&&(((K=window.matchMedia)==null?void 0:K.call(window,"(hover: hover)").matches)??!1)});R.useEffect(()=>{if(!E||a)return;const K=requestAnimationFrame(()=>k(!0)),oA=setTimeout(()=>k(!1),uf);return()=>{cancelAnimationFrame(K),clearTimeout(oA)}},[E,a]);const Q=Math.max(vs,Math.min(bs,d)),z=K=>{K.stopPropagation();const oA=Math.min(bs,Q+Gi);y==null||y(oA)},Y=K=>{K.stopPropagation();const oA=Math.max(vs,Q-Gi);y==null||y(oA)},U=Qvs+.001,sA=E&&!a&&j,X=a?"Configure wardriving coverage":"Show wardriving coverage";return p.jsxs("button",{onClick:u,onMouseEnter:()=>j&&F(!0),onMouseLeave:()=>j&&F(!1),onPointerEnter:()=>j&&F(!0),onPointerLeave:()=>j&&F(!1),className:"map-tool-btn flex items-center gap-2 w-full text-left radius-inner transition-base",style:{padding:"0.5rem 0.625rem",...a&&{backgroundColor:b?of:sf}},title:X,"aria-label":X,"aria-pressed":a,children:[p.jsx(ec,{className:`w-3.5 h-3.5 shrink-0 transition-colors ${a?"text-sys-amber":"text-fg-secondary"}`,style:sA?{color:Ui}:void 0}),p.jsx("span",{className:`${a?"text-sys-amber":"text-fg-secondary"}`,"aria-hidden":"true",style:{fontFamily:a||sA?lf:"ui-monospace, SFMono-Regular, monospace",fontSize:a||sA?"0.75rem":"0.6875rem",fontWeight:500,letterSpacing:"-0.01em",lineHeight:1,transition:"none",transform:a?`scale(${Ls})`:sA?`scale(${B?af:Ls})`:void 0,transformOrigin:"left center",...sA?{color:Ui}:{}},children:"Wardrive"}),a&&y&&p.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[p.jsx("button",{onClick:Y,disabled:!q,className:`p-1 sm:p-0.5 min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 flex items-center justify-center rounded transition-colors ${q?"text-sys-amber hover:bg-[var(--map-ui-hover,var(--elevated))] active:bg-[var(--map-ui-active,var(--subtle))]":"cursor-not-allowed"}`,style:q?void 0:{color:b?"rgba(0, 0, 0, 0.25)":"rgba(251, 191, 36, 0.3)"},title:`Decrease opacity (${Math.round(Q*100)}%)`,"aria-label":`Decrease opacity, currently ${Math.round(Q*100)}%`,children:p.jsx(Ws,{className:"w-3.5 h-3.5"})}),p.jsx("button",{onClick:z,disabled:!U,className:`p-1 sm:p-0.5 min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 flex items-center justify-center rounded transition-colors ${U?"text-sys-amber hover:bg-[var(--map-ui-hover,var(--elevated))] active:bg-[var(--map-ui-active,var(--subtle))]":"cursor-not-allowed"}`,style:U?void 0:{color:b?"rgba(0, 0, 0, 0.25)":"rgba(251, 191, 36, 0.3)"},title:`Increase opacity (${Math.round(Q*100)}%)`,"aria-label":`Increase opacity, currently ${Math.round(Q*100)}%`,children:p.jsx(Ys,{className:"w-3.5 h-3.5"})})]})]})}const ff="0123456789bcdefghjkmnpqrstuvwxyz";function hf(a){let u=!0,d=-90,y=90,x=-180,b=180;for(const E of a.toLowerCase()){const F=ff.indexOf(E);if(F!==-1)for(let B=4;B>=0;B--){const k=F>>B&1;if(u){const j=(x+b)/2;k?x=j:b=j}else{const j=(d+y)/2;k?d=j:y=j}u=!u}}return{lat:(d+y)/2,lon:(x+b)/2}}function df(a){return Math.exp(-a*Math.LN2/7)}const Ns="pymc-wardriving-url",il="pymc-wardriving-enabled",ol="pymc-wardriving-brightness",Vi=.7;function mf(){return typeof localStorage>"u"?"":localStorage.getItem(Ns)||""}function Wi(a){typeof localStorage>"u"||(a?localStorage.setItem(Ns,a):localStorage.removeItem(Ns))}function pf(){return typeof localStorage>"u"?!1:localStorage.getItem(il)==="true"}function N0(a){typeof localStorage>"u"||localStorage.setItem(il,String(a))}function gf(){if(typeof localStorage>"u")return Vi;const a=localStorage.getItem(ol);if(a){const u=parseFloat(a);if(!isNaN(u)&&u>=.01&&u<=1)return u}return Vi}function yf(a){if(typeof localStorage>"u")return;const u=Math.max(.01,Math.min(1,a));localStorage.setItem(ol,String(u))}const xf=8e3;async function wf(a,u={},d=xf){const y=new AbortController,x=setTimeout(()=>y.abort(),d);try{return await fetch(a,{...u,signal:y.signal})}catch(b){throw b instanceof Error&&b.name==="AbortError"?new Error(`Connection timed out after ${d/1e3}s`):b}finally{clearTimeout(x)}}async function vf(a){const d=`${a.replace(/\/+$/,"").replace(/\/get-nodes$/,"").replace(/\/get-samples$/,"")}/get-samples`,y=await wf(d,{headers:{Accept:"application/json"}});if(!y.ok)throw new Error(`Failed to fetch precise samples: ${y.status}`);return y.json()}function bf(a,u=null){if(a!==null){const y=(Math.max(-12,Math.min(12,a))+12)/24;if(u!==null){const b=(Math.max(-120,Math.min(-50,u))+120)/70;return y*.8+b*.2}return y}return u!==null?(Math.max(-120,Math.min(-50,u))+120)/70:.5}function kf(a){var d;const u=[];for(const y of a.keys){if(!y.observed)continue;const{lat:x,lon:b}=hf(y.hash),E=parseInt(y.time,10),F=isNaN(E)?30:(Date.now()-E)/(1e3*60*60*24),B=df(F),j=bf(y.snr,y.rssi)*(.3+B*.7);u.push({lat:x,lon:b,successRate:y.observed?1:0,weight:j,totalSamples:1,ageDays:F,geohash:y.hash,repeaters:((d=y.path)==null?void 0:d.map(Q=>Q.toLowerCase()))||[]})}return u}const x0=$s((a,u)=>({status:"idle",isVisible:pf(),coveragePoints:[],repeaters:[],error:null,stats:{coverageCount:0,repeaterCount:0,lastUpdated:null},url:mf(),brightness:gf(),isModalOpen:!1,openModal:()=>a({isModalOpen:!0}),closeModal:()=>a({isModalOpen:!1}),setUrl:d=>a({url:d}),setBrightness:d=>{const y=Math.max(.01,Math.min(1,d));yf(y),a({brightness:y})},toggleVisibility:()=>{const d=!u().isVisible;N0(d),a({isVisible:d})},setVisible:d=>{N0(d),a({isVisible:d})},loadCoverage:async d=>{if(!d.trim())return a({error:"Please enter a URL",status:"error"}),!1;try{new URL(d.trim())}catch{return a({error:"Invalid URL format",status:"error"}),!1}a({error:null,status:"connecting"});try{a({status:"loading"});const y=await vf(d.trim());if(!y||typeof y!="object")throw new Error("Invalid response from server");if(!Array.isArray(y.keys))throw new Error("No sample data found in response");a({status:"processing"});const x=kf(y);if(x.length===0)throw new Error("No valid coverage points found");return a({coveragePoints:x,repeaters:[],stats:{coverageCount:x.length,repeaterCount:0,lastUpdated:new Date},status:"success",isVisible:!0,url:d.trim()}),Wi(d.trim()),N0(!0),!0}catch(y){const x=y instanceof Error?y.message:"Failed to load coverage data";let b=x;return x.includes("timed out")?b="Connection timed out. Server may be unreachable or slow.":x.includes("Failed to fetch")||x.includes("NetworkError")?b="Could not connect to server. Check the URL and try again.":x.includes("CORS")?b="Server does not allow cross-origin requests.":x.includes("404")?b="Coverage endpoint not found. Check the URL.":(x.includes("ERR_NAME_NOT_RESOLVED")||x.includes("DNS"))&&(b="Server not found. Check the URL for typos."),a({error:b,status:"error"}),!1}},clearCoverage:()=>{a({coveragePoints:[],repeaters:[],stats:{coverageCount:0,repeaterCount:0,lastUpdated:null},status:"idle",error:null,isVisible:!1,url:""}),Wi(""),N0(!1)}})),Cf={bg:"#F8F8F8",bgSubtle:"#F0F0F0",bgElevated:"#FFFFFF",bgInput:"#FFFFFF",border:"rgba(0, 0, 0, 0.12)",borderStrong:"rgba(0, 0, 0, 0.20)",borderFocus:"#3B82F6",text:"#1A1A1A",textSecondary:"#4A4A4A",textMuted:"#737373",success:"#059669",successBg:"#ECFDF5",successBorder:"#A7F3D0",error:"#DC2626",errorBg:"#FEF2F2",errorBorder:"#FECACA",info:"#2563EB",infoBg:"#EFF6FF",infoBorder:"#BFDBFE",warning:"#D97706",warningBg:"#FFFBEB",warningBorder:"#FDE68A",primary:"#F59E0B",hoverBg:"rgba(0, 0, 0, 0.04)",sliderTrack:"#E5E7EB",sliderThumb:"#F59E0B"},ll={bg:"var(--surface)",bgSubtle:"var(--subtle)",bgElevated:"var(--elevated)",bgInput:"var(--subtle)",border:"var(--edge-subtle)",borderStrong:"var(--edge-strong)",borderFocus:"var(--sys-blue)",text:"var(--fg-primary)",textSecondary:"var(--fg-secondary)",textMuted:"var(--fg-muted)",success:"var(--sys-green)",successBg:"rgba(74, 222, 128, 0.1)",successBorder:"rgba(74, 222, 128, 0.3)",error:"var(--sys-red)",errorBg:"rgba(239, 68, 68, 0.1)",errorBorder:"rgba(239, 68, 68, 0.3)",info:"var(--sys-indigo)",infoBg:"rgba(249, 210, 111, 0.1)",infoBorder:"rgba(249, 210, 111, 0.3)",warning:"var(--sys-indigo)",warningBg:"rgba(249, 210, 111, 0.1)",warningBorder:"rgba(249, 210, 111, 0.3)",primary:"var(--sys-indigo)",hoverBg:"var(--hover-tint)",sliderTrack:"var(--elevated)",sliderThumb:"var(--sys-indigo)"},al=R.createContext({theme:ll,isLight:!1});function Bn(){return R.useContext(al)}function Sf({status:a,hasData:u}){const{theme:d,isLight:y}=Bn(),x=R.useMemo(()=>a==="connecting"||a==="loading"||a==="processing"?{icon:p.jsx(q0,{className:"w-3.5 h-3.5 animate-spin"}),label:a==="connecting"?"Connecting...":a==="loading"?"Loading...":"Processing...",color:d.warning,bg:d.warningBg}:a==="error"?{icon:p.jsx(Tu,{className:"w-3.5 h-3.5"}),label:"Disconnected",color:d.error,bg:d.errorBg}:u?{icon:p.jsx(Ru,{className:"w-3.5 h-3.5"}),label:"Connected",color:d.success,bg:d.successBg}:{icon:p.jsx(Po,{className:"w-3.5 h-3.5"}),label:"Ready",color:d.textMuted,bg:y?"rgba(0,0,0,0.04)":"rgba(255,255,255,0.04)"},[a,u,d,y]);return p.jsxs(Xt.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},className:"flex items-center gap-1.5 px-2 py-1 rounded-full text-xs font-medium",style:{backgroundColor:x.bg,color:x.color},children:[x.icon,p.jsx("span",{children:x.label})]},x.label)}function Ef({status:a}){const{theme:u}=Bn(),d=R.useMemo(()=>{switch(a){case"connecting":return 25;case"loading":return 60;case"processing":return 90;default:return 0}},[a]);return d===0?null:p.jsx(Xt.div,{initial:{opacity:0,scaleY:0},animate:{opacity:1,scaleY:1},exit:{opacity:0,scaleY:0},className:"h-1 rounded-full overflow-hidden origin-top",style:{backgroundColor:u.sliderTrack},children:p.jsx(Xt.div,{className:"h-full rounded-full",style:{backgroundColor:u.primary},initial:{width:0},animate:{width:`${d}%`},transition:{duration:.4,ease:"easeOut"}})})}function Yi({variant:a,title:u,description:d,onDismiss:y}){const{theme:x}=Bn(),b=R.useMemo(()=>{switch(a){case"success":return{icon:p.jsx(Yn,{className:"w-4 h-4"}),color:x.success,bg:x.successBg,border:x.successBorder};case"error":return{icon:p.jsx(ju,{className:"w-4 h-4"}),color:x.error,bg:x.errorBg,border:x.errorBorder};case"info":return{icon:p.jsx(Wu,{className:"w-4 h-4"}),color:x.info,bg:x.infoBg,border:x.infoBorder}}},[a,x]);return p.jsxs(Xt.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:En.snappy,className:"flex items-start gap-3 p-3 rounded-lg border",style:{backgroundColor:b.bg,borderColor:b.border,color:b.color},children:[p.jsx("div",{className:"shrink-0 mt-0.5",children:b.icon}),p.jsxs("div",{className:"flex-1 min-w-0",children:[p.jsx("p",{className:"text-sm font-medium",children:u}),d&&p.jsx("p",{className:"text-xs mt-0.5 opacity-80",children:d})]}),y&&p.jsx("button",{onClick:y,className:"shrink-0 p-1 rounded hover:bg-black/10 transition-colors","aria-label":"Dismiss",children:p.jsx(Mn,{className:"w-3.5 h-3.5"})})]})}function Mf({value:a,onChange:u,onSubmit:d,disabled:y}){const{theme:x,isLight:b}=Bn(),[E,F]=R.useState(!1),B=k=>{k.key==="Enter"&&!k.shiftKey&&!y&&(k.preventDefault(),d())};return p.jsxs("div",{className:"space-y-1.5",children:[p.jsx("label",{className:"block text-sm font-medium",style:{color:x.textSecondary},children:"Coverage Server URL"}),p.jsxs("div",{className:"relative",children:[p.jsx("input",{type:"url",value:a,onChange:k=>u(k.target.value),onKeyDown:B,onFocus:()=>F(!0),onBlur:()=>F(!1),placeholder:"https://coverage.wcmesh.com",disabled:y,className:Or("w-full pl-3 pr-10 py-2.5 rounded-lg border text-sm transition-all duration-150","focus:outline-none",y&&"opacity-50 cursor-not-allowed"),style:{backgroundColor:x.bgInput,borderColor:E?x.borderFocus:x.border,color:x.text,boxShadow:E?`0 0 0 3px ${b?"rgba(59, 130, 246, 0.15)":"rgba(139, 92, 246, 0.15)"}`:"none"}}),a&&!y&&p.jsx("button",{onClick:()=>u(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 p-1 rounded transition-colors",style:{color:x.textMuted},onMouseEnter:k=>k.currentTarget.style.color=x.text,onMouseLeave:k=>k.currentTarget.style.color=x.textMuted,"aria-label":"Clear URL",children:p.jsx(Mn,{className:"w-4 h-4"})})]}),p.jsx("p",{className:"text-xs",style:{color:x.textMuted},children:"Press Enter to connect, or use the Connect button below"})]})}function Bf({value:a,onChange:u}){const{theme:d,isLight:y}=Bn(),x=Math.round(a*100);return p.jsx(Xt.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:En.gentle,className:"overflow-hidden",children:p.jsx("div",{className:"p-3 rounded-lg border",style:{backgroundColor:d.bgSubtle,borderColor:d.border},children:p.jsxs("div",{className:"flex items-center gap-3",children:[p.jsxs("div",{className:"relative w-4 h-4",children:[p.jsx(Ws,{className:"w-4 h-4 absolute inset-0 transition-opacity",style:{color:d.textMuted,opacity:a<.5?1:0}}),p.jsx(Ys,{className:"w-4 h-4 absolute inset-0 transition-opacity",style:{color:d.primary,opacity:a>=.5?1:0}})]}),p.jsxs("div",{className:"flex-1",children:[p.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[p.jsx("span",{className:"text-xs font-medium",style:{color:d.textSecondary},children:"Layer Opacity"}),p.jsxs("span",{className:"text-xs font-mono tabular-nums px-1.5 py-0.5 rounded",style:{color:d.text,backgroundColor:y?"rgba(0,0,0,0.06)":"rgba(255,255,255,0.06)"},children:[x,"%"]})]}),p.jsx("input",{type:"range",min:5,max:100,value:x,onChange:b=>u(Number(b.target.value)/100),className:Or("w-full h-2 rounded-full appearance-none cursor-pointer","[&::-webkit-slider-thumb]:appearance-none","[&::-webkit-slider-thumb]:w-4","[&::-webkit-slider-thumb]:h-4","[&::-webkit-slider-thumb]:rounded-full","[&::-webkit-slider-thumb]:cursor-pointer","[&::-webkit-slider-thumb]:transition-transform","[&::-webkit-slider-thumb]:hover:scale-110","[&::-webkit-slider-thumb]:shadow-lg","[&::-moz-range-thumb]:appearance-none","[&::-moz-range-thumb]:w-4","[&::-moz-range-thumb]:h-4","[&::-moz-range-thumb]:rounded-full","[&::-moz-range-thumb]:border-0","[&::-moz-range-thumb]:cursor-pointer"),style:{background:`linear-gradient(to right, ${d.primary} ${x}%, ${d.sliderTrack} ${x}%)`,"--thumb-color":d.sliderThumb}}),p.jsx("style",{children:` + input[type="range"]::-webkit-slider-thumb { + background-color: ${d.sliderThumb}; + } + input[type="range"]::-moz-range-thumb { + background-color: ${d.sliderThumb}; + } + `})]})]})})})}function Df({coverageCount:a,repeaterCount:u,lastUpdated:d}){const{theme:y}=Bn();return p.jsxs("div",{className:"grid grid-cols-3 gap-2 p-3 rounded-lg border",style:{backgroundColor:y.bgSubtle,borderColor:y.border},children:[p.jsxs("div",{className:"text-center",children:[p.jsx(Mi,{value:a,format:{useGrouping:!0,maximumFractionDigits:0},className:"text-lg font-semibold tabular-nums block",style:{color:y.text}}),p.jsx("div",{className:"text-xs mt-0.5",style:{color:y.textMuted},children:"Points"})]}),p.jsxs("div",{className:"text-center border-x",style:{borderColor:y.border},children:[p.jsx(Mi,{value:u,format:{useGrouping:!0,maximumFractionDigits:0},className:"text-lg font-semibold tabular-nums block",style:{color:y.text}}),p.jsx("div",{className:"text-xs mt-0.5",style:{color:y.textMuted},children:"Repeaters"})]}),p.jsxs("div",{className:"text-center",children:[p.jsxs("div",{className:"flex items-center justify-center gap-1",children:[p.jsx(Jo,{className:"w-3.5 h-3.5",style:{color:y.textMuted}}),p.jsx("span",{className:"text-lg font-semibold tabular-nums",style:{color:y.text},children:d?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"—"})]}),p.jsx("div",{className:"text-xs mt-0.5",style:{color:y.textMuted},children:"Updated"})]})]})}function $i({icon:a,label:u,onClick:d,disabled:y,variant:x="default",active:b}){const{theme:E,isLight:F}=Bn(),B=R.useMemo(()=>x==="danger"?{text:E.error,hoverBg:F?"rgba(220, 38, 38, 0.08)":"rgba(239, 68, 68, 0.15)"}:{text:b?E.primary:E.textSecondary,hoverBg:E.hoverBg},[x,b,E,F]);return p.jsxs("button",{onClick:d,disabled:y,className:Or("flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-sm font-medium transition-colors",y&&"opacity-50 cursor-not-allowed"),style:{color:B.text},onMouseEnter:k=>!y&&(k.currentTarget.style.backgroundColor=B.hoverBg),onMouseLeave:k=>k.currentTarget.style.backgroundColor="transparent",children:[a,p.jsx("span",{children:u})]})}function _f(){const a=Fo(),u=a==="light",d=u?Cf:ll,{isModalOpen:y,closeModal:x,status:b,isVisible:E,stats:F,error:B,url:k,brightness:j,loadCoverage:Q,clearCoverage:z,toggleVisibility:Y,setUrl:U,setBrightness:q}=x0(),sA=b==="connecting"||b==="loading"||b==="processing",X=F.coverageCount>0,[K,oA]=R.useState(!0),[uA,kA]=R.useState(k);R.useEffect(()=>{kA(k)},[k]),R.useEffect(()=>{b==="error"&&oA(!0)},[b]);const lA=R.useCallback(async()=>{await Q(uA)},[uA,Q]),aA=R.useCallback(()=>{kA(""),z()},[z]),BA=R.useCallback(fA=>{kA(fA),U(fA)},[U]),EA=R.useCallback(()=>{sA||x()},[sA,x]),bA=uA.trim().length>0&&!sA;return p.jsx(al.Provider,{value:{theme:d,isLight:u},children:p.jsxs(_o,{open:y,onClose:EA,size:"md",bottomSheet:!0,basemapMode:a,children:[p.jsxs("div",{className:"flex items-center justify-between p-4 border-b",style:{borderColor:d.border},children:[p.jsxs("div",{className:"flex items-center gap-3",children:[p.jsx("div",{className:"p-2 rounded-lg",style:{backgroundColor:d.bgSubtle,color:d.primary},children:p.jsx(Po,{className:"w-5 h-5"})}),p.jsxs("div",{children:[p.jsx("h2",{className:"type-micro",style:{color:d.text},children:"Wardriving Coverage"}),p.jsx("p",{className:"text-xs",style:{color:d.textMuted},children:"RF coverage heatmap overlay"})]})]}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx(Sf,{status:b,hasData:X}),!sA&&p.jsxs(p.Fragment,{children:[p.jsx("button",{onClick:EA,className:"sm:hidden min-h-[44px] min-w-[44px] px-3 flex items-center justify-center text-[15px] font-medium transition-base radius-inner active:bg-subtle-fill",style:{color:d.primary},children:"Done"}),p.jsx("button",{onClick:EA,className:"hidden sm:flex items-center justify-center p-2 rounded-lg transition-colors",style:{color:d.textMuted},onMouseEnter:fA=>{fA.currentTarget.style.color=d.text,fA.currentTarget.style.backgroundColor=d.hoverBg},onMouseLeave:fA=>{fA.currentTarget.style.color=d.textMuted,fA.currentTarget.style.backgroundColor="transparent"},"aria-label":"Close",children:p.jsx(Mn,{className:"w-5 h-5"})})]})]})]}),p.jsx(Sr,{children:sA&&p.jsx(Ef,{status:b})}),p.jsxs(To,{className:"space-y-4",children:[p.jsx(Mf,{value:uA,onChange:BA,onSubmit:lA,disabled:sA}),p.jsx(Sr,{children:b==="error"&&B&&K&&p.jsx(Yi,{variant:"error",title:"Connection Failed",description:B,onDismiss:()=>oA(!1)})}),p.jsx(Sr,{children:b==="success"&&X&&p.jsx(Yi,{variant:"success",title:"Coverage Data Loaded",description:"Adjust opacity below, then close to view on map"})}),p.jsx(Sr,{children:X&&!sA&&p.jsx(Xt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},transition:En.snappy,children:p.jsx(Df,{coverageCount:F.coverageCount,repeaterCount:F.repeaterCount,lastUpdated:F.lastUpdated})})}),p.jsx(Sr,{children:X&&!sA&&p.jsx(Bf,{value:j,onChange:q})})]}),p.jsxs("div",{className:"flex items-center justify-between p-4 border-t",style:{borderColor:d.border},children:[p.jsx("div",{className:"flex items-center gap-1",children:p.jsx(Sr,{children:X&&p.jsxs(Xt.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},exit:{opacity:0,x:-10},transition:En.snappy,className:"flex items-center gap-1",children:[p.jsx($i,{icon:E?p.jsx(Cu,{className:"w-4 h-4"}):p.jsx(Zo,{className:"w-4 h-4"}),label:E?"Hide":"Show",onClick:Y,disabled:sA,active:E}),p.jsx($i,{icon:p.jsx(_u,{className:"w-4 h-4"}),label:"Clear",onClick:aA,disabled:sA,variant:"danger"})]})})}),p.jsxs("div",{className:"flex items-center gap-2",children:[p.jsx(Nt,{plain:!0,color:"muted",onClick:EA,disabled:sA,children:X?"Done":"Cancel"}),p.jsx(Nt,{color:"warning",onClick:lA,disabled:!bA,children:sA?p.jsxs(p.Fragment,{children:[p.jsx(q0,{"data-slot":"icon",className:"animate-spin"}),b==="connecting"?"Connecting...":b==="loading"?"Loading...":"Processing..."]}):X?p.jsxs(p.Fragment,{children:[p.jsx(Io,{"data-slot":"icon"}),"Refresh"]}):p.jsxs(p.Fragment,{children:[p.jsx(Ro,{"data-slot":"icon"}),"Connect"]})})]})]})]})})}const Tf={bandwidth:.07,threshold:.1,opacity:1,strokeWidth:4.5};function F0({label:a,value:u,min:d,max:y,step:x,unit:b,formatValue:E,onChange:F}){const B=E?E(u):u.toFixed(2);return p.jsxs("div",{className:"flex items-center gap-2 sm:gap-2",children:[p.jsx("span",{className:"text-xs font-medium w-14 sm:w-16 shrink-0 text-fg-secondary",children:a}),p.jsx("input",{type:"range",min:d,max:y,step:x,value:u,onChange:k=>F(parseFloat(k.target.value)),className:`flex-1 h-1.5 rounded-full appearance-none cursor-pointer bg-elevated + [&::-webkit-slider-thumb]:appearance-none + [&::-webkit-slider-thumb]:w-3.5 + [&::-webkit-slider-thumb]:h-3.5 + [&::-webkit-slider-thumb]:rounded-full + [&::-webkit-slider-thumb]:bg-sys-indigo + [&::-webkit-slider-thumb]:cursor-pointer + [&::-webkit-slider-thumb]:transition-transform + [&::-webkit-slider-thumb]:hover:scale-110 + [&::-webkit-slider-thumb]:shadow-md`}),p.jsxs("span",{className:"text-xs font-mono tabular-nums w-12 sm:w-14 text-right shrink-0 text-fg-muted",children:[B,b&&p.jsx("span",{className:"ml-0.5 opacity-70",children:b})]})]})}function P0({icon:a,label:u,value:d,subtext:y}){return p.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 py-0.5 sm:py-1",children:[p.jsx("div",{className:"text-fg-muted",children:a}),p.jsx("div",{className:"flex-1 min-w-0",children:p.jsx("div",{className:"text-[10px] sm:text-xs truncate text-fg-secondary",children:u})}),p.jsxs("div",{className:"text-right",children:[p.jsx("div",{className:"text-xs font-mono tabular-nums text-fg-primary",children:d}),y&&p.jsx("div",{className:"text-[9px] leading-tight opacity-70 text-fg-muted",children:y})]})]})}function Rf({visible:a,onClose:u,settings:d,onSettingsChange:y,partition:x,totalNodes:b,basemapMode:E="dark"}){const F=Su(),B=R.useRef(null),k=R.useMemo(()=>{if(!x)return{numCommunities:0,avgCommunitySize:0,minCommunitySize:0,maxCommunitySize:0,fiedlerValue:0,modularity:0,coveragePercent:0};const z=Array.from(x.communities.values()).map(U=>U.length),Y=z.reduce((U,q)=>U+q,0);return{numCommunities:x.numCommunities,avgCommunitySize:z.length>0?Math.round(Y/z.length):0,minCommunitySize:z.length>0?Math.min(...z):0,maxCommunitySize:z.length>0?Math.max(...z):0,fiedlerValue:x.fiedlerValue,modularity:0,coveragePercent:b>0?Math.round(Y/b*100):0}},[x,b]),j=(z,Y)=>{y({...d,[z]:Y})},Q=(d.bandwidth*111).toFixed(1);return p.jsx("div",{ref:B,className:"absolute inset-0 z-[600] pointer-events-none",children:p.jsx(Sr,{children:a&&p.jsx(Xt.div,{drag:!0,dragControls:F,dragConstraints:B,dragElastic:.1,dragMomentum:!1,initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},transition:En.smooth,className:` + absolute pointer-events-auto + /* Mobile: bottom sheet style, full width with margins */ + bottom-2 left-2 right-2 + /* sm+: floating panel in bottom-right */ + sm:bottom-16 sm:left-auto sm:right-3 sm:w-64 + /* md+: slightly wider */ + md:w-72 + `,style:{touchAction:"none"},children:p.jsxs("div",{className:` + map-control-surface rounded-lg overflow-hidden shadow-lg + /* Mobile: limit height, allow scroll */ + max-h-[45vh] sm:max-h-[calc(100vh-180px)] overflow-y-auto + /* iOS momentum scrolling */ + overscroll-contain + `,children:[p.jsxs("div",{className:` + flex items-center justify-between + px-3 py-2 sm:px-2.5 sm:py-1.5 + border-b border-edge-subtle + cursor-grab active:cursor-grabbing + min-h-[44px] sm:min-h-0 + `,onPointerDown:z=>F.start(z),children:[p.jsxs("div",{className:"flex items-center gap-2 sm:gap-1.5",children:[p.jsx(Eu,{className:"w-4 h-4 sm:w-3 sm:h-3 text-fg-muted"}),p.jsx(Ts,{className:"w-4 h-4 sm:w-3.5 sm:h-3.5 text-sys-blue"}),p.jsx("span",{className:"text-sm sm:text-xs font-medium text-fg-primary",children:"Partition"})]}),p.jsx(Nt,{plain:!0,color:"muted",onClick:u,className:"!p-1.5 sm:!p-0.5 !rounded min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 flex items-center justify-center","aria-label":"Close toolbox",children:p.jsx(Mn,{className:"w-4 h-4 sm:w-3 sm:h-3"})})]}),p.jsx("div",{className:"px-3 py-2 sm:px-2.5 sm:py-1.5 border-b border-edge-subtle",children:p.jsxs("div",{className:"grid grid-cols-2 gap-x-4 sm:gap-x-3 gap-y-1 sm:gap-y-0.5",children:[p.jsx(P0,{icon:p.jsx(Ts,{className:"w-3.5 h-3.5 sm:w-3 sm:h-3"}),label:"Communities",value:k.numCommunities}),p.jsx(P0,{icon:p.jsx(ki,{className:"w-3.5 h-3.5 sm:w-3 sm:h-3"}),label:"Avg Size",value:k.avgCommunitySize,subtext:`${k.minCommunitySize}–${k.maxCommunitySize}`}),p.jsx(P0,{icon:p.jsx(Xu,{className:"w-3.5 h-3.5 sm:w-3 sm:h-3"}),label:"Fiedler λ₂",value:k.fiedlerValue.toFixed(3)}),p.jsx(P0,{icon:p.jsx(ki,{className:"w-3.5 h-3.5 sm:w-3 sm:h-3"}),label:"Coverage",value:`${k.coveragePercent}%`,subtext:`of ${b}`})]})}),p.jsx("div",{className:"px-3 py-2 sm:px-2.5 sm:py-1.5",children:p.jsxs("div",{className:"space-y-3 sm:space-y-1.5",children:[p.jsx(F0,{label:"Bandwidth",value:d.bandwidth,min:.01,max:.15,step:.005,formatValue:()=>Q,unit:"km",onChange:z=>j("bandwidth",z)}),p.jsx(F0,{label:"Threshold",value:d.threshold,min:.05,max:.5,step:.01,formatValue:z=>`${Math.round((1-z)*100)}%`,unit:"cov",onChange:z=>j("threshold",z)}),p.jsx(F0,{label:"Opacity",value:d.opacity,min:.1,max:1,step:.05,formatValue:z=>`${Math.round(z*100)}%`,onChange:z=>j("opacity",z)}),p.jsx(F0,{label:"Stroke",value:d.strokeWidth,min:0,max:5,step:.5,unit:"px",formatValue:z=>z.toFixed(1),onChange:z=>j("strokeWidth",z)})]})})]})})})})}const jf={excellent:"text-signal-excellent",good:"text-signal-good",fair:"text-signal-fair",poor:"text-signal-poor",critical:"text-signal-critical"};function w0(a,u){return jf[zo(a,u)]}const If={backgroundColor:"var(--map-ui-hover, var(--elevated))",color:"var(--map-ui-text, var(--fg-primary))",boxShadow:"inset 0 0 0 1px var(--map-ui-border-strong, var(--edge-strong))"},Lf={backgroundColor:"var(--map-ui-bg, var(--body))",color:"var(--map-ui-text, var(--fg-primary))",boxShadow:"0 1px 4px rgba(0,0,0,0.15), inset 0 0 0 1px var(--map-ui-border, var(--edge-subtle))"};function Gn({prefix:a,name:u}){const d=R.useRef(null),[y,x]=R.useState(!1),[b,E]=R.useState({top:0,left:0}),F=()=>{if(!u||!d.current)return;const B=d.current.getBoundingClientRect();E({top:B.top-4,left:B.left+B.width/2}),x(!0)};return p.jsxs(p.Fragment,{children:[p.jsx("span",{ref:d,className:"inline-flex items-center px-1.5 py-0.5 rounded font-mono text-[10px] font-semibold transition-opacity hover:opacity-80 cursor-default",style:If,onMouseEnter:F,onMouseLeave:()=>x(!1),children:a}),u&&y&&Oa.createPortal(p.jsx("span",{className:"fixed z-[9999] pointer-events-none -translate-x-1/2 -translate-y-full whitespace-nowrap rounded px-1.5 py-0.5 text-[10px] font-medium",style:{...Lf,top:b.top,left:b.left},children:u}),document.body)]})}function ul(a){if(a._tracePathHashes)return a._tracePathHashes;if(a.payload&&a.payload.length>=20){const u=parseInt(a.payload.slice(16,18),16),y=(isNaN(u)?1:1<<(u&3))*2,x=a.payload.slice(18),b=[];for(let E=0;E+y<=x.length;E+=y)b.push(x.slice(E,E+y).toUpperCase());return b.length>0?b:null}return null}function cl(a,u){return a.src_hash?[a.src_hash.replace(/^0x/i,"").slice(0,2).toUpperCase(),...u.map(y=>y.toUpperCase())]:u.map(d=>d.toUpperCase())}function Nf(a,u,d,y=15){const x=[],b=u.toUpperCase(),E=d.toUpperCase();for(const F of a){if((F.type??F.payload_type)!==Qa.TRACE)continue;const k=ul(F);if(!k||k.length<1)continue;const j=cl(F,k);if(!(j.length<2)){for(let Q=0;Q=y)break}}return x}function Ff(a){switch(a){case"improving":return p.jsx(Ha,{className:"w-3 h-3 text-sys-green"});case"degrading":return p.jsx(rc,{className:"w-3 h-3 text-sys-red"});case"stable":return p.jsx(No,{className:"w-3 h-3 text-fg-muted"});default:return null}}const Pf={backgroundColor:"var(--map-ui-stripe)"};function W0({label:a,value:u,unit:d,color:y,tooltip:x}){return p.jsxs("div",{className:`flex items-center justify-between gap-2 py-[3px] ${x?"cursor-help":""}`,title:x,children:[p.jsx("span",{className:"type-data-xs text-fg-muted",children:a}),p.jsxs("span",{className:`data-box data-box-compact ${y||""}`,children:[u,d&&p.jsx("span",{className:"text-fg-muted ml-0.5",children:d})]})]})}function Ki({stats:a,direction:u,sf:d,noiseFloor:y}){if(!a)return p.jsxs("div",{className:"min-w-0",children:[p.jsx("div",{className:"flex items-center justify-between mb-1.5",children:p.jsx("p",{className:"type-data-xs text-fg-secondary font-medium",children:u})}),p.jsx("p",{className:"type-data-xs text-fg-muted italic px-1.5",children:"No data"})]});const x=a.max-a.min,b=a.median-a.mean,E=za(d),F=a.mean-E,B=zo(a.mean,d),k=[`Mean SNR: ${a.mean.toFixed(1)} dB (${B}) from ${a.count} measurement${a.count!==1?"s":""}`,`Variability: ±${a.stdDev.toFixed(1)} dB`,"",`Link budget (SF${d}, 3.5 dBi omni):`,` Demod threshold: ${E.toFixed(1)} dB`,` SNR margin: ${F>=0?"+":""}${F.toFixed(1)} dB`];return y!=null&&k.push(` Noise floor: ${y} dBm`),p.jsxs("div",{className:"min-w-0",children:[p.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[p.jsx("p",{className:"type-data-xs text-fg-secondary font-medium",children:u}),p.jsxs("span",{className:"type-data-xs text-fg-muted tabular-nums",title:`${a.count} measurement${a.count!==1?"s":""}`,children:["n=",a.count]})]}),p.jsx(W0,{label:"Mean",value:a.mean.toFixed(1),unit:"dB",color:w0(a.mean,d),tooltip:k.join(` +`)}),p.jsx(W0,{label:"Median",value:a.median.toFixed(1),unit:"dB",tooltip:`Middle value — less affected by unusual readings than the average.${Math.abs(b)>=.15?` +Differs from mean by ${b>0?"+":""}${b.toFixed(1)} dB`:""}`}),p.jsx(W0,{label:"Range",value:`${a.min.toFixed(1)}–${a.max.toFixed(1)}`,unit:"dB",tooltip:`Best to worst signal observed. Total spread: ${x.toFixed(1)} dB.`})]})}function Qf({pair:a,onClose:u,prefixToName:d}){var kA,lA,aA,BA,EA,bA,fA,IA,LA,FA,UA,vA;const y=Qo(),x=Ia(),b=La(),E=Na(),[F,B]=R.useState(null),k=((lA=(kA=b==null?void 0:b.config)==null?void 0:kA.radio)==null?void 0:lA.spreading_factor)??Fa,j=R.useMemo(()=>{const cA=`${a.nodeA.hash}>${a.nodeB.hash}`,dA=`${a.nodeB.hash}>${a.nodeA.hash}`;return{forward:y.get(cA)??null,reverse:y.get(dA)??null}},[y,a.nodeA.hash,a.nodeB.hash]),Q=R.useMemo(()=>!x||x.length===0?[]:Nf(x,a.nodeA.prefix,a.nodeB.prefix),[x,a.nodeA.prefix,a.nodeB.prefix]),z=a.nodeA.name||(d==null?void 0:d.get(a.nodeA.prefix.toUpperCase()))||null,Y=a.nodeB.name||(d==null?void 0:d.get(a.nodeB.prefix.toUpperCase()))||null,U=((aA=j.forward)==null?void 0:aA.trend)??((BA=j.reverse)==null?void 0:BA.trend)??"insufficient",q=Math.max(((EA=j.forward)==null?void 0:EA.lastSeen)??0,((bA=j.reverse)==null?void 0:bA.lastSeen)??0),sA=(((fA=j.forward)==null?void 0:fA.uniqueTraceCount)??0)+(((IA=j.reverse)==null?void 0:IA.uniqueTraceCount)??0),X=U==="insufficient"?"Not enough data to determine trend (need at least 4 measurements).":`Whether signal quality is getting better or worse over time. +Compares older measurements to newer ones.`,K=((LA=j.forward)==null?void 0:LA.uniqueTraceCount)??0,oA=((FA=j.reverse)==null?void 0:FA.uniqueTraceCount)??0,uA=["Number of trace packets that traveled through this link.",`${a.nodeA.prefix}→${a.nodeB.prefix}: ${K}`,`${a.nodeB.prefix}→${a.nodeA.prefix}: ${oA}`].join(` +`);return p.jsx("div",{className:` + absolute z-[700] overflow-hidden + /* Mobile: full-width bottom sheet with breathing room */ + bottom-2 left-2 right-2 + /* sm+: right-aligned floating panel */ + sm:bottom-16 sm:left-auto sm:right-4 sm:w-[280px] + `,children:p.jsxs("div",{className:` + map-control-surface flex flex-col + /* Mobile: cap at 45vh so map stays visible */ + max-h-[45vh] + /* sm+: taller allowance */ + sm:max-h-[420px] + `,children:[p.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 sm:py-2 min-h-[44px] sm:min-h-0 border-b border-edge-subtle",children:[p.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[p.jsx(tl,{className:"w-4 h-4 sm:w-3.5 sm:h-3.5 text-sys-green shrink-0"}),p.jsx(Gn,{prefix:a.nodeA.prefix,name:z}),p.jsx("span",{className:"type-data-xs text-fg-muted",children:"↔"}),p.jsx(Gn,{prefix:a.nodeB.prefix,name:Y})]}),p.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[q>0&&p.jsx("span",{className:"type-data-xs text-fg-muted",title:Ci(q),children:Oo(q)}),p.jsx(Nt,{plain:!0,color:"muted",onClick:u,className:"!p-1.5 sm:!p-0.5 !rounded-md min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 flex items-center justify-center",children:p.jsx(Mn,{className:"w-4 h-4 sm:w-3.5 sm:h-3.5"})})]})]}),p.jsxs("div",{className:"px-3 py-2.5 border-b border-edge-subtle",children:[p.jsxs("div",{className:"space-y-1.5 mb-2",children:[p.jsxs("div",{className:"flex items-center justify-between cursor-help",title:`${a.nodeA.prefix}→${a.nodeB.prefix}: mean of ${((UA=a.aToB)==null?void 0:UA.count)??0} measurements`,children:[p.jsxs("span",{className:"flex items-center gap-1",children:[p.jsx(Gn,{prefix:a.nodeA.prefix,name:z}),p.jsx("span",{className:"type-data-xs text-fg-muted",children:"→"}),p.jsx(Gn,{prefix:a.nodeB.prefix,name:Y})]}),a.aToB?p.jsxs("span",{className:`type-data-sm tabular-nums font-semibold ${w0(a.aToB.mean,k)}`,children:[a.aToB.mean.toFixed(1),p.jsx("span",{className:"text-fg-muted font-normal ml-0.5",children:"dB"})]}):p.jsx("span",{className:"type-data-sm text-fg-muted",children:"—"})]}),p.jsxs("div",{className:"flex items-center justify-between cursor-help",title:`${a.nodeB.prefix}→${a.nodeA.prefix}: mean of ${((vA=a.bToA)==null?void 0:vA.count)??0} measurements`,children:[p.jsxs("span",{className:"flex items-center gap-1",children:[p.jsx(Gn,{prefix:a.nodeB.prefix,name:Y}),p.jsx("span",{className:"type-data-xs text-fg-muted",children:"→"}),p.jsx(Gn,{prefix:a.nodeA.prefix,name:z})]}),a.bToA?p.jsxs("span",{className:`type-data-sm tabular-nums font-semibold ${w0(a.bToA.mean,k)}`,children:[a.bToA.mean.toFixed(1),p.jsx("span",{className:"text-fg-muted font-normal ml-0.5",children:"dB"})]}):p.jsx("span",{className:"type-data-sm text-fg-muted",children:"—"})]})]}),p.jsxs("div",{className:"grid grid-cols-2 gap-0 -mx-3 border-t border-edge-subtle",children:[p.jsx("div",{className:"px-3 pt-2 pb-1 border-r border-edge-subtle",children:p.jsx(Ki,{stats:a.aToB,direction:`${a.nodeA.prefix}→${a.nodeB.prefix}`,sf:k,noiseFloor:E})}),p.jsx("div",{className:"px-3 pt-2 pb-1",children:p.jsx(Ki,{stats:a.bToA,direction:`${a.nodeB.prefix}→${a.nodeA.prefix}`,sf:k,noiseFloor:E})})]})]}),p.jsxs("div",{className:"px-3 py-1.5 border-b border-edge-subtle",children:[U!=="insufficient"&&p.jsxs("div",{className:"flex items-center justify-between gap-2 py-[3px] cursor-help",title:X,children:[p.jsx("span",{className:"type-data-xs text-fg-muted",children:"Trend"}),p.jsx("span",{className:"data-box data-box-compact",children:p.jsxs("span",{className:"flex items-center gap-1",children:[Ff(U),p.jsx("span",{className:"text-fg-secondary capitalize",children:U})]})})]}),sA>0&&p.jsx(W0,{label:"Unique traces",value:sA.toString(),tooltip:uA})]}),Q.length>0&&p.jsxs("div",{className:"px-3 py-2 flex-1 min-h-0 flex flex-col",children:[p.jsxs("p",{className:"type-micro text-fg-secondary mb-1 shrink-0",children:["Source packets (",Q.length,")"]}),p.jsx("div",{className:"overflow-y-auto flex-1 min-h-0 overscroll-contain",style:{scrollbarGutter:"stable"},children:Q.map((cA,dA)=>{const jA=ul(cA),_A=jA?cl(cA,jA):null,YA=_A?Math.max(0,_A.length-1):0,ue=_A?_A.map(VA=>(d==null?void 0:d.get(VA))??VA).join(" → "):null,JA=F===dA,KA=cA.id??`${cA.packet_hash}-${cA.timestamp}`;return p.jsxs("div",{className:"rounded-sm",style:dA%2===1?Pf:void 0,children:[p.jsxs("button",{onClick:()=>B(JA?null:dA),className:"flex items-center gap-1.5 py-[3px] px-1 w-full text-left text-[10px] font-mono text-fg-secondary hover:text-fg-primary transition-colors group",children:[JA?p.jsx(Vs,{className:"w-2.5 h-2.5 text-fg-muted shrink-0"}):p.jsx(Iu,{className:"w-2.5 h-2.5 text-fg-muted shrink-0 opacity-0 group-hover:opacity-100 transition-opacity"}),p.jsx("span",{className:"text-fg-muted w-[52px] shrink-0",children:Ci(cA.timestamp)}),ue?p.jsx("span",{className:"text-fg-secondary truncate min-w-0",title:_A.join(" → "),children:ue}):p.jsx("span",{className:"text-fg-muted truncate min-w-0 italic",children:"path n/a"}),p.jsxs("span",{className:"text-fg-muted shrink-0",children:[YA,"h"]}),cA.snr!=null&&p.jsx("span",{className:`shrink-0 tabular-nums ${w0(cA.snr,k)}`,children:cA.snr.toFixed(1)})]}),JA&&p.jsxs("div",{className:"mb-1 mt-0.5 mx-1 pl-2 border-l border-edge-subtle space-y-0.5 text-[10px]",children:[cA.rssi!=null&&p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("span",{className:"text-fg-muted",children:"RSSI"}),p.jsxs("span",{className:"font-mono tabular-nums text-fg-secondary",children:[cA.rssi," dBm"]})]}),cA.snr!=null&&p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("span",{className:"text-fg-muted",children:"SNR"}),p.jsxs("span",{className:`font-mono tabular-nums ${w0(cA.snr,k)}`,children:[cA.snr.toFixed(1)," dB"]})]}),p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("span",{className:"text-fg-muted",children:"Route"}),p.jsx("span",{className:"font-mono text-fg-secondary",children:Pa(cA.route??cA.route_type)})]}),cA.packet_hash&&p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("span",{className:"text-fg-muted",children:"Hash"}),p.jsxs("button",{onClick:VA=>{VA.stopPropagation(),As(cA.packet_hash)},className:"flex items-center gap-1 font-mono text-fg-secondary hover:text-fg-primary transition-colors",title:"Copy packet hash",children:[p.jsx("span",{className:"truncate max-w-[120px]",children:cA.packet_hash}),p.jsx(X0,{className:"w-2.5 h-2.5 text-fg-muted shrink-0"})]})]}),cA.src_hash&&p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("span",{className:"text-fg-muted",children:"Source"}),p.jsx("span",{className:"font-mono text-fg-secondary truncate max-w-[140px]",title:cA.src_hash,children:cA.src_hash})]}),_A&&_A.length>0&&p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("span",{className:"text-fg-muted",children:"Path"}),p.jsx("span",{className:"font-mono text-fg-secondary truncate max-w-[140px]",title:_A.join(" → "),children:_A.join(" → ")})]})]})]},KA)})})]})]})})}function Of(a){const u=[];for(const d of a){if(d.is_outgoing)continue;const y=Lu(d.text);y&&u.push({lat:y.lat,lon:y.lon,timestampS:d.timestamp,senderName:d.sender_name??"Unknown",pathHops:d.path_hops,pathSnr:d.path_snr,pathRssi:d.path_rssi,msgSnr:d.msg_snr})}return u.sort((d,y)=>d.timestampS-y.timestampS),u}function zf(a){const u=new Set;for(const d of a)u.add(d.senderName);return[...u].sort((d,y)=>d.localeCompare(y))}function Zi(a,u){return a.filter(d=>d.senderName===u)}function Hf(a,u){if(a.length===0)return null;if(u<=a[0].timestampS)return{lo:0,hi:0,t:0};if(u>=a[a.length-1].timestampS){const E=a.length-1;return{lo:E,hi:E,t:0}}let d=0,y=a.length-1;for(;d>1;a[E].timestampS<=u?d=E:y=E}const x=a[y].timestampS-a[d].timestampS,b=x>0?(u-a[d].timestampS)/x:0;return{lo:d,hi:y,t:b}}function qi(a,u,d,y,x){const b=x*x,E=b*x;return .5*(2*u+(-a+d)*x+(2*a-5*u+4*d-y)*b+(-a+3*u-3*d+y)*E)}function Gf(a,u,d,y){const x=Math.PI/180,b=(y-u)*x,E=Math.sin(b)*Math.cos(d*x),F=Math.cos(a*x)*Math.sin(d*x)-Math.sin(a*x)*Math.cos(d*x)*Math.cos(b);return(Math.atan2(E,F)*180/Math.PI+360)%360}function fl(a,u){if(a.length===0)return null;const d=Hf(a,u);if(!d)return null;const{lo:y,hi:x,t:b}=d;if(y===x)return{lat:a[y].lat,lon:a[y].lon,bearing:null};const E=Math.max(0,y-1),F=y,B=x,k=Math.min(a.length-1,x+1),j=a[E],Q=a[F],z=a[B],Y=a[k];let U,q;E===F&&B===k?(U=Q.lat+(z.lat-Q.lat)*b,q=Q.lon+(z.lon-Q.lon)*b):(U=qi(j.lat,Q.lat,z.lat,Y.lat,b),q=qi(j.lon,Q.lon,z.lon,Y.lon,b));const sA=Gf(Q.lat,Q.lon,z.lat,z.lon);return{lat:U,lon:q,bearing:sA}}function Uf(a,u){if(a.length===0)return null;if(u<=a[0].timestampS)return a[0];if(u>=a[a.length-1].timestampS)return a[a.length-1];let d=0,y=a.length-1;for(;d>1;a[x].timestampS<=u?d=x:y=x}return a[d]}function Vf(a,u){const d=[];for(const x of a){if(x.timestampS>u)break;d.push([x.lon,x.lat])}const y=fl(a,u);if(y&&d.length>0){const x=d[d.length-1];(Math.abs(x[0]-y.lon)>1e-7||Math.abs(x[1]-y.lat)>1e-7)&&d.push([y.lon,y.lat])}return d}function Ji(a){const u=Math.max(0,Math.round(a)),d=Math.floor(u/3600),y=Math.floor(u%3600/60),x=u%60;return d>0?`${d}:${String(y).padStart(2,"0")}:${String(x).padStart(2,"0")}`:`${y}:${String(x).padStart(2,"0")}`}const Wf=[2,5,10,20],ks={isActive:!1,samples:[],senders:[],selectedSender:null,filteredSamples:[],isPlaying:!1,speed:5,currentTimeS:0,timeRange:{start:0,end:0}},Gt=$s((a,u)=>({...ks,loadFromChannel:d=>{const y=Of(d);if(y.length===0){a({...ks});return}const x=zf(y),b=x[0],E=Zi(y,b),F=E.length>0?{start:E[0].timestampS,end:E[E.length-1].timestampS}:{start:0,end:0};a({isActive:!0,samples:y,senders:x,selectedSender:b,filteredSamples:E,isPlaying:!1,currentTimeS:F.start,timeRange:F})},selectSender:d=>{const{samples:y}=u(),x=Zi(y,d),b=x.length>0?{start:x[0].timestampS,end:x[x.length-1].timestampS}:{start:0,end:0};a({selectedSender:d,filteredSamples:x,isPlaying:!1,currentTimeS:b.start,timeRange:b})},togglePlay:()=>{const{isPlaying:d,currentTimeS:y,timeRange:x}=u();d?a({isPlaying:!1}):y>=x.end?a({isPlaying:!0,currentTimeS:x.start}):a({isPlaying:!0})},pause:()=>a({isPlaying:!1}),setSpeed:d=>a({speed:d}),seek:d=>{const{timeRange:y}=u(),x=Math.max(y.start,Math.min(y.end,d));a({currentTimeS:x})},stopReplay:()=>a({...ks}),tick:d=>{const{isPlaying:y,speed:x,currentTimeS:b,timeRange:E}=u();if(!y)return;const F=x*(d/1e3),B=b+F;B>=E.end?a({currentTimeS:E.end,isPlaying:!1}):a({currentTimeS:B})}})),Zs=()=>Gt(a=>a.isActive),qs=()=>Gt(a=>a.isPlaying),hl=()=>Gt(a=>a.currentTimeS),Yf=()=>Gt(a=>a.speed),$f=()=>Gt(a=>a.timeRange),Kf=()=>Gt(a=>a.senders),Zf=()=>Gt(a=>a.selectedSender),qf=()=>Gt(a=>a.filteredSamples);function dl(){const{isActive:a,filteredSamples:u,currentTimeS:d}=Gt.getState();return!a||u.length===0?null:fl(u,d)}function Jf(){const{isActive:a,filteredSamples:u,currentTimeS:d}=Gt.getState();if(!a||u.length===0)return;const y=Uf(u,d);return y==null?void 0:y.pathHops}function Xf({channels:a,messages:u}){const d=R.useMemo(()=>a.find(b=>b.name.toLowerCase().includes("wardrive"))??null,[a]),y=R.useMemo(()=>d?u.get(`ch:${d.index}`)??[]:[],[d,u]);if(!d||y.length===0)return null;const x=()=>{Gt.getState().loadFromChannel(y)};return p.jsxs("button",{onClick:x,className:"map-tool-btn flex items-center gap-2 w-full text-left radius-inner transition-base",style:{padding:"0.5rem 0.625rem"},title:`Replay #wardrive journey (${y.length} msgs)`,"aria-label":"Replay #wardrive journey",children:[p.jsx(Zu,{className:"w-3.5 h-3.5 shrink-0 text-fg-secondary"}),p.jsx("span",{className:"text-fg-secondary",style:{fontFamily:"ui-monospace, SFMono-Regular, monospace",fontSize:"0.6875rem",fontWeight:500,letterSpacing:"-0.01em",lineHeight:1},children:"Replay"}),p.jsx("span",{className:"ml-auto text-fg-muted tabular-nums",style:{fontSize:"0.625rem"},children:y.length})]})}function A2(){const a=Zs(),u=qs(),d=hl(),y=Yf(),x=$f(),b=Zf(),E=Kf(),{togglePlay:F,setSpeed:B,seek:k,stopReplay:j,selectSender:Q}=Gt.getState(),z=x.end-x.start,Y=d-x.start,U=z>0?Y/z:0,q=R.useCallback(oA=>{const uA=parseFloat(oA.target.value)/100;k(x.start+uA*z)},[k,x.start,z]),[sA,X]=R.useState(!1),K=R.useRef(null);return R.useEffect(()=>{if(!sA)return;const oA=uA=>{var kA;(kA=K.current)!=null&&kA.contains(uA.target)||X(!1)};return document.addEventListener("mousedown",oA),()=>document.removeEventListener("mousedown",oA)},[sA]),a?p.jsx("div",{className:"absolute bottom-3 left-3 right-3 z-[700] sm:bottom-4 sm:left-4 sm:right-4",children:p.jsxs("div",{className:"map-control-surface flex items-center gap-2 px-2.5 py-2 sm:gap-3 sm:px-3",children:[p.jsx("button",{onClick:j,className:"p-1 rounded text-fg-muted hover:text-fg-primary hover:bg-[var(--map-ui-hover,var(--elevated))] transition-colors shrink-0",title:"Stop replay","aria-label":"Stop replay",children:p.jsx(Mn,{className:"w-3.5 h-3.5"})}),p.jsx("button",{onClick:F,className:"p-1.5 rounded-full bg-sys-blue/20 text-sys-blue hover:bg-sys-blue/30 transition-colors shrink-0",title:u?"Pause":"Play","aria-label":u?"Pause replay":"Play replay",children:u?p.jsx(Ga,{className:"w-3.5 h-3.5"}):p.jsx(Ua,{className:"w-3.5 h-3.5"})}),p.jsxs("div",{ref:K,className:"relative shrink-0",children:[E.length>1?p.jsxs("button",{onClick:()=>X(!sA),className:"flex items-center gap-1 text-xs font-medium text-fg-secondary hover:text-fg-primary transition-colors max-w-[100px] sm:max-w-[140px]",title:`Replaying: ${b}`,children:[p.jsx("span",{className:"truncate",children:b}),p.jsx(Vs,{className:Or("w-2.5 h-2.5 shrink-0 transition-transform",sA&&"rotate-180")})]}):p.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate max-w-[100px] sm:max-w-[140px] block",children:b}),sA&&E.length>1&&p.jsx("div",{className:"absolute bottom-full mb-1 left-0 z-50 map-control-surface min-w-[120px] py-1",children:E.map(oA=>p.jsx("button",{onClick:()=>{Q(oA),X(!1)},className:Or("w-full px-3 py-1 text-left text-xs transition-colors",oA===b?"text-sys-blue font-medium":"text-fg-secondary hover:text-fg-primary hover:bg-[var(--map-ui-hover,var(--elevated))]"),children:oA},oA))})]}),p.jsx("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:p.jsx("input",{type:"range",min:0,max:100,step:.1,value:U*100,onChange:q,className:"replay-scrubber w-full h-1 appearance-none bg-edge-subtle rounded-full cursor-pointer","aria-label":"Replay timeline","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(U*100)})}),p.jsxs("span",{className:"text-[10px] sm:text-xs tabular-nums text-fg-muted whitespace-nowrap shrink-0",children:[Ji(Y)," / ",Ji(z)]}),p.jsx("div",{className:"flex items-center gap-0.5 shrink-0",children:Wf.map(oA=>p.jsxs("button",{onClick:()=>B(oA),className:Or("px-1.5 py-0.5 rounded text-[10px] sm:text-xs font-medium transition-colors",oA===y?"bg-sys-blue/20 text-sys-blue shadow-[inset_0_0_0_1px_var(--sys-blue)]":"text-fg-muted hover:text-fg-secondary hover:bg-[var(--map-ui-hover,var(--elevated))]"),title:`${oA}× speed`,"aria-label":`${oA} times speed`,"aria-pressed":oA===y,children:[oA,"×"]},oA))})]})}):null}const ml=[{target:"Sparklines",fn:"sparklines",minStage:2}];Ko(ml);const pl=R.memo(function({nodeHash:u,width:d=60,height:y=20,color:x,showArea:b=!0,showTooltip:E=!1,className:F=""}){$o(ml);const B=Va(u),k=Wa(),Q=!Ho().backgroundLoadComplete||k,z=typeof d=="number"?d:60;return p.jsx(Nu,{data:B,width:z,height:y,color:x,isLoading:Q,className:F})});function e2(a){return a===null?"—":a<1e3?`${Math.round(a)}m`:`${(a/1e3).toFixed(1)}km`}function t2(a){const u=new Date(a*1e3);return`${(u.getMonth()+1).toString().padStart(2,"0")}/${u.getDate().toString().padStart(2,"0")}`}function r2({txDelayRec:a,networkRole:u,roleTitles:d,dataConfidence:y,dataQualityTitles:x}){const[b,E]=R.useState(!1),F=a.floodFactor??a.txDelayFactor,B=a.directFactor??a.directTxDelayFactor,k=async()=>{const j=`set txdelay ${F.toFixed(1)} +set direct.txdelay ${B.toFixed(1)}`;await As(j),E(!0),setTimeout(()=>E(!1),1500)};return p.jsxs("div",{className:"flex flex-col gap-1.5 text-sm",children:[(u||y)&&p.jsxs("div",{className:"flex items-center gap-2",children:[u&&p.jsx(gt,{color:Pu[u],compact:!0,title:d[u],children:u}),y&&p.jsxs(gt,{color:Qu[y],compact:!0,title:x[y],children:[y," data"]})]}),p.jsxs("button",{onClick:k,className:"flex items-center gap-2 py-1.5 px-2 bg-subtle-fill hover:bg-subtle-fill-hover rounded transition-colors group",title:"Click to copy CLI commands",children:[p.jsx(sc,{className:"w-3.5 h-3.5 text-sys-amber shrink-0"}),p.jsx("span",{className:"text-fg-muted",children:"TxDelay"}),p.jsxs("div",{className:"flex gap-2",children:[p.jsxs("div",{className:"flex items-center gap-1",children:[p.jsx("span",{className:"text-fg-muted",children:"F"}),p.jsxs("span",{className:"data-box text-sys-amber",children:["×",F.toFixed(1)]})]}),p.jsxs("div",{className:"flex items-center gap-1",children:[p.jsx("span",{className:"text-fg-muted",children:"D"}),p.jsxs("span",{className:"data-box text-sys-amber",children:["×",B.toFixed(1)]})]})]}),b?p.jsx(Yn,{className:"w-3.5 h-3.5 text-sys-green ml-auto"}):p.jsx(X0,{className:"w-3.5 h-3.5 text-fg-muted opacity-0 group-hover:opacity-100 transition-opacity ml-auto"})]})]})}function n2({hash:a,hashPrefix:u,name:d,isHub:y,isGateway:x,isBackbone:b,isZeroHop:E,isMobile:F,isRoomServer:B,isStale:k,lastSeenTimestamp:j,centrality:Q,affinity:z,meanSnr:Y,meanRssi:U,neighbor:q,onRemove:sA,txDelayRec:X,hideHeader:K=!1}){const[oA,uA]=R.useState(!1),kA=async()=>{await As(a),uA(!0),setTimeout(()=>uA(!1),1500)},lA=E?"Direct":z!=null&&z.typicalHopPosition?`${z.typicalHopPosition}-hop`:null,aA=X&&!X.insufficientData,BA={hub:"Hub: High-connectivity node that bridges many paths",backbone:"Backbone: Critical relay with high traffic",relay:"Relay: Standard forwarding node",edge:"Edge: Peripheral node"},EA={high:"1000+ packets",medium:"500-999 packets",low:"100-499 packets",insufficient:"Insufficient data"};return p.jsxs("div",{children:[!K&&p.jsx("div",{className:"text-[14px] font-semibold text-fg-primary leading-tight truncate mb-1",children:d}),!K&&p.jsxs("div",{className:"flex items-center gap-1 flex-wrap mb-1.5",children:[p.jsx("code",{className:"type-data-xs text-fg-secondary bg-data-box-bg border border-data-box-border px-1 py-0.5 rounded",children:u}),p.jsx("button",{onClick:kA,className:"p-0.5 hover:bg-subtle-fill-hover rounded transition-colors",title:"Copy full hash",children:oA?p.jsx(Yn,{className:"w-3 h-3 text-sys-green"}):p.jsx(X0,{className:"w-3 h-3 text-fg-secondary"})}),p.jsx(Xo,{hash:a,size:"sm"}),lA&&p.jsx(gt,{color:E?$0.direct:$0.multihop,compact:!0,children:lA}),q.is_repeater&&p.jsx(gt,{color:ur.repeater,compact:!0,children:"Rptr"}),y&&p.jsx(gt,{color:ur.hub,compact:!0,title:"Hub: ≥10% of last-hop traffic",children:"Hub"}),x&&!y&&p.jsx(gt,{color:ur.gateway,compact:!0,title:"Gateway: 7-10% of last-hop traffic",children:"Gate"}),b&&p.jsx(gt,{color:ur.backbone,compact:!0,title:"Backbone",children:"Bone"}),F&&p.jsx(gt,{color:ur.mobile,compact:!0,children:"Mobile"}),B&&p.jsx(gt,{color:ur.room,compact:!0,children:"Room"}),k&&j&&p.jsxs(gt,{compact:!0,title:"Neighbor not heard in 7+ days",children:["Idle ",t2(j)]})]}),p.jsx("div",{title:"7-day activity trend (6-hour buckets)",children:p.jsx(pl,{nodeHash:a,width:224,height:28,showArea:!0,showTooltip:!0,className:"w-full"})}),p.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5 text-sm text-fg-secondary mt-2",children:[p.jsxs("span",{className:"flex items-center gap-0.5",title:q.last_seen?`Last heard: ${new Date(q.last_seen*1e3).toLocaleString()}`:"Last heard time",children:[p.jsx(Jo,{className:"w-3 h-3 text-fg-muted shrink-0"}),p.jsx("span",{className:"font-mono",children:Oo(q.last_seen)})]}),(z==null?void 0:z.distanceMeters)&&p.jsxs("span",{className:"flex items-center gap-0.5",title:"Line-of-sight distance from local node",children:[p.jsx(Fu,{className:"w-3 h-3 text-fg-muted shrink-0"}),p.jsx("span",{className:"font-mono font-semibold text-fg-primary",children:e2(z.distanceMeters)})]}),q.latitude&&q.longitude&&q.latitude!==0&&q.longitude!==0&&p.jsxs("span",{className:"flex items-center gap-0.5",title:"GPS coordinates (lat, lon)",children:[p.jsx(Ou,{className:"w-3 h-3 text-fg-muted shrink-0"}),p.jsxs("span",{className:"font-mono text-fg-muted",children:[q.latitude.toFixed(2),", ",q.longitude.toFixed(2)]})]})]}),p.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1.5 text-sm mt-2",children:[p.jsxs("div",{className:"flex justify-between items-center gap-2",title:"Total packets seen from this node",children:[p.jsx("span",{className:"text-fg-muted",children:"Packets"}),p.jsx("span",{className:"data-box",children:(z==null?void 0:z.frequency)||0})]}),p.jsxs("div",{className:"flex justify-between items-center gap-2",title:"ADVERT beacon packets received",children:[p.jsx("span",{className:"text-fg-muted",children:"Adverts"}),p.jsx("span",{className:"data-box",children:q.advert_count||0})]}),E&&Y!==void 0&&p.jsxs("div",{className:"flex justify-between items-center gap-2",title:"Average Signal-to-Noise Ratio (direct zero-hop)",children:[p.jsx("span",{className:"text-fg-muted",children:"SNR"}),p.jsxs("span",{className:"data-box",children:[Y.toFixed(1)," dB"]})]}),E&&U!==void 0&&p.jsxs("div",{className:"flex justify-between items-center gap-2",title:"Average Received Signal Strength (direct zero-hop)",children:[p.jsx("span",{className:"text-fg-muted",children:"RSSI"}),p.jsxs("span",{className:"data-box",children:[Math.round(U)," dBm"]})]})]}),aA&&p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"border-t border-edge-subtle mt-2.5 mb-2"}),p.jsx(r2,{txDelayRec:X,networkRole:X.networkRole,roleTitles:BA,dataConfidence:X.dataConfidence,dataQualityTitles:EA})]}),sA&&p.jsx("button",{onClick:sA,className:"w-full text-center text-sm mt-2 py-3 sm:py-1.5 rounded text-fg-muted hover:text-sys-red hover:bg-sys-red/10 transition-colors",children:"Remove from Contacts"})]})}function s2(a){const u=new Date(a*1e3);return`${(u.getMonth()+1).toString().padStart(2,"0")}/${u.getDate().toString().padStart(2,"0")}`}function i2({data:a,localNode:u,localColor:d,onClose:y,onRemove:x}){var k,j,Q,z;const[b,E]=R.useState(!1);R.useEffect(()=>{if(!a)return;const Y=U=>{U.key==="Escape"&&y()};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[a,y]);const F=async()=>{a!=null&&a.hash&&(await As(a.hash),E(!0),setTimeout(()=>E(!1),1500))},B=a!=null&&a.isZeroHop?"Direct":(k=a==null?void 0:a.affinity)!=null&&k.typicalHopPosition?`${a.affinity.typicalHopPosition}-hop`:null;return p.jsx(Sr,{children:a&&p.jsx(Xt.div,{className:"map-node-panel",initial:{opacity:0,y:16},animate:{opacity:1,y:0},exit:{opacity:0,y:16},transition:En.smooth,children:p.jsxs("div",{className:"map-control-surface flex flex-col max-h-[38dvh] sm:max-h-[50vh]",children:[p.jsx("div",{className:"map-node-panel-drag-handle sm:hidden"}),p.jsxs("div",{className:"flex flex-col gap-1.5 px-3 py-2.5 shrink-0",children:[p.jsxs("div",{className:"flex items-start justify-between gap-2",children:[p.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:[p.jsx("span",{className:"text-sm font-semibold truncate text-fg-primary",children:a.name||"Unknown"}),a.hash&&p.jsxs(p.Fragment,{children:[p.jsx("code",{className:"type-data-xs text-fg-secondary bg-data-box-bg border border-data-box-border px-1 py-0.5 rounded ml-1",children:a.hashPrefix||a.hash.substring(0,2)}),p.jsx("button",{onClick:F,className:"p-2 -m-1.5 sm:p-0.5 sm:m-0 hover:bg-subtle-fill-hover rounded transition-colors",title:"Copy full hash",children:b?p.jsx(Yn,{className:"w-3 h-3 text-sys-green"}):p.jsx(X0,{className:"w-3 h-3 text-fg-secondary"})}),p.jsx(Xo,{hash:a.hash,size:"sm"})]})]}),p.jsx(Nt,{plain:!0,color:"muted",onClick:y,className:"!p-1 !rounded-md -mr-1 -mt-1 hover:bg-subtle-fill-hover min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 flex items-center justify-center","aria-label":"Close node detail",children:p.jsx(Mn,{className:"w-4 h-4"})})]}),(B||((j=a.neighbor)==null?void 0:j.is_repeater)||a.isHub||a.isGateway&&!a.isHub||a.isBackbone||a.isMobile||a.isRoomServer||a.isStale&&a.lastSeenTimestamp)&&p.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[B&&p.jsx(gt,{color:a.isZeroHop?$0.direct:$0.multihop,compact:!0,title:a.isZeroHop?"Direct RF contact (zero-hop)":`${((Q=a.affinity)==null?void 0:Q.typicalHopPosition)??"?"} hops from local node`,children:B}),((z=a.neighbor)==null?void 0:z.is_repeater)&&p.jsx(gt,{color:ur.repeater,compact:!0,title:"Repeater node (forwards packets)",children:"Rptr"}),a.isHub&&p.jsx(gt,{color:ur.hub,compact:!0,title:"Hub: ≥10% of last-hop traffic",children:"Hub"}),a.isGateway&&!a.isHub&&p.jsx(gt,{color:ur.gateway,compact:!0,title:"Gateway: 7-10% of last-hop traffic",children:"Gate"}),a.isBackbone&&p.jsx(gt,{color:ur.backbone,compact:!0,title:"Backbone: critical relay with high traffic",children:"Bone"}),a.isMobile&&p.jsx(gt,{color:ur.mobile,compact:!0,title:"Mobile repeater (path volatility detected)",children:"Mobile"}),a.isRoomServer&&p.jsx(gt,{color:ur.room,compact:!0,title:"Room server node",children:"Room"}),a.isStale&&a.lastSeenTimestamp&&p.jsxs(gt,{compact:!0,title:"Neighbor not heard in 7+ days",children:["Idle ",s2(a.lastSeenTimestamp)]})]})]}),p.jsx("div",{className:"overflow-y-auto flex-1 min-h-0 overscroll-contain px-3 pt-2 pb-3",children:a.isLocal?p.jsxs("div",{className:"text-sm",children:[p.jsx("div",{className:"mb-2",children:p.jsx("span",{style:{color:d},className:"font-medium",children:"This Node (Local)"})}),a.hash&&p.jsx("div",{className:"mb-2",children:p.jsx(pl,{nodeHash:a.hash,width:224,height:28,showArea:!0,showTooltip:!0,className:"w-full"})}),u&&p.jsxs("div",{className:"text-xs text-fg-muted font-mono border-t border-edge-subtle pt-2",children:[u.latitude.toFixed(5),", ",u.longitude.toFixed(5)]})]}):a.neighbor&&a.hash?p.jsx(n2,{hash:a.hash,hashPrefix:a.hashPrefix,name:a.name,isHub:a.isHub,isGateway:a.isGateway,isBackbone:a.isBackbone,isZeroHop:a.isZeroHop,isMobile:a.isMobile,isRoomServer:a.isRoomServer,isStale:a.isStale,lastSeenTimestamp:a.lastSeenTimestamp,centrality:a.centrality,affinity:a.affinity,meanSnr:a.meanSnr,meanRssi:a.meanRssi,neighbor:a.neighbor,txDelayRec:a.txDelayRec,onRemove:x?()=>x(a.hash,a.name):void 0,hideHeader:!0}):null})]})})})}const o2={getItem:a=>{try{return localStorage.getItem(a)}catch{return null}},setItem:(a,u)=>{try{localStorage.setItem(a,u)}catch{}},removeItem:a=>{try{localStorage.removeItem(a)}catch{}}},gl=$s()(pu(a=>({isEnabled:!1,toggle:()=>a(u=>({isEnabled:!u.isEnabled})),setEnabled:u=>a({isEnabled:u})}),{name:"pymc-live-trace",storage:gu(()=>o2)})),l2=()=>gl(a=>a.isEnabled),a2=()=>gl(a=>a.toggle);var Ft=(function(a){a=a||{};var u=typeof a<"u"?a:{},d={},y;for(y in u)u.hasOwnProperty(y)&&(d[y]=u[y]);var x="";function b(nA){return u.locateFile?u.locateFile(nA,x):x+nA}var E;typeof document<"u"&&document.currentScript&&(x=document.currentScript.src),x.indexOf("blob:")!==0?x=x.substr(0,x.lastIndexOf("/")+1):x="",E=function(yA,RA,xA){var t=new XMLHttpRequest;t.open("GET",yA,!0),t.responseType="arraybuffer",t.onload=function(){if(t.status==200||t.status==0&&t.response){RA(t.response);return}var ge=gr(yA);if(ge){RA(ge.buffer);return}xA()},t.onerror=xA,t.send(null)};var F=u.print||console.log.bind(console),B=u.printErr||console.warn.bind(console);for(y in d)d.hasOwnProperty(y)&&(u[y]=d[y]);d=null,u.arguments&&u.arguments;var k=0,j=function(nA){k=nA},Q=function(){return k},z=8;function Y(nA,yA,RA,xA){switch(RA=RA||"i8",RA.charAt(RA.length-1)==="*"&&(RA="i32"),RA){case"i1":IA[nA>>0]=yA;break;case"i8":IA[nA>>0]=yA;break;case"i16":FA[nA>>1]=yA;break;case"i32":UA[nA>>2]=yA;break;case"i64":ct=[yA>>>0,(ze=yA,+ke(ze)>=1?ze>0?(Ke(+pe(ze/4294967296),4294967295)|0)>>>0:~~+Ee((ze-+(~~ze>>>0))/4294967296)>>>0:0)],UA[nA>>2]=ct[0],UA[nA+4>>2]=ct[1];break;case"float":vA[nA>>2]=yA;break;case"double":cA[nA>>3]=yA;break;default:yt("invalid type for setValue: "+RA)}}function U(nA,yA,RA){switch(yA=yA||"i8",yA.charAt(yA.length-1)==="*"&&(yA="i32"),yA){case"i1":return IA[nA>>0];case"i8":return IA[nA>>0];case"i16":return FA[nA>>1];case"i32":return UA[nA>>2];case"i64":return UA[nA>>2];case"float":return vA[nA>>2];case"double":return cA[nA>>3];default:yt("invalid type for getValue: "+yA)}return null}var q=!1;function sA(nA,yA){nA||yt("Assertion failed: "+yA)}function X(nA){var yA=u["_"+nA];return sA(yA,"Cannot call unknown function "+nA+", make sure it is exported"),yA}function K(nA,yA,RA,xA,t){var C={string:function(se){var et=0;if(se!=null&&se!==0){var St=(se.length<<2)+1;et=ft(St),BA(se,et,St)}return et},array:function(se){var et=ft(se.length);return EA(se,et),et}};function ge(se){return yA==="string"?lA(se):yA==="boolean"?!!se:se}var De=X(nA),Le=[],ee=0;if(xA)for(var Ce=0;Ce=xA);)++t;if(t-yA>16&&nA.subarray&&uA)return uA.decode(nA.subarray(yA,t));for(var C="";yA>10,56320|ee&1023)}}return C}function lA(nA,yA){return nA?kA(LA,nA,yA):""}function aA(nA,yA,RA,xA){if(!(xA>0))return 0;for(var t=RA,C=RA+xA-1,ge=0;ge=55296&&De<=57343){var Le=nA.charCodeAt(++ge);De=65536+((De&1023)<<10)|Le&1023}if(De<=127){if(RA>=C)break;yA[RA++]=De}else if(De<=2047){if(RA+1>=C)break;yA[RA++]=192|De>>6,yA[RA++]=128|De&63}else if(De<=65535){if(RA+2>=C)break;yA[RA++]=224|De>>12,yA[RA++]=128|De>>6&63,yA[RA++]=128|De&63}else{if(RA+3>=C)break;yA[RA++]=240|De>>18,yA[RA++]=128|De>>12&63,yA[RA++]=128|De>>6&63,yA[RA++]=128|De&63}}return yA[RA]=0,RA-t}function BA(nA,yA,RA){return aA(nA,LA,yA,RA)}typeof TextDecoder<"u"&&new TextDecoder("utf-16le");function EA(nA,yA){IA.set(nA,yA)}function bA(nA,yA){return nA%yA>0&&(nA+=yA-nA%yA),nA}var fA,IA,LA,FA,UA,vA,cA;function dA(nA){fA=nA,u.HEAP8=IA=new Int8Array(nA),u.HEAP16=FA=new Int16Array(nA),u.HEAP32=UA=new Int32Array(nA),u.HEAPU8=LA=new Uint8Array(nA),u.HEAPU16=new Uint16Array(nA),u.HEAPU32=new Uint32Array(nA),u.HEAPF32=vA=new Float32Array(nA),u.HEAPF64=cA=new Float64Array(nA)}var jA=5271536,_A=28624,YA=u.TOTAL_MEMORY||33554432;u.buffer?fA=u.buffer:fA=new ArrayBuffer(YA),YA=fA.byteLength,dA(fA),UA[_A>>2]=jA;function ue(nA){for(;nA.length>0;){var yA=nA.shift();if(typeof yA=="function"){yA();continue}var RA=yA.func;typeof RA=="number"?yA.arg===void 0?u.dynCall_v(RA):u.dynCall_vi(RA,yA.arg):RA(yA.arg===void 0?null:yA.arg)}}var JA=[],KA=[],VA=[],je=[];function Ie(){if(u.preRun)for(typeof u.preRun=="function"&&(u.preRun=[u.preRun]);u.preRun.length;)$e(u.preRun.shift());ue(JA)}function oe(){ue(KA)}function me(){ue(VA)}function we(){if(u.postRun)for(typeof u.postRun=="function"&&(u.postRun=[u.postRun]);u.postRun.length;)be(u.postRun.shift());ue(je)}function $e(nA){JA.unshift(nA)}function be(nA){je.unshift(nA)}var ke=Math.abs,Ee=Math.ceil,pe=Math.floor,Ke=Math.min,Je=0,At=null;function it(nA){Je++,u.monitorRunDependencies&&u.monitorRunDependencies(Je)}function Et(nA){if(Je--,u.monitorRunDependencies&&u.monitorRunDependencies(Je),Je==0&&At){var yA=At;At=null,yA()}}u.preloadedImages={},u.preloadedAudios={};var Qe=null,Xe="data:application/octet-stream;base64,";function Me(nA){return String.prototype.startsWith?nA.startsWith(Xe):nA.indexOf(Xe)===0}var ze,ct;Qe="data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAQAAAAIAAAADAAAABAAAAAUAAAAGAAAAAQAAAAQAAAADAAAABgAAAAUAAAACAAAAAAAAAAIAAAADAAAAAQAAAAQAAAAGAAAAAAAAAAUAAAADAAAABgAAAAQAAAAFAAAAAAAAAAEAAAACAAAABAAAAAUAAAAGAAAAAAAAAAIAAAADAAAAAQAAAAUAAAACAAAAAAAAAAEAAAADAAAABgAAAAQAAAAGAAAAAAAAAAUAAAACAAAAAQAAAAQAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAIAAAADAAAAAAAAAAAAAAACAAAAAAAAAAEAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAYAAAAAAAAABQAAAAAAAAAAAAAABAAAAAUAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAYAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAIAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAIAAAADAAAABQAAAAYAAAAAAAAAAQAAAAIAAAADAAAABAAAAAYAAAAAAAAAAQAAAAIAAAADAAAABAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAYAAAAAAAAAAwAAAAIAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAFAAAABAAAAAAAAAABAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAYAAAAAAAAABAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAFAAAAAgAAAAQAAAADAAAACAAAAAEAAAAHAAAABgAAAAkAAAAAAAAAAwAAAAIAAAACAAAABgAAAAoAAAALAAAAAAAAAAEAAAAFAAAAAwAAAA0AAAABAAAABwAAAAQAAAAMAAAAAAAAAAQAAAB/AAAADwAAAAgAAAADAAAAAAAAAAwAAAAFAAAAAgAAABIAAAAKAAAACAAAAAAAAAAQAAAABgAAAA4AAAALAAAAEQAAAAEAAAAJAAAAAgAAAAcAAAAVAAAACQAAABMAAAADAAAADQAAAAEAAAAIAAAABQAAABYAAAAQAAAABAAAAAAAAAAPAAAACQAAABMAAAAOAAAAFAAAAAEAAAAHAAAABgAAAAoAAAALAAAAGAAAABcAAAAFAAAAAgAAABIAAAALAAAAEQAAABcAAAAZAAAAAgAAAAYAAAAKAAAADAAAABwAAAANAAAAGgAAAAQAAAAPAAAAAwAAAA0AAAAaAAAAFQAAAB0AAAADAAAADAAAAAcAAAAOAAAAfwAAABEAAAAbAAAACQAAABQAAAAGAAAADwAAABYAAAAcAAAAHwAAAAQAAAAIAAAADAAAABAAAAASAAAAIQAAAB4AAAAIAAAABQAAABYAAAARAAAACwAAAA4AAAAGAAAAIwAAABkAAAAbAAAAEgAAABgAAAAeAAAAIAAAAAUAAAAKAAAAEAAAABMAAAAiAAAAFAAAACQAAAAHAAAAFQAAAAkAAAAUAAAADgAAABMAAAAJAAAAKAAAABsAAAAkAAAAFQAAACYAAAATAAAAIgAAAA0AAAAdAAAABwAAABYAAAAQAAAAKQAAACEAAAAPAAAACAAAAB8AAAAXAAAAGAAAAAsAAAAKAAAAJwAAACUAAAAZAAAAGAAAAH8AAAAgAAAAJQAAAAoAAAAXAAAAEgAAABkAAAAXAAAAEQAAAAsAAAAtAAAAJwAAACMAAAAaAAAAKgAAAB0AAAArAAAADAAAABwAAAANAAAAGwAAACgAAAAjAAAALgAAAA4AAAAUAAAAEQAAABwAAAAfAAAAKgAAACwAAAAMAAAADwAAABoAAAAdAAAAKwAAACYAAAAvAAAADQAAABoAAAAVAAAAHgAAACAAAAAwAAAAMgAAABAAAAASAAAAIQAAAB8AAAApAAAALAAAADUAAAAPAAAAFgAAABwAAAAgAAAAHgAAABgAAAASAAAANAAAADIAAAAlAAAAIQAAAB4AAAAxAAAAMAAAABYAAAAQAAAAKQAAACIAAAATAAAAJgAAABUAAAA2AAAAJAAAADMAAAAjAAAALgAAAC0AAAA4AAAAEQAAABsAAAAZAAAAJAAAABQAAAAiAAAAEwAAADcAAAAoAAAANgAAACUAAAAnAAAANAAAADkAAAAYAAAAFwAAACAAAAAmAAAAfwAAACIAAAAzAAAAHQAAAC8AAAAVAAAAJwAAACUAAAAZAAAAFwAAADsAAAA5AAAALQAAACgAAAAbAAAAJAAAABQAAAA8AAAALgAAADcAAAApAAAAMQAAADUAAAA9AAAAFgAAACEAAAAfAAAAKgAAADoAAAArAAAAPgAAABwAAAAsAAAAGgAAACsAAAA+AAAALwAAAEAAAAAaAAAAKgAAAB0AAAAsAAAANQAAADoAAABBAAAAHAAAAB8AAAAqAAAALQAAACcAAAAjAAAAGQAAAD8AAAA7AAAAOAAAAC4AAAA8AAAAOAAAAEQAAAAbAAAAKAAAACMAAAAvAAAAJgAAACsAAAAdAAAARQAAADMAAABAAAAAMAAAADEAAAAeAAAAIQAAAEMAAABCAAAAMgAAADEAAAB/AAAAPQAAAEIAAAAhAAAAMAAAACkAAAAyAAAAMAAAACAAAAAeAAAARgAAAEMAAAA0AAAAMwAAAEUAAAA2AAAARwAAACYAAAAvAAAAIgAAADQAAAA5AAAARgAAAEoAAAAgAAAAJQAAADIAAAA1AAAAPQAAAEEAAABLAAAAHwAAACkAAAAsAAAANgAAAEcAAAA3AAAASQAAACIAAAAzAAAAJAAAADcAAAAoAAAANgAAACQAAABIAAAAPAAAAEkAAAA4AAAARAAAAD8AAABNAAAAIwAAAC4AAAAtAAAAOQAAADsAAABKAAAATgAAACUAAAAnAAAANAAAADoAAAB/AAAAPgAAAEwAAAAsAAAAQQAAACoAAAA7AAAAPwAAAE4AAABPAAAAJwAAAC0AAAA5AAAAPAAAAEgAAABEAAAAUAAAACgAAAA3AAAALgAAAD0AAAA1AAAAMQAAACkAAABRAAAASwAAAEIAAAA+AAAAKwAAADoAAAAqAAAAUgAAAEAAAABMAAAAPwAAAH8AAAA4AAAALQAAAE8AAAA7AAAATQAAAEAAAAAvAAAAPgAAACsAAABUAAAARQAAAFIAAABBAAAAOgAAADUAAAAsAAAAVgAAAEwAAABLAAAAQgAAAEMAAABRAAAAVQAAADEAAAAwAAAAPQAAAEMAAABCAAAAMgAAADAAAABXAAAAVQAAAEYAAABEAAAAOAAAADwAAAAuAAAAWgAAAE0AAABQAAAARQAAADMAAABAAAAALwAAAFkAAABHAAAAVAAAAEYAAABDAAAANAAAADIAAABTAAAAVwAAAEoAAABHAAAAWQAAAEkAAABbAAAAMwAAAEUAAAA2AAAASAAAAH8AAABJAAAANwAAAFAAAAA8AAAAWAAAAEkAAABbAAAASAAAAFgAAAA2AAAARwAAADcAAABKAAAATgAAAFMAAABcAAAANAAAADkAAABGAAAASwAAAEEAAAA9AAAANQAAAF4AAABWAAAAUQAAAEwAAABWAAAAUgAAAGAAAAA6AAAAQQAAAD4AAABNAAAAPwAAAEQAAAA4AAAAXQAAAE8AAABaAAAATgAAAEoAAAA7AAAAOQAAAF8AAABcAAAATwAAAE8AAABOAAAAPwAAADsAAABdAAAAXwAAAE0AAABQAAAARAAAAEgAAAA8AAAAYwAAAFoAAABYAAAAUQAAAFUAAABeAAAAZQAAAD0AAABCAAAASwAAAFIAAABgAAAAVAAAAGIAAAA+AAAATAAAAEAAAABTAAAAfwAAAEoAAABGAAAAZAAAAFcAAABcAAAAVAAAAEUAAABSAAAAQAAAAGEAAABZAAAAYgAAAFUAAABXAAAAZQAAAGYAAABCAAAAQwAAAFEAAABWAAAATAAAAEsAAABBAAAAaAAAAGAAAABeAAAAVwAAAFMAAABmAAAAZAAAAEMAAABGAAAAVQAAAFgAAABIAAAAWwAAAEkAAABjAAAAUAAAAGkAAABZAAAAYQAAAFsAAABnAAAARQAAAFQAAABHAAAAWgAAAE0AAABQAAAARAAAAGoAAABdAAAAYwAAAFsAAABJAAAAWQAAAEcAAABpAAAAWAAAAGcAAABcAAAAUwAAAE4AAABKAAAAbAAAAGQAAABfAAAAXQAAAE8AAABaAAAATQAAAG0AAABfAAAAagAAAF4AAABWAAAAUQAAAEsAAABrAAAAaAAAAGUAAABfAAAAXAAAAE8AAABOAAAAbQAAAGwAAABdAAAAYAAAAGgAAABiAAAAbgAAAEwAAABWAAAAUgAAAGEAAAB/AAAAYgAAAFQAAABnAAAAWQAAAG8AAABiAAAAbgAAAGEAAABvAAAAUgAAAGAAAABUAAAAYwAAAFAAAABpAAAAWAAAAGoAAABaAAAAcQAAAGQAAABmAAAAUwAAAFcAAABsAAAAcgAAAFwAAABlAAAAZgAAAGsAAABwAAAAUQAAAFUAAABeAAAAZgAAAGUAAABXAAAAVQAAAHIAAABwAAAAZAAAAGcAAABbAAAAYQAAAFkAAAB0AAAAaQAAAG8AAABoAAAAawAAAG4AAABzAAAAVgAAAF4AAABgAAAAaQAAAFgAAABnAAAAWwAAAHEAAABjAAAAdAAAAGoAAABdAAAAYwAAAFoAAAB1AAAAbQAAAHEAAABrAAAAfwAAAGUAAABeAAAAcwAAAGgAAABwAAAAbAAAAGQAAABfAAAAXAAAAHYAAAByAAAAbQAAAG0AAABsAAAAXQAAAF8AAAB1AAAAdgAAAGoAAABuAAAAYgAAAGgAAABgAAAAdwAAAG8AAABzAAAAbwAAAGEAAABuAAAAYgAAAHQAAABnAAAAdwAAAHAAAABrAAAAZgAAAGUAAAB4AAAAcwAAAHIAAABxAAAAYwAAAHQAAABpAAAAdQAAAGoAAAB5AAAAcgAAAHAAAABkAAAAZgAAAHYAAAB4AAAAbAAAAHMAAABuAAAAawAAAGgAAAB4AAAAdwAAAHAAAAB0AAAAZwAAAHcAAABvAAAAcQAAAGkAAAB5AAAAdQAAAH8AAABtAAAAdgAAAHEAAAB5AAAAagAAAHYAAAB4AAAAbAAAAHIAAAB1AAAAeQAAAG0AAAB3AAAAbwAAAHMAAABuAAAAeQAAAHQAAAB4AAAAeAAAAHMAAAByAAAAcAAAAHkAAAB3AAAAdgAAAHkAAAB0AAAAeAAAAHcAAAB1AAAAcQAAAHYAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAABAAAABQAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAACAAAABQAAAAEAAAAAAAAA/////wEAAAAAAAAAAwAAAAQAAAACAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAFAAAAAQAAAAAAAAAAAAAAAQAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAADAAAAAAAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAADAAAABQAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAEAAAABQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAQAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAUAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAAAwAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAADAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAUAAAABAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABAAAAAUAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAIAAAAFAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAUAAAAAAAAAAAAAAAUAAAAFAAAAAAAAAAAAAAD/////AQAAAAAAAAADAAAABAAAAAIAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAUAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAEAAAD//////////wEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAADAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAACAAAAAAAAAAAAAAABAAAAAgAAAAYAAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAKAAAAAgAAAAAAAAAAAAAAAQAAAAEAAAAFAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAACAAAAAAAAAAAAAAABAAAAAwAAAAcAAAAGAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAABwAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAADgAAAAIAAAAAAAAAAAAAAAEAAAAAAAAACQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAMAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAIAAAAAAAAAAAAAAAEAAAAEAAAACAAAAAoAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAACQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAgAAAAAAAAAAAAAAAQAAAAsAAAAPAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAOAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAIAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAABQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAgAAAAAAAAAAAAAAAQAAAAwAAAAQAAAADAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAADwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAACAAAAAAAAAAAAAAABAAAACgAAABMAAAAIAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAQAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAACQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAIAAAAAAAAAAAAAAAEAAAANAAAAEQAAAA0AAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAARAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA0AAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAACAAAAAAAAAAAAAAABAAAADgAAABIAAAAPAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAADwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAASAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAABEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEgAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAABIAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAATAAAAAgAAAAAAAAAAAAAAAQAAAP//////////EwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAASAAAAAAAAABgAAAAAAAAAIQAAAAAAAAAeAAAAAAAAACAAAAADAAAAMQAAAAEAAAAwAAAAAwAAADIAAAADAAAACAAAAAAAAAAFAAAABQAAAAoAAAAFAAAAFgAAAAAAAAAQAAAAAAAAABIAAAAAAAAAKQAAAAEAAAAhAAAAAAAAAB4AAAAAAAAABAAAAAAAAAAAAAAABQAAAAIAAAAFAAAADwAAAAEAAAAIAAAAAAAAAAUAAAAFAAAAHwAAAAEAAAAWAAAAAAAAABAAAAAAAAAAAgAAAAAAAAAGAAAAAAAAAA4AAAAAAAAACgAAAAAAAAALAAAAAAAAABEAAAADAAAAGAAAAAEAAAAXAAAAAwAAABkAAAADAAAAAAAAAAAAAAABAAAABQAAAAkAAAAFAAAABQAAAAAAAAACAAAAAAAAAAYAAAAAAAAAEgAAAAEAAAAKAAAAAAAAAAsAAAAAAAAABAAAAAEAAAADAAAABQAAAAcAAAAFAAAACAAAAAEAAAAAAAAAAAAAAAEAAAAFAAAAEAAAAAEAAAAFAAAAAAAAAAIAAAAAAAAABwAAAAAAAAAVAAAAAAAAACYAAAAAAAAACQAAAAAAAAATAAAAAAAAACIAAAADAAAADgAAAAEAAAAUAAAAAwAAACQAAAADAAAAAwAAAAAAAAANAAAABQAAAB0AAAAFAAAAAQAAAAAAAAAHAAAAAAAAABUAAAAAAAAABgAAAAEAAAAJAAAAAAAAABMAAAAAAAAABAAAAAIAAAAMAAAABQAAABoAAAAFAAAAAAAAAAEAAAADAAAAAAAAAA0AAAAFAAAAAgAAAAEAAAABAAAAAAAAAAcAAAAAAAAAGgAAAAAAAAAqAAAAAAAAADoAAAAAAAAAHQAAAAAAAAArAAAAAAAAAD4AAAADAAAAJgAAAAEAAAAvAAAAAwAAAEAAAAADAAAADAAAAAAAAAAcAAAABQAAACwAAAAFAAAADQAAAAAAAAAaAAAAAAAAACoAAAAAAAAAFQAAAAEAAAAdAAAAAAAAACsAAAAAAAAABAAAAAMAAAAPAAAABQAAAB8AAAAFAAAAAwAAAAEAAAAMAAAAAAAAABwAAAAFAAAABwAAAAEAAAANAAAAAAAAABoAAAAAAAAAHwAAAAAAAAApAAAAAAAAADEAAAAAAAAALAAAAAAAAAA1AAAAAAAAAD0AAAADAAAAOgAAAAEAAABBAAAAAwAAAEsAAAADAAAADwAAAAAAAAAWAAAABQAAACEAAAAFAAAAHAAAAAAAAAAfAAAAAAAAACkAAAAAAAAAKgAAAAEAAAAsAAAAAAAAADUAAAAAAAAABAAAAAQAAAAIAAAABQAAABAAAAAFAAAADAAAAAEAAAAPAAAAAAAAABYAAAAFAAAAGgAAAAEAAAAcAAAAAAAAAB8AAAAAAAAAMgAAAAAAAAAwAAAAAAAAADEAAAADAAAAIAAAAAAAAAAeAAAAAwAAACEAAAADAAAAGAAAAAMAAAASAAAAAwAAABAAAAADAAAARgAAAAAAAABDAAAAAAAAAEIAAAADAAAANAAAAAMAAAAyAAAAAAAAADAAAAAAAAAAJQAAAAMAAAAgAAAAAAAAAB4AAAADAAAAUwAAAAAAAABXAAAAAwAAAFUAAAADAAAASgAAAAMAAABGAAAAAAAAAEMAAAAAAAAAOQAAAAEAAAA0AAAAAwAAADIAAAAAAAAAGQAAAAAAAAAXAAAAAAAAABgAAAADAAAAEQAAAAAAAAALAAAAAwAAAAoAAAADAAAADgAAAAMAAAAGAAAAAwAAAAIAAAADAAAALQAAAAAAAAAnAAAAAAAAACUAAAADAAAAIwAAAAMAAAAZAAAAAAAAABcAAAAAAAAAGwAAAAMAAAARAAAAAAAAAAsAAAADAAAAPwAAAAAAAAA7AAAAAwAAADkAAAADAAAAOAAAAAMAAAAtAAAAAAAAACcAAAAAAAAALgAAAAMAAAAjAAAAAwAAABkAAAAAAAAAJAAAAAAAAAAUAAAAAAAAAA4AAAADAAAAIgAAAAAAAAATAAAAAwAAAAkAAAADAAAAJgAAAAMAAAAVAAAAAwAAAAcAAAADAAAANwAAAAAAAAAoAAAAAAAAABsAAAADAAAANgAAAAMAAAAkAAAAAAAAABQAAAAAAAAAMwAAAAMAAAAiAAAAAAAAABMAAAADAAAASAAAAAAAAAA8AAAAAwAAAC4AAAADAAAASQAAAAMAAAA3AAAAAAAAACgAAAAAAAAARwAAAAMAAAA2AAAAAwAAACQAAAAAAAAAQAAAAAAAAAAvAAAAAAAAACYAAAADAAAAPgAAAAAAAAArAAAAAwAAAB0AAAADAAAAOgAAAAMAAAAqAAAAAwAAABoAAAADAAAAVAAAAAAAAABFAAAAAAAAADMAAAADAAAAUgAAAAMAAABAAAAAAAAAAC8AAAAAAAAATAAAAAMAAAA+AAAAAAAAACsAAAADAAAAYQAAAAAAAABZAAAAAwAAAEcAAAADAAAAYgAAAAMAAABUAAAAAAAAAEUAAAAAAAAAYAAAAAMAAABSAAAAAwAAAEAAAAAAAAAASwAAAAAAAABBAAAAAAAAADoAAAADAAAAPQAAAAAAAAA1AAAAAwAAACwAAAADAAAAMQAAAAMAAAApAAAAAwAAAB8AAAADAAAAXgAAAAAAAABWAAAAAAAAAEwAAAADAAAAUQAAAAMAAABLAAAAAAAAAEEAAAAAAAAAQgAAAAMAAAA9AAAAAAAAADUAAAADAAAAawAAAAAAAABoAAAAAwAAAGAAAAADAAAAZQAAAAMAAABeAAAAAAAAAFYAAAAAAAAAVQAAAAMAAABRAAAAAwAAAEsAAAAAAAAAOQAAAAAAAAA7AAAAAAAAAD8AAAADAAAASgAAAAAAAABOAAAAAwAAAE8AAAADAAAAUwAAAAMAAABcAAAAAwAAAF8AAAADAAAAJQAAAAAAAAAnAAAAAwAAAC0AAAADAAAANAAAAAAAAAA5AAAAAAAAADsAAAAAAAAARgAAAAMAAABKAAAAAAAAAE4AAAADAAAAGAAAAAAAAAAXAAAAAwAAABkAAAADAAAAIAAAAAMAAAAlAAAAAAAAACcAAAADAAAAMgAAAAMAAAA0AAAAAAAAADkAAAAAAAAALgAAAAAAAAA8AAAAAAAAAEgAAAADAAAAOAAAAAAAAABEAAAAAwAAAFAAAAADAAAAPwAAAAMAAABNAAAAAwAAAFoAAAADAAAAGwAAAAAAAAAoAAAAAwAAADcAAAADAAAAIwAAAAAAAAAuAAAAAAAAADwAAAAAAAAALQAAAAMAAAA4AAAAAAAAAEQAAAADAAAADgAAAAAAAAAUAAAAAwAAACQAAAADAAAAEQAAAAMAAAAbAAAAAAAAACgAAAADAAAAGQAAAAMAAAAjAAAAAAAAAC4AAAAAAAAARwAAAAAAAABZAAAAAAAAAGEAAAADAAAASQAAAAAAAABbAAAAAwAAAGcAAAADAAAASAAAAAMAAABYAAAAAwAAAGkAAAADAAAAMwAAAAAAAABFAAAAAwAAAFQAAAADAAAANgAAAAAAAABHAAAAAAAAAFkAAAAAAAAANwAAAAMAAABJAAAAAAAAAFsAAAADAAAAJgAAAAAAAAAvAAAAAwAAAEAAAAADAAAAIgAAAAMAAAAzAAAAAAAAAEUAAAADAAAAJAAAAAMAAAA2AAAAAAAAAEcAAAAAAAAAYAAAAAAAAABoAAAAAAAAAGsAAAADAAAAYgAAAAAAAABuAAAAAwAAAHMAAAADAAAAYQAAAAMAAABvAAAAAwAAAHcAAAADAAAATAAAAAAAAABWAAAAAwAAAF4AAAADAAAAUgAAAAAAAABgAAAAAAAAAGgAAAAAAAAAVAAAAAMAAABiAAAAAAAAAG4AAAADAAAAOgAAAAAAAABBAAAAAwAAAEsAAAADAAAAPgAAAAMAAABMAAAAAAAAAFYAAAADAAAAQAAAAAMAAABSAAAAAAAAAGAAAAAAAAAAVQAAAAAAAABXAAAAAAAAAFMAAAADAAAAZQAAAAAAAABmAAAAAwAAAGQAAAADAAAAawAAAAMAAABwAAAAAwAAAHIAAAADAAAAQgAAAAAAAABDAAAAAwAAAEYAAAADAAAAUQAAAAAAAABVAAAAAAAAAFcAAAAAAAAAXgAAAAMAAABlAAAAAAAAAGYAAAADAAAAMQAAAAAAAAAwAAAAAwAAADIAAAADAAAAPQAAAAMAAABCAAAAAAAAAEMAAAADAAAASwAAAAMAAABRAAAAAAAAAFUAAAAAAAAAXwAAAAAAAABcAAAAAAAAAFMAAAAAAAAATwAAAAAAAABOAAAAAAAAAEoAAAADAAAAPwAAAAEAAAA7AAAAAwAAADkAAAADAAAAbQAAAAAAAABsAAAAAAAAAGQAAAAFAAAAXQAAAAEAAABfAAAAAAAAAFwAAAAAAAAATQAAAAEAAABPAAAAAAAAAE4AAAAAAAAAdQAAAAQAAAB2AAAABQAAAHIAAAAFAAAAagAAAAEAAABtAAAAAAAAAGwAAAAAAAAAWgAAAAEAAABdAAAAAQAAAF8AAAAAAAAAWgAAAAAAAABNAAAAAAAAAD8AAAAAAAAAUAAAAAAAAABEAAAAAAAAADgAAAADAAAASAAAAAEAAAA8AAAAAwAAAC4AAAADAAAAagAAAAAAAABdAAAAAAAAAE8AAAAFAAAAYwAAAAEAAABaAAAAAAAAAE0AAAAAAAAAWAAAAAEAAABQAAAAAAAAAEQAAAAAAAAAdQAAAAMAAABtAAAABQAAAF8AAAAFAAAAcQAAAAEAAABqAAAAAAAAAF0AAAAAAAAAaQAAAAEAAABjAAAAAQAAAFoAAAAAAAAAaQAAAAAAAABYAAAAAAAAAEgAAAAAAAAAZwAAAAAAAABbAAAAAAAAAEkAAAADAAAAYQAAAAEAAABZAAAAAwAAAEcAAAADAAAAcQAAAAAAAABjAAAAAAAAAFAAAAAFAAAAdAAAAAEAAABpAAAAAAAAAFgAAAAAAAAAbwAAAAEAAABnAAAAAAAAAFsAAAAAAAAAdQAAAAIAAABqAAAABQAAAFoAAAAFAAAAeQAAAAEAAABxAAAAAAAAAGMAAAAAAAAAdwAAAAEAAAB0AAAAAQAAAGkAAAAAAAAAdwAAAAAAAABvAAAAAAAAAGEAAAAAAAAAcwAAAAAAAABuAAAAAAAAAGIAAAADAAAAawAAAAEAAABoAAAAAwAAAGAAAAADAAAAeQAAAAAAAAB0AAAAAAAAAGcAAAAFAAAAeAAAAAEAAAB3AAAAAAAAAG8AAAAAAAAAcAAAAAEAAABzAAAAAAAAAG4AAAAAAAAAdQAAAAEAAABxAAAABQAAAGkAAAAFAAAAdgAAAAEAAAB5AAAAAAAAAHQAAAAAAAAAcgAAAAEAAAB4AAAAAQAAAHcAAAAAAAAAcgAAAAAAAABwAAAAAAAAAGsAAAAAAAAAZAAAAAAAAABmAAAAAAAAAGUAAAADAAAAUwAAAAEAAABXAAAAAwAAAFUAAAADAAAAdgAAAAAAAAB4AAAAAAAAAHMAAAAFAAAAbAAAAAEAAAByAAAAAAAAAHAAAAAAAAAAXAAAAAEAAABkAAAAAAAAAGYAAAAAAAAAdQAAAAAAAAB5AAAABQAAAHcAAAAFAAAAbQAAAAEAAAB2AAAAAAAAAHgAAAAAAAAAXwAAAAEAAABsAAAAAQAAAHIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAGAAAAAgAAAAUAAAABAAAABAAAAAAAAAAAAAAABQAAAAMAAAABAAAABgAAAAQAAAACAAAAAAAAAH6iBfbytuk/Gq6akm/58z/Xrm0Liez0P5doSdOpSwRAWs602ULg8D/dT7Rcbo/1v1N1RQHFNOM/g9Snx7HW3L8HWsP8Q3jfP6VwOLosutk/9rjk1YQcxj+gnmKMsNn6P/HDeuPFY+M/YHwDjqKhB0Ci19/fCVrbP4UxKkDWOP6/pvljWa09tL9wi7wrQXjnv/Z6yLImkM2/3yTlOzY14D+m+WNZrT20PzwKVQnrQwNA9nrIsiaQzT/g40rFrRQFwPa45NWEHMa/kbslHEZq97/xw3rjxWPjv4cLC2SMBci/otff3wla27+rKF5oIAv0P1N1RQHFNOO/iDJPGyWHBUAHWsP8Q3jfvwQf/by16gXAfqIF9vK26b8XrO0Vh0r+v9eubQuJ7PS/BxLrA0ZZ479azrTZQuDwv1MK1EuItPw/yscgV9Z6FkAwHBR2WjQMQJNRzXsQ5vY/GlUHVJYKF0DONuFv2lMNQNCGZ28QJfk/0WUwoIL36D8ggDOMQuATQNqMOeAy/wZAWFYOYM+M2z/LWC4uH3oSQDE+LyTsMgRAkJzhRGWFGEDd4soovCQQQKqk0DJMEP8/rGmNdwOLBUAW2X/9xCbjP4hu3dcqJhNAzuYItRvdB0CgzW3zJW/sPxotm/Y2TxRAQAk9XmdDDEC1Kx9MKgT3P1M+NctcghZAFVqcLlb0C0Bgzd3sB2b2P77mZDPUWhZAFROHJpUGCEDAfma5CxXtPz1DWq/zYxRAmhYY5824F0DOuQKWSbAOQNCMqrvu3fs/L6DR22K2wT9nAAxPBU8RQGiN6mW43AFAZhu25b633D8c1YgmzowSQNM25BRKWARArGS08/lNxD+LFssHwmMRQLC5aNcxBgJABL9HT0WRF0CjCmJmOGEOQHsuaVzMP/s/TWJCaGGwBUCeu1PAPLzjP9nqN9DZOBNAKE4JcydbCkCGtbd1qjPzP8dgm9U8jhVAtPeKTkVwDkCeCLss5l37P401XMPLmBdAFd29VMVQDUBg0yA55h75Pz6odcYLCRdApBM4rBrkAkDyAVWgQxbRP4XDMnK20hFAymLlF7EmzD8GUgo9XBHlP3lbK7T9COc/k+OhPthhy7+YGEpnrOvCPzBFhLs15u4/epbqB6H4uz9IuuLF5svev6lzLKY31es/CaQ0envF5z8ZY0xlUADXv7zaz7HYEuI/CfbK1sn16T8uAQfWwxLWPzKn/YuFN94/5KdbC1AFu793fyCSnlfvPzK2y4doAMY/NRg5t1/X6b/shq4QJaHDP5yNIAKPOeI/vpn7BSE30r/X4YQrO6nrv78Ziv/Thto/DqJ1Y6+y5z9l51NaxFrlv8QlA65HOLS/86dxiEc96z+Hj0+LFjneP6LzBZ8LTc2/DaJ1Y6+y579l51NaxFrlP8QlA65HOLQ/8qdxiEc967+Jj0+LFjnev6LzBZ8LTc0/1qdbC1AFuz93fyCSnlfvvzK2y4doAMa/NRg5t1/X6T/vhq4QJaHDv5yNIAKPOeK/wJn7BSE30j/W4YQrO6nrP78Ziv/Thtq/CaQ0envF578XY0xlUADXP7zaz7HYEuK/CvbK1sn16b8rAQfWwxLWvzKn/YuFN96/zWLlF7EmzL8GUgo9XBHlv3lbK7T9COe/kOOhPthhyz+cGEpnrOvCvzBFhLs15u6/c5bqB6H4u79IuuLF5sveP6lzLKY31eu/AQAAAP////8HAAAA/////zEAAAD/////VwEAAP////9hCQAA/////6dBAAD/////kcsBAP/////3kAwA/////8H2VwAAAAAAAAAAAAAAAAACAAAA/////w4AAAD/////YgAAAP////+uAgAA/////8ISAAD/////ToMAAP////8ilwMA/////+4hGQD/////gu2vAAAAAAAAAAAAAAAAAAAAAAACAAAA//////////8BAAAAAwAAAP//////////////////////////////////////////////////////////////////////////AQAAAAAAAAACAAAA////////////////AwAAAP//////////////////////////////////////////////////////////////////////////AQAAAAAAAAACAAAA////////////////AwAAAP//////////////////////////////////////////////////////////////////////////AQAAAAAAAAACAAAA////////////////AwAAAP//////////////////////////////////////////////////////////AgAAAP//////////AQAAAAAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD/////////////////////AQAAAP///////////////wIAAAD///////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAD///////////////8CAAAAAQAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8BAAAAAgAAAP///////////////wAAAAD/////////////////////AwAAAP///////////////////////////////wIAAAD///////////////8BAAAA/////////////////////wAAAAD/////////////////////AwAAAP////////////////////////////////////////////////////8DAAAA/////////////////////wAAAAABAAAA//////////8CAAAA//////////////////////////////////////////////////////////8DAAAA////////////////AgAAAAAAAAABAAAA//////////////////////////////////////////////////////////////////////////8DAAAA////////////////AgAAAAAAAAABAAAA//////////////////////////////////////////////////////////////////////////8DAAAA////////////////AgAAAAAAAAABAAAA//////////////////////////////////////////////////////////////////////////8DAAAAAQAAAP//////////AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAACAAAAAAAAAAIAAAABAAAAAQAAAAIAAAACAAAAAAAAAAUAAAAFAAAAAAAAAAIAAAACAAAAAwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAAAAEAAAACAAAAAgAAAAIAAAAAAAAABQAAAAYAAAAAAAAAAgAAAAIAAAADAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAgAAAAAAAAACAAAAAQAAAAMAAAACAAAAAgAAAAAAAAAFAAAABwAAAAAAAAACAAAAAgAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAACAAAAAAAAAAIAAAABAAAABAAAAAIAAAACAAAAAAAAAAUAAAAIAAAAAAAAAAIAAAACAAAAAwAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAIAAAAAAAAAAgAAAAEAAAAAAAAAAgAAAAIAAAAAAAAABQAAAAkAAAAAAAAAAgAAAAIAAAADAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAgAAAAIAAAAAAAAAAwAAAA4AAAACAAAAAAAAAAIAAAADAAAAAAAAAAAAAAACAAAAAgAAAAMAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAACAAAAAgAAAAAAAAADAAAACgAAAAIAAAAAAAAAAgAAAAMAAAABAAAAAAAAAAIAAAACAAAAAwAAAAcAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAIAAAACAAAAAAAAAAMAAAALAAAAAgAAAAAAAAACAAAAAwAAAAIAAAAAAAAAAgAAAAIAAAADAAAACAAAAAAAAAAAAAAAAAAAAAAAAAANAAAAAgAAAAIAAAAAAAAAAwAAAAwAAAACAAAAAAAAAAIAAAADAAAAAwAAAAAAAAACAAAAAgAAAAMAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAACAAAAAgAAAAAAAAADAAAADQAAAAIAAAAAAAAAAgAAAAMAAAAEAAAAAAAAAAIAAAACAAAAAwAAAAoAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAIAAAACAAAAAAAAAAMAAAAGAAAAAgAAAAAAAAACAAAAAwAAAA8AAAAAAAAAAgAAAAIAAAADAAAACwAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAgAAAAIAAAAAAAAAAwAAAAcAAAACAAAAAAAAAAIAAAADAAAAEAAAAAAAAAACAAAAAgAAAAMAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAcAAAACAAAAAgAAAAAAAAADAAAACAAAAAIAAAAAAAAAAgAAAAMAAAARAAAAAAAAAAIAAAACAAAAAwAAAA0AAAAAAAAAAAAAAAAAAAAAAAAACAAAAAIAAAACAAAAAAAAAAMAAAAJAAAAAgAAAAAAAAACAAAAAwAAABIAAAAAAAAAAgAAAAIAAAADAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAJAAAAAgAAAAIAAAAAAAAAAwAAAAUAAAACAAAAAAAAAAIAAAADAAAAEwAAAAAAAAACAAAAAgAAAAMAAAAPAAAAAAAAAAAAAAAAAAAAAAAAABAAAAACAAAAAAAAAAIAAAABAAAAEwAAAAIAAAACAAAAAAAAAAUAAAAKAAAAAAAAAAIAAAACAAAAAwAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAAAIAAAAAAAAAAgAAAAEAAAAPAAAAAgAAAAIAAAAAAAAABQAAAAsAAAAAAAAAAgAAAAIAAAADAAAAEQAAAAAAAAAAAAAAAAAAAAAAAAASAAAAAgAAAAAAAAACAAAAAQAAABAAAAACAAAAAgAAAAAAAAAFAAAADAAAAAAAAAACAAAAAgAAAAMAAAASAAAAAAAAAAAAAAAAAAAAAAAAABMAAAACAAAAAAAAAAIAAAABAAAAEQAAAAIAAAACAAAAAAAAAAUAAAANAAAAAAAAAAIAAAACAAAAAwAAABMAAAAAAAAAAAAAAAAAAAAAAAAADwAAAAIAAAAAAAAAAgAAAAEAAAASAAAAAgAAAAIAAAAAAAAABQAAAA4AAAAAAAAAAgAAAAIAAAADAAAAAgAAAAEAAAAAAAAAAQAAAAIAAAAAAAAAAAAAAAIAAAABAAAAAAAAAAEAAAACAAAAAQAAAAAAAAACAAAAAAAAAAUAAAAEAAAAAAAAAAEAAAAFAAAAAAAAAAAAAAAFAAAABAAAAAAAAAABAAAABQAAAAQAAAAAAAAABQAAAAAAAAACAAAAAQAAAAAAAAABAAAAAgAAAAAAAAAAAAAAAgAAAAEAAAAAAAAAAQAAAAIAAAABAAAAAAAAAAIAAAACAAAAAAAAAAEAAAAAAAAAAAAAAAUAAAAEAAAAAAAAAAEAAAAFAAAAAAAAAAAAAAAFAAAABAAAAAAAAAABAAAABQAAAAQAAAAAAAAABQAAAAUAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAABAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAEAAAAAAAAAAAEAAAAAAQAAAAAAAAAAAQAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAABAAAAAAAAAAAAAQAAAAAAAAAAAAA6B6FaUp9QQTPXMuL4myJBraiDfBwx9UBYJseitzTIQOL5if9jqZtAnXX+Z+ycb0C3pucbhRBCQG8wJBYqpRRAlWbDCzCY5z/eFWBUEve6P/+qo4Q50Y4/D9YM3iCcYT8fcA2QJSA0P4ADxu0qAAc/BNcGolVJ2j5d9FACqwquPh9z7MthtI9CSUSYJke/YUJQ/64OyjU0Qpi0+HCmFQdCm3GfIVdh2kHsJ11kAyauQYC3UDFJOoFBSJsFV1OwU0FK5fcxX4AmQWhy/zZIt/lACqaCPsBjzUDbdUNIScugQMYQlVJ4MXNANiuq8GTvRUDxTXnulxEZQFZ8QX5kpuw/qmG/JwYFlEAluh3Q6DB+QKn4vyNq0GZAKOXekas+UUB8xabXXhI6QG63C2pLtSNAdDBtyNfLDUDyOcu67ID2P0rCMvRXAeE/Ki2TSVyzyT9Dk+8Sz2uzP5J+w5ARWp0/NQAoOiMuhj9YnP+RyMJwPxgW7TvQVFk/KgsLYF0kQz9g5dAC6IwzQcgHPVvDex1B1XjppodHBkHJq3OMM9fwQNvcmJ7wddlAInGPpQs/w0BRobq5EBmtQJZ2ai7n+ZVAtv2G5E+bgECG+gIfKBlpQK5f8jdI91JAL39sL/WpPEB8rGxhDqklQK6yUf43XhBAxL9y/tK8+D86XyZpgrHiPwAAAAD/////AAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////AAAAAP////8AAAAAAAAAAAAAAAABAAAAAAAAAAAAAAD/////AAAAAAAAAAABAAAAAQAAAAAAAAAAAAAA/////wAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAP////8FAAAABQAAAAAAAAAAAAAAAAAAAAAAAAD/////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////////////////////////wAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////////////////////////////////////8AAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////AAAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAQAAAAEAAAABAAAAAAAAAAEAAAAAAAAABQAAAAEAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAQAAAAAAAQABAAABAQAAAAAAAQAAAAEAAAABAAEAAAAAAAAAAAAAAAAAAAAAquJYWJZl+D9jaeZNtj/zPwwdI9KqaeO/qGefXwdHdz+q4lhYlmX4P+OrlPMN3PI/DB0j0qpp47+7SQLV4VIEQKriWFiWZfg/r2kma3tz8T82eQmLqNIGwMRIWXMqSvo/fcCszPux9j+jara6ozTwP6hnn18HR3c/MSoKLequ8r+SabgA2nj0P7jBLbDOHO8/1Ym/ICfH4T+6lxjvlFXHv73m373LRPU/0vXyDVxo7T+ToKRHJXMAQF/33578aPE/pAyy64tD9T8+U/hCvyruPwxv8Y7YYwLAuXYr8NAiCEB4+LDK0Sn0P1Qeuy4j+eo/OMx50n7K7L+TrGB/nyf8v5ehC2fbYPM/aXMKexiT6z8mFRIMjg/zP7yUVwGGBNw/E6opHERf8z/z0wR2g9DqPw4pBpcOhvu/NbA29uWAA8DMaTExyXzyP02biiQ+Ruk/S8jz2/FKBEB1pzZnpbb9P7pQU4wLfPI//7ZcQXeG6D9CqEQvAYoIwDB2VB6sSgRAVyv8H5We8T+EHWF8XNPmPzB2wT8Nrrg/SEi+cX+w4L8of+GtdSDxP1sjk5AdouU/6ZjOVru13r8K0obqI6bxvwVbdNXyhfA/w5GG024n5z+rwmtMzP8BwLw9pSX49QXABe/2uQxP8D+b6wCzCvXkP7uGT87fK+Q/pz/JWw4coj+qoBf2J0nwP/yE3PUo0+I/vFJeHcaC+D96luSIqvntP/bf8sHUYu8/gZNN41mL4z9bhOqVOF4FwO6lmAh1hQhAbCVxbdhk7z+1C8NdDcfiPwG36x/0OQBAx0WJ76c2+D9nlSHXANfuP2HlfZ3gqOE/EwnVlVPg9r96+oHzEH//v5bXzdT1Auw/DM3GwLsA4D9p/8uoKcr+v+U9x5DQVAPAehjSdghb7D9sc1IetODgP8MVwwB1pu6/azPk6OGe978W8t/TUc3rP+0QMvYfP+A/RsG/QpSE8D+l3uwScxzgPwQaifgujuw/k1Vti1I43z8MAwLnSh0GQH5nYnwwZgJAiGUzWC5s6j8WyyI/BbLgPw4iUapGeQJAB3W+imnp/j9BLWR4ssrpP2t+gG5Pstk/cpBsfm6DCMCOpU9dOZsFQEv8nFypHeo/ehJ6i+6S2D9jqlGEmarLv7STC5TRiOa/bC+x8WZD6D9H3yUkWpDZP8gZvmCMuQLAreY19/eRBsCoPOc8UzzpP6KI/QV+y9g/t/MoboyWzT+Hv5q3Zu3Mvy2xROCT4uY/9gQitMMg1T9abAqhWMDkv1oLTavoUfG/PMUJP9CD5j+fHRX3t6fSPz7W2gk6bvs/WRnuHwqN9D8YFturGCTmP1EZczv0b9I/5t4exabB5D/1ESLh5fTEP9X2z6SYweQ/6lv3I2zT0D9zkRGNUNMAQKoSvc4EIfs/Xggt8wQI5T+mJHHg/w/SP4lhT/9t8vQ/DrZ/DbwH7D+XlhbYZrjkP34LIpFt6c4/lwfp8fLX9L+j96CTTf76v3WdNhEv9uM/d8c3o4lV0D/vFdCHVcsFwAHeDq0F1QhApbYqcZiN5D9KoilqByXLPwX0/diA0vq/0fo0GxnxAMBbaTkvlCzjP/RrFrWXrMs/UYTrky7jA0DB9f4FiZYAQEGAk/3QzeE/r/TeqE8t0D/OqjlsnPbvvz8RKU8JOfW/smSEbK/O4T8MzuyPm3DDP/rFtctq9gZAfb1EVEaSA0Dts5dVInnhP18SFMc79MM/7y34cw6LAMDFrRJsZO0DwC2KLvLSYuA/hx5wcUHewz+49SnK/4ruPyeS0PX9a+E/ZxaaLvvZ3z8WPu5T2QS8Pygo4RIvMqa/BJ0Kqsd0279cKW4ay8jdP3b05bmZ364/10/qtdxk2r+Bcz6CDMvpv54qOw+Amdw/qLV71pW7sT/YKc80nIPUP8OfIaBJ77G/LyTuD1un2z+diYu8efWzP1wU7ACkfwjAZroyPL1yBkAmv3lKJJbbPysKSE4W+p0/dIgqY79TA8ATLTOQ3tsGwJ2zweD/Xdg/XO/jXeFUaL8VW2qLFKfov1cA9Aa6XfK/tIa7YGgI2T+f3hu/sxqPv2nXdPpf3Pc/jkw8Jbda8j+tT/z8tGPVP1yBHpJd35k/KYvYOy1s8j/yz+kCQjPrP9+agH7x59g/PZfJ9aBhpr/rDKzvYBb+PwtkiaGCt/c/vb1mVr+f1T/JIHwHc8Govw7aeF6+9vG/Xv7kD6fp979isYioQYHVP7AIQZuSFrG/3z1AdUTnAUDN3XY9O7f9P0AdQ9ljYNQ/dJANJPTOrb8kLECUiiPlP4yF7UgmStA/9xGmXxCG1T9qZzix4W2zv2SGJRJVrPe/Fh9a2M/B/b8IexzFCoPSP9y1QFD2bLe/Q86cWLJe/b+mOOfYm78BwOTjkPAGE9E/8aPCUKu/ub9pPZyLCiUGwBA7Mev/BQlALOmrlRi+0j+AMJ/dKULBv7iLtL6a6QRAEMDV/yajAUDa62dE3crJP1P70RgBUbq/38hVnR6esT/s1tG10Z/Ov/zLwalHPss/dTS9NKTXx78nMcRzCIEHQAabxDsAmQRA0tyLK3gSyT+Aui7nOhDGv5Gs58z3WgHATN3forJuBMCAui7nOhDGP9Lciyt4Esm/WAJyHQ4c7z8UP5HFIs3iP3U0vTSk18c//MvBqUc+y7+cvv8HLg/Kvy1I/mHsI+K/U/vRGAFRuj/a62dE3crJv8p+WV8KlQjAuQ/nOP43B0CAMJ/dKULBPyzpq5UYvtK/ZoU+VoLh4L9etLlRUfvtv/GjwlCrv7k/5OOQ8AYT0b9DfT9FhufXPwUX8hJp+4u/3LVAUPZstz8IexzFCoPSv9+L609E5fQ/q9Fz7X2J7T9qZzix4W2zP/cRpl8QhtW/vtNilqGX+j8MOy7QJoL0P3SQDST0zq0/QB1D2WNg1L8IIjSvGNkDwGB8Jou2GAfAsAhBm5IWsT9isYioQYHVvyS9D3zb6uy/gnwRa7uM9L/JIHwHc8GoP729Zla/n9W/CsAHJZwmAEDEW6OYT1r6Pz2XyfWgYaY/35qAfvHn2L83Tdy4lS30vxf2/gZ0jPq/XIEekl3fmb+tT/z8tGPVvybPr2zJ1/+/K7mJ0ypVAsCf3hu/sxqPPwCGu2BoCNm/5oITrpZn+r+UDUyDP+n/v1zv413hVGg/nbPB4P9d2L9MlmkxNvgCQMtZlKE85v8/KwpIThb6nb8mv3lKJJbbv8+SZsTvOOc/pQCIIOYw0j+diYu8efWzvy8k7g9bp9u/kxYDa+pKtD9XlYvA8HnVv6i1e9aVu7G/nio7D4CZ3L/WR6rNh5EGwCkgQweBkghAdvTluZnfrr9cKW4ay8jdvxbjhr1f1QVAR5C0MzivAkAWPu5T2QS8v2cWmi772d+/cKj4lzLJCEBx2QJfYrMFQIcecHFB3sO/LYou8tJi4L+jr7lhO38BwIcI0Nb7xgTAXxIUxzv0w7/ts5dVInnhv0T+l8DZLfE/MP3FoFvS5D8MzuyPm3DDv7JkhGyvzuG/tzhzRIRc0b9Ovv3/0z7mv6/03qhPLdC/m4CT/dDN4b9dwjU5VCQBQBBJX1ntCv0/9GsWtZesy79baTkvlCzjv1mjYgEz++S/oW6KnOQW8b9KoilqByXLv6W2KnGYjeS/SmaKz3Vx9z+BZB5yxGHwP3fHN6OJVdC/dZ02ES/2478PuaBjLrXaP4/JU81pPaO/fgsikW3pzr+XlhbYZrjkv4tSn7YDbP0/f2LnFKlF9z+mJHHg/w/Sv14ILfMECOW/mfg4qYhR/b+OP+RQDCACwOpb9yNs09C/1fbPpJjB5L9pN2WOVZ3wv3hHy9nxIve/URlzO/Rv0r8YFturGCTmv1d1/KKR8QPA8gsy9qzSB8CfHRX3t6fSvzzFCT/Qg+a/EYStnrzV9r/2QJqI7Lb9v/YEIrTDINW/LbFE4JPi5r/7kQEs5fEDQHunnf4GeQBAooj9BX7L2L+oPOc8Uzzpv+ydYY2SSAfAL4HK6CRTB0BH3yUkWpDZv2wvsfFmQ+i/Ik0Yzruh6T8fM3LoGoDUP3oSeovukti/S/ycXKkd6r9rEv+7UWcHQCRIQe/GfwNAa36Abk+y2b9BLWR4ssrpv9KT87qa0bM/FTyktw823L8WyyI/BbLgv4hlM1gubOq/DizMp9Ki6r8b5ckdjVrzv5NVbYtSON+/BBqJ+C6O7L/dUBFqgyXYv00Wh18r7+q/7RAy9h8/4L8W8t/TUc3rv4RM5DKx3wDAfvWIj94aBcBsc1IetODgv3oY0nYIW+y/oGcTFF54AUDkJqS/FKX6PwzNxsC7AOC/ltfN1PUC7L+5Wrz/zHnzP6688w2rNOc/YeV9neCo4b9nlSHXANfuvw9RsxKjY/s/1V8GteXE8j+1C8NdDcfiv2wlcW3YZO+/IOywaA7Q8b9bFP+4Tg36v4GTTeNZi+O/9t/ywdRi77+tRc3yFR7eP2bkcHXJkLO//ITc9SjT4r+qoBf2J0nwv2YHKoswwfm/iQcLspCjAcCb6wCzCvXkvwXv9rkMT/C/YkuwYAMXBMApCNUai9kIwMORhtNuJ+e/BVt01fKF8L+ZqWEfvIjsP6h693QZYNk/WyOTkB2i5b8of+GtdSDxvwpaaulDSwVADMQAX+lOAECEHWF8XNPmv1cr/B+VnvG/XyFG6opcCMD/mtR32/UEQP+2XEF3hui/ulBTjAt88r/imfCfRP+yP9zbvtc8XeO/TZuKJD5G6b/MaTExyXzyvxiTQeElXOO/rbJRQVGN9L/z0wR2g9DqvxOqKRxEX/O/FDGCEei99j9x8zV4VYTmP2lzCnsYk+u/l6ELZ9tg878pRXacaDT/v3k6GZRqoQXAVB67LiP56r94+LDK0Sn0vwO6pZ9b7wFAvK0nKVcc9j8+U/hCvyruv6QMsuuLQ/W/FPhKFYv46j8MyxaDTOW/v9L18g1caO2/vebfvctE9b/7GD8ZrF3xv3gx1AR9bQDAuMEtsM4c77+SabgA2nj0v5xKFIwxsATArKNSBaKsB0Cjara6ozTwv33ArMz7sfa/dF2U0FcWCcDxL357DJX/P69pJmt7c/G/quJYWJZl+L/YntVJlnrSP4sRLzXM+fe/46uU8w3c8r+q4lhYlmX4v85lu5+QRwRAsI0H/WU8479jaeZNtj/zv6riWFiWZfi/sI0H/WU847/OZbufkEcEQHAoPUBrnss/9exKzDtFtT88wM8kax+gP9OqeKeAYog/MW0ItiZvcj+ph+smvt5bP2lCaV5dEUU/StaUmQDaLz+kK9y22BMYP0O3whZuMwI/IIbgZGWE6z7UkjYaEM3UPuezxwa9cr8+LybxRMnFpz6E1N8DbPiRPsYjySMvK3s+//////8fAAj//////zMQCP////9/MiAI/////28yMAj/////YzJACP///z9iMlAI////N2IyYAj///8zYjJwCP//vzNiMoAI//+rM2IykAj/f6szYjKgCP8PqzNiMrAI/wOrM2IywAi/A6szYjLQCJ8DqzNiMuAImQOrM2Iy8Aj//////z8PCP//////Kx8I/////38pLwj/////Pyk/CP////85KU8I////PzgpXwj///8POClvCP///w44KX8I//8fDjgpjwj//w8OOCmfCP9/DQ44Ka8I/w8NDjgpvwj/DQ0OOCnPCP8MDQ44Kd8IxwwNDjgp7wjEDA0OOCn/CAcAAAAHAAAAAQAAAAIAAAAEAAAAAwAAAAAAAAAAAAAABwAAAAMAAAABAAAAAgAAAAUAAAAEAAAAAAAAAAAAAAAEAAAABAAAAAAAAAACAAAAAQAAAAMAAAAOAAAABgAAAAsAAAACAAAABwAAAAEAAAAYAAAABQAAAAoAAAABAAAABgAAAAAAAAAmAAAABwAAAAwAAAADAAAACAAAAAIAAAAxAAAACQAAAA4AAAAAAAAABQAAAAQAAAA6AAAACAAAAA0AAAAEAAAACQAAAAMAAAA/AAAACwAAAAYAAAAPAAAACgAAABAAAABIAAAADAAAAAcAAAAQAAAACwAAABEAAABTAAAACgAAAAUAAAATAAAADgAAAA8AAABhAAAADQAAAAgAAAARAAAADAAAABIAAABrAAAADgAAAAkAAAASAAAADQAAABMAAAB1AAAADwAAABMAAAARAAAAEgAAABAAAAAGAAAAAgAAAAMAAAAFAAAABAAAAAAAAAAAAAAAAAAAAAYAAAACAAAAAwAAAAEAAAAFAAAABAAAAAAAAAAAAAAABwAAAAUAAAADAAAABAAAAAEAAAAAAAAAAgAAAAAAAAACAAAAAwAAAAEAAAAFAAAABAAAAAYAAAAAAAAAAAAAABgtRFT7Ifk/GC1EVPsh+b8YLURU+yEJQBgtRFT7IQnAYWxnb3MuYwBoM05laWdoYm9yUm90YXRpb25zAGNvb3JkaWprLmMAX3VwQXA3Q2hlY2tlZABfdXBBcDdyQ2hlY2tlZABkaXJlY3RlZEVkZ2UuYwBkaXJlY3RlZEVkZ2VUb0JvdW5kYXJ5AGFkamFjZW50RmFjZURpclt0bXBGaWprLmZhY2VdW2ZpamsuZmFjZV0gPT0gS0kAZmFjZWlqay5jAF9mYWNlSWprUGVudFRvQ2VsbEJvdW5kYXJ5AGFkamFjZW50RmFjZURpcltjZW50ZXJJSksuZmFjZV1bZmFjZTJdID09IEtJAF9mYWNlSWprVG9DZWxsQm91bmRhcnkAaDNJbmRleC5jAGNvbXBhY3RDZWxscwBsYXRMbmdUb0NlbGwAY2VsbFRvQ2hpbGRQb3MAdmFsaWRhdGVDaGlsZFBvcwBsYXRMbmcuYwBjZWxsQXJlYVJhZHMyAHBvbHlnb24tPm5leHQgPT0gTlVMTABsaW5rZWRHZW8uYwBhZGROZXdMaW5rZWRQb2x5Z29uAG5leHQgIT0gTlVMTABsb29wICE9IE5VTEwAYWRkTmV3TGlua2VkTG9vcABwb2x5Z29uLT5maXJzdCA9PSBOVUxMAGFkZExpbmtlZExvb3AAY29vcmQgIT0gTlVMTABhZGRMaW5rZWRDb29yZABsb29wLT5maXJzdCA9PSBOVUxMAGlubmVyTG9vcHMgIT0gTlVMTABub3JtYWxpemVNdWx0aVBvbHlnb24AYmJveGVzICE9IE5VTEwAY2FuZGlkYXRlcyAhPSBOVUxMAGZpbmRQb2x5Z29uRm9ySG9sZQBjYW5kaWRhdGVCQm94ZXMgIT0gTlVMTAByZXZEaXIgIT0gSU5WQUxJRF9ESUdJVABsb2NhbGlqLmMAY2VsbFRvTG9jYWxJamsAYmFzZUNlbGwgIT0gb3JpZ2luQmFzZUNlbGwAIShvcmlnaW5PblBlbnQgJiYgaW5kZXhPblBlbnQpAGJhc2VDZWxsID09IG9yaWdpbkJhc2VDZWxsAGJhc2VDZWxsICE9IElOVkFMSURfQkFTRV9DRUxMAGxvY2FsSWprVG9DZWxsACFfaXNCYXNlQ2VsbFBlbnRhZ29uKGJhc2VDZWxsKQBiYXNlQ2VsbFJvdGF0aW9ucyA+PSAwAGdyaWRQYXRoQ2VsbHMAcG9seWZpbGwuYwBpdGVyU3RlcFBvbHlnb25Db21wYWN0ADAAdmVydGV4LmMAdmVydGV4Um90YXRpb25zAGNlbGxUb1ZlcnRleABncmFwaC0+YnVja2V0cyAhPSBOVUxMAHZlcnRleEdyYXBoLmMAaW5pdFZlcnRleEdyYXBoAG5vZGUgIT0gTlVMTABhZGRWZXJ0ZXhOb2Rl";var Pt=28640;function Dr(nA,yA,RA,xA){yt("Assertion failed: "+lA(nA)+", at: "+[yA?lA(yA):"unknown filename",RA,xA?lA(xA):"unknown function"])}function Ar(){return IA.length}function er(nA,yA,RA){LA.set(LA.subarray(yA,yA+RA),nA)}function Gr(nA){return u.___errno_location&&(UA[u.___errno_location()>>2]=nA),nA}function on(nA){yt("OOM")}function _r(nA){try{var yA=new ArrayBuffer(nA);return yA.byteLength!=nA?void 0:(new Int8Array(yA).set(IA),yr(yA),dA(yA),1)}catch{}}function Ut(nA){var yA=Ar(),RA=16777216,xA=2147483648-RA;if(nA>xA)return!1;for(var t=16777216,C=Math.max(yA,t);C>4,t=(De&15)<<4|Le>>2,C=(Le&3)<<6|ee,RA=RA+String.fromCharCode(xA),Le!==64&&(RA=RA+String.fromCharCode(t)),ee!==64&&(RA=RA+String.fromCharCode(C));while(Ce13780509?(A=S0(15,A)|0,A|0):(r=((e|0)<0)<<31>>31,s=mt(e|0,r|0,3,0)|0,n=M()|0,r=$A(e|0,r|0,1,0)|0,r=mt(s|0,n|0,r|0,M()|0)|0,r=$A(r|0,M()|0,1,0)|0,e=M()|0,t[A>>2]=r,t[A+4>>2]=e,A=0,A|0)}function v(e,A,r,n){return e=e|0,A=A|0,r=r|0,n=n|0,T(e,A,r,n,0)|0}function T(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0;if(c=S,S=S+16|0,o=c,!(O(e,A,r,n,s)|0))return n=0,S=c,n|0;do if((r|0)>=0){if((r|0)>13780509){if(i=S0(15,o)|0,i|0)break;l=o,o=t[l>>2]|0,l=t[l+4>>2]|0}else i=((r|0)<0)<<31>>31,f=mt(r|0,i|0,3,0)|0,l=M()|0,i=$A(r|0,i|0,1,0)|0,i=mt(f|0,l|0,i|0,M()|0)|0,i=$A(i|0,M()|0,1,0)|0,l=M()|0,t[o>>2]=i,t[o+4>>2]=l,o=i;if(An(n|0,0,o<<3|0)|0,s|0){An(s|0,0,o<<2|0)|0,i=AA(e,A,r,n,s,o,l,0)|0;break}i=Ht(o,4)|0,i?(f=AA(e,A,r,n,i,o,l,0)|0,ZA(i),i=f):i=13}else i=2;while(!1);return f=i,S=c,f|0}function O(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0;if(G=S,S=S+16|0,L=G,N=G+8|0,I=L,t[I>>2]=e,t[I+4>>2]=A,(r|0)<0)return N=2,S=G,N|0;if(i=n,t[i>>2]=e,t[i+4>>2]=A,i=(s|0)!=0,i&&(t[s>>2]=0),Oe(e,A)|0)return N=9,S=G,N|0;t[N>>2]=0;A:do if((r|0)>=1)if(i)for(g=1,f=0,D=0,I=1,i=e;;){if(!(f|D)){if(i=$(i,A,4,N,L)|0,i|0)break A;if(A=L,i=t[A>>2]|0,A=t[A+4>>2]|0,Oe(i,A)|0){i=9;break A}}if(i=$(i,A,t[26800+(D<<2)>>2]|0,N,L)|0,i|0)break A;if(A=L,i=t[A>>2]|0,A=t[A+4>>2]|0,e=n+(g<<3)|0,t[e>>2]=i,t[e+4>>2]=A,t[s+(g<<2)>>2]=I,e=f+1|0,o=(e|0)==(I|0),l=D+1|0,c=(l|0)==6,Oe(i,A)|0){i=9;break A}if(I=I+(c&o&1)|0,(I|0)>(r|0)){i=0;break}else g=g+1|0,f=o?0:e,D=o?c?0:l:D}else for(g=1,f=0,D=0,I=1,i=e;;){if(!(f|D)){if(i=$(i,A,4,N,L)|0,i|0)break A;if(A=L,i=t[A>>2]|0,A=t[A+4>>2]|0,Oe(i,A)|0){i=9;break A}}if(i=$(i,A,t[26800+(D<<2)>>2]|0,N,L)|0,i|0)break A;if(A=L,i=t[A>>2]|0,A=t[A+4>>2]|0,e=n+(g<<3)|0,t[e>>2]=i,t[e+4>>2]=A,e=f+1|0,o=(e|0)==(I|0),l=D+1|0,c=(l|0)==6,Oe(i,A)|0){i=9;break A}if(I=I+(c&o&1)|0,(I|0)>(r|0)){i=0;break}else g=g+1|0,f=o?0:e,D=o?c?0:l:D}else i=0;while(!1);return N=i,S=G,N|0}function AA(e,A,r,n,s,i,o,l){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0,i=i|0,o=o|0,l=l|0;var c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0;if(G=S,S=S+16|0,L=G+8|0,N=G,c=Fn(e|0,A|0,i|0,o|0)|0,g=M()|0,D=n+(c<<3)|0,W=D,iA=t[W>>2]|0,W=t[W+4>>2]|0,f=(iA|0)==(e|0)&(W|0)==(A|0),!((iA|0)==0&(W|0)==0|f))do c=$A(c|0,g|0,1,0)|0,c=Nn(c|0,M()|0,i|0,o|0)|0,g=M()|0,D=n+(c<<3)|0,iA=D,W=t[iA>>2]|0,iA=t[iA+4>>2]|0,f=(W|0)==(e|0)&(iA|0)==(A|0);while(!((W|0)==0&(iA|0)==0|f));if(c=s+(c<<2)|0,f&&(t[c>>2]|0)<=(l|0)||(iA=D,t[iA>>2]=e,t[iA+4>>2]=A,t[c>>2]=l,(l|0)>=(r|0)))return iA=0,S=G,iA|0;switch(f=l+1|0,t[L>>2]=0,c=$(e,A,2,L,N)|0,c|0){case 9:{I=9;break}case 0:{c=N,c=AA(t[c>>2]|0,t[c+4>>2]|0,r,n,s,i,o,f)|0,c||(I=9);break}}A:do if((I|0)==9){switch(t[L>>2]=0,c=$(e,A,3,L,N)|0,c|0){case 9:break;case 0:{if(c=N,c=AA(t[c>>2]|0,t[c+4>>2]|0,r,n,s,i,o,f)|0,c|0)break A;break}default:break A}switch(t[L>>2]=0,c=$(e,A,1,L,N)|0,c|0){case 9:break;case 0:{if(c=N,c=AA(t[c>>2]|0,t[c+4>>2]|0,r,n,s,i,o,f)|0,c|0)break A;break}default:break A}switch(t[L>>2]=0,c=$(e,A,5,L,N)|0,c|0){case 9:break;case 0:{if(c=N,c=AA(t[c>>2]|0,t[c+4>>2]|0,r,n,s,i,o,f)|0,c|0)break A;break}default:break A}switch(t[L>>2]=0,c=$(e,A,4,L,N)|0,c|0){case 9:break;case 0:{if(c=N,c=AA(t[c>>2]|0,t[c+4>>2]|0,r,n,s,i,o,f)|0,c|0)break A;break}default:break A}switch(t[L>>2]=0,c=$(e,A,6,L,N)|0,c|0){case 9:break;case 0:{if(c=N,c=AA(t[c>>2]|0,t[c+4>>2]|0,r,n,s,i,o,f)|0,c|0)break A;break}default:break A}return iA=0,S=G,iA|0}while(!1);return iA=c,S=G,iA|0}function $(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0;if(r>>>0>6)return s=1,s|0;if(D=(t[n>>2]|0)%6|0,t[n>>2]=D,(D|0)>0){i=0;do r=$t(r)|0,i=i+1|0;while((i|0)<(t[n>>2]|0))}if(D=wA(e|0,A|0,45)|0,M()|0,g=D&127,g>>>0>121)return s=5,s|0;c=zt(e,A)|0,i=wA(e|0,A|0,52)|0,M()|0,i=i&15;A:do if(!i)f=8;else{for(;;){if(o=(15-i|0)*3|0,l=wA(e|0,A|0,o|0)|0,M()|0,l=l&7,(l|0)==7){A=5;break}if(N=(ir(i)|0)==0,i=i+-1|0,I=CA(7,0,o|0)|0,A=A&~(M()|0),L=CA(t[(N?432:16)+(l*28|0)+(r<<2)>>2]|0,0,o|0)|0,o=M()|0,r=t[(N?640:224)+(l*28|0)+(r<<2)>>2]|0,e=L|e&~I,A=o|A,!r){r=0;break A}if(!i){f=8;break A}}return A|0}while(!1);(f|0)==8&&(N=t[848+(g*28|0)+(r<<2)>>2]|0,L=CA(N|0,0,45)|0,e=L|e,A=M()|0|A&-1040385,r=t[4272+(g*28|0)+(r<<2)>>2]|0,(N&127|0)==127&&(N=CA(t[848+(g*28|0)+20>>2]|0,0,45)|0,A=M()|0|A&-1040385,r=t[4272+(g*28|0)+20>>2]|0,e=mn(N|e,A)|0,A=M()|0,t[n>>2]=(t[n>>2]|0)+1)),l=wA(e|0,A|0,45)|0,M()|0,l=l&127;A:do if(_e(l)|0){e:do if((zt(e,A)|0)==1){if((g|0)!=(l|0))if(Ir(l,t[7696+(g*28|0)>>2]|0)|0){e=ns(e,A)|0,o=1,A=M()|0;break}else OA(27795,26864,533,26872);switch(c|0){case 3:{e=mn(e,A)|0,A=M()|0,t[n>>2]=(t[n>>2]|0)+1,o=0;break e}case 5:{e=ns(e,A)|0,A=M()|0,t[n>>2]=(t[n>>2]|0)+5,o=0;break e}case 0:return N=9,N|0;default:return N=1,N|0}}else o=0;while(!1);if((r|0)>0){i=0;do e=rs(e,A)|0,A=M()|0,i=i+1|0;while((i|0)!=(r|0))}if((g|0)!=(l|0)){if(!(Dt(l)|0)){if((o|0)!=0|(zt(e,A)|0)!=5)break;t[n>>2]=(t[n>>2]|0)+1;break}switch(D&127){case 8:case 118:break A}(zt(e,A)|0)!=3&&(t[n>>2]=(t[n>>2]|0)+1)}}else if((r|0)>0){i=0;do e=mn(e,A)|0,A=M()|0,i=i+1|0;while((i|0)!=(r|0))}while(!1);return t[n>>2]=((t[n>>2]|0)+r|0)%6|0,N=s,t[N>>2]=e,t[N+4>>2]=A,N=0,N|0}function hA(e,A,r,n){return e=e|0,A=A|0,r=r|0,n=n|0,TA(e,A,r,n)|0?(An(n|0,0,r*48|0)|0,n=XA(e,A,r,n)|0,n|0):(n=0,n|0)}function TA(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0;if(N=S,S=S+16|0,I=N,L=N+8|0,D=I,t[D>>2]=e,t[D+4>>2]=A,(r|0)<0)return L=2,S=N,L|0;if(!r)return L=n,t[L>>2]=e,t[L+4>>2]=A,L=0,S=N,L|0;t[L>>2]=0;A:do if(Oe(e,A)|0)e=9;else{s=0,D=e;do{if(e=$(D,A,4,L,I)|0,e|0)break A;if(A=I,D=t[A>>2]|0,A=t[A+4>>2]|0,s=s+1|0,Oe(D,A)|0){e=9;break A}}while((s|0)<(r|0));g=n,t[g>>2]=D,t[g+4>>2]=A,g=r+-1|0,f=0,e=1;do{if(s=26800+(f<<2)|0,(f|0)==5)for(o=t[s>>2]|0,i=0,s=e;;){if(e=I,e=$(t[e>>2]|0,t[e+4>>2]|0,o,L,I)|0,e|0)break A;if((i|0)!=(g|0))if(c=I,l=t[c>>2]|0,c=t[c+4>>2]|0,e=n+(s<<3)|0,t[e>>2]=l,t[e+4>>2]=c,!(Oe(l,c)|0))e=s+1|0;else{e=9;break A}else e=s;if(i=i+1|0,(i|0)>=(r|0))break;s=e}else for(o=I,c=t[s>>2]|0,l=0,s=e,i=t[o>>2]|0,o=t[o+4>>2]|0;;){if(e=$(i,o,c,L,I)|0,e|0)break A;if(o=I,i=t[o>>2]|0,o=t[o+4>>2]|0,e=n+(s<<3)|0,t[e>>2]=i,t[e+4>>2]=o,e=s+1|0,Oe(i,o)|0){e=9;break A}if(l=l+1|0,(l|0)>=(r|0))break;s=e}f=f+1|0}while(f>>>0<6);e=I,e=(D|0)==(t[e>>2]|0)&&(A|0)==(t[e+4>>2]|0)?0:9}while(!1);return L=e,S=N,L|0}function XA(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0;if(D=S,S=S+16|0,o=D,!r)return t[n>>2]=e,t[n+4>>2]=A,n=0,S=D,n|0;do if((r|0)>=0){if((r|0)>13780509){if(s=S0(15,o)|0,s|0)break;i=o,s=t[i>>2]|0,i=t[i+4>>2]|0}else s=((r|0)<0)<<31>>31,g=mt(r|0,s|0,3,0)|0,i=M()|0,s=$A(r|0,s|0,1,0)|0,s=mt(g|0,i|0,s|0,M()|0)|0,s=$A(s|0,M()|0,1,0)|0,i=M()|0,g=o,t[g>>2]=s,t[g+4>>2]=i;if(f=Ht(s,8)|0,!f)s=13;else{if(g=Ht(s,4)|0,!g){ZA(f),s=13;break}if(s=AA(e,A,r,f,g,s,i,0)|0,s|0){ZA(f),ZA(g);break}if(A=t[o>>2]|0,o=t[o+4>>2]|0,(o|0)>0|(o|0)==0&A>>>0>0){s=0,l=0,c=0;do e=f+(l<<3)|0,i=t[e>>2]|0,e=t[e+4>>2]|0,!((i|0)==0&(e|0)==0)&&(t[g+(l<<2)>>2]|0)==(r|0)&&(I=n+(s<<3)|0,t[I>>2]=i,t[I+4>>2]=e,s=s+1|0),l=$A(l|0,c|0,1,0)|0,c=M()|0;while((c|0)<(o|0)|(c|0)==(o|0)&l>>>0>>0)}ZA(f),ZA(g),s=0}}else s=2;while(!1);return I=s,S=D,I|0}function qA(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0;for(l=S,S=S+16|0,i=l,o=l+8|0,s=(Oe(e,A)|0)==0,s=s?1:2;;){if(t[o>>2]=0,f=($(e,A,s,o,i)|0)==0,c=i,f&((t[c>>2]|0)==(r|0)?(t[c+4>>2]|0)==(n|0):0)){e=4;break}if(s=s+1|0,s>>>0>=7){s=7,e=4;break}}return(e|0)==4?(S=l,s|0):0}function fe(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0;if(l=S,S=S+48|0,s=l+16|0,i=l+8|0,o=l,r=l0(r)|0,r|0)return o=r,S=l,o|0;if(f=e,c=t[f+4>>2]|0,r=i,t[r>>2]=t[f>>2],t[r+4>>2]=c,li(i,s),r=Yt(s,A,o)|0,!r){if(A=t[i>>2]|0,i=t[e+8>>2]|0,(i|0)>0){s=t[e+12>>2]|0,r=0;do A=(t[s+(r<<3)>>2]|0)+A|0,r=r+1|0;while((r|0)<(i|0))}r=o,s=t[r>>2]|0,r=t[r+4>>2]|0,i=((A|0)<0)<<31>>31,(r|0)<(i|0)|(r|0)==(i|0)&s>>>0>>0?(r=o,t[r>>2]=A,t[r+4>>2]=i,r=i):A=s,c=$A(A|0,r|0,12,0)|0,f=M()|0,r=o,t[r>>2]=c,t[r+4>>2]=f,r=n,t[r>>2]=c,t[r+4>>2]=f,r=0}return f=r,S=l,f|0}function Ne(e,A,r,n,s,i,o){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0,i=i|0,o=o|0;var l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0,he=0,Se=0,ie=0,GA=0,SA=0,xe=0,We=0,de=0,Ye=0,Lt=0,bi=0;if(We=S,S=S+64|0,ie=We+48|0,GA=We+32|0,SA=We+24|0,MA=We+8|0,HA=We,c=t[e>>2]|0,(c|0)<=0)return xe=0,S=We,xe|0;for(QA=e+4|0,ce=ie+8|0,he=GA+8|0,Se=MA+8|0,l=0,Z=0;;){f=t[QA>>2]|0,J=f+(Z<<4)|0,t[ie>>2]=t[J>>2],t[ie+4>>2]=t[J+4>>2],t[ie+8>>2]=t[J+8>>2],t[ie+12>>2]=t[J+12>>2],(Z|0)==(c+-1|0)?(t[GA>>2]=t[f>>2],t[GA+4>>2]=t[f+4>>2],t[GA+8>>2]=t[f+8>>2],t[GA+12>>2]=t[f+12>>2]):(J=f+(Z+1<<4)|0,t[GA>>2]=t[J>>2],t[GA+4>>2]=t[J+4>>2],t[GA+8>>2]=t[J+8>>2],t[GA+12>>2]=t[J+12>>2]),c=$r(ie,GA,n,SA)|0;A:do if(c)f=0,l=c;else if(c=SA,f=t[c>>2]|0,c=t[c+4>>2]|0,(c|0)>0|(c|0)==0&f>>>0>0){iA=0,J=0;e:for(;;){if(Ye=1/(+(f>>>0)+4294967296*+(c|0)),bi=+C[ie>>3],c=dt(f|0,c|0,iA|0,J|0)|0,Lt=+(c>>>0)+4294967296*+(M()|0),de=+(iA>>>0)+4294967296*+(J|0),C[MA>>3]=Ye*(bi*Lt)+Ye*(+C[GA>>3]*de),C[Se>>3]=Ye*(+C[ce>>3]*Lt)+Ye*(+C[he>>3]*de),c=ss(MA,n,HA)|0,c|0){l=c;break}W=HA,G=t[W>>2]|0,W=t[W+4>>2]|0,I=Fn(G|0,W|0,A|0,r|0)|0,g=M()|0,c=o+(I<<3)|0,D=c,f=t[D>>2]|0,D=t[D+4>>2]|0;t:do if((f|0)==0&(D|0)==0)V=c,xe=16;else for(L=0,N=0;;){if((L|0)>(r|0)|(L|0)==(r|0)&N>>>0>A>>>0){l=1;break e}if((f|0)==(G|0)&(D|0)==(W|0))break t;if(c=$A(I|0,g|0,1,0)|0,I=Nn(c|0,M()|0,A|0,r|0)|0,g=M()|0,N=$A(N|0,L|0,1,0)|0,L=M()|0,c=o+(I<<3)|0,D=c,f=t[D>>2]|0,D=t[D+4>>2]|0,(f|0)==0&(D|0)==0){V=c,xe=16;break}}while(!1);if((xe|0)==16&&(xe=0,!((G|0)==0&(W|0)==0))&&(N=V,t[N>>2]=G,t[N+4>>2]=W,N=i+(t[s>>2]<<3)|0,t[N>>2]=G,t[N+4>>2]=W,N=s,N=$A(t[N>>2]|0,t[N+4>>2]|0,1,0)|0,G=M()|0,W=s,t[W>>2]=N,t[W+4>>2]=G),iA=$A(iA|0,J|0,1,0)|0,J=M()|0,c=SA,f=t[c>>2]|0,c=t[c+4>>2]|0,!((c|0)>(J|0)|(c|0)==(J|0)&f>>>0>iA>>>0)){f=1;break A}}f=0}else f=1;while(!1);if(Z=Z+1|0,!f){xe=21;break}if(c=t[e>>2]|0,(Z|0)>=(c|0)){l=0,xe=21;break}}return(xe|0)==21?(S=We,l|0):0}function Bt(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0,he=0,Se=0,ie=0,GA=0,SA=0,xe=0,We=0,de=0,Ye=0,Lt=0;if(Lt=S,S=S+112|0,xe=Lt+80|0,c=Lt+72|0,We=Lt,de=Lt+56|0,s=l0(r)|0,s|0)return Ye=s,S=Lt,Ye|0;if(f=e+8|0,Ye=Cr((t[f>>2]<<5)+32|0)|0,!Ye)return Ye=13,S=Lt,Ye|0;if(fs(e,Ye),s=l0(r)|0,!s){if(GA=e,SA=t[GA+4>>2]|0,s=c,t[s>>2]=t[GA>>2],t[s+4>>2]=SA,li(c,xe),s=Yt(xe,A,We)|0,s)GA=0,SA=0;else{if(s=t[c>>2]|0,i=t[f>>2]|0,(i|0)>0){o=t[e+12>>2]|0,r=0;do s=(t[o+(r<<3)>>2]|0)+s|0,r=r+1|0;while((r|0)!=(i|0));r=s}else r=s;s=We,i=t[s>>2]|0,s=t[s+4>>2]|0,o=((r|0)<0)<<31>>31,(s|0)<(o|0)|(s|0)==(o|0)&i>>>0>>0?(s=We,t[s>>2]=r,t[s+4>>2]=o,s=o):r=i,GA=$A(r|0,s|0,12,0)|0,SA=M()|0,s=We,t[s>>2]=GA,t[s+4>>2]=SA,s=0}if(!s){if(r=Ht(GA,8)|0,!r)return ZA(Ye),Ye=13,S=Lt,Ye|0;if(l=Ht(GA,8)|0,!l)return ZA(Ye),ZA(r),Ye=13,S=Lt,Ye|0;Se=xe,t[Se>>2]=0,t[Se+4>>2]=0,Se=e,ie=t[Se+4>>2]|0,s=c,t[s>>2]=t[Se>>2],t[s+4>>2]=ie,s=Ne(c,GA,SA,A,xe,r,l)|0;A:do if(s)ZA(r),ZA(l),ZA(Ye);else{e:do if((t[f>>2]|0)>0){for(o=e+12|0,i=0;s=Ne((t[o>>2]|0)+(i<<3)|0,GA,SA,A,xe,r,l)|0,i=i+1|0,!(s|0);)if((i|0)>=(t[f>>2]|0))break e;ZA(r),ZA(l),ZA(Ye);break A}while(!1);(SA|0)>0|(SA|0)==0&GA>>>0>0&&An(l|0,0,GA<<3|0)|0,ie=xe,Se=t[ie+4>>2]|0;e:do if((Se|0)>0|(Se|0)==0&(t[ie>>2]|0)>>>0>0){QA=r,ce=l,he=r,Se=l,ie=r,s=r,V=r,MA=l,HA=l,r=l;t:for(;;){for(W=0,iA=0,J=0,Z=0,i=0,o=0;;){l=We,c=l+56|0;do t[l>>2]=0,l=l+4|0;while((l|0)<(c|0));if(A=QA+(W<<3)|0,f=t[A>>2]|0,A=t[A+4>>2]|0,O(f,A,1,We,0)|0){l=We,c=l+56|0;do t[l>>2]=0,l=l+4|0;while((l|0)<(c|0));l=Ht(7,4)|0,l|0&&(AA(f,A,1,We,l,7,0,0)|0,ZA(l))}for(G=0;;){N=We+(G<<3)|0,L=t[N>>2]|0,N=t[N+4>>2]|0;r:do if((L|0)==0&(N|0)==0)l=i,c=o;else{if(g=Fn(L|0,N|0,GA|0,SA|0)|0,f=M()|0,l=n+(g<<3)|0,A=l,c=t[A>>2]|0,A=t[A+4>>2]|0,!((c|0)==0&(A|0)==0)){D=0,I=0;do{if((D|0)>(SA|0)|(D|0)==(SA|0)&I>>>0>GA>>>0)break t;if((c|0)==(L|0)&(A|0)==(N|0)){l=i,c=o;break r}l=$A(g|0,f|0,1,0)|0,g=Nn(l|0,M()|0,GA|0,SA|0)|0,f=M()|0,I=$A(I|0,D|0,1,0)|0,D=M()|0,l=n+(g<<3)|0,A=l,c=t[A>>2]|0,A=t[A+4>>2]|0}while(!((c|0)==0&(A|0)==0))}if((L|0)==0&(N|0)==0){l=i,c=o;break}pn(L,N,de)|0,hs(e,Ye,de)|0&&(I=$A(i|0,o|0,1,0)|0,o=M()|0,D=l,t[D>>2]=L,t[D+4>>2]=N,i=ce+(i<<3)|0,t[i>>2]=L,t[i+4>>2]=N,i=I),l=i,c=o}while(!1);if(G=G+1|0,G>>>0>=7)break;i=l,o=c}if(W=$A(W|0,iA|0,1,0)|0,iA=M()|0,J=$A(J|0,Z|0,1,0)|0,Z=M()|0,o=xe,i=t[o>>2]|0,o=t[o+4>>2]|0,(Z|0)<(o|0)|(Z|0)==(o|0)&J>>>0>>0)i=l,o=c;else break}if((o|0)>0|(o|0)==0&i>>>0>0){i=0,o=0;do Z=QA+(i<<3)|0,t[Z>>2]=0,t[Z+4>>2]=0,i=$A(i|0,o|0,1,0)|0,o=M()|0,Z=xe,J=t[Z+4>>2]|0;while((o|0)<(J|0)|((o|0)==(J|0)?i>>>0<(t[Z>>2]|0)>>>0:0))}if(Z=xe,t[Z>>2]=l,t[Z+4>>2]=c,(c|0)>0|(c|0)==0&l>>>0>0)G=r,W=HA,iA=ie,J=MA,Z=ce,r=V,HA=s,MA=he,V=G,s=W,ie=Se,Se=iA,he=J,ce=QA,QA=Z;else break e}ZA(he),ZA(Se),ZA(Ye),s=1;break A}else s=l;while(!1);ZA(Ye),ZA(r),ZA(s),s=0}while(!1);return Ye=s,S=Lt,Ye|0}}return ZA(Ye),Ye=s,S=Lt,Ye|0}function rt(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(g=S,S=S+176|0,c=g,(A|0)<1)return di(r,0,0),f=0,S=g,f|0;for(l=e,l=wA(t[l>>2]|0,t[l+4>>2]|0,52)|0,M()|0,di(r,(A|0)>6?A:6,l&15),l=0;n=e+(l<<3)|0,n=In(t[n>>2]|0,t[n+4>>2]|0,c)|0,!(n|0);){if(n=t[c>>2]|0,(n|0)>0){o=0;do i=c+8+(o<<4)|0,o=o+1|0,n=c+8+(((o|0)%(n|0)|0)<<4)|0,s=xa(r,n,i)|0,s?gi(r,s)|0:ya(r,i,n)|0,n=t[c>>2]|0;while((o|0)<(n|0))}if(l=l+1|0,(l|0)>=(A|0)){n=0,f=13;break}}return(f|0)==13?(S=g,n|0):(mi(r),f=n,S=g,f|0)}function vt(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0;if(i=S,S=S+32|0,n=i,s=i+16|0,e=rt(e,A,s)|0,e|0)return r=e,S=i,r|0;if(t[r>>2]=0,t[r+4>>2]=0,t[r+8>>2]=0,e=pi(s)|0,e|0)do{A=$l(r)|0;do Kl(A,e)|0,o=e+16|0,t[n>>2]=t[o>>2],t[n+4>>2]=t[o+4>>2],t[n+8>>2]=t[o+8>>2],t[n+12>>2]=t[o+12>>2],gi(s,e)|0,e=wa(s,n)|0;while((e|0)!=0);e=pi(s)|0}while((e|0)!=0);return mi(s),e=Zl(r)|0,e?(ni(r),o=e,S=i,o|0):(o=0,S=i,o|0)}function _e(e){return e=e|0,e>>>0>121?(e=0,e|0):(e=t[7696+(e*28|0)+16>>2]|0,e|0)}function Dt(e){return e=e|0,(e|0)==4|(e|0)==117|0}function wr(e){return e=e|0,t[11120+((t[e>>2]|0)*216|0)+((t[e+4>>2]|0)*72|0)+((t[e+8>>2]|0)*24|0)+(t[e+12>>2]<<3)>>2]|0}function nr(e){return e=e|0,t[11120+((t[e>>2]|0)*216|0)+((t[e+4>>2]|0)*72|0)+((t[e+8>>2]|0)*24|0)+(t[e+12>>2]<<3)+4>>2]|0}function Yr(e,A){e=e|0,A=A|0,e=7696+(e*28|0)|0,t[A>>2]=t[e>>2],t[A+4>>2]=t[e+4>>2],t[A+8>>2]=t[e+8>>2],t[A+12>>2]=t[e+12>>2]}function sr(e,A){e=e|0,A=A|0;var r=0,n=0;if(A>>>0>20)return A=-1,A|0;do if((t[11120+(A*216|0)>>2]|0)!=(e|0))if((t[11120+(A*216|0)+8>>2]|0)!=(e|0))if((t[11120+(A*216|0)+16>>2]|0)!=(e|0))if((t[11120+(A*216|0)+24>>2]|0)!=(e|0))if((t[11120+(A*216|0)+32>>2]|0)!=(e|0))if((t[11120+(A*216|0)+40>>2]|0)!=(e|0))if((t[11120+(A*216|0)+48>>2]|0)!=(e|0))if((t[11120+(A*216|0)+56>>2]|0)!=(e|0))if((t[11120+(A*216|0)+64>>2]|0)!=(e|0))if((t[11120+(A*216|0)+72>>2]|0)!=(e|0))if((t[11120+(A*216|0)+80>>2]|0)!=(e|0))if((t[11120+(A*216|0)+88>>2]|0)!=(e|0))if((t[11120+(A*216|0)+96>>2]|0)!=(e|0))if((t[11120+(A*216|0)+104>>2]|0)!=(e|0))if((t[11120+(A*216|0)+112>>2]|0)!=(e|0))if((t[11120+(A*216|0)+120>>2]|0)!=(e|0))if((t[11120+(A*216|0)+128>>2]|0)!=(e|0))if((t[11120+(A*216|0)+136>>2]|0)==(e|0))e=2,r=1,n=2;else{if((t[11120+(A*216|0)+144>>2]|0)==(e|0)){e=0,r=2,n=0;break}if((t[11120+(A*216|0)+152>>2]|0)==(e|0)){e=0,r=2,n=1;break}if((t[11120+(A*216|0)+160>>2]|0)==(e|0)){e=0,r=2,n=2;break}if((t[11120+(A*216|0)+168>>2]|0)==(e|0)){e=1,r=2,n=0;break}if((t[11120+(A*216|0)+176>>2]|0)==(e|0)){e=1,r=2,n=1;break}if((t[11120+(A*216|0)+184>>2]|0)==(e|0)){e=1,r=2,n=2;break}if((t[11120+(A*216|0)+192>>2]|0)==(e|0)){e=2,r=2,n=0;break}if((t[11120+(A*216|0)+200>>2]|0)==(e|0)){e=2,r=2,n=1;break}if((t[11120+(A*216|0)+208>>2]|0)==(e|0)){e=2,r=2,n=2;break}else e=-1;return e|0}else e=2,r=1,n=1;else e=2,r=1,n=0;else e=1,r=1,n=2;else e=1,r=1,n=1;else e=1,r=1,n=0;else e=0,r=1,n=2;else e=0,r=1,n=1;else e=0,r=1,n=0;else e=2,r=0,n=2;else e=2,r=0,n=1;else e=2,r=0,n=0;else e=1,r=0,n=2;else e=1,r=0,n=1;else e=1,r=0,n=0;else e=0,r=0,n=2;else e=0,r=0,n=1;else e=0,r=0,n=0;while(!1);return A=t[11120+(A*216|0)+(r*72|0)+(e*24|0)+(n<<3)+4>>2]|0,A|0}function Ir(e,A){return e=e|0,A=A|0,(t[7696+(e*28|0)+20>>2]|0)==(A|0)?(A=1,A|0):(A=(t[7696+(e*28|0)+24>>2]|0)==(A|0),A|0)}function un(e,A){return e=e|0,A=A|0,t[848+(e*28|0)+(A<<2)>>2]|0}function cn(e,A){return e=e|0,A=A|0,(t[848+(e*28|0)>>2]|0)==(A|0)?(A=0,A|0):(t[848+(e*28|0)+4>>2]|0)==(A|0)?(A=1,A|0):(t[848+(e*28|0)+8>>2]|0)==(A|0)?(A=2,A|0):(t[848+(e*28|0)+12>>2]|0)==(A|0)?(A=3,A|0):(t[848+(e*28|0)+16>>2]|0)==(A|0)?(A=4,A|0):(t[848+(e*28|0)+20>>2]|0)==(A|0)?(A=5,A|0):((t[848+(e*28|0)+24>>2]|0)==(A|0)?6:7)|0}function $n(){return 122}function Kn(e){e=e|0;var A=0,r=0,n=0;A=0;do CA(A|0,0,45)|0,n=M()|0|134225919,r=e+(A<<3)|0,t[r>>2]=-1,t[r+4>>2]=n,A=A+1|0;while((A|0)!=122);return 0}function Zn(e){e=e|0;var A=0,r=0,n=0;return n=+C[e+16>>3],r=+C[e+24>>3],A=n-r,+(n>3]<+C[e+24>>3]|0}function fn(e){return e=e|0,+(+C[e>>3]-+C[e+8>>3])}function vr(e,A){e=e|0,A=A|0;var r=0,n=0,s=0;return r=+C[A>>3],!(r>=+C[e+8>>3])||!(r<=+C[e>>3])?(A=0,A|0):(n=+C[e+16>>3],r=+C[e+24>>3],s=+C[A+8>>3],A=s>=r,e=s<=n&1,n>3]<+C[A+8>>3]||+C[e+8>>3]>+C[A>>3]?(n=0,n|0):(i=+C[e+16>>3],r=e+24|0,g=+C[r>>3],o=i>3],s=A+24|0,c=+C[s>>3],l=f>3],A)||(g=+Zt(+C[r>>3],e),g>+Zt(+C[n>>3],A))?(l=0,l|0):(l=1,l|0))}function Lr(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0;i=+C[e+16>>3],c=+C[e+24>>3],e=i>3],o=+C[A+24>>3],s=l>2]=e?s|A?1:2:0,t[n>>2]=s?e?1:A?2:1:0}function Nr(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;return+C[e>>3]<+C[A>>3]||+C[e+8>>3]>+C[A+8>>3]?(n=0,n|0):(n=e+16|0,c=+C[n>>3],i=+C[e+24>>3],o=c>3],s=A+24|0,f=+C[s>>3],l=g>3],A)?(g=+Zt(+C[n>>3],e),l=g>=+Zt(+C[r>>3],A),l|0):(l=0,l|0))}function br(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0;s=S,S=S+176|0,n=s,t[n>>2]=4,l=+C[A>>3],C[n+8>>3]=l,i=+C[A+16>>3],C[n+16>>3]=i,C[n+24>>3]=l,l=+C[A+24>>3],C[n+32>>3]=l,o=+C[A+8>>3],C[n+40>>3]=o,C[n+48>>3]=l,C[n+56>>3]=o,C[n+64>>3]=i,A=n+72|0,r=A+96|0;do t[A>>2]=0,A=A+4|0;while((A|0)<(r|0));Pn(e|0,n|0,168)|0,S=s}function Yt(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0;N=S,S=S+288|0,g=N+264|0,D=N+96|0,f=N,l=f,c=l+96|0;do t[l>>2]=0,l=l+4|0;while((l|0)<(c|0));return A=os(A,f)|0,A|0?(L=A,S=N,L|0):(c=f,f=t[c>>2]|0,c=t[c+4>>2]|0,pn(f,c,g)|0,In(f,c,D)|0,o=+i0(g,D+8|0),C[g>>3]=+C[e>>3],c=g+8|0,C[c>>3]=+C[e+16>>3],C[D>>3]=+C[e+8>>3],f=D+8|0,C[f>>3]=+C[e+24>>3],s=+i0(g,D),W=+C[c>>3]-+C[f>>3],i=+ee(+W),G=+C[g>>3]-+C[D>>3],n=+ee(+G),!(W==0|G==0)&&(W=+wi(+i,+n),W=+Wt(+(s*s/+B0(+(W/+B0(+i,+n)),3)/(o*(o*2.59807621135)*.8))),C[ge>>3]=W,I=~~W>>>0,L=+ee(W)>=1?W>0?~~+tt(+Le(W/4294967296),4294967295)>>>0:~~+Wt((W-+(~~W>>>0))/4294967296)>>>0:0,(t[ge+4>>2]&2146435072|0)!=2146435072)?(D=(I|0)==0&(L|0)==0,A=r,t[A>>2]=D?1:I,t[A+4>>2]=D?0:L,A=0):A=1,L=A,S=N,L|0)}function $r(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0;f=S,S=S+288|0,o=f+264|0,l=f+96|0,c=f,s=c,i=s+96|0;do t[s>>2]=0,s=s+4|0;while((s|0)<(i|0));return r=os(r,c)|0,r|0?(n=r,S=f,n|0):(r=c,s=t[r>>2]|0,r=t[r+4>>2]|0,pn(s,r,o)|0,In(s,r,l)|0,g=+i0(o,l+8|0),g=+Wt(+(+i0(e,A)/(g*2))),C[ge>>3]=g,r=~~g>>>0,s=+ee(g)>=1?g>0?~~+tt(+Le(g/4294967296),4294967295)>>>0:~~+Wt((g-+(~~g>>>0))/4294967296)>>>0:0,(t[ge+4>>2]&2146435072|0)==2146435072?(n=1,S=f,n|0):(c=(r|0)==0&(s|0)==0,t[n>>2]=c?1:r,t[n+4>>2]=c?0:s,n=0,S=f,n|0))}function pr(e,A){e=e|0,A=+A;var r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;i=e+16|0,o=+C[i>>3],r=e+24|0,s=+C[r>>3],n=o-s,n=o>3],l=e+8|0,c=+C[l>>3],g=f-c,n=(n*A-n)*.5,A=(g*A-g)*.5,f=f+A,C[e>>3]=f>1.5707963267948966?1.5707963267948966:f,A=c-A,C[l>>3]=A<-1.5707963267948966?-1.5707963267948966:A,A=o+n,A=A>3.141592653589793?A+-6.283185307179586:A,C[i>>3]=A<-3.141592653589793?A+6.283185307179586:A,A=s-n,A=A>3.141592653589793?A+-6.283185307179586:A,C[r>>3]=A<-3.141592653589793?A+6.283185307179586:A}function hn(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0,t[e>>2]=A,t[e+4>>2]=r,t[e+8>>2]=n}function Kr(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0;D=A+8|0,t[D>>2]=0,c=+C[e>>3],o=+ee(+c),f=+C[e+8>>3],l=+ee(+f)*1.1547005383792515,o=o+l*.5,r=~~o,e=~~l,o=o-+(r|0),l=l-+(e|0);do if(o<.5)if(o<.3333333333333333)if(t[A>>2]=r,l<(o+1)*.5){t[A+4>>2]=e;break}else{e=e+1|0,t[A+4>>2]=e;break}else if(I=1-o,e=(!(l>2]=e,I<=l&l>2]=r;break}else{t[A>>2]=r;break}else{if(!(o<.6666666666666666))if(r=r+1|0,t[A>>2]=r,l>2]=e;break}else{e=e+1|0,t[A+4>>2]=e;break}if(l<1-o){if(t[A+4>>2]=e,o*2+-1>2]=r;break}}else e=e+1|0,t[A+4>>2]=e;r=r+1|0,t[A>>2]=r}while(!1);do if(c<0)if(e&1){g=(e+1|0)/2|0,g=dt(r|0,((r|0)<0)<<31>>31|0,g|0,((g|0)<0)<<31>>31|0)|0,r=~~(+(r|0)-((+(g>>>0)+4294967296*+(M()|0))*2+1)),t[A>>2]=r;break}else{g=(e|0)/2|0,g=dt(r|0,((r|0)<0)<<31>>31|0,g|0,((g|0)<0)<<31>>31|0)|0,r=~~(+(r|0)-(+(g>>>0)+4294967296*+(M()|0))*2),t[A>>2]=r;break}while(!1);g=A+4|0,f<0&&(r=r-((e<<1|1|0)/2|0)|0,t[A>>2]=r,e=0-e|0,t[g>>2]=e),n=e-r|0,(r|0)<0?(s=0-r|0,t[g>>2]=n,t[D>>2]=s,t[A>>2]=0,e=n,r=0):s=0,(e|0)<0&&(r=r-e|0,t[A>>2]=r,s=s-e|0,t[D>>2]=s,t[g>>2]=0,e=0),i=r-s|0,n=e-s|0,(s|0)<0&&(t[A>>2]=i,t[g>>2]=n,t[D>>2]=0,e=n,r=i,s=0),n=(e|0)<(r|0)?e:r,n=(s|0)<(n|0)?s:n,!((n|0)<=0)&&(t[A>>2]=r-n,t[g>>2]=e-n,t[D>>2]=s-n)}function nt(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0;A=t[e>>2]|0,o=e+4|0,r=t[o>>2]|0,(A|0)<0&&(r=r-A|0,t[o>>2]=r,i=e+8|0,t[i>>2]=(t[i>>2]|0)-A,t[e>>2]=0,A=0),(r|0)<0?(A=A-r|0,t[e>>2]=A,i=e+8|0,s=(t[i>>2]|0)-r|0,t[i>>2]=s,t[o>>2]=0,r=0):(s=e+8|0,i=s,s=t[s>>2]|0),(s|0)<0&&(A=A-s|0,t[e>>2]=A,r=r-s|0,t[o>>2]=r,t[i>>2]=0,s=0),n=(r|0)<(A|0)?r:A,n=(s|0)<(n|0)?s:n,!((n|0)<=0)&&(t[e>>2]=A-n,t[o>>2]=r-n,t[i>>2]=s-n)}function H(e,A){e=e|0,A=A|0;var r=0,n=0;n=t[e+8>>2]|0,r=+((t[e+4>>2]|0)-n|0),C[A>>3]=+((t[e>>2]|0)-n|0)-r*.5,C[A+8>>3]=r*.8660254037844386}function tA(e,A,r){e=e|0,A=A|0,r=r|0,t[r>>2]=(t[A>>2]|0)+(t[e>>2]|0),t[r+4>>2]=(t[A+4>>2]|0)+(t[e+4>>2]|0),t[r+8>>2]=(t[A+8>>2]|0)+(t[e+8>>2]|0)}function mA(e,A,r){e=e|0,A=A|0,r=r|0,t[r>>2]=(t[e>>2]|0)-(t[A>>2]|0),t[r+4>>2]=(t[e+4>>2]|0)-(t[A+4>>2]|0),t[r+8>>2]=(t[e+8>>2]|0)-(t[A+8>>2]|0)}function NA(e,A){e=e|0,A=A|0;var r=0,n=0;r=ht(t[e>>2]|0,A)|0,t[e>>2]=r,r=e+4|0,n=ht(t[r>>2]|0,A)|0,t[r>>2]=n,e=e+8|0,A=ht(t[e>>2]|0,A)|0,t[e>>2]=A}function zA(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;o=t[e>>2]|0,l=(o|0)<0,n=(t[e+4>>2]|0)-(l?o:0)|0,i=(n|0)<0,s=(i?0-n|0:0)+((t[e+8>>2]|0)-(l?o:0))|0,r=(s|0)<0,e=r?0:s,A=(i?0:n)-(r?s:0)|0,s=(l?0:o)-(i?n:0)-(r?s:0)|0,r=(A|0)<(s|0)?A:s,r=(e|0)<(r|0)?e:r,n=(r|0)>0,e=e-(n?r:0)|0,A=A-(n?r:0)|0;A:do switch(s-(n?r:0)|0){case 0:switch(A|0){case 0:return l=(e|0)==0?0:(e|0)==1?1:7,l|0;case 1:return l=(e|0)==0?2:(e|0)==1?3:7,l|0;default:break A}case 1:switch(A|0){case 0:return l=(e|0)==0?4:(e|0)==1?5:7,l|0;case 1:{if(!e)e=6;else break A;return e|0}default:break A}}while(!1);return l=7,l|0}function te(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0;if(c=e+8|0,o=t[c>>2]|0,l=(t[e>>2]|0)-o|0,f=e+4|0,o=(t[f>>2]|0)-o|0,l>>>0>715827881|o>>>0>715827881){if(n=(l|0)>0,s=2147483647-l|0,i=-2147483648-l|0,(n?(s|0)<(l|0):(i|0)>(l|0))||(r=l<<1,n?(2147483647-r|0)<(l|0):(-2147483648-r|0)>(l|0))||((o|0)>0?(2147483647-o|0)<(o|0):(-2147483648-o|0)>(o|0))||(A=l*3|0,r=o<<1,(n?(s|0)<(r|0):(i|0)>(r|0))||((l|0)>-1?(A|-2147483648|0)>=(o|0):(A^-2147483648|0)<(o|0))))return f=1,f|0}else r=o<<1,A=l*3|0;return n=Jr(+(A-o|0)*.14285714285714285)|0,t[e>>2]=n,s=Jr(+(r+l|0)*.14285714285714285)|0,t[f>>2]=s,t[c>>2]=0,r=(s|0)<(n|0),A=r?n:s,r=r?s:n,(r|0)<0&&(((r|0)==-2147483648||((A|0)>0?(2147483647-A|0)<(r|0):(-2147483648-A|0)>(r|0)))&&OA(27795,26892,354,26903),((A|0)>-1?(A|-2147483648|0)>=(r|0):(A^-2147483648|0)<(r|0))&&OA(27795,26892,354,26903)),A=s-n|0,(n|0)<0?(r=0-n|0,t[f>>2]=A,t[c>>2]=r,t[e>>2]=0,n=0):(A=s,r=0),(A|0)<0&&(n=n-A|0,t[e>>2]=n,r=r-A|0,t[c>>2]=r,t[f>>2]=0,A=0),i=n-r|0,s=A-r|0,(r|0)<0?(t[e>>2]=i,t[f>>2]=s,t[c>>2]=0,A=s,s=i,r=0):s=n,n=(A|0)<(s|0)?A:s,n=(r|0)<(n|0)?r:n,(n|0)<=0?(f=0,f|0):(t[e>>2]=s-n,t[f>>2]=A-n,t[c>>2]=r-n,f=0,f|0)}function Te(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0,c=0;if(o=e+8|0,s=t[o>>2]|0,i=(t[e>>2]|0)-s|0,l=e+4|0,s=(t[l>>2]|0)-s|0,i>>>0>715827881|s>>>0>715827881){if(r=(i|0)>0,(r?(2147483647-i|0)<(i|0):(-2147483648-i|0)>(i|0))||(A=i<<1,n=(s|0)>0,n?(2147483647-s|0)<(s|0):(-2147483648-s|0)>(s|0)))return l=1,l|0;if(c=s<<1,(n?(2147483647-c|0)<(s|0):(-2147483648-c|0)>(s|0))||(r?(2147483647-A|0)<(s|0):(-2147483648-A|0)>(s|0))||(r=s*3|0,(s|0)>-1?(r|-2147483648|0)>=(i|0):(r^-2147483648|0)<(i|0)))return c=1,c|0}else r=s*3|0,A=i<<1;return n=Jr(+(A+s|0)*.14285714285714285)|0,t[e>>2]=n,s=Jr(+(r-i|0)*.14285714285714285)|0,t[l>>2]=s,t[o>>2]=0,r=(s|0)<(n|0),A=r?n:s,r=r?s:n,(r|0)<0&&(((r|0)==-2147483648||((A|0)>0?(2147483647-A|0)<(r|0):(-2147483648-A|0)>(r|0)))&&OA(27795,26892,402,26917),((A|0)>-1?(A|-2147483648|0)>=(r|0):(A^-2147483648|0)<(r|0))&&OA(27795,26892,402,26917)),A=s-n|0,(n|0)<0?(r=0-n|0,t[l>>2]=A,t[o>>2]=r,t[e>>2]=0,n=0):(A=s,r=0),(A|0)<0&&(n=n-A|0,t[e>>2]=n,r=r-A|0,t[o>>2]=r,t[l>>2]=0,A=0),i=n-r|0,s=A-r|0,(r|0)<0?(t[e>>2]=i,t[l>>2]=s,t[o>>2]=0,A=s,s=i,r=0):s=n,n=(A|0)<(s|0)?A:s,n=(r|0)<(n|0)?r:n,(n|0)<=0?(c=0,c|0):(t[e>>2]=s-n,t[l>>2]=A-n,t[o>>2]=r-n,c=0,c|0)}function He(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;o=e+8|0,r=t[o>>2]|0,A=(t[e>>2]|0)-r|0,l=e+4|0,r=(t[l>>2]|0)-r|0,n=Jr(+((A*3|0)-r|0)*.14285714285714285)|0,t[e>>2]=n,A=Jr(+((r<<1)+A|0)*.14285714285714285)|0,t[l>>2]=A,t[o>>2]=0,r=A-n|0,(n|0)<0?(i=0-n|0,t[l>>2]=r,t[o>>2]=i,t[e>>2]=0,A=r,n=0,r=i):r=0,(A|0)<0&&(n=n-A|0,t[e>>2]=n,r=r-A|0,t[o>>2]=r,t[l>>2]=0,A=0),i=n-r|0,s=A-r|0,(r|0)<0?(t[e>>2]=i,t[l>>2]=s,t[o>>2]=0,A=s,s=i,r=0):s=n,n=(A|0)<(s|0)?A:s,n=(r|0)<(n|0)?r:n,!((n|0)<=0)&&(t[e>>2]=s-n,t[l>>2]=A-n,t[o>>2]=r-n)}function st(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;o=e+8|0,r=t[o>>2]|0,A=(t[e>>2]|0)-r|0,l=e+4|0,r=(t[l>>2]|0)-r|0,n=Jr(+((A<<1)+r|0)*.14285714285714285)|0,t[e>>2]=n,A=Jr(+((r*3|0)-A|0)*.14285714285714285)|0,t[l>>2]=A,t[o>>2]=0,r=A-n|0,(n|0)<0?(i=0-n|0,t[l>>2]=r,t[o>>2]=i,t[e>>2]=0,A=r,n=0,r=i):r=0,(A|0)<0&&(n=n-A|0,t[e>>2]=n,r=r-A|0,t[o>>2]=r,t[l>>2]=0,A=0),i=n-r|0,s=A-r|0,(r|0)<0?(t[e>>2]=i,t[l>>2]=s,t[o>>2]=0,A=s,s=i,r=0):s=n,n=(A|0)<(s|0)?A:s,n=(r|0)<(n|0)?r:n,!((n|0)<=0)&&(t[e>>2]=s-n,t[l>>2]=A-n,t[o>>2]=r-n)}function bt(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;A=t[e>>2]|0,o=e+4|0,r=t[o>>2]|0,l=e+8|0,n=t[l>>2]|0,s=r+(A*3|0)|0,t[e>>2]=s,r=n+(r*3|0)|0,t[o>>2]=r,A=(n*3|0)+A|0,t[l>>2]=A,n=r-s|0,(s|0)<0?(A=A-s|0,t[o>>2]=n,t[l>>2]=A,t[e>>2]=0,r=n,n=0):n=s,(r|0)<0&&(n=n-r|0,t[e>>2]=n,A=A-r|0,t[l>>2]=A,t[o>>2]=0,r=0),i=n-A|0,s=r-A|0,(A|0)<0?(t[e>>2]=i,t[o>>2]=s,t[l>>2]=0,n=i,A=0):s=r,r=(s|0)<(n|0)?s:n,r=(A|0)<(r|0)?A:r,!((r|0)<=0)&&(t[e>>2]=n-r,t[o>>2]=s-r,t[l>>2]=A-r)}function Ze(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;s=t[e>>2]|0,o=e+4|0,A=t[o>>2]|0,l=e+8|0,r=t[l>>2]|0,n=(A*3|0)+s|0,s=r+(s*3|0)|0,t[e>>2]=s,t[o>>2]=n,A=(r*3|0)+A|0,t[l>>2]=A,r=n-s|0,(s|0)<0?(A=A-s|0,t[o>>2]=r,t[l>>2]=A,t[e>>2]=0,s=0):r=n,(r|0)<0&&(s=s-r|0,t[e>>2]=s,A=A-r|0,t[l>>2]=A,t[o>>2]=0,r=0),i=s-A|0,n=r-A|0,(A|0)<0?(t[e>>2]=i,t[o>>2]=n,t[l>>2]=0,s=i,A=0):n=r,r=(n|0)<(s|0)?n:s,r=(A|0)<(r|0)?A:r,!((r|0)<=0)&&(t[e>>2]=s-r,t[o>>2]=n-r,t[l>>2]=A-r)}function ot(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0;(A+-1|0)>>>0>=6||(s=(t[15440+(A*12|0)>>2]|0)+(t[e>>2]|0)|0,t[e>>2]=s,l=e+4|0,n=(t[15440+(A*12|0)+4>>2]|0)+(t[l>>2]|0)|0,t[l>>2]=n,o=e+8|0,A=(t[15440+(A*12|0)+8>>2]|0)+(t[o>>2]|0)|0,t[o>>2]=A,r=n-s|0,(s|0)<0?(A=A-s|0,t[l>>2]=r,t[o>>2]=A,t[e>>2]=0,n=0):(r=n,n=s),(r|0)<0&&(n=n-r|0,t[e>>2]=n,A=A-r|0,t[o>>2]=A,t[l>>2]=0,r=0),i=n-A|0,s=r-A|0,(A|0)<0?(t[e>>2]=i,t[l>>2]=s,t[o>>2]=0,n=i,A=0):s=r,r=(s|0)<(n|0)?s:n,r=(A|0)<(r|0)?A:r,!((r|0)<=0)&&(t[e>>2]=n-r,t[l>>2]=s-r,t[o>>2]=A-r))}function _t(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;s=t[e>>2]|0,o=e+4|0,A=t[o>>2]|0,l=e+8|0,r=t[l>>2]|0,n=A+s|0,s=r+s|0,t[e>>2]=s,t[o>>2]=n,A=r+A|0,t[l>>2]=A,r=n-s|0,(s|0)<0?(A=A-s|0,t[o>>2]=r,t[l>>2]=A,t[e>>2]=0,n=0):(r=n,n=s),(r|0)<0&&(n=n-r|0,t[e>>2]=n,A=A-r|0,t[l>>2]=A,t[o>>2]=0,r=0),i=n-A|0,s=r-A|0,(A|0)<0?(t[e>>2]=i,t[o>>2]=s,t[l>>2]=0,n=i,A=0):s=r,r=(s|0)<(n|0)?s:n,r=(A|0)<(r|0)?A:r,!((r|0)<=0)&&(t[e>>2]=n-r,t[o>>2]=s-r,t[l>>2]=A-r)}function Fr(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;A=t[e>>2]|0,o=e+4|0,n=t[o>>2]|0,l=e+8|0,r=t[l>>2]|0,s=n+A|0,t[e>>2]=s,n=r+n|0,t[o>>2]=n,A=r+A|0,t[l>>2]=A,r=n-s|0,(s|0)<0?(A=A-s|0,t[o>>2]=r,t[l>>2]=A,t[e>>2]=0,n=0):(r=n,n=s),(r|0)<0&&(n=n-r|0,t[e>>2]=n,A=A-r|0,t[l>>2]=A,t[o>>2]=0,r=0),i=n-A|0,s=r-A|0,(A|0)<0?(t[e>>2]=i,t[o>>2]=s,t[l>>2]=0,n=i,A=0):s=r,r=(s|0)<(n|0)?s:n,r=(A|0)<(r|0)?A:r,!((r|0)<=0)&&(t[e>>2]=n-r,t[o>>2]=s-r,t[l>>2]=A-r)}function $t(e){switch(e=e|0,e|0){case 1:{e=5;break}case 5:{e=4;break}case 4:{e=6;break}case 6:{e=2;break}case 2:{e=3;break}case 3:{e=1;break}}return e|0}function Kt(e){switch(e=e|0,e|0){case 1:{e=3;break}case 3:{e=2;break}case 2:{e=6;break}case 6:{e=4;break}case 4:{e=5;break}case 5:{e=1;break}}return e|0}function qn(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;A=t[e>>2]|0,o=e+4|0,r=t[o>>2]|0,l=e+8|0,n=t[l>>2]|0,s=r+(A<<1)|0,t[e>>2]=s,r=n+(r<<1)|0,t[o>>2]=r,A=(n<<1)+A|0,t[l>>2]=A,n=r-s|0,(s|0)<0?(A=A-s|0,t[o>>2]=n,t[l>>2]=A,t[e>>2]=0,r=n,n=0):n=s,(r|0)<0&&(n=n-r|0,t[e>>2]=n,A=A-r|0,t[l>>2]=A,t[o>>2]=0,r=0),i=n-A|0,s=r-A|0,(A|0)<0?(t[e>>2]=i,t[o>>2]=s,t[l>>2]=0,n=i,A=0):s=r,r=(s|0)<(n|0)?s:n,r=(A|0)<(r|0)?A:r,!((r|0)<=0)&&(t[e>>2]=n-r,t[o>>2]=s-r,t[l>>2]=A-r)}function Jn(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;s=t[e>>2]|0,o=e+4|0,A=t[o>>2]|0,l=e+8|0,r=t[l>>2]|0,n=(A<<1)+s|0,s=r+(s<<1)|0,t[e>>2]=s,t[o>>2]=n,A=(r<<1)+A|0,t[l>>2]=A,r=n-s|0,(s|0)<0?(A=A-s|0,t[o>>2]=r,t[l>>2]=A,t[e>>2]=0,s=0):r=n,(r|0)<0&&(s=s-r|0,t[e>>2]=s,A=A-r|0,t[l>>2]=A,t[o>>2]=0,r=0),i=s-A|0,n=r-A|0,(A|0)<0?(t[e>>2]=i,t[o>>2]=n,t[l>>2]=0,s=i,A=0):n=r,r=(n|0)<(s|0)?n:s,r=(A|0)<(r|0)?A:r,!((r|0)<=0)&&(t[e>>2]=s-r,t[o>>2]=n-r,t[l>>2]=A-r)}function Dn(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0;return o=(t[e>>2]|0)-(t[A>>2]|0)|0,l=(o|0)<0,n=(t[e+4>>2]|0)-(t[A+4>>2]|0)-(l?o:0)|0,i=(n|0)<0,s=(l?0-o|0:0)+(t[e+8>>2]|0)-(t[A+8>>2]|0)+(i?0-n|0:0)|0,e=(s|0)<0,A=e?0:s,r=(i?0:n)-(e?s:0)|0,s=(l?0:o)-(i?n:0)-(e?s:0)|0,e=(r|0)<(s|0)?r:s,e=(A|0)<(e|0)?A:e,n=(e|0)>0,A=A-(n?e:0)|0,r=r-(n?e:0)|0,e=s-(n?e:0)|0,e=(e|0)>-1?e:0-e|0,r=(r|0)>-1?r:0-r|0,A=(A|0)>-1?A:0-A|0,A=(r|0)>(A|0)?r:A,((e|0)>(A|0)?e:A)|0}function Xn(e,A){e=e|0,A=A|0;var r=0;r=t[e+8>>2]|0,t[A>>2]=(t[e>>2]|0)-r,t[A+4>>2]=(t[e+4>>2]|0)-r}function Tt(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0;return n=t[e>>2]|0,t[A>>2]=n,s=t[e+4>>2]|0,o=A+4|0,t[o>>2]=s,l=A+8|0,t[l>>2]=0,r=(s|0)<(n|0),e=r?n:s,r=r?s:n,(r|0)<0&&((r|0)==-2147483648||((e|0)>0?(2147483647-e|0)<(r|0):(-2147483648-e|0)>(r|0))||((e|0)>-1?(e|-2147483648|0)>=(r|0):(e^-2147483648|0)<(r|0)))?(A=1,A|0):(e=s-n|0,(n|0)<0?(r=0-n|0,t[o>>2]=e,t[l>>2]=r,t[A>>2]=0,n=0):(e=s,r=0),(e|0)<0&&(n=n-e|0,t[A>>2]=n,r=r-e|0,t[l>>2]=r,t[o>>2]=0,e=0),i=n-r|0,s=e-r|0,(r|0)<0?(t[A>>2]=i,t[o>>2]=s,t[l>>2]=0,e=s,s=i,r=0):s=n,n=(e|0)<(s|0)?e:s,n=(r|0)<(n|0)?r:n,(n|0)<=0?(A=0,A|0):(t[A>>2]=s-n,t[o>>2]=e-n,t[l>>2]=r-n,A=0,A|0))}function A0(e){e=e|0;var A=0,r=0,n=0,s=0;A=e+8|0,s=t[A>>2]|0,r=s-(t[e>>2]|0)|0,t[e>>2]=r,n=e+4|0,e=(t[n>>2]|0)-s|0,t[n>>2]=e,t[A>>2]=0-(e+r)}function e0(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;r=t[e>>2]|0,A=0-r|0,t[e>>2]=A,o=e+8|0,t[o>>2]=0,l=e+4|0,n=t[l>>2]|0,s=n+r|0,(r|0)>0?(t[l>>2]=s,t[o>>2]=r,t[e>>2]=0,A=0,n=s):r=0,(n|0)<0?(i=A-n|0,t[e>>2]=i,r=r-n|0,t[o>>2]=r,t[l>>2]=0,s=i-r|0,A=0-r|0,(r|0)<0?(t[e>>2]=s,t[l>>2]=A,t[o>>2]=0,n=A,r=0):(n=0,s=i)):s=A,A=(n|0)<(s|0)?n:s,A=(r|0)<(A|0)?r:A,!((A|0)<=0)&&(t[e>>2]=s-A,t[l>>2]=n-A,t[o>>2]=r-A)}function ts(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0;if(D=S,S=S+64|0,g=D,l=D+56|0,!(!0&(A&2013265920|0)==134217728&(!0&(n&2013265920|0)==134217728)))return s=5,S=D,s|0;if((e|0)==(r|0)&(A|0)==(n|0))return t[s>>2]=0,s=0,S=D,s|0;if(o=wA(e|0,A|0,52)|0,M()|0,o=o&15,f=wA(r|0,n|0,52)|0,M()|0,(o|0)!=(f&15|0))return s=12,S=D,s|0;if(i=o+-1|0,o>>>0>1){It(e,A,i,g)|0,It(r,n,i,l)|0,f=g,c=t[f>>2]|0,f=t[f+4>>2]|0;A:do if((c|0)==(t[l>>2]|0)&&(f|0)==(t[l+4>>2]|0)){o=(o^15)*3|0,i=wA(e|0,A|0,o|0)|0,M()|0,i=i&7,o=wA(r|0,n|0,o|0)|0,M()|0,o=o&7;do if((i|0)==0|(o|0)==0)t[s>>2]=1,i=0;else if((i|0)==7)i=5;else{if((i|0)==1|(o|0)==1&&Oe(c,f)|0){i=5;break}if((t[15536+(i<<2)>>2]|0)!=(o|0)&&(t[15568+(i<<2)>>2]|0)!=(o|0))break A;t[s>>2]=1,i=0}while(!1);return s=i,S=D,s|0}while(!1)}i=g,o=i+56|0;do t[i>>2]=0,i=i+4|0;while((i|0)<(o|0));return v(e,A,1,g)|0,A=g,!((t[A>>2]|0)==(r|0)&&(t[A+4>>2]|0)==(n|0))&&(A=g+8|0,!((t[A>>2]|0)==(r|0)&&(t[A+4>>2]|0)==(n|0)))&&(A=g+16|0,!((t[A>>2]|0)==(r|0)&&(t[A+4>>2]|0)==(n|0)))&&(A=g+24|0,!((t[A>>2]|0)==(r|0)&&(t[A+4>>2]|0)==(n|0)))&&(A=g+32|0,!((t[A>>2]|0)==(r|0)&&(t[A+4>>2]|0)==(n|0)))&&(A=g+40|0,!((t[A>>2]|0)==(r|0)&&(t[A+4>>2]|0)==(n|0)))?(i=g+48|0,i=((t[i>>2]|0)==(r|0)?(t[i+4>>2]|0)==(n|0):0)&1):i=1,t[s>>2]=i,s=0,S=D,s|0}function v0(e,A,r,n,s){return e=e|0,A=A|0,r=r|0,n=n|0,s=s|0,r=qA(e,A,r,n)|0,(r|0)==7?(s=11,s|0):(n=CA(r|0,0,56)|0,A=A&-2130706433|(M()|0)|268435456,t[s>>2]=e|n,t[s+4>>2]=A,s=0,s|0)}function _n(e,A,r){return e=e|0,A=A|0,r=r|0,!0&(A&2013265920|0)==268435456?(t[r>>2]=e,t[r+4>>2]=A&-2130706433|134217728,r=0,r|0):(r=6,r|0)}function b0(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;return s=S,S=S+16|0,n=s,t[n>>2]=0,!0&(A&2013265920|0)==268435456?(i=wA(e|0,A|0,56)|0,M()|0,n=$(e,A&-2130706433|134217728,i&7,n,r)|0,S=s,n|0):(n=6,S=s,n|0)}function t0(e,A){e=e|0,A=A|0;var r=0;switch(r=wA(e|0,A|0,56)|0,M()|0,r&7){case 0:case 7:return r=0,r|0}return r=A&-2130706433|134217728,!(!0&(A&2013265920|0)==268435456)||!0&(A&117440512|0)==16777216&(Oe(e,r)|0)!=0?(r=0,r|0):(r=Ve(e,r)|0,r|0)}function Tn(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0;return s=S,S=S+16|0,n=s,!0&(A&2013265920|0)==268435456?(i=A&-2130706433|134217728,o=r,t[o>>2]=e,t[o+4>>2]=i,t[n>>2]=0,A=wA(e|0,A|0,56)|0,M()|0,n=$(e,i,A&7,n,r+8|0)|0,S=s,n|0):(n=6,S=s,n|0)}function Rn(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0;return s=(Oe(e,A)|0)==0,A=A&-2130706433,n=r,t[n>>2]=s?e:0,t[n+4>>2]=s?A|285212672:0,n=r+8|0,t[n>>2]=e,t[n+4>>2]=A|301989888,n=r+16|0,t[n>>2]=e,t[n+4>>2]=A|318767104,n=r+24|0,t[n>>2]=e,t[n+4>>2]=A|335544320,n=r+32|0,t[n>>2]=e,t[n+4>>2]=A|352321536,r=r+40|0,t[r>>2]=e,t[r+4>>2]=A|369098752,0}function dn(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0;return o=S,S=S+16|0,s=o,i=A&-2130706433|134217728,!0&(A&2013265920|0)==268435456?(n=wA(e|0,A|0,56)|0,M()|0,n=ma(e,i,n&7)|0,(n|0)==-1?(t[r>>2]=0,i=6,S=o,i|0):(jn(e,i,s)|0&&OA(27795,26932,282,26947),A=wA(e|0,A|0,52)|0,M()|0,A=A&15,Oe(e,i)|0?w(s,A,n,2,r):eA(s,A,n,2,r),i=0,S=o,i|0)):(i=6,S=o,i|0)}function k0(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0;n=S,S=S+16|0,s=n,C0(e,A,r,s),Kr(s,r+4|0),S=n}function C0(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0;if(l=S,S=S+16|0,c=l,r0(e,r,c),i=+St(+(1-+C[c>>3]*.5)),i<1e-16){t[n>>2]=0,t[n+4>>2]=0,t[n+8>>2]=0,t[n+12>>2]=0,S=l;return}if(c=t[r>>2]|0,s=+C[15920+(c*24|0)>>3],s=+s0(s-+s0(+Pl(15600+(c<<4)|0,e))),ir(A)|0?o=+s0(s+-.3334731722518321):o=s,s=+et(+i)*2.618033988749896,(A|0)>0){e=0;do s=s*2.6457513110645907,e=e+1|0;while((e|0)!=(A|0))}i=+Be(+o)*s,C[n>>3]=i,o=+se(+o)*s,C[n+8>>3]=o,S=l}function r0(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;if(i=S,S=S+32|0,s=i,da(e,s),t[A>>2]=0,C[r>>3]=5,n=+ut(16400,s),n<+C[r>>3]&&(t[A>>2]=0,C[r>>3]=n),n=+ut(16424,s),n<+C[r>>3]&&(t[A>>2]=1,C[r>>3]=n),n=+ut(16448,s),n<+C[r>>3]&&(t[A>>2]=2,C[r>>3]=n),n=+ut(16472,s),n<+C[r>>3]&&(t[A>>2]=3,C[r>>3]=n),n=+ut(16496,s),n<+C[r>>3]&&(t[A>>2]=4,C[r>>3]=n),n=+ut(16520,s),n<+C[r>>3]&&(t[A>>2]=5,C[r>>3]=n),n=+ut(16544,s),n<+C[r>>3]&&(t[A>>2]=6,C[r>>3]=n),n=+ut(16568,s),n<+C[r>>3]&&(t[A>>2]=7,C[r>>3]=n),n=+ut(16592,s),n<+C[r>>3]&&(t[A>>2]=8,C[r>>3]=n),n=+ut(16616,s),n<+C[r>>3]&&(t[A>>2]=9,C[r>>3]=n),n=+ut(16640,s),n<+C[r>>3]&&(t[A>>2]=10,C[r>>3]=n),n=+ut(16664,s),n<+C[r>>3]&&(t[A>>2]=11,C[r>>3]=n),n=+ut(16688,s),n<+C[r>>3]&&(t[A>>2]=12,C[r>>3]=n),n=+ut(16712,s),n<+C[r>>3]&&(t[A>>2]=13,C[r>>3]=n),n=+ut(16736,s),n<+C[r>>3]&&(t[A>>2]=14,C[r>>3]=n),n=+ut(16760,s),n<+C[r>>3]&&(t[A>>2]=15,C[r>>3]=n),n=+ut(16784,s),n<+C[r>>3]&&(t[A>>2]=16,C[r>>3]=n),n=+ut(16808,s),n<+C[r>>3]&&(t[A>>2]=17,C[r>>3]=n),n=+ut(16832,s),n<+C[r>>3]&&(t[A>>2]=18,C[r>>3]=n),n=+ut(16856,s),!(n<+C[r>>3])){S=i;return}t[A>>2]=19,C[r>>3]=n,S=i}function Zr(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0;if(i=+ha(e),i<1e-16){A=15600+(A<<4)|0,t[s>>2]=t[A>>2],t[s+4>>2]=t[A+4>>2],t[s+8>>2]=t[A+8>>2],t[s+12>>2]=t[A+12>>2];return}if(o=+at(+ +C[e+8>>3],+ +C[e>>3]),(r|0)>0){e=0;do i=i*.37796447300922725,e=e+1|0;while((e|0)!=(r|0))}l=i*.3333333333333333,n?(r=(ir(r)|0)==0,i=+Vt(+((r?l:l*.37796447300922725)*.381966011250105))):(i=+Vt(+(i*.381966011250105)),ir(r)|0&&(o=+s0(o+.3334731722518321))),Ql(15600+(A<<4)|0,+s0(+C[15920+(A*24|0)>>3]-o),i,s)}function m(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0;n=S,S=S+16|0,s=n,H(e+4|0,s),Zr(s,t[e>>2]|0,A,0,r),S=n}function w(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0,he=0,Se=0,ie=0,GA=0,SA=0,xe=0,We=0,de=0;if(xe=S,S=S+272|0,i=xe+256|0,J=xe+240|0,ie=xe,GA=xe+224|0,SA=xe+208|0,Z=xe+176|0,V=xe+160|0,MA=xe+192|0,HA=xe+144|0,QA=xe+128|0,ce=xe+112|0,he=xe+96|0,Se=xe+80|0,t[i>>2]=A,t[J>>2]=t[e>>2],t[J+4>>2]=t[e+4>>2],t[J+8>>2]=t[e+8>>2],t[J+12>>2]=t[e+12>>2],_(J,i,ie),t[s>>2]=0,J=n+r+((n|0)==5&1)|0,(J|0)<=(r|0)){S=xe;return}c=t[i>>2]|0,f=GA+4|0,g=Z+4|0,D=r+5|0,I=16880+(c<<2)|0,L=16960+(c<<2)|0,N=QA+8|0,G=ce+8|0,W=he+8|0,iA=SA+4|0,l=r;A:for(;;){o=ie+(((l|0)%5|0)<<4)|0,t[SA>>2]=t[o>>2],t[SA+4>>2]=t[o+4>>2],t[SA+8>>2]=t[o+8>>2],t[SA+12>>2]=t[o+12>>2];do;while((P(SA,c,0,1)|0)==2);if((l|0)>(r|0)&(ir(A)|0)!=0){if(t[Z>>2]=t[SA>>2],t[Z+4>>2]=t[SA+4>>2],t[Z+8>>2]=t[SA+8>>2],t[Z+12>>2]=t[SA+12>>2],H(f,V),n=t[Z>>2]|0,i=t[17040+(n*80|0)+(t[GA>>2]<<2)>>2]|0,t[Z>>2]=t[18640+(n*80|0)+(i*20|0)>>2],o=t[18640+(n*80|0)+(i*20|0)+16>>2]|0,(o|0)>0){e=0;do _t(g),e=e+1|0;while((e|0)<(o|0))}switch(o=18640+(n*80|0)+(i*20|0)+4|0,t[MA>>2]=t[o>>2],t[MA+4>>2]=t[o+4>>2],t[MA+8>>2]=t[o+8>>2],NA(MA,(t[I>>2]|0)*3|0),tA(g,MA,g),nt(g),H(g,HA),We=+(t[L>>2]|0),C[QA>>3]=We*3,C[N>>3]=0,de=We*-1.5,C[ce>>3]=de,C[G>>3]=We*2.598076211353316,C[he>>3]=de,C[W>>3]=We*-2.598076211353316,t[17040+((t[Z>>2]|0)*80|0)+(t[SA>>2]<<2)>>2]|0){case 1:{e=ce,n=QA;break}case 3:{e=he,n=ce;break}case 2:{e=QA,n=he;break}default:{e=12;break A}}ci(V,HA,n,e,Se),Zr(Se,t[Z>>2]|0,c,1,s+8+(t[s>>2]<<4)|0),t[s>>2]=(t[s>>2]|0)+1}if((l|0)<(D|0)&&(H(iA,Z),Zr(Z,t[SA>>2]|0,c,1,s+8+(t[s>>2]<<4)|0),t[s>>2]=(t[s>>2]|0)+1),t[GA>>2]=t[SA>>2],t[GA+4>>2]=t[SA+4>>2],t[GA+8>>2]=t[SA+8>>2],t[GA+12>>2]=t[SA+12>>2],l=l+1|0,(l|0)>=(J|0)){e=3;break}}if((e|0)==3){S=xe;return}else(e|0)==12&&OA(26970,27017,572,27027)}function _(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0;c=S,S=S+128|0,n=c+64|0,s=c,i=n,o=20240,l=i+60|0;do t[i>>2]=t[o>>2],i=i+4|0,o=o+4|0;while((i|0)<(l|0));i=s,o=20304,l=i+60|0;do t[i>>2]=t[o>>2],i=i+4|0,o=o+4|0;while((i|0)<(l|0));l=(ir(t[A>>2]|0)|0)==0,n=l?n:s,s=e+4|0,qn(s),Jn(s),ir(t[A>>2]|0)|0&&(Ze(s),t[A>>2]=(t[A>>2]|0)+1),t[r>>2]=t[e>>2],A=r+4|0,tA(s,n,A),nt(A),t[r+16>>2]=t[e>>2],A=r+20|0,tA(s,n+12|0,A),nt(A),t[r+32>>2]=t[e>>2],A=r+36|0,tA(s,n+24|0,A),nt(A),t[r+48>>2]=t[e>>2],A=r+52|0,tA(s,n+36|0,A),nt(A),t[r+64>>2]=t[e>>2],r=r+68|0,tA(s,n+48|0,r),nt(r),S=c}function P(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0;if(N=S,S=S+32|0,I=N+12|0,l=N,L=e+4|0,D=t[16960+(A<<2)>>2]|0,g=(n|0)!=0,D=g?D*3|0:D,s=t[L>>2]|0,f=e+8|0,o=t[f>>2]|0,g){if(i=e+12|0,n=t[i>>2]|0,s=o+s+n|0,(s|0)==(D|0))return L=1,S=N,L|0;c=i}else c=e+12|0,n=t[c>>2]|0,s=o+s+n|0;if((s|0)<=(D|0))return L=0,S=N,L|0;do if((n|0)>0){if(n=t[e>>2]|0,(o|0)>0){i=18640+(n*80|0)+60|0,n=e;break}n=18640+(n*80|0)+40|0,r?(hn(I,D,0,0),mA(L,I,l),Fr(l),tA(l,I,L),i=n,n=e):(i=n,n=e)}else i=18640+((t[e>>2]|0)*80|0)+20|0,n=e;while(!1);if(t[n>>2]=t[i>>2],s=i+16|0,(t[s>>2]|0)>0){n=0;do _t(L),n=n+1|0;while((n|0)<(t[s>>2]|0))}return e=i+4|0,t[I>>2]=t[e>>2],t[I+4>>2]=t[e+4>>2],t[I+8>>2]=t[e+8>>2],A=t[16880+(A<<2)>>2]|0,NA(I,g?A*3|0:A),tA(L,I,L),nt(L),g?n=((t[f>>2]|0)+(t[L>>2]|0)+(t[c>>2]|0)|0)==(D|0)?1:2:n=2,L=n,S=N,L|0}function rA(e,A){e=e|0,A=A|0;var r=0;do r=P(e,A,0,1)|0;while((r|0)==2);return r|0}function eA(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0,he=0,Se=0,ie=0;if(he=S,S=S+240|0,i=he+224|0,MA=he+208|0,HA=he,QA=he+192|0,ce=he+176|0,W=he+160|0,iA=he+144|0,J=he+128|0,Z=he+112|0,V=he+96|0,t[i>>2]=A,t[MA>>2]=t[e>>2],t[MA+4>>2]=t[e+4>>2],t[MA+8>>2]=t[e+8>>2],t[MA+12>>2]=t[e+12>>2],pA(MA,i,HA),t[s>>2]=0,G=n+r+((n|0)==6&1)|0,(G|0)<=(r|0)){S=he;return}c=t[i>>2]|0,f=r+6|0,g=16960+(c<<2)|0,D=iA+8|0,I=J+8|0,L=Z+8|0,N=QA+4|0,o=0,l=r,n=-1;A:for(;;){if(i=(l|0)%6|0,e=HA+(i<<4)|0,t[QA>>2]=t[e>>2],t[QA+4>>2]=t[e+4>>2],t[QA+8>>2]=t[e+8>>2],t[QA+12>>2]=t[e+12>>2],e=o,o=P(QA,c,0,1)|0,(l|0)>(r|0)&(ir(A)|0)!=0&&(e|0)!=1&&(t[QA>>2]|0)!=(n|0)){switch(H(HA+(((i+5|0)%6|0)<<4)+4|0,ce),H(HA+(i<<4)+4|0,W),Se=+(t[g>>2]|0),C[iA>>3]=Se*3,C[D>>3]=0,ie=Se*-1.5,C[J>>3]=ie,C[I>>3]=Se*2.598076211353316,C[Z>>3]=ie,C[L>>3]=Se*-2.598076211353316,i=t[MA>>2]|0,t[17040+(i*80|0)+(((n|0)==(i|0)?t[QA>>2]|0:n)<<2)>>2]|0){case 1:{e=J,n=iA;break}case 3:{e=Z,n=J;break}case 2:{e=iA,n=Z;break}default:{e=8;break A}}ci(ce,W,n,e,V),!(fi(ce,V)|0)&&!(fi(W,V)|0)&&(Zr(V,t[MA>>2]|0,c,1,s+8+(t[s>>2]<<4)|0),t[s>>2]=(t[s>>2]|0)+1)}if((l|0)<(f|0)&&(H(N,ce),Zr(ce,t[QA>>2]|0,c,1,s+8+(t[s>>2]<<4)|0),t[s>>2]=(t[s>>2]|0)+1),l=l+1|0,(l|0)>=(G|0)){e=3;break}else n=t[QA>>2]|0}if((e|0)==3){S=he;return}else(e|0)==8&&OA(27054,27017,737,27099)}function pA(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0;c=S,S=S+160|0,n=c+80|0,s=c,i=n,o=20368,l=i+72|0;do t[i>>2]=t[o>>2],i=i+4|0,o=o+4|0;while((i|0)<(l|0));i=s,o=20448,l=i+72|0;do t[i>>2]=t[o>>2],i=i+4|0,o=o+4|0;while((i|0)<(l|0));l=(ir(t[A>>2]|0)|0)==0,n=l?n:s,s=e+4|0,qn(s),Jn(s),ir(t[A>>2]|0)|0&&(Ze(s),t[A>>2]=(t[A>>2]|0)+1),t[r>>2]=t[e>>2],A=r+4|0,tA(s,n,A),nt(A),t[r+16>>2]=t[e>>2],A=r+20|0,tA(s,n+12|0,A),nt(A),t[r+32>>2]=t[e>>2],A=r+36|0,tA(s,n+24|0,A),nt(A),t[r+48>>2]=t[e>>2],A=r+52|0,tA(s,n+36|0,A),nt(A),t[r+64>>2]=t[e>>2],A=r+68|0,tA(s,n+48|0,A),nt(A),t[r+80>>2]=t[e>>2],r=r+84|0,tA(s,n+60|0,r),nt(r),S=c}function DA(e,A){return e=e|0,A=A|0,A=wA(e|0,A|0,52)|0,M()|0,A&15|0}function re(e,A){return e=e|0,A=A|0,A=wA(e|0,A|0,45)|0,M()|0,A&127|0}function ve(e,A,r,n){return e=e|0,A=A|0,r=r|0,n=n|0,(r+-1|0)>>>0>14?(n=4,n|0):(r=wA(e|0,A|0,(15-r|0)*3|0)|0,M()|0,t[n>>2]=r&7,n=0,n|0)}function ye(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0;if(e>>>0>15)return n=4,n|0;if(A>>>0>121)return n=17,n|0;o=CA(e|0,0,52)|0,s=M()|0,l=CA(A|0,0,45)|0,s=s|(M()|0)|134225919;A:do if((e|0)>=1){for(l=1,o=(xA[20528+A>>0]|0)!=0,i=-1;;){if(A=t[r+(l+-1<<2)>>2]|0,A>>>0>6){s=18,A=10;break}if(!((A|0)==0|o^1))if((A|0)==1){s=19,A=10;break}else o=0;if(f=(15-l|0)*3|0,c=CA(7,0,f|0)|0,s=s&~(M()|0),A=CA(A|0,((A|0)<0)<<31>>31|0,f|0)|0,i=A|i&~c,s=M()|0|s,(l|0)<(e|0))l=l+1|0;else break A}if((A|0)==10)return s|0}else i=-1;while(!1);return f=n,t[f>>2]=i,t[f+4>>2]=s,f=0,f|0}function Ve(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0;return!(!0&(A&-16777216|0)==134217728)||(n=wA(e|0,A|0,52)|0,M()|0,n=n&15,r=wA(e|0,A|0,45)|0,M()|0,r=r&127,r>>>0>121)?(e=0,e|0):(o=(n^15)*3|0,s=wA(e|0,A|0,o|0)|0,o=CA(s|0,M()|0,o|0)|0,s=M()|0,i=dt(-1227133514,-1171,o|0,s|0)|0,!((o&613566756&i|0)==0&(s&4681&(M()|0)|0)==0)||(o=(n*3|0)+19|0,i=CA(~e|0,~A|0,o|0)|0,o=wA(i|0,M()|0,o|0)|0,!((n|0)==15|(o|0)==0&(M()|0)==0))?(o=0,o|0):!(xA[20528+r>>0]|0)||(A=A&8191,(e|0)==0&(A|0)==0)?(o=1,o|0):(o=ms(e|0,A|0)|0,M()|0,((63-o|0)%3|0|0)!=0|0))}function Rt(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0;return!0&(A&-16777216|0)==134217728&&(n=wA(e|0,A|0,52)|0,M()|0,n=n&15,r=wA(e|0,A|0,45)|0,M()|0,r=r&127,r>>>0<=121)&&(o=(n^15)*3|0,s=wA(e|0,A|0,o|0)|0,o=CA(s|0,M()|0,o|0)|0,s=M()|0,i=dt(-1227133514,-1171,o|0,s|0)|0,(o&613566756&i|0)==0&(s&4681&(M()|0)|0)==0)&&(o=(n*3|0)+19|0,i=CA(~e|0,~A|0,o|0)|0,o=wA(i|0,M()|0,o|0)|0,(n|0)==15|(o|0)==0&(M()|0)==0)&&(!(xA[20528+r>>0]|0)||(r=A&8191,(e|0)==0&(r|0)==0)||(o=ms(e|0,r|0)|0,M()|0,(63-o|0)%3|0|0))||t0(e,A)|0?(o=1,o|0):(o=(hi(e,A)|0)!=0&1,o|0)}function jt(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0;if(s=CA(A|0,0,52)|0,i=M()|0,r=CA(r|0,0,45)|0,r=i|(M()|0)|134225919,(A|0)<1){i=-1,n=r,A=e,t[A>>2]=i,e=e+4|0,t[e>>2]=n;return}for(i=1,s=-1;o=(15-i|0)*3|0,l=CA(7,0,o|0)|0,r=r&~(M()|0),o=CA(n|0,0,o|0)|0,s=s&~l|o,r=r|(M()|0),(i|0)!=(A|0);)i=i+1|0;l=e,o=l,t[o>>2]=s,l=l+4|0,t[l>>2]=r}function It(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0;if(i=wA(e|0,A|0,52)|0,M()|0,i=i&15,r>>>0>15)return n=4,n|0;if((i|0)<(r|0))return n=12,n|0;if((i|0)==(r|0))return t[n>>2]=e,t[n+4>>2]=A,n=0,n|0;if(s=CA(r|0,0,52)|0,s=s|e,e=M()|0|A&-15728641,(i|0)>(r|0))do A=CA(7,0,(14-r|0)*3|0)|0,r=r+1|0,s=A|s,e=M()|0|e;while((r|0)<(i|0));return t[n>>2]=s,t[n+4>>2]=e,n=0,n|0}function kr(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0;if(i=wA(e|0,A|0,52)|0,M()|0,i=i&15,!((r|0)<16&(i|0)<=(r|0)))return n=4,n|0;s=r-i|0,r=wA(e|0,A|0,45)|0,M()|0;A:do if(!(_e(r&127)|0))r=qr(7,0,s,((s|0)<0)<<31>>31)|0,s=M()|0;else{e:do if(i|0){for(r=1;o=CA(7,0,(15-r|0)*3|0)|0,!!((o&e|0)==0&((M()|0)&A|0)==0);)if(r>>>0>>0)r=r+1|0;else break e;r=qr(7,0,s,((s|0)<0)<<31>>31)|0,s=M()|0;break A}while(!1);r=qr(7,0,s,((s|0)<0)<<31>>31)|0,r=mt(r|0,M()|0,5,0)|0,r=$A(r|0,M()|0,-5,-1)|0,r=Xr(r|0,M()|0,6,0)|0,r=$A(r|0,M()|0,1,0)|0,s=M()|0}while(!1);return o=n,t[o>>2]=r,t[o+4>>2]=s,o=0,o|0}function Oe(e,A){e=e|0,A=A|0;var r=0,n=0,s=0;if(s=wA(e|0,A|0,45)|0,M()|0,!(_e(s&127)|0))return s=0,s|0;s=wA(e|0,A|0,52)|0,M()|0,s=s&15;A:do if(!s)r=0;else for(n=1;;){if(r=wA(e|0,A|0,(15-n|0)*3|0)|0,M()|0,r=r&7,r|0)break A;if(n>>>0>>0)n=n+1|0;else{r=0;break}}while(!1);return s=(r|0)==0&1,s|0}function n0(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0;if(o=S,S=S+16|0,i=o,ls(i,e,A,r),A=i,e=t[A>>2]|0,A=t[A+4>>2]|0,(e|0)==0&(A|0)==0)return S=o,0;s=0,r=0;do l=n+(s<<3)|0,t[l>>2]=e,t[l+4>>2]=A,s=$A(s|0,r|0,1,0)|0,r=M()|0,as(i),l=i,e=t[l>>2]|0,A=t[l+4>>2]|0;while(!((e|0)==0&(A|0)==0));return S=o,0}function Js(e,A,r,n){return e=e|0,A=A|0,r=r|0,n=n|0,(n|0)<(r|0)?(r=A,n=e,WA(r|0),n|0):(r=CA(-1,-1,((n-r|0)*3|0)+3|0)|0,n=CA(~r|0,~(M()|0)|0,(15-n|0)*3|0)|0,r=~(M()|0)&A,n=~n&e,WA(r|0),n|0)}function Xs(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0;return s=wA(e|0,A|0,52)|0,M()|0,s=s&15,(r|0)<16&(s|0)<=(r|0)?((s|0)<(r|0)&&(s=CA(-1,-1,((r+-1-s|0)*3|0)+3|0)|0,s=CA(~s|0,~(M()|0)|0,(15-r|0)*3|0)|0,A=~(M()|0)&A,e=~s&e),s=CA(r|0,0,52)|0,r=A&-15728641|(M()|0),t[n>>2]=e|s,t[n+4>>2]=r,n=0,n|0):(n=4,n|0)}function El(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0,he=0,Se=0,ie=0,GA=0,SA=0;if((r|0)==0&(n|0)==0)return SA=0,SA|0;if(s=e,i=t[s>>2]|0,s=t[s+4>>2]|0,!0&(s&15728640|0)==0){if(!((n|0)>0|(n|0)==0&r>>>0>0)||(SA=A,t[SA>>2]=i,t[SA+4>>2]=s,(r|0)==1&(n|0)==0))return SA=0,SA|0;s=1,i=0;do ie=e+(s<<3)|0,GA=t[ie+4>>2]|0,SA=A+(s<<3)|0,t[SA>>2]=t[ie>>2],t[SA+4>>2]=GA,s=$A(s|0,i|0,1,0)|0,i=M()|0;while((i|0)<(n|0)|(i|0)==(n|0)&s>>>0>>0);return s=0,s|0}if(Se=r<<3,GA=Cr(Se)|0,!GA)return SA=13,SA|0;if(Pn(GA|0,e|0,Se|0)|0,ie=Ht(r,8)|0,!ie)return ZA(GA),SA=13,SA|0;A:for(;;){s=GA,f=t[s>>2]|0,s=t[s+4>>2]|0,ce=wA(f|0,s|0,52)|0,M()|0,ce=ce&15,he=ce+-1|0,QA=(ce|0)!=0,HA=(n|0)>0|(n|0)==0&r>>>0>0;e:do if(QA&HA){if(J=CA(he|0,0,52)|0,Z=M()|0,he>>>0>15){if(!((f|0)==0&(s|0)==0)){SA=16;break A}for(i=0,e=0;;){if(i=$A(i|0,e|0,1,0)|0,e=M()|0,!((e|0)<(n|0)|(e|0)==(n|0)&i>>>0>>0))break e;if(o=GA+(i<<3)|0,MA=t[o>>2]|0,o=t[o+4>>2]|0,!((MA|0)==0&(o|0)==0)){s=o,SA=16;break A}}}for(l=f,e=s,i=0,o=0;;){if(!((l|0)==0&(e|0)==0)){if(!(!0&(e&117440512|0)==0)){SA=21;break A}if(g=wA(l|0,e|0,52)|0,M()|0,g=g&15,(g|0)<(he|0)){s=12,SA=27;break A}if((g|0)!=(he|0)&&(l=l|J,e=e&-15728641|Z,g>>>0>=ce>>>0)){c=he;do MA=CA(7,0,(14-c|0)*3|0)|0,c=c+1|0,l=MA|l,e=M()|0|e;while(c>>>0>>0)}if(I=Fn(l|0,e|0,r|0,n|0)|0,L=M()|0,c=ie+(I<<3)|0,g=c,D=t[g>>2]|0,g=t[g+4>>2]|0,!((D|0)==0&(g|0)==0)){W=0,iA=0;do{if((W|0)>(n|0)|(W|0)==(n|0)&iA>>>0>r>>>0){SA=31;break A}if((D|0)==(l|0)&(g&-117440513|0)==(e|0)){N=wA(D|0,g|0,56)|0,M()|0,N=N&7,G=N+1|0,MA=wA(D|0,g|0,45)|0,M()|0;t:do if(!(_e(MA&127)|0))g=7;else{if(D=wA(D|0,g|0,52)|0,M()|0,D=D&15,!D){g=6;break}for(g=1;;){if(MA=CA(7,0,(15-g|0)*3|0)|0,!((MA&l|0)==0&((M()|0)&e|0)==0)){g=7;break t}if(g>>>0>>0)g=g+1|0;else{g=6;break}}}while(!1);if((N+2|0)>>>0>g>>>0){SA=41;break A}MA=CA(G|0,0,56)|0,e=M()|0|e&-117440513,V=c,t[V>>2]=0,t[V+4>>2]=0,l=MA|l}else I=$A(I|0,L|0,1,0)|0,I=Nn(I|0,M()|0,r|0,n|0)|0,L=M()|0;iA=$A(iA|0,W|0,1,0)|0,W=M()|0,c=ie+(I<<3)|0,g=c,D=t[g>>2]|0,g=t[g+4>>2]|0}while(!((D|0)==0&(g|0)==0))}MA=c,t[MA>>2]=l,t[MA+4>>2]=e}if(i=$A(i|0,o|0,1,0)|0,o=M()|0,!((o|0)<(n|0)|(o|0)==(n|0)&i>>>0>>0))break e;e=GA+(i<<3)|0,l=t[e>>2]|0,e=t[e+4>>2]|0}}while(!1);if(MA=$A(r|0,n|0,5,0)|0,V=M()|0,V>>>0<0|(V|0)==0&MA>>>0<11){SA=85;break}if(MA=Xr(r|0,n|0,6,0)|0,M()|0,MA=Ht(MA,8)|0,!MA){SA=48;break}do if(HA){for(G=0,e=0,N=0,W=0;;){if(g=ie+(G<<3)|0,o=g,i=t[o>>2]|0,o=t[o+4>>2]|0,(i|0)==0&(o|0)==0)V=N;else{D=wA(i|0,o|0,56)|0,M()|0,D=D&7,l=D+1|0,I=o&-117440513,V=wA(i|0,o|0,45)|0,M()|0;e:do if(_e(V&127)|0){if(L=wA(i|0,o|0,52)|0,M()|0,L=L&15,L|0)for(c=1;;){if(V=CA(7,0,(15-c|0)*3|0)|0,!((i&V|0)==0&(I&(M()|0)|0)==0))break e;if(c>>>0>>0)c=c+1|0;else break}o=CA(l|0,0,56)|0,i=o|i,o=M()|0|I,l=g,t[l>>2]=i,t[l+4>>2]=o,l=D+2|0}while(!1);(l|0)==7?(V=MA+(e<<3)|0,t[V>>2]=i,t[V+4>>2]=o&-117440513,e=$A(e|0,N|0,1,0)|0,V=M()|0):V=N}if(G=$A(G|0,W|0,1,0)|0,W=M()|0,(W|0)<(n|0)|(W|0)==(n|0)&G>>>0>>0)N=V;else break}if(HA){if(iA=he>>>0>15,J=CA(he|0,0,52)|0,Z=M()|0,!QA){for(i=0,c=0,l=0,o=0;(f|0)==0&(s|0)==0||(he=A+(i<<3)|0,t[he>>2]=f,t[he+4>>2]=s,i=$A(i|0,c|0,1,0)|0,c=M()|0),l=$A(l|0,o|0,1,0)|0,o=M()|0,!!((o|0)<(n|0)|(o|0)==(n|0)&l>>>0>>0);)s=GA+(l<<3)|0,f=t[s>>2]|0,s=t[s+4>>2]|0;s=V;break}for(i=0,c=0,o=0,l=0;;){do if(!((f|0)==0&(s|0)==0)){if(L=wA(f|0,s|0,52)|0,M()|0,L=L&15,iA|(L|0)<(he|0)){SA=80;break A}if((L|0)!=(he|0)){if(g=f|J,D=s&-15728641|Z,L>>>0>=ce>>>0){I=he;do QA=CA(7,0,(14-I|0)*3|0)|0,I=I+1|0,g=QA|g,D=M()|0|D;while(I>>>0>>0)}}else g=f,D=s;N=Fn(g|0,D|0,r|0,n|0)|0,I=0,L=0,W=M()|0;do{if((I|0)>(n|0)|(I|0)==(n|0)&L>>>0>r>>>0){SA=81;break A}if(QA=ie+(N<<3)|0,G=t[QA+4>>2]|0,(G&-117440513|0)==(D|0)&&(t[QA>>2]|0)==(g|0)){SA=65;break}QA=$A(N|0,W|0,1,0)|0,N=Nn(QA|0,M()|0,r|0,n|0)|0,W=M()|0,L=$A(L|0,I|0,1,0)|0,I=M()|0,QA=ie+(N<<3)|0}while(!((t[QA>>2]|0)==(g|0)&&(t[QA+4>>2]|0)==(D|0)));if((SA|0)==65&&(SA=0,!0&(G&117440512|0)==100663296))break;QA=A+(i<<3)|0,t[QA>>2]=f,t[QA+4>>2]=s,i=$A(i|0,c|0,1,0)|0,c=M()|0}while(!1);if(o=$A(o|0,l|0,1,0)|0,l=M()|0,!((l|0)<(n|0)|(l|0)==(n|0)&o>>>0>>0))break;s=GA+(o<<3)|0,f=t[s>>2]|0,s=t[s+4>>2]|0}s=V}else i=0,s=V}else i=0,e=0,s=0;while(!1);if(An(ie|0,0,Se|0)|0,Pn(GA|0,MA|0,e<<3|0)|0,ZA(MA),(e|0)==0&(s|0)==0){SA=89;break}else A=A+(i<<3)|0,n=s,r=e}if((SA|0)==16)!0&(s&117440512|0)==0?(s=4,SA=27):SA=21;else if((SA|0)==31)OA(27795,27122,620,27132);else{if((SA|0)==41)return ZA(GA),ZA(ie),SA=10,SA|0;if((SA|0)==48)return ZA(GA),ZA(ie),SA=13,SA|0;(SA|0)==80?OA(27795,27122,711,27132):(SA|0)==81?OA(27795,27122,723,27132):(SA|0)==85&&(Pn(A|0,GA|0,r<<3|0)|0,SA=89)}return(SA|0)==21?(ZA(GA),ZA(ie),SA=5,SA|0):(SA|0)==27?(ZA(GA),ZA(ie),SA=s,SA|0):(SA|0)==89?(ZA(GA),ZA(ie),SA=0,SA|0):0}function Ml(e,A,r,n,s,i,o){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0,i=i|0,o=o|0;var l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0;if(G=S,S=S+16|0,N=G,!((r|0)>0|(r|0)==0&A>>>0>0))return N=0,S=G,N|0;if((o|0)>=16)return N=12,S=G,N|0;I=0,L=0,D=0,l=0;A:for(;;){if(f=e+(I<<3)|0,c=t[f>>2]|0,f=t[f+4>>2]|0,g=wA(c|0,f|0,52)|0,M()|0,(g&15|0)>(o|0)){l=12,c=11;break}if(ls(N,c,f,o),g=N,f=t[g>>2]|0,g=t[g+4>>2]|0,(f|0)==0&(g|0)==0)c=D;else{c=D;do{if(!((l|0)<(i|0)|(l|0)==(i|0)&c>>>0>>0)){c=10;break A}D=n+(c<<3)|0,t[D>>2]=f,t[D+4>>2]=g,c=$A(c|0,l|0,1,0)|0,l=M()|0,as(N),D=N,f=t[D>>2]|0,g=t[D+4>>2]|0}while(!((f|0)==0&(g|0)==0))}if(I=$A(I|0,L|0,1,0)|0,L=M()|0,(L|0)<(r|0)|(L|0)==(r|0)&I>>>0>>0)D=c;else{l=0,c=11;break}}return(c|0)==10?(N=14,S=G,N|0):(c|0)==11?(S=G,l|0):0}function Bl(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0;I=S,S=S+16|0,D=I;A:do if((r|0)>0|(r|0)==0&A>>>0>0){for(f=0,o=0,i=0,g=0;;){if(c=e+(f<<3)|0,l=t[c>>2]|0,c=t[c+4>>2]|0,!((l|0)==0&(c|0)==0)&&(c=(kr(l,c,n,D)|0)==0,l=D,o=$A(t[l>>2]|0,t[l+4>>2]|0,o|0,i|0)|0,i=M()|0,!c)){i=12;break}if(f=$A(f|0,g|0,1,0)|0,g=M()|0,!((g|0)<(r|0)|(g|0)==(r|0)&f>>>0>>0))break A}return S=I,i|0}else o=0,i=0;while(!1);return t[s>>2]=o,t[s+4>>2]=i,s=0,S=I,s|0}function Dl(e,A){return e=e|0,A=A|0,A=wA(e|0,A|0,52)|0,M()|0,A&1|0}function zt(e,A){e=e|0,A=A|0;var r=0,n=0,s=0;if(s=wA(e|0,A|0,52)|0,M()|0,s=s&15,!s)return s=0,s|0;for(n=1;;){if(r=wA(e|0,A|0,(15-n|0)*3|0)|0,M()|0,r=r&7,r|0){n=5;break}if(n>>>0>>0)n=n+1|0;else{r=0,n=5;break}}return(n|0)==5?r|0:0}function rs(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0;if(c=wA(e|0,A|0,52)|0,M()|0,c=c&15,!c)return l=A,c=e,WA(l|0),c|0;for(l=1,r=0;;){i=(15-l|0)*3|0,n=CA(7,0,i|0)|0,s=M()|0,o=wA(e|0,A|0,i|0)|0,M()|0,i=CA($t(o&7)|0,0,i|0)|0,o=M()|0,e=i|e&~n,A=o|A&~s;A:do if(!r)if((i&n|0)==0&(o&s|0)==0)r=0;else if(n=wA(e|0,A|0,52)|0,M()|0,n=n&15,!n)r=1;else{r=1;e:for(;;){switch(o=wA(e|0,A|0,(15-r|0)*3|0)|0,M()|0,o&7){case 1:break e;case 0:break;default:{r=1;break A}}if(r>>>0>>0)r=r+1|0;else{r=1;break A}}for(r=1;;)if(o=(15-r|0)*3|0,s=wA(e|0,A|0,o|0)|0,M()|0,i=CA(7,0,o|0)|0,A=A&~(M()|0),o=CA($t(s&7)|0,0,o|0)|0,e=e&~i|o,A=A|(M()|0),r>>>0>>0)r=r+1|0;else{r=1;break}}while(!1);if(l>>>0>>0)l=l+1|0;else break}return WA(A|0),e|0}function mn(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0;if(n=wA(e|0,A|0,52)|0,M()|0,n=n&15,!n)return r=A,n=e,WA(r|0),n|0;for(r=1;i=(15-r|0)*3|0,o=wA(e|0,A|0,i|0)|0,M()|0,s=CA(7,0,i|0)|0,A=A&~(M()|0),i=CA($t(o&7)|0,0,i|0)|0,e=i|e&~s,A=M()|0|A,r>>>0>>0;)r=r+1|0;return WA(A|0),e|0}function _l(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0;if(c=wA(e|0,A|0,52)|0,M()|0,c=c&15,!c)return l=A,c=e,WA(l|0),c|0;for(l=1,r=0;;){i=(15-l|0)*3|0,n=CA(7,0,i|0)|0,s=M()|0,o=wA(e|0,A|0,i|0)|0,M()|0,i=CA(Kt(o&7)|0,0,i|0)|0,o=M()|0,e=i|e&~n,A=o|A&~s;A:do if(!r)if((i&n|0)==0&(o&s|0)==0)r=0;else if(n=wA(e|0,A|0,52)|0,M()|0,n=n&15,!n)r=1;else{r=1;e:for(;;){switch(o=wA(e|0,A|0,(15-r|0)*3|0)|0,M()|0,o&7){case 1:break e;case 0:break;default:{r=1;break A}}if(r>>>0>>0)r=r+1|0;else{r=1;break A}}for(r=1;;)if(s=(15-r|0)*3|0,i=CA(7,0,s|0)|0,o=A&~(M()|0),A=wA(e|0,A|0,s|0)|0,M()|0,A=CA(Kt(A&7)|0,0,s|0)|0,e=e&~i|A,A=o|(M()|0),r>>>0>>0)r=r+1|0;else{r=1;break}}while(!1);if(l>>>0>>0)l=l+1|0;else break}return WA(A|0),e|0}function ns(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0;if(n=wA(e|0,A|0,52)|0,M()|0,n=n&15,!n)return r=A,n=e,WA(r|0),n|0;for(r=1;o=(15-r|0)*3|0,i=CA(7,0,o|0)|0,s=A&~(M()|0),A=wA(e|0,A|0,o|0)|0,M()|0,A=CA(Kt(A&7)|0,0,o|0)|0,e=A|e&~i,A=M()|0|s,r>>>0>>0;)r=r+1|0;return WA(A|0),e|0}function Tl(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(c=S,S=S+64|0,l=c+40|0,n=c+24|0,s=c+12|0,i=c,CA(A|0,0,52)|0,r=M()|0|134225919,!A)return(t[e+4>>2]|0)>2||(t[e+8>>2]|0)>2||(t[e+12>>2]|0)>2?(o=0,l=0,WA(o|0),S=c,l|0):(CA(wr(e)|0,0,45)|0,o=M()|0|r,l=-1,WA(o|0),S=c,l|0);if(t[l>>2]=t[e>>2],t[l+4>>2]=t[e+4>>2],t[l+8>>2]=t[e+8>>2],t[l+12>>2]=t[e+12>>2],o=l+4|0,(A|0)>0)for(e=-1;t[n>>2]=t[o>>2],t[n+4>>2]=t[o+4>>2],t[n+8>>2]=t[o+8>>2],A&1?(He(o),t[s>>2]=t[o>>2],t[s+4>>2]=t[o+4>>2],t[s+8>>2]=t[o+8>>2],bt(s)):(st(o),t[s>>2]=t[o>>2],t[s+4>>2]=t[o+4>>2],t[s+8>>2]=t[o+8>>2],Ze(s)),mA(n,s,i),nt(i),g=(15-A|0)*3|0,f=CA(7,0,g|0)|0,r=r&~(M()|0),g=CA(zA(i)|0,0,g|0)|0,e=g|e&~f,r=M()|0|r,(A|0)>1;)A=A+-1|0;else e=-1;A:do if((t[o>>2]|0)<=2&&(t[l+8>>2]|0)<=2&&(t[l+12>>2]|0)<=2){if(n=wr(l)|0,A=CA(n|0,0,45)|0,A=A|e,e=M()|0|r&-1040385,i=nr(l)|0,!(_e(n)|0)){if((i|0)<=0)break;for(s=0;;){if(n=wA(A|0,e|0,52)|0,M()|0,n=n&15,n)for(r=1;g=(15-r|0)*3|0,l=wA(A|0,e|0,g|0)|0,M()|0,f=CA(7,0,g|0)|0,e=e&~(M()|0),g=CA($t(l&7)|0,0,g|0)|0,A=A&~f|g,e=e|(M()|0),r>>>0>>0;)r=r+1|0;if(s=s+1|0,(s|0)==(i|0))break A}}s=wA(A|0,e|0,52)|0,M()|0,s=s&15;e:do if(s){r=1;t:for(;;){switch(g=wA(A|0,e|0,(15-r|0)*3|0)|0,M()|0,g&7){case 1:break t;case 0:break;default:break e}if(r>>>0>>0)r=r+1|0;else break e}if(Ir(n,t[l>>2]|0)|0)for(r=1;l=(15-r|0)*3|0,f=CA(7,0,l|0)|0,g=e&~(M()|0),e=wA(A|0,e|0,l|0)|0,M()|0,e=CA(Kt(e&7)|0,0,l|0)|0,A=A&~f|e,e=g|(M()|0),r>>>0>>0;)r=r+1|0;else for(r=1;g=(15-r|0)*3|0,l=wA(A|0,e|0,g|0)|0,M()|0,f=CA(7,0,g|0)|0,e=e&~(M()|0),g=CA($t(l&7)|0,0,g|0)|0,A=A&~f|g,e=e|(M()|0),r>>>0>>0;)r=r+1|0}while(!1);if((i|0)>0){r=0;do A=rs(A,e)|0,e=M()|0,r=r+1|0;while((r|0)!=(i|0))}}else A=0,e=0;while(!1);return f=e,g=A,WA(f|0),S=c,g|0}function ir(e){return e=e|0,(e|0)%2|0|0}function ss(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0;return s=S,S=S+16|0,n=s,A>>>0>15?(n=4,S=s,n|0):(t[e+4>>2]&2146435072|0)==2146435072||(t[e+8+4>>2]&2146435072|0)==2146435072?(n=3,S=s,n|0):(k0(e,A,n),A=Tl(n,A)|0,n=M()|0,t[r>>2]=A,t[r+4>>2]=n,(A|0)==0&(n|0)==0&&OA(27795,27122,1050,27145),n=0,S=s,n|0)}function is(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0;if(s=r+4|0,i=wA(e|0,A|0,52)|0,M()|0,i=i&15,o=wA(e|0,A|0,45)|0,M()|0,n=(i|0)==0,_e(o&127)|0){if(n)return o=1,o|0;n=1}else{if(n)return o=0,o|0;(t[s>>2]|0)==0&&(t[r+8>>2]|0)==0?n=(t[r+12>>2]|0)!=0&1:n=1}for(r=1;r&1?bt(s):Ze(s),o=wA(e|0,A|0,(15-r|0)*3|0)|0,M()|0,ot(s,o&7),r>>>0>>0;)r=r+1|0;return n|0}function jn(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(g=S,S=S+16|0,c=g,f=wA(e|0,A|0,45)|0,M()|0,f=f&127,f>>>0>121)return t[r>>2]=0,t[r+4>>2]=0,t[r+8>>2]=0,t[r+12>>2]=0,f=5,S=g,f|0;A:do if((_e(f)|0)!=0&&(i=wA(e|0,A|0,52)|0,M()|0,i=i&15,(i|0)!=0)){n=1;e:for(;;){switch(l=wA(e|0,A|0,(15-n|0)*3|0)|0,M()|0,l&7){case 5:break e;case 0:break;default:{n=A;break A}}if(n>>>0>>0)n=n+1|0;else{n=A;break A}}for(s=1,n=A;A=(15-s|0)*3|0,o=CA(7,0,A|0)|0,l=n&~(M()|0),n=wA(e|0,n|0,A|0)|0,M()|0,n=CA(Kt(n&7)|0,0,A|0)|0,e=e&~o|n,n=l|(M()|0),s>>>0>>0;)s=s+1|0}else n=A;while(!1);if(l=7696+(f*28|0)|0,t[r>>2]=t[l>>2],t[r+4>>2]=t[l+4>>2],t[r+8>>2]=t[l+8>>2],t[r+12>>2]=t[l+12>>2],!(is(e,n,r)|0))return f=0,S=g,f|0;if(o=r+4|0,t[c>>2]=t[o>>2],t[c+4>>2]=t[o+4>>2],t[c+8>>2]=t[o+8>>2],i=wA(e|0,n|0,52)|0,M()|0,l=i&15,i&1?(Ze(o),i=l+1|0):i=l,!(_e(f)|0))n=0;else{A:do if(!l)n=0;else for(A=1;;){if(s=wA(e|0,n|0,(15-A|0)*3|0)|0,M()|0,s=s&7,s|0){n=s;break A}if(A>>>0>>0)A=A+1|0;else{n=0;break}}while(!1);n=(n|0)==4&1}if(!(P(r,i,n,0)|0))(i|0)!=(l|0)&&(t[o>>2]=t[c>>2],t[o+4>>2]=t[c+4>>2],t[o+8>>2]=t[c+8>>2]);else{if(_e(f)|0)do;while((P(r,i,0,0)|0)!=0);(i|0)!=(l|0)&&st(o)}return f=0,S=g,f|0}function pn(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;return i=S,S=S+16|0,n=i,s=jn(e,A,n)|0,s|0?(S=i,s|0):(s=wA(e|0,A|0,52)|0,M()|0,m(n,s&15,r),s=0,S=i,s|0)}function In(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0;if(o=S,S=S+16|0,i=o,n=jn(e,A,i)|0,n|0)return i=n,S=o,i|0;n=wA(e|0,A|0,45)|0,M()|0,n=(_e(n&127)|0)==0,s=wA(e|0,A|0,52)|0,M()|0,s=s&15;A:do if(!n){if(s|0)for(n=1;;){if(l=CA(7,0,(15-n|0)*3|0)|0,!((l&e|0)==0&((M()|0)&A|0)==0))break A;if(n>>>0>>0)n=n+1|0;else break}return w(i,s,0,5,r),l=0,S=o,l|0}while(!1);return eA(i,s,0,6,r),l=0,S=o,l|0}function Rl(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;if(s=wA(e|0,A|0,45)|0,M()|0,!(_e(s&127)|0))return s=2,t[r>>2]=s,0;if(s=wA(e|0,A|0,52)|0,M()|0,s=s&15,!s)return s=5,t[r>>2]=s,0;for(n=1;;){if(i=CA(7,0,(15-n|0)*3|0)|0,!((i&e|0)==0&((M()|0)&A|0)==0)){n=2,e=6;break}if(n>>>0>>0)n=n+1|0;else{n=5,e=6;break}}return(e|0)==6&&(t[r>>2]=n),0}function Ai(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0;D=S,S=S+128|0,f=D+112|0,i=D+96|0,g=D,s=wA(e|0,A|0,52)|0,M()|0,l=s&15,t[f>>2]=l,o=wA(e|0,A|0,45)|0,M()|0,o=o&127;A:do if(_e(o)|0){if(l|0)for(n=1;;){if(c=CA(7,0,(15-n|0)*3|0)|0,!((c&e|0)==0&((M()|0)&A|0)==0)){s=0;break A}if(n>>>0>>0)n=n+1|0;else break}if(s&1)s=1;else return c=CA(l+1|0,0,52)|0,g=M()|0|A&-15728641,f=CA(7,0,(14-l|0)*3|0)|0,g=Ai((c|e)&~f,g&~(M()|0),r)|0,S=D,g|0}else s=0;while(!1);if(n=jn(e,A,i)|0,!n){s?(_(i,f,g),c=5):(pA(i,f,g),c=6);A:do if(_e(o)|0)if(!l)e=5;else for(n=1;;){if(o=CA(7,0,(15-n|0)*3|0)|0,!((o&e|0)==0&((M()|0)&A|0)==0)){e=2;break A}if(n>>>0>>0)n=n+1|0;else{e=5;break}}else e=2;while(!1);An(r|0,-1,e<<2|0)|0;A:do if(s)for(i=0;;){if(o=g+(i<<4)|0,rA(o,t[f>>2]|0)|0,o=t[o>>2]|0,l=t[r>>2]|0,(l|0)==-1|(l|0)==(o|0))n=r;else{s=0;do{if(s=s+1|0,s>>>0>=e>>>0){n=1;break A}n=r+(s<<2)|0,l=t[n>>2]|0}while(!((l|0)==-1|(l|0)==(o|0)))}if(t[n>>2]=o,i=i+1|0,i>>>0>=c>>>0){n=0;break}}else for(i=0;;){if(o=g+(i<<4)|0,P(o,t[f>>2]|0,0,1)|0,o=t[o>>2]|0,l=t[r>>2]|0,(l|0)==-1|(l|0)==(o|0))n=r;else{s=0;do{if(s=s+1|0,s>>>0>=e>>>0){n=1;break A}n=r+(s<<2)|0,l=t[n>>2]|0}while(!((l|0)==-1|(l|0)==(o|0)))}if(t[n>>2]=o,i=i+1|0,i>>>0>=c>>>0){n=0;break}}while(!1)}return g=n,S=D,g|0}function jl(){return 12}function os(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0;if(e>>>0>15)return l=4,l|0;if(CA(e|0,0,52)|0,l=M()|0|134225919,!e){r=0,n=0;do _e(n)|0&&(CA(n|0,0,45)|0,o=l|(M()|0),e=A+(r<<3)|0,t[e>>2]=-1,t[e+4>>2]=o,r=r+1|0),n=n+1|0;while((n|0)!=122);return r=0,r|0}r=0,o=0;do{if(_e(o)|0){for(CA(o|0,0,45)|0,n=1,s=-1,i=l|(M()|0);c=CA(7,0,(15-n|0)*3|0)|0,s=s&~c,i=i&~(M()|0),(n|0)!=(e|0);)n=n+1|0;c=A+(r<<3)|0,t[c>>2]=s,t[c+4>>2]=i,r=r+1|0}o=o+1|0}while((o|0)!=122);return r=0,r|0}function Il(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0;if(J=S,S=S+16|0,W=J,iA=wA(e|0,A|0,52)|0,M()|0,iA=iA&15,r>>>0>15)return iA=4,S=J,iA|0;if((iA|0)<(r|0))return iA=12,S=J,iA|0;if((iA|0)!=(r|0))if(i=CA(r|0,0,52)|0,i=i|e,l=M()|0|A&-15728641,(iA|0)>(r|0)){c=r;do G=CA(7,0,(14-c|0)*3|0)|0,c=c+1|0,i=G|i,l=M()|0|l;while((c|0)<(iA|0));G=i}else G=i;else G=e,l=A;N=wA(G|0,l|0,45)|0,M()|0;A:do if(_e(N&127)|0){if(c=wA(G|0,l|0,52)|0,M()|0,c=c&15,c|0)for(i=1;;){if(N=CA(7,0,(15-i|0)*3|0)|0,!((N&G|0)==0&((M()|0)&l|0)==0)){f=33;break A}if(i>>>0>>0)i=i+1|0;else break}if(N=n,t[N>>2]=0,t[N+4>>2]=0,(iA|0)>(r|0)){for(N=A&-15728641,L=iA;;){if(I=L,L=L+-1|0,L>>>0>15|(iA|0)<(L|0)){f=19;break}if((iA|0)!=(L|0))if(i=CA(L|0,0,52)|0,i=i|e,c=M()|0|N,(iA|0)<(I|0))D=i;else{f=L;do D=CA(7,0,(14-f|0)*3|0)|0,f=f+1|0,i=D|i,c=M()|0|c;while((f|0)<(iA|0));D=i}else D=e,c=A;if(g=wA(D|0,c|0,45)|0,M()|0,!(_e(g&127)|0))i=0;else{g=wA(D|0,c|0,52)|0,M()|0,g=g&15;e:do if(!g)i=0;else for(f=1;;){if(i=wA(D|0,c|0,(15-f|0)*3|0)|0,M()|0,i=i&7,i|0)break e;if(f>>>0>>0)f=f+1|0;else{i=0;break}}while(!1);i=(i|0)==0&1}if(c=wA(e|0,A|0,(15-I|0)*3|0)|0,M()|0,c=c&7,(c|0)==7){s=5,f=42;break}if(i=(i|0)!=0,(c|0)==1&i){s=5,f=42;break}if(D=c+(((c|0)!=0&i)<<31>>31)|0,D|0&&(f=iA-I|0,f=qr(7,0,f,((f|0)<0)<<31>>31)|0,g=M()|0,i?(i=mt(f|0,g|0,5,0)|0,i=$A(i|0,M()|0,-5,-1)|0,i=Xr(i|0,M()|0,6,0)|0,i=$A(i|0,M()|0,1,0)|0,c=M()|0):(i=f,c=g),I=D+-1|0,I=mt(f|0,g|0,I|0,((I|0)<0)<<31>>31|0)|0,I=$A(i|0,c|0,I|0,M()|0)|0,D=M()|0,g=n,g=$A(I|0,D|0,t[g>>2]|0,t[g+4>>2]|0)|0,D=M()|0,I=n,t[I>>2]=g,t[I+4>>2]=D),(L|0)<=(r|0)){f=37;break}}if((f|0)==19)OA(27795,27122,1367,27158);else if((f|0)==37){o=n,s=t[o+4>>2]|0,o=t[o>>2]|0;break}else if((f|0)==42)return S=J,s|0}else s=0,o=0}else f=33;while(!1);A:do if((f|0)==33)if(N=n,t[N>>2]=0,t[N+4>>2]=0,(iA|0)>(r|0)){for(i=iA;;){if(s=wA(e|0,A|0,(15-i|0)*3|0)|0,M()|0,s=s&7,(s|0)==7){s=5;break}if(o=iA-i|0,o=qr(7,0,o,((o|0)<0)<<31>>31)|0,s=mt(o|0,M()|0,s|0,0)|0,o=M()|0,N=n,o=$A(t[N>>2]|0,t[N+4>>2]|0,s|0,o|0)|0,s=M()|0,N=n,t[N>>2]=o,t[N+4>>2]=s,i=i+-1|0,(i|0)<=(r|0))break A}return S=J,s|0}else s=0,o=0;while(!1);return kr(G,l,iA,W)|0&&OA(27795,27122,1327,27173),iA=W,W=t[iA+4>>2]|0,((s|0)>-1|(s|0)==-1&o>>>0>4294967295)&((W|0)>(s|0)|((W|0)==(s|0)?(t[iA>>2]|0)>>>0>o>>>0:0))?(iA=0,S=J,iA|0):(OA(27795,27122,1407,27158),0)}function Ll(e,A,r,n,s,i){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0,i=i|0;var o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0;if(D=S,S=S+16|0,o=D,s>>>0>15)return i=4,S=D,i|0;if(l=wA(r|0,n|0,52)|0,M()|0,l=l&15,(l|0)>(s|0))return i=12,S=D,i|0;if(kr(r,n,s,o)|0&&OA(27795,27122,1327,27173),g=o,f=t[g+4>>2]|0,!(((A|0)>-1|(A|0)==-1&e>>>0>4294967295)&((f|0)>(A|0)|((f|0)==(A|0)?(t[g>>2]|0)>>>0>e>>>0:0))))return i=2,S=D,i|0;g=s-l|0,s=CA(s|0,0,52)|0,c=M()|0|n&-15728641,f=i,t[f>>2]=s|r,t[f+4>>2]=c,f=wA(r|0,n|0,45)|0,M()|0;A:do if(_e(f&127)|0){if(l|0)for(o=1;;){if(f=CA(7,0,(15-o|0)*3|0)|0,!((f&r|0)==0&((M()|0)&n|0)==0))break A;if(o>>>0>>0)o=o+1|0;else break}if((g|0)<1)return i=0,S=D,i|0;for(f=l^15,n=-1,c=1,o=1;;){l=g-c|0,l=qr(7,0,l,((l|0)<0)<<31>>31)|0,r=M()|0;do if(o)if(o=mt(l|0,r|0,5,0)|0,o=$A(o|0,M()|0,-5,-1)|0,o=Xr(o|0,M()|0,6,0)|0,s=M()|0,(A|0)>(s|0)|(A|0)==(s|0)&e>>>0>o>>>0){A=$A(e|0,A|0,-1,-1)|0,A=dt(A|0,M()|0,o|0,s|0)|0,o=M()|0,I=i,N=t[I>>2]|0,I=t[I+4>>2]|0,G=(f+n|0)*3|0,L=CA(7,0,G|0)|0,I=I&~(M()|0),n=Xr(A|0,o|0,l|0,r|0)|0,e=M()|0,s=$A(n|0,e|0,2,0)|0,G=CA(s|0,M()|0,G|0)|0,I=M()|0|I,s=i,t[s>>2]=G|N&~L,t[s+4>>2]=I,e=mt(n|0,e|0,l|0,r|0)|0,e=dt(A|0,o|0,e|0,M()|0)|0,o=0,A=M()|0;break}else{G=i,L=t[G>>2]|0,G=t[G+4>>2]|0,N=CA(7,0,(f+n|0)*3|0)|0,G=G&~(M()|0),o=i,t[o>>2]=L&~N,t[o+4>>2]=G,o=1;break}else L=i,s=t[L>>2]|0,L=t[L+4>>2]|0,n=(f+n|0)*3|0,I=CA(7,0,n|0)|0,L=L&~(M()|0),G=Xr(e|0,A|0,l|0,r|0)|0,o=M()|0,n=CA(G|0,o|0,n|0)|0,L=M()|0|L,N=i,t[N>>2]=n|s&~I,t[N+4>>2]=L,o=mt(G|0,o|0,l|0,r|0)|0,e=dt(e|0,A|0,o|0,M()|0)|0,o=0,A=M()|0;while(!1);if((g|0)>(c|0))n=~c,c=c+1|0;else{A=0;break}}return S=D,A|0}while(!1);if((g|0)<1)return G=0,S=D,G|0;for(s=l^15,o=1;;)if(N=g-o|0,N=qr(7,0,N,((N|0)<0)<<31>>31)|0,G=M()|0,c=i,r=t[c>>2]|0,c=t[c+4>>2]|0,l=(s-o|0)*3|0,n=CA(7,0,l|0)|0,c=c&~(M()|0),I=Xr(e|0,A|0,N|0,G|0)|0,L=M()|0,l=CA(I|0,L|0,l|0)|0,c=M()|0|c,f=i,t[f>>2]=l|r&~n,t[f+4>>2]=c,G=mt(I|0,L|0,N|0,G|0)|0,e=dt(e|0,A|0,G|0,M()|0)|0,A=M()|0,(g|0)<=(o|0)){A=0;break}else o=o+1|0;return S=D,A|0}function ls(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0;s=wA(A|0,r|0,52)|0,M()|0,s=s&15,(A|0)==0&(r|0)==0|((n|0)>15|(s|0)>(n|0))?(i=-1,A=-1,r=0,s=0):(A=Js(A,r,s+1|0,n)|0,o=(M()|0)&-15728641,r=CA(n|0,0,52)|0,r=A|r,o=o|(M()|0),A=(Oe(r,o)|0)==0,i=s,A=A?-1:n,s=o),o=e,t[o>>2]=r,t[o+4>>2]=s,t[e+8>>2]=i,t[e+12>>2]=A}function ei(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0;if(s=wA(e|0,A|0,52)|0,M()|0,s=s&15,i=n+8|0,t[i>>2]=s,(e|0)==0&(A|0)==0|((r|0)>15|(s|0)>(r|0))){r=n,t[r>>2]=0,t[r+4>>2]=0,t[i>>2]=-1,t[n+12>>2]=-1;return}if(e=Js(e,A,s+1|0,r)|0,i=(M()|0)&-15728641,s=CA(r|0,0,52)|0,s=e|s,i=i|(M()|0),e=n,t[e>>2]=s,t[e+4>>2]=i,e=n+12|0,Oe(s,i)|0){t[e>>2]=r;return}else{t[e>>2]=-1;return}}function as(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0;if(r=e,A=t[r>>2]|0,r=t[r+4>>2]|0,!((A|0)==0&(r|0)==0)&&(n=wA(A|0,r|0,52)|0,M()|0,n=n&15,l=CA(1,0,(n^15)*3|0)|0,A=$A(l|0,M()|0,A|0,r|0)|0,r=M()|0,l=e,t[l>>2]=A,t[l+4>>2]=r,l=e+8|0,o=t[l>>2]|0,!((n|0)<(o|0)))){for(c=e+12|0,i=n;;){if((i|0)==(o|0)){n=5;break}if(f=(i|0)==(t[c>>2]|0),s=(15-i|0)*3|0,n=wA(A|0,r|0,s|0)|0,M()|0,n=n&7,f&((n|0)==1&!0)){n=7;break}if(!((n|0)==7&!0)){n=10;break}if(f=CA(1,0,s|0)|0,A=$A(A|0,r|0,f|0,M()|0)|0,r=M()|0,f=e,t[f>>2]=A,t[f+4>>2]=r,(i|0)>(o|0))i=i+-1|0;else{n=10;break}}if((n|0)==5){f=e,t[f>>2]=0,t[f+4>>2]=0,t[l>>2]=-1,t[c>>2]=-1;return}else if((n|0)==7){o=CA(1,0,s|0)|0,o=$A(A|0,r|0,o|0,M()|0)|0,l=M()|0,f=e,t[f>>2]=o,t[f+4>>2]=l,t[c>>2]=i+-1;return}else if((n|0)==10)return}}function s0(e){e=+e;var A=0;return A=e<0?e+6.283185307179586:e,+(e>=6.283185307179586?A+-6.283185307179586:A)}function Ln(e,A){return e=e|0,A=A|0,+ee(+(+C[e>>3]-+C[A>>3]))<17453292519943298e-27?(A=+ee(+(+C[e+8>>3]-+C[A+8>>3]))<17453292519943298e-27,A|0):(A=0,A|0)}function Zt(e,A){switch(e=+e,A=A|0,A|0){case 1:{e=e<0?e+6.283185307179586:e;break}case 2:{e=e>0?e+-6.283185307179586:e;break}}return+e}function Nl(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0;return s=+C[A>>3],n=+C[e>>3],i=+se(+((s-n)*.5)),r=+se(+((+C[A+8>>3]-+C[e+8>>3])*.5)),r=i*i+r*(+Be(+s)*+Be(+n)*r),+(+at(+ +Ce(+r),+ +Ce(+(1-r)))*2)}function i0(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0;return s=+C[A>>3],n=+C[e>>3],i=+se(+((s-n)*.5)),r=+se(+((+C[A+8>>3]-+C[e+8>>3])*.5)),r=i*i+r*(+Be(+s)*+Be(+n)*r),+(+at(+ +Ce(+r),+ +Ce(+(1-r)))*2*6371.007180918475)}function Fl(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0;return s=+C[A>>3],n=+C[e>>3],i=+se(+((s-n)*.5)),r=+se(+((+C[A+8>>3]-+C[e+8>>3])*.5)),r=i*i+r*(+Be(+s)*+Be(+n)*r),+(+at(+ +Ce(+r),+ +Ce(+(1-r)))*2*6371.007180918475*1e3)}function Pl(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0;return i=+C[A>>3],n=+Be(+i),s=+C[A+8>>3]-+C[e+8>>3],o=n*+se(+s),r=+C[e>>3],+ +at(+o,+(+se(+i)*+Be(+r)-+Be(+s)*(n*+se(+r))))}function Ql(e,A,r,n){e=e|0,A=+A,r=+r,n=n|0;var s=0,i=0,o=0,l=0;if(r<1e-16){t[n>>2]=t[e>>2],t[n+4>>2]=t[e+4>>2],t[n+8>>2]=t[e+8>>2],t[n+12>>2]=t[e+12>>2];return}i=A<0?A+6.283185307179586:A,i=A>=6.283185307179586?i+-6.283185307179586:i;do if(i<1e-16)A=+C[e>>3]+r,C[n>>3]=A,s=n;else{if(s=+ee(+(i+-3.141592653589793))<1e-16,A=+C[e>>3],s){A=A-r,C[n>>3]=A,s=n;break}if(o=+Be(+r),r=+se(+r),A=o*+se(+A)+ +Be(+i)*(r*+Be(+A)),A=A>1?1:A,A=+xt(+(A<-1?-1:A)),C[n>>3]=A,+ee(+(A+-1.5707963267948966))<1e-16){C[n>>3]=1.5707963267948966,C[n+8>>3]=0;return}if(+ee(+(A+1.5707963267948966))<1e-16){C[n>>3]=-1.5707963267948966,C[n+8>>3]=0;return}if(l=1/+Be(+A),i=r*+se(+i)*l,r=+C[e>>3],A=l*((o-+se(+A)*+se(+r))/+Be(+r)),o=i>1?1:i,A=A>1?1:A,A=+C[e+8>>3]+ +at(+(o<-1?-1:o),+(A<-1?-1:A)),A>3.141592653589793)do A=A+-6.283185307179586;while(A>3.141592653589793);if(A<-3.141592653589793)do A=A+6.283185307179586;while(A<-3.141592653589793);C[n+8>>3]=A;return}while(!1);if(+ee(+(A+-1.5707963267948966))<1e-16){C[s>>3]=1.5707963267948966,C[n+8>>3]=0;return}if(+ee(+(A+1.5707963267948966))<1e-16){C[s>>3]=-1.5707963267948966,C[n+8>>3]=0;return}if(A=+C[e+8>>3],A>3.141592653589793)do A=A+-6.283185307179586;while(A>3.141592653589793);if(A<-3.141592653589793)do A=A+6.283185307179586;while(A<-3.141592653589793);C[n+8>>3]=A}function ti(e,A){return e=e|0,A=A|0,e>>>0>15?(A=4,A|0):(C[A>>3]=+C[20656+(e<<3)>>3],A=0,A|0)}function Ol(e,A){return e=e|0,A=A|0,e>>>0>15?(A=4,A|0):(C[A>>3]=+C[20784+(e<<3)>>3],A=0,A|0)}function zl(e,A){return e=e|0,A=A|0,e>>>0>15?(A=4,A|0):(C[A>>3]=+C[20912+(e<<3)>>3],A=0,A|0)}function Hl(e,A){return e=e|0,A=A|0,e>>>0>15?(A=4,A|0):(C[A>>3]=+C[21040+(e<<3)>>3],A=0,A|0)}function S0(e,A){e=e|0,A=A|0;var r=0;return e>>>0>15?(A=4,A|0):(r=qr(7,0,e,((e|0)<0)<<31>>31)|0,r=mt(r|0,M()|0,120,0)|0,e=M()|0,t[A>>2]=r|2,t[A+4>>2]=e,A=0,A|0)}function ri(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0;return I=+C[A>>3],g=+C[e>>3],c=+se(+((I-g)*.5)),i=+C[A+8>>3],f=+C[e+8>>3],o=+se(+((i-f)*.5)),l=+Be(+g),D=+Be(+I),o=c*c+o*(D*l*o),o=+at(+ +Ce(+o),+ +Ce(+(1-o)))*2,c=+C[r>>3],I=+se(+((c-I)*.5)),n=+C[r+8>>3],i=+se(+((n-i)*.5)),s=+Be(+c),i=I*I+i*(D*s*i),i=+at(+ +Ce(+i),+ +Ce(+(1-i)))*2,c=+se(+((g-c)*.5)),n=+se(+((f-n)*.5)),n=c*c+n*(l*s*n),n=+at(+ +Ce(+n),+ +Ce(+(1-n)))*2,s=(o+i+n)*.5,+(+Vt(+ +Ce(+(+et(+(s*.5))*+et(+((s-o)*.5))*+et(+((s-i)*.5))*+et(+((s-n)*.5)))))*4)}function us(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0;if(l=S,S=S+192|0,i=l+168|0,o=l,s=pn(e,A,i)|0,s|0)return r=s,S=l,r|0;if(In(e,A,o)|0&&OA(27795,27190,415,27199),A=t[o>>2]|0,(A|0)>0){if(n=+ri(o+8|0,o+8+(((A|0)!=1&1)<<4)|0,i)+0,(A|0)!=1){e=1;do s=e,e=e+1|0,n=n+ +ri(o+8+(s<<4)|0,o+8+(((e|0)%(A|0)|0)<<4)|0,i);while((e|0)<(A|0))}}else n=0;return C[r>>3]=n,r=0,S=l,r|0}function Gl(e,A,r){return e=e|0,A=A|0,r=r|0,e=us(e,A,r)|0,e|0||(C[r>>3]=+C[r>>3]*6371.007180918475*6371.007180918475),e|0}function Ul(e,A,r){return e=e|0,A=A|0,r=r|0,e=us(e,A,r)|0,e|0||(C[r>>3]=+C[r>>3]*6371.007180918475*6371.007180918475*1e3*1e3),e|0}function Vl(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(l=S,S=S+176|0,o=l,e=dn(e,A,o)|0,e|0)return o=e,S=l,o|0;if(C[r>>3]=0,e=t[o>>2]|0,(e|0)<=1)return o=0,S=l,o|0;A=e+-1|0,e=0,n=+C[o+8>>3],s=+C[o+16>>3],i=0;do e=e+1|0,f=n,n=+C[o+8+(e<<4)>>3],g=+se(+((n-f)*.5)),c=s,s=+C[o+8+(e<<4)+8>>3],c=+se(+((s-c)*.5)),c=g*g+c*(+Be(+n)*+Be(+f)*c),i=i+ +at(+ +Ce(+c),+ +Ce(+(1-c)))*2;while((e|0)<(A|0));return C[r>>3]=i,o=0,S=l,o|0}function Wl(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(l=S,S=S+176|0,o=l,e=dn(e,A,o)|0,e|0)return o=e,i=+C[r>>3],i=i*6371.007180918475,C[r>>3]=i,S=l,o|0;if(C[r>>3]=0,e=t[o>>2]|0,(e|0)<=1)return o=0,i=0,i=i*6371.007180918475,C[r>>3]=i,S=l,o|0;A=e+-1|0,e=0,n=+C[o+8>>3],s=+C[o+16>>3],i=0;do e=e+1|0,f=n,n=+C[o+8+(e<<4)>>3],g=+se(+((n-f)*.5)),c=s,s=+C[o+8+(e<<4)+8>>3],c=+se(+((s-c)*.5)),c=g*g+c*(+Be(+f)*+Be(+n)*c),i=i+ +at(+ +Ce(+c),+ +Ce(+(1-c)))*2;while((e|0)!=(A|0));return C[r>>3]=i,o=0,g=i,g=g*6371.007180918475,C[r>>3]=g,S=l,o|0}function Yl(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(l=S,S=S+176|0,o=l,e=dn(e,A,o)|0,e|0)return o=e,i=+C[r>>3],i=i*6371.007180918475,i=i*1e3,C[r>>3]=i,S=l,o|0;if(C[r>>3]=0,e=t[o>>2]|0,(e|0)<=1)return o=0,i=0,i=i*6371.007180918475,i=i*1e3,C[r>>3]=i,S=l,o|0;A=e+-1|0,e=0,n=+C[o+8>>3],s=+C[o+16>>3],i=0;do e=e+1|0,f=n,n=+C[o+8+(e<<4)>>3],g=+se(+((n-f)*.5)),c=s,s=+C[o+8+(e<<4)+8>>3],c=+se(+((s-c)*.5)),c=g*g+c*(+Be(+f)*+Be(+n)*c),i=i+ +at(+ +Ce(+c),+ +Ce(+(1-c)))*2;while((e|0)!=(A|0));return C[r>>3]=i,o=0,g=i,g=g*6371.007180918475,g=g*1e3,C[r>>3]=g,S=l,o|0}function $l(e){e=e|0;var A=0,r=0,n=0;return A=Ht(1,12)|0,A||OA(27280,27235,49,27293),r=e+4|0,n=t[r>>2]|0,n|0?(n=n+8|0,t[n>>2]=A,t[r>>2]=A,A|0):(t[e>>2]|0&&OA(27310,27235,61,27333),n=e,t[n>>2]=A,t[r>>2]=A,A|0)}function Kl(e,A){e=e|0,A=A|0;var r=0,n=0;return n=Cr(24)|0,n||OA(27347,27235,78,27361),t[n>>2]=t[A>>2],t[n+4>>2]=t[A+4>>2],t[n+8>>2]=t[A+8>>2],t[n+12>>2]=t[A+12>>2],t[n+16>>2]=0,A=e+4|0,r=t[A>>2]|0,r|0?(t[r+16>>2]=n,t[A>>2]=n,n|0):(t[e>>2]|0&&OA(27376,27235,82,27361),t[e>>2]=n,t[A>>2]=n,n|0)}function ni(e){e=e|0;var A=0,r=0,n=0,s=0;if(e)for(n=1;;){if(A=t[e>>2]|0,A|0)do{if(r=t[A>>2]|0,r|0)do s=r,r=t[r+16>>2]|0,ZA(s);while((r|0)!=0);s=A,A=t[A+8>>2]|0,ZA(s)}while((A|0)!=0);if(A=e,e=t[e+8>>2]|0,n||ZA(A),e)n=0;else break}}function Zl(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0,he=0,Se=0,ie=0,GA=0,SA=0,xe=0,We=0,de=0;if(s=e+8|0,t[s>>2]|0)return de=1,de|0;if(n=t[e>>2]|0,!n)return de=0,de|0;A=n,r=0;do r=r+1|0,A=t[A+8>>2]|0;while((A|0)!=0);if(r>>>0<2)return de=0,de|0;xe=Cr(r<<2)|0,xe||OA(27396,27235,317,27415),SA=Cr(r<<5)|0,SA||OA(27437,27235,321,27415),t[e>>2]=0,HA=e+4|0,t[HA>>2]=0,t[s>>2]=0,r=0,GA=0,MA=0,D=0;A:for(;;){if(g=t[n>>2]|0,g){i=0,o=g;do{if(c=+C[o+8>>3],A=o,o=t[o+16>>2]|0,f=(o|0)==0,s=f?g:o,l=+C[s+8>>3],+ee(+(c-l))>3.141592653589793){de=14;break}i=i+(l-c)*(+C[A>>3]+ +C[s>>3])}while(!f);if((de|0)==14){de=0,i=0,A=g;do V=+C[A+8>>3],ie=A+16|0,Se=t[ie>>2]|0,Se=(Se|0)==0?g:Se,Z=+C[Se+8>>3],i=i+(+C[A>>3]+ +C[Se>>3])*((Z<0?Z+6.283185307179586:Z)-(V<0?V+6.283185307179586:V)),A=t[((A|0)==0?n:ie)>>2]|0;while((A|0)!=0)}i>0?(t[xe+(GA<<2)>>2]=n,GA=GA+1|0,s=MA,A=D):de=19}else de=19;if((de|0)==19){de=0;do if(r){if(A=r+8|0,t[A>>2]|0){de=21;break A}if(r=Ht(1,12)|0,!r){de=23;break A}t[A>>2]=r,s=r+4|0,o=r,A=D}else if(D){s=HA,o=D+8|0,A=n,r=e;break}else if(t[e>>2]|0){de=27;break A}else{s=HA,o=e,A=n,r=e;break}while(!1);if(t[o>>2]=n,t[s>>2]=n,o=SA+(MA<<5)|0,f=t[n>>2]|0,f){for(g=SA+(MA<<5)+8|0,C[g>>3]=17976931348623157e292,D=SA+(MA<<5)+24|0,C[D>>3]=17976931348623157e292,C[o>>3]=-17976931348623157e292,I=SA+(MA<<5)+16|0,C[I>>3]=-17976931348623157e292,iA=17976931348623157e292,J=-17976931348623157e292,s=0,L=f,c=17976931348623157e292,G=17976931348623157e292,W=-17976931348623157e292,l=-17976931348623157e292;i=+C[L>>3],V=+C[L+8>>3],L=t[L+16>>2]|0,N=(L|0)==0,Z=+C[(N?f:L)+8>>3],i>3]=i,c=i),V>3]=V,G=V),i>W?C[o>>3]=i:i=W,V>l&&(C[I>>3]=V,l=V),iA=V>0&VJ?V:J,s=s|+ee(+(V-Z))>3.141592653589793,!N;)W=i;s&&(C[I>>3]=J,C[D>>3]=iA)}else t[o>>2]=0,t[o+4>>2]=0,t[o+8>>2]=0,t[o+12>>2]=0,t[o+16>>2]=0,t[o+20>>2]=0,t[o+24>>2]=0,t[o+28>>2]=0;s=MA+1|0}if(ie=n+8|0,n=t[ie>>2]|0,t[ie>>2]=0,n)MA=s,D=A;else{de=45;break}}if((de|0)==21)OA(27213,27235,35,27247);else if((de|0)==23)OA(27267,27235,37,27247);else if((de|0)==27)OA(27310,27235,61,27333);else if((de|0)==45){A:do if((GA|0)>0){for(ie=(s|0)==0,he=s<<2,Se=(e|0)==0,ce=0,A=0;;){if(QA=t[xe+(ce<<2)>>2]|0,ie)de=73;else{if(MA=Cr(he)|0,!MA){de=50;break}if(HA=Cr(he)|0,!HA){de=52;break}e:do if(Se)r=0;else{for(s=0,r=0,o=e;n=SA+(s<<5)|0,si(t[o>>2]|0,n,t[QA>>2]|0)|0?(t[MA+(r<<2)>>2]=o,t[HA+(r<<2)>>2]=n,N=r+1|0):N=r,o=t[o+8>>2]|0,o;)s=s+1|0,r=N;if((N|0)>0)if(n=t[MA>>2]|0,(N|0)==1)r=n;else for(I=0,L=-1,r=n,D=n;;){for(f=t[D>>2]|0,n=0,o=0;s=t[t[MA+(o<<2)>>2]>>2]|0,(s|0)==(f|0)?g=n:g=n+((si(s,t[HA+(o<<2)>>2]|0,t[f>>2]|0)|0)&1)|0,o=o+1|0,(o|0)!=(N|0);)n=g;if(s=(g|0)>(L|0),r=s?D:r,n=I+1|0,(n|0)==(N|0))break e;I=n,L=s?g:L,D=t[MA+(n<<2)>>2]|0}else r=0}while(!1);if(ZA(MA),ZA(HA),r){if(s=r+4|0,n=t[s>>2]|0,n)r=n+8|0;else if(t[r>>2]|0){de=70;break}t[r>>2]=QA,t[s>>2]=QA}else de=73}if((de|0)==73){if(de=0,A=t[QA>>2]|0,A|0)do HA=A,A=t[A+16>>2]|0,ZA(HA);while((A|0)!=0);ZA(QA),A=1}if(ce=ce+1|0,(ce|0)>=(GA|0)){We=A;break A}}(de|0)==50?OA(27452,27235,249,27471):(de|0)==52?OA(27490,27235,252,27471):(de|0)==70&&OA(27310,27235,61,27333)}else We=0;while(!1);return ZA(xe),ZA(SA),de=We,de|0}return 0}function si(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(!(vr(A,r)|0)||(A=Ot(A)|0,n=+C[r>>3],s=+C[r+8>>3],s=A&s<0?s+6.283185307179586:s,e=t[e>>2]|0,!e))return e=0,e|0;if(A){A=0,f=s,r=e;A:for(;;){for(;o=+C[r>>3],s=+C[r+8>>3],r=r+16|0,g=t[r>>2]|0,g=(g|0)==0?e:g,i=+C[g>>3],l=+C[g+8>>3],o>i?(c=o,o=l):(c=i,i=o,o=s,s=l),n=n==i|n==c?n+2220446049250313e-31:n,!!(nc);)if(r=t[r>>2]|0,!r){r=22;break A}if(l=o<0?o+6.283185307179586:o,o=s<0?s+6.283185307179586:s,f=l==f|o==f?f+-2220446049250313e-31:f,c=l+(o-l)*((n-i)/(c-i)),(c<0?c+6.283185307179586:c)>f&&(A=A^1),r=t[r>>2]|0,!r){r=22;break}}if((r|0)==22)return A|0}else{A=0,f=s,r=e;A:for(;;){for(;o=+C[r>>3],s=+C[r+8>>3],r=r+16|0,g=t[r>>2]|0,g=(g|0)==0?e:g,i=+C[g>>3],l=+C[g+8>>3],o>i?(c=o,o=l):(c=i,i=o,o=s,s=l),n=n==i|n==c?n+2220446049250313e-31:n,!!(nc);)if(r=t[r>>2]|0,!r){r=22;break A}if(f=o==f|s==f?f+-2220446049250313e-31:f,o+(s-o)*((n-i)/(c-i))>f&&(A=A^1),r=t[r>>2]|0,!r){r=22;break}}if((r|0)==22)return A|0}return 0}function Pr(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0;if(J=S,S=S+32|0,iA=J+16|0,W=J,i=wA(e|0,A|0,52)|0,M()|0,i=i&15,L=wA(r|0,n|0,52)|0,M()|0,(i|0)!=(L&15|0))return iA=12,S=J,iA|0;if(f=wA(e|0,A|0,45)|0,M()|0,f=f&127,g=wA(r|0,n|0,45)|0,M()|0,g=g&127,f>>>0>121|g>>>0>121)return iA=5,S=J,iA|0;if(L=(f|0)!=(g|0),L){if(l=cn(f,g)|0,(l|0)==7)return iA=1,S=J,iA|0;c=cn(g,f)|0,(c|0)==7?OA(27514,27538,161,27548):(N=l,o=c)}else N=0,o=0;D=_e(f)|0,I=_e(g)|0,t[iA>>2]=0,t[iA+4>>2]=0,t[iA+8>>2]=0,t[iA+12>>2]=0;do if(N){if(g=t[4272+(f*28|0)+(N<<2)>>2]|0,l=(g|0)>0,I)if(l){f=0,c=r,l=n;do c=_l(c,l)|0,l=M()|0,o=Kt(o)|0,(o|0)==1&&(o=Kt(1)|0),f=f+1|0;while((f|0)!=(g|0));g=o,f=c,c=l}else g=o,f=r,c=n;else if(l){f=0,c=r,l=n;do c=ns(c,l)|0,l=M()|0,o=Kt(o)|0,f=f+1|0;while((f|0)!=(g|0));g=o,f=c,c=l}else g=o,f=r,c=n;if(is(f,c,iA)|0,L||OA(27563,27538,191,27548),l=(D|0)!=0,o=(I|0)!=0,l&o&&OA(27590,27538,192,27548),l){if(o=zt(e,A)|0,(o|0)==7){i=5;break}if(xA[22e3+(o*7|0)+N>>0]|0){i=1;break}c=t[21168+(o*28|0)+(N<<2)>>2]|0,f=c}else if(o){if(o=zt(f,c)|0,(o|0)==7){i=5;break}if(xA[22e3+(o*7|0)+g>>0]|0){i=1;break}f=0,c=t[21168+(g*28|0)+(o<<2)>>2]|0}else f=0,c=0;if((f|c|0)<0)i=5;else{if((c|0)>0){l=iA+4|0,o=0;do Fr(l),o=o+1|0;while((o|0)!=(c|0))}if(t[W>>2]=0,t[W+4>>2]=0,t[W+8>>2]=0,ot(W,N),i|0)for(;ir(i)|0?bt(W):Ze(W),(i|0)>1;)i=i+-1|0;if((f|0)>0){i=0;do Fr(W),i=i+1|0;while((i|0)!=(f|0))}G=iA+4|0,tA(G,W,G),nt(G),G=51}}else if(is(r,n,iA)|0,(D|0)!=0&(I|0)!=0)if((g|0)!=(f|0)&&OA(27621,27538,261,27548),o=zt(e,A)|0,i=zt(r,n)|0,(o|0)==7|(i|0)==7)i=5;else if(xA[22e3+(o*7|0)+i>>0]|0)i=1;else if(o=t[21168+(o*28|0)+(i<<2)>>2]|0,(o|0)>0){l=iA+4|0,i=0;do Fr(l),i=i+1|0;while((i|0)!=(o|0));G=51}else G=51;else G=51;while(!1);return(G|0)==51&&(i=iA+4|0,t[s>>2]=t[i>>2],t[s+4>>2]=t[i+4>>2],t[s+8>>2]=t[i+8>>2],i=0),iA=i,S=J,iA|0}function ii(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0;if(G=S,S=S+48|0,f=G+36|0,o=G+24|0,l=G+12|0,c=G,s=wA(e|0,A|0,52)|0,M()|0,s=s&15,I=wA(e|0,A|0,45)|0,M()|0,I=I&127,I>>>0>121)return n=5,S=G,n|0;if(g=_e(I)|0,CA(s|0,0,52)|0,W=M()|0|134225919,i=n,t[i>>2]=-1,t[i+4>>2]=W,!s)return s=zA(r)|0,(s|0)==7||(s=un(I,s)|0,(s|0)==127)?(W=1,S=G,W|0):(L=CA(s|0,0,45)|0,N=M()|0,I=n,N=t[I+4>>2]&-1040385|N,W=n,t[W>>2]=t[I>>2]|L,t[W+4>>2]=N,W=0,S=G,W|0);for(t[f>>2]=t[r>>2],t[f+4>>2]=t[r+4>>2],t[f+8>>2]=t[r+8>>2],r=s;;){if(i=r,r=r+-1|0,t[o>>2]=t[f>>2],t[o+4>>2]=t[f+4>>2],t[o+8>>2]=t[f+8>>2],ir(i)|0){if(s=te(f)|0,s|0){r=13;break}t[l>>2]=t[f>>2],t[l+4>>2]=t[f+4>>2],t[l+8>>2]=t[f+8>>2],bt(l)}else{if(s=Te(f)|0,s|0){r=13;break}t[l>>2]=t[f>>2],t[l+4>>2]=t[f+4>>2],t[l+8>>2]=t[f+8>>2],Ze(l)}if(mA(o,l,c),nt(c),s=n,J=t[s>>2]|0,s=t[s+4>>2]|0,Z=(15-i|0)*3|0,iA=CA(7,0,Z|0)|0,s=s&~(M()|0),Z=CA(zA(c)|0,0,Z|0)|0,s=M()|0|s,W=n,t[W>>2]=Z|J&~iA,t[W+4>>2]=s,(i|0)<=1){r=14;break}}A:do if((r|0)!=13&&(r|0)==14)if((t[f>>2]|0)<=1&&(t[f+4>>2]|0)<=1&&(t[f+8>>2]|0)<=1){r=zA(f)|0,s=un(I,r)|0,(s|0)==127?c=0:c=_e(s)|0;e:do if(r){if(g){if(s=zt(e,A)|0,(s|0)==7){s=5;break A}if(i=t[21376+(s*28|0)+(r<<2)>>2]|0,(i|0)>0){s=r,r=0;do s=$t(s)|0,r=r+1|0;while((r|0)!=(i|0))}else s=r;if((s|0)==1){s=9;break A}r=un(I,s)|0,(r|0)==127&&OA(27648,27538,411,27678),_e(r)|0?OA(27693,27538,412,27678):(N=r,L=i,D=s)}else N=s,L=0,D=r;if(l=t[4272+(I*28|0)+(D<<2)>>2]|0,(l|0)<=-1&&OA(27724,27538,419,27678),!c){if((L|0)<0){s=5;break A}if(L|0){i=n,s=0,r=t[i>>2]|0,i=t[i+4>>2]|0;do r=mn(r,i)|0,i=M()|0,Z=n,t[Z>>2]=r,t[Z+4>>2]=i,s=s+1|0;while((s|0)<(L|0))}if((l|0)<=0){s=N,r=58;break}for(i=n,s=0,r=t[i>>2]|0,i=t[i+4>>2]|0;;)if(r=mn(r,i)|0,i=M()|0,Z=n,t[Z>>2]=r,t[Z+4>>2]=i,s=s+1|0,(s|0)==(l|0)){s=N,r=58;break e}}if(o=cn(N,I)|0,(o|0)==7&&OA(27514,27538,428,27678),s=n,r=t[s>>2]|0,s=t[s+4>>2]|0,(l|0)>0){i=0;do r=mn(r,s)|0,s=M()|0,Z=n,t[Z>>2]=r,t[Z+4>>2]=s,i=i+1|0;while((i|0)!=(l|0))}if(s=zt(r,s)|0,(s|0)==7&&OA(27795,27538,440,27678),r=Dt(N)|0,r=t[(r?21792:21584)+(o*28|0)+(s<<2)>>2]|0,(r|0)<0&&OA(27795,27538,454,27678),!r)s=N,r=58;else{o=n,s=0,i=t[o>>2]|0,o=t[o+4>>2]|0;do i=rs(i,o)|0,o=M()|0,Z=n,t[Z>>2]=i,t[Z+4>>2]=o,s=s+1|0;while((s|0)<(r|0));s=N,r=58}}else if((g|0)!=0&(c|0)!=0){if(r=zt(e,A)|0,i=n,i=zt(t[i>>2]|0,t[i+4>>2]|0)|0,(r|0)==7|(i|0)==7){s=5;break A}if(i=t[21376+(r*28|0)+(i<<2)>>2]|0,(i|0)<0){s=5;break A}if(!i)r=59;else{l=n,r=0,o=t[l>>2]|0,l=t[l+4>>2]|0;do o=mn(o,l)|0,l=M()|0,Z=n,t[Z>>2]=o,t[Z+4>>2]=l,r=r+1|0;while((r|0)<(i|0));r=58}}else r=58;while(!1);if((r|0)==58&&c&&(r=59),(r|0)==59&&(Z=n,(zt(t[Z>>2]|0,t[Z+4>>2]|0)|0)==1)){s=9;break}Z=n,iA=t[Z>>2]|0,Z=t[Z+4>>2]&-1040385,J=CA(s|0,0,45)|0,Z=Z|(M()|0),s=n,t[s>>2]=iA|J,t[s+4>>2]=Z,s=0}else s=1;while(!1);return Z=s,S=G,Z|0}function ql(e,A,r,n,s,i){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0,i=i|0;var o=0,l=0;return l=S,S=S+16|0,o=l,s?e=15:(e=Pr(e,A,r,n,o)|0,e||(Xn(o,i),e=0)),S=l,e|0}function Jl(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0;return o=S,S=S+16|0,i=o,n?r=15:(r=Tt(r,i)|0,r||(r=ii(e,A,i,s)|0)),S=o,r|0}function Xl(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0;return c=S,S=S+32|0,o=c+12|0,l=c,i=Pr(e,A,e,A,o)|0,i|0?(l=i,S=c,l|0):(e=Pr(e,A,r,n,l)|0,e|0?(l=e,S=c,l|0):(o=Dn(o,l)|0,l=s,t[l>>2]=o,t[l+4>>2]=((o|0)<0)<<31>>31,l=0,S=c,l|0))}function Aa(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0;return c=S,S=S+32|0,o=c+12|0,l=c,i=Pr(e,A,e,A,o)|0,!i&&(i=Pr(e,A,r,n,l)|0,!i)?(n=Dn(o,l)|0,n=$A(n|0,((n|0)<0)<<31>>31|0,1,0)|0,o=M()|0,l=s,t[l>>2]=n,t[l+4>>2]=o,l=0,S=c,l|0):(l=i,S=c,l|0)}function ea(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0;if(QA=S,S=S+48|0,MA=QA+24|0,o=QA+12|0,HA=QA,i=Pr(e,A,e,A,MA)|0,!i&&(i=Pr(e,A,r,n,o)|0,!i)){Z=Dn(MA,o)|0,V=((Z|0)<0)<<31>>31,t[MA>>2]=0,t[MA+4>>2]=0,t[MA+8>>2]=0,t[o>>2]=0,t[o+4>>2]=0,t[o+8>>2]=0,Pr(e,A,e,A,MA)|0&&OA(27795,27538,692,27747),Pr(e,A,r,n,o)|0&&OA(27795,27538,697,27747),A0(MA),A0(o),g=(Z|0)==0?0:1/+(Z|0),r=t[MA>>2]|0,G=g*+((t[o>>2]|0)-r|0),W=MA+4|0,n=t[W>>2]|0,iA=g*+((t[o+4>>2]|0)-n|0),J=MA+8|0,i=t[J>>2]|0,g=g*+((t[o+8>>2]|0)-i|0),t[HA>>2]=r,D=HA+4|0,t[D>>2]=n,I=HA+8|0,t[I>>2]=i;A:do if((Z|0)<0)i=0;else for(L=0,N=0;;){c=+(N>>>0)+4294967296*+(L|0),ce=G*c+ +(r|0),l=iA*c+ +(n|0),c=g*c+ +(i|0),r=~~+D0(+ce),o=~~+D0(+l),i=~~+D0(+c),ce=+ee(+(+(r|0)-ce)),l=+ee(+(+(o|0)-l)),c=+ee(+(+(i|0)-c));do if(ce>l&ce>c)r=0-(o+i)|0,n=o;else if(f=0-r|0,l>c){n=f-i|0;break}else{n=o,i=f-o|0;break}while(!1);if(t[HA>>2]=r,t[D>>2]=n,t[I>>2]=i,e0(HA),i=ii(e,A,HA,s+(N<<3)|0)|0,i|0)break A;if(!((L|0)<(V|0)|(L|0)==(V|0)&N>>>0>>0)){i=0;break A}r=$A(N|0,L|0,1,0)|0,n=M()|0,L=n,N=r,r=t[MA>>2]|0,n=t[W>>2]|0,i=t[J>>2]|0}while(!1);return HA=i,S=QA,HA|0}return HA=i,S=QA,HA|0}function qr(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0;if((r|0)==0&(n|0)==0)return s=0,i=1,WA(s|0),i|0;i=e,s=A,e=1,A=0;do o=(r&1|0)==0&!0,e=mt((o?1:i)|0,(o?0:s)|0,e|0,A|0)|0,A=M()|0,r=xi(r|0,n|0,1)|0,n=M()|0,i=mt(i|0,s|0,i|0,s|0)|0,s=M()|0;while(!((r|0)==0&(n|0)==0));return WA(A|0),e|0}function cs(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0;l=S,S=S+16|0,i=l,o=wA(e|0,A|0,52)|0,M()|0,o=o&15;do if(o){if(s=pn(e,A,i)|0,!s){f=+C[i>>3],c=1/+Be(+f),g=+C[25968+(o<<3)>>3],C[r>>3]=f+g,C[r+8>>3]=f-g,f=+C[i+8>>3],c=g*c,C[r+16>>3]=c+f,C[r+24>>3]=f-c;break}return o=s,S=l,o|0}else{if(s=wA(e|0,A|0,45)|0,M()|0,s=s&127,s>>>0>121)return o=5,S=l,o|0;i=22064+(s<<5)|0,t[r>>2]=t[i>>2],t[r+4>>2]=t[i+4>>2],t[r+8>>2]=t[i+8>>2],t[r+12>>2]=t[i+12>>2],t[r+16>>2]=t[i+16>>2],t[r+20>>2]=t[i+20>>2],t[r+24>>2]=t[i+24>>2],t[r+28>>2]=t[i+28>>2];break}while(!1);return pr(r,n?1.4:1.1),n=26096+(o<<3)|0,(t[n>>2]|0)==(e|0)&&(t[n+4>>2]|0)==(A|0)&&(C[r>>3]=1.5707963267948966),o=26224+(o<<3)|0,(t[o>>2]|0)==(e|0)&&(t[o+4>>2]|0)==(A|0)&&(C[r+8>>3]=-1.5707963267948966),+C[r>>3]!=1.5707963267948966&&+C[r+8>>3]!=-1.5707963267948966?(o=0,S=l,o|0):(C[r+16>>3]=3.141592653589793,C[r+24>>3]=-3.141592653589793,o=0,S=l,o|0)}function ta(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0;f=S,S=S+48|0,o=f+32|0,i=f+40|0,l=f,jt(o,0,0,0),c=t[o>>2]|0,o=t[o+4>>2]|0;do if(r>>>0<=15){if(s=l0(n)|0,s|0){n=l,t[n>>2]=0,t[n+4>>2]=0,t[l+8>>2]=s,t[l+12>>2]=-1,n=l+16|0,c=l+29|0,t[n>>2]=0,t[n+4>>2]=0,t[n+8>>2]=0,xA[n+12>>0]=0,xA[c>>0]=xA[i>>0]|0,xA[c+1>>0]=xA[i+1>>0]|0,xA[c+2>>0]=xA[i+2>>0]|0;break}if(s=Ht((t[A+8>>2]|0)+1|0,32)|0,s){fs(A,s),g=l,t[g>>2]=c,t[g+4>>2]=o,t[l+8>>2]=0,t[l+12>>2]=r,t[l+16>>2]=n,t[l+20>>2]=A,t[l+24>>2]=s,xA[l+28>>0]=0,c=l+29|0,xA[c>>0]=xA[i>>0]|0,xA[c+1>>0]=xA[i+1>>0]|0,xA[c+2>>0]=xA[i+2>>0]|0;break}else{n=l,t[n>>2]=0,t[n+4>>2]=0,t[l+8>>2]=13,t[l+12>>2]=-1,n=l+16|0,c=l+29|0,t[n>>2]=0,t[n+4>>2]=0,t[n+8>>2]=0,xA[n+12>>0]=0,xA[c>>0]=xA[i>>0]|0,xA[c+1>>0]=xA[i+1>>0]|0,xA[c+2>>0]=xA[i+2>>0]|0;break}}else c=l,t[c>>2]=0,t[c+4>>2]=0,t[l+8>>2]=4,t[l+12>>2]=-1,c=l+16|0,g=l+29|0,t[c>>2]=0,t[c+4>>2]=0,t[c+8>>2]=0,xA[c+12>>0]=0,xA[g>>0]=xA[i>>0]|0,xA[g+1>>0]=xA[i+1>>0]|0,xA[g+2>>0]=xA[i+2>>0]|0;while(!1);E0(l),t[e>>2]=t[l>>2],t[e+4>>2]=t[l+4>>2],t[e+8>>2]=t[l+8>>2],t[e+12>>2]=t[l+12>>2],t[e+16>>2]=t[l+16>>2],t[e+20>>2]=t[l+20>>2],t[e+24>>2]=t[l+24>>2],t[e+28>>2]=t[l+28>>2],S=f}function E0(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0;if(V=S,S=S+336|0,L=V+168|0,N=V,n=e,r=t[n>>2]|0,n=t[n+4>>2]|0,(r|0)==0&(n|0)==0){S=V;return}if(A=e+28|0,xA[A>>0]|0?(r=oi(r,n)|0,n=M()|0):xA[A>>0]=1,Z=e+20|0,!(t[t[Z>>2]>>2]|0)){A=e+24|0,r=t[A>>2]|0,r|0&&ZA(r),J=e,t[J>>2]=0,t[J+4>>2]=0,t[e+8>>2]=0,t[Z>>2]=0,t[e+12>>2]=-1,t[e+16>>2]=0,t[A>>2]=0,S=V;return}J=e+16|0,A=t[J>>2]|0,s=A&15;A:do if((r|0)==0&(n|0)==0)iA=e+24|0;else{G=e+12|0,D=(s|0)==3,g=A&255,c=(s|1|0)==3,I=e+24|0,f=(s+-1|0)>>>0<3,o=(s|2|0)==3,l=N+8|0;e:for(;;){if(i=wA(r|0,n|0,52)|0,M()|0,i=i&15,(i|0)==(t[G>>2]|0)){switch(g&15){case 0:case 2:case 3:{if(s=pn(r,n,L)|0,s|0){W=15;break e}if(hs(t[Z>>2]|0,t[I>>2]|0,L)|0){W=19;break e}break}}if(c&&(s=t[(t[Z>>2]|0)+4>>2]|0,t[L>>2]=t[s>>2],t[L+4>>2]=t[s+4>>2],t[L+8>>2]=t[s+8>>2],t[L+12>>2]=t[s+12>>2],vr(26832,L)|0)){if(ss(t[(t[Z>>2]|0)+4>>2]|0,i,N)|0){W=25;break}if(s=N,(t[s>>2]|0)==(r|0)&&(t[s+4>>2]|0)==(n|0)){W=29;break}}if(f){if(s=In(r,n,L)|0,s|0){W=32;break}if(cs(r,n,N,0)|0){W=36;break}if(o&&ai(t[Z>>2]|0,t[I>>2]|0,L,N)|0){W=42;break}if(c&&ui(t[Z>>2]|0,t[I>>2]|0,L,N)|0){W=42;break}}if(D){if(A=cs(r,n,L,1)|0,s=t[I>>2]|0,A|0){W=45;break}if(Pe(s,L)|0){if(br(N,L),Nr(L,t[I>>2]|0)|0){W=53;break}if(hs(t[Z>>2]|0,t[I>>2]|0,l)|0){W=53;break}if(ui(t[Z>>2]|0,t[I>>2]|0,N,L)|0){W=53;break}}}}do if((i|0)<(t[G>>2]|0)){if(A=cs(r,n,L,1)|0,s=t[I>>2]|0,A|0){W=58;break e}if(!(Pe(s,L)|0)){W=73;break}if(Nr(t[I>>2]|0,L)|0&&(br(N,L),ai(t[Z>>2]|0,t[I>>2]|0,N,L)|0)){W=65;break e}if(r=Xs(r,n,i+1|0,N)|0,r|0){W=67;break e}n=N,r=t[n>>2]|0,n=t[n+4>>2]|0}else W=73;while(!1);if((W|0)==73&&(W=0,r=oi(r,n)|0,n=M()|0),(r|0)==0&(n|0)==0){iA=I;break A}}switch(W|0){case 15:{A=t[I>>2]|0,A|0&&ZA(A),W=e,t[W>>2]=0,t[W+4>>2]=0,t[Z>>2]=0,t[G>>2]=-1,t[J>>2]=0,t[I>>2]=0,t[e+8>>2]=s,W=20;break}case 19:{t[e>>2]=r,t[e+4>>2]=n,W=20;break}case 25:{OA(27795,27761,470,27772);break}case 29:{t[e>>2]=r,t[e+4>>2]=n,S=V;return}case 32:{A=t[I>>2]|0,A|0&&ZA(A),iA=e,t[iA>>2]=0,t[iA+4>>2]=0,t[Z>>2]=0,t[G>>2]=-1,t[J>>2]=0,t[I>>2]=0,t[e+8>>2]=s,S=V;return}case 36:{OA(27795,27761,493,27772);break}case 42:{t[e>>2]=r,t[e+4>>2]=n,S=V;return}case 45:{s|0&&ZA(s),W=e,t[W>>2]=0,t[W+4>>2]=0,t[Z>>2]=0,t[G>>2]=-1,t[J>>2]=0,t[I>>2]=0,t[e+8>>2]=A,W=55;break}case 53:{t[e>>2]=r,t[e+4>>2]=n,W=55;break}case 58:{s|0&&ZA(s),W=e,t[W>>2]=0,t[W+4>>2]=0,t[Z>>2]=0,t[G>>2]=-1,t[J>>2]=0,t[I>>2]=0,t[e+8>>2]=A,W=71;break}case 65:{t[e>>2]=r,t[e+4>>2]=n,W=71;break}case 67:{A=t[I>>2]|0,A|0&&ZA(A),iA=e,t[iA>>2]=0,t[iA+4>>2]=0,t[Z>>2]=0,t[G>>2]=-1,t[J>>2]=0,t[I>>2]=0,t[e+8>>2]=r,S=V;return}}if((W|0)==20){S=V;return}else if((W|0)==55){S=V;return}else if((W|0)==71){S=V;return}}while(!1);A=t[iA>>2]|0,A|0&&ZA(A),W=e,t[W>>2]=0,t[W+4>>2]=0,t[e+8>>2]=0,t[Z>>2]=0,t[e+12>>2]=-1,t[J>>2]=0,t[iA>>2]=0,S=V}function oi(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0;D=S,S=S+16|0,g=D,n=wA(e|0,A|0,52)|0,M()|0,n=n&15,r=wA(e|0,A|0,45)|0,M()|0;do if(n){for(;r=CA(n+4095|0,0,52)|0,s=M()|0|A&-15728641,i=(15-n|0)*3|0,o=CA(7,0,i|0)|0,l=M()|0,r=r|e|o,s=s|l,c=wA(e|0,A|0,i|0)|0,M()|0,c=c&7,n=n+-1|0,!(c>>>0<6);)if(n)A=s,e=r;else{f=4;break}if((f|0)==4){r=wA(r|0,s|0,45)|0,M()|0;break}return g=(c|0)==0&(Oe(r,s)|0)!=0,g=CA((g?2:1)+c|0,0,i|0)|0,f=M()|0|A&~l,g=g|e&~o,WA(f|0),S=D,g|0}while(!1);return r=r&127,r>>>0>120?(f=0,g=0,WA(f|0),S=D,g|0):(jt(g,0,r+1|0,0),f=t[g+4>>2]|0,g=t[g>>2]|0,WA(f|0),S=D,g|0)}function ra(e,A,r,n,s,i){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0,i=i|0;var o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0;W=S,S=S+160|0,D=W+80|0,l=W+64|0,I=W+112|0,G=W,ta(D,e,A,r),f=D,ls(l,t[f>>2]|0,t[f+4>>2]|0,A),f=l,c=t[f>>2]|0,f=t[f+4>>2]|0,o=t[D+8>>2]|0,L=I+4|0,t[L>>2]=t[D>>2],t[L+4>>2]=t[D+4>>2],t[L+8>>2]=t[D+8>>2],t[L+12>>2]=t[D+12>>2],t[L+16>>2]=t[D+16>>2],t[L+20>>2]=t[D+20>>2],t[L+24>>2]=t[D+24>>2],t[L+28>>2]=t[D+28>>2],L=G,t[L>>2]=c,t[L+4>>2]=f,L=G+8|0,t[L>>2]=o,e=G+12|0,A=I,r=e+36|0;do t[e>>2]=t[A>>2],e=e+4|0,A=A+4|0;while((e|0)<(r|0));if(I=G+48|0,t[I>>2]=t[l>>2],t[I+4>>2]=t[l+4>>2],t[I+8>>2]=t[l+8>>2],t[I+12>>2]=t[l+12>>2],(c|0)==0&(f|0)==0)return G=o,S=W,G|0;r=G+16|0,g=G+24|0,D=G+28|0,o=0,l=0,A=c,e=f;do{if(!((o|0)<(s|0)|(o|0)==(s|0)&l>>>0>>0)){N=4;break}if(f=l,l=$A(l|0,o|0,1,0)|0,o=M()|0,f=i+(f<<3)|0,t[f>>2]=A,t[f+4>>2]=e,as(I),e=I,A=t[e>>2]|0,e=t[e+4>>2]|0,(A|0)==0&(e|0)==0){if(E0(r),A=r,e=t[A>>2]|0,A=t[A+4>>2]|0,(e|0)==0&(A|0)==0){N=10;break}ei(e,A,t[D>>2]|0,I),e=I,A=t[e>>2]|0,e=t[e+4>>2]|0}f=G,t[f>>2]=A,t[f+4>>2]=e}while(!((A|0)==0&(e|0)==0));return(N|0)==4?(e=G+40|0,A=t[e>>2]|0,A|0&&ZA(A),N=G+16|0,t[N>>2]=0,t[N+4>>2]=0,t[g>>2]=0,t[G+36>>2]=0,t[D>>2]=-1,t[G+32>>2]=0,t[e>>2]=0,ei(0,0,0,I),t[G>>2]=0,t[G+4>>2]=0,t[L>>2]=0,G=14,S=W,G|0):((N|0)==10&&(t[G>>2]=0,t[G+4>>2]=0,t[L>>2]=t[g>>2]),G=t[L>>2]|0,S=W,G|0)}function na(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0;if(D=S,S=S+48|0,c=D+32|0,l=D+40|0,f=D,!(t[e>>2]|0))return g=n,t[g>>2]=0,t[g+4>>2]=0,g=0,S=D,g|0;jt(c,0,0,0),o=c,s=t[o>>2]|0,o=t[o+4>>2]|0;do if(A>>>0>15)g=f,t[g>>2]=0,t[g+4>>2]=0,t[f+8>>2]=4,t[f+12>>2]=-1,g=f+16|0,r=f+29|0,t[g>>2]=0,t[g+4>>2]=0,t[g+8>>2]=0,xA[g+12>>0]=0,xA[r>>0]=xA[l>>0]|0,xA[r+1>>0]=xA[l+1>>0]|0,xA[r+2>>0]=xA[l+2>>0]|0,r=4,g=9;else{if(r=l0(r)|0,r|0){c=f,t[c>>2]=0,t[c+4>>2]=0,t[f+8>>2]=r,t[f+12>>2]=-1,c=f+16|0,g=f+29|0,t[c>>2]=0,t[c+4>>2]=0,t[c+8>>2]=0,xA[c+12>>0]=0,xA[g>>0]=xA[l>>0]|0,xA[g+1>>0]=xA[l+1>>0]|0,xA[g+2>>0]=xA[l+2>>0]|0,g=9;break}if(r=Ht((t[e+8>>2]|0)+1|0,32)|0,!r){g=f,t[g>>2]=0,t[g+4>>2]=0,t[f+8>>2]=13,t[f+12>>2]=-1,g=f+16|0,r=f+29|0,t[g>>2]=0,t[g+4>>2]=0,t[g+8>>2]=0,xA[g+12>>0]=0,xA[r>>0]=xA[l>>0]|0,xA[r+1>>0]=xA[l+1>>0]|0,xA[r+2>>0]=xA[l+2>>0]|0,r=13,g=9;break}fs(e,r),L=f,t[L>>2]=s,t[L+4>>2]=o,o=f+8|0,t[o>>2]=0,t[f+12>>2]=A,t[f+20>>2]=e,t[f+24>>2]=r,xA[f+28>>0]=0,s=f+29|0,xA[s>>0]=xA[l>>0]|0,xA[s+1>>0]=xA[l+1>>0]|0,xA[s+2>>0]=xA[l+2>>0]|0,t[f+16>>2]=3,I=+fn(r),I=I*+Zn(r),i=+ee(+ +C[r>>3]),i=I/+Be(+ +B0(+i,+ +ee(+ +C[r+8>>3])))*6371.007180918475*6371.007180918475,s=f+12|0,r=t[s>>2]|0;A:do if((r|0)>0)do{if(ti(r+-1|0,c)|0,!(i/+C[c>>3]>10))break A;L=t[s>>2]|0,r=L+-1|0,t[s>>2]=r}while((L|0)>1);while(!1);if(E0(f),s=n,t[s>>2]=0,t[s+4>>2]=0,s=f,r=t[s>>2]|0,s=t[s+4>>2]|0,!((r|0)==0&(s|0)==0))do kr(r,s,A,c)|0,l=c,e=n,l=$A(t[e>>2]|0,t[e+4>>2]|0,t[l>>2]|0,t[l+4>>2]|0)|0,e=M()|0,L=n,t[L>>2]=l,t[L+4>>2]=e,E0(f),L=f,r=t[L>>2]|0,s=t[L+4>>2]|0;while(!((r|0)==0&(s|0)==0));r=t[o>>2]|0}while(!1);return L=r,S=D,L|0}function o0(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0;if(!(vr(A,r)|0)||(A=Ot(A)|0,n=+C[r>>3],s=+C[r+8>>3],s=A&s<0?s+6.283185307179586:s,I=t[e>>2]|0,(I|0)<=0))return I=0,I|0;if(D=t[e+4>>2]|0,A){A=0,g=s,r=-1,e=0;A:for(;;){for(f=e;o=+C[D+(f<<4)>>3],s=+C[D+(f<<4)+8>>3],e=(r+2|0)%(I|0)|0,i=+C[D+(e<<4)>>3],l=+C[D+(e<<4)+8>>3],o>i?(c=o,o=l):(c=i,i=o,o=s,s=l),n=n==i|n==c?n+2220446049250313e-31:n,!!(nc);)if(r=f+1|0,(r|0)>=(I|0)){r=22;break A}else e=f,f=r,r=e;if(l=o<0?o+6.283185307179586:o,o=s<0?s+6.283185307179586:s,g=l==g|o==g?g+-2220446049250313e-31:g,c=l+(o-l)*((n-i)/(c-i)),(c<0?c+6.283185307179586:c)>g&&(A=A^1),e=f+1|0,(e|0)>=(I|0)){r=22;break}else r=f}if((r|0)==22)return A|0}else{A=0,g=s,r=-1,e=0;A:for(;;){for(f=e;o=+C[D+(f<<4)>>3],s=+C[D+(f<<4)+8>>3],e=(r+2|0)%(I|0)|0,i=+C[D+(e<<4)>>3],l=+C[D+(e<<4)+8>>3],o>i?(c=o,o=l):(c=i,i=o,o=s,s=l),n=n==i|n==c?n+2220446049250313e-31:n,!!(nc);)if(r=f+1|0,(r|0)>=(I|0)){r=22;break A}else e=f,f=r,r=e;if(g=o==g|s==g?g+-2220446049250313e-31:g,o+(s-o)*((n-i)/(c-i))>g&&(A=A^1),e=f+1|0,(e|0)>=(I|0)){r=22;break}else r=f}if((r|0)==22)return A|0}return 0}function li(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0;if(N=t[e>>2]|0,!N){t[A>>2]=0,t[A+4>>2]=0,t[A+8>>2]=0,t[A+12>>2]=0,t[A+16>>2]=0,t[A+20>>2]=0,t[A+24>>2]=0,t[A+28>>2]=0;return}if(G=A+8|0,C[G>>3]=17976931348623157e292,W=A+24|0,C[W>>3]=17976931348623157e292,C[A>>3]=-17976931348623157e292,iA=A+16|0,C[iA>>3]=-17976931348623157e292,!((N|0)<=0)){for(I=t[e+4>>2]|0,f=17976931348623157e292,g=-17976931348623157e292,D=0,e=-1,i=17976931348623157e292,o=17976931348623157e292,c=-17976931348623157e292,n=-17976931348623157e292,L=0;r=+C[I+(L<<4)>>3],l=+C[I+(L<<4)+8>>3],e=e+2|0,s=+C[I+(((e|0)==(N|0)?0:e)<<4)+8>>3],r>3]=r,i=r),l>3]=l,o=l),r>c?C[A>>3]=r:r=c,l>n&&(C[iA>>3]=l,n=l),f=l>0&lg?l:g,D=D|+ee(+(l-s))>3.141592653589793,e=L+1|0,(e|0)!=(N|0);)J=L,c=r,L=e,e=J;D&&(C[iA>>3]=g,C[W>>3]=f)}}function l0(e){return e=e|0,(e>>>0<4?0:15)|0}function fs(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0;if(N=t[e>>2]|0,N){if(G=A+8|0,C[G>>3]=17976931348623157e292,W=A+24|0,C[W>>3]=17976931348623157e292,C[A>>3]=-17976931348623157e292,iA=A+16|0,C[iA>>3]=-17976931348623157e292,(N|0)>0){for(s=t[e+4>>2]|0,I=17976931348623157e292,L=-17976931348623157e292,n=0,r=-1,c=17976931348623157e292,f=17976931348623157e292,D=-17976931348623157e292,o=-17976931348623157e292,J=0;i=+C[s+(J<<4)>>3],g=+C[s+(J<<4)+8>>3],HA=r+2|0,l=+C[s+(((HA|0)==(N|0)?0:HA)<<4)+8>>3],i>3]=i,c=i),g>3]=g,f=g),i>D?C[A>>3]=i:i=D,g>o&&(C[iA>>3]=g,o=g),I=g>0&gL?g:L,n=n|+ee(+(g-l))>3.141592653589793,r=J+1|0,(r|0)!=(N|0);)HA=J,D=i,J=r,r=HA;n&&(C[iA>>3]=L,C[W>>3]=I)}}else t[A>>2]=0,t[A+4>>2]=0,t[A+8>>2]=0,t[A+12>>2]=0,t[A+16>>2]=0,t[A+20>>2]=0,t[A+24>>2]=0,t[A+28>>2]=0;if(HA=e+8|0,r=t[HA>>2]|0,!((r|0)<=0)){MA=e+12|0,V=0;do if(s=t[MA>>2]|0,n=V,V=V+1|0,W=A+(V<<5)|0,iA=t[s+(n<<3)>>2]|0,iA){if(J=A+(V<<5)+8|0,C[J>>3]=17976931348623157e292,e=A+(V<<5)+24|0,C[e>>3]=17976931348623157e292,C[W>>3]=-17976931348623157e292,Z=A+(V<<5)+16|0,C[Z>>3]=-17976931348623157e292,(iA|0)>0){for(N=t[s+(n<<3)+4>>2]|0,I=17976931348623157e292,L=-17976931348623157e292,s=0,n=-1,G=0,c=17976931348623157e292,f=17976931348623157e292,g=-17976931348623157e292,o=-17976931348623157e292;i=+C[N+(G<<4)>>3],D=+C[N+(G<<4)+8>>3],n=n+2|0,l=+C[N+(((n|0)==(iA|0)?0:n)<<4)+8>>3],i>3]=i,c=i),D>3]=D,f=D),i>g?C[W>>3]=i:i=g,D>o&&(C[Z>>3]=D,o=D),I=D>0&DL?D:L,s=s|+ee(+(D-l))>3.141592653589793,n=G+1|0,(n|0)!=(iA|0);)QA=G,G=n,g=i,n=QA;s&&(C[Z>>3]=L,C[e>>3]=I)}}else t[W>>2]=0,t[W+4>>2]=0,t[W+8>>2]=0,t[W+12>>2]=0,t[W+16>>2]=0,t[W+20>>2]=0,t[W+24>>2]=0,t[W+28>>2]=0,r=t[HA>>2]|0;while((V|0)<(r|0))}}function hs(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;if(!(o0(e,A,r)|0))return s=0,s|0;if(s=e+8|0,(t[s>>2]|0)<=0)return s=1,s|0;for(n=e+12|0,e=0;;){if(i=e,e=e+1|0,o0((t[n>>2]|0)+(i<<3)|0,A+(e<<5)|0,r)|0){e=0,n=6;break}if((e|0)>=(t[s>>2]|0)){e=1,n=6;break}}return(n|0)==6?e|0:0}function ai(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(f=S,S=S+16|0,l=f,o=r+8|0,!(o0(e,A,o)|0))return c=0,S=f,c|0;c=e+8|0;A:do if((t[c>>2]|0)>0){for(i=e+12|0,s=0;;){if(g=s,s=s+1|0,o0((t[i>>2]|0)+(g<<3)|0,A+(s<<5)|0,o)|0){s=0;break}if((s|0)>=(t[c>>2]|0))break A}return S=f,s|0}while(!1);if(M0(e,A,r,n)|0)return g=0,S=f,g|0;t[l>>2]=t[r>>2],t[l+4>>2]=o,s=t[c>>2]|0;A:do if((s|0)>0)for(e=e+12|0,o=0,i=s;;){if(s=t[e>>2]|0,(t[s+(o<<3)>>2]|0)>0){if(o0(l,n,t[s+(o<<3)+4>>2]|0)|0){s=0;break A}if(s=o+1|0,M0((t[e>>2]|0)+(o<<3)|0,A+(s<<5)|0,r,n)|0){s=0;break A}i=t[c>>2]|0}else s=o+1|0;if((s|0)<(i|0))o=s;else{s=1;break}}else s=1;while(!1);return g=s,S=f,g|0}function M0(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0,HA=0,QA=0,ce=0;if(HA=S,S=S+176|0,J=HA+172|0,s=HA+168|0,Z=HA,!(Pe(A,n)|0))return e=0,S=HA,e|0;if(Lr(A,n,J,s),Pn(Z|0,r|0,168)|0,(t[r>>2]|0)>0){A=0;do QA=Z+8+(A<<4)+8|0,iA=+Zt(+C[QA>>3],t[s>>2]|0),C[QA>>3]=iA,A=A+1|0;while((A|0)<(t[r>>2]|0))}G=+C[n>>3],W=+C[n+8>>3],iA=+Zt(+C[n+16>>3],t[s>>2]|0),L=+Zt(+C[n+24>>3],t[s>>2]|0);A:do if((t[e>>2]|0)>0){if(n=e+4|0,s=t[Z>>2]|0,(s|0)<=0){for(A=0;;)if(A=A+1|0,(A|0)>=(t[e>>2]|0)){A=0;break A}}for(r=0;;){if(A=t[n>>2]|0,I=+C[A+(r<<4)>>3],N=+Zt(+C[A+(r<<4)+8>>3],t[J>>2]|0),A=t[n>>2]|0,r=r+1|0,QA=(r|0)%(t[e>>2]|0)|0,i=+C[A+(QA<<4)>>3],o=+Zt(+C[A+(QA<<4)+8>>3],t[J>>2]|0),!(I>=G)|!(i>=G)&&!(I<=W)|!(i<=W)&&!(N<=L)|!(o<=L)&&!(N>=iA)|!(o>=iA)){D=i-I,f=o-N,A=0;do if(ce=A,A=A+1|0,QA=(A|0)==(s|0)?0:A,i=+C[Z+8+(ce<<4)+8>>3],o=+C[Z+8+(QA<<4)+8>>3]-i,l=+C[Z+8+(ce<<4)>>3],c=+C[Z+8+(QA<<4)>>3]-l,g=D*o-f*c,g!=0&&(V=N-i,MA=I-l,c=(V*c-o*MA)/g,!(c<0|c>1))&&(g=(D*V-f*MA)/g,g>=0&g<=1)){A=1;break A}while((A|0)<(s|0))}if((r|0)>=(t[e>>2]|0)){A=0;break}}}else A=0;while(!1);return ce=A,S=HA,ce|0}function ui(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0;if(M0(e,A,r,n)|0)return i=1,i|0;if(i=e+8|0,(t[i>>2]|0)<=0)return i=0,i|0;for(s=e+12|0,e=0;;){if(o=e,e=e+1|0,M0((t[s>>2]|0)+(o<<3)|0,A+(e<<5)|0,r,n)|0){e=1,s=6;break}if((e|0)>=(t[i>>2]|0)){e=0,s=6;break}}return(s|0)==6?e|0:0}function sa(){return 8}function ia(){return 16}function oa(){return 168}function la(){return 8}function aa(){return 16}function ua(){return 12}function ca(){return 8}function fa(e){return e=e|0,+(+((t[e>>2]|0)>>>0)+4294967296*+(t[e+4>>2]|0))}function ha(e){e=e|0;var A=0,r=0;return r=+C[e>>3],A=+C[e+8>>3],+ +Ce(+(r*r+A*A))}function ci(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0;f=+C[e>>3],c=+C[A>>3]-f,l=+C[e+8>>3],o=+C[A+8>>3]-l,D=+C[r>>3],i=+C[n>>3]-D,I=+C[r+8>>3],g=+C[n+8>>3]-I,i=(i*(l-I)-(f-D)*g)/(c*g-o*i),C[s>>3]=f+c*i,C[s+8>>3]=l+o*i}function fi(e,A){return e=e|0,A=A|0,+ee(+(+C[e>>3]-+C[A>>3]))<11920928955078125e-23?(A=+ee(+(+C[e+8>>3]-+C[A+8>>3]))<11920928955078125e-23,A|0):(A=0,A|0)}function ut(e,A){e=e|0,A=A|0;var r=0,n=0,s=0;return s=+C[e>>3]-+C[A>>3],n=+C[e+8>>3]-+C[A+8>>3],r=+C[e+16>>3]-+C[A+16>>3],+(s*s+n*n+r*r)}function da(e,A){e=e|0,A=A|0;var r=0,n=0,s=0;r=+C[e>>3],n=+Be(+r),r=+se(+r),C[A+16>>3]=r,r=+C[e+8>>3],s=n*+Be(+r),C[A>>3]=s,r=n*+se(+r),C[A+8>>3]=r}function ma(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;if(i=S,S=S+16|0,s=i,n=Oe(e,A)|0,(r+-1|0)>>>0>5||(n=(n|0)!=0,(r|0)==1&n))return s=-1,S=i,s|0;do if(a0(e,A,s)|0)n=-1;else if(n){n=((t[26352+(r<<2)>>2]|0)+5-(t[s>>2]|0)|0)%5|0;break}else{n=((t[26384+(r<<2)>>2]|0)+6-(t[s>>2]|0)|0)%6|0;break}while(!1);return s=n,S=i,s|0}function a0(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0;if(g=S,S=S+32|0,l=g+16|0,c=g,n=jn(e,A,l)|0,n|0)return r=n,S=g,r|0;i=re(e,A)|0,f=zt(e,A)|0,Yr(i,c),n=sr(i,t[l>>2]|0)|0;do if(_e(i)|0){do switch(i|0){case 4:{s=0;break}case 14:{s=1;break}case 24:{s=2;break}case 38:{s=3;break}case 49:{s=4;break}case 58:{s=5;break}case 63:{s=6;break}case 72:{s=7;break}case 83:{s=8;break}case 97:{s=9;break}case 107:{s=10;break}case 117:{s=11;break}default:OA(27795,27797,75,27806)}while(!1);if(o=t[26416+(s*24|0)+8>>2]|0,A=t[26416+(s*24|0)+16>>2]|0,e=t[l>>2]|0,(e|0)!=(t[c>>2]|0)&&(c=Dt(i)|0,e=t[l>>2]|0,c|(e|0)==(A|0)&&(n=(n+1|0)%6|0)),(f|0)==3&(e|0)==(A|0)){n=(n+5|0)%6|0;break}(f|0)==5&(e|0)==(o|0)&&(n=(n+1|0)%6|0)}while(!1);return t[r>>2]=n,r=0,S=g,r|0}function or(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0;if(Z=S,S=S+32|0,J=Z+24|0,W=Z+20|0,N=Z+8|0,L=Z+16|0,I=Z,c=(Oe(e,A)|0)==0,c=c?6:5,g=wA(e|0,A|0,52)|0,M()|0,g=g&15,c>>>0<=r>>>0)return n=2,S=Z,n|0;D=(g|0)==0,!D&&(G=CA(7,0,(g^15)*3|0)|0,(G&e|0)==0&((M()|0)&A|0)==0)?s=r:i=4;A:do if((i|0)==4){if(s=(Oe(e,A)|0)!=0,((s?4:5)|0)<(r|0)||a0(e,A,J)|0||(i=(t[J>>2]|0)+r|0,s?s=26704+(((i|0)%5|0)<<2)|0:s=26736+(((i|0)%6|0)<<2)|0,G=t[s>>2]|0,(G|0)==7))return n=1,S=Z,n|0;t[W>>2]=0,s=$(e,A,G,W,N)|0;do if(!s){if(l=N,f=t[l>>2]|0,l=t[l+4>>2]|0,o=l>>>0>>0|(l|0)==(A|0)&f>>>0>>0,i=o?f:e,o=o?l:A,!D&&(D=CA(7,0,(g^15)*3|0)|0,(f&D|0)==0&(l&(M()|0)|0)==0))s=r;else{if(l=(r+-1+c|0)%(c|0)|0,s=Oe(e,A)|0,(l|0)<0&&OA(27795,27797,248,27822),c=(s|0)!=0,((c?4:5)|0)<(l|0)&&OA(27795,27797,248,27822),a0(e,A,J)|0&&OA(27795,27797,248,27822),s=(t[J>>2]|0)+l|0,c?s=26704+(((s|0)%5|0)<<2)|0:s=26736+(((s|0)%6|0)<<2)|0,l=t[s>>2]|0,(l|0)==7&&OA(27795,27797,248,27822),t[L>>2]=0,s=$(e,A,l,L,I)|0,s|0)break;f=I,c=t[f>>2]|0,f=t[f+4>>2]|0;do if(f>>>0>>0|(f|0)==(o|0)&c>>>0>>0){if(Oe(c,f)|0?i=qA(c,f,e,A)|0:i=t[26800+((((t[L>>2]|0)+(t[26768+(l<<2)>>2]|0)|0)%6|0)<<2)>>2]|0,s=Oe(c,f)|0,(i+-1|0)>>>0>5){s=-1,i=c,o=f;break}if(s=(s|0)!=0,(i|0)==1&s){s=-1,i=c,o=f;break}do if(a0(c,f,J)|0)s=-1;else if(s){s=((t[26352+(i<<2)>>2]|0)+5-(t[J>>2]|0)|0)%5|0;break}else{s=((t[26384+(i<<2)>>2]|0)+6-(t[J>>2]|0)|0)%6|0;break}while(!1);i=c,o=f}else s=r;while(!1);l=N,f=t[l>>2]|0,l=t[l+4>>2]|0}if((i|0)==(f|0)&(o|0)==(l|0)){if(c=(Oe(f,l)|0)!=0,c?e=qA(f,l,e,A)|0:e=t[26800+((((t[W>>2]|0)+(t[26768+(G<<2)>>2]|0)|0)%6|0)<<2)>>2]|0,s=Oe(f,l)|0,(e+-1|0)>>>0<=5&&(iA=(s|0)!=0,!((e|0)==1&iA)))do if(a0(f,l,J)|0)s=-1;else if(iA){s=((t[26352+(e<<2)>>2]|0)+5-(t[J>>2]|0)|0)%5|0;break}else{s=((t[26384+(e<<2)>>2]|0)+6-(t[J>>2]|0)|0)%6|0;break}while(!1);else s=-1;s=s+1|0,s=(s|0)==6|c&(s|0)==5?0:s}A=o,e=i;break A}while(!1);return n=s,S=Z,n|0}while(!1);return iA=CA(s|0,0,56)|0,J=M()|0|A&-2130706433|536870912,t[n>>2]=iA|e,t[n+4>>2]=J,n=0,S=Z,n|0}function pa(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;return i=(Oe(e,A)|0)==0,n=or(e,A,0,r)|0,s=(n|0)==0,i?!s||(n=or(e,A,1,r+8|0)|0,n|0)||(n=or(e,A,2,r+16|0)|0,n|0)||(n=or(e,A,3,r+24|0)|0,n|0)||(n=or(e,A,4,r+32|0)|0,n)?(i=n,i|0):or(e,A,5,r+40|0)|0:!s||(n=or(e,A,1,r+8|0)|0,n|0)||(n=or(e,A,2,r+16|0)|0,n|0)||(n=or(e,A,3,r+24|0)|0,n|0)||(n=or(e,A,4,r+32|0)|0,n|0)?(i=n,i|0):(i=r+40|0,t[i>>2]=0,t[i+4>>2]=0,i=0,i|0)}function ga(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0,l=0,c=0;return c=S,S=S+192|0,s=c,i=c+168|0,o=wA(e|0,A|0,56)|0,M()|0,o=o&7,l=A&-2130706433|134217728,n=jn(e,l,i)|0,n|0?(l=n,S=c,l|0):(A=wA(e|0,A|0,52)|0,M()|0,A=A&15,Oe(e,l)|0?w(i,A,o,1,s):eA(i,A,o,1,s),l=s+8|0,t[r>>2]=t[l>>2],t[r+4>>2]=t[l+4>>2],t[r+8>>2]=t[l+8>>2],t[r+12>>2]=t[l+12>>2],l=0,S=c,l|0)}function hi(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0;return s=S,S=S+16|0,r=s,!(!0&(A&2013265920|0)==536870912)||(n=A&-2130706433|134217728,!(Ve(e,n)|0))?(n=0,S=s,n|0):(i=wA(e|0,A|0,56)|0,M()|0,i=(or(e,n,i&7,r)|0)==0,n=r,n=i&((t[n>>2]|0)==(e|0)?(t[n+4>>2]|0)==(A|0):0)&1,S=s,n|0)}function di(e,A,r){e=e|0,A=A|0,r=r|0;var n=0;(A|0)>0?(n=Ht(A,4)|0,t[e>>2]=n,n||OA(27835,27858,40,27872)):t[e>>2]=0,t[e+4>>2]=A,t[e+8>>2]=0,t[e+12>>2]=r}function mi(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0;s=e+4|0,i=e+12|0,o=e+8|0;A:for(;;){for(r=t[s>>2]|0,A=0;;){if((A|0)>=(r|0))break A;if(n=t[e>>2]|0,l=t[n+(A<<2)>>2]|0,!l)A=A+1|0;else break}A=n+(~~(+ee(+(+Ge(10,+ +(15-(t[i>>2]|0)|0))*(+C[l>>3]+ +C[l+8>>3])))%+(r|0))>>>0<<2)|0,r=t[A>>2]|0;e:do if(r|0){if(n=l+32|0,(r|0)==(l|0))t[A>>2]=t[n>>2];else{if(r=r+32|0,A=t[r>>2]|0,!A)break;for(;(A|0)!=(l|0);)if(r=A+32|0,A=t[r>>2]|0,!A)break e;t[r>>2]=t[n>>2]}ZA(l),t[o>>2]=(t[o>>2]|0)+-1}while(!1)}ZA(t[e>>2]|0)}function pi(e){e=e|0;var A=0,r=0,n=0;for(n=t[e+4>>2]|0,r=0;;){if((r|0)>=(n|0)){A=0,r=4;break}if(A=t[(t[e>>2]|0)+(r<<2)>>2]|0,!A)r=r+1|0;else{r=4;break}}return(r|0)==4?A|0:0}function gi(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0;if(r=~~(+ee(+(+Ge(10,+ +(15-(t[e+12>>2]|0)|0))*(+C[A>>3]+ +C[A+8>>3])))%+(t[e+4>>2]|0))>>>0,r=(t[e>>2]|0)+(r<<2)|0,n=t[r>>2]|0,!n)return i=1,i|0;i=A+32|0;do if((n|0)!=(A|0)){if(r=t[n+32>>2]|0,!r)return i=1,i|0;for(s=r;;){if((s|0)==(A|0)){s=8;break}if(r=t[s+32>>2]|0,r)n=s,s=r;else{r=1,s=10;break}}if((s|0)==8){t[n+32>>2]=t[i>>2];break}else if((s|0)==10)return r|0}else t[r>>2]=t[i>>2];while(!1);return ZA(A),i=e+8|0,t[i>>2]=(t[i>>2]|0)+-1,i=0,i|0}function ya(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0;i=Cr(40)|0,i||OA(27888,27858,98,27901),t[i>>2]=t[A>>2],t[i+4>>2]=t[A+4>>2],t[i+8>>2]=t[A+8>>2],t[i+12>>2]=t[A+12>>2],s=i+16|0,t[s>>2]=t[r>>2],t[s+4>>2]=t[r+4>>2],t[s+8>>2]=t[r+8>>2],t[s+12>>2]=t[r+12>>2],t[i+32>>2]=0,s=~~(+ee(+(+Ge(10,+ +(15-(t[e+12>>2]|0)|0))*(+C[A>>3]+ +C[A+8>>3])))%+(t[e+4>>2]|0))>>>0,s=(t[e>>2]|0)+(s<<2)|0,n=t[s>>2]|0;do if(!n)t[s>>2]=i;else{for(;!(Ln(n,A)|0&&Ln(n+16|0,r)|0);)if(s=t[n+32>>2]|0,n=(s|0)==0?n:s,!(t[n+32>>2]|0)){o=10;break}if((o|0)==10){t[n+32>>2]=i;break}return ZA(i),o=n,o|0}while(!1);return o=e+8|0,t[o>>2]=(t[o>>2]|0)+1,o=i,o|0}function xa(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0;if(s=~~(+ee(+(+Ge(10,+ +(15-(t[e+12>>2]|0)|0))*(+C[A>>3]+ +C[A+8>>3])))%+(t[e+4>>2]|0))>>>0,s=t[(t[e>>2]|0)+(s<<2)>>2]|0,!s)return r=0,r|0;if(!r){for(e=s;;){if(Ln(e,A)|0){n=10;break}if(e=t[e+32>>2]|0,!e){e=0,n=10;break}}if((n|0)==10)return e|0}for(e=s;;){if(Ln(e,A)|0&&Ln(e+16|0,r)|0){n=10;break}if(e=t[e+32>>2]|0,!e){e=0,n=10;break}}return(n|0)==10?e|0:0}function wa(e,A){e=e|0,A=A|0;var r=0;if(r=~~(+ee(+(+Ge(10,+ +(15-(t[e+12>>2]|0)|0))*(+C[A>>3]+ +C[A+8>>3])))%+(t[e+4>>2]|0))>>>0,e=t[(t[e>>2]|0)+(r<<2)>>2]|0,!e)return r=0,r|0;for(;;){if(Ln(e,A)|0){A=5;break}if(e=t[e+32>>2]|0,!e){e=0,A=5;break}}return(A|0)==5?e|0:0}function va(){return 27920}function Jr(e){return e=+e,~~+vi(+e)|0}function Cr(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0,G=0,W=0,iA=0,J=0,Z=0,V=0,MA=0;MA=S,S=S+16|0,I=MA;do if(e>>>0<245){if(f=e>>>0<11?16:e+11&-8,e=f>>>3,D=t[6981]|0,r=D>>>e,r&3|0)return A=(r&1^1)+e|0,e=27964+(A<<1<<2)|0,r=e+8|0,n=t[r>>2]|0,s=n+8|0,i=t[s>>2]|0,(i|0)==(e|0)?t[6981]=D&~(1<>2]=e,t[r>>2]=i),V=A<<3,t[n+4>>2]=V|3,V=n+V+4|0,t[V>>2]=t[V>>2]|1,V=s,S=MA,V|0;if(g=t[6983]|0,f>>>0>g>>>0){if(r|0)return A=2<>>12&16,A=A>>>l,r=A>>>5&8,A=A>>>r,i=A>>>2&4,A=A>>>i,e=A>>>1&2,A=A>>>e,n=A>>>1&1,n=(r|l|i|e|n)+(A>>>n)|0,A=27964+(n<<1<<2)|0,e=A+8|0,i=t[e>>2]|0,l=i+8|0,r=t[l>>2]|0,(r|0)==(A|0)?(e=D&~(1<>2]=A,t[e>>2]=r,e=D),V=n<<3,o=V-f|0,t[i+4>>2]=f|3,s=i+f|0,t[s+4>>2]=o|1,t[i+V>>2]=o,g|0&&(n=t[6986]|0,A=g>>>3,r=27964+(A<<1<<2)|0,A=1<>2]|0):(t[6981]=e|A,A=r,e=r+8|0),t[e>>2]=n,t[A+12>>2]=n,t[n+8>>2]=A,t[n+12>>2]=r),t[6983]=o,t[6986]=s,V=l,S=MA,V|0;if(i=t[6982]|0,i){for(r=(i&0-i)+-1|0,s=r>>>12&16,r=r>>>s,n=r>>>5&8,r=r>>>n,o=r>>>2&4,r=r>>>o,l=r>>>1&2,r=r>>>l,c=r>>>1&1,c=t[28228+((n|s|o|l|c)+(r>>>c)<<2)>>2]|0,r=c,l=c,c=(t[c+4>>2]&-8)-f|0;e=t[r+16>>2]|0,!(!e&&(e=t[r+20>>2]|0,!e));)o=(t[e+4>>2]&-8)-f|0,s=o>>>0>>0,r=e,l=s?e:l,c=s?o:c;if(o=l+f|0,o>>>0>l>>>0){s=t[l+24>>2]|0,A=t[l+12>>2]|0;do if((A|0)==(l|0)){if(e=l+20|0,A=t[e>>2]|0,!A&&(e=l+16|0,A=t[e>>2]|0,!A)){r=0;break}for(;;)if(n=A+20|0,r=t[n>>2]|0,r)A=r,e=n;else if(n=A+16|0,r=t[n>>2]|0,r)A=r,e=n;else break;t[e>>2]=0,r=A}else r=t[l+8>>2]|0,t[r+12>>2]=A,t[A+8>>2]=r,r=A;while(!1);do if(s|0){if(A=t[l+28>>2]|0,e=28228+(A<<2)|0,(l|0)==(t[e>>2]|0)){if(t[e>>2]=r,!r){t[6982]=i&~(1<>2]|0)==(l|0)?V:s+20|0)>>2]=r,!r)break;t[r+24>>2]=s,A=t[l+16>>2]|0,A|0&&(t[r+16>>2]=A,t[A+24>>2]=r),A=t[l+20>>2]|0,A|0&&(t[r+20>>2]=A,t[A+24>>2]=r)}while(!1);return c>>>0<16?(V=c+f|0,t[l+4>>2]=V|3,V=l+V+4|0,t[V>>2]=t[V>>2]|1):(t[l+4>>2]=f|3,t[o+4>>2]=c|1,t[o+c>>2]=c,g|0&&(n=t[6986]|0,A=g>>>3,r=27964+(A<<1<<2)|0,A=1<>2]|0):(t[6981]=A|D,A=r,e=r+8|0),t[e>>2]=n,t[A+12>>2]=n,t[n+8>>2]=A,t[n+12>>2]=r),t[6983]=c,t[6986]=o),V=l+8|0,S=MA,V|0}else D=f}else D=f}else D=f}else if(e>>>0<=4294967231)if(e=e+11|0,f=e&-8,n=t[6982]|0,n){s=0-f|0,e=e>>>8,e?f>>>0>16777215?c=31:(D=(e+1048320|0)>>>16&8,G=e<>>16&4,G=G<>>16&2,c=14-(l|D|c)+(G<>>15)|0,c=f>>>(c+7|0)&1|c<<1):c=0,r=t[28228+(c<<2)>>2]|0;A:do if(!r)r=0,e=0,G=61;else for(e=0,l=f<<((c|0)==31?0:25-(c>>>1)|0),i=0;;){if(o=(t[r+4>>2]&-8)-f|0,o>>>0>>0)if(o)e=r,s=o;else{e=r,s=0,G=65;break A}if(G=t[r+20>>2]|0,r=t[r+16+(l>>>31<<2)>>2]|0,i=(G|0)==0|(G|0)==(r|0)?i:G,r)l=l<<1;else{r=i,G=61;break}}while(!1);if((G|0)==61){if((r|0)==0&(e|0)==0){if(e=2<>>12&16,D=D>>>o,i=D>>>5&8,D=D>>>i,l=D>>>2&4,D=D>>>l,c=D>>>1&2,D=D>>>c,r=D>>>1&1,e=0,r=t[28228+((i|o|l|c|r)+(D>>>r)<<2)>>2]|0}r?G=65:(l=e,o=s)}if((G|0)==65)for(i=r;;)if(D=(t[i+4>>2]&-8)-f|0,r=D>>>0>>0,s=r?D:s,e=r?i:e,r=t[i+16>>2]|0,r||(r=t[i+20>>2]|0),r)i=r;else{l=e,o=s;break}if((l|0)!=0&&o>>>0<((t[6983]|0)-f|0)>>>0&&(g=l+f|0,g>>>0>l>>>0)){i=t[l+24>>2]|0,A=t[l+12>>2]|0;do if((A|0)==(l|0)){if(e=l+20|0,A=t[e>>2]|0,!A&&(e=l+16|0,A=t[e>>2]|0,!A)){A=0;break}for(;;)if(s=A+20|0,r=t[s>>2]|0,r)A=r,e=s;else if(s=A+16|0,r=t[s>>2]|0,r)A=r,e=s;else break;t[e>>2]=0}else V=t[l+8>>2]|0,t[V+12>>2]=A,t[A+8>>2]=V;while(!1);do if(i){if(e=t[l+28>>2]|0,r=28228+(e<<2)|0,(l|0)==(t[r>>2]|0)){if(t[r>>2]=A,!A){n=n&~(1<>2]|0)==(l|0)?V:i+20|0)>>2]=A,!A)break;t[A+24>>2]=i,e=t[l+16>>2]|0,e|0&&(t[A+16>>2]=e,t[e+24>>2]=A),e=t[l+20>>2]|0,e&&(t[A+20>>2]=e,t[e+24>>2]=A)}while(!1);A:do if(o>>>0<16)V=o+f|0,t[l+4>>2]=V|3,V=l+V+4|0,t[V>>2]=t[V>>2]|1;else{if(t[l+4>>2]=f|3,t[g+4>>2]=o|1,t[g+o>>2]=o,A=o>>>3,o>>>0<256){r=27964+(A<<1<<2)|0,e=t[6981]|0,A=1<>2]|0):(t[6981]=e|A,A=r,e=r+8|0),t[e>>2]=g,t[A+12>>2]=g,t[g+8>>2]=A,t[g+12>>2]=r;break}if(A=o>>>8,A?o>>>0>16777215?r=31:(Z=(A+1048320|0)>>>16&8,V=A<>>16&4,V=V<>>16&2,r=14-(J|Z|r)+(V<>>15)|0,r=o>>>(r+7|0)&1|r<<1):r=0,A=28228+(r<<2)|0,t[g+28>>2]=r,e=g+16|0,t[e+4>>2]=0,t[e>>2]=0,e=1<>2]=g,t[g+24>>2]=A,t[g+12>>2]=g,t[g+8>>2]=g;break}A=t[A>>2]|0;e:do if((t[A+4>>2]&-8|0)!=(o|0)){for(n=o<<((r|0)==31?0:25-(r>>>1)|0);r=A+16+(n>>>31<<2)|0,e=t[r>>2]|0,!!e;)if((t[e+4>>2]&-8|0)==(o|0)){A=e;break e}else n=n<<1,A=e;t[r>>2]=g,t[g+24>>2]=A,t[g+12>>2]=g,t[g+8>>2]=g;break A}while(!1);Z=A+8|0,V=t[Z>>2]|0,t[V+12>>2]=g,t[Z>>2]=g,t[g+8>>2]=V,t[g+12>>2]=A,t[g+24>>2]=0}while(!1);return V=l+8|0,S=MA,V|0}else D=f}else D=f;else D=-1;while(!1);if(r=t[6983]|0,r>>>0>=D>>>0)return A=r-D|0,e=t[6986]|0,A>>>0>15?(V=e+D|0,t[6986]=V,t[6983]=A,t[V+4>>2]=A|1,t[e+r>>2]=A,t[e+4>>2]=D|3):(t[6983]=0,t[6986]=0,t[e+4>>2]=r|3,V=e+r+4|0,t[V>>2]=t[V>>2]|1),V=e+8|0,S=MA,V|0;if(o=t[6984]|0,o>>>0>D>>>0)return J=o-D|0,t[6984]=J,V=t[6987]|0,Z=V+D|0,t[6987]=Z,t[Z+4>>2]=J|1,t[V+4>>2]=D|3,V=V+8|0,S=MA,V|0;if(t[7099]|0?e=t[7101]|0:(t[7101]=4096,t[7100]=4096,t[7102]=-1,t[7103]=-1,t[7104]=0,t[7092]=0,t[7099]=I&-16^1431655768,e=4096),l=D+48|0,c=D+47|0,i=e+c|0,s=0-e|0,f=i&s,f>>>0<=D>>>0||(e=t[7091]|0,e|0&&(g=t[7089]|0,I=g+f|0,I>>>0<=g>>>0|I>>>0>e>>>0)))return V=0,S=MA,V|0;A:do if(t[7092]&4)A=0,G=143;else{r=t[6987]|0;e:do if(r){for(n=28372;I=t[n>>2]|0,!(I>>>0<=r>>>0&&(I+(t[n+4>>2]|0)|0)>>>0>r>>>0);)if(e=t[n+8>>2]|0,e)n=e;else{G=128;break e}if(A=i-o&s,A>>>0<2147483647)if(e=en(A|0)|0,(e|0)==((t[n>>2]|0)+(t[n+4>>2]|0)|0)){if((e|0)!=-1){o=A,i=e,G=145;break A}}else n=e,G=136;else A=0}else G=128;while(!1);do if((G|0)==128)if(r=en(0)|0,(r|0)!=-1&&(A=r,L=t[7100]|0,N=L+-1|0,A=((N&A|0)==0?0:(N+A&0-L)-A|0)+f|0,L=t[7089]|0,N=A+L|0,A>>>0>D>>>0&A>>>0<2147483647)){if(I=t[7091]|0,I|0&&N>>>0<=L>>>0|N>>>0>I>>>0){A=0;break}if(e=en(A|0)|0,(e|0)==(r|0)){o=A,i=r,G=145;break A}else n=e,G=136}else A=0;while(!1);do if((G|0)==136){if(r=0-A|0,!(l>>>0>A>>>0&(A>>>0<2147483647&(n|0)!=-1)))if((n|0)==-1){A=0;break}else{o=A,i=n,G=145;break A}if(e=t[7101]|0,e=c-A+e&0-e,e>>>0>=2147483647){o=A,i=n,G=145;break A}if((en(e|0)|0)==-1){en(r|0)|0,A=0;break}else{o=e+A|0,i=n,G=145;break A}}while(!1);t[7092]=t[7092]|4,G=143}while(!1);if((G|0)==143&&f>>>0<2147483647&&(J=en(f|0)|0,N=en(0)|0,W=N-J|0,iA=W>>>0>(D+40|0)>>>0,!((J|0)==-1|iA^1|J>>>0>>0&((J|0)!=-1&(N|0)!=-1)^1))&&(o=iA?W:A,i=J,G=145),(G|0)==145){A=(t[7089]|0)+o|0,t[7089]=A,A>>>0>(t[7090]|0)>>>0&&(t[7090]=A),c=t[6987]|0;A:do if(c){for(A=28372;;){if(e=t[A>>2]|0,r=t[A+4>>2]|0,(i|0)==(e+r|0)){G=154;break}if(n=t[A+8>>2]|0,n)A=n;else break}if((G|0)==154&&(Z=A+4|0,(t[A+12>>2]&8|0)==0)&&i>>>0>c>>>0&e>>>0<=c>>>0){t[Z>>2]=r+o,V=(t[6984]|0)+o|0,J=c+8|0,J=(J&7|0)==0?0:0-J&7,Z=c+J|0,J=V-J|0,t[6987]=Z,t[6984]=J,t[Z+4>>2]=J|1,t[c+V+4>>2]=40,t[6988]=t[7103];break}for(i>>>0<(t[6985]|0)>>>0&&(t[6985]=i),r=i+o|0,A=28372;;){if((t[A>>2]|0)==(r|0)){G=162;break}if(e=t[A+8>>2]|0,e)A=e;else break}if((G|0)==162&&(t[A+12>>2]&8|0)==0){t[A>>2]=i,g=A+4|0,t[g>>2]=(t[g>>2]|0)+o,g=i+8|0,g=i+((g&7|0)==0?0:0-g&7)|0,A=r+8|0,A=r+((A&7|0)==0?0:0-A&7)|0,f=g+D|0,l=A-g-D|0,t[g+4>>2]=D|3;e:do if((c|0)==(A|0))V=(t[6984]|0)+l|0,t[6984]=V,t[6987]=f,t[f+4>>2]=V|1;else{if((t[6986]|0)==(A|0)){V=(t[6983]|0)+l|0,t[6983]=V,t[6986]=f,t[f+4>>2]=V|1,t[f+V>>2]=V;break}if(e=t[A+4>>2]|0,(e&3|0)==1){o=e&-8,n=e>>>3;t:do if(e>>>0<256)if(e=t[A+8>>2]|0,r=t[A+12>>2]|0,(r|0)==(e|0)){t[6981]=t[6981]&~(1<>2]=r,t[r+8>>2]=e;break}else{i=t[A+24>>2]|0,e=t[A+12>>2]|0;do if((e|0)==(A|0)){if(r=A+16|0,n=r+4|0,e=t[n>>2]|0,e)r=n;else if(e=t[r>>2]|0,!e){e=0;break}for(;;)if(s=e+20|0,n=t[s>>2]|0,n)e=n,r=s;else if(s=e+16|0,n=t[s>>2]|0,n)e=n,r=s;else break;t[r>>2]=0}else V=t[A+8>>2]|0,t[V+12>>2]=e,t[e+8>>2]=V;while(!1);if(!i)break;r=t[A+28>>2]|0,n=28228+(r<<2)|0;do if((t[n>>2]|0)!=(A|0)){if(V=i+16|0,t[((t[V>>2]|0)==(A|0)?V:i+20|0)>>2]=e,!e)break t}else{if(t[n>>2]=e,e|0)break;t[6982]=t[6982]&~(1<>2]=i,r=A+16|0,n=t[r>>2]|0,n|0&&(t[e+16>>2]=n,t[n+24>>2]=e),r=t[r+4>>2]|0,!r)break;t[e+20>>2]=r,t[r+24>>2]=e}while(!1);A=A+o|0,s=o+l|0}else s=l;if(A=A+4|0,t[A>>2]=t[A>>2]&-2,t[f+4>>2]=s|1,t[f+s>>2]=s,A=s>>>3,s>>>0<256){r=27964+(A<<1<<2)|0,e=t[6981]|0,A=1<>2]|0):(t[6981]=e|A,A=r,e=r+8|0),t[e>>2]=f,t[A+12>>2]=f,t[f+8>>2]=A,t[f+12>>2]=r;break}A=s>>>8;do if(!A)n=0;else{if(s>>>0>16777215){n=31;break}Z=(A+1048320|0)>>>16&8,V=A<>>16&4,V=V<>>16&2,n=14-(J|Z|n)+(V<>>15)|0,n=s>>>(n+7|0)&1|n<<1}while(!1);if(A=28228+(n<<2)|0,t[f+28>>2]=n,e=f+16|0,t[e+4>>2]=0,t[e>>2]=0,e=t[6982]|0,r=1<>2]=f,t[f+24>>2]=A,t[f+12>>2]=f,t[f+8>>2]=f;break}A=t[A>>2]|0;t:do if((t[A+4>>2]&-8|0)!=(s|0)){for(n=s<<((n|0)==31?0:25-(n>>>1)|0);r=A+16+(n>>>31<<2)|0,e=t[r>>2]|0,!!e;)if((t[e+4>>2]&-8|0)==(s|0)){A=e;break t}else n=n<<1,A=e;t[r>>2]=f,t[f+24>>2]=A,t[f+12>>2]=f,t[f+8>>2]=f;break e}while(!1);Z=A+8|0,V=t[Z>>2]|0,t[V+12>>2]=f,t[Z>>2]=f,t[f+8>>2]=V,t[f+12>>2]=A,t[f+24>>2]=0}while(!1);return V=g+8|0,S=MA,V|0}for(A=28372;e=t[A>>2]|0,!(e>>>0<=c>>>0&&(V=e+(t[A+4>>2]|0)|0,V>>>0>c>>>0));)A=t[A+8>>2]|0;s=V+-47|0,e=s+8|0,e=s+((e&7|0)==0?0:0-e&7)|0,s=c+16|0,e=e>>>0>>0?c:e,A=e+8|0,r=o+-40|0,J=i+8|0,J=(J&7|0)==0?0:0-J&7,Z=i+J|0,J=r-J|0,t[6987]=Z,t[6984]=J,t[Z+4>>2]=J|1,t[i+r+4>>2]=40,t[6988]=t[7103],r=e+4|0,t[r>>2]=27,t[A>>2]=t[7093],t[A+4>>2]=t[7094],t[A+8>>2]=t[7095],t[A+12>>2]=t[7096],t[7093]=i,t[7094]=o,t[7096]=0,t[7095]=A,A=e+24|0;do Z=A,A=A+4|0,t[A>>2]=7;while((Z+8|0)>>>0>>0);if((e|0)!=(c|0)){if(i=e-c|0,t[r>>2]=t[r>>2]&-2,t[c+4>>2]=i|1,t[e>>2]=i,A=i>>>3,i>>>0<256){r=27964+(A<<1<<2)|0,e=t[6981]|0,A=1<>2]|0):(t[6981]=e|A,A=r,e=r+8|0),t[e>>2]=c,t[A+12>>2]=c,t[c+8>>2]=A,t[c+12>>2]=r;break}if(A=i>>>8,A?i>>>0>16777215?n=31:(Z=(A+1048320|0)>>>16&8,V=A<>>16&4,V=V<>>16&2,n=14-(J|Z|n)+(V<>>15)|0,n=i>>>(n+7|0)&1|n<<1):n=0,r=28228+(n<<2)|0,t[c+28>>2]=n,t[c+20>>2]=0,t[s>>2]=0,A=t[6982]|0,e=1<>2]=c,t[c+24>>2]=r,t[c+12>>2]=c,t[c+8>>2]=c;break}A=t[r>>2]|0;e:do if((t[A+4>>2]&-8|0)!=(i|0)){for(n=i<<((n|0)==31?0:25-(n>>>1)|0);r=A+16+(n>>>31<<2)|0,e=t[r>>2]|0,!!e;)if((t[e+4>>2]&-8|0)==(i|0)){A=e;break e}else n=n<<1,A=e;t[r>>2]=c,t[c+24>>2]=A,t[c+12>>2]=c,t[c+8>>2]=c;break A}while(!1);Z=A+8|0,V=t[Z>>2]|0,t[V+12>>2]=c,t[Z>>2]=c,t[c+8>>2]=V,t[c+12>>2]=A,t[c+24>>2]=0}}else V=t[6985]|0,(V|0)==0|i>>>0>>0&&(t[6985]=i),t[7093]=i,t[7094]=o,t[7096]=0,t[6990]=t[7099],t[6989]=-1,t[6994]=27964,t[6993]=27964,t[6996]=27972,t[6995]=27972,t[6998]=27980,t[6997]=27980,t[7e3]=27988,t[6999]=27988,t[7002]=27996,t[7001]=27996,t[7004]=28004,t[7003]=28004,t[7006]=28012,t[7005]=28012,t[7008]=28020,t[7007]=28020,t[7010]=28028,t[7009]=28028,t[7012]=28036,t[7011]=28036,t[7014]=28044,t[7013]=28044,t[7016]=28052,t[7015]=28052,t[7018]=28060,t[7017]=28060,t[7020]=28068,t[7019]=28068,t[7022]=28076,t[7021]=28076,t[7024]=28084,t[7023]=28084,t[7026]=28092,t[7025]=28092,t[7028]=28100,t[7027]=28100,t[7030]=28108,t[7029]=28108,t[7032]=28116,t[7031]=28116,t[7034]=28124,t[7033]=28124,t[7036]=28132,t[7035]=28132,t[7038]=28140,t[7037]=28140,t[7040]=28148,t[7039]=28148,t[7042]=28156,t[7041]=28156,t[7044]=28164,t[7043]=28164,t[7046]=28172,t[7045]=28172,t[7048]=28180,t[7047]=28180,t[7050]=28188,t[7049]=28188,t[7052]=28196,t[7051]=28196,t[7054]=28204,t[7053]=28204,t[7056]=28212,t[7055]=28212,V=o+-40|0,J=i+8|0,J=(J&7|0)==0?0:0-J&7,Z=i+J|0,J=V-J|0,t[6987]=Z,t[6984]=J,t[Z+4>>2]=J|1,t[i+V+4>>2]=40,t[6988]=t[7103];while(!1);if(A=t[6984]|0,A>>>0>D>>>0)return J=A-D|0,t[6984]=J,V=t[6987]|0,Z=V+D|0,t[6987]=Z,t[Z+4>>2]=J|1,t[V+4>>2]=D|3,V=V+8|0,S=MA,V|0}return V=va()|0,t[V>>2]=12,V=0,S=MA,V|0}function ZA(e){e=e|0;var A=0,r=0,n=0,s=0,i=0,o=0,l=0,c=0;if(e){r=e+-8|0,s=t[6985]|0,e=t[e+-4>>2]|0,A=e&-8,c=r+A|0;do if(e&1)l=r,o=r;else{if(n=t[r>>2]|0,!(e&3)||(o=r+(0-n)|0,i=n+A|0,o>>>0>>0))return;if((t[6986]|0)==(o|0)){if(e=c+4|0,A=t[e>>2]|0,(A&3|0)!=3){l=o,A=i;break}t[6983]=i,t[e>>2]=A&-2,t[o+4>>2]=i|1,t[o+i>>2]=i;return}if(r=n>>>3,n>>>0<256)if(e=t[o+8>>2]|0,A=t[o+12>>2]|0,(A|0)==(e|0)){t[6981]=t[6981]&~(1<>2]=A,t[A+8>>2]=e,l=o,A=i;break}s=t[o+24>>2]|0,e=t[o+12>>2]|0;do if((e|0)==(o|0)){if(A=o+16|0,r=A+4|0,e=t[r>>2]|0,e)A=r;else if(e=t[A>>2]|0,!e){e=0;break}for(;;)if(n=e+20|0,r=t[n>>2]|0,r)e=r,A=n;else if(n=e+16|0,r=t[n>>2]|0,r)e=r,A=n;else break;t[A>>2]=0}else l=t[o+8>>2]|0,t[l+12>>2]=e,t[e+8>>2]=l;while(!1);if(s){if(A=t[o+28>>2]|0,r=28228+(A<<2)|0,(t[r>>2]|0)==(o|0)){if(t[r>>2]=e,!e){t[6982]=t[6982]&~(1<>2]|0)==(o|0)?l:s+20|0)>>2]=e,!e){l=o,A=i;break}t[e+24>>2]=s,A=o+16|0,r=t[A>>2]|0,r|0&&(t[e+16>>2]=r,t[r+24>>2]=e),A=t[A+4>>2]|0,A?(t[e+20>>2]=A,t[A+24>>2]=e,l=o,A=i):(l=o,A=i)}else l=o,A=i}while(!1);if(!(o>>>0>=c>>>0)&&(e=c+4|0,n=t[e>>2]|0,!!(n&1))){if(n&2)t[e>>2]=n&-2,t[l+4>>2]=A|1,t[o+A>>2]=A,s=A;else{if((t[6987]|0)==(c|0)){if(c=(t[6984]|0)+A|0,t[6984]=c,t[6987]=l,t[l+4>>2]=c|1,(l|0)!=(t[6986]|0))return;t[6986]=0,t[6983]=0;return}if((t[6986]|0)==(c|0)){c=(t[6983]|0)+A|0,t[6983]=c,t[6986]=o,t[l+4>>2]=c|1,t[o+c>>2]=c;return}s=(n&-8)+A|0,r=n>>>3;do if(n>>>0<256)if(A=t[c+8>>2]|0,e=t[c+12>>2]|0,(e|0)==(A|0)){t[6981]=t[6981]&~(1<>2]=e,t[e+8>>2]=A;break}else{i=t[c+24>>2]|0,e=t[c+12>>2]|0;do if((e|0)==(c|0)){if(A=c+16|0,r=A+4|0,e=t[r>>2]|0,e)A=r;else if(e=t[A>>2]|0,!e){r=0;break}for(;;)if(n=e+20|0,r=t[n>>2]|0,r)e=r,A=n;else if(n=e+16|0,r=t[n>>2]|0,r)e=r,A=n;else break;t[A>>2]=0,r=e}else r=t[c+8>>2]|0,t[r+12>>2]=e,t[e+8>>2]=r,r=e;while(!1);if(i|0){if(e=t[c+28>>2]|0,A=28228+(e<<2)|0,(t[A>>2]|0)==(c|0)){if(t[A>>2]=r,!r){t[6982]=t[6982]&~(1<>2]|0)==(c|0)?n:i+20|0)>>2]=r,!r)break;t[r+24>>2]=i,e=c+16|0,A=t[e>>2]|0,A|0&&(t[r+16>>2]=A,t[A+24>>2]=r),e=t[e+4>>2]|0,e|0&&(t[r+20>>2]=e,t[e+24>>2]=r)}}while(!1);if(t[l+4>>2]=s|1,t[o+s>>2]=s,(l|0)==(t[6986]|0)){t[6983]=s;return}}if(e=s>>>3,s>>>0<256){r=27964+(e<<1<<2)|0,A=t[6981]|0,e=1<>2]|0):(t[6981]=A|e,e=r,A=r+8|0),t[A>>2]=l,t[e+12>>2]=l,t[l+8>>2]=e,t[l+12>>2]=r;return}e=s>>>8,e?s>>>0>16777215?n=31:(o=(e+1048320|0)>>>16&8,c=e<>>16&4,c=c<>>16&2,n=14-(i|o|n)+(c<>>15)|0,n=s>>>(n+7|0)&1|n<<1):n=0,e=28228+(n<<2)|0,t[l+28>>2]=n,t[l+20>>2]=0,t[l+16>>2]=0,A=t[6982]|0,r=1<>2]=l,t[l+24>>2]=e,t[l+12>>2]=l,t[l+8>>2]=l;else{e=t[e>>2]|0;e:do if((t[e+4>>2]&-8|0)!=(s|0)){for(n=s<<((n|0)==31?0:25-(n>>>1)|0);r=e+16+(n>>>31<<2)|0,A=t[r>>2]|0,!!A;)if((t[A+4>>2]&-8|0)==(s|0)){e=A;break e}else n=n<<1,e=A;t[r>>2]=l,t[l+24>>2]=e,t[l+12>>2]=l,t[l+8>>2]=l;break A}while(!1);o=e+8|0,c=t[o>>2]|0,t[c+12>>2]=l,t[o>>2]=l,t[l+8>>2]=c,t[l+12>>2]=e,t[l+24>>2]=0}while(!1);if(c=(t[6989]|0)+-1|0,t[6989]=c,!(c|0)){for(e=28380;e=t[e>>2]|0,e;)e=e+8|0;t[6989]=-1}}}}function Ht(e,A){e=e|0,A=A|0;var r=0;return e?(r=ht(A,e)|0,(A|e)>>>0>65535&&(r=((r>>>0)/(e>>>0)|0|0)==(A|0)?r:-1)):r=0,e=Cr(r)|0,!e||!(t[e+-4>>2]&3)||An(e|0,0,r|0)|0,e|0}function $A(e,A,r,n){return e=e|0,A=A|0,r=r|0,n=n|0,r=e+r>>>0,WA(A+n+(r>>>0>>0|0)>>>0|0),r|0|0}function dt(e,A,r,n){return e=e|0,A=A|0,r=r|0,n=n|0,n=A-n-(r>>>0>e>>>0|0)>>>0,WA(n|0),e-r>>>0|0|0}function yi(e){return e=e|0,(e?31-(wt(e^e-1)|0)|0:32)|0}function ds(e,A,r,n,s){e=e|0,A=A|0,r=r|0,n=n|0,s=s|0;var i=0,o=0,l=0,c=0,f=0,g=0,D=0,I=0,L=0,N=0;if(g=e,c=A,f=c,o=r,I=n,l=I,!f)return i=(s|0)!=0,l?i?(t[s>>2]=e|0,t[s+4>>2]=A&0,I=0,s=0,WA(I|0),s|0):(I=0,s=0,WA(I|0),s|0):(i&&(t[s>>2]=(g>>>0)%(o>>>0),t[s+4>>2]=0),I=0,s=(g>>>0)/(o>>>0)>>>0,WA(I|0),s|0);i=(l|0)==0;do if(o){if(!i){if(i=(wt(l|0)|0)-(wt(f|0)|0)|0,i>>>0<=31){D=i+1|0,l=31-i|0,A=i-31>>31,o=D,e=g>>>(D>>>0)&A|f<>>(D>>>0)&A,i=0,l=g<>2]=e|0,t[s+4>>2]=c|A&0,I=0,s=0,WA(I|0),s|0):(I=0,s=0,WA(I|0),s|0)}if(i=o-1|0,i&o|0){l=(wt(o|0)|0)+33-(wt(f|0)|0)|0,N=64-l|0,D=32-l|0,c=D>>31,L=l-32|0,A=L>>31,o=l,e=D-1>>31&f>>>(L>>>0)|(f<>>(l>>>0))&A,A=A&f>>>(l>>>0),i=g<>>(L>>>0))&c|g<>31;break}return s|0&&(t[s>>2]=i&g,t[s+4>>2]=0),(o|0)==1?(L=c|A&0,N=e|0|0,WA(L|0),N|0):(N=yi(o|0)|0,L=f>>>(N>>>0)|0,N=f<<32-N|g>>>(N>>>0)|0,WA(L|0),N|0)}else{if(i)return s|0&&(t[s>>2]=(f>>>0)%(o>>>0),t[s+4>>2]=0),L=0,N=(f>>>0)/(o>>>0)>>>0,WA(L|0),N|0;if(!g)return s|0&&(t[s>>2]=0,t[s+4>>2]=(f>>>0)%(l>>>0)),L=0,N=(f>>>0)/(l>>>0)>>>0,WA(L|0),N|0;if(i=l-1|0,!(i&l))return s|0&&(t[s>>2]=e|0,t[s+4>>2]=i&f|A&0),L=0,N=f>>>((yi(l|0)|0)>>>0),WA(L|0),N|0;if(i=(wt(l|0)|0)-(wt(f|0)|0)|0,i>>>0<=30){A=i+1|0,l=31-i|0,o=A,e=f<>>(A>>>0),A=f>>>(A>>>0),i=0,l=g<>2]=e|0,t[s+4>>2]=c|A&0,L=0,N=0,WA(L|0),N|0):(L=0,N=0,WA(L|0),N|0)}while(!1);if(!o)f=l,c=0,l=0;else{D=r|0|0,g=I|n&0,f=$A(D|0,g|0,-1,-1)|0,r=M()|0,c=l,l=0;do n=c,c=i>>>31|c<<1,i=l|i<<1,n=e<<1|n>>>31|0,I=e>>>31|A<<1|0,dt(f|0,r|0,n|0,I|0)|0,N=M()|0,L=N>>31|((N|0)<0?-1:0)<<1,l=L&1,e=dt(n|0,I|0,L&D|0,(((N|0)<0?-1:0)>>31|((N|0)<0?-1:0)<<1)&g|0)|0,A=M()|0,o=o-1|0;while((o|0)!=0);f=c,c=0}return o=0,s|0&&(t[s>>2]=e,t[s+4>>2]=A),L=(i|0)>>>31|(f|o)<<1|(o<<1|i>>>31)&0|c,N=(i<<1|0)&-2|l,WA(L|0),N|0}function Xr(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0;return f=A>>31|((A|0)<0?-1:0)<<1,c=((A|0)<0?-1:0)>>31|((A|0)<0?-1:0)<<1,i=n>>31|((n|0)<0?-1:0)<<1,s=((n|0)<0?-1:0)>>31|((n|0)<0?-1:0)<<1,l=dt(f^e|0,c^A|0,f|0,c|0)|0,o=M()|0,e=i^f,A=s^c,dt((ds(l,o,dt(i^r|0,s^n|0,i|0,s|0)|0,M()|0,0)|0)^e|0,(M()|0)^A|0,e|0,A|0)|0}function ba(e,A){e=e|0,A=A|0;var r=0,n=0,s=0,i=0;return i=e&65535,s=A&65535,r=ht(s,i)|0,n=e>>>16,e=(r>>>16)+(ht(s,n)|0)|0,s=A>>>16,A=ht(s,i)|0,WA((e>>>16)+(ht(s,n)|0)+(((e&65535)+A|0)>>>16)|0),e+A<<16|r&65535|0|0}function mt(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0;return s=e,i=r,r=ba(s,i)|0,e=M()|0,WA((ht(A,i)|0)+(ht(n,s)|0)+e|e&0|0),r|0|0|0}function Nn(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0,o=0,l=0,c=0,f=0;return s=S,S=S+16|0,l=s|0,o=A>>31|((A|0)<0?-1:0)<<1,i=((A|0)<0?-1:0)>>31|((A|0)<0?-1:0)<<1,f=n>>31|((n|0)<0?-1:0)<<1,c=((n|0)<0?-1:0)>>31|((n|0)<0?-1:0)<<1,e=dt(o^e|0,i^A|0,o|0,i|0)|0,A=M()|0,ds(e,A,dt(f^r|0,c^n|0,f|0,c|0)|0,M()|0,l)|0,n=dt(t[l>>2]^o|0,t[l+4>>2]^i|0,o|0,i|0)|0,r=M()|0,S=s,WA(r|0),n|0}function Fn(e,A,r,n){e=e|0,A=A|0,r=r|0,n=n|0;var s=0,i=0;return i=S,S=S+16|0,s=i|0,ds(e,A,r,n,s)|0,S=i,WA(t[s+4>>2]|0),t[s>>2]|0|0}function xi(e,A,r){return e=e|0,A=A|0,r=r|0,(r|0)<32?(WA(A>>r|0),e>>>r|(A&(1<>r-32|0)}function wA(e,A,r){return e=e|0,A=A|0,r=r|0,(r|0)<32?(WA(A>>>r|0),e>>>r|(A&(1<>>r-32|0)}function CA(e,A,r){return e=e|0,A=A|0,r=r|0,(r|0)<32?(WA(A<>>32-r|0),e<=0?+Le(e+.5):+Wt(e-.5)}function Pn(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0;if((r|0)>=8192)return fr(e|0,A|0,r|0)|0,e|0;if(i=e|0,s=e+r|0,(e&3)==(A&3)){for(;e&3;){if(!r)return i|0;xA[e>>0]=xA[A>>0]|0,e=e+1|0,A=A+1|0,r=r-1|0}for(r=s&-4|0,n=r-64|0;(e|0)<=(n|0);)t[e>>2]=t[A>>2],t[e+4>>2]=t[A+4>>2],t[e+8>>2]=t[A+8>>2],t[e+12>>2]=t[A+12>>2],t[e+16>>2]=t[A+16>>2],t[e+20>>2]=t[A+20>>2],t[e+24>>2]=t[A+24>>2],t[e+28>>2]=t[A+28>>2],t[e+32>>2]=t[A+32>>2],t[e+36>>2]=t[A+36>>2],t[e+40>>2]=t[A+40>>2],t[e+44>>2]=t[A+44>>2],t[e+48>>2]=t[A+48>>2],t[e+52>>2]=t[A+52>>2],t[e+56>>2]=t[A+56>>2],t[e+60>>2]=t[A+60>>2],e=e+64|0,A=A+64|0;for(;(e|0)<(r|0);)t[e>>2]=t[A>>2],e=e+4|0,A=A+4|0}else for(r=s-4|0;(e|0)<(r|0);)xA[e>>0]=xA[A>>0]|0,xA[e+1>>0]=xA[A+1>>0]|0,xA[e+2>>0]=xA[A+2>>0]|0,xA[e+3>>0]=xA[A+3>>0]|0,e=e+4|0,A=A+4|0;for(;(e|0)<(s|0);)xA[e>>0]=xA[A>>0]|0,e=e+1|0,A=A+1|0;return i|0}function An(e,A,r){e=e|0,A=A|0,r=r|0;var n=0,s=0,i=0,o=0;if(i=e+r|0,A=A&255,(r|0)>=67){for(;e&3;)xA[e>>0]=A,e=e+1|0;for(n=i&-4|0,o=A|A<<8|A<<16|A<<24,s=n-64|0;(e|0)<=(s|0);)t[e>>2]=o,t[e+4>>2]=o,t[e+8>>2]=o,t[e+12>>2]=o,t[e+16>>2]=o,t[e+20>>2]=o,t[e+24>>2]=o,t[e+28>>2]=o,t[e+32>>2]=o,t[e+36>>2]=o,t[e+40>>2]=o,t[e+44>>2]=o,t[e+48>>2]=o,t[e+52>>2]=o,t[e+56>>2]=o,t[e+60>>2]=o,e=e+64|0;for(;(e|0)<(n|0);)t[e>>2]=o,e=e+4|0}for(;(e|0)<(i|0);)xA[e>>0]=A,e=e+1|0;return i-r|0}function vi(e){return e=+e,e>=0?+Le(e+.5):+Wt(e-.5)}function en(e){e=e|0;var A=0,r=0,n=0;return n=xr()|0,r=t[De>>2]|0,A=r+e|0,(e|0)>0&(A|0)<(r|0)|(A|0)<0?(rr(A|0)|0,Ue(12),-1):(A|0)>(n|0)&&!(hr(A|0)|0)?(Ue(12),-1):(t[De>>2]=A,r|0)}return{___divdi3:Xr,___muldi3:mt,___remdi3:Nn,___uremdi3:Fn,_areNeighborCells:ts,_bitshift64Ashr:xi,_bitshift64Lshr:wA,_bitshift64Shl:CA,_calloc:Ht,_cellAreaKm2:Gl,_cellAreaM2:Ul,_cellAreaRads2:us,_cellToBoundary:In,_cellToCenterChild:Xs,_cellToChildPos:Il,_cellToChildren:n0,_cellToChildrenSize:kr,_cellToLatLng:pn,_cellToLocalIj:ql,_cellToParent:It,_cellToVertex:or,_cellToVertexes:pa,_cellsToDirectedEdge:v0,_cellsToLinkedMultiPolygon:vt,_childPosToCell:Ll,_compactCells:El,_constructCell:ye,_destroyLinkedMultiPolygon:ni,_directedEdgeToBoundary:dn,_directedEdgeToCells:Tn,_edgeLengthKm:Wl,_edgeLengthM:Yl,_edgeLengthRads:Vl,_emscripten_replace_memory:dr,_free:ZA,_getBaseCellNumber:re,_getDirectedEdgeDestination:b0,_getDirectedEdgeOrigin:_n,_getHexagonAreaAvgKm2:ti,_getHexagonAreaAvgM2:Ol,_getHexagonEdgeLengthAvgKm:zl,_getHexagonEdgeLengthAvgM:Hl,_getIcosahedronFaces:Ai,_getIndexDigit:ve,_getNumCells:S0,_getPentagons:os,_getRes0Cells:Kn,_getResolution:DA,_greatCircleDistanceKm:i0,_greatCircleDistanceM:Fl,_greatCircleDistanceRads:Nl,_gridDisk:v,_gridDiskDistances:T,_gridDistance:Xl,_gridPathCells:ea,_gridPathCellsSize:Aa,_gridRing:hA,_gridRingUnsafe:TA,_i64Add:$A,_i64Subtract:dt,_isPentagon:Oe,_isResClassIII:Dl,_isValidCell:Ve,_isValidDirectedEdge:t0,_isValidIndex:Rt,_isValidVertex:hi,_latLngToCell:ss,_llvm_ctlz_i64:ms,_llvm_maxnum_f64:wi,_llvm_minnum_f64:B0,_llvm_round_f64:D0,_localIjToCell:Jl,_malloc:Cr,_maxFaceCount:Rl,_maxGridDiskSize:h,_maxPolygonToCellsSize:fe,_maxPolygonToCellsSizeExperimental:na,_memcpy:Pn,_memset:An,_originToDirectedEdges:Rn,_pentagonCount:jl,_polygonToCells:Bt,_polygonToCellsExperimental:ra,_readInt64AsDoubleFromPointer:fa,_res0CellCount:$n,_round:vi,_sbrk:en,_sizeOfCellBoundary:oa,_sizeOfCoordIJ:ca,_sizeOfGeoLoop:la,_sizeOfGeoPolygon:aa,_sizeOfH3Index:sa,_sizeOfLatLng:ia,_sizeOfLinkedGeoPolygon:ua,_uncompactCells:Ml,_uncompactCellsSize:Bl,_vertexToLatLng:ga,establishStackSpace:jr,stackAlloc:mr,stackRestore:Wr,stackSave:Rr}})(an,Ur,fA);u.___divdi3=gA.___divdi3,u.___muldi3=gA.___muldi3,u.___remdi3=gA.___remdi3,u.___uremdi3=gA.___uremdi3,u._areNeighborCells=gA._areNeighborCells,u._bitshift64Ashr=gA._bitshift64Ashr,u._bitshift64Lshr=gA._bitshift64Lshr,u._bitshift64Shl=gA._bitshift64Shl,u._calloc=gA._calloc,u._cellAreaKm2=gA._cellAreaKm2,u._cellAreaM2=gA._cellAreaM2,u._cellAreaRads2=gA._cellAreaRads2,u._cellToBoundary=gA._cellToBoundary,u._cellToCenterChild=gA._cellToCenterChild,u._cellToChildPos=gA._cellToChildPos,u._cellToChildren=gA._cellToChildren,u._cellToChildrenSize=gA._cellToChildrenSize,u._cellToLatLng=gA._cellToLatLng,u._cellToLocalIj=gA._cellToLocalIj,u._cellToParent=gA._cellToParent,u._cellToVertex=gA._cellToVertex,u._cellToVertexes=gA._cellToVertexes,u._cellsToDirectedEdge=gA._cellsToDirectedEdge,u._cellsToLinkedMultiPolygon=gA._cellsToLinkedMultiPolygon,u._childPosToCell=gA._childPosToCell,u._compactCells=gA._compactCells,u._constructCell=gA._constructCell,u._destroyLinkedMultiPolygon=gA._destroyLinkedMultiPolygon,u._directedEdgeToBoundary=gA._directedEdgeToBoundary,u._directedEdgeToCells=gA._directedEdgeToCells,u._edgeLengthKm=gA._edgeLengthKm,u._edgeLengthM=gA._edgeLengthM,u._edgeLengthRads=gA._edgeLengthRads;var yr=u._emscripten_replace_memory=gA._emscripten_replace_memory;u._free=gA._free,u._getBaseCellNumber=gA._getBaseCellNumber,u._getDirectedEdgeDestination=gA._getDirectedEdgeDestination,u._getDirectedEdgeOrigin=gA._getDirectedEdgeOrigin,u._getHexagonAreaAvgKm2=gA._getHexagonAreaAvgKm2,u._getHexagonAreaAvgM2=gA._getHexagonAreaAvgM2,u._getHexagonEdgeLengthAvgKm=gA._getHexagonEdgeLengthAvgKm,u._getHexagonEdgeLengthAvgM=gA._getHexagonEdgeLengthAvgM,u._getIcosahedronFaces=gA._getIcosahedronFaces,u._getIndexDigit=gA._getIndexDigit,u._getNumCells=gA._getNumCells,u._getPentagons=gA._getPentagons,u._getRes0Cells=gA._getRes0Cells,u._getResolution=gA._getResolution,u._greatCircleDistanceKm=gA._greatCircleDistanceKm,u._greatCircleDistanceM=gA._greatCircleDistanceM,u._greatCircleDistanceRads=gA._greatCircleDistanceRads,u._gridDisk=gA._gridDisk,u._gridDiskDistances=gA._gridDiskDistances,u._gridDistance=gA._gridDistance,u._gridPathCells=gA._gridPathCells,u._gridPathCellsSize=gA._gridPathCellsSize,u._gridRing=gA._gridRing,u._gridRingUnsafe=gA._gridRingUnsafe,u._i64Add=gA._i64Add,u._i64Subtract=gA._i64Subtract,u._isPentagon=gA._isPentagon,u._isResClassIII=gA._isResClassIII,u._isValidCell=gA._isValidCell,u._isValidDirectedEdge=gA._isValidDirectedEdge,u._isValidIndex=gA._isValidIndex,u._isValidVertex=gA._isValidVertex,u._latLngToCell=gA._latLngToCell,u._llvm_ctlz_i64=gA._llvm_ctlz_i64,u._llvm_maxnum_f64=gA._llvm_maxnum_f64,u._llvm_minnum_f64=gA._llvm_minnum_f64,u._llvm_round_f64=gA._llvm_round_f64,u._localIjToCell=gA._localIjToCell,u._malloc=gA._malloc,u._maxFaceCount=gA._maxFaceCount,u._maxGridDiskSize=gA._maxGridDiskSize,u._maxPolygonToCellsSize=gA._maxPolygonToCellsSize,u._maxPolygonToCellsSizeExperimental=gA._maxPolygonToCellsSizeExperimental,u._memcpy=gA._memcpy,u._memset=gA._memset,u._originToDirectedEdges=gA._originToDirectedEdges,u._pentagonCount=gA._pentagonCount,u._polygonToCells=gA._polygonToCells,u._polygonToCellsExperimental=gA._polygonToCellsExperimental,u._readInt64AsDoubleFromPointer=gA._readInt64AsDoubleFromPointer,u._res0CellCount=gA._res0CellCount,u._round=gA._round,u._sbrk=gA._sbrk,u._sizeOfCellBoundary=gA._sizeOfCellBoundary,u._sizeOfCoordIJ=gA._sizeOfCoordIJ,u._sizeOfGeoLoop=gA._sizeOfGeoLoop,u._sizeOfGeoPolygon=gA._sizeOfGeoPolygon,u._sizeOfH3Index=gA._sizeOfH3Index,u._sizeOfLatLng=gA._sizeOfLatLng,u._sizeOfLinkedGeoPolygon=gA._sizeOfLinkedGeoPolygon,u._uncompactCells=gA._uncompactCells,u._uncompactCellsSize=gA._uncompactCellsSize,u._vertexToLatLng=gA._vertexToLatLng,u.establishStackSpace=gA.establishStackSpace;var ft=u.stackAlloc=gA.stackAlloc,Fe=u.stackRestore=gA.stackRestore,cr=u.stackSave=gA.stackSave;if(u.asm=gA,u.cwrap=oA,u.setValue=Y,u.getValue=U,Qe){Me(Qe)||(Qe=b(Qe));{it();var qe=function(nA){nA.byteLength&&(nA=new Uint8Array(nA)),LA.set(nA,z),u.memoryInitializerRequest&&delete u.memoryInitializerRequest.response,Et()},kt=function(){E(Qe,qe,function(){throw"could not load memory initializer "+Qe})},Mt=gr(Qe);if(Mt)qe(Mt.buffer);else if(u.memoryInitializerRequest){var tr=function(){var nA=u.memoryInitializerRequest,yA=nA.response;if(nA.status!==200&&nA.status!==0){var RA=gr(u.memoryInitializerRequestURL);if(RA)yA=RA.buffer;else{console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+nA.status+", retrying "+Qe),kt();return}}qe(yA)};u.memoryInitializerRequest.response?setTimeout(tr,0):u.memoryInitializerRequest.addEventListener("load",tr)}else kt()}}var Ct;At=function nA(){Ct||Qt(),Ct||(At=nA)};function Qt(nA){if(Je>0||(Ie(),Je>0))return;function yA(){Ct||(Ct=!0,!q&&(oe(),me(),u.onRuntimeInitialized&&u.onRuntimeInitialized(),we()))}u.setStatus?(u.setStatus("Running..."),setTimeout(function(){setTimeout(function(){u.setStatus("")},1),yA()},1)):yA()}u.run=Qt;function yt(nA){throw u.onAbort&&u.onAbort(nA),nA+="",F(nA),B(nA),q=!0,"abort("+nA+"). Build with -s ASSERTIONS=1 for more info."}if(u.abort=yt,u.preInit)for(typeof u.preInit=="function"&&(u.preInit=[u.preInit]);u.preInit.length>0;)u.preInit.pop()();return Qt(),a})(typeof Ft=="object"?Ft:{}),ne="number",Ae=ne,Un=ne,le=ne,ae=ne,pt=ne,PA=ne,u2=[["sizeOfH3Index",ne],["sizeOfLatLng",ne],["sizeOfCellBoundary",ne],["sizeOfGeoLoop",ne],["sizeOfGeoPolygon",ne],["sizeOfLinkedGeoPolygon",ne],["sizeOfCoordIJ",ne],["readInt64AsDoubleFromPointer",ne],["isValidCell",Un,[le,ae]],["isValidIndex",Un,[le,ae]],["latLngToCell",Ae,[ne,ne,pt,PA]],["cellToLatLng",Ae,[le,ae,PA]],["cellToBoundary",Ae,[le,ae,PA]],["maxGridDiskSize",Ae,[ne,PA]],["gridDisk",Ae,[le,ae,ne,PA]],["gridDiskDistances",Ae,[le,ae,ne,PA,PA]],["gridRing",Ae,[le,ae,ne,PA]],["gridRingUnsafe",Ae,[le,ae,ne,PA]],["maxPolygonToCellsSize",Ae,[PA,pt,ne,PA]],["polygonToCells",Ae,[PA,pt,ne,PA]],["maxPolygonToCellsSizeExperimental",Ae,[PA,pt,ne,PA]],["polygonToCellsExperimental",Ae,[PA,pt,ne,ne,ne,PA]],["cellsToLinkedMultiPolygon",Ae,[PA,ne,PA]],["destroyLinkedMultiPolygon",null,[PA]],["compactCells",Ae,[PA,PA,ne,ne]],["uncompactCells",Ae,[PA,ne,ne,PA,ne,pt]],["uncompactCellsSize",Ae,[PA,ne,ne,pt,PA]],["isPentagon",Un,[le,ae]],["isResClassIII",Un,[le,ae]],["getBaseCellNumber",ne,[le,ae]],["getResolution",ne,[le,ae]],["getIndexDigit",ne,[le,ae,ne]],["constructCell",Ae,[ne,ne,PA,PA]],["maxFaceCount",Ae,[le,ae,PA]],["getIcosahedronFaces",Ae,[le,ae,PA]],["cellToParent",Ae,[le,ae,pt,PA]],["cellToChildren",Ae,[le,ae,pt,PA]],["cellToCenterChild",Ae,[le,ae,pt,PA]],["cellToChildrenSize",Ae,[le,ae,pt,PA]],["cellToChildPos",Ae,[le,ae,pt,PA]],["childPosToCell",Ae,[ne,ne,le,ae,pt,PA]],["areNeighborCells",Ae,[le,ae,le,ae,PA]],["cellsToDirectedEdge",Ae,[le,ae,le,ae,PA]],["getDirectedEdgeOrigin",Ae,[le,ae,PA]],["getDirectedEdgeDestination",Ae,[le,ae,PA]],["isValidDirectedEdge",Un,[le,ae]],["directedEdgeToCells",Ae,[le,ae,PA]],["originToDirectedEdges",Ae,[le,ae,PA]],["directedEdgeToBoundary",Ae,[le,ae,PA]],["gridDistance",Ae,[le,ae,le,ae,PA]],["gridPathCells",Ae,[le,ae,le,ae,PA]],["gridPathCellsSize",Ae,[le,ae,le,ae,PA]],["cellToLocalIj",Ae,[le,ae,le,ae,ne,PA]],["localIjToCell",Ae,[le,ae,PA,ne,PA]],["getHexagonAreaAvgM2",Ae,[pt,PA]],["getHexagonAreaAvgKm2",Ae,[pt,PA]],["getHexagonEdgeLengthAvgM",Ae,[pt,PA]],["getHexagonEdgeLengthAvgKm",Ae,[pt,PA]],["greatCircleDistanceM",ne,[PA,PA]],["greatCircleDistanceKm",ne,[PA,PA]],["greatCircleDistanceRads",ne,[PA,PA]],["cellAreaM2",Ae,[le,ae,PA]],["cellAreaKm2",Ae,[le,ae,PA]],["cellAreaRads2",Ae,[le,ae,PA]],["edgeLengthM",Ae,[le,ae,PA]],["edgeLengthKm",Ae,[le,ae,PA]],["edgeLengthRads",Ae,[le,ae,PA]],["getNumCells",Ae,[pt,PA]],["getRes0Cells",Ae,[PA]],["res0CellCount",ne],["getPentagons",Ae,[ne,PA]],["pentagonCount",ne],["cellToVertex",Ae,[le,ae,ne,PA]],["cellToVertexes",Ae,[le,ae,PA]],["vertexToLatLng",Ae,[le,ae,PA]],["isValidVertex",Un,[le,ae]]],c2=0,f2=1,h2=2,d2=3,m2=4,p2=5,g2=6,y2=7,x2=8,w2=9,v2=10,b2=11,k2=12,C2=13,S2=14,E2=15,M2=16,B2=17,D2=18,_2=19,lt={};lt[c2]="Success";lt[f2]="The operation failed but a more specific error is not available";lt[h2]="Argument was outside of acceptable range";lt[d2]="Latitude or longitude arguments were outside of acceptable range";lt[m2]="Resolution argument was outside of acceptable range";lt[p2]="Cell argument was not valid";lt[g2]="Directed edge argument was not valid";lt[y2]="Undirected edge argument was not valid";lt[x2]="Vertex argument was not valid";lt[w2]="Pentagon distortion was encountered";lt[v2]="Duplicate input";lt[b2]="Cell arguments were not neighbors";lt[k2]="Cell arguments had incompatible resolutions";lt[C2]="Memory allocation failed";lt[S2]="Bounds of provided memory were insufficient";lt[E2]="Mode or flags argument was not valid";lt[M2]="Index argument was not valid";lt[B2]="Base cell number was outside of acceptable range";lt[D2]="Child indexing digits invalid";lt[_2]="Child indexing digits refer to a deleted subsequence";var T2=1e3,R2=1001,yl=1002,es={};es[T2]="Unknown unit";es[R2]="Array length out of bounds";es[yl]="Got unexpected null value for H3 index";var j2="Unknown error";function xl(a,u,d){var y=d&&"value"in d,x=new Error((a[u]||j2)+" (code: "+u+(y?", value: "+d.value:"")+")");return x.code=u,x}function I2(a,u){var d=arguments.length===2?{value:u}:{};return xl(lt,a,d)}function L2(a,u){var d=arguments.length===2?{value:u}:{};return xl(es,a,d)}function wl(a){if(a!==0)throw I2(a)}var Br={};u2.forEach(function(u){Br[u[0]]=Ft.cwrap.apply(Ft,u)});var Wn=16,N2=4,K0=8,Fs=Br.sizeOfH3Index(),F2=Br.sizeOfLatLng(),P2=Br.sizeOfCellBoundary();Br.sizeOfGeoPolygon();Br.sizeOfGeoLoop();Br.sizeOfLinkedGeoPolygon();Br.sizeOfCoordIJ();function Q2(a){if(!a)throw L2(yl);return a}var O2=/[^0-9a-fA-F]/;function z2(a){if(Array.isArray(a)&&a.length===2&&Number.isInteger(a[0])&&Number.isInteger(a[1]))return a;if(typeof a!="string"||O2.test(a))return[0,0];var u=parseInt(a.substring(0,a.length-8),Wn),d=parseInt(a.substring(a.length-8),Wn);return[d,u]}function Xi(a){if(a>=0)return a.toString(Wn);a=a&2147483647;var u=vl(8,a.toString(Wn)),d=(parseInt(u[0],Wn)+8).toString(Wn);return u=d+u.substring(1),u}function H2(a,u){return Xi(u)+vl(8,Xi(a))}function vl(a,u){for(var d=a-u.length,y="",x=0;x.85?.9+(a-.85)/.15*.1:.1+(a-.15)/.7*.8}function Cl(a,u,d,y){const x=d-u;if(x<.001)return eo(y[12]);const b=Math.max(0,Math.min(1,(a-u)/x)),E=e1(b),F=Math.min(23,Math.floor(E*24));return eo(y[F])}function t1(a){const u=new Map;for(const b of a){if(typeof b.lat!="number"||typeof b.lon!="number"||isNaN(b.lat)||isNaN(b.lon))continue;const E=W2(b.lat,b.lon,K2),F=u.get(E),B=b.weight;F?(F.count++,F.qualitySum+=B):u.set(E,{count:1,qualitySum:B})}const d=[];let y=1/0,x=-1/0;for(const[b,E]of u.entries()){const F=E.qualitySum/E.count;d.push({hexId:b,count:E.count,avgQuality:F}),y=Math.min(y,F),x=Math.max(x,F)}return{cells:d,minQuality:d.length>0?y:0,maxQuality:d.length>0?x:0}}function r1(a,u,d,y){const x=[];for(const b of a){const F=bl(b.hexId).map(([k,j])=>[j,k]);F.push(F[0]);const B=Cl(b.avgQuality,u,d,y);x.push({type:"Feature",properties:{color:B,quality:b.avgQuality,count:b.count},geometry:{type:"Polygon",coordinates:[F]}})}return{type:"FeatureCollection",features:x}}async function n1(a,u,d,y,x){const b=[];let E=0;for(;E[Y,z]);j.push(j[0]);const Q=Cl(B.avgQuality,u,d,y);b.push({type:"Feature",properties:{color:Q,quality:B.avgQuality,count:B.count},geometry:{type:"Polygon",coordinates:[j]}})}ErequestAnimationFrame(B))}return{type:"FeatureCollection",features:b}}function s1(a,u){const[d,y]=R.useState(a);return R.useEffect(()=>{const x=setTimeout(()=>y(a),u);return()=>clearTimeout(x)},[a,u]),d}function i1(a,u){const d=[];for(const y of a){if(y.timestampS>u)break;const x=y.msgSnr??y.pathSnr??0,b=Math.max(0,Math.min(1,(x+20)/40));d.push({lat:y.lat,lon:y.lon,successRate:1,weight:b,totalSamples:1,ageDays:0,geohash:"",repeaters:y.pathHops??[]})}return d}function o1({coveragePoints:a,visible:u,terrainEnabled:d=!1,brightness:y=Z2,basemapMode:x="dark",replaySamples:b,replayTimeS:E}){const F=R.useMemo(()=>b&&b.length>0&&E!=null?i1(b,E):a,[b,E,a]),{current:B}=Hr(),[k,j]=R.useState(null);R.useEffect(()=>{const lA=()=>{var bA;const EA=(bA=B==null?void 0:B.getMap)==null?void 0:bA.call(B);EA&&!k&&j(EA)};lA();const aA=setInterval(lA,50),BA=setTimeout(()=>clearInterval(aA),5e3);return()=>{clearInterval(aA),clearTimeout(BA)}},[B,k]);const[Q,z]=R.useState(null),[Y,U]=R.useState(!1),q=R.useRef({aborted:!1}),sA=R.useRef(0),X=R.useRef(x),oA=s1(F,b?100:q2),uA=R.useMemo(()=>A1(x),[x]);R.useEffect(()=>{if(!oA||!Array.isArray(oA)||oA.length===0){queueMicrotask(()=>{z(null),sA.current=0});return}const lA=X.current!==x;if(oA.length===sA.current&&Q&&!lA)return;sA.current=oA.length,X.current=x,q.current.aborted=!0,q.current={aborted:!1};const aA=q.current;U(!0);const{cells:BA,minQuality:EA,maxQuality:bA}=t1(oA);if(BA.length===0){z(null),U(!1);return}if(BA.length{!aA.aborted&&fA&&z(fA)}).finally(()=>{aA.aborted||U(!1)}),()=>{aA.aborted=!0}},[oA,uA]),R.useEffect(()=>{if(!k)return;const lA=()=>{var aA,BA;try{const EA=k.getLayer(vn),bA=k.getSource(wn);if(u&&Q&&Q.features.length>0){if(bA?k.getSource(wn).setData(Q):k.addSource(wn,{type:"geojson",data:Q}),!EA){const fA=k.getLayer("topology-weak-edges-native"),IA=(BA=(aA=k.getStyle())==null?void 0:aA.layers)==null?void 0:BA.find(FA=>FA.type==="symbol"),LA=fA?"topology-weak-edges-native":IA==null?void 0:IA.id;k.addLayer({id:vn,type:"fill",source:wn,paint:{"fill-color":["get","color"],"fill-opacity":y}},LA)}}else EA&&k.removeLayer(vn),bA&&k.removeSource(wn)}catch(EA){console.warn("[WardrivingHexLayerMapLibre] Layer update error:",EA)}};k.isStyleLoaded()?lA():k.once("style.load",lA)},[k,u,Q,d]),R.useEffect(()=>{if(!(!k||!u))try{k.getLayer(vn)&&k.setPaintProperty(vn,"fill-opacity",y)}catch{}},[k,y,u]),R.useEffect(()=>()=>{if(k)try{k.getLayer(vn)&&k.removeLayer(vn),k.getSource(wn)&&k.removeSource(wn)}catch{}},[k]);const kA=(Q==null?void 0:Q.features.length)??0;return kA>0&&u?p.jsx("div",{"data-testid":"wardriving-hexlayer-maplibre-active","data-point-count":(a==null?void 0:a.length)||0,"data-cell-count":kA,"data-terrain-enabled":d,"data-is-processing":Y,style:{display:"none"}}):null}const u0="replay-marker",Q0="replay-marker-circle",c0="replay-trail",O0="replay-trail-line",f0="replay-trace",Cs="replay-trace-line",h0="replay-marker-icon",to=7,l1=2.5,a1=1.5;function u1(){const a=to*2*2,u=document.createElement("canvas");u.width=a,u.height=a;const d=u.getContext("2d");if(!d)return u;const y=a/2,x=a/2,b=to*2-2;return d.beginPath(),d.arc(y,x,b+2,0,Math.PI*2),d.fillStyle="rgba(59, 130, 246, 0.25)",d.fill(),d.beginPath(),d.arc(y,x,b,0,Math.PI*2),d.fillStyle="#3B82F6",d.fill(),d.lineWidth=2,d.strokeStyle="#1E3A5F",d.stroke(),d.beginPath(),d.arc(y,x,3,0,Math.PI*2),d.fillStyle="#FFFFFF",d.fill(),u}const c1={type:"FeatureCollection",features:[]},d0={type:"FeatureCollection",features:[]};function f1({neighbors:a}){const{current:u}=Hr(),d=Zs(),y=R.useRef(null),x=R.useRef(0),b=R.useRef(!1);return R.useEffect(()=>{const E=u==null?void 0:u.getMap();if(!E||!d)return;const F=()=>{if(!b.current){if(!E.hasImage(h0)){const B=u1(),k=B.getContext("2d");if(k){const j=k.getImageData(0,0,B.width,B.height);E.addImage(h0,j,{pixelRatio:2})}}E.getSource(u0)||E.addSource(u0,{type:"geojson",data:c1}),E.getLayer(Q0)||E.addLayer({id:Q0,type:"symbol",source:u0,layout:{"icon-image":h0,"icon-allow-overlap":!0,"icon-ignore-placement":!0}}),E.getSource(c0)||E.addSource(c0,{type:"geojson",data:d0}),E.getLayer(O0)||E.addLayer({id:O0,type:"line",source:c0,paint:{"line-color":"rgba(59, 130, 246, 0.4)","line-width":l1},layout:{"line-cap":"round","line-join":"round"}},Q0),E.getSource(f0)||E.addSource(f0,{type:"geojson",data:d0}),E.getLayer(Cs)||E.addLayer({id:Cs,type:"line",source:f0,paint:{"line-color":"rgba(251, 191, 36, 0.6)","line-width":a1,"line-dasharray":[4,4]},layout:{"line-cap":"round"}},O0),b.current=!0}};return E.isStyleLoaded()?F():E.once("styledata",F),()=>{if(cancelAnimationFrame(x.current),y.current=null,!E.isStyleLoaded()){b.current=!1;return}for(const B of[Q0,O0,Cs])E.getLayer(B)&&E.removeLayer(B);for(const B of[u0,c0,f0])E.getSource(B)&&E.removeSource(B);E.hasImage(h0)&&E.removeImage(h0),b.current=!1}},[u,d]),R.useEffect(()=>{const E=u==null?void 0:u.getMap();if(!E||!d)return;const F=()=>{if(!b.current){x.current=requestAnimationFrame(F);return}const B=Gt.getState();if(!B.isActive)return;const{filteredSamples:k,currentTimeS:j}=B,Q=dl(),z=E.getSource(u0);z&&Q&&z.setData({type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"Point",coordinates:[Q.lon,Q.lat]},properties:{}}]});const Y=E.getSource(c0);if(Y){const q=Vf(k,j);q.length>=2?Y.setData({type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"LineString",coordinates:q},properties:{}}]}):Y.setData(d0)}const U=E.getSource(f0);if(U&&Q){const q=Jf(),sA=(q==null?void 0:q[0])??null;if(sA!==y.current||sA)if(y.current=sA,sA&&a){const X=h1(sA,a);X?U.setData({type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"LineString",coordinates:[[Q.lon,Q.lat],[X.lon,X.lat]]},properties:{}}]}):U.setData(d0)}else U.setData(d0)}x.current=requestAnimationFrame(F)};return x.current=requestAnimationFrame(F),()=>cancelAnimationFrame(x.current)},[u,d,a]),null}function h1(a,u){const d=a.toLowerCase();for(const[y,x]of Object.entries(u))if((y.startsWith("0x")?y.slice(2):y).toLowerCase().startsWith(d)&&x.latitude&&x.longitude&&x.latitude!==0&&x.longitude!==0)return{lat:x.latitude,lon:x.longitude};return null}const ro="https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png",no="terrarium",so=256,io=14,m0={shadowColor:"rgba(10, 10, 10, 0.6)",highlightColor:"rgba(245, 240, 230, 0.4)",accentColor:"rgba(90, 75, 65, 0.3)",illuminationDirection:315,exaggeration:.35},tn="terrain-dem",Vn="hillshade-dem",z0="terrain-hillshade";function d1({enabled:a,exaggeration:u=4}){const{current:d}=Hr(),[y,x]=R.useState(null),b=R.useRef(null);return R.useEffect(()=>{const E=()=>{var j;const k=(j=d==null?void 0:d.getMap)==null?void 0:j.call(d);k&&!y&&x(k)};E();const F=setInterval(E,50),B=setTimeout(()=>clearInterval(F),5e3);return()=>{clearInterval(F),clearTimeout(B)}},[d,y]),R.useEffect(()=>{if(!y)return;let E=!0;const F=()=>{var B,k;if(E)try{if(y.getSource(Vn)||y.addSource(Vn,{type:"raster-dem",tiles:[ro],encoding:no,tileSize:so,maxzoom:io}),!y.getLayer(z0)){const j=(k=(B=y.getStyle())==null?void 0:B.layers)==null?void 0:k.find(Q=>Q.type==="symbol");y.addLayer({id:z0,type:"hillshade",source:Vn,paint:{"hillshade-shadow-color":m0.shadowColor,"hillshade-highlight-color":m0.highlightColor,"hillshade-accent-color":m0.accentColor,"hillshade-illumination-direction":m0.illuminationDirection,"hillshade-exaggeration":m0.exaggeration}},j==null?void 0:j.id)}y.getSource(tn)||y.addSource(tn,{type:"raster-dem",tiles:[ro],encoding:no,tileSize:so,maxzoom:io})}catch(j){console.error("[TerrainLayer] Source/layer setup error:",j)}};return y.isStyleLoaded()?F():(y.once("style.load",F),y.once("load",()=>{E&&!y.getSource(Vn)&&F()})),()=>{E=!1}},[y]),R.useEffect(()=>{if(!y)return;let E=!0,F=!1;const B=()=>{if(!(!E||!y.getSource(tn)))try{a?(y.setCenterClampedToGround(!1),y.setTerrain({source:tn,exaggeration:u}),y.setMaxPitch(70),!F&&y.getPitch()<30&&!y.isMoving()&&(F=!0,b.current!==null&&clearTimeout(b.current),b.current=window.setTimeout(()=>{b.current=null,E&&!y.isMoving()&&y.getPitch()<30&&y.easeTo({pitch:45,duration:1e3})},200))):(y.setTerrain(null),y.setCenterClampedToGround(!0),y.getPitch()>0&&!y.isMoving()&&y.easeTo({pitch:0,duration:800}),y.setMaxPitch(60))}catch(k){console.error("[TerrainLayer] Terrain state error:",k)}};if(y.isStyleLoaded()&&y.getSource(tn))B();else{const k=()=>{y.getSource(tn)&&B()};y.once("idle",k)}return()=>{E=!1,b.current!==null&&(clearTimeout(b.current),b.current=null)}},[y,a,u]),R.useEffect(()=>()=>{var E;try{(E=y==null?void 0:y.getStyle)!=null&&E.call(y)&&y.isStyleLoaded()&&(y.setTerrain(null),y.getLayer(z0)&&y.removeLayer(z0),y.getSource(Vn)&&y.removeSource(Vn),y.getSource(tn)&&y.removeSource(tn))}catch{}},[y]),null}const m1=.03,p1=.1,g1=2,y1=3,x1=.02,w1=3;function v1(a,u=w1){if(a.length<3||u<=0)return a;let d=a;for(let y=0;y0&&x.push([x[0][0],x[0][1]]),d=x}return d}function b1(a,u){let d=1/0,y=-1/0,x=1/0,b=-1/0;for(const[E,F]of a)Ey&&(y=E),Fb&&(b=F);return d-=u,y+=u,x-=u,b+=u,{minX:d,minY:x,maxX:y,maxY:b,width:y-d,height:b-x}}function k1(a,u={}){if(a.length(X-b.minX)/b.width*j,Y=X=>(X-b.minY)/b.height*Q,U=X=>X/j*b.width+b.minX,q=X=>X/Q*b.height+b.minY,sA=d/b.width*j;try{const K=_c().x(EA=>z(EA[0])).y(EA=>Y(EA[1])).size([j,Q]).bandwidth(Math.max(5,sA)).cellSize(x)(a);if(K.length===0)return{coordinates:[],valid:!1};const uA=Math.max(...K.map(EA=>EA.value))*y;let kA=K[0],lA=1/0;for(const EA of K){const bA=Math.abs(EA.value-uA);bA0){const LA=IA[0],FA=IA[IA.length-1];(LA[0]!==FA[0]||LA[1]!==FA[1])&&IA.push([LA[0],LA[1]])}if(IA.length>=4){const LA=v1(IA);bA.push(LA)}}bA.length>0&&aA.push(bA)}const BA=[];for(const EA of aA)for(const bA of EA)BA.push(bA);return{coordinates:aA,valid:aA.length>0}}catch(X){return console.warn("[KDE Contour] Failed to generate contour:",X),{coordinates:[],valid:!1}}}function C1(a,u={}){const d=k1(a,u);return!d.valid||d.coordinates.length===0?null:d.coordinates.length===1?{type:"Polygon",coordinates:d.coordinates[0]}:{type:"MultiPolygon",coordinates:d.coordinates}}const S1="mincut-partition",E1="mincut-partition-fill",M1="mincut-partition-stroke",B1=3,D1=.05,_1=.15,T1=.008,oo=12;function lo(a,u,d){return(u[0]-a[0])*(d[1]-a[1])-(u[1]-a[1])*(d[0]-a[0])}function R1(a){if(a.length<3)return a;const u=[...a].sort((x,b)=>x[0]-b[0]||x[1]-b[1]),d=[];for(const x of u){for(;d.length>=2&&lo(d[d.length-2],d[d.length-1],x)<=0;)d.pop();d.push(x)}const y=[];for(let x=u.length-1;x>=0;x--){const b=u[x];for(;y.length>=2&&lo(y[y.length-2],y[y.length-1],b)<=0;)y.pop();y.push(b)}return d.pop(),y.pop(),d.concat(y)}function j1(a,u){if(a.length<3)return a;let d=0,y=0;for(const[x,b]of a)d+=x,y+=b;return d/=a.length,y/=a.length,a.map(([x,b])=>{const E=x-d,F=b-y,B=Math.sqrt(E*E+F*F);if(B<1e-4)return[x,b];const k=(B+u)/B;return[d+E*k,y+F*k]})}function I1(a,u,d,y,x){const b=x*x,E=b*x;return[.5*(2*u[0]+(-a[0]+d[0])*x+(2*a[0]-5*u[0]+4*d[0]-y[0])*b+(-a[0]+3*u[0]-3*d[0]+y[0])*E),.5*(2*u[1]+(-a[1]+d[1])*x+(2*a[1]-5*u[1]+4*d[1]-y[1])*b+(-a[1]+3*u[1]-3*d[1]+y[1])*E)]}function L1(a){if(a.length<3)return a;const u=[],d=a.length;for(let y=0;ya?F1(a,u,x,b):{type:"FeatureCollection",features:[]},[a,u,x,b]),B=d?y:0,k={"fill-color":["get","color"],"fill-opacity":B},j={"line-color":["get","borderColor"],"line-width":E,"line-opacity":B};return p.jsxs(zr,{id:S1,type:"geojson",data:F,children:[p.jsx(Jt,{id:E1,type:"fill",paint:k}),p.jsx(Jt,{id:M1,type:"line",paint:j})]})}function Q1(){const a=qs(),u=R.useRef(0),d=R.useRef(0);R.useEffect(()=>{if(!a){d.current=0;return}const y=Gt.getState().tick,x=b=>{if(d.current>0){const E=Math.min(b-d.current,100);y(E)}d.current=b,u.current=requestAnimationFrame(x)};return u.current=requestAnimationFrame(x),()=>{cancelAnimationFrame(u.current),d.current=0}},[a])}function O1(a,u=!1,d=!1,y=!1,x=.7,b){const E=jo(b);return y?x>=.75?E.restBright:E.rest:x>=.85?E.rest:(x>=.7,E.restDim)}function ao(a){return[a[1],a[0]]}function z1(a,u,d,y=12){const[x,b]=a,[E,F]=u,B=[];for(let k=0;k<=y;k++){const j=k/y,Q=b+(F-b)*j,z=x+(E-x)*j,Y=4*d*j*(1-j);B.push([Q,z,Y])}return B}function uo(a,u,d,y,x,b,E,F,B,k,j,Q="dark"){const z=Ks(),Y=[];let U=1/0,q=-1/0;const sA=[];for(const K of a){const oA=K.edge.avgConfidence??(u?.7:.5),uA=K.edge.certainCount/Math.max(E,1),kA=oA*.7+uA*.3+(u?.5:0);sA.push({polyline:K,brightnessScore:kA}),U=Math.min(U,kA),q=Math.max(q,kA)}if(sA.length===0)return{type:"FeatureCollection",features:[]};const X=q-U||1;sA.sort((K,oA)=>K.brightnessScore-oA.brightnessScore);for(const{polyline:K,brightnessScore:oA}of sA){const{from:uA,to:kA,edge:lA}=K,aA=d.get(lA.key)??0;if(aA<=0)continue;const BA=F.has(lA.key),EA=B.has(lA.key),bA=lA.avgConfidence??(u?.7:.5),fA=k===lA.key,IA=j[lA.fromHash],LA=j[lA.toHash],FA=(IA==null?void 0:IA.node_name)||(IA==null?void 0:IA.name)||lA.fromHash.slice(0,8),UA=(LA==null?void 0:LA.node_name)||(LA==null?void 0:LA.name)||lA.toHash.slice(0,8),vA=[uA[0]+(kA[0]-uA[0])*aA,uA[1]+(kA[1]-uA[1])*aA];let cA;if(!u)cA=1.5;else{const ue=b.get(lA.key)??Rs(lA.certainCount),JA=x.get(lA.key)??ue;cA=JA+(ue-JA)*y,fA?cA=Math.max(cA*1.6,4.5):EA&&(cA=cA*1.3)}let dA;fA?dA=z.edges.highlight:dA=O1(!1,lA.isDirectPathEdge??!1,BA,EA,bA,Q);let jA;fA?jA=z.edges.highlight:lA.isDirectPathEdge?jA=z.edges.hoverDirect:BA?jA=z.edges.hoverLoop:jA=z.edges.hoverStandard;let _A;if(!u)_A=(.3+bA*.3)*aA;else{const ue=Math.min(aA*1.5,1)*z.edgeOpacity;_A=EA?ue*1.15:ue}fA&&(_A=.95);const YA=(oA-U)/X;Y.push({type:"Feature",properties:{key:lA.key,baseColor:dA,hoverColor:jA,baseWidth:cA,baseOpacity:_A,brightnessScore:YA,isLoopEdge:BA,isBackbone:EA,isDirectPath:lA.isDirectPathEdge??!1,isHubConnection:lA.isHubConnection??!1,isZeroHop:lA.isZeroHop??!1,isValidated:u,certainCount:lA.certainCount,confidence:bA,symmetryRatio:lA.symmetryRatio??1,dominantDirection:lA.dominantDirection??"balanced",fromName:FA,toName:UA,fromHash:lA.fromHash,toHash:lA.toHash},geometry:{type:"LineString",coordinates:[ao(uA),ao(vA)]}})}return{type:"FeatureCollection",features:Y}}const H1=150,G1=8;function co(a,u){const d=Ks(),y=[];let x=0;for(const b of a){const E=u.get(b.hash);E&&E.blendedScore>x&&(x=E.blendedScore)}for(const b of a){const{from:E,to:F,hash:B,neighbor:k,lastHopData:j}=b,Q=`neighbor-${B}`,z=(j==null?void 0:j.avgRssi)??k.rssi??null,Y=(j==null?void 0:j.avgSnr)??k.snr??null,U=(j==null?void 0:j.count)??0,q=(j==null?void 0:j.confidence)??1,sA=u.get(B),X=(sA==null?void 0:sA.listenerScore)??0,K=(sA==null?void 0:sA.loudScore)??0,oA=(sA==null?void 0:sA.blendedScore)??0,uA=x>0?oA/x:0,kA=b.rxAdvertCount??0,lA=b.txProxyCount??0,aA=kA+lA,BA=aA>0?(lA-kA)/aA:0,EA=z1(E,F,H1,G1);y.push({type:"Feature",properties:{key:Q,hash:B,name:k.node_name||k.name||B.slice(0,8),prefix:B.slice(2,4).toUpperCase(),color:d.neighborColor,width:2.5,opacity:.85,rssi:z,snr:Y,packetCount:U,confidence:q,hasAvgRssi:(j==null?void 0:j.avgRssi)!==void 0,hasAvgSnr:(j==null?void 0:j.avgSnr)!==void 0,isNeighborEdge:!0,listenerScore:X,loudScore:K,blendedScore:oA,trafficWeight:uA,linkAsymmetry:BA,rxAdvertCount:kA,txProxyCount:lA},geometry:{type:"LineString",coordinates:EA}})}return{type:"FeatureCollection",features:y}}function U1({map:a,showTopology:u,validatedPolylines:d,weakPolylines:y,maxCertainCount:x,loopEdgeKeys:b,backboneEdgeKeys:E,highlightedEdgeKey:F,neighbors:B,validatedSourceId:k,weakSourceId:j,neighborPolylines:Q=[],showNeighborLines:z=!0,neighborSourceId:Y,neighborLinkScores:U=new Map,basemapMode:q}){const sA=R.useRef(null);R.useEffect(()=>{const oe=a&&"current"in a?a.current:a;sA.current=oe});const X=R.useRef(new Map),K=R.useRef(1),oA=R.useRef(new Map),uA=R.useRef(new Map),kA=R.useRef(!1),lA=R.useRef(null),aA=R.useRef(u),BA=R.useRef(new Set),EA=R.useRef(""),bA=R.useRef(new Map),fA=R.useRef(""),IA=R.useRef(""),LA=R.useRef(""),FA=R.useRef(d),UA=R.useRef(y),vA=R.useRef(x),cA=R.useRef(b),dA=R.useRef(E),jA=R.useRef(F),_A=R.useRef(B),YA=R.useRef(Q),ue=R.useRef(z),JA=R.useRef(U),KA=R.useRef(q);R.useEffect(()=>{FA.current=d,UA.current=y,vA.current=x,cA.current=b,dA.current=E,jA.current=F,_A.current=B,YA.current=Q,ue.current=z,JA.current=U,KA.current=q},[d,y,x,b,E,F,B,Q,z,U,q]);const VA=R.useCallback((oe=!1)=>{var ke,Ee,pe,Ke,Je,At,it,Et,Qe,Xe;const me=sA.current;if(!me)return;const we=me.getSource(k),$e=me.getSource(j),be=me.getSource(Y);if(we){const Me=uo(FA.current,!0,X.current,K.current,oA.current,uA.current,vA.current,cA.current,dA.current,jA.current,_A.current,KA.current),ze=`${Me.features.length}:${((Ee=(ke=Me.features[0])==null?void 0:ke.properties)==null?void 0:Ee.key)??""}:${((Ke=(pe=Me.features[Me.features.length-1])==null?void 0:pe.properties)==null?void 0:Ke.key)??""}:${Array.from(X.current.values()).reduce((ct,Pt)=>ct+Pt,0).toFixed(2)}`;(oe||ze!==fA.current)&&(we.setData(Me),fA.current=ze)}if($e){const Me=uo(UA.current,!1,X.current,K.current,oA.current,uA.current,vA.current,cA.current,dA.current,jA.current,_A.current,KA.current),ze=`${Me.features.length}:${((At=(Je=Me.features[0])==null?void 0:Je.properties)==null?void 0:At.key)??""}:${((Et=(it=Me.features[Me.features.length-1])==null?void 0:it.properties)==null?void 0:Et.key)??""}`;(oe||ze!==IA.current)&&($e.setData(Me),IA.current=ze)}if(be&&YA.current.length>0){const Me=co(YA.current,JA.current),ze=`${Me.features.length}:${((Xe=(Qe=Me.features[0])==null?void 0:Qe.properties)==null?void 0:Xe.hash)??""}`;(oe||ze!==LA.current)&&(be.setData(Me),LA.current=ze)}},[k,j,Y]),je=R.useCallback(()=>{lA.current&&(cancelAnimationFrame(lA.current),lA.current=null),X.current=new Map,K.current=1,oA.current=new Map,uA.current=new Map,kA.current=!1,BA.current=new Set,EA.current="",bA.current=new Map},[]);R.useEffect(()=>{const oe=aA.current,me=u;if(aA.current=u,!!sA.current){if(lA.current&&(cancelAnimationFrame(lA.current),lA.current=null),oe&&!me&&!kA.current){kA.current=!0;const $e=new Map(X.current);let be=null;const ke=Ee=>{be||(be=Ee);const pe=Ee-be,Ke=Math.min(pe/Nc,1),Je=Al(Ke);for(const[At,it]of $e)X.current.set(At,it*(1-Je));VA(!0),Ke<1?lA.current=requestAnimationFrame(ke):(kA.current=!1,X.current=new Map,BA.current=new Set,EA.current="",oA.current=new Map,uA.current=new Map,lA.current=null,VA(!0))};lA.current=requestAnimationFrame(ke)}!oe&&me&&(X.current=new Map,BA.current=new Set,EA.current="")}},[u,VA]),R.useEffect(()=>{const oe=sA.current;if(!u||kA.current||!oe)return;const me=[...d,...y],we=me.map(pe=>`${pe.edge.key}:${pe.edge.certainCount}`).sort().join(","),$e=BA.current.size===0,be=EA.current!==""&&EA.current!==we;if(!$e&&!be){VA();return}const ke=[],Ee=[];for(const{edge:pe}of me)BA.current.has(pe.key)?Ee.push(pe.key):ke.push(pe.key);be&&Ee.length>0&&(oA.current=new Map(bA.current),K.current=0),uA.current=new Map;for(const{edge:pe}of d){const Ke=Rs(pe.certainCount);uA.current.set(pe.key,Ke)}for(const pe of ke)X.current.set(pe,0);for(const pe of Ee)X.current.has(pe)||X.current.set(pe,1);if(ke.length>0||be&&Ee.length>0){lA.current&&(cancelAnimationFrame(lA.current),lA.current=null);let pe=null;const Ke=Math.min(100,R0/Math.max(ke.length,1)/2),Je=At=>{pe||(pe=At);const it=At-pe;for(let Qe=0;Qe0){const Qe=Math.min(it/R0,1);K.current=_s(Qe)}VA(!0);const Et=R0+(ke.length-1)*Ke;it{const oe=sA.current;if(!oe||!Y)return;const me=()=>{const be=oe.getSource(Y);if(!be)return!1;if(Q.length>0){const ke=co(Q,U);be.setData(ke)}else be.setData({type:"FeatureCollection",features:[]});return!0};if(me())return;const we=be=>{be.sourceId===Y&&me()&&oe.off("sourcedata",we)};oe.on("sourcedata",we);const $e=()=>{me()&&(oe.off("styledata",$e),oe.off("sourcedata",we))};return oe.on("styledata",$e),()=>{oe.off("sourcedata",we),oe.off("styledata",$e)}},[Y,Q,U]);const Ie=R.useRef(q);return R.useEffect(()=>{q!==Ie.current&&(Ie.current=q,fA.current="",IA.current="",LA.current="",VA(!0))},[q,VA]),R.useEffect(()=>()=>{lA.current&&(cancelAnimationFrame(lA.current),lA.current=null)},[]),{isExiting:kA.current,isAnimating:lA.current!==null,resetAnimationState:je,weightAnimProgress:K.current,animStartWeights:oA.current,animTargetWeights:uA.current}}function V1({activeFilters:a,neighborHashes:u,hubConnectedNodes:d,directNodeSet:y,localConnectedNodes:x,nodeTypeMap:b,showTopology:E}){const[F,B]=R.useState(new Map),k=R.useMemo(()=>[...a].sort().join(","),[a]),j=R.useRef(k),Q=R.useRef(!1),z=R.useRef(new Map),Y=R.useRef(null),U=R.useRef(d),q=R.useRef(y),sA=R.useRef(x),X=R.useRef(b),K=R.useRef(E);return R.useEffect(()=>{U.current=d,q.current=y,sA.current=x,X.current=b,K.current=E},[d,y,x,b,E]),R.useEffect(()=>{const uA=j.current,kA=k;if(j.current=k,uA===kA)return;Y.current&&(cancelAnimationFrame(Y.current),Y.current=null);const lA=new Set(uA?uA.split(",").filter(Boolean):[]),aA=a,BA=U.current,EA=q.current,bA=X.current;for(const vA of u)z.current.has(vA)||z.current.set(vA,Math.random());const fA=(vA,cA)=>{if(cA.size===0)return!1;const dA=bA.get(vA)??"unknown";return!!(cA.has("repeater")&&dA==="repeater"||cA.has("companion")&&(dA==="companion"||dA==="unknown")||cA.has("room_server")&&dA==="room_server"||cA.has("direct")&&EA.has(vA)||cA.has("hubs")&&BA.has(vA))},IA=[];for(const vA of u){const cA=fA(vA,lA),dA=fA(vA,aA);cA!==dA&&IA.push({hash:vA,startOpacity:cA?1:0,targetOpacity:dA?1:0})}if(IA.length===0)return;Q.current=!0,B(vA=>{const cA=new Map(vA);for(const{hash:dA,startOpacity:jA}of IA)cA.set(dA,jA);return cA});const LA=IA;let FA=null;const UA=vA=>{FA||(FA=vA);const cA=vA-FA;let dA=!0;B(()=>{const _A=new Map;for(const{hash:YA,startOpacity:ue,targetOpacity:JA}of LA){const KA=(z.current.get(YA)??0)*Ii,VA=Math.max(0,cA-KA),je=Math.min(VA/ji,1),Ie=_s(je),oe=ue+(JA-ue)*Ie;_A.set(YA,oe),je<1&&(dA=!1)}return _A});const jA=ji+Ii;cA{Y.current&&(cancelAnimationFrame(Y.current),Y.current=null),Q.current=!1}},[k,a,u]),{nodeOpacities:F,getNodeOpacity:(uA,kA)=>Q.current&&F.has(uA)?F.get(uA):kA?1:0}}const Ss=240,fo=240;function W1(a,u){if(a[u,u]))}function $1(a,u,d){const y=d?Er(d):null,x=[];for(const b of a){if(y&&Uo(b.toUpperCase(),y)){d&&x.push(d);continue}const E=u.get(b.toUpperCase());E&&x.push(E)}return x}function K1({neighbors:a,localHash:u,enabled:d=!0}){const[y,x]=R.useState(new Map),b=js(),E=R.useRef(b);R.useEffect(()=>{E.current=b},[b]);const F=R.useRef(0),B=R.useRef(null),k=R.useRef(new Map),j=R.useRef(new Map);R.useEffect(()=>{j.current=Y1(a)},[a]);const Q=R.useRef(null);return R.useEffect(()=>{const z=()=>{const Y=performance.now(),U=k.current;if(U.size===0){B.current=null,x(new Map);return}const q=new Map,sA=[];for(const[X,{startTime:K,staggerDelay:oA}]of U){const uA=Y-K-oA;if(!(uA<0))if(uA>=j0)sA.push(X);else{const kA=W1(uA,j0);kA>0&&q.set(X,kA)}}for(const X of sA)U.delete(X);x(q),U.size>0&&Q.current?B.current=requestAnimationFrame(Q.current):B.current=null};Q.current=z},[]),R.useEffect(()=>{if(!d)return;const z=E.current;if(z.length===0)return;const Y=F.current,U=z.filter(K=>(K.timestamp??0)>Y);if(Y===0){const K=z.reduce((oA,uA)=>Math.max(oA,uA.timestamp??0),0);F.current=K;return}if(U.length===0)return;const q=U.reduce((K,oA)=>Math.max(K,oA.timestamp??0),0);F.current=q;const sA=performance.now();let X=0;for(const K of U){const oA=Go(K,u);if(!oA||oA.original.length===0)continue;const uA=$1(oA.original,j.current,u);if(uA.length===0)continue;const kA=j0*.5;for(let lA=0;lA()=>{B.current!==null&&(cancelAnimationFrame(B.current),B.current=null)},[]),{blinkingNodes:y,blinkColor:Lc}}const rn="edge-blink-source",Sn="edge-blink-layer",Ps=1e3,Qs=1e3,Es=150,Z1=175,q1=3e4,J1=ar.teal,X1="#8B7BAD",Ah=2.5,eh=1.875,th=.5,Z0="node-markers-layer";function rh(a){if(!a.getLayer(Sn))return;const u=a.getLayer(Z0)?Z0:void 0;try{a.moveLayer(Sn,u)}catch{}}function nh(a,u){const d=new Map;for(const y of Object.keys(a)){const x=Er(y);d.has(x)||d.set(x,y)}if(u){const y=Er(u);d.set(y,u)}return d}function sh(a){return a<0||a>=Ps?0:1-a/Ps}function ih(a){if(a<0||a>=Qs)return 0;const u=a/Qs;return Math.pow(1-u,3)}function H0(a){return[a[1],a[0]]}function oh({map:a,nodeCoordinates:u,packets:d,localHash:y,neighbors:x,meshTopology:b,enabled:E=!0}){const F=R.useRef(null),B=a&&"current"in a?a.current:a;R.useEffect(()=>{F.current=B},[B]);const k=R.useRef(!1),j=R.useRef(null),Q=R.useRef([]),z=R.useRef(0),Y=R.useRef(!1),[U,q]=R.useState(!1),sA=R.useRef(null),X=R.useRef([]),K=R.useRef(new Map),oA=R.useRef(u);R.useEffect(()=>{oA.current=u},[u]),R.useEffect(()=>{K.current=nh(x,y)},[x,y]),R.useEffect(()=>{if(!E){sA.current&&(clearTimeout(sA.current),sA.current=null),X.current=[],j.current!==null&&(cancelAnimationFrame(j.current),j.current=null),Q.current=[];const aA=F.current;if(aA&&k.current){const BA=aA.getSource(rn);BA&&BA.setData({type:"FeatureCollection",features:[]})}Y.current=!1,z.current=0}},[E]),R.useEffect(()=>{const aA=B;if(!aA)return;let BA=null,EA=!1;const bA=()=>{if(!EA&&!k.current)try{aA.getLayer(Sn)&&aA.removeLayer(Sn),aA.getSource(rn)&&aA.removeSource(rn),aA.addSource(rn,{type:"geojson",data:{type:"FeatureCollection",features:[]}});const fA=aA.getLayer(Z0)?Z0:void 0;aA.addLayer({id:Sn,type:"line",source:rn,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["any",["==",["get","isSpeculative"],!0],["==",["get","isSpeculative"],"true"]],X1,J1],"line-width":["case",["any",["==",["get","isSpeculative"],!0],["==",["get","isSpeculative"],"true"]],eh,Ah],"line-opacity":["*",["get","opacityMult"],["interpolate",["linear"],["get","intensity"],0,0,.1,.8,.5,1,1,1]]}},fA),k.current=!0,q(!0),BA&&(clearInterval(BA),BA=null)}catch{}};return aA.isStyleLoaded()&&bA(),aA.once("style.load",()=>{bA()}),k.current||(BA=setInterval(()=>{if(k.current){BA&&clearInterval(BA);return}bA()},100),setTimeout(()=>{BA&&(clearInterval(BA),BA=null)},5e3)),()=>{EA=!0,BA&&clearInterval(BA),j.current!==null&&(cancelAnimationFrame(j.current),j.current=null);const fA=F.current;if(fA&&k.current){try{fA.getLayer(Sn)&&fA.removeLayer(Sn),fA.getSource(rn)&&fA.removeSource(rn)}catch{}k.current=!1,q(!1)}}},[B]);const uA=R.useRef(()=>{});R.useEffect(()=>{uA.current=()=>{const aA=F.current;if(!aA)return;const BA=aA.getSource(rn);if(!BA)return;const EA=performance.now(),bA=Q.current,fA=[],IA=[];for(const LA of bA){const FA=EA-LA.startTime-LA.delay,UA=LA.isSpeculative?Qs:Ps;if(FA0&&fA.push({type:"Feature",properties:{intensity:vA,opacityMult:LA.isSpeculative?th:1,isSpeculative:LA.isSpeculative??!1},geometry:{type:"LineString",coordinates:[LA.fromCoord,LA.toCoord]}})}}BA.setData({type:"FeatureCollection",features:fA}),Q.current=IA,IA.length>0?j.current=requestAnimationFrame(()=>uA.current()):j.current=null}},[]);const kA=R.useCallback(()=>{const aA=F.current;aA&&rh(aA),j.current===null&&(j.current=requestAnimationFrame(()=>uA.current()))},[]),lA=R.useCallback(()=>{if(!F.current||!k.current)return;const BA=X.current;if(X.current=[],sA.current=null,BA.length===0)return;const EA=K.current,bA=oA.current;if(EA.size===0)return;const fA=performance.now();let IA=0,LA=!1;const FA=new Set;for(const UA of BA){const vA=Go(UA,y);if(!vA||vA.original.length<2)continue;const cA=vA.original;let dA=0,jA=null;for(let JA=0;JA0){JA.sort((Ie,oe)=>oe.confidence-Ie.confidence);const KA=Math.max(1,Math.ceil(JA.length*.25)),VA=JA.slice(0,KA),je=IA+dA*Es;for(const{edgeKey:Ie,otherHash:oe}of VA){const me=bA.get(jA),we=bA.get(oe);Q.current.push({edgeKey:Ie,fromCoord:H0(me),toCoord:H0(we),startTime:fA,delay:je,isSpeculative:!0}),FA.add(Ie),LA=!0}}}dA>0&&(IA+=dA*Es*.5)}LA&&kA()},[y,b,kA]);R.useEffect(()=>{const aA=F.current;if(!E||!aA||!U||d.length===0)return;const BA=Date.now(),EA=z.current;if(!Y.current){Y.current=!0;const IA=(BA-q1)/1e3,LA=d.filter(UA=>(UA.timestamp??0)>=IA);let FA=0;for(const UA of d){const vA=UA.timestamp??0;vA>FA&&(FA=vA)}if(z.current=FA,LA.length>0){LA.sort((vA,cA)=>(vA.timestamp??0)-(cA.timestamp??0));const UA=LA.slice(-20);X.current.push(...UA),lA()}return}const bA=d.filter(IA=>(IA.timestamp??0)>EA);if(bA.length===0)return;let fA=0;for(const IA of bA){const LA=IA.timestamp??0;LA>fA&&(fA=LA)}z.current=fA,X.current.push(...bA),sA.current&&clearTimeout(sA.current),sA.current=setTimeout(lA,Z1)},[E,d,lA,U]),R.useEffect(()=>()=>{sA.current&&clearTimeout(sA.current)},[])}var nn={},bn={};/** + * @license React + * react-dom-server-legacy.browser.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 ho;function lh(){if(ho)return bn;ho=1;var a=Vo();function u(h){for(var v="https://reactjs.org/docs/error-decoder.html?invariant="+h,T=1;T