@xenon-device-management/xenon 1.2.0 → 1.4.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.
- package/README.md +91 -0
- package/lib/package.json +1 -1
- package/lib/public/assets/{Layouts-D0WSzKOh.js → Layouts-BV_fQEKa.js} +1 -1
- package/lib/public/assets/{ai-settings-DQWDdNd7.js → ai-settings-BnoeJplt.js} +2 -2
- package/lib/public/assets/api-keys-TLWTJYrE.js +1 -0
- package/lib/public/assets/{apps-1sLWHOGO.js → apps-BGCcB8_p.js} +2 -2
- package/lib/public/assets/arrow-left-B6-SH02F.js +6 -0
- package/lib/public/assets/{badge-BiR1gmMm.js → badge-BtQKmQsj.js} +1 -1
- package/lib/public/assets/button-CNLKazSa.js +16 -0
- package/lib/public/assets/{calendar-yMyP2_Nc.js → calendar-CPNkf0zl.js} +1 -1
- package/lib/public/assets/{clock-CsVplnJ2.js → clock-C8ZaLIQA.js} +1 -1
- package/lib/public/assets/copy-DCAmOyY9.js +11 -0
- package/lib/public/assets/{cpu-DNC8n7kK.js → cpu-D3PzrmhN.js} +1 -1
- package/lib/public/assets/{device-explorer-DFu8Gxj4.js → device-explorer-BfFe3bRe.js} +36 -41
- package/lib/public/assets/{index-S71J2rWg.js → index-Do3u3FMx.js} +44 -34
- package/lib/public/assets/{lock-BstCxnX6.js → lock-DNzAbx6Q.js} +1 -1
- package/lib/public/assets/{maintenance-settings-BwfG9cu2.js → maintenance-settings-yHAKnfz_.js} +2 -2
- package/lib/public/assets/{mouse-pointer-2-CSn_Wnc9.js → mouse-pointer-2-B0KBsfLG.js} +1 -1
- package/lib/public/assets/{plus-DfjM7G6e.js → plus-DecbehZh.js} +1 -1
- package/lib/public/assets/{session-dashboard-C6ek4z65.js → session-dashboard-CJvDLc6D.js} +17 -22
- package/lib/public/assets/settings-DjTQTjSq.js +1 -0
- package/lib/public/assets/shield-alert-Br1Ebl1G.js +6 -0
- package/lib/public/assets/teams-LILlQka3.js +1 -0
- package/lib/public/assets/{trash-2-CZWUMK5b.js → trash-2-DEafUZlN.js} +1 -1
- package/lib/public/assets/{useSocket-CliVeWS3.js → useSocket-Dzv_TTsO.js} +2 -2
- package/lib/public/assets/{webhook-settings-tPiwWf8y.js → webhook-settings-CVwvtwI7.js} +1 -1
- package/lib/public/assets/{zap-ZrK5B58i.js → zap-DCsIYdwr.js} +1 -1
- package/lib/public/index.html +1 -1
- package/lib/schema.json +85 -38
- package/lib/src/InternalHttpClient.js +69 -14
- package/lib/src/XenonCapabilityManager.js +30 -0
- package/lib/src/app/index.js +95 -24
- package/lib/src/app/routers/apikeys.js +36 -0
- package/lib/src/app/routers/apps.js +4 -0
- package/lib/src/app/routers/auth.js +36 -0
- package/lib/src/app/routers/config.js +4 -0
- package/lib/src/app/routers/control.js +61 -10
- package/lib/src/app/routers/dashboard.js +5 -6
- package/lib/src/app/routers/grid.js +76 -14
- package/lib/src/app/routers/processes.js +24 -0
- package/lib/src/app/routers/reservation.js +15 -0
- package/lib/src/app/routers/teams.js +66 -0
- package/lib/src/app/routers/webhook.js +6 -3
- package/lib/src/auth/nodeSecret.js +33 -0
- package/lib/src/config.js +5 -0
- package/lib/src/dashboard/event-manager.js +2 -0
- package/lib/src/data-service/device-store.js +12 -0
- package/lib/src/data-service/prisma-store.js +24 -1
- package/lib/src/device-managers/AndroidDeviceManager.js +2 -2
- package/lib/src/device-managers/NodeDevices.js +8 -1
- package/lib/src/device-managers/ios/IOSDiscoveryService.js +7 -4
- package/lib/src/device-managers/ios/IOSStreamService.js +7 -0
- package/lib/src/device-managers/ios/WDAClient.js +2 -0
- package/lib/src/device-utils.js +36 -5
- package/lib/src/generated/client/edge.js +18 -7
- package/lib/src/generated/client/index-browser.js +15 -4
- package/lib/src/generated/client/index.d.ts +2613 -391
- package/lib/src/generated/client/index.js +18 -7
- package/lib/src/generated/client/package.json +1 -1
- package/lib/src/generated/client/schema.prisma +21 -0
- package/lib/src/generated/client/wasm.js +15 -4
- package/lib/src/helpers/UniversalMjpegProxy.js +23 -0
- package/lib/src/index.js +10 -2
- package/lib/src/interceptors/CommandInterceptor.js +29 -0
- package/lib/src/interfaces/IPluginArgs.js +0 -1
- package/lib/src/logger.js +47 -2
- package/lib/src/logging/sessionContext.js +28 -0
- package/lib/src/middleware/apiKeyMiddleware.js +69 -0
- package/lib/src/middleware/csrfMiddleware.js +73 -0
- package/lib/src/middleware/nodeSecretMiddleware.js +38 -0
- package/lib/src/middleware/rateLimitMiddleware.js +68 -0
- package/lib/src/middleware/scopeGuard.js +41 -0
- package/lib/src/plugin.js +1 -1
- package/lib/src/services/AIService.js +43 -8
- package/lib/src/services/ApiKeyService.js +121 -0
- package/lib/src/services/CircuitBreaker.js +158 -0
- package/lib/src/services/CleanupService.js +137 -39
- package/lib/src/services/DeviceReconciler.js +102 -0
- package/lib/src/services/MetricsService.js +78 -0
- package/lib/src/services/PortAllocator.js +13 -0
- package/lib/src/services/ProcessMetricsService.js +99 -0
- package/lib/src/services/ProcessRegistry.js +123 -0
- package/lib/src/services/ServerManager.js +23 -4
- package/lib/src/services/SessionLifecycleService.js +133 -27
- package/lib/src/services/ShutdownCoordinator.js +89 -0
- package/lib/src/services/SocketClient.js +11 -0
- package/lib/src/services/SocketServer.js +109 -6
- package/lib/src/services/TeamService.js +100 -0
- package/lib/src/services/VideoPipelineService.js +2 -0
- package/lib/src/services/healing/HealingMetrics.js +63 -0
- package/lib/src/services/healing/HealingOrchestrator.js +32 -4
- package/lib/src/services/healing/OcrHealingProvider.js +7 -0
- package/lib/src/sessions/XenonSession.js +3 -0
- package/lib/test/unit/ApiKeyService.test.js +101 -0
- package/lib/test/unit/PortAllocator.test.js +14 -0
- package/lib/test/unit/ProcessRegistry.test.js +70 -0
- package/lib/test/unit/apiKeyMiddleware.test.js +58 -0
- package/lib/test/unit/nodeSecretMiddleware.test.js +38 -0
- package/lib/test/unit/rateLimitMiddleware.test.js +37 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/prisma/migrations/20260423081701_add_session_indexes/migration.sql +8 -0
- package/prisma/migrations/20260424033547_add_teams/migration.sql +101 -0
- package/prisma/schema.prisma +21 -0
- package/schema.json +85 -38
- package/lib/public/assets/button-BVazt4Z1.js +0 -26
- package/lib/public/assets/settings-BDYP8ULf.js +0 -1
- /package/lib/public/assets/{Layouts-DPMls9vh.css → settings-DPMls9vh.css} +0 -0
|
@@ -1,144 +1,139 @@
|
|
|
1
|
-
import{c as E,r,a as
|
|
1
|
+
import{c as E,r,a as Ds,j as e,X as ss,C as Ls,u as fs,b as ns,R as qe,S as ts,U as Ts,d as is,e as ys,T as zs,f as js,L as He,g as rs}from"./index-Do3u3FMx.js";import{p as ls,H as Is,C as bs,a as Ke,u as Es}from"./useSocket-Dzv_TTsO.js";import{X as A}from"./index-C1DBaoSh.js";import{C as Ns}from"./clock-C8ZaLIQA.js";import{P as ws}from"./plus-DecbehZh.js";import{A as ks,T as as,U as Rs,B as Je}from"./button-CNLKazSa.js";import{C as Ms}from"./cpu-D3PzrmhN.js";import{M as _s}from"./mouse-pointer-2-B0KBsfLG.js";import{S as Xe,D as Us,B as Pe}from"./badge-BtQKmQsj.js";import{C as Ze,a as Qe}from"./copy-DCAmOyY9.js";import{Z as Fs}from"./zap-DCsIYdwr.js";import{S as cs}from"./shield-alert-Br1Ebl1G.js";import{L as Os}from"./lock-DNzAbx6Q.js";import{T as Be}from"./trash-2-DEafUZlN.js";/**
|
|
2
2
|
* @license lucide-react v0.555.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const
|
|
6
|
+
*/const Hs=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],Ps=E("box",Hs);/**
|
|
7
7
|
* @license lucide-react v0.555.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const
|
|
11
|
+
*/const Bs=[["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5",key:"1glfrc"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}]],Cs=E("calendar-plus",Bs);/**
|
|
12
12
|
* @license lucide-react v0.555.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const
|
|
16
|
+
*/const Ws=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],os=E("chevron-left",Ws);/**
|
|
17
17
|
* @license lucide-react v0.555.0 - ISC
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const
|
|
21
|
+
*/const Vs=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],qs=E("chevron-up",Vs);/**
|
|
22
22
|
* @license lucide-react v0.555.0 - ISC
|
|
23
23
|
*
|
|
24
24
|
* This source code is licensed under the ISC license.
|
|
25
25
|
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const
|
|
26
|
+
*/const Xs=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}]],Gs=E("clipboard",Xs);/**
|
|
27
27
|
* @license lucide-react v0.555.0 - ISC
|
|
28
28
|
*
|
|
29
29
|
* This source code is licensed under the ISC license.
|
|
30
30
|
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const
|
|
31
|
+
*/const Ys=[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],ds=E("code-xml",Ys);/**
|
|
32
32
|
* @license lucide-react v0.555.0 - ISC
|
|
33
33
|
*
|
|
34
34
|
* This source code is licensed under the ISC license.
|
|
35
35
|
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const
|
|
36
|
+
*/const Ks=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],Js=E("file-text",Ks);/**
|
|
37
37
|
* @license lucide-react v0.555.0 - ISC
|
|
38
38
|
*
|
|
39
39
|
* This source code is licensed under the ISC license.
|
|
40
40
|
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const
|
|
41
|
+
*/const Zs=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],Qs=E("grid-3x3",Zs);/**
|
|
42
42
|
* @license lucide-react v0.555.0 - ISC
|
|
43
43
|
*
|
|
44
44
|
* This source code is licensed under the ISC license.
|
|
45
45
|
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/const
|
|
46
|
+
*/const et=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],st=E("house",et);/**
|
|
47
47
|
* @license lucide-react v0.555.0 - ISC
|
|
48
48
|
*
|
|
49
49
|
* This source code is licensed under the ISC license.
|
|
50
50
|
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const
|
|
51
|
+
*/const tt=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],it=E("layers",tt);/**
|
|
52
52
|
* @license lucide-react v0.555.0 - ISC
|
|
53
53
|
*
|
|
54
54
|
* This source code is licensed under the ISC license.
|
|
55
55
|
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
-
*/const
|
|
56
|
+
*/const at=[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]],nt=E("lightbulb",at);/**
|
|
57
57
|
* @license lucide-react v0.555.0 - ISC
|
|
58
58
|
*
|
|
59
59
|
* This source code is licensed under the ISC license.
|
|
60
60
|
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
-
*/const
|
|
61
|
+
*/const rt=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],Ss=E("lock-open",rt);/**
|
|
62
62
|
* @license lucide-react v0.555.0 - ISC
|
|
63
63
|
*
|
|
64
64
|
* This source code is licensed under the ISC license.
|
|
65
65
|
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/const
|
|
66
|
+
*/const lt=[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]],ct=E("map-pin",lt);/**
|
|
67
67
|
* @license lucide-react v0.555.0 - ISC
|
|
68
68
|
*
|
|
69
69
|
* This source code is licensed under the ISC license.
|
|
70
70
|
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
-
*/const
|
|
71
|
+
*/const ot=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],dt=E("message-square",ot);/**
|
|
72
72
|
* @license lucide-react v0.555.0 - ISC
|
|
73
73
|
*
|
|
74
74
|
* This source code is licensed under the ISC license.
|
|
75
75
|
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
-
*/const
|
|
76
|
+
*/const ht=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],hs=E("monitor",ht);/**
|
|
77
77
|
* @license lucide-react v0.555.0 - ISC
|
|
78
78
|
*
|
|
79
79
|
* This source code is licensed under the ISC license.
|
|
80
80
|
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
-
*/const
|
|
81
|
+
*/const mt=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],ut=E("move",mt);/**
|
|
82
82
|
* @license lucide-react v0.555.0 - ISC
|
|
83
83
|
*
|
|
84
84
|
* This source code is licensed under the ISC license.
|
|
85
85
|
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
-
*/const
|
|
86
|
+
*/const pt=[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]],vt=E("package",pt);/**
|
|
87
87
|
* @license lucide-react v0.555.0 - ISC
|
|
88
88
|
*
|
|
89
89
|
* This source code is licensed under the ISC license.
|
|
90
90
|
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
-
*/const
|
|
91
|
+
*/const xt=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]],gt=E("panels-top-left",xt);/**
|
|
92
92
|
* @license lucide-react v0.555.0 - ISC
|
|
93
93
|
*
|
|
94
94
|
* This source code is licensed under the ISC license.
|
|
95
95
|
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
-
*/const
|
|
96
|
+
*/const ft=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Ve=E("rotate-cw",ft);/**
|
|
97
97
|
* @license lucide-react v0.555.0 - ISC
|
|
98
98
|
*
|
|
99
99
|
* This source code is licensed under the ISC license.
|
|
100
100
|
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
-
*/const
|
|
101
|
+
*/const yt=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],ms=E("sparkles",yt);/**
|
|
102
102
|
* @license lucide-react v0.555.0 - ISC
|
|
103
103
|
*
|
|
104
104
|
* This source code is licensed under the ISC license.
|
|
105
105
|
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
-
*/const
|
|
106
|
+
*/const jt=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],bt=E("tag",jt);/**
|
|
107
107
|
* @license lucide-react v0.555.0 - ISC
|
|
108
108
|
*
|
|
109
109
|
* This source code is licensed under the ISC license.
|
|
110
110
|
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
-
*/const
|
|
111
|
+
*/const Nt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],us=E("target",Nt);/**
|
|
112
112
|
* @license lucide-react v0.555.0 - ISC
|
|
113
113
|
*
|
|
114
114
|
* This source code is licensed under the ISC license.
|
|
115
115
|
* See the LICENSE file in the root directory of this source tree.
|
|
116
|
-
*/const
|
|
116
|
+
*/const wt=[["path",{d:"M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z",key:"17jzev"}]],kt=E("thermometer",wt);/**
|
|
117
117
|
* @license lucide-react v0.555.0 - ISC
|
|
118
118
|
*
|
|
119
119
|
* This source code is licensed under the ISC license.
|
|
120
120
|
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
-
*/const
|
|
121
|
+
*/const Ct=[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"M2 14h20",key:"myj16y"}],["path",{d:"M12 20v-6",key:"1rm09r"}]],St=E("touchpad",Ct);/**
|
|
122
122
|
* @license lucide-react v0.555.0 - ISC
|
|
123
123
|
*
|
|
124
124
|
* This source code is licensed under the ISC license.
|
|
125
125
|
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
-
*/const
|
|
126
|
+
*/const $t=[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]],At=E("user",$t);/**
|
|
127
127
|
* @license lucide-react v0.555.0 - ISC
|
|
128
128
|
*
|
|
129
129
|
* This source code is licensed under the ISC license.
|
|
130
130
|
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
-
*/const
|
|
131
|
+
*/const Dt=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],$s=E("wifi",Dt);/**
|
|
132
132
|
* @license lucide-react v0.555.0 - ISC
|
|
133
133
|
*
|
|
134
134
|
* This source code is licensed under the ISC license.
|
|
135
135
|
* See the LICENSE file in the root directory of this source tree.
|
|
136
|
-
*/const As=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],$t=E("wifi",As);/**
|
|
137
|
-
* @license lucide-react v0.555.0 - ISC
|
|
138
|
-
*
|
|
139
|
-
* This source code is licensed under the ISC license.
|
|
140
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
141
|
-
*/const Ls=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],Ts=E("wrench",Ls),zs=[{label:"1 Hour",value:"1h"},{label:"2 Hours",value:"2h"},{label:"4 Hours",value:"4h"},{label:"8 Hours",value:"8h"}],Es=({device:n,onClose:t,onReserved:l})=>{const[u,p]=r.useState(""),[s,L]=r.useState("1h"),[v,x]=r.useState(""),[h,m]=r.useState(!1),[A,S]=r.useState(null),U=async()=>{if(!u.trim()){S("Please enter your name/ID");return}m(!0),S(null);try{const w=await D.reserveDevice(n.udid,n.host,u,s,v);w.success?(l(),t()):S(w.error||"Failed to reserve device")}catch(w){S(w.message||"An unexpected error occurred")}finally{m(!1)}};return At.createPortal(e.jsx("div",{className:"reservation-modal-overlay",onClick:t,children:e.jsxs("div",{className:"reservation-modal",onClick:w=>w.stopPropagation(),children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.05,zIndex:1001}}),e.jsxs("div",{className:"reservation-modal-header",children:[e.jsxs("div",{className:"reservation-modal-title",children:[e.jsx(Ct,{size:18,className:"title-icon"}),"Reserve Device"]}),e.jsx("button",{className:"close-btn",onClick:t,children:e.jsx(tt,{size:20})})]}),e.jsxs("div",{className:"reservation-modal-body",children:[e.jsxs("div",{className:"device-id-badge",children:[e.jsx("span",{className:"label",children:"Device:"}),e.jsx("span",{className:"value",children:n.udid})]}),e.jsxs("p",{children:["Reserve ",e.jsx("strong",{children:n.name||n.udid})," for exclusive use. This will prevent CI sessions from using this device."]}),e.jsxs("div",{className:"reservation-form-group",children:[e.jsxs("label",{children:[e.jsx(Ds,{size:14,style:{marginRight:6,verticalAlign:"middle",color:"var(--color-primary)"}}),"Reserved By"]}),e.jsx("input",{type:"text",className:"reservation-input",placeholder:"Enter your name or ID",value:u,onChange:w=>p(w.target.value),disabled:h})]}),e.jsxs("div",{className:"reservation-form-group",children:[e.jsxs("label",{children:[e.jsx(Nt,{size:14,style:{marginRight:6,verticalAlign:"middle",color:"var(--color-primary)"}}),"Duration"]}),e.jsx("div",{className:"duration-selector",children:zs.map(w=>e.jsx("div",{className:`duration-option ${s===w.value?"active":""}`,onClick:()=>L(w.value),children:w.label},w.value))})]}),e.jsxs("div",{className:"reservation-form-group",children:[e.jsxs("label",{children:[e.jsx(os,{size:14,style:{marginRight:6,verticalAlign:"middle",color:"var(--color-primary)"}}),"Reason (Optional)"]}),e.jsx("input",{type:"text",className:"reservation-input",placeholder:"e.g., Debugging flaky login test",value:v,onChange:w=>x(w.target.value),disabled:h})]}),A&&e.jsxs("div",{className:"error-message",children:[e.jsx(Lt,{size:14,style:{marginRight:6,verticalAlign:"middle"}}),A]})]}),e.jsxs("div",{className:"reservation-actions",children:[e.jsx("button",{className:"btn-cancel",onClick:t,disabled:h,children:"Cancel"}),e.jsx("button",{className:"btn-reserve",onClick:U,disabled:h||!u.trim(),children:h?"Reserving...":"Confirm Reservation"})]})]})}),document.body)},Is=({device:n,onClose:t,onUpdated:l})=>{const{toast:u}=ft(),[p,s]=r.useState(n.tags||[]),[L,v]=r.useState(""),[x,h]=r.useState(!1),m=r.useRef(null);r.useEffect(()=>{m.current&&m.current.focus()},[]);const A=()=>{const j=L.trim();j&&!p.includes(j)&&(s([...p,j]),v(""))},S=j=>{s(p.filter(T=>T!==j))},U=j=>{j.key==="Enter"?A():j.key==="Escape"&&t()},w=async()=>{h(!0);try{await D.updateDeviceTags(n.udid,n.host,p),l(),t()}catch(j){console.error("Failed to update tags",j),u("Error saving tags. Please try again.","error")}finally{h(!1)}};return e.jsx("div",{className:"tag-modal-overlay",onClick:t,children:e.jsxs("div",{className:"tag-modal-container",onClick:j=>j.stopPropagation(),children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.05,zIndex:1001}}),e.jsxs("div",{className:"tag-modal-header",children:[e.jsxs("div",{className:"tag-modal-title",children:[e.jsx(bs,{size:18,className:"title-icon"}),"Manage Device Tags"]}),e.jsx("button",{className:"close-btn",onClick:t,children:e.jsx(tt,{size:20})})]}),e.jsxs("div",{className:"tag-modal-body",children:[e.jsxs("div",{className:"device-id-badge",children:[e.jsx("span",{className:"label",children:"Device:"}),e.jsx("span",{className:"value",children:n.udid})]}),e.jsxs("div",{className:"tag-input-section",children:[e.jsx("label",{htmlFor:"tag-input",children:"Add New Tag"}),e.jsxs("div",{className:"input-with-button",children:[e.jsx("input",{ref:m,id:"tag-input",type:"text",placeholder:"e.g. stable, team-a, ios-17",value:L,onChange:j=>v(j.target.value),onKeyDown:U}),e.jsx("button",{className:"add-inline-btn",onClick:A,disabled:!L.trim(),children:e.jsx(wt,{size:16})})]}),e.jsx("p",{className:"input-hint",children:"Press Enter to add multiple tags"})]}),e.jsxs("div",{className:"tags-display-section",children:[e.jsx("label",{children:"Current Tags"}),e.jsx("div",{className:"tags-list",children:p.length>0?p.map(j=>e.jsxs("div",{className:"tag-pill-editable",children:[j,e.jsx("button",{className:"remove-tag",onClick:()=>S(j),children:e.jsx(tt,{size:12})})]},j)):e.jsx("div",{className:"empty-tags",children:"No tags assigned to this device."})})]})]}),e.jsxs("div",{className:"tag-modal-footer",children:[e.jsx("button",{className:"btn-cancel",onClick:t,children:"Cancel"}),e.jsx("button",{className:"btn-save",onClick:w,disabled:x,children:x?"Saving...":"Apply Changes"})]})]})})};class Rs extends qe.Component{constructor(t){super(t),this.state={showReservation:!1,showTagManager:!1,showControl:!1}}getStatusClassName(){return this.props.device.offline?"disabled":this.props.device.busy?"busy":this.isReserved()?"reserved":""}getDeviceState(){return this.props.device.offline?"offline":this.props.device.userBlocked?"maintenance":this.props.device.busy?"busy":this.isReserved()?"reserved":"ready"}isReserved(){const{reservedUntil:t}=this.props.device;return t?Date.now()<t:!1}getRemainingReservationTime(){const{reservedUntil:t}=this.props.device;if(!t)return"";const l=t-Date.now();return l<=0?"":lt(l,{compact:!0})}async releaseReservation(t,l){await D.releaseReservation(t,l),this.props.reloadDevices()}async blockDevice(t,l){await D.blockDevice(t,l),this.props.reloadDevices()}async unblockDevice(t,l){await D.unblockDevice(t,l),this.props.reloadDevices()}async manageTags(){this.setState({showTagManager:!0})}render(){var H;const{name:t,sdk:l,deviceType:u,platform:p,udid:s,dashboard_link:L,total_session_count:v,host:x,totalUtilizationTimeMilliSec:h,userBlocked:m,busy:A,session_id:S,reservedBy:U,reservedUntil:w,reservationReason:j,batteryLevel:T,thermalStatus:F,storageFree:b,tags:k,sessionProgress:y,totalHealedCount:R}=this.props.device,M=this.getDeviceState();let _="";try{_=new URL(x).hostname}catch{_=x.split(":")[1].replace("//","")}const q=()=>A?null:this.isReserved()?e.jsx("button",{className:"tactical-btn reserved",onClick:()=>this.releaseReservation(s,x),title:`Reserved by ${U}${j?`: ${j}`:""}. Expires: ${w?new Date(w).toLocaleString():"Never"}`,children:e.jsx(St,{size:14,color:"#38bdf8"})}):m?e.jsx("button",{className:"tactical-btn exit-maintenance",onClick:()=>this.unblockDevice(s,x),title:"Exit Maintenance",children:e.jsx(it,{size:14})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"tactical-btn reserve",onClick:()=>this.setState({showReservation:!0}),title:"Reserve Device",children:e.jsx(Ct,{size:14,color:"#38bdf8"})}),e.jsx("button",{className:"tactical-btn maintenance",onClick:()=>this.blockDevice(s,x),title:"Enter Maintenance",children:e.jsx(Ts,{size:14,color:"#fbbf24"})})]});return e.jsxs("div",{className:`device-info-card-container ${this.getStatusClassName()} group`,children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.1,zIndex:0}}),e.jsxs("div",{className:"card-header relative z-10",children:[e.jsxs("div",{className:"header-left",children:[e.jsx("div",{className:`platform-icon-wrapper ${p}`,children:["ios","tvos"].includes(p)?e.jsx(kt,{size:14}):e.jsx(st,{size:14})}),e.jsx("div",{className:"device-id-mono",title:s,children:s})]}),e.jsx("div",{className:`device-status-badge ${M} ${M==="busy"&&y&&y!=="Session Active"?"pulse":""}`,children:M==="busy"&&y&&y!=="Session Active"?y:M})]}),e.jsxs("div",{className:"device-info-main relative z-10",children:[e.jsx("h3",{className:"device-name",title:t,children:t}),e.jsxs("p",{className:"device-subtext",children:[u.toUpperCase()," • ",l]}),this.props.device.tags&&this.props.device.tags.length>0&&e.jsxs("div",{className:"device-tags-inline",children:[this.props.device.tags.slice(0,3).map(te=>e.jsx("span",{className:"inline-tag",title:te,children:te},te)),this.props.device.tags.length>3&&e.jsxs("span",{className:"inline-tag-overflow",children:["+",this.props.device.tags.length-3]})]})]}),e.jsxs("div",{className:"metrics-grid relative z-10",children:[e.jsxs("div",{className:"metric-item",title:`Host: ${_}${this.props.device.ip?` • IP: ${this.props.device.ip}`:""}`,children:[this.props.device.ip?e.jsx($t,{size:10,className:"text-dim"}):e.jsx(dt,{size:10,className:"text-dim"}),e.jsx("span",{className:"truncate",children:this.props.device.ip||_})]}),e.jsxs("div",{className:"metric-item",title:`Architecture: ${this.props.device.cpuArchitecture||"Unknown"}`,children:[e.jsx(Rt,{size:10,className:"text-dim"}),e.jsx("span",{className:"truncate uppercase",children:this.props.device.cpuArchitecture||"arch"})]}),e.jsxs("div",{className:`metric-item health ${((H=this.props.device.healthStatus)==null?void 0:H.toLowerCase())||"healthy"}`,title:this.props.device.healthCheckError||"Device is healthy",children:[e.jsx("div",{className:"health-dot"}),e.jsx("span",{children:this.props.device.healthStatus||"Healthy"}),R&&R>0&&e.jsxs("span",{className:"heal-badge",children:[e.jsx(it,{size:8})," ",R]})]}),F&&F!=="Unknown"&&e.jsxs("div",{className:"metric-item thermal",title:`Thermal: ${F}`,children:[e.jsx(ks,{size:10,style:{color:F==="Nominal"?"var(--color-primary)":"var(--color-amber)"}}),e.jsx("span",{children:F})]}),T!==void 0&&e.jsxs("div",{className:"metric-item battery",title:`Battery: ${T}%`,children:[e.jsx("div",{className:`mini-battery ${T<20?"low":""}`,children:e.jsx("div",{className:"battery-fill",style:{width:`${T}%`}})}),e.jsxs("span",{children:[T,"%"]})]}),b&&b!=="Unknown"&&e.jsxs("div",{className:"metric-item storage",title:`Free Space: ${b}`,children:[e.jsx(zt,{size:10,style:{color:"var(--color-sky)"}}),e.jsx("span",{children:b})]})]}),e.jsx("div",{className:"dynamic-data-layer relative z-10",children:this.isReserved()?e.jsxs("div",{className:"reservation-micro-banner",children:[e.jsx(Nt,{size:10}),e.jsxs("span",{children:["RES: ",U||"Anon"," (",this.getRemainingReservationTime(),")"]})]}):S?e.jsxs("div",{className:"session-micro-banner",children:[e.jsx(at,{size:10}),e.jsxs("span",{children:["SID: ",S]})]}):e.jsx("div",{className:"utilization-micro-info",children:e.jsxs("span",{children:["UTIL: ",lt(h||0,{compact:!0})]})})}),e.jsxs("div",{className:"action-row relative z-10",children:[e.jsx("button",{className:"tactical-btn add-tag",onClick:()=>this.manageTags(),title:"Manage Tags",children:e.jsx(wt,{size:14})}),q(),e.jsxs("button",{className:`tactical-btn control-btn ${A&&S&&!S.toString().startsWith("manual_")?"disabled":""}`,onClick:()=>!(A&&S&&!S.toString().startsWith("manual_"))&&this.props.navigate(`/devices/${s}/control`),disabled:A&&!!S&&!S.toString().startsWith("manual_"),title:A&&S&&!S.toString().startsWith("manual_")?"Locked: Appium Session":"Take Control",children:[e.jsx(dt,{size:14}),e.jsx("span",{style:{fontSize:"10px",fontWeight:800,letterSpacing:"0.05em",fontFamily:"Outfit, sans-serif"},children:"CTRL"})]})]}),this.state.showReservation&&e.jsx(Es,{device:this.props.device,onClose:()=>this.setState({showReservation:!1}),onReserved:()=>this.props.reloadDevices()}),this.state.showTagManager&&e.jsx(Is,{device:this.props.device,onClose:()=>this.setState({showTagManager:!1}),onUpdated:()=>this.props.reloadDevices()})]})}}function Ms(n){const t=nt();return e.jsx(Rs,{...n,navigate:t})}class _s extends qe.Component{render(){return e.jsx("div",{className:"device-explorer-card-container",children:qe.Children.toArray(this.props.devices.map(t=>e.jsx(Ms,{device:t,reloadDevices:this.props.reloadDevices})))})}}var We,Us=new Uint8Array(16);function Fs(){if(!We&&(We=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!We))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return We(Us)}const Os=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Hs(n){return typeof n=="string"&&Os.test(n)}var X=[];for(var et=0;et<256;++et)X.push((et+256).toString(16).substr(1));function Ps(n){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,l=(X[n[t+0]]+X[n[t+1]]+X[n[t+2]]+X[n[t+3]]+"-"+X[n[t+4]]+X[n[t+5]]+"-"+X[n[t+6]]+X[n[t+7]]+"-"+X[n[t+8]]+X[n[t+9]]+"-"+X[n[t+10]]+X[n[t+11]]+X[n[t+12]]+X[n[t+13]]+X[n[t+14]]+X[n[t+15]]).toLowerCase();if(!Hs(l))throw TypeError("Stringified UUID is invalid");return l}function Bs(n,t,l){n=n||{};var u=n.random||(n.rng||Fs)();return u[6]=u[6]&15|64,u[8]=u[8]&63|128,Ps(u)}const Ws=({onCommand:n,prompt:t="$",welcomeMessage:l="Interactive Shell (Restricted Mode)",platform:u})=>{const[p,s]=r.useState([{type:"system",content:l,timestamp:Date.now()},{type:"system",content:'Type "help" for allowed commands.',timestamp:Date.now()}]),[L,v]=r.useState(""),[x,h]=r.useState([]),[m,A]=r.useState(-1),[S,U]=r.useState(!1),w=r.useRef(null),j=r.useRef(null);r.useEffect(()=>{w.current&&(w.current.scrollTop=w.current.scrollHeight)},[p]);const T=b=>{const k=b.trim();if((k.startsWith("{")||k.startsWith("["))&&(k.endsWith("}")||k.endsWith("]")))try{const y=JSON.parse(k);return JSON.stringify(y,null,2)}catch{}return b},F=async b=>{if(b.key==="Enter"&&!S){const k=L.trim();if(!k)return;if(v(""),s(y=>[...y,{type:"command",content:`${t} ${k}`,timestamp:Date.now()}]),h(y=>[...y,k]),A(-1),U(!0),k==="clear"){s([]),U(!1);return}if(k==="help"){let y="";u==="android"?y=`
|
|
136
|
+
*/const Lt=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],Tt=E("wrench",Lt),zt=[{label:"1 Hour",value:"1h"},{label:"2 Hours",value:"2h"},{label:"4 Hours",value:"4h"},{label:"8 Hours",value:"8h"}],It=({device:n,onClose:s,onReserved:l})=>{const[u,p]=r.useState(""),[t,L]=r.useState("1h"),[v,x]=r.useState(""),[h,m]=r.useState(!1),[D,S]=r.useState(null),U=async()=>{if(!u.trim()){S("Please enter your name/ID");return}m(!0),S(null);try{const w=await A.reserveDevice(n.udid,n.host,u,t,v);w.success?(l(),s()):S(w.error||"Failed to reserve device")}catch(w){S(w.message||"An unexpected error occurred")}finally{m(!1)}};return Ds.createPortal(e.jsx("div",{className:"reservation-modal-overlay",onClick:s,children:e.jsxs("div",{className:"reservation-modal",onClick:w=>w.stopPropagation(),children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.05,zIndex:1001}}),e.jsxs("div",{className:"reservation-modal-header",children:[e.jsxs("div",{className:"reservation-modal-title",children:[e.jsx(Cs,{size:18,className:"title-icon"}),"Reserve Device"]}),e.jsx("button",{className:"close-btn",onClick:s,children:e.jsx(ss,{size:20})})]}),e.jsxs("div",{className:"reservation-modal-body",children:[e.jsxs("div",{className:"device-id-badge",children:[e.jsx("span",{className:"label",children:"Device:"}),e.jsx("span",{className:"value",children:n.udid})]}),e.jsxs("p",{children:["Reserve ",e.jsx("strong",{children:n.name||n.udid})," for exclusive use. This will prevent CI sessions from using this device."]}),e.jsxs("div",{className:"reservation-form-group",children:[e.jsxs("label",{children:[e.jsx(At,{size:14,style:{marginRight:6,verticalAlign:"middle",color:"var(--color-primary)"}}),"Reserved By"]}),e.jsx("input",{type:"text",className:"reservation-input",placeholder:"Enter your name or ID",value:u,onChange:w=>p(w.target.value),disabled:h})]}),e.jsxs("div",{className:"reservation-form-group",children:[e.jsxs("label",{children:[e.jsx(Ns,{size:14,style:{marginRight:6,verticalAlign:"middle",color:"var(--color-primary)"}}),"Duration"]}),e.jsx("div",{className:"duration-selector",children:zt.map(w=>e.jsx("div",{className:`duration-option ${t===w.value?"active":""}`,onClick:()=>L(w.value),children:w.label},w.value))})]}),e.jsxs("div",{className:"reservation-form-group",children:[e.jsxs("label",{children:[e.jsx(dt,{size:14,style:{marginRight:6,verticalAlign:"middle",color:"var(--color-primary)"}}),"Reason (Optional)"]}),e.jsx("input",{type:"text",className:"reservation-input",placeholder:"e.g., Debugging flaky login test",value:v,onChange:w=>x(w.target.value),disabled:h})]}),D&&e.jsxs("div",{className:"error-message",children:[e.jsx(Ls,{size:14,style:{marginRight:6,verticalAlign:"middle"}}),D]})]}),e.jsxs("div",{className:"reservation-actions",children:[e.jsx("button",{className:"btn-cancel",onClick:s,disabled:h,children:"Cancel"}),e.jsx("button",{className:"btn-reserve",onClick:U,disabled:h||!u.trim(),children:h?"Reserving...":"Confirm Reservation"})]})]})}),document.body)},Et=({device:n,onClose:s,onUpdated:l})=>{const{toast:u}=fs(),[p,t]=r.useState(n.tags||[]),[L,v]=r.useState(""),[x,h]=r.useState(!1),m=r.useRef(null);r.useEffect(()=>{m.current&&m.current.focus()},[]);const D=()=>{const j=L.trim();j&&!p.includes(j)&&(t([...p,j]),v(""))},S=j=>{t(p.filter(T=>T!==j))},U=j=>{j.key==="Enter"?D():j.key==="Escape"&&s()},w=async()=>{h(!0);try{await A.updateDeviceTags(n.udid,n.host,p),l(),s()}catch(j){console.error("Failed to update tags",j),u("Error saving tags. Please try again.","error")}finally{h(!1)}};return e.jsx("div",{className:"tag-modal-overlay",onClick:s,children:e.jsxs("div",{className:"tag-modal-container",onClick:j=>j.stopPropagation(),children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.05,zIndex:1001}}),e.jsxs("div",{className:"tag-modal-header",children:[e.jsxs("div",{className:"tag-modal-title",children:[e.jsx(bt,{size:18,className:"title-icon"}),"Manage Device Tags"]}),e.jsx("button",{className:"close-btn",onClick:s,children:e.jsx(ss,{size:20})})]}),e.jsxs("div",{className:"tag-modal-body",children:[e.jsxs("div",{className:"device-id-badge",children:[e.jsx("span",{className:"label",children:"Device:"}),e.jsx("span",{className:"value",children:n.udid})]}),e.jsxs("div",{className:"tag-input-section",children:[e.jsx("label",{htmlFor:"tag-input",children:"Add New Tag"}),e.jsxs("div",{className:"input-with-button",children:[e.jsx("input",{ref:m,id:"tag-input",type:"text",placeholder:"e.g. stable, team-a, ios-17",value:L,onChange:j=>v(j.target.value),onKeyDown:U}),e.jsx("button",{className:"add-inline-btn",onClick:D,disabled:!L.trim(),children:e.jsx(ws,{size:16})})]}),e.jsx("p",{className:"input-hint",children:"Press Enter to add multiple tags"})]}),e.jsxs("div",{className:"tags-display-section",children:[e.jsx("label",{children:"Current Tags"}),e.jsx("div",{className:"tags-list",children:p.length>0?p.map(j=>e.jsxs("div",{className:"tag-pill-editable",children:[j,e.jsx("button",{className:"remove-tag",onClick:()=>S(j),children:e.jsx(ss,{size:12})})]},j)):e.jsx("div",{className:"empty-tags",children:"No tags assigned to this device."})})]})]}),e.jsxs("div",{className:"tag-modal-footer",children:[e.jsx("button",{className:"btn-cancel",onClick:s,children:"Cancel"}),e.jsx("button",{className:"btn-save",onClick:w,disabled:x,children:x?"Saving...":"Apply Changes"})]})]})})};class Rt extends qe.Component{constructor(s){super(s),this.state={showReservation:!1,showTagManager:!1,showControl:!1}}getStatusClassName(){return this.props.device.offline?"disabled":this.props.device.busy?"busy":this.isReserved()?"reserved":""}getDeviceState(){return this.props.device.offline?"offline":this.props.device.userBlocked?"maintenance":this.props.device.busy?"busy":this.isReserved()?"reserved":"ready"}isReserved(){const{reservedUntil:s}=this.props.device;return s?Date.now()<s:!1}getRemainingReservationTime(){const{reservedUntil:s}=this.props.device;if(!s)return"";const l=s-Date.now();return l<=0?"":ls(l,{compact:!0})}async releaseReservation(s,l){await A.releaseReservation(s,l),this.props.reloadDevices()}async blockDevice(s,l){await A.blockDevice(s,l),this.props.reloadDevices()}async unblockDevice(s,l){await A.unblockDevice(s,l),this.props.reloadDevices()}async manageTags(){this.setState({showTagManager:!0})}render(){var H;const{name:s,sdk:l,deviceType:u,platform:p,udid:t,dashboard_link:L,total_session_count:v,host:x,totalUtilizationTimeMilliSec:h,userBlocked:m,busy:D,session_id:S,reservedBy:U,reservedUntil:w,reservationReason:j,batteryLevel:T,thermalStatus:F,storageFree:b,tags:k,sessionProgress:y,totalHealedCount:R}=this.props.device,M=this.getDeviceState();let _="";try{_=new URL(x).hostname}catch{_=x.split(":")[1].replace("//","")}const q=()=>D?null:this.isReserved()?e.jsx("button",{className:"tactical-btn reserved",onClick:()=>this.releaseReservation(t,x),title:`Reserved by ${U}${j?`: ${j}`:""}. Expires: ${w?new Date(w).toLocaleString():"Never"}`,children:e.jsx(Ss,{size:14,color:"#38bdf8"})}):m?e.jsx("button",{className:"tactical-btn exit-maintenance",onClick:()=>this.unblockDevice(t,x),title:"Exit Maintenance",children:e.jsx(is,{size:14})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"tactical-btn reserve",onClick:()=>this.setState({showReservation:!0}),title:"Reserve Device",children:e.jsx(Cs,{size:14,color:"#38bdf8"})}),e.jsx("button",{className:"tactical-btn maintenance",onClick:()=>this.blockDevice(t,x),title:"Enter Maintenance",children:e.jsx(Tt,{size:14,color:"#fbbf24"})})]});return e.jsxs("div",{className:`device-info-card-container ${this.getStatusClassName()} group`,children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.1,zIndex:0}}),e.jsxs("div",{className:"card-header relative z-10",children:[e.jsxs("div",{className:"header-left",children:[e.jsx("div",{className:`platform-icon-wrapper ${p}`,children:["ios","tvos"].includes(p)?e.jsx(ks,{size:14}):e.jsx(ts,{size:14})}),e.jsx("div",{className:"device-id-mono",title:t,children:t})]}),e.jsx("div",{className:`device-status-badge ${M} ${M==="busy"&&y&&y!=="Session Active"?"pulse":""}`,children:M==="busy"&&y&&y!=="Session Active"?y:M})]}),e.jsxs("div",{className:"device-info-main relative z-10",children:[e.jsx("h3",{className:"device-name",title:s,children:s}),e.jsxs("p",{className:"device-subtext",children:[u.toUpperCase()," • ",l]}),(this.props.device.teamId||this.props.device.tags&&this.props.device.tags.length>0)&&e.jsxs("div",{className:"device-tags-inline",children:[this.props.device.teamId&&e.jsxs("span",{className:"inline-tag",title:`Assigned to team ${this.props.device.teamId}`,style:{background:"rgba(16,185,129,0.15)",color:"#34d399"},children:[e.jsx(Ts,{size:10,style:{marginRight:4,verticalAlign:"-2px"}}),"team"]}),this.props.device.tags&&this.props.device.tags.slice(0,3).map(se=>e.jsx("span",{className:"inline-tag",title:se,children:se},se)),this.props.device.tags&&this.props.device.tags.length>3&&e.jsxs("span",{className:"inline-tag-overflow",children:["+",this.props.device.tags.length-3]})]})]}),e.jsxs("div",{className:"metrics-grid relative z-10",children:[e.jsxs("div",{className:"metric-item",title:`Host: ${_}${this.props.device.ip?` • IP: ${this.props.device.ip}`:""}`,children:[this.props.device.ip?e.jsx($s,{size:10,className:"text-dim"}):e.jsx(hs,{size:10,className:"text-dim"}),e.jsx("span",{className:"truncate",children:this.props.device.ip||_})]}),e.jsxs("div",{className:"metric-item",title:`Architecture: ${this.props.device.cpuArchitecture||"Unknown"}`,children:[e.jsx(Ms,{size:10,className:"text-dim"}),e.jsx("span",{className:"truncate uppercase",children:this.props.device.cpuArchitecture||"arch"})]}),e.jsxs("div",{className:`metric-item health ${((H=this.props.device.healthStatus)==null?void 0:H.toLowerCase())||"healthy"}`,title:this.props.device.healthCheckError||"Device is healthy",children:[e.jsx("div",{className:"health-dot"}),e.jsx("span",{children:this.props.device.healthStatus||"Healthy"}),R&&R>0&&e.jsxs("span",{className:"heal-badge",children:[e.jsx(is,{size:8})," ",R]})]}),F&&F!=="Unknown"&&e.jsxs("div",{className:"metric-item thermal",title:`Thermal: ${F}`,children:[e.jsx(kt,{size:10,style:{color:F==="Nominal"?"var(--color-primary)":"var(--color-amber)"}}),e.jsx("span",{children:F})]}),T!==void 0&&e.jsxs("div",{className:"metric-item battery",title:`Battery: ${T}%`,children:[e.jsx("div",{className:`mini-battery ${T<20?"low":""}`,children:e.jsx("div",{className:"battery-fill",style:{width:`${T}%`}})}),e.jsxs("span",{children:[T,"%"]})]}),b&&b!=="Unknown"&&e.jsxs("div",{className:"metric-item storage",title:`Free Space: ${b}`,children:[e.jsx(Is,{size:10,style:{color:"var(--color-sky)"}}),e.jsx("span",{children:b})]})]}),e.jsx("div",{className:"dynamic-data-layer relative z-10",children:this.isReserved()?e.jsxs("div",{className:"reservation-micro-banner",children:[e.jsx(Ns,{size:10}),e.jsxs("span",{children:["RES: ",U||"Anon"," (",this.getRemainingReservationTime(),")"]})]}):S?e.jsxs("div",{className:"session-micro-banner",children:[e.jsx(as,{size:10}),e.jsxs("span",{children:["SID: ",S]})]}):e.jsx("div",{className:"utilization-micro-info",children:e.jsxs("span",{children:["UTIL: ",ls(h||0,{compact:!0})]})})}),e.jsxs("div",{className:"action-row relative z-10",children:[e.jsx("button",{className:"tactical-btn add-tag",onClick:()=>this.manageTags(),title:"Manage Tags",children:e.jsx(ws,{size:14})}),q(),e.jsxs("button",{className:`tactical-btn control-btn ${D&&S&&!S.toString().startsWith("manual_")?"disabled":""}`,onClick:()=>!(D&&S&&!S.toString().startsWith("manual_"))&&this.props.navigate(`/devices/${t}/control`),disabled:D&&!!S&&!S.toString().startsWith("manual_"),title:D&&S&&!S.toString().startsWith("manual_")?"Locked: Appium Session":"Take Control",children:[e.jsx(hs,{size:14}),e.jsx("span",{style:{fontSize:"10px",fontWeight:800,letterSpacing:"0.05em",fontFamily:"Outfit, sans-serif"},children:"CTRL"})]})]}),this.state.showReservation&&e.jsx(It,{device:this.props.device,onClose:()=>this.setState({showReservation:!1}),onReserved:()=>this.props.reloadDevices()}),this.state.showTagManager&&e.jsx(Et,{device:this.props.device,onClose:()=>this.setState({showTagManager:!1}),onUpdated:()=>this.props.reloadDevices()})]})}}function Mt(n){const s=ns();return e.jsx(Rt,{...n,navigate:s})}class _t extends qe.Component{render(){return e.jsx("div",{className:"device-explorer-card-container",children:qe.Children.toArray(this.props.devices.map(s=>e.jsx(Mt,{device:s,reloadDevices:this.props.reloadDevices})))})}}var We,Ut=new Uint8Array(16);function Ft(){if(!We&&(We=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!We))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return We(Ut)}const Ot=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Ht(n){return typeof n=="string"&&Ot.test(n)}var X=[];for(var es=0;es<256;++es)X.push((es+256).toString(16).substr(1));function Pt(n){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,l=(X[n[s+0]]+X[n[s+1]]+X[n[s+2]]+X[n[s+3]]+"-"+X[n[s+4]]+X[n[s+5]]+"-"+X[n[s+6]]+X[n[s+7]]+"-"+X[n[s+8]]+X[n[s+9]]+"-"+X[n[s+10]]+X[n[s+11]]+X[n[s+12]]+X[n[s+13]]+X[n[s+14]]+X[n[s+15]]).toLowerCase();if(!Ht(l))throw TypeError("Stringified UUID is invalid");return l}function Bt(n,s,l){n=n||{};var u=n.random||(n.rng||Ft)();return u[6]=u[6]&15|64,u[8]=u[8]&63|128,Pt(u)}const Wt=({onCommand:n,prompt:s="$",welcomeMessage:l="Interactive Shell (Restricted Mode)",platform:u})=>{const[p,t]=r.useState([{type:"system",content:l,timestamp:Date.now()},{type:"system",content:'Type "help" for allowed commands.',timestamp:Date.now()}]),[L,v]=r.useState(""),[x,h]=r.useState([]),[m,D]=r.useState(-1),[S,U]=r.useState(!1),w=r.useRef(null),j=r.useRef(null);r.useEffect(()=>{w.current&&(w.current.scrollTop=w.current.scrollHeight)},[p]);const T=b=>{const k=b.trim();if((k.startsWith("{")||k.startsWith("["))&&(k.endsWith("}")||k.endsWith("]")))try{const y=JSON.parse(k);return JSON.stringify(y,null,2)}catch{}return b},F=async b=>{if(b.key==="Enter"&&!S){const k=L.trim();if(!k)return;if(v(""),t(y=>[...y,{type:"command",content:`${s} ${k}`,timestamp:Date.now()}]),h(y=>[...y,k]),D(-1),U(!0),k==="clear"){t([]),U(!1);return}if(k==="help"){let y="";u==="android"?y=`
|
|
142
137
|
Android Allowed Commands:
|
|
143
138
|
• System Info: getprop, ip addr, date, uptime, cat /proc/meminfo, cat /proc/cpuinfo
|
|
144
139
|
• Process Mgmt: ps, top
|
|
@@ -153,11 +148,11 @@ iOS Allowed Commands:
|
|
|
153
148
|
listapps, get_app_container, list, getenv
|
|
154
149
|
• Simulator System:
|
|
155
150
|
ls, ps, top, date, uptime, whoami
|
|
156
|
-
`),
|
|
157
|
-
`:p.toLowerCase().startsWith("-android")&&
|
|
158
|
-
`:"",
|
|
151
|
+
`),t(R=>[...R,{type:"output",content:y.trim(),timestamp:Date.now()}]),U(!1);return}try{const y=await n(k),R=T(y||"(No output)");t(M=>[...M,{type:"output",content:R,timestamp:Date.now()}])}catch(y){t(R=>[...R,{type:"error",content:y.message||"Unknown error",timestamp:Date.now()}])}finally{U(!1),setTimeout(()=>{var y;return(y=j.current)==null?void 0:y.focus()},10)}}else if(b.key==="ArrowUp"){if(b.preventDefault(),x.length>0){const k=m===-1?x.length-1:Math.max(0,m-1);D(k),v(x[k])}}else if(b.key==="ArrowDown"&&(b.preventDefault(),m!==-1)){const k=m+1;k>=x.length?(D(-1),v("")):(D(k),v(x[k]))}};return e.jsxs("div",{className:"terminal-container",children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.05,zIndex:1001}}),e.jsxs("header",{className:"terminal-header",children:[e.jsxs("div",{className:"terminal-controls",children:[e.jsx("div",{className:"dot red"}),e.jsx("div",{className:"dot yellow"}),e.jsx("div",{className:"dot green"})]}),e.jsxs("div",{className:"terminal-title",children:[u.toUpperCase()," INTERNAL SHELL"]}),e.jsx("div",{className:"terminal-actions",children:e.jsx("button",{className:"terminal-action-btn",onClick:()=>t([]),title:"Clear Terminal",children:"CLEAR"})})]}),e.jsxs("div",{className:"terminal-history",ref:w,onClick:()=>{var b;return(b=j.current)==null?void 0:b.focus()},children:[p.map((b,k)=>e.jsx("div",{className:`terminal-line ${b.type}`,children:b.content},k)),S&&e.jsx("div",{className:"terminal-line system animate-pulse",children:"Executing command..."})]}),e.jsxs("div",{className:"terminal-input-area",children:[e.jsx("span",{className:"terminal-prompt",children:s}),e.jsx("input",{ref:j,className:"terminal-input",value:L,onChange:b=>v(b.target.value),onKeyDown:F,disabled:S,autoFocus:!0,spellCheck:!1,autoComplete:"off",placeholder:"Type a command..."})]})]})};function ps(n,s){const l=n.toLowerCase();if(l==="accessibility id")return/[0-9a-f]{8}-[0-9a-f]{4}/i.test(s)?{level:"fragile",reason:"UUID in accessibility ID — dynamically generated, unreliable"}:{level:"stable",reason:"#1 recommended by Appium — portable across Android & iOS"};if(l==="id")return/[0-9a-f]{8}-[0-9a-f]{4}/i.test(s)?{level:"fragile",reason:"UUID in resource ID — dynamically generated"}:/\d{6,}/.test(s)&&!s.includes(":id/")?{level:"moderate",reason:"Long numeric ID without package prefix — may not be unique"}:/^[a-z][a-z0-9.]+:id\//.test(s)?{level:"stable",reason:"Android resource-id with package prefix — #2 by Appium priority"}:{level:"stable",reason:"Element ID — #2 by Appium 2.x recommended priority"};if(l==="xpath"){if(s.startsWith("/hierarchy")||s.startsWith("/")&&!s.startsWith("//"))return{level:"very-fragile",reason:"ABSOLUTE XPath — breaks on any layout change. Avoid entirely"};if(/\[\d+\]/.test(s))return{level:"very-fragile",reason:"Index-based XPath [n] — breaks when element order changes"};const u=(s.match(/\//g)||[]).length;return u>7?{level:"fragile",reason:`${u}-level deep XPath — brittle to layout changes, 10x slower on iOS`}:s.includes("@content-desc")||s.includes("@resource-id")||s.includes("@text")?{level:"moderate",reason:"XPath with semantic attribute — more stable, but still prefer ID/accessibility id"}:{level:"fragile",reason:"XPath is a LAST RESORT per Appium docs — 10x slower on iOS, breaks on UI changes"}}return l==="-ios predicate string"?{level:"stable",reason:"iOS NSPredicate — native engine, excellent performance on iOS"}:l==="-ios class chain"?{level:"stable",reason:"iOS Class Chain — native iOS, faster than XPath"}:l==="-android uiautomator"?s.includes("resourceId")||s.includes("description")?{level:"stable",reason:"UIAutomator2 with resourceId/description — Android native, very reliable"}:s.includes("textContains")||s.includes("text(")?{level:"moderate",reason:"UIAutomator2 with text matching — breaks if copy changes"}:{level:"stable",reason:"UIAutomator2 — Android native engine, preferred over XPath on Android"}:l==="class name"?{level:"fragile",reason:"Class name alone is almost never unique — use with explicit index or prefer accessibility id"}:l==="name"?{level:"fragile",reason:"⚠️ Deprecated in Appium 2.x — replace with accessibility id or id"}:l==="link text"?{level:"moderate",reason:"Text-based locator — breaks if copy/label changes"}:{level:"moderate",reason:"Verify reliability for your target platform"}}function vs(n,s,l,u){var b,k,y,R,M,_,q;const{strategy:p,value:t}=u,L=(n.text||n.name||((b=n.type)==null?void 0:b.split(".").pop())||"element").replace(/[^a-zA-Z0-9]/g,"_").replace(/^_+/,"").slice(0,24)||"element",v=L.charAt(0).toLowerCase()+L.slice(1),x=((k=n.type)==null?void 0:k.toLowerCase().includes("edit"))||((y=n.type)==null?void 0:y.toLowerCase().includes("input"))||((R=n.type)==null?void 0:R.toLowerCase().includes("field"))||((M=n.type)==null?void 0:M.toLowerCase().includes("textfield")),h=((_=n.attributes)==null?void 0:_.scrollable)==="true"||((q=n.attributes)==null?void 0:q.scrollable)===!0,m=p.toLowerCase().startsWith("-ios")&&s!=="ios"?`// ⚠️ -ios predicate/class chain ONLY work with XCUITest (iOS)
|
|
152
|
+
`:p.toLowerCase().startsWith("-android")&&s!=="android"?`// ⚠️ -android uiautomator ONLY works with UIAutomator2 (Android)
|
|
153
|
+
`:"",D={"accessibility id":`~${t}`,id:s==="ios"?`-ios predicate string:label == "${t}"`:`android=new UiSelector().resourceId("${t}")`,xpath:`${t}`,"-ios predicate string":`-ios predicate string:${t}`,"-ios class chain":`-ios class chain:${t}`,"-android uiautomator":`android=${t}`},S={"accessibility id":`AppiumBy.accessibilityId("${t}")`,id:`AppiumBy.id("${t}")`,xpath:`AppiumBy.xpath("${t}")`,"-ios predicate string":`AppiumBy.iOSNsPredicateString("${t}")`,"-ios class chain":`AppiumBy.iOSClassChain("${t}")`,"-android uiautomator":`AppiumBy.androidUIAutomator("${t}")`,"class name":`AppiumBy.className("${t}")`},U={"accessibility id":`AppiumBy.ACCESSIBILITY_ID, "${t}"`,id:`AppiumBy.ID, "${t}"`,xpath:`AppiumBy.XPATH, "${t}"`,"-ios predicate string":`AppiumBy.IOS_PREDICATE, "${t}"`,"-ios class chain":`AppiumBy.IOS_CLASS_CHAIN, "${t}"`,"-android uiautomator":`AppiumBy.ANDROID_UIAUTOMATOR, '${t}'`,"class name":`AppiumBy.CLASS_NAME, "${t}"`},w=S[p.toLowerCase()],j=U[p.toLowerCase()],T=D[p.toLowerCase()];return l==="java"?w?`${m}// Appium Java Client 9.x + Selenium 4 + TestNG
|
|
159
154
|
import io.appium.java_client.AppiumBy;
|
|
160
|
-
import io.appium.java_client.${
|
|
155
|
+
import io.appium.java_client.${s==="android"?"AndroidDriver":s==="ios"?"IOSDriver":"AppiumDriver"};
|
|
161
156
|
import org.openqa.selenium.WebElement;
|
|
162
157
|
import org.testng.annotations.Test;
|
|
163
158
|
|
|
@@ -189,7 +184,7 @@ const element = await driver.$('${T}');
|
|
|
189
184
|
await element.waitForExist({ timeout: 5000 });
|
|
190
185
|
${x?`await driver.$('target').clearValue();
|
|
191
186
|
await element.addValue("your text here");`:"await element.click();"}
|
|
192
|
-
// Assert with expect(element).toBeDisplayed()`:`// Strategy "${p}" not supported in WebdriverIO mobile`}function Vs(n){var U,w,j,T,F,b,k,y,R,M,_;const t=(n.type||"").toLowerCase(),l=((U=n.attributes)==null?void 0:U.clickable)==="true"||((w=n.attributes)==null?void 0:w.clickable)===!0,u=((j=n.attributes)==null?void 0:j.enabled)!=="false"&&((T=n.attributes)==null?void 0:T.enabled)!==!1,p=((F=n.attributes)==null?void 0:F.scrollable)==="true"||((b=n.attributes)==null?void 0:b.scrollable)===!0,s=n.text||n.label||n.value||"",L=((k=n.children)==null?void 0:k.length)||0;let v="Element",x="📦";t.includes("button")||t.includes("btn")||l&&L===0?(v="Button",x="🔘"):t.includes("edit")||t.includes("input")||t.includes("field")?(v="Text Input",x="✏️"):t.includes("image")||t.includes("img")||t.includes("imageview")?(v="Image",x="🖼️"):t.includes("scroll")||t.includes("recyclerview")||t.includes("listview")||p?(v="Scrollable List",x="📜"):t.includes("text")||t.includes("label")?(v="Text Label",x="📝"):t.includes("switch")||t.includes("toggle")||t.includes("checkbox")?(v="Toggle / Checkbox",x="☑️"):t.includes("nav")||t.includes("toolbar")||t.includes("tabbar")?(v="Navigation Bar",x="🧭"):L>0&&(v=`Container (${L} children)`,x="🗂️");const h=((y=n.suggestedLocators)==null?void 0:y.find(q=>q.strategy==="accessibility id"||q.strategy==="id"))||((R=n.suggestedLocators)==null?void 0:R[0]),m=u?((M=n.rect)==null?void 0:M.width)===0||((_=n.rect)==null?void 0:_.height)===0?"⚠️ Zero-size element — may not be interactable":void 0:"⚠️ Element is disabled",A=s?` with text "${s.slice(0,30)}"`:"",S=`This is a ${v.toLowerCase()}${A}. ${l?"It can be tapped/clicked.":p?"It supports scrolling.":"It is a visual container."}${L>0?` Contains ${L} child element${L>1?"s":""}.`:""}`;return{role:v,description:S,interactable:l||u,bestLocator:h,warning:m,emoji:x}}function xt(n,t){if(!t)return!0;const l=t.toLowerCase().trim(),u={button:["button","btn","clickable","tapable"],input:["edittext","input","field","textfield","textinput","edit"],image:["image","imageview","img","picture","photo","icon"],text:["textview","label","text","statictext"],list:["listview","recyclerview","scrollview","tableview","collectionview","scroll"],toggle:["switch","checkbox","toggle","radiobutton"],nav:["toolbar","navigationbar","tabbar","actionbar","navbar"]},p=(n.type||"").toLowerCase(),s=(n.text||n.label||n.value||"").toLowerCase(),L=(n.name||"").toLowerCase(),v=Object.values(n.attributes||{}).join(" ").toLowerCase();for(const[x,h]of Object.entries(u))if(l.includes(x)&&h.some(m=>p.includes(m)))return!0;return p.includes(l)||s.includes(l)||L.includes(l)||v.includes(l)}const qs=({sessionId:n,udid:t,streamUrl:l})=>{var De,ie,ae,ke,xe,Ae,Ue;const[u,p]=r.useState(!0),[s,L]=r.useState(null),[v,x]=r.useState(null),[h,m]=r.useState(null),[A,S]=r.useState(null),[U,w]=r.useState(new Set(["/"])),[j,T]=r.useState(""),[F,b]=r.useState(null),[k,y]=r.useState("info"),[R,M]=r.useState("java"),[_,q]=r.useState(null),[H,te]=r.useState({width:0,height:0}),[Ce,fe]=r.useState({width:0,height:0}),[Ge,d]=r.useState(!1),[Z,Te]=r.useState("inspect"),Se=r.useRef(null),ye=r.useRef(null),je=r.useRef(null),me=r.useRef(null),ue=r.useCallback(()=>{var z,K,J;if(!Se.current)return;const i=Se.current.getBoundingClientRect(),o=i.width,g=i.height,C=(z=s==null?void 0:s.hierarchy)==null?void 0:z.rect;let O=((K=s==null?void 0:s.metadata)==null?void 0:K.screenWidth)||H.width||1,P=((J=s==null?void 0:s.metadata)==null?void 0:J.screenHeight)||H.height||1;C&&C.width>0&&C.height>0&&(O=C.width,P=C.height);const B=O/P;let W,V;o/g>B?(V=g,W=V*B):(W=o,V=W/B),fe({width:W,height:V})},[s,H]);r.useEffect(()=>(ue(),window.addEventListener("resize",ue),()=>window.removeEventListener("resize",ue)),[ue]),r.useEffect(()=>{t&&ce()},[t]),r.useEffect(()=>{var i;if((i=h==null?void 0:h.suggestedLocators)!=null&&i.length){const o=h.suggestedLocators.find(g=>g.strategy==="accessibility id"||g.strategy==="id")||h.suggestedLocators[0];q(o)}else q(null)},[h]);const ce=async()=>{if(t){p(!0),x(null);try{const i=await D.getInspectorSnapshot(t);L(i);const o=new Set(["/"]),g=(C,O)=>{var P;O<2&&(o.add(C.xpath),(P=C.children)==null||P.forEach(B=>g(B,O+1)))};i.hierarchy&&g(i.hierarchy,0),w(o)}catch(i){x(i.message||"Failed to capture snapshot")}finally{p(!1)}}},ze=i=>{const{naturalWidth:o,naturalHeight:g}=i.currentTarget;te({width:o,height:g})},le=()=>d(!0),Ee=i=>{d(!1);const{naturalWidth:o,naturalHeight:g}=i.currentTarget;o>0&&g>0&&te({width:o,height:g})},Q=l&&!Ge,Ie=i=>{if(Z!=="interact"||!t)return;const o=i.currentTarget.getBoundingClientRect();me.current={x:i.clientX-o.left,y:i.clientY-o.top,time:Date.now()}},oe=async i=>{var de,Fe,Le;if(Z!=="interact"||!t||!me.current)return;const o=me.current,g=i.currentTarget.getBoundingClientRect(),C=i.clientX-g.left,O=i.clientY-g.top,P=Date.now()-o.time,B=Ce.width,W=Ce.height,V=(de=s==null?void 0:s.hierarchy)==null?void 0:de.rect;let z=((Fe=s==null?void 0:s.metadata)==null?void 0:Fe.screenWidth)||H.width,K=((Le=s==null?void 0:s.metadata)==null?void 0:Le.screenHeight)||H.height;if(V&&V.width>0&&V.height>0&&(z=V.width,K=V.height),!z||!K||B===0||W===0)return;const J=(a,c)=>({x:Math.round(a/B*z),y:Math.round(c/W*K),px:a/B,py:c/W}),Y=J(o.x,o.y),ge=J(C,O),se=Math.sqrt(Math.pow(C-o.x,2)+Math.pow(O-o.y,2));if(!(Y.px<0||Y.px>1||Y.py<0||Y.py>1)){try{P<500&&se<10?await D.tap(t,Y.x,Y.y):P>=500&&se<10?await D.touchAndHold(t,Y.x,Y.y,P):se>=10&&await D.swipe(t,Y.x,Y.y,ge.x,ge.y)}catch(a){console.error("Interaction failed:",a)}me.current=null}},Ye=i=>{const o=new Set(U);o.has(i)?o.delete(i):o.add(i),w(o)},$e=()=>{const i=new Set,o=g=>{var C;i.add(g.xpath),(C=g.children)==null||C.forEach(o)};s!=null&&s.hierarchy&&o(s.hierarchy),w(i)},be=()=>w(new Set(["/"])),Re=(i,o)=>{navigator.clipboard.writeText(i),b(o),setTimeout(()=>b(null),2e3)},pe=i=>{var g;let o=1;return(g=i.children)==null||g.forEach(C=>o+=pe(C)),o},Ne=i=>i.xpath.split("/").filter(Boolean).slice(-3),ee=(i,o=0)=>{var V;if(!i)return null;const g=U.has(i.xpath),C=((V=i.children)==null?void 0:V.length)>0,O=(h==null?void 0:h.xpath)===i.xpath,P=(A==null?void 0:A.xpath)===i.xpath,B=i.name||i.type.split(".").pop()||"Element",W=!j||xt(i,j);if(!W&&!C)return null;if(j&&!W){const z=K=>{var J;return xt(K,j)?!0:((J=K.children)==null?void 0:J.some(z))||!1};if(!z(i))return null}return e.jsxs("div",{className:"tree-node",children:[e.jsxs("div",{className:`tree-item ${O?"selected":""} ${P&&!O?"hovered":""}`,onClick:()=>{m(i),y("info")},onMouseEnter:()=>S(i),onMouseLeave:()=>S(null),children:[e.jsx("div",{className:"tree-item-indent",style:{width:`${o*14}px`}}),C?e.jsx("button",{onClick:z=>{z.stopPropagation(),Ye(i.xpath)},className:"tree-toggle",children:g?e.jsx(yt,{size:11}):e.jsx(bt,{size:11})}):e.jsx("span",{className:"tree-toggle-spacer"}),e.jsx(Ht,{size:11,className:"tree-icon"}),e.jsx("span",{className:"tree-label",children:B}),i.text&&e.jsxs("span",{className:"tree-text-preview",children:['"',i.text.slice(0,20),'"']}),C&&e.jsx("span",{className:"tree-badge",children:i.children.length})]}),g&&C&&e.jsx("div",{className:"tree-children",children:i.children.map(z=>ee(z,o+1))})]},i.xpath)},we=i=>{var B,W,V;if(!H.width)return[];const o=[],g=(B=s==null?void 0:s.hierarchy)==null?void 0:B.rect;let C=((W=s==null?void 0:s.metadata)==null?void 0:W.screenWidth)||H.width,O=((V=s==null?void 0:s.metadata)==null?void 0:V.screenHeight)||H.height;g&&g.width>0&&g.height>0&&(C=g.width,O=g.height);const P=(z,K)=>{var Y,ge,se;const J=!z.children||z.children.length===0;((Y=z.rect)==null?void 0:Y.width)>0&&((ge=z.rect)==null?void 0:ge.height)>0&&J&&o.push(e.jsx("div",{className:"omni-hit-area",style:{left:`${z.rect.x/C*100}%`,top:`${z.rect.y/O*100}%`,width:`${z.rect.width/C*100}%`,height:`${z.rect.height/O*100}%`,zIndex:K},onClick:de=>{de.stopPropagation(),m(z),y("info")},onMouseEnter:()=>S(z),onMouseLeave:()=>S(null)},z.xpath)),(se=z.children)==null||se.forEach(de=>P(de,K+1))};return s!=null&&s.hierarchy&&P(s.hierarchy,1),o},ve=(i,o)=>{var P,B,W;if(!(i!=null&&i.rect)||!H.width)return null;const g=(P=s==null?void 0:s.hierarchy)==null?void 0:P.rect;let C=((B=s==null?void 0:s.metadata)==null?void 0:B.screenWidth)||H.width,O=((W=s==null?void 0:s.metadata)==null?void 0:W.screenHeight)||H.height;return g&&g.width>0&&g.height>0&&(C=g.width,O=g.height),e.jsx("div",{className:`omni-frame-${o}`,style:{left:`${i.rect.x/C*100}%`,top:`${i.rect.y/O*100}%`,width:`${i.rect.width/C*100}%`,height:`${i.rect.height/O*100}%`}})},Me=s!=null&&s.hierarchy?pe(s.hierarchy):0,G=h?Vs(h):null,_e={stable:{icon:e.jsx(it,{size:10}),cls:"stable"},moderate:{icon:e.jsx(Tt,{size:10}),cls:"moderate"},fragile:{icon:e.jsx(ht,{size:10}),cls:"fragile"},"very-fragile":{icon:e.jsx(ht,{size:10}),cls:"very-fragile"}};return e.jsx("div",{className:"omni-inspector-container",children:e.jsxs("div",{className:"omni-main-content",children:[e.jsxs("div",{className:"omni-screenshot-panel",children:[e.jsxs("div",{className:"omni-screenshot-header",children:[e.jsxs("div",{className:"omni-header-left",children:[e.jsx("span",{className:"omni-screenshot-title",children:"Device Preview"}),e.jsxs("div",{className:"omni-mode-toggle",children:[e.jsxs("button",{className:`omni-mode-btn ${Z==="inspect"?"active":""}`,onClick:()=>Te("inspect"),title:"Inspection Mode (Highlight Elements)",children:[e.jsx(Mt,{size:12}),e.jsx("span",{children:"Inspect"})]}),e.jsxs("button",{className:`omni-mode-btn ${Z==="interact"?"active":""}`,onClick:()=>Te("interact"),title:"Interaction Mode (Direct Control)",children:[e.jsx(Ss,{size:12}),e.jsx("span",{children:"Interact"})]})]})]}),e.jsxs("button",{className:"omni-refresh-btn",onClick:ce,disabled:u,children:[e.jsx(Ve,{size:12,className:u?"animate-spin":""}),u?"Capturing...":"Refresh"]})]}),e.jsxs("div",{className:"omni-screenshot-container",ref:Se,children:[u&&!Q&&e.jsxs("div",{className:"omni-loading-overlay",children:[e.jsx("div",{className:"omni-spinner"}),e.jsx("span",{children:"Capturing screen..."})]}),!s&&!u&&!Q&&e.jsxs("div",{className:"omni-empty-state",children:[e.jsx(ut,{size:40}),e.jsx("span",{children:"Click Refresh to capture"})]}),Q&&e.jsxs("div",{className:`omni-screenshot-wrapper ${Z==="interact"?"interactable":""}`,onMouseDown:Ie,onMouseUp:oe,children:[e.jsx("img",{ref:je,src:l,onLoad:Ee,onError:le,className:"omni-screenshot-img",style:Z==="interact"?{pointerEvents:"none"}:{},draggable:!1,alt:"Live Device Stream"}),(s==null?void 0:s.hierarchy)&&Z==="inspect"&&e.jsxs("div",{className:"omni-overlay",children:[we(s.hierarchy),ve(A,"hover"),ve(h,"select")]})]}),!Q&&(s==null?void 0:s.screenshot)&&e.jsxs("div",{className:`omni-screenshot-wrapper ${Z==="interact"?"interactable":""}`,onMouseDown:Ie,onMouseUp:oe,children:[e.jsx("img",{ref:ye,src:`data:image/png;base64,${s.screenshot}`,onLoad:ze,className:"omni-screenshot-img",style:Z==="interact"?{pointerEvents:"none"}:{},draggable:!1}),Z==="inspect"&&e.jsxs("div",{className:"omni-overlay",children:[we(s.hierarchy),ve(A,"hover"),ve(h,"select")]})]})]})]}),e.jsxs("div",{className:"omni-tree-panel",children:[e.jsxs("div",{className:"omni-tree-header",children:[e.jsxs("div",{className:"omni-tree-title",children:[e.jsx(ss,{size:14}),e.jsx("span",{children:"Source"}),Me>0&&e.jsxs("span",{className:"omni-count-badge",children:[Me," elements"]})]}),e.jsxs("div",{className:"omni-tree-actions",children:[e.jsx("button",{onClick:$e,className:"omni-action-btn",title:"Expand All",children:e.jsx(Zt,{size:12})}),e.jsx("button",{onClick:be,className:"omni-action-btn",title:"Collapse All",children:e.jsx(xs,{size:12})})]})]}),e.jsxs("div",{className:"omni-tree-search",children:[e.jsx(Xe,{size:14}),e.jsx("input",{type:"text",placeholder:"Search elements... (try 'login button' or 'text field')",value:j,onChange:i=>T(i.target.value)}),j&&e.jsx("button",{onClick:()=>T(""),className:"omni-clear-btn",children:"×"})]}),j&&e.jsxs("div",{className:"omni-search-hint",children:[e.jsx(mt,{size:10}),' Smart search active — try "button", "input", "image"']}),e.jsx("div",{className:"omni-tree-content",children:s!=null&&s.hierarchy?ee(s.hierarchy):e.jsx("div",{className:"omni-empty-state small",children:e.jsx("span",{children:"No hierarchy loaded"})})})]}),e.jsxs("div",{className:"omni-details-panel",children:[e.jsxs("div",{className:"omni-details-tabs",children:[e.jsxs("button",{className:`omni-details-tab ${k==="info"?"active":""}`,onClick:()=>y("info"),children:[e.jsx(ls,{size:12})," Info"]}),e.jsxs("button",{className:`omni-details-tab ${k==="insight"?"active":""}`,onClick:()=>y("insight"),disabled:!h,title:"AI Element Analysis",children:[e.jsx(as,{size:12})," AI Insight"]}),e.jsxs("button",{className:`omni-details-tab ${k==="code"?"active":""}`,onClick:()=>y("code"),disabled:!h,title:"Generate Test Code",children:[e.jsx(ot,{size:12})," Code Gen"]})]}),e.jsx("div",{className:"omni-details-content",children:h?e.jsxs(e.Fragment,{children:[k==="info"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"omni-section",children:[e.jsx("div",{className:"omni-section-header",children:"Element Info"}),e.jsxs("div",{className:"omni-info-table",children:[e.jsxs("div",{className:"omni-info-row",children:[e.jsx("span",{className:"omni-info-key",children:"Type"}),e.jsx("span",{className:"omni-info-value mono",children:h.type})]}),h.text&&e.jsxs("div",{className:"omni-info-row",children:[e.jsx("span",{className:"omni-info-key",children:"Text"}),e.jsx("span",{className:"omni-info-value",children:h.text})]}),e.jsxs("div",{className:"omni-info-row",children:[e.jsx("span",{className:"omni-info-key",children:"Path"}),e.jsx("span",{className:"omni-info-value mono small",children:Ne(h).join(" › ")})]})]})]}),e.jsxs("div",{className:"omni-section",children:[e.jsx("div",{className:"omni-section-header",children:"Layout"}),e.jsx("div",{className:"omni-layout-grid",children:["x","y","width","height"].map(i=>e.jsxs("div",{className:"omni-layout-item",children:[e.jsx("span",{className:"omni-layout-label",children:i.toUpperCase()}),e.jsx("span",{className:"omni-layout-value",children:h.rect[i]})]},i))})]}),e.jsxs("div",{className:"omni-section",children:[e.jsxs("div",{className:"omni-section-header",children:["Locators",e.jsx("span",{className:"omni-section-badge",children:"Stability Scored"})]}),e.jsx("div",{className:"omni-locators-list",children:(De=h.suggestedLocators)==null?void 0:De.map(i=>{const o=pt(i.strategy,i.value),g=_e[o.level];return e.jsxs("div",{className:`omni-locator-row ${(_==null?void 0:_.strategy)===i.strategy?"selected-for-code":""}`,onClick:()=>q(i),title:"Click to use in Code Generator",children:[e.jsxs("div",{className:"omni-locator-left",children:[e.jsxs("div",{className:"omni-locator-top",children:[e.jsx("span",{className:"omni-locator-strategy",children:i.strategy}),e.jsxs("span",{className:`omni-stability-badge ${g.cls}`,title:o.reason,children:[g.icon,o.level]})]}),e.jsx("code",{className:"omni-locator-value",children:i.value}),e.jsx("span",{className:"omni-stability-reason",children:o.reason})]}),e.jsx("button",{onClick:C=>{C.stopPropagation(),Re(i.value,i.strategy)},className:`omni-copy-btn ${F===i.strategy?"copied":""}`,children:F===i.strategy?e.jsx(Je,{size:12}):e.jsx(Ze,{size:12})})]},i.strategy)})})]}),e.jsxs("div",{className:"omni-section",children:[e.jsx("div",{className:"omni-section-header",children:"Attributes"}),e.jsx("div",{className:"omni-attributes-table",children:Object.entries(h.attributes||{}).filter(([i,o])=>o!=null&&o!=="").map(([i,o])=>e.jsxs("div",{className:"omni-attr-row",children:[e.jsx("span",{className:"omni-attr-key",children:i}),e.jsx("span",{className:"omni-attr-value",children:String(o)})]},i))})]})]}),k==="insight"&&G&&e.jsxs("div",{className:"omni-insight-panel",children:[e.jsxs("div",{className:"omni-insight-role",children:[e.jsx("span",{className:"omni-insight-emoji",children:G.emoji}),e.jsxs("div",{children:[e.jsx("div",{className:"omni-insight-role-name",children:G.role}),e.jsx("div",{className:"omni-insight-interactable",children:G.interactable?e.jsxs("span",{className:"omni-badge-green",children:[e.jsx(Ut,{size:10})," Interactable"]}):e.jsx("span",{className:"omni-badge-gray",children:"Visual Only"})})]})]}),G.warning&&e.jsx("div",{className:"omni-insight-warning",children:G.warning}),e.jsxs("div",{className:"omni-insight-description",children:[e.jsx(mt,{size:12,className:"omni-insight-icon"}),e.jsx("p",{children:G.description})]}),G.bestLocator&&e.jsxs("div",{className:"omni-insight-best-locator",children:[e.jsx("div",{className:"omni-section-header",children:"Recommended Locator"}),e.jsxs("div",{className:"omni-locator-row",children:[e.jsxs("div",{className:"omni-locator-left",children:[e.jsx("span",{className:"omni-locator-strategy",children:G.bestLocator.strategy}),e.jsx("code",{className:"omni-locator-value",children:G.bestLocator.value})]}),e.jsx("button",{onClick:()=>Re(G.bestLocator.value,"best"),className:`omni-copy-btn ${F==="best"?"copied":""}`,children:F==="best"?e.jsx(Je,{size:12}):e.jsx(Ze,{size:12})})]})]}),e.jsxs("div",{className:"omni-insight-attributes",children:[e.jsx("div",{className:"omni-section-header",children:"Quick Facts"}),e.jsx("div",{className:"omni-quick-facts",children:[{label:"Clickable",value:(ie=h.attributes)==null?void 0:ie.clickable},{label:"Enabled",value:(ae=h.attributes)==null?void 0:ae.enabled},{label:"Scrollable",value:(ke=h.attributes)==null?void 0:ke.scrollable},{label:"Focusable",value:(xe=h.attributes)==null?void 0:xe.focusable},{label:"Children",value:((Ae=h.children)==null?void 0:Ae.length)||0}].map(({label:i,value:o})=>e.jsxs("div",{className:"omni-quick-fact-row",children:[e.jsx("span",{className:"omni-quick-fact-label",children:i}),e.jsx("span",{className:`omni-quick-fact-value ${o==="true"||o===!0?"true":""}`,children:String(o??"—")})]},i))})]})]}),k==="code"&&e.jsxs("div",{className:"omni-codegen-panel",children:[e.jsx("div",{className:"omni-codegen-frameworks",children:["java","python","javascript","wdio"].map(i=>e.jsx("button",{className:`omni-fw-btn ${R===i?"active":""}`,onClick:()=>M(i),children:i==="java"?"☕ Java":i==="python"?"🐍 Python":i==="javascript"?"🟨 JS":"🔷 WD.io"},i))}),_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"omni-codegen-locator-selector",children:[e.jsx("span",{className:"omni-codegen-label",children:"Locator:"}),e.jsx("select",{value:_.strategy,onChange:i=>{var g;const o=(g=h.suggestedLocators)==null?void 0:g.find(C=>C.strategy===i.target.value);o&&q(o)},className:"omni-fw-select",children:(Ue=h.suggestedLocators)==null?void 0:Ue.map(i=>e.jsxs("option",{value:i.strategy,children:[i.strategy," — ",pt(i.strategy,i.value).level]},i.strategy))})]}),e.jsxs("div",{className:"omni-codegen-output",children:[e.jsxs("div",{className:"omni-codegen-header",children:[e.jsx("span",{className:"omni-codegen-lang",children:R==="java"?"Java / TestNG":R==="python"?"Python / unittest":R==="javascript"?"JavaScript / Mocha":"WebdriverIO"}),e.jsx("button",{className:"omni-copy-btn",onClick:()=>Re(vt(h,(s==null?void 0:s.platform)==="android"?"android":(s==null?void 0:s.platform)==="ios"?"ios":"unknown",R,_),"code"),children:F==="code"?e.jsx(Je,{size:12}):e.jsx(Ze,{size:12})})]}),e.jsx("pre",{className:"omni-codegen-pre",children:e.jsx("code",{children:vt(h,(s==null?void 0:s.platform)==="android"?"android":(s==null?void 0:s.platform)==="ios"?"ios":"unknown",R,_)})})]})]}):e.jsxs("div",{className:"omni-empty-state small",children:[e.jsx(ot,{size:24}),e.jsx("span",{children:"No locators available for this element"})]})]})]}):e.jsxs("div",{className:"omni-empty-state",children:[e.jsx(ut,{size:32}),e.jsx("span",{children:"Select an element from the tree or screenshot"})]})})]})]})})};function Xs({device:n,onClose:t}){var Le;const{toast:l,removeToast:u}=ft(),p=nt(),{tab:s}=jt(),L=r.useRef(null),v=r.useRef(null),[x,h]=r.useState({width:0,height:0}),[m,A]=r.useState(s||"actions"),[S,U]=r.useState(""),[w,j]=r.useState(""),[T,F]=r.useState(""),[b,k]=r.useState(!0),[y,R]=r.useState([]),[M,_]=r.useState(null),[q,H]=r.useState(!1),[te,Ce]=r.useState(!1),[fe,Ge]=r.useState(0),[d,Z]=r.useState(n),[Te,Se]=r.useState([]),[ye,je]=r.useState(!1),[me,ue]=r.useState(!1),[ce,ze]=r.useState(null),[le,Ee]=r.useState([]),[Q,Ie]=r.useState(!0),[oe,Ye]=r.useState(""),[$e,be]=r.useState(!1),[Re,pe]=r.useState(0),Ne=r.useRef(""),ee=r.useRef(null),[we,ve]=r.useState(!1);r.useEffect(()=>{m&&(!s||s!==m)&&p(`/devices/${n.udid}/control/${m}`,{replace:!0})},[m,s,n.udid,p]),r.useEffect(()=>{let a;if(m==="logs"){be(!1),pe(0);const c=async()=>{try{const f=await D.getLogs(d.udid);if(pe(N=>N+1),f&&f.logs&&f.logs.trim().length>0){be(!0);const N=f.logs.replace(/\\u[0-9a-fA-F]{4}/g,$=>JSON.parse(`"${$}"`)).replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,"").split(`
|
|
193
|
-
`).filter($=>$.trim().length>0);N.length>0&&Ee($=>[...$,...N].slice(-1e3))}else pe(N=>(N>=3&&be(!0),N))}catch(f){console.error("Failed to fetch logs:",f),pe(N=>(N>=3&&be(!0),N))}};c(),a=setInterval(c,3e3)}return()=>clearInterval(a)},[m,d.udid]);const Me=()=>{if(le.length===0)return e.jsx("div",{className:"log-empty-state",children:$e?e.jsxs(e.Fragment,{children:[e.jsx(at,{size:28,style:{color:"var(--text-muted)",marginBottom:12,opacity:.4}}),e.jsx("p",{className:"log-empty-title",children:"No log output yet"}),e.jsx("p",{className:"log-empty-subtitle",children:"The log stream is active but the device is quiet. Interact with the device to generate logs."})]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{size:28,className:"animate-spin",style:{color:"var(--primary)",marginBottom:12}}),e.jsx("p",{className:"log-empty-title",children:"Connecting to device syslog..."}),e.jsxs("p",{className:"log-empty-subtitle",children:["Initializing persistent log stream for ",d.name]})]})});const a=le.filter(c=>!oe||c.toLowerCase().includes(oe.toLowerCase()));return a.length===0&&oe?e.jsxs("div",{className:"log-empty-state",children:[e.jsx(Xe,{size:28,style:{color:"var(--text-muted)",marginBottom:12,opacity:.4}}),e.jsxs("p",{className:"log-empty-title",children:['No matches for "',oe,'"']}),e.jsxs("p",{className:"log-empty-subtitle",children:[le.length," lines in buffer. Try a different search term."]})]}):a.map((c,f)=>{let N="log-debug";const $=c.toLowerCase();return $.includes("error")||$.includes("fail")?N="log-error":$.includes("warning")||$.includes("warn")?N="log-warn":($.includes("notice")||$.includes("info"))&&(N="log-notice"),e.jsxs("div",{className:`log-line ${N}`,children:[e.jsx("span",{className:"log-index",children:f+1}),e.jsx("span",{className:"log-content",children:c})]},`${f}-${c.substring(0,10)}`)})};r.useEffect(()=>{m==="logs"&&Q&&v.current&&(v.current.scrollTop=v.current.scrollHeight)},[le,m,Q]),r.useEffect(()=>((async()=>{try{Ce(!0),await D.startStream(d.udid);const f=(await D.getDevices()).find(N=>N.udid===d.udid);f&&Z(f)}catch(c){console.error("Auto-start stream failed:",c)}finally{Ce(!1)}})(),()=>{D.stopStream(d.udid).catch(()=>{})}),[n.udid]);const G=r.useCallback(async()=>{try{je(!0);const a=await D.listApps(d.udid);Array.isArray(a)&&Se(a)}catch(a){console.error("Failed to load apps:",a)}finally{je(!1)}},[d.udid]);r.useEffect(()=>{m==="actions"&&G()},[m,G]);const _e=parseInt(d.screenWidth||"1080",10),De=parseInt(d.screenHeight||"1920",10),ie=Math.min(_e,De),ae=Math.max(_e,De),ke=ie/ae,xe=r.useCallback(()=>{const a=!b,c=a?window.innerHeight*.55:window.innerHeight*.7,f=a?window.innerWidth*.8:window.innerWidth*.45,N=b?ke:1/ke;let $,I;b?($=c,I=$*N,I>f&&(I=f,$=I/N)):(I=f,$=I/N,$>c&&($=c,I=$*N)),h({width:I,height:$})},[ke,b]);r.useEffect(()=>(xe(),window.addEventListener("resize",xe),()=>window.removeEventListener("resize",xe)),[xe]),r.useEffect(()=>{const a=async()=>{if(Ne.current.length>0){const f=Ne.current;Ne.current="";try{await D.typeText(d.udid,f)}catch(N){console.error("Keyboard buffering flush failed:",N)}}},c=f=>{const N=document.activeElement;if(N&&(N.tagName==="INPUT"||N.tagName==="TEXTAREA"||N.isContentEditable)||!we&&m!=="terminal")return;const I=f.key;I==="Enter"?(ee.current&&clearTimeout(ee.current),a(),D.pressKey(d.udid,d.platform==="android"?66:"enter")):I==="Backspace"?(ee.current&&clearTimeout(ee.current),a(),D.pressKey(d.udid,d.platform==="android"?67:"backspace")):I.length===1&&(Ne.current+=I,ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{a()},50))};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c),ee.current&&clearTimeout(ee.current)}},[d.udid,d.platform,we,m]);const[Ae,Ue]=r.useState(Date.now()),i=()=>{const a=fe>0?`r=${fe}&`:"";return d.session_id&&!String(d.session_id).startsWith("manual_")?`/xenon/api/session/${d.session_id}/live_video?${a}t=${Ae}`:`/xenon/api/control/${d.udid}/stream?${a}t=${Ae}`};r.useEffect(()=>{fe>0&&Ue(Date.now())},[fe]);const o=r.useRef(null),g=a=>{const c=a.currentTarget.getBoundingClientRect();return{x:a.clientX-c.left,y:a.clientY-c.top}},C=a=>{const c=g(a);o.current={x:c.x,y:c.y,time:Date.now()}},O=async a=>{if(!o.current)return;const c=o.current,f=g(a),N=Date.now()-c.time;let $,I,ne,re;b?($=c.x/x.width*ie,I=c.y/x.height*ae,ne=f.x/x.width*ie,re=f.y/x.height*ae):($=c.x/x.width*ae,I=c.y/x.height*ie,ne=f.x/x.width*ae,re=f.y/x.height*ie);const he=Math.abs(ne-$),Oe=Math.abs(re-I);try{N<500&&he<10&&Oe<10?await D.tap(d.udid,Math.round($),Math.round(I)):N>=500&&he<10&&Oe<10?await D.touchAndHold(d.udid,Math.round($),Math.round(I),N):await D.swipe(d.udid,Math.round($),Math.round(I),Math.round(ne),Math.round(re))}catch(Dt){console.error("Action failed:",Dt)}o.current=null},P=()=>D.pressKey(d.udid,d.platform==="android"?3:"home"),B=()=>D.lock(d.udid),W=()=>D.unlock(d.udid),V=async()=>{S.trim()&&(await D.typeText(d.udid,S),U(""))},z=async()=>{try{j("Fetching...");const a=await D.getClipboard(d.udid);a&&a.content!==void 0?j(a.content||"(Clipboard is empty)"):j("No content received")}catch{j("Error: Check Appium Settings app")}},K=async()=>{H(!0);try{const a=await D.getScreenshot(d.udid);if(a!=null&&a.screenshot){const c={id:Bs(),base64:a.screenshot,timestamp:Date.now()};R(f=>[c,...f]),_(0)}}catch(a){console.error("Failed to take screenshot:",a)}finally{H(!1)}},J=a=>{R(c=>{const f=c.filter(N=>N.id!==a);return f.length===0?_(null):M!==null&&M>=f.length&&_(0),f})},Y=()=>{R([]),_(null),l("Cleared all captured evidence.","success")},ge=a=>{const c=document.createElement("a");c.href=`data:image/png;base64,${a}`,c.download=`screenshot-${d.udid}-${Date.now()}.png`,c.click()},se=async a=>{const c=ie/2,f=ae/2,N=ie*.4,$=ae*.4;let I,ne,re,he;switch(a){case"left":I=c+N,ne=f,re=c-N,he=f;break;case"right":I=c-N,ne=f,re=c+N,he=f;break;case"up":I=c,ne=f+$,re=c,he=f-$;break;case"down":I=c,ne=f-$,re=c,he=f+$;break}try{await D.swipe(d.udid,Math.round(I),Math.round(ne),Math.round(re),Math.round(he))}catch(Oe){console.error(`Quick swipe ${a} failed:`,Oe)}},de=async()=>{if(T.trim()){const a=l(`Uninstalling ${T}...`,"loading",0);try{je(!0),await D.uninstallApp(d.udid,T),F(""),l(`Request sent for ${T}`,"success"),setTimeout(G,3e3)}catch{l("Uninstall failed. Check logs.","error")}finally{je(!1),u(a)}}},Fe=async()=>{if(!ce)return;let a;try{ue(!0),a=l(`Installing app to ${d.udid}...`,"loading",0);const c=await D.uploadAndInstallApp(d.udid,ce);c.success?(l(c.message||"App installed successfully","success"),ze(null),setTimeout(G,5e3)):l("Installation failed: "+(c.error||"Unknown error"),"error")}catch(c){l("Installation failed: "+c.message,"error")}finally{a&&u(a),ue(!1)}};return e.jsxs("div",{className:"device-control-view",children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.05,zIndex:1001}}),e.jsxs("header",{className:"control-view-top-bar",children:[e.jsxs("button",{className:"back-to-devices-btn",onClick:t,children:[e.jsx(ct,{size:18})," DEVICES"]}),e.jsxs("div",{className:"device-info-mini",children:[e.jsx("span",{className:`device-pill platform-pill ${d.platform}`,children:d.platform==="ios"?"Apple":"Android"}),e.jsxs("span",{className:"device-pill version-pill",children:["v",d.sdk]}),d.reservedUntil&&Date.now()<d.reservedUntil&&e.jsxs("span",{className:"device-pill reserved-pill",title:`Reserved by ${d.reservedBy}${d.reservationReason?`: ${d.reservationReason}`:""}`,children:["RESERVED BY ",((Le=d.reservedBy)==null?void 0:Le.toUpperCase())||"ANONYMOUS"]}),e.jsx("h2",{className:"device-name-text",children:d.name}),e.jsx("span",{className:"code-font",style:{opacity:.5},children:d.udid})]})]}),e.jsxs("div",{className:`control-view-main ${b?"":"is-landscape"} ${m==="omni"?"omni-mode":""}`,children:[e.jsxs("div",{className:"device-preview-column",children:[e.jsx("div",{className:"device-screen-wrapper",children:e.jsxs("div",{ref:L,className:`device-stream-canvas ${b?"":"landscape"} ${we?"focused":""}`,style:{width:x.width,height:x.height,background:"#000"},tabIndex:0,onFocus:()=>ve(!0),onBlur:()=>ve(!1),onMouseDown:C,onMouseUp:O,children:[te&&e.jsxs("div",{className:"device-stream-placeholder",style:{position:"absolute",zIndex:10},children:[e.jsx(Ve,{size:40,className:"animate-spin",color:"var(--primary)"}),e.jsx("p",{style:{marginTop:16},children:"ESTABLISHING TRACE..."})]}),e.jsx("img",{src:i(),alt:"Device Stream",className:"device-stream-image",style:{width:"100%",height:"100%",objectFit:"contain"},onError:()=>{console.warn("Stream failed to load, retrying..."),setTimeout(()=>Ge(a=>a+1),2e3)}})]})}),e.jsxs("aside",{className:"device-footer-actions",children:[e.jsxs("button",{className:`footer-action-btn ${b?"active":""}`,onClick:()=>k(!0),children:[e.jsx(Ve,{size:14,style:{transform:b?"none":"rotate(-90deg)"}})," ","PORTRAIT"]}),e.jsxs("button",{className:`footer-action-btn ${b?"":"active"}`,onClick:()=>k(!1),children:[e.jsx(Ve,{size:14,style:{transform:"rotate(90deg)"}})," LANDSCAPE"]}),e.jsx("div",{className:"footer-divider"}),e.jsxs("button",{className:"footer-action-btn",onClick:P,children:[e.jsx(es,{size:20})," HOME"]}),e.jsx("button",{className:"footer-action-btn",onClick:B,title:"Lock Device",children:e.jsx(Ft,{size:20})}),e.jsx("button",{className:"footer-action-btn",onClick:W,title:"Unlock Device",children:e.jsx(St,{size:20})})]})]}),e.jsxs("div",{className:"device-interactions-column",children:[e.jsxs("div",{className:"interaction-tabs",children:[e.jsx("button",{className:`tab-btn ${m==="actions"?"active":""}`,onClick:()=>A("actions"),children:"ACTIONS"}),e.jsx("button",{className:`tab-btn ${m==="screenshot"?"active":""}`,onClick:()=>A("screenshot"),children:"SCREENSHOT"}),e.jsx("button",{className:`tab-btn ${m==="logs"?"active":""}`,onClick:()=>A("logs"),children:"DEBUG LOGS"}),e.jsxs("button",{className:`tab-btn ${m==="terminal"?"active":""}`,onClick:()=>A("terminal"),children:[e.jsx(at,{size:14,style:{marginRight:6}})," SHELL"]}),e.jsx("button",{className:`tab-btn ${m==="omni"?"active":""}`,onClick:()=>A("omni"),children:"OMNI-VISION"})]}),e.jsx("div",{className:`interactions-scroll-area ${m==="terminal"?"terminal-mode":""} ${m==="screenshot"||m==="logs"?"screenshot-mode":""}`,children:e.jsxs("div",{className:"tab-content",children:[m==="omni"&&e.jsx("div",{className:"omni-inspector-tab-wrapper animate-fade-in",style:{height:"calc(100vh - 266px)"},children:e.jsx(qs,{sessionId:d.session_id?String(d.session_id):null,udid:d.udid,streamUrl:i()})}),m==="actions"&&e.jsxs("div",{className:"actions-grid",children:[e.jsxs("div",{className:"action-card",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(ms,{size:18,color:"var(--primary)"})," Directional Gestures"]}),e.jsxs("div",{className:"gestures-grid-container",children:[e.jsxs("div",{className:"gestures-dpad",children:[e.jsx("div",{}),e.jsx("button",{className:"dpad-btn",onClick:()=>se("up"),children:e.jsx(Vt,{size:24})}),e.jsx("div",{}),e.jsx("button",{className:"dpad-btn",onClick:()=>se("left"),children:e.jsx(ct,{size:24})}),e.jsx("div",{className:"dpad-center"}),e.jsx("button",{className:"dpad-btn",onClick:()=>se("right"),children:e.jsx(bt,{size:24})}),e.jsx("div",{}),e.jsx("button",{className:"dpad-btn",onClick:()=>se("down"),children:e.jsx(yt,{size:24})}),e.jsx("div",{})]}),e.jsx("p",{className:"compact-label",style:{opacity:.5},children:"Directional Glide"})]})]}),e.jsxs("div",{className:"action-card",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(Kt,{size:18,color:"var(--primary)"})," Smart Input"]}),e.jsx("input",{type:"text",className:"type-input-field compact",placeholder:"Relay keystrokes...",value:S,onChange:a=>U(a.target.value),onKeyDown:a=>a.key==="Enter"&&V()})]}),e.jsxs("div",{className:"action-card full-width",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(ps,{size:18,color:"var(--primary)"})," App Management"]}),e.jsxs("div",{className:"app-mgmt-content",children:[e.jsxs("div",{className:"install-section",children:[e.jsx("p",{className:"compact-label",children:"Install Package (.apk, .ipa, .app)"}),e.jsxs("div",{className:"upload-box-row",children:[e.jsxs("label",{className:"file-upload-launcher",children:[e.jsx(It,{size:14}),e.jsx("span",{children:ce?ce.name:"Select File"}),e.jsx("input",{type:"file",accept:".apk,.ipa,.app",onChange:a=>{var c;return ze(((c=a.target.files)==null?void 0:c[0])||null)},hidden:!0})]}),e.jsx("button",{className:"btn-premium btn-sm",disabled:!ce||me,onClick:Fe,children:me?e.jsx(He,{className:"animate-spin",size:14}):"INSTALL"})]})]}),e.jsx("div",{className:"divider-v"}),e.jsxs("div",{className:"uninstall-section",children:[e.jsx("p",{className:"compact-label",children:"Quick Uninstall"}),e.jsxs("div",{className:"uninstall-controls-row",children:[e.jsxs("div",{className:"select-wrapper",children:[e.jsxs("select",{className:"app-select-dropdown compact",value:T,onChange:a=>F(a.target.value),disabled:ye,children:[e.jsx("option",{value:"",children:ye?"Loading apps...":"-- Select App to Remove --"}),Te.map(a=>e.jsx("option",{value:a,children:a},a))]}),ye&&e.jsx(He,{className:"animate-spin select-loader",size:12})]}),e.jsxs("button",{className:"btn-destructive btn-sm",onClick:de,disabled:!T||ye,children:[e.jsx(Be,{size:14})," UNINSTALL"]})]}),e.jsxs("div",{className:"manual-input-box",children:[e.jsx("p",{className:"hint-text",children:"Or enter manually:"}),e.jsx("input",{type:"text",className:"type-input-field tiny",placeholder:"com.example.app",value:T,onChange:a=>F(a.target.value)})]})]})]})]}),e.jsxs("div",{className:"action-card full-width",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(Xt,{size:18,color:"var(--primary)"})," Clipboard"]}),e.jsxs("div",{style:{display:"flex",gap:"12px",alignItems:"flex-start"},children:[e.jsx("button",{className:"btn-premium btn-sm",style:{width:"140px",flexShrink:0},onClick:z,children:"FETCH VALUE"}),e.jsx("div",{className:"clipboard-display compact",style:{marginTop:0,flex:1},children:w})]})]})]}),m==="screenshot"&&e.jsxs("div",{className:"action-card screenshot-card",children:[e.jsxs("header",{className:"action-card-header",children:[e.jsxs("div",{className:"title-group",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(Ke,{size:20,color:"var(--primary)"})," Captured Evidence"]}),e.jsx("p",{className:"hint-text",children:"Relay screenshots from device to host."})]}),y.length>0&&e.jsx("button",{className:"btn-text-only",onClick:Y,children:"CLEAR ALL"})]}),e.jsxs("div",{className:"screenshot-workspace",children:[e.jsxs("div",{className:"screenshot-gallery-sidebar",children:[e.jsxs("button",{className:"btn-premium take-screenshot-btn",onClick:K,disabled:q,children:[q?e.jsx(He,{className:"animate-spin",size:16}):e.jsx(Ke,{size:16}),e.jsx("span",{children:q?"CAPTURING...":"NEW CAPTURE"})]}),e.jsxs("div",{className:"screenshot-thumbnails-list",children:[y.length===0&&!q&&e.jsx("div",{className:"empty-gallery-state",children:e.jsx("p",{children:"No captures yet"})}),y.map((a,c)=>e.jsxs("div",{className:`screenshot-thumb-item ${M===c?"active":""}`,onClick:()=>_(c),children:[e.jsx("img",{src:`data:image/png;base64,${a.base64}`,alt:"Thumb"}),e.jsx("span",{className:"thumb-time",children:new Date(a.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}),e.jsx("button",{className:"thumb-delete-btn",onClick:f=>{f.stopPropagation(),J(a.id)},children:e.jsx(Be,{size:12})})]},a.id))]})]}),e.jsx("div",{className:"screenshot-main-preview",children:M!==null&&y[M]?e.jsxs("div",{className:"preview-container",children:[e.jsx("div",{className:"preview-image-wrapper",children:e.jsx("img",{src:`data:image/png;base64,${y[M].base64}`,alt:"Selected Evidence"})}),e.jsxs("footer",{className:"preview-footer",children:[e.jsxs("div",{className:"preview-meta",children:[e.jsx("span",{className:"meta-label",children:"ID:"}),e.jsx("span",{className:"meta-value",children:y[M].id.substring(0,8)}),e.jsx("span",{className:"meta-divider",children:"|"}),e.jsx("span",{className:"meta-value",children:new Date(y[M].timestamp).toLocaleString()})]}),e.jsxs("div",{className:"preview-actions",children:[e.jsx("button",{className:"btn-premium btn-sm",onClick:()=>ge(y[M].base64),children:"DOWNLOAD PNG"}),e.jsxs("button",{className:"btn-destructive btn-sm",onClick:()=>J(y[M].id),children:[e.jsx(Be,{size:14})," DELETE"]})]})]})]}):e.jsxs("div",{className:"preview-empty-placeholder",children:[e.jsx(Ke,{size:48,style:{opacity:.1,marginBottom:16}}),e.jsx("p",{children:"Capture a screenshot to begin analysis"})]})})]})]}),m==="logs"&&e.jsxs("div",{className:"action-card screenshot-card",style:{padding:0,gap:0},children:[e.jsxs("div",{className:"log-toolbar",children:[e.jsxs("div",{className:"log-filter-group",children:[e.jsxs("div",{className:"log-stat-pill",children:[e.jsx("span",{className:`log-live-dot ${$e?"active":""}`}),$e?"LIVE":"CONNECTING"]}),e.jsxs("div",{className:"log-stat-pill",style:{opacity:.6},children:[le.length," LINES"]}),e.jsxs("div",{className:"log-search-box",children:[e.jsx(Xe,{size:14,className:"search-icon-inline"}),e.jsx("input",{type:"text",className:"type-input-field tiny",placeholder:"Filter trace...",value:oe,onChange:a=>Ye(a.target.value)})]})]}),e.jsxs("div",{className:"log-actions-group",children:[e.jsxs("button",{className:`btn-secondary btn-sm ${Q?"active":""}`,onClick:()=>Ie(!Q),title:Q?"Freeze Logs":"Follow Logs",children:[e.jsx($t,{size:14,className:Q?"animate-pulse":""}),Q?"FREEZE":"FOLLOW"]}),e.jsxs("button",{className:"btn-premium btn-sm",onClick:()=>{const a=new Blob([le.join(`
|
|
194
|
-
`)],{type:"text/plain"}),c=URL.createObjectURL(a),f=document.createElement("a");f.href=c,f.download=`logs-${d.udid}-${Date.now()}.txt`,f.click(),URL.revokeObjectURL(c)},disabled:le.length===0,children:[e.jsx(
|
|
195
|
-
Internal Shell Environment.`,onCommand:async a=>{const c=await
|
|
187
|
+
// Assert with expect(element).toBeDisplayed()`:`// Strategy "${p}" not supported in WebdriverIO mobile`}function Vt(n){var U,w,j,T,F,b,k,y,R,M,_;const s=(n.type||"").toLowerCase(),l=((U=n.attributes)==null?void 0:U.clickable)==="true"||((w=n.attributes)==null?void 0:w.clickable)===!0,u=((j=n.attributes)==null?void 0:j.enabled)!=="false"&&((T=n.attributes)==null?void 0:T.enabled)!==!1,p=((F=n.attributes)==null?void 0:F.scrollable)==="true"||((b=n.attributes)==null?void 0:b.scrollable)===!0,t=n.text||n.label||n.value||"",L=((k=n.children)==null?void 0:k.length)||0;let v="Element",x="📦";s.includes("button")||s.includes("btn")||l&&L===0?(v="Button",x="🔘"):s.includes("edit")||s.includes("input")||s.includes("field")?(v="Text Input",x="✏️"):s.includes("image")||s.includes("img")||s.includes("imageview")?(v="Image",x="🖼️"):s.includes("scroll")||s.includes("recyclerview")||s.includes("listview")||p?(v="Scrollable List",x="📜"):s.includes("text")||s.includes("label")?(v="Text Label",x="📝"):s.includes("switch")||s.includes("toggle")||s.includes("checkbox")?(v="Toggle / Checkbox",x="☑️"):s.includes("nav")||s.includes("toolbar")||s.includes("tabbar")?(v="Navigation Bar",x="🧭"):L>0&&(v=`Container (${L} children)`,x="🗂️");const h=((y=n.suggestedLocators)==null?void 0:y.find(q=>q.strategy==="accessibility id"||q.strategy==="id"))||((R=n.suggestedLocators)==null?void 0:R[0]),m=u?((M=n.rect)==null?void 0:M.width)===0||((_=n.rect)==null?void 0:_.height)===0?"⚠️ Zero-size element — may not be interactable":void 0:"⚠️ Element is disabled",D=t?` with text "${t.slice(0,30)}"`:"",S=`This is a ${v.toLowerCase()}${D}. ${l?"It can be tapped/clicked.":p?"It supports scrolling.":"It is a visual container."}${L>0?` Contains ${L} child element${L>1?"s":""}.`:""}`;return{role:v,description:S,interactable:l||u,bestLocator:h,warning:m,emoji:x}}function xs(n,s){if(!s)return!0;const l=s.toLowerCase().trim(),u={button:["button","btn","clickable","tapable"],input:["edittext","input","field","textfield","textinput","edit"],image:["image","imageview","img","picture","photo","icon"],text:["textview","label","text","statictext"],list:["listview","recyclerview","scrollview","tableview","collectionview","scroll"],toggle:["switch","checkbox","toggle","radiobutton"],nav:["toolbar","navigationbar","tabbar","actionbar","navbar"]},p=(n.type||"").toLowerCase(),t=(n.text||n.label||n.value||"").toLowerCase(),L=(n.name||"").toLowerCase(),v=Object.values(n.attributes||{}).join(" ").toLowerCase();for(const[x,h]of Object.entries(u))if(l.includes(x)&&h.some(m=>p.includes(m)))return!0;return p.includes(l)||t.includes(l)||L.includes(l)||v.includes(l)}const qt=({sessionId:n,udid:s,streamUrl:l})=>{var Ae,ie,ae,ke,xe,De,Ue;const[u,p]=r.useState(!0),[t,L]=r.useState(null),[v,x]=r.useState(null),[h,m]=r.useState(null),[D,S]=r.useState(null),[U,w]=r.useState(new Set(["/"])),[j,T]=r.useState(""),[F,b]=r.useState(null),[k,y]=r.useState("info"),[R,M]=r.useState("java"),[_,q]=r.useState(null),[H,se]=r.useState({width:0,height:0}),[Ce,fe]=r.useState({width:0,height:0}),[Ge,d]=r.useState(!1),[Z,Te]=r.useState("inspect"),Se=r.useRef(null),ye=r.useRef(null),je=r.useRef(null),me=r.useRef(null),ue=r.useCallback(()=>{var z,K,J;if(!Se.current)return;const i=Se.current.getBoundingClientRect(),o=i.width,g=i.height,C=(z=t==null?void 0:t.hierarchy)==null?void 0:z.rect;let O=((K=t==null?void 0:t.metadata)==null?void 0:K.screenWidth)||H.width||1,P=((J=t==null?void 0:t.metadata)==null?void 0:J.screenHeight)||H.height||1;C&&C.width>0&&C.height>0&&(O=C.width,P=C.height);const B=O/P;let W,V;o/g>B?(V=g,W=V*B):(W=o,V=W/B),fe({width:W,height:V})},[t,H]);r.useEffect(()=>(ue(),window.addEventListener("resize",ue),()=>window.removeEventListener("resize",ue)),[ue]),r.useEffect(()=>{s&&ce()},[s]),r.useEffect(()=>{var i;if((i=h==null?void 0:h.suggestedLocators)!=null&&i.length){const o=h.suggestedLocators.find(g=>g.strategy==="accessibility id"||g.strategy==="id")||h.suggestedLocators[0];q(o)}else q(null)},[h]);const ce=async()=>{if(s){p(!0),x(null);try{const i=await A.getInspectorSnapshot(s);L(i);const o=new Set(["/"]),g=(C,O)=>{var P;O<2&&(o.add(C.xpath),(P=C.children)==null||P.forEach(B=>g(B,O+1)))};i.hierarchy&&g(i.hierarchy,0),w(o)}catch(i){x(i.message||"Failed to capture snapshot")}finally{p(!1)}}},ze=i=>{const{naturalWidth:o,naturalHeight:g}=i.currentTarget;se({width:o,height:g})},le=()=>d(!0),Ie=i=>{d(!1);const{naturalWidth:o,naturalHeight:g}=i.currentTarget;o>0&&g>0&&se({width:o,height:g})},Q=l&&!Ge,Ee=i=>{if(Z!=="interact"||!s)return;const o=i.currentTarget.getBoundingClientRect();me.current={x:i.clientX-o.left,y:i.clientY-o.top,time:Date.now()}},oe=async i=>{var de,Fe,Le;if(Z!=="interact"||!s||!me.current)return;const o=me.current,g=i.currentTarget.getBoundingClientRect(),C=i.clientX-g.left,O=i.clientY-g.top,P=Date.now()-o.time,B=Ce.width,W=Ce.height,V=(de=t==null?void 0:t.hierarchy)==null?void 0:de.rect;let z=((Fe=t==null?void 0:t.metadata)==null?void 0:Fe.screenWidth)||H.width,K=((Le=t==null?void 0:t.metadata)==null?void 0:Le.screenHeight)||H.height;if(V&&V.width>0&&V.height>0&&(z=V.width,K=V.height),!z||!K||B===0||W===0)return;const J=(a,c)=>({x:Math.round(a/B*z),y:Math.round(c/W*K),px:a/B,py:c/W}),Y=J(o.x,o.y),ge=J(C,O),te=Math.sqrt(Math.pow(C-o.x,2)+Math.pow(O-o.y,2));if(!(Y.px<0||Y.px>1||Y.py<0||Y.py>1)){try{P<500&&te<10?await A.tap(s,Y.x,Y.y):P>=500&&te<10?await A.touchAndHold(s,Y.x,Y.y,P):te>=10&&await A.swipe(s,Y.x,Y.y,ge.x,ge.y)}catch(a){console.error("Interaction failed:",a)}me.current=null}},Ye=i=>{const o=new Set(U);o.has(i)?o.delete(i):o.add(i),w(o)},$e=()=>{const i=new Set,o=g=>{var C;i.add(g.xpath),(C=g.children)==null||C.forEach(o)};t!=null&&t.hierarchy&&o(t.hierarchy),w(i)},be=()=>w(new Set(["/"])),Re=(i,o)=>{navigator.clipboard.writeText(i),b(o),setTimeout(()=>b(null),2e3)},pe=i=>{var g;let o=1;return(g=i.children)==null||g.forEach(C=>o+=pe(C)),o},Ne=i=>i.xpath.split("/").filter(Boolean).slice(-3),ee=(i,o=0)=>{var V;if(!i)return null;const g=U.has(i.xpath),C=((V=i.children)==null?void 0:V.length)>0,O=(h==null?void 0:h.xpath)===i.xpath,P=(D==null?void 0:D.xpath)===i.xpath,B=i.name||i.type.split(".").pop()||"Element",W=!j||xs(i,j);if(!W&&!C)return null;if(j&&!W){const z=K=>{var J;return xs(K,j)?!0:((J=K.children)==null?void 0:J.some(z))||!1};if(!z(i))return null}return e.jsxs("div",{className:"tree-node",children:[e.jsxs("div",{className:`tree-item ${O?"selected":""} ${P&&!O?"hovered":""}`,onClick:()=>{m(i),y("info")},onMouseEnter:()=>S(i),onMouseLeave:()=>S(null),children:[e.jsx("div",{className:"tree-item-indent",style:{width:`${o*14}px`}}),C?e.jsx("button",{onClick:z=>{z.stopPropagation(),Ye(i.xpath)},className:"tree-toggle",children:g?e.jsx(ys,{size:11}):e.jsx(bs,{size:11})}):e.jsx("span",{className:"tree-toggle-spacer"}),e.jsx(Ps,{size:11,className:"tree-icon"}),e.jsx("span",{className:"tree-label",children:B}),i.text&&e.jsxs("span",{className:"tree-text-preview",children:['"',i.text.slice(0,20),'"']}),C&&e.jsx("span",{className:"tree-badge",children:i.children.length})]}),g&&C&&e.jsx("div",{className:"tree-children",children:i.children.map(z=>ee(z,o+1))})]},i.xpath)},we=i=>{var B,W,V;if(!H.width)return[];const o=[],g=(B=t==null?void 0:t.hierarchy)==null?void 0:B.rect;let C=((W=t==null?void 0:t.metadata)==null?void 0:W.screenWidth)||H.width,O=((V=t==null?void 0:t.metadata)==null?void 0:V.screenHeight)||H.height;g&&g.width>0&&g.height>0&&(C=g.width,O=g.height);const P=(z,K)=>{var Y,ge,te;const J=!z.children||z.children.length===0;((Y=z.rect)==null?void 0:Y.width)>0&&((ge=z.rect)==null?void 0:ge.height)>0&&J&&o.push(e.jsx("div",{className:"omni-hit-area",style:{left:`${z.rect.x/C*100}%`,top:`${z.rect.y/O*100}%`,width:`${z.rect.width/C*100}%`,height:`${z.rect.height/O*100}%`,zIndex:K},onClick:de=>{de.stopPropagation(),m(z),y("info")},onMouseEnter:()=>S(z),onMouseLeave:()=>S(null)},z.xpath)),(te=z.children)==null||te.forEach(de=>P(de,K+1))};return t!=null&&t.hierarchy&&P(t.hierarchy,1),o},ve=(i,o)=>{var P,B,W;if(!(i!=null&&i.rect)||!H.width)return null;const g=(P=t==null?void 0:t.hierarchy)==null?void 0:P.rect;let C=((B=t==null?void 0:t.metadata)==null?void 0:B.screenWidth)||H.width,O=((W=t==null?void 0:t.metadata)==null?void 0:W.screenHeight)||H.height;return g&&g.width>0&&g.height>0&&(C=g.width,O=g.height),e.jsx("div",{className:`omni-frame-${o}`,style:{left:`${i.rect.x/C*100}%`,top:`${i.rect.y/O*100}%`,width:`${i.rect.width/C*100}%`,height:`${i.rect.height/O*100}%`}})},Me=t!=null&&t.hierarchy?pe(t.hierarchy):0,G=h?Vt(h):null,_e={stable:{icon:e.jsx(is,{size:10}),cls:"stable"},moderate:{icon:e.jsx(zs,{size:10}),cls:"moderate"},fragile:{icon:e.jsx(cs,{size:10}),cls:"fragile"},"very-fragile":{icon:e.jsx(cs,{size:10}),cls:"very-fragile"}};return e.jsx("div",{className:"omni-inspector-container",children:e.jsxs("div",{className:"omni-main-content",children:[e.jsxs("div",{className:"omni-screenshot-panel",children:[e.jsxs("div",{className:"omni-screenshot-header",children:[e.jsxs("div",{className:"omni-header-left",children:[e.jsx("span",{className:"omni-screenshot-title",children:"Device Preview"}),e.jsxs("div",{className:"omni-mode-toggle",children:[e.jsxs("button",{className:`omni-mode-btn ${Z==="inspect"?"active":""}`,onClick:()=>Te("inspect"),title:"Inspection Mode (Highlight Elements)",children:[e.jsx(_s,{size:12}),e.jsx("span",{children:"Inspect"})]}),e.jsxs("button",{className:`omni-mode-btn ${Z==="interact"?"active":""}`,onClick:()=>Te("interact"),title:"Interaction Mode (Direct Control)",children:[e.jsx(St,{size:12}),e.jsx("span",{children:"Interact"})]})]})]}),e.jsxs("button",{className:"omni-refresh-btn",onClick:ce,disabled:u,children:[e.jsx(Ve,{size:12,className:u?"animate-spin":""}),u?"Capturing...":"Refresh"]})]}),e.jsxs("div",{className:"omni-screenshot-container",ref:Se,children:[u&&!Q&&e.jsxs("div",{className:"omni-loading-overlay",children:[e.jsx("div",{className:"omni-spinner"}),e.jsx("span",{children:"Capturing screen..."})]}),!t&&!u&&!Q&&e.jsxs("div",{className:"omni-empty-state",children:[e.jsx(us,{size:40}),e.jsx("span",{children:"Click Refresh to capture"})]}),Q&&e.jsxs("div",{className:`omni-screenshot-wrapper ${Z==="interact"?"interactable":""}`,onMouseDown:Ee,onMouseUp:oe,children:[e.jsx("img",{ref:je,src:l,onLoad:Ie,onError:le,className:"omni-screenshot-img",style:Z==="interact"?{pointerEvents:"none"}:{},draggable:!1,alt:"Live Device Stream"}),(t==null?void 0:t.hierarchy)&&Z==="inspect"&&e.jsxs("div",{className:"omni-overlay",children:[we(t.hierarchy),ve(D,"hover"),ve(h,"select")]})]}),!Q&&(t==null?void 0:t.screenshot)&&e.jsxs("div",{className:`omni-screenshot-wrapper ${Z==="interact"?"interactable":""}`,onMouseDown:Ee,onMouseUp:oe,children:[e.jsx("img",{ref:ye,src:`data:image/png;base64,${t.screenshot}`,onLoad:ze,className:"omni-screenshot-img",style:Z==="interact"?{pointerEvents:"none"}:{},draggable:!1}),Z==="inspect"&&e.jsxs("div",{className:"omni-overlay",children:[we(t.hierarchy),ve(D,"hover"),ve(h,"select")]})]})]})]}),e.jsxs("div",{className:"omni-tree-panel",children:[e.jsxs("div",{className:"omni-tree-header",children:[e.jsxs("div",{className:"omni-tree-title",children:[e.jsx(it,{size:14}),e.jsx("span",{children:"Source"}),Me>0&&e.jsxs("span",{className:"omni-count-badge",children:[Me," elements"]})]}),e.jsxs("div",{className:"omni-tree-actions",children:[e.jsx("button",{onClick:$e,className:"omni-action-btn",title:"Expand All",children:e.jsx(Qs,{size:12})}),e.jsx("button",{onClick:be,className:"omni-action-btn",title:"Collapse All",children:e.jsx(gt,{size:12})})]})]}),e.jsxs("div",{className:"omni-tree-search",children:[e.jsx(Xe,{size:14}),e.jsx("input",{type:"text",placeholder:"Search elements... (try 'login button' or 'text field')",value:j,onChange:i=>T(i.target.value)}),j&&e.jsx("button",{onClick:()=>T(""),className:"omni-clear-btn",children:"×"})]}),j&&e.jsxs("div",{className:"omni-search-hint",children:[e.jsx(ms,{size:10}),' Smart search active — try "button", "input", "image"']}),e.jsx("div",{className:"omni-tree-content",children:t!=null&&t.hierarchy?ee(t.hierarchy):e.jsx("div",{className:"omni-empty-state small",children:e.jsx("span",{children:"No hierarchy loaded"})})})]}),e.jsxs("div",{className:"omni-details-panel",children:[e.jsxs("div",{className:"omni-details-tabs",children:[e.jsxs("button",{className:`omni-details-tab ${k==="info"?"active":""}`,onClick:()=>y("info"),children:[e.jsx(ct,{size:12})," Info"]}),e.jsxs("button",{className:`omni-details-tab ${k==="insight"?"active":""}`,onClick:()=>y("insight"),disabled:!h,title:"AI Element Analysis",children:[e.jsx(nt,{size:12})," AI Insight"]}),e.jsxs("button",{className:`omni-details-tab ${k==="code"?"active":""}`,onClick:()=>y("code"),disabled:!h,title:"Generate Test Code",children:[e.jsx(ds,{size:12})," Code Gen"]})]}),e.jsx("div",{className:"omni-details-content",children:h?e.jsxs(e.Fragment,{children:[k==="info"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"omni-section",children:[e.jsx("div",{className:"omni-section-header",children:"Element Info"}),e.jsxs("div",{className:"omni-info-table",children:[e.jsxs("div",{className:"omni-info-row",children:[e.jsx("span",{className:"omni-info-key",children:"Type"}),e.jsx("span",{className:"omni-info-value mono",children:h.type})]}),h.text&&e.jsxs("div",{className:"omni-info-row",children:[e.jsx("span",{className:"omni-info-key",children:"Text"}),e.jsx("span",{className:"omni-info-value",children:h.text})]}),e.jsxs("div",{className:"omni-info-row",children:[e.jsx("span",{className:"omni-info-key",children:"Path"}),e.jsx("span",{className:"omni-info-value mono small",children:Ne(h).join(" › ")})]})]})]}),e.jsxs("div",{className:"omni-section",children:[e.jsx("div",{className:"omni-section-header",children:"Layout"}),e.jsx("div",{className:"omni-layout-grid",children:["x","y","width","height"].map(i=>e.jsxs("div",{className:"omni-layout-item",children:[e.jsx("span",{className:"omni-layout-label",children:i.toUpperCase()}),e.jsx("span",{className:"omni-layout-value",children:h.rect[i]})]},i))})]}),e.jsxs("div",{className:"omni-section",children:[e.jsxs("div",{className:"omni-section-header",children:["Locators",e.jsx("span",{className:"omni-section-badge",children:"Stability Scored"})]}),e.jsx("div",{className:"omni-locators-list",children:(Ae=h.suggestedLocators)==null?void 0:Ae.map(i=>{const o=ps(i.strategy,i.value),g=_e[o.level];return e.jsxs("div",{className:`omni-locator-row ${(_==null?void 0:_.strategy)===i.strategy?"selected-for-code":""}`,onClick:()=>q(i),title:"Click to use in Code Generator",children:[e.jsxs("div",{className:"omni-locator-left",children:[e.jsxs("div",{className:"omni-locator-top",children:[e.jsx("span",{className:"omni-locator-strategy",children:i.strategy}),e.jsxs("span",{className:`omni-stability-badge ${g.cls}`,title:o.reason,children:[g.icon,o.level]})]}),e.jsx("code",{className:"omni-locator-value",children:i.value}),e.jsx("span",{className:"omni-stability-reason",children:o.reason})]}),e.jsx("button",{onClick:C=>{C.stopPropagation(),Re(i.value,i.strategy)},className:`omni-copy-btn ${F===i.strategy?"copied":""}`,children:F===i.strategy?e.jsx(Ze,{size:12}):e.jsx(Qe,{size:12})})]},i.strategy)})})]}),e.jsxs("div",{className:"omni-section",children:[e.jsx("div",{className:"omni-section-header",children:"Attributes"}),e.jsx("div",{className:"omni-attributes-table",children:Object.entries(h.attributes||{}).filter(([i,o])=>o!=null&&o!=="").map(([i,o])=>e.jsxs("div",{className:"omni-attr-row",children:[e.jsx("span",{className:"omni-attr-key",children:i}),e.jsx("span",{className:"omni-attr-value",children:String(o)})]},i))})]})]}),k==="insight"&&G&&e.jsxs("div",{className:"omni-insight-panel",children:[e.jsxs("div",{className:"omni-insight-role",children:[e.jsx("span",{className:"omni-insight-emoji",children:G.emoji}),e.jsxs("div",{children:[e.jsx("div",{className:"omni-insight-role-name",children:G.role}),e.jsx("div",{className:"omni-insight-interactable",children:G.interactable?e.jsxs("span",{className:"omni-badge-green",children:[e.jsx(Fs,{size:10})," Interactable"]}):e.jsx("span",{className:"omni-badge-gray",children:"Visual Only"})})]})]}),G.warning&&e.jsx("div",{className:"omni-insight-warning",children:G.warning}),e.jsxs("div",{className:"omni-insight-description",children:[e.jsx(ms,{size:12,className:"omni-insight-icon"}),e.jsx("p",{children:G.description})]}),G.bestLocator&&e.jsxs("div",{className:"omni-insight-best-locator",children:[e.jsx("div",{className:"omni-section-header",children:"Recommended Locator"}),e.jsxs("div",{className:"omni-locator-row",children:[e.jsxs("div",{className:"omni-locator-left",children:[e.jsx("span",{className:"omni-locator-strategy",children:G.bestLocator.strategy}),e.jsx("code",{className:"omni-locator-value",children:G.bestLocator.value})]}),e.jsx("button",{onClick:()=>Re(G.bestLocator.value,"best"),className:`omni-copy-btn ${F==="best"?"copied":""}`,children:F==="best"?e.jsx(Ze,{size:12}):e.jsx(Qe,{size:12})})]})]}),e.jsxs("div",{className:"omni-insight-attributes",children:[e.jsx("div",{className:"omni-section-header",children:"Quick Facts"}),e.jsx("div",{className:"omni-quick-facts",children:[{label:"Clickable",value:(ie=h.attributes)==null?void 0:ie.clickable},{label:"Enabled",value:(ae=h.attributes)==null?void 0:ae.enabled},{label:"Scrollable",value:(ke=h.attributes)==null?void 0:ke.scrollable},{label:"Focusable",value:(xe=h.attributes)==null?void 0:xe.focusable},{label:"Children",value:((De=h.children)==null?void 0:De.length)||0}].map(({label:i,value:o})=>e.jsxs("div",{className:"omni-quick-fact-row",children:[e.jsx("span",{className:"omni-quick-fact-label",children:i}),e.jsx("span",{className:`omni-quick-fact-value ${o==="true"||o===!0?"true":""}`,children:String(o??"—")})]},i))})]})]}),k==="code"&&e.jsxs("div",{className:"omni-codegen-panel",children:[e.jsx("div",{className:"omni-codegen-frameworks",children:["java","python","javascript","wdio"].map(i=>e.jsx("button",{className:`omni-fw-btn ${R===i?"active":""}`,onClick:()=>M(i),children:i==="java"?"☕ Java":i==="python"?"🐍 Python":i==="javascript"?"🟨 JS":"🔷 WD.io"},i))}),_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"omni-codegen-locator-selector",children:[e.jsx("span",{className:"omni-codegen-label",children:"Locator:"}),e.jsx("select",{value:_.strategy,onChange:i=>{var g;const o=(g=h.suggestedLocators)==null?void 0:g.find(C=>C.strategy===i.target.value);o&&q(o)},className:"omni-fw-select",children:(Ue=h.suggestedLocators)==null?void 0:Ue.map(i=>e.jsxs("option",{value:i.strategy,children:[i.strategy," — ",ps(i.strategy,i.value).level]},i.strategy))})]}),e.jsxs("div",{className:"omni-codegen-output",children:[e.jsxs("div",{className:"omni-codegen-header",children:[e.jsx("span",{className:"omni-codegen-lang",children:R==="java"?"Java / TestNG":R==="python"?"Python / unittest":R==="javascript"?"JavaScript / Mocha":"WebdriverIO"}),e.jsx("button",{className:"omni-copy-btn",onClick:()=>Re(vs(h,(t==null?void 0:t.platform)==="android"?"android":(t==null?void 0:t.platform)==="ios"?"ios":"unknown",R,_),"code"),children:F==="code"?e.jsx(Ze,{size:12}):e.jsx(Qe,{size:12})})]}),e.jsx("pre",{className:"omni-codegen-pre",children:e.jsx("code",{children:vs(h,(t==null?void 0:t.platform)==="android"?"android":(t==null?void 0:t.platform)==="ios"?"ios":"unknown",R,_)})})]})]}):e.jsxs("div",{className:"omni-empty-state small",children:[e.jsx(ds,{size:24}),e.jsx("span",{children:"No locators available for this element"})]})]})]}):e.jsxs("div",{className:"omni-empty-state",children:[e.jsx(us,{size:32}),e.jsx("span",{children:"Select an element from the tree or screenshot"})]})})]})]})})};function Xt({device:n,onClose:s}){var Le;const{toast:l,removeToast:u}=fs(),p=ns(),{tab:t}=js(),L=r.useRef(null),v=r.useRef(null),[x,h]=r.useState({width:0,height:0}),[m,D]=r.useState(t||"actions"),[S,U]=r.useState(""),[w,j]=r.useState(""),[T,F]=r.useState(""),[b,k]=r.useState(!0),[y,R]=r.useState([]),[M,_]=r.useState(null),[q,H]=r.useState(!1),[se,Ce]=r.useState(!1),[fe,Ge]=r.useState(0),[d,Z]=r.useState(n),[Te,Se]=r.useState([]),[ye,je]=r.useState(!1),[me,ue]=r.useState(!1),[ce,ze]=r.useState(null),[le,Ie]=r.useState([]),[Q,Ee]=r.useState(!0),[oe,Ye]=r.useState(""),[$e,be]=r.useState(!1),[Re,pe]=r.useState(0),Ne=r.useRef(""),ee=r.useRef(null),[we,ve]=r.useState(!1);r.useEffect(()=>{m&&(!t||t!==m)&&p(`/devices/${n.udid}/control/${m}`,{replace:!0})},[m,t,n.udid,p]),r.useEffect(()=>{let a;if(m==="logs"){be(!1),pe(0);const c=async()=>{try{const f=await A.getLogs(d.udid);if(pe(N=>N+1),f&&f.logs&&f.logs.trim().length>0){be(!0);const N=f.logs.replace(/\\u[0-9a-fA-F]{4}/g,$=>JSON.parse(`"${$}"`)).replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,"").split(`
|
|
188
|
+
`).filter($=>$.trim().length>0);N.length>0&&Ie($=>[...$,...N].slice(-1e3))}else pe(N=>(N>=3&&be(!0),N))}catch(f){console.error("Failed to fetch logs:",f),pe(N=>(N>=3&&be(!0),N))}};c(),a=setInterval(c,3e3)}return()=>clearInterval(a)},[m,d.udid]);const Me=()=>{if(le.length===0)return e.jsx("div",{className:"log-empty-state",children:$e?e.jsxs(e.Fragment,{children:[e.jsx(as,{size:28,style:{color:"var(--text-muted)",marginBottom:12,opacity:.4}}),e.jsx("p",{className:"log-empty-title",children:"No log output yet"}),e.jsx("p",{className:"log-empty-subtitle",children:"The log stream is active but the device is quiet. Interact with the device to generate logs."})]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{size:28,className:"animate-spin",style:{color:"var(--primary)",marginBottom:12}}),e.jsx("p",{className:"log-empty-title",children:"Connecting to device syslog..."}),e.jsxs("p",{className:"log-empty-subtitle",children:["Initializing persistent log stream for ",d.name]})]})});const a=le.filter(c=>!oe||c.toLowerCase().includes(oe.toLowerCase()));return a.length===0&&oe?e.jsxs("div",{className:"log-empty-state",children:[e.jsx(Xe,{size:28,style:{color:"var(--text-muted)",marginBottom:12,opacity:.4}}),e.jsxs("p",{className:"log-empty-title",children:['No matches for "',oe,'"']}),e.jsxs("p",{className:"log-empty-subtitle",children:[le.length," lines in buffer. Try a different search term."]})]}):a.map((c,f)=>{let N="log-debug";const $=c.toLowerCase();return $.includes("error")||$.includes("fail")?N="log-error":$.includes("warning")||$.includes("warn")?N="log-warn":($.includes("notice")||$.includes("info"))&&(N="log-notice"),e.jsxs("div",{className:`log-line ${N}`,children:[e.jsx("span",{className:"log-index",children:f+1}),e.jsx("span",{className:"log-content",children:c})]},`${f}-${c.substring(0,10)}`)})};r.useEffect(()=>{m==="logs"&&Q&&v.current&&(v.current.scrollTop=v.current.scrollHeight)},[le,m,Q]),r.useEffect(()=>((async()=>{try{Ce(!0),await A.startStream(d.udid);const f=(await A.getDevices()).find(N=>N.udid===d.udid);f&&Z(f)}catch(c){console.error("Auto-start stream failed:",c)}finally{Ce(!1)}})(),()=>{A.stopStream(d.udid).catch(()=>{})}),[n.udid]);const G=r.useCallback(async()=>{try{je(!0);const a=await A.listApps(d.udid);Array.isArray(a)&&Se(a)}catch(a){console.error("Failed to load apps:",a)}finally{je(!1)}},[d.udid]);r.useEffect(()=>{m==="actions"&&G()},[m,G]);const _e=parseInt(d.screenWidth||"1080",10),Ae=parseInt(d.screenHeight||"1920",10),ie=Math.min(_e,Ae),ae=Math.max(_e,Ae),ke=ie/ae,xe=r.useCallback(()=>{const a=!b,c=a?window.innerHeight*.55:window.innerHeight*.7,f=a?window.innerWidth*.8:window.innerWidth*.45,N=b?ke:1/ke;let $,I;b?($=c,I=$*N,I>f&&(I=f,$=I/N)):(I=f,$=I/N,$>c&&($=c,I=$*N)),h({width:I,height:$})},[ke,b]);r.useEffect(()=>(xe(),window.addEventListener("resize",xe),()=>window.removeEventListener("resize",xe)),[xe]),r.useEffect(()=>{const a=async()=>{if(Ne.current.length>0){const f=Ne.current;Ne.current="";try{await A.typeText(d.udid,f)}catch(N){console.error("Keyboard buffering flush failed:",N)}}},c=f=>{const N=document.activeElement;if(N&&(N.tagName==="INPUT"||N.tagName==="TEXTAREA"||N.isContentEditable)||!we&&m!=="terminal")return;const I=f.key;I==="Enter"?(ee.current&&clearTimeout(ee.current),a(),A.pressKey(d.udid,d.platform==="android"?66:"enter")):I==="Backspace"?(ee.current&&clearTimeout(ee.current),a(),A.pressKey(d.udid,d.platform==="android"?67:"backspace")):I.length===1&&(Ne.current+=I,ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{a()},50))};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c),ee.current&&clearTimeout(ee.current)}},[d.udid,d.platform,we,m]);const[De,Ue]=r.useState(Date.now()),i=()=>{const a=fe>0?`r=${fe}&`:"";return d.session_id&&!String(d.session_id).startsWith("manual_")?`/xenon/api/session/${d.session_id}/live_video?${a}t=${De}`:`/xenon/api/control/${d.udid}/stream?${a}t=${De}`};r.useEffect(()=>{fe>0&&Ue(Date.now())},[fe]);const o=r.useRef(null),g=a=>{const c=a.currentTarget.getBoundingClientRect();return{x:a.clientX-c.left,y:a.clientY-c.top}},C=a=>{const c=g(a);o.current={x:c.x,y:c.y,time:Date.now()}},O=async a=>{if(!o.current)return;const c=o.current,f=g(a),N=Date.now()-c.time;let $,I,ne,re;b?($=c.x/x.width*ie,I=c.y/x.height*ae,ne=f.x/x.width*ie,re=f.y/x.height*ae):($=c.x/x.width*ae,I=c.y/x.height*ie,ne=f.x/x.width*ae,re=f.y/x.height*ie);const he=Math.abs(ne-$),Oe=Math.abs(re-I);try{N<500&&he<10&&Oe<10?await A.tap(d.udid,Math.round($),Math.round(I)):N>=500&&he<10&&Oe<10?await A.touchAndHold(d.udid,Math.round($),Math.round(I),N):await A.swipe(d.udid,Math.round($),Math.round(I),Math.round(ne),Math.round(re))}catch(As){console.error("Action failed:",As)}o.current=null},P=()=>A.pressKey(d.udid,d.platform==="android"?3:"home"),B=()=>A.lock(d.udid),W=()=>A.unlock(d.udid),V=async()=>{S.trim()&&(await A.typeText(d.udid,S),U(""))},z=async()=>{try{j("Fetching...");const a=await A.getClipboard(d.udid);a&&a.content!==void 0?j(a.content||"(Clipboard is empty)"):j("No content received")}catch{j("Error: Check Appium Settings app")}},K=async()=>{H(!0);try{const a=await A.getScreenshot(d.udid);if(a!=null&&a.screenshot){const c={id:Bt(),base64:a.screenshot,timestamp:Date.now()};R(f=>[c,...f]),_(0)}}catch(a){console.error("Failed to take screenshot:",a)}finally{H(!1)}},J=a=>{R(c=>{const f=c.filter(N=>N.id!==a);return f.length===0?_(null):M!==null&&M>=f.length&&_(0),f})},Y=()=>{R([]),_(null),l("Cleared all captured evidence.","success")},ge=a=>{const c=document.createElement("a");c.href=`data:image/png;base64,${a}`,c.download=`screenshot-${d.udid}-${Date.now()}.png`,c.click()},te=async a=>{const c=ie/2,f=ae/2,N=ie*.4,$=ae*.4;let I,ne,re,he;switch(a){case"left":I=c+N,ne=f,re=c-N,he=f;break;case"right":I=c-N,ne=f,re=c+N,he=f;break;case"up":I=c,ne=f+$,re=c,he=f-$;break;case"down":I=c,ne=f-$,re=c,he=f+$;break}try{await A.swipe(d.udid,Math.round(I),Math.round(ne),Math.round(re),Math.round(he))}catch(Oe){console.error(`Quick swipe ${a} failed:`,Oe)}},de=async()=>{if(T.trim()){const a=l(`Uninstalling ${T}...`,"loading",0);try{je(!0),await A.uninstallApp(d.udid,T),F(""),l(`Request sent for ${T}`,"success"),setTimeout(G,3e3)}catch{l("Uninstall failed. Check logs.","error")}finally{je(!1),u(a)}}},Fe=async()=>{if(!ce)return;let a;try{ue(!0),a=l(`Installing app to ${d.udid}...`,"loading",0);const c=await A.uploadAndInstallApp(d.udid,ce);c.success?(l(c.message||"App installed successfully","success"),ze(null),setTimeout(G,5e3)):l("Installation failed: "+(c.error||"Unknown error"),"error")}catch(c){l("Installation failed: "+c.message,"error")}finally{a&&u(a),ue(!1)}};return e.jsxs("div",{className:"device-control-view",children:[e.jsx("div",{className:"scanline",style:{position:"absolute",inset:0,pointerEvents:"none",opacity:.05,zIndex:1001}}),e.jsxs("header",{className:"control-view-top-bar",children:[e.jsxs("button",{className:"back-to-devices-btn",onClick:s,children:[e.jsx(os,{size:18})," DEVICES"]}),e.jsxs("div",{className:"device-info-mini",children:[e.jsx("span",{className:`device-pill platform-pill ${d.platform}`,children:d.platform==="ios"?"Apple":"Android"}),e.jsxs("span",{className:"device-pill version-pill",children:["v",d.sdk]}),d.reservedUntil&&Date.now()<d.reservedUntil&&e.jsxs("span",{className:"device-pill reserved-pill",title:`Reserved by ${d.reservedBy}${d.reservationReason?`: ${d.reservationReason}`:""}`,children:["RESERVED BY ",((Le=d.reservedBy)==null?void 0:Le.toUpperCase())||"ANONYMOUS"]}),e.jsx("h2",{className:"device-name-text",children:d.name}),e.jsx("span",{className:"code-font",style:{opacity:.5},children:d.udid})]})]}),e.jsxs("div",{className:`control-view-main ${b?"":"is-landscape"} ${m==="omni"?"omni-mode":""}`,children:[e.jsxs("div",{className:"device-preview-column",children:[e.jsx("div",{className:"device-screen-wrapper",children:e.jsxs("div",{ref:L,className:`device-stream-canvas ${b?"":"landscape"} ${we?"focused":""}`,style:{width:x.width,height:x.height,background:"#000"},tabIndex:0,onFocus:()=>ve(!0),onBlur:()=>ve(!1),onMouseDown:C,onMouseUp:O,children:[se&&e.jsxs("div",{className:"device-stream-placeholder",style:{position:"absolute",zIndex:10},children:[e.jsx(Ve,{size:40,className:"animate-spin",color:"var(--primary)"}),e.jsx("p",{style:{marginTop:16},children:"ESTABLISHING TRACE..."})]}),e.jsx("img",{src:i(),alt:"Device Stream",className:"device-stream-image",style:{width:"100%",height:"100%",objectFit:"contain"},onError:()=>{console.warn("Stream failed to load, retrying..."),setTimeout(()=>Ge(a=>a+1),2e3)}})]})}),e.jsxs("aside",{className:"device-footer-actions",children:[e.jsxs("button",{className:`footer-action-btn ${b?"active":""}`,onClick:()=>k(!0),children:[e.jsx(Ve,{size:14,style:{transform:b?"none":"rotate(-90deg)"}})," ","PORTRAIT"]}),e.jsxs("button",{className:`footer-action-btn ${b?"":"active"}`,onClick:()=>k(!1),children:[e.jsx(Ve,{size:14,style:{transform:"rotate(90deg)"}})," LANDSCAPE"]}),e.jsx("div",{className:"footer-divider"}),e.jsxs("button",{className:"footer-action-btn",onClick:P,children:[e.jsx(st,{size:20})," HOME"]}),e.jsx("button",{className:"footer-action-btn",onClick:B,title:"Lock Device",children:e.jsx(Os,{size:20})}),e.jsx("button",{className:"footer-action-btn",onClick:W,title:"Unlock Device",children:e.jsx(Ss,{size:20})})]})]}),e.jsxs("div",{className:"device-interactions-column",children:[e.jsxs("div",{className:"interaction-tabs",children:[e.jsx("button",{className:`tab-btn ${m==="actions"?"active":""}`,onClick:()=>D("actions"),children:"ACTIONS"}),e.jsx("button",{className:`tab-btn ${m==="screenshot"?"active":""}`,onClick:()=>D("screenshot"),children:"SCREENSHOT"}),e.jsx("button",{className:`tab-btn ${m==="logs"?"active":""}`,onClick:()=>D("logs"),children:"DEBUG LOGS"}),e.jsxs("button",{className:`tab-btn ${m==="terminal"?"active":""}`,onClick:()=>D("terminal"),children:[e.jsx(as,{size:14,style:{marginRight:6}})," SHELL"]}),e.jsx("button",{className:`tab-btn ${m==="omni"?"active":""}`,onClick:()=>D("omni"),children:"OMNI-VISION"})]}),e.jsx("div",{className:`interactions-scroll-area ${m==="terminal"?"terminal-mode":""} ${m==="screenshot"||m==="logs"?"screenshot-mode":""}`,children:e.jsxs("div",{className:"tab-content",children:[m==="omni"&&e.jsx("div",{className:"omni-inspector-tab-wrapper animate-fade-in",style:{height:"calc(100vh - 266px)"},children:e.jsx(qt,{sessionId:d.session_id?String(d.session_id):null,udid:d.udid,streamUrl:i()})}),m==="actions"&&e.jsxs("div",{className:"actions-grid",children:[e.jsxs("div",{className:"action-card",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(ut,{size:18,color:"var(--primary)"})," Directional Gestures"]}),e.jsxs("div",{className:"gestures-grid-container",children:[e.jsxs("div",{className:"gestures-dpad",children:[e.jsx("div",{}),e.jsx("button",{className:"dpad-btn",onClick:()=>te("up"),children:e.jsx(qs,{size:24})}),e.jsx("div",{}),e.jsx("button",{className:"dpad-btn",onClick:()=>te("left"),children:e.jsx(os,{size:24})}),e.jsx("div",{className:"dpad-center"}),e.jsx("button",{className:"dpad-btn",onClick:()=>te("right"),children:e.jsx(bs,{size:24})}),e.jsx("div",{}),e.jsx("button",{className:"dpad-btn",onClick:()=>te("down"),children:e.jsx(ys,{size:24})}),e.jsx("div",{})]}),e.jsx("p",{className:"compact-label",style:{opacity:.5},children:"Directional Glide"})]})]}),e.jsxs("div",{className:"action-card",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(Js,{size:18,color:"var(--primary)"})," Smart Input"]}),e.jsx("input",{type:"text",className:"type-input-field compact",placeholder:"Relay keystrokes...",value:S,onChange:a=>U(a.target.value),onKeyDown:a=>a.key==="Enter"&&V()})]}),e.jsxs("div",{className:"action-card full-width",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(vt,{size:18,color:"var(--primary)"})," App Management"]}),e.jsxs("div",{className:"app-mgmt-content",children:[e.jsxs("div",{className:"install-section",children:[e.jsx("p",{className:"compact-label",children:"Install Package (.apk, .ipa, .app)"}),e.jsxs("div",{className:"upload-box-row",children:[e.jsxs("label",{className:"file-upload-launcher",children:[e.jsx(Rs,{size:14}),e.jsx("span",{children:ce?ce.name:"Select File"}),e.jsx("input",{type:"file",accept:".apk,.ipa,.app",onChange:a=>{var c;return ze(((c=a.target.files)==null?void 0:c[0])||null)},hidden:!0})]}),e.jsx("button",{className:"btn-premium btn-sm",disabled:!ce||me,onClick:Fe,children:me?e.jsx(He,{className:"animate-spin",size:14}):"INSTALL"})]})]}),e.jsx("div",{className:"divider-v"}),e.jsxs("div",{className:"uninstall-section",children:[e.jsx("p",{className:"compact-label",children:"Quick Uninstall"}),e.jsxs("div",{className:"uninstall-controls-row",children:[e.jsxs("div",{className:"select-wrapper",children:[e.jsxs("select",{className:"app-select-dropdown compact",value:T,onChange:a=>F(a.target.value),disabled:ye,children:[e.jsx("option",{value:"",children:ye?"Loading apps...":"-- Select App to Remove --"}),Te.map(a=>e.jsx("option",{value:a,children:a},a))]}),ye&&e.jsx(He,{className:"animate-spin select-loader",size:12})]}),e.jsxs("button",{className:"btn-destructive btn-sm",onClick:de,disabled:!T||ye,children:[e.jsx(Be,{size:14})," UNINSTALL"]})]}),e.jsxs("div",{className:"manual-input-box",children:[e.jsx("p",{className:"hint-text",children:"Or enter manually:"}),e.jsx("input",{type:"text",className:"type-input-field tiny",placeholder:"com.example.app",value:T,onChange:a=>F(a.target.value)})]})]})]})]}),e.jsxs("div",{className:"action-card full-width",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(Gs,{size:18,color:"var(--primary)"})," Clipboard"]}),e.jsxs("div",{style:{display:"flex",gap:"12px",alignItems:"flex-start"},children:[e.jsx("button",{className:"btn-premium btn-sm",style:{width:"140px",flexShrink:0},onClick:z,children:"FETCH VALUE"}),e.jsx("div",{className:"clipboard-display compact",style:{marginTop:0,flex:1},children:w})]})]})]}),m==="screenshot"&&e.jsxs("div",{className:"action-card screenshot-card",children:[e.jsxs("header",{className:"action-card-header",children:[e.jsxs("div",{className:"title-group",children:[e.jsxs("h4",{className:"action-card-title",children:[e.jsx(Ke,{size:20,color:"var(--primary)"})," Captured Evidence"]}),e.jsx("p",{className:"hint-text",children:"Relay screenshots from device to host."})]}),y.length>0&&e.jsx("button",{className:"btn-text-only",onClick:Y,children:"CLEAR ALL"})]}),e.jsxs("div",{className:"screenshot-workspace",children:[e.jsxs("div",{className:"screenshot-gallery-sidebar",children:[e.jsxs("button",{className:"btn-premium take-screenshot-btn",onClick:K,disabled:q,children:[q?e.jsx(He,{className:"animate-spin",size:16}):e.jsx(Ke,{size:16}),e.jsx("span",{children:q?"CAPTURING...":"NEW CAPTURE"})]}),e.jsxs("div",{className:"screenshot-thumbnails-list",children:[y.length===0&&!q&&e.jsx("div",{className:"empty-gallery-state",children:e.jsx("p",{children:"No captures yet"})}),y.map((a,c)=>e.jsxs("div",{className:`screenshot-thumb-item ${M===c?"active":""}`,onClick:()=>_(c),children:[e.jsx("img",{src:`data:image/png;base64,${a.base64}`,alt:"Thumb"}),e.jsx("span",{className:"thumb-time",children:new Date(a.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}),e.jsx("button",{className:"thumb-delete-btn",onClick:f=>{f.stopPropagation(),J(a.id)},children:e.jsx(Be,{size:12})})]},a.id))]})]}),e.jsx("div",{className:"screenshot-main-preview",children:M!==null&&y[M]?e.jsxs("div",{className:"preview-container",children:[e.jsx("div",{className:"preview-image-wrapper",children:e.jsx("img",{src:`data:image/png;base64,${y[M].base64}`,alt:"Selected Evidence"})}),e.jsxs("footer",{className:"preview-footer",children:[e.jsxs("div",{className:"preview-meta",children:[e.jsx("span",{className:"meta-label",children:"ID:"}),e.jsx("span",{className:"meta-value",children:y[M].id.substring(0,8)}),e.jsx("span",{className:"meta-divider",children:"|"}),e.jsx("span",{className:"meta-value",children:new Date(y[M].timestamp).toLocaleString()})]}),e.jsxs("div",{className:"preview-actions",children:[e.jsx("button",{className:"btn-premium btn-sm",onClick:()=>ge(y[M].base64),children:"DOWNLOAD PNG"}),e.jsxs("button",{className:"btn-destructive btn-sm",onClick:()=>J(y[M].id),children:[e.jsx(Be,{size:14})," DELETE"]})]})]})]}):e.jsxs("div",{className:"preview-empty-placeholder",children:[e.jsx(Ke,{size:48,style:{opacity:.1,marginBottom:16}}),e.jsx("p",{children:"Capture a screenshot to begin analysis"})]})})]})]}),m==="logs"&&e.jsxs("div",{className:"action-card screenshot-card",style:{padding:0,gap:0},children:[e.jsxs("div",{className:"log-toolbar",children:[e.jsxs("div",{className:"log-filter-group",children:[e.jsxs("div",{className:"log-stat-pill",children:[e.jsx("span",{className:`log-live-dot ${$e?"active":""}`}),$e?"LIVE":"CONNECTING"]}),e.jsxs("div",{className:"log-stat-pill",style:{opacity:.6},children:[le.length," LINES"]}),e.jsxs("div",{className:"log-search-box",children:[e.jsx(Xe,{size:14,className:"search-icon-inline"}),e.jsx("input",{type:"text",className:"type-input-field tiny",placeholder:"Filter trace...",value:oe,onChange:a=>Ye(a.target.value)})]})]}),e.jsxs("div",{className:"log-actions-group",children:[e.jsxs("button",{className:`btn-secondary btn-sm ${Q?"active":""}`,onClick:()=>Ee(!Q),title:Q?"Freeze Logs":"Follow Logs",children:[e.jsx($s,{size:14,className:Q?"animate-pulse":""}),Q?"FREEZE":"FOLLOW"]}),e.jsxs("button",{className:"btn-premium btn-sm",onClick:()=>{const a=new Blob([le.join(`
|
|
189
|
+
`)],{type:"text/plain"}),c=URL.createObjectURL(a),f=document.createElement("a");f.href=c,f.download=`logs-${d.udid}-${Date.now()}.txt`,f.click(),URL.revokeObjectURL(c)},disabled:le.length===0,children:[e.jsx(Us,{size:14}),"EXPORT"]}),e.jsxs("button",{className:"btn-secondary btn-sm",onClick:()=>Ie([]),title:"Clear Logs",children:[e.jsx(Be,{size:14}),"CLEAR"]})]})]}),e.jsx("div",{className:"log-display-area",ref:v,style:{flex:1},children:Me()})]}),m==="terminal"&&e.jsx("div",{className:"action-card full-height",children:e.jsx(Wt,{platform:(d.platform||"").toLowerCase(),prompt:`${(d.platform||"").toLowerCase()==="ios"?"ios":"adb"} $`,welcomeMessage:`Connected to ${d.name} (${d.udid}).
|
|
190
|
+
Internal Shell Environment.`,onCommand:async a=>{const c=await A.executeShell(d.udid,a);if(c.error)throw new Error(c.error);return c.output}})})]})})]})]})]})}const gs={platform:{ios:!0,android:!0},state:{ready:!0,offline:!0,busy:!0},name:""};class Gt extends qe.Component{constructor(s){super(s),this.socketCleanups=[],this.refreshTimeout=null,this.state={devices:[],activeSessionsCount:0,pendingSessionsCount:0,queueSummary:null,filter:gs}}componentDidMount(){this.fetchDevices(),this.devicePolling=setInterval(()=>{this.fetchDevices()},1e4);const s=this.props.onSocketEvent("device_unblocked",()=>{console.info("Real-time: Device unblocked, triggering debounced refresh"),this.fetchDevicesDebounced()}),l=this.props.onSocketEvent("device_blocked",()=>{console.info("Real-time: Device blocked, triggering debounced refresh"),this.fetchDevicesDebounced()});this.socketCleanups.push(s,l)}componentWillUnmount(){this.devicePolling&&(clearInterval(this.devicePolling),this.devicePolling=void 0),this.refreshTimeout&&(clearTimeout(this.refreshTimeout),this.refreshTimeout=null),this.socketCleanups.forEach(s=>s())}fetchDevicesDebounced(){this.refreshTimeout&&clearTimeout(this.refreshTimeout),this.refreshTimeout=setTimeout(()=>{this.refreshTimeout=null,this.fetchDevices()},500)}getBusyDevicesCount(s){return[u=>u.busy].reduce((u,p)=>u.filter(p),s).length}async fetchDevices(){try{const s=await A.getDevices(),l=this.getBusyDevicesCount(s),u=await A.getPendingSessionsCount(),p=await A.getQueueSummary();console.log(s),this.setState({devices:s,activeSessionsCount:l,pendingSessionsCount:u,queueSummary:p})}catch(s){console.log(s)}}getFilteredDevice(){const{ready:s,busy:l,offline:u}=this.state.filter.state,{ios:p,android:t}=this.state.filter.platform,L=[v=>p&&(v.platform=="ios"||v.platform=="tvos")||t&&v.platform=="android",v=>s&&!v.busy&&!v.offline||l&&v.busy||u&&v.offline];return this.state.filter.name!=""&&L.push(v=>v.name.toLowerCase().includes(this.state.filter.name.toLowerCase())||v.udid.toLowerCase().includes(this.state.filter.name.toLowerCase())),L.reduce((v,x)=>v.filter(x),this.state.devices)}setFilter(s){this.setState({filter:{...this.state.filter,...s}})}getPlatformFilterComponent(){const{ios:s,android:l}=this.state.filter.platform;return e.jsxs("div",{className:"device-explorer-header-value",children:[e.jsxs("button",{className:`device-explorer-header__platform-btn ${l&&"selected"}`,onClick:()=>this.setFilter({platform:{...this.state.filter.platform,android:!this.state.filter.platform.android}}),children:[e.jsx(ts,{size:20,color:"currentColor"}),"Android"]}),e.jsxs("button",{className:`device-explorer-header__platform-btn ${s&&"selected"}`,onClick:()=>this.setFilter({platform:{...this.state.filter.platform,ios:!this.state.filter.platform.ios}}),children:[e.jsx(ks,{size:20,color:"currentColor"}),"iOS"]})]})}getDeviceStateFilterComponent(){const{ready:s,busy:l,offline:u}=this.state.filter.state;return e.jsxs("div",{className:"device-explorer-header-value",children:[e.jsx("div",{className:`device-explorer-header__device-state ready ${s&&"selected"}`,onClick:()=>this.setFilter({state:{...this.state.filter.state,ready:!this.state.filter.state.ready}}),children:"Ready"}),e.jsx("div",{className:`device-explorer-header__device-state busy ${l&&"selected"}`,onClick:()=>this.setFilter({state:{...this.state.filter.state,busy:!this.state.filter.state.busy}}),children:"Busy"}),e.jsx("div",{className:`device-explorer-header__device-state offline ${u&&"selected"}`,onClick:()=>this.setFilter({state:{...this.state.filter.state,offline:!this.state.filter.state.offline}}),children:"Offline"})]})}render(){const s=this.getFilteredDevice(),{udid:l}=this.props.params,u=l?this.state.devices.find(p=>p.udid===l):null;return e.jsxs("div",{className:"device-explorer-container",children:[e.jsxs("div",{className:"device-explorer-header-container",children:[e.jsxs("div",{className:"device-explorer-header-left-container",children:[e.jsxs("div",{className:"device-explorer-header-entry",children:[e.jsx("div",{className:"device-explorer-header-entry-header",children:"Platform"}),this.getPlatformFilterComponent()]}),e.jsxs("div",{className:"device-explorer-header-entry",children:[e.jsx("div",{className:"device-explorer-header-entry-header",children:"Device state"}),this.getDeviceStateFilterComponent()]}),e.jsxs("div",{className:"device-explorer-header-entry search-entry",children:[e.jsx("div",{className:"device-explorer-header-entry-header",children:"Search by name or udid"}),e.jsx("div",{className:"device-explorer-header-value",children:e.jsxs("div",{className:"device-explorer-search-wrapper",children:[e.jsx(Xe,{size:16,color:"#94a3b8",className:"device-explorer-search-icon"}),e.jsx("input",{type:"text",className:"device-explorer-header-text-filter",placeholder:"Search devices...",onChange:p=>{this.setState({filter:{...this.state.filter,name:p.target.value}})}})]})})]})]}),e.jsx("div",{className:"device-explorer-header-filter-count",children:e.jsxs(Pe,{variant:"secondary",children:[e.jsx("span",{className:"font-bold",children:s.length})," of"," ",e.jsx("span",{className:"font-bold",children:this.state.devices.length})," ",this.state.devices.length===1?"device":"devices"]})}),e.jsxs("div",{className:"device-explorer-header-right-container",children:[this.state.queueSummary&&this.state.pendingSessionsCount>0&&e.jsxs(Pe,{variant:"secondary",className:"mr-2",children:[e.jsx("span",{className:"font-bold",children:"Queue Insights:"})," ",Object.entries(this.state.queueSummary.byPlatform).map(([p,t])=>e.jsxs("span",{className:"ml-1",children:[p==="any"?"Mixed":p.toUpperCase(),":"," ",Math.ceil(t.avgDurationMs/6e4),"m ETA"]},p))]}),e.jsxs(Pe,{variant:"success",children:[e.jsx("span",{className:"font-bold",children:this.state.activeSessionsCount})," Active session",this.state.activeSessionsCount!==1?"s":""]}),e.jsxs(Pe,{variant:"warning",children:[e.jsx("span",{className:"font-bold",children:this.state.pendingSessionsCount})," Pending session",this.state.pendingSessionsCount!==1?"s":""]}),e.jsxs(Je,{size:"sm",variant:"default",onClick:()=>this.fetchDevices(),children:[e.jsx(rs,{size:14,color:"currentColor",className:"mr-1"}),"Refresh"]})]})]}),s.length>0?e.jsx(_t,{devices:s,reloadDevices:()=>this.fetchDevices()}):e.jsxs("div",{className:"device-explorer-empty stagger-1",children:[e.jsx("div",{className:"device-explorer-empty-icon",children:e.jsx(ts,{size:32})}),this.state.devices.length===0?e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"brand-font",children:"Global Device Registry Empty"}),e.jsx("p",{children:"Xenon hasn't detected any active device nodes in your infrastructure. Ensure your device farm is connected and heartbeat signals are active."}),e.jsxs(Je,{variant:"default",onClick:()=>this.fetchDevices(),children:[e.jsx(rs,{size:14,className:"mr-2"}),"Manual Sync"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"brand-font",children:"No Devices Found"}),e.jsx("p",{children:"Deployment configuration mismatch. Adjust your platform or state filters to find the appropriate testing target."}),e.jsx(Je,{variant:"outline",onClick:()=>this.setState({filter:gs}),children:"Reset All Filters"})]})]}),u&&e.jsx("div",{className:"device-control-modal-overlay",children:e.jsx("div",{className:"device-control-modal",children:e.jsx(Xt,{device:u,onClose:()=>this.props.navigate("/devices")})})})]})}}function oi(){const n=js(),s=ns(),{on:l}=Es();return e.jsx(Gt,{params:n,navigate:s,onSocketEvent:l})}export{Gt as DeviceExplorer,oi as default};
|