@xenon-device-management/xenon 2.9.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/lib/package.json +1 -1
  2. package/lib/public/assets/{AnnotationOverlay-Dm_URoOL.js → AnnotationOverlay-LzfXiiZJ.js} +1 -1
  3. package/lib/public/assets/{ApiKeyGate-BdGOuXDm.js → ApiKeyGate-BzFDp4mK.js} +1 -1
  4. package/lib/public/assets/{BugReportButton-BuWGEjgw.js → BugReportButton-BpgWvmZo.js} +1 -1
  5. package/lib/public/assets/{DeviceMosaicView-Pu3rJ99D.js → DeviceMosaicView-CCB-egSH.js} +2 -2
  6. package/lib/public/assets/{EmptyState-syyHElMd.js → EmptyState-DkUVmANo.js} +1 -1
  7. package/lib/public/assets/{FieldGroup-BZR5ZBVv.js → FieldGroup-mbfnfTql.js} +1 -1
  8. package/lib/public/assets/{FilterMenu-CsgtrmPb.js → FilterMenu-BH5usz4Y.js} +1 -1
  9. package/lib/public/assets/{Menu-DP8XOm1A.js → Menu-Cbo9mdTk.js} +1 -1
  10. package/lib/public/assets/{Modal-Dtd-8uI2.js → Modal-D6XfQHPr.js} +1 -1
  11. package/lib/public/assets/{RecordingPage-CdAtAmHj.js → RecordingPage-CmFPkWqH.js} +1 -1
  12. package/lib/public/assets/{RecordingsPage-Br3CKxTe.js → RecordingsPage-CSlKk2qC.js} +1 -1
  13. package/lib/public/assets/{SegmentedControl-BOaNmUL-.js → SegmentedControl-BFW9Dlqd.js} +1 -1
  14. package/lib/public/assets/{SettingCard-CQuK9ZZX.js → SettingCard-C4DioTTi.js} +1 -1
  15. package/lib/public/assets/{Table-CswCefnT.js → Table-DrKjlL00.js} +1 -1
  16. package/lib/public/assets/{activity-6fhH3u4C.js → activity-C9bE7Jm8.js} +1 -1
  17. package/lib/public/assets/{ai-settings-CU24L3D4.js → ai-settings-DRYic4oO.js} +1 -1
  18. package/lib/public/assets/{api-keys-DC3BZDaG.js → api-keys-CaQU0g7c.js} +1 -1
  19. package/lib/public/assets/{apps-Ce5Z-wNc.js → apps-c1gUFmmK.js} +1 -1
  20. package/lib/public/assets/{arrow-left-DZJqYn7r.js → arrow-left-DMvAWA8r.js} +1 -1
  21. package/lib/public/assets/{arrow-right-nIvK8CyN.js → arrow-right-BEQgxmKT.js} +1 -1
  22. package/lib/public/assets/{arrow-up-right-BfugJj3f.js → arrow-up-right-Ba0e2GeU.js} +1 -1
  23. package/lib/public/assets/{auth-shell-B1Cz75Vq.js → auth-shell-COODQnc7.js} +2 -2
  24. package/lib/public/assets/{builds-page-5mlJGjIk.js → builds-page-DZQgWBUs.js} +4 -4
  25. package/lib/public/assets/{button-D_W88sn-.js → button-WW9j43wR.js} +1 -1
  26. package/lib/public/assets/{calendar-Dc6pWZS9.js → calendar-COUs9VxF.js} +1 -1
  27. package/lib/public/assets/{check-BbvtnP8m.js → check-D8ifHIJR.js} +1 -1
  28. package/lib/public/assets/{chevron-right-CgBUaRCA.js → chevron-right-BjKVUlB_.js} +1 -1
  29. package/lib/public/assets/{circle-check-BWjEKvA4.js → circle-check-CfP79QE2.js} +1 -1
  30. package/lib/public/assets/{circle-x-BLUdeRhT.js → circle-x-BZbFCixZ.js} +1 -1
  31. package/lib/public/assets/{clock-PAhKG1jT.js → clock-BuTm35Qg.js} +1 -1
  32. package/lib/public/assets/{copy-2CHdAPBf.js → copy-W00zUBwN.js} +1 -1
  33. package/lib/public/assets/{device-explorer-EyAhEL_S.js → device-explorer-BEpS-Y-_.js} +5 -5
  34. package/lib/public/assets/{download-B1vKGhGP.js → download-CGz-MS3y.js} +1 -1
  35. package/lib/public/assets/{forgot-password-NSrrBA5N.js → forgot-password-DG7SqVgU.js} +1 -1
  36. package/lib/public/assets/{index-C8pvxG1f.css → index-DQa193-A.css} +1 -1
  37. package/lib/public/assets/{index-BEk1D5-B.js → index-DWHTp1YP.js} +1 -1
  38. package/lib/public/assets/{index-BxaH84UO.js → index-EkaQM1DK.js} +2 -2
  39. package/lib/public/assets/{input-cA_lrNIw.js → input-ChaTXeCq.js} +1 -1
  40. package/lib/public/assets/{keycodes-DZLCZ-uv.js → keycodes-BhbgeW_r.js} +10 -5
  41. package/lib/public/assets/line-chart-9P3RxScy.js +1 -0
  42. package/lib/public/assets/list-checks-_23IIEEL.js +11 -0
  43. package/lib/public/assets/{lock-ChoclF8X.js → lock-B2JaqqRI.js} +1 -1
  44. package/lib/public/assets/{login-63DiXJ0M.js → login-BEWIfLfC.js} +1 -1
  45. package/lib/public/assets/{maintenance-settings-A47Y-PYy.js → maintenance-settings-BGJIJQ-k.js} +1 -1
  46. package/lib/public/assets/{monitor-BYPF43Ds.js → monitor-BrwMY4G0.js} +1 -1
  47. package/lib/public/assets/{mouse-pointer-2-Pcl7inmZ.js → mouse-pointer-2-DsWDMyrY.js} +1 -1
  48. package/lib/public/assets/{network-ChaLfnWe.js → network-DfIhNVJv.js} +1 -1
  49. package/lib/public/assets/overview-B1mePY2_.js +6 -0
  50. package/lib/public/assets/{page-header-bv2AQSMG.js → page-header-DoD3TOzZ.js} +1 -1
  51. package/lib/public/assets/{plus-u0x2Y5uW.js → plus-BGvWvpBB.js} +1 -1
  52. package/lib/public/assets/{profile-page-Cvmef2iY.js → profile-page-CvV5aWvl.js} +1 -1
  53. package/lib/public/assets/{reset-password-DqStVhBo.js → reset-password-CGVd31LR.js} +1 -1
  54. package/lib/public/assets/{runbook-page-UK0C95QF.js → runbook-page-Bq2cvwb5.js} +1 -1
  55. package/lib/public/assets/{select-CQ6O804R.js → select-CTcD4jWR.js} +1 -1
  56. package/lib/public/assets/selector-detail-redirect-19odlD4B.js +1 -0
  57. package/lib/public/assets/selector-health-page-LqIsLrjW.js +11 -0
  58. package/lib/public/assets/session-detail-page-DQzb8_fq.js +4 -0
  59. package/lib/public/assets/{settings-Cva7V4n-.js → settings-C-EnGIqs.js} +1 -1
  60. package/lib/public/assets/stat-tile-BY0RDTRm.js +1 -0
  61. package/lib/public/assets/{tablet-BPtlTsKn.js → tablet-B4cFM-5B.js} +1 -1
  62. package/lib/public/assets/{teams-D4r1UMME.js → teams-BFe-RpYd.js} +1 -1
  63. package/lib/public/assets/time-D-gjmE1o.js +1 -0
  64. package/lib/public/assets/{trash-2-CnysPtdR.js → trash-2-CJCKBOP9.js} +1 -1
  65. package/lib/public/assets/{upload-Uyj4-Cyq.js → upload-DidWkbld.js} +1 -1
  66. package/lib/public/assets/use-builds-data-fnfxatOd.js +8 -0
  67. package/lib/public/assets/{use-password-reset-mode-Du-ykGHP.js → use-password-reset-mode-iPen3tmC.js} +1 -1
  68. package/lib/public/assets/{users-ttkwKBos.js → users-CrcjmRdf.js} +1 -1
  69. package/lib/public/assets/{users-Cs00GNmy.js → users-DBUv0CJx.js} +1 -1
  70. package/lib/public/assets/{video-off-BYa4qD8N.js → video-off-eh69-FKB.js} +1 -1
  71. package/lib/public/assets/view-state-CP9dE1UI.js +1 -0
  72. package/lib/public/assets/{webhook-settings-DuEnPlet.js → webhook-settings-CQoSshBn.js} +1 -1
  73. package/lib/public/assets/{zap-CxHn6Vwu.js → zap-CICtWiLn.js} +1 -1
  74. package/lib/public/index.html +2 -2
  75. package/lib/schema.json +5 -0
  76. package/lib/src/app/routers/dashboard.js +86 -40
  77. package/lib/src/app/routers/selector-health.js +75 -0
  78. package/lib/src/app/swagger-docs.js +77 -8
  79. package/lib/src/dashboard/event-manager.js +15 -99
  80. package/lib/src/device-managers/ios/IOSDiscoveryService.js +6 -65
  81. package/lib/src/device-managers/ios/IOSStreamService.js +7 -66
  82. package/lib/src/device-managers/ios/WDAClient.js +65 -86
  83. package/lib/src/generated/client/edge.js +27 -3
  84. package/lib/src/generated/client/index-browser.js +24 -0
  85. package/lib/src/generated/client/index.d.ts +8207 -5283
  86. package/lib/src/generated/client/index.js +27 -3
  87. package/lib/src/generated/client/package.json +1 -1
  88. package/lib/src/generated/client/schema.prisma +43 -9
  89. package/lib/src/generated/client/wasm.js +24 -0
  90. package/lib/src/prisma.js +2 -0
  91. package/lib/src/services/CleanupService.js +1 -0
  92. package/lib/src/services/NotificationService.js +3 -4
  93. package/lib/src/services/SelectorStateService.js +151 -113
  94. package/lib/src/services/SelectorVerificationJob.js +14 -9
  95. package/lib/src/services/metrics/AndroidMetricsSampler.js +94 -0
  96. package/lib/src/services/metrics/IOSMetricsSampler.js +120 -0
  97. package/lib/src/services/metrics/SessionMetricsService.js +238 -0
  98. package/lib/src/services/metrics/androidMetrics.js +94 -0
  99. package/lib/src/services/metrics/iosMetrics.js +26 -0
  100. package/lib/src/services/metrics/metricsBody.js +37 -0
  101. package/lib/src/services/metrics/types.js +19 -0
  102. package/lib/src/services/selector-health/access.js +66 -0
  103. package/lib/src/services/selector-health/healingTrend.js +49 -0
  104. package/lib/src/services/selector-health/people.js +27 -0
  105. package/lib/src/services/selector-health/selectorDetail.js +198 -0
  106. package/lib/src/services/selector-health/selectorKeys.js +36 -0
  107. package/lib/src/services/selector-health/selectorList.js +333 -0
  108. package/lib/src/services/selector-health/stateView.js +67 -0
  109. package/lib/test/helpers/scratch-database.js +2 -0
  110. package/lib/test/helpers/selector-health-fixture.js +216 -0
  111. package/lib/test/integration/team-visibility-sessions.spec.js +1 -0
  112. package/lib/test/unit/CleanupService.spec.js +28 -2
  113. package/lib/test/unit/dashboard-events-metrics.spec.js +146 -0
  114. package/lib/test/unit/healing-no-cost.spec.js +134 -0
  115. package/lib/test/unit/healing-state-endpoints.spec.js +70 -0
  116. package/lib/test/unit/healing-trend.spec.js +118 -0
  117. package/lib/test/unit/ios-discovery-same-host.spec.js +0 -1
  118. package/lib/test/unit/ios-no-network-fallback.spec.js +219 -0
  119. package/lib/test/unit/selector-event-model.spec.js +47 -0
  120. package/lib/test/unit/selector-health-actions.spec.js +106 -0
  121. package/lib/test/unit/selector-health-detail.spec.js +131 -0
  122. package/lib/test/unit/selector-health-list.spec.js +185 -0
  123. package/lib/test/unit/selector-state-service.spec.js +74 -1
  124. package/lib/test/unit/selector-verification-job.spec.js +38 -0
  125. package/lib/test/unit/session-metrics-parse.spec.js +138 -0
  126. package/lib/test/unit/session-metrics-route.spec.js +140 -0
  127. package/lib/test/unit/session-metrics-samplers.spec.js +248 -0
  128. package/lib/test/unit/session-metrics-service.spec.js +215 -0
  129. package/lib/tsconfig.tsbuildinfo +1 -1
  130. package/package.json +1 -1
  131. package/prisma/migrations/20261002120000_session_metric/migration.sql +17 -0
  132. package/prisma/migrations/20261002130000_selector_event/migration.sql +13 -0
  133. package/prisma/schema.prisma +43 -9
  134. package/schema.json +5 -0
  135. package/lib/public/assets/chevron-left-DQDpR9ne.js +0 -6
  136. package/lib/public/assets/funnel-C9mzkCSI.js +0 -6
  137. package/lib/public/assets/layers-BuXMIJz3.js +0 -6
  138. package/lib/public/assets/list-checks-B8q68tPG.js +0 -6
  139. package/lib/public/assets/overview-bj_vktQG.js +0 -1
  140. package/lib/public/assets/selector-detail-page-D-PjU6mC.js +0 -1
  141. package/lib/public/assets/selector-health-BlICzZlk.css +0 -1
  142. package/lib/public/assets/selector-health-CVm0cTOU.js +0 -16
  143. package/lib/public/assets/selector-health-page-BdibBs8g.js +0 -16
  144. package/lib/public/assets/session-detail-page-BijicGOF.js +0 -4
  145. package/lib/public/assets/stat-tile-BdIoEoou.js +0 -8
  146. package/lib/public/assets/time-B8FIgwPE.js +0 -1
  147. package/lib/src/profiling/AndroidAppProfiler.js +0 -213
  148. /package/lib/public/assets/{session-detail-page-Bzzc3bMl.css → line-chart-Bzzc3bMl.css} +0 -0
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xenon-device-management/xenon",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "description": "Xenon - Intelligent Mobile Infrastructure. A self-healing device orchestration platform for Appium.",
5
5
  "main": "./lib/src/index.js",
