const n={5:-2.5,6:-5,7:-7.5,8:-10,9:-12.5,10:-15,11:-17.5,12:-20},r={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 i(i,t,e){if(null==i||!Number.isFinite(i))return null;if(null==t||!Number.isFinite(t))return null;const{sf:a,bwHz:o}=e,u=function(r){const i=Math.max(5,Math.min(12,Math.round(r)));return n[i]??n[7]}(a),l=function(n,i){let t=62500;t=n>=375e3?5e5:n>=187500?25e4:n>=93750?125e3:62500;const e=r[t];return e[Math.max(5,Math.min(12,Math.round(i)))]??e[7]}(o,a),s=i-u,c=t-l;return{snrMargin:s,rssiMargin:c,worstMargin:Math.min(s,c)}}const t={EXCELLENT:6,GOOD:3,FAIR:0},e={EXCELLENT:10,GOOD:6,FAIR:2},a=["excellent","good","fair","poor","critical"];function o(n,r){return n>=r.EXCELLENT?"excellent":n>=r.GOOD?"good":n>=r.FAIR?"fair":n>=r.FAIR-3?"poor":"critical"}function u(n,r){if(0===r)return n;const i=a.indexOf(n),t=Math.min(i+r,a.length-1);return a[t]}function l(n,r,i,l){const s=(c=o(n.snrMargin,t),f=o(n.rssiMargin,e),a.indexOf(c)>=a.indexOf(f)?c:f);var c,f;const M=u(s,r);return{baseGrade:s,finalGrade:M,snrMargin:n.snrMargin,rssiMargin:n.rssiMargin,worstMargin:n.worstMargin,nfPenalty:r,wasDowngraded:r>0&&M!==s,confidence:i,isMarginBased:l}}function s(n,r,t,e=0){return t&&null!=n?function(n,r,t,e=0){const a=i(n,r,t);return a?l(a,e,"high",!0):null}(n,r,t,e):null!=n&&null!=r?function(n,r,t=0){const e=function(n,r){return i(n,r,{sf:7,bwHz:62500})}(n,r);return e?l(e,t,"low",!0):null}(n,r,e):function(n,r=0){if(null==n||!Number.isFinite(n))return null;const i=function(n){return n>=-90?"excellent":n>=-100?"good":n>=-110?"fair":n>=-120?"poor":"critical"}(n),t=u(i,r);return{baseGrade:i,finalGrade:t,snrMargin:null,rssiMargin:null,worstMargin:null,nfPenalty:r,wasDowngraded:r>0&&t!==i,confidence:"low",isMarginBased:!1}}(r,e)}export{s};
