-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhome-assistant-flightradar24-card.js
More file actions
1420 lines (1404 loc) · 141 KB
/
Copy pathhome-assistant-flightradar24-card.js
File metadata and controls
1420 lines (1404 loc) · 141 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(){var tt=Object.defineProperty,U=(t,e)=>()=>(t&&(e=t(t=0)),e),gt=(t,e)=>{let a={};for(var i in t)tt(a,i,{get:t[i],enumerable:!0});return e||tt(a,Symbol.toStringTag,{value:"Module"}),a};function mt(t,e){const a=e.querySelector("style[data-fr24-style]");a&&a.remove();const i=t.radar,o=i["background-color"]||i["primary-color"]||"var(--dark-primary-color)",r=i["aircraft-color"]||i["accent-color"]||"var(--accent-color)",n=i["aircraft-selected-color"]||i["aircraft-color"]||i["accent-color"]||"var(--accent-color)",d=i["radar-grid-color"]||i["feature-color"]||"var(--secondary-text-color)",s=i["local-features-color"]||i["feature-color"]||i["radar-grid-color"]||"var(--secondary-text-color)",f=i["callsign-label-color"]||"var(--primary-background-color)",b=i["background-opacity"]!==void 0?Math.max(0,Math.min(1,i["background-opacity"])):.05,_=i.radar_size!==void 0?Math.max(30,Math.min(90,i.radar_size)):70,v=(100-_)/2,y=t.config.scale!==void 0?Math.max(.5,Math.min(3,t.config.scale)):1,C=document.createElement("style");C.setAttribute("data-fr24-style","1"),C.textContent=`
:host {
--radar-background-color: ${o};
--radar-aircraft-color: ${r};
--radar-aircraft-selected-color: ${n};
--radar-grid-color: ${d};
--radar-local-features-color: ${s};
--radar-callsign-label-color: ${f};
}
#flights-card {
padding: 16px;
transform: scale(${y});
transform-origin: top center;
}
#flights {
padding: 0px;
}
#flights .flight {
margin-top: 16px;
margin-bottom: 16px;
}
#flights .flight.first {
margin-top: 0px;
}
#flights .flight.selected {
margin-left: -3px;
margin-right: -3px;
padding: 3px;
background-color: var(--primary-background-color);
border: 1px solid var(--fc-border-color);
border-radius: 4px;
}
#flights .flight {
margin-top: 16px;
margin-bottom: 16px;
}
#flights > :first-child {
margin-top: 0px;
}
#flights > :last-child {
margin-bottom: 0px;
}
#flights .flight a {
text-decoration: none;
font-size: 0.8em;
margin-left: 0.2em;
}
#flights .description {
flex-grow: 1;
}
#flights .no-flights-message {
text-align: center;
font-size: 1.2em;
color: gray;
margin-top: 20px;
}
#radar-container {
display: flex;
justify-content: space-between;
}
#radar-overlay {
position: absolute;
width: ${_}%;
left: ${v}%;
padding: 0 0 ${_}% 0;
margin-bottom: 5%;
z-index: 1;
opacity: 0;
pointer-events: auto;
border-radius: 50%;
overflow: hidden;
}
#radar-info {
position: absolute;
width: 30%;
text-align: left;
font-size: 0.9em;
padding: 0;
margin: 0;
}
#toggle-container {
position: absolute;
right: 0;
width: 25%;
text-align: left;
font-size: 0.9em;
padding: 0;
margin: 0 15px;
}
.toggle {
display: flex;
align-items: center;
margin-bottom: 5px;
}
.toggle label {
margin-right: 10px;
flex: 1;
}
#radar {
position: relative;
width: ${_}%;
height: 0;
margin: 0 ${v}%;
padding-bottom: ${_}%;
margin-bottom: 5%;
border-radius: 50%;
overflow: hidden;
}
#radar-screen {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
padding: 0%;
}
#radar-screen-background {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
padding: 0%;
background-color: var(--radar-background-color);
opacity: ${b};
}
#tracker {
position: absolute;
width: 3px;
height: 3px;
background-color: var(--info-color);
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.plane {
position: absolute;
translate: -50% -50%;
z-index: 2;
--marker-base-scale: 1.0;
--selected-scale: 1.0;
scale: calc(var(--marker-base-scale) * var(--selected-scale));
}
.plane.marker-size-small { --marker-base-scale: 0.7; }
.plane.marker-size-large { --marker-base-scale: 1.4; }
.plane.marker-size-x-large { --marker-base-scale: 2.0; }
.plane.marker-size-xx-large { --marker-base-scale: 2.8; }
.plane.plane-small {
width: 4px;
height: 6px;
}
.plane.plane-medium {
width: 6px;
height: 8px;
}
.plane.plane-large {
width: 8px;
height: 16px;
}
.plane .arrow {
position: absolute;
width: 0;
height: 0;
transform-origin: center center;
}
.plane.plane-small .arrow {
border-left: 2px solid transparent;
border-right: 2px solid transparent;
border-bottom: 6px solid var(--radar-aircraft-color);
}
.plane.plane-medium .arrow {
border-left: 3px solid transparent;
border-right: 3px solid transparent;
border-bottom: 8px solid var(--radar-aircraft-color);
}
.plane.plane-large .arrow {
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 16px solid var(--radar-aircraft-color);
}
.plane.selected {
z-index: 3;
--selected-scale: 1.2;
}
.plane.selected .arrow {
border-bottom-color: var(--radar-aircraft-selected-color);
}
.callsign-label {
position: absolute;
background-color: var(--radar-callsign-label-color);
opacity: 0.7;
border: 1px solid lightgray;
line-height: 1em;
padding: 0px;
margin: 0px;
border-radius: 3px;
font-size: 9px;
color: var(--primary-text-color);
z-index: 2;
}
.ring {
position: absolute;
border: 1px dashed var(--radar-grid-color);
border-radius: 50%;
pointer-events: none;
}
.dotted-line {
position: absolute;
top: 50%;
left: 50%;
border-bottom: 1px dotted var(--radar-grid-color);
width: 50%;
height: 0px;
transform-origin: 0 0;
pointer-events: none;
}
.runway {
position: absolute;
background-color: var(--radar-local-features-color);
height: 2px;
}
.location-dot {
position: absolute;
width: 4px;
height: 4px;
background-color: var(--radar-local-features-color);
border-radius: 50%;
}
.location-label {
position: absolute;
background: none;
line-height: 0;
border: none;
padding: 0px;
font-size: 10px;
color: var(--radar-local-features-color);
opacity: 0.5;
}
.outline-line {
position: absolute;
background-color: var(--radar-local-features-color);
opacity: 0.35;
}
`,e.appendChild(C)}function _t(t,e){if(!e)return;e.innerHTML="";const a=t.config.toggles||{},i=!!window.customElements&&!!customElements.get("ha-switch");Object.keys(a).forEach(o=>{const r=a[o],n=document.createElement("div");n.className="toggle";const d=document.createElement("label");d.textContent=r.label||o,n.appendChild(d);let s;i?s=document.createElement("ha-switch"):(s=document.createElement("input"),s.type="checkbox"),s.checked=r.default===!0,s.addEventListener("change",()=>{t.setToggleValue&&t.setToggleValue(o,s.checked)}),n.appendChild(s),e.appendChild(n)})}function O(t){return t*(Math.PI/180)}function W(t){return t*(180/Math.PI)}function z(t,e,a,i,o="km"){const n=O(a-t),d=O(i-e),s=Math.sin(n/2)*Math.sin(n/2)+Math.cos(O(t))*Math.cos(O(a))*Math.sin(d/2)*Math.sin(d/2),f=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s));return o==="km"?6371*f:6371*f/1.60934}function q(t,e,a,i){const o=O(i-e),r=Math.sin(o)*Math.cos(O(a)),n=Math.cos(O(t))*Math.sin(O(a))-Math.sin(O(t))*Math.cos(O(a))*Math.cos(o);return(W(Math.atan2(r,n))+360)%360}function G(t,e,a,i){const r=O(a),n=O(t),d=O(e),s=i/6371,f=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r)),b=d+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(f));return{lat:W(f),lon:W(b)}}function vt(t,e,a,i,o){const r=q(a,i,t,e),n=Math.abs((o-r+360)%360);return G(a,i,o,z(t,e,a,i)*Math.cos(O(n)))}function bt(t){return["N","NE","E","SE","S","SW","W","NW"][Math.round(t/45)%8]}function et(t,e,a=60){const i=Math.abs((t-e+360)%360);return i<=a||i>=360-a}function K(t){if(!t||!t.config)return console.error("Config not set in getLocation"),{latitude:0,longitude:0};const{config:e,hass:a}=t;if(e.location_tracker&&a&&a.states&&e.location_tracker in a.states){const i=a.states[e.location_tracker].attributes;return{latitude:i.latitude,longitude:i.longitude}}else{if(e.location)return{latitude:e.location.lat,longitude:e.location.lon};if(a&&a.config)return{latitude:a.config.latitude,longitude:a.config.longitude}}return{latitude:0,longitude:0}}var yt=new Set(["bw","light","color","dark","voyager","satellite","topo","outlines","system"]);function at(t){const e=t?.radar;return!(!e||e.hide===!0||!e.background_map||!yt.has(e.background_map))}function xt(t,e,a){if(at(t)){if(window.L){a();return}if(!e.querySelector("#leaflet-css-loader")){const i=document.createElement("link");i.id="leaflet-css-loader",i.rel="stylesheet",i.href="https://unpkg.com/leaflet/dist/leaflet.css",e.appendChild(i)}if(e.querySelector("#leaflet-js-loader")){const i=setInterval(()=>{window.L&&(clearInterval(i),a())},50)}else{const i=document.createElement("script");i.id="leaflet-js-loader",i.src="https://unpkg.com/leaflet/dist/leaflet.js",i.async=!0,i.defer=!0,i.onload=a,i.onerror=()=>i.remove(),e.appendChild(i)}}}function wt(t,e){const{config:a,dimensions:i}=t;if(!at(t)){t._leafletMap&&(t._leafletMap.remove(),t._leafletMap=null);const w=e.querySelector("#radar-map-bg");w&&w.remove();return}const o=a?.radar?.background_map,r={bw:["https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}.png",{api_key:"?api_key=",attribution:"Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap",subdomains:[]}],light:["https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",{attribution:"© CartoDB, © OpenStreetMap contributors",subdomains:["a","b","c","d"]}],color:["https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:"© OpenStreetMap contributors",subdomains:["a","b","c"]}],dark:["https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",{attribution:"© CartoDB, © OpenStreetMap contributors",subdomains:["a","b","c","d"]}],voyager:["https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png",{attribution:"© CartoDB, © OpenStreetMap contributors",subdomains:["a","b","c","d"]}],satellite:["https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",{attribution:"© Esri, Maxar, Earthstar Geographics",subdomains:[]}],topo:["https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png",{attribution:"© OpenTopoMap, © OpenStreetMap contributors",subdomains:["a","b","c"]}],outlines:["https://tiles.stadiamaps.com/tiles/stamen_toner_lines/{z}/{x}/{y}.png",{api_key:"?api_key=",attribution:"Map tiles by Stamen Design, hosted by Stadia Maps; Data by OpenStreetMap",subdomains:[]}],system:null},n=typeof a?.radar?.background_map_opacity=="number"?Math.max(0,Math.min(1,a.radar.background_map_opacity)):1;let d=e.querySelector("#radar-map-bg");d?d.style.opacity=String(n):(d=document.createElement("div"),d.id="radar-map-bg",d.style.position="absolute",d.style.top="0",d.style.left="0",d.style.width="100%",d.style.height="100%",d.style.zIndex="0",d.style.pointerEvents="none",d.style.opacity=String(n),e.appendChild(d)),d.style.transform="",t._leafletMap&&t._leafletMap.getContainer()!==d&&(t._leafletMap.remove(),t._leafletMap=null);const s=K(t),f=Math.max(i?.range||1,1),b=t.units?.distance==="miles"?f*1.60934:f,_=s?.latitude||0,v=s?.longitude||0,y=Math.PI/180,C=111.13209-.56605*Math.cos(2*_*y)+.0012*Math.cos(4*_*y),M=111.32*Math.cos(_*y)-.094*Math.cos(3*_*y),u=b/C,h=b/M,c=[[_-u,v-h],[_+u,v+h]];let g=o;if(o==="system"){const w=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches;let $=!1;try{$=!!(window.parent&&window.parent.document&&window.parent.document.body.classList.contains("dark"))}catch{}$||w?g="dark":g="color"}const m=r[g||"bw"]||r.bw;if(!m)return d;let[l,p]=m;const x=p&&"api_key"in p,k=a?.radar?.background_map_api_key&&a.radar.background_map_api_key.trim().length>0;if(x&&!k)return t._leafletMap&&(t._leafletMap.remove(),t._leafletMap=null),d.innerHTML='<div style="display: flex; align-items: center; justify-content: center; height: 100%; color: var(--secondary-text-color); text-align: center; padding: 20px; font-size: 0.9em;">API key required for this map type. Configure in Background Map settings.</div>',d;if(t._leafletMap||(d.innerHTML=""),x&&k&&a?.radar?.background_map_api_key&&(l=l+p.api_key+encodeURIComponent(a.radar.background_map_api_key)),window.L){const w={type:g||"bw",apiKey:a?.radar?.background_map_api_key},$=!t._currentMapConfig||t._currentMapConfig.type!==w.type||t._currentMapConfig.apiKey!==w.apiKey;t._leafletMap?$&&(t._leafletMap.eachLayer(A=>{t._leafletMap.removeLayer(A)}),window.L.tileLayer(l,p).addTo(t._leafletMap),t._currentMapConfig=w):(t._leafletMap=window.L.map(d,{attributionControl:!1,zoomControl:!1,dragging:!1,scrollWheelZoom:!1,boxZoom:!1,doubleClickZoom:!1,keyboard:!1,touchZoom:!1,pointerEvents:!1}),window.L.tileLayer(l,p).addTo(t._leafletMap),t._currentMapConfig=w),t._leafletMap.fitBounds(c,{animate:!1,padding:[0,0]}),requestAnimationFrame(()=>{if(!t._leafletMap)return;const A=t._leafletMap.getContainer(),L=A.offsetHeight,S=A.offsetWidth;if(L===0||S===0)return;const F=window.L.point(0,L/2),E=window.L.point(S,L/2),R=t._leafletMap.containerPointToLatLng(F),P=t._leafletMap.containerPointToLatLng(E),T=z(R.lat,R.lng,P.lat,P.lng,"km")/(b*2);Math.abs(T-1)>.01?d.style.transform=`scale(${T})`:d.style.transform=""})}return d}function it(t={},e,a=[]){if(a.includes(e))return console.error("Circular template dependencies detected. "+a.join(" -> ")+" -> "+e),"";if(t["compiled_"+e])return t["compiled_"+e];let i=t[e];if(i===void 0)return console.error("Missing template reference: "+e),"";const o=/tpl\.([a-zA-Z_$][a-zA-Z0-9_$]*)/g;let r;const n={};for(;(r=o.exec(i))!==null;){const d=r[1];n[d]||(n[d]=it(t,d,[...a,e])),i=i.replace(`tpl.${d}`,"(`"+n[d]+'`).replace(/^undefined$/, "")')}return t["compiled_"+e]=i,i}function Y(t,e,a,i){const o=t.templates||{},r=t.flightsContext||{},n=t.units||{distance:"km",altitude:"ft",speed:"kts"},d=t.radar||{range:35},s=it(o,e);try{const f=new Function("flights","flight","tpl","units","radar_range","joinList",`return \`${s.replace(/\${(.*?)}/g,(b,_)=>`\${${_}}`)}\``)(r,a,{},n,Math.round(d.range),i);return f!=="undefined"?f:""}catch(f){return console.error("Error when rendering: "+s,f),""}}function J(t,e,a,i){const{defines:o={},config:r={},radar:n={range:35},selectedFlights:d=[]}=t;if(typeof e=="string"&&e.startsWith("${")&&e.endsWith("}")){const s=e.slice(2,-1);if(s==="selectedFlights")return d;if(s==="radar_range")return i&&i(!0),n.range;if(s in o)return o[s];if(r.toggles&&s in r.toggles)return r.toggles[s].default;if(a!==void 0)return a;console.error("Unresolved placeholder: "+s),console.debug("Defines",o)}return e}function X(t){const{units:e,radar:a,dom:i,dimensions:o,hass:r}=t,n=i?.radarInfoDisplay||i&&i.radarContainer?.querySelector("#radar-info");n&&(n.innerHTML=[a?.hide_range!==!0?Y(t,"radar_range",null,void 0):""].filter(m=>m).join("<br />"));const d=i?.radarScreen||i&&i.radarContainer?.querySelector("#radar-screen")||t.mainCard?.shadowRoot&&t.mainCard.shadowRoot.getElementById("radar-screen");if(!d)return;Array.from(d.childNodes).forEach(m=>{const l=m;l.id!=="radar-map-bg"&&l.id!=="radar-screen-background"&&d.removeChild(m)});let s=d.querySelector("#radar-screen-background");s||(s=document.createElement("div"),s.id="radar-screen-background",d.appendChild(s)),wt(t,d);const{width:f,height:b,range:_,scaleFactor:v,centerX:y,centerY:C}=o||{};if(!f||!b||!_||!v||y==null||C==null)return;const M=_*1.15,u=a?.ring_distance??10,h=Math.floor(_/u);for(let m=1;m<=h;m++){const l=m*u*v,p=document.createElement("div");p.className="ring",p.style.width=p.style.height=l*2+"px",p.style.top=Math.floor(C-l)+"px",p.style.left=Math.floor(y-l)+"px",d.appendChild(p)}for(let m=0;m<360;m+=45){const l=document.createElement("div");l.className="dotted-line",l.style.transform=`rotate(${m-90}deg)`,d.appendChild(l)}const c=K(t),g=a?.local_features;if(g&&r&&c){const m=c.latitude,l=c.longitude;g.forEach(p=>{if(!(p.max_range&&a.range&&p.max_range<=a.range)){if(p.type==="outline"&&p.points&&p.points.length>1)for(let x=0;x<p.points.length-1;x++){const k=p.points[x],w=p.points[x+1],$=z(m,l,k.lat,k.lon,e.distance),A=z(m,l,w.lat,w.lon,e.distance);if($<=M||A<=M){const L=q(m,l,k.lat,k.lon),S=q(m,l,w.lat,w.lon),F=y+Math.cos((L-90)*Math.PI/180)*$*v,E=C+Math.sin((L-90)*Math.PI/180)*$*v,R=y+Math.cos((S-90)*Math.PI/180)*A*v,P=C+Math.sin((S-90)*Math.PI/180)*A*v,T=document.createElement("div");T.className="outline-line",T.style.width=Math.hypot(R-F,P-E)+"px",T.style.height="1px",T.style.top=E+"px",T.style.left=F+"px",T.style.transformOrigin="0 0",T.style.transform=`rotate(${Math.atan2(P-E,R-F)*(180/Math.PI)}deg)`,d.appendChild(T)}}else if("position"in p&&p.position){const{lat:x,lon:k}=p.position,w=z(m,l,x,k,e.distance);if(w<=M){const $=q(m,l,x,k),A=y+Math.cos(($-90)*Math.PI/180)*w*v,L=C+Math.sin(($-90)*Math.PI/180)*w*v;if(p.type==="runway"){const S=p.heading??0,F=p.length??0,E=e.distance==="km"?F*3048e-7:F*18939e-8,R=document.createElement("div");R.className="runway",R.style.width=E*v+"px",R.style.height="1px",R.style.top=L+"px",R.style.left=A+"px",R.style.transformOrigin="0 50%",R.style.transform=`rotate(${S-90}deg)`,d.appendChild(R)}if(p.type==="location"){const S=document.createElement("div");S.className="location-dot";const F=p.label;if(S.title=F??"Location",S.style.top=L+"px",S.style.left=A+"px",d.appendChild(S),F){const E=document.createElement("div");E.className="location-label",E.textContent=F||"Location",d.appendChild(E);const R=E.getBoundingClientRect(),P=R.width,T=R.height;E.style.top=L-T-4+"px",E.style.left=A-P/2+"px"}}}}}})}}function nt(t,e){let a=null,i=null;function o(f){const b=f[0],_=f[1],v=b.clientX-_.clientX,y=b.clientY-_.clientY;return Math.sqrt(v*v+y*y)}function r(f){f.preventDefault();const b=Math.sign(f.deltaY);t.radar.range+=b*2;const _=t.radar.min_range||1,v=t.radar.max_range||Math.max(100,t.radar.initialRange||35);t.radar.range<_&&(t.radar.range=_),t.radar.range>v&&(t.radar.range=v),t.mainCard.updateRadarRange(b*2)}function n(f){f.touches.length===2&&(a=o(f.touches),i=t.radar.range)}function d(f){if(f.touches.length===2&&a!==null&&i!==null){f.preventDefault();const b=o(f.touches),_=a/b,v=t.radar.min_range||1,y=t.radar.max_range||Math.max(100,t.radar.initialRange||35);let C=Math.round(i*_);C<v&&(C=v),C>y&&(C=y),t.radar.range=C,t.mainCard.updateRadarRange(0)}}function s(){a!==null&&(a=null,i=null,t.config.updateRangeFilterOnTouchEnd&&t.renderDynamicOnRangeChange&&t.mainCard.renderDynamic())}return e&&(e.addEventListener("wheel",r,{passive:!1}),e.addEventListener("touchstart",n,{passive:!0}),e.addEventListener("touchmove",d,{passive:!1}),e.addEventListener("touchend",s,{passive:!0})),()=>{e&&(e.removeEventListener("wheel",r),e.removeEventListener("touchstart",n),e.removeEventListener("touchmove",d),e.removeEventListener("touchend",s))}}function Ct(t,e){e.shadowRoot.innerHTML="";const a=document.createElement("ha-card");if(a.id="flights-card",!t.radar?.hide){const o=document.createElement("div");o.id="radar-container";const r=document.createElement("div");r.id="radar-overlay",o.appendChild(r);const n=document.createElement("div");n.id="radar-info",o.appendChild(n);const d=document.createElement("div");d.id="toggle-container",o.appendChild(d);const s=document.createElement("div");s.id="radar";const f=document.createElement("div");f.id="radar-screen",s.appendChild(f);const b=document.createElement("div");b.id="tracker",s.appendChild(b);const _=document.createElement("div");_.id="planes",s.appendChild(_),o.appendChild(s),a.appendChild(o),requestAnimationFrame(()=>{X(t),e.observeRadarResize(),nt(t,r)}),t.dom=t.dom||{},t.dom.toggleContainer=d,t.dom.planesContainer=_,t.dom.radar=s,t.dom.radarScreen=f,t.dom.radarInfoDisplay=n,t.dom.shadowRoot=e.shadowRoot,t.mainCard=e}const i=document.createElement("div");i.id="flights",t.list&&t.list.hide===!0&&(i.style.display="none"),a.appendChild(i),e.shadowRoot.appendChild(a),mt(t,e.shadowRoot),t.dom?.toggleContainer&&_t(t,t.dom.toggleContainer)}function ot(t,e){return(t.flights||[]).filter(a=>rt(t,a,e))}function rt(t,e,a){return Array.isArray(a)?a.every(i=>B(t,e,i)):B(t,e,a)}function B(t,e,a){let i=!0;if(a.type==="AND"&&a.conditions)i=a.conditions.every(o=>B(t,e,o));else if(a.type==="OR"&&a.conditions)i=a.conditions.some(o=>B(t,e,o));else if(a.type==="NOT"&&a.condition)i=!B(t,e,a.condition);else{const{field:o,defined:r,defaultValue:n,comparator:d}=a,s=J(t,a.value),f=o?e[o]:r?J(t,"${"+r+"}",n):void 0;switch(d){case"eq":i=f===s;break;case"lt":i=Number(f)<Number(s);break;case"lte":i=Number(f)<=Number(s);break;case"gt":i=Number(f)>Number(s);break;case"gte":i=Number(f)>=Number(s);break;case"oneOf":i=(Array.isArray(s)?s:typeof s=="string"?s.split(",").map(b=>b.trim()):[]).includes(f);break;case"containsOneOf":{const b=Array.isArray(s)?s:typeof s=="string"?s.split(",").map(_=>_.trim()):[];i=!!f&&b.some(_=>f.includes(_));break}default:i=!1}}return a.debugIf===i&&console.debug("applyCondition",a,e,i),i}function Z(t){const{flights:e,radar:a,selectedFlights:i,dimensions:o,dom:r}=t;let n;a&&a.filter===!0?n=t.flightsFiltered||e:a&&a.filter&&typeof a.filter=="object"?n=ot(t,a.filter):n=e;const d=r?.planesContainer||t.mainCard?.shadowRoot&&t.mainCard.shadowRoot.getElementById("planes");if(!d)return;d.innerHTML="";const{range:s,scaleFactor:f,centerX:b,centerY:_}=o;if(!s||!f||b===void 0||_===void 0)return;const v=s*1.15;n.slice().reverse().forEach(y=>{const C=y.distance_to_tracker;if(C!==void 0&&C<=v){const M=document.createElement("div");M.className="plane";const u=y.heading_from_tracker??0,h=b+Math.cos((u-90)*Math.PI/180)*C*f,c=_+Math.sin((u-90)*Math.PI/180)*C*f;M.style.top=c+"px",M.style.left=h+"px";const g=document.createElement("div");g.className="arrow",g.style.transform=`rotate(${y.heading}deg)`,M.appendChild(g);const m=document.createElement("div");m.className="callsign-label",m.textContent=y.callsign??y.aircraft_registration??"n/a",d.appendChild(m);const l=m.getBoundingClientRect(),p=l.width+3,x=l.height+6;m.style.top=c-x+"px",m.style.left=h-p+"px",(y.altitude??0)<=0?M.classList.add("plane-small"):M.classList.add("plane-medium");const k=a["aircraft-marker-size"];k&&k!=="normal"&&M.classList.add(`marker-size-${k}`),i&&i.includes(y.id)&&M.classList.add("selected"),M.addEventListener("click",()=>t.toggleSelectedFlight(y)),m.addEventListener("click",()=>t.toggleSelectedFlight(y)),d.appendChild(M)}})}function st(t,e){const a=document.createElement("img");return a.setAttribute("src",`https://flagsapi.com/${t}/shiny/16.png`),a.setAttribute("title",`${e}`),a.style.position="relative",a.style.top="3px",a.style.left="2px",a}function kt(t,e,a){try{let i=e[a];if(t.config.annotate){const o=Object.assign({},e);t.config.annotate.filter(r=>r.field===a).forEach(r=>{rt(t,e,r.conditions)&&(o[a]=r.render.replace(/\$\{([^}]*)\}/g,(n,d)=>String(o[d]||"")))}),i=String(o[a]||"")}return i}catch(i){return console.error(`[FR24Card] flightField error for field '${a}':`,i),""}}function $t(t,e){try{const a=Object.assign({},e);["flight_number","callsign","aircraft_registration","aircraft_model","aircraft_code","airline","airline_short","airline_iata","airline_icao","airport_origin_name","airport_origin_code_iata","airport_origin_code_icao","airport_origin_country_name","airport_origin_country_code","airport_destination_name","airport_destination_code_iata","airport_destination_code_icao","airport_destination_country_name","airport_destination_country_code"].forEach(o=>{a[o]=kt(t,a,o)}),a.origin_flag=a.airport_origin_country_code?st(a.airport_origin_country_code,a.airport_origin_country_name||"").outerHTML:"",a.destination_flag=a.airport_destination_country_code?st(a.airport_destination_country_code,a.airport_destination_country_name||"").outerHTML:"",a.climb_descend_indicator=Math.abs(a.vertical_speed)>100?a.vertical_speed>100?"↑":"↓":"",a.alt_in_unit=a.altitude>=17750?`FL${Math.round(a.altitude/1e3)*10}`:a.altitude>0?t.units.altitude==="m"?`${Math.round(a.altitude*.3048)} m`:`${Math.round(a.altitude)} ft`:void 0,a.spd_in_unit=a.ground_speed>0?t.units.speed==="kmh"?`${Math.round(a.ground_speed*1.852)} km/h`:t.units.speed==="mph"?`${Math.round(a.ground_speed*1.15078)} mph`:`${Math.round(a.ground_speed)} kts`:void 0,a.approach_indicator=a.ground_speed>70?a.is_approaching?"↓":a.is_receding?"↑":"":"",a.dist_in_unit=`${Math.round(a.distance_to_tracker||0)} ${t.units.distance}`,a.direction_info=`${Math.round(a.heading_from_tracker||0)}° ${a.cardinal_direction_from_tracker||""}`;const i=document.createElement("div");return i.style.clear="both",i.className="flight",t.selectedFlights&&t.selectedFlights.includes(a.id)&&(i.className+=" selected"),i.innerHTML=Y(t,"flight_element",a,o=>(...r)=>r?.filter(n=>n).join(o||" ")),i.addEventListener("click",()=>t.toggleSelectedFlight(a)),i}catch(a){console.error("[FR24Card] renderFlight error:",a);const i=document.createElement("div");return i.className="flight error",i.textContent=`Error rendering flight: ${a}`,i}}var lt={altitude:"ft",speed:"kts",distance:"km"},Mt=[{field:"id",comparator:"oneOf",value:"${selectedFlights}",order:"DESC"},{field:"altitude",comparator:"eq",value:0,order:"ASC"},{field:"closest_passing_distance ?? distance_to_tracker",order:"ASC"}],V,dt=U((()=>{V={img_element:'${flight.aircraft_photo_small ? `<img style="float: right; width: 120px; height: auto; marginLeft: 8px; border: 1px solid black;" src="${flight.aircraft_photo_small}" />` : ""}',icon:'${flight.altitude > 0 ? (flight.vertical_speed > 100 ? "airplane-takeoff" : flight.vertical_speed < -100 ? "airplane-landing" : "airplane") : "airport"}',icon_element:'<ha-icon style="float: left;" icon="mdi:${tpl.icon}"></ha-icon>',flight_info:'${joinList(" - ")(flight.airline_short, flight.flight_number, flight.callsign !== flight.flight_number ? flight.callsign : "")}',flight_info_element:'<div style="font-weight: bold; padding-left: 5px; padding-top: 5px;">${tpl.flight_info}</div>',header:"<div>${tpl.img_element}${tpl.icon_element}${tpl.flight_info_element}</div>",aircraft_info:'${joinList(" - ")(flight.aircraft_registration, flight.aircraft_model)}',aircraft_info_element:'${tpl.aircraft_info ? `<div>${tpl.aircraft_info}</div>` : ""}',departure_info:'${flight.altitude === 0 && flight.time_scheduled_departure ? ` (${new Date(flight.time_scheduled_departure * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })})` : ""}',origin_info:'${joinList("")(flight.airport_origin_code_iata, tpl.departure_info, flight.origin_flag)}',arrival_info:"",destination_info:'${joinList("")(flight.airport_destination_code_iata, tpl.arrival_info, flight.destination_flag)}',route_info:'${joinList(" -> ")(tpl.origin_info, tpl.destination_info)}',route_element:"<div>${tpl.route_info}</div>",alt_info:'${flight.alt_in_unit ? "Alt: " + flight.alt_in_unit + flight.climb_descend_indicator : undefined}',spd_info:'${flight.spd_in_unit ? "Spd: " + flight.spd_in_unit : undefined}',hdg_info:'${flight.heading ? "Hdg: " + flight.heading + "°" : undefined}',dist_info:'${flight.dist_in_unit ? "Dist: " + flight.dist_in_unit + flight.approach_indicator : undefined}',flight_status:'<div>${joinList(" - ")(tpl.alt_info, tpl.spd_info, tpl.hdg_info)}</div>',position_status:'<div>${joinList(" - ")(tpl.dist_info, flight.direction_info)}</div>',proximity_info:'<div style="font-weight: bold; font-style: italic;">${flight.is_approaching && flight.ground_speed > 70 && flight.closest_passing_distance < 15 ? `Closest Distance: ${flight.closest_passing_distance} ${units.distance}, ETA: ${flight.eta_to_closest_distance} min` : ""}</div>',flight_element:"${tpl.header}${tpl.aircraft_info_element}${tpl.route_element}${tpl.flight_status}${tpl.position_status}${tpl.proximity_info}",radar_range:"Range: ${radar_range} ${units.distance}",list_status:"${flights.shown}/${flights.total}"}}));dt();function ct(t,e){return e.split(" ?? ").reduce((a,i)=>a??t[i],void 0)}function At(t,e=a=>a){return function(a,i){for(const o of t){const{field:r,comparator:n,order:d="ASC"}=o,s=e(o.value),f=ct(a,r),b=ct(i,r);let _=0;switch(n){case"eq":f===s&&b!==s?_=1:f!==s&&b===s&&(_=-1);break;case"lt":f<s&&b>=s?_=1:f>=s&&b<s&&(_=-1);break;case"lte":f<=s&&b>s?_=1:f>s&&b<=s&&(_=-1);break;case"gt":f>s&&b<=s?_=1:f<=s&&b>s&&(_=-1);break;case"gte":f>=s&&b<s?_=1:f<s&&b>=s&&(_=-1);break;case"oneOf":if(s!=null&&(Array.isArray(s)||typeof s=="string")){const v=s.includes(f),y=s.includes(b);v&&!y?_=1:!v&&y&&(_=-1)}break;case"containsOneOf":if(Array.isArray(s)&&s.length>0){const v=s.some(C=>(Array.isArray(f)||typeof f=="string")&&f.includes(C)),y=s.some(C=>(Array.isArray(b)||typeof b=="string")&&b.includes(C));v&&!y?_=1:!v&&y&&(_=-1)}break;default:_=f-b;break}if(_!==0)return d.toUpperCase()==="DESC"?-_:_}return 0}}var D={flights_entity:"sensor.flightradar24_current_in_area",projection_interval:5,no_flights_message:"No flights are currently visible. Please check back later.",list:{hide:!1,showListStatus:!0},units:lt,radar:{range:lt.distance==="km"?35:25,background_map:"none",background_map_opacity:0,background_map_api_key:""},sort:Mt,templates:V,defines:{}},pt=class{constructor(){this.hass=null,this.config={},this.radar={range:35},this.list={},this.templates={},this.defines={},this.units={altitude:"ft",speed:"kts",distance:"km"},this.flightsContext={},this.dimensions={},this.flights=[],this.selectedFlights=[],this.renderDynamicOnRangeChange=!1,this._leafletMap=null,this.sortFn=()=>0}setConfig(t){if(!t)throw new Error("Configuration is missing.");this.config={...t},this.config.flights_entity=t.flights_entity??D.flights_entity,this.config.projection_interval=t.projection_interval??D.projection_interval,this.config.no_flights_message=t.no_flights_message??D.no_flights_message,this.list={...D.list,...t.list},this.units={...D.units,...t.units},this.radar={range:this.units.distance==="km"?D.radar.range:25,background_map:t.radar?.background_map??D.radar.background_map,background_map_opacity:t.radar?.background_map_opacity??D.radar.background_map_opacity,background_map_api_key:t.radar?.background_map_api_key??D.radar.background_map_api_key,...t.radar},this.radar.initialRange=this.radar.range,this.defines={...D.defines,...t.defines},this.sortFn=At(t.sort??D.sort,e=>J(this,e,void 0,a=>{this.renderDynamicOnRangeChange=a})),this.templates={...D.templates,...t.templates}}toggleSelectedFlight(t){this.selectedFlights||(this.selectedFlights=[]),this.selectedFlights.includes(t.id)?this.selectedFlights=this.selectedFlights.filter(e=>e!==t.id):this.selectedFlights.push(t.id),typeof this.renderDynamicFn=="function"&&this.renderDynamicFn()}setRenderDynamic(t){this.renderDynamicFn=t}setToggleValue(t,e){this.config&&this.config.toggles&&(this.defines[t]=["true",!0,1].includes(e),typeof this.renderDynamicFn=="function"&&this.renderDynamicFn())}};async function Lt(){if(N)return N;try{const e=await fetch("/local/flightradar24-card/runways.csv");if(e.ok)return N=await e.text(),N}catch{}try{const e=await fetch("data/runways.csv");if(e.ok)return N=await e.text(),N}catch{}const t=await fetch("https://davidmegginson.github.io/ourairports-data/runways.csv");if(!t.ok)throw new Error(`Failed to fetch runway data: ${t.status}`);return N=await t.text(),N}async function Et(){if(j)return j;try{const e=await fetch("/local/flightradar24-card/airports.csv");if(e.ok)return j=await e.text(),j}catch{}try{const e=await fetch("data/airports.csv");if(e.ok)return j=await e.text(),j}catch{}const t=await fetch("https://davidmegginson.github.io/ourairports-data/airports.csv");if(!t.ok)throw new Error(`Failed to fetch airport data: ${t.status}`);return j=await t.text(),j}function H(t){const e=[];let a="",i=!1;for(let o=0;o<t.length;o++){const r=t[o];r==='"'?i=!i:r===","&&!i?(e.push(a),a=""):a+=r}return e.push(a),e}function Ft(t,e,a,i,o){let r=0;a&&a===t&&(r+=1e3),a&&a.startsWith(t)&&(r+=500),e===t&&(r+=900),e.startsWith(t)&&(r+=400),o&&`${e}${o}`.includes(t)&&(r+=300);const n=i.toUpperCase().split(/[\s,/-]+/);for(const d of n)if(d.startsWith(t)){r+=250;break}return i.toUpperCase().includes(t)&&(r+=100),r}async function Rt(t){if(!t||t.length<2)return[];const e=t.trim().toUpperCase(),a=[],[i,o]=await Promise.all([Lt(),Et()]),r=new Map,n=o.split(`
`),d=H(n[0]),s=d.indexOf("ident"),f=d.indexOf("name"),b=d.indexOf("iata_code");for(let x=1;x<n.length;x++){const k=n[x].trim();if(!k)continue;const w=H(k),$=w[s],A=w[f],L=w[b];$&&r.set($,{name:A||"",iata:L||""})}const _=i.split(`
`),v=H(_[0]),y=v.indexOf("airport_ident"),C=v.indexOf("le_ident"),M=v.indexOf("he_ident"),u=v.indexOf("le_latitude_deg"),h=v.indexOf("le_longitude_deg"),c=v.indexOf("he_latitude_deg"),g=v.indexOf("he_longitude_deg"),m=v.indexOf("le_heading_degT"),l=v.indexOf("he_heading_degT"),p=v.indexOf("length_ft");for(let x=1;x<_.length;x++){const k=_[x].trim();if(!k)continue;const w=H(k),$=w[y],A=w[C],L=w[M],S=r.get($);if(!S)continue;const{name:F,iata:E}=S,R=$.startsWith(e),P=E&&E.toUpperCase().startsWith(e),T=F.toUpperCase().includes(e),Dt=A&&`${$}${A}`.includes(e),It=L&&`${$}${L}`.includes(e);if(!R&&!P&&!T&&!Dt&&!It)continue;const ht=Ft(e,$,E,F,A||L||"");if(A){const I=[];E&&I.push(E),I.push($),I.push(`RWY${A}`),F&&I.push(`- ${F}`),a.push({displayText:I.join(" "),airportCode:$,airportName:F,iataCode:E,runwayDesignator:A,data:{airportCode:$,runwayDesignator:A,latitude:parseFloat(w[u]),longitude:parseFloat(w[h]),heading:parseFloat(w[m]),length:parseFloat(w[p])},score:ht})}if(L){const I=[];E&&I.push(E),I.push($),I.push(`RWY${L}`),F&&I.push(`- ${F}`),a.push({displayText:I.join(" "),airportCode:$,airportName:F,iataCode:E,runwayDesignator:L,data:{airportCode:$,runwayDesignator:L,latitude:parseFloat(w[c]),longitude:parseFloat(w[g]),heading:parseFloat(w[l]),length:parseFloat(w[p])},score:ht})}}return a.sort((x,k)=>k.score-x.score).slice(0,10).map(({score:x,...k})=>k)}var N,j,St=U((()=>{N=null,j=null})),Tt=gt({Flightradar24CardEditor:()=>Q}),Q,ut=U((()=>{St(),dt(),Q=class extends HTMLElement{constructor(){super(),this._config={},this._openSections=new Set(["basic-settings"]),this._openConditions=new Set,this._openFeatures=new Set,this._openAnnotations=new Set,this._mapModal=null,this._internalUpdate=!1,this._shadowRoot=this.attachShadow({mode:"open"})}setConfig(t){this._config={...t},this._internalUpdate||this._render(),this._internalUpdate=!1}get availableFlightEntities(){return this.hass?Object.keys(this.hass.states).filter(t=>t.includes("flightradar")).sort():[]}get availableTrackerEntities(){return this.hass?Object.keys(this.hass.states).filter(t=>t.startsWith("device_tracker.")||t.startsWith("person.")||t.startsWith("zone.")).sort():[]}get availableFlightFields(){return[{value:"id",label:"ID",group:"Basic"},{value:"flight_number",label:"Flight Number",group:"Basic"},{value:"callsign",label:"Callsign",group:"Basic"},{value:"aircraft_registration",label:"Aircraft Registration",group:"Aircraft"},{value:"aircraft_model",label:"Aircraft Model",group:"Aircraft"},{value:"aircraft_code",label:"Aircraft Code",group:"Aircraft"},{value:"airline",label:"Airline Name",group:"Airline"},{value:"airline_short",label:"Airline Short",group:"Airline"},{value:"airline_iata",label:"Airline IATA",group:"Airline"},{value:"airline_icao",label:"Airline ICAO",group:"Airline"},{value:"airport_origin_name",label:"Origin Airport",group:"Origin"},{value:"airport_origin_code_iata",label:"Origin IATA",group:"Origin"},{value:"airport_origin_country_name",label:"Origin Country",group:"Origin"},{value:"airport_origin_country_code",label:"Origin Country Code",group:"Origin"},{value:"airport_destination_name",label:"Destination Airport",group:"Destination"},{value:"airport_destination_code_iata",label:"Destination IATA",group:"Destination"},{value:"airport_destination_country_name",label:"Destination Country",group:"Destination"},{value:"airport_destination_country_code",label:"Destination Country Code",group:"Destination"},{value:"latitude",label:"Latitude",group:"Position"},{value:"longitude",label:"Longitude",group:"Position"},{value:"altitude",label:"Altitude",group:"Position"},{value:"vertical_speed",label:"Vertical Speed",group:"Movement"},{value:"ground_speed",label:"Ground Speed",group:"Movement"},{value:"heading",label:"Heading",group:"Movement"},{value:"distance_to_tracker",label:"Distance to Tracker",group:"Tracking"},{value:"heading_from_tracker",label:"Heading from Tracker",group:"Tracking"},{value:"cardinal_direction_from_tracker",label:"Cardinal Direction",group:"Tracking"},{value:"is_approaching",label:"Is Approaching",group:"Tracking"},{value:"is_receding",label:"Is Receding",group:"Tracking"},{value:"closest_passing_distance",label:"Closest Passing Distance",group:"Approach"},{value:"eta_to_closest_distance",label:"ETA to Closest",group:"Approach"},{value:"heading_from_tracker_to_closest_passing",label:"Heading to Closest",group:"Approach"}]}_mapTypeRequiresApiKey(t){return t==="bw"||t==="outlines"}get validFlightFields(){return new Set(this.availableFlightFields.map(t=>t.value))}get allDefineAndToggleKeys(){const t=new Set;return Object.keys(this._config.toggles||{}).forEach(e=>t.add(e)),Object.keys(this._config.defines||{}).forEach(e=>t.add(e)),t}getUsedDefinesAndToggles(){const t=new Set,e=this._config.templates||{},a=this._config.filter,i=this._config.sort||[];Object.values(e).forEach(r=>{const n=r.matchAll(/\$\{(\w+)\}/g);for(const d of n){const s=d[1];this.allDefineAndToggleKeys.has(s)&&t.add(s)}});const o=r=>{r.forEach(n=>{if("type"in n&&(n.type==="AND"||n.type==="OR"))o(n.conditions||[]);else if("type"in n&&n.type==="NOT")o([n.condition]);else{const d=n;d.field&&this.allDefineAndToggleKeys.has(d.field)&&t.add(d.field);const s=d.value;if(typeof s=="string"&&s.startsWith("${")&&s.endsWith("}")){const f=s.slice(2,-1);this.allDefineAndToggleKeys.has(f)&&t.add(f)}}})};return a&&Array.isArray(a)&&o(a),i.forEach(r=>{r.field&&this.allDefineAndToggleKeys.has(r.field)&&t.add(r.field)}),t}getUnusedDefinesAndToggles(){const t=this.getUsedDefinesAndToggles(),e=[],a=[];return Object.keys(this._config.toggles||{}).forEach(i=>{t.has(i)||e.push(i)}),Object.keys(this._config.defines||{}).forEach(i=>{t.has(i)||a.push(i)}),{toggles:e,defines:a}}getUsedTemplateKeys(){const t=new Set,e=this._config.templates||{};return["flight_element","radar_range","list_status"].forEach(a=>{e[a]!==void 0&&t.add(a)}),Object.values(e).forEach(a=>{const i=a.matchAll(/\$\{(\w+)\([\s\S]*?\)\}/g);for(const o of i){const r=o[1];e[r]!==void 0&&t.add(r)}}),t}getUnusedTemplates(){const t=this.getUsedTemplateKeys(),e=this._config.templates||{},a=[];return Object.keys(e).forEach(i=>{t.has(i)||a.push(i)}),a}validateConditionField(t){return this.validFlightFields.has(t)?{valid:!0}:this.allDefineAndToggleKeys.has(t)?{valid:!0}:{valid:!1,error:`Unknown field: "${t}". Not a flight property or define/toggle.`}}hasValidationErrors(){const t=this.getUnusedDefinesAndToggles();if(t.toggles.length>0||t.defines.length>0||this.getUnusedTemplates().length>0)return!0;const e=this._config.filter;if(e&&Array.isArray(e)&&this._checkConditionsForInvalidFields(e))return!0;const a=this._config.sort||[];for(const i of a)if(i.field&&!this.validateConditionField(i.field).valid)return!0;return!1}_checkConditionsForInvalidFields(t){for(const e of t)if("type"in e&&(e.type==="AND"||e.type==="OR")){if(this._checkConditionsForInvalidFields(e.conditions||[]))return!0}else if("type"in e&&e.type==="NOT"){if(this._checkConditionsForInvalidFields([e.condition]))return!0}else{const a=e;if(a.field&&!this.validateConditionField(a.field).valid)return!0}return!1}_render(){this.hass&&(this._saveOpenSections(),this._shadowRoot.innerHTML=`
<style>
${this._getStyles()}
</style>
<div class="editor-container">
${this._renderBasicSettings()}
${this._renderAdvancedSettings()}
${this._renderRadarConfig()}
${this._renderListConfig()}
${this._renderTogglesAndDefinesConfig()}
${this._renderTemplatesConfig()}
</div>
`,this._attachEventListeners(),this._restoreOpenSections())}_saveOpenSections(){this._shadowRoot.querySelectorAll("details").forEach(t=>{const e=t.getAttribute("data-section-id");e&&(t.open?this._openSections.add(e):this._openSections.delete(e));const a=t.getAttribute("data-condition-path");a&&(t.open?this._openConditions.add(a):this._openConditions.delete(a));const i=t.getAttribute("data-feature-id");i&&(t.open?this._openFeatures.add(i):this._openFeatures.delete(i));const o=t.getAttribute("data-annotation-id");o&&(t.open?this._openAnnotations.add(o):this._openAnnotations.delete(o))})}_restoreOpenSections(){this._shadowRoot.querySelectorAll("details").forEach(t=>{const e=t.getAttribute("data-section-id");e&&this._openSections.has(e)&&(t.open=!0);const a=t.getAttribute("data-condition-path");a&&this._openConditions.has(a)&&(t.open=!0);const i=t.getAttribute("data-feature-id");i&&this._openFeatures.has(i)&&(t.open=!0);const o=t.getAttribute("data-annotation-id");o&&this._openAnnotations.has(o)&&(t.open=!0)})}_getStyles(){return`
.editor-container {
position: relative;
z-index: 1000;
background: var(--card-background-color, #fff);
}
details {
margin-bottom: 12px;
border: 1px solid var(--divider-color, #ccc);
border-radius: 4px;
padding: 6px;
}
summary {
cursor: pointer;
user-select: none;
font-weight: bold;
padding: 6px;
margin: -6px;
}
summary:hover {
background: var(--secondary-background-color, #f0f0f0);
}
h3 {
display: inline;
margin: 0;
}
h4 {
margin: 12px 0 6px 0;
font-size: 0.95em;
font-weight: 600;
color: var(--secondary-text-color, #666);
}
summary h4 {
display: inline;
margin: 0;
}
h5 {
margin: 8px 0 4px 0;
font-size: 0.9em;
font-weight: 600;
color: var(--secondary-text-color, #666);
}
summary h5 {
display: inline;
margin: 0;
}
details details {
margin-bottom: 8px;
border: 1px solid var(--divider-color, #e0e0e0);
background: var(--secondary-background-color, #f5f5f5);
}
details details summary {
padding: 4px;
margin: -4px;
}
details details .section-content {
padding: 8px 6px 6px 6px;
}
.subsection {
margin-bottom: 12px;
padding: 8px;
border: 1px solid var(--divider-color, #e0e0e0);
border-radius: 4px;
}
.subsection legend {
padding: 0 6px;
font-size: 0.95em;
font-weight: 600;
color: var(--secondary-text-color, #666);
}
.section-content {
padding: 12px 6px 6px 6px;
}
.form-row {
display: flex;
flex-direction: column;
gap: 4px;
margin-bottom: 10px;
}
.form-row label {
font-weight: 500;
font-size: 0.9em;
color: var(--secondary-text-color, #666);
}
input[type="text"],
input[type="number"],
input[type="color"],
select,
textarea {
padding: 6px 8px;
border: 1px solid var(--divider-color, #ccc);
border-radius: 4px;
font-family: inherit;
font-size: 14px;
width: 100%;
box-sizing: border-box;
}
input[type="number"] {
max-width: 120px;
}
input[type="checkbox"] {
width: 18px;
height: 18px;
}
.full-width {
width: 100%;
}
textarea.full-width {
min-height: 60px;
}
.help-text {
color: var(--secondary-text-color, #666);
font-size: 0.85em;
margin: 2px 0;
line-height: 1.3;
}
.item-box {
border: 1px solid var(--divider-color, #ccc);
border-radius: 4px;
padding: 0;
margin-bottom: 8px;
background: var(--secondary-background-color, #f5f5f5);
}
.item-box summary.item-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px;
margin: 0;
font-weight: bold;
cursor: pointer;
user-select: none;
list-style: none;
font-size: 0.9em;
}
.item-box summary.item-header::-webkit-details-marker {
display: none;
}
.item-box summary.item-header::before {
content: '▶';
font-size: 9px;
margin-right: 6px;
transition: transform 0.2s;
}
.item-box[open] summary.item-header::before {
transform: rotate(90deg);
}
.item-box summary.item-header:hover {
background: rgba(0, 0, 0, 0.03);
}
.item-box .section-content {
padding: 0 8px 8px 8px;
}
.button-group {
display: flex;
gap: 4px;
flex-wrap: wrap;
}
button {
padding: 5px 10px;
border: 1px solid var(--divider-color, #ccc);
border-radius: 4px;
background: var(--card-background-color, #fff);
cursor: pointer;
font-size: 13px;
}
button:hover {
background: var(--secondary-background-color, #f0f0f0);
}
.add-button {
background: var(--primary-color, #03a9f4);
color: white;
border: none;
}
.add-button:hover {
background: var(--dark-primary-color, #0288d1);
}
.remove-button {
background: var(--error-color, #f44336);
color: white;
border: none;
}
.remove-button:hover {
background: #d32f2f;
}
.small-button {
font-size: 11px;
padding: 3px 6px;
}
.icon-button {
padding: 3px 6px;
font-weight: bold;
}
.condition-box {
border-left: 3px solid var(--primary-color, #03a9f4);
padding: 0;
margin: 6px 0;
background: var(--card-background-color, #fff);
border-radius: 4px;
border: 1px solid var(--divider-color, #e0e0e0);
}
.condition-box[open] {
padding-bottom: 8px;
}
.condition-group {
background: var(--secondary-background-color, #f5f5f5);
border-left: 3px solid var(--accent-color, #ff9800);
}
.condition-not {
background: #fff3e0;
border-left: 3px solid #fb8c00;
}
.condition-summary {
display: flex;
align-items: center;
gap: 6px;
padding: 8px;
cursor: pointer;
user-select: none;
list-style: none;
font-size: 0.9em;
}
.condition-summary::-webkit-details-marker {
display: none;
}
.condition-summary::before {
content: '▶';
font-size: 9px;
transition: transform 0.2s;
flex-shrink: 0;
}
.condition-box[open] > .condition-summary::before {
transform: rotate(90deg);
}
.condition-summary:hover {
background: rgba(0, 0, 0, 0.02);
}
.condition-type-badge {
background: var(--primary-color, #03a9f4);
color: white;
padding: 2px 6px;
border-radius: 3px;
font-size: 10px;
font-weight: bold;
text-transform: uppercase;
flex-shrink: 0;
}
.condition-group .condition-type-badge {
background: var(--accent-color, #ff9800);
}
.condition-not .condition-type-badge {
background: #fb8c00;
}
.condition-description {
flex: 1;
font-size: 13px;
color: var(--secondary-text-color, #666);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-family: 'Courier New', monospace;
}
.condition-content {
padding: 0 8px 0 8px;
}
.condition-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.conditions-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.empty-state {
color: var(--secondary-text-color, #999);
font-style: italic;
text-align: center;
padding: 12px;
font-size: 0.9em;
}
.map-modal-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
z-index: 10000;
align-items: center;
justify-content: center;
}
.map-modal-overlay.open {
display: flex;
}
.map-modal {
background: var(--card-background-color, #fff);
border-radius: 8px;
width: 90%;
max-width: 800px;
height: 80%;
max-height: 600px;
display: flex;
flex-direction: column;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.map-modal-header {
padding: 16px;
border-bottom: 1px solid var(--divider-color, #e0e0e0);
display: flex;
justify-content: space-between;
align-items: center;
}
.map-modal-header h3 {
margin: 0;
}
.map-modal-body {
flex: 1;
position: relative;
overflow: hidden;
}
.map-modal-map {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.map-modal-footer {
padding: 16px;
border-top: 1px solid var(--divider-color, #e0e0e0);
display: flex;
justify-content: space-between;
align-items: center;
}
.map-modal-instructions {
color: var(--secondary-text-color, #666);
font-size: 0.9em;
}
.runway-dropdown {
position: absolute;
top: 100%;
left: 0;
right: 0;
background: var(--card-background-color, #fff);
border: 1px solid var(--divider-color, #ccc);
border-radius: 4px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
max-height: 300px;
overflow-y: auto;
z-index: 1000;
margin-top: 4px;
}
.runway-dropdown-item {
padding: 8px 12px;
cursor: pointer;
border-bottom: 1px solid var(--divider-color, #f0f0f0);
}
.runway-dropdown-item:last-child {
border-bottom: none;
}
.runway-dropdown-item:hover {
background: var(--secondary-background-color, #f5f5f5);
}
.runway-dropdown-loading {
padding: 12px;
text-align: center;
color: var(--secondary-text-color, #666);
font-style: italic;
}
.runway-dropdown-empty {
padding: 12px;
text-align: center;
color: var(--secondary-text-color, #666);
font-style: italic;
}
.template-button-container {
position: relative;
}
.template-dropdown-button {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
.template-dropdown-button::after {
content: '▼';
font-size: 10px;
margin-left: 8px;
}
.template-dropdown {
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
background: var(--card-background-color, #fff);
border: 1px solid var(--divider-color, #ccc);
border-radius: 4px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
max-height: 300px;
overflow-y: auto;
z-index: 1000;
margin-top: 4px;
}
.template-dropdown.open {
display: block;
}
.template-dropdown-header {
padding: 8px 12px;
font-weight: 600;
font-size: 0.85em;
color: var(--secondary-text-color, #666);
background: var(--secondary-background-color, #f5f5f5);
border-bottom: 1px solid var(--divider-color, #e0e0e0);
}
.template-dropdown-item {
padding: 8px 12px;
cursor: pointer;
border-bottom: 1px solid var(--divider-color, #f0f0f0);
}
.template-dropdown-item:last-child {
border-bottom: none;
}
.template-dropdown-item:hover {
background: var(--secondary-background-color, #f5f5f5);
}
/* Responsive adjustments for narrow editor panes (typical HA editor width ~460px) */
.button-group {
flex-wrap: wrap;
}
.condition-field-type {
flex: 1;
min-width: 100px;
}
/* Aircraft marker size selector */
.marker-size-selector {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.marker-size-option {
position: relative;
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
border: 2px solid transparent;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
min-width: 50px;
min-height: 50px;
overflow: hidden;
}
.marker-size-option:hover {
border-color: var(--primary-color, #03a9f4);
}
.marker-size-option.selected {
border-color: var(--primary-color, #03a9f4);
box-shadow: 0 0 0 1px var(--primary-color, #03a9f4);
}
.marker-button-background {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
}
.marker-preview {
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
z-index: 1;
}
`}_renderBasicSettings(){return`
<details data-section-id="basic-settings">
<summary><h3>Basic</h3></summary>
<div class="section-content">
<div class="form-row">
<label>Flights Entity:</label>
<select class="full-width" id="flights-entity" data-config="flights_entity">
<option value="">Select entity...</option>
${this.availableFlightEntities.map(t=>`<option value="${t}" ${this._config.flights_entity===t?"selected":""}>${t}</option>`).join("")}
</select>
</div>
<div class="form-row">
<label>Location Tracker:</label>
<select class="full-width" id="location-tracker" data-config="location_tracker">
<option value="">Manual coordinates...</option>
${this.availableTrackerEntities.map(t=>`<option value="${t}" ${this._config.location_tracker===t?"selected":""}>${t}</option>`).join("")}
</select>
</div>
${this._config.location_tracker?"":`
<div class="form-row">
<label>Latitude:</label>
<input type="number" step="0.0001" id="location-lat"
value="${this._config.location?.lat??""}" placeholder="63.4041" />
</div>
<div class="form-row">
<label>Longitude:</label>
<input type="number" step="0.0001" id="location-lon"
value="${this._config.location?.lon??""}" placeholder="10.4301" />
</div>
`}
<fieldset class="subsection">
<legend>Units</legend>
<div class="form-row">
<label>Altitude:</label>
<select id="unit-altitude" data-unit="altitude">
<option value="ft" ${(this._config.units?.altitude||"ft")==="ft"?"selected":""}>Feet (ft)</option>
<option value="m" ${(this._config.units?.altitude||"ft")==="m"?"selected":""}>Meters (m)</option>
</select>
</div>
<div class="form-row">
<label>Speed:</label>
<select id="unit-speed" data-unit="speed">
<option value="kts" ${(this._config.units?.speed||"kts")==="kts"?"selected":""}>Knots (kts)</option>
<option value="kmh" ${(this._config.units?.speed||"kts")==="kmh"?"selected":""}>Km/h</option>
<option value="mph" ${(this._config.units?.speed||"kts")==="mph"?"selected":""}>Mph</option>
</select>
</div>
<div class="form-row">
<label>Distance:</label>
<select id="unit-distance" data-unit="distance">
<option value="km" ${(this._config.units?.distance||"km")==="km"?"selected":""}>Kilometers (km)</option>
<option value="miles" ${(this._config.units?.distance||"km")==="miles"?"selected":""}>Miles</option>
</select>
</div>
</fieldset>
<div class="form-row">
<label>Max Flights:</label>
<input type="number" min="1" step="1" id="max-flights"
value="${this._config.max_flights??""}" placeholder="unlimited" />
</div>
</div>
</details>
`}_renderAdvancedSettings(){const t=this._config.annotate||[];JSON.stringify(t,null,2);const e=this._config.filter||[];return`
<details data-section-id="advanced-settings">
<summary><h3>Advanced</h3></summary>
<div class="section-content">
<div class="form-row">
<label>Projection Interval (ms):</label>
<input type="number" min="100" step="100" id="projection-interval"
value="${this._config.projection_interval??1e3}" />
<span class="help-text">Flight position update frequency</span>
</div>
<div class="form-row">
<label>Scale:</label>
<input type="number" min="0.5" max="2" step="0.1" id="scale"
value="${this._config.scale??1}" />
<span class="help-text">Card zoom level - Use with caution: values > 1 may cause the card to overflow and break page layout</span>
</div>
<details data-section-id="advanced-filter">
<summary>
<h4>Filter</h4>
${e.length>0&&this._checkConditionsForInvalidFields(e)?'<span style="color: #ff9800; font-size: 1.2em; margin-left: 0.5em;" title="Contains invalid filter fields">⚠️</span>':""}
</summary>
<div class="section-content">
<p class="help-text">Filter which flights are displayed. All top-level conditions must match (implicit AND).</p>
<div id="filter-conditions">
${e.length>0?this._renderConditionsList(e,"filter"):'<p class="empty-state">No filters defined</p>'}
</div>
<div class="button-group" style="margin-top: 12px;">
<button class="add-button" data-action="add-filter-condition">Add Value Condition</button>
<button class="add-button" data-action="add-filter-group">Add AND/OR Group</button>
<button class="add-button" data-action="add-filter-not">Add NOT Condition</button>
</div>
</div>
</details>
<details data-section-id="advanced-sort">
<summary>
<h4>Sort</h4>
${(this._config.sort||[]).some(a=>a.field?!this.validateConditionField(a.field).valid:!1)?'<span style="color: #ff9800; font-size: 1.2em; margin-left: 0.5em;" title="Contains invalid sort fields">⚠️</span>':""}
</summary>
<div class="section-content">
<p class="help-text">Define how flights are sorted in the list</p>
<div id="sort-list">
${(this._config.sort||[]).map((a,i)=>{const o=a.field?this.validateConditionField(a.field):{valid:!0},r=!o.valid;return`
<div class="item-box" ${r?'style="border-color: #ff9800;"':""}>
<div class="item-header">
<span>Sort ${i+1}</span>
${r?`<span style="color: #ff9800; font-size: 1.2em; margin-left: 0.5em;" title="${o.error||"Invalid field"}">⚠️</span>`:""}
<button class="remove-button" data-action="remove-sort" data-index="${i}">Remove</button>
</div>
<div class="form-row">
<label>Field:</label>
<input type="text" value="${a.field}" data-sort-prop="${i}:field" placeholder="distance, altitude, speed, etc." ${r?'style="border-color: #ff9800;"':""} />
</div>
${r?`<div class="form-row"><p style="color: #ff9800; margin: 0; font-size: 0.9em;">${o.error||"Invalid field"}</p></div>`:""}
<div class="form-row">
<label>Order:</label>
<select data-sort-prop="${i}:order">
<option value="asc" ${(a.order||"asc")==="asc"?"selected":""}>Ascending</option>
<option value="desc" ${a.order==="desc"?"selected":""}>Descending</option>
</select>
</div>
</div>
`}).join("")}
</div>
<button class="add-button" data-action="add-sort">Add Sort Criterion</button>
</div>
</details>
<details data-section-id="advanced-annotations">
<summary><h4>Annotations</h4></summary>
<div class="section-content">
<p class="help-text">Conditional rendering with custom templates for specific flight fields</p>
<div id="annotations-list">
${t.length>0?t.map((a,i)=>this._renderAnnotation(a,i)).join(""):'<p class="empty-state">No annotations defined</p>'}
</div>
<button class="add-button" data-action="add-annotation">Add Annotation</button>
</div>
</details>
</div>
</details>
`}_renderRadarConfig(){const t=this._config.radar||{},e=(this._config.units?.distance||"km")==="miles"?"miles":"km";return`
<details data-section-id="radar-config">
<summary><h3>Radar</h3></summary>
<div class="section-content">
<div class="form-row">
<label>
<input type="checkbox" id="radar-show" ${t.hide!==!0?"checked":""} />
Show Radar
</label>
</div>
<details data-section-id="radar-range">
<summary><h4>Range</h4></summary>
<div class="section-content">
<div class="form-row">
<label>Default Range (${e}):</label>
<input type="number" min="1" step="1" id="radar-range" value="${t.range??50}" />
</div>
<div class="form-row">
<label>Min Range (${e}):</label>
<input type="number" min="1" step="1" id="radar-min-range" value="${t.min_range??5}" />
</div>
<div class="form-row">
<label>Max Range (${e}):</label>
<input type="number" min="1" step="1" id="radar-max-range" value="${t.max_range??100}" />
</div>
<div class="form-row">
<label>Ring Distance (${e}):</label>
<input type="number" min="1" step="1" id="radar-ring-distance" value="${t.ring_distance??10}" />
</div>
</div>
</details>
<details data-section-id="radar-colors">
<summary><h4>Colors</h4></summary>
<div class="section-content">
<div class="form-row">
<label>Background Color:</label>
<input type="color" id="radar-background-color" value="${t["background-color"]??t["primary-color"]??"#ffffff"}" />
</div>
<div class="form-row">
<label>Background Opacity:</label>
<input type="number" min="0" max="1" step="0.05" id="radar-background-opacity" value="${t["background-opacity"]??.05}" />
</div>
<div class="form-row">
<label>Aircraft Marker:</label>
<input type="color" id="radar-aircraft-color" value="${t["aircraft-color"]??t["accent-color"]??"#ff0000"}" />
</div>
<div class="form-row">
<label>Aircraft Marker (Selected):</label>
<input type="color" id="radar-aircraft-selected-color" value="${t["aircraft-selected-color"]??t["aircraft-color"]??t["accent-color"]??"#ff6600"}" />
</div>
<div class="form-row">
<label>Radar Grid:</label>
<input type="color" id="radar-grid-color" value="${t["radar-grid-color"]??t["feature-color"]??"#888888"}" />
</div>
<div class="form-row">
<label>Local Features:</label>
<input type="color" id="radar-local-features-color" value="${t["local-features-color"]??t["feature-color"]??t["radar-grid-color"]??"#888888"}" />
</div>
</div>
</details>
<details data-section-id="radar-aircraft-marker">
<summary><h4>Aircraft Marker</h4></summary>
<div class="section-content">
<div class="form-row">
<label>Marker Size:</label>
<div class="marker-size-selector">
${["small","normal","large","x-large","xx-large"].map(a=>{const i=(t["aircraft-marker-size"]||"normal")===a,o={small:.7,normal:1,large:1.4,"x-large":2,"xx-large":2.8}[a],r=t["background-color"]||t["primary-color"]||"#1a1a1a",n=t["aircraft-color"]||t["accent-color"]||"#ff0000",d=t["background-opacity"]??.05;return`
<button class="marker-size-option ${i?"selected":""}" data-size="${a}">
<div class="marker-button-background" style="background-color: ${r}; opacity: ${d};"></div>
<div class="marker-preview">
<div class="preview-arrow" style="
width: 0;
height: 0;
border-left: ${3*o}px solid transparent;
border-right: ${3*o}px solid transparent;
border-bottom: ${8*o}px solid ${n};
transform: rotate(45deg);
"></div>
</div>
</button>
`}).join("")}
</div>
</div>
</div>
</details>
<details data-section-id="radar-background-map">
<summary><h4>Background Map</h4></summary>
<div class="section-content">
<div class="form-row">
<label>Background Map:</label>
<select id="radar-background-map">
<option value="none" ${(t.background_map||"none")==="none"?"selected":""}>None</option>
<option value="system" ${t.background_map==="system"?"selected":""}>System (auto dark/light)</option>
<option value="bw" ${t.background_map==="bw"?"selected":""}>Black & White (requires API key)</option>
<option value="light" ${t.background_map==="light"?"selected":""}>Light</option>
<option value="color" ${t.background_map==="color"?"selected":""}>Color</option>
<option value="dark" ${t.background_map==="dark"?"selected":""}>Dark</option>
<option value="voyager" ${t.background_map==="voyager"?"selected":""}>Voyager</option>
<option value="satellite" ${t.background_map==="satellite"?"selected":""}>Satellite</option>
<option value="topo" ${t.background_map==="topo"?"selected":""}>Topographic</option>
<option value="outlines" ${t.background_map==="outlines"?"selected":""}>Outlines (requires API key)</option>
</select>
</div>
${this._mapTypeRequiresApiKey(t.background_map)?`
<div class="form-row">
<label>Stadia Maps API Key:</label>
<input type="text" class="full-width" id="radar-background-map-api-key"
value="${t.background_map_api_key||""}" placeholder="Get free key at stadiamaps.com" />
<span class="help-text">Required for Black & White and Outlines map types. <a href="https://stadiamaps.com/" target="_blank" rel="noopener noreferrer">Get a free API key</a></span>