6
6
  "exports": {
@@ -1 +1 @@
1
- import{r as w,j as _}from"./index-BxaH84UO.js";const F=1600;function j(t,r){const e=F/Math.max(t,r);return{w:Math.round(t*e),h:Math.round(r*e)}}function B(t,r,e,s=document){if(r<=0||e<=0)return null;const{w:o,h:f}=j(r,e),l=s.createElement("canvas");l.width=o,l.height=f;const y=l.getContext("2d");if(!y)return null;y.scale(o/r,f/e),Y(y,r,e,t);try{return l.toDataURL("image/png")}catch{return null}}function U(t,r,e){const s={left:0,top:0,width:t,height:r};if(!e||!(e>0)||t<=0||r<=0)return s;const o=t/r;if(Math.abs(o-e)<1e-6)return s;if(e>o){const l=t/e;return{left:0,top:(r-l)/2,width:t,height:l}}const f=r*e;return{left:(t-f)/2,top:0,width:f,height:r}}const G=(t,r)=>t===r||!!t&&!!r&&t.left===r.left&&t.top===r.top&&t.width===r.width&&t.height===r.height,J=2,q=2e3;function D(t,r,e){if(t.length>=q)return t;const s=t[t.length-1];return s&&Math.hypot(r-s[0],e-s[1])<J?t:[...t,[r,e]]}function $(t,r){const e=(t||"#ff3333").trim();if(/^#[0-9a-fA-F]{6}$/.test(e)){const s=parseInt(e.slice(1,3),16),o=parseInt(e.slice(3,5),16),f=parseInt(e.slice(5,7),16);return`rgba(${s},${o},${f},${r})`}return e}function Y(t,r,e,s){var S;const o=s.geometry,f=s.color||"#ff3333",l=Math.max(4,Math.round(Math.min(r,e)*.008));if(t.lineCap="round",t.lineJoin="round",s.shape==="CIRCLE"){const h=(o.x??0)*r,M=(o.y??0)*e,p=Math.max(2,(o.w??0)*r),a=Math.max(2,(o.h??0)*e);t.beginPath(),t.ellipse(h,M,p,a,0,0,Math.PI*2),t.fillStyle=$(f,.22),t.fill(),t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",t.stroke(),t.beginPath(),t.ellipse(h,M,p,a,0,0,Math.PI*2),t.lineWidth=l,t.strokeStyle=f,t.stroke();return}if(s.shape==="ARROW"){const h=(o.x??0)*r,M=(o.y??0)*e,p=h+(o.w??0)*r,a=M+(o.h??0)*e;t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",t.beginPath(),t.moveTo(h,M),t.lineTo(p,a),t.stroke(),t.lineWidth=l,t.strokeStyle=f,t.beginPath(),t.moveTo(h,M),t.lineTo(p,a),t.stroke();const P=Math.atan2(a-M,p-h),k=Math.max(14,l*3);t.fillStyle=f,t.beginPath(),t.moveTo(p,a),t.lineTo(p-k*Math.cos(P-.4),a-k*Math.sin(P-.4)),t.lineTo(p-k*Math.cos(P+.4),a-k*Math.sin(P+.4)),t.closePath(),t.fill();return}if(s.shape==="TEXT"&&s.text){const h=Math.max(16,Math.round(Math.min(r,e)*.035));t.font=`bold ${h}px sans-serif`,t.lineWidth=3,t.strokeStyle="rgba(0,0,0,0.65)",t.strokeText(s.text,(o.x??0)*r,(o.y??0)*e),t.fillStyle=f,t.fillText(s.text,(o.x??0)*r,(o.y??0)*e);return}if(s.shape==="FREEHAND"&&(((S=o.points)==null?void 0:S.length)??0)>=2){const h=o.points,M=()=>{t.beginPath(),t.moveTo(h[0][0]*r,h[0][1]*e);for(let p=1;p<h.length;p++)t.lineTo(h[p][0]*r,h[p][1]*e)};t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",M(),t.stroke(),t.lineWidth=l,t.strokeStyle=f,M(),t.stroke();return}const y=(o.x??0)*r,R=(o.y??0)*e,c=Math.max(2,(o.w??0)*r),g=Math.max(2,(o.h??0)*e);t.fillStyle=$(f,.22),t.fillRect(y,R,c,g),t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",t.strokeRect(y,R,c,g),t.lineWidth=l,t.strokeStyle=f,t.strokeRect(y,R,c,g)}function O(t,r,e,s,o){if(s<=0||o<=0)return null;if(t==="CIRCLE"){const c=Math.hypot(e.curX-e.startX,e.curY-e.startY);return c<=4?null:{shape:t,color:r,geometry:{x:e.startX/s,y:e.startY/o,w:c/s,h:c/o}}}if(t==="ARROW"){const c=e.curX-e.startX,g=e.curY-e.startY;return Math.hypot(c,g)<=6?null:{shape:t,color:r,geometry:{x:e.startX/s,y:e.startY/o,w:c/s,h:g/o}}}if(t==="FREEHAND"){if(e.points.length<2)return null;const c=e.points.map(M=>M[0]),g=e.points.map(M=>M[1]),S=Math.min(...c),h=Math.min(...g);return{shape:t,color:r,geometry:{x:S/s,y:h/o,w:Math.max(.005,(Math.max(...c)-S)/s),h:Math.max(.005,(Math.max(...g)-h)/o),points:e.points.map(([M,p])=>[M/s,p/o])}}}const f=Math.min(e.startX,e.curX)/s,l=Math.min(e.startY,e.curY)/o,y=Math.abs(e.curX-e.startX)/s,R=Math.abs(e.curY-e.startY)/o;return y<=.005||R<=.005?null:{shape:t,color:r,geometry:{x:f,y:l,w:y,h:R}}}function K({enabled:t,shape:r,color:e,onCommit:s,committed:o,onCommittedChange:f,mediaAspect:l}){const y=w.useRef(null),[R,c]=w.useState(null),[g,S]=w.useState([]),[h,M]=w.useState(null),p=o??g,a=w.useRef(p),P=w.useRef(R),k=w.useRef(r),X=w.useRef(e),I=w.useRef(t);a.current=p,P.current=R,k.current=r,X.current=e,I.current=t;const b=w.useCallback(n=>{const i=n(a.current);a.current=i,f?f(i):S(i)},[f]),T=w.useCallback(()=>{const n=y.current;if(!n)return;const i=n.getContext("2d");if(!i)return;i.clearRect(0,0,n.width,n.height);for(const m of a.current)Y(i,n.width,n.height,m);const u=P.current;if(u){const m=O(k.current,X.current,u,n.width,n.height);m&&Y(i,n.width,n.height,m)}},[]);w.useEffect(()=>{const n=y.current;if(!n)return;const i=()=>{const m=Math.max(1,Math.round(n.clientWidth)),d=Math.max(1,Math.round(n.clientHeight));(n.width!==m||n.height!==d)&&(n.width=m,n.height=d),T()};i();const u=new ResizeObserver(i);return u.observe(n),()=>u.disconnect()},[T]),w.useEffect(()=>{T()},[R,p,T]),w.useEffect(()=>{var m;const n=(m=y.current)==null?void 0:m.parentElement;if(!n)return;const i=()=>{const d=l?U(n.clientWidth,n.clientHeight,l):null;M(E=>G(E,d)?E:d)};i();const u=new ResizeObserver(i);return u.observe(n),()=>u.disconnect()},[l]),w.useEffect(()=>{var i;if(t)return;c(null);const n=y.current;if(n&&n.hasPointerCapture)try{for(let u=0;u<8;u++)(i=n.hasPointerCapture)!=null&&i.call(n,u)&&n.releasePointerCapture(u)}catch{}},[t]);const C=n=>{const u=y.current.getBoundingClientRect();return{px:n.clientX-u.left,py:n.clientY-u.top,w:u.width,h:u.height}},z=n=>{const i=P.current;if(!i||!I.current){c(null);return}const u=y.current;if(!u||u.width<=0){c(null);return}const m=C(n),d=O(k.current,X.current,{...i,curX:m.px,curY:m.py,points:D(i.points,m.px,m.py)},m.w,m.h);d&&(b(E=>[...E,d]),s(d,B(d,m.w,m.h))),c(null)},N=n=>{if(!t||n.button!==0)return;n.preventDefault(),n.currentTarget.setPointerCapture(n.pointerId);const i=C(n);c({startX:i.px,startY:i.py,curX:i.px,curY:i.py,points:[[i.px,i.py]]})},L=n=>{if(!P.current)return;const i=C(n);c(u=>u&&{...u,curX:i.px,curY:i.py,points:D(u.points,i.px,i.py)})},A=n=>{try{n.currentTarget.releasePointerCapture(n.pointerId)}catch{}z(n)};return _.jsx("canvas",{ref:y,style:{position:"absolute",...h?{left:`${h.left}px`,top:`${h.top}px`,width:`${h.width}px`,height:`${h.height}px`}:{inset:0,width:"100%",height:"100%"},pointerEvents:t?"auto":"none",cursor:t?"crosshair":"default",zIndex:t?40:25},onPointerDown:N,onPointerMove:L,onPointerUp:A,onPointerCancel:A})}export{K as A,U as f};
1
+ import{r as w,j as _}from"./index-EkaQM1DK.js";const F=1600;function j(t,r){const e=F/Math.max(t,r);return{w:Math.round(t*e),h:Math.round(r*e)}}function B(t,r,e,s=document){if(r<=0||e<=0)return null;const{w:o,h:f}=j(r,e),l=s.createElement("canvas");l.width=o,l.height=f;const y=l.getContext("2d");if(!y)return null;y.scale(o/r,f/e),Y(y,r,e,t);try{return l.toDataURL("image/png")}catch{return null}}function U(t,r,e){const s={left:0,top:0,width:t,height:r};if(!e||!(e>0)||t<=0||r<=0)return s;const o=t/r;if(Math.abs(o-e)<1e-6)return s;if(e>o){const l=t/e;return{left:0,top:(r-l)/2,width:t,height:l}}const f=r*e;return{left:(t-f)/2,top:0,width:f,height:r}}const G=(t,r)=>t===r||!!t&&!!r&&t.left===r.left&&t.top===r.top&&t.width===r.width&&t.height===r.height,J=2,q=2e3;function D(t,r,e){if(t.length>=q)return t;const s=t[t.length-1];return s&&Math.hypot(r-s[0],e-s[1])<J?t:[...t,[r,e]]}function $(t,r){const e=(t||"#ff3333").trim();if(/^#[0-9a-fA-F]{6}$/.test(e)){const s=parseInt(e.slice(1,3),16),o=parseInt(e.slice(3,5),16),f=parseInt(e.slice(5,7),16);return`rgba(${s},${o},${f},${r})`}return e}function Y(t,r,e,s){var S;const o=s.geometry,f=s.color||"#ff3333",l=Math.max(4,Math.round(Math.min(r,e)*.008));if(t.lineCap="round",t.lineJoin="round",s.shape==="CIRCLE"){const h=(o.x??0)*r,M=(o.y??0)*e,p=Math.max(2,(o.w??0)*r),a=Math.max(2,(o.h??0)*e);t.beginPath(),t.ellipse(h,M,p,a,0,0,Math.PI*2),t.fillStyle=$(f,.22),t.fill(),t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",t.stroke(),t.beginPath(),t.ellipse(h,M,p,a,0,0,Math.PI*2),t.lineWidth=l,t.strokeStyle=f,t.stroke();return}if(s.shape==="ARROW"){const h=(o.x??0)*r,M=(o.y??0)*e,p=h+(o.w??0)*r,a=M+(o.h??0)*e;t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",t.beginPath(),t.moveTo(h,M),t.lineTo(p,a),t.stroke(),t.lineWidth=l,t.strokeStyle=f,t.beginPath(),t.moveTo(h,M),t.lineTo(p,a),t.stroke();const P=Math.atan2(a-M,p-h),k=Math.max(14,l*3);t.fillStyle=f,t.beginPath(),t.moveTo(p,a),t.lineTo(p-k*Math.cos(P-.4),a-k*Math.sin(P-.4)),t.lineTo(p-k*Math.cos(P+.4),a-k*Math.sin(P+.4)),t.closePath(),t.fill();return}if(s.shape==="TEXT"&&s.text){const h=Math.max(16,Math.round(Math.min(r,e)*.035));t.font=`bold ${h}px sans-serif`,t.lineWidth=3,t.strokeStyle="rgba(0,0,0,0.65)",t.strokeText(s.text,(o.x??0)*r,(o.y??0)*e),t.fillStyle=f,t.fillText(s.text,(o.x??0)*r,(o.y??0)*e);return}if(s.shape==="FREEHAND"&&(((S=o.points)==null?void 0:S.length)??0)>=2){const h=o.points,M=()=>{t.beginPath(),t.moveTo(h[0][0]*r,h[0][1]*e);for(let p=1;p<h.length;p++)t.lineTo(h[p][0]*r,h[p][1]*e)};t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",M(),t.stroke(),t.lineWidth=l,t.strokeStyle=f,M(),t.stroke();return}const y=(o.x??0)*r,R=(o.y??0)*e,c=Math.max(2,(o.w??0)*r),g=Math.max(2,(o.h??0)*e);t.fillStyle=$(f,.22),t.fillRect(y,R,c,g),t.lineWidth=l+2,t.strokeStyle="rgba(0,0,0,0.55)",t.strokeRect(y,R,c,g),t.lineWidth=l,t.strokeStyle=f,t.strokeRect(y,R,c,g)}function O(t,r,e,s,o){if(s<=0||o<=0)return null;if(t==="CIRCLE"){const c=Math.hypot(e.curX-e.startX,e.curY-e.startY);return c<=4?null:{shape:t,color:r,geometry:{x:e.startX/s,y:e.startY/o,w:c/s,h:c/o}}}if(t==="ARROW"){const c=e.curX-e.startX,g=e.curY-e.startY;return Math.hypot(c,g)<=6?null:{shape:t,color:r,geometry:{x:e.startX/s,y:e.startY/o,w:c/s,h:g/o}}}if(t==="FREEHAND"){if(e.points.length<2)return null;const c=e.points.map(M=>M[0]),g=e.points.map(M=>M[1]),S=Math.min(...c),h=Math.min(...g);return{shape:t,color:r,geometry:{x:S/s,y:h/o,w:Math.max(.005,(Math.max(...c)-S)/s),h:Math.max(.005,(Math.max(...g)-h)/o),points:e.points.map(([M,p])=>[M/s,p/o])}}}const f=Math.min(e.startX,e.curX)/s,l=Math.min(e.startY,e.curY)/o,y=Math.abs(e.curX-e.startX)/s,R=Math.abs(e.curY-e.startY)/o;return y<=.005||R<=.005?null:{shape:t,color:r,geometry:{x:f,y:l,w:y,h:R}}}function K({enabled:t,shape:r,color:e,onCommit:s,committed:o,onCommittedChange:f,mediaAspect:l}){const y=w.useRef(null),[R,c]=w.useState(null),[g,S]=w.useState([]),[h,M]=w.useState(null),p=o??g,a=w.useRef(p),P=w.useRef(R),k=w.useRef(r),X=w.useRef(e),I=w.useRef(t);a.current=p,P.current=R,k.current=r,X.current=e,I.current=t;const b=w.useCallback(n=>{const i=n(a.current);a.current=i,f?f(i):S(i)},[f]),T=w.useCallback(()=>{const n=y.current;if(!n)return;const i=n.getContext("2d");if(!i)return;i.clearRect(0,0,n.width,n.height);for(const m of a.current)Y(i,n.width,n.height,m);const u=P.current;if(u){const m=O(k.current,X.current,u,n.width,n.height);m&&Y(i,n.width,n.height,m)}},[]);w.useEffect(()=>{const n=y.current;if(!n)return;const i=()=>{const m=Math.max(1,Math.round(n.clientWidth)),d=Math.max(1,Math.round(n.clientHeight));(n.width!==m||n.height!==d)&&(n.width=m,n.height=d),T()};i();const u=new ResizeObserver(i);return u.observe(n),()=>u.disconnect()},[T]),w.useEffect(()=>{T()},[R,p,T]),w.useEffect(()=>{var m;const n=(m=y.current)==null?void 0:m.parentElement;if(!n)return;const i=()=>{const d=l?U(n.clientWidth,n.clientHeight,l):null;M(E=>G(E,d)?E:d)};i();const u=new ResizeObserver(i);return u.observe(n),()=>u.disconnect()},[l]),w.useEffect(()=>{var i;if(t)return;c(null);const n=y.current;if(n&&n.hasPointerCapture)try{for(let u=0;u<8;u++)(i=n.hasPointerCapture)!=null&&i.call(n,u)&&n.releasePointerCapture(u)}catch{}},[t]);const C=n=>{const u=y.current.getBoundingClientRect();return{px:n.clientX-u.left,py:n.clientY-u.top,w:u.width,h:u.height}},z=n=>{const i=P.current;if(!i||!I.current){c(null);return}const u=y.current;if(!u||u.width<=0){c(null);return}const m=C(n),d=O(k.current,X.current,{...i,curX:m.px,curY:m.py,points:D(i.points,m.px,m.py)},m.w,m.h);d&&(b(E=>[...E,d]),s(d,B(d,m.w,m.h))),c(null)},N=n=>{if(!t||n.button!==0)return;n.preventDefault(),n.currentTarget.setPointerCapture(n.pointerId);const i=C(n);c({startX:i.px,startY:i.py,curX:i.px,curY:i.py,points:[[i.px,i.py]]})},L=n=>{if(!P.current)return;const i=C(n);c(u=>u&&{...u,curX:i.px,curY:i.py,points:D(u.points,i.px,i.py)})},A=n=>{try{n.currentTarget.releasePointerCapture(n.pointerId)}catch{}z(n)};return _.jsx("canvas",{ref:y,style:{position:"absolute",...h?{left:`${h.left}px`,top:`${h.top}px`,width:`${h.width}px`,height:`${h.height}px`}:{inset:0,width:"100%",height:"100%"},pointerEvents:t?"auto":"none",cursor:t?"crosshair":"default",zIndex:t?40:25},onPointerDown:N,onPointerMove:L,onPointerUp:A,onPointerCancel:A})}export{K as A,U as f};
@@ -1 +1 @@
1
- import{r as n,j as e,o as h}from"./index-BxaH84UO.js";function y({children:c}){const[i,s]=n.useState(null),[o,l]=n.useState(""),[a,r]=n.useState(null);if(n.useEffect(()=>{fetch("/xenon/api/health").then(()=>fetch("/xenon/api/sessions",{credentials:"include"})).then(t=>s(t.status!==401)).catch(()=>s(!1))},[]),i===null)return e.jsx("div",{style:{padding:40},children:"Loading…"});if(i)return e.jsx(e.Fragment,{children:c});async function u(t){t.preventDefault(),r(null);const d=await fetch("/xenon/api/auth/dashboard-session",{method:"POST",headers:{"Content-Type":"application/json",...h},credentials:"include",body:JSON.stringify({apiKey:o.trim()})});if(d.ok)s(!0);else{const p=await d.json().catch(()=>({}));r(p.error||"Invalid key")}}return e.jsxs("div",{style:{maxWidth:420,margin:"120px auto",padding:24},children:[e.jsx("h2",{children:"Sign in to Xenon"}),e.jsxs("p",{children:["Paste an API key. First-time setup: the bootstrap key is in"," ",e.jsx("code",{children:"~/.cache/xenon/bootstrap-key.txt"})," on the server."]}),e.jsxs("form",{onSubmit:u,children:[e.jsx("input",{type:"password",value:o,onChange:t=>l(t.target.value),placeholder:"API key",style:{width:"100%",padding:8,boxSizing:"border-box"},autoFocus:!0}),e.jsx("button",{type:"submit",style:{marginTop:12,padding:"8px 16px"},children:"Continue"})]}),a&&e.jsx("p",{style:{color:"crimson",marginTop:12},children:a})]})}export{y as ApiKeyGate};
1
+ import{r as n,j as e,o as h}from"./index-EkaQM1DK.js";function y({children:c}){const[i,s]=n.useState(null),[o,l]=n.useState(""),[a,r]=n.useState(null);if(n.useEffect(()=>{fetch("/xenon/api/health").then(()=>fetch("/xenon/api/sessions",{credentials:"include"})).then(t=>s(t.status!==401)).catch(()=>s(!1))},[]),i===null)return e.jsx("div",{style:{padding:40},children:"Loading…"});if(i)return e.jsx(e.Fragment,{children:c});async function u(t){t.preventDefault(),r(null);const d=await fetch("/xenon/api/auth/dashboard-session",{method:"POST",headers:{"Content-Type":"application/json",...h},credentials:"include",body:JSON.stringify({apiKey:o.trim()})});if(d.ok)s(!0);else{const p=await d.json().catch(()=>({}));r(p.error||"Invalid key")}}return e.jsxs("div",{style:{maxWidth:420,margin:"120px auto",padding:24},children:[e.jsx("h2",{children:"Sign in to Xenon"}),e.jsxs("p",{children:["Paste an API key. First-time setup: the bootstrap key is in"," ",e.jsx("code",{children:"~/.cache/xenon/bootstrap-key.txt"})," on the server."]}),e.jsxs("form",{onSubmit:u,children:[e.jsx("input",{type:"password",value:o,onChange:t=>l(t.target.value),placeholder:"API key",style:{width:"100%",padding:8,boxSizing:"border-box"},autoFocus:!0}),e.jsx("button",{type:"submit",style:{marginTop:12,padding:"8px 16px"},children:"Continue"})]}),a&&e.jsx("p",{style:{color:"crimson",marginTop:12},children:a})]})}export{y as ApiKeyGate};
@@ -1,4 +1,4 @@
1
- import{c as g,j as o,r as f,t as m,f as b}from"./index-BxaH84UO.js";/**
1
+ import{c as g,j as o,r as f,t as m,f as b}from"./index-EkaQM1DK.js";/**
2
2
  * @license lucide-react v0.555.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,2 +1,2 @@
1
- import{r as d,j as r,z as $e,w as Me,X as D,v as Pe,e as Le,Y as Be,T as He,Z as We}from"./index-BxaH84UO.js";import{p as Ve}from"./labels-C21SA4JG.js";import{C as ze}from"./circle-check-BWjEKvA4.js";import{C as xe,M as Ue,A as ee,H as Fe,S as be,a as Ge,I as Ke,h as ve}from"./keycodes-DZLCZ-uv.js";import{f as Ye,A as Xe}from"./AnnotationOverlay-Dm_URoOL.js";import{V as qe}from"./video-off-BYa4qD8N.js";import{C as Je}from"./chevron-left-DQDpR9ne.js";import{P as Ze}from"./plus-u0x2Y5uW.js";import{a as Qe}from"./SegmentedControl-BOaNmUL-.js";import{v as et,a as tt,c as rt,s as nt,R as ot,b as st,g as at,d as le,e as it}from"./recordings-BWe1ydXm.js";import{D as oe}from"./download-B1vKGhGP.js";import{B as de}from"./button-D_W88sn-.js";import{C as ct}from"./clock-PAhKG1jT.js";import{a as lt}from"./page-header-bv2AQSMG.js";import"./utils-CDN07tui.js";function dt(e,t){return e!=="auto"?e:t<=1?"1":t===2?"2x1":t<=4?"2x2":"3x2"}const ut={selected:new Set,layout:"auto",tiles:[],groupId:null,compositeEnabled:!1,downloadableVideoCount:0,recordingPhase:"idle",recording:!1,startedAt:null,annotateMode:!1,shape:"RECT",color:"#ff3333",overlayAnnotations:{},errorBanner:null,banner:null};function ft(e,t){var n;switch(t.type){case"SET_LAYOUT":return{...e,layout:t.layout};case"TOGGLE_SELECTED":{const o=new Set(e.selected);return o.has(t.udid)?o.delete(t.udid):o.add(t.udid),{...e,selected:o}}case"CLEAR_SELECTED":return{...e,selected:new Set};case"SET_TILES":return{...e,tiles:t.tiles};case"ADD_TILE":return e.tiles.some(o=>o.udid===t.tile.udid)?e:{...e,tiles:[...e.tiles,t.tile]};case"PATCH_TILE_DIMS":{let o=!1;const i=e.tiles.map(g=>g.udid!==t.udid||g.screenWidth&&g.screenHeight?g:(o=!0,{...g,screenWidth:t.screenWidth,screenHeight:t.screenHeight,aspect:t.aspect??g.aspect}));return o?{...e,tiles:i}:e}case"REMOVE_TILE":return e.recordingPhase!=="idle"?e:{...e,tiles:e.tiles.filter(o=>o.udid!==t.udid)};case"BIND_RECORDING_IDS":{const o=e.tiles.map(i=>({...i,recordingId:t.map[i.udid]??i.recordingId}));return{...e,tiles:o}}case"SET_RECORDING_PHASE":{const o=t.phase;return{...e,recordingPhase:o,recording:o==="recording"||o==="stopping"}}case"START_RECORDING":{const o=e.tiles.map(i=>({...i,recordingId:t.tileIds[i.udid]??i.recordingId}));return{...e,groupId:t.groupId,compositeEnabled:t.compositeEnabled===!0,downloadableVideoCount:0,recordingPhase:"recording",recording:!0,annotateMode:!1,startedAt:t.startedAt,overlayAnnotations:{},tiles:o}}case"REHYDRATE_RECORDING":{const o=e.tiles.map(i=>({...i,recordingId:t.tileIds[i.udid]??i.recordingId}));return{...e,groupId:t.groupId,compositeEnabled:t.compositeEnabled,downloadableVideoCount:0,recordingPhase:"recording",recording:!0,annotateMode:!1,startedAt:t.startedAt,overlayAnnotations:t.overlayAnnotations,tiles:o}}case"STOP_RECORDING":{const o=e.tiles.map(i=>({...i,recordingId:void 0}));return{...e,recording:!1,recordingPhase:"idle",annotateMode:!1,overlayAnnotations:{},downloadableVideoCount:t.downloadableVideoCount??e.downloadableVideoCount,compositeEnabled:t.compositeEnabled!==void 0?t.compositeEnabled:e.compositeEnabled,tiles:o}}case"SET_ANNOTATE_MODE":return{...e,annotateMode:t.enabled};case"SET_SHAPE":return{...e,shape:t.shape};case"SET_COLOR":return{...e,color:t.color};case"SET_OVERLAY_ANNOTATIONS":return{...e,overlayAnnotations:{...e.overlayAnnotations,[t.recordingId]:t.annotations}};case"CLEAR_OVERLAY_ANNOTATIONS":return{...e,overlayAnnotations:{}};case"SET_ERROR_BANNER":return{...e,errorBanner:t.message,banner:t.message?{tone:"error",message:t.message}:null};case"SET_BANNER":return{...e,banner:t.banner,errorBanner:((n=t.banner)==null?void 0:n.tone)==="error"?t.banner.message:null};default:return e}}const ye=d.createContext(null);function ht(){const e=d.useContext(ye);if(!e)throw new Error("useMosaic must be used inside <MosaicContext.Provider>");return e}function pt(){return d.useReducer(ft,ut)}function mt(e){const t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/3600),o=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`:`${o}:${String(i).padStart(2,"0")}`}function gt(e){switch(e){case"automation":return"In automation";case"manual_other":return"Manual control by another user";case"manual_self":return"On your grid";case"recording_other_group":return"Recording in another group";default:return e?"Busy":null}}const ue=[{id:"ios",label:"iOS",match:e=>e==="ios"},{id:"android",label:"Android",match:e=>e==="android"},{id:"tvos",label:"tvOS",match:e=>e==="tvos"},{id:"androidtv",label:"Android TV",match:e=>e==="androidtv"||e==="android-tv"},{id:"other",label:"Other",match:()=>!0}],Y={available:"bg-[var(--color-success)]",inUse:"bg-[var(--color-warning)]",offline:"bg-[rgb(var(--rgb-offline))]"},xt=[["available",Y.available],["in use",Y.inUse],["offline",Y.offline]];function fe(e){return Ve(e)}function bt({devices:e,inMosaic:t,onToggle:n,status:o="ready"}){const[i,g]=d.useState(""),[u,N]=d.useState({}),p=d.useMemo(()=>{const l=i.trim().toLowerCase();return l?e.filter(v=>v.udid.toLowerCase().includes(l)||(v.name??"").toLowerCase().includes(l)||(v.altName??"").toLowerCase().includes(l)||(v.platform??"").toLowerCase().includes(l)):e},[e,i]),E=d.useMemo(()=>{const l=ue.map(f=>({id:f.id,label:f.label,rows:[]})),v=f=>l.find((j,y)=>ue[y].match(f))??l[l.length-1];for(const f of p)v((f.platform??"").toLowerCase()).rows.push(f);return l.filter(f=>f.rows.length>0)},[p]);if(e.length===0){const l=o==="loading"?"Loading devices…":o==="error"?"Couldn’t load devices. Retrying…":"No devices online.";return r.jsx("div",{role:"status",className:"text-xs text-[var(--text-dim)] p-3",children:l})}return r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("div",{className:"relative",children:[r.jsx($e,{"aria-hidden":!0,size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--text-dim)]"}),r.jsx("input",{type:"text",value:i,placeholder:"Filter devices...",onChange:l=>g(l.target.value),className:"w-full pl-7 pr-2 py-1.5 text-xs rounded border border-[var(--border)] bg-transparent placeholder:text-[var(--text-dim)] focus:outline-none focus:border-[var(--color-info)]"})]}),E.map(l=>{const v=u[l.id];return r.jsxs("section",{className:"flex flex-col gap-1",children:[r.jsxs("button",{type:"button","aria-expanded":!v,onClick:()=>N(f=>({...f,[l.id]:!f[l.id]})),className:"flex items-center justify-between w-full text-[11px] text-[var(--text-dim)] hover:text-[rgb(var(--rgb-fg))] px-1 py-0.5",children:[r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx(Me,{"aria-hidden":!0,size:12,className:`transition-transform ${v?"-rotate-90":"rotate-0"}`}),l.label]}),r.jsx("span",{children:l.rows.length})]}),!v&&r.jsx("ul",{className:"flex flex-col gap-1 text-sm",children:l.rows.map(f=>{const j=f.busyReason==="manual_self",y=t.has(f.udid),x=!!f.busy&&!j&&!y||!!f.offline,R=f.offline?"Offline":gt(f.busyReason),O=!x,T=[f.name??f.udid,f.platform&&fe(f.platform)].concat(x&&R?[R]:[]).filter(Boolean).join(", ");return r.jsx("li",{children:r.jsxs("button",{type:"button",disabled:x,draggable:!x,onDragStart:w=>{w.dataTransfer.effectAllowed="copy",w.dataTransfer.setData("application/x-xenon-udid",f.udid),w.dataTransfer.setData("text/plain",f.udid)},onClick:()=>n(f.udid),"aria-label":T,"aria-pressed":y,className:`w-full flex items-center gap-2 px-2 py-1.5 rounded text-left border transition-colors ${x?"opacity-60 cursor-not-allowed border-transparent":y?"border-[rgb(var(--rgb-accent)/0.4)] bg-[rgb(var(--rgb-accent)/0.05)] hover:bg-[rgb(var(--rgb-accent)/0.1)]":"border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"}`,title:x?`${R} — release first`:y?"Click to remove from the grid":"Click to add to the grid (or drag to a cell)",children:[y?r.jsx(ze,{"aria-hidden":!0,size:14,className:"shrink-0 text-[var(--color-accent-soft)]"}):r.jsx(xe,{"aria-hidden":!0,size:14,className:"shrink-0 text-[var(--text-dim)]"}),r.jsx("span",{"aria-hidden":!0,className:`inline-block w-1.5 h-1.5 rounded-full ${f.offline?Y.offline:O?Y.available:Y.inUse}`}),r.jsx("span",{className:"font-medium flex-1 truncate text-[13px]",children:f.name??f.udid}),f.platform&&r.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded bg-[var(--surface-2)] text-[var(--text-dim)]",children:fe(f.platform)})]})},f.udid)})})]},l.id)}),i&&E.length===0&&r.jsxs("div",{className:"text-xs text-[var(--text-dim)] px-1 py-2",children:['No devices match "',i,'".']}),r.jsx("div",{className:"text-[10px] text-[var(--text-dim)] px-1 pt-2 flex items-center gap-3",children:xt.map(([l,v])=>r.jsxs("span",{className:"inline-flex items-center gap-1",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full inline-block ${v}`}),l]},l))})]})}const vt=[{id:"1",label:"1",icon:r.jsx(wt,{})},{id:"2x1",label:"2×1",icon:r.jsx(Et,{})},{id:"2x2",label:"2×2",icon:r.jsx(Nt,{})},{id:"3x2",label:"3×2",icon:r.jsx(Rt,{})},{id:"auto",label:"Auto",icon:r.jsx(St,{})}];function yt({value:e,onChange:t}){return r.jsx("div",{role:"tablist",className:"inline-flex border border-[var(--border)] rounded-md overflow-hidden text-xs bg-[rgb(var(--rgb-white)/0.02)]",children:vt.map(n=>{const o=e===n.id;return r.jsxs("button",{role:"tab","aria-selected":o,onClick:()=>t(n.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 border-r border-[var(--border)] last:border-r-0 transition-colors ${o?"bg-[var(--surface-2)] text-[rgb(var(--rgb-fg))]":"text-[var(--text-dim)] hover:bg-[var(--surface-2)] hover:text-[rgb(var(--rgb-fg))]"}`,title:`Layout: ${n.label}`,children:[r.jsx("span",{className:"w-3.5 h-3.5 inline-flex items-center justify-center",children:n.icon}),r.jsx("span",{children:n.label})]},n.id)})})}function B(e){return r.jsx("rect",{rx:1.2,ry:1.2,fill:"currentColor",...e})}function wt(){return r.jsx("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:B({x:2,y:2,width:10,height:10})})}function Et(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:[B({x:1.5,y:3,width:5,height:8}),B({x:7.5,y:3,width:5,height:8})]})}function Nt(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:[B({x:1.5,y:1.5,width:5,height:5}),B({x:7.5,y:1.5,width:5,height:5}),B({x:1.5,y:7.5,width:5,height:5}),B({x:7.5,y:7.5,width:5,height:5})]})}function Rt(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:[B({x:1,y:1.5,width:3.3,height:5}),B({x:5.35,y:1.5,width:3.3,height:5}),B({x:9.7,y:1.5,width:3.3,height:5}),B({x:1,y:7.5,width:3.3,height:5}),B({x:5.35,y:7.5,width:3.3,height:5}),B({x:9.7,y:7.5,width:3.3,height:5})]})}function St(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",children:[r.jsx("rect",{x:"2",y:"2",width:"10",height:"10",rx:"1.5"}),r.jsx("circle",{cx:"7",cy:"7",r:"1.5",fill:"currentColor",stroke:"none"})]})}function jt(e,t,n,o,i,g,u=!1){const N=Ye(n.width,n.height,g);let p=(e-n.left-N.left)/N.width,E=(t-n.top-N.top)/N.height;return!(p>=0&&p<=1&&E>=0&&E<=1)&&!u?null:(p=Math.min(1,Math.max(0,p)),E=Math.min(1,Math.max(0,E)),{x:Math.round(p*o),y:Math.round(E*i)})}const Tt=5e3;function Ct(e,t){if(e.httpStatus===404)return{ended:!0,startedAt:t};if(e.httpStatus!==200)return{ended:!1,startedAt:t};const n=e.body??{};return n.status!=="running"?{ended:!0,startedAt:t}:t&&n.startedAt&&n.startedAt!==t?{ended:!0,startedAt:t}:{ended:!1,startedAt:t??n.startedAt}}function At(e,t,n,o=Tt){const i=d.useRef(n);i.current=n,d.useEffect(()=>{if(!t)return;let g=!1,u=!1,N;const p=async()=>{if(!(u||g)){u=!0;try{const l=await fetch(`/xenon/api/control/${encodeURIComponent(e)}/stream/status`),v=l.ok?await l.json().catch(()=>{}):void 0;if(g)return;const f=Ct({httpStatus:l.status,body:v},N);N=f.startedAt,f.ended&&(g=!0,i.current())}catch{}finally{u=!1}}};p();const E=setInterval(p,o);return()=>{g=!0,clearInterval(E)}},[e,t,o])}const Dt=3,It=45e3,he=[2e3,5e3,1e4];function _t(e){const t=Math.max(0,Math.min(e,he.length-1));return he[t]}function kt(e){return e<Dt}function pe(e){var n;const t=(e.lastError||"").toLowerCase();if(/did not find test app|not installed|webdriveragentrunner|applicationverification/.test(t))return"WebDriverAgent is not installed on this device. Install and trust WDA, then retry.";if(/unsupported ios version|manualpairingtunnelstart/.test(t))return"This device’s iOS version is not supported for live streaming on this host.";if(/port range for purpose 'tunnel' is exhausted/.test(t))return"No free tunnel ports on this host (12100–12199 are in use). Stop another iPhone’s preview, then retry.";if(/go-ios tunnel .* exited before it was ready/.test(t)){const o=(n=/exited before it was ready \([^)]*\): (.+)$/.exec(e.lastError||""))==null?void 0:n[1];return`The device tunnel stopped while starting${o?` (go-ios: ${o.trim()})`:""}. Retry; if it keeps failing, unlock the iPhone and check it trusts this Mac.`}return/go-ios tunnel .* came up on port/.test(t)?"The device tunnel started on an unexpected port and was stopped. Retry.":/econnrefused|econnreset|connection reset|tunnel/.test(t)?"Lost the connection to the device tunnel. Reconnect the device, then retry.":e.lastError&&e.lastError.trim()?e.lastError.trim():"We couldn’t start the live stream for this device."}function Ot(e){for(let t=0;t+4<e.length;t++){const n=e[t]===0&&e[t+1]===0&&e[t+2]===0&&e[t+3]===1,o=e[t]===0&&e[t+1]===0&&e[t+2]===1;if(!n&&!o)continue;const i=t+(n?4:3);if((e[i]&31)===7){const g=u=>u.toString(16).padStart(2,"0");return`avc1.${g(e[i+1])}${g(e[i+2])}${g(e[i+3])}`}}return"avc1.42e01e"}const $t=({wsUrl:e,onFatal:t,onReady:n,onFrameSize:o,className:i})=>{const g=d.useRef(null),u=d.useRef(t);u.current=t;const N=d.useRef(n);N.current=n;const p=d.useRef(o);return p.current=o,d.useEffect(()=>{var T;const E=window,l=g.current;if(typeof E.VideoDecoder>"u"||!l){(T=u.current)==null||T.call(u);return}const v=l.getContext("2d");let f=!1,j=!1,y=!0,x=0;const R=new E.VideoDecoder({output:w=>{var C,$;if(f){w.close();return}(l.width!==w.displayWidth||l.height!==w.displayHeight)&&(l.width=w.displayWidth,l.height=w.displayHeight,(C=p.current)==null||C.call(p,w.displayWidth,w.displayHeight)),v==null||v.drawImage(w,0,0),w.close(),y&&(y=!1,($=N.current)==null||$.call(N))},error:()=>{var w;return(w=u.current)==null?void 0:w.call(u)}}),O=new WebSocket(e);return O.binaryType="arraybuffer",O.onerror=()=>{var w;return(w=u.current)==null?void 0:w.call(u)},O.onclose=()=>{var w;f||(w=u.current)==null||w.call(u)},O.onmessage=w=>{var m;const C=w.data,$=new DataView(C).getUint8(0),V=new Uint8Array(C,1);if($===0){if(j)return;try{R.configure({codec:Ot(V),optimizeForLatency:!0}),j=!0}catch{(m=u.current)==null||m.call(u)}return}if(!(!j||R.state!=="configured"))try{R.decode(new E.EncodedVideoChunk({type:$===1?"key":"delta",timestamp:x,data:V})),x+=11111}catch{}},()=>{f=!0;try{O.close()}catch{}try{R.state!=="closed"&&R.close()}catch{}}},[e]),r.jsx("canvas",{ref:g,className:i,style:{width:"100%",height:"100%",objectFit:"contain",display:"block"}})};function Mt(e,t,n){return(e==="android"||e==="androidtv"||e==="android-tv")&&t==="h264"&&n?"h264":"mjpeg"}const Pt=10,Lt=500;function Bt({udid:e,name:t,recordingId:n,annotateMode:o,shape:i,color:g,aspect:u="9 / 16",screenWidth:N,screenHeight:p,platform:E,onAnnotation:l,overlayAnnotations:v,onOverlayAnnotationsChange:f,onRemove:j}){const[y,x]=d.useState("connecting"),[R,O]=d.useState(),T=d.useCallback((a,h)=>{if(!(a>0)||!(h>0))return;const _=a/h;O(k=>k!==void 0&&Math.abs(k-_)<.001?k:_)},[]),[w,C]=d.useState(0),[$,V]=d.useState(null),m=d.useRef(0),s=d.useRef(null),[c,b]=d.useState(""),[S,H]=d.useState([]),[U,M]=d.useState(!1),z=d.useRef(null),W=d.useRef(null),P=E==="android"||E==="androidtv"||E==="android-tv",A=E==="ios"||E==="tvos";d.useEffect(()=>{let a=!1;if(n){V(null),x("connecting"),C(Date.now()),D.startStream(e).catch(()=>{});return}const h=typeof window.VideoDecoder<"u";return(async()=>{try{const _=encodeURIComponent(e),k=await fetch(`/xenon/api/control/${_}/stream/status`);if(!k.ok)return;const I=await k.json();if(Mt(E||"",I==null?void 0:I.type,h)!=="h264"||!(I!=null&&I.h264Path))return;const G=await fetch(`/xenon/api/control/${_}/stream/ticket`,{method:"POST"});if(!G.ok)return;const{ticket:L}=await G.json();if(a||!L)return;const Z=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}${I.h264Path}?ticket=${encodeURIComponent(L)}`;V(Z)}catch{}})(),()=>{a=!0}},[e,E,n]);const F=!o&&!!N&&!!p,re=(a,h,_,k=!1)=>jt(a,h,_,N,p,R,k),Re=(a,h,_)=>{const k=Date.now()+Math.random(),I=a-_.left,G=h-_.top;H(L=>[...L,{id:k,x:I,y:G}]),window.setTimeout(()=>{H(L=>L.filter(q=>q.id!==k))},500)},Se=a=>{if(!F||y==="unavailable"||a.button!==0)return;const h=a.currentTarget;h.focus(),re(a.clientX,a.clientY,h.getBoundingClientRect())&&(h.setPointerCapture(a.pointerId),W.current={startX:a.clientX,startY:a.clientY,startTime:Date.now(),rect:h.getBoundingClientRect()},Re(a.clientX,a.clientY,W.current.rect))},je=async a=>{var Z,ce;const h=W.current;if(W.current=null,!h||!F)return;try{a.currentTarget.releasePointerCapture(a.pointerId)}catch{}const _=a.clientX-h.startX,k=a.clientY-h.startY,I=Math.hypot(_,k),G=Date.now()-h.startTime,L=re(h.startX,h.startY,h.rect,!0),q=I<Pt;try{if(q&&G<Lt)await D.tap(e,L.x,L.y);else if(q)await((ce=(Z=D).touchAndHold)==null?void 0:ce.call(Z,e,L.x,L.y,G));else{const Q=re(a.clientX,a.clientY,h.rect,!0);await D.swipe(e,L.x,L.y,Q.x,Q.y)}}catch(Q){console.error(`[DeviceTile] gesture failed for ${e}`,Q)}},Te=()=>{W.current=null},Ce=async a=>{if(!F||y==="unavailable"||a.metaKey||a.ctrlKey||a.altKey)return;const h=a.key;try{if(h.length===1){a.preventDefault(),await D.typeText(e,h);return}if(h==="Backspace"){a.preventDefault(),P?await D.pressKey(e,67):await D.typeText(e,"\b");return}if(h==="Enter"){a.preventDefault(),P?await D.pressKey(e,66):await D.typeText(e,`
2
- `);return}if(h==="Tab"){a.preventDefault(),await D.typeText(e," ");return}h==="Escape"&&P&&(a.preventDefault(),await D.pressKey(e,ee.BACK))}catch(_){console.error(`[DeviceTile] keystroke "${h}" failed for ${e}`,_)}},Ae=()=>D.pressKey(e,P?ee.HOME:Ke.HOME).catch(a=>console.error(`[DeviceTile] home failed for ${e}`,a)),De=()=>D.pressKey(e,ee.BACK).catch(a=>console.error(`[DeviceTile] back failed for ${e}`,a)),Ie=()=>D.pressKey(e,ee.APP_SWITCH).catch(a=>console.error(`[DeviceTile] app-switch failed for ${e}`,a)),_e=async()=>{try{const a=await D.getScreenshot(e),h=(a==null?void 0:a.screenshot)??(a==null?void 0:a.value)??a;if(!h)return;const _=await fetch(`data:image/png;base64,${h}`).then(G=>G.blob()),k=URL.createObjectURL(_),I=document.createElement("a");I.href=k,I.download=`${t||e}-${Date.now()}.png`,document.body.appendChild(I),I.click(),I.remove(),setTimeout(()=>URL.revokeObjectURL(k),1e3)}catch(a){console.error(`[DeviceTile] screenshot failed for ${e}`,a)}};d.useEffect(()=>{console.log(`[DeviceTile] Rendering ${e} in state: ${y}`)},[e,y]);const ke=`/xenon/api/control/${encodeURIComponent(e)}/stream?t=${w}`,ie=d.useCallback(async()=>{try{const a=await fetch(`/xenon/api/control/${encodeURIComponent(e)}/stream/status`);if(!a.ok)throw new Error(String(a.status));const h=await a.json();b(pe({lastError:h==null?void 0:h.lastError,status:h==null?void 0:h.status}))}catch{b(pe({}))}},[e]),ne=d.useCallback(()=>{const a=m.current;kt(a)?(m.current=a+1,s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{x("connecting"),C(Date.now())},_t(a))):(x("unavailable"),ie())},[ie]);d.useEffect(()=>{if(y!=="connecting")return;const a=setTimeout(ne,It);return()=>clearTimeout(a)},[y,w,ne]),At(e,y==="live"&&!$,()=>{console.warn(`[DeviceTile] MJPEG stream ended for ${e}; reconnecting`),x("connecting"),C(Date.now())}),d.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const Oe=()=>{s.current&&clearTimeout(s.current),m.current=0,b(""),x("connecting"),C(Date.now())},X=!!n,J=t||e.slice(0,16)+"…";return r.jsxs("div",{className:"flex items-stretch justify-center w-full h-full min-h-0 min-w-0 gap-2",children:[r.jsxs("div",{className:"theme-dark relative bg-[var(--black)] rounded-lg overflow-hidden border border-[var(--border)] group max-h-full max-w-full self-center",style:{aspectRatio:u,height:"100%"},children:[y==="connecting"&&r.jsxs("div",{role:"status","aria-live":"polite",className:"flex flex-col items-center justify-center gap-1 px-4 text-center bg-[rgb(var(--rgb-well)/0.8)] text-[var(--text-dim)] absolute inset-0 z-20 pointer-events-none",children:[r.jsx("div",{"aria-hidden":!0,className:"w-10 h-10 mb-3 border-4 border-[var(--border)] border-t-[var(--text-dim)] rounded-full animate-spin"}),r.jsx("div",{className:"font-semibold text-[var(--text)]",children:"Starting stream…"}),r.jsx("div",{className:"text-xs text-[var(--text-dim)] truncate max-w-full",children:J}),r.jsx("div",{className:"text-[11px] mt-3 text-[var(--text-dim)] leading-snug",children:A?"iPhone streams can take up to 20 seconds to start.":"Connecting to the device…"})]}),y==="unavailable"&&r.jsx("div",{role:"alert",className:"flex items-center justify-center bg-[var(--black)] text-[var(--text-dim)] absolute inset-0 z-20",children:r.jsxs("div",{className:"text-center p-6",children:[r.jsx(qe,{"aria-hidden":!0,size:36,className:"mx-auto mb-3 text-[var(--text-dim)]"}),r.jsx("div",{className:"font-semibold text-[var(--text)]",children:"Connection failed"}),r.jsx("p",{className:"text-xs mt-2 text-[var(--text-dim)] leading-relaxed max-w-[240px] mx-auto",children:c||"We couldn’t start the live stream for this device."}),r.jsx("button",{type:"button",className:"mt-5 text-sm font-semibold px-4 py-2 rounded bg-[var(--color-accent)] hover:bg-[var(--color-accent-strong)] text-[var(--color-on-accent)] transition-colors",onClick:Oe,children:"Retry"})]})}),$?r.jsx($t,{wsUrl:$,className:"absolute inset-0 w-full h-full object-contain bg-black select-none pointer-events-none",onReady:()=>x("live"),onFrameSize:T,onFatal:()=>{console.warn(`[DeviceTile] H.264 fatal for ${e}; falling back to MJPEG`),V(null),x("connecting"),C(Date.now())}}):r.jsx(Ue,{src:ke,alt:J,className:"absolute inset-0 w-full h-full object-contain bg-black select-none pointer-events-none",draggable:!1,style:{opacity:y==="live"?1:0,transition:"opacity 0.3s ease-in-out"},onLoad:a=>{console.log(`[DeviceTile] Image LOADED for ${e}`),T(a.currentTarget.naturalWidth,a.currentTarget.naturalHeight),m.current=0,s.current&&clearTimeout(s.current),x("live")},onError:a=>{console.error(`[DeviceTile] Image ERROR for ${e}`,a),ne()}},w),F&&y!=="unavailable"&&r.jsx("div",{ref:z,className:`absolute inset-0 z-[35] touch-none outline-none ${U?"ring-2 ring-[rgb(var(--rgb-accent)/0.6)] ring-inset rounded-lg":""}`,tabIndex:0,onPointerDown:Se,onPointerUp:je,onPointerCancel:Te,onKeyDown:Ce,onFocus:()=>M(!0),onBlur:()=>M(!1)}),r.jsx("div",{className:"absolute inset-0 z-20 pointer-events-none overflow-hidden",children:S.map(a=>r.jsx("span",{className:"absolute block w-10 h-10 rounded-full border-2 border-[var(--color-accent-soft)] animate-ping",style:{left:a.x-20,top:a.y-20}},a.id))}),X&&r.jsx(Xe,{enabled:o,shape:i,color:g,committed:v,mediaAspect:R,onCommittedChange:f,onCommit:(a,h)=>l(n,a,h)}),X&&o&&y==="live"&&r.jsx("div",{className:"absolute top-3 left-14 right-3 z-30 flex justify-end pointer-events-none",children:r.jsx("span",{className:"px-2 py-0.5 rounded-sm bg-[var(--color-info)] text-white text-[10px] font-semibold shadow-lg whitespace-nowrap overflow-hidden text-ellipsis",children:"Annotating · Esc to stop"})}),X&&r.jsx("div",{className:"absolute top-3 left-3 z-30 pointer-events-none",children:r.jsx("span",{className:"px-2 py-0.5 rounded-sm bg-[var(--red-600)] text-white text-[9px] font-black shadow-lg",children:"REC"})}),r.jsxs("div",{className:"absolute top-3 left-3 z-30 flex flex-col gap-1.5 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-150",children:[y==="live"&&r.jsx("span",{className:"px-2 py-0.5 rounded-sm bg-[var(--color-success)] text-[var(--color-on-success)] text-[11px] font-semibold shadow-lg w-fit",children:"Live"}),r.jsx("span",{className:"px-2 py-1 rounded bg-[rgb(var(--rgb-well)/0.8)] text-[var(--text)] text-[11px] font-medium backdrop-blur-md border border-[rgb(var(--rgb-fg)/0.1)] shadow-xl truncate max-w-[180px]",children:J})]})]}),r.jsx(Ht,{streamState:y,recording:X,isIOS:A,isAndroid:P,onClose:!X&&j?()=>j(e):void 0,sendHome:Ae,sendBack:De,sendAppSwitch:Ie,captureScreenshot:_e,displayName:J})]})}const te="w-7 h-7 flex items-center justify-center rounded-md hover:bg-[var(--surface-2)] hover:text-[var(--text)] transition-colors";function Ht({streamState:e,recording:t,isIOS:n,isAndroid:o,onClose:i,sendHome:g,sendBack:u,sendAppSwitch:N,captureScreenshot:p,displayName:E}){const l=e==="live";return!i&&!l?null:r.jsxs("div",{className:"self-stretch w-9 flex flex-col items-center justify-between gap-1 py-2 rounded-lg bg-[var(--surface)] border border-[var(--border)] text-[var(--text-dim)]",children:[r.jsx("div",{className:"flex flex-col items-center gap-1",children:i&&r.jsx("button",{type:"button","aria-label":`Remove ${E}`,title:"Remove from the grid",onClick:i,className:"w-7 h-7 flex items-center justify-center rounded-md hover:bg-[rgb(var(--rgb-red)/0.15)] hover:text-[var(--color-danger)] transition-colors",children:r.jsx(Pe,{"aria-hidden":!0,size:16})})}),l&&r.jsxs("div",{className:"flex flex-col items-center gap-1.5 my-auto",children:[(o||n)&&r.jsx("button",{type:"button","aria-label":"Home",title:"Home",onClick:g,className:te,children:r.jsx(Fe,{"aria-hidden":!0,size:15})}),o&&r.jsx("button",{type:"button","aria-label":"Back",title:"Back",onClick:u,className:te,children:r.jsx(Je,{"aria-hidden":!0,size:16})}),o&&r.jsx("button",{type:"button","aria-label":"Recent apps",title:"Recent apps",onClick:N,className:te,children:r.jsx(be,{"aria-hidden":!0,size:13})})]}),l&&r.jsx("div",{className:"flex flex-col items-center gap-1",children:r.jsx("button",{type:"button","aria-label":"Screenshot",title:"Screenshot",onClick:p,className:te,children:r.jsx(Ge,{"aria-hidden":!0,size:15})})})]})}const Wt={1:"1fr","2x1":"1fr 1fr","2x2":"1fr 1fr","3x2":"1fr 1fr 1fr"},Vt={1:"1fr","2x1":"1fr","2x2":"1fr 1fr","3x2":"1fr 1fr"},zt={1:1,"2x1":2,"2x2":4,"3x2":6};function Ut({layout:e,tiles:t,annotateMode:n,shape:o,color:i,onAnnotation:g,overlayAnnotationsByRecording:u,onOverlayAnnotationsChange:N,onRemove:p,onDropDevice:E}){const l=dt(e,t.length),v=zt[l];t.length;const f=t.length,j=e==="auto"?Math.max(f,1):v,y=Math.max(0,j-f);return r.jsxs("div",{style:{display:"grid",gap:8,gridTemplateColumns:Wt[l],gridTemplateRows:Vt[l]},className:"h-full",children:[t.map(x=>r.jsx(Bt,{udid:x.udid,name:x.name,mjpegPort:x.mjpegPort,recordingId:x.recordingId,aspect:x.aspect,screenWidth:x.screenWidth,screenHeight:x.screenHeight,platform:x.platform,annotateMode:n,shape:o,color:i,overlayAnnotations:x.recordingId?u==null?void 0:u[x.recordingId]:void 0,onOverlayAnnotationsChange:x.recordingId&&N?R=>N(x.recordingId,R):void 0,onAnnotation:g,onRemove:p},x.udid)),Array.from({length:y},(x,R)=>r.jsx(Ft,{onDropDevice:E},`empty-${R}`))]})}function Ft({onDropDevice:e}){const[t,n]=d.useState(!1);return r.jsxs("div",{onDragOver:o=>{e&&(o.preventDefault(),o.dataTransfer.dropEffect="copy",t||n(!0))},onDragLeave:()=>n(!1),onDrop:o=>{if(n(!1),!e)return;o.preventDefault();const i=o.dataTransfer.getData("application/x-xenon-udid")||o.dataTransfer.getData("text/plain");i&&e(i)},className:`flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed transition-colors ${t?"border-[rgb(var(--rgb-accent)/0.6)] bg-[rgb(var(--rgb-accent)/0.05)]":"border-[var(--border)] bg-[rgb(var(--rgb-fg)/0.02)]"} text-[var(--text-dim)] min-h-[120px]`,children:[r.jsx("div",{"aria-hidden":"true",className:`w-8 h-8 rounded-full flex items-center justify-center ${t?"bg-[rgb(var(--rgb-accent)/0.15)] text-[var(--color-accent-soft)]":"bg-[rgb(var(--rgb-fg)/0.05)] text-[rgb(var(--rgb-fg)/0.6)]"}`,children:r.jsx(Ze,{size:16})}),r.jsx("div",{className:"text-xs font-medium",children:"Drag a device here"}),r.jsx("div",{className:"text-[10px] opacity-70",children:"or click one in the list"})]})}function Gt(e,t){return t==="starting"?"Starting…":e<=1?"Record":`Record ${e} devices`}const K={"aria-hidden":!0,size:14,className:"shrink-0"};function Kt({selectedUdids:e,onClearMarks:t}){const{state:n,dispatch:o}=ht(),[i,g]=d.useState(()=>Date.now());d.useEffect(()=>{if(n.recordingPhase!=="recording"&&n.recordingPhase!=="stopping")return;g(Date.now());const m=window.setInterval(()=>g(Date.now()),250);return()=>window.clearInterval(m)},[n.recordingPhase]);const u=n.startedAt&&(n.recordingPhase==="recording"||n.recordingPhase==="stopping")?i-n.startedAt:0,N=n.recordingPhase==="starting"||n.recordingPhase==="stopping",p=n.recordingPhase==="idle"&&e.length>0&&!N,E=n.recordingPhase==="recording"||n.recording&&n.tiles.some(m=>!!m.recordingId),l=E&&!N,v=l,f=v&&n.annotateMode,j=!!n.groupId&&n.recordingPhase==="idle",y=e.length>1||n.downloadableVideoCount>1,x=j&&n.compositeEnabled,R=j&&!n.compositeEnabled&&(n.downloadableVideoCount===1||n.downloadableVideoCount===0&&e.length<=1),O=async()=>{var m;if(p){o({type:"SET_RECORDING_PHASE",phase:"starting"}),o({type:"SET_BANNER",banner:null});try{const s=await nt(e);if(!((m=s.recordings)!=null&&m.length)){o({type:"SET_RECORDING_PHASE",phase:"idle"}),o({type:"SET_BANNER",banner:{tone:"error",message:"Recording did not start. Check that live preview is working, then try again."}});return}const c={};for(const S of s.recordings)c[S.udid]=S.id;const b=e.length-s.recordings.length;o({type:"START_RECORDING",groupId:s.groupId,startedAt:Date.now(),tileIds:c,compositeEnabled:s.compositeEnabled===!0}),b>0?o({type:"SET_BANNER",banner:{tone:"error",message:`Recording started on ${s.recordings.length} of ${e.length} devices (${b} failed).`}}):o({type:"SET_BANNER",banner:null})}catch(s){if(o({type:"SET_RECORDING_PHASE",phase:"idle"}),s instanceof ot)if(s.body.error==="device_busy"){const c=(s.body.busyDevices??[]).map(b=>`${b.udid} (${b.reason})`).join(", ");o({type:"SET_BANNER",banner:{tone:"error",message:`Cannot start — these devices are busy: ${c}`}})}else o({type:"SET_BANNER",banner:{tone:"error",message:`Server-wide recording cap reached (${s.body.active}/${s.body.limit}).`}});else o({type:"SET_BANNER",banner:{tone:"error",message:`Recording failed: ${s.message}`}})}}},T=async()=>{if(!(!n.groupId||n.recordingPhase!=="recording")){o({type:"SET_RECORDING_PHASE",phase:"stopping"});try{const m=await st(n.groupId),s=(m.recordings??[]).filter(b=>b.status==="STOPPED"&&(b.sizeBytes??0)>=1024),c=(m.recordings??[]).filter(b=>b.status!=="STOPPED");o({type:"STOP_RECORDING",downloadableVideoCount:s.length,compositeEnabled:n.compositeEnabled}),s.length===0?o({type:"SET_BANNER",banner:{tone:"error",message:c.length>0?`Recording failed on ${c.length} device(s). Nothing to download.`:"Recording stopped but no playable video was produced."}}):c.length>0?o({type:"SET_BANNER",banner:{tone:"info",message:`${s.length} ready, ${c.length} failed. Download with the button above.`}}):o({type:"SET_BANNER",banner:{tone:"info",message:s.length===1?"Video ready. Download it with the button above.":`${s.length} videos ready. Download them with the button above.`}})}catch(m){o({type:"STOP_RECORDING"}),o({type:"SET_BANNER",banner:{tone:"error",message:`Stop failed: ${m.message}`}})}}},w=m=>{const s=m==="annotate";s&&!v||s!==n.annotateMode&&o({type:"SET_ANNOTATE_MODE",enabled:s})};d.useEffect(()=>{if(!n.annotateMode)return;const m=s=>{var b;if(s.key!=="Escape"||s.repeat)return;const c=s.target;c&&((b=c.closest)!=null&&b.call(c,"input, textarea, select")||c.isContentEditable)||o({type:"SET_ANNOTATE_MODE",enabled:!1})};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[n.annotateMode,o]);const C=()=>{v&&t()},$=Object.values(n.overlayAnnotations).some(m=>((m==null?void 0:m.length)??0)>0),V=[{id:"RECT",label:"Rect"},{id:"CIRCLE",label:"Circle"},{id:"ARROW",label:"Arrow"},{id:"FREEHAND",label:"Draw"}];return r.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-end",children:[n.recordingPhase==="recording"||n.recordingPhase==="stopping"?r.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded text-xs font-mono tabular-nums bg-[rgb(var(--rgb-red-600)/0.2)] text-[var(--red-200)] border border-[rgb(var(--rgb-red)/0.4)]",title:"Recording elapsed time",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-[var(--red)] animate-pulse"}),"REC ",mt(u),n.recordingPhase==="stopping"?" · Stopping…":""]}):r.jsxs("button",{type:"button",onClick:O,disabled:!p,title:e.length===0?"Add a device to the grid first":"Record every device on the grid",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-[var(--red-600)] text-white disabled:opacity-40 disabled:cursor-not-allowed light:disabled:bg-transparent light:disabled:text-[var(--text)] light:disabled:ring-1 light:disabled:ring-inset light:disabled:ring-[color:var(--border)]",children:[r.jsx(xe,{...K,size:10,fill:"currentColor"}),Gt(e.length,n.recordingPhase)]}),r.jsxs("button",{type:"button",onClick:T,disabled:!l,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(be,{...K,size:12}),n.recordingPhase==="stopping"?"Stopping…":"Stop"]}),r.jsx(Qe,{size:"sm",value:n.annotateMode?"annotate":"interact",onChange:w,segments:[{value:"interact",label:"Interact",title:"Tap, swipe and type on the devices (Esc)",keyShortcuts:"Escape"},{value:"annotate",label:"Annotate",title:v?"Draw marks on the recording":"Start recording to annotate",disabled:!v}]}),E&&r.jsxs("div",{className:"flex items-center gap-1 ml-1 pl-2 border-l border-[var(--border)]",children:[V.map(m=>r.jsx("button",{type:"button",disabled:!f,"aria-pressed":n.shape===m.id,onClick:()=>o({type:"SET_SHAPE",shape:m.id}),className:`px-2 py-1 text-xs rounded border disabled:opacity-40 disabled:cursor-not-allowed ${n.shape===m.id?"bg-[var(--surface-2)] border-[var(--color-info)] text-[rgb(var(--rgb-fg))]":"border-[var(--border)] opacity-80 hover:opacity-100"}`,children:m.label},m.id)),r.jsx("input",{type:"color",value:n.color,disabled:!f,onChange:m=>o({type:"SET_COLOR",color:m.target.value}),title:"Annotation color","aria-label":"Annotation color",className:"w-7 h-7 rounded border border-[var(--border)] bg-transparent cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed"}),r.jsx("button",{type:"button",onClick:C,disabled:!v||!$,title:"Clear marks from the preview and the recording",className:"px-2 py-1 text-xs rounded border border-[var(--border)] hover:bg-[var(--surface-2)] disabled:opacity-40 disabled:cursor-not-allowed",children:"Clear marks"})]}),j&&R&&r.jsxs("a",{href:et(n.groupId),className:"ml-1 inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",download:!0,children:[r.jsx(oe,{...K}),"Download video"]}),j&&!R&&r.jsxs("a",{href:tt(n.groupId),className:"ml-1 inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",download:`videos-${n.groupId}.zip`,title:"ZIP of mp4 files only (no JSON extras)",children:[r.jsx(oe,{...K}),"Download ",y?"videos":"video"]}),x&&r.jsxs("a",{href:rt(n.groupId),className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",download:`side-by-side-${n.groupId}.mp4`,title:"All devices in one side-by-side video",children:[r.jsx(oe,{...K}),"Side-by-side"]}),j&&n.groupId&&r.jsxs(Le,{to:`/recordings/${encodeURIComponent(n.groupId)}`,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",children:[r.jsx(Be,{...K}),"Open in Recordings"]})]})}function Yt({remainingSec:e,onContinue:t,onReleaseNow:n}){return r.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"idle-warning-title",className:"fixed inset-0 z-40 bg-black/60 flex items-center justify-center",children:r.jsxs("div",{className:"bg-[var(--bg)] border border-[var(--border)] rounded-lg w-full max-w-md p-6",children:[r.jsx("h3",{id:"idle-warning-title",className:"text-base font-semibold mb-2",children:"Are you still there?"}),r.jsxs("p",{className:"text-sm text-[var(--text-dim)] mb-4",children:["Your devices will be released in"," ",r.jsxs("span",{className:"text-[var(--text)] font-mono font-semibold",children:[e,"s"]})," due to inactivity. Click ",r.jsx("strong",{children:"Continue Session"})," to keep them locked."]}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{type:"button",onClick:n,className:"h-9 px-3 rounded-md border border-[var(--border)] text-sm text-[var(--text-dim)] hover:text-[var(--text)]",children:"Release now"}),r.jsx("button",{type:"button",autoFocus:!0,onClick:t,className:"h-9 px-4 rounded-md bg-[var(--color-accent)] text-[var(--color-on-accent)] text-sm font-medium",children:"Continue session"})]})]})})}function Xt({message:e,onRestore:t,onDismiss:n}){return r.jsxs("div",{role:"status",className:"text-sm rounded border border-[var(--border)] bg-[var(--surface-2)] text-[var(--text)] px-3 py-2 flex items-center gap-2",children:[r.jsx(ct,{"aria-hidden":!0,size:14,className:"shrink-0 text-[var(--text-dim)]"}),r.jsx("span",{className:"flex-1",children:e}),t&&r.jsx(de,{variant:"tonal",size:"sm",onClick:t,children:"Restore devices"}),r.jsx(de,{variant:"ghost",size:"sm",onClick:n,children:"Dismiss"})]})}function we(e){var t;return((t=e.marketingName)==null?void 0:t.trim())||e.name||e.udid}function Ee(e){if(!e)return"9 / 16";const t=Number(e.screenWidth),n=Number(e.screenHeight);if(Number.isFinite(t)&&Number.isFinite(n)&&t>0&&n>0)return`${t} / ${n}`;const o=(e.platform||"").toLowerCase();return o==="tvos"||o==="androidtv"||o==="android-tv"?"16 / 9":"9 / 16"}function se(e){const t=Number(e.screenWidth),n=Number(e.screenHeight);return{udid:e.udid,name:we(e),mjpegPort:0,aspect:Ee(e),screenWidth:Number.isFinite(t)&&t>0?t:void 0,screenHeight:Number.isFinite(n)&&n>0?n:void 0,platform:e.platform}}function qt(e,t){return t?"blocked":e?"remove":"add"}function ae(e,t,n){return!n||!e?!1:e===`manual_${n}_${t}`}function Jt(e,t){if(!e.busy)return;const n=ve(e);return n?n.startsWith("manual_")?ae(n,e.udid,t)?"manual_self":"manual_other":"automation":"unknown"}function Zt(e,t){return e.busy?ae(ve(e),e.udid,t):!1}function Qt(e,t){return e>0&&t==="idle"}function er(e,t,n){const o=[],i=[];for(const g of e){const u=t.find(p=>p.udid===g.udid),N=(u==null?void 0:u.name)||g.name||g.udid;u?u.offline?i.push({name:N,reason:"offline"}):u.busy&&!ae(u.session_id,u.udid,n)?i.push({name:N,reason:"in_use"}):o.push(u):i.push({name:N,reason:"gone"})}return{restore:o,skipped:i}}const Ne=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function tr(e,t){return`Released ${Ne(e,"device")} after ${t} minutes without activity.`}const rr={in_use:"is now in use by someone else.",offline:"is offline.",gone:"is no longer connected."};function nr(e,t){return t.length===0?null:[e>0?`Restored ${Ne(e,"device")}.`:"No devices restored.",...t.map(o=>`${o.name} ${rr[o.reason]}`)].join(" ")}function or(){let e=Promise.resolve();return{enqueue(t){const n=e.then(t,t);return e=n.then(()=>{},()=>{}),n}}}const me=["mousemove","mousedown","keydown","touchstart","wheel"];function sr({idleAfterMs:e,warningSec:t,onWarning:n,onTimeout:o,enabled:i}){const[g,u]=d.useState(!1),[N,p]=d.useState(null),E=d.useRef(null),l=d.useRef(null),v=d.useRef(!1),f=d.useRef(n),j=d.useRef(o);f.current=n,j.current=o;function y(){E.current&&(clearTimeout(E.current),E.current=null),l.current&&(clearInterval(l.current),l.current=null)}function x(){v.current=!0,u(!0),p(t),f.current(t);let T=t;l.current=setInterval(()=>{T-=1,T<=0?(y(),v.current=!1,u(!1),p(null),j.current()):p(T)},1e3)}function R(){y(),v.current=!1,u(!1),p(null);const T=e-t*1e3;E.current=setTimeout(x,Math.max(0,T))}function O(){i&&R()}return d.useEffect(()=>{if(!i){y(),v.current=!1,u(!1),p(null);return}function T(){v.current||R()}return me.forEach(w=>window.addEventListener(w,T,{passive:!0})),R(),()=>{me.forEach(w=>window.removeEventListener(w,T)),y()}},[i,e,t]),{warning:g,remainingSec:N,reset:O}}const ge=5*60*1e3,ar=30;function ir(e,t){return{udid:e.udid,name:we(e),altName:e.name,platform:e.platform,busy:e.busy,busyReason:Jt(e,t),mjpegServerPort:e.mjpegServerPort,offline:!!e.offline}}function Nr(){const[e,t]=pt(),[n,o]=d.useState([]),[i,g]=d.useState("loading"),[u,N]=d.useState(0),[p,E]=d.useState(null),l=d.useRef(!1),v=d.useRef(or());d.useEffect(()=>{let s=!1;return fetch("/xenon/api/auth/me",{credentials:"include"}).then(c=>c.ok?c.json():null).then(c=>{!s&&(c!=null&&c.userId)&&E(c.userId)}).catch(()=>{}),()=>{s=!0}},[]),d.useEffect(()=>{let s=!1;const c=async()=>{try{const S=await D.getDevices();if(s)return;o(Array.isArray(S)?S:[]),g("ready")}catch{s||g("error")}};c();const b=window.setInterval(c,5e3);return()=>{s=!0,window.clearInterval(b)}},[u]),d.useEffect(()=>{let s=!1;if(!(!p||l.current))return l.current=!0,(async()=>{var S;let c=[],b=[];try{const H=await D.getDevices();c=Array.isArray(H)?H:[];const U=c.filter(z=>Zt(z,p));if(b=(await Promise.all(U.map(async z=>{try{const W=await fetch(`/xenon/api/control/${encodeURIComponent(z.udid)}/stream/status`);if(!W.ok)return null;const P=await W.json();return(P==null?void 0:P.status)==="running"?z:null}catch{return null}}))).filter(z=>z!==null).map(se),s)return;b.length>0&&t({type:"SET_TILES",tiles:b})}catch{}try{const{serverNow:H,groups:U}=await at(),M=U[0];if(s||!M)return;const z=new Set(b.map(A=>A.udid)),W=M.recordings.filter(A=>!z.has(A.udid)).map(A=>c.find(F=>F.udid===A.udid)).filter(A=>!!A).map(se);W.length>0&&t({type:"SET_TILES",tiles:[...b,...W]});const P={};for(const A of M.annotations){let F;try{F=JSON.parse(A.geometry)}catch{continue}(P[S=A.recordingId]??(P[S]=[])).push({shape:A.shape,color:A.color,geometry:F,text:A.text??void 0})}t({type:"REHYDRATE_RECORDING",groupId:M.groupId,startedAt:Date.now()-(H-Date.parse(M.startedAt)),tileIds:Object.fromEntries(M.recordings.map(A=>[A.udid,A.id])),compositeEnabled:M.compositeEnabled,overlayAnnotations:P})}catch{}})(),()=>{s=!0}},[p,t]),d.useEffect(()=>{for(const s of e.tiles){if(s.screenWidth&&s.screenHeight)continue;const c=n.find(H=>H.udid===s.udid);if(!c)continue;const b=Number(c.screenWidth),S=Number(c.screenHeight);Number.isFinite(b)&&b>0&&Number.isFinite(S)&&S>0&&t({type:"PATCH_TILE_DIMS",udid:s.udid,screenWidth:b,screenHeight:S,aspect:Ee(c)})}},[n,e.tiles,t]);const f=d.useMemo(()=>new Set(e.tiles.map(s=>s.udid)),[e.tiles]),j=d.useMemo(()=>n.map(s=>ir(s,p)),[n,p]),y=async s=>{t({type:"ADD_TILE",tile:se(s)});const c=await D.startStream(s.udid).catch(()=>null);We(c)&&t({type:"REMOVE_TILE",udid:s.udid})},x=async s=>{const c=qt(e.tiles.some(S=>S.udid===s),e.recording);if(c==="blocked"){t({type:"SET_ERROR_BANNER",message:"Stop recording before changing the devices on the grid."});return}if(c==="remove"){await R(s);return}const b=n.find(S=>S.udid===s);b&&await y(b)},R=async s=>{t({type:"REMOVE_TILE",udid:s});try{await fetch(`/xenon/api/control/${encodeURIComponent(s)}/stream/leave`,{method:"POST"})}catch{}N(c=>c+1)},O=(s,c,b)=>{if(!e.groupId)return;const S=e.groupId,H=e.startedAt?Date.now()-e.startedAt:0,U={recordingId:s,timecodeMs:H,shape:c.shape,geometry:JSON.stringify(c.geometry),color:c.color,text:c.text};v.current.enqueue(async()=>{try{return await le(S,b?{...U,image:b}:U)}catch(M){if(!b)throw M;return le(S,U)}}).catch(M=>t({type:"SET_ERROR_BANNER",message:`Annotation failed: ${M.message}`}))},T=()=>{if(!e.groupId)return;const s=e.groupId,c=e.startedAt?Date.now()-e.startedAt:0;t({type:"CLEAR_OVERLAY_ANNOTATIONS"}),v.current.enqueue(()=>it(s,c)).catch(()=>t({type:"SET_ERROR_BANNER",message:"Couldn't clear marks from the recording. They will still appear in the video."}))},w=()=>{for(const s of e.tiles){const c=`/xenon/api/control/${encodeURIComponent(s.udid)}/stream/leave`;try{navigator.sendBeacon?navigator.sendBeacon(c):fetch(c,{method:"POST",keepalive:!0}).catch(()=>{})}catch{}}e.tiles.forEach(s=>t({type:"REMOVE_TILE",udid:s.udid}))},[C,$]=d.useState(null),V=async()=>{const s=C==null?void 0:C.tiles;if(!s)return;const c=er(s,n,p);for(const S of c.restore)await y(S);const b=nr(c.restore.length,c.skipped);$(b?{message:b,tiles:null}:null),N(S=>S+1)},m=sr({idleAfterMs:ge,warningSec:ar,enabled:Qt(e.tiles.length,e.recordingPhase),onWarning:()=>{},onTimeout:()=>{const s=e.tiles;w(),$({message:tr(s.length,ge/6e4),tiles:s})}});return r.jsxs(ye.Provider,{value:{state:e,dispatch:t},children:[r.jsxs("div",{className:"flex flex-col h-full p-4 gap-3",children:[r.jsxs("header",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(lt,{icon:He,children:"Live devices"}),r.jsx(yt,{value:e.layout,onChange:s=>t({type:"SET_LAYOUT",layout:s})})]}),r.jsx(Kt,{selectedUdids:e.tiles.map(s=>s.udid),onClearMarks:T})]}),e.banner&&r.jsxs("div",{role:"alert",className:`text-sm rounded border px-3 py-2 flex items-center gap-2 ${e.banner.tone==="error"?"border-[rgb(var(--rgb-red)/0.4)] bg-[rgb(var(--rgb-red)/0.1)] text-[var(--red-100)]":"border-[rgb(var(--rgb-success)/0.4)] bg-[rgb(var(--rgb-success)/0.1)] text-[var(--text)]"}`,children:[r.jsx("span",{className:"flex-1",children:e.banner.message}),r.jsx("button",{type:"button",className:"text-xs opacity-80 hover:opacity-100",onClick:()=>t({type:"SET_BANNER",banner:null}),children:"Dismiss"})]}),C&&r.jsx(Xt,{message:C.message,onRestore:C.tiles&&!e.recording?V:void 0,onDismiss:()=>$(null)}),r.jsxs("div",{className:"grid grid-cols-[260px_1fr] gap-3 flex-1 min-h-0",children:[r.jsxs("aside",{className:"flex flex-col gap-2 border border-[var(--border)] rounded p-3 overflow-y-auto min-h-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs text-[var(--text-dim)]",children:"Devices"}),r.jsx("button",{className:"text-xs underline opacity-70 hover:opacity-100",onClick:()=>N(s=>s+1),children:"Refresh"})]}),r.jsx(bt,{devices:j,inMosaic:f,onToggle:x,status:i}),r.jsx("p",{className:"mt-2 text-[11px] text-[var(--text-dim)] leading-relaxed",children:"Click a device to add it to the grid. Record captures every device on the grid; after Stop, download the video."})]}),r.jsx("main",{className:"border border-[var(--border)] rounded p-2 overflow-y-auto h-full min-h-0",children:r.jsx(Ut,{layout:e.layout,tiles:e.tiles,annotateMode:e.annotateMode,shape:e.shape,color:e.color,overlayAnnotationsByRecording:e.overlayAnnotations,onOverlayAnnotationsChange:(s,c)=>t({type:"SET_OVERLAY_ANNOTATIONS",recordingId:s,annotations:c}),onAnnotation:O,onRemove:R,onDropDevice:x})})]})]}),m.warning&&m.remainingSec!==null&&r.jsx(Yt,{remainingSec:m.remainingSec,onContinue:m.reset,onReleaseNow:w})]})}export{Nr as default};
1
+ import{r as d,j as r,z as $e,w as Me,X as D,v as Pe,e as Le,Y as Be,T as He,Z as We}from"./index-EkaQM1DK.js";import{p as Ve}from"./labels-C21SA4JG.js";import{C as ze}from"./circle-check-CfP79QE2.js";import{C as xe,M as Ue,A as ee,H as Fe,a as Ge,S as be,b as Ke,I as Ye,h as ve}from"./keycodes-BhbgeW_r.js";import{f as Xe,A as qe}from"./AnnotationOverlay-LzfXiiZJ.js";import{V as Je}from"./video-off-eh69-FKB.js";import{P as Ze}from"./plus-BGvWvpBB.js";import{a as Qe}from"./SegmentedControl-BFW9Dlqd.js";import{v as et,a as tt,c as rt,s as nt,R as ot,b as st,g as at,d as le,e as it}from"./recordings-BWe1ydXm.js";import{D as oe}from"./download-CGz-MS3y.js";import{B as de}from"./button-WW9j43wR.js";import{C as ct}from"./clock-BuTm35Qg.js";import{a as lt}from"./page-header-DoD3TOzZ.js";import"./utils-CDN07tui.js";function dt(e,t){return e!=="auto"?e:t<=1?"1":t===2?"2x1":t<=4?"2x2":"3x2"}const ut={selected:new Set,layout:"auto",tiles:[],groupId:null,compositeEnabled:!1,downloadableVideoCount:0,recordingPhase:"idle",recording:!1,startedAt:null,annotateMode:!1,shape:"RECT",color:"#ff3333",overlayAnnotations:{},errorBanner:null,banner:null};function ft(e,t){var n;switch(t.type){case"SET_LAYOUT":return{...e,layout:t.layout};case"TOGGLE_SELECTED":{const o=new Set(e.selected);return o.has(t.udid)?o.delete(t.udid):o.add(t.udid),{...e,selected:o}}case"CLEAR_SELECTED":return{...e,selected:new Set};case"SET_TILES":return{...e,tiles:t.tiles};case"ADD_TILE":return e.tiles.some(o=>o.udid===t.tile.udid)?e:{...e,tiles:[...e.tiles,t.tile]};case"PATCH_TILE_DIMS":{let o=!1;const i=e.tiles.map(g=>g.udid!==t.udid||g.screenWidth&&g.screenHeight?g:(o=!0,{...g,screenWidth:t.screenWidth,screenHeight:t.screenHeight,aspect:t.aspect??g.aspect}));return o?{...e,tiles:i}:e}case"REMOVE_TILE":return e.recordingPhase!=="idle"?e:{...e,tiles:e.tiles.filter(o=>o.udid!==t.udid)};case"BIND_RECORDING_IDS":{const o=e.tiles.map(i=>({...i,recordingId:t.map[i.udid]??i.recordingId}));return{...e,tiles:o}}case"SET_RECORDING_PHASE":{const o=t.phase;return{...e,recordingPhase:o,recording:o==="recording"||o==="stopping"}}case"START_RECORDING":{const o=e.tiles.map(i=>({...i,recordingId:t.tileIds[i.udid]??i.recordingId}));return{...e,groupId:t.groupId,compositeEnabled:t.compositeEnabled===!0,downloadableVideoCount:0,recordingPhase:"recording",recording:!0,annotateMode:!1,startedAt:t.startedAt,overlayAnnotations:{},tiles:o}}case"REHYDRATE_RECORDING":{const o=e.tiles.map(i=>({...i,recordingId:t.tileIds[i.udid]??i.recordingId}));return{...e,groupId:t.groupId,compositeEnabled:t.compositeEnabled,downloadableVideoCount:0,recordingPhase:"recording",recording:!0,annotateMode:!1,startedAt:t.startedAt,overlayAnnotations:t.overlayAnnotations,tiles:o}}case"STOP_RECORDING":{const o=e.tiles.map(i=>({...i,recordingId:void 0}));return{...e,recording:!1,recordingPhase:"idle",annotateMode:!1,overlayAnnotations:{},downloadableVideoCount:t.downloadableVideoCount??e.downloadableVideoCount,compositeEnabled:t.compositeEnabled!==void 0?t.compositeEnabled:e.compositeEnabled,tiles:o}}case"SET_ANNOTATE_MODE":return{...e,annotateMode:t.enabled};case"SET_SHAPE":return{...e,shape:t.shape};case"SET_COLOR":return{...e,color:t.color};case"SET_OVERLAY_ANNOTATIONS":return{...e,overlayAnnotations:{...e.overlayAnnotations,[t.recordingId]:t.annotations}};case"CLEAR_OVERLAY_ANNOTATIONS":return{...e,overlayAnnotations:{}};case"SET_ERROR_BANNER":return{...e,errorBanner:t.message,banner:t.message?{tone:"error",message:t.message}:null};case"SET_BANNER":return{...e,banner:t.banner,errorBanner:((n=t.banner)==null?void 0:n.tone)==="error"?t.banner.message:null};default:return e}}const ye=d.createContext(null);function ht(){const e=d.useContext(ye);if(!e)throw new Error("useMosaic must be used inside <MosaicContext.Provider>");return e}function pt(){return d.useReducer(ft,ut)}function mt(e){const t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/3600),o=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`:`${o}:${String(i).padStart(2,"0")}`}function gt(e){switch(e){case"automation":return"In automation";case"manual_other":return"Manual control by another user";case"manual_self":return"On your grid";case"recording_other_group":return"Recording in another group";default:return e?"Busy":null}}const ue=[{id:"ios",label:"iOS",match:e=>e==="ios"},{id:"android",label:"Android",match:e=>e==="android"},{id:"tvos",label:"tvOS",match:e=>e==="tvos"},{id:"androidtv",label:"Android TV",match:e=>e==="androidtv"||e==="android-tv"},{id:"other",label:"Other",match:()=>!0}],Y={available:"bg-[var(--color-success)]",inUse:"bg-[var(--color-warning)]",offline:"bg-[rgb(var(--rgb-offline))]"},xt=[["available",Y.available],["in use",Y.inUse],["offline",Y.offline]];function fe(e){return Ve(e)}function bt({devices:e,inMosaic:t,onToggle:n,status:o="ready"}){const[i,g]=d.useState(""),[u,N]=d.useState({}),p=d.useMemo(()=>{const l=i.trim().toLowerCase();return l?e.filter(v=>v.udid.toLowerCase().includes(l)||(v.name??"").toLowerCase().includes(l)||(v.altName??"").toLowerCase().includes(l)||(v.platform??"").toLowerCase().includes(l)):e},[e,i]),E=d.useMemo(()=>{const l=ue.map(f=>({id:f.id,label:f.label,rows:[]})),v=f=>l.find((j,y)=>ue[y].match(f))??l[l.length-1];for(const f of p)v((f.platform??"").toLowerCase()).rows.push(f);return l.filter(f=>f.rows.length>0)},[p]);if(e.length===0){const l=o==="loading"?"Loading devices…":o==="error"?"Couldn’t load devices. Retrying…":"No devices online.";return r.jsx("div",{role:"status",className:"text-xs text-[var(--text-dim)] p-3",children:l})}return r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("div",{className:"relative",children:[r.jsx($e,{"aria-hidden":!0,size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--text-dim)]"}),r.jsx("input",{type:"text",value:i,placeholder:"Filter devices...",onChange:l=>g(l.target.value),className:"w-full pl-7 pr-2 py-1.5 text-xs rounded border border-[var(--border)] bg-transparent placeholder:text-[var(--text-dim)] focus:outline-none focus:border-[var(--color-info)]"})]}),E.map(l=>{const v=u[l.id];return r.jsxs("section",{className:"flex flex-col gap-1",children:[r.jsxs("button",{type:"button","aria-expanded":!v,onClick:()=>N(f=>({...f,[l.id]:!f[l.id]})),className:"flex items-center justify-between w-full text-[11px] text-[var(--text-dim)] hover:text-[rgb(var(--rgb-fg))] px-1 py-0.5",children:[r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx(Me,{"aria-hidden":!0,size:12,className:`transition-transform ${v?"-rotate-90":"rotate-0"}`}),l.label]}),r.jsx("span",{children:l.rows.length})]}),!v&&r.jsx("ul",{className:"flex flex-col gap-1 text-sm",children:l.rows.map(f=>{const j=f.busyReason==="manual_self",y=t.has(f.udid),x=!!f.busy&&!j&&!y||!!f.offline,R=f.offline?"Offline":gt(f.busyReason),O=!x,T=[f.name??f.udid,f.platform&&fe(f.platform)].concat(x&&R?[R]:[]).filter(Boolean).join(", ");return r.jsx("li",{children:r.jsxs("button",{type:"button",disabled:x,draggable:!x,onDragStart:w=>{w.dataTransfer.effectAllowed="copy",w.dataTransfer.setData("application/x-xenon-udid",f.udid),w.dataTransfer.setData("text/plain",f.udid)},onClick:()=>n(f.udid),"aria-label":T,"aria-pressed":y,className:`w-full flex items-center gap-2 px-2 py-1.5 rounded text-left border transition-colors ${x?"opacity-60 cursor-not-allowed border-transparent":y?"border-[rgb(var(--rgb-accent)/0.4)] bg-[rgb(var(--rgb-accent)/0.05)] hover:bg-[rgb(var(--rgb-accent)/0.1)]":"border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"}`,title:x?`${R} — release first`:y?"Click to remove from the grid":"Click to add to the grid (or drag to a cell)",children:[y?r.jsx(ze,{"aria-hidden":!0,size:14,className:"shrink-0 text-[var(--color-accent-soft)]"}):r.jsx(xe,{"aria-hidden":!0,size:14,className:"shrink-0 text-[var(--text-dim)]"}),r.jsx("span",{"aria-hidden":!0,className:`inline-block w-1.5 h-1.5 rounded-full ${f.offline?Y.offline:O?Y.available:Y.inUse}`}),r.jsx("span",{className:"font-medium flex-1 truncate text-[13px]",children:f.name??f.udid}),f.platform&&r.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded bg-[var(--surface-2)] text-[var(--text-dim)]",children:fe(f.platform)})]})},f.udid)})})]},l.id)}),i&&E.length===0&&r.jsxs("div",{className:"text-xs text-[var(--text-dim)] px-1 py-2",children:['No devices match "',i,'".']}),r.jsx("div",{className:"text-[10px] text-[var(--text-dim)] px-1 pt-2 flex items-center gap-3",children:xt.map(([l,v])=>r.jsxs("span",{className:"inline-flex items-center gap-1",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full inline-block ${v}`}),l]},l))})]})}const vt=[{id:"1",label:"1",icon:r.jsx(wt,{})},{id:"2x1",label:"2×1",icon:r.jsx(Et,{})},{id:"2x2",label:"2×2",icon:r.jsx(Nt,{})},{id:"3x2",label:"3×2",icon:r.jsx(Rt,{})},{id:"auto",label:"Auto",icon:r.jsx(St,{})}];function yt({value:e,onChange:t}){return r.jsx("div",{role:"tablist",className:"inline-flex border border-[var(--border)] rounded-md overflow-hidden text-xs bg-[rgb(var(--rgb-white)/0.02)]",children:vt.map(n=>{const o=e===n.id;return r.jsxs("button",{role:"tab","aria-selected":o,onClick:()=>t(n.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 border-r border-[var(--border)] last:border-r-0 transition-colors ${o?"bg-[var(--surface-2)] text-[rgb(var(--rgb-fg))]":"text-[var(--text-dim)] hover:bg-[var(--surface-2)] hover:text-[rgb(var(--rgb-fg))]"}`,title:`Layout: ${n.label}`,children:[r.jsx("span",{className:"w-3.5 h-3.5 inline-flex items-center justify-center",children:n.icon}),r.jsx("span",{children:n.label})]},n.id)})})}function B(e){return r.jsx("rect",{rx:1.2,ry:1.2,fill:"currentColor",...e})}function wt(){return r.jsx("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:B({x:2,y:2,width:10,height:10})})}function Et(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:[B({x:1.5,y:3,width:5,height:8}),B({x:7.5,y:3,width:5,height:8})]})}function Nt(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:[B({x:1.5,y:1.5,width:5,height:5}),B({x:7.5,y:1.5,width:5,height:5}),B({x:1.5,y:7.5,width:5,height:5}),B({x:7.5,y:7.5,width:5,height:5})]})}function Rt(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",children:[B({x:1,y:1.5,width:3.3,height:5}),B({x:5.35,y:1.5,width:3.3,height:5}),B({x:9.7,y:1.5,width:3.3,height:5}),B({x:1,y:7.5,width:3.3,height:5}),B({x:5.35,y:7.5,width:3.3,height:5}),B({x:9.7,y:7.5,width:3.3,height:5})]})}function St(){return r.jsxs("svg",{viewBox:"0 0 14 14",className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",children:[r.jsx("rect",{x:"2",y:"2",width:"10",height:"10",rx:"1.5"}),r.jsx("circle",{cx:"7",cy:"7",r:"1.5",fill:"currentColor",stroke:"none"})]})}function jt(e,t,n,o,i,g,u=!1){const N=Xe(n.width,n.height,g);let p=(e-n.left-N.left)/N.width,E=(t-n.top-N.top)/N.height;return!(p>=0&&p<=1&&E>=0&&E<=1)&&!u?null:(p=Math.min(1,Math.max(0,p)),E=Math.min(1,Math.max(0,E)),{x:Math.round(p*o),y:Math.round(E*i)})}const Tt=5e3;function Ct(e,t){if(e.httpStatus===404)return{ended:!0,startedAt:t};if(e.httpStatus!==200)return{ended:!1,startedAt:t};const n=e.body??{};return n.status!=="running"?{ended:!0,startedAt:t}:t&&n.startedAt&&n.startedAt!==t?{ended:!0,startedAt:t}:{ended:!1,startedAt:t??n.startedAt}}function At(e,t,n,o=Tt){const i=d.useRef(n);i.current=n,d.useEffect(()=>{if(!t)return;let g=!1,u=!1,N;const p=async()=>{if(!(u||g)){u=!0;try{const l=await fetch(`/xenon/api/control/${encodeURIComponent(e)}/stream/status`),v=l.ok?await l.json().catch(()=>{}):void 0;if(g)return;const f=Ct({httpStatus:l.status,body:v},N);N=f.startedAt,f.ended&&(g=!0,i.current())}catch{}finally{u=!1}}};p();const E=setInterval(p,o);return()=>{g=!0,clearInterval(E)}},[e,t,o])}const Dt=3,It=45e3,he=[2e3,5e3,1e4];function _t(e){const t=Math.max(0,Math.min(e,he.length-1));return he[t]}function kt(e){return e<Dt}function pe(e){var n;const t=(e.lastError||"").toLowerCase();if(/did not find test app|not installed|webdriveragentrunner|applicationverification/.test(t))return"WebDriverAgent is not installed on this device. Install and trust WDA, then retry.";if(/unsupported ios version|manualpairingtunnelstart/.test(t))return"This device’s iOS version is not supported for live streaming on this host.";if(/port range for purpose 'tunnel' is exhausted/.test(t))return"No free tunnel ports on this host (12100–12199 are in use). Stop another iPhone’s preview, then retry.";if(/go-ios tunnel .* exited before it was ready/.test(t)){const o=(n=/exited before it was ready \([^)]*\): (.+)$/.exec(e.lastError||""))==null?void 0:n[1];return`The device tunnel stopped while starting${o?` (go-ios: ${o.trim()})`:""}. Retry; if it keeps failing, unlock the iPhone and check it trusts this Mac.`}return/go-ios tunnel .* came up on port/.test(t)?"The device tunnel started on an unexpected port and was stopped. Retry.":/econnrefused|econnreset|connection reset|tunnel/.test(t)?"Lost the connection to the device tunnel. Reconnect the device, then retry.":e.lastError&&e.lastError.trim()?e.lastError.trim():"We couldn’t start the live stream for this device."}function Ot(e){for(let t=0;t+4<e.length;t++){const n=e[t]===0&&e[t+1]===0&&e[t+2]===0&&e[t+3]===1,o=e[t]===0&&e[t+1]===0&&e[t+2]===1;if(!n&&!o)continue;const i=t+(n?4:3);if((e[i]&31)===7){const g=u=>u.toString(16).padStart(2,"0");return`avc1.${g(e[i+1])}${g(e[i+2])}${g(e[i+3])}`}}return"avc1.42e01e"}const $t=({wsUrl:e,onFatal:t,onReady:n,onFrameSize:o,className:i})=>{const g=d.useRef(null),u=d.useRef(t);u.current=t;const N=d.useRef(n);N.current=n;const p=d.useRef(o);return p.current=o,d.useEffect(()=>{var T;const E=window,l=g.current;if(typeof E.VideoDecoder>"u"||!l){(T=u.current)==null||T.call(u);return}const v=l.getContext("2d");let f=!1,j=!1,y=!0,x=0;const R=new E.VideoDecoder({output:w=>{var C,$;if(f){w.close();return}(l.width!==w.displayWidth||l.height!==w.displayHeight)&&(l.width=w.displayWidth,l.height=w.displayHeight,(C=p.current)==null||C.call(p,w.displayWidth,w.displayHeight)),v==null||v.drawImage(w,0,0),w.close(),y&&(y=!1,($=N.current)==null||$.call(N))},error:()=>{var w;return(w=u.current)==null?void 0:w.call(u)}}),O=new WebSocket(e);return O.binaryType="arraybuffer",O.onerror=()=>{var w;return(w=u.current)==null?void 0:w.call(u)},O.onclose=()=>{var w;f||(w=u.current)==null||w.call(u)},O.onmessage=w=>{var m;const C=w.data,$=new DataView(C).getUint8(0),V=new Uint8Array(C,1);if($===0){if(j)return;try{R.configure({codec:Ot(V),optimizeForLatency:!0}),j=!0}catch{(m=u.current)==null||m.call(u)}return}if(!(!j||R.state!=="configured"))try{R.decode(new E.EncodedVideoChunk({type:$===1?"key":"delta",timestamp:x,data:V})),x+=11111}catch{}},()=>{f=!0;try{O.close()}catch{}try{R.state!=="closed"&&R.close()}catch{}}},[e]),r.jsx("canvas",{ref:g,className:i,style:{width:"100%",height:"100%",objectFit:"contain",display:"block"}})};function Mt(e,t,n){return(e==="android"||e==="androidtv"||e==="android-tv")&&t==="h264"&&n?"h264":"mjpeg"}const Pt=10,Lt=500;function Bt({udid:e,name:t,recordingId:n,annotateMode:o,shape:i,color:g,aspect:u="9 / 16",screenWidth:N,screenHeight:p,platform:E,onAnnotation:l,overlayAnnotations:v,onOverlayAnnotationsChange:f,onRemove:j}){const[y,x]=d.useState("connecting"),[R,O]=d.useState(),T=d.useCallback((a,h)=>{if(!(a>0)||!(h>0))return;const _=a/h;O(k=>k!==void 0&&Math.abs(k-_)<.001?k:_)},[]),[w,C]=d.useState(0),[$,V]=d.useState(null),m=d.useRef(0),s=d.useRef(null),[c,b]=d.useState(""),[S,H]=d.useState([]),[U,M]=d.useState(!1),z=d.useRef(null),W=d.useRef(null),P=E==="android"||E==="androidtv"||E==="android-tv",A=E==="ios"||E==="tvos";d.useEffect(()=>{let a=!1;if(n){V(null),x("connecting"),C(Date.now()),D.startStream(e).catch(()=>{});return}const h=typeof window.VideoDecoder<"u";return(async()=>{try{const _=encodeURIComponent(e),k=await fetch(`/xenon/api/control/${_}/stream/status`);if(!k.ok)return;const I=await k.json();if(Mt(E||"",I==null?void 0:I.type,h)!=="h264"||!(I!=null&&I.h264Path))return;const G=await fetch(`/xenon/api/control/${_}/stream/ticket`,{method:"POST"});if(!G.ok)return;const{ticket:L}=await G.json();if(a||!L)return;const Z=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}${I.h264Path}?ticket=${encodeURIComponent(L)}`;V(Z)}catch{}})(),()=>{a=!0}},[e,E,n]);const F=!o&&!!N&&!!p,re=(a,h,_,k=!1)=>jt(a,h,_,N,p,R,k),Re=(a,h,_)=>{const k=Date.now()+Math.random(),I=a-_.left,G=h-_.top;H(L=>[...L,{id:k,x:I,y:G}]),window.setTimeout(()=>{H(L=>L.filter(q=>q.id!==k))},500)},Se=a=>{if(!F||y==="unavailable"||a.button!==0)return;const h=a.currentTarget;h.focus(),re(a.clientX,a.clientY,h.getBoundingClientRect())&&(h.setPointerCapture(a.pointerId),W.current={startX:a.clientX,startY:a.clientY,startTime:Date.now(),rect:h.getBoundingClientRect()},Re(a.clientX,a.clientY,W.current.rect))},je=async a=>{var Z,ce;const h=W.current;if(W.current=null,!h||!F)return;try{a.currentTarget.releasePointerCapture(a.pointerId)}catch{}const _=a.clientX-h.startX,k=a.clientY-h.startY,I=Math.hypot(_,k),G=Date.now()-h.startTime,L=re(h.startX,h.startY,h.rect,!0),q=I<Pt;try{if(q&&G<Lt)await D.tap(e,L.x,L.y);else if(q)await((ce=(Z=D).touchAndHold)==null?void 0:ce.call(Z,e,L.x,L.y,G));else{const Q=re(a.clientX,a.clientY,h.rect,!0);await D.swipe(e,L.x,L.y,Q.x,Q.y)}}catch(Q){console.error(`[DeviceTile] gesture failed for ${e}`,Q)}},Te=()=>{W.current=null},Ce=async a=>{if(!F||y==="unavailable"||a.metaKey||a.ctrlKey||a.altKey)return;const h=a.key;try{if(h.length===1){a.preventDefault(),await D.typeText(e,h);return}if(h==="Backspace"){a.preventDefault(),P?await D.pressKey(e,67):await D.typeText(e,"\b");return}if(h==="Enter"){a.preventDefault(),P?await D.pressKey(e,66):await D.typeText(e,`
2
+ `);return}if(h==="Tab"){a.preventDefault(),await D.typeText(e," ");return}h==="Escape"&&P&&(a.preventDefault(),await D.pressKey(e,ee.BACK))}catch(_){console.error(`[DeviceTile] keystroke "${h}" failed for ${e}`,_)}},Ae=()=>D.pressKey(e,P?ee.HOME:Ye.HOME).catch(a=>console.error(`[DeviceTile] home failed for ${e}`,a)),De=()=>D.pressKey(e,ee.BACK).catch(a=>console.error(`[DeviceTile] back failed for ${e}`,a)),Ie=()=>D.pressKey(e,ee.APP_SWITCH).catch(a=>console.error(`[DeviceTile] app-switch failed for ${e}`,a)),_e=async()=>{try{const a=await D.getScreenshot(e),h=(a==null?void 0:a.screenshot)??(a==null?void 0:a.value)??a;if(!h)return;const _=await fetch(`data:image/png;base64,${h}`).then(G=>G.blob()),k=URL.createObjectURL(_),I=document.createElement("a");I.href=k,I.download=`${t||e}-${Date.now()}.png`,document.body.appendChild(I),I.click(),I.remove(),setTimeout(()=>URL.revokeObjectURL(k),1e3)}catch(a){console.error(`[DeviceTile] screenshot failed for ${e}`,a)}};d.useEffect(()=>{console.log(`[DeviceTile] Rendering ${e} in state: ${y}`)},[e,y]);const ke=`/xenon/api/control/${encodeURIComponent(e)}/stream?t=${w}`,ie=d.useCallback(async()=>{try{const a=await fetch(`/xenon/api/control/${encodeURIComponent(e)}/stream/status`);if(!a.ok)throw new Error(String(a.status));const h=await a.json();b(pe({lastError:h==null?void 0:h.lastError,status:h==null?void 0:h.status}))}catch{b(pe({}))}},[e]),ne=d.useCallback(()=>{const a=m.current;kt(a)?(m.current=a+1,s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{x("connecting"),C(Date.now())},_t(a))):(x("unavailable"),ie())},[ie]);d.useEffect(()=>{if(y!=="connecting")return;const a=setTimeout(ne,It);return()=>clearTimeout(a)},[y,w,ne]),At(e,y==="live"&&!$,()=>{console.warn(`[DeviceTile] MJPEG stream ended for ${e}; reconnecting`),x("connecting"),C(Date.now())}),d.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const Oe=()=>{s.current&&clearTimeout(s.current),m.current=0,b(""),x("connecting"),C(Date.now())},X=!!n,J=t||e.slice(0,16)+"…";return r.jsxs("div",{className:"flex items-stretch justify-center w-full h-full min-h-0 min-w-0 gap-2",children:[r.jsxs("div",{className:"theme-dark relative bg-[var(--black)] rounded-lg overflow-hidden border border-[var(--border)] group max-h-full max-w-full self-center",style:{aspectRatio:u,height:"100%"},children:[y==="connecting"&&r.jsxs("div",{role:"status","aria-live":"polite",className:"flex flex-col items-center justify-center gap-1 px-4 text-center bg-[rgb(var(--rgb-well)/0.8)] text-[var(--text-dim)] absolute inset-0 z-20 pointer-events-none",children:[r.jsx("div",{"aria-hidden":!0,className:"w-10 h-10 mb-3 border-4 border-[var(--border)] border-t-[var(--text-dim)] rounded-full animate-spin"}),r.jsx("div",{className:"font-semibold text-[var(--text)]",children:"Starting stream…"}),r.jsx("div",{className:"text-xs text-[var(--text-dim)] truncate max-w-full",children:J}),r.jsx("div",{className:"text-[11px] mt-3 text-[var(--text-dim)] leading-snug",children:A?"iPhone streams can take up to 20 seconds to start.":"Connecting to the device…"})]}),y==="unavailable"&&r.jsx("div",{role:"alert",className:"flex items-center justify-center bg-[var(--black)] text-[var(--text-dim)] absolute inset-0 z-20",children:r.jsxs("div",{className:"text-center p-6",children:[r.jsx(Je,{"aria-hidden":!0,size:36,className:"mx-auto mb-3 text-[var(--text-dim)]"}),r.jsx("div",{className:"font-semibold text-[var(--text)]",children:"Connection failed"}),r.jsx("p",{className:"text-xs mt-2 text-[var(--text-dim)] leading-relaxed max-w-[240px] mx-auto",children:c||"We couldn’t start the live stream for this device."}),r.jsx("button",{type:"button",className:"mt-5 text-sm font-semibold px-4 py-2 rounded bg-[var(--color-accent)] hover:bg-[var(--color-accent-strong)] text-[var(--color-on-accent)] transition-colors",onClick:Oe,children:"Retry"})]})}),$?r.jsx($t,{wsUrl:$,className:"absolute inset-0 w-full h-full object-contain bg-black select-none pointer-events-none",onReady:()=>x("live"),onFrameSize:T,onFatal:()=>{console.warn(`[DeviceTile] H.264 fatal for ${e}; falling back to MJPEG`),V(null),x("connecting"),C(Date.now())}}):r.jsx(Ue,{src:ke,alt:J,className:"absolute inset-0 w-full h-full object-contain bg-black select-none pointer-events-none",draggable:!1,style:{opacity:y==="live"?1:0,transition:"opacity 0.3s ease-in-out"},onLoad:a=>{console.log(`[DeviceTile] Image LOADED for ${e}`),T(a.currentTarget.naturalWidth,a.currentTarget.naturalHeight),m.current=0,s.current&&clearTimeout(s.current),x("live")},onError:a=>{console.error(`[DeviceTile] Image ERROR for ${e}`,a),ne()}},w),F&&y!=="unavailable"&&r.jsx("div",{ref:z,className:`absolute inset-0 z-[35] touch-none outline-none ${U?"ring-2 ring-[rgb(var(--rgb-accent)/0.6)] ring-inset rounded-lg":""}`,tabIndex:0,onPointerDown:Se,onPointerUp:je,onPointerCancel:Te,onKeyDown:Ce,onFocus:()=>M(!0),onBlur:()=>M(!1)}),r.jsx("div",{className:"absolute inset-0 z-20 pointer-events-none overflow-hidden",children:S.map(a=>r.jsx("span",{className:"absolute block w-10 h-10 rounded-full border-2 border-[var(--color-accent-soft)] animate-ping",style:{left:a.x-20,top:a.y-20}},a.id))}),X&&r.jsx(qe,{enabled:o,shape:i,color:g,committed:v,mediaAspect:R,onCommittedChange:f,onCommit:(a,h)=>l(n,a,h)}),X&&o&&y==="live"&&r.jsx("div",{className:"absolute top-3 left-14 right-3 z-30 flex justify-end pointer-events-none",children:r.jsx("span",{className:"px-2 py-0.5 rounded-sm bg-[var(--color-info)] text-white text-[10px] font-semibold shadow-lg whitespace-nowrap overflow-hidden text-ellipsis",children:"Annotating · Esc to stop"})}),X&&r.jsx("div",{className:"absolute top-3 left-3 z-30 pointer-events-none",children:r.jsx("span",{className:"px-2 py-0.5 rounded-sm bg-[var(--red-600)] text-white text-[9px] font-black shadow-lg",children:"REC"})}),r.jsxs("div",{className:"absolute top-3 left-3 z-30 flex flex-col gap-1.5 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-150",children:[y==="live"&&r.jsx("span",{className:"px-2 py-0.5 rounded-sm bg-[var(--color-success)] text-[var(--color-on-success)] text-[11px] font-semibold shadow-lg w-fit",children:"Live"}),r.jsx("span",{className:"px-2 py-1 rounded bg-[rgb(var(--rgb-well)/0.8)] text-[var(--text)] text-[11px] font-medium backdrop-blur-md border border-[rgb(var(--rgb-fg)/0.1)] shadow-xl truncate max-w-[180px]",children:J})]})]}),r.jsx(Ht,{streamState:y,recording:X,isIOS:A,isAndroid:P,onClose:!X&&j?()=>j(e):void 0,sendHome:Ae,sendBack:De,sendAppSwitch:Ie,captureScreenshot:_e,displayName:J})]})}const te="w-7 h-7 flex items-center justify-center rounded-md hover:bg-[var(--surface-2)] hover:text-[var(--text)] transition-colors";function Ht({streamState:e,recording:t,isIOS:n,isAndroid:o,onClose:i,sendHome:g,sendBack:u,sendAppSwitch:N,captureScreenshot:p,displayName:E}){const l=e==="live";return!i&&!l?null:r.jsxs("div",{className:"self-stretch w-9 flex flex-col items-center justify-between gap-1 py-2 rounded-lg bg-[var(--surface)] border border-[var(--border)] text-[var(--text-dim)]",children:[r.jsx("div",{className:"flex flex-col items-center gap-1",children:i&&r.jsx("button",{type:"button","aria-label":`Remove ${E}`,title:"Remove from the grid",onClick:i,className:"w-7 h-7 flex items-center justify-center rounded-md hover:bg-[rgb(var(--rgb-red)/0.15)] hover:text-[var(--color-danger)] transition-colors",children:r.jsx(Pe,{"aria-hidden":!0,size:16})})}),l&&r.jsxs("div",{className:"flex flex-col items-center gap-1.5 my-auto",children:[(o||n)&&r.jsx("button",{type:"button","aria-label":"Home",title:"Home",onClick:g,className:te,children:r.jsx(Fe,{"aria-hidden":!0,size:15})}),o&&r.jsx("button",{type:"button","aria-label":"Back",title:"Back",onClick:u,className:te,children:r.jsx(Ge,{"aria-hidden":!0,size:16})}),o&&r.jsx("button",{type:"button","aria-label":"Recent apps",title:"Recent apps",onClick:N,className:te,children:r.jsx(be,{"aria-hidden":!0,size:13})})]}),l&&r.jsx("div",{className:"flex flex-col items-center gap-1",children:r.jsx("button",{type:"button","aria-label":"Screenshot",title:"Screenshot",onClick:p,className:te,children:r.jsx(Ke,{"aria-hidden":!0,size:15})})})]})}const Wt={1:"1fr","2x1":"1fr 1fr","2x2":"1fr 1fr","3x2":"1fr 1fr 1fr"},Vt={1:"1fr","2x1":"1fr","2x2":"1fr 1fr","3x2":"1fr 1fr"},zt={1:1,"2x1":2,"2x2":4,"3x2":6};function Ut({layout:e,tiles:t,annotateMode:n,shape:o,color:i,onAnnotation:g,overlayAnnotationsByRecording:u,onOverlayAnnotationsChange:N,onRemove:p,onDropDevice:E}){const l=dt(e,t.length),v=zt[l];t.length;const f=t.length,j=e==="auto"?Math.max(f,1):v,y=Math.max(0,j-f);return r.jsxs("div",{style:{display:"grid",gap:8,gridTemplateColumns:Wt[l],gridTemplateRows:Vt[l]},className:"h-full",children:[t.map(x=>r.jsx(Bt,{udid:x.udid,name:x.name,mjpegPort:x.mjpegPort,recordingId:x.recordingId,aspect:x.aspect,screenWidth:x.screenWidth,screenHeight:x.screenHeight,platform:x.platform,annotateMode:n,shape:o,color:i,overlayAnnotations:x.recordingId?u==null?void 0:u[x.recordingId]:void 0,onOverlayAnnotationsChange:x.recordingId&&N?R=>N(x.recordingId,R):void 0,onAnnotation:g,onRemove:p},x.udid)),Array.from({length:y},(x,R)=>r.jsx(Ft,{onDropDevice:E},`empty-${R}`))]})}function Ft({onDropDevice:e}){const[t,n]=d.useState(!1);return r.jsxs("div",{onDragOver:o=>{e&&(o.preventDefault(),o.dataTransfer.dropEffect="copy",t||n(!0))},onDragLeave:()=>n(!1),onDrop:o=>{if(n(!1),!e)return;o.preventDefault();const i=o.dataTransfer.getData("application/x-xenon-udid")||o.dataTransfer.getData("text/plain");i&&e(i)},className:`flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed transition-colors ${t?"border-[rgb(var(--rgb-accent)/0.6)] bg-[rgb(var(--rgb-accent)/0.05)]":"border-[var(--border)] bg-[rgb(var(--rgb-fg)/0.02)]"} text-[var(--text-dim)] min-h-[120px]`,children:[r.jsx("div",{"aria-hidden":"true",className:`w-8 h-8 rounded-full flex items-center justify-center ${t?"bg-[rgb(var(--rgb-accent)/0.15)] text-[var(--color-accent-soft)]":"bg-[rgb(var(--rgb-fg)/0.05)] text-[rgb(var(--rgb-fg)/0.6)]"}`,children:r.jsx(Ze,{size:16})}),r.jsx("div",{className:"text-xs font-medium",children:"Drag a device here"}),r.jsx("div",{className:"text-[10px] opacity-70",children:"or click one in the list"})]})}function Gt(e,t){return t==="starting"?"Starting…":e<=1?"Record":`Record ${e} devices`}const K={"aria-hidden":!0,size:14,className:"shrink-0"};function Kt({selectedUdids:e,onClearMarks:t}){const{state:n,dispatch:o}=ht(),[i,g]=d.useState(()=>Date.now());d.useEffect(()=>{if(n.recordingPhase!=="recording"&&n.recordingPhase!=="stopping")return;g(Date.now());const m=window.setInterval(()=>g(Date.now()),250);return()=>window.clearInterval(m)},[n.recordingPhase]);const u=n.startedAt&&(n.recordingPhase==="recording"||n.recordingPhase==="stopping")?i-n.startedAt:0,N=n.recordingPhase==="starting"||n.recordingPhase==="stopping",p=n.recordingPhase==="idle"&&e.length>0&&!N,E=n.recordingPhase==="recording"||n.recording&&n.tiles.some(m=>!!m.recordingId),l=E&&!N,v=l,f=v&&n.annotateMode,j=!!n.groupId&&n.recordingPhase==="idle",y=e.length>1||n.downloadableVideoCount>1,x=j&&n.compositeEnabled,R=j&&!n.compositeEnabled&&(n.downloadableVideoCount===1||n.downloadableVideoCount===0&&e.length<=1),O=async()=>{var m;if(p){o({type:"SET_RECORDING_PHASE",phase:"starting"}),o({type:"SET_BANNER",banner:null});try{const s=await nt(e);if(!((m=s.recordings)!=null&&m.length)){o({type:"SET_RECORDING_PHASE",phase:"idle"}),o({type:"SET_BANNER",banner:{tone:"error",message:"Recording did not start. Check that live preview is working, then try again."}});return}const c={};for(const S of s.recordings)c[S.udid]=S.id;const b=e.length-s.recordings.length;o({type:"START_RECORDING",groupId:s.groupId,startedAt:Date.now(),tileIds:c,compositeEnabled:s.compositeEnabled===!0}),b>0?o({type:"SET_BANNER",banner:{tone:"error",message:`Recording started on ${s.recordings.length} of ${e.length} devices (${b} failed).`}}):o({type:"SET_BANNER",banner:null})}catch(s){if(o({type:"SET_RECORDING_PHASE",phase:"idle"}),s instanceof ot)if(s.body.error==="device_busy"){const c=(s.body.busyDevices??[]).map(b=>`${b.udid} (${b.reason})`).join(", ");o({type:"SET_BANNER",banner:{tone:"error",message:`Cannot start — these devices are busy: ${c}`}})}else o({type:"SET_BANNER",banner:{tone:"error",message:`Server-wide recording cap reached (${s.body.active}/${s.body.limit}).`}});else o({type:"SET_BANNER",banner:{tone:"error",message:`Recording failed: ${s.message}`}})}}},T=async()=>{if(!(!n.groupId||n.recordingPhase!=="recording")){o({type:"SET_RECORDING_PHASE",phase:"stopping"});try{const m=await st(n.groupId),s=(m.recordings??[]).filter(b=>b.status==="STOPPED"&&(b.sizeBytes??0)>=1024),c=(m.recordings??[]).filter(b=>b.status!=="STOPPED");o({type:"STOP_RECORDING",downloadableVideoCount:s.length,compositeEnabled:n.compositeEnabled}),s.length===0?o({type:"SET_BANNER",banner:{tone:"error",message:c.length>0?`Recording failed on ${c.length} device(s). Nothing to download.`:"Recording stopped but no playable video was produced."}}):c.length>0?o({type:"SET_BANNER",banner:{tone:"info",message:`${s.length} ready, ${c.length} failed. Download with the button above.`}}):o({type:"SET_BANNER",banner:{tone:"info",message:s.length===1?"Video ready. Download it with the button above.":`${s.length} videos ready. Download them with the button above.`}})}catch(m){o({type:"STOP_RECORDING"}),o({type:"SET_BANNER",banner:{tone:"error",message:`Stop failed: ${m.message}`}})}}},w=m=>{const s=m==="annotate";s&&!v||s!==n.annotateMode&&o({type:"SET_ANNOTATE_MODE",enabled:s})};d.useEffect(()=>{if(!n.annotateMode)return;const m=s=>{var b;if(s.key!=="Escape"||s.repeat)return;const c=s.target;c&&((b=c.closest)!=null&&b.call(c,"input, textarea, select")||c.isContentEditable)||o({type:"SET_ANNOTATE_MODE",enabled:!1})};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[n.annotateMode,o]);const C=()=>{v&&t()},$=Object.values(n.overlayAnnotations).some(m=>((m==null?void 0:m.length)??0)>0),V=[{id:"RECT",label:"Rect"},{id:"CIRCLE",label:"Circle"},{id:"ARROW",label:"Arrow"},{id:"FREEHAND",label:"Draw"}];return r.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-end",children:[n.recordingPhase==="recording"||n.recordingPhase==="stopping"?r.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded text-xs font-mono tabular-nums bg-[rgb(var(--rgb-red-600)/0.2)] text-[var(--red-200)] border border-[rgb(var(--rgb-red)/0.4)]",title:"Recording elapsed time",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-[var(--red)] animate-pulse"}),"REC ",mt(u),n.recordingPhase==="stopping"?" · Stopping…":""]}):r.jsxs("button",{type:"button",onClick:O,disabled:!p,title:e.length===0?"Add a device to the grid first":"Record every device on the grid",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded bg-[var(--red-600)] text-white disabled:opacity-40 disabled:cursor-not-allowed light:disabled:bg-transparent light:disabled:text-[var(--text)] light:disabled:ring-1 light:disabled:ring-inset light:disabled:ring-[color:var(--border)]",children:[r.jsx(xe,{...K,size:10,fill:"currentColor"}),Gt(e.length,n.recordingPhase)]}),r.jsxs("button",{type:"button",onClick:T,disabled:!l,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(be,{...K,size:12}),n.recordingPhase==="stopping"?"Stopping…":"Stop"]}),r.jsx(Qe,{size:"sm",value:n.annotateMode?"annotate":"interact",onChange:w,segments:[{value:"interact",label:"Interact",title:"Tap, swipe and type on the devices (Esc)",keyShortcuts:"Escape"},{value:"annotate",label:"Annotate",title:v?"Draw marks on the recording":"Start recording to annotate",disabled:!v}]}),E&&r.jsxs("div",{className:"flex items-center gap-1 ml-1 pl-2 border-l border-[var(--border)]",children:[V.map(m=>r.jsx("button",{type:"button",disabled:!f,"aria-pressed":n.shape===m.id,onClick:()=>o({type:"SET_SHAPE",shape:m.id}),className:`px-2 py-1 text-xs rounded border disabled:opacity-40 disabled:cursor-not-allowed ${n.shape===m.id?"bg-[var(--surface-2)] border-[var(--color-info)] text-[rgb(var(--rgb-fg))]":"border-[var(--border)] opacity-80 hover:opacity-100"}`,children:m.label},m.id)),r.jsx("input",{type:"color",value:n.color,disabled:!f,onChange:m=>o({type:"SET_COLOR",color:m.target.value}),title:"Annotation color","aria-label":"Annotation color",className:"w-7 h-7 rounded border border-[var(--border)] bg-transparent cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed"}),r.jsx("button",{type:"button",onClick:C,disabled:!v||!$,title:"Clear marks from the preview and the recording",className:"px-2 py-1 text-xs rounded border border-[var(--border)] hover:bg-[var(--surface-2)] disabled:opacity-40 disabled:cursor-not-allowed",children:"Clear marks"})]}),j&&R&&r.jsxs("a",{href:et(n.groupId),className:"ml-1 inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",download:!0,children:[r.jsx(oe,{...K}),"Download video"]}),j&&!R&&r.jsxs("a",{href:tt(n.groupId),className:"ml-1 inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",download:`videos-${n.groupId}.zip`,title:"ZIP of mp4 files only (no JSON extras)",children:[r.jsx(oe,{...K}),"Download ",y?"videos":"video"]}),x&&r.jsxs("a",{href:rt(n.groupId),className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",download:`side-by-side-${n.groupId}.mp4`,title:"All devices in one side-by-side video",children:[r.jsx(oe,{...K}),"Side-by-side"]}),j&&n.groupId&&r.jsxs(Le,{to:`/recordings/${encodeURIComponent(n.groupId)}`,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded border border-[var(--border)] hover:bg-[var(--surface-2)]",children:[r.jsx(Be,{...K}),"Open in Recordings"]})]})}function Yt({remainingSec:e,onContinue:t,onReleaseNow:n}){return r.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"idle-warning-title",className:"fixed inset-0 z-40 bg-black/60 flex items-center justify-center",children:r.jsxs("div",{className:"bg-[var(--bg)] border border-[var(--border)] rounded-lg w-full max-w-md p-6",children:[r.jsx("h3",{id:"idle-warning-title",className:"text-base font-semibold mb-2",children:"Are you still there?"}),r.jsxs("p",{className:"text-sm text-[var(--text-dim)] mb-4",children:["Your devices will be released in"," ",r.jsxs("span",{className:"text-[var(--text)] font-mono font-semibold",children:[e,"s"]})," due to inactivity. Click ",r.jsx("strong",{children:"Continue Session"})," to keep them locked."]}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{type:"button",onClick:n,className:"h-9 px-3 rounded-md border border-[var(--border)] text-sm text-[var(--text-dim)] hover:text-[var(--text)]",children:"Release now"}),r.jsx("button",{type:"button",autoFocus:!0,onClick:t,className:"h-9 px-4 rounded-md bg-[var(--color-accent)] text-[var(--color-on-accent)] text-sm font-medium",children:"Continue session"})]})]})})}function Xt({message:e,onRestore:t,onDismiss:n}){return r.jsxs("div",{role:"status",className:"text-sm rounded border border-[var(--border)] bg-[var(--surface-2)] text-[var(--text)] px-3 py-2 flex items-center gap-2",children:[r.jsx(ct,{"aria-hidden":!0,size:14,className:"shrink-0 text-[var(--text-dim)]"}),r.jsx("span",{className:"flex-1",children:e}),t&&r.jsx(de,{variant:"tonal",size:"sm",onClick:t,children:"Restore devices"}),r.jsx(de,{variant:"ghost",size:"sm",onClick:n,children:"Dismiss"})]})}function we(e){var t;return((t=e.marketingName)==null?void 0:t.trim())||e.name||e.udid}function Ee(e){if(!e)return"9 / 16";const t=Number(e.screenWidth),n=Number(e.screenHeight);if(Number.isFinite(t)&&Number.isFinite(n)&&t>0&&n>0)return`${t} / ${n}`;const o=(e.platform||"").toLowerCase();return o==="tvos"||o==="androidtv"||o==="android-tv"?"16 / 9":"9 / 16"}function se(e){const t=Number(e.screenWidth),n=Number(e.screenHeight);return{udid:e.udid,name:we(e),mjpegPort:0,aspect:Ee(e),screenWidth:Number.isFinite(t)&&t>0?t:void 0,screenHeight:Number.isFinite(n)&&n>0?n:void 0,platform:e.platform}}function qt(e,t){return t?"blocked":e?"remove":"add"}function ae(e,t,n){return!n||!e?!1:e===`manual_${n}_${t}`}function Jt(e,t){if(!e.busy)return;const n=ve(e);return n?n.startsWith("manual_")?ae(n,e.udid,t)?"manual_self":"manual_other":"automation":"unknown"}function Zt(e,t){return e.busy?ae(ve(e),e.udid,t):!1}function Qt(e,t){return e>0&&t==="idle"}function er(e,t,n){const o=[],i=[];for(const g of e){const u=t.find(p=>p.udid===g.udid),N=(u==null?void 0:u.name)||g.name||g.udid;u?u.offline?i.push({name:N,reason:"offline"}):u.busy&&!ae(u.session_id,u.udid,n)?i.push({name:N,reason:"in_use"}):o.push(u):i.push({name:N,reason:"gone"})}return{restore:o,skipped:i}}const Ne=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function tr(e,t){return`Released ${Ne(e,"device")} after ${t} minutes without activity.`}const rr={in_use:"is now in use by someone else.",offline:"is offline.",gone:"is no longer connected."};function nr(e,t){return t.length===0?null:[e>0?`Restored ${Ne(e,"device")}.`:"No devices restored.",...t.map(o=>`${o.name} ${rr[o.reason]}`)].join(" ")}function or(){let e=Promise.resolve();return{enqueue(t){const n=e.then(t,t);return e=n.then(()=>{},()=>{}),n}}}const me=["mousemove","mousedown","keydown","touchstart","wheel"];function sr({idleAfterMs:e,warningSec:t,onWarning:n,onTimeout:o,enabled:i}){const[g,u]=d.useState(!1),[N,p]=d.useState(null),E=d.useRef(null),l=d.useRef(null),v=d.useRef(!1),f=d.useRef(n),j=d.useRef(o);f.current=n,j.current=o;function y(){E.current&&(clearTimeout(E.current),E.current=null),l.current&&(clearInterval(l.current),l.current=null)}function x(){v.current=!0,u(!0),p(t),f.current(t);let T=t;l.current=setInterval(()=>{T-=1,T<=0?(y(),v.current=!1,u(!1),p(null),j.current()):p(T)},1e3)}function R(){y(),v.current=!1,u(!1),p(null);const T=e-t*1e3;E.current=setTimeout(x,Math.max(0,T))}function O(){i&&R()}return d.useEffect(()=>{if(!i){y(),v.current=!1,u(!1),p(null);return}function T(){v.current||R()}return me.forEach(w=>window.addEventListener(w,T,{passive:!0})),R(),()=>{me.forEach(w=>window.removeEventListener(w,T)),y()}},[i,e,t]),{warning:g,remainingSec:N,reset:O}}const ge=5*60*1e3,ar=30;function ir(e,t){return{udid:e.udid,name:we(e),altName:e.name,platform:e.platform,busy:e.busy,busyReason:Jt(e,t),mjpegServerPort:e.mjpegServerPort,offline:!!e.offline}}function Er(){const[e,t]=pt(),[n,o]=d.useState([]),[i,g]=d.useState("loading"),[u,N]=d.useState(0),[p,E]=d.useState(null),l=d.useRef(!1),v=d.useRef(or());d.useEffect(()=>{let s=!1;return fetch("/xenon/api/auth/me",{credentials:"include"}).then(c=>c.ok?c.json():null).then(c=>{!s&&(c!=null&&c.userId)&&E(c.userId)}).catch(()=>{}),()=>{s=!0}},[]),d.useEffect(()=>{let s=!1;const c=async()=>{try{const S=await D.getDevices();if(s)return;o(Array.isArray(S)?S:[]),g("ready")}catch{s||g("error")}};c();const b=window.setInterval(c,5e3);return()=>{s=!0,window.clearInterval(b)}},[u]),d.useEffect(()=>{let s=!1;if(!(!p||l.current))return l.current=!0,(async()=>{var S;let c=[],b=[];try{const H=await D.getDevices();c=Array.isArray(H)?H:[];const U=c.filter(z=>Zt(z,p));if(b=(await Promise.all(U.map(async z=>{try{const W=await fetch(`/xenon/api/control/${encodeURIComponent(z.udid)}/stream/status`);if(!W.ok)return null;const P=await W.json();return(P==null?void 0:P.status)==="running"?z:null}catch{return null}}))).filter(z=>z!==null).map(se),s)return;b.length>0&&t({type:"SET_TILES",tiles:b})}catch{}try{const{serverNow:H,groups:U}=await at(),M=U[0];if(s||!M)return;const z=new Set(b.map(A=>A.udid)),W=M.recordings.filter(A=>!z.has(A.udid)).map(A=>c.find(F=>F.udid===A.udid)).filter(A=>!!A).map(se);W.length>0&&t({type:"SET_TILES",tiles:[...b,...W]});const P={};for(const A of M.annotations){let F;try{F=JSON.parse(A.geometry)}catch{continue}(P[S=A.recordingId]??(P[S]=[])).push({shape:A.shape,color:A.color,geometry:F,text:A.text??void 0})}t({type:"REHYDRATE_RECORDING",groupId:M.groupId,startedAt:Date.now()-(H-Date.parse(M.startedAt)),tileIds:Object.fromEntries(M.recordings.map(A=>[A.udid,A.id])),compositeEnabled:M.compositeEnabled,overlayAnnotations:P})}catch{}})(),()=>{s=!0}},[p,t]),d.useEffect(()=>{for(const s of e.tiles){if(s.screenWidth&&s.screenHeight)continue;const c=n.find(H=>H.udid===s.udid);if(!c)continue;const b=Number(c.screenWidth),S=Number(c.screenHeight);Number.isFinite(b)&&b>0&&Number.isFinite(S)&&S>0&&t({type:"PATCH_TILE_DIMS",udid:s.udid,screenWidth:b,screenHeight:S,aspect:Ee(c)})}},[n,e.tiles,t]);const f=d.useMemo(()=>new Set(e.tiles.map(s=>s.udid)),[e.tiles]),j=d.useMemo(()=>n.map(s=>ir(s,p)),[n,p]),y=async s=>{t({type:"ADD_TILE",tile:se(s)});const c=await D.startStream(s.udid).catch(()=>null);We(c)&&t({type:"REMOVE_TILE",udid:s.udid})},x=async s=>{const c=qt(e.tiles.some(S=>S.udid===s),e.recording);if(c==="blocked"){t({type:"SET_ERROR_BANNER",message:"Stop recording before changing the devices on the grid."});return}if(c==="remove"){await R(s);return}const b=n.find(S=>S.udid===s);b&&await y(b)},R=async s=>{t({type:"REMOVE_TILE",udid:s});try{await fetch(`/xenon/api/control/${encodeURIComponent(s)}/stream/leave`,{method:"POST"})}catch{}N(c=>c+1)},O=(s,c,b)=>{if(!e.groupId)return;const S=e.groupId,H=e.startedAt?Date.now()-e.startedAt:0,U={recordingId:s,timecodeMs:H,shape:c.shape,geometry:JSON.stringify(c.geometry),color:c.color,text:c.text};v.current.enqueue(async()=>{try{return await le(S,b?{...U,image:b}:U)}catch(M){if(!b)throw M;return le(S,U)}}).catch(M=>t({type:"SET_ERROR_BANNER",message:`Annotation failed: ${M.message}`}))},T=()=>{if(!e.groupId)return;const s=e.groupId,c=e.startedAt?Date.now()-e.startedAt:0;t({type:"CLEAR_OVERLAY_ANNOTATIONS"}),v.current.enqueue(()=>it(s,c)).catch(()=>t({type:"SET_ERROR_BANNER",message:"Couldn't clear marks from the recording. They will still appear in the video."}))},w=()=>{for(const s of e.tiles){const c=`/xenon/api/control/${encodeURIComponent(s.udid)}/stream/leave`;try{navigator.sendBeacon?navigator.sendBeacon(c):fetch(c,{method:"POST",keepalive:!0}).catch(()=>{})}catch{}}e.tiles.forEach(s=>t({type:"REMOVE_TILE",udid:s.udid}))},[C,$]=d.useState(null),V=async()=>{const s=C==null?void 0:C.tiles;if(!s)return;const c=er(s,n,p);for(const S of c.restore)await y(S);const b=nr(c.restore.length,c.skipped);$(b?{message:b,tiles:null}:null),N(S=>S+1)},m=sr({idleAfterMs:ge,warningSec:ar,enabled:Qt(e.tiles.length,e.recordingPhase),onWarning:()=>{},onTimeout:()=>{const s=e.tiles;w(),$({message:tr(s.length,ge/6e4),tiles:s})}});return r.jsxs(ye.Provider,{value:{state:e,dispatch:t},children:[r.jsxs("div",{className:"flex flex-col h-full p-4 gap-3",children:[r.jsxs("header",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(lt,{icon:He,children:"Live devices"}),r.jsx(yt,{value:e.layout,onChange:s=>t({type:"SET_LAYOUT",layout:s})})]}),r.jsx(Kt,{selectedUdids:e.tiles.map(s=>s.udid),onClearMarks:T})]}),e.banner&&r.jsxs("div",{role:"alert",className:`text-sm rounded border px-3 py-2 flex items-center gap-2 ${e.banner.tone==="error"?"border-[rgb(var(--rgb-red)/0.4)] bg-[rgb(var(--rgb-red)/0.1)] text-[var(--red-100)]":"border-[rgb(var(--rgb-success)/0.4)] bg-[rgb(var(--rgb-success)/0.1)] text-[var(--text)]"}`,children:[r.jsx("span",{className:"flex-1",children:e.banner.message}),r.jsx("button",{type:"button",className:"text-xs opacity-80 hover:opacity-100",onClick:()=>t({type:"SET_BANNER",banner:null}),children:"Dismiss"})]}),C&&r.jsx(Xt,{message:C.message,onRestore:C.tiles&&!e.recording?V:void 0,onDismiss:()=>$(null)}),r.jsxs("div",{className:"grid grid-cols-[260px_1fr] gap-3 flex-1 min-h-0",children:[r.jsxs("aside",{className:"flex flex-col gap-2 border border-[var(--border)] rounded p-3 overflow-y-auto min-h-0",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs text-[var(--text-dim)]",children:"Devices"}),r.jsx("button",{className:"text-xs underline opacity-70 hover:opacity-100",onClick:()=>N(s=>s+1),children:"Refresh"})]}),r.jsx(bt,{devices:j,inMosaic:f,onToggle:x,status:i}),r.jsx("p",{className:"mt-2 text-[11px] text-[var(--text-dim)] leading-relaxed",children:"Click a device to add it to the grid. Record captures every device on the grid; after Stop, download the video."})]}),r.jsx("main",{className:"border border-[var(--border)] rounded p-2 overflow-y-auto h-full min-h-0",children:r.jsx(Ut,{layout:e.layout,tiles:e.tiles,annotateMode:e.annotateMode,shape:e.shape,color:e.color,overlayAnnotationsByRecording:e.overlayAnnotations,onOverlayAnnotationsChange:(s,c)=>t({type:"SET_OVERLAY_ANNOTATIONS",recordingId:s,annotations:c}),onAnnotation:O,onRemove:R,onDropDevice:x})})]})]}),m.warning&&m.remainingSec!==null&&r.jsx(Yt,{remainingSec:m.remainingSec,onContinue:m.reset,onReleaseNow:w})]})}export{Er as default};
@@ -1 +1 @@
1
- import{j as s}from"./index-BxaH84UO.js";const i=({icon:e,title:m,description:t,action:a})=>s.jsxs("div",{className:"empty-state",children:[e&&s.jsx("div",{className:"empty-state-icon",children:e}),s.jsx("div",{className:"empty-state-title",children:m}),t&&s.jsx("div",{className:"empty-state-desc",children:t}),a&&s.jsx("div",{className:"empty-state-action",children:a})]});export{i as E};
1
+ import{j as s}from"./index-EkaQM1DK.js";const i=({icon:e,title:m,description:t,action:a})=>s.jsxs("div",{className:"empty-state",children:[e&&s.jsx("div",{className:"empty-state-icon",children:e}),s.jsx("div",{className:"empty-state-title",children:m}),t&&s.jsx("div",{className:"empty-state-desc",children:t}),a&&s.jsx("div",{className:"empty-state-action",children:a})]});export{i as E};
@@ -1 +1 @@
1
- import{j as s}from"./index-BxaH84UO.js";const r=({label:e,description:l,children:c,error:a,htmlFor:d})=>s.jsxs("div",{className:"fg",children:[s.jsx("label",{className:"fg-label",htmlFor:d,children:e}),l&&s.jsx("div",{className:"fg-desc",children:l}),s.jsx("div",{className:"fg-control",children:c}),a&&s.jsx("div",{className:"fg-error",children:a})]});export{r as F};
1
+ import{j as s}from"./index-EkaQM1DK.js";const r=({label:e,description:l,children:c,error:a,htmlFor:d})=>s.jsxs("div",{className:"fg",children:[s.jsx("label",{className:"fg-label",htmlFor:d,children:e}),l&&s.jsx("div",{className:"fg-desc",children:l}),s.jsx("div",{className:"fg-control",children:c}),a&&s.jsx("div",{className:"fg-error",children:a})]});export{r as F};
@@ -1 +1 @@
1
- import{r as t,j as s,v as d}from"./index-BxaH84UO.js";import{P as b,M as C,a as g}from"./Menu-DP8XOm1A.js";import{P as k}from"./plus-u0x2Y5uW.js";function F({name:a,value:r,anyValue:o,options:u,onChange:f}){const[m,p]=t.useState(!1),x=t.useRef(null),h=t.useRef(null),c=r!==o,l=u.find(e=>e.value===r),n=()=>{var e;p(!1),(e=h.current)==null||e.focus()},j=t.useCallback(e=>{const i=(e==null?void 0:e.querySelector('[aria-checked="true"]'))??(e==null?void 0:e.querySelector('[role="menuitemradio"]'));i==null||i.focus()},[]);return s.jsxs("span",{ref:x,className:`fm${c?" fm-set":""}`,children:[s.jsx("button",{ref:h,type:"button",className:"fm-trigger","aria-haspopup":"menu","aria-expanded":m,onClick:()=>p(e=>!e),children:c?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"fm-name",children:[a,":"]})," ",(l==null?void 0:l.label)??r]}):s.jsxs(s.Fragment,{children:[s.jsx(k,{size:12,"aria-hidden":"true"}),a]})}),c&&s.jsx("button",{type:"button",className:"fm-clear","aria-label":`Clear ${a.toLowerCase()} filter`,onClick:()=>{f(o),n()},children:s.jsx(d,{size:12,"aria-hidden":"true"})}),s.jsx(b,{open:m,onClose:n,anchorRef:x,placement:"bottom-start",children:s.jsx("div",{ref:j,children:s.jsx(C,{children:u.map(e=>s.jsx(g,{checked:e.value===r,note:e.note,trailing:s.jsx("span",{className:"fm-count",children:e.count}),onClick:()=>{f(e.value),n()},children:e.label},e.value))})})})]})}export{F};
1
+ import{r as t,j as s,v as d}from"./index-EkaQM1DK.js";import{P as b,M as C,a as g}from"./Menu-Cbo9mdTk.js";import{P as k}from"./plus-BGvWvpBB.js";function F({name:a,value:r,anyValue:o,options:u,onChange:f}){const[m,p]=t.useState(!1),x=t.useRef(null),h=t.useRef(null),c=r!==o,l=u.find(e=>e.value===r),n=()=>{var e;p(!1),(e=h.current)==null||e.focus()},j=t.useCallback(e=>{const i=(e==null?void 0:e.querySelector('[aria-checked="true"]'))??(e==null?void 0:e.querySelector('[role="menuitemradio"]'));i==null||i.focus()},[]);return s.jsxs("span",{ref:x,className:`fm${c?" fm-set":""}`,children:[s.jsx("button",{ref:h,type:"button",className:"fm-trigger","aria-haspopup":"menu","aria-expanded":m,onClick:()=>p(e=>!e),children:c?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"fm-name",children:[a,":"]})," ",(l==null?void 0:l.label)??r]}):s.jsxs(s.Fragment,{children:[s.jsx(k,{size:12,"aria-hidden":"true"}),a]})}),c&&s.jsx("button",{type:"button",className:"fm-clear","aria-label":`Clear ${a.toLowerCase()} filter`,onClick:()=>{f(o),n()},children:s.jsx(d,{size:12,"aria-hidden":"true"})}),s.jsx(b,{open:m,onClose:n,anchorRef:x,placement:"bottom-start",children:s.jsx("div",{ref:j,children:s.jsx(C,{children:u.map(e=>s.jsx(g,{checked:e.value===r,note:e.note,trailing:s.jsx("span",{className:"fm-count",children:e.count}),onClick:()=>{f(e.value),n()},children:e.label},e.value))})})})]})}export{F};
@@ -1 +1 @@
1
- import{r as x,x as Ve,j as C,a1 as Ye,a0 as Ke,R as Z}from"./index-BxaH84UO.js";import{P as lt,b as ht,a as st,u as ce,f as Nt,i as Xe,D as Ge,g as Ut,d as Ue,e as tt,c as qe}from"./index-BEk1D5-B.js";import{C as Ze}from"./check-BbvtnP8m.js";const Je=["top","right","bottom","left"],U=Math.min,j=Math.max,gt=Math.round,mt=Math.floor,V=t=>({x:t,y:t}),Qe={left:"right",right:"left",bottom:"top",top:"bottom"};function Tt(t,e,n){return j(t,U(e,n))}function K(t,e){return typeof t=="function"?t(e):t}function X(t){return t.split("-")[0]}function ot(t){return t.split("-")[1]}function Ft(t){return t==="x"?"y":"x"}function Lt(t){return t==="y"?"height":"width"}function z(t){const e=t[0];return e==="t"||e==="b"?"y":"x"}function _t(t){return Ft(z(t))}function tn(t,e,n){n===void 0&&(n=!1);const o=ot(t),r=_t(t),i=Lt(r);let s=r==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[i]>e.floating[i]&&(s=wt(s)),[s,wt(s)]}function en(t){const e=wt(t);return[Dt(t),e,Dt(e)]}function Dt(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const qt=["left","right"],Zt=["right","left"],nn=["top","bottom"],on=["bottom","top"];function rn(t,e,n){switch(t){case"top":case"bottom":return n?e?Zt:qt:e?qt:Zt;case"left":case"right":return e?nn:on;default:return[]}}function sn(t,e,n,o){const r=ot(t);let i=rn(X(t),n==="start",o);return r&&(i=i.map(s=>s+"-"+r),e&&(i=i.concat(i.map(Dt)))),i}function wt(t){const e=X(t);return Qe[e]+t.slice(e.length)}function cn(t){return{top:0,right:0,bottom:0,left:0,...t}}function le(t){return typeof t!="number"?cn(t):{top:t,right:t,bottom:t,left:t}}function xt(t){const{x:e,y:n,width:o,height:r}=t;return{width:o,height:r,top:n,left:e,right:e+o,bottom:n+r,x:e,y:n}}function Jt(t,e,n){let{reference:o,floating:r}=t;const i=z(e),s=_t(e),c=Lt(s),a=X(e),f=i==="y",l=o.x+o.width/2-r.width/2,u=o.y+o.height/2-r.height/2,m=o[c]/2-r[c]/2;let d;switch(a){case"top":d={x:l,y:o.y-r.height};break;case"bottom":d={x:l,y:o.y+o.height};break;case"right":d={x:o.x+o.width,y:u};break;case"left":d={x:o.x-r.width,y:u};break;default:d={x:o.x,y:o.y}}switch(ot(e)){case"start":d[s]-=m*(n&&f?-1:1);break;case"end":d[s]+=m*(n&&f?-1:1);break}return d}async function ln(t,e){var n;e===void 0&&(e={});const{x:o,y:r,platform:i,rects:s,elements:c,strategy:a}=t,{boundary:f="clippingAncestors",rootBoundary:l="viewport",elementContext:u="floating",altBoundary:m=!1,padding:d=0}=K(e,t),p=le(d),h=c[m?u==="floating"?"reference":"floating":u],w=xt(await i.getClippingRect({element:(n=await(i.isElement==null?void 0:i.isElement(h)))==null||n?h:h.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(c.floating)),boundary:f,rootBoundary:l,strategy:a})),b=u==="floating"?{x:o,y:r,width:s.floating.width,height:s.floating.height}:s.reference,y=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c.floating)),v=await(i.isElement==null?void 0:i.isElement(y))?await(i.getScale==null?void 0:i.getScale(y))||{x:1,y:1}:{x:1,y:1},A=xt(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:b,offsetParent:y,strategy:a}):b);return{top:(w.top-A.top+p.top)/v.y,bottom:(A.bottom-w.bottom+p.bottom)/v.y,left:(w.left-A.left+p.left)/v.x,right:(A.right-w.right+p.right)/v.x}}const an=50,fn=async(t,e,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:s}=n,c=s.detectOverflow?s:{...s,detectOverflow:ln},a=await(s.isRTL==null?void 0:s.isRTL(e));let f=await s.getElementRects({reference:t,floating:e,strategy:r}),{x:l,y:u}=Jt(f,o,a),m=o,d=0;const p={};for(let g=0;g<i.length;g++){const h=i[g];if(!h)continue;const{name:w,fn:b}=h,{x:y,y:v,data:A,reset:R}=await b({x:l,y:u,initialPlacement:o,placement:m,strategy:r,middlewareData:p,rects:f,platform:c,elements:{reference:t,floating:e}});l=y??l,u=v??u,p[w]={...p[w],...A},R&&d<an&&(d++,typeof R=="object"&&(R.placement&&(m=R.placement),R.rects&&(f=R.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:r}):R.rects),{x:l,y:u}=Jt(f,m,a)),g=-1)}return{x:l,y:u,placement:m,strategy:r,middlewareData:p}},un=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:i,platform:s,elements:c,middlewareData:a}=e,{element:f,padding:l=0}=K(t,e)||{};if(f==null)return{};const u=le(l),m={x:n,y:o},d=_t(r),p=Lt(d),g=await s.getDimensions(f),h=d==="y",w=h?"top":"left",b=h?"bottom":"right",y=h?"clientHeight":"clientWidth",v=i.reference[p]+i.reference[d]-m[d]-i.floating[p],A=m[d]-i.reference[d],R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(f));let P=R?R[y]:0;(!P||!await(s.isElement==null?void 0:s.isElement(R)))&&(P=c.floating[y]||i.floating[p]);const O=v/2-A/2,L=P/2-g[p]/2-1,D=U(u[w],L),M=U(u[b],L),F=D,I=P-g[p]-M,T=P/2-g[p]/2+O,$=Tt(F,T,I),E=!a.arrow&&ot(r)!=null&&T!==$&&i.reference[p]/2-(T<F?D:M)-g[p]/2<0,N=E?T<F?T-F:T-I:0;return{[d]:m[d]+N,data:{[d]:$,centerOffset:T-$-N,...E&&{alignmentOffset:N}},reset:E}}}),dn=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;const{placement:r,middlewareData:i,rects:s,initialPlacement:c,platform:a,elements:f}=e,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:m,fallbackStrategy:d="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:g=!0,...h}=K(t,e);if((n=i.arrow)!=null&&n.alignmentOffset)return{};const w=X(r),b=z(c),y=X(c)===c,v=await(a.isRTL==null?void 0:a.isRTL(f.floating)),A=m||(y||!g?[wt(c)]:en(c)),R=p!=="none";!m&&R&&A.push(...sn(c,g,p,v));const P=[c,...A],O=await a.detectOverflow(e,h),L=[];let D=((o=i.flip)==null?void 0:o.overflows)||[];if(l&&L.push(O[w]),u){const T=tn(r,s,v);L.push(O[T[0]],O[T[1]])}if(D=[...D,{placement:r,overflows:L}],!L.every(T=>T<=0)){var M,F;const T=(((M=i.flip)==null?void 0:M.index)||0)+1,$=P[T];if($&&(!(u==="alignment"?b!==z($):!1)||D.every(S=>z(S.placement)===b?S.overflows[0]>0:!0)))return{data:{index:T,overflows:D},reset:{placement:$}};let E=(F=D.filter(N=>N.overflows[0]<=0).sort((N,S)=>N.overflows[1]-S.overflows[1])[0])==null?void 0:F.placement;if(!E)switch(d){case"bestFit":{var I;const N=(I=D.filter(S=>{if(R){const _=z(S.placement);return _===b||_==="y"}return!0}).map(S=>[S.placement,S.overflows.filter(_=>_>0).reduce((_,B)=>_+B,0)]).sort((S,_)=>S[1]-_[1])[0])==null?void 0:I[0];N&&(E=N);break}case"initialPlacement":E=c;break}if(r!==E)return{reset:{placement:E}}}return{}}}};function Qt(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function te(t){return Je.some(e=>t[e]>=0)}const mn=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n,platform:o}=e,{strategy:r="referenceHidden",...i}=K(t,e);switch(r){case"referenceHidden":{const s=await o.detectOverflow(e,{...i,elementContext:"reference"}),c=Qt(s,n.reference);return{data:{referenceHiddenOffsets:c,referenceHidden:te(c)}}}case"escaped":{const s=await o.detectOverflow(e,{...i,altBoundary:!0}),c=Qt(s,n.floating);return{data:{escapedOffsets:c,escaped:te(c)}}}default:return{}}}}},ae=new Set(["left","top"]);async function pn(t,e){const{placement:n,platform:o,elements:r}=t,i=await(o.isRTL==null?void 0:o.isRTL(r.floating)),s=X(n),c=ot(n),a=z(n)==="y",f=ae.has(s)?-1:1,l=i&&a?-1:1,u=K(e,t);let{mainAxis:m,crossAxis:d,alignmentAxis:p}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return c&&typeof p=="number"&&(d=c==="end"?p*-1:p),a?{x:d*l,y:m*f}:{x:m*f,y:d*l}}const hn=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:r,y:i,placement:s,middlewareData:c}=e,a=await pn(e,t);return s===((n=c.offset)==null?void 0:n.placement)&&(o=c.arrow)!=null&&o.alignmentOffset?{}:{x:r+a.x,y:i+a.y,data:{...a,placement:s}}}}},gn=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:r,platform:i}=e,{mainAxis:s=!0,crossAxis:c=!1,limiter:a={fn:w=>{let{x:b,y}=w;return{x:b,y}}},...f}=K(t,e),l={x:n,y:o},u=await i.detectOverflow(e,f),m=z(X(r)),d=Ft(m);let p=l[d],g=l[m];if(s){const w=d==="y"?"top":"left",b=d==="y"?"bottom":"right",y=p+u[w],v=p-u[b];p=Tt(y,p,v)}if(c){const w=m==="y"?"top":"left",b=m==="y"?"bottom":"right",y=g+u[w],v=g-u[b];g=Tt(y,g,v)}const h=a.fn({...e,[d]:p,[m]:g});return{...h,data:{x:h.x-n,y:h.y-o,enabled:{[d]:s,[m]:c}}}}}},wn=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:o,placement:r,rects:i,middlewareData:s}=e,{offset:c=0,mainAxis:a=!0,crossAxis:f=!0}=K(t,e),l={x:n,y:o},u=z(r),m=Ft(u);let d=l[m],p=l[u];const g=K(c,e),h=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(a){const y=m==="y"?"height":"width",v=i.reference[m]-i.floating[y]+h.mainAxis,A=i.reference[m]+i.reference[y]-h.mainAxis;d<v?d=v:d>A&&(d=A)}if(f){var w,b;const y=m==="y"?"width":"height",v=ae.has(X(r)),A=i.reference[u]-i.floating[y]+(v&&((w=s.offset)==null?void 0:w[u])||0)+(v?0:h.crossAxis),R=i.reference[u]+i.reference[y]+(v?0:((b=s.offset)==null?void 0:b[u])||0)-(v?h.crossAxis:0);p<A?p=A:p>R&&(p=R)}return{[m]:d,[u]:p}}}},xn=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,o;const{placement:r,rects:i,platform:s,elements:c}=e,{apply:a=()=>{},...f}=K(t,e),l=await s.detectOverflow(e,f),u=X(r),m=ot(r),d=z(r)==="y",{width:p,height:g}=i.floating;let h,w;u==="top"||u==="bottom"?(h=u,w=m===(await(s.isRTL==null?void 0:s.isRTL(c.floating))?"start":"end")?"left":"right"):(w=u,h=m==="end"?"top":"bottom");const b=g-l.top-l.bottom,y=p-l.left-l.right,v=U(g-l[h],b),A=U(p-l[w],y),R=!e.middlewareData.shift;let P=v,O=A;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(O=y),(o=e.middlewareData.shift)!=null&&o.enabled.y&&(P=b),R&&!m){const D=j(l.left,0),M=j(l.right,0),F=j(l.top,0),I=j(l.bottom,0);d?O=p-2*(D!==0||M!==0?D+M:j(l.left,l.right)):P=g-2*(F!==0||I!==0?F+I:j(l.top,l.bottom))}await a({...e,availableWidth:O,availableHeight:P});const L=await s.getDimensions(c.floating);return p!==L.width||g!==L.height?{reset:{rects:!0}}:{}}}};function bt(){return typeof window<"u"}function rt(t){return fe(t)?(t.nodeName||"").toLowerCase():"#document"}function k(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Y(t){var e;return(e=(fe(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function fe(t){return bt()?t instanceof Node||t instanceof k(t).Node:!1}function W(t){return bt()?t instanceof Element||t instanceof k(t).Element:!1}function G(t){return bt()?t instanceof HTMLElement||t instanceof k(t).HTMLElement:!1}function ee(t){return!bt()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof k(t).ShadowRoot}function at(t){const{overflow:e,overflowX:n,overflowY:o,display:r}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&r!=="inline"&&r!=="contents"}function yn(t){return/^(table|td|th)$/.test(rt(t))}function Rt(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const vn=/transform|translate|scale|rotate|perspective|filter/,bn=/paint|layout|strict|content/,J=t=>!!t&&t!=="none";let St;function $t(t){const e=W(t)?H(t):t;return J(e.transform)||J(e.translate)||J(e.scale)||J(e.rotate)||J(e.perspective)||!jt()&&(J(e.backdropFilter)||J(e.filter))||vn.test(e.willChange||"")||bn.test(e.contain||"")}function Rn(t){let e=q(t);for(;G(e)&&!nt(e);){if($t(e))return e;if(Rt(e))return null;e=q(e)}return null}function jt(){return St==null&&(St=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),St}function nt(t){return/^(html|body|#document)$/.test(rt(t))}function H(t){return k(t).getComputedStyle(t)}function At(t){return W(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function q(t){if(rt(t)==="html")return t;const e=t.assignedSlot||t.parentNode||ee(t)&&t.host||Y(t);return ee(e)?e.host:e}function ue(t){const e=q(t);return nt(e)?t.ownerDocument?t.ownerDocument.body:t.body:G(e)&&at(e)?e:ue(e)}function ct(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);const r=ue(t),i=r===((o=t.ownerDocument)==null?void 0:o.body),s=k(r);if(i){const c=It(s);return e.concat(s,s.visualViewport||[],at(r)?r:[],c&&n?ct(c):[])}else return e.concat(r,ct(r,[],n))}function It(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function de(t){const e=H(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=G(t),i=r?t.offsetWidth:n,s=r?t.offsetHeight:o,c=gt(n)!==i||gt(o)!==s;return c&&(n=i,o=s),{width:n,height:o,$:c}}function kt(t){return W(t)?t:t.contextElement}function et(t){const e=kt(t);if(!G(e))return V(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:i}=de(e);let s=(i?gt(n.width):n.width)/o,c=(i?gt(n.height):n.height)/r;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}const An=V(0);function me(t){const e=k(t);return!jt()||!e.visualViewport?An:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Cn(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==k(t)?!1:e}function Q(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);const r=t.getBoundingClientRect(),i=kt(t);let s=V(1);e&&(o?W(o)&&(s=et(o)):s=et(t));const c=Cn(i,n,o)?me(i):V(0);let a=(r.left+c.x)/s.x,f=(r.top+c.y)/s.y,l=r.width/s.x,u=r.height/s.y;if(i){const m=k(i),d=o&&W(o)?k(o):o;let p=m,g=It(p);for(;g&&o&&d!==p;){const h=et(g),w=g.getBoundingClientRect(),b=H(g),y=w.left+(g.clientLeft+parseFloat(b.paddingLeft))*h.x,v=w.top+(g.clientTop+parseFloat(b.paddingTop))*h.y;a*=h.x,f*=h.y,l*=h.x,u*=h.y,a+=y,f+=v,p=k(g),g=It(p)}}return xt({width:l,height:u,x:a,y:f})}function Ct(t,e){const n=At(t).scrollLeft;return e?e.left+n:Q(Y(t)).left+n}function pe(t,e){const n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Ct(t,n),r=n.top+e.scrollTop;return{x:o,y:r}}function Sn(t){let{elements:e,rect:n,offsetParent:o,strategy:r}=t;const i=r==="fixed",s=Y(o),c=e?Rt(e.floating):!1;if(o===s||c&&i)return n;let a={scrollLeft:0,scrollTop:0},f=V(1);const l=V(0),u=G(o);if((u||!u&&!i)&&((rt(o)!=="body"||at(s))&&(a=At(o)),u)){const d=Q(o);f=et(o),l.x=d.x+o.clientLeft,l.y=d.y+o.clientTop}const m=s&&!u&&!i?pe(s,a):V(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-a.scrollLeft*f.x+l.x+m.x,y:n.y*f.y-a.scrollTop*f.y+l.y+m.y}}function On(t){return Array.from(t.getClientRects())}function Pn(t){const e=Y(t),n=At(t),o=t.ownerDocument.body,r=j(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),i=j(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let s=-n.scrollLeft+Ct(t);const c=-n.scrollTop;return H(o).direction==="rtl"&&(s+=j(e.clientWidth,o.clientWidth)-r),{width:r,height:i,x:s,y:c}}const ne=25;function En(t,e){const n=k(t),o=Y(t),r=n.visualViewport;let i=o.clientWidth,s=o.clientHeight,c=0,a=0;if(r){i=r.width,s=r.height;const l=jt();(!l||l&&e==="fixed")&&(c=r.offsetLeft,a=r.offsetTop)}const f=Ct(o);if(f<=0){const l=o.ownerDocument,u=l.body,m=getComputedStyle(u),d=l.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,p=Math.abs(o.clientWidth-u.clientWidth-d);p<=ne&&(i-=p)}else f<=ne&&(i+=f);return{width:i,height:s,x:c,y:a}}function Tn(t,e){const n=Q(t,!0,e==="fixed"),o=n.top+t.clientTop,r=n.left+t.clientLeft,i=G(t)?et(t):V(1),s=t.clientWidth*i.x,c=t.clientHeight*i.y,a=r*i.x,f=o*i.y;return{width:s,height:c,x:a,y:f}}function oe(t,e,n){let o;if(e==="viewport")o=En(t,n);else if(e==="document")o=Pn(Y(t));else if(W(e))o=Tn(e,n);else{const r=me(t);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return xt(o)}function he(t,e){const n=q(t);return n===e||!W(n)||nt(n)?!1:H(n).position==="fixed"||he(n,e)}function Dn(t,e){const n=e.get(t);if(n)return n;let o=ct(t,[],!1).filter(c=>W(c)&&rt(c)!=="body"),r=null;const i=H(t).position==="fixed";let s=i?q(t):t;for(;W(s)&&!nt(s);){const c=H(s),a=$t(s);!a&&c.position==="fixed"&&(r=null),(i?!a&&!r:!a&&c.position==="static"&&!!r&&(r.position==="absolute"||r.position==="fixed")||at(s)&&!a&&he(t,s))?o=o.filter(l=>l!==s):r=c,s=q(s)}return e.set(t,o),o}function In(t){let{element:e,boundary:n,rootBoundary:o,strategy:r}=t;const s=[...n==="clippingAncestors"?Rt(e)?[]:Dn(e,this._c):[].concat(n),o],c=oe(e,s[0],r);let a=c.top,f=c.right,l=c.bottom,u=c.left;for(let m=1;m<s.length;m++){const d=oe(e,s[m],r);a=j(d.top,a),f=U(d.right,f),l=U(d.bottom,l),u=j(d.left,u)}return{width:f-u,height:l-a,x:u,y:a}}function Mn(t){const{width:e,height:n}=de(t);return{width:e,height:n}}function Nn(t,e,n){const o=G(e),r=Y(e),i=n==="fixed",s=Q(t,!0,i,e);let c={scrollLeft:0,scrollTop:0};const a=V(0);function f(){a.x=Ct(r)}if(o||!o&&!i)if((rt(e)!=="body"||at(r))&&(c=At(e)),o){const d=Q(e,!0,i,e);a.x=d.x+e.clientLeft,a.y=d.y+e.clientTop}else r&&f();i&&!o&&r&&f();const l=r&&!o&&!i?pe(r,c):V(0),u=s.left+c.scrollLeft-a.x-l.x,m=s.top+c.scrollTop-a.y-l.y;return{x:u,y:m,width:s.width,height:s.height}}function Ot(t){return H(t).position==="static"}function re(t,e){if(!G(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Y(t)===n&&(n=n.ownerDocument.body),n}function ge(t,e){const n=k(t);if(Rt(t))return n;if(!G(t)){let r=q(t);for(;r&&!nt(r);){if(W(r)&&!Ot(r))return r;r=q(r)}return n}let o=re(t,e);for(;o&&yn(o)&&Ot(o);)o=re(o,e);return o&&nt(o)&&Ot(o)&&!$t(o)?n:o||Rn(t)||n}const Fn=async function(t){const e=this.getOffsetParent||ge,n=this.getDimensions,o=await n(t.floating);return{reference:Nn(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ln(t){return H(t).direction==="rtl"}const _n={convertOffsetParentRelativeRectToViewportRelativeRect:Sn,getDocumentElement:Y,getClippingRect:In,getOffsetParent:ge,getElementRects:Fn,getClientRects:On,getDimensions:Mn,getScale:et,isElement:W,isRTL:Ln};function we(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function $n(t,e){let n=null,o;const r=Y(t);function i(){var c;clearTimeout(o),(c=n)==null||c.disconnect(),n=null}function s(c,a){c===void 0&&(c=!1),a===void 0&&(a=1),i();const f=t.getBoundingClientRect(),{left:l,top:u,width:m,height:d}=f;if(c||e(),!m||!d)return;const p=mt(u),g=mt(r.clientWidth-(l+m)),h=mt(r.clientHeight-(u+d)),w=mt(l),y={rootMargin:-p+"px "+-g+"px "+-h+"px "+-w+"px",threshold:j(0,U(1,a))||1};let v=!0;function A(R){const P=R[0].intersectionRatio;if(P!==a){if(!v)return s();P?s(!1,P):o=setTimeout(()=>{s(!1,1e-7)},1e3)}P===1&&!we(f,t.getBoundingClientRect())&&s(),v=!1}try{n=new IntersectionObserver(A,{...y,root:r.ownerDocument})}catch{n=new IntersectionObserver(A,y)}n.observe(t)}return s(!0),i}function jn(t,e,n,o){o===void 0&&(o={});const{ancestorScroll:r=!0,ancestorResize:i=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:a=!1}=o,f=kt(t),l=r||i?[...f?ct(f):[],...e?ct(e):[]]:[];l.forEach(w=>{r&&w.addEventListener("scroll",n,{passive:!0}),i&&w.addEventListener("resize",n)});const u=f&&c?$n(f,n):null;let m=-1,d=null;s&&(d=new ResizeObserver(w=>{let[b]=w;b&&b.target===f&&d&&e&&(d.unobserve(e),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var y;(y=d)==null||y.observe(e)})),n()}),f&&!a&&d.observe(f),e&&d.observe(e));let p,g=a?Q(t):null;a&&h();function h(){const w=Q(t);g&&!we(g,w)&&n(),g=w,p=requestAnimationFrame(h)}return n(),()=>{var w;l.forEach(b=>{r&&b.removeEventListener("scroll",n),i&&b.removeEventListener("resize",n)}),u==null||u(),(w=d)==null||w.disconnect(),d=null,a&&cancelAnimationFrame(p)}}const kn=hn,Wn=gn,Hn=dn,Bn=xn,zn=mn,ie=un,Vn=wn,Yn=(t,e,n)=>{const o=new Map,r={platform:_n,...n},i={...r.platform,_c:o};return fn(t,e,{...r,platform:i})};var Kn=typeof document<"u",Xn=function(){},pt=Kn?x.useLayoutEffect:Xn;function yt(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,o,r;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(o=n;o--!==0;)if(!yt(t[o],e[o]))return!1;return!0}if(r=Object.keys(t),n=r.length,n!==Object.keys(e).length)return!1;for(o=n;o--!==0;)if(!{}.hasOwnProperty.call(e,r[o]))return!1;for(o=n;o--!==0;){const i=r[o];if(!(i==="_owner"&&t.$$typeof)&&!yt(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}function xe(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function se(t,e){const n=xe(t);return Math.round(e*n)/n}function Pt(t){const e=x.useRef(t);return pt(()=>{e.current=t}),e}function Gn(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:o=[],platform:r,elements:{reference:i,floating:s}={},transform:c=!0,whileElementsMounted:a,open:f}=t,[l,u]=x.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[m,d]=x.useState(o);yt(m,o)||d(o);const[p,g]=x.useState(null),[h,w]=x.useState(null),b=x.useCallback(S=>{S!==R.current&&(R.current=S,g(S))},[]),y=x.useCallback(S=>{S!==P.current&&(P.current=S,w(S))},[]),v=i||p,A=s||h,R=x.useRef(null),P=x.useRef(null),O=x.useRef(l),L=a!=null,D=Pt(a),M=Pt(r),F=Pt(f),I=x.useCallback(()=>{if(!R.current||!P.current)return;const S={placement:e,strategy:n,middleware:m};M.current&&(S.platform=M.current),Yn(R.current,P.current,S).then(_=>{const B={..._,isPositioned:F.current!==!1};T.current&&!yt(O.current,B)&&(O.current=B,Ve.flushSync(()=>{u(B)}))})},[m,e,n,M,F]);pt(()=>{f===!1&&O.current.isPositioned&&(O.current.isPositioned=!1,u(S=>({...S,isPositioned:!1})))},[f]);const T=x.useRef(!1);pt(()=>(T.current=!0,()=>{T.current=!1}),[]),pt(()=>{if(v&&(R.current=v),A&&(P.current=A),v&&A){if(D.current)return D.current(v,A,I);I()}},[v,A,I,D,L]);const $=x.useMemo(()=>({reference:R,floating:P,setReference:b,setFloating:y}),[b,y]),E=x.useMemo(()=>({reference:v,floating:A}),[v,A]),N=x.useMemo(()=>{const S={position:n,left:0,top:0};if(!E.floating)return S;const _=se(E.floating,l.x),B=se(E.floating,l.y);return c?{...S,transform:"translate("+_+"px, "+B+"px)",...xe(E.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:_,top:B}},[n,c,E.floating,l.x,l.y]);return x.useMemo(()=>({...l,update:I,refs:$,elements:E,floatingStyles:N}),[l,I,$,E,N])}const Un=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:o,padding:r}=typeof t=="function"?t(n):t;return o&&e(o)?o.current!=null?ie({element:o.current,padding:r}).fn(n):{}:o?ie({element:o,padding:r}).fn(n):{}}}},qn=(t,e)=>{const n=kn(t);return{name:n.name,fn:n.fn,options:[t,e]}},Zn=(t,e)=>{const n=Wn(t);return{name:n.name,fn:n.fn,options:[t,e]}},Jn=(t,e)=>({fn:Vn(t).fn,options:[t,e]}),Qn=(t,e)=>{const n=Hn(t);return{name:n.name,fn:n.fn,options:[t,e]}},to=(t,e)=>{const n=Bn(t);return{name:n.name,fn:n.fn,options:[t,e]}},eo=(t,e)=>{const n=zn(t);return{name:n.name,fn:n.fn,options:[t,e]}},no=(t,e)=>{const n=Un(t);return{name:n.name,fn:n.fn,options:[t,e]}};var oo="Arrow",ye=x.forwardRef((t,e)=>{const{children:n,width:o=10,height:r=5,...i}=t;return C.jsx(lt.svg,{...i,ref:e,width:o,height:r,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:C.jsx("polygon",{points:"0,0 30,0 15,10"})})});ye.displayName=oo;var ro=ye;function io(t){const[e,n]=x.useState(void 0);return ht(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const o=new ResizeObserver(r=>{if(!Array.isArray(r)||!r.length)return;const i=r[0];let s,c;if("borderBoxSize"in i){const a=i.borderBoxSize,f=Array.isArray(a)?a[0]:a;s=f.inlineSize,c=f.blockSize}else s=t.offsetWidth,c=t.offsetHeight;n({width:s,height:c})});return o.observe(t,{box:"border-box"}),()=>o.unobserve(t)}else n(void 0)},[t]),e}var Wt="Popper",[ve]=Nt(Wt),[so,be]=ve(Wt),Re=t=>{const{__scopePopper:e,children:n}=t,[o,r]=x.useState(null);return C.jsx(so,{scope:e,anchor:o,onAnchorChange:r,children:n})};Re.displayName=Wt;var Ae="PopperAnchor",Ce=x.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:o,...r}=t,i=be(Ae,n),s=x.useRef(null),c=st(e,s),a=x.useRef(null);return x.useEffect(()=>{const f=a.current;a.current=(o==null?void 0:o.current)||s.current,f!==a.current&&i.onAnchorChange(a.current)}),o?null:C.jsx(lt.div,{...r,ref:c})});Ce.displayName=Ae;var Ht="PopperContent",[co,lo]=ve(Ht),Se=x.forwardRef((t,e)=>{var Bt,zt,Vt,Yt,Kt,Xt;const{__scopePopper:n,side:o="bottom",sideOffset:r=0,align:i="center",alignOffset:s=0,arrowPadding:c=0,avoidCollisions:a=!0,collisionBoundary:f=[],collisionPadding:l=0,sticky:u="partial",hideWhenDetached:m=!1,updatePositionStrategy:d="optimized",onPlaced:p,...g}=t,h=be(Ht,n),[w,b]=x.useState(null),y=st(e,it=>b(it)),[v,A]=x.useState(null),R=io(v),P=(R==null?void 0:R.width)??0,O=(R==null?void 0:R.height)??0,L=o+(i!=="center"?"-"+i:""),D=typeof l=="number"?l:{top:0,right:0,bottom:0,left:0,...l},M=Array.isArray(f)?f:[f],F=M.length>0,I={padding:D,boundary:M.filter(uo),altBoundary:F},{refs:T,floatingStyles:$,placement:E,isPositioned:N,middlewareData:S}=Gn({strategy:"fixed",placement:L,whileElementsMounted:(...it)=>jn(...it,{animationFrame:d==="always"}),elements:{reference:h.anchor},middleware:[qn({mainAxis:r+O,alignmentAxis:s}),a&&Zn({mainAxis:!0,crossAxis:!1,limiter:u==="partial"?Jn():void 0,...I}),a&&Qn({...I}),to({...I,apply:({elements:it,rects:Gt,availableWidth:We,availableHeight:He})=>{const{width:Be,height:ze}=Gt.reference,dt=it.floating.style;dt.setProperty("--radix-popper-available-width",`${We}px`),dt.setProperty("--radix-popper-available-height",`${He}px`),dt.setProperty("--radix-popper-anchor-width",`${Be}px`),dt.setProperty("--radix-popper-anchor-height",`${ze}px`)}}),v&&no({element:v,padding:c}),mo({arrowWidth:P,arrowHeight:O}),m&&eo({strategy:"referenceHidden",...I})]}),[_,B]=Pe(E),ut=ce(p);ht(()=>{N&&(ut==null||ut())},[N,ut]);const Le=(Bt=S.arrow)==null?void 0:Bt.x,_e=(zt=S.arrow)==null?void 0:zt.y,$e=((Vt=S.arrow)==null?void 0:Vt.centerOffset)!==0,[je,ke]=x.useState();return ht(()=>{w&&ke(window.getComputedStyle(w).zIndex)},[w]),C.jsx("div",{ref:T.setFloating,"data-radix-popper-content-wrapper":"",style:{...$,transform:N?$.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:je,"--radix-popper-transform-origin":[(Yt=S.transformOrigin)==null?void 0:Yt.x,(Kt=S.transformOrigin)==null?void 0:Kt.y].join(" "),...((Xt=S.hide)==null?void 0:Xt.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:C.jsx(co,{scope:n,placedSide:_,onArrowChange:A,arrowX:Le,arrowY:_e,shouldHideArrow:$e,children:C.jsx(lt.div,{"data-side":_,"data-align":B,...g,ref:y,style:{...g.style,animation:N?void 0:"none"}})})})});Se.displayName=Ht;var Oe="PopperArrow",ao={top:"bottom",right:"left",bottom:"top",left:"right"},fo=x.forwardRef(function(e,n){const{__scopePopper:o,...r}=e,i=lo(Oe,o),s=ao[i.placedSide];return C.jsx("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[s]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:C.jsx(ro,{...r,ref:n,style:{...r.style,display:"block"}})})});fo.displayName=Oe;function uo(t){return t!==null}var mo=t=>({name:"transformOrigin",options:t,fn(e){var h,w,b;const{placement:n,rects:o,middlewareData:r}=e,s=((h=r.arrow)==null?void 0:h.centerOffset)!==0,c=s?0:t.arrowWidth,a=s?0:t.arrowHeight,[f,l]=Pe(n),u={start:"0%",center:"50%",end:"100%"}[l],m=(((w=r.arrow)==null?void 0:w.x)??0)+c/2,d=(((b=r.arrow)==null?void 0:b.y)??0)+a/2;let p="",g="";return f==="bottom"?(p=s?u:`${m}px`,g=`${-a}px`):f==="top"?(p=s?u:`${m}px`,g=`${o.floating.height+a}px`):f==="right"?(p=`${-a}px`,g=s?u:`${d}px`):f==="left"&&(p=`${o.floating.width+a}px`,g=s?u:`${d}px`),{data:{x:p,y:g}}}});function Pe(t){const[e,n="center"]=t.split("-");return[e,n]}var po=Re,ho=Ce,go=Se,wo=Symbol.for("react.lazy"),vt=Ye[" use ".trim().toString()];function xo(t){return typeof t=="object"&&t!==null&&"then"in t}function Ee(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===wo&&"_payload"in t&&xo(t._payload)}function yo(t){const e=vo(t),n=x.forwardRef((o,r)=>{let{children:i,...s}=o;Ee(i)&&typeof vt=="function"&&(i=vt(i._payload));const c=x.Children.toArray(i),a=c.find(Ro);if(a){const f=a.props.children,l=c.map(u=>u===a?x.Children.count(f)>1?x.Children.only(null):x.isValidElement(f)?f.props.children:null:u);return C.jsx(e,{...s,ref:r,children:x.isValidElement(f)?x.cloneElement(f,void 0,l):null})}return C.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function vo(t){const e=x.forwardRef((n,o)=>{let{children:r,...i}=n;if(Ee(r)&&typeof vt=="function"&&(r=vt(r._payload)),x.isValidElement(r)){const s=Co(r),c=Ao(i,r.props);return r.type!==x.Fragment&&(c.ref=o?Xe(o,s):s),x.cloneElement(r,c)}return x.Children.count(r)>1?x.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var bo=Symbol("radix.slottable");function Ro(t){return x.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===bo}function Ao(t,e){const n={...e};for(const o in e){const r=t[o],i=e[o];/^on[A-Z]/.test(o)?r&&i?n[o]=(...c)=>{const a=i(...c);return r(...c),a}:r&&(n[o]=r):o==="style"?n[o]={...r,...i}:o==="className"&&(n[o]=[r,i].filter(Boolean).join(" "))}return{...t,...n}}function Co(t){var o,r;let e=(o=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(r=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var So=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Oo=So.reduce((t,e)=>{const n=yo(`Primitive.${e}`),o=x.forwardRef((r,i)=>{const{asChild:s,...c}=r,a=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),C.jsx(a,{...c,ref:i})});return o.displayName=`Primitive.${e}`,{...t,[e]:o}},{}),Po="Portal",Te=x.forwardRef((t,e)=>{var c;const{container:n,...o}=t,[r,i]=x.useState(!1);ht(()=>i(!0),[]);const s=n||r&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return s?Ke.createPortal(C.jsx(Oo.div,{...o,ref:e}),s):null});Te.displayName=Po;const Ko=({open:t,onClose:e,anchorRef:n,placement:o="bottom-end",children:r})=>{const i=x.useRef(null);if(x.useEffect(()=>{if(!t)return;const f=l=>{var u,m;t&&((u=i.current)!=null&&u.contains(l.target)||(m=n.current)!=null&&m.contains(l.target)||e())};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[t,e,n]),!t)return null;const s=o.startsWith("top")?"top":"bottom",c=o.endsWith("end")?"end":"start",a=o.startsWith("top")?8:4;return C.jsxs(po,{children:[C.jsx(ho,{virtualRef:n}),C.jsx(Te,{children:C.jsx(Ge,{onEscapeKeyDown:f=>{f.preventDefault(),e()},onPointerDownOutside:f=>{var l;if((l=n.current)!=null&&l.contains(f.target)){f.preventDefault();return}e()},children:C.jsx(go,{ref:i,side:s,align:c,sideOffset:a,className:`popover popover-${o}`,role:"dialog",children:r})})})]})};function Eo(t){const e=t+"CollectionProvider",[n,o]=Nt(e),[r,i]=n(e,{collectionRef:{current:null},itemMap:new Map}),s=g=>{const{scope:h,children:w}=g,b=Z.useRef(null),y=Z.useRef(new Map).current;return C.jsx(r,{scope:h,itemMap:y,collectionRef:b,children:w})};s.displayName=e;const c=t+"CollectionSlot",a=Ut(c),f=Z.forwardRef((g,h)=>{const{scope:w,children:b}=g,y=i(c,w),v=st(h,y.collectionRef);return C.jsx(a,{ref:v,children:b})});f.displayName=c;const l=t+"CollectionItemSlot",u="data-radix-collection-item",m=Ut(l),d=Z.forwardRef((g,h)=>{const{scope:w,children:b,...y}=g,v=Z.useRef(null),A=st(h,v),R=i(l,w);return Z.useEffect(()=>(R.itemMap.set(v,{ref:v,...y}),()=>void R.itemMap.delete(v))),C.jsx(m,{[u]:"",ref:A,children:b})});d.displayName=l;function p(g){const h=i(t+"CollectionConsumer",g);return Z.useCallback(()=>{const b=h.collectionRef.current;if(!b)return[];const y=Array.from(b.querySelectorAll(`[${u}]`));return Array.from(h.itemMap.values()).sort((R,P)=>y.indexOf(R.ref.current)-y.indexOf(P.ref.current))},[h.collectionRef,h.itemMap])}return[{Provider:s,Slot:f,ItemSlot:d},p,o]}var To=x.createContext(void 0);function Do(t){const e=x.useContext(To);return t||e||"ltr"}var Et="rovingFocusGroup.onEntryFocus",Io={bubbles:!1,cancelable:!0},ft="RovingFocusGroup",[Mt,De,Mo]=Eo(ft),[No]=Nt(ft,[Mo]),[Fo,Lo]=No(ft),Ie=x.forwardRef((t,e)=>C.jsx(Mt.Provider,{scope:t.__scopeRovingFocusGroup,children:C.jsx(Mt.Slot,{scope:t.__scopeRovingFocusGroup,children:C.jsx(_o,{...t,ref:e})})}));Ie.displayName=ft;var _o=x.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:o,loop:r=!1,dir:i,currentTabStopId:s,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:a,onEntryFocus:f,preventScrollOnEntryFocus:l=!1,...u}=t,m=x.useRef(null),d=st(e,m),p=Do(i),[g,h]=qe({prop:s,defaultProp:c??null,onChange:a,caller:ft}),[w,b]=x.useState(!1),y=ce(f),v=De(n),A=x.useRef(!1),[R,P]=x.useState(0);return x.useEffect(()=>{const O=m.current;if(O)return O.addEventListener(Et,y),()=>O.removeEventListener(Et,y)},[y]),C.jsx(Fo,{scope:n,orientation:o,dir:p,loop:r,currentTabStopId:g,onItemFocus:x.useCallback(O=>h(O),[h]),onItemShiftTab:x.useCallback(()=>b(!0),[]),onFocusableItemAdd:x.useCallback(()=>P(O=>O+1),[]),onFocusableItemRemove:x.useCallback(()=>P(O=>O-1),[]),children:C.jsx(lt.div,{tabIndex:w||R===0?-1:0,"data-orientation":o,...u,ref:d,style:{outline:"none",...t.style},onMouseDown:tt(t.onMouseDown,()=>{A.current=!0}),onFocus:tt(t.onFocus,O=>{const L=!A.current;if(O.target===O.currentTarget&&L&&!w){const D=new CustomEvent(Et,Io);if(O.currentTarget.dispatchEvent(D),!D.defaultPrevented){const M=v().filter(E=>E.focusable),F=M.find(E=>E.active),I=M.find(E=>E.id===g),$=[F,I,...M].filter(Boolean).map(E=>E.ref.current);Fe($,l)}}A.current=!1}),onBlur:tt(t.onBlur,()=>b(!1))})})}),Me="RovingFocusGroupItem",Ne=x.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:o=!0,active:r=!1,tabStopId:i,children:s,...c}=t,a=Ue(),f=i||a,l=Lo(Me,n),u=l.currentTabStopId===f,m=De(n),{onFocusableItemAdd:d,onFocusableItemRemove:p,currentTabStopId:g}=l;return x.useEffect(()=>{if(o)return d(),()=>p()},[o,d,p]),C.jsx(Mt.ItemSlot,{scope:n,id:f,focusable:o,active:r,children:C.jsx(lt.span,{tabIndex:u?0:-1,"data-orientation":l.orientation,...c,ref:e,onMouseDown:tt(t.onMouseDown,h=>{o?l.onItemFocus(f):h.preventDefault()}),onFocus:tt(t.onFocus,()=>l.onItemFocus(f)),onKeyDown:tt(t.onKeyDown,h=>{if(h.key==="Tab"&&h.shiftKey){l.onItemShiftTab();return}if(h.target!==h.currentTarget)return;const w=ko(h,l.orientation,l.dir);if(w!==void 0){if(h.metaKey||h.ctrlKey||h.altKey||h.shiftKey)return;h.preventDefault();let y=m().filter(v=>v.focusable).map(v=>v.ref.current);if(w==="last")y.reverse();else if(w==="prev"||w==="next"){w==="prev"&&y.reverse();const v=y.indexOf(h.currentTarget);y=l.loop?Wo(y,v+1):y.slice(v+1)}setTimeout(()=>Fe(y))}}),children:typeof s=="function"?s({isCurrentTabStop:u,hasTabStop:g!=null}):s})})});Ne.displayName=Me;var $o={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function jo(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function ko(t,e,n){const o=jo(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(o))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(o)))return $o[o]}function Fe(t,e=!1){const n=document.activeElement;for(const o of t)if(o===n||(o.focus({preventScroll:e}),document.activeElement!==n))return}function Wo(t,e){return t.map((n,o)=>t[(e+o)%t.length])}var Ho=Ie,Bo=Ne;const Xo=({icon:t,children:e,onClick:n,danger:o,disabled:r,checked:i,note:s,trailing:c})=>C.jsx(Bo,{asChild:!0,focusable:!r,active:!1,children:C.jsxs("button",{type:"button",role:i===void 0?"menuitem":"menuitemradio","aria-checked":i,className:`menu-item${o?" menu-item-danger":""}`,onClick:n,disabled:r,children:[i!==void 0&&C.jsx("span",{className:"menu-item-check","aria-hidden":"true",children:i&&C.jsx(Ze,{size:12})}),t&&C.jsx("span",{className:"menu-item-icon",children:t}),C.jsxs("span",{className:"menu-item-label",children:[e,s&&C.jsx("span",{className:"menu-item-note",children:s})]}),c!==void 0&&C.jsx("span",{className:"menu-item-trailing",children:c})]})}),Go=()=>C.jsx("div",{className:"menu-divider",role:"separator"}),Uo=({children:t})=>C.jsx(Ho,{asChild:!0,orientation:"vertical",loop:!0,children:C.jsx("div",{className:"menu",role:"menu",children:t})});export{Uo as M,Ko as P,Xo as a,Go as b};
1
+ import{r as x,x as Ve,j as C,a1 as Ye,a0 as Ke,R as Z}from"./index-EkaQM1DK.js";import{P as lt,b as ht,a as st,u as ce,f as Nt,i as Xe,D as Ge,g as Ut,d as Ue,e as tt,c as qe}from"./index-DWHTp1YP.js";import{C as Ze}from"./check-D8ifHIJR.js";const Je=["top","right","bottom","left"],U=Math.min,j=Math.max,gt=Math.round,mt=Math.floor,V=t=>({x:t,y:t}),Qe={left:"right",right:"left",bottom:"top",top:"bottom"};function Tt(t,e,n){return j(t,U(e,n))}function K(t,e){return typeof t=="function"?t(e):t}function X(t){return t.split("-")[0]}function ot(t){return t.split("-")[1]}function Ft(t){return t==="x"?"y":"x"}function Lt(t){return t==="y"?"height":"width"}function z(t){const e=t[0];return e==="t"||e==="b"?"y":"x"}function _t(t){return Ft(z(t))}function tn(t,e,n){n===void 0&&(n=!1);const o=ot(t),r=_t(t),i=Lt(r);let s=r==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[i]>e.floating[i]&&(s=wt(s)),[s,wt(s)]}function en(t){const e=wt(t);return[Dt(t),e,Dt(e)]}function Dt(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const qt=["left","right"],Zt=["right","left"],nn=["top","bottom"],on=["bottom","top"];function rn(t,e,n){switch(t){case"top":case"bottom":return n?e?Zt:qt:e?qt:Zt;case"left":case"right":return e?nn:on;default:return[]}}function sn(t,e,n,o){const r=ot(t);let i=rn(X(t),n==="start",o);return r&&(i=i.map(s=>s+"-"+r),e&&(i=i.concat(i.map(Dt)))),i}function wt(t){const e=X(t);return Qe[e]+t.slice(e.length)}function cn(t){return{top:0,right:0,bottom:0,left:0,...t}}function le(t){return typeof t!="number"?cn(t):{top:t,right:t,bottom:t,left:t}}function xt(t){const{x:e,y:n,width:o,height:r}=t;return{width:o,height:r,top:n,left:e,right:e+o,bottom:n+r,x:e,y:n}}function Jt(t,e,n){let{reference:o,floating:r}=t;const i=z(e),s=_t(e),c=Lt(s),a=X(e),f=i==="y",l=o.x+o.width/2-r.width/2,u=o.y+o.height/2-r.height/2,m=o[c]/2-r[c]/2;let d;switch(a){case"top":d={x:l,y:o.y-r.height};break;case"bottom":d={x:l,y:o.y+o.height};break;case"right":d={x:o.x+o.width,y:u};break;case"left":d={x:o.x-r.width,y:u};break;default:d={x:o.x,y:o.y}}switch(ot(e)){case"start":d[s]-=m*(n&&f?-1:1);break;case"end":d[s]+=m*(n&&f?-1:1);break}return d}async function ln(t,e){var n;e===void 0&&(e={});const{x:o,y:r,platform:i,rects:s,elements:c,strategy:a}=t,{boundary:f="clippingAncestors",rootBoundary:l="viewport",elementContext:u="floating",altBoundary:m=!1,padding:d=0}=K(e,t),p=le(d),h=c[m?u==="floating"?"reference":"floating":u],w=xt(await i.getClippingRect({element:(n=await(i.isElement==null?void 0:i.isElement(h)))==null||n?h:h.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(c.floating)),boundary:f,rootBoundary:l,strategy:a})),b=u==="floating"?{x:o,y:r,width:s.floating.width,height:s.floating.height}:s.reference,y=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c.floating)),v=await(i.isElement==null?void 0:i.isElement(y))?await(i.getScale==null?void 0:i.getScale(y))||{x:1,y:1}:{x:1,y:1},A=xt(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:b,offsetParent:y,strategy:a}):b);return{top:(w.top-A.top+p.top)/v.y,bottom:(A.bottom-w.bottom+p.bottom)/v.y,left:(w.left-A.left+p.left)/v.x,right:(A.right-w.right+p.right)/v.x}}const an=50,fn=async(t,e,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:s}=n,c=s.detectOverflow?s:{...s,detectOverflow:ln},a=await(s.isRTL==null?void 0:s.isRTL(e));let f=await s.getElementRects({reference:t,floating:e,strategy:r}),{x:l,y:u}=Jt(f,o,a),m=o,d=0;const p={};for(let g=0;g<i.length;g++){const h=i[g];if(!h)continue;const{name:w,fn:b}=h,{x:y,y:v,data:A,reset:R}=await b({x:l,y:u,initialPlacement:o,placement:m,strategy:r,middlewareData:p,rects:f,platform:c,elements:{reference:t,floating:e}});l=y??l,u=v??u,p[w]={...p[w],...A},R&&d<an&&(d++,typeof R=="object"&&(R.placement&&(m=R.placement),R.rects&&(f=R.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:r}):R.rects),{x:l,y:u}=Jt(f,m,a)),g=-1)}return{x:l,y:u,placement:m,strategy:r,middlewareData:p}},un=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:i,platform:s,elements:c,middlewareData:a}=e,{element:f,padding:l=0}=K(t,e)||{};if(f==null)return{};const u=le(l),m={x:n,y:o},d=_t(r),p=Lt(d),g=await s.getDimensions(f),h=d==="y",w=h?"top":"left",b=h?"bottom":"right",y=h?"clientHeight":"clientWidth",v=i.reference[p]+i.reference[d]-m[d]-i.floating[p],A=m[d]-i.reference[d],R=await(s.getOffsetParent==null?void 0:s.getOffsetParent(f));let P=R?R[y]:0;(!P||!await(s.isElement==null?void 0:s.isElement(R)))&&(P=c.floating[y]||i.floating[p]);const O=v/2-A/2,L=P/2-g[p]/2-1,D=U(u[w],L),M=U(u[b],L),F=D,I=P-g[p]-M,T=P/2-g[p]/2+O,$=Tt(F,T,I),E=!a.arrow&&ot(r)!=null&&T!==$&&i.reference[p]/2-(T<F?D:M)-g[p]/2<0,N=E?T<F?T-F:T-I:0;return{[d]:m[d]+N,data:{[d]:$,centerOffset:T-$-N,...E&&{alignmentOffset:N}},reset:E}}}),dn=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;const{placement:r,middlewareData:i,rects:s,initialPlacement:c,platform:a,elements:f}=e,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:m,fallbackStrategy:d="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:g=!0,...h}=K(t,e);if((n=i.arrow)!=null&&n.alignmentOffset)return{};const w=X(r),b=z(c),y=X(c)===c,v=await(a.isRTL==null?void 0:a.isRTL(f.floating)),A=m||(y||!g?[wt(c)]:en(c)),R=p!=="none";!m&&R&&A.push(...sn(c,g,p,v));const P=[c,...A],O=await a.detectOverflow(e,h),L=[];let D=((o=i.flip)==null?void 0:o.overflows)||[];if(l&&L.push(O[w]),u){const T=tn(r,s,v);L.push(O[T[0]],O[T[1]])}if(D=[...D,{placement:r,overflows:L}],!L.every(T=>T<=0)){var M,F;const T=(((M=i.flip)==null?void 0:M.index)||0)+1,$=P[T];if($&&(!(u==="alignment"?b!==z($):!1)||D.every(S=>z(S.placement)===b?S.overflows[0]>0:!0)))return{data:{index:T,overflows:D},reset:{placement:$}};let E=(F=D.filter(N=>N.overflows[0]<=0).sort((N,S)=>N.overflows[1]-S.overflows[1])[0])==null?void 0:F.placement;if(!E)switch(d){case"bestFit":{var I;const N=(I=D.filter(S=>{if(R){const _=z(S.placement);return _===b||_==="y"}return!0}).map(S=>[S.placement,S.overflows.filter(_=>_>0).reduce((_,B)=>_+B,0)]).sort((S,_)=>S[1]-_[1])[0])==null?void 0:I[0];N&&(E=N);break}case"initialPlacement":E=c;break}if(r!==E)return{reset:{placement:E}}}return{}}}};function Qt(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function te(t){return Je.some(e=>t[e]>=0)}const mn=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n,platform:o}=e,{strategy:r="referenceHidden",...i}=K(t,e);switch(r){case"referenceHidden":{const s=await o.detectOverflow(e,{...i,elementContext:"reference"}),c=Qt(s,n.reference);return{data:{referenceHiddenOffsets:c,referenceHidden:te(c)}}}case"escaped":{const s=await o.detectOverflow(e,{...i,altBoundary:!0}),c=Qt(s,n.floating);return{data:{escapedOffsets:c,escaped:te(c)}}}default:return{}}}}},ae=new Set(["left","top"]);async function pn(t,e){const{placement:n,platform:o,elements:r}=t,i=await(o.isRTL==null?void 0:o.isRTL(r.floating)),s=X(n),c=ot(n),a=z(n)==="y",f=ae.has(s)?-1:1,l=i&&a?-1:1,u=K(e,t);let{mainAxis:m,crossAxis:d,alignmentAxis:p}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return c&&typeof p=="number"&&(d=c==="end"?p*-1:p),a?{x:d*l,y:m*f}:{x:m*f,y:d*l}}const hn=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:r,y:i,placement:s,middlewareData:c}=e,a=await pn(e,t);return s===((n=c.offset)==null?void 0:n.placement)&&(o=c.arrow)!=null&&o.alignmentOffset?{}:{x:r+a.x,y:i+a.y,data:{...a,placement:s}}}}},gn=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:r,platform:i}=e,{mainAxis:s=!0,crossAxis:c=!1,limiter:a={fn:w=>{let{x:b,y}=w;return{x:b,y}}},...f}=K(t,e),l={x:n,y:o},u=await i.detectOverflow(e,f),m=z(X(r)),d=Ft(m);let p=l[d],g=l[m];if(s){const w=d==="y"?"top":"left",b=d==="y"?"bottom":"right",y=p+u[w],v=p-u[b];p=Tt(y,p,v)}if(c){const w=m==="y"?"top":"left",b=m==="y"?"bottom":"right",y=g+u[w],v=g-u[b];g=Tt(y,g,v)}const h=a.fn({...e,[d]:p,[m]:g});return{...h,data:{x:h.x-n,y:h.y-o,enabled:{[d]:s,[m]:c}}}}}},wn=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:o,placement:r,rects:i,middlewareData:s}=e,{offset:c=0,mainAxis:a=!0,crossAxis:f=!0}=K(t,e),l={x:n,y:o},u=z(r),m=Ft(u);let d=l[m],p=l[u];const g=K(c,e),h=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(a){const y=m==="y"?"height":"width",v=i.reference[m]-i.floating[y]+h.mainAxis,A=i.reference[m]+i.reference[y]-h.mainAxis;d<v?d=v:d>A&&(d=A)}if(f){var w,b;const y=m==="y"?"width":"height",v=ae.has(X(r)),A=i.reference[u]-i.floating[y]+(v&&((w=s.offset)==null?void 0:w[u])||0)+(v?0:h.crossAxis),R=i.reference[u]+i.reference[y]+(v?0:((b=s.offset)==null?void 0:b[u])||0)-(v?h.crossAxis:0);p<A?p=A:p>R&&(p=R)}return{[m]:d,[u]:p}}}},xn=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,o;const{placement:r,rects:i,platform:s,elements:c}=e,{apply:a=()=>{},...f}=K(t,e),l=await s.detectOverflow(e,f),u=X(r),m=ot(r),d=z(r)==="y",{width:p,height:g}=i.floating;let h,w;u==="top"||u==="bottom"?(h=u,w=m===(await(s.isRTL==null?void 0:s.isRTL(c.floating))?"start":"end")?"left":"right"):(w=u,h=m==="end"?"top":"bottom");const b=g-l.top-l.bottom,y=p-l.left-l.right,v=U(g-l[h],b),A=U(p-l[w],y),R=!e.middlewareData.shift;let P=v,O=A;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(O=y),(o=e.middlewareData.shift)!=null&&o.enabled.y&&(P=b),R&&!m){const D=j(l.left,0),M=j(l.right,0),F=j(l.top,0),I=j(l.bottom,0);d?O=p-2*(D!==0||M!==0?D+M:j(l.left,l.right)):P=g-2*(F!==0||I!==0?F+I:j(l.top,l.bottom))}await a({...e,availableWidth:O,availableHeight:P});const L=await s.getDimensions(c.floating);return p!==L.width||g!==L.height?{reset:{rects:!0}}:{}}}};function bt(){return typeof window<"u"}function rt(t){return fe(t)?(t.nodeName||"").toLowerCase():"#document"}function k(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Y(t){var e;return(e=(fe(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function fe(t){return bt()?t instanceof Node||t instanceof k(t).Node:!1}function W(t){return bt()?t instanceof Element||t instanceof k(t).Element:!1}function G(t){return bt()?t instanceof HTMLElement||t instanceof k(t).HTMLElement:!1}function ee(t){return!bt()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof k(t).ShadowRoot}function at(t){const{overflow:e,overflowX:n,overflowY:o,display:r}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&r!=="inline"&&r!=="contents"}function yn(t){return/^(table|td|th)$/.test(rt(t))}function Rt(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const vn=/transform|translate|scale|rotate|perspective|filter/,bn=/paint|layout|strict|content/,J=t=>!!t&&t!=="none";let St;function $t(t){const e=W(t)?H(t):t;return J(e.transform)||J(e.translate)||J(e.scale)||J(e.rotate)||J(e.perspective)||!jt()&&(J(e.backdropFilter)||J(e.filter))||vn.test(e.willChange||"")||bn.test(e.contain||"")}function Rn(t){let e=q(t);for(;G(e)&&!nt(e);){if($t(e))return e;if(Rt(e))return null;e=q(e)}return null}function jt(){return St==null&&(St=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),St}function nt(t){return/^(html|body|#document)$/.test(rt(t))}function H(t){return k(t).getComputedStyle(t)}function At(t){return W(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function q(t){if(rt(t)==="html")return t;const e=t.assignedSlot||t.parentNode||ee(t)&&t.host||Y(t);return ee(e)?e.host:e}function ue(t){const e=q(t);return nt(e)?t.ownerDocument?t.ownerDocument.body:t.body:G(e)&&at(e)?e:ue(e)}function ct(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);const r=ue(t),i=r===((o=t.ownerDocument)==null?void 0:o.body),s=k(r);if(i){const c=It(s);return e.concat(s,s.visualViewport||[],at(r)?r:[],c&&n?ct(c):[])}else return e.concat(r,ct(r,[],n))}function It(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function de(t){const e=H(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=G(t),i=r?t.offsetWidth:n,s=r?t.offsetHeight:o,c=gt(n)!==i||gt(o)!==s;return c&&(n=i,o=s),{width:n,height:o,$:c}}function kt(t){return W(t)?t:t.contextElement}function et(t){const e=kt(t);if(!G(e))return V(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:i}=de(e);let s=(i?gt(n.width):n.width)/o,c=(i?gt(n.height):n.height)/r;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}const An=V(0);function me(t){const e=k(t);return!jt()||!e.visualViewport?An:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Cn(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==k(t)?!1:e}function Q(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);const r=t.getBoundingClientRect(),i=kt(t);let s=V(1);e&&(o?W(o)&&(s=et(o)):s=et(t));const c=Cn(i,n,o)?me(i):V(0);let a=(r.left+c.x)/s.x,f=(r.top+c.y)/s.y,l=r.width/s.x,u=r.height/s.y;if(i){const m=k(i),d=o&&W(o)?k(o):o;let p=m,g=It(p);for(;g&&o&&d!==p;){const h=et(g),w=g.getBoundingClientRect(),b=H(g),y=w.left+(g.clientLeft+parseFloat(b.paddingLeft))*h.x,v=w.top+(g.clientTop+parseFloat(b.paddingTop))*h.y;a*=h.x,f*=h.y,l*=h.x,u*=h.y,a+=y,f+=v,p=k(g),g=It(p)}}return xt({width:l,height:u,x:a,y:f})}function Ct(t,e){const n=At(t).scrollLeft;return e?e.left+n:Q(Y(t)).left+n}function pe(t,e){const n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-Ct(t,n),r=n.top+e.scrollTop;return{x:o,y:r}}function Sn(t){let{elements:e,rect:n,offsetParent:o,strategy:r}=t;const i=r==="fixed",s=Y(o),c=e?Rt(e.floating):!1;if(o===s||c&&i)return n;let a={scrollLeft:0,scrollTop:0},f=V(1);const l=V(0),u=G(o);if((u||!u&&!i)&&((rt(o)!=="body"||at(s))&&(a=At(o)),u)){const d=Q(o);f=et(o),l.x=d.x+o.clientLeft,l.y=d.y+o.clientTop}const m=s&&!u&&!i?pe(s,a):V(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-a.scrollLeft*f.x+l.x+m.x,y:n.y*f.y-a.scrollTop*f.y+l.y+m.y}}function On(t){return Array.from(t.getClientRects())}function Pn(t){const e=Y(t),n=At(t),o=t.ownerDocument.body,r=j(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),i=j(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let s=-n.scrollLeft+Ct(t);const c=-n.scrollTop;return H(o).direction==="rtl"&&(s+=j(e.clientWidth,o.clientWidth)-r),{width:r,height:i,x:s,y:c}}const ne=25;function En(t,e){const n=k(t),o=Y(t),r=n.visualViewport;let i=o.clientWidth,s=o.clientHeight,c=0,a=0;if(r){i=r.width,s=r.height;const l=jt();(!l||l&&e==="fixed")&&(c=r.offsetLeft,a=r.offsetTop)}const f=Ct(o);if(f<=0){const l=o.ownerDocument,u=l.body,m=getComputedStyle(u),d=l.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,p=Math.abs(o.clientWidth-u.clientWidth-d);p<=ne&&(i-=p)}else f<=ne&&(i+=f);return{width:i,height:s,x:c,y:a}}function Tn(t,e){const n=Q(t,!0,e==="fixed"),o=n.top+t.clientTop,r=n.left+t.clientLeft,i=G(t)?et(t):V(1),s=t.clientWidth*i.x,c=t.clientHeight*i.y,a=r*i.x,f=o*i.y;return{width:s,height:c,x:a,y:f}}function oe(t,e,n){let o;if(e==="viewport")o=En(t,n);else if(e==="document")o=Pn(Y(t));else if(W(e))o=Tn(e,n);else{const r=me(t);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return xt(o)}function he(t,e){const n=q(t);return n===e||!W(n)||nt(n)?!1:H(n).position==="fixed"||he(n,e)}function Dn(t,e){const n=e.get(t);if(n)return n;let o=ct(t,[],!1).filter(c=>W(c)&&rt(c)!=="body"),r=null;const i=H(t).position==="fixed";let s=i?q(t):t;for(;W(s)&&!nt(s);){const c=H(s),a=$t(s);!a&&c.position==="fixed"&&(r=null),(i?!a&&!r:!a&&c.position==="static"&&!!r&&(r.position==="absolute"||r.position==="fixed")||at(s)&&!a&&he(t,s))?o=o.filter(l=>l!==s):r=c,s=q(s)}return e.set(t,o),o}function In(t){let{element:e,boundary:n,rootBoundary:o,strategy:r}=t;const s=[...n==="clippingAncestors"?Rt(e)?[]:Dn(e,this._c):[].concat(n),o],c=oe(e,s[0],r);let a=c.top,f=c.right,l=c.bottom,u=c.left;for(let m=1;m<s.length;m++){const d=oe(e,s[m],r);a=j(d.top,a),f=U(d.right,f),l=U(d.bottom,l),u=j(d.left,u)}return{width:f-u,height:l-a,x:u,y:a}}function Mn(t){const{width:e,height:n}=de(t);return{width:e,height:n}}function Nn(t,e,n){const o=G(e),r=Y(e),i=n==="fixed",s=Q(t,!0,i,e);let c={scrollLeft:0,scrollTop:0};const a=V(0);function f(){a.x=Ct(r)}if(o||!o&&!i)if((rt(e)!=="body"||at(r))&&(c=At(e)),o){const d=Q(e,!0,i,e);a.x=d.x+e.clientLeft,a.y=d.y+e.clientTop}else r&&f();i&&!o&&r&&f();const l=r&&!o&&!i?pe(r,c):V(0),u=s.left+c.scrollLeft-a.x-l.x,m=s.top+c.scrollTop-a.y-l.y;return{x:u,y:m,width:s.width,height:s.height}}function Ot(t){return H(t).position==="static"}function re(t,e){if(!G(t)||H(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Y(t)===n&&(n=n.ownerDocument.body),n}function ge(t,e){const n=k(t);if(Rt(t))return n;if(!G(t)){let r=q(t);for(;r&&!nt(r);){if(W(r)&&!Ot(r))return r;r=q(r)}return n}let o=re(t,e);for(;o&&yn(o)&&Ot(o);)o=re(o,e);return o&&nt(o)&&Ot(o)&&!$t(o)?n:o||Rn(t)||n}const Fn=async function(t){const e=this.getOffsetParent||ge,n=this.getDimensions,o=await n(t.floating);return{reference:Nn(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ln(t){return H(t).direction==="rtl"}const _n={convertOffsetParentRelativeRectToViewportRelativeRect:Sn,getDocumentElement:Y,getClippingRect:In,getOffsetParent:ge,getElementRects:Fn,getClientRects:On,getDimensions:Mn,getScale:et,isElement:W,isRTL:Ln};function we(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function $n(t,e){let n=null,o;const r=Y(t);function i(){var c;clearTimeout(o),(c=n)==null||c.disconnect(),n=null}function s(c,a){c===void 0&&(c=!1),a===void 0&&(a=1),i();const f=t.getBoundingClientRect(),{left:l,top:u,width:m,height:d}=f;if(c||e(),!m||!d)return;const p=mt(u),g=mt(r.clientWidth-(l+m)),h=mt(r.clientHeight-(u+d)),w=mt(l),y={rootMargin:-p+"px "+-g+"px "+-h+"px "+-w+"px",threshold:j(0,U(1,a))||1};let v=!0;function A(R){const P=R[0].intersectionRatio;if(P!==a){if(!v)return s();P?s(!1,P):o=setTimeout(()=>{s(!1,1e-7)},1e3)}P===1&&!we(f,t.getBoundingClientRect())&&s(),v=!1}try{n=new IntersectionObserver(A,{...y,root:r.ownerDocument})}catch{n=new IntersectionObserver(A,y)}n.observe(t)}return s(!0),i}function jn(t,e,n,o){o===void 0&&(o={});const{ancestorScroll:r=!0,ancestorResize:i=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:a=!1}=o,f=kt(t),l=r||i?[...f?ct(f):[],...e?ct(e):[]]:[];l.forEach(w=>{r&&w.addEventListener("scroll",n,{passive:!0}),i&&w.addEventListener("resize",n)});const u=f&&c?$n(f,n):null;let m=-1,d=null;s&&(d=new ResizeObserver(w=>{let[b]=w;b&&b.target===f&&d&&e&&(d.unobserve(e),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var y;(y=d)==null||y.observe(e)})),n()}),f&&!a&&d.observe(f),e&&d.observe(e));let p,g=a?Q(t):null;a&&h();function h(){const w=Q(t);g&&!we(g,w)&&n(),g=w,p=requestAnimationFrame(h)}return n(),()=>{var w;l.forEach(b=>{r&&b.removeEventListener("scroll",n),i&&b.removeEventListener("resize",n)}),u==null||u(),(w=d)==null||w.disconnect(),d=null,a&&cancelAnimationFrame(p)}}const kn=hn,Wn=gn,Hn=dn,Bn=xn,zn=mn,ie=un,Vn=wn,Yn=(t,e,n)=>{const o=new Map,r={platform:_n,...n},i={...r.platform,_c:o};return fn(t,e,{...r,platform:i})};var Kn=typeof document<"u",Xn=function(){},pt=Kn?x.useLayoutEffect:Xn;function yt(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,o,r;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(o=n;o--!==0;)if(!yt(t[o],e[o]))return!1;return!0}if(r=Object.keys(t),n=r.length,n!==Object.keys(e).length)return!1;for(o=n;o--!==0;)if(!{}.hasOwnProperty.call(e,r[o]))return!1;for(o=n;o--!==0;){const i=r[o];if(!(i==="_owner"&&t.$$typeof)&&!yt(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}function xe(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function se(t,e){const n=xe(t);return Math.round(e*n)/n}function Pt(t){const e=x.useRef(t);return pt(()=>{e.current=t}),e}function Gn(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:o=[],platform:r,elements:{reference:i,floating:s}={},transform:c=!0,whileElementsMounted:a,open:f}=t,[l,u]=x.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[m,d]=x.useState(o);yt(m,o)||d(o);const[p,g]=x.useState(null),[h,w]=x.useState(null),b=x.useCallback(S=>{S!==R.current&&(R.current=S,g(S))},[]),y=x.useCallback(S=>{S!==P.current&&(P.current=S,w(S))},[]),v=i||p,A=s||h,R=x.useRef(null),P=x.useRef(null),O=x.useRef(l),L=a!=null,D=Pt(a),M=Pt(r),F=Pt(f),I=x.useCallback(()=>{if(!R.current||!P.current)return;const S={placement:e,strategy:n,middleware:m};M.current&&(S.platform=M.current),Yn(R.current,P.current,S).then(_=>{const B={..._,isPositioned:F.current!==!1};T.current&&!yt(O.current,B)&&(O.current=B,Ve.flushSync(()=>{u(B)}))})},[m,e,n,M,F]);pt(()=>{f===!1&&O.current.isPositioned&&(O.current.isPositioned=!1,u(S=>({...S,isPositioned:!1})))},[f]);const T=x.useRef(!1);pt(()=>(T.current=!0,()=>{T.current=!1}),[]),pt(()=>{if(v&&(R.current=v),A&&(P.current=A),v&&A){if(D.current)return D.current(v,A,I);I()}},[v,A,I,D,L]);const $=x.useMemo(()=>({reference:R,floating:P,setReference:b,setFloating:y}),[b,y]),E=x.useMemo(()=>({reference:v,floating:A}),[v,A]),N=x.useMemo(()=>{const S={position:n,left:0,top:0};if(!E.floating)return S;const _=se(E.floating,l.x),B=se(E.floating,l.y);return c?{...S,transform:"translate("+_+"px, "+B+"px)",...xe(E.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:_,top:B}},[n,c,E.floating,l.x,l.y]);return x.useMemo(()=>({...l,update:I,refs:$,elements:E,floatingStyles:N}),[l,I,$,E,N])}const Un=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:o,padding:r}=typeof t=="function"?t(n):t;return o&&e(o)?o.current!=null?ie({element:o.current,padding:r}).fn(n):{}:o?ie({element:o,padding:r}).fn(n):{}}}},qn=(t,e)=>{const n=kn(t);return{name:n.name,fn:n.fn,options:[t,e]}},Zn=(t,e)=>{const n=Wn(t);return{name:n.name,fn:n.fn,options:[t,e]}},Jn=(t,e)=>({fn:Vn(t).fn,options:[t,e]}),Qn=(t,e)=>{const n=Hn(t);return{name:n.name,fn:n.fn,options:[t,e]}},to=(t,e)=>{const n=Bn(t);return{name:n.name,fn:n.fn,options:[t,e]}},eo=(t,e)=>{const n=zn(t);return{name:n.name,fn:n.fn,options:[t,e]}},no=(t,e)=>{const n=Un(t);return{name:n.name,fn:n.fn,options:[t,e]}};var oo="Arrow",ye=x.forwardRef((t,e)=>{const{children:n,width:o=10,height:r=5,...i}=t;return C.jsx(lt.svg,{...i,ref:e,width:o,height:r,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:C.jsx("polygon",{points:"0,0 30,0 15,10"})})});ye.displayName=oo;var ro=ye;function io(t){const[e,n]=x.useState(void 0);return ht(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const o=new ResizeObserver(r=>{if(!Array.isArray(r)||!r.length)return;const i=r[0];let s,c;if("borderBoxSize"in i){const a=i.borderBoxSize,f=Array.isArray(a)?a[0]:a;s=f.inlineSize,c=f.blockSize}else s=t.offsetWidth,c=t.offsetHeight;n({width:s,height:c})});return o.observe(t,{box:"border-box"}),()=>o.unobserve(t)}else n(void 0)},[t]),e}var Wt="Popper",[ve]=Nt(Wt),[so,be]=ve(Wt),Re=t=>{const{__scopePopper:e,children:n}=t,[o,r]=x.useState(null);return C.jsx(so,{scope:e,anchor:o,onAnchorChange:r,children:n})};Re.displayName=Wt;var Ae="PopperAnchor",Ce=x.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:o,...r}=t,i=be(Ae,n),s=x.useRef(null),c=st(e,s),a=x.useRef(null);return x.useEffect(()=>{const f=a.current;a.current=(o==null?void 0:o.current)||s.current,f!==a.current&&i.onAnchorChange(a.current)}),o?null:C.jsx(lt.div,{...r,ref:c})});Ce.displayName=Ae;var Ht="PopperContent",[co,lo]=ve(Ht),Se=x.forwardRef((t,e)=>{var Bt,zt,Vt,Yt,Kt,Xt;const{__scopePopper:n,side:o="bottom",sideOffset:r=0,align:i="center",alignOffset:s=0,arrowPadding:c=0,avoidCollisions:a=!0,collisionBoundary:f=[],collisionPadding:l=0,sticky:u="partial",hideWhenDetached:m=!1,updatePositionStrategy:d="optimized",onPlaced:p,...g}=t,h=be(Ht,n),[w,b]=x.useState(null),y=st(e,it=>b(it)),[v,A]=x.useState(null),R=io(v),P=(R==null?void 0:R.width)??0,O=(R==null?void 0:R.height)??0,L=o+(i!=="center"?"-"+i:""),D=typeof l=="number"?l:{top:0,right:0,bottom:0,left:0,...l},M=Array.isArray(f)?f:[f],F=M.length>0,I={padding:D,boundary:M.filter(uo),altBoundary:F},{refs:T,floatingStyles:$,placement:E,isPositioned:N,middlewareData:S}=Gn({strategy:"fixed",placement:L,whileElementsMounted:(...it)=>jn(...it,{animationFrame:d==="always"}),elements:{reference:h.anchor},middleware:[qn({mainAxis:r+O,alignmentAxis:s}),a&&Zn({mainAxis:!0,crossAxis:!1,limiter:u==="partial"?Jn():void 0,...I}),a&&Qn({...I}),to({...I,apply:({elements:it,rects:Gt,availableWidth:We,availableHeight:He})=>{const{width:Be,height:ze}=Gt.reference,dt=it.floating.style;dt.setProperty("--radix-popper-available-width",`${We}px`),dt.setProperty("--radix-popper-available-height",`${He}px`),dt.setProperty("--radix-popper-anchor-width",`${Be}px`),dt.setProperty("--radix-popper-anchor-height",`${ze}px`)}}),v&&no({element:v,padding:c}),mo({arrowWidth:P,arrowHeight:O}),m&&eo({strategy:"referenceHidden",...I})]}),[_,B]=Pe(E),ut=ce(p);ht(()=>{N&&(ut==null||ut())},[N,ut]);const Le=(Bt=S.arrow)==null?void 0:Bt.x,_e=(zt=S.arrow)==null?void 0:zt.y,$e=((Vt=S.arrow)==null?void 0:Vt.centerOffset)!==0,[je,ke]=x.useState();return ht(()=>{w&&ke(window.getComputedStyle(w).zIndex)},[w]),C.jsx("div",{ref:T.setFloating,"data-radix-popper-content-wrapper":"",style:{...$,transform:N?$.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:je,"--radix-popper-transform-origin":[(Yt=S.transformOrigin)==null?void 0:Yt.x,(Kt=S.transformOrigin)==null?void 0:Kt.y].join(" "),...((Xt=S.hide)==null?void 0:Xt.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:C.jsx(co,{scope:n,placedSide:_,onArrowChange:A,arrowX:Le,arrowY:_e,shouldHideArrow:$e,children:C.jsx(lt.div,{"data-side":_,"data-align":B,...g,ref:y,style:{...g.style,animation:N?void 0:"none"}})})})});Se.displayName=Ht;var Oe="PopperArrow",ao={top:"bottom",right:"left",bottom:"top",left:"right"},fo=x.forwardRef(function(e,n){const{__scopePopper:o,...r}=e,i=lo(Oe,o),s=ao[i.placedSide];return C.jsx("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[s]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:C.jsx(ro,{...r,ref:n,style:{...r.style,display:"block"}})})});fo.displayName=Oe;function uo(t){return t!==null}var mo=t=>({name:"transformOrigin",options:t,fn(e){var h,w,b;const{placement:n,rects:o,middlewareData:r}=e,s=((h=r.arrow)==null?void 0:h.centerOffset)!==0,c=s?0:t.arrowWidth,a=s?0:t.arrowHeight,[f,l]=Pe(n),u={start:"0%",center:"50%",end:"100%"}[l],m=(((w=r.arrow)==null?void 0:w.x)??0)+c/2,d=(((b=r.arrow)==null?void 0:b.y)??0)+a/2;let p="",g="";return f==="bottom"?(p=s?u:`${m}px`,g=`${-a}px`):f==="top"?(p=s?u:`${m}px`,g=`${o.floating.height+a}px`):f==="right"?(p=`${-a}px`,g=s?u:`${d}px`):f==="left"&&(p=`${o.floating.width+a}px`,g=s?u:`${d}px`),{data:{x:p,y:g}}}});function Pe(t){const[e,n="center"]=t.split("-");return[e,n]}var po=Re,ho=Ce,go=Se,wo=Symbol.for("react.lazy"),vt=Ye[" use ".trim().toString()];function xo(t){return typeof t=="object"&&t!==null&&"then"in t}function Ee(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===wo&&"_payload"in t&&xo(t._payload)}function yo(t){const e=vo(t),n=x.forwardRef((o,r)=>{let{children:i,...s}=o;Ee(i)&&typeof vt=="function"&&(i=vt(i._payload));const c=x.Children.toArray(i),a=c.find(Ro);if(a){const f=a.props.children,l=c.map(u=>u===a?x.Children.count(f)>1?x.Children.only(null):x.isValidElement(f)?f.props.children:null:u);return C.jsx(e,{...s,ref:r,children:x.isValidElement(f)?x.cloneElement(f,void 0,l):null})}return C.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function vo(t){const e=x.forwardRef((n,o)=>{let{children:r,...i}=n;if(Ee(r)&&typeof vt=="function"&&(r=vt(r._payload)),x.isValidElement(r)){const s=Co(r),c=Ao(i,r.props);return r.type!==x.Fragment&&(c.ref=o?Xe(o,s):s),x.cloneElement(r,c)}return x.Children.count(r)>1?x.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var bo=Symbol("radix.slottable");function Ro(t){return x.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===bo}function Ao(t,e){const n={...e};for(const o in e){const r=t[o],i=e[o];/^on[A-Z]/.test(o)?r&&i?n[o]=(...c)=>{const a=i(...c);return r(...c),a}:r&&(n[o]=r):o==="style"?n[o]={...r,...i}:o==="className"&&(n[o]=[r,i].filter(Boolean).join(" "))}return{...t,...n}}function Co(t){var o,r;let e=(o=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(r=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var So=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Oo=So.reduce((t,e)=>{const n=yo(`Primitive.${e}`),o=x.forwardRef((r,i)=>{const{asChild:s,...c}=r,a=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),C.jsx(a,{...c,ref:i})});return o.displayName=`Primitive.${e}`,{...t,[e]:o}},{}),Po="Portal",Te=x.forwardRef((t,e)=>{var c;const{container:n,...o}=t,[r,i]=x.useState(!1);ht(()=>i(!0),[]);const s=n||r&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return s?Ke.createPortal(C.jsx(Oo.div,{...o,ref:e}),s):null});Te.displayName=Po;const Ko=({open:t,onClose:e,anchorRef:n,placement:o="bottom-end",children:r})=>{const i=x.useRef(null);if(x.useEffect(()=>{if(!t)return;const f=l=>{var u,m;t&&((u=i.current)!=null&&u.contains(l.target)||(m=n.current)!=null&&m.contains(l.target)||e())};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[t,e,n]),!t)return null;const s=o.startsWith("top")?"top":"bottom",c=o.endsWith("end")?"end":"start",a=o.startsWith("top")?8:4;return C.jsxs(po,{children:[C.jsx(ho,{virtualRef:n}),C.jsx(Te,{children:C.jsx(Ge,{onEscapeKeyDown:f=>{f.preventDefault(),e()},onPointerDownOutside:f=>{var l;if((l=n.current)!=null&&l.contains(f.target)){f.preventDefault();return}e()},children:C.jsx(go,{ref:i,side:s,align:c,sideOffset:a,className:`popover popover-${o}`,role:"dialog",children:r})})})]})};function Eo(t){const e=t+"CollectionProvider",[n,o]=Nt(e),[r,i]=n(e,{collectionRef:{current:null},itemMap:new Map}),s=g=>{const{scope:h,children:w}=g,b=Z.useRef(null),y=Z.useRef(new Map).current;return C.jsx(r,{scope:h,itemMap:y,collectionRef:b,children:w})};s.displayName=e;const c=t+"CollectionSlot",a=Ut(c),f=Z.forwardRef((g,h)=>{const{scope:w,children:b}=g,y=i(c,w),v=st(h,y.collectionRef);return C.jsx(a,{ref:v,children:b})});f.displayName=c;const l=t+"CollectionItemSlot",u="data-radix-collection-item",m=Ut(l),d=Z.forwardRef((g,h)=>{const{scope:w,children:b,...y}=g,v=Z.useRef(null),A=st(h,v),R=i(l,w);return Z.useEffect(()=>(R.itemMap.set(v,{ref:v,...y}),()=>void R.itemMap.delete(v))),C.jsx(m,{[u]:"",ref:A,children:b})});d.displayName=l;function p(g){const h=i(t+"CollectionConsumer",g);return Z.useCallback(()=>{const b=h.collectionRef.current;if(!b)return[];const y=Array.from(b.querySelectorAll(`[${u}]`));return Array.from(h.itemMap.values()).sort((R,P)=>y.indexOf(R.ref.current)-y.indexOf(P.ref.current))},[h.collectionRef,h.itemMap])}return[{Provider:s,Slot:f,ItemSlot:d},p,o]}var To=x.createContext(void 0);function Do(t){const e=x.useContext(To);return t||e||"ltr"}var Et="rovingFocusGroup.onEntryFocus",Io={bubbles:!1,cancelable:!0},ft="RovingFocusGroup",[Mt,De,Mo]=Eo(ft),[No]=Nt(ft,[Mo]),[Fo,Lo]=No(ft),Ie=x.forwardRef((t,e)=>C.jsx(Mt.Provider,{scope:t.__scopeRovingFocusGroup,children:C.jsx(Mt.Slot,{scope:t.__scopeRovingFocusGroup,children:C.jsx(_o,{...t,ref:e})})}));Ie.displayName=ft;var _o=x.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:o,loop:r=!1,dir:i,currentTabStopId:s,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:a,onEntryFocus:f,preventScrollOnEntryFocus:l=!1,...u}=t,m=x.useRef(null),d=st(e,m),p=Do(i),[g,h]=qe({prop:s,defaultProp:c??null,onChange:a,caller:ft}),[w,b]=x.useState(!1),y=ce(f),v=De(n),A=x.useRef(!1),[R,P]=x.useState(0);return x.useEffect(()=>{const O=m.current;if(O)return O.addEventListener(Et,y),()=>O.removeEventListener(Et,y)},[y]),C.jsx(Fo,{scope:n,orientation:o,dir:p,loop:r,currentTabStopId:g,onItemFocus:x.useCallback(O=>h(O),[h]),onItemShiftTab:x.useCallback(()=>b(!0),[]),onFocusableItemAdd:x.useCallback(()=>P(O=>O+1),[]),onFocusableItemRemove:x.useCallback(()=>P(O=>O-1),[]),children:C.jsx(lt.div,{tabIndex:w||R===0?-1:0,"data-orientation":o,...u,ref:d,style:{outline:"none",...t.style},onMouseDown:tt(t.onMouseDown,()=>{A.current=!0}),onFocus:tt(t.onFocus,O=>{const L=!A.current;if(O.target===O.currentTarget&&L&&!w){const D=new CustomEvent(Et,Io);if(O.currentTarget.dispatchEvent(D),!D.defaultPrevented){const M=v().filter(E=>E.focusable),F=M.find(E=>E.active),I=M.find(E=>E.id===g),$=[F,I,...M].filter(Boolean).map(E=>E.ref.current);Fe($,l)}}A.current=!1}),onBlur:tt(t.onBlur,()=>b(!1))})})}),Me="RovingFocusGroupItem",Ne=x.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:o=!0,active:r=!1,tabStopId:i,children:s,...c}=t,a=Ue(),f=i||a,l=Lo(Me,n),u=l.currentTabStopId===f,m=De(n),{onFocusableItemAdd:d,onFocusableItemRemove:p,currentTabStopId:g}=l;return x.useEffect(()=>{if(o)return d(),()=>p()},[o,d,p]),C.jsx(Mt.ItemSlot,{scope:n,id:f,focusable:o,active:r,children:C.jsx(lt.span,{tabIndex:u?0:-1,"data-orientation":l.orientation,...c,ref:e,onMouseDown:tt(t.onMouseDown,h=>{o?l.onItemFocus(f):h.preventDefault()}),onFocus:tt(t.onFocus,()=>l.onItemFocus(f)),onKeyDown:tt(t.onKeyDown,h=>{if(h.key==="Tab"&&h.shiftKey){l.onItemShiftTab();return}if(h.target!==h.currentTarget)return;const w=ko(h,l.orientation,l.dir);if(w!==void 0){if(h.metaKey||h.ctrlKey||h.altKey||h.shiftKey)return;h.preventDefault();let y=m().filter(v=>v.focusable).map(v=>v.ref.current);if(w==="last")y.reverse();else if(w==="prev"||w==="next"){w==="prev"&&y.reverse();const v=y.indexOf(h.currentTarget);y=l.loop?Wo(y,v+1):y.slice(v+1)}setTimeout(()=>Fe(y))}}),children:typeof s=="function"?s({isCurrentTabStop:u,hasTabStop:g!=null}):s})})});Ne.displayName=Me;var $o={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function jo(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function ko(t,e,n){const o=jo(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(o))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(o)))return $o[o]}function Fe(t,e=!1){const n=document.activeElement;for(const o of t)if(o===n||(o.focus({preventScroll:e}),document.activeElement!==n))return}function Wo(t,e){return t.map((n,o)=>t[(e+o)%t.length])}var Ho=Ie,Bo=Ne;const Xo=({icon:t,children:e,onClick:n,danger:o,disabled:r,checked:i,note:s,trailing:c})=>C.jsx(Bo,{asChild:!0,focusable:!r,active:!1,children:C.jsxs("button",{type:"button",role:i===void 0?"menuitem":"menuitemradio","aria-checked":i,className:`menu-item${o?" menu-item-danger":""}`,onClick:n,disabled:r,children:[i!==void 0&&C.jsx("span",{className:"menu-item-check","aria-hidden":"true",children:i&&C.jsx(Ze,{size:12})}),t&&C.jsx("span",{className:"menu-item-icon",children:t}),C.jsxs("span",{className:"menu-item-label",children:[e,s&&C.jsx("span",{className:"menu-item-note",children:s})]}),c!==void 0&&C.jsx("span",{className:"menu-item-trailing",children:c})]})}),Go=()=>C.jsx("div",{className:"menu-divider",role:"separator"}),Uo=({children:t})=>C.jsx(Ho,{asChild:!0,orientation:"vertical",loop:!0,children:C.jsx("div",{className:"menu",role:"menu",children:t})});export{Uo as M,Ko as P,Xo as a,Go as b};