import{j as n,aw as e,ax as r,ay as t,az as a,aA as s,r as o}from"./vendor-react-O8XH9yVn.js";import{c as i}from"./recharts-BU7auunF.js";const l={5:-2.5,6:-5,7:-7.5,8:-10,9:-12.5,10:-15,11:-17.5,12:-20},c={62500:{5:-123,6:-125,7:-127,8:-130,9:-133,10:-136,11:-138,12:-140},125e3:{5:-120,6:-122,7:-124,8:-127,9:-130,10:-133,11:-135,12:-137},25e4:{5:-117,6:-119,7:-121,8:-124,9:-127,10:-130,11:-132,12:-134},5e5:{5:-114,6:-116,7:-118,8:-121,9:-124,10:-127,11:-129,12:-131}};function u(n,e,r){if(null==n||!Number.isFinite(n))return null;if(null==e||!Number.isFinite(e))return null;const{sf:t,bwHz:a}=r,s=function(n){const e=Math.max(5,Math.min(12,Math.round(n)));return l[e]??l[7]}(t),o=function(n,e){let r=62500;r=n>=375e3?5e5:n>=187500?25e4:n>=93750?125e3:62500;const t=c[r];return t[Math.max(5,Math.min(12,Math.round(e)))]??t[7]}(a,t),i=n-s,u=e-o;return{snrMargin:i,rssiMargin:u,worstMargin:Math.min(i,u)}}const d={EXCELLENT:6,GOOD:3,FAIR:0},x={EXCELLENT:10,GOOD:6,FAIR:2},f=["excellent","good","fair","poor","critical"];function g(n,e){return n>=e.EXCELLENT?"excellent":n>=e.GOOD?"good":n>=e.FAIR?"fair":n>=e.FAIR-3?"poor":"critical"}function m(n,e){if(0===e)return n;const r=f.indexOf(n),t=Math.min(r+e,f.length-1);return f[t]}function p(n,e,r,t){const a=(s=g(n.snrMargin,d),o=g(n.rssiMargin,x),f.indexOf(s)>=f.indexOf(o)?s:o);var s,o;const i=m(a,e);return{baseGrade:a,finalGrade:i,snrMargin:n.snrMargin,rssiMargin:n.rssiMargin,worstMargin:n.worstMargin,nfPenalty:e,wasDowngraded:e>0&&i!==a,confidence:r,isMarginBased:t}}function h(n,e,r,t=0){return r&&null!=n?function(n,e,r,t=0){const a=u(n,e,r);return a?p(a,t,"high",!0):null}(n,e,r,t):null!=n&&null!=e?function(n,e,r=0){const t=function(n,e){return u(n,e,{sf:7,bwHz:62500})}(n,e);return t?p(t,r,"low",!0):null}(n,e,t):function(n,e=0){if(null==n||!Number.isFinite(n))return null;const r=function(n){return n>=-90?"excellent":n>=-100?"good":n>=-110?"fair":n>=-120?"poor":"critical"}(n),t=m(r,e);return{baseGrade:r,finalGrade:t,snrMargin:null,rssiMargin:null,worstMargin:null,nfPenalty:e,wasDowngraded:e>0&&t!==r,confidence:"low",isMarginBased:!1}}(e,t)}const w={excellent:"color(display-p3 0.00 1.00 0.00)",good:"color(display-p3 0.55 0.90 0.15)",fair:"color(display-p3 1.00 0.85 0.00)",weak:"color(display-p3 1.00 0.55 0.15)",poor:"color(display-p3 1.00 0.20 0.20)"},M={excellent:"#4ADE80",good:"#A3E635",fair:"#FACC15",weak:"#FB923C",poor:"#EF4444"};function N(n){return n>=-90?"excellent":n>=-100?"good":n>=-110?"fair":n>=-120?"weak":"poor"}function j(n,e){return e?{backgroundColor:M[n],"--p3-color":w[n]}:{backgroundColor:"rgba(255, 255, 255, 0.1)"}}function y(n){return n?"signal-bar-active":""}function b({rssi:o,className:l="w-4 h-4"}){const c=N(o),u=function(n){switch(n){case"excellent":return"text-signal-excellent";case"good":return"text-signal-good";case"fair":return"text-signal-fair";case"weak":return"text-signal-poor";case"poor":return"text-signal-critical";default:return"text-text-muted"}}(c),d=i(u,l);switch(c){case"excellent":return n.jsx(s,{className:d});case"good":return n.jsx(a,{className:d});case"fair":return n.jsx(t,{className:d});case"weak":return n.jsx(r,{className:d});default:return n.jsx(e,{className:d})}}const v=o.memo(function({rssi:e,snr:r,compact:t=!1,showValues:a=!0,radioConfig:s,nfPenalty:o=0}){const l=void 0!==r?function(n,e,r,t=0){const a=h(e,n,r,t);return a?function(n){switch(n){case"excellent":return"excellent";case"good":return"good";case"fair":return"fair";case"poor":return"weak";case"critical":return"poor"}}(a.finalGrade):N(n)}(e,r,s,o):N(e),c={excellent:4,good:3,fair:2,weak:1,poor:0}[l];return t?n.jsxs("div",{className:"flex items-center gap-1.5",children:[a&&n.jsx("span",{className:"text-[10px] font-mono text-text-secondary tabular-nums w-[32px] text-left",children:e}),n.jsx("div",{className:"flex items-end gap-[2px] h-3 w-[14px]",children:Array.from({length:4}).map((e,r)=>n.jsx("div",{className:i("w-[3px] rounded-[1px] transition-colors",y(r<c)),style:{height:(r+1)/4*100+"%",...j(l,r<c)}},r))})]}):n.jsxs("div",{className:"flex items-center gap-2",children:[a&&n.jsxs("div",{className:"flex flex-col items-start w-[52px]",children:[n.jsxs("span",{className:"text-xs font-mono text-text-secondary leading-tight tabular-nums",children:[e," dBm"]}),void 0!==r&&n.jsxs("span",{className:"text-[10px] font-mono text-text-muted leading-tight tabular-nums",children:[r.toFixed(1)," dB"]})]}),n.jsx("div",{className:"flex items-end gap-[2px] h-3.5 w-[14px]",children:Array.from({length:4}).map((e,r)=>n.jsx("div",{className:i("w-[3px] rounded-[1px] transition-colors",y(r<c)),style:{height:(r+1)/4*100+"%",...j(l,r<c)}},r))})]})});function E(n){const e=N(n);return e.charAt(0).toUpperCase()+e.slice(1)}export{v as S,b as a,E as g,h as s};
