autoglm-gui 1.4.1__py3-none-any.whl → 1.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. AutoGLM_GUI/__init__.py +11 -0
  2. AutoGLM_GUI/__main__.py +26 -4
  3. AutoGLM_GUI/actions/__init__.py +6 -0
  4. AutoGLM_GUI/actions/handler.py +196 -0
  5. AutoGLM_GUI/actions/types.py +15 -0
  6. AutoGLM_GUI/adb/__init__.py +53 -0
  7. AutoGLM_GUI/adb/apps.py +227 -0
  8. AutoGLM_GUI/adb/connection.py +323 -0
  9. AutoGLM_GUI/adb/device.py +171 -0
  10. AutoGLM_GUI/adb/input.py +67 -0
  11. AutoGLM_GUI/adb/screenshot.py +11 -0
  12. AutoGLM_GUI/adb/timing.py +167 -0
  13. AutoGLM_GUI/adb_plus/keyboard_installer.py +4 -2
  14. AutoGLM_GUI/adb_plus/screenshot.py +22 -1
  15. AutoGLM_GUI/adb_plus/serial.py +38 -20
  16. AutoGLM_GUI/adb_plus/touch.py +4 -9
  17. AutoGLM_GUI/agents/__init__.py +43 -12
  18. AutoGLM_GUI/agents/events.py +19 -0
  19. AutoGLM_GUI/agents/factory.py +31 -38
  20. AutoGLM_GUI/agents/glm/__init__.py +7 -0
  21. AutoGLM_GUI/agents/glm/agent.py +292 -0
  22. AutoGLM_GUI/agents/glm/message_builder.py +81 -0
  23. AutoGLM_GUI/agents/glm/parser.py +110 -0
  24. AutoGLM_GUI/agents/glm/prompts_en.py +77 -0
  25. AutoGLM_GUI/agents/glm/prompts_zh.py +75 -0
  26. AutoGLM_GUI/agents/mai/__init__.py +28 -0
  27. AutoGLM_GUI/agents/mai/agent.py +405 -0
  28. AutoGLM_GUI/agents/mai/parser.py +254 -0
  29. AutoGLM_GUI/agents/mai/prompts.py +103 -0
  30. AutoGLM_GUI/agents/mai/traj_memory.py +91 -0
  31. AutoGLM_GUI/agents/protocols.py +12 -8
  32. AutoGLM_GUI/agents/stream_runner.py +188 -0
  33. AutoGLM_GUI/api/__init__.py +40 -21
  34. AutoGLM_GUI/api/agents.py +157 -240
  35. AutoGLM_GUI/api/control.py +9 -6
  36. AutoGLM_GUI/api/devices.py +102 -12
  37. AutoGLM_GUI/api/history.py +78 -0
  38. AutoGLM_GUI/api/layered_agent.py +67 -15
  39. AutoGLM_GUI/api/media.py +64 -1
  40. AutoGLM_GUI/api/scheduled_tasks.py +98 -0
  41. AutoGLM_GUI/config.py +81 -0
  42. AutoGLM_GUI/config_manager.py +68 -51
  43. AutoGLM_GUI/device_manager.py +248 -29
  44. AutoGLM_GUI/device_protocol.py +1 -1
  45. AutoGLM_GUI/devices/adb_device.py +5 -10
  46. AutoGLM_GUI/devices/mock_device.py +4 -2
  47. AutoGLM_GUI/devices/remote_device.py +8 -3
  48. AutoGLM_GUI/history_manager.py +164 -0
  49. AutoGLM_GUI/i18n.py +81 -0
  50. AutoGLM_GUI/model/__init__.py +5 -0
  51. AutoGLM_GUI/model/message_builder.py +69 -0
  52. AutoGLM_GUI/model/types.py +24 -0
  53. AutoGLM_GUI/models/__init__.py +10 -0
  54. AutoGLM_GUI/models/history.py +96 -0
  55. AutoGLM_GUI/models/scheduled_task.py +71 -0
  56. AutoGLM_GUI/parsers/__init__.py +22 -0
  57. AutoGLM_GUI/parsers/base.py +50 -0
  58. AutoGLM_GUI/parsers/phone_parser.py +58 -0
  59. AutoGLM_GUI/phone_agent_manager.py +62 -396
  60. AutoGLM_GUI/platform_utils.py +26 -0
  61. AutoGLM_GUI/prompt_config.py +15 -0
  62. AutoGLM_GUI/prompts/__init__.py +32 -0
  63. AutoGLM_GUI/scheduler_manager.py +304 -0
  64. AutoGLM_GUI/schemas.py +234 -72
  65. AutoGLM_GUI/scrcpy_stream.py +142 -24
  66. AutoGLM_GUI/socketio_server.py +100 -27
  67. AutoGLM_GUI/static/assets/{about-_XNhzQZX.js → about-BQm96DAl.js} +1 -1
  68. AutoGLM_GUI/static/assets/alert-dialog-B42XxGPR.js +1 -0
  69. AutoGLM_GUI/static/assets/chat-C0L2gQYG.js +129 -0
  70. AutoGLM_GUI/static/assets/circle-alert-D4rSJh37.js +1 -0
  71. AutoGLM_GUI/static/assets/dialog-DZ78cEcj.js +45 -0
  72. AutoGLM_GUI/static/assets/history-DFBv7TGc.js +1 -0
  73. AutoGLM_GUI/static/assets/index-Bzyv2yQ2.css +1 -0
  74. AutoGLM_GUI/static/assets/{index-Cy8TmmHV.js → index-CmZSnDqc.js} +1 -1
  75. AutoGLM_GUI/static/assets/index-CssG-3TH.js +11 -0
  76. AutoGLM_GUI/static/assets/label-BCUzE_nm.js +1 -0
  77. AutoGLM_GUI/static/assets/logs-eoFxn5of.js +1 -0
  78. AutoGLM_GUI/static/assets/popover-DLsuV5Sx.js +1 -0
  79. AutoGLM_GUI/static/assets/scheduled-tasks-MyqGJvy_.js +1 -0
  80. AutoGLM_GUI/static/assets/square-pen-zGWYrdfj.js +1 -0
  81. AutoGLM_GUI/static/assets/textarea-BX6y7uM5.js +1 -0
  82. AutoGLM_GUI/static/assets/workflows-CYFs6ssC.js +1 -0
  83. AutoGLM_GUI/static/index.html +2 -2
  84. AutoGLM_GUI/types.py +17 -0
  85. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/METADATA +137 -130
  86. autoglm_gui-1.5.0.dist-info/RECORD +157 -0
  87. AutoGLM_GUI/agents/mai_adapter.py +0 -627
  88. AutoGLM_GUI/api/dual_model.py +0 -317
  89. AutoGLM_GUI/dual_model/__init__.py +0 -53
  90. AutoGLM_GUI/dual_model/decision_model.py +0 -664
  91. AutoGLM_GUI/dual_model/dual_agent.py +0 -917
  92. AutoGLM_GUI/dual_model/protocols.py +0 -354
  93. AutoGLM_GUI/dual_model/vision_model.py +0 -442
  94. AutoGLM_GUI/mai_ui_adapter/agent_wrapper.py +0 -291
  95. AutoGLM_GUI/phone_agent_patches.py +0 -147
  96. AutoGLM_GUI/static/assets/chat-DwJpiAWf.js +0 -126
  97. AutoGLM_GUI/static/assets/dialog-B3uW4T8V.js +0 -45
  98. AutoGLM_GUI/static/assets/index-Cpv2gSF1.css +0 -1
  99. AutoGLM_GUI/static/assets/index-UYYauTly.js +0 -12
  100. AutoGLM_GUI/static/assets/workflows-Du_de-dt.js +0 -1
  101. autoglm_gui-1.4.1.dist-info/RECORD +0 -117
  102. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/WHEEL +0 -0
  103. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/entry_points.txt +0 -0
  104. {autoglm_gui-1.4.1.dist-info → autoglm_gui-1.5.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,126 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-UYYauTly.js","assets/index-Cpv2gSF1.css"])))=>i.map(i=>d[i]);
2
- import{c as Oe,j as o,u as Dr,r as v,T as Un,e as Wn,f as zn,g as Cn,B as ve,h as ms,R as We,i as bn,k as oa,m as Ea,P as Zt,n as dt,o as Sa,p as Zn,q as gr,s as nr,t as ai,v as H_,w as G_,x as $_,y as q_,z as X_,S as ns,A as du,C as Y_,D as Na,E as V_,F as fu,G as hu,H as K_,M as Gu,I as $u,J as Q_,K as qu,L as J_,N as Z_,O as ev,Q as tv,U as nv,V as rv,W as mi,X as sv,Y as iv,Z as ov,_ as av,$ as lv,a0 as cv,a1 as uv,a2 as Xu,l as Yu,a3 as dv,a4 as fv,a5 as hv,a6 as pv,a7 as mv,a8 as gv,a9 as xv,aa as _v}from"./index-UYYauTly.js";import{L as hn,P as vv,D as Vu,d as Ku,e as Qu,f as Ju,j as Zu,g as Nt,I as $t,i as ed,C as er,k as bv,R as yv,u as wv,F as Ev,T as Sv,h as td}from"./dialog-B3uW4T8V.js";const Nv=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],nd=Oe("arrow-up-down",Nv);const Cv=[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]],gi=Oe("brain",Cv);const kv=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],aa=Oe("chevron-down",kv);const Tv=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Ca=Oe("chevron-left",Tv);const Rv=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ka=Oe("chevron-right",Rv);const Av=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],la=Oe("chevron-up",Av);const jv=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],Nn=Oe("circle-alert",jv);const Pv=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Mv=Oe("circle-check-big",Pv);const Iv=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Hn=Oe("circle-check",Iv);const Dv=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],ca=Oe("circle-x",Dv);const Lv=[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]],Ov=Oe("cpu",Lv);const Fv=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],pu=Oe("external-link",Fv);const Bv=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],mu=Oe("eye-off",Bv);const Uv=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],us=Oe("eye",Uv);const Wv=[["path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4",key:"1nerag"}],["path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88",key:"o46ks0"}],["path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02",key:"ptglia"}],["path",{d:"M2 12a10 10 0 0 1 18-6",key:"ydlgp0"}],["path",{d:"M2 16h.01",key:"1gqxmh"}],["path",{d:"M21.8 16c.2-2 .131-5.354 0-6",key:"drycrb"}],["path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2",key:"1tidbn"}],["path",{d:"M8.65 22c.21-.66.45-1.32.57-2",key:"13wd9y"}],["path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2",key:"1fr1j5"}]],rd=Oe("fingerprint-pattern",Wv);const zv=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],xi=Oe("history",zv);const Hv=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],_i=Oe("image",Hv);const Gv=[["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"}]],ua=Oe("layers",Gv);const $v=[["path",{d:"M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z",key:"vbtd3f"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",key:"x3v2xh"}]],sd=Oe("monitor-play",$v);const qv=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],Xv=Oe("plug",qv);const Yv=[["path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z",key:"m3kijz"}],["path",{d:"m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z",key:"1fmvmk"}],["path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0",key:"1f8sc4"}],["path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5",key:"qeys4"}]],Vv=Oe("rocket",Yv);const Kv=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],id=Oe("rotate-ccw",Kv);const Qv=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],od=Oe("send",Qv);const Jv=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],gu=Oe("server",Jv);const Zv=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],ad=Oe("settings",Zv);const e1=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],da=Oe("smartphone",e1);const t1=[["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"}]],as=Oe("sparkles",t1);const n1=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],ld=Oe("square",n1);const r1=[["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"}]],cd=Oe("target",r1);const s1=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],ud=Oe("video",s1);const i1=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],xu=Oe("wifi-off",i1);const o1=[["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"}]],fa=Oe("wifi",o1);const a1=[["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"}]],l1=Oe("wrench",a1);const c1=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],ha=Oe("zap",c1);function _u({isOpen:s,title:n,content:r,onConfirm:a,onCancel:u,confirmText:l="确认",cancelText:p="取消"}){return s?o.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm animate-in fade-in duration-200",children:o.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-xl max-w-md w-full overflow-hidden transform transition-all animate-in zoom-in-95 duration-200",onClick:b=>b.stopPropagation(),children:[o.jsxs("div",{className:"p-6",children:[o.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2",children:n}),o.jsx("p",{className:"text-gray-500 dark:text-gray-400 text-sm leading-relaxed whitespace-pre-wrap",children:r})]}),o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-700/50 px-6 py-4 flex justify-end gap-3",children:[o.jsx("button",{onClick:b=>{b.stopPropagation(),u()},className:"px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 transition-colors",children:p}),o.jsx("button",{onClick:b=>{b.stopPropagation(),a()},className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors",children:l})]})]})}):null}function u1({id:s,serial:n,model:r,status:a,connectionType:u,agent:l,isActive:p,onClick:b,onConnectWifi:f,onDisconnectWifi:g}){const h=Dr(),_=a==="device",y=u==="usb",S=u==="remote",[N,j]=v.useState(!1),[R,M]=v.useState(!1),[F,A]=v.useState(!1),G=r||h.deviceCard.unknownDevice,q=()=>{if(!_||!l)return"status-agent-none";switch(l.state){case"idle":return"status-agent-idle";case"busy":return"status-agent-busy";case"error":return"status-agent-error";case"initializing":return"status-agent-initializing";default:return"status-agent-none"}},X=()=>{if(!_||!l)return h.deviceCard.statusTooltip.none;switch(l.state){case"idle":return h.deviceCard.statusTooltip.idle;case"busy":return h.deviceCard.statusTooltip.busy;case"error":return h.deviceCard.statusTooltip.error;case"initializing":return h.deviceCard.statusTooltip.initializing;default:return h.deviceCard.statusTooltip.none}},K=D=>{D.stopPropagation(),!(N||!f)&&M(!0)},V=D=>{D.stopPropagation(),!(N||!g)&&A(!0)},U=async()=>{M(!1),j(!0);try{f&&await f()}finally{j(!1)}},I=async()=>{A(!1),j(!0);try{g&&await g()}finally{j(!1)}};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{onClick:b,role:"button",tabIndex:0,onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&b()},className:`
3
- group relative w-full text-left p-4 rounded-xl transition-all duration-200 cursor-pointer
4
- border-2
5
- ${p?"bg-slate-50 border-[#1d9bf0] dark:bg-slate-800/50 dark:border-[#1d9bf0]":"bg-white border-transparent hover:border-slate-200 dark:bg-slate-900 dark:hover:border-slate-700"}
6
- `,children:[p&&o.jsx("div",{className:"absolute left-0 top-2 bottom-2 w-1 bg-[#1d9bf0] rounded-r"}),o.jsxs("div",{className:"flex items-center gap-3 pl-2",children:[o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsx("div",{className:`relative flex-shrink-0 ${q()} w-3 h-3 rounded-full transition-all cursor-help ${p?"scale-110":""}`})}),o.jsx(zn,{side:"right",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1.5",children:[o.jsxs("p",{className:"font-medium",children:[h.deviceCard.statusTooltip.title,X()]}),o.jsxs("div",{className:"text-xs opacity-80 space-y-0.5",children:[o.jsx("p",{children:h.deviceCard.statusTooltip.legend.green}),o.jsx("p",{children:h.deviceCard.statusTooltip.legend.yellow}),o.jsx("p",{children:h.deviceCard.statusTooltip.legend.red}),o.jsx("p",{children:h.deviceCard.statusTooltip.legend.gray})]})]})})]}),o.jsxs("div",{className:"flex-1 min-w-0 flex flex-col justify-center gap-0.5",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(da,{className:`w-4 h-4 flex-shrink-0 ${p?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),o.jsx("span",{className:`font-semibold text-sm truncate ${p?"text-slate-900 dark:text-slate-100":"text-slate-700 dark:text-slate-300"}`,children:G})]}),o.jsx("span",{className:`text-xs font-mono truncate ${p?"text-slate-500 dark:text-slate-400":"text-slate-400 dark:text-slate-500"}`,children:r||s})]}),o.jsxs("div",{className:"flex-shrink-0 flex flex-col items-end gap-1",children:[y&&o.jsx(Cn,{variant:"outline",className:"text-xs border-slate-200 text-slate-600 dark:border-slate-700 dark:text-slate-400",children:"USB"}),S&&o.jsxs(Cn,{variant:"outline",className:"text-xs border-slate-200 text-slate-600 dark:border-slate-700 dark:text-slate-400",children:[o.jsx(xu,{className:"w-2.5 h-2.5 mr-1"}),"Remote"]})]}),o.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[f&&y&&o.jsx(ve,{variant:"ghost",size:"icon",onClick:K,disabled:N,className:"h-7 w-7 text-slate-400 hover:text-[#1d9bf0]",title:h.deviceCard.connectViaWifi,children:N?o.jsx(hn,{className:"w-3.5 h-3.5 animate-spin"}):o.jsx(fa,{className:"w-3.5 h-3.5"})}),g&&S&&o.jsx(ve,{variant:"ghost",size:"icon",onClick:V,disabled:N,className:"h-7 w-7 text-slate-400 hover:text-orange-500",title:h.deviceCard.disconnectWifi,children:N?o.jsx(hn,{className:"w-3.5 h-3.5 animate-spin"}):o.jsx(xu,{className:"w-3.5 h-3.5"})})]})]})]}),o.jsx(_u,{isOpen:R,title:h.deviceCard.connectWifiTitle,content:h.deviceCard.connectWifiContent,onConfirm:U,onCancel:()=>M(!1)}),o.jsx(_u,{isOpen:F,title:h.deviceCard.disconnectWifiTitle,content:h.deviceCard.disconnectWifiContent,onConfirm:I,onCancel:()=>A(!1)})]})}function d1(s){const n=s+"CollectionProvider",[r,a]=ms(n),[u,l]=r(n,{collectionRef:{current:null},itemMap:new Map}),p=j=>{const{scope:R,children:M}=j,F=We.useRef(null),A=We.useRef(new Map).current;return o.jsx(u,{scope:R,itemMap:A,collectionRef:F,children:M})};p.displayName=n;const b=s+"CollectionSlot",f=oa(b),g=We.forwardRef((j,R)=>{const{scope:M,children:F}=j,A=l(b,M),G=bn(R,A.collectionRef);return o.jsx(f,{ref:G,children:F})});g.displayName=b;const h=s+"CollectionItemSlot",_="data-radix-collection-item",y=oa(h),S=We.forwardRef((j,R)=>{const{scope:M,children:F,...A}=j,G=We.useRef(null),q=bn(R,G),X=l(h,M);return We.useEffect(()=>(X.itemMap.set(G,{ref:G,...A}),()=>void X.itemMap.delete(G))),o.jsx(y,{[_]:"",ref:q,children:F})});S.displayName=h;function N(j){const R=l(s+"CollectionConsumer",j);return We.useCallback(()=>{const F=R.collectionRef.current;if(!F)return[];const A=Array.from(F.querySelectorAll(`[${_}]`));return Array.from(R.itemMap.values()).sort((X,K)=>A.indexOf(X.ref.current)-A.indexOf(K.ref.current))},[R.collectionRef,R.itemMap])}return[{Provider:p,Slot:g,ItemSlot:S},N,a]}var f1=v.createContext(void 0);function Ta(s){const n=v.useContext(f1);return s||n||"ltr"}var Yo="rovingFocusGroup.onEntryFocus",h1={bubbles:!1,cancelable:!0},gs="RovingFocusGroup",[pa,dd,p1]=d1(gs),[m1,fd]=ms(gs,[p1]),[g1,x1]=m1(gs),hd=v.forwardRef((s,n)=>o.jsx(pa.Provider,{scope:s.__scopeRovingFocusGroup,children:o.jsx(pa.Slot,{scope:s.__scopeRovingFocusGroup,children:o.jsx(_1,{...s,ref:n})})}));hd.displayName=gs;var _1=v.forwardRef((s,n)=>{const{__scopeRovingFocusGroup:r,orientation:a,loop:u=!1,dir:l,currentTabStopId:p,defaultCurrentTabStopId:b,onCurrentTabStopIdChange:f,onEntryFocus:g,preventScrollOnEntryFocus:h=!1,..._}=s,y=v.useRef(null),S=bn(n,y),N=Ta(l),[j,R]=Sa({prop:p,defaultProp:b??null,onChange:f,caller:gs}),[M,F]=v.useState(!1),A=Zn(g),G=dd(r),q=v.useRef(!1),[X,K]=v.useState(0);return v.useEffect(()=>{const V=y.current;if(V)return V.addEventListener(Yo,A),()=>V.removeEventListener(Yo,A)},[A]),o.jsx(g1,{scope:r,orientation:a,dir:N,loop:u,currentTabStopId:j,onItemFocus:v.useCallback(V=>R(V),[R]),onItemShiftTab:v.useCallback(()=>F(!0),[]),onFocusableItemAdd:v.useCallback(()=>K(V=>V+1),[]),onFocusableItemRemove:v.useCallback(()=>K(V=>V-1),[]),children:o.jsx(Zt.div,{tabIndex:M||X===0?-1:0,"data-orientation":a,..._,ref:S,style:{outline:"none",...s.style},onMouseDown:dt(s.onMouseDown,()=>{q.current=!0}),onFocus:dt(s.onFocus,V=>{const U=!q.current;if(V.target===V.currentTarget&&U&&!M){const I=new CustomEvent(Yo,h1);if(V.currentTarget.dispatchEvent(I),!I.defaultPrevented){const D=G().filter(T=>T.focusable),me=D.find(T=>T.active),ye=D.find(T=>T.id===j),J=[me,ye,...D].filter(Boolean).map(T=>T.ref.current);gd(J,h)}}q.current=!1}),onBlur:dt(s.onBlur,()=>F(!1))})})}),pd="RovingFocusGroupItem",md=v.forwardRef((s,n)=>{const{__scopeRovingFocusGroup:r,focusable:a=!0,active:u=!1,tabStopId:l,children:p,...b}=s,f=Ea(),g=l||f,h=x1(pd,r),_=h.currentTabStopId===g,y=dd(r),{onFocusableItemAdd:S,onFocusableItemRemove:N,currentTabStopId:j}=h;return v.useEffect(()=>{if(a)return S(),()=>N()},[a,S,N]),o.jsx(pa.ItemSlot,{scope:r,id:g,focusable:a,active:u,children:o.jsx(Zt.span,{tabIndex:_?0:-1,"data-orientation":h.orientation,...b,ref:n,onMouseDown:dt(s.onMouseDown,R=>{a?h.onItemFocus(g):R.preventDefault()}),onFocus:dt(s.onFocus,()=>h.onItemFocus(g)),onKeyDown:dt(s.onKeyDown,R=>{if(R.key==="Tab"&&R.shiftKey){h.onItemShiftTab();return}if(R.target!==R.currentTarget)return;const M=y1(R,h.orientation,h.dir);if(M!==void 0){if(R.metaKey||R.ctrlKey||R.altKey||R.shiftKey)return;R.preventDefault();let A=y().filter(G=>G.focusable).map(G=>G.ref.current);if(M==="last")A.reverse();else if(M==="prev"||M==="next"){M==="prev"&&A.reverse();const G=A.indexOf(R.currentTarget);A=h.loop?w1(A,G+1):A.slice(G+1)}setTimeout(()=>gd(A))}}),children:typeof p=="function"?p({isCurrentTabStop:_,hasTabStop:j!=null}):p})})});md.displayName=pd;var v1={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function b1(s,n){return n!=="rtl"?s:s==="ArrowLeft"?"ArrowRight":s==="ArrowRight"?"ArrowLeft":s}function y1(s,n,r){const a=b1(s.key,r);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(a))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(a)))return v1[a]}function gd(s,n=!1){const r=document.activeElement;for(const a of s)if(a===r||(a.focus({preventScroll:n}),document.activeElement!==r))return}function w1(s,n){return s.map((r,a)=>s[(n+a)%s.length])}var E1=hd,S1=md,Ni="Tabs",[N1]=ms(Ni,[fd]),xd=fd(),[C1,Ra]=N1(Ni),_d=v.forwardRef((s,n)=>{const{__scopeTabs:r,value:a,onValueChange:u,defaultValue:l,orientation:p="horizontal",dir:b,activationMode:f="automatic",...g}=s,h=Ta(b),[_,y]=Sa({prop:a,onChange:u,defaultProp:l??"",caller:Ni});return o.jsx(C1,{scope:r,baseId:Ea(),value:_,onValueChange:y,orientation:p,dir:h,activationMode:f,children:o.jsx(Zt.div,{dir:h,"data-orientation":p,...g,ref:n})})});_d.displayName=Ni;var vd="TabsList",bd=v.forwardRef((s,n)=>{const{__scopeTabs:r,loop:a=!0,...u}=s,l=Ra(vd,r),p=xd(r);return o.jsx(E1,{asChild:!0,...p,orientation:l.orientation,dir:l.dir,loop:a,children:o.jsx(Zt.div,{role:"tablist","aria-orientation":l.orientation,...u,ref:n})})});bd.displayName=vd;var yd="TabsTrigger",wd=v.forwardRef((s,n)=>{const{__scopeTabs:r,value:a,disabled:u=!1,...l}=s,p=Ra(yd,r),b=xd(r),f=Nd(p.baseId,a),g=Cd(p.baseId,a),h=a===p.value;return o.jsx(S1,{asChild:!0,...b,focusable:!u,active:h,children:o.jsx(Zt.button,{type:"button",role:"tab","aria-selected":h,"aria-controls":g,"data-state":h?"active":"inactive","data-disabled":u?"":void 0,disabled:u,id:f,...l,ref:n,onMouseDown:dt(s.onMouseDown,_=>{!u&&_.button===0&&_.ctrlKey===!1?p.onValueChange(a):_.preventDefault()}),onKeyDown:dt(s.onKeyDown,_=>{[" ","Enter"].includes(_.key)&&p.onValueChange(a)}),onFocus:dt(s.onFocus,()=>{const _=p.activationMode!=="manual";!h&&!u&&_&&p.onValueChange(a)})})})});wd.displayName=yd;var Ed="TabsContent",Sd=v.forwardRef((s,n)=>{const{__scopeTabs:r,value:a,forceMount:u,children:l,...p}=s,b=Ra(Ed,r),f=Nd(b.baseId,a),g=Cd(b.baseId,a),h=a===b.value,_=v.useRef(h);return v.useEffect(()=>{const y=requestAnimationFrame(()=>_.current=!1);return()=>cancelAnimationFrame(y)},[]),o.jsx(gr,{present:u||h,children:({present:y})=>o.jsx(Zt.div,{"data-state":h?"active":"inactive","data-orientation":b.orientation,role:"tabpanel","aria-labelledby":f,hidden:!y,id:g,tabIndex:0,...p,ref:n,style:{...s.style,animationDuration:_.current?"0s":void 0},children:y&&l})})});Sd.displayName=Ed;function Nd(s,n){return`${s}-trigger-${n}`}function Cd(s,n){return`${s}-content-${n}`}var k1=_d,T1=bd,R1=wd,A1=Sd;function j1({className:s,...n}){return o.jsx(k1,{"data-slot":"tabs",className:nr("flex flex-col gap-2",s),...n})}function P1({className:s,...n}){return o.jsx(T1,{"data-slot":"tabs-list",className:nr("bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",s),...n})}function vu({className:s,...n}){return o.jsx(R1,{"data-slot":"tabs-trigger",className:nr("data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",s),...n})}function bu({className:s,...n}){return o.jsx(A1,{"data-slot":"tabs-content",className:nr("flex-1 outline-none",s),...n})}var M1=Object.defineProperty,vi=Object.getOwnPropertySymbols,kd=Object.prototype.hasOwnProperty,Td=Object.prototype.propertyIsEnumerable,yu=(s,n,r)=>n in s?M1(s,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[n]=r,ma=(s,n)=>{for(var r in n||(n={}))kd.call(n,r)&&yu(s,r,n[r]);if(vi)for(var r of vi(n))Td.call(n,r)&&yu(s,r,n[r]);return s},ga=(s,n)=>{var r={};for(var a in s)kd.call(s,a)&&n.indexOf(a)<0&&(r[a]=s[a]);if(s!=null&&vi)for(var a of vi(s))n.indexOf(a)<0&&Td.call(s,a)&&(r[a]=s[a]);return r};var mr;(s=>{const n=class Ae{constructor(f,g,h,_){if(this.version=f,this.errorCorrectionLevel=g,this.modules=[],this.isFunction=[],f<Ae.MIN_VERSION||f>Ae.MAX_VERSION)throw new RangeError("Version value out of range");if(_<-1||_>7)throw new RangeError("Mask value out of range");this.size=f*4+17;let y=[];for(let N=0;N<this.size;N++)y.push(!1);for(let N=0;N<this.size;N++)this.modules.push(y.slice()),this.isFunction.push(y.slice());this.drawFunctionPatterns();const S=this.addEccAndInterleave(h);if(this.drawCodewords(S),_==-1){let N=1e9;for(let j=0;j<8;j++){this.applyMask(j),this.drawFormatBits(j);const R=this.getPenaltyScore();R<N&&(_=j,N=R),this.applyMask(j)}}u(0<=_&&_<=7),this.mask=_,this.applyMask(_),this.drawFormatBits(_),this.isFunction=[]}static encodeText(f,g){const h=s.QrSegment.makeSegments(f);return Ae.encodeSegments(h,g)}static encodeBinary(f,g){const h=s.QrSegment.makeBytes(f);return Ae.encodeSegments([h],g)}static encodeSegments(f,g,h=1,_=40,y=-1,S=!0){if(!(Ae.MIN_VERSION<=h&&h<=_&&_<=Ae.MAX_VERSION)||y<-1||y>7)throw new RangeError("Invalid value");let N,j;for(N=h;;N++){const A=Ae.getNumDataCodewords(N,g)*8,G=p.getTotalBits(f,N);if(G<=A){j=G;break}if(N>=_)throw new RangeError("Data too long")}for(const A of[Ae.Ecc.MEDIUM,Ae.Ecc.QUARTILE,Ae.Ecc.HIGH])S&&j<=Ae.getNumDataCodewords(N,A)*8&&(g=A);let R=[];for(const A of f){r(A.mode.modeBits,4,R),r(A.numChars,A.mode.numCharCountBits(N),R);for(const G of A.getData())R.push(G)}u(R.length==j);const M=Ae.getNumDataCodewords(N,g)*8;u(R.length<=M),r(0,Math.min(4,M-R.length),R),r(0,(8-R.length%8)%8,R),u(R.length%8==0);for(let A=236;R.length<M;A^=253)r(A,8,R);let F=[];for(;F.length*8<R.length;)F.push(0);return R.forEach((A,G)=>F[G>>>3]|=A<<7-(G&7)),new Ae(N,g,F,y)}getModule(f,g){return 0<=f&&f<this.size&&0<=g&&g<this.size&&this.modules[g][f]}getModules(){return this.modules}drawFunctionPatterns(){for(let h=0;h<this.size;h++)this.setFunctionModule(6,h,h%2==0),this.setFunctionModule(h,6,h%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const f=this.getAlignmentPatternPositions(),g=f.length;for(let h=0;h<g;h++)for(let _=0;_<g;_++)h==0&&_==0||h==0&&_==g-1||h==g-1&&_==0||this.drawAlignmentPattern(f[h],f[_]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(f){const g=this.errorCorrectionLevel.formatBits<<3|f;let h=g;for(let y=0;y<10;y++)h=h<<1^(h>>>9)*1335;const _=(g<<10|h)^21522;u(_>>>15==0);for(let y=0;y<=5;y++)this.setFunctionModule(8,y,a(_,y));this.setFunctionModule(8,7,a(_,6)),this.setFunctionModule(8,8,a(_,7)),this.setFunctionModule(7,8,a(_,8));for(let y=9;y<15;y++)this.setFunctionModule(14-y,8,a(_,y));for(let y=0;y<8;y++)this.setFunctionModule(this.size-1-y,8,a(_,y));for(let y=8;y<15;y++)this.setFunctionModule(8,this.size-15+y,a(_,y));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let f=this.version;for(let h=0;h<12;h++)f=f<<1^(f>>>11)*7973;const g=this.version<<12|f;u(g>>>18==0);for(let h=0;h<18;h++){const _=a(g,h),y=this.size-11+h%3,S=Math.floor(h/3);this.setFunctionModule(y,S,_),this.setFunctionModule(S,y,_)}}drawFinderPattern(f,g){for(let h=-4;h<=4;h++)for(let _=-4;_<=4;_++){const y=Math.max(Math.abs(_),Math.abs(h)),S=f+_,N=g+h;0<=S&&S<this.size&&0<=N&&N<this.size&&this.setFunctionModule(S,N,y!=2&&y!=4)}}drawAlignmentPattern(f,g){for(let h=-2;h<=2;h++)for(let _=-2;_<=2;_++)this.setFunctionModule(f+_,g+h,Math.max(Math.abs(_),Math.abs(h))!=1)}setFunctionModule(f,g,h){this.modules[g][f]=h,this.isFunction[g][f]=!0}addEccAndInterleave(f){const g=this.version,h=this.errorCorrectionLevel;if(f.length!=Ae.getNumDataCodewords(g,h))throw new RangeError("Invalid argument");const _=Ae.NUM_ERROR_CORRECTION_BLOCKS[h.ordinal][g],y=Ae.ECC_CODEWORDS_PER_BLOCK[h.ordinal][g],S=Math.floor(Ae.getNumRawDataModules(g)/8),N=_-S%_,j=Math.floor(S/_);let R=[];const M=Ae.reedSolomonComputeDivisor(y);for(let A=0,G=0;A<_;A++){let q=f.slice(G,G+j-y+(A<N?0:1));G+=q.length;const X=Ae.reedSolomonComputeRemainder(q,M);A<N&&q.push(0),R.push(q.concat(X))}let F=[];for(let A=0;A<R[0].length;A++)R.forEach((G,q)=>{(A!=j-y||q>=N)&&F.push(G[A])});return u(F.length==S),F}drawCodewords(f){if(f.length!=Math.floor(Ae.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let g=0;for(let h=this.size-1;h>=1;h-=2){h==6&&(h=5);for(let _=0;_<this.size;_++)for(let y=0;y<2;y++){const S=h-y,j=(h+1&2)==0?this.size-1-_:_;!this.isFunction[j][S]&&g<f.length*8&&(this.modules[j][S]=a(f[g>>>3],7-(g&7)),g++)}}u(g==f.length*8)}applyMask(f){if(f<0||f>7)throw new RangeError("Mask value out of range");for(let g=0;g<this.size;g++)for(let h=0;h<this.size;h++){let _;switch(f){case 0:_=(h+g)%2==0;break;case 1:_=g%2==0;break;case 2:_=h%3==0;break;case 3:_=(h+g)%3==0;break;case 4:_=(Math.floor(h/3)+Math.floor(g/2))%2==0;break;case 5:_=h*g%2+h*g%3==0;break;case 6:_=(h*g%2+h*g%3)%2==0;break;case 7:_=((h+g)%2+h*g%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[g][h]&&_&&(this.modules[g][h]=!this.modules[g][h])}}getPenaltyScore(){let f=0;for(let y=0;y<this.size;y++){let S=!1,N=0,j=[0,0,0,0,0,0,0];for(let R=0;R<this.size;R++)this.modules[y][R]==S?(N++,N==5?f+=Ae.PENALTY_N1:N>5&&f++):(this.finderPenaltyAddHistory(N,j),S||(f+=this.finderPenaltyCountPatterns(j)*Ae.PENALTY_N3),S=this.modules[y][R],N=1);f+=this.finderPenaltyTerminateAndCount(S,N,j)*Ae.PENALTY_N3}for(let y=0;y<this.size;y++){let S=!1,N=0,j=[0,0,0,0,0,0,0];for(let R=0;R<this.size;R++)this.modules[R][y]==S?(N++,N==5?f+=Ae.PENALTY_N1:N>5&&f++):(this.finderPenaltyAddHistory(N,j),S||(f+=this.finderPenaltyCountPatterns(j)*Ae.PENALTY_N3),S=this.modules[R][y],N=1);f+=this.finderPenaltyTerminateAndCount(S,N,j)*Ae.PENALTY_N3}for(let y=0;y<this.size-1;y++)for(let S=0;S<this.size-1;S++){const N=this.modules[y][S];N==this.modules[y][S+1]&&N==this.modules[y+1][S]&&N==this.modules[y+1][S+1]&&(f+=Ae.PENALTY_N2)}let g=0;for(const y of this.modules)g=y.reduce((S,N)=>S+(N?1:0),g);const h=this.size*this.size,_=Math.ceil(Math.abs(g*20-h*10)/h)-1;return u(0<=_&&_<=9),f+=_*Ae.PENALTY_N4,u(0<=f&&f<=2568888),f}getAlignmentPatternPositions(){if(this.version==1)return[];{const f=Math.floor(this.version/7)+2,g=this.version==32?26:Math.ceil((this.version*4+4)/(f*2-2))*2;let h=[6];for(let _=this.size-7;h.length<f;_-=g)h.splice(1,0,_);return h}}static getNumRawDataModules(f){if(f<Ae.MIN_VERSION||f>Ae.MAX_VERSION)throw new RangeError("Version number out of range");let g=(16*f+128)*f+64;if(f>=2){const h=Math.floor(f/7)+2;g-=(25*h-10)*h-55,f>=7&&(g-=36)}return u(208<=g&&g<=29648),g}static getNumDataCodewords(f,g){return Math.floor(Ae.getNumRawDataModules(f)/8)-Ae.ECC_CODEWORDS_PER_BLOCK[g.ordinal][f]*Ae.NUM_ERROR_CORRECTION_BLOCKS[g.ordinal][f]}static reedSolomonComputeDivisor(f){if(f<1||f>255)throw new RangeError("Degree out of range");let g=[];for(let _=0;_<f-1;_++)g.push(0);g.push(1);let h=1;for(let _=0;_<f;_++){for(let y=0;y<g.length;y++)g[y]=Ae.reedSolomonMultiply(g[y],h),y+1<g.length&&(g[y]^=g[y+1]);h=Ae.reedSolomonMultiply(h,2)}return g}static reedSolomonComputeRemainder(f,g){let h=g.map(_=>0);for(const _ of f){const y=_^h.shift();h.push(0),g.forEach((S,N)=>h[N]^=Ae.reedSolomonMultiply(S,y))}return h}static reedSolomonMultiply(f,g){if(f>>>8||g>>>8)throw new RangeError("Byte out of range");let h=0;for(let _=7;_>=0;_--)h=h<<1^(h>>>7)*285,h^=(g>>>_&1)*f;return u(h>>>8==0),h}finderPenaltyCountPatterns(f){const g=f[1];u(g<=this.size*3);const h=g>0&&f[2]==g&&f[3]==g*3&&f[4]==g&&f[5]==g;return(h&&f[0]>=g*4&&f[6]>=g?1:0)+(h&&f[6]>=g*4&&f[0]>=g?1:0)}finderPenaltyTerminateAndCount(f,g,h){return f&&(this.finderPenaltyAddHistory(g,h),g=0),g+=this.size,this.finderPenaltyAddHistory(g,h),this.finderPenaltyCountPatterns(h)}finderPenaltyAddHistory(f,g){g[0]==0&&(f+=this.size),g.pop(),g.unshift(f)}};n.MIN_VERSION=1,n.MAX_VERSION=40,n.PENALTY_N1=3,n.PENALTY_N2=3,n.PENALTY_N3=40,n.PENALTY_N4=10,n.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],n.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],s.QrCode=n;function r(b,f,g){if(f<0||f>31||b>>>f)throw new RangeError("Value out of range");for(let h=f-1;h>=0;h--)g.push(b>>>h&1)}function a(b,f){return(b>>>f&1)!=0}function u(b){if(!b)throw new Error("Assertion error")}const l=class ot{constructor(f,g,h){if(this.mode=f,this.numChars=g,this.bitData=h,g<0)throw new RangeError("Invalid argument");this.bitData=h.slice()}static makeBytes(f){let g=[];for(const h of f)r(h,8,g);return new ot(ot.Mode.BYTE,f.length,g)}static makeNumeric(f){if(!ot.isNumeric(f))throw new RangeError("String contains non-numeric characters");let g=[];for(let h=0;h<f.length;){const _=Math.min(f.length-h,3);r(parseInt(f.substring(h,h+_),10),_*3+1,g),h+=_}return new ot(ot.Mode.NUMERIC,f.length,g)}static makeAlphanumeric(f){if(!ot.isAlphanumeric(f))throw new RangeError("String contains unencodable characters in alphanumeric mode");let g=[],h;for(h=0;h+2<=f.length;h+=2){let _=ot.ALPHANUMERIC_CHARSET.indexOf(f.charAt(h))*45;_+=ot.ALPHANUMERIC_CHARSET.indexOf(f.charAt(h+1)),r(_,11,g)}return h<f.length&&r(ot.ALPHANUMERIC_CHARSET.indexOf(f.charAt(h)),6,g),new ot(ot.Mode.ALPHANUMERIC,f.length,g)}static makeSegments(f){return f==""?[]:ot.isNumeric(f)?[ot.makeNumeric(f)]:ot.isAlphanumeric(f)?[ot.makeAlphanumeric(f)]:[ot.makeBytes(ot.toUtf8ByteArray(f))]}static makeEci(f){let g=[];if(f<0)throw new RangeError("ECI assignment value out of range");if(f<128)r(f,8,g);else if(f<16384)r(2,2,g),r(f,14,g);else if(f<1e6)r(6,3,g),r(f,21,g);else throw new RangeError("ECI assignment value out of range");return new ot(ot.Mode.ECI,0,g)}static isNumeric(f){return ot.NUMERIC_REGEX.test(f)}static isAlphanumeric(f){return ot.ALPHANUMERIC_REGEX.test(f)}getData(){return this.bitData.slice()}static getTotalBits(f,g){let h=0;for(const _ of f){const y=_.mode.numCharCountBits(g);if(_.numChars>=1<<y)return 1/0;h+=4+y+_.bitData.length}return h}static toUtf8ByteArray(f){f=encodeURI(f);let g=[];for(let h=0;h<f.length;h++)f.charAt(h)!="%"?g.push(f.charCodeAt(h)):(g.push(parseInt(f.substring(h+1,h+3),16)),h+=2);return g}};l.NUMERIC_REGEX=/^[0-9]*$/,l.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,l.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let p=l;s.QrSegment=l})(mr||(mr={}));(s=>{(n=>{const r=class{constructor(u,l){this.ordinal=u,this.formatBits=l}};r.LOW=new r(0,1),r.MEDIUM=new r(1,0),r.QUARTILE=new r(2,3),r.HIGH=new r(3,2),n.Ecc=r})(s.QrCode||(s.QrCode={}))})(mr||(mr={}));(s=>{(n=>{const r=class{constructor(u,l){this.modeBits=u,this.numBitsCharCount=l}numCharCountBits(u){return this.numBitsCharCount[Math.floor((u+7)/17)]}};r.NUMERIC=new r(1,[10,12,14]),r.ALPHANUMERIC=new r(2,[9,11,13]),r.BYTE=new r(4,[8,16,16]),r.KANJI=new r(8,[8,10,12]),r.ECI=new r(7,[0,0,0]),n.Mode=r})(s.QrSegment||(s.QrSegment={}))})(mr||(mr={}));var Pr=mr;var I1={L:Pr.QrCode.Ecc.LOW,M:Pr.QrCode.Ecc.MEDIUM,Q:Pr.QrCode.Ecc.QUARTILE,H:Pr.QrCode.Ecc.HIGH},Rd=128,Ad="L",jd="#FFFFFF",Pd="#000000",Md=!1,Id=1,D1=4,L1=0,O1=.1;function Dd(s,n=0){const r=[];return s.forEach(function(a,u){let l=null;a.forEach(function(p,b){if(!p&&l!==null){r.push(`M${l+n} ${u+n}h${b-l}v1H${l+n}z`),l=null;return}if(b===a.length-1){if(!p)return;l===null?r.push(`M${b+n},${u+n} h1v1H${b+n}z`):r.push(`M${l+n},${u+n} h${b+1-l}v1H${l+n}z`);return}p&&l===null&&(l=b)})}),r.join("")}function Ld(s,n){return s.slice().map((r,a)=>a<n.y||a>=n.y+n.h?r:r.map((u,l)=>l<n.x||l>=n.x+n.w?u:!1))}function F1(s,n,r,a){if(a==null)return null;const u=s.length+r*2,l=Math.floor(n*O1),p=u/n,b=(a.width||l)*p,f=(a.height||l)*p,g=a.x==null?s.length/2-b/2:a.x*p,h=a.y==null?s.length/2-f/2:a.y*p,_=a.opacity==null?1:a.opacity;let y=null;if(a.excavate){let N=Math.floor(g),j=Math.floor(h),R=Math.ceil(b+g-N),M=Math.ceil(f+h-j);y={x:N,y:j,w:R,h:M}}const S=a.crossOrigin;return{x:g,y:h,h:f,w:b,excavation:y,opacity:_,crossOrigin:S}}function B1(s,n){return n!=null?Math.max(Math.floor(n),0):s?D1:L1}function Od({value:s,level:n,minVersion:r,includeMargin:a,marginSize:u,imageSettings:l,size:p,boostLevel:b}){let f=We.useMemo(()=>{const N=(Array.isArray(s)?s:[s]).reduce((j,R)=>(j.push(...Pr.QrSegment.makeSegments(R)),j),[]);return Pr.QrCode.encodeSegments(N,I1[n],r,void 0,void 0,b)},[s,n,r,b]);const{cells:g,margin:h,numCells:_,calculatedImageSettings:y}=We.useMemo(()=>{let S=f.getModules();const N=B1(a,u),j=S.length+N*2,R=F1(S,p,N,l);return{cells:S,margin:N,numCells:j,calculatedImageSettings:R}},[f,p,l,a,u]);return{qrcode:f,margin:h,cells:g,numCells:_,calculatedImageSettings:y}}var U1=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),W1=We.forwardRef(function(n,r){const a=n,{value:u,size:l=Rd,level:p=Ad,bgColor:b=jd,fgColor:f=Pd,includeMargin:g=Md,minVersion:h=Id,boostLevel:_,marginSize:y,imageSettings:S}=a,j=ga(a,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:R}=j,M=ga(j,["style"]),F=S?.src,A=We.useRef(null),G=We.useRef(null),q=We.useCallback($=>{A.current=$,typeof r=="function"?r($):r&&(r.current=$)},[r]),[X,K]=We.useState(!1),{margin:V,cells:U,numCells:I,calculatedImageSettings:D}=Od({value:u,level:p,minVersion:h,boostLevel:_,includeMargin:g,marginSize:y,imageSettings:S,size:l});We.useEffect(()=>{if(A.current!=null){const $=A.current,J=$.getContext("2d");if(!J)return;let T=U;const O=G.current,re=D!=null&&O!==null&&O.complete&&O.naturalHeight!==0&&O.naturalWidth!==0;re&&D.excavation!=null&&(T=Ld(U,D.excavation));const de=window.devicePixelRatio||1;$.height=$.width=l*de;const ue=l/I*de;J.scale(ue,ue),J.fillStyle=b,J.fillRect(0,0,I,I),J.fillStyle=f,U1?J.fill(new Path2D(Dd(T,V))):U.forEach(function(Z,Se){Z.forEach(function(je,Fe){je&&J.fillRect(Fe+V,Se+V,1,1)})}),D&&(J.globalAlpha=D.opacity),re&&J.drawImage(O,D.x+V,D.y+V,D.w,D.h)}}),We.useEffect(()=>{K(!1)},[F]);const me=ma({height:l,width:l},R);let ye=null;return F!=null&&(ye=We.createElement("img",{src:F,key:F,style:{display:"none"},onLoad:()=>{K(!0)},ref:G,crossOrigin:D?.crossOrigin})),We.createElement(We.Fragment,null,We.createElement("canvas",ma({style:me,height:l,width:l,ref:q,role:"img"},M)),ye)});W1.displayName="QRCodeCanvas";var Fd=We.forwardRef(function(n,r){const a=n,{value:u,size:l=Rd,level:p=Ad,bgColor:b=jd,fgColor:f=Pd,includeMargin:g=Md,minVersion:h=Id,boostLevel:_,title:y,marginSize:S,imageSettings:N}=a,j=ga(a,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:R,cells:M,numCells:F,calculatedImageSettings:A}=Od({value:u,level:p,minVersion:h,boostLevel:_,includeMargin:g,marginSize:S,imageSettings:N,size:l});let G=M,q=null;N!=null&&A!=null&&(A.excavation!=null&&(G=Ld(M,A.excavation)),q=We.createElement("image",{href:N.src,height:A.h,width:A.w,x:A.x+R,y:A.y+R,preserveAspectRatio:"none",opacity:A.opacity,crossOrigin:A.crossOrigin}));const X=Dd(G,R);return We.createElement("svg",ma({height:l,width:l,viewBox:`0 0 ${F} ${F}`,ref:r,role:"img"},j),!!y&&We.createElement("title",null,y),We.createElement("path",{fill:b,d:`M0,0 h${F}v${F}H0z`,shapeRendering:"crispEdges"}),We.createElement("path",{fill:f,d:X,shapeRendering:"crispEdges"}),q)});Fd.displayName="QRCodeSVG";var ls={exports:{}};var z1=ls.exports,wu;function H1(){return wu||(wu=1,(function(s,n){(function(){var r,a="4.17.21",u=200,l="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",p="Expected a function",b="Invalid `variable` option passed into `_.template`",f="__lodash_hash_undefined__",g=500,h="__lodash_placeholder__",_=1,y=2,S=4,N=1,j=2,R=1,M=2,F=4,A=8,G=16,q=32,X=64,K=128,V=256,U=512,I=30,D="...",me=800,ye=16,$=1,J=2,T=3,O=1/0,re=9007199254740991,de=17976931348623157e292,ue=NaN,Z=4294967295,Se=Z-1,je=Z>>>1,Fe=[["ary",K],["bind",R],["bindKey",M],["curry",A],["curryRight",G],["flip",U],["partial",q],["partialRight",X],["rearg",V]],Ie="[object Arguments]",at="[object Array]",lt="[object AsyncFunction]",Ge="[object Boolean]",Te="[object Date]",$e="[object DOMException]",mt="[object Error]",tt="[object Function]",At="[object GeneratorFunction]",Xe="[object Map]",gt="[object Number]",ne="[object Null]",se="[object Object]",L="[object Promise]",ee="[object Proxy]",le="[object RegExp]",ce="[object Set]",Ce="[object String]",we="[object Symbol]",xt="[object Undefined]",bt="[object WeakMap]",Q="[object WeakSet]",ie="[object ArrayBuffer]",ge="[object DataView]",Ke="[object Float32Array]",Ft="[object Float64Array]",st="[object Int8Array]",en="[object Int16Array]",jt="[object Int32Array]",tn="[object Uint8Array]",Qe="[object Uint8ClampedArray]",Ct="[object Uint16Array]",Pt="[object Uint32Array]",xr=/\b__p \+= '';/g,sr=/\b(__p \+=) '' \+/g,He=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Mt=/&(?:amp|lt|gt|quot|#39);/g,wt=/[&<>"']/g,It=RegExp(Mt.source),An=RegExp(wt.source),Or=/<%-([\s\S]+?)%>/g,Pi=/<%([\s\S]+?)%>/g,_s=/<%=([\s\S]+?)%>/g,Mi=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ii=/^\w*$/,Di=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Fr=/[\\^$.*+?()[\]{}|]/g,Br=RegExp(Fr.source),H=/^\s+/,Pe=/\s/,xe=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,nt=/\{\n\/\* \[wrapped with (.+)\] \*/,yn=/,? & /,ft=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Je=/[()=,{}\[\]\/\s]/,ht=/\\(\\)?/g,Bt=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Ur=/\w*$/,Li=/^[-+]0x[0-9a-f]+$/i,Ze=/^0b[01]+$/i,Ut=/^\[object .+?Constructor\]$/,qt=/^0o[0-7]+$/i,nn=/^(?:0|[1-9]\d*)$/,ir=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,vs=/($^)/,Df=/['\n\r\u2028\u2029\\]/g,bs="\\ud800-\\udfff",Lf="\\u0300-\\u036f",Of="\\ufe20-\\ufe2f",Ff="\\u20d0-\\u20ff",Ua=Lf+Of+Ff,Wa="\\u2700-\\u27bf",za="a-z\\xdf-\\xf6\\xf8-\\xff",Bf="\\xac\\xb1\\xd7\\xf7",Uf="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Wf="\\u2000-\\u206f",zf=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Ha="A-Z\\xc0-\\xd6\\xd8-\\xde",Ga="\\ufe0e\\ufe0f",$a=Bf+Uf+Wf+zf,Oi="['’]",Hf="["+bs+"]",qa="["+$a+"]",ys="["+Ua+"]",Xa="\\d+",Gf="["+Wa+"]",Ya="["+za+"]",Va="[^"+bs+$a+Xa+Wa+za+Ha+"]",Fi="\\ud83c[\\udffb-\\udfff]",$f="(?:"+ys+"|"+Fi+")",Ka="[^"+bs+"]",Bi="(?:\\ud83c[\\udde6-\\uddff]){2}",Ui="[\\ud800-\\udbff][\\udc00-\\udfff]",_r="["+Ha+"]",Qa="\\u200d",Ja="(?:"+Ya+"|"+Va+")",qf="(?:"+_r+"|"+Va+")",Za="(?:"+Oi+"(?:d|ll|m|re|s|t|ve))?",el="(?:"+Oi+"(?:D|LL|M|RE|S|T|VE))?",tl=$f+"?",nl="["+Ga+"]?",Xf="(?:"+Qa+"(?:"+[Ka,Bi,Ui].join("|")+")"+nl+tl+")*",Yf="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Vf="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",rl=nl+tl+Xf,Kf="(?:"+[Gf,Bi,Ui].join("|")+")"+rl,Qf="(?:"+[Ka+ys+"?",ys,Bi,Ui,Hf].join("|")+")",Jf=RegExp(Oi,"g"),Zf=RegExp(ys,"g"),Wi=RegExp(Fi+"(?="+Fi+")|"+Qf+rl,"g"),eh=RegExp([_r+"?"+Ya+"+"+Za+"(?="+[qa,_r,"$"].join("|")+")",qf+"+"+el+"(?="+[qa,_r+Ja,"$"].join("|")+")",_r+"?"+Ja+"+"+Za,_r+"+"+el,Vf,Yf,Xa,Kf].join("|"),"g"),th=RegExp("["+Qa+bs+Ua+Ga+"]"),nh=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,rh=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],sh=-1,Ve={};Ve[Ke]=Ve[Ft]=Ve[st]=Ve[en]=Ve[jt]=Ve[tn]=Ve[Qe]=Ve[Ct]=Ve[Pt]=!0,Ve[Ie]=Ve[at]=Ve[ie]=Ve[Ge]=Ve[ge]=Ve[Te]=Ve[mt]=Ve[tt]=Ve[Xe]=Ve[gt]=Ve[se]=Ve[le]=Ve[ce]=Ve[Ce]=Ve[bt]=!1;var Ye={};Ye[Ie]=Ye[at]=Ye[ie]=Ye[ge]=Ye[Ge]=Ye[Te]=Ye[Ke]=Ye[Ft]=Ye[st]=Ye[en]=Ye[jt]=Ye[Xe]=Ye[gt]=Ye[se]=Ye[le]=Ye[ce]=Ye[Ce]=Ye[we]=Ye[tn]=Ye[Qe]=Ye[Ct]=Ye[Pt]=!0,Ye[mt]=Ye[tt]=Ye[bt]=!1;var ih={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"},oh={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ah={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},lh={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},ch=parseFloat,uh=parseInt,sl=typeof ai=="object"&&ai&&ai.Object===Object&&ai,dh=typeof self=="object"&&self&&self.Object===Object&&self,Et=sl||dh||Function("return this")(),zi=n&&!n.nodeType&&n,or=zi&&!0&&s&&!s.nodeType&&s,il=or&&or.exports===zi,Hi=il&&sl.process,rn=(function(){try{var C=or&&or.require&&or.require("util").types;return C||Hi&&Hi.binding&&Hi.binding("util")}catch{}})(),ol=rn&&rn.isArrayBuffer,al=rn&&rn.isDate,ll=rn&&rn.isMap,cl=rn&&rn.isRegExp,ul=rn&&rn.isSet,dl=rn&&rn.isTypedArray;function Xt(C,B,P){switch(P.length){case 0:return C.call(B);case 1:return C.call(B,P[0]);case 2:return C.call(B,P[0],P[1]);case 3:return C.call(B,P[0],P[1],P[2])}return C.apply(B,P)}function fh(C,B,P,oe){for(var _e=-1,Be=C==null?0:C.length;++_e<Be;){var _t=C[_e];B(oe,_t,P(_t),C)}return oe}function sn(C,B){for(var P=-1,oe=C==null?0:C.length;++P<oe&&B(C[P],P,C)!==!1;);return C}function hh(C,B){for(var P=C==null?0:C.length;P--&&B(C[P],P,C)!==!1;);return C}function fl(C,B){for(var P=-1,oe=C==null?0:C.length;++P<oe;)if(!B(C[P],P,C))return!1;return!0}function Gn(C,B){for(var P=-1,oe=C==null?0:C.length,_e=0,Be=[];++P<oe;){var _t=C[P];B(_t,P,C)&&(Be[_e++]=_t)}return Be}function ws(C,B){var P=C==null?0:C.length;return!!P&&vr(C,B,0)>-1}function Gi(C,B,P){for(var oe=-1,_e=C==null?0:C.length;++oe<_e;)if(P(B,C[oe]))return!0;return!1}function et(C,B){for(var P=-1,oe=C==null?0:C.length,_e=Array(oe);++P<oe;)_e[P]=B(C[P],P,C);return _e}function $n(C,B){for(var P=-1,oe=B.length,_e=C.length;++P<oe;)C[_e+P]=B[P];return C}function $i(C,B,P,oe){var _e=-1,Be=C==null?0:C.length;for(oe&&Be&&(P=C[++_e]);++_e<Be;)P=B(P,C[_e],_e,C);return P}function ph(C,B,P,oe){var _e=C==null?0:C.length;for(oe&&_e&&(P=C[--_e]);_e--;)P=B(P,C[_e],_e,C);return P}function qi(C,B){for(var P=-1,oe=C==null?0:C.length;++P<oe;)if(B(C[P],P,C))return!0;return!1}var mh=Xi("length");function gh(C){return C.split("")}function xh(C){return C.match(ft)||[]}function hl(C,B,P){var oe;return P(C,function(_e,Be,_t){if(B(_e,Be,_t))return oe=Be,!1}),oe}function Es(C,B,P,oe){for(var _e=C.length,Be=P+(oe?1:-1);oe?Be--:++Be<_e;)if(B(C[Be],Be,C))return Be;return-1}function vr(C,B,P){return B===B?Rh(C,B,P):Es(C,pl,P)}function _h(C,B,P,oe){for(var _e=P-1,Be=C.length;++_e<Be;)if(oe(C[_e],B))return _e;return-1}function pl(C){return C!==C}function ml(C,B){var P=C==null?0:C.length;return P?Vi(C,B)/P:ue}function Xi(C){return function(B){return B==null?r:B[C]}}function Yi(C){return function(B){return C==null?r:C[B]}}function gl(C,B,P,oe,_e){return _e(C,function(Be,_t,qe){P=oe?(oe=!1,Be):B(P,Be,_t,qe)}),P}function vh(C,B){var P=C.length;for(C.sort(B);P--;)C[P]=C[P].value;return C}function Vi(C,B){for(var P,oe=-1,_e=C.length;++oe<_e;){var Be=B(C[oe]);Be!==r&&(P=P===r?Be:P+Be)}return P}function Ki(C,B){for(var P=-1,oe=Array(C);++P<C;)oe[P]=B(P);return oe}function bh(C,B){return et(B,function(P){return[P,C[P]]})}function xl(C){return C&&C.slice(0,yl(C)+1).replace(H,"")}function Yt(C){return function(B){return C(B)}}function Qi(C,B){return et(B,function(P){return C[P]})}function Wr(C,B){return C.has(B)}function _l(C,B){for(var P=-1,oe=C.length;++P<oe&&vr(B,C[P],0)>-1;);return P}function vl(C,B){for(var P=C.length;P--&&vr(B,C[P],0)>-1;);return P}function yh(C,B){for(var P=C.length,oe=0;P--;)C[P]===B&&++oe;return oe}var wh=Yi(ih),Eh=Yi(oh);function Sh(C){return"\\"+lh[C]}function Nh(C,B){return C==null?r:C[B]}function br(C){return th.test(C)}function Ch(C){return nh.test(C)}function kh(C){for(var B,P=[];!(B=C.next()).done;)P.push(B.value);return P}function Ji(C){var B=-1,P=Array(C.size);return C.forEach(function(oe,_e){P[++B]=[_e,oe]}),P}function bl(C,B){return function(P){return C(B(P))}}function qn(C,B){for(var P=-1,oe=C.length,_e=0,Be=[];++P<oe;){var _t=C[P];(_t===B||_t===h)&&(C[P]=h,Be[_e++]=P)}return Be}function Ss(C){var B=-1,P=Array(C.size);return C.forEach(function(oe){P[++B]=oe}),P}function Th(C){var B=-1,P=Array(C.size);return C.forEach(function(oe){P[++B]=[oe,oe]}),P}function Rh(C,B,P){for(var oe=P-1,_e=C.length;++oe<_e;)if(C[oe]===B)return oe;return-1}function Ah(C,B,P){for(var oe=P+1;oe--;)if(C[oe]===B)return oe;return oe}function yr(C){return br(C)?Ph(C):mh(C)}function mn(C){return br(C)?Mh(C):gh(C)}function yl(C){for(var B=C.length;B--&&Pe.test(C.charAt(B)););return B}var jh=Yi(ah);function Ph(C){for(var B=Wi.lastIndex=0;Wi.test(C);)++B;return B}function Mh(C){return C.match(Wi)||[]}function Ih(C){return C.match(eh)||[]}var Dh=(function C(B){B=B==null?Et:wr.defaults(Et.Object(),B,wr.pick(Et,rh));var P=B.Array,oe=B.Date,_e=B.Error,Be=B.Function,_t=B.Math,qe=B.Object,Zi=B.RegExp,Lh=B.String,on=B.TypeError,Ns=P.prototype,Oh=Be.prototype,Er=qe.prototype,Cs=B["__core-js_shared__"],ks=Oh.toString,ze=Er.hasOwnProperty,Fh=0,wl=(function(){var e=/[^.]+$/.exec(Cs&&Cs.keys&&Cs.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""})(),Ts=Er.toString,Bh=ks.call(qe),Uh=Et._,Wh=Zi("^"+ks.call(ze).replace(Fr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Rs=il?B.Buffer:r,Xn=B.Symbol,As=B.Uint8Array,El=Rs?Rs.allocUnsafe:r,js=bl(qe.getPrototypeOf,qe),Sl=qe.create,Nl=Er.propertyIsEnumerable,Ps=Ns.splice,Cl=Xn?Xn.isConcatSpreadable:r,zr=Xn?Xn.iterator:r,ar=Xn?Xn.toStringTag:r,Ms=(function(){try{var e=fr(qe,"defineProperty");return e({},"",{}),e}catch{}})(),zh=B.clearTimeout!==Et.clearTimeout&&B.clearTimeout,Hh=oe&&oe.now!==Et.Date.now&&oe.now,Gh=B.setTimeout!==Et.setTimeout&&B.setTimeout,Is=_t.ceil,Ds=_t.floor,eo=qe.getOwnPropertySymbols,$h=Rs?Rs.isBuffer:r,kl=B.isFinite,qh=Ns.join,Xh=bl(qe.keys,qe),vt=_t.max,kt=_t.min,Yh=oe.now,Vh=B.parseInt,Tl=_t.random,Kh=Ns.reverse,to=fr(B,"DataView"),Hr=fr(B,"Map"),no=fr(B,"Promise"),Sr=fr(B,"Set"),Gr=fr(B,"WeakMap"),$r=fr(qe,"create"),Ls=Gr&&new Gr,Nr={},Qh=hr(to),Jh=hr(Hr),Zh=hr(no),ep=hr(Sr),tp=hr(Gr),Os=Xn?Xn.prototype:r,qr=Os?Os.valueOf:r,Rl=Os?Os.toString:r;function m(e){if(it(e)&&!be(e)&&!(e instanceof Me)){if(e instanceof an)return e;if(ze.call(e,"__wrapped__"))return Ac(e)}return new an(e)}var Cr=(function(){function e(){}return function(t){if(!rt(t))return{};if(Sl)return Sl(t);e.prototype=t;var i=new e;return e.prototype=r,i}})();function Fs(){}function an(e,t){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=r}m.templateSettings={escape:Or,evaluate:Pi,interpolate:_s,variable:"",imports:{_:m}},m.prototype=Fs.prototype,m.prototype.constructor=m,an.prototype=Cr(Fs.prototype),an.prototype.constructor=an;function Me(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=Z,this.__views__=[]}function np(){var e=new Me(this.__wrapped__);return e.__actions__=Wt(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=Wt(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=Wt(this.__views__),e}function rp(){if(this.__filtered__){var e=new Me(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e}function sp(){var e=this.__wrapped__.value(),t=this.__dir__,i=be(e),c=t<0,d=i?e.length:0,x=gm(0,d,this.__views__),w=x.start,E=x.end,k=E-w,W=c?E:w-1,z=this.__iteratees__,Y=z.length,te=0,ae=kt(k,this.__takeCount__);if(!i||!c&&d==k&&ae==k)return Zl(e,this.__actions__);var he=[];e:for(;k--&&te<ae;){W+=t;for(var Ne=-1,pe=e[W];++Ne<Y;){var Re=z[Ne],De=Re.iteratee,Qt=Re.type,Ot=De(pe);if(Qt==J)pe=Ot;else if(!Ot){if(Qt==$)continue e;break e}}he[te++]=pe}return he}Me.prototype=Cr(Fs.prototype),Me.prototype.constructor=Me;function lr(e){var t=-1,i=e==null?0:e.length;for(this.clear();++t<i;){var c=e[t];this.set(c[0],c[1])}}function ip(){this.__data__=$r?$r(null):{},this.size=0}function op(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}function ap(e){var t=this.__data__;if($r){var i=t[e];return i===f?r:i}return ze.call(t,e)?t[e]:r}function lp(e){var t=this.__data__;return $r?t[e]!==r:ze.call(t,e)}function cp(e,t){var i=this.__data__;return this.size+=this.has(e)?0:1,i[e]=$r&&t===r?f:t,this}lr.prototype.clear=ip,lr.prototype.delete=op,lr.prototype.get=ap,lr.prototype.has=lp,lr.prototype.set=cp;function jn(e){var t=-1,i=e==null?0:e.length;for(this.clear();++t<i;){var c=e[t];this.set(c[0],c[1])}}function up(){this.__data__=[],this.size=0}function dp(e){var t=this.__data__,i=Bs(t,e);if(i<0)return!1;var c=t.length-1;return i==c?t.pop():Ps.call(t,i,1),--this.size,!0}function fp(e){var t=this.__data__,i=Bs(t,e);return i<0?r:t[i][1]}function hp(e){return Bs(this.__data__,e)>-1}function pp(e,t){var i=this.__data__,c=Bs(i,e);return c<0?(++this.size,i.push([e,t])):i[c][1]=t,this}jn.prototype.clear=up,jn.prototype.delete=dp,jn.prototype.get=fp,jn.prototype.has=hp,jn.prototype.set=pp;function Pn(e){var t=-1,i=e==null?0:e.length;for(this.clear();++t<i;){var c=e[t];this.set(c[0],c[1])}}function mp(){this.size=0,this.__data__={hash:new lr,map:new(Hr||jn),string:new lr}}function gp(e){var t=Qs(this,e).delete(e);return this.size-=t?1:0,t}function xp(e){return Qs(this,e).get(e)}function _p(e){return Qs(this,e).has(e)}function vp(e,t){var i=Qs(this,e),c=i.size;return i.set(e,t),this.size+=i.size==c?0:1,this}Pn.prototype.clear=mp,Pn.prototype.delete=gp,Pn.prototype.get=xp,Pn.prototype.has=_p,Pn.prototype.set=vp;function cr(e){var t=-1,i=e==null?0:e.length;for(this.__data__=new Pn;++t<i;)this.add(e[t])}function bp(e){return this.__data__.set(e,f),this}function yp(e){return this.__data__.has(e)}cr.prototype.add=cr.prototype.push=bp,cr.prototype.has=yp;function gn(e){var t=this.__data__=new jn(e);this.size=t.size}function wp(){this.__data__=new jn,this.size=0}function Ep(e){var t=this.__data__,i=t.delete(e);return this.size=t.size,i}function Sp(e){return this.__data__.get(e)}function Np(e){return this.__data__.has(e)}function Cp(e,t){var i=this.__data__;if(i instanceof jn){var c=i.__data__;if(!Hr||c.length<u-1)return c.push([e,t]),this.size=++i.size,this;i=this.__data__=new Pn(c)}return i.set(e,t),this.size=i.size,this}gn.prototype.clear=wp,gn.prototype.delete=Ep,gn.prototype.get=Sp,gn.prototype.has=Np,gn.prototype.set=Cp;function Al(e,t){var i=be(e),c=!i&&pr(e),d=!i&&!c&&Jn(e),x=!i&&!c&&!d&&Ar(e),w=i||c||d||x,E=w?Ki(e.length,Lh):[],k=E.length;for(var W in e)(t||ze.call(e,W))&&!(w&&(W=="length"||d&&(W=="offset"||W=="parent")||x&&(W=="buffer"||W=="byteLength"||W=="byteOffset")||Ln(W,k)))&&E.push(W);return E}function jl(e){var t=e.length;return t?e[po(0,t-1)]:r}function kp(e,t){return Js(Wt(e),ur(t,0,e.length))}function Tp(e){return Js(Wt(e))}function ro(e,t,i){(i!==r&&!xn(e[t],i)||i===r&&!(t in e))&&Mn(e,t,i)}function Xr(e,t,i){var c=e[t];(!(ze.call(e,t)&&xn(c,i))||i===r&&!(t in e))&&Mn(e,t,i)}function Bs(e,t){for(var i=e.length;i--;)if(xn(e[i][0],t))return i;return-1}function Rp(e,t,i,c){return Yn(e,function(d,x,w){t(c,d,i(d),w)}),c}function Pl(e,t){return e&&En(t,yt(t),e)}function Ap(e,t){return e&&En(t,Ht(t),e)}function Mn(e,t,i){t=="__proto__"&&Ms?Ms(e,t,{configurable:!0,enumerable:!0,value:i,writable:!0}):e[t]=i}function so(e,t){for(var i=-1,c=t.length,d=P(c),x=e==null;++i<c;)d[i]=x?r:Bo(e,t[i]);return d}function ur(e,t,i){return e===e&&(i!==r&&(e=e<=i?e:i),t!==r&&(e=e>=t?e:t)),e}function ln(e,t,i,c,d,x){var w,E=t&_,k=t&y,W=t&S;if(i&&(w=d?i(e,c,d,x):i(e)),w!==r)return w;if(!rt(e))return e;var z=be(e);if(z){if(w=_m(e),!E)return Wt(e,w)}else{var Y=Tt(e),te=Y==tt||Y==At;if(Jn(e))return nc(e,E);if(Y==se||Y==Ie||te&&!d){if(w=k||te?{}:yc(e),!E)return k?am(e,Ap(w,e)):om(e,Pl(w,e))}else{if(!Ye[Y])return d?e:{};w=vm(e,Y,E)}}x||(x=new gn);var ae=x.get(e);if(ae)return ae;x.set(e,w),Kc(e)?e.forEach(function(pe){w.add(ln(pe,t,i,pe,e,x))}):Yc(e)&&e.forEach(function(pe,Re){w.set(Re,ln(pe,t,i,Re,e,x))});var he=W?k?No:So:k?Ht:yt,Ne=z?r:he(e);return sn(Ne||e,function(pe,Re){Ne&&(Re=pe,pe=e[Re]),Xr(w,Re,ln(pe,t,i,Re,e,x))}),w}function jp(e){var t=yt(e);return function(i){return Ml(i,e,t)}}function Ml(e,t,i){var c=i.length;if(e==null)return!c;for(e=qe(e);c--;){var d=i[c],x=t[d],w=e[d];if(w===r&&!(d in e)||!x(w))return!1}return!0}function Il(e,t,i){if(typeof e!="function")throw new on(p);return es(function(){e.apply(r,i)},t)}function Yr(e,t,i,c){var d=-1,x=ws,w=!0,E=e.length,k=[],W=t.length;if(!E)return k;i&&(t=et(t,Yt(i))),c?(x=Gi,w=!1):t.length>=u&&(x=Wr,w=!1,t=new cr(t));e:for(;++d<E;){var z=e[d],Y=i==null?z:i(z);if(z=c||z!==0?z:0,w&&Y===Y){for(var te=W;te--;)if(t[te]===Y)continue e;k.push(z)}else x(t,Y,c)||k.push(z)}return k}var Yn=ac(wn),Dl=ac(oo,!0);function Pp(e,t){var i=!0;return Yn(e,function(c,d,x){return i=!!t(c,d,x),i}),i}function Us(e,t,i){for(var c=-1,d=e.length;++c<d;){var x=e[c],w=t(x);if(w!=null&&(E===r?w===w&&!Kt(w):i(w,E)))var E=w,k=x}return k}function Mp(e,t,i,c){var d=e.length;for(i=Ee(i),i<0&&(i=-i>d?0:d+i),c=c===r||c>d?d:Ee(c),c<0&&(c+=d),c=i>c?0:Jc(c);i<c;)e[i++]=t;return e}function Ll(e,t){var i=[];return Yn(e,function(c,d,x){t(c,d,x)&&i.push(c)}),i}function St(e,t,i,c,d){var x=-1,w=e.length;for(i||(i=ym),d||(d=[]);++x<w;){var E=e[x];t>0&&i(E)?t>1?St(E,t-1,i,c,d):$n(d,E):c||(d[d.length]=E)}return d}var io=lc(),Ol=lc(!0);function wn(e,t){return e&&io(e,t,yt)}function oo(e,t){return e&&Ol(e,t,yt)}function Ws(e,t){return Gn(t,function(i){return On(e[i])})}function dr(e,t){t=Kn(t,e);for(var i=0,c=t.length;e!=null&&i<c;)e=e[Sn(t[i++])];return i&&i==c?e:r}function Fl(e,t,i){var c=t(e);return be(e)?c:$n(c,i(e))}function Dt(e){return e==null?e===r?xt:ne:ar&&ar in qe(e)?mm(e):Tm(e)}function ao(e,t){return e>t}function Ip(e,t){return e!=null&&ze.call(e,t)}function Dp(e,t){return e!=null&&t in qe(e)}function Lp(e,t,i){return e>=kt(t,i)&&e<vt(t,i)}function lo(e,t,i){for(var c=i?Gi:ws,d=e[0].length,x=e.length,w=x,E=P(x),k=1/0,W=[];w--;){var z=e[w];w&&t&&(z=et(z,Yt(t))),k=kt(z.length,k),E[w]=!i&&(t||d>=120&&z.length>=120)?new cr(w&&z):r}z=e[0];var Y=-1,te=E[0];e:for(;++Y<d&&W.length<k;){var ae=z[Y],he=t?t(ae):ae;if(ae=i||ae!==0?ae:0,!(te?Wr(te,he):c(W,he,i))){for(w=x;--w;){var Ne=E[w];if(!(Ne?Wr(Ne,he):c(e[w],he,i)))continue e}te&&te.push(he),W.push(ae)}}return W}function Op(e,t,i,c){return wn(e,function(d,x,w){t(c,i(d),x,w)}),c}function Vr(e,t,i){t=Kn(t,e),e=Nc(e,t);var c=e==null?e:e[Sn(un(t))];return c==null?r:Xt(c,e,i)}function Bl(e){return it(e)&&Dt(e)==Ie}function Fp(e){return it(e)&&Dt(e)==ie}function Bp(e){return it(e)&&Dt(e)==Te}function Kr(e,t,i,c,d){return e===t?!0:e==null||t==null||!it(e)&&!it(t)?e!==e&&t!==t:Up(e,t,i,c,Kr,d)}function Up(e,t,i,c,d,x){var w=be(e),E=be(t),k=w?at:Tt(e),W=E?at:Tt(t);k=k==Ie?se:k,W=W==Ie?se:W;var z=k==se,Y=W==se,te=k==W;if(te&&Jn(e)){if(!Jn(t))return!1;w=!0,z=!1}if(te&&!z)return x||(x=new gn),w||Ar(e)?_c(e,t,i,c,d,x):hm(e,t,k,i,c,d,x);if(!(i&N)){var ae=z&&ze.call(e,"__wrapped__"),he=Y&&ze.call(t,"__wrapped__");if(ae||he){var Ne=ae?e.value():e,pe=he?t.value():t;return x||(x=new gn),d(Ne,pe,i,c,x)}}return te?(x||(x=new gn),pm(e,t,i,c,d,x)):!1}function Wp(e){return it(e)&&Tt(e)==Xe}function co(e,t,i,c){var d=i.length,x=d,w=!c;if(e==null)return!x;for(e=qe(e);d--;){var E=i[d];if(w&&E[2]?E[1]!==e[E[0]]:!(E[0]in e))return!1}for(;++d<x;){E=i[d];var k=E[0],W=e[k],z=E[1];if(w&&E[2]){if(W===r&&!(k in e))return!1}else{var Y=new gn;if(c)var te=c(W,z,k,e,t,Y);if(!(te===r?Kr(z,W,N|j,c,Y):te))return!1}}return!0}function Ul(e){if(!rt(e)||Em(e))return!1;var t=On(e)?Wh:Ut;return t.test(hr(e))}function zp(e){return it(e)&&Dt(e)==le}function Hp(e){return it(e)&&Tt(e)==ce}function Gp(e){return it(e)&&si(e.length)&&!!Ve[Dt(e)]}function Wl(e){return typeof e=="function"?e:e==null?Gt:typeof e=="object"?be(e)?Gl(e[0],e[1]):Hl(e):cu(e)}function uo(e){if(!Zr(e))return Xh(e);var t=[];for(var i in qe(e))ze.call(e,i)&&i!="constructor"&&t.push(i);return t}function $p(e){if(!rt(e))return km(e);var t=Zr(e),i=[];for(var c in e)c=="constructor"&&(t||!ze.call(e,c))||i.push(c);return i}function fo(e,t){return e<t}function zl(e,t){var i=-1,c=zt(e)?P(e.length):[];return Yn(e,function(d,x,w){c[++i]=t(d,x,w)}),c}function Hl(e){var t=ko(e);return t.length==1&&t[0][2]?Ec(t[0][0],t[0][1]):function(i){return i===e||co(i,e,t)}}function Gl(e,t){return Ro(e)&&wc(t)?Ec(Sn(e),t):function(i){var c=Bo(i,e);return c===r&&c===t?Uo(i,e):Kr(t,c,N|j)}}function zs(e,t,i,c,d){e!==t&&io(t,function(x,w){if(d||(d=new gn),rt(x))qp(e,t,w,i,zs,c,d);else{var E=c?c(jo(e,w),x,w+"",e,t,d):r;E===r&&(E=x),ro(e,w,E)}},Ht)}function qp(e,t,i,c,d,x,w){var E=jo(e,i),k=jo(t,i),W=w.get(k);if(W){ro(e,i,W);return}var z=x?x(E,k,i+"",e,t,w):r,Y=z===r;if(Y){var te=be(k),ae=!te&&Jn(k),he=!te&&!ae&&Ar(k);z=k,te||ae||he?be(E)?z=E:ct(E)?z=Wt(E):ae?(Y=!1,z=nc(k,!0)):he?(Y=!1,z=rc(k,!0)):z=[]:ts(k)||pr(k)?(z=E,pr(E)?z=Zc(E):(!rt(E)||On(E))&&(z=yc(k))):Y=!1}Y&&(w.set(k,z),d(z,k,c,x,w),w.delete(k)),ro(e,i,z)}function $l(e,t){var i=e.length;if(i)return t+=t<0?i:0,Ln(t,i)?e[t]:r}function ql(e,t,i){t.length?t=et(t,function(x){return be(x)?function(w){return dr(w,x.length===1?x[0]:x)}:x}):t=[Gt];var c=-1;t=et(t,Yt(fe()));var d=zl(e,function(x,w,E){var k=et(t,function(W){return W(x)});return{criteria:k,index:++c,value:x}});return vh(d,function(x,w){return im(x,w,i)})}function Xp(e,t){return Xl(e,t,function(i,c){return Uo(e,c)})}function Xl(e,t,i){for(var c=-1,d=t.length,x={};++c<d;){var w=t[c],E=dr(e,w);i(E,w)&&Qr(x,Kn(w,e),E)}return x}function Yp(e){return function(t){return dr(t,e)}}function ho(e,t,i,c){var d=c?_h:vr,x=-1,w=t.length,E=e;for(e===t&&(t=Wt(t)),i&&(E=et(e,Yt(i)));++x<w;)for(var k=0,W=t[x],z=i?i(W):W;(k=d(E,z,k,c))>-1;)E!==e&&Ps.call(E,k,1),Ps.call(e,k,1);return e}function Yl(e,t){for(var i=e?t.length:0,c=i-1;i--;){var d=t[i];if(i==c||d!==x){var x=d;Ln(d)?Ps.call(e,d,1):xo(e,d)}}return e}function po(e,t){return e+Ds(Tl()*(t-e+1))}function Vp(e,t,i,c){for(var d=-1,x=vt(Is((t-e)/(i||1)),0),w=P(x);x--;)w[c?x:++d]=e,e+=i;return w}function mo(e,t){var i="";if(!e||t<1||t>re)return i;do t%2&&(i+=e),t=Ds(t/2),t&&(e+=e);while(t);return i}function ke(e,t){return Po(Sc(e,t,Gt),e+"")}function Kp(e){return jl(jr(e))}function Qp(e,t){var i=jr(e);return Js(i,ur(t,0,i.length))}function Qr(e,t,i,c){if(!rt(e))return e;t=Kn(t,e);for(var d=-1,x=t.length,w=x-1,E=e;E!=null&&++d<x;){var k=Sn(t[d]),W=i;if(k==="__proto__"||k==="constructor"||k==="prototype")return e;if(d!=w){var z=E[k];W=c?c(z,k,E):r,W===r&&(W=rt(z)?z:Ln(t[d+1])?[]:{})}Xr(E,k,W),E=E[k]}return e}var Vl=Ls?function(e,t){return Ls.set(e,t),e}:Gt,Jp=Ms?function(e,t){return Ms(e,"toString",{configurable:!0,enumerable:!1,value:zo(t),writable:!0})}:Gt;function Zp(e){return Js(jr(e))}function cn(e,t,i){var c=-1,d=e.length;t<0&&(t=-t>d?0:d+t),i=i>d?d:i,i<0&&(i+=d),d=t>i?0:i-t>>>0,t>>>=0;for(var x=P(d);++c<d;)x[c]=e[c+t];return x}function em(e,t){var i;return Yn(e,function(c,d,x){return i=t(c,d,x),!i}),!!i}function Hs(e,t,i){var c=0,d=e==null?c:e.length;if(typeof t=="number"&&t===t&&d<=je){for(;c<d;){var x=c+d>>>1,w=e[x];w!==null&&!Kt(w)&&(i?w<=t:w<t)?c=x+1:d=x}return d}return go(e,t,Gt,i)}function go(e,t,i,c){var d=0,x=e==null?0:e.length;if(x===0)return 0;t=i(t);for(var w=t!==t,E=t===null,k=Kt(t),W=t===r;d<x;){var z=Ds((d+x)/2),Y=i(e[z]),te=Y!==r,ae=Y===null,he=Y===Y,Ne=Kt(Y);if(w)var pe=c||he;else W?pe=he&&(c||te):E?pe=he&&te&&(c||!ae):k?pe=he&&te&&!ae&&(c||!Ne):ae||Ne?pe=!1:pe=c?Y<=t:Y<t;pe?d=z+1:x=z}return kt(x,Se)}function Kl(e,t){for(var i=-1,c=e.length,d=0,x=[];++i<c;){var w=e[i],E=t?t(w):w;if(!i||!xn(E,k)){var k=E;x[d++]=w===0?0:w}}return x}function Ql(e){return typeof e=="number"?e:Kt(e)?ue:+e}function Vt(e){if(typeof e=="string")return e;if(be(e))return et(e,Vt)+"";if(Kt(e))return Rl?Rl.call(e):"";var t=e+"";return t=="0"&&1/e==-O?"-0":t}function Vn(e,t,i){var c=-1,d=ws,x=e.length,w=!0,E=[],k=E;if(i)w=!1,d=Gi;else if(x>=u){var W=t?null:dm(e);if(W)return Ss(W);w=!1,d=Wr,k=new cr}else k=t?[]:E;e:for(;++c<x;){var z=e[c],Y=t?t(z):z;if(z=i||z!==0?z:0,w&&Y===Y){for(var te=k.length;te--;)if(k[te]===Y)continue e;t&&k.push(Y),E.push(z)}else d(k,Y,i)||(k!==E&&k.push(Y),E.push(z))}return E}function xo(e,t){return t=Kn(t,e),e=Nc(e,t),e==null||delete e[Sn(un(t))]}function Jl(e,t,i,c){return Qr(e,t,i(dr(e,t)),c)}function Gs(e,t,i,c){for(var d=e.length,x=c?d:-1;(c?x--:++x<d)&&t(e[x],x,e););return i?cn(e,c?0:x,c?x+1:d):cn(e,c?x+1:0,c?d:x)}function Zl(e,t){var i=e;return i instanceof Me&&(i=i.value()),$i(t,function(c,d){return d.func.apply(d.thisArg,$n([c],d.args))},i)}function _o(e,t,i){var c=e.length;if(c<2)return c?Vn(e[0]):[];for(var d=-1,x=P(c);++d<c;)for(var w=e[d],E=-1;++E<c;)E!=d&&(x[d]=Yr(x[d]||w,e[E],t,i));return Vn(St(x,1),t,i)}function ec(e,t,i){for(var c=-1,d=e.length,x=t.length,w={};++c<d;){var E=c<x?t[c]:r;i(w,e[c],E)}return w}function vo(e){return ct(e)?e:[]}function bo(e){return typeof e=="function"?e:Gt}function Kn(e,t){return be(e)?e:Ro(e,t)?[e]:Rc(Ue(e))}var tm=ke;function Qn(e,t,i){var c=e.length;return i=i===r?c:i,!t&&i>=c?e:cn(e,t,i)}var tc=zh||function(e){return Et.clearTimeout(e)};function nc(e,t){if(t)return e.slice();var i=e.length,c=El?El(i):new e.constructor(i);return e.copy(c),c}function yo(e){var t=new e.constructor(e.byteLength);return new As(t).set(new As(e)),t}function nm(e,t){var i=t?yo(e.buffer):e.buffer;return new e.constructor(i,e.byteOffset,e.byteLength)}function rm(e){var t=new e.constructor(e.source,Ur.exec(e));return t.lastIndex=e.lastIndex,t}function sm(e){return qr?qe(qr.call(e)):{}}function rc(e,t){var i=t?yo(e.buffer):e.buffer;return new e.constructor(i,e.byteOffset,e.length)}function sc(e,t){if(e!==t){var i=e!==r,c=e===null,d=e===e,x=Kt(e),w=t!==r,E=t===null,k=t===t,W=Kt(t);if(!E&&!W&&!x&&e>t||x&&w&&k&&!E&&!W||c&&w&&k||!i&&k||!d)return 1;if(!c&&!x&&!W&&e<t||W&&i&&d&&!c&&!x||E&&i&&d||!w&&d||!k)return-1}return 0}function im(e,t,i){for(var c=-1,d=e.criteria,x=t.criteria,w=d.length,E=i.length;++c<w;){var k=sc(d[c],x[c]);if(k){if(c>=E)return k;var W=i[c];return k*(W=="desc"?-1:1)}}return e.index-t.index}function ic(e,t,i,c){for(var d=-1,x=e.length,w=i.length,E=-1,k=t.length,W=vt(x-w,0),z=P(k+W),Y=!c;++E<k;)z[E]=t[E];for(;++d<w;)(Y||d<x)&&(z[i[d]]=e[d]);for(;W--;)z[E++]=e[d++];return z}function oc(e,t,i,c){for(var d=-1,x=e.length,w=-1,E=i.length,k=-1,W=t.length,z=vt(x-E,0),Y=P(z+W),te=!c;++d<z;)Y[d]=e[d];for(var ae=d;++k<W;)Y[ae+k]=t[k];for(;++w<E;)(te||d<x)&&(Y[ae+i[w]]=e[d++]);return Y}function Wt(e,t){var i=-1,c=e.length;for(t||(t=P(c));++i<c;)t[i]=e[i];return t}function En(e,t,i,c){var d=!i;i||(i={});for(var x=-1,w=t.length;++x<w;){var E=t[x],k=c?c(i[E],e[E],E,i,e):r;k===r&&(k=e[E]),d?Mn(i,E,k):Xr(i,E,k)}return i}function om(e,t){return En(e,To(e),t)}function am(e,t){return En(e,vc(e),t)}function $s(e,t){return function(i,c){var d=be(i)?fh:Rp,x=t?t():{};return d(i,e,fe(c,2),x)}}function kr(e){return ke(function(t,i){var c=-1,d=i.length,x=d>1?i[d-1]:r,w=d>2?i[2]:r;for(x=e.length>3&&typeof x=="function"?(d--,x):r,w&&Lt(i[0],i[1],w)&&(x=d<3?r:x,d=1),t=qe(t);++c<d;){var E=i[c];E&&e(t,E,c,x)}return t})}function ac(e,t){return function(i,c){if(i==null)return i;if(!zt(i))return e(i,c);for(var d=i.length,x=t?d:-1,w=qe(i);(t?x--:++x<d)&&c(w[x],x,w)!==!1;);return i}}function lc(e){return function(t,i,c){for(var d=-1,x=qe(t),w=c(t),E=w.length;E--;){var k=w[e?E:++d];if(i(x[k],k,x)===!1)break}return t}}function lm(e,t,i){var c=t&R,d=Jr(e);function x(){var w=this&&this!==Et&&this instanceof x?d:e;return w.apply(c?i:this,arguments)}return x}function cc(e){return function(t){t=Ue(t);var i=br(t)?mn(t):r,c=i?i[0]:t.charAt(0),d=i?Qn(i,1).join(""):t.slice(1);return c[e]()+d}}function Tr(e){return function(t){return $i(au(ou(t).replace(Jf,"")),e,"")}}function Jr(e){return function(){var t=arguments;switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3]);case 5:return new e(t[0],t[1],t[2],t[3],t[4]);case 6:return new e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return new e(t[0],t[1],t[2],t[3],t[4],t[5],t[6])}var i=Cr(e.prototype),c=e.apply(i,t);return rt(c)?c:i}}function cm(e,t,i){var c=Jr(e);function d(){for(var x=arguments.length,w=P(x),E=x,k=Rr(d);E--;)w[E]=arguments[E];var W=x<3&&w[0]!==k&&w[x-1]!==k?[]:qn(w,k);if(x-=W.length,x<i)return pc(e,t,qs,d.placeholder,r,w,W,r,r,i-x);var z=this&&this!==Et&&this instanceof d?c:e;return Xt(z,this,w)}return d}function uc(e){return function(t,i,c){var d=qe(t);if(!zt(t)){var x=fe(i,3);t=yt(t),i=function(E){return x(d[E],E,d)}}var w=e(t,i,c);return w>-1?d[x?t[w]:w]:r}}function dc(e){return Dn(function(t){var i=t.length,c=i,d=an.prototype.thru;for(e&&t.reverse();c--;){var x=t[c];if(typeof x!="function")throw new on(p);if(d&&!w&&Ks(x)=="wrapper")var w=new an([],!0)}for(c=w?c:i;++c<i;){x=t[c];var E=Ks(x),k=E=="wrapper"?Co(x):r;k&&Ao(k[0])&&k[1]==(K|A|q|V)&&!k[4].length&&k[9]==1?w=w[Ks(k[0])].apply(w,k[3]):w=x.length==1&&Ao(x)?w[E]():w.thru(x)}return function(){var W=arguments,z=W[0];if(w&&W.length==1&&be(z))return w.plant(z).value();for(var Y=0,te=i?t[Y].apply(this,W):z;++Y<i;)te=t[Y].call(this,te);return te}})}function qs(e,t,i,c,d,x,w,E,k,W){var z=t&K,Y=t&R,te=t&M,ae=t&(A|G),he=t&U,Ne=te?r:Jr(e);function pe(){for(var Re=arguments.length,De=P(Re),Qt=Re;Qt--;)De[Qt]=arguments[Qt];if(ae)var Ot=Rr(pe),Jt=yh(De,Ot);if(c&&(De=ic(De,c,d,ae)),x&&(De=oc(De,x,w,ae)),Re-=Jt,ae&&Re<W){var ut=qn(De,Ot);return pc(e,t,qs,pe.placeholder,i,De,ut,E,k,W-Re)}var _n=Y?i:this,Bn=te?_n[e]:e;return Re=De.length,E?De=Rm(De,E):he&&Re>1&&De.reverse(),z&&k<Re&&(De.length=k),this&&this!==Et&&this instanceof pe&&(Bn=Ne||Jr(Bn)),Bn.apply(_n,De)}return pe}function fc(e,t){return function(i,c){return Op(i,e,t(c),{})}}function Xs(e,t){return function(i,c){var d;if(i===r&&c===r)return t;if(i!==r&&(d=i),c!==r){if(d===r)return c;typeof i=="string"||typeof c=="string"?(i=Vt(i),c=Vt(c)):(i=Ql(i),c=Ql(c)),d=e(i,c)}return d}}function wo(e){return Dn(function(t){return t=et(t,Yt(fe())),ke(function(i){var c=this;return e(t,function(d){return Xt(d,c,i)})})})}function Ys(e,t){t=t===r?" ":Vt(t);var i=t.length;if(i<2)return i?mo(t,e):t;var c=mo(t,Is(e/yr(t)));return br(t)?Qn(mn(c),0,e).join(""):c.slice(0,e)}function um(e,t,i,c){var d=t&R,x=Jr(e);function w(){for(var E=-1,k=arguments.length,W=-1,z=c.length,Y=P(z+k),te=this&&this!==Et&&this instanceof w?x:e;++W<z;)Y[W]=c[W];for(;k--;)Y[W++]=arguments[++E];return Xt(te,d?i:this,Y)}return w}function hc(e){return function(t,i,c){return c&&typeof c!="number"&&Lt(t,i,c)&&(i=c=r),t=Fn(t),i===r?(i=t,t=0):i=Fn(i),c=c===r?t<i?1:-1:Fn(c),Vp(t,i,c,e)}}function Vs(e){return function(t,i){return typeof t=="string"&&typeof i=="string"||(t=dn(t),i=dn(i)),e(t,i)}}function pc(e,t,i,c,d,x,w,E,k,W){var z=t&A,Y=z?w:r,te=z?r:w,ae=z?x:r,he=z?r:x;t|=z?q:X,t&=~(z?X:q),t&F||(t&=-4);var Ne=[e,t,d,ae,Y,he,te,E,k,W],pe=i.apply(r,Ne);return Ao(e)&&Cc(pe,Ne),pe.placeholder=c,kc(pe,e,t)}function Eo(e){var t=_t[e];return function(i,c){if(i=dn(i),c=c==null?0:kt(Ee(c),292),c&&kl(i)){var d=(Ue(i)+"e").split("e"),x=t(d[0]+"e"+(+d[1]+c));return d=(Ue(x)+"e").split("e"),+(d[0]+"e"+(+d[1]-c))}return t(i)}}var dm=Sr&&1/Ss(new Sr([,-0]))[1]==O?function(e){return new Sr(e)}:$o;function mc(e){return function(t){var i=Tt(t);return i==Xe?Ji(t):i==ce?Th(t):bh(t,e(t))}}function In(e,t,i,c,d,x,w,E){var k=t&M;if(!k&&typeof e!="function")throw new on(p);var W=c?c.length:0;if(W||(t&=-97,c=d=r),w=w===r?w:vt(Ee(w),0),E=E===r?E:Ee(E),W-=d?d.length:0,t&X){var z=c,Y=d;c=d=r}var te=k?r:Co(e),ae=[e,t,i,c,d,z,Y,x,w,E];if(te&&Cm(ae,te),e=ae[0],t=ae[1],i=ae[2],c=ae[3],d=ae[4],E=ae[9]=ae[9]===r?k?0:e.length:vt(ae[9]-W,0),!E&&t&(A|G)&&(t&=-25),!t||t==R)var he=lm(e,t,i);else t==A||t==G?he=cm(e,t,E):(t==q||t==(R|q))&&!d.length?he=um(e,t,i,c):he=qs.apply(r,ae);var Ne=te?Vl:Cc;return kc(Ne(he,ae),e,t)}function gc(e,t,i,c){return e===r||xn(e,Er[i])&&!ze.call(c,i)?t:e}function xc(e,t,i,c,d,x){return rt(e)&&rt(t)&&(x.set(t,e),zs(e,t,r,xc,x),x.delete(t)),e}function fm(e){return ts(e)?r:e}function _c(e,t,i,c,d,x){var w=i&N,E=e.length,k=t.length;if(E!=k&&!(w&&k>E))return!1;var W=x.get(e),z=x.get(t);if(W&&z)return W==t&&z==e;var Y=-1,te=!0,ae=i&j?new cr:r;for(x.set(e,t),x.set(t,e);++Y<E;){var he=e[Y],Ne=t[Y];if(c)var pe=w?c(Ne,he,Y,t,e,x):c(he,Ne,Y,e,t,x);if(pe!==r){if(pe)continue;te=!1;break}if(ae){if(!qi(t,function(Re,De){if(!Wr(ae,De)&&(he===Re||d(he,Re,i,c,x)))return ae.push(De)})){te=!1;break}}else if(!(he===Ne||d(he,Ne,i,c,x))){te=!1;break}}return x.delete(e),x.delete(t),te}function hm(e,t,i,c,d,x,w){switch(i){case ge:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case ie:return!(e.byteLength!=t.byteLength||!x(new As(e),new As(t)));case Ge:case Te:case gt:return xn(+e,+t);case mt:return e.name==t.name&&e.message==t.message;case le:case Ce:return e==t+"";case Xe:var E=Ji;case ce:var k=c&N;if(E||(E=Ss),e.size!=t.size&&!k)return!1;var W=w.get(e);if(W)return W==t;c|=j,w.set(e,t);var z=_c(E(e),E(t),c,d,x,w);return w.delete(e),z;case we:if(qr)return qr.call(e)==qr.call(t)}return!1}function pm(e,t,i,c,d,x){var w=i&N,E=So(e),k=E.length,W=So(t),z=W.length;if(k!=z&&!w)return!1;for(var Y=k;Y--;){var te=E[Y];if(!(w?te in t:ze.call(t,te)))return!1}var ae=x.get(e),he=x.get(t);if(ae&&he)return ae==t&&he==e;var Ne=!0;x.set(e,t),x.set(t,e);for(var pe=w;++Y<k;){te=E[Y];var Re=e[te],De=t[te];if(c)var Qt=w?c(De,Re,te,t,e,x):c(Re,De,te,e,t,x);if(!(Qt===r?Re===De||d(Re,De,i,c,x):Qt)){Ne=!1;break}pe||(pe=te=="constructor")}if(Ne&&!pe){var Ot=e.constructor,Jt=t.constructor;Ot!=Jt&&"constructor"in e&&"constructor"in t&&!(typeof Ot=="function"&&Ot instanceof Ot&&typeof Jt=="function"&&Jt instanceof Jt)&&(Ne=!1)}return x.delete(e),x.delete(t),Ne}function Dn(e){return Po(Sc(e,r,Mc),e+"")}function So(e){return Fl(e,yt,To)}function No(e){return Fl(e,Ht,vc)}var Co=Ls?function(e){return Ls.get(e)}:$o;function Ks(e){for(var t=e.name+"",i=Nr[t],c=ze.call(Nr,t)?i.length:0;c--;){var d=i[c],x=d.func;if(x==null||x==e)return d.name}return t}function Rr(e){var t=ze.call(m,"placeholder")?m:e;return t.placeholder}function fe(){var e=m.iteratee||Ho;return e=e===Ho?Wl:e,arguments.length?e(arguments[0],arguments[1]):e}function Qs(e,t){var i=e.__data__;return wm(t)?i[typeof t=="string"?"string":"hash"]:i.map}function ko(e){for(var t=yt(e),i=t.length;i--;){var c=t[i],d=e[c];t[i]=[c,d,wc(d)]}return t}function fr(e,t){var i=Nh(e,t);return Ul(i)?i:r}function mm(e){var t=ze.call(e,ar),i=e[ar];try{e[ar]=r;var c=!0}catch{}var d=Ts.call(e);return c&&(t?e[ar]=i:delete e[ar]),d}var To=eo?function(e){return e==null?[]:(e=qe(e),Gn(eo(e),function(t){return Nl.call(e,t)}))}:qo,vc=eo?function(e){for(var t=[];e;)$n(t,To(e)),e=js(e);return t}:qo,Tt=Dt;(to&&Tt(new to(new ArrayBuffer(1)))!=ge||Hr&&Tt(new Hr)!=Xe||no&&Tt(no.resolve())!=L||Sr&&Tt(new Sr)!=ce||Gr&&Tt(new Gr)!=bt)&&(Tt=function(e){var t=Dt(e),i=t==se?e.constructor:r,c=i?hr(i):"";if(c)switch(c){case Qh:return ge;case Jh:return Xe;case Zh:return L;case ep:return ce;case tp:return bt}return t});function gm(e,t,i){for(var c=-1,d=i.length;++c<d;){var x=i[c],w=x.size;switch(x.type){case"drop":e+=w;break;case"dropRight":t-=w;break;case"take":t=kt(t,e+w);break;case"takeRight":e=vt(e,t-w);break}}return{start:e,end:t}}function xm(e){var t=e.match(nt);return t?t[1].split(yn):[]}function bc(e,t,i){t=Kn(t,e);for(var c=-1,d=t.length,x=!1;++c<d;){var w=Sn(t[c]);if(!(x=e!=null&&i(e,w)))break;e=e[w]}return x||++c!=d?x:(d=e==null?0:e.length,!!d&&si(d)&&Ln(w,d)&&(be(e)||pr(e)))}function _m(e){var t=e.length,i=new e.constructor(t);return t&&typeof e[0]=="string"&&ze.call(e,"index")&&(i.index=e.index,i.input=e.input),i}function yc(e){return typeof e.constructor=="function"&&!Zr(e)?Cr(js(e)):{}}function vm(e,t,i){var c=e.constructor;switch(t){case ie:return yo(e);case Ge:case Te:return new c(+e);case ge:return nm(e,i);case Ke:case Ft:case st:case en:case jt:case tn:case Qe:case Ct:case Pt:return rc(e,i);case Xe:return new c;case gt:case Ce:return new c(e);case le:return rm(e);case ce:return new c;case we:return sm(e)}}function bm(e,t){var i=t.length;if(!i)return e;var c=i-1;return t[c]=(i>1?"& ":"")+t[c],t=t.join(i>2?", ":" "),e.replace(xe,`{
7
- /* [wrapped with `+t+`] */
8
- `)}function ym(e){return be(e)||pr(e)||!!(Cl&&e&&e[Cl])}function Ln(e,t){var i=typeof e;return t=t??re,!!t&&(i=="number"||i!="symbol"&&nn.test(e))&&e>-1&&e%1==0&&e<t}function Lt(e,t,i){if(!rt(i))return!1;var c=typeof t;return(c=="number"?zt(i)&&Ln(t,i.length):c=="string"&&t in i)?xn(i[t],e):!1}function Ro(e,t){if(be(e))return!1;var i=typeof e;return i=="number"||i=="symbol"||i=="boolean"||e==null||Kt(e)?!0:Ii.test(e)||!Mi.test(e)||t!=null&&e in qe(t)}function wm(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Ao(e){var t=Ks(e),i=m[t];if(typeof i!="function"||!(t in Me.prototype))return!1;if(e===i)return!0;var c=Co(i);return!!c&&e===c[0]}function Em(e){return!!wl&&wl in e}var Sm=Cs?On:Xo;function Zr(e){var t=e&&e.constructor,i=typeof t=="function"&&t.prototype||Er;return e===i}function wc(e){return e===e&&!rt(e)}function Ec(e,t){return function(i){return i==null?!1:i[e]===t&&(t!==r||e in qe(i))}}function Nm(e){var t=ni(e,function(c){return i.size===g&&i.clear(),c}),i=t.cache;return t}function Cm(e,t){var i=e[1],c=t[1],d=i|c,x=d<(R|M|K),w=c==K&&i==A||c==K&&i==V&&e[7].length<=t[8]||c==(K|V)&&t[7].length<=t[8]&&i==A;if(!(x||w))return e;c&R&&(e[2]=t[2],d|=i&R?0:F);var E=t[3];if(E){var k=e[3];e[3]=k?ic(k,E,t[4]):E,e[4]=k?qn(e[3],h):t[4]}return E=t[5],E&&(k=e[5],e[5]=k?oc(k,E,t[6]):E,e[6]=k?qn(e[5],h):t[6]),E=t[7],E&&(e[7]=E),c&K&&(e[8]=e[8]==null?t[8]:kt(e[8],t[8])),e[9]==null&&(e[9]=t[9]),e[0]=t[0],e[1]=d,e}function km(e){var t=[];if(e!=null)for(var i in qe(e))t.push(i);return t}function Tm(e){return Ts.call(e)}function Sc(e,t,i){return t=vt(t===r?e.length-1:t,0),function(){for(var c=arguments,d=-1,x=vt(c.length-t,0),w=P(x);++d<x;)w[d]=c[t+d];d=-1;for(var E=P(t+1);++d<t;)E[d]=c[d];return E[t]=i(w),Xt(e,this,E)}}function Nc(e,t){return t.length<2?e:dr(e,cn(t,0,-1))}function Rm(e,t){for(var i=e.length,c=kt(t.length,i),d=Wt(e);c--;){var x=t[c];e[c]=Ln(x,i)?d[x]:r}return e}function jo(e,t){if(!(t==="constructor"&&typeof e[t]=="function")&&t!="__proto__")return e[t]}var Cc=Tc(Vl),es=Gh||function(e,t){return Et.setTimeout(e,t)},Po=Tc(Jp);function kc(e,t,i){var c=t+"";return Po(e,bm(c,Am(xm(c),i)))}function Tc(e){var t=0,i=0;return function(){var c=Yh(),d=ye-(c-i);if(i=c,d>0){if(++t>=me)return arguments[0]}else t=0;return e.apply(r,arguments)}}function Js(e,t){var i=-1,c=e.length,d=c-1;for(t=t===r?c:t;++i<t;){var x=po(i,d),w=e[x];e[x]=e[i],e[i]=w}return e.length=t,e}var Rc=Nm(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(Di,function(i,c,d,x){t.push(d?x.replace(ht,"$1"):c||i)}),t});function Sn(e){if(typeof e=="string"||Kt(e))return e;var t=e+"";return t=="0"&&1/e==-O?"-0":t}function hr(e){if(e!=null){try{return ks.call(e)}catch{}try{return e+""}catch{}}return""}function Am(e,t){return sn(Fe,function(i){var c="_."+i[0];t&i[1]&&!ws(e,c)&&e.push(c)}),e.sort()}function Ac(e){if(e instanceof Me)return e.clone();var t=new an(e.__wrapped__,e.__chain__);return t.__actions__=Wt(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t}function jm(e,t,i){(i?Lt(e,t,i):t===r)?t=1:t=vt(Ee(t),0);var c=e==null?0:e.length;if(!c||t<1)return[];for(var d=0,x=0,w=P(Is(c/t));d<c;)w[x++]=cn(e,d,d+=t);return w}function Pm(e){for(var t=-1,i=e==null?0:e.length,c=0,d=[];++t<i;){var x=e[t];x&&(d[c++]=x)}return d}function Mm(){var e=arguments.length;if(!e)return[];for(var t=P(e-1),i=arguments[0],c=e;c--;)t[c-1]=arguments[c];return $n(be(i)?Wt(i):[i],St(t,1))}var Im=ke(function(e,t){return ct(e)?Yr(e,St(t,1,ct,!0)):[]}),Dm=ke(function(e,t){var i=un(t);return ct(i)&&(i=r),ct(e)?Yr(e,St(t,1,ct,!0),fe(i,2)):[]}),Lm=ke(function(e,t){var i=un(t);return ct(i)&&(i=r),ct(e)?Yr(e,St(t,1,ct,!0),r,i):[]});function Om(e,t,i){var c=e==null?0:e.length;return c?(t=i||t===r?1:Ee(t),cn(e,t<0?0:t,c)):[]}function Fm(e,t,i){var c=e==null?0:e.length;return c?(t=i||t===r?1:Ee(t),t=c-t,cn(e,0,t<0?0:t)):[]}function Bm(e,t){return e&&e.length?Gs(e,fe(t,3),!0,!0):[]}function Um(e,t){return e&&e.length?Gs(e,fe(t,3),!0):[]}function Wm(e,t,i,c){var d=e==null?0:e.length;return d?(i&&typeof i!="number"&&Lt(e,t,i)&&(i=0,c=d),Mp(e,t,i,c)):[]}function jc(e,t,i){var c=e==null?0:e.length;if(!c)return-1;var d=i==null?0:Ee(i);return d<0&&(d=vt(c+d,0)),Es(e,fe(t,3),d)}function Pc(e,t,i){var c=e==null?0:e.length;if(!c)return-1;var d=c-1;return i!==r&&(d=Ee(i),d=i<0?vt(c+d,0):kt(d,c-1)),Es(e,fe(t,3),d,!0)}function Mc(e){var t=e==null?0:e.length;return t?St(e,1):[]}function zm(e){var t=e==null?0:e.length;return t?St(e,O):[]}function Hm(e,t){var i=e==null?0:e.length;return i?(t=t===r?1:Ee(t),St(e,t)):[]}function Gm(e){for(var t=-1,i=e==null?0:e.length,c={};++t<i;){var d=e[t];c[d[0]]=d[1]}return c}function Ic(e){return e&&e.length?e[0]:r}function $m(e,t,i){var c=e==null?0:e.length;if(!c)return-1;var d=i==null?0:Ee(i);return d<0&&(d=vt(c+d,0)),vr(e,t,d)}function qm(e){var t=e==null?0:e.length;return t?cn(e,0,-1):[]}var Xm=ke(function(e){var t=et(e,vo);return t.length&&t[0]===e[0]?lo(t):[]}),Ym=ke(function(e){var t=un(e),i=et(e,vo);return t===un(i)?t=r:i.pop(),i.length&&i[0]===e[0]?lo(i,fe(t,2)):[]}),Vm=ke(function(e){var t=un(e),i=et(e,vo);return t=typeof t=="function"?t:r,t&&i.pop(),i.length&&i[0]===e[0]?lo(i,r,t):[]});function Km(e,t){return e==null?"":qh.call(e,t)}function un(e){var t=e==null?0:e.length;return t?e[t-1]:r}function Qm(e,t,i){var c=e==null?0:e.length;if(!c)return-1;var d=c;return i!==r&&(d=Ee(i),d=d<0?vt(c+d,0):kt(d,c-1)),t===t?Ah(e,t,d):Es(e,pl,d,!0)}function Jm(e,t){return e&&e.length?$l(e,Ee(t)):r}var Zm=ke(Dc);function Dc(e,t){return e&&e.length&&t&&t.length?ho(e,t):e}function e0(e,t,i){return e&&e.length&&t&&t.length?ho(e,t,fe(i,2)):e}function t0(e,t,i){return e&&e.length&&t&&t.length?ho(e,t,r,i):e}var n0=Dn(function(e,t){var i=e==null?0:e.length,c=so(e,t);return Yl(e,et(t,function(d){return Ln(d,i)?+d:d}).sort(sc)),c});function r0(e,t){var i=[];if(!(e&&e.length))return i;var c=-1,d=[],x=e.length;for(t=fe(t,3);++c<x;){var w=e[c];t(w,c,e)&&(i.push(w),d.push(c))}return Yl(e,d),i}function Mo(e){return e==null?e:Kh.call(e)}function s0(e,t,i){var c=e==null?0:e.length;return c?(i&&typeof i!="number"&&Lt(e,t,i)?(t=0,i=c):(t=t==null?0:Ee(t),i=i===r?c:Ee(i)),cn(e,t,i)):[]}function i0(e,t){return Hs(e,t)}function o0(e,t,i){return go(e,t,fe(i,2))}function a0(e,t){var i=e==null?0:e.length;if(i){var c=Hs(e,t);if(c<i&&xn(e[c],t))return c}return-1}function l0(e,t){return Hs(e,t,!0)}function c0(e,t,i){return go(e,t,fe(i,2),!0)}function u0(e,t){var i=e==null?0:e.length;if(i){var c=Hs(e,t,!0)-1;if(xn(e[c],t))return c}return-1}function d0(e){return e&&e.length?Kl(e):[]}function f0(e,t){return e&&e.length?Kl(e,fe(t,2)):[]}function h0(e){var t=e==null?0:e.length;return t?cn(e,1,t):[]}function p0(e,t,i){return e&&e.length?(t=i||t===r?1:Ee(t),cn(e,0,t<0?0:t)):[]}function m0(e,t,i){var c=e==null?0:e.length;return c?(t=i||t===r?1:Ee(t),t=c-t,cn(e,t<0?0:t,c)):[]}function g0(e,t){return e&&e.length?Gs(e,fe(t,3),!1,!0):[]}function x0(e,t){return e&&e.length?Gs(e,fe(t,3)):[]}var _0=ke(function(e){return Vn(St(e,1,ct,!0))}),v0=ke(function(e){var t=un(e);return ct(t)&&(t=r),Vn(St(e,1,ct,!0),fe(t,2))}),b0=ke(function(e){var t=un(e);return t=typeof t=="function"?t:r,Vn(St(e,1,ct,!0),r,t)});function y0(e){return e&&e.length?Vn(e):[]}function w0(e,t){return e&&e.length?Vn(e,fe(t,2)):[]}function E0(e,t){return t=typeof t=="function"?t:r,e&&e.length?Vn(e,r,t):[]}function Io(e){if(!(e&&e.length))return[];var t=0;return e=Gn(e,function(i){if(ct(i))return t=vt(i.length,t),!0}),Ki(t,function(i){return et(e,Xi(i))})}function Lc(e,t){if(!(e&&e.length))return[];var i=Io(e);return t==null?i:et(i,function(c){return Xt(t,r,c)})}var S0=ke(function(e,t){return ct(e)?Yr(e,t):[]}),N0=ke(function(e){return _o(Gn(e,ct))}),C0=ke(function(e){var t=un(e);return ct(t)&&(t=r),_o(Gn(e,ct),fe(t,2))}),k0=ke(function(e){var t=un(e);return t=typeof t=="function"?t:r,_o(Gn(e,ct),r,t)}),T0=ke(Io);function R0(e,t){return ec(e||[],t||[],Xr)}function A0(e,t){return ec(e||[],t||[],Qr)}var j0=ke(function(e){var t=e.length,i=t>1?e[t-1]:r;return i=typeof i=="function"?(e.pop(),i):r,Lc(e,i)});function Oc(e){var t=m(e);return t.__chain__=!0,t}function P0(e,t){return t(e),e}function Zs(e,t){return t(e)}var M0=Dn(function(e){var t=e.length,i=t?e[0]:0,c=this.__wrapped__,d=function(x){return so(x,e)};return t>1||this.__actions__.length||!(c instanceof Me)||!Ln(i)?this.thru(d):(c=c.slice(i,+i+(t?1:0)),c.__actions__.push({func:Zs,args:[d],thisArg:r}),new an(c,this.__chain__).thru(function(x){return t&&!x.length&&x.push(r),x}))});function I0(){return Oc(this)}function D0(){return new an(this.value(),this.__chain__)}function L0(){this.__values__===r&&(this.__values__=Qc(this.value()));var e=this.__index__>=this.__values__.length,t=e?r:this.__values__[this.__index__++];return{done:e,value:t}}function O0(){return this}function F0(e){for(var t,i=this;i instanceof Fs;){var c=Ac(i);c.__index__=0,c.__values__=r,t?d.__wrapped__=c:t=c;var d=c;i=i.__wrapped__}return d.__wrapped__=e,t}function B0(){var e=this.__wrapped__;if(e instanceof Me){var t=e;return this.__actions__.length&&(t=new Me(this)),t=t.reverse(),t.__actions__.push({func:Zs,args:[Mo],thisArg:r}),new an(t,this.__chain__)}return this.thru(Mo)}function U0(){return Zl(this.__wrapped__,this.__actions__)}var W0=$s(function(e,t,i){ze.call(e,i)?++e[i]:Mn(e,i,1)});function z0(e,t,i){var c=be(e)?fl:Pp;return i&&Lt(e,t,i)&&(t=r),c(e,fe(t,3))}function H0(e,t){var i=be(e)?Gn:Ll;return i(e,fe(t,3))}var G0=uc(jc),$0=uc(Pc);function q0(e,t){return St(ei(e,t),1)}function X0(e,t){return St(ei(e,t),O)}function Y0(e,t,i){return i=i===r?1:Ee(i),St(ei(e,t),i)}function Fc(e,t){var i=be(e)?sn:Yn;return i(e,fe(t,3))}function Bc(e,t){var i=be(e)?hh:Dl;return i(e,fe(t,3))}var V0=$s(function(e,t,i){ze.call(e,i)?e[i].push(t):Mn(e,i,[t])});function K0(e,t,i,c){e=zt(e)?e:jr(e),i=i&&!c?Ee(i):0;var d=e.length;return i<0&&(i=vt(d+i,0)),ii(e)?i<=d&&e.indexOf(t,i)>-1:!!d&&vr(e,t,i)>-1}var Q0=ke(function(e,t,i){var c=-1,d=typeof t=="function",x=zt(e)?P(e.length):[];return Yn(e,function(w){x[++c]=d?Xt(t,w,i):Vr(w,t,i)}),x}),J0=$s(function(e,t,i){Mn(e,i,t)});function ei(e,t){var i=be(e)?et:zl;return i(e,fe(t,3))}function Z0(e,t,i,c){return e==null?[]:(be(t)||(t=t==null?[]:[t]),i=c?r:i,be(i)||(i=i==null?[]:[i]),ql(e,t,i))}var eg=$s(function(e,t,i){e[i?0:1].push(t)},function(){return[[],[]]});function tg(e,t,i){var c=be(e)?$i:gl,d=arguments.length<3;return c(e,fe(t,4),i,d,Yn)}function ng(e,t,i){var c=be(e)?ph:gl,d=arguments.length<3;return c(e,fe(t,4),i,d,Dl)}function rg(e,t){var i=be(e)?Gn:Ll;return i(e,ri(fe(t,3)))}function sg(e){var t=be(e)?jl:Kp;return t(e)}function ig(e,t,i){(i?Lt(e,t,i):t===r)?t=1:t=Ee(t);var c=be(e)?kp:Qp;return c(e,t)}function og(e){var t=be(e)?Tp:Zp;return t(e)}function ag(e){if(e==null)return 0;if(zt(e))return ii(e)?yr(e):e.length;var t=Tt(e);return t==Xe||t==ce?e.size:uo(e).length}function lg(e,t,i){var c=be(e)?qi:em;return i&&Lt(e,t,i)&&(t=r),c(e,fe(t,3))}var cg=ke(function(e,t){if(e==null)return[];var i=t.length;return i>1&&Lt(e,t[0],t[1])?t=[]:i>2&&Lt(t[0],t[1],t[2])&&(t=[t[0]]),ql(e,St(t,1),[])}),ti=Hh||function(){return Et.Date.now()};function ug(e,t){if(typeof t!="function")throw new on(p);return e=Ee(e),function(){if(--e<1)return t.apply(this,arguments)}}function Uc(e,t,i){return t=i?r:t,t=e&&t==null?e.length:t,In(e,K,r,r,r,r,t)}function Wc(e,t){var i;if(typeof t!="function")throw new on(p);return e=Ee(e),function(){return--e>0&&(i=t.apply(this,arguments)),e<=1&&(t=r),i}}var Do=ke(function(e,t,i){var c=R;if(i.length){var d=qn(i,Rr(Do));c|=q}return In(e,c,t,i,d)}),zc=ke(function(e,t,i){var c=R|M;if(i.length){var d=qn(i,Rr(zc));c|=q}return In(t,c,e,i,d)});function Hc(e,t,i){t=i?r:t;var c=In(e,A,r,r,r,r,r,t);return c.placeholder=Hc.placeholder,c}function Gc(e,t,i){t=i?r:t;var c=In(e,G,r,r,r,r,r,t);return c.placeholder=Gc.placeholder,c}function $c(e,t,i){var c,d,x,w,E,k,W=0,z=!1,Y=!1,te=!0;if(typeof e!="function")throw new on(p);t=dn(t)||0,rt(i)&&(z=!!i.leading,Y="maxWait"in i,x=Y?vt(dn(i.maxWait)||0,t):x,te="trailing"in i?!!i.trailing:te);function ae(ut){var _n=c,Bn=d;return c=d=r,W=ut,w=e.apply(Bn,_n),w}function he(ut){return W=ut,E=es(Re,t),z?ae(ut):w}function Ne(ut){var _n=ut-k,Bn=ut-W,uu=t-_n;return Y?kt(uu,x-Bn):uu}function pe(ut){var _n=ut-k,Bn=ut-W;return k===r||_n>=t||_n<0||Y&&Bn>=x}function Re(){var ut=ti();if(pe(ut))return De(ut);E=es(Re,Ne(ut))}function De(ut){return E=r,te&&c?ae(ut):(c=d=r,w)}function Qt(){E!==r&&tc(E),W=0,c=k=d=E=r}function Ot(){return E===r?w:De(ti())}function Jt(){var ut=ti(),_n=pe(ut);if(c=arguments,d=this,k=ut,_n){if(E===r)return he(k);if(Y)return tc(E),E=es(Re,t),ae(k)}return E===r&&(E=es(Re,t)),w}return Jt.cancel=Qt,Jt.flush=Ot,Jt}var dg=ke(function(e,t){return Il(e,1,t)}),fg=ke(function(e,t,i){return Il(e,dn(t)||0,i)});function hg(e){return In(e,U)}function ni(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new on(p);var i=function(){var c=arguments,d=t?t.apply(this,c):c[0],x=i.cache;if(x.has(d))return x.get(d);var w=e.apply(this,c);return i.cache=x.set(d,w)||x,w};return i.cache=new(ni.Cache||Pn),i}ni.Cache=Pn;function ri(e){if(typeof e!="function")throw new on(p);return function(){var t=arguments;switch(t.length){case 0:return!e.call(this);case 1:return!e.call(this,t[0]);case 2:return!e.call(this,t[0],t[1]);case 3:return!e.call(this,t[0],t[1],t[2])}return!e.apply(this,t)}}function pg(e){return Wc(2,e)}var mg=tm(function(e,t){t=t.length==1&&be(t[0])?et(t[0],Yt(fe())):et(St(t,1),Yt(fe()));var i=t.length;return ke(function(c){for(var d=-1,x=kt(c.length,i);++d<x;)c[d]=t[d].call(this,c[d]);return Xt(e,this,c)})}),Lo=ke(function(e,t){var i=qn(t,Rr(Lo));return In(e,q,r,t,i)}),qc=ke(function(e,t){var i=qn(t,Rr(qc));return In(e,X,r,t,i)}),gg=Dn(function(e,t){return In(e,V,r,r,r,t)});function xg(e,t){if(typeof e!="function")throw new on(p);return t=t===r?t:Ee(t),ke(e,t)}function _g(e,t){if(typeof e!="function")throw new on(p);return t=t==null?0:vt(Ee(t),0),ke(function(i){var c=i[t],d=Qn(i,0,t);return c&&$n(d,c),Xt(e,this,d)})}function vg(e,t,i){var c=!0,d=!0;if(typeof e!="function")throw new on(p);return rt(i)&&(c="leading"in i?!!i.leading:c,d="trailing"in i?!!i.trailing:d),$c(e,t,{leading:c,maxWait:t,trailing:d})}function bg(e){return Uc(e,1)}function yg(e,t){return Lo(bo(t),e)}function wg(){if(!arguments.length)return[];var e=arguments[0];return be(e)?e:[e]}function Eg(e){return ln(e,S)}function Sg(e,t){return t=typeof t=="function"?t:r,ln(e,S,t)}function Ng(e){return ln(e,_|S)}function Cg(e,t){return t=typeof t=="function"?t:r,ln(e,_|S,t)}function kg(e,t){return t==null||Ml(e,t,yt(t))}function xn(e,t){return e===t||e!==e&&t!==t}var Tg=Vs(ao),Rg=Vs(function(e,t){return e>=t}),pr=Bl((function(){return arguments})())?Bl:function(e){return it(e)&&ze.call(e,"callee")&&!Nl.call(e,"callee")},be=P.isArray,Ag=ol?Yt(ol):Fp;function zt(e){return e!=null&&si(e.length)&&!On(e)}function ct(e){return it(e)&&zt(e)}function jg(e){return e===!0||e===!1||it(e)&&Dt(e)==Ge}var Jn=$h||Xo,Pg=al?Yt(al):Bp;function Mg(e){return it(e)&&e.nodeType===1&&!ts(e)}function Ig(e){if(e==null)return!0;if(zt(e)&&(be(e)||typeof e=="string"||typeof e.splice=="function"||Jn(e)||Ar(e)||pr(e)))return!e.length;var t=Tt(e);if(t==Xe||t==ce)return!e.size;if(Zr(e))return!uo(e).length;for(var i in e)if(ze.call(e,i))return!1;return!0}function Dg(e,t){return Kr(e,t)}function Lg(e,t,i){i=typeof i=="function"?i:r;var c=i?i(e,t):r;return c===r?Kr(e,t,r,i):!!c}function Oo(e){if(!it(e))return!1;var t=Dt(e);return t==mt||t==$e||typeof e.message=="string"&&typeof e.name=="string"&&!ts(e)}function Og(e){return typeof e=="number"&&kl(e)}function On(e){if(!rt(e))return!1;var t=Dt(e);return t==tt||t==At||t==lt||t==ee}function Xc(e){return typeof e=="number"&&e==Ee(e)}function si(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=re}function rt(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}function it(e){return e!=null&&typeof e=="object"}var Yc=ll?Yt(ll):Wp;function Fg(e,t){return e===t||co(e,t,ko(t))}function Bg(e,t,i){return i=typeof i=="function"?i:r,co(e,t,ko(t),i)}function Ug(e){return Vc(e)&&e!=+e}function Wg(e){if(Sm(e))throw new _e(l);return Ul(e)}function zg(e){return e===null}function Hg(e){return e==null}function Vc(e){return typeof e=="number"||it(e)&&Dt(e)==gt}function ts(e){if(!it(e)||Dt(e)!=se)return!1;var t=js(e);if(t===null)return!0;var i=ze.call(t,"constructor")&&t.constructor;return typeof i=="function"&&i instanceof i&&ks.call(i)==Bh}var Fo=cl?Yt(cl):zp;function Gg(e){return Xc(e)&&e>=-re&&e<=re}var Kc=ul?Yt(ul):Hp;function ii(e){return typeof e=="string"||!be(e)&&it(e)&&Dt(e)==Ce}function Kt(e){return typeof e=="symbol"||it(e)&&Dt(e)==we}var Ar=dl?Yt(dl):Gp;function $g(e){return e===r}function qg(e){return it(e)&&Tt(e)==bt}function Xg(e){return it(e)&&Dt(e)==Q}var Yg=Vs(fo),Vg=Vs(function(e,t){return e<=t});function Qc(e){if(!e)return[];if(zt(e))return ii(e)?mn(e):Wt(e);if(zr&&e[zr])return kh(e[zr]());var t=Tt(e),i=t==Xe?Ji:t==ce?Ss:jr;return i(e)}function Fn(e){if(!e)return e===0?e:0;if(e=dn(e),e===O||e===-O){var t=e<0?-1:1;return t*de}return e===e?e:0}function Ee(e){var t=Fn(e),i=t%1;return t===t?i?t-i:t:0}function Jc(e){return e?ur(Ee(e),0,Z):0}function dn(e){if(typeof e=="number")return e;if(Kt(e))return ue;if(rt(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=rt(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=xl(e);var i=Ze.test(e);return i||qt.test(e)?uh(e.slice(2),i?2:8):Li.test(e)?ue:+e}function Zc(e){return En(e,Ht(e))}function Kg(e){return e?ur(Ee(e),-re,re):e===0?e:0}function Ue(e){return e==null?"":Vt(e)}var Qg=kr(function(e,t){if(Zr(t)||zt(t)){En(t,yt(t),e);return}for(var i in t)ze.call(t,i)&&Xr(e,i,t[i])}),eu=kr(function(e,t){En(t,Ht(t),e)}),oi=kr(function(e,t,i,c){En(t,Ht(t),e,c)}),Jg=kr(function(e,t,i,c){En(t,yt(t),e,c)}),Zg=Dn(so);function ex(e,t){var i=Cr(e);return t==null?i:Pl(i,t)}var tx=ke(function(e,t){e=qe(e);var i=-1,c=t.length,d=c>2?t[2]:r;for(d&&Lt(t[0],t[1],d)&&(c=1);++i<c;)for(var x=t[i],w=Ht(x),E=-1,k=w.length;++E<k;){var W=w[E],z=e[W];(z===r||xn(z,Er[W])&&!ze.call(e,W))&&(e[W]=x[W])}return e}),nx=ke(function(e){return e.push(r,xc),Xt(tu,r,e)});function rx(e,t){return hl(e,fe(t,3),wn)}function sx(e,t){return hl(e,fe(t,3),oo)}function ix(e,t){return e==null?e:io(e,fe(t,3),Ht)}function ox(e,t){return e==null?e:Ol(e,fe(t,3),Ht)}function ax(e,t){return e&&wn(e,fe(t,3))}function lx(e,t){return e&&oo(e,fe(t,3))}function cx(e){return e==null?[]:Ws(e,yt(e))}function ux(e){return e==null?[]:Ws(e,Ht(e))}function Bo(e,t,i){var c=e==null?r:dr(e,t);return c===r?i:c}function dx(e,t){return e!=null&&bc(e,t,Ip)}function Uo(e,t){return e!=null&&bc(e,t,Dp)}var fx=fc(function(e,t,i){t!=null&&typeof t.toString!="function"&&(t=Ts.call(t)),e[t]=i},zo(Gt)),hx=fc(function(e,t,i){t!=null&&typeof t.toString!="function"&&(t=Ts.call(t)),ze.call(e,t)?e[t].push(i):e[t]=[i]},fe),px=ke(Vr);function yt(e){return zt(e)?Al(e):uo(e)}function Ht(e){return zt(e)?Al(e,!0):$p(e)}function mx(e,t){var i={};return t=fe(t,3),wn(e,function(c,d,x){Mn(i,t(c,d,x),c)}),i}function gx(e,t){var i={};return t=fe(t,3),wn(e,function(c,d,x){Mn(i,d,t(c,d,x))}),i}var xx=kr(function(e,t,i){zs(e,t,i)}),tu=kr(function(e,t,i,c){zs(e,t,i,c)}),_x=Dn(function(e,t){var i={};if(e==null)return i;var c=!1;t=et(t,function(x){return x=Kn(x,e),c||(c=x.length>1),x}),En(e,No(e),i),c&&(i=ln(i,_|y|S,fm));for(var d=t.length;d--;)xo(i,t[d]);return i});function vx(e,t){return nu(e,ri(fe(t)))}var bx=Dn(function(e,t){return e==null?{}:Xp(e,t)});function nu(e,t){if(e==null)return{};var i=et(No(e),function(c){return[c]});return t=fe(t),Xl(e,i,function(c,d){return t(c,d[0])})}function yx(e,t,i){t=Kn(t,e);var c=-1,d=t.length;for(d||(d=1,e=r);++c<d;){var x=e==null?r:e[Sn(t[c])];x===r&&(c=d,x=i),e=On(x)?x.call(e):x}return e}function wx(e,t,i){return e==null?e:Qr(e,t,i)}function Ex(e,t,i,c){return c=typeof c=="function"?c:r,e==null?e:Qr(e,t,i,c)}var ru=mc(yt),su=mc(Ht);function Sx(e,t,i){var c=be(e),d=c||Jn(e)||Ar(e);if(t=fe(t,4),i==null){var x=e&&e.constructor;d?i=c?new x:[]:rt(e)?i=On(x)?Cr(js(e)):{}:i={}}return(d?sn:wn)(e,function(w,E,k){return t(i,w,E,k)}),i}function Nx(e,t){return e==null?!0:xo(e,t)}function Cx(e,t,i){return e==null?e:Jl(e,t,bo(i))}function kx(e,t,i,c){return c=typeof c=="function"?c:r,e==null?e:Jl(e,t,bo(i),c)}function jr(e){return e==null?[]:Qi(e,yt(e))}function Tx(e){return e==null?[]:Qi(e,Ht(e))}function Rx(e,t,i){return i===r&&(i=t,t=r),i!==r&&(i=dn(i),i=i===i?i:0),t!==r&&(t=dn(t),t=t===t?t:0),ur(dn(e),t,i)}function Ax(e,t,i){return t=Fn(t),i===r?(i=t,t=0):i=Fn(i),e=dn(e),Lp(e,t,i)}function jx(e,t,i){if(i&&typeof i!="boolean"&&Lt(e,t,i)&&(t=i=r),i===r&&(typeof t=="boolean"?(i=t,t=r):typeof e=="boolean"&&(i=e,e=r)),e===r&&t===r?(e=0,t=1):(e=Fn(e),t===r?(t=e,e=0):t=Fn(t)),e>t){var c=e;e=t,t=c}if(i||e%1||t%1){var d=Tl();return kt(e+d*(t-e+ch("1e-"+((d+"").length-1))),t)}return po(e,t)}var Px=Tr(function(e,t,i){return t=t.toLowerCase(),e+(i?iu(t):t)});function iu(e){return Wo(Ue(e).toLowerCase())}function ou(e){return e=Ue(e),e&&e.replace(ir,wh).replace(Zf,"")}function Mx(e,t,i){e=Ue(e),t=Vt(t);var c=e.length;i=i===r?c:ur(Ee(i),0,c);var d=i;return i-=t.length,i>=0&&e.slice(i,d)==t}function Ix(e){return e=Ue(e),e&&An.test(e)?e.replace(wt,Eh):e}function Dx(e){return e=Ue(e),e&&Br.test(e)?e.replace(Fr,"\\$&"):e}var Lx=Tr(function(e,t,i){return e+(i?"-":"")+t.toLowerCase()}),Ox=Tr(function(e,t,i){return e+(i?" ":"")+t.toLowerCase()}),Fx=cc("toLowerCase");function Bx(e,t,i){e=Ue(e),t=Ee(t);var c=t?yr(e):0;if(!t||c>=t)return e;var d=(t-c)/2;return Ys(Ds(d),i)+e+Ys(Is(d),i)}function Ux(e,t,i){e=Ue(e),t=Ee(t);var c=t?yr(e):0;return t&&c<t?e+Ys(t-c,i):e}function Wx(e,t,i){e=Ue(e),t=Ee(t);var c=t?yr(e):0;return t&&c<t?Ys(t-c,i)+e:e}function zx(e,t,i){return i||t==null?t=0:t&&(t=+t),Vh(Ue(e).replace(H,""),t||0)}function Hx(e,t,i){return(i?Lt(e,t,i):t===r)?t=1:t=Ee(t),mo(Ue(e),t)}function Gx(){var e=arguments,t=Ue(e[0]);return e.length<3?t:t.replace(e[1],e[2])}var $x=Tr(function(e,t,i){return e+(i?"_":"")+t.toLowerCase()});function qx(e,t,i){return i&&typeof i!="number"&&Lt(e,t,i)&&(t=i=r),i=i===r?Z:i>>>0,i?(e=Ue(e),e&&(typeof t=="string"||t!=null&&!Fo(t))&&(t=Vt(t),!t&&br(e))?Qn(mn(e),0,i):e.split(t,i)):[]}var Xx=Tr(function(e,t,i){return e+(i?" ":"")+Wo(t)});function Yx(e,t,i){return e=Ue(e),i=i==null?0:ur(Ee(i),0,e.length),t=Vt(t),e.slice(i,i+t.length)==t}function Vx(e,t,i){var c=m.templateSettings;i&&Lt(e,t,i)&&(t=r),e=Ue(e),t=oi({},t,c,gc);var d=oi({},t.imports,c.imports,gc),x=yt(d),w=Qi(d,x),E,k,W=0,z=t.interpolate||vs,Y="__p += '",te=Zi((t.escape||vs).source+"|"+z.source+"|"+(z===_s?Bt:vs).source+"|"+(t.evaluate||vs).source+"|$","g"),ae="//# sourceURL="+(ze.call(t,"sourceURL")?(t.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++sh+"]")+`
9
- `;e.replace(te,function(pe,Re,De,Qt,Ot,Jt){return De||(De=Qt),Y+=e.slice(W,Jt).replace(Df,Sh),Re&&(E=!0,Y+=`' +
10
- __e(`+Re+`) +
11
- '`),Ot&&(k=!0,Y+=`';
12
- `+Ot+`;
13
- __p += '`),De&&(Y+=`' +
14
- ((__t = (`+De+`)) == null ? '' : __t) +
15
- '`),W=Jt+pe.length,pe}),Y+=`';
16
- `;var he=ze.call(t,"variable")&&t.variable;if(!he)Y=`with (obj) {
17
- `+Y+`
18
- }
19
- `;else if(Je.test(he))throw new _e(b);Y=(k?Y.replace(xr,""):Y).replace(sr,"$1").replace(He,"$1;"),Y="function("+(he||"obj")+`) {
20
- `+(he?"":`obj || (obj = {});
21
- `)+"var __t, __p = ''"+(E?", __e = _.escape":"")+(k?`, __j = Array.prototype.join;
22
- function print() { __p += __j.call(arguments, '') }
23
- `:`;
24
- `)+Y+`return __p
25
- }`;var Ne=lu(function(){return Be(x,ae+"return "+Y).apply(r,w)});if(Ne.source=Y,Oo(Ne))throw Ne;return Ne}function Kx(e){return Ue(e).toLowerCase()}function Qx(e){return Ue(e).toUpperCase()}function Jx(e,t,i){if(e=Ue(e),e&&(i||t===r))return xl(e);if(!e||!(t=Vt(t)))return e;var c=mn(e),d=mn(t),x=_l(c,d),w=vl(c,d)+1;return Qn(c,x,w).join("")}function Zx(e,t,i){if(e=Ue(e),e&&(i||t===r))return e.slice(0,yl(e)+1);if(!e||!(t=Vt(t)))return e;var c=mn(e),d=vl(c,mn(t))+1;return Qn(c,0,d).join("")}function e_(e,t,i){if(e=Ue(e),e&&(i||t===r))return e.replace(H,"");if(!e||!(t=Vt(t)))return e;var c=mn(e),d=_l(c,mn(t));return Qn(c,d).join("")}function t_(e,t){var i=I,c=D;if(rt(t)){var d="separator"in t?t.separator:d;i="length"in t?Ee(t.length):i,c="omission"in t?Vt(t.omission):c}e=Ue(e);var x=e.length;if(br(e)){var w=mn(e);x=w.length}if(i>=x)return e;var E=i-yr(c);if(E<1)return c;var k=w?Qn(w,0,E).join(""):e.slice(0,E);if(d===r)return k+c;if(w&&(E+=k.length-E),Fo(d)){if(e.slice(E).search(d)){var W,z=k;for(d.global||(d=Zi(d.source,Ue(Ur.exec(d))+"g")),d.lastIndex=0;W=d.exec(z);)var Y=W.index;k=k.slice(0,Y===r?E:Y)}}else if(e.indexOf(Vt(d),E)!=E){var te=k.lastIndexOf(d);te>-1&&(k=k.slice(0,te))}return k+c}function n_(e){return e=Ue(e),e&&It.test(e)?e.replace(Mt,jh):e}var r_=Tr(function(e,t,i){return e+(i?" ":"")+t.toUpperCase()}),Wo=cc("toUpperCase");function au(e,t,i){return e=Ue(e),t=i?r:t,t===r?Ch(e)?Ih(e):xh(e):e.match(t)||[]}var lu=ke(function(e,t){try{return Xt(e,r,t)}catch(i){return Oo(i)?i:new _e(i)}}),s_=Dn(function(e,t){return sn(t,function(i){i=Sn(i),Mn(e,i,Do(e[i],e))}),e});function i_(e){var t=e==null?0:e.length,i=fe();return e=t?et(e,function(c){if(typeof c[1]!="function")throw new on(p);return[i(c[0]),c[1]]}):[],ke(function(c){for(var d=-1;++d<t;){var x=e[d];if(Xt(x[0],this,c))return Xt(x[1],this,c)}})}function o_(e){return jp(ln(e,_))}function zo(e){return function(){return e}}function a_(e,t){return e==null||e!==e?t:e}var l_=dc(),c_=dc(!0);function Gt(e){return e}function Ho(e){return Wl(typeof e=="function"?e:ln(e,_))}function u_(e){return Hl(ln(e,_))}function d_(e,t){return Gl(e,ln(t,_))}var f_=ke(function(e,t){return function(i){return Vr(i,e,t)}}),h_=ke(function(e,t){return function(i){return Vr(e,i,t)}});function Go(e,t,i){var c=yt(t),d=Ws(t,c);i==null&&!(rt(t)&&(d.length||!c.length))&&(i=t,t=e,e=this,d=Ws(t,yt(t)));var x=!(rt(i)&&"chain"in i)||!!i.chain,w=On(e);return sn(d,function(E){var k=t[E];e[E]=k,w&&(e.prototype[E]=function(){var W=this.__chain__;if(x||W){var z=e(this.__wrapped__),Y=z.__actions__=Wt(this.__actions__);return Y.push({func:k,args:arguments,thisArg:e}),z.__chain__=W,z}return k.apply(e,$n([this.value()],arguments))})}),e}function p_(){return Et._===this&&(Et._=Uh),this}function $o(){}function m_(e){return e=Ee(e),ke(function(t){return $l(t,e)})}var g_=wo(et),x_=wo(fl),__=wo(qi);function cu(e){return Ro(e)?Xi(Sn(e)):Yp(e)}function v_(e){return function(t){return e==null?r:dr(e,t)}}var b_=hc(),y_=hc(!0);function qo(){return[]}function Xo(){return!1}function w_(){return{}}function E_(){return""}function S_(){return!0}function N_(e,t){if(e=Ee(e),e<1||e>re)return[];var i=Z,c=kt(e,Z);t=fe(t),e-=Z;for(var d=Ki(c,t);++i<e;)t(i);return d}function C_(e){return be(e)?et(e,Sn):Kt(e)?[e]:Wt(Rc(Ue(e)))}function k_(e){var t=++Fh;return Ue(e)+t}var T_=Xs(function(e,t){return e+t},0),R_=Eo("ceil"),A_=Xs(function(e,t){return e/t},1),j_=Eo("floor");function P_(e){return e&&e.length?Us(e,Gt,ao):r}function M_(e,t){return e&&e.length?Us(e,fe(t,2),ao):r}function I_(e){return ml(e,Gt)}function D_(e,t){return ml(e,fe(t,2))}function L_(e){return e&&e.length?Us(e,Gt,fo):r}function O_(e,t){return e&&e.length?Us(e,fe(t,2),fo):r}var F_=Xs(function(e,t){return e*t},1),B_=Eo("round"),U_=Xs(function(e,t){return e-t},0);function W_(e){return e&&e.length?Vi(e,Gt):0}function z_(e,t){return e&&e.length?Vi(e,fe(t,2)):0}return m.after=ug,m.ary=Uc,m.assign=Qg,m.assignIn=eu,m.assignInWith=oi,m.assignWith=Jg,m.at=Zg,m.before=Wc,m.bind=Do,m.bindAll=s_,m.bindKey=zc,m.castArray=wg,m.chain=Oc,m.chunk=jm,m.compact=Pm,m.concat=Mm,m.cond=i_,m.conforms=o_,m.constant=zo,m.countBy=W0,m.create=ex,m.curry=Hc,m.curryRight=Gc,m.debounce=$c,m.defaults=tx,m.defaultsDeep=nx,m.defer=dg,m.delay=fg,m.difference=Im,m.differenceBy=Dm,m.differenceWith=Lm,m.drop=Om,m.dropRight=Fm,m.dropRightWhile=Bm,m.dropWhile=Um,m.fill=Wm,m.filter=H0,m.flatMap=q0,m.flatMapDeep=X0,m.flatMapDepth=Y0,m.flatten=Mc,m.flattenDeep=zm,m.flattenDepth=Hm,m.flip=hg,m.flow=l_,m.flowRight=c_,m.fromPairs=Gm,m.functions=cx,m.functionsIn=ux,m.groupBy=V0,m.initial=qm,m.intersection=Xm,m.intersectionBy=Ym,m.intersectionWith=Vm,m.invert=fx,m.invertBy=hx,m.invokeMap=Q0,m.iteratee=Ho,m.keyBy=J0,m.keys=yt,m.keysIn=Ht,m.map=ei,m.mapKeys=mx,m.mapValues=gx,m.matches=u_,m.matchesProperty=d_,m.memoize=ni,m.merge=xx,m.mergeWith=tu,m.method=f_,m.methodOf=h_,m.mixin=Go,m.negate=ri,m.nthArg=m_,m.omit=_x,m.omitBy=vx,m.once=pg,m.orderBy=Z0,m.over=g_,m.overArgs=mg,m.overEvery=x_,m.overSome=__,m.partial=Lo,m.partialRight=qc,m.partition=eg,m.pick=bx,m.pickBy=nu,m.property=cu,m.propertyOf=v_,m.pull=Zm,m.pullAll=Dc,m.pullAllBy=e0,m.pullAllWith=t0,m.pullAt=n0,m.range=b_,m.rangeRight=y_,m.rearg=gg,m.reject=rg,m.remove=r0,m.rest=xg,m.reverse=Mo,m.sampleSize=ig,m.set=wx,m.setWith=Ex,m.shuffle=og,m.slice=s0,m.sortBy=cg,m.sortedUniq=d0,m.sortedUniqBy=f0,m.split=qx,m.spread=_g,m.tail=h0,m.take=p0,m.takeRight=m0,m.takeRightWhile=g0,m.takeWhile=x0,m.tap=P0,m.throttle=vg,m.thru=Zs,m.toArray=Qc,m.toPairs=ru,m.toPairsIn=su,m.toPath=C_,m.toPlainObject=Zc,m.transform=Sx,m.unary=bg,m.union=_0,m.unionBy=v0,m.unionWith=b0,m.uniq=y0,m.uniqBy=w0,m.uniqWith=E0,m.unset=Nx,m.unzip=Io,m.unzipWith=Lc,m.update=Cx,m.updateWith=kx,m.values=jr,m.valuesIn=Tx,m.without=S0,m.words=au,m.wrap=yg,m.xor=N0,m.xorBy=C0,m.xorWith=k0,m.zip=T0,m.zipObject=R0,m.zipObjectDeep=A0,m.zipWith=j0,m.entries=ru,m.entriesIn=su,m.extend=eu,m.extendWith=oi,Go(m,m),m.add=T_,m.attempt=lu,m.camelCase=Px,m.capitalize=iu,m.ceil=R_,m.clamp=Rx,m.clone=Eg,m.cloneDeep=Ng,m.cloneDeepWith=Cg,m.cloneWith=Sg,m.conformsTo=kg,m.deburr=ou,m.defaultTo=a_,m.divide=A_,m.endsWith=Mx,m.eq=xn,m.escape=Ix,m.escapeRegExp=Dx,m.every=z0,m.find=G0,m.findIndex=jc,m.findKey=rx,m.findLast=$0,m.findLastIndex=Pc,m.findLastKey=sx,m.floor=j_,m.forEach=Fc,m.forEachRight=Bc,m.forIn=ix,m.forInRight=ox,m.forOwn=ax,m.forOwnRight=lx,m.get=Bo,m.gt=Tg,m.gte=Rg,m.has=dx,m.hasIn=Uo,m.head=Ic,m.identity=Gt,m.includes=K0,m.indexOf=$m,m.inRange=Ax,m.invoke=px,m.isArguments=pr,m.isArray=be,m.isArrayBuffer=Ag,m.isArrayLike=zt,m.isArrayLikeObject=ct,m.isBoolean=jg,m.isBuffer=Jn,m.isDate=Pg,m.isElement=Mg,m.isEmpty=Ig,m.isEqual=Dg,m.isEqualWith=Lg,m.isError=Oo,m.isFinite=Og,m.isFunction=On,m.isInteger=Xc,m.isLength=si,m.isMap=Yc,m.isMatch=Fg,m.isMatchWith=Bg,m.isNaN=Ug,m.isNative=Wg,m.isNil=Hg,m.isNull=zg,m.isNumber=Vc,m.isObject=rt,m.isObjectLike=it,m.isPlainObject=ts,m.isRegExp=Fo,m.isSafeInteger=Gg,m.isSet=Kc,m.isString=ii,m.isSymbol=Kt,m.isTypedArray=Ar,m.isUndefined=$g,m.isWeakMap=qg,m.isWeakSet=Xg,m.join=Km,m.kebabCase=Lx,m.last=un,m.lastIndexOf=Qm,m.lowerCase=Ox,m.lowerFirst=Fx,m.lt=Yg,m.lte=Vg,m.max=P_,m.maxBy=M_,m.mean=I_,m.meanBy=D_,m.min=L_,m.minBy=O_,m.stubArray=qo,m.stubFalse=Xo,m.stubObject=w_,m.stubString=E_,m.stubTrue=S_,m.multiply=F_,m.nth=Jm,m.noConflict=p_,m.noop=$o,m.now=ti,m.pad=Bx,m.padEnd=Ux,m.padStart=Wx,m.parseInt=zx,m.random=jx,m.reduce=tg,m.reduceRight=ng,m.repeat=Hx,m.replace=Gx,m.result=yx,m.round=B_,m.runInContext=C,m.sample=sg,m.size=ag,m.snakeCase=$x,m.some=lg,m.sortedIndex=i0,m.sortedIndexBy=o0,m.sortedIndexOf=a0,m.sortedLastIndex=l0,m.sortedLastIndexBy=c0,m.sortedLastIndexOf=u0,m.startCase=Xx,m.startsWith=Yx,m.subtract=U_,m.sum=W_,m.sumBy=z_,m.template=Vx,m.times=N_,m.toFinite=Fn,m.toInteger=Ee,m.toLength=Jc,m.toLower=Kx,m.toNumber=dn,m.toSafeInteger=Kg,m.toString=Ue,m.toUpper=Qx,m.trim=Jx,m.trimEnd=Zx,m.trimStart=e_,m.truncate=t_,m.unescape=n_,m.uniqueId=k_,m.upperCase=r_,m.upperFirst=Wo,m.each=Fc,m.eachRight=Bc,m.first=Ic,Go(m,(function(){var e={};return wn(m,function(t,i){ze.call(m.prototype,i)||(e[i]=t)}),e})(),{chain:!1}),m.VERSION=a,sn(["bind","bindKey","curry","curryRight","partial","partialRight"],function(e){m[e].placeholder=m}),sn(["drop","take"],function(e,t){Me.prototype[e]=function(i){i=i===r?1:vt(Ee(i),0);var c=this.__filtered__&&!t?new Me(this):this.clone();return c.__filtered__?c.__takeCount__=kt(i,c.__takeCount__):c.__views__.push({size:kt(i,Z),type:e+(c.__dir__<0?"Right":"")}),c},Me.prototype[e+"Right"]=function(i){return this.reverse()[e](i).reverse()}}),sn(["filter","map","takeWhile"],function(e,t){var i=t+1,c=i==$||i==T;Me.prototype[e]=function(d){var x=this.clone();return x.__iteratees__.push({iteratee:fe(d,3),type:i}),x.__filtered__=x.__filtered__||c,x}}),sn(["head","last"],function(e,t){var i="take"+(t?"Right":"");Me.prototype[e]=function(){return this[i](1).value()[0]}}),sn(["initial","tail"],function(e,t){var i="drop"+(t?"":"Right");Me.prototype[e]=function(){return this.__filtered__?new Me(this):this[i](1)}}),Me.prototype.compact=function(){return this.filter(Gt)},Me.prototype.find=function(e){return this.filter(e).head()},Me.prototype.findLast=function(e){return this.reverse().find(e)},Me.prototype.invokeMap=ke(function(e,t){return typeof e=="function"?new Me(this):this.map(function(i){return Vr(i,e,t)})}),Me.prototype.reject=function(e){return this.filter(ri(fe(e)))},Me.prototype.slice=function(e,t){e=Ee(e);var i=this;return i.__filtered__&&(e>0||t<0)?new Me(i):(e<0?i=i.takeRight(-e):e&&(i=i.drop(e)),t!==r&&(t=Ee(t),i=t<0?i.dropRight(-t):i.take(t-e)),i)},Me.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},Me.prototype.toArray=function(){return this.take(Z)},wn(Me.prototype,function(e,t){var i=/^(?:filter|find|map|reject)|While$/.test(t),c=/^(?:head|last)$/.test(t),d=m[c?"take"+(t=="last"?"Right":""):t],x=c||/^find/.test(t);d&&(m.prototype[t]=function(){var w=this.__wrapped__,E=c?[1]:arguments,k=w instanceof Me,W=E[0],z=k||be(w),Y=function(Re){var De=d.apply(m,$n([Re],E));return c&&te?De[0]:De};z&&i&&typeof W=="function"&&W.length!=1&&(k=z=!1);var te=this.__chain__,ae=!!this.__actions__.length,he=x&&!te,Ne=k&&!ae;if(!x&&z){w=Ne?w:new Me(this);var pe=e.apply(w,E);return pe.__actions__.push({func:Zs,args:[Y],thisArg:r}),new an(pe,te)}return he&&Ne?e.apply(this,E):(pe=this.thru(Y),he?c?pe.value()[0]:pe.value():pe)})}),sn(["pop","push","shift","sort","splice","unshift"],function(e){var t=Ns[e],i=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",c=/^(?:pop|shift)$/.test(e);m.prototype[e]=function(){var d=arguments;if(c&&!this.__chain__){var x=this.value();return t.apply(be(x)?x:[],d)}return this[i](function(w){return t.apply(be(w)?w:[],d)})}}),wn(Me.prototype,function(e,t){var i=m[t];if(i){var c=i.name+"";ze.call(Nr,c)||(Nr[c]=[]),Nr[c].push({name:t,func:i})}}),Nr[qs(r,M).name]=[{name:"wrapper",func:r}],Me.prototype.clone=np,Me.prototype.reverse=rp,Me.prototype.value=sp,m.prototype.at=M0,m.prototype.chain=I0,m.prototype.commit=D0,m.prototype.next=L0,m.prototype.plant=F0,m.prototype.reverse=B0,m.prototype.toJSON=m.prototype.valueOf=m.prototype.value=U0,m.prototype.first=m.prototype.head,zr&&(m.prototype[zr]=O0),m}),wr=Dh();or?((or.exports=wr)._=wr,zi._=wr):Et._=wr}).call(z1)})(ls,ls.exports)),ls.exports}var Bd=H1();const G1=H_(Bd);function $1(s,n){const[r,a]=v.useState(s),u=v.useRef(G1.debounce(a,n)),l=v.useCallback(p=>{u.current(p)},[]);return[r,l]}const q1=()=>{try{const s=localStorage.getItem("sidebar-collapsed");return s!==null?JSON.parse(s):!1}catch(s){return console.warn("Failed to load sidebar collapsed state:",s),!1}};function X1({devices:s,currentDeviceId:n,onSelectDevice:r,onOpenConfig:a,onConnectWifi:u,onDisconnectWifi:l}){const p=Dr(),[b,f]=v.useState(q1),[g,h]=v.useState(!1),[_,y]=v.useState(""),[S,N]=v.useState("5555"),[j,R]=v.useState(""),[M,F]=v.useState(""),[A,G]=v.useState("direct"),[q,X]=v.useState(""),[K,V]=v.useState(""),[U,I]=v.useState("5555"),[D,me]=v.useState(""),[ye,$]=v.useState(!1),[J,T]=v.useState([]),[O,re]=$1(!1,300),[de,ue]=v.useState(""),[Z,Se]=v.useState(null),[je,Fe]=v.useState(!1),Ie=v.useRef(null);v.useEffect(()=>{localStorage.setItem("sidebar-collapsed",JSON.stringify(b))},[b]),v.useEffect(()=>{const L=ee=>{(ee.metaKey||ee.ctrlKey)&&ee.key==="b"&&(ee.preventDefault(),f(!b))};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[b]);const at=()=>{f(!b)},lt=L=>/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(L)?L.split(".").every(ce=>{const Ce=parseInt(ce,10);return Ce>=0&&Ce<=255}):!1,Ge=L=>{const ee=parseInt(L,10);return!isNaN(ee)&&ee>=1&&ee<=65535},Te=L=>/^\d{6}$/.test(L),$e=async()=>{R(""),F("");let L=!1;if(lt(_)||(R(p.deviceSidebar.invalidIpError),L=!0),Ge(S)||(F(p.deviceSidebar.invalidPortError),L=!0),!L){$(!0);try{const ee=await du({ip:_,port:parseInt(S,10)});ee.success?(h(!1),y(""),N("5555")):R(ee.message||p.toasts.wifiManualConnectError)}catch{R(p.toasts.wifiManualConnectError)}finally{$(!1)}}},mt=async()=>{me(""),R(""),F("");let L=!1;if(lt(_)||(R(p.deviceSidebar.invalidIpError),L=!0),Ge(K)||(F(p.deviceSidebar.invalidPortError),L=!0),Ge(U)||(F(p.deviceSidebar.invalidPortError),L=!0),Te(q)||(me(p.deviceSidebar.invalidPairingCodeError),L=!0),!L){$(!0);try{const ee=await Y_({ip:_,pairing_port:parseInt(K,10),pairing_code:q,connection_port:parseInt(U,10)});ee.success?(h(!1),y(""),N("5555"),X(""),V(""),I("5555"),G("direct")):ee.error==="invalid_pairing_code"?me(ee.message):ee.error==="invalid_ip"?R(ee.message):R(ee.message||p.toasts.wifiPairError)}catch{R(p.toasts.wifiPairError)}finally{$(!1)}}},tt=v.useCallback(()=>{Ie.current!==null&&(clearInterval(Ie.current),Ie.current=null)},[]),At=v.useCallback(L=>{tt(),Ie.current=window.setInterval(async()=>{try{const ee=await G_(L);Se(le=>le?{...le,status:ee.status}:null),["connected","timeout","error"].includes(ee.status)&&(tt(),ee.status==="connected"&&setTimeout(()=>{h(!1),Se(null)},2e3))}catch(ee){console.error("[QR Pairing] Status poll failed:",ee)}},1e3)},[tt]),Xe=v.useCallback(async()=>{Fe(!0);try{const L=await $_();L.success&&L.qr_payload&&L.session_id&&(Se({sessionId:L.session_id,payload:L.qr_payload,status:"listening",expiresAt:L.expires_at??Date.now()+12e4}),At(L.session_id))}catch(L){console.error("[QR Pairing] Generation failed:",L)}finally{Fe(!1)}},[At]),gt=v.useCallback(async()=>{if(Z)try{await q_(Z.sessionId),Se(null),tt()}catch(L){console.error("[QR Pairing] Cancel failed:",L)}},[Z,tt]);v.useEffect(()=>{(!g||A!=="pair")&&(Z&&Z.status==="listening"&&gt(),tt())},[g,A,Z,tt,gt]),v.useEffect(()=>()=>{tt()},[tt]),v.useEffect(()=>{g&&A==="pair"&&!Z&&!je&&Xe()},[g,A,Z,je,Xe]);const ne=v.useCallback(async()=>{re(!0),ue("");try{const L=await X_();L.success?T(L.devices):(ue(L.error||p.deviceSidebar.scanError.replace("{error}","Unknown error")),T([]))}catch(L){ue(p.deviceSidebar.scanError.replace("{error}",String(L))),T([])}finally{re(!1)}},[p.deviceSidebar.scanError,re]),se=async(L,ee)=>{if(!ee&&!L.has_pairing){$(!0),R("");try{const le=await du({ip:L.ip,port:L.port});le.success?h(!1):R(le.message||p.toasts.wifiManualConnectError)}catch(le){R(p.toasts.wifiManualConnectError),console.error("[DeviceSidebar] Error connecting:",le)}finally{$(!1)}}else ee&&L.has_pairing&&(y(L.ip),V(L.pairing_port?String(L.pairing_port):""),I(String(L.port)),setTimeout(()=>{document.getElementById("pairing-code")?.focus()},100))};return v.useEffect(()=>{if(g){ne();const L=setInterval(()=>{ne()},5e3);return()=>{clearInterval(L)}}},[g,ne]),o.jsxs(o.Fragment,{children:[b&&o.jsx(ve,{variant:"outline",size:"icon",onClick:at,className:"absolute left-0 top-20 z-50 h-16 w-8 rounded-r-lg rounded-l-none border-l-0 bg-slate-100 hover:bg-slate-200 dark:bg-slate-800 dark:hover:bg-slate-700",title:"Expand sidebar",children:o.jsx(ka,{className:"h-4 w-4"})}),o.jsxs("div",{className:`
26
- ${b?"w-0 -ml-4 opacity-0":"w-80 opacity-100"}
27
- transition-all duration-300 ease-in-out
28
- h-full min-h-0
29
- bg-white dark:bg-slate-950
30
- border-r border-slate-200 dark:border-slate-800
31
- flex flex-col
32
- overflow-hidden
33
- `,children:[o.jsxs("div",{className:"flex items-center justify-between p-4",children:[o.jsx("div",{className:"flex items-center gap-2",children:o.jsxs("div",{children:[o.jsx("h2",{className:"text-base font-bold text-slate-900 dark:text-slate-100",children:"AutoGLM"}),o.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:[s.length," ",(s.length===1,p.deviceSidebar.devices)]})]})}),o.jsx(ve,{variant:"ghost",size:"icon",onClick:at,className:"h-8 w-8 rounded-full text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300",title:"Collapse sidebar",children:o.jsx(Ca,{className:"h-4 w-4"})})]}),o.jsx(ns,{className:"mx-4"}),o.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-2 min-h-0",children:s.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[o.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800",children:o.jsx(Xv,{className:"h-8 w-8 text-slate-400"})}),o.jsx("p",{className:"mt-4 font-medium text-slate-900 dark:text-slate-100",children:p.deviceSidebar.noDevicesConnected}),o.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:p.deviceSidebar.clickToRefresh})]}):s.map(L=>o.jsx(u1,{id:L.id,serial:L.serial,model:L.model,status:L.status,connectionType:L.connection_type,agent:L.agent,isActive:n===L.id,onClick:()=>r(L.id),onConnectWifi:async()=>{await u(L.id)},onDisconnectWifi:async()=>{await l(L.id)}},L.id))}),o.jsx(ns,{className:"mx-4"}),o.jsxs("div",{className:"p-3 space-y-2",children:[o.jsxs(ve,{variant:"outline",onClick:()=>h(!0),className:"w-full justify-start gap-2 rounded-full border-slate-200 dark:border-slate-700",children:[o.jsx(vv,{className:"h-4 w-4"}),p.deviceSidebar.addDevice]}),o.jsxs(ve,{variant:"outline",onClick:a,className:"w-full justify-start gap-2 rounded-full border-slate-200 dark:border-slate-700",children:[o.jsx(ad,{className:"h-4 w-4"}),p.deviceSidebar.settings]})]}),o.jsx(Vu,{open:g,onOpenChange:h,children:o.jsxs(Ku,{className:"sm:max-w-md max-h-[80vh] overflow-y-auto",children:[o.jsxs(Qu,{children:[o.jsx(Ju,{children:p.deviceSidebar.manualConnectTitle}),o.jsx(Zu,{children:p.deviceSidebar.manualConnectDescription})]}),o.jsxs(j1,{value:A,onValueChange:G,className:"w-full",children:[o.jsxs(P1,{className:"grid w-full grid-cols-2",children:[o.jsx(vu,{value:"direct",children:p.deviceSidebar.directConnectTab}),o.jsx(vu,{value:"pair",children:p.deviceSidebar.pairTab})]}),o.jsxs(bu,{value:"direct",className:"space-y-4 mt-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("h3",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:p.deviceSidebar.discoveredDevices}),o.jsx(ve,{variant:"outline",size:"sm",onClick:ne,disabled:O,className:"h-8",children:O?o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"mr-2 h-3 w-3 animate-spin rounded-full border-2 border-slate-400 border-t-transparent"}),p.deviceSidebar.scanning]}):p.deviceSidebar.scanAgain})]}),de&&o.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-950/20 p-3",children:o.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:de})}),(()=>{const L=J.filter(ee=>!ee.has_pairing);return!O&&L.length===0?o.jsxs("div",{className:"rounded-lg bg-slate-50 dark:bg-slate-900 p-4 text-center",children:[o.jsx(fa,{className:"mx-auto h-8 w-8 text-slate-400"}),o.jsx("p",{className:"mt-2 text-sm text-slate-500 dark:text-slate-400",children:p.deviceSidebar.noDirectDevices})]}):L.length>0?o.jsx("div",{className:"space-y-2",children:L.map(ee=>o.jsx("button",{onClick:()=>se(ee,!1),disabled:ye,className:"w-full rounded-lg border border-slate-200 dark:border-slate-700 p-3 text-left transition-colors hover:bg-slate-50 dark:hover:bg-slate-800 disabled:opacity-50 disabled:cursor-not-allowed",children:o.jsx("div",{className:"flex items-start justify-between",children:o.jsxs("div",{className:"flex-1",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(da,{className:"h-4 w-4 text-[#1d9bf0]"}),o.jsx("span",{className:"font-medium text-slate-900 dark:text-slate-100",children:ee.name})]}),o.jsxs("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:[ee.ip,":",ee.port]})]})})},`${ee.ip}:${ee.port}`))}):null})(),j&&A==="direct"&&o.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-950/20 p-3",children:o.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:j})}),o.jsxs("div",{className:"relative my-4",children:[o.jsx(ns,{}),o.jsx("span",{className:"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-white dark:bg-slate-950 px-2 text-sm text-slate-500",children:p.deviceSidebar.orManualConnect})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsx("div",{className:"rounded-lg bg-amber-50 dark:bg-amber-950/20 p-3 text-sm",children:o.jsx("p",{className:"text-amber-800 dark:text-amber-200",children:p.deviceSidebar.directConnectNote})}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"ip",children:p.deviceSidebar.ipAddress}),o.jsx($t,{id:"ip",placeholder:"192.168.1.100",value:_,onChange:L=>y(L.target.value),onKeyDown:L=>L.key==="Enter"&&$e(),className:j?"border-red-500":""})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"port",children:p.deviceSidebar.port}),o.jsx($t,{id:"port",type:"number",value:S,onChange:L=>N(L.target.value),onKeyDown:L=>L.key==="Enter"&&$e(),className:M?"border-red-500":""}),M&&o.jsx("p",{className:"text-sm text-red-500",children:M})]}),o.jsx(ve,{onClick:$e,disabled:ye,className:"w-full",children:ye?p.common.loading:p.deviceSidebar.connect})]})]}),o.jsxs(bu,{value:"pair",className:"space-y-4 mt-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("h3",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:p.deviceSidebar.discoveredDevices}),o.jsx(ve,{variant:"outline",size:"sm",onClick:ne,disabled:O,className:"h-8",children:O?o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"mr-2 h-3 w-3 animate-spin rounded-full border-2 border-slate-400 border-t-transparent"}),p.deviceSidebar.scanning]}):p.deviceSidebar.scanAgain})]}),de&&o.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-950/20 p-3",children:o.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:de})}),(()=>{const L=J.filter(ee=>ee.has_pairing);return!O&&L.length===0?o.jsxs("div",{className:"rounded-lg bg-slate-50 dark:bg-slate-900 p-4 text-center",children:[o.jsx(fa,{className:"mx-auto h-8 w-8 text-slate-400"}),o.jsx("p",{className:"mt-2 text-sm text-slate-500 dark:text-slate-400",children:p.deviceSidebar.noPairingDevices})]}):L.length>0?o.jsx("div",{className:"space-y-2",children:L.map(ee=>o.jsx("button",{onClick:()=>se(ee,!0),disabled:ye,className:"w-full rounded-lg border border-slate-200 dark:border-slate-700 p-3 text-left transition-colors hover:bg-slate-50 dark:hover:bg-slate-800 disabled:opacity-50 disabled:cursor-not-allowed",children:o.jsx("div",{className:"flex items-start justify-between",children:o.jsxs("div",{className:"flex-1",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(da,{className:"h-4 w-4 text-[#1d9bf0]"}),o.jsx("span",{className:"font-medium text-slate-900 dark:text-slate-100",children:ee.name})]}),o.jsxs("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:[ee.ip,":",ee.port]}),o.jsxs("div",{className:"mt-2 flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400",children:[o.jsx(Nn,{className:"h-3 w-3"}),o.jsx("span",{children:p.deviceSidebar.pairingRequired})]})]})})},`${ee.ip}:${ee.port}`))}):null})(),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"relative my-4",children:[o.jsx(ns,{}),o.jsx("span",{className:"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-white dark:bg-slate-950 px-2 text-sm text-slate-500",children:p.deviceSidebar.orQrPair})]}),o.jsxs("div",{className:"rounded-lg bg-purple-50 dark:bg-purple-950/20 p-3 text-sm",children:[o.jsx("p",{className:"font-medium text-purple-900 dark:text-purple-100 mb-2",children:p.deviceSidebar.qrPairingTitle}),o.jsxs("ol",{className:"space-y-1 text-purple-700 dark:text-purple-300 text-xs",children:[o.jsx("li",{children:p.deviceSidebar.qrStep1}),o.jsx("li",{children:p.deviceSidebar.qrStep2}),o.jsx("li",{children:p.deviceSidebar.qrStep3})]})]}),Z&&o.jsx("div",{className:"rounded-lg border border-slate-200 dark:border-slate-700 p-4 bg-white dark:bg-slate-900",children:o.jsxs("div",{className:"flex flex-col items-center space-y-3",children:[o.jsx("div",{className:"bg-white p-4 rounded-lg",children:o.jsx(Fd,{value:Z.payload,size:200,level:"M"})}),o.jsxs("div",{className:"flex items-center gap-2",children:[Z.status==="listening"&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"h-2 w-2 rounded-full bg-blue-500 animate-pulse"}),o.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:p.deviceSidebar.qrWaitingForScan})]}),Z.status==="pairing"&&o.jsxs(o.Fragment,{children:[o.jsx(hn,{className:"h-4 w-4 animate-spin text-blue-500"}),o.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:p.deviceSidebar.qrPairing})]}),Z.status==="connected"&&o.jsxs(o.Fragment,{children:[o.jsx(Mv,{className:"h-4 w-4 text-green-500"}),o.jsx("span",{className:"text-sm text-green-600 dark:text-green-400",children:p.deviceSidebar.qrConnected})]}),Z.status==="timeout"&&o.jsxs(o.Fragment,{children:[o.jsx(ca,{className:"h-4 w-4 text-amber-500"}),o.jsx("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:p.deviceSidebar.qrTimeout})]}),Z.status==="error"&&o.jsxs(o.Fragment,{children:[o.jsx(ca,{className:"h-4 w-4 text-red-500"}),o.jsx("span",{className:"text-sm text-red-600 dark:text-red-400",children:p.deviceSidebar.qrError})]})]}),o.jsxs("div",{className:"flex gap-2 w-full",children:[(Z.status==="timeout"||Z.status==="error")&&o.jsx(ve,{variant:"outline",onClick:Xe,className:"flex-1",children:p.deviceSidebar.qrRegenerate}),Z.status==="listening"&&o.jsx(ve,{variant:"outline",onClick:gt,className:"flex-1",children:p.common.cancel}),Z.status==="connected"&&o.jsx(ve,{onClick:()=>h(!1),className:"flex-1",children:p.common.confirm})]})]})}),!Z&&je&&o.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-slate-600 dark:text-slate-400",children:[o.jsx(hn,{className:"h-4 w-4 animate-spin"}),o.jsx("span",{className:"text-sm",children:p.common.loading})]})]}),o.jsxs("div",{className:"relative my-4",children:[o.jsx(ns,{}),o.jsx("span",{className:"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-white dark:bg-slate-950 px-2 text-sm text-slate-500",children:p.deviceSidebar.orManualPair})]}),o.jsxs("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-950/20 p-3 text-sm",children:[o.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100 mb-2",children:p.deviceSidebar.pairingInstructions}),o.jsxs("ol",{className:"space-y-1 text-blue-700 dark:text-blue-300 text-xs",children:[o.jsx("li",{children:p.deviceSidebar.pairingStep1}),o.jsx("li",{children:p.deviceSidebar.pairingStep2}),o.jsx("li",{children:p.deviceSidebar.pairingStep3}),o.jsx("li",{children:p.deviceSidebar.pairingStep4})]}),o.jsx("p",{className:"mt-2 text-xs text-blue-600 dark:text-blue-400",children:p.deviceSidebar.pairingNote})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"pair-ip",children:p.deviceSidebar.ipAddress}),o.jsx($t,{id:"pair-ip",placeholder:"192.168.1.100",value:_,onChange:L=>y(L.target.value),className:j?"border-red-500":""}),j&&A==="pair"&&o.jsx("p",{className:"text-sm text-red-500",children:j})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"pairing-port",children:p.deviceSidebar.pairingPort}),o.jsx($t,{id:"pairing-port",type:"number",placeholder:"37831",value:K,onChange:L=>V(L.target.value),className:M?"border-red-500":""}),M&&o.jsx("p",{className:"text-sm text-red-500",children:M})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"pairing-code",children:p.deviceSidebar.pairingCode}),o.jsx($t,{id:"pairing-code",type:"text",placeholder:"123456",maxLength:6,value:q,onChange:L=>X(L.target.value.replace(/\D/g,"")),onKeyDown:L=>L.key==="Enter"&&mt(),className:D?"border-red-500":""}),D&&o.jsx("p",{className:"text-sm text-red-500",children:D})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"connection-port",children:p.deviceSidebar.connectionPort}),o.jsx($t,{id:"connection-port",type:"number",value:U,onChange:L=>I(L.target.value),onKeyDown:L=>L.key==="Enter"&&mt()})]}),o.jsx(ve,{onClick:mt,disabled:ye,className:"w-full",children:ye?p.common.loading:p.deviceSidebar.pairAndConnect})]})]})]}),o.jsx(ed,{children:o.jsx(ve,{variant:"outline",onClick:()=>{h(!1),R(""),F(""),me(""),ue(""),y(""),N("5555"),X(""),V(""),I("5555"),G("direct"),T([])},children:p.common.cancel})})]})})]})]})}const Tn=Object.create(null);Tn.open="0";Tn.close="1";Tn.ping="2";Tn.pong="3";Tn.message="4";Tn.upgrade="5";Tn.noop="6";const ui=Object.create(null);Object.keys(Tn).forEach(s=>{ui[Tn[s]]=s});const xa={type:"error",data:"parser error"},Ud=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",Wd=typeof ArrayBuffer=="function",zd=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,Aa=({type:s,data:n},r,a)=>Ud&&n instanceof Blob?r?a(n):Eu(n,a):Wd&&(n instanceof ArrayBuffer||zd(n))?r?a(n):Eu(new Blob([n]),a):a(Tn[s]+(n||"")),Eu=(s,n)=>{const r=new FileReader;return r.onload=function(){const a=r.result.split(",")[1];n("b"+(a||""))},r.readAsDataURL(s)};function Su(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}let Vo;function Y1(s,n){if(Ud&&s.data instanceof Blob)return s.data.arrayBuffer().then(Su).then(n);if(Wd&&(s.data instanceof ArrayBuffer||zd(s.data)))return n(Su(s.data));Aa(s,!1,r=>{Vo||(Vo=new TextEncoder),n(Vo.encode(r))})}const Nu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",cs=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<Nu.length;s++)cs[Nu.charCodeAt(s)]=s;const V1=s=>{let n=s.length*.75,r=s.length,a,u=0,l,p,b,f;s[s.length-1]==="="&&(n--,s[s.length-2]==="="&&n--);const g=new ArrayBuffer(n),h=new Uint8Array(g);for(a=0;a<r;a+=4)l=cs[s.charCodeAt(a)],p=cs[s.charCodeAt(a+1)],b=cs[s.charCodeAt(a+2)],f=cs[s.charCodeAt(a+3)],h[u++]=l<<2|p>>4,h[u++]=(p&15)<<4|b>>2,h[u++]=(b&3)<<6|f&63;return g},K1=typeof ArrayBuffer=="function",ja=(s,n)=>{if(typeof s!="string")return{type:"message",data:Hd(s,n)};const r=s.charAt(0);return r==="b"?{type:"message",data:Q1(s.substring(1),n)}:ui[r]?s.length>1?{type:ui[r],data:s.substring(1)}:{type:ui[r]}:xa},Q1=(s,n)=>{if(K1){const r=V1(s);return Hd(r,n)}else return{base64:!0,data:s}},Hd=(s,n)=>{switch(n){case"blob":return s instanceof Blob?s:new Blob([s]);case"arraybuffer":default:return s instanceof ArrayBuffer?s:s.buffer}},Gd="",J1=(s,n)=>{const r=s.length,a=new Array(r);let u=0;s.forEach((l,p)=>{Aa(l,!1,b=>{a[p]=b,++u===r&&n(a.join(Gd))})})},Z1=(s,n)=>{const r=s.split(Gd),a=[];for(let u=0;u<r.length;u++){const l=ja(r[u],n);if(a.push(l),l.type==="error")break}return a};function eb(){return new TransformStream({transform(s,n){Y1(s,r=>{const a=r.length;let u;if(a<126)u=new Uint8Array(1),new DataView(u.buffer).setUint8(0,a);else if(a<65536){u=new Uint8Array(3);const l=new DataView(u.buffer);l.setUint8(0,126),l.setUint16(1,a)}else{u=new Uint8Array(9);const l=new DataView(u.buffer);l.setUint8(0,127),l.setBigUint64(1,BigInt(a))}s.data&&typeof s.data!="string"&&(u[0]|=128),n.enqueue(u),n.enqueue(r)})}})}let Ko;function li(s){return s.reduce((n,r)=>n+r.length,0)}function ci(s,n){if(s[0].length===n)return s.shift();const r=new Uint8Array(n);let a=0;for(let u=0;u<n;u++)r[u]=s[0][a++],a===s[0].length&&(s.shift(),a=0);return s.length&&a<s[0].length&&(s[0]=s[0].slice(a)),r}function tb(s,n){Ko||(Ko=new TextDecoder);const r=[];let a=0,u=-1,l=!1;return new TransformStream({transform(p,b){for(r.push(p);;){if(a===0){if(li(r)<1)break;const f=ci(r,1);l=(f[0]&128)===128,u=f[0]&127,u<126?a=3:u===126?a=1:a=2}else if(a===1){if(li(r)<2)break;const f=ci(r,2);u=new DataView(f.buffer,f.byteOffset,f.length).getUint16(0),a=3}else if(a===2){if(li(r)<8)break;const f=ci(r,8),g=new DataView(f.buffer,f.byteOffset,f.length),h=g.getUint32(0);if(h>Math.pow(2,21)-1){b.enqueue(xa);break}u=h*Math.pow(2,32)+g.getUint32(4),a=3}else{if(li(r)<u)break;const f=ci(r,u);b.enqueue(ja(l?f:Ko.decode(f),n)),a=0}if(u===0||u>s){b.enqueue(xa);break}}}})}const $d=4;function pt(s){if(s)return nb(s)}function nb(s){for(var n in pt.prototype)s[n]=pt.prototype[n];return s}pt.prototype.on=pt.prototype.addEventListener=function(s,n){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(n),this};pt.prototype.once=function(s,n){function r(){this.off(s,r),n.apply(this,arguments)}return r.fn=n,this.on(s,r),this};pt.prototype.off=pt.prototype.removeListener=pt.prototype.removeAllListeners=pt.prototype.removeEventListener=function(s,n){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var r=this._callbacks["$"+s];if(!r)return this;if(arguments.length==1)return delete this._callbacks["$"+s],this;for(var a,u=0;u<r.length;u++)if(a=r[u],a===n||a.fn===n){r.splice(u,1);break}return r.length===0&&delete this._callbacks["$"+s],this};pt.prototype.emit=function(s){this._callbacks=this._callbacks||{};for(var n=new Array(arguments.length-1),r=this._callbacks["$"+s],a=1;a<arguments.length;a++)n[a-1]=arguments[a];if(r){r=r.slice(0);for(var a=0,u=r.length;a<u;++a)r[a].apply(this,n)}return this};pt.prototype.emitReserved=pt.prototype.emit;pt.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]};pt.prototype.hasListeners=function(s){return!!this.listeners(s).length};const Ci=typeof Promise=="function"&&typeof Promise.resolve=="function"?n=>Promise.resolve().then(n):(n,r)=>r(n,0),fn=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),rb="arraybuffer";function qd(s,...n){return n.reduce((r,a)=>(s.hasOwnProperty(a)&&(r[a]=s[a]),r),{})}const sb=fn.setTimeout,ib=fn.clearTimeout;function ki(s,n){n.useNativeTimers?(s.setTimeoutFn=sb.bind(fn),s.clearTimeoutFn=ib.bind(fn)):(s.setTimeoutFn=fn.setTimeout.bind(fn),s.clearTimeoutFn=fn.clearTimeout.bind(fn))}const ob=1.33;function ab(s){return typeof s=="string"?lb(s):Math.ceil((s.byteLength||s.size)*ob)}function lb(s){let n=0,r=0;for(let a=0,u=s.length;a<u;a++)n=s.charCodeAt(a),n<128?r+=1:n<2048?r+=2:n<55296||n>=57344?r+=3:(a++,r+=4);return r}function Xd(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function cb(s){let n="";for(let r in s)s.hasOwnProperty(r)&&(n.length&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(s[r]));return n}function ub(s){let n={},r=s.split("&");for(let a=0,u=r.length;a<u;a++){let l=r[a].split("=");n[decodeURIComponent(l[0])]=decodeURIComponent(l[1])}return n}class db extends Error{constructor(n,r,a){super(n),this.description=r,this.context=a,this.type="TransportError"}}class Pa extends pt{constructor(n){super(),this.writable=!1,ki(this,n),this.opts=n,this.query=n.query,this.socket=n.socket,this.supportsBinary=!n.forceBase64}onError(n,r,a){return super.emitReserved("error",new db(n,r,a)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(n){this.readyState==="open"&&this.write(n)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(n){const r=ja(n,this.socket.binaryType);this.onPacket(r)}onPacket(n){super.emitReserved("packet",n)}onClose(n){this.readyState="closed",super.emitReserved("close",n)}pause(n){}createUri(n,r={}){return n+"://"+this._hostname()+this._port()+this.opts.path+this._query(r)}_hostname(){const n=this.opts.hostname;return n.indexOf(":")===-1?n:"["+n+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(n){const r=cb(n);return r.length?"?"+r:""}}class fb extends Pa{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(n){this.readyState="pausing";const r=()=>{this.readyState="paused",n()};if(this._polling||!this.writable){let a=0;this._polling&&(a++,this.once("pollComplete",function(){--a||r()})),this.writable||(a++,this.once("drain",function(){--a||r()}))}else r()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(n){const r=a=>{if(this.readyState==="opening"&&a.type==="open"&&this.onOpen(),a.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(a)};Z1(n,this.socket.binaryType).forEach(r),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const n=()=>{this.write([{type:"close"}])};this.readyState==="open"?n():this.once("open",n)}write(n){this.writable=!1,J1(n,r=>{this.doWrite(r,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const n=this.opts.secure?"https":"http",r=this.query||{};return this.opts.timestampRequests!==!1&&(r[this.opts.timestampParam]=Xd()),!this.supportsBinary&&!r.sid&&(r.b64=1),this.createUri(n,r)}}let Yd=!1;try{Yd=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const hb=Yd;function pb(){}class mb extends fb{constructor(n){if(super(n),typeof location<"u"){const r=location.protocol==="https:";let a=location.port;a||(a=r?"443":"80"),this.xd=typeof location<"u"&&n.hostname!==location.hostname||a!==n.port}}doWrite(n,r){const a=this.request({method:"POST",data:n});a.on("success",r),a.on("error",(u,l)=>{this.onError("xhr post error",u,l)})}doPoll(){const n=this.request();n.on("data",this.onData.bind(this)),n.on("error",(r,a)=>{this.onError("xhr poll error",r,a)}),this.pollXhr=n}}class kn extends pt{constructor(n,r,a){super(),this.createRequest=n,ki(this,a),this._opts=a,this._method=a.method||"GET",this._uri=r,this._data=a.data!==void 0?a.data:null,this._create()}_create(){var n;const r=qd(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");r.xdomain=!!this._opts.xd;const a=this._xhr=this.createRequest(r);try{a.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){a.setDisableHeaderCheck&&a.setDisableHeaderCheck(!0);for(let u in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(u)&&a.setRequestHeader(u,this._opts.extraHeaders[u])}}catch{}if(this._method==="POST")try{a.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{a.setRequestHeader("Accept","*/*")}catch{}(n=this._opts.cookieJar)===null||n===void 0||n.addCookies(a),"withCredentials"in a&&(a.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(a.timeout=this._opts.requestTimeout),a.onreadystatechange=()=>{var u;a.readyState===3&&((u=this._opts.cookieJar)===null||u===void 0||u.parseCookies(a.getResponseHeader("set-cookie"))),a.readyState===4&&(a.status===200||a.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof a.status=="number"?a.status:0)},0))},a.send(this._data)}catch(u){this.setTimeoutFn(()=>{this._onError(u)},0);return}typeof document<"u"&&(this._index=kn.requestsCount++,kn.requests[this._index]=this)}_onError(n){this.emitReserved("error",n,this._xhr),this._cleanup(!0)}_cleanup(n){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=pb,n)try{this._xhr.abort()}catch{}typeof document<"u"&&delete kn.requests[this._index],this._xhr=null}}_onLoad(){const n=this._xhr.responseText;n!==null&&(this.emitReserved("data",n),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}kn.requestsCount=0;kn.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",Cu);else if(typeof addEventListener=="function"){const s="onpagehide"in fn?"pagehide":"unload";addEventListener(s,Cu,!1)}}function Cu(){for(let s in kn.requests)kn.requests.hasOwnProperty(s)&&kn.requests[s].abort()}const gb=(function(){const s=Vd({xdomain:!1});return s&&s.responseType!==null})();class xb extends mb{constructor(n){super(n);const r=n&&n.forceBase64;this.supportsBinary=gb&&!r}request(n={}){return Object.assign(n,{xd:this.xd},this.opts),new kn(Vd,this.uri(),n)}}function Vd(s){const n=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!n||hb))return new XMLHttpRequest}catch{}if(!n)try{return new fn[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const Kd=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class _b extends Pa{get name(){return"websocket"}doOpen(){const n=this.uri(),r=this.opts.protocols,a=Kd?{}:qd(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(a.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(n,r,a)}catch(u){return this.emitReserved("error",u)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=n=>this.onClose({description:"websocket connection closed",context:n}),this.ws.onmessage=n=>this.onData(n.data),this.ws.onerror=n=>this.onError("websocket error",n)}write(n){this.writable=!1;for(let r=0;r<n.length;r++){const a=n[r],u=r===n.length-1;Aa(a,this.supportsBinary,l=>{try{this.doWrite(a,l)}catch{}u&&Ci(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const n=this.opts.secure?"wss":"ws",r=this.query||{};return this.opts.timestampRequests&&(r[this.opts.timestampParam]=Xd()),this.supportsBinary||(r.b64=1),this.createUri(n,r)}}const Qo=fn.WebSocket||fn.MozWebSocket;class vb extends _b{createSocket(n,r,a){return Kd?new Qo(n,r,a):r?new Qo(n,r):new Qo(n)}doWrite(n,r){this.ws.send(r)}}class bb extends Pa{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(n){return this.emitReserved("error",n)}this._transport.closed.then(()=>{this.onClose()}).catch(n=>{this.onError("webtransport error",n)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(n=>{const r=tb(Number.MAX_SAFE_INTEGER,this.socket.binaryType),a=n.readable.pipeThrough(r).getReader(),u=eb();u.readable.pipeTo(n.writable),this._writer=u.writable.getWriter();const l=()=>{a.read().then(({done:b,value:f})=>{b||(this.onPacket(f),l())}).catch(b=>{})};l();const p={type:"open"};this.query.sid&&(p.data=`{"sid":"${this.query.sid}"}`),this._writer.write(p).then(()=>this.onOpen())})})}write(n){this.writable=!1;for(let r=0;r<n.length;r++){const a=n[r],u=r===n.length-1;this._writer.write(a).then(()=>{u&&Ci(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var n;(n=this._transport)===null||n===void 0||n.close()}}const yb={websocket:vb,webtransport:bb,polling:xb},wb=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Eb=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function _a(s){if(s.length>8e3)throw"URI too long";const n=s,r=s.indexOf("["),a=s.indexOf("]");r!=-1&&a!=-1&&(s=s.substring(0,r)+s.substring(r,a).replace(/:/g,";")+s.substring(a,s.length));let u=wb.exec(s||""),l={},p=14;for(;p--;)l[Eb[p]]=u[p]||"";return r!=-1&&a!=-1&&(l.source=n,l.host=l.host.substring(1,l.host.length-1).replace(/;/g,":"),l.authority=l.authority.replace("[","").replace("]","").replace(/;/g,":"),l.ipv6uri=!0),l.pathNames=Sb(l,l.path),l.queryKey=Nb(l,l.query),l}function Sb(s,n){const r=/\/{2,9}/g,a=n.replace(r,"/").split("/");return(n.slice(0,1)=="/"||n.length===0)&&a.splice(0,1),n.slice(-1)=="/"&&a.splice(a.length-1,1),a}function Nb(s,n){const r={};return n.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(a,u,l){u&&(r[u]=l)}),r}const va=typeof addEventListener=="function"&&typeof removeEventListener=="function",di=[];va&&addEventListener("offline",()=>{di.forEach(s=>s())},!1);class tr extends pt{constructor(n,r){if(super(),this.binaryType=rb,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,n&&typeof n=="object"&&(r=n,n=null),n){const a=_a(n);r.hostname=a.host,r.secure=a.protocol==="https"||a.protocol==="wss",r.port=a.port,a.query&&(r.query=a.query)}else r.host&&(r.hostname=_a(r.host).host);ki(this,r),this.secure=r.secure!=null?r.secure:typeof location<"u"&&location.protocol==="https:",r.hostname&&!r.port&&(r.port=this.secure?"443":"80"),this.hostname=r.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=r.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},r.transports.forEach(a=>{const u=a.prototype.name;this.transports.push(u),this._transportsByName[u]=a}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},r),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=ub(this.opts.query)),va&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},di.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(n){const r=Object.assign({},this.opts.query);r.EIO=$d,r.transport=n,this.id&&(r.sid=this.id);const a=Object.assign({},this.opts,{query:r,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[n]);return new this._transportsByName[n](a)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const n=this.opts.rememberUpgrade&&tr.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const r=this.createTransport(n);r.open(),this.setTransport(r)}setTransport(n){this.transport&&this.transport.removeAllListeners(),this.transport=n,n.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",r=>this._onClose("transport close",r))}onOpen(){this.readyState="open",tr.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",n),this.emitReserved("heartbeat"),n.type){case"open":this.onHandshake(JSON.parse(n.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const r=new Error("server error");r.code=n.data,this._onError(r);break;case"message":this.emitReserved("data",n.data),this.emitReserved("message",n.data);break}}onHandshake(n){this.emitReserved("handshake",n),this.id=n.sid,this.transport.query.sid=n.sid,this._pingInterval=n.pingInterval,this._pingTimeout=n.pingTimeout,this._maxPayload=n.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const n=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+n,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},n),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const n=this._getWritablePackets();this.transport.send(n),this._prevBufferLen=n.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let r=1;for(let a=0;a<this.writeBuffer.length;a++){const u=this.writeBuffer[a].data;if(u&&(r+=ab(u)),a>0&&r>this._maxPayload)return this.writeBuffer.slice(0,a);r+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const n=Date.now()>this._pingTimeoutTime;return n&&(this._pingTimeoutTime=0,Ci(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),n}write(n,r,a){return this._sendPacket("message",n,r,a),this}send(n,r,a){return this._sendPacket("message",n,r,a),this}_sendPacket(n,r,a,u){if(typeof r=="function"&&(u=r,r=void 0),typeof a=="function"&&(u=a,a=null),this.readyState==="closing"||this.readyState==="closed")return;a=a||{},a.compress=a.compress!==!1;const l={type:n,data:r,options:a};this.emitReserved("packetCreate",l),this.writeBuffer.push(l),u&&this.once("flush",u),this.flush()}close(){const n=()=>{this._onClose("forced close"),this.transport.close()},r=()=>{this.off("upgrade",r),this.off("upgradeError",r),n()},a=()=>{this.once("upgrade",r),this.once("upgradeError",r)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?a():n()}):this.upgrading?a():n()),this}_onError(n){if(tr.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",n),this._onClose("transport error",n)}_onClose(n,r){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),va&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const a=di.indexOf(this._offlineEventListener);a!==-1&&di.splice(a,1)}this.readyState="closed",this.id=null,this.emitReserved("close",n,r),this.writeBuffer=[],this._prevBufferLen=0}}}tr.protocol=$d;class Cb extends tr{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let n=0;n<this._upgrades.length;n++)this._probe(this._upgrades[n])}_probe(n){let r=this.createTransport(n),a=!1;tr.priorWebsocketSuccess=!1;const u=()=>{a||(r.send([{type:"ping",data:"probe"}]),r.once("packet",_=>{if(!a)if(_.type==="pong"&&_.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",r),!r)return;tr.priorWebsocketSuccess=r.name==="websocket",this.transport.pause(()=>{a||this.readyState!=="closed"&&(h(),this.setTransport(r),r.send([{type:"upgrade"}]),this.emitReserved("upgrade",r),r=null,this.upgrading=!1,this.flush())})}else{const y=new Error("probe error");y.transport=r.name,this.emitReserved("upgradeError",y)}}))};function l(){a||(a=!0,h(),r.close(),r=null)}const p=_=>{const y=new Error("probe error: "+_);y.transport=r.name,l(),this.emitReserved("upgradeError",y)};function b(){p("transport closed")}function f(){p("socket closed")}function g(_){r&&_.name!==r.name&&l()}const h=()=>{r.removeListener("open",u),r.removeListener("error",p),r.removeListener("close",b),this.off("close",f),this.off("upgrading",g)};r.once("open",u),r.once("error",p),r.once("close",b),this.once("close",f),this.once("upgrading",g),this._upgrades.indexOf("webtransport")!==-1&&n!=="webtransport"?this.setTimeoutFn(()=>{a||r.open()},200):r.open()}onHandshake(n){this._upgrades=this._filterUpgrades(n.upgrades),super.onHandshake(n)}_filterUpgrades(n){const r=[];for(let a=0;a<n.length;a++)~this.transports.indexOf(n[a])&&r.push(n[a]);return r}}let kb=class extends Cb{constructor(n,r={}){const a=typeof n=="object"?n:r;(!a.transports||a.transports&&typeof a.transports[0]=="string")&&(a.transports=(a.transports||["polling","websocket","webtransport"]).map(u=>yb[u]).filter(u=>!!u)),super(n,a)}};function Tb(s,n="",r){let a=s;r=r||typeof location<"u"&&location,s==null&&(s=r.protocol+"//"+r.host),typeof s=="string"&&(s.charAt(0)==="/"&&(s.charAt(1)==="/"?s=r.protocol+s:s=r.host+s),/^(https?|wss?):\/\//.test(s)||(typeof r<"u"?s=r.protocol+"//"+s:s="https://"+s),a=_a(s)),a.port||(/^(http|ws)$/.test(a.protocol)?a.port="80":/^(http|ws)s$/.test(a.protocol)&&(a.port="443")),a.path=a.path||"/";const l=a.host.indexOf(":")!==-1?"["+a.host+"]":a.host;return a.id=a.protocol+"://"+l+":"+a.port+n,a.href=a.protocol+"://"+l+(r&&r.port===a.port?"":":"+a.port),a}const Rb=typeof ArrayBuffer=="function",Ab=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s.buffer instanceof ArrayBuffer,Qd=Object.prototype.toString,jb=typeof Blob=="function"||typeof Blob<"u"&&Qd.call(Blob)==="[object BlobConstructor]",Pb=typeof File=="function"||typeof File<"u"&&Qd.call(File)==="[object FileConstructor]";function Ma(s){return Rb&&(s instanceof ArrayBuffer||Ab(s))||jb&&s instanceof Blob||Pb&&s instanceof File}function fi(s,n){if(!s||typeof s!="object")return!1;if(Array.isArray(s)){for(let r=0,a=s.length;r<a;r++)if(fi(s[r]))return!0;return!1}if(Ma(s))return!0;if(s.toJSON&&typeof s.toJSON=="function"&&arguments.length===1)return fi(s.toJSON(),!0);for(const r in s)if(Object.prototype.hasOwnProperty.call(s,r)&&fi(s[r]))return!0;return!1}function Mb(s){const n=[],r=s.data,a=s;return a.data=ba(r,n),a.attachments=n.length,{packet:a,buffers:n}}function ba(s,n){if(!s)return s;if(Ma(s)){const r={_placeholder:!0,num:n.length};return n.push(s),r}else if(Array.isArray(s)){const r=new Array(s.length);for(let a=0;a<s.length;a++)r[a]=ba(s[a],n);return r}else if(typeof s=="object"&&!(s instanceof Date)){const r={};for(const a in s)Object.prototype.hasOwnProperty.call(s,a)&&(r[a]=ba(s[a],n));return r}return s}function Ib(s,n){return s.data=ya(s.data,n),delete s.attachments,s}function ya(s,n){if(!s)return s;if(s&&s._placeholder===!0){if(typeof s.num=="number"&&s.num>=0&&s.num<n.length)return n[s.num];throw new Error("illegal attachments")}else if(Array.isArray(s))for(let r=0;r<s.length;r++)s[r]=ya(s[r],n);else if(typeof s=="object")for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&(s[r]=ya(s[r],n));return s}const Db=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Lb=5;var Le;(function(s){s[s.CONNECT=0]="CONNECT",s[s.DISCONNECT=1]="DISCONNECT",s[s.EVENT=2]="EVENT",s[s.ACK=3]="ACK",s[s.CONNECT_ERROR=4]="CONNECT_ERROR",s[s.BINARY_EVENT=5]="BINARY_EVENT",s[s.BINARY_ACK=6]="BINARY_ACK"})(Le||(Le={}));class Ob{constructor(n){this.replacer=n}encode(n){return(n.type===Le.EVENT||n.type===Le.ACK)&&fi(n)?this.encodeAsBinary({type:n.type===Le.EVENT?Le.BINARY_EVENT:Le.BINARY_ACK,nsp:n.nsp,data:n.data,id:n.id}):[this.encodeAsString(n)]}encodeAsString(n){let r=""+n.type;return(n.type===Le.BINARY_EVENT||n.type===Le.BINARY_ACK)&&(r+=n.attachments+"-"),n.nsp&&n.nsp!=="/"&&(r+=n.nsp+","),n.id!=null&&(r+=n.id),n.data!=null&&(r+=JSON.stringify(n.data,this.replacer)),r}encodeAsBinary(n){const r=Mb(n),a=this.encodeAsString(r.packet),u=r.buffers;return u.unshift(a),u}}function ku(s){return Object.prototype.toString.call(s)==="[object Object]"}class Ia extends pt{constructor(n){super(),this.reviver=n}add(n){let r;if(typeof n=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");r=this.decodeString(n);const a=r.type===Le.BINARY_EVENT;a||r.type===Le.BINARY_ACK?(r.type=a?Le.EVENT:Le.ACK,this.reconstructor=new Fb(r),r.attachments===0&&super.emitReserved("decoded",r)):super.emitReserved("decoded",r)}else if(Ma(n)||n.base64)if(this.reconstructor)r=this.reconstructor.takeBinaryData(n),r&&(this.reconstructor=null,super.emitReserved("decoded",r));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+n)}decodeString(n){let r=0;const a={type:Number(n.charAt(0))};if(Le[a.type]===void 0)throw new Error("unknown packet type "+a.type);if(a.type===Le.BINARY_EVENT||a.type===Le.BINARY_ACK){const l=r+1;for(;n.charAt(++r)!=="-"&&r!=n.length;);const p=n.substring(l,r);if(p!=Number(p)||n.charAt(r)!=="-")throw new Error("Illegal attachments");a.attachments=Number(p)}if(n.charAt(r+1)==="/"){const l=r+1;for(;++r&&!(n.charAt(r)===","||r===n.length););a.nsp=n.substring(l,r)}else a.nsp="/";const u=n.charAt(r+1);if(u!==""&&Number(u)==u){const l=r+1;for(;++r;){const p=n.charAt(r);if(p==null||Number(p)!=p){--r;break}if(r===n.length)break}a.id=Number(n.substring(l,r+1))}if(n.charAt(++r)){const l=this.tryParse(n.substr(r));if(Ia.isPayloadValid(a.type,l))a.data=l;else throw new Error("invalid payload")}return a}tryParse(n){try{return JSON.parse(n,this.reviver)}catch{return!1}}static isPayloadValid(n,r){switch(n){case Le.CONNECT:return ku(r);case Le.DISCONNECT:return r===void 0;case Le.CONNECT_ERROR:return typeof r=="string"||ku(r);case Le.EVENT:case Le.BINARY_EVENT:return Array.isArray(r)&&(typeof r[0]=="number"||typeof r[0]=="string"&&Db.indexOf(r[0])===-1);case Le.ACK:case Le.BINARY_ACK:return Array.isArray(r)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Fb{constructor(n){this.packet=n,this.buffers=[],this.reconPack=n}takeBinaryData(n){if(this.buffers.push(n),this.buffers.length===this.reconPack.attachments){const r=Ib(this.reconPack,this.buffers);return this.finishedReconstruction(),r}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Bb=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Ia,Encoder:Ob,get PacketType(){return Le},protocol:Lb},Symbol.toStringTag,{value:"Module"}));function vn(s,n,r){return s.on(n,r),function(){s.off(n,r)}}const Ub=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Jd extends pt{constructor(n,r,a){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=n,this.nsp=r,a&&a.auth&&(this.auth=a.auth),this._opts=Object.assign({},a),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const n=this.io;this.subs=[vn(n,"open",this.onopen.bind(this)),vn(n,"packet",this.onpacket.bind(this)),vn(n,"error",this.onerror.bind(this)),vn(n,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...n){return n.unshift("message"),this.emit.apply(this,n),this}emit(n,...r){var a,u,l;if(Ub.hasOwnProperty(n))throw new Error('"'+n.toString()+'" is a reserved event name');if(r.unshift(n),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(r),this;const p={type:Le.EVENT,data:r};if(p.options={},p.options.compress=this.flags.compress!==!1,typeof r[r.length-1]=="function"){const h=this.ids++,_=r.pop();this._registerAckCallback(h,_),p.id=h}const b=(u=(a=this.io.engine)===null||a===void 0?void 0:a.transport)===null||u===void 0?void 0:u.writable,f=this.connected&&!(!((l=this.io.engine)===null||l===void 0)&&l._hasPingExpired());return this.flags.volatile&&!b||(f?(this.notifyOutgoingListeners(p),this.packet(p)):this.sendBuffer.push(p)),this.flags={},this}_registerAckCallback(n,r){var a;const u=(a=this.flags.timeout)!==null&&a!==void 0?a:this._opts.ackTimeout;if(u===void 0){this.acks[n]=r;return}const l=this.io.setTimeoutFn(()=>{delete this.acks[n];for(let b=0;b<this.sendBuffer.length;b++)this.sendBuffer[b].id===n&&this.sendBuffer.splice(b,1);r.call(this,new Error("operation has timed out"))},u),p=(...b)=>{this.io.clearTimeoutFn(l),r.apply(this,b)};p.withError=!0,this.acks[n]=p}emitWithAck(n,...r){return new Promise((a,u)=>{const l=(p,b)=>p?u(p):a(b);l.withError=!0,r.push(l),this.emit(n,...r)})}_addToQueue(n){let r;typeof n[n.length-1]=="function"&&(r=n.pop());const a={id:this._queueSeq++,tryCount:0,pending:!1,args:n,flags:Object.assign({fromQueue:!0},this.flags)};n.push((u,...l)=>a!==this._queue[0]?void 0:(u!==null?a.tryCount>this._opts.retries&&(this._queue.shift(),r&&r(u)):(this._queue.shift(),r&&r(null,...l)),a.pending=!1,this._drainQueue())),this._queue.push(a),this._drainQueue()}_drainQueue(n=!1){if(!this.connected||this._queue.length===0)return;const r=this._queue[0];r.pending&&!n||(r.pending=!0,r.tryCount++,this.flags=r.flags,this.emit.apply(this,r.args))}packet(n){n.nsp=this.nsp,this.io._packet(n)}onopen(){typeof this.auth=="function"?this.auth(n=>{this._sendConnectPacket(n)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(n){this.packet({type:Le.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},n):n})}onerror(n){this.connected||this.emitReserved("connect_error",n)}onclose(n,r){this.connected=!1,delete this.id,this.emitReserved("disconnect",n,r),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(n=>{if(!this.sendBuffer.some(a=>String(a.id)===n)){const a=this.acks[n];delete this.acks[n],a.withError&&a.call(this,new Error("socket has been disconnected"))}})}onpacket(n){if(n.nsp===this.nsp)switch(n.type){case Le.CONNECT:n.data&&n.data.sid?this.onconnect(n.data.sid,n.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Le.EVENT:case Le.BINARY_EVENT:this.onevent(n);break;case Le.ACK:case Le.BINARY_ACK:this.onack(n);break;case Le.DISCONNECT:this.ondisconnect();break;case Le.CONNECT_ERROR:this.destroy();const a=new Error(n.data.message);a.data=n.data.data,this.emitReserved("connect_error",a);break}}onevent(n){const r=n.data||[];n.id!=null&&r.push(this.ack(n.id)),this.connected?this.emitEvent(r):this.receiveBuffer.push(Object.freeze(r))}emitEvent(n){if(this._anyListeners&&this._anyListeners.length){const r=this._anyListeners.slice();for(const a of r)a.apply(this,n)}super.emit.apply(this,n),this._pid&&n.length&&typeof n[n.length-1]=="string"&&(this._lastOffset=n[n.length-1])}ack(n){const r=this;let a=!1;return function(...u){a||(a=!0,r.packet({type:Le.ACK,id:n,data:u}))}}onack(n){const r=this.acks[n.id];typeof r=="function"&&(delete this.acks[n.id],r.withError&&n.data.unshift(null),r.apply(this,n.data))}onconnect(n,r){this.id=n,this.recovered=r&&this._pid===r,this._pid=r,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(n=>this.emitEvent(n)),this.receiveBuffer=[],this.sendBuffer.forEach(n=>{this.notifyOutgoingListeners(n),this.packet(n)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(n=>n()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Le.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(n){return this.flags.compress=n,this}get volatile(){return this.flags.volatile=!0,this}timeout(n){return this.flags.timeout=n,this}onAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(n),this}prependAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(n),this}offAny(n){if(!this._anyListeners)return this;if(n){const r=this._anyListeners;for(let a=0;a<r.length;a++)if(n===r[a])return r.splice(a,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(n),this}prependAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(n),this}offAnyOutgoing(n){if(!this._anyOutgoingListeners)return this;if(n){const r=this._anyOutgoingListeners;for(let a=0;a<r.length;a++)if(n===r[a])return r.splice(a,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(n){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const r=this._anyOutgoingListeners.slice();for(const a of r)a.apply(this,n.data)}}}function Lr(s){s=s||{},this.ms=s.min||100,this.max=s.max||1e4,this.factor=s.factor||2,this.jitter=s.jitter>0&&s.jitter<=1?s.jitter:0,this.attempts=0}Lr.prototype.duration=function(){var s=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var n=Math.random(),r=Math.floor(n*this.jitter*s);s=(Math.floor(n*10)&1)==0?s-r:s+r}return Math.min(s,this.max)|0};Lr.prototype.reset=function(){this.attempts=0};Lr.prototype.setMin=function(s){this.ms=s};Lr.prototype.setMax=function(s){this.max=s};Lr.prototype.setJitter=function(s){this.jitter=s};class wa extends pt{constructor(n,r){var a;super(),this.nsps={},this.subs=[],n&&typeof n=="object"&&(r=n,n=void 0),r=r||{},r.path=r.path||"/socket.io",this.opts=r,ki(this,r),this.reconnection(r.reconnection!==!1),this.reconnectionAttempts(r.reconnectionAttempts||1/0),this.reconnectionDelay(r.reconnectionDelay||1e3),this.reconnectionDelayMax(r.reconnectionDelayMax||5e3),this.randomizationFactor((a=r.randomizationFactor)!==null&&a!==void 0?a:.5),this.backoff=new Lr({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(r.timeout==null?2e4:r.timeout),this._readyState="closed",this.uri=n;const u=r.parser||Bb;this.encoder=new u.Encoder,this.decoder=new u.Decoder,this._autoConnect=r.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(n){return arguments.length?(this._reconnection=!!n,n||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(n){return n===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=n,this)}reconnectionDelay(n){var r;return n===void 0?this._reconnectionDelay:(this._reconnectionDelay=n,(r=this.backoff)===null||r===void 0||r.setMin(n),this)}randomizationFactor(n){var r;return n===void 0?this._randomizationFactor:(this._randomizationFactor=n,(r=this.backoff)===null||r===void 0||r.setJitter(n),this)}reconnectionDelayMax(n){var r;return n===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=n,(r=this.backoff)===null||r===void 0||r.setMax(n),this)}timeout(n){return arguments.length?(this._timeout=n,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(n){if(~this._readyState.indexOf("open"))return this;this.engine=new kb(this.uri,this.opts);const r=this.engine,a=this;this._readyState="opening",this.skipReconnect=!1;const u=vn(r,"open",function(){a.onopen(),n&&n()}),l=b=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",b),n?n(b):this.maybeReconnectOnOpen()},p=vn(r,"error",l);if(this._timeout!==!1){const b=this._timeout,f=this.setTimeoutFn(()=>{u(),l(new Error("timeout")),r.close()},b);this.opts.autoUnref&&f.unref(),this.subs.push(()=>{this.clearTimeoutFn(f)})}return this.subs.push(u),this.subs.push(p),this}connect(n){return this.open(n)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const n=this.engine;this.subs.push(vn(n,"ping",this.onping.bind(this)),vn(n,"data",this.ondata.bind(this)),vn(n,"error",this.onerror.bind(this)),vn(n,"close",this.onclose.bind(this)),vn(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(n){try{this.decoder.add(n)}catch(r){this.onclose("parse error",r)}}ondecoded(n){Ci(()=>{this.emitReserved("packet",n)},this.setTimeoutFn)}onerror(n){this.emitReserved("error",n)}socket(n,r){let a=this.nsps[n];return a?this._autoConnect&&!a.active&&a.connect():(a=new Jd(this,n,r),this.nsps[n]=a),a}_destroy(n){const r=Object.keys(this.nsps);for(const a of r)if(this.nsps[a].active)return;this._close()}_packet(n){const r=this.encoder.encode(n);for(let a=0;a<r.length;a++)this.engine.write(r[a],n.options)}cleanup(){this.subs.forEach(n=>n()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(n,r){var a;this.cleanup(),(a=this.engine)===null||a===void 0||a.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",n,r),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const n=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const r=this.backoff.duration();this._reconnecting=!0;const a=this.setTimeoutFn(()=>{n.skipReconnect||(this.emitReserved("reconnect_attempt",n.backoff.attempts),!n.skipReconnect&&n.open(u=>{u?(n._reconnecting=!1,n.reconnect(),this.emitReserved("reconnect_error",u)):n.onreconnect()}))},r);this.opts.autoUnref&&a.unref(),this.subs.push(()=>{this.clearTimeoutFn(a)})}}onreconnect(){const n=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",n)}}const rs={};function hi(s,n){typeof s=="object"&&(n=s,s=void 0),n=n||{};const r=Tb(s,n.path||"/socket.io"),a=r.source,u=r.id,l=r.path,p=rs[u]&&l in rs[u].nsps,b=n.forceNew||n["force new connection"]||n.multiplex===!1||p;let f;return b?f=new wa(a,n):(rs[u]||(rs[u]=new wa(a,n)),f=rs[u]),r.query&&!n.query&&(n.query=r.queryKey),f.socket(r.path,n)}Object.assign(hi,{Manager:wa,Socket:Jd,io:hi,connect:hi});function Wb(s,n){return(s[n]|s[n+1]<<8|s[n+2]<<16|s[n+3]<<24)>>>0}const pi={H264:1748121140,H265:1748121141,AV1:6387249},{WritableStream:zb}=globalThis;class Hb{#e;#t;#n=0;#r=7;get byteAligned(){return this.#r===7}get ended(){return this.#n>=this.#e.length}constructor(n){this.#e=n,this.#t=n[0]}f1(){const n=this.#t>>this.#r;return this.#r-=1,this.#r<0&&(this.#n+=1,this.#r=7,this.#t=this.#e[this.#n]),n&1}f(n){let r=0;for(;n>0;n-=1)r<<=1,r|=this.f1();return r}skip(n){if(n<=this.#r+1){this.#n+=1,this.#r=7,this.#t=this.#e[this.#n];return}n-=this.#r+1,this.#n+=1;const r=n/8|0;r>0&&(this.#n+=r,n-=r*8),this.#r=7-n,this.#t=this.#e[this.#n]}readBytes(n){if(!this.byteAligned)throw new Error("Bytes must be byte-aligned");const r=this.#e.subarray(this.#n,this.#n+n);return this.#n+=n,this.#t=this.#e[this.#n],r}getPosition(){return[this.#n,this.#r]}setPosition([n,r]){this.#n=n,this.#r=r,this.#t=this.#e[n]}}const Gb={SequenceHeader:1,TemporalDelimiter:2,FrameHeader:3,TileGroup:4,Metadata:5,Frame:6,RedundantFrameHeader:7,TileList:8,Padding:15},$b={Bt709:1,Unspecified:2,Bt470M:4,Bt470BG:5,Bt601:6,Smpte240:7,GenericFilm:8,Bt2020:9,Xyz:10,Smpte431:11,Smpte432:12,Ebu3213:22},qb={Bt709:1,Unspecified:2,Bt470M:4,Bt470BG:5,Bt601:6,Smpte240:7,Linear:8,Log100:9,Log100Sqrt10:10,Iec61966:11,Bt1361:12,Srgb:13,Bt2020Ten:14,Bt2020Twelve:15,Smpte2084:16,Smpte428:17,Hlg:18},Xb={Identity:0,Bt709:1,Unspecified:2,Fcc:4,Bt470BG:5,Bt601:6,Smpte240:7,YCgCo:8,Bt2020Ncl:9,Bt2020Cl:10,Smpte2085:11,ChromatNcl:12,ChromatCl:13,ICtCp:14};class Rt extends Hb{static ObuType=Gb;static ColorPrimaries=$b;static TransferCharacteristics=qb;static MatrixCoefficients=Xb;#e=0;uvlc(){let n=0;for(;!this.f1();)n+=1;return n>=32?2**32-1:this.f(n)+(1<<n>>>0)-1}leb128(){if(!this.byteAligned)throw new Error("LEB128 must be byte-aligned");let n=0n;this.#e=0;for(let r=0n;r<8n;r+=1n){const a=this.f(8);if(n|=BigInt(a&127)<<7n*r,this.#e+=1,(a&128)==0)break}return n}*annexBBitstream(){for(;!this.ended;){const n=this.leb128();yield*this.temporalUnit(n)}}*temporalUnit(n){for(;n>0;){const r=this.leb128();n-=BigInt(this.#e),yield*this.frameUnit(r),n-=r}}*frameUnit(n){for(;n>0;){const r=this.leb128();n-=BigInt(this.#e);const a=this.openBitstreamUnit(r);a&&(yield a),n-=r}}#t=0;openBitstreamUnit(n){const r=this.obuHeader();let a;if(r.obu_has_size_field)a=this.leb128();else if(n!==void 0)a=n-1n-(r.obu_extension_flag?1n:0n);else throw new Error("obu_has_size_field must be true");const u=this.getPosition();if(r.obu_type!==Rt.ObuType.SequenceHeader&&r.obu_type!==Rt.ObuType.TemporalDelimiter&&this.#t!==0&&r.obu_extension_header){const f=!!(this.#t&1<<r.obu_extension_header.temporal_id),g=!!(this.#t&1<<r.obu_extension_header.spatial_id+8);if(!f||!g){this.skip(Number(a));return}}let l;switch(r.obu_type){case Rt.ObuType.SequenceHeader:l=this.sequenceHeaderObu();break}const p=this.getPosition(),b=(p[0]-u[0])*8+(u[1]-p[1]);return a>0&&this.skip(Number(a)*8-b),{obu_header:r,obu_size:a,sequence_header_obu:l}}obuHeader(){if(!!this.f1())throw new Error("Invalid data");const r=this.f(4),a=!!this.f1(),u=!!this.f1();this.f1();let l;return a&&(l=this.obuExtensionHeader()),{obu_type:r,obu_extension_flag:a,obu_has_size_field:u,obu_extension_header:l}}obuExtensionHeader(){const n=this.f(3),r=this.f(2);return this.skip(3),{temporal_id:n,spatial_id:r}}static SelectScreenContentTools=2;static SelectIntegerMv=2;sequenceHeaderObu(){const n=this.f(3),r=!!this.f1(),a=!!this.f1();let u=!1,l,p=!1,b,f=!1,g=0;const h=[],_=[],y=[],S=[],N=[];let j,R;if(a)h[0]=0,_[0]=this.f(5),y[0]=0,S[0]=!1,N[0]=!1;else{u=!!this.f1(),u&&(l=this.timingInfo(),p=!!this.f1(),p&&(b=this.decoderModelInfo(),j=[])),f=!!this.f1(),f&&(R=[]),g=this.f(5);for(let Te=0;Te<=g;Te+=1)h[Te]=this.f(12),_[Te]=this.f(5),_[Te]>7?y[Te]=this.f1():y[Te]=0,p?(S[Te]=!!this.f1(),S[Te]&&(j[Te]=this.operatingParametersInfo(b))):S[Te]=!1,f&&(N[Te]=!!this.f1(),N[Te]&&(R[Te]=this.f(4)))}const M=this.chooseOperatingPoint();this.#t=h[M];const F=this.f(4),A=this.f(4),G=this.f(F+1),q=this.f(A+1);let X=!1,K,V;a||(X=!!this.f1(),X&&(K=this.f(4),V=this.f(3)));const U=!!this.f1(),I=!!this.f1(),D=!!this.f1();let me=!1,ye=!1,$=!1,J=!1,T=!1,O=!1,re=!1,de=!1,ue=Rt.SelectScreenContentTools,Z=!1,Se=Rt.SelectIntegerMv,je;a||(me=!!this.f1(),ye=!!this.f1(),$=!!this.f1(),J=!!this.f1(),T=!!this.f1(),T&&(O=!!this.f1(),re=!!this.f1()),de=!!this.f1(),de||(ue=this.f1()),ue>0&&(Z=!!this.f1(),Z||(Se=this.f1())),T&&(je=this.f(3)));const Fe=!!this.f1(),Ie=!!this.f1(),at=!!this.f1(),lt=this.colorConfig(n),Ge=!!this.f1();return{seq_profile:n,still_picture:r,reduced_still_picture_header:a,timing_info_present_flag:u,timing_info:l,decoder_model_info_present_flag:p,decoder_model_info:b,initial_display_delay_present_flag:f,initial_display_delay_minus_1:R,operating_points_cnt_minus_1:g,operating_point_idc:h,seq_level_idx:_,seq_tier:y,decoder_model_present_for_this_op:S,operating_parameters_info:j,initial_display_delay_present_for_this_op:N,frame_width_bits_minus_1:F,frame_height_bits_minus_1:A,max_frame_width_minus_1:G,max_frame_height_minus_1:q,frame_id_numbers_present_flag:X,delta_frame_id_length_minus_2:K,additional_frame_id_length_minus_1:V,use_128x128_superblock:U,enable_filter_intra:I,enable_intra_edge_filter:D,enable_interintra_compound:me,enable_masked_compound:ye,enable_warped_motion:$,enable_dual_filter:J,enable_order_hint:T,enable_jnt_comp:O,enable_ref_frame_mvs:re,seq_choose_screen_content_tools:de,seq_force_screen_content_tools:ue,seq_choose_integer_mv:Z,seq_force_integer_mv:Se,order_hint_bits_minus_1:je,enable_superres:Fe,enable_cdef:Ie,enable_restoration:at,color_config:lt,film_grain_params_present:Ge}}searchSequenceHeaderObu(){for(;!this.ended;){const n=this.openBitstreamUnit();if(n&&n.sequence_header_obu)return n.sequence_header_obu}}timingInfo(){const n=this.f(32),r=this.f(32),a=!!this.f1();let u;return a&&(u=this.uvlc()),{num_units_in_display_tick:n,time_scale:r,equal_picture_interval:a,num_ticks_per_picture_minus_1:u}}decoderModelInfo(){const n=this.f(5),r=this.f(32),a=this.f(5),u=this.f(5);return{buffer_delay_length_minus_1:n,num_units_in_decoding_tick:r,buffer_removal_time_length_minus_1:a,frame_presentation_time_length_minus_1:u}}operatingParametersInfo(n){const r=n.buffer_delay_length_minus_1+1,a=this.f(r),u=this.f(r),l=!!this.f1();return{decoder_buffer_delay:a,encoder_buffer_delay:u,low_delay_mode_flag:l}}chooseOperatingPoint(){return 0}colorConfig(n){const r=!!this.f1();let a=!1,u=8;n===2&&r?(a=!!this.f1(),u=a?12:10):n<=2&&(u=r?10:8);let l=!1;n===1&&(l=!!this.f1());const p=!!this.f1();let b=Rt.ColorPrimaries.Unspecified,f=Rt.TransferCharacteristics.Unspecified,g=Rt.MatrixCoefficients.Unspecified;p&&(b=this.f(8),f=this.f(8),g=this.f(8));let h=!1,_,y,S=0,N=!1;if(l)h=!!this.f1(),_=!0,y=!0;else{if(b===Rt.ColorPrimaries.Bt709&&f===Rt.TransferCharacteristics.Srgb&&g===Rt.MatrixCoefficients.Identity)h=!0,_=!1,y=!1;else{switch(h=!!this.f1(),n){case 0:_=!0,y=!0;break;case 1:_=!1,y=!1;break;default:u==12?(_=!!this.f1(),_?y=!!this.f1():y=!1):(_=!0,y=!1);break}_&&y&&(S=this.f(2))}N=!!this.f1()}return{high_bitdepth:r,twelve_bit:a,BitDepth:u,mono_chrome:l,color_description_present_flag:p,color_primaries:b,transfer_characteristics:f,matrix_coefficients:g,color_range:h,subsampling_x:_,subsampling_y:y,chroma_sample_position:S,separate_uv_delta_q:N}}}function*Zd(s){let n=-1,r=0,a=!1;for(let u=0;u<s.length;u+=1){const l=s[u];if(a){if(l>3)throw new Error("Invalid data");a=!1;continue}if(l===0){r+=1;continue}const p=r;if(r=0,n===-1){if(p>=2&&l===1){n=u+1;continue}throw new Error("Invalid data")}if(!(p<2)){if(l===1){yield s.subarray(n,u-p),n=u+1;continue}if(p>2)throw new Error("Invalid data");switch(l){case 2:throw new Error("Invalid data");case 3:a=!0;break}}}if(a)throw new Error("Invalid data");yield s.subarray(n,s.length)}class Ti{#e;#t;#n;#r=0;#i=0;#s=7;#o=0;get byteLength(){return this.#t}get stopBitIndex(){return this.#n}get bytePosition(){return this.#i}get bitPosition(){return this.#s}get ended(){return this.#i>=this.#t&&this.#s<=this.#n}constructor(n){this.#e=n;for(let r=n.length-1;r>=0;r-=1){if(this.#e[r]===0)continue;const a=n[r];for(let u=0;u<8;u+=1)if((a>>u&1)===1){this.#t=r,this.#n=u,this.#l();return}}throw new Error("Stop bit not found")}#l(){if(this.#o=this.#e[this.#i],this.#r===2&&this.#o===3){this.#r=0,this.#i+=1,this.#l();return}this.#o===0?this.#r+=1:this.#r=0}next(){if(this.ended)throw new Error("Bit index out of bounds");const n=this.#o>>this.#s&1;return this.#s-=1,this.#s<0&&(this.#i+=1,this.#s=7,this.#l()),n}read(n){if(n>32)throw new Error("Read length too large");let r=0;for(let a=0;a<n;a+=1)r=r<<1|this.next();return r}#c(){if(this.#i>=this.#t&&this.#s<this.#n)throw new Error("Bit index out of bounds")}skip(n){if(n<=this.#s+1){this.#s-=n,this.#c();return}for(n-=this.#s+1,this.#i+=1,this.#s=7,this.#l(),this.#c();n>=8;n-=8)this.#i+=1,this.#l(),this.#c();this.#s=7-n,this.#c()}decodeExponentialGolombNumber(){let n=0;for(;this.next()===0;)n+=1;return n===0?0:(1<<n|this.read(n))-1}#d(){return{zeroCount:this.#r,bytePosition:this.#i,bitPosition:this.#s,byte:this.#o}}#a(n){this.#r=n.zeroCount,this.#i=n.bytePosition,this.#s=n.bitPosition,this.#o=n.byte}peek(n){const r=this.#d(),a=this.read(n);return this.#a(r),a}readBytes(n){const r=new Uint8Array(n);for(let a=0;a<n;a+=1)r[a]=this.read(8);return r}peekBytes(n){const r=this.#d(),a=this.readBytes(n);return this.#a(r),a}}function Yb(s){const n=new Ti(s);if(n.next()!==0)throw new Error("Invalid data");const r=n.read(2);if(n.read(5)!==7)throw new Error("Invalid data");if(r===0)throw new Error("Invalid data");const u=n.read(8),l=n.peek(8),p=!!n.next(),b=!!n.next(),f=!!n.next(),g=!!n.next(),h=!!n.next(),_=!!n.next();if(n.read(2)!==0)throw new Error("Invalid data");const y=n.read(8),S=n.decodeExponentialGolombNumber();if(u===100||u===110||u===122||u===244||u===44||u===83||u===86||u===118||u===128||u===138||u===139||u===134){const K=n.decodeExponentialGolombNumber();if(K===3&&n.next(),n.decodeExponentialGolombNumber(),n.decodeExponentialGolombNumber(),n.next(),!!n.next())for(let U=0;U<(K!==3?8:12);U+=1)n.next()}n.decodeExponentialGolombNumber();const N=n.decodeExponentialGolombNumber();if(N===0)n.decodeExponentialGolombNumber();else if(N===1){n.next(),n.decodeExponentialGolombNumber(),n.decodeExponentialGolombNumber();const K=n.decodeExponentialGolombNumber();for(let V=0;V<K;V+=1)n.decodeExponentialGolombNumber()}n.decodeExponentialGolombNumber(),n.next();const j=n.decodeExponentialGolombNumber(),R=n.decodeExponentialGolombNumber(),M=n.next();M||n.next(),n.next();const F=!!n.next();let A,G,q,X;return F?(A=n.decodeExponentialGolombNumber(),G=n.decodeExponentialGolombNumber(),q=n.decodeExponentialGolombNumber(),X=n.decodeExponentialGolombNumber()):(A=0,G=0,q=0,X=0),n.next(),{profile_idc:u,constraint_set:l,constraint_set0_flag:p,constraint_set1_flag:b,constraint_set2_flag:f,constraint_set3_flag:g,constraint_set4_flag:h,constraint_set5_flag:_,level_idc:y,seq_parameter_set_id:S,pic_width_in_mbs_minus1:j,pic_height_in_map_units_minus1:R,frame_mbs_only_flag:M,frame_cropping_flag:F,frame_crop_left_offset:A,frame_crop_right_offset:G,frame_crop_top_offset:q,frame_crop_bottom_offset:X}}function Vb(s){let n,r;for(const a of Zd(s))switch(a[0]&31){case 7:if(n=a,r)return{sequenceParameterSet:n,pictureParameterSet:r};break;case 8:if(r=a,n)return{sequenceParameterSet:n,pictureParameterSet:r};break}throw new Error("Invalid data")}function Kb(s){const{sequenceParameterSet:n,pictureParameterSet:r}=Vb(s),{profile_idc:a,constraint_set:u,level_idc:l,pic_width_in_mbs_minus1:p,pic_height_in_map_units_minus1:b,frame_mbs_only_flag:f,frame_crop_left_offset:g,frame_crop_right_offset:h,frame_crop_top_offset:_,frame_crop_bottom_offset:y}=Yb(n),S=(p+1)*16,N=(b+1)*(2-f)*16,j=g*2,R=h*2,M=_*2,F=y*2,A=S-j-R,G=N-M-F;return{pictureParameterSet:r,sequenceParameterSet:n,profileIndex:a,constraintSet:u,levelIndex:l,encodedWidth:S,encodedHeight:N,cropLeft:j,cropRight:R,cropTop:M,cropBottom:F,croppedWidth:A,croppedHeight:G}}function Qb(s){switch(s){case 0:case 3:return 1;case 1:case 2:return 2;default:throw new Error("Invalid chroma_format_idc")}}function Jb(s){switch(s){case 0:case 2:case 3:return 1;case 1:return 2;default:throw new Error("Invalid chroma_format_idc")}}function Zb(s){const n=new Ti(s);if(n.next()!==0)throw new Error("Invalid NALU header");const r=n.read(6),a=n.read(6),u=n.read(3);return{nal_unit_type:r,nuh_layer_id:a,nuh_temporal_id_plus1:u}}function ey(s){const n=new Ti(s),r=n.read(4),a=!!n.next(),u=!!n.next(),l=n.read(6),p=n.read(3),b=!!n.next();n.skip(16);const f=ef(n,!0,p),g=!!n.next(),h=[],_=[],y=[];for(let I=g?0:p;I<=p;I+=1)h[I]=n.decodeExponentialGolombNumber(),_[I]=n.decodeExponentialGolombNumber(),y[I]=n.decodeExponentialGolombNumber();const S=n.read(6),N=n.decodeExponentialGolombNumber(),j=[];for(let I=1;I<=N;I+=1){j[I]=[];for(let D=0;D<=S;D+=1)j[I][D]=!!n.next()}const R=!!n.next();let M,F,A,G,q,X,K,V;if(R){M=n.read(32),F=n.read(32),A=!!n.next(),A&&(G=n.decodeExponentialGolombNumber()),q=n.decodeExponentialGolombNumber(),X=[],K=[!0],V=[];for(let I=0;I<q;I+=1)X[I]=n.decodeExponentialGolombNumber(),I>0&&(K[I]=!!n.next()),V[I]=tf(n,K[I],p)}const U=!!n.next();return{vps_video_parameter_set_id:r,vps_base_layer_internal_flag:a,vps_base_layer_available_flag:u,vps_max_layers_minus1:l,vps_max_sub_layers_minus1:p,vps_temporal_id_nesting_flag:b,profileTierLevel:f,vps_sub_layer_ordering_info_present_flag:g,vps_max_dec_pic_buffering_minus1:h,vps_max_num_reorder_pics:_,vps_max_latency_increase_plus1:y,vps_max_layer_id:S,vps_num_layer_sets_minus1:N,layer_id_included_flag:j,vps_timing_info_present_flag:R,vps_num_units_in_tick:M,vps_time_scale:F,vps_poc_proportional_to_timing_flag:A,vps_num_ticks_poc_diff_one_minus1:G,vps_num_hrd_parameters:q,hrd_layer_set_idx:X,cprms_present_flag:K,hrdParameters:V,vps_extension_flag:U}}function ty(s){const n=new Ti(s),r=n.read(4),a=n.read(3),u=!!n.next(),l=ef(n,!0,a),p=n.decodeExponentialGolombNumber(),b=n.decodeExponentialGolombNumber();let f;b===3&&(f=!!n.next());const g=n.decodeExponentialGolombNumber(),h=n.decodeExponentialGolombNumber(),_=!!n.next();let y,S,N,j;_&&(y=n.decodeExponentialGolombNumber(),S=n.decodeExponentialGolombNumber(),N=n.decodeExponentialGolombNumber(),j=n.decodeExponentialGolombNumber());const R=n.decodeExponentialGolombNumber(),M=n.decodeExponentialGolombNumber(),F=n.decodeExponentialGolombNumber(),A=[],G=[],q=[],X=!!n.next();for(let we=X?0:a;we<=a;we+=1)A[we]=n.decodeExponentialGolombNumber(),G[we]=n.decodeExponentialGolombNumber(),q[we]=n.decodeExponentialGolombNumber();const K=n.decodeExponentialGolombNumber(),V=n.decodeExponentialGolombNumber(),U=n.decodeExponentialGolombNumber(),I=n.decodeExponentialGolombNumber(),D=n.decodeExponentialGolombNumber(),me=n.decodeExponentialGolombNumber(),ye=!!n.next();let $,J;ye&&($=!!n.next(),$&&(J=ny(n)));const T=!!n.next(),O=!!n.next(),re=!!n.next();let de,ue,Z,Se,je;re&&(de=n.read(4),ue=n.read(4),Z=n.read(4),Se=n.read(4),je=!!n.next());const Fe=n.decodeExponentialGolombNumber(),Ie=[];for(let we=0;we<Fe;we+=1)Ie[we]=ry(n,we,Fe,Ie);const at=!!n.next();let lt,Ge,Te;if(at){lt=n.decodeExponentialGolombNumber(),Ge=[],Te=[];for(let we=0;we<lt;we+=1)Ge[we]=n.read(F+4),Te[we]=!!n.next()}const $e=!!n.next(),mt=!!n.next(),tt=!!n.next();let At;tt&&(At=sy(n,a));const Xe=!!n.next();let gt,ne,se,L,ee;if(Xe&&(gt=!!n.next(),ne=!!n.next(),se=!!n.next(),L=!!n.next(),ee=n.read(4)),gt)throw new Error("Not implemented");let le;ne&&(le=oy(n));let ce;if(se&&(ce=ay(n)),L)throw new Error("Not implemented");let Ce;if(ee){Ce=[];let we=0;for(;!n.ended;)Ce[we]=!!n.next(),we+=1}return{sps_video_parameter_set_id:r,sps_max_sub_layers_minus1:a,sps_temporal_id_nesting_flag:u,profileTierLevel:l,sps_seq_parameter_set_id:p,chroma_format_idc:b,separate_colour_plane_flag:f,pic_width_in_luma_samples:g,pic_height_in_luma_samples:h,conformance_window_flag:_,conf_win_left_offset:y,conf_win_right_offset:S,conf_win_top_offset:N,conf_win_bottom_offset:j,bit_depth_luma_minus8:R,bit_depth_chroma_minus8:M,log2_max_pic_order_cnt_lsb_minus4:F,sps_sub_layer_ordering_info_present_flag:X,sps_max_dec_pic_buffering_minus1:A,sps_max_num_reorder_pics:G,sps_max_latency_increase_plus1:q,log2_min_luma_coding_block_size_minus3:K,log2_diff_max_min_luma_coding_block_size:V,log2_min_luma_transform_block_size_minus2:U,log2_diff_max_min_luma_transform_block_size:I,max_transform_hierarchy_depth_inter:D,max_transform_hierarchy_depth_intra:me,scaling_list_enabled_flag:ye,sps_scaling_list_data_present_flag:$,scalingListData:J,amp_enabled_flag:T,sample_adaptive_offset_enabled_flag:O,pcm_enabled_flag:re,pcm_sample_bit_depth_luma_minus1:de,pcm_sample_bit_depth_chroma_minus1:ue,log2_min_pcm_luma_coding_block_size_minus3:Z,log2_diff_max_min_pcm_luma_coding_block_size:Se,pcm_loop_filter_disabled_flag:je,num_short_term_ref_pic_sets:Fe,shortTermRefPicSets:Ie,long_term_ref_pics_present_flag:at,num_long_term_ref_pics_sps:lt,lt_ref_pic_poc_lsb_sps:Ge,used_by_curr_pic_lt_sps_flag:Te,sps_temporal_mvp_enabled_flag:$e,strong_intra_smoothing_enabled_flag:mt,vui_parameters_present_flag:tt,vuiParameters:At,sps_extension_present_flag:Xe,sps_range_extension_flag:gt,sps_multilayer_extension_flag:ne,sps_3d_extension_flag:se,sps_scc_extension_flag:L,sps_extension_4bits:ee,spsMultilayerExtension:le,sps3dExtension:ce,sps_extension_data_flag:Ce}}function Tu(s){const n=s.read(2),r=!!s.next(),a=s.read(5),u=s.peekBytes(4),l=[];for(let X=0;X<32;X+=1)l[X]=!!s.next();const p=s.peekBytes(6),b=!!s.next(),f=!!s.next(),g=!!s.next(),h=!!s.next();let _,y,S,N,j,R,M,F,A,G;a===4||l[4]||a===5||l[5]||a===6||l[6]||a===7||l[7]||a===8||l[8]||a===9||l[9]||a===10||l[10]||a===11||l[11]?(_=!!s.next(),y=!!s.next(),S=!!s.next(),N=!!s.next(),j=!!s.next(),R=!!s.next(),M=!!s.next(),F=!!s.next(),A=!!s.next(),a===5||l[5]||a===9||l[9]||a===10||l[10]||a===11||l[11]?(G=!!s.next(),s.skip(33)):s.skip(34)):a===2||l[2]?(s.skip(7),F=!!s.next(),s.skip(35)):s.skip(43);let q;return a===1||l[1]||a===2||l[2]||a===3||l[3]||a===4||l[4]||a===5||l[5]||a===9||l[9]||a===11||l[11]?q=!!s.next():s.skip(1),{profile_space:n,tier_flag:r,profile_idc:a,profileCompatibilitySet:u,profile_compatibility_flag:l,constraintSet:p,progressive_source_flag:b,interlaced_source_flag:f,non_packed_constraint_flag:g,frame_only_constraint_flag:h,max_12bit_constraint_flag:_,max_10bit_constraint_flag:y,max_8bit_constraint_flag:S,max_422chroma_constraint_flag:N,max_420chroma_constraint_flag:j,max_monochrome_constraint_flag:R,intra_constraint_flag:M,one_picture_only_constraint_flag:F,lower_bit_rate_constraint_flag:A,max_14bit_constraint_flag:G,inbld_flag:q}}function ef(s,n,r){let a;a=Tu(s);const u=s.read(8),l=[],p=[];for(let g=0;g<r;g+=1)l[g]=!!s.next(),p[g]=!!s.next();if(r>0)for(let g=r;g<8;g+=1)s.read(2);const b=[],f=[];for(let g=0;g<r;g+=1)l[g]&&(b[g]=Tu(s)),p[g]&&(f[g]=s.read(8));return{generalProfileTier:a,general_level_idc:u,sub_layer_profile_present_flag:l,sub_layer_level_present_flag:p,subLayerProfileTier:b,sub_layer_level_idc:f}}function ny(s){const n=[];for(let r=0;r<4;r+=1){n[r]=[];for(let a=0;a<6;a+=r===3?3:1)if(!!!s.next())s.decodeExponentialGolombNumber();else{let l=8;const p=Math.min(64,1<<4+(r<<1));r>1&&(l=s.decodeExponentialGolombNumber()+8),n[r][a]=[];for(let b=0;b<p;b+=1){const f=s.decodeExponentialGolombNumber();l=(l+f+256)%256,n[r][a][b]=l}}}return n}function ry(s,n,r,a){let u=!1;n!==0&&(u=!!s.next());let l=0,p=!1,b=0;const f=[],g=[];let h=0,_=0;const y=[],S=[],N=[],j=[];if(u){n===r&&(l=s.decodeExponentialGolombNumber()),p=!!s.next(),b=s.decodeExponentialGolombNumber();const R=n-(l+1),M=a[R],F=M.num_negative_pics+M.num_positive_pics;for(let D=0;D<=F;D+=1)f[D]=!!s.next(),f[D]?g[D]=!0:g[D]=!!s.next();const A=(1-2*Number(p))*(b+1),G=[],q=[],X=[],K=[];let V=0;for(let D=0;D<M.num_negative_pics;D+=1)V-=M.delta_poc_s0_minus1[D]+1,G[D]=V;V=0;for(let D=0;D<M.num_positive_pics;D+=1)V+=M.delta_poc_s1_minus1[D]+1,q[D]=V;let U=0;if(M.num_positive_pics>0)for(let D=M.num_positive_pics-1;D>=0;D-=1)V=q[D]+A,V<0&&g[M.num_negative_pics+D]&&(X[U]=V,S[U]=f[M.num_negative_pics+D],U+=1);A<0&&g[F]&&(X[U]=A,S[U]=f[F],U+=1);for(let D=0;D<M.num_negative_pics;D+=1)V=G[D]+A,V<0&&g[D]&&(X[U]=V,S[U]=f[D],U+=1);h=U;let I=0;for(U=0;U<h;U+=1){const D=X[U];y[U]=-(D-I-1),I=D}if(U=0,M.num_negative_pics>0)for(let D=M.num_negative_pics-1;D>=0;D-=1)V=G[D]+A,V>0&&g[D]&&(K[U]=V,j[U]=f[D],U+=1);A>0&&g[F]&&(K[U]=A,j[U]=f[F],U+=1);for(let D=0;D<M.num_positive_pics;D+=1)V=q[D]+A,V>0&&g[M.num_negative_pics+D]&&(K[U]=V,j[U]=f[M.num_negative_pics+D],U+=1);for(_=U,I=0,U=0;U<_;U+=1){const D=K[U];N[U]=D-I-1,I=D}}else{h=s.decodeExponentialGolombNumber(),_=s.decodeExponentialGolombNumber();for(let R=0;R<h;R+=1)y[R]=s.decodeExponentialGolombNumber(),S[R]=!!s.next();for(let R=0;R<_;R+=1)N[R]=s.decodeExponentialGolombNumber(),j[R]=!!s.next()}return{stRpsIdx:n,num_short_term_ref_pic_sets:r,inter_ref_pic_set_prediction_flag:u,delta_idx_minus1:l,delta_rps_sign:p,abs_delta_rps_minus1:b,used_by_curr_pic_flag:f,use_delta_flag:g,num_negative_pics:h,num_positive_pics:_,delta_poc_s0_minus1:y,used_by_curr_pic_s0_flag:S,delta_poc_s1_minus1:N,used_by_curr_pic_s1_flag:j}}function sy(s,n){const r=!!s.next();let a,u,l;r&&(a=s.read(8),a===255&&(u=s.read(16),l=s.read(16)));const p=!!s.next();let b;p&&(b=!!s.next());const f=!!s.next();let g,h,_,y,S,N;f&&(g=s.read(3),h=!!s.next(),_=!!s.next(),_&&(y=s.read(8),S=s.read(8),N=s.read(8)));const j=!!s.next();let R,M;j&&(R=s.decodeExponentialGolombNumber(),M=s.decodeExponentialGolombNumber());const F=!!s.next(),A=!!s.next(),G=!!s.next(),q=!!s.next();let X,K,V,U;q&&(X=s.decodeExponentialGolombNumber(),K=s.decodeExponentialGolombNumber(),V=s.decodeExponentialGolombNumber(),U=s.decodeExponentialGolombNumber());const I=!!s.next();let D,me,ye,$,J,T;I&&(D=s.read(32),me=s.read(32),ye=!!s.next(),ye&&($=s.decodeExponentialGolombNumber()),J=!!s.next(),J&&(T=tf(s,!0,n)));const O=!!s.next();let re,de,ue,Z,Se,je,Fe,Ie;return O&&(re=!!s.next(),de=!!s.next(),ue=!!s.next(),Z=s.decodeExponentialGolombNumber(),Se=s.decodeExponentialGolombNumber(),je=s.decodeExponentialGolombNumber(),Fe=s.decodeExponentialGolombNumber(),Ie=s.decodeExponentialGolombNumber()),{aspect_ratio_info_present_flag:r,aspect_ratio_idc:a,sar_width:u,sar_height:l,overscan_info_present_flag:p,overscan_appropriate_flag:b,video_signal_type_present_flag:f,video_format:g,video_full_range_flag:h,colour_description_present_flag:_,colour_primaries:y,transfer_characteristics:S,matrix_coeffs:N,chroma_loc_info_present_flag:j,chroma_sample_loc_type_top_field:R,chroma_sample_loc_type_bottom_field:M,neutral_chroma_indication_flag:F,field_seq_flag:A,frame_field_info_present_flag:G,default_display_window_flag:q,def_disp_win_left_offset:X,def_disp_win_right_offset:K,def_disp_win_top_offset:V,def_disp_win_bottom_offset:U,vui_timing_info_present_flag:I,vui_num_units_in_tick:D,vui_time_scale:me,vui_poc_proportional_to_timing_flag:ye,vui_num_ticks_poc_diff_one_minus1:$,vui_hrd_parameters_present_flag:J,vui_hrd_parameters:T,bitstream_restriction_flag:O,tiles_fixed_structure_flag:re,motion_vectors_over_pic_boundaries_flag:de,restricted_ref_pic_lists_flag:ue,min_spatial_segmentation_idc:Z,max_bytes_per_pic_denom:Se,max_bits_per_min_cu_denom:je,log2_max_mv_length_horizontal:Fe,log2_max_mv_length_vertical:Ie}}function tf(s,n,r){let a,u,l,p,b,f,g,h,_,y,S,N,j;n&&(a=!!s.next(),u=!!s.next(),(a||u)&&(l=!!s.next(),l&&(p=s.read(8),b=s.read(5),f=!!s.next(),g=s.read(5)),h=s.read(4),_=s.read(4),l&&(y=s.read(4)),S=s.read(5),N=s.read(5),j=s.read(5)));const R=[],M=[],F=[],A=[],G=[],q=[],X=[];for(let K=0;K<=r;K+=1)R[K]=!!s.next(),R[K]||(M[K]=!!s.next()),M[K]?F[K]=s.decodeExponentialGolombNumber():A[K]=!!s.next(),A[K]||(G[K]=s.decodeExponentialGolombNumber()),a&&(q[K]=Ru(s,K,Au(G[K]))),u&&(X[K]=Ru(s,K,Au(G[K])));return{nal_hrd_parameters_present_flag:a,vcl_hrd_parameters_present_flag:u,sub_pic_hrd_params_present_flag:l,tick_divisor_minus2:p,du_cpb_removal_delay_increment_length_minus1:b,sub_pic_cpb_params_in_pic_timing_sei_flag:f,dpb_output_delay_du_length_minus1:g,bit_rate_scale:h,cpb_size_scale:_,cpb_size_du_scale:y,initial_cpb_removal_delay_length_minus1:S,au_cpb_removal_delay_length_minus1:N,dpb_output_delay_length_minus1:j,fixed_pic_rate_general_flag:R,fixed_pic_rate_within_cvs_flag:M,elemental_duration_in_tc_minus1:F,low_delay_hrd_flag:A,cpb_cnt_minus1:G,nalHrdParameters:q,vclHrdParameters:X}}function Ru(s,n,r){const a=[],u=[],l=[],p=[],b=[];for(let f=0;f<r;f+=1)a[f]=s.decodeExponentialGolombNumber(),u[f]=s.decodeExponentialGolombNumber(),n>0&&(b[f]=!!s.next());return{bit_rate_value_minus1:a,cpb_size_value_minus1:u,cpb_size_du_value_minus1:l,bit_rate_du_value_minus1:p,cbr_flag:b}}function Au(s){return s+1}function iy(s){let n,r,a,u=0;for(const l of Zd(s)){const p=Zb(l),b={...p,data:l,rbsp:l.subarray(2)};switch(p.nal_unit_type){case 32:n=b;break;case 33:r=b;break;case 34:a=b;break;default:continue}if(u+=1,u===3)return{videoParameterSet:n,sequenceParameterSet:r,pictureParameterSet:a}}throw new Error("Invalid data")}function oy(s){return{inter_view_mv_vert_constraint_flag:!!s.next()}}function ay(s){const n=[],r=[];n[0]=!!s.next(),r[0]=!!s.next();const a=s.decodeExponentialGolombNumber(),u=!!s.next(),l=!!s.next(),p=!!s.next(),b=!!s.next();n[1]=!!s.next(),r[1]=!!s.next();const f=!!s.next(),g=s.decodeExponentialGolombNumber(),h=!!s.next(),_=!!s.next(),y=!!s.next(),S=!!s.next(),N=!!s.next();return{iv_di_mc_enabled_flag:n,iv_mv_scal_enabled_flag:r,log2_ivmc_sub_pb_size_minus3:a,iv_res_pred_enabled_flag:u,depth_ref_enabled_flag:l,vsp_mc_enabled_flag:p,dbbp_enabled_flag:b,tex_mc_enabled_flag:f,log2_texmc_sub_pb_size_minus3:g,intra_contour_enabled_flag:h,intra_dc_only_wedge_enabled_flag:_,cqt_cu_part_pred_enabled_flag:y,inter_dc_only_enabled_flag:S,skip_intra_enabled_flag:N}}function ly(s){const{videoParameterSet:n,sequenceParameterSet:r,pictureParameterSet:a}=iy(s),{profileTierLevel:{generalProfileTier:{profile_space:u,tier_flag:l,profile_idc:p,profileCompatibilitySet:b,constraintSet:f},general_level_idc:g}}=ey(n.rbsp),{chroma_format_idc:h,pic_width_in_luma_samples:_,pic_height_in_luma_samples:y,conf_win_left_offset:S=0,conf_win_right_offset:N=0,conf_win_top_offset:j=0,conf_win_bottom_offset:R=0}=ty(r.rbsp),M=Qb(h),F=Jb(h),A=_-M*(S+N),G=y-F*(j+R);return{videoParameterSet:n,sequenceParameterSet:r,pictureParameterSet:a,generalProfileSpace:u,generalProfileIndex:p,generalProfileCompatibilitySet:b,generalTierFlag:l,generalLevelIndex:g,generalConstraintSet:f,encodedWidth:_,encodedHeight:y,cropLeft:S,cropRight:N,cropTop:j,cropBottom:R,croppedWidth:A,croppedHeight:G}}function ju(s){return s.toString(16).toUpperCase()}function Jo(s){return s.toString(16).toUpperCase().padStart(2,"0")}function ss(s){return s.toString(10).padStart(2,"0")}class cy{#e;#t;constructor(n,r){this.#e=n,this.#t=r}#n(n){const a=new Rt(n).searchSequenceHeaderObu();if(!a)return;const{seq_profile:u,seq_level_idx:[l=0],max_frame_width_minus_1:p,max_frame_height_minus_1:b,color_config:{BitDepth:f,mono_chrome:g,subsampling_x:h,subsampling_y:_,chroma_sample_position:y,color_description_present_flag:S}}=a;let N,j,R,M;S?{color_primaries:N,transfer_characteristics:j,matrix_coefficients:R,color_range:M}=a.color_config:(N=Rt.ColorPrimaries.Bt709,j=Rt.TransferCharacteristics.Bt709,R=Rt.MatrixCoefficients.Bt709,M=!1);const F=p+1,A=b+1;this.#t(F,A);const G=["av01",u.toString(16),ss(l)+(a.seq_tier[0]?"H":"M"),ss(f),g?"1":"0",(h?"1":"0")+(_?"1":"0")+y.toString(),ss(N),ss(j),ss(R),M?"1":"0"].join(".");this.#e.configure({codec:G,optimizeForLatency:!0})}decode(n){n.type!=="configuration"&&(this.#n(n.data),this.#e.decode(new EncodedVideoChunk({type:n.keyframe===!1?"delta":"key",timestamp:0,data:n.data})))}}class nf{#e;#t;constructor(n){this.#t=n}decode(n){if(n.type==="configuration"){this.#e=n.data,this.configure(n.data);return}let r;this.#e!==void 0?(r=new Uint8Array(this.#e.length+n.data.length),r.set(this.#e,0),r.set(n.data,this.#e.length),this.#e=void 0):r=n.data,this.#t.decode(new EncodedVideoChunk({type:n.keyframe===!1?"delta":"key",timestamp:0,data:r}))}}class uy extends nf{#e;#t;constructor(n,r){super(n),this.#e=n,this.#t=r}configure(n){const{profileIndex:r,constraintSet:a,levelIndex:u,croppedWidth:l,croppedHeight:p}=Kb(n);this.#t(l,p);const b="avc1."+Jo(r)+Jo(a)+Jo(u);this.#e.configure({codec:b,optimizeForLatency:!0})}}class dy extends nf{#e;#t;constructor(n,r){super(n),this.#e=n,this.#t=r}configure(n){const{generalProfileSpace:r,generalProfileIndex:a,generalProfileCompatibilitySet:u,generalTierFlag:l,generalLevelIndex:p,generalConstraintSet:b,croppedWidth:f,croppedHeight:g}=ly(n);this.#t(f,g);const h=["hev1",["","A","B","C"][r]+a.toString(),ju(Wb(u,0)),(l?"H":"L")+p.toString(),...Array.from(b,ju)].join(".");this.#e.configure({codec:h,codedWidth:f,codedHeight:g,optimizeForLatency:!0})}}class fy{listeners=[];constructor(){this.event=this.event.bind(this)}addEventListener(n){this.listeners.push(n);const r=()=>{const a=this.listeners.indexOf(n);a!==-1&&this.listeners.splice(a,1)};return r.dispose=r,r}event=(n,r,...a)=>{const u={listener:n,thisArg:r,args:a};return this.addEventListener(u)};fire(n){for(const r of this.listeners.slice())r.listener.apply(r.thisArg,[n,...r.args])}dispose(){this.listeners.length=0}}class hy{#e;#t=new ReadableStream({start:n=>{this.#e=n},pull:n=>{n.enqueue(this.#r())}},{highWaterMark:0});#n=this.#t.getReader();#r;#i=0;#s;constructor(n,r){this.#r=n,this.#s=r}async borrow(){return(await this.#n.read()).value}return(n){this.#i<this.#s&&(this.#e.enqueue(n),this.#i+=1)}}class py{#e;#t;constructor(){typeof OffscreenCanvas<"u"?this.#e=new OffscreenCanvas(1,1):(this.#e=document.createElement("canvas"),this.#e.width=1,this.#e.height=1),this.#t=this.#e.getContext("bitmaprenderer",{alpha:!1})}async capture(n){this.#e.width=n.displayWidth,this.#e.height=n.displayHeight;const r=await createImageBitmap(n);return this.#t.transferFromImageBitmap(r),this.#e instanceof OffscreenCanvas?await this.#e.convertToBlob({type:"image/png"}):new Promise((a,u)=>{this.#e.toBlob(l=>{l?a(l):u(new Error("Failed to convert canvas to blob"))},"image/png")})}}const Pu=new hy(()=>new py,4);class Mu{static get isSupported(){return typeof globalThis.VideoDecoder<"u"}static capabilities={h264:{},h265:{},av1:{}};#e;get codec(){return this.#e}#t;#n;get writable(){return this.#n}#r;#i;#s;get renderer(){return this.#s}#o=0;#l=0;get framesRendered(){return this.#l}#c=0;get framesSkipped(){return this.#c}#d=new fy;get sizeChanged(){return this.#d.event}#a;#p=!1;#u;#f;#m=0;constructor({codec:n,renderer:r}){switch(this.#e=n,this.#s=r,this.#a=new VideoDecoder({output:a=>{if(this.#f?.close(),this.#f=a.clone(),this.#p){this.#u&&(this.#u.close(),this.#c+=1),this.#u=a;return}this.#x(a)},error:a=>{this.#g(a)}}),this.#e){case pi.H264:this.#t=new uy(this.#a,this.#h);break;case pi.H265:this.#t=new dy(this.#a,this.#h);break;case pi.AV1:this.#t=new cy(this.#a,this.#h);break;default:throw new Error(`Unsupported codec: ${this.#e}`)}this.#n=new zb({start:a=>{this.#r?a.error(this.#r):this.#i=a},write:a=>{this.#t.decode(a)}}),this.#_()}#g(n){if(this.#i)try{this.#i.error(n)}catch{}else this.#r=n}async#x(n){try{if(this.#p=!0,this.#h(n.displayWidth,n.displayHeight),await this.#s.draw(n),this.#o+=1,n.close(),this.#u){const r=this.#u;this.#u=void 0,await this.#x(r)}this.#p=!1}catch(r){this.#g(r)}}#h=(n,r)=>{this.#s.setSize(n,r),this.#d.fire({width:n,height:r})};#_=()=>{this.#o>0&&(this.#l+=1,this.#c+=this.#o-1,this.#o=0),this.#m=requestAnimationFrame(this.#_)};async snapshot(){const n=this.#f;if(!n)return;const r=await Pu.borrow(),a=await r.capture(n);return Pu.return(r),a}dispose(){cancelAnimationFrame(this.#m),this.#a.state!=="closed"&&this.#a.close(),this.#u?.close(),this.#f?.close()}}var Zo={exports:{}},ea={exports:{}},Iu;function Da(){return Iu||(Iu=1,(function(){function s(n,r){throw new Error("abstract")}s.prototype.drawFrame=function(n){throw new Error("abstract")},s.prototype.clear=function(){throw new Error("abstract")},ea.exports=s})()),ea.exports}var ta={exports:{}},na={exports:{}},ra={exports:{}},Du;function my(){return Du||(Du=1,(function(){function s(n){for(var r=0,a=n>>1;a!=0;)a=a>>1,r++;if(n!==1<<r)throw"chroma plane dimensions must be power of 2 ratio to luma plane dimensions; got "+n;return r}ra.exports=s})()),ra.exports}var Lu;function gy(){return Lu||(Lu=1,(function(){var s=my();function n(r,a){var u=r.format.width|0,l=r.format.height|0,p=s(r.format.width/r.format.chromaWidth)|0,b=s(r.format.height/r.format.chromaHeight)|0,f=r.y.bytes,g=r.u.bytes,h=r.v.bytes,_=r.y.stride|0,y=r.u.stride|0,S=r.v.stride|0,N=u<<2,j=0,R=0,M=0,F=0,A=0,G=0,q=0,X=0,K=0,V=0,U=0,I=0,D=0,me=0,ye=0,$=0,J=0,T=0;if(p==1&&b==1)for(q=0,X=N,T=0,$=0;$<l;$+=2){for(R=$*_|0,M=R+_|0,F=T*y|0,A=T*S|0,ye=0;ye<u;ye+=2)K=g[F++]|0,V=h[A++]|0,I=(409*V|0)-57088|0,D=(100*K|0)+(208*V|0)-34816|0,me=(516*K|0)-70912|0,U=298*f[R++]|0,a[q]=U+I>>8,a[q+1]=U-D>>8,a[q+2]=U+me>>8,q+=4,U=298*f[R++]|0,a[q]=U+I>>8,a[q+1]=U-D>>8,a[q+2]=U+me>>8,q+=4,U=298*f[M++]|0,a[X]=U+I>>8,a[X+1]=U-D>>8,a[X+2]=U+me>>8,X+=4,U=298*f[M++]|0,a[X]=U+I>>8,a[X+1]=U-D>>8,a[X+2]=U+me>>8,X+=4;q+=N,X+=N,T++}else for(G=0,$=0;$<l;$++)for(J=0,T=$>>b,j=$*_|0,F=T*y|0,A=T*S|0,ye=0;ye<u;ye++)J=ye>>p,K=g[F+J]|0,V=h[A+J]|0,I=(409*V|0)-57088|0,D=(100*K|0)+(208*V|0)-34816|0,me=(516*K|0)-70912|0,U=298*f[j++]|0,a[G]=U+I>>8,a[G+1]=U-D>>8,a[G+2]=U+me>>8,G+=4}na.exports={convertYCbCr:n}})()),na.exports}var Ou;function xy(){return Ou||(Ou=1,(function(){var s=Da(),n=gy();function r(a){var u=this,l=a.getContext("2d"),p=null,b=null,f=null;function g(_,y){p=l.createImageData(_,y);for(var S=p.data,N=_*y*4,j=0;j<N;j+=4)S[j+3]=255}function h(_,y){b=document.createElement("canvas"),b.width=_,b.height=y,f=b.getContext("2d")}return u.drawFrame=function(y){var S=y.format;(a.width!==S.displayWidth||a.height!==S.displayHeight)&&(a.width=S.displayWidth,a.height=S.displayHeight),(p===null||p.width!=S.width||p.height!=S.height)&&g(S.width,S.height),n.convertYCbCr(y,p.data);var N=S.cropWidth!=S.displayWidth||S.cropHeight!=S.displayHeight,j;N?(b||h(S.cropWidth,S.cropHeight),j=f):j=l,j.putImageData(p,-S.cropLeft,-S.cropTop,S.cropLeft,S.cropTop,S.cropWidth,S.cropHeight),N&&l.drawImage(b,0,0,S.displayWidth,S.displayHeight)},u.clear=function(){l.clearRect(0,0,a.width,a.height)},u}r.prototype=Object.create(s.prototype),ta.exports=r})()),ta.exports}var sa={exports:{}},ia,Fu;function _y(){return Fu||(Fu=1,ia={vertex:`precision mediump float;
34
-
35
- attribute vec2 aPosition;
36
- attribute vec2 aLumaPosition;
37
- attribute vec2 aChromaPosition;
38
- varying vec2 vLumaPosition;
39
- varying vec2 vChromaPosition;
40
- void main() {
41
- gl_Position = vec4(aPosition, 0, 1);
42
- vLumaPosition = aLumaPosition;
43
- vChromaPosition = aChromaPosition;
44
- }
45
- `,fragment:`// inspired by https://github.com/mbebenita/Broadway/blob/master/Player/canvas.js
46
-
47
- precision mediump float;
48
-
49
- uniform sampler2D uTextureY;
50
- uniform sampler2D uTextureCb;
51
- uniform sampler2D uTextureCr;
52
- varying vec2 vLumaPosition;
53
- varying vec2 vChromaPosition;
54
- void main() {
55
- // Y, Cb, and Cr planes are uploaded as ALPHA textures.
56
- float fY = texture2D(uTextureY, vLumaPosition).w;
57
- float fCb = texture2D(uTextureCb, vChromaPosition).w;
58
- float fCr = texture2D(uTextureCr, vChromaPosition).w;
59
-
60
- // Premultipy the Y...
61
- float fYmul = fY * 1.1643828125;
62
-
63
- // And convert that to RGB!
64
- gl_FragColor = vec4(
65
- fYmul + 1.59602734375 * fCr - 0.87078515625,
66
- fYmul - 0.39176171875 * fCb - 0.81296875 * fCr + 0.52959375,
67
- fYmul + 2.017234375 * fCb - 1.081390625,
68
- 1
69
- );
70
- }
71
- `,vertexStripe:`precision mediump float;
72
-
73
- attribute vec2 aPosition;
74
- attribute vec2 aTexturePosition;
75
- varying vec2 vTexturePosition;
76
-
77
- void main() {
78
- gl_Position = vec4(aPosition, 0, 1);
79
- vTexturePosition = aTexturePosition;
80
- }
81
- `,fragmentStripe:`// extra 'stripe' texture fiddling to work around IE 11's poor performance on gl.LUMINANCE and gl.ALPHA textures
82
-
83
- precision mediump float;
84
-
85
- uniform sampler2D uStripe;
86
- uniform sampler2D uTexture;
87
- varying vec2 vTexturePosition;
88
- void main() {
89
- // Y, Cb, and Cr planes are mapped into a pseudo-RGBA texture
90
- // so we can upload them without expanding the bytes on IE 11
91
- // which doesn't allow LUMINANCE or ALPHA textures
92
- // The stripe textures mark which channel to keep for each pixel.
93
- // Each texture extraction will contain the relevant value in one
94
- // channel only.
95
-
96
- float fLuminance = dot(
97
- texture2D(uStripe, vTexturePosition),
98
- texture2D(uTexture, vTexturePosition)
99
- );
100
-
101
- gl_FragColor = vec4(0, 0, 0, fLuminance);
102
- }
103
- `}),ia}var Bu;function vy(){return Bu||(Bu=1,(function(){var s=Da(),n=_y();function r(a){var u=this,l=r.contextForCanvas(a);if(l===null)throw new Error("WebGL unavailable");function p($,J){var T=l.createShader($);if(l.shaderSource(T,J),l.compileShader(T),!l.getShaderParameter(T,l.COMPILE_STATUS)){var O=l.getShaderInfoLog(T);throw l.deleteShader(T),new Error("GL shader compilation for "+$+" failed: "+O)}return T}var b,f,g=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),h={},_={},y={},S,N,j,R,M,F,A,G,q,X;function K($,J){return(!h[$]||J)&&(h[$]=l.createTexture()),h[$]}function V($,J,T,O,re){var de=!h[$]||J,ue=K($,J);if(l.activeTexture(l.TEXTURE0),r.stripe){var Z=!h[$+"_temp"]||J,Se=K($+"_temp",J);l.bindTexture(l.TEXTURE_2D,Se),Z?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,T/4,O,0,l.RGBA,l.UNSIGNED_BYTE,re)):l.texSubImage2D(l.TEXTURE_2D,0,0,0,T/4,O,l.RGBA,l.UNSIGNED_BYTE,re);var je=h[$+"_stripe"],Fe=!je||J;Fe&&(je=K($+"_stripe",J)),l.bindTexture(l.TEXTURE_2D,je),Fe&&(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,T,1,0,l.RGBA,l.UNSIGNED_BYTE,D(T)))}else l.bindTexture(l.TEXTURE_2D,ue),de?(l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR),l.texImage2D(l.TEXTURE_2D,0,l.ALPHA,T,O,0,l.ALPHA,l.UNSIGNED_BYTE,re)):l.texSubImage2D(l.TEXTURE_2D,0,0,0,T,O,l.ALPHA,l.UNSIGNED_BYTE,re)}function U($,J,T,O){var re=h[$];l.useProgram(f);var de=_[$];(!de||J)&&(l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,re),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,T,O,0,l.RGBA,l.UNSIGNED_BYTE,null),de=_[$]=l.createFramebuffer()),l.bindFramebuffer(l.FRAMEBUFFER,de),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,re,0);var ue=h[$+"_temp"];l.activeTexture(l.TEXTURE1),l.bindTexture(l.TEXTURE_2D,ue),l.uniform1i(F,1);var Z=h[$+"_stripe"];l.activeTexture(l.TEXTURE2),l.bindTexture(l.TEXTURE_2D,Z),l.uniform1i(M,2),l.bindBuffer(l.ARRAY_BUFFER,S),l.enableVertexAttribArray(N),l.vertexAttribPointer(N,2,l.FLOAT,!1,0,0),l.bindBuffer(l.ARRAY_BUFFER,j),l.enableVertexAttribArray(R),l.vertexAttribPointer(R,2,l.FLOAT,!1,0,0),l.viewport(0,0,T,O),l.drawArrays(l.TRIANGLES,0,g.length/2),l.bindFramebuffer(l.FRAMEBUFFER,null)}function I($,J,T){l.activeTexture(J),l.bindTexture(l.TEXTURE_2D,h[$]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR),l.uniform1i(l.getUniformLocation(b,$),T)}function D($){if(y[$])return y[$];for(var J=$,T=new Uint32Array(J),O=0;O<J;O+=4)T[O]=255,T[O+1]=65280,T[O+2]=16711680,T[O+3]=4278190080;return y[$]=new Uint8Array(T.buffer)}function me($,J){var T=p(l.VERTEX_SHADER,$),O=p(l.FRAGMENT_SHADER,J),re=l.createProgram();if(l.attachShader(re,T),l.attachShader(re,O),l.linkProgram(re),!l.getProgramParameter(re,l.LINK_STATUS)){var de=l.getProgramInfoLog(re);throw l.deleteProgram(re),new Error("GL program linking failed: "+de)}return re}function ye(){if(r.stripe){f=me(n.vertexStripe,n.fragmentStripe),l.getAttribLocation(f,"aPosition"),j=l.createBuffer();var $=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]);l.bindBuffer(l.ARRAY_BUFFER,j),l.bufferData(l.ARRAY_BUFFER,$,l.STATIC_DRAW),R=l.getAttribLocation(f,"aTexturePosition"),M=l.getUniformLocation(f,"uStripe"),F=l.getUniformLocation(f,"uTexture")}b=me(n.vertex,n.fragment),S=l.createBuffer(),l.bindBuffer(l.ARRAY_BUFFER,S),l.bufferData(l.ARRAY_BUFFER,g,l.STATIC_DRAW),N=l.getAttribLocation(b,"aPosition"),A=l.createBuffer(),G=l.getAttribLocation(b,"aLumaPosition"),q=l.createBuffer(),X=l.getAttribLocation(b,"aChromaPosition")}return u.drawFrame=function($){var J=$.format,T=!b||a.width!==J.displayWidth||a.height!==J.displayHeight;if(T&&(a.width=J.displayWidth,a.height=J.displayHeight,u.clear()),b||ye(),T){var O=function(re,de,ue){var Z=J.cropLeft/ue,Se=(J.cropLeft+J.cropWidth)/ue,je=(J.cropTop+J.cropHeight)/J.height,Fe=J.cropTop/J.height,Ie=new Float32Array([Z,je,Se,je,Z,Fe,Z,Fe,Se,je,Se,Fe]);l.bindBuffer(l.ARRAY_BUFFER,re),l.bufferData(l.ARRAY_BUFFER,Ie,l.STATIC_DRAW)};O(A,G,$.y.stride),O(q,X,$.u.stride*J.width/J.chromaWidth)}V("uTextureY",T,$.y.stride,J.height,$.y.bytes),V("uTextureCb",T,$.u.stride,J.chromaHeight,$.u.bytes),V("uTextureCr",T,$.v.stride,J.chromaHeight,$.v.bytes),r.stripe&&(U("uTextureY",T,$.y.stride,J.height),U("uTextureCb",T,$.u.stride,J.chromaHeight),U("uTextureCr",T,$.v.stride,J.chromaHeight)),l.useProgram(b),l.viewport(0,0,a.width,a.height),I("uTextureY",l.TEXTURE0,0),I("uTextureCb",l.TEXTURE1,1),I("uTextureCr",l.TEXTURE2,2),l.bindBuffer(l.ARRAY_BUFFER,S),l.enableVertexAttribArray(N),l.vertexAttribPointer(N,2,l.FLOAT,!1,0,0),l.bindBuffer(l.ARRAY_BUFFER,A),l.enableVertexAttribArray(G),l.vertexAttribPointer(G,2,l.FLOAT,!1,0,0),l.bindBuffer(l.ARRAY_BUFFER,q),l.enableVertexAttribArray(X),l.vertexAttribPointer(X,2,l.FLOAT,!1,0,0),l.drawArrays(l.TRIANGLES,0,g.length/2)},u.clear=function(){l.viewport(0,0,a.width,a.height),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT)},u.clear(),u}r.stripe=!1,r.contextForCanvas=function(a){var u={preferLowPowerToHighPerformance:!0,powerPreference:"low-power",failIfMajorPerformanceCaveat:!0,preserveDrawingBuffer:!0};return a.getContext("webgl",u)||a.getContext("experimental-webgl",u)},r.isAvailable=function(){var a=document.createElement("canvas"),u;a.width=1,a.height=1;try{u=r.contextForCanvas(a)}catch{return!1}if(u){var l=u.TEXTURE0,p=4,b=4,f=u.createTexture(),g=new Uint8Array(p*b),h=r.stripe?p/4:p,_=r.stripe?u.RGBA:u.ALPHA,y=r.stripe?u.NEAREST:u.LINEAR;u.activeTexture(l),u.bindTexture(u.TEXTURE_2D,f),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,y),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,y),u.texImage2D(u.TEXTURE_2D,0,_,h,b,0,_,u.UNSIGNED_BYTE,g);var S=u.getError();return!S}else return!1},r.prototype=Object.create(s.prototype),sa.exports=r})()),sa.exports}var Uu;function by(){return Uu||(Uu=1,(function(){var s=Da(),n=xy(),r=vy(),a={FrameSink:s,SoftwareFrameSink:n,WebGLFrameSink:r,attach:function(u,l){l=l||{};var p="webGL"in l?l.webGL:r.isAvailable();return p?new r(u,l):new n(u,l)}};Zo.exports=a})()),Zo.exports}by();function rf(){if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("no canvas input found nor any canvas can be created")}class sf{#e;get canvas(){return this.#e}constructor(n){n?this.#e=n:this.#e=rf()}setSize(n,r){(this.#e.width!==n||this.#e.height!==r)&&(this.#e.width=n,this.#e.height=r)}}class yy extends sf{#e;constructor(n){super(n),this.#e=this.canvas.getContext("bitmaprenderer",{alpha:!1})}async draw(n){const r=await createImageBitmap(n);this.#e.transferFromImageBitmap(r)}}const wy=Promise.resolve();function Wu(s,n){const r={powerPreference:"low-power",alpha:!1,failIfMajorPerformanceCaveat:!0,preserveDrawingBuffer:!!n};return s.getContext("webgl2",r)||s.getContext("webgl",r)}class ps extends sf{static vertexShaderSource=`
104
- attribute vec2 xy;
105
-
106
- varying highp vec2 uv;
107
-
108
- void main(void) {
109
- gl_Position = vec4(xy, 0.0, 1.0);
110
- // Map vertex coordinates (-1 to +1) to UV coordinates (0 to 1).
111
- // UV coordinates are Y-flipped relative to vertex coordinates.
112
- uv = vec2((1.0 + xy.x) / 2.0, (1.0 - xy.y) / 2.0);
113
- }
114
- `;static fragmentShaderSource=`
115
- varying highp vec2 uv;
116
-
117
- uniform sampler2D texture;
118
-
119
- void main(void) {
120
- gl_FragColor = texture2D(texture, uv);
121
- }
122
- `;static get isSupported(){const n=rf();return!!Wu(n)}#e;constructor(n,r){super(n);const a=Wu(this.canvas,r);if(!a)throw new Error("WebGL not supported");this.#e=a;const u=a.createShader(a.VERTEX_SHADER);if(a.shaderSource(u,ps.vertexShaderSource),a.compileShader(u),!a.getShaderParameter(u,a.COMPILE_STATUS))throw new Error(a.getShaderInfoLog(u));const l=a.createShader(a.FRAGMENT_SHADER);if(a.shaderSource(l,ps.fragmentShaderSource),a.compileShader(l),!a.getShaderParameter(l,a.COMPILE_STATUS))throw new Error(a.getShaderInfoLog(l));const p=a.createProgram();if(a.attachShader(p,u),a.attachShader(p,l),a.linkProgram(p),!a.getProgramParameter(p,a.LINK_STATUS))throw new Error(a.getProgramInfoLog(p));a.useProgram(p);const b=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,b),a.bufferData(a.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),a.STATIC_DRAW);const f=a.getAttribLocation(p,"xy");a.vertexAttribPointer(f,2,a.FLOAT,!1,0,0),a.enableVertexAttribArray(f);const g=a.createTexture();a.bindTexture(a.TEXTURE_2D,g),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE)}draw(n){const r=this.#e;return r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,n),r.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight),r.drawArrays(r.TRIANGLE_FAN,0,4),wy}}const zu=50,Ey=300;function of({deviceId:s,className:n,onFallback:r,fallbackTimeout:a=5e3,enableControl:u=!1,onTapSuccess:l,onTapError:p,onSwipeSuccess:b,onSwipeError:f,onStreamReady:g}){const h=v.useRef(null),_=v.useRef(null),y=v.useRef(null),S=v.useRef(null),N=v.useRef(null),j=v.useRef(null),R=v.useRef(null),M=v.useRef(!1),F=v.useRef(!1),A=v.useRef(r),G=v.useRef(a),q=v.useRef(g),[X,K]=v.useState("connecting"),[V,U]=v.useState(null),[I,D]=v.useState(null),[me,ye]=v.useState(null),$=v.useRef(!1),J=v.useRef(null),T=v.useRef(!1),O=v.useRef(0),re=v.useRef(null),de=v.useRef(null),ue=v.useRef(null),Z=v.useRef(null);v.useEffect(()=>{A.current=r,G.current=a,q.current=g},[r,a,g]),v.useEffect(()=>{(async()=>{try{const se=await Na(s);se.success&&ye({width:se.width,height:se.height})}catch(se){console.error("[ScrcpyPlayer] Failed to fetch device resolution:",se)}})()},[s]);const Se=v.useCallback(()=>{const ne=S.current,se=y.current;if(!ne||!se||!I)return;const L=se.clientWidth,ee=se.clientHeight,{width:le,height:ce}=I,Ce=le/ce;let we=L,xt=L/Ce;xt>ee&&(xt=ee,we=ee*Ce),ne.width=le,ne.height=ce,ne.style.width=`${we}px`,ne.style.height=`${xt}px`},[I]);v.useEffect(()=>{const ne=()=>Se();return window.addEventListener("resize",ne),()=>window.removeEventListener("resize",ne)},[Se]),v.useEffect(()=>{Se()},[I,Se]);const je=v.useCallback(async()=>{if(ps.isSupported){const se=new ps;return{renderer:se,element:se.canvas}}const ne=new yy;return{renderer:ne,element:ne.canvas}},[]),Fe=v.useCallback(async ne=>{if(!Mu.isSupported)throw new Error("Current browser does not support WebCodecs API. Please use the latest Chrome/Edge.");const{renderer:se,element:L}=await je();return S.current=L,y.current&&!L.parentElement&&y.current.appendChild(L),new Mu({codec:ne,renderer:se})},[je]),Ie=v.useCallback(()=>{M.current||(M.current=!0,N.current&&(clearTimeout(N.current),N.current=null))},[]),at=v.useCallback(ne=>{let se=!1,L=[];const ee=new TransformStream({transform(ce,Ce){if(ce.type==="configuration"){Ce.enqueue(ce),se=!0,L.length>0&&(L.forEach(we=>Ce.enqueue(we)),L=[]);return}if(ce.type==="data"&&!se){L.push(ce);return}Ce.enqueue(ce)}});return new ReadableStream({start(ce){let Ce=!1;const we=ie=>{if(!Ce)try{Ie();const ge={...ie,data:ie.data instanceof Uint8Array?ie.data:new Uint8Array(ie.data)};ce.enqueue(ge)}catch(ge){console.error("[ScrcpyPlayer] Video enqueue error:",ge),Ce=!0,Q()}},xt=ie=>{Ce||(ce.error(new Error(ie?.message||"Socket error")),Ce=!0,Q())},bt=()=>{Ce||(ce.close(),Ce=!0,Q())},Q=()=>{h.current?.off("video-data",we),h.current?.off("error",xt),h.current?.off("disconnect",bt)};return h.current?.on("video-data",we),h.current?.on("error",xt),h.current?.on("disconnect",bt),()=>{Ce=!0,Q()}}}).pipeThrough(ee)},[Ie]),lt=v.useCallback((ne=!1)=>{if(ne&&(F.current=!0),_.current){try{_.current.dispose()}catch(se){console.error("[ScrcpyPlayer] Failed to dispose decoder:",se)}_.current=null}S.current=null,h.current&&(h.current.disconnect(),h.current=null),q.current?.(null),j.current&&(clearTimeout(j.current),j.current=null),N.current&&(clearTimeout(N.current),N.current=null),K("disconnected"),D(null),U(null)},[]),Ge=v.useCallback(()=>{lt(!0),M.current=!1,K("connecting"),U(null);const ne=hi({path:"/socket.io",transports:["websocket"],timeout:1e4});h.current=ne,ne.on("connect",()=>{ne.emit("connect-device",{device_id:s,maxSize:1280,bitRate:4e6}),N.current=setTimeout(()=>{M.current||(K("error"),U("Video stream timeout"),F.current=!0,ne.close(),A.current?.())},G.current)}),ne.on("video-metadata",async se=>{try{_.current&&(_.current.dispose(),_.current=null);const L=se?.codec?se.codec:pi.H264;_.current=await Fe(L),_.current.sizeChanged(({width:le,height:ce})=>{D({width:le,height:ce})}),at(se).pipeTo(_.current.writable).catch(le=>{console.error("[ScrcpyPlayer] Video stream error:",le)}),K("connected"),q.current?.({close:()=>ne.close()})}catch(L){console.error("[ScrcpyPlayer] Decoder initialization failed:",L),K("error"),U("Decoder initialization failed"),F.current=!0,ne.close(),A.current?.()}}),ne.on("error",se=>{console.error("[ScrcpyPlayer] Socket error:",se),K("error"),U(se?.message||"Socket error")}),ne.on("disconnect",()=>{if(F.current){F.current=!1;return}K("disconnected"),q.current?.(null),j.current||(j.current=setTimeout(()=>{j.current=null,R.current?.()},3e3))})},[s,lt,Fe,at]);v.useEffect(()=>{R.current=Ge},[Ge]),v.useEffect(()=>(queueMicrotask(()=>{Ge()}),()=>{de.current&&(clearTimeout(de.current),de.current=null),ue.current&&(clearTimeout(ue.current),ue.current=null),lt(!0)}),[Ge,lt]);const Te=()=>{if(I)return{width:I.width,height:I.height};const ne=S.current;return ne?{width:ne.width,height:ne.height}:null},$e=(ne,se)=>{const L=S.current,ee=Te();if(!L||!ee)return null;const le=L.getBoundingClientRect();if(ne<le.left||ne>le.right||se<le.top||se>le.bottom)return null;const ce=ne-le.left,Ce=se-le.top,we=Math.round(ce/le.width*ee.width),xt=Math.round(Ce/le.height*ee.height),bt=me?me.width/ee.width:1,Q=me?me.height/ee.height:1;return{x:Math.round(we*bt),y:Math.round(xt*Q)}},mt=async ne=>{if(!u||X!=="connected")return;const se=$e(ne.clientX,ne.clientY);if(se){$.current=!0,T.current=!1,J.current={x:ne.clientX,y:ne.clientY};try{await K_(se.x,se.y,s)}catch(L){console.error("[ScrcpyPlayer] Touch down failed:",L)}}},tt=ne=>{if(!$.current||X!=="connected")return;const se=Date.now(),L=$e(ne.clientX,ne.clientY);if(L){if(J.current){const ee=ne.clientX-J.current.x,le=ne.clientY-J.current.y;Math.hypot(ee,le)>4&&(T.current=!0)}if(re.current=L,se-O.current<zu){de.current||(de.current=setTimeout(()=>{de.current=null,re.current&&(hu(re.current.x,re.current.y,s).catch(ee=>{console.error("[ScrcpyPlayer] Touch move failed:",ee)}),re.current=null,O.current=Date.now())},zu));return}O.current=se,hu(L.x,L.y,s).catch(ee=>{console.error("[ScrcpyPlayer] Touch move failed:",ee)})}},At=async ne=>{if(!$.current||X!=="connected")return;const se=$e(ne.clientX,ne.clientY);if($.current=!1,J.current=null,!!se)try{await fu(se.x,se.y,s),T.current?b?.():l?.()}catch(L){const ee=String(L);T.current?f?.(ee):p?.(ee)}},Xe=async ne=>{if(!$.current||X!=="connected")return;const se=$e(ne.clientX,ne.clientY);if($.current=!1,J.current=null,!!se)try{await fu(se.x,se.y,s)}catch(L){console.error("[ScrcpyPlayer] Touch cancel failed:",L)}},gt=ne=>{if(!u||X!=="connected")return;ne.preventDefault();const se=ne.deltaY;Z.current||(Z.current={deltaY:0}),Z.current.deltaY+=se,ue.current&&clearTimeout(ue.current),ue.current=setTimeout(async()=>{const L=Z.current;if(Z.current=null,!L)return;const ee=S.current,le=Te();if(!ee||!le)return;const ce=ee.getBoundingClientRect(),Ce=ce.left+ce.width/2,we=ce.top+ce.height/2,xt=$e(Ce,we);if(!xt)return;const bt=Math.max(Math.min(L.deltaY,600),-600),Q=we+bt,ie=$e(Ce,Q);if(ie)try{const ge=await V_(xt.x,xt.y,ie.x,ie.y,300,s);ge.success?b?.():f?.(ge.error||"Scroll failed")}catch(ge){f?.(String(ge))}},Ey)};return o.jsx("div",{className:`relative w-full h-full flex items-center justify-center ${n||""}`,children:o.jsx("div",{ref:y,className:"relative w-full h-full flex items-center justify-center bg-slate-50 dark:bg-slate-900",onMouseDown:mt,onMouseMove:tt,onMouseUp:At,onMouseLeave:Xe,onWheel:gt,children:X!=="connected"&&o.jsxs("div",{className:"absolute inset-0 flex items-center justify-center text-slate-400",children:[X==="connecting"&&"Connecting...",X==="error"&&(V||"Connection error"),X==="disconnected"&&"Disconnected"]})})})}const af=v.forwardRef(({className:s,value:n=0,max:r=100,...a},u)=>{const l=Math.min(Math.max(n/r*100,0),100);return o.jsx("div",{ref:u,role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":r,className:nr("relative h-2 w-full overflow-hidden rounded-full bg-slate-200 dark:bg-slate-800",s),...a,children:o.jsx("div",{className:"h-full bg-primary transition-all duration-300 ease-in-out",style:{width:`${l}%`}})})});af.displayName="Progress";function Sy({state:s,isStreaming:n,className:r="",decisionModelName:a="Decision Model",visionModelName:u="Vision Model"}){const[l,p]=We.useState("decision"),b=g=>{p(h=>h===g?null:g)},f=s.totalSteps>0?Math.round(s.currentStep/s.totalSteps*100):0;return o.jsxs("div",{className:`space-y-3 ${r}`,children:[n&&o.jsxs("div",{className:"space-y-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-500 dark:text-slate-400",children:[o.jsxs("span",{children:["Step ",s.currentStep," / ",s.totalSteps||"?"]}),o.jsxs("span",{children:[f,"%"]})]}),o.jsx(af,{value:f,className:"h-1.5"})]}),s.taskPlan.length>0&&o.jsxs(er,{className:"p-3 bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-800",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx(cd,{className:"w-4 h-4 text-blue-500"}),o.jsx("span",{className:"text-xs font-medium text-slate-700 dark:text-slate-300",children:"Task Plan"})]}),o.jsx("ul",{className:"space-y-1",children:s.taskPlan.map((g,h)=>o.jsxs("li",{className:`text-xs flex items-start gap-2 ${h<s.currentStep?"text-green-600 dark:text-green-400":h===s.currentStep?"text-blue-600 dark:text-blue-400 font-medium":"text-slate-500 dark:text-slate-400"}`,children:[o.jsx("span",{className:"flex-shrink-0 w-4 h-4 rounded-full border flex items-center justify-center text-[10px]",children:h<s.currentStep?o.jsx(Hn,{className:"w-3 h-3"}):h+1}),o.jsx("span",{className:"line-clamp-1",children:g})]},h))})]}),o.jsxs(er,{className:`overflow-hidden transition-all duration-200 ${s.decisionActive?"border-purple-300 dark:border-purple-700 shadow-sm shadow-purple-100 dark:shadow-purple-900/20":"border-slate-200 dark:border-slate-800"}`,children:[o.jsxs("button",{onClick:()=>b("decision"),className:"w-full p-3 flex items-center justify-between hover:bg-slate-50 dark:hover:bg-slate-900/50 transition-colors",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${s.decisionActive?"bg-purple-100 dark:bg-purple-900/30":"bg-slate-100 dark:bg-slate-800"}`,children:o.jsx(gi,{className:`w-4 h-4 ${s.decisionActive?"text-purple-600 dark:text-purple-400":"text-slate-400"}`})}),o.jsxs("div",{className:"text-left",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:a}),o.jsx(Cn,{variant:s.decisionActive?"default":"secondary",className:"text-[10px] px-1.5 py-0",children:"决策模型"})]}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s.decisionStage==="analyzing"?"Analyzing task...":s.decisionStage==="deciding"?"Making decision...":s.decisionStage==="generating"?"Generating content...":s.decisionActive?"Active":"Idle"})]})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[s.decisionActive&&o.jsx(hn,{className:"w-4 h-4 text-purple-500 animate-spin"}),l==="decision"?o.jsx(la,{className:"w-4 h-4 text-slate-400"}):o.jsx(aa,{className:"w-4 h-4 text-slate-400"})]})]}),l==="decision"&&o.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-slate-100 dark:border-slate-800",children:[s.decisionThinking&&o.jsxs("div",{className:"mt-2 p-2 bg-purple-50 dark:bg-purple-900/20 rounded-lg",children:[o.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[o.jsx(Gu,{className:"w-3 h-3 text-purple-500"}),o.jsx("span",{className:"text-[10px] font-medium text-purple-600 dark:text-purple-400",children:"Thinking"})]}),o.jsxs("p",{className:"text-xs text-purple-700 dark:text-purple-300 whitespace-pre-wrap",children:[s.decisionThinking,s.decisionActive&&o.jsx("span",{className:"inline-block w-1 h-3 ml-0.5 bg-purple-500 animate-pulse"})]})]}),s.decisionResult&&o.jsxs("div",{className:"mt-2 p-2 bg-slate-50 dark:bg-slate-900/50 rounded-lg",children:[o.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[o.jsx(ha,{className:"w-3 h-3 text-amber-500"}),o.jsx("span",{className:"text-[10px] font-medium text-slate-600 dark:text-slate-400",children:"Decision"})]}),o.jsx("p",{className:"text-xs text-slate-700 dark:text-slate-300",children:s.decisionResult})]}),s.decisions.length>0&&o.jsxs("details",{className:"mt-2",children:[o.jsxs("summary",{className:"text-[10px] text-slate-500 cursor-pointer hover:text-slate-700 dark:hover:text-slate-300",children:["View decision history (",s.decisions.length,")"]}),o.jsx("div",{className:"mt-1 space-y-1 max-h-32 overflow-y-auto",children:s.decisions.slice(-5).map((g,h)=>o.jsxs("div",{className:"text-[10px] p-1.5 bg-slate-100 dark:bg-slate-800 rounded",children:[o.jsxs("span",{className:"text-purple-600 dark:text-purple-400",children:["[",g.decision.action,"]"]})," ",g.decision.target]},h))})]})]})]}),o.jsxs(er,{className:`overflow-hidden transition-all duration-200 ${s.visionActive?"border-green-300 dark:border-green-700 shadow-sm shadow-green-100 dark:shadow-green-900/20":"border-slate-200 dark:border-slate-800"}`,children:[o.jsxs("button",{onClick:()=>b("vision"),className:"w-full p-3 flex items-center justify-between hover:bg-slate-50 dark:hover:bg-slate-900/50 transition-colors",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${s.visionActive?"bg-green-100 dark:bg-green-900/30":"bg-slate-100 dark:bg-slate-800"}`,children:o.jsx(us,{className:`w-4 h-4 ${s.visionActive?"text-green-600 dark:text-green-400":"text-slate-400"}`})}),o.jsxs("div",{className:"text-left",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:u}),o.jsx(Cn,{variant:s.visionActive?"success":"secondary",className:"text-[10px] px-1.5 py-0",children:"视觉模型"})]}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s.visionStage==="capturing"?"Capturing screen...":s.visionStage==="recognizing"?"Recognizing elements...":s.visionStage==="executing"?"Executing action...":s.visionActive?"Active":"Idle"})]})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[s.visionActive&&o.jsx(hn,{className:"w-4 h-4 text-green-500 animate-spin"}),l==="vision"?o.jsx(la,{className:"w-4 h-4 text-slate-400"}):o.jsx(aa,{className:"w-4 h-4 text-slate-400"})]})]}),l==="vision"&&o.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-slate-100 dark:border-slate-800",children:[s.visionDescription&&o.jsxs("div",{className:"mt-2 p-2 bg-green-50 dark:bg-green-900/20 rounded-lg",children:[o.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[o.jsx(us,{className:"w-3 h-3 text-green-500"}),o.jsx("span",{className:"text-[10px] font-medium text-green-600 dark:text-green-400",children:"Screen Recognition"})]}),o.jsx("p",{className:"text-xs text-green-700 dark:text-green-300 line-clamp-3",children:s.visionDescription})]}),s.visionAction&&o.jsxs("div",{className:"mt-2 p-2 bg-slate-50 dark:bg-slate-900/50 rounded-lg",children:[o.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[o.jsx(ha,{className:"w-3 h-3 text-amber-500"}),o.jsx("span",{className:"text-[10px] font-medium text-slate-600 dark:text-slate-400",children:"Action"})]}),o.jsx("p",{className:"text-xs text-slate-700 dark:text-slate-300",children:s.visionAction})]}),s.actions.length>0&&o.jsxs("details",{className:"mt-2",children:[o.jsxs("summary",{className:"text-[10px] text-slate-500 cursor-pointer hover:text-slate-700 dark:hover:text-slate-300",children:["View action history (",s.actions.length,")"]}),o.jsx("div",{className:"mt-1 space-y-1 max-h-32 overflow-y-auto",children:s.actions.slice(-5).map((g,h)=>o.jsxs("div",{className:`text-[10px] p-1.5 rounded flex items-center gap-1 ${g.success?"bg-green-50 dark:bg-green-900/20":"bg-red-50 dark:bg-red-900/20"}`,children:[g.success?o.jsx(Hn,{className:"w-3 h-3 text-green-500"}):o.jsx(ca,{className:"w-3 h-3 text-red-500"}),o.jsxs("span",{className:g.success?"text-green-700 dark:text-green-300":"text-red-700 dark:text-red-300",children:["[",g.action_type,"] ",g.target]})]},h))})]})]})]})]})}function Ny(){const[s,n]=We.useState({decisionActive:!1,decisionStage:"idle",decisionThinking:"",decisionResult:"",taskPlan:[],visionActive:!1,visionStage:"idle",visionDescription:"",visionAction:"",currentStep:0,totalSteps:0,decisions:[],recognitions:[],actions:[]}),r=We.useCallback(u=>{n(l=>{switch(u.type){case"decision_start":return{...l,decisionActive:!0,decisionStage:u.stage,visionActive:!1};case"decision_thinking":return{...l,decisionThinking:l.decisionThinking+u.chunk};case"decision_result":return{...l,decisionActive:!1,decisionStage:"idle",decisionThinking:"",decisionResult:`${u.decision.action}: ${u.decision.target}`,decisions:[...l.decisions,u]};case"task_plan":return{...l,taskPlan:u.plan.steps,totalSteps:u.plan.estimated_actions};case"vision_start":return{...l,visionActive:!0,visionStage:u.stage,decisionActive:!1};case"vision_recognition":return{...l,visionDescription:u.description,recognitions:[...l.recognitions,u]};case"action_start":return{...l,visionStage:"executing",visionAction:`${u.action.action}: ${u.action.target}`};case"action_result":return{...l,visionActive:!1,visionStage:"idle",visionAction:`${u.action_type}: ${u.target} - ${u.success?"Success":"Failed"}`,actions:[...l.actions,u]};case"step_complete":return{...l,currentStep:u.step};case"task_complete":return{...l,decisionActive:!1,visionActive:!1,decisionStage:"idle",visionStage:"idle"};case"error":case"aborted":return{...l,decisionActive:!1,visionActive:!1,decisionStage:"idle",visionStage:"idle"};default:return l}})},[]),a=We.useCallback(()=>{n({decisionActive:!1,decisionStage:"idle",decisionThinking:"",decisionResult:"",taskPlan:[],visionActive:!1,visionStage:"idle",visionDescription:"",visionAction:"",currentStep:0,totalSteps:0,decisions:[],recognitions:[],actions:[]})},[]);return{state:s,handleEvent:r,reset:a}}var Ri="Popover",[lf]=ms(Ri,[$u]),xs=$u(),[Cy,rr]=lf(Ri),cf=s=>{const{__scopePopover:n,children:r,open:a,defaultOpen:u,onOpenChange:l,modal:p=!1}=s,b=xs(n),f=v.useRef(null),[g,h]=v.useState(!1),[_,y]=Sa({prop:a,defaultProp:u??!1,onChange:l,caller:Ri});return o.jsx(Q_,{...b,children:o.jsx(Cy,{scope:n,contentId:Ea(),triggerRef:f,open:_,onOpenChange:y,onOpenToggle:v.useCallback(()=>y(S=>!S),[y]),hasCustomAnchor:g,onCustomAnchorAdd:v.useCallback(()=>h(!0),[]),onCustomAnchorRemove:v.useCallback(()=>h(!1),[]),modal:p,children:r})})};cf.displayName=Ri;var uf="PopoverAnchor",ky=v.forwardRef((s,n)=>{const{__scopePopover:r,...a}=s,u=rr(uf,r),l=xs(r),{onCustomAnchorAdd:p,onCustomAnchorRemove:b}=u;return v.useEffect(()=>(p(),()=>b()),[p,b]),o.jsx(qu,{...l,...a,ref:n})});ky.displayName=uf;var df="PopoverTrigger",ff=v.forwardRef((s,n)=>{const{__scopePopover:r,...a}=s,u=rr(df,r),l=xs(r),p=bn(n,u.triggerRef),b=o.jsx(Zt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":u.open,"aria-controls":u.contentId,"data-state":xf(u.open),...a,ref:p,onClick:dt(s.onClick,u.onOpenToggle)});return u.hasCustomAnchor?b:o.jsx(qu,{asChild:!0,...l,children:b})});ff.displayName=df;var La="PopoverPortal",[Ty,Ry]=lf(La,{forceMount:void 0}),hf=s=>{const{__scopePopover:n,forceMount:r,children:a,container:u}=s,l=rr(La,n);return o.jsx(Ty,{scope:n,forceMount:r,children:o.jsx(gr,{present:r||l.open,children:o.jsx(J_,{asChild:!0,container:u,children:a})})})};hf.displayName=La;var Mr="PopoverContent",pf=v.forwardRef((s,n)=>{const r=Ry(Mr,s.__scopePopover),{forceMount:a=r.forceMount,...u}=s,l=rr(Mr,s.__scopePopover);return o.jsx(gr,{present:a||l.open,children:l.modal?o.jsx(jy,{...u,ref:n}):o.jsx(Py,{...u,ref:n})})});pf.displayName=Mr;var Ay=oa("PopoverContent.RemoveScroll"),jy=v.forwardRef((s,n)=>{const r=rr(Mr,s.__scopePopover),a=v.useRef(null),u=bn(n,a),l=v.useRef(!1);return v.useEffect(()=>{const p=a.current;if(p)return bv(p)},[]),o.jsx(yv,{as:Ay,allowPinchZoom:!0,children:o.jsx(mf,{...s,ref:u,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:dt(s.onCloseAutoFocus,p=>{p.preventDefault(),l.current||r.triggerRef.current?.focus()}),onPointerDownOutside:dt(s.onPointerDownOutside,p=>{const b=p.detail.originalEvent,f=b.button===0&&b.ctrlKey===!0,g=b.button===2||f;l.current=g},{checkForDefaultPrevented:!1}),onFocusOutside:dt(s.onFocusOutside,p=>p.preventDefault(),{checkForDefaultPrevented:!1})})})}),Py=v.forwardRef((s,n)=>{const r=rr(Mr,s.__scopePopover),a=v.useRef(!1),u=v.useRef(!1);return o.jsx(mf,{...s,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{s.onCloseAutoFocus?.(l),l.defaultPrevented||(a.current||r.triggerRef.current?.focus(),l.preventDefault()),a.current=!1,u.current=!1},onInteractOutside:l=>{s.onInteractOutside?.(l),l.defaultPrevented||(a.current=!0,l.detail.originalEvent.type==="pointerdown"&&(u.current=!0));const p=l.target;r.triggerRef.current?.contains(p)&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&u.current&&l.preventDefault()}})}),mf=v.forwardRef((s,n)=>{const{__scopePopover:r,trapFocus:a,onOpenAutoFocus:u,onCloseAutoFocus:l,disableOutsidePointerEvents:p,onEscapeKeyDown:b,onPointerDownOutside:f,onFocusOutside:g,onInteractOutside:h,..._}=s,y=rr(Mr,r),S=xs(r);return wv(),o.jsx(Ev,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:u,onUnmountAutoFocus:l,children:o.jsx(Z_,{asChild:!0,disableOutsidePointerEvents:p,onInteractOutside:h,onEscapeKeyDown:b,onPointerDownOutside:f,onFocusOutside:g,onDismiss:()=>y.onOpenChange(!1),children:o.jsx(ev,{"data-state":xf(y.open),role:"dialog",id:y.contentId,...S,..._,ref:n,style:{..._.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),gf="PopoverClose",My=v.forwardRef((s,n)=>{const{__scopePopover:r,...a}=s,u=rr(gf,r);return o.jsx(Zt.button,{type:"button",...a,ref:n,onClick:dt(s.onClick,()=>u.onOpenChange(!1))})});My.displayName=gf;var Iy="PopoverArrow",Dy=v.forwardRef((s,n)=>{const{__scopePopover:r,...a}=s,u=xs(r);return o.jsx(tv,{...u,...a,ref:n})});Dy.displayName=Iy;function xf(s){return s?"open":"closed"}var Ly=cf,Oy=ff,Fy=hf,By=pf;function bi({...s}){return o.jsx(Ly,{"data-slot":"popover",...s})}function yi({...s}){return o.jsx(Oy,{"data-slot":"popover-trigger",...s})}function wi({className:s,align:n="center",sideOffset:r=4,...a}){return o.jsx(Fy,{children:o.jsx(By,{"data-slot":"popover-content",align:n,sideOffset:r,className:nr("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",s),...a})})}function Uy(s,[n,r]){return Math.min(r,Math.max(n,s))}function Wy(s,n){return v.useReducer((r,a)=>n[r][a]??r,s)}var Oa="ScrollArea",[_f]=ms(Oa),[zy,pn]=_f(Oa),vf=v.forwardRef((s,n)=>{const{__scopeScrollArea:r,type:a="hover",dir:u,scrollHideDelay:l=600,...p}=s,[b,f]=v.useState(null),[g,h]=v.useState(null),[_,y]=v.useState(null),[S,N]=v.useState(null),[j,R]=v.useState(null),[M,F]=v.useState(0),[A,G]=v.useState(0),[q,X]=v.useState(!1),[K,V]=v.useState(!1),U=bn(n,D=>f(D)),I=Ta(u);return o.jsx(zy,{scope:r,type:a,dir:I,scrollHideDelay:l,scrollArea:b,viewport:g,onViewportChange:h,content:_,onContentChange:y,scrollbarX:S,onScrollbarXChange:N,scrollbarXEnabled:q,onScrollbarXEnabledChange:X,scrollbarY:j,onScrollbarYChange:R,scrollbarYEnabled:K,onScrollbarYEnabledChange:V,onCornerWidthChange:F,onCornerHeightChange:G,children:o.jsx(Zt.div,{dir:I,...p,ref:U,style:{position:"relative","--radix-scroll-area-corner-width":M+"px","--radix-scroll-area-corner-height":A+"px",...s.style}})})});vf.displayName=Oa;var bf="ScrollAreaViewport",yf=v.forwardRef((s,n)=>{const{__scopeScrollArea:r,children:a,nonce:u,...l}=s,p=pn(bf,r),b=v.useRef(null),f=bn(n,b,p.onViewportChange);return o.jsxs(o.Fragment,{children:[o.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:u}),o.jsx(Zt.div,{"data-radix-scroll-area-viewport":"",...l,ref:f,style:{overflowX:p.scrollbarXEnabled?"scroll":"hidden",overflowY:p.scrollbarYEnabled?"scroll":"hidden",...s.style},children:o.jsx("div",{ref:p.onContentChange,style:{minWidth:"100%",display:"table"},children:a})})]})});yf.displayName=bf;var Rn="ScrollAreaScrollbar",wf=v.forwardRef((s,n)=>{const{forceMount:r,...a}=s,u=pn(Rn,s.__scopeScrollArea),{onScrollbarXEnabledChange:l,onScrollbarYEnabledChange:p}=u,b=s.orientation==="horizontal";return v.useEffect(()=>(b?l(!0):p(!0),()=>{b?l(!1):p(!1)}),[b,l,p]),u.type==="hover"?o.jsx(Hy,{...a,ref:n,forceMount:r}):u.type==="scroll"?o.jsx(Gy,{...a,ref:n,forceMount:r}):u.type==="auto"?o.jsx(Ef,{...a,ref:n,forceMount:r}):u.type==="always"?o.jsx(Fa,{...a,ref:n}):null});wf.displayName=Rn;var Hy=v.forwardRef((s,n)=>{const{forceMount:r,...a}=s,u=pn(Rn,s.__scopeScrollArea),[l,p]=v.useState(!1);return v.useEffect(()=>{const b=u.scrollArea;let f=0;if(b){const g=()=>{window.clearTimeout(f),p(!0)},h=()=>{f=window.setTimeout(()=>p(!1),u.scrollHideDelay)};return b.addEventListener("pointerenter",g),b.addEventListener("pointerleave",h),()=>{window.clearTimeout(f),b.removeEventListener("pointerenter",g),b.removeEventListener("pointerleave",h)}}},[u.scrollArea,u.scrollHideDelay]),o.jsx(gr,{present:r||l,children:o.jsx(Ef,{"data-state":l?"visible":"hidden",...a,ref:n})})}),Gy=v.forwardRef((s,n)=>{const{forceMount:r,...a}=s,u=pn(Rn,s.__scopeScrollArea),l=s.orientation==="horizontal",p=ji(()=>f("SCROLL_END"),100),[b,f]=Wy("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(b==="idle"){const g=window.setTimeout(()=>f("HIDE"),u.scrollHideDelay);return()=>window.clearTimeout(g)}},[b,u.scrollHideDelay,f]),v.useEffect(()=>{const g=u.viewport,h=l?"scrollLeft":"scrollTop";if(g){let _=g[h];const y=()=>{const S=g[h];_!==S&&(f("SCROLL"),p()),_=S};return g.addEventListener("scroll",y),()=>g.removeEventListener("scroll",y)}},[u.viewport,l,f,p]),o.jsx(gr,{present:r||b!=="hidden",children:o.jsx(Fa,{"data-state":b==="hidden"?"hidden":"visible",...a,ref:n,onPointerEnter:dt(s.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:dt(s.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),Ef=v.forwardRef((s,n)=>{const r=pn(Rn,s.__scopeScrollArea),{forceMount:a,...u}=s,[l,p]=v.useState(!1),b=s.orientation==="horizontal",f=ji(()=>{if(r.viewport){const g=r.viewport.offsetWidth<r.viewport.scrollWidth,h=r.viewport.offsetHeight<r.viewport.scrollHeight;p(b?g:h)}},10);return Ir(r.viewport,f),Ir(r.content,f),o.jsx(gr,{present:a||l,children:o.jsx(Fa,{"data-state":l?"visible":"hidden",...u,ref:n})})}),Fa=v.forwardRef((s,n)=>{const{orientation:r="vertical",...a}=s,u=pn(Rn,s.__scopeScrollArea),l=v.useRef(null),p=v.useRef(0),[b,f]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),g=Tf(b.viewport,b.content),h={...a,sizes:b,onSizesChange:f,hasThumb:g>0&&g<1,onThumbChange:y=>l.current=y,onThumbPointerUp:()=>p.current=0,onThumbPointerDown:y=>p.current=y};function _(y,S){return Ky(y,p.current,b,S)}return r==="horizontal"?o.jsx($y,{...h,ref:n,onThumbPositionChange:()=>{if(u.viewport&&l.current){const y=u.viewport.scrollLeft,S=Hu(y,b,u.dir);l.current.style.transform=`translate3d(${S}px, 0, 0)`}},onWheelScroll:y=>{u.viewport&&(u.viewport.scrollLeft=y)},onDragScroll:y=>{u.viewport&&(u.viewport.scrollLeft=_(y,u.dir))}}):r==="vertical"?o.jsx(qy,{...h,ref:n,onThumbPositionChange:()=>{if(u.viewport&&l.current){const y=u.viewport.scrollTop,S=Hu(y,b);l.current.style.transform=`translate3d(0, ${S}px, 0)`}},onWheelScroll:y=>{u.viewport&&(u.viewport.scrollTop=y)},onDragScroll:y=>{u.viewport&&(u.viewport.scrollTop=_(y))}}):null}),$y=v.forwardRef((s,n)=>{const{sizes:r,onSizesChange:a,...u}=s,l=pn(Rn,s.__scopeScrollArea),[p,b]=v.useState(),f=v.useRef(null),g=bn(n,f,l.onScrollbarXChange);return v.useEffect(()=>{f.current&&b(getComputedStyle(f.current))},[f]),o.jsx(Nf,{"data-orientation":"horizontal",...u,ref:g,sizes:r,style:{bottom:0,left:l.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:l.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ai(r)+"px",...s.style},onThumbPointerDown:h=>s.onThumbPointerDown(h.x),onDragScroll:h=>s.onDragScroll(h.x),onWheelScroll:(h,_)=>{if(l.viewport){const y=l.viewport.scrollLeft+h.deltaX;s.onWheelScroll(y),Af(y,_)&&h.preventDefault()}},onResize:()=>{f.current&&l.viewport&&p&&a({content:l.viewport.scrollWidth,viewport:l.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:Si(p.paddingLeft),paddingEnd:Si(p.paddingRight)}})}})}),qy=v.forwardRef((s,n)=>{const{sizes:r,onSizesChange:a,...u}=s,l=pn(Rn,s.__scopeScrollArea),[p,b]=v.useState(),f=v.useRef(null),g=bn(n,f,l.onScrollbarYChange);return v.useEffect(()=>{f.current&&b(getComputedStyle(f.current))},[f]),o.jsx(Nf,{"data-orientation":"vertical",...u,ref:g,sizes:r,style:{top:0,right:l.dir==="ltr"?0:void 0,left:l.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ai(r)+"px",...s.style},onThumbPointerDown:h=>s.onThumbPointerDown(h.y),onDragScroll:h=>s.onDragScroll(h.y),onWheelScroll:(h,_)=>{if(l.viewport){const y=l.viewport.scrollTop+h.deltaY;s.onWheelScroll(y),Af(y,_)&&h.preventDefault()}},onResize:()=>{f.current&&l.viewport&&p&&a({content:l.viewport.scrollHeight,viewport:l.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:Si(p.paddingTop),paddingEnd:Si(p.paddingBottom)}})}})}),[Xy,Sf]=_f(Rn),Nf=v.forwardRef((s,n)=>{const{__scopeScrollArea:r,sizes:a,hasThumb:u,onThumbChange:l,onThumbPointerUp:p,onThumbPointerDown:b,onThumbPositionChange:f,onDragScroll:g,onWheelScroll:h,onResize:_,...y}=s,S=pn(Rn,r),[N,j]=v.useState(null),R=bn(n,U=>j(U)),M=v.useRef(null),F=v.useRef(""),A=S.viewport,G=a.content-a.viewport,q=Zn(h),X=Zn(f),K=ji(_,10);function V(U){if(M.current){const I=U.clientX-M.current.left,D=U.clientY-M.current.top;g({x:I,y:D})}}return v.useEffect(()=>{const U=I=>{const D=I.target;N?.contains(D)&&q(I,G)};return document.addEventListener("wheel",U,{passive:!1}),()=>document.removeEventListener("wheel",U,{passive:!1})},[A,N,G,q]),v.useEffect(X,[a,X]),Ir(N,K),Ir(S.content,K),o.jsx(Xy,{scope:r,scrollbar:N,hasThumb:u,onThumbChange:Zn(l),onThumbPointerUp:Zn(p),onThumbPositionChange:X,onThumbPointerDown:Zn(b),children:o.jsx(Zt.div,{...y,ref:R,style:{position:"absolute",...y.style},onPointerDown:dt(s.onPointerDown,U=>{U.button===0&&(U.target.setPointerCapture(U.pointerId),M.current=N.getBoundingClientRect(),F.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",S.viewport&&(S.viewport.style.scrollBehavior="auto"),V(U))}),onPointerMove:dt(s.onPointerMove,V),onPointerUp:dt(s.onPointerUp,U=>{const I=U.target;I.hasPointerCapture(U.pointerId)&&I.releasePointerCapture(U.pointerId),document.body.style.webkitUserSelect=F.current,S.viewport&&(S.viewport.style.scrollBehavior=""),M.current=null})})})}),Ei="ScrollAreaThumb",Cf=v.forwardRef((s,n)=>{const{forceMount:r,...a}=s,u=Sf(Ei,s.__scopeScrollArea);return o.jsx(gr,{present:r||u.hasThumb,children:o.jsx(Yy,{ref:n,...a})})}),Yy=v.forwardRef((s,n)=>{const{__scopeScrollArea:r,style:a,...u}=s,l=pn(Ei,r),p=Sf(Ei,r),{onThumbPositionChange:b}=p,f=bn(n,_=>p.onThumbChange(_)),g=v.useRef(void 0),h=ji(()=>{g.current&&(g.current(),g.current=void 0)},100);return v.useEffect(()=>{const _=l.viewport;if(_){const y=()=>{if(h(),!g.current){const S=Qy(_,b);g.current=S,b()}};return b(),_.addEventListener("scroll",y),()=>_.removeEventListener("scroll",y)}},[l.viewport,h,b]),o.jsx(Zt.div,{"data-state":p.hasThumb?"visible":"hidden",...u,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...a},onPointerDownCapture:dt(s.onPointerDownCapture,_=>{const S=_.target.getBoundingClientRect(),N=_.clientX-S.left,j=_.clientY-S.top;p.onThumbPointerDown({x:N,y:j})}),onPointerUp:dt(s.onPointerUp,p.onThumbPointerUp)})});Cf.displayName=Ei;var Ba="ScrollAreaCorner",kf=v.forwardRef((s,n)=>{const r=pn(Ba,s.__scopeScrollArea),a=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&a?o.jsx(Vy,{...s,ref:n}):null});kf.displayName=Ba;var Vy=v.forwardRef((s,n)=>{const{__scopeScrollArea:r,...a}=s,u=pn(Ba,r),[l,p]=v.useState(0),[b,f]=v.useState(0),g=!!(l&&b);return Ir(u.scrollbarX,()=>{const h=u.scrollbarX?.offsetHeight||0;u.onCornerHeightChange(h),f(h)}),Ir(u.scrollbarY,()=>{const h=u.scrollbarY?.offsetWidth||0;u.onCornerWidthChange(h),p(h)}),g?o.jsx(Zt.div,{...a,ref:n,style:{width:l,height:b,position:"absolute",right:u.dir==="ltr"?0:void 0,left:u.dir==="rtl"?0:void 0,bottom:0,...s.style}}):null});function Si(s){return s?parseInt(s,10):0}function Tf(s,n){const r=s/n;return isNaN(r)?0:r}function Ai(s){const n=Tf(s.viewport,s.content),r=s.scrollbar.paddingStart+s.scrollbar.paddingEnd,a=(s.scrollbar.size-r)*n;return Math.max(a,18)}function Ky(s,n,r,a="ltr"){const u=Ai(r),l=u/2,p=n||l,b=u-p,f=r.scrollbar.paddingStart+p,g=r.scrollbar.size-r.scrollbar.paddingEnd-b,h=r.content-r.viewport,_=a==="ltr"?[0,h]:[h*-1,0];return Rf([f,g],_)(s)}function Hu(s,n,r="ltr"){const a=Ai(n),u=n.scrollbar.paddingStart+n.scrollbar.paddingEnd,l=n.scrollbar.size-u,p=n.content-n.viewport,b=l-a,f=r==="ltr"?[0,p]:[p*-1,0],g=Uy(s,f);return Rf([0,p],[0,b])(g)}function Rf(s,n){return r=>{if(s[0]===s[1]||n[0]===n[1])return n[0];const a=(n[1]-n[0])/(s[1]-s[0]);return n[0]+a*(r-s[0])}}function Af(s,n){return s>0&&s<n}var Qy=(s,n=()=>{})=>{let r={left:s.scrollLeft,top:s.scrollTop},a=0;return(function u(){const l={left:s.scrollLeft,top:s.scrollTop},p=r.left!==l.left,b=r.top!==l.top;(p||b)&&n(),r=l,a=window.requestAnimationFrame(u)})(),()=>window.cancelAnimationFrame(a)};function ji(s,n){const r=Zn(s),a=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(a.current),[]),v.useCallback(()=>{window.clearTimeout(a.current),a.current=window.setTimeout(r,n)},[r,n])}function Ir(s,n){const r=Zn(n);nv(()=>{let a=0;if(s){const u=new ResizeObserver(()=>{cancelAnimationFrame(a),a=window.requestAnimationFrame(r)});return u.observe(s),()=>{window.cancelAnimationFrame(a),u.unobserve(s)}}},[s,r])}var Jy=vf,Zy=yf,ew=kf;function ds({className:s,children:n,...r}){return o.jsxs(Jy,{"data-slot":"scroll-area",className:nr("relative",s),...r,children:[o.jsx(Zy,{"data-slot":"scroll-area-viewport",className:"focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",children:n}),o.jsx(tw,{}),o.jsx(ew,{})]})}function tw({className:s,orientation:n="vertical",...r}){return o.jsx(wf,{"data-slot":"scroll-area-scrollbar",orientation:n,className:nr("flex touch-none p-px transition-colors select-none",n==="vertical"&&"h-full w-2.5 border-l border-l-transparent",n==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",s),...r,children:o.jsx(Cf,{"data-slot":"scroll-area-thumb",className:"bg-border relative flex-1 rounded-full"})})}const nw=100,rw=20;function fs(s,n,r,a){return{id:Date.now().toString(),deviceId:s||"unknown",deviceName:n||"Unknown Device",taskText:r?.content||"No task description",success:a?.success??!1,steps:a?.steps??0,startTime:r?.timestamp||new Date,endTime:a?.timestamp||new Date,duration:(a?.timestamp?.getTime()||Date.now())-(r?.timestamp?.getTime()||Date.now()),thinking:a?.thinking??[],actions:a?.actions??[],finalMessage:a?.content||"No result message",errorMessage:a?.success===!1?a?.content||"Unknown error":void 0}}function hs(s,n){try{const r=`history-${s}`,a=localStorage.getItem(r),u=a?JSON.parse(a):[];u.unshift(n);const l=u.slice(0,nw);localStorage.setItem(r,JSON.stringify(l))}catch(r){if(r instanceof Error&&r.name==="QuotaExceededError"){console.warn("localStorage quota exceeded, clearing old history");try{const a=`history-${s}`,u=localStorage.getItem(a),p=(u?JSON.parse(u):[]).slice(0,rw);p.unshift(n),localStorage.setItem(a,JSON.stringify(p))}catch(a){console.error("Failed to save history even after reduction:",a)}}else console.warn("Failed to save history:",r)}}function jf(s){try{const n=`history-${s}`,r=localStorage.getItem(n);return r?JSON.parse(r).map(u=>({...u,startTime:new Date(u.startTime),endTime:new Date(u.endTime)})):[]}catch(n){return console.warn("Failed to load history:",n),[]}}function Pf(s,n){try{const r=`history-${s}`,a=localStorage.getItem(r);if(!a)return;const l=JSON.parse(a).filter(p=>p.id!==n);localStorage.setItem(r,JSON.stringify(l))}catch(r){console.warn("Failed to delete history item:",r)}}function Mf(s){try{const n=`history-${s}`;localStorage.removeItem(n)}catch(n){console.warn("Failed to clear history:",n)}}function sw(s){const r=new Date().getTime()-s.getTime(),a=Math.floor(r/6e4),u=Math.floor(r/36e5),l=Math.floor(r/864e5);return a<1?"Just now":a<60?`${a}m ago`:u<24?`${u}h ago`:l<7?`${l}d ago`:s.toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function iw(s){const n=Math.floor(s/1e3),r=Math.floor(n/60),a=n%60;return r===0?`${a}s`:`${r}m ${a}s`}function If({item:s,onSelect:n,onDelete:r}){const a=Dr(),u=l=>{l.stopPropagation(),confirm(a.history.deleteConfirm)&&r(s.id)};return o.jsx(er,{className:"hover:bg-slate-50 dark:hover:bg-slate-800/50 transition-colors cursor-pointer group",onClick:()=>n(s),children:o.jsxs("div",{className:"p-3 space-y-2",children:[o.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100 line-clamp-2",children:s.taskText}),o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[o.jsx("span",{children:sw(s.startTime)}),o.jsx("span",{children:"•"}),o.jsxs("span",{children:[s.steps," ",s.steps===1?"step":"steps"]}),o.jsx("span",{children:"•"}),o.jsx("span",{children:iw(s.duration)})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Cn,{variant:s.success?"success":"destructive",className:"shrink-0",children:s.success?o.jsxs(o.Fragment,{children:[o.jsx(Hn,{className:"w-3 h-3 mr-1"}),a.history.success]}):o.jsxs(o.Fragment,{children:[o.jsx(Nn,{className:"w-3 h-3 mr-1"}),a.history.failed]})}),o.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-red-500 dark:text-slate-500 dark:hover:text-red-400",onClick:u,title:a.history.deleteItem,children:o.jsx(Sv,{className:"w-3 h-3"})})]})]})]})})}function ow({deviceId:s,deviceSerial:n,deviceName:r,config:a,isConfigured:u,thinkingMode:l="deep",onThinkingModeChange:p,dualModelEnabled:b=!1}){const f=Dr(),[g,h]=v.useState([]),[_,y]=v.useState(""),[S,N]=v.useState(!1),[j,R]=v.useState(!1),[M,F]=v.useState(null),[A,G]=v.useState(!1),[q,X]=v.useState(null),[K,V]=v.useState(!0),[U,I]=v.useState(!1),[D,me]=v.useState("auto"),[ye,$]=v.useState(null),[J,T]=v.useState("success"),[O,re]=v.useState(!1),[de,ue]=v.useState([]),[Z,Se]=v.useState([]),[je,Fe]=v.useState(!1),[Ie,at]=v.useState(!1),{state:lt,handleEvent:Ge,reset:Te}=Ny(),$e=v.useRef(null),mt=(H,Pe=2e3,xe="success")=>{$e.current&&clearTimeout($e.current),T(xe),$(H),$e.current=setTimeout(()=>{$(null)},Pe)};v.useEffect(()=>()=>{$e.current&&clearTimeout($e.current)},[]);const[tt,At]=v.useState(!1),[Xe,gt]=v.useState(!1),ne=v.useRef(null),se=()=>{ne.current&&clearTimeout(ne.current),At(!0)},L=()=>{ne.current=setTimeout(()=>{At(!1)},500)};v.useEffect(()=>()=>{ne.current&&clearTimeout(ne.current)},[]);const ee=()=>{gt(H=>!H)},le=v.useRef(null),ce=v.useRef(null),Ce=v.useRef(null),we=v.useRef(null),xt=v.useRef(null),bt=v.useRef(!1),Q=v.useRef(!1),ie=v.useRef(null),ge=v.useRef(0),Ke=v.useRef(null),[Ft,st]=v.useState(!0),[en,jt]=v.useState(!1),tn=v.useRef(Bd.throttle(()=>{const H=xt.current;if(!H)return;const Pe=80,xe=H.scrollHeight-H.scrollTop-H.clientHeight,nt=xe<=1;st(nt),xe<=Pe&&jt(!1)},100));v.useEffect(()=>{const H=tn.current;return()=>{H.cancel()}},[]);const Qe=v.useCallback(async(H=!1)=>{if(a)try{await rv({model_config:{base_url:a.base_url||void 0,api_key:a.api_key||void 0,model_name:a.model_name||void 0},agent_config:{device_id:s},agent_type:a.agent_type,agent_config_params:a.agent_config_params,force:H}),G(!0),F(null)}catch(Pe){const xe=mi(Pe);F(xe),H&&G(!1)}},[s,a]),Ct=v.useCallback(async()=>{if(a)try{await sv({device_id:s,decision_base_url:a.decision_base_url||"",decision_api_key:a.decision_api_key||"",decision_model_name:a.decision_model_name||"",vision_base_url:a.base_url,vision_api_key:a.api_key,vision_model_name:a.model_name,thinking_mode:l}),at(!0),F(null)}catch(H){const Pe=mi(H);F(Pe)}},[s,a,l]);v.useEffect(()=>{b&&!Ie&&A&&a?.decision_base_url&&a?.base_url&&Ct()},[b,Ie,A,a,Ct]),v.useEffect(()=>{b&&Ie&&a?.decision_base_url&&a?.base_url&&Ct()},[l,b,Ie,a]),v.useEffect(()=>{u&&a&&!A&&!Q.current&&(Q.current=!0,Qe())},[u,a,A,Qe]),v.useEffect(()=>{if(O){const H=jf(n);ue(H)}},[O,n]);const Pt=H=>{const Pe={id:`${H.id}-user`,role:"user",content:H.taskText,timestamp:H.startTime},xe={id:`${H.id}-agent`,role:"assistant",content:H.finalMessage,timestamp:H.endTime,steps:H.steps,success:H.success,thinking:H.thinking,actions:H.actions,isStreaming:!1},nt=[Pe,xe];h(nt),ge.current=nt.length,Ke.current=[xe.id,xe.content?.length??0,xe.currentThinking?.length??0,xe.thinking?JSON.stringify(xe.thinking).length:0,xe.steps??"",xe.isStreaming?1:0].join("|"),jt(!1),st(!0),re(!1)},xr=()=>{confirm(f.history.clearAllConfirm)&&(Mf(n),ue([]))},sr=H=>{Pf(n,H),ue(Pe=>Pe.filter(xe=>xe.id!==H))};v.useEffect(()=>{if(!A||!a)return;const H=ie.current;H&&(H.base_url!==a.base_url||H.model_name!==a.model_name||H.api_key!==a.api_key||H.agent_type!==a.agent_type)&&(console.log(`[DevicePanel] Config changed for device ${s}, force re-initializing...`),Qe(!0)),ie.current=a},[a,A,s,Qe]);const He=v.useCallback(async()=>{const H=_.trim();if(!H||S)return;A||await Qe();const Pe={id:Date.now().toString(),role:"user",content:H,timestamp:new Date};h(Ze=>[...Ze,Pe]),y(""),N(!0),F(null);const xe=[],nt=[];let yn="";const ft=[];let Je=null;const ht=(Date.now()+1).toString(),Bt={id:ht,role:"assistant",content:"",timestamp:new Date,thinking:[],actions:[],isStreaming:!0,currentThinking:""};h(Ze=>[...Ze,Bt]);const Ur=()=>{if(ft.length>0){const Ze=ft.join("");ft.length=0,yn+=Ze,h(Ut=>Ut.map(qt=>qt.id===ht?{...qt,currentThinking:yn}:qt))}Je=null},Li=iv(Pe.content,s,Ze=>{ft.push(Ze.chunk),Je===null&&(Je=setTimeout(Ur,50))},Ze=>{Je!==null&&(clearTimeout(Je),Ur());const Ut=Ze.thinking&&Ze.thinking.length>0?Ze.thinking:yn;Ut&&xe.push(Ut),yn="",nt.push(Ze.action),h(qt=>qt.map(nn=>nn.id===ht?{...nn,thinking:[...xe],actions:[...nt],steps:Ze.step,currentThinking:""}:nn))},Ze=>{Je!==null&&clearTimeout(Je);const Ut={...Bt,content:Ze.message,success:Ze.success,isStreaming:!1,steps:Ze.steps,thinking:[...xe],actions:[...nt],timestamp:new Date,currentThinking:void 0};h(nn=>nn.map(ir=>ir.id===ht?Ut:ir)),N(!1),le.current=null;const qt=fs(n,r,Pe,Ut);hs(n,qt)},Ze=>{Je!==null&&clearTimeout(Je);const Ut={...Bt,content:`Error: ${Ze.message}`,success:!1,isStreaming:!1,thinking:[...xe],actions:[...nt],timestamp:new Date,currentThinking:void 0};h(nn=>nn.map(ir=>ir.id===ht?Ut:ir)),N(!1),F(Ze.message),le.current=null;const qt=fs(n,r,Pe,Ut);hs(n,qt)},Ze=>{Je!==null&&clearTimeout(Je);const Ut={...Bt,content:Ze.message||"Chat aborted by user",success:!1,isStreaming:!1,thinking:[...xe],actions:[...nt],timestamp:new Date,currentThinking:void 0};h(qt=>qt.map(nn=>nn.id===ht?Ut:nn)),N(!1),le.current=null,$(f.chat.aborted),T("success"),setTimeout(()=>$(null),2e3)});le.current=Li},[_,S,A,s,n,r,Qe,f,$,T]),Mt=v.useCallback(async()=>{const H=_.trim();if(!H||S)return;Ie||await Ct();const Pe={id:Date.now().toString(),role:"user",content:H,timestamp:new Date};h(ft=>[...ft,Pe]),y(""),N(!0),F(null),Te();const xe=(Date.now()+1).toString(),nt={id:xe,role:"assistant",content:"",timestamp:new Date,thinking:[],actions:[],isStreaming:!0};h(ft=>[...ft,nt]);const yn=ov(Pe.content,s,ft=>{if(Ge(ft),ft.type==="task_complete"){const Je=ft;h(ht=>ht.map(Bt=>Bt.id===xe?{...Bt,content:Je.message,success:Je.success,steps:Je.steps,isStreaming:!1}:Bt)),N(!1),ce.current=null}else if(ft.type==="error"){const Je=ft;h(ht=>ht.map(Bt=>Bt.id===xe?{...Bt,content:`Error: ${Je.message}`,success:!1,isStreaming:!1}:Bt)),N(!1),F(Je.message),ce.current=null}else ft.type==="aborted"&&(h(Je=>Je.map(ht=>ht.id===xe?{...ht,content:"Task aborted",success:!1,isStreaming:!1}:ht)),N(!1),ce.current=null)},ft=>{h(Je=>Je.map(ht=>ht.id===xe?{...ht,content:`Error: ${ft.message}`,success:!1,isStreaming:!1}:ht)),N(!1),F(ft.message),ce.current=null});ce.current=yn},[_,S,Ie,s,Ct,Ge,Te]),wt=v.useCallback(async()=>{b?await Mt():await He()},[b,Mt,He]),It=v.useCallback(async()=>{le.current&&le.current.close(),ce.current&&ce.current.close(),h([]),N(!1),F(null),jt(!1),st(!0),le.current=null,ce.current=null,ge.current=0,Ke.current=null,Te(),b?await av(s):await lv(s)},[s,b,Te]),An=v.useCallback(async()=>{if(!(!le.current&&!ce.current)){R(!0);try{le.current&&(le.current.close(),le.current=null),ce.current&&(ce.current.close(),ce.current=null),h(H=>{const Pe=H[H.length-1];return Pe&&Pe.role==="assistant"&&Pe.isStreaming?H.map((xe,nt)=>nt===H.length-1?{...xe,content:xe.content||f.chat.aborted,isStreaming:!1,success:!1,currentThinking:void 0}:xe):H}),b?cv(s).catch(H=>console.error("Backend abort failed:",H)):uv(s).catch(H=>console.error("Backend abort failed:",H)),$(f.chat.aborted),T("success"),setTimeout(()=>$(null),2e3)}catch(H){console.error("Failed to abort chat:",H),$(f.chat.abortFailed),T("error"),setTimeout(()=>$(null),2e3)}finally{N(!1),R(!1)}}},[s,b,f]),Or=v.useCallback(()=>{we.current?.scrollIntoView({behavior:"smooth"})},[]);v.useEffect(()=>{const H=g[g.length-1],Pe=H?.thinking?JSON.stringify(H.thinking).length:0,xe=H?[H.id,H.content?.length??0,H.currentThinking?.length??0,Pe,H.steps??"",H.isStreaming?1:0].join("|"):null,nt=g.length>ge.current,yn=xe!==Ke.current&&g.length>0;if(ge.current=g.length,Ke.current=xe,Ft){Or(),jt(!1);return}if(g.length===0){jt(!1);return}(nt||yn)&&jt(!0)},[g,Ft,Or]),v.useEffect(()=>()=>{le.current&&le.current.close(),ce.current&&ce.current.close(),Ce.current&&Ce.current.close()},[s]),v.useEffect(()=>{(async()=>{try{const Pe=await Yu();Se(Pe.workflows)}catch(Pe){console.error("Failed to load workflows:",Pe)}})()},[]);const Pi=H=>{y(H.text),Fe(!1)},_s=()=>{tn.current()},Mi=()=>{Or(),jt(!1),st(!0)};v.useEffect(()=>{if(!s||!(D==="screenshot"||D==="auto"&&U))return;const Pe=async()=>{if(!bt.current){bt.current=!0;try{const nt=await Na(s);nt.success&&X(nt)}catch(nt){console.error("Failed to fetch screenshot:",nt)}finally{bt.current=!1}}};Pe();const xe=setInterval(Pe,500);return()=>clearInterval(xe)},[s,U,D]);const Ii=H=>{(H.metaKey||H.ctrlKey)&&H.key==="Enter"&&(H.preventDefault(),wt())},Di=v.useCallback(H=>{Ce.current=H},[]),Fr=v.useCallback(()=>{I(!0),V(!1)},[]),Br=H=>{me(H)};return o.jsxs("div",{className:"flex-1 flex gap-4 p-4 items-stretch justify-center min-h-0",children:[o.jsxs(er,{className:"flex-1 flex flex-col min-h-0 max-w-2xl",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:o.jsx(as,{className:"h-5 w-5 text-[#1d9bf0]"})}),o.jsxs("div",{className:"group",children:[o.jsx("div",{className:"flex items-center gap-1",children:o.jsx("h2",{className:"font-bold text-slate-900 dark:text-slate-100",children:r})}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 font-mono",children:s})]})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs(bi,{open:O,onOpenChange:re,children:[o.jsx(yi,{asChild:!0,children:o.jsx(ve,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300",title:f.history.title,children:o.jsx(xi,{className:"h-4 w-4"})})}),o.jsxs(wi,{className:"w-96 p-0",align:"end",sideOffset:8,children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[o.jsx("h3",{className:"font-semibold text-sm text-slate-900 dark:text-slate-100",children:f.history.title}),de.length>0&&o.jsx(ve,{variant:"ghost",size:"sm",onClick:xr,className:"h-7 text-xs",children:f.history.clearAll})]}),o.jsx(ds,{className:"h-[400px]",children:o.jsx("div",{className:"p-4 space-y-2",children:de.length>0?de.map(H=>o.jsx(If,{item:H,onSelect:Pt,onDelete:sr},H.id)):o.jsxs("div",{className:"text-center py-8",children:[o.jsx(xi,{className:"h-12 w-12 text-slate-300 dark:text-slate-700 mx-auto mb-3"}),o.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:f.history.noHistory}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1",children:f.history.noHistoryDescription})]})})})]})]}),u?A?o.jsxs(Cn,{variant:"success",children:[o.jsx(Hn,{className:"w-3 h-3 mr-1"}),f.devicePanel.ready]}):o.jsx(ve,{onClick:()=>Qe(),disabled:!u||!a,size:"sm",variant:"twitter",children:f.devicePanel.initializing}):o.jsxs(Cn,{variant:"warning",children:[o.jsx(Nn,{className:"w-3 h-3 mr-1"}),f.devicePanel.noConfig]}),b&&p&&o.jsxs(o.Fragment,{children:[o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsx(ve,{variant:l==="fast"?"default":"ghost",size:"icon",onClick:()=>p("fast"),className:`h-8 w-8 rounded-full ${l==="fast"?"bg-green-500 hover:bg-green-600 text-white":"text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300"}`,children:o.jsx(ha,{className:"h-4 w-4"})})}),o.jsx(zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.fastMode}),o.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.fastModeDesc})]})})]}),o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsx(ve,{variant:l==="deep"?"default":"ghost",size:"icon",onClick:()=>p("deep"),className:`h-8 w-8 rounded-full ${l==="deep"?"bg-blue-500 hover:bg-blue-600 text-white":"text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300"}`,children:o.jsx(cd,{className:"h-4 w-4"})})}),o.jsx(zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.deepMode}),o.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.deepModeDesc})]})})]}),o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsx(ve,{variant:l==="turbo"?"default":"ghost",size:"icon",onClick:()=>p("turbo"),className:`h-8 w-8 rounded-full ${l==="turbo"?"bg-orange-500 hover:bg-orange-600 text-white":"text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300"}`,children:o.jsx(Vv,{className:"h-4 w-4"})})}),o.jsx(zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.turboMode}),o.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.turboModeDesc})]})})]})]}),o.jsx(ve,{variant:"ghost",size:"icon",onClick:It,className:"h-8 w-8 rounded-full text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300",title:"Reset chat",children:o.jsx(id,{className:"h-4 w-4"})})]})]}),b&&o.jsx("div",{className:"border-b border-slate-200 dark:border-slate-800 p-4",children:o.jsx(Sy,{state:lt,isStreaming:S,className:"",decisionModelName:a?.decision_model_name||"",visionModelName:a?.model_name||"autoglm-phone"})}),M&&o.jsxs("div",{className:"mx-4 mt-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl text-sm text-red-600 dark:text-red-400 flex items-center gap-2",children:[o.jsx(Nn,{className:"w-4 h-4 flex-shrink-0"}),M]}),o.jsxs("div",{className:"flex-1 min-h-0 relative",children:[o.jsxs("div",{className:"h-full overflow-y-auto p-4",ref:xt,onScroll:_s,children:[g.length===0?o.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center min-h-[calc(100%-1rem)]",children:[o.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800 mb-4",children:o.jsx(as,{className:"h-8 w-8 text-slate-400"})}),o.jsx("p",{className:"font-medium text-slate-900 dark:text-slate-100",children:f.devicePanel.readyToHelp}),o.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:f.devicePanel.describeTask})]}):g.map(H=>o.jsx("div",{className:`flex ${H.role==="user"?"justify-end":"justify-start"}`,children:H.role==="assistant"?o.jsxs("div",{className:"max-w-[85%] space-y-3",children:[H.thinking?.map((Pe,xe)=>o.jsxs("div",{className:"bg-slate-100 dark:bg-slate-800 rounded-2xl rounded-tl-sm px-4 py-3",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:o.jsx(as,{className:"h-3 w-3 text-[#1d9bf0]"})}),o.jsxs("span",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:["Step ",xe+1]})]}),o.jsx("p",{className:"text-sm whitespace-pre-wrap text-slate-700 dark:text-slate-300",children:Pe}),H.actions?.[xe]&&o.jsxs("details",{className:"mt-2 text-xs",children:[o.jsx("summary",{className:"cursor-pointer text-[#1d9bf0] hover:text-[#1a8cd8]",children:"View action"}),o.jsx("pre",{className:"mt-2 p-2 bg-slate-900 text-slate-200 rounded-lg overflow-x-auto text-xs",children:JSON.stringify(H.actions[xe],null,2)})]})]},xe)),H.currentThinking&&o.jsxs("div",{className:"bg-slate-100 dark:bg-slate-800 rounded-2xl rounded-tl-sm px-4 py-3",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:o.jsx(as,{className:"h-3 w-3 text-[#1d9bf0] animate-pulse"})}),o.jsx("span",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:"Thinking..."})]}),o.jsxs("p",{className:"text-sm whitespace-pre-wrap text-slate-700 dark:text-slate-300",children:[H.currentThinking,o.jsx("span",{className:"inline-block w-1 h-4 ml-0.5 bg-[#1d9bf0] animate-pulse"})]})]}),H.content&&o.jsxs("div",{className:`
123
- rounded-2xl px-4 py-3 flex items-start gap-2
124
- ${H.success===!1?"bg-red-100 dark:bg-red-900/20 text-red-600 dark:text-red-400":"bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300"}
125
- `,children:[o.jsx(Hn,{className:`w-5 h-5 flex-shrink-0 mt-0.5 ${H.success===!1?"text-red-500":"text-green-500"}`}),o.jsxs("div",{children:[o.jsx("p",{className:"whitespace-pre-wrap",children:H.content}),H.steps!==void 0&&o.jsxs("p",{className:"text-xs mt-2 opacity-60 text-slate-500 dark:text-slate-400",children:[H.steps," steps completed"]})]})]}),H.isStreaming&&o.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400",children:[o.jsx(hn,{className:"w-4 h-4 animate-spin"}),"Processing..."]})]}):o.jsxs("div",{className:"max-w-[75%]",children:[o.jsx("div",{className:"chat-bubble-user px-4 py-3",children:o.jsx("p",{className:"whitespace-pre-wrap",children:H.content})}),o.jsx("p",{className:"text-xs text-slate-400 dark:text-slate-500 mt-1 text-right",children:H.timestamp.toLocaleTimeString()})]})},H.id)),o.jsx("div",{ref:we})]}),en&&o.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-4 flex justify-center",children:o.jsx(ve,{onClick:Mi,size:"sm",className:"pointer-events-auto shadow-lg bg-[#1d9bf0] text-white hover:bg-[#1a8cd8]","aria-label":f.devicePanel.newMessages,children:f.devicePanel.newMessages})})]}),o.jsx("div",{className:"p-4 border-t border-slate-200 dark:border-slate-800",children:o.jsxs("div",{className:"flex items-end gap-3",children:[o.jsx(td,{value:_,onChange:H=>y(H.target.value),onKeyDown:Ii,placeholder:u?A?f.devicePanel.whatToDo:f.devicePanel.initDeviceFirst:f.devicePanel.configureFirst,disabled:S,className:"flex-1 min-h-[40px] max-h-[120px] resize-none",rows:1}),o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsxs(bi,{open:je,onOpenChange:Fe,children:[o.jsx(yi,{asChild:!0,children:o.jsx(ve,{variant:"outline",size:"icon",className:"h-10 w-10 flex-shrink-0",children:o.jsx(Xu,{className:"w-4 h-4"})})}),o.jsx(wi,{align:"start",className:"w-72 p-3",children:o.jsxs("div",{className:"space-y-2",children:[o.jsx("h4",{className:"font-medium text-sm",children:f.workflows.selectWorkflow}),Z.length===0?o.jsxs("div",{className:"text-sm text-slate-500 dark:text-slate-400 space-y-1",children:[o.jsx("p",{children:f.workflows.empty}),o.jsxs("p",{children:["前往"," ",o.jsx("a",{href:"/workflows",className:"text-primary underline",children:"工作流"})," ","页面创建。"]})]}):o.jsx(ds,{className:"h-64",children:o.jsx("div",{className:"space-y-1",children:Z.map(H=>o.jsxs("button",{onClick:()=>Pi(H),className:"w-full text-left p-2 rounded hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:[o.jsx("div",{className:"font-medium text-sm",children:H.name}),o.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400 line-clamp-2",children:H.text})]},H.uuid))})})]})})]})}),o.jsx(zn,{side:"top",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.workflowButton}),o.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.workflowButtonDesc})]})})]}),S&&o.jsx(ve,{onClick:An,disabled:j,size:"icon",variant:"destructive",className:"h-10 w-10 rounded-full flex-shrink-0",title:f.chat.abortChat,children:j?o.jsx(hn,{className:"h-4 w-4 animate-spin"}):o.jsx(ld,{className:"h-4 w-4"})}),!S&&o.jsx(ve,{onClick:wt,disabled:!_.trim(),size:"icon",variant:"twitter",className:"h-10 w-10 rounded-full flex-shrink-0",children:o.jsx(od,{className:"h-4 w-4"})})]})})]}),o.jsxs(er,{className:"w-[320px] flex-shrink-0 relative min-h-0 overflow-hidden bg-background",onMouseEnter:se,onMouseLeave:L,children:[o.jsx("div",{className:`absolute top-4 right-4 z-10 transition-opacity duration-200 ${tt?"opacity-100":"opacity-0 pointer-events-none"}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("div",{className:`flex items-center gap-1 bg-popover/90 backdrop-blur rounded-xl p-1 shadow-lg border border-border transition-all duration-300 ${Xe?"opacity-100 translate-x-0":"opacity-0 translate-x-4 pointer-events-none"}`,children:[o.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Br("auto"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${D==="auto"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:f.devicePanel.auto}),o.jsxs(ve,{variant:"ghost",size:"sm",onClick:()=>Br("video"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${D==="video"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[o.jsx(ud,{className:"w-3 h-3 mr-1"}),f.devicePanel.video]}),o.jsxs(ve,{variant:"ghost",size:"sm",onClick:()=>Br("screenshot"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${D==="screenshot"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[o.jsx(_i,{className:"w-3 h-3 mr-1"}),f.devicePanel.image]})]}),o.jsx(ve,{variant:"ghost",size:"icon",onClick:ee,className:"h-8 w-8 rounded-full bg-popover/90 backdrop-blur border border-border shadow-lg hover:bg-accent",title:Xe?"Hide controls":"Show controls",children:Xe?o.jsx(ka,{className:"w-4 h-4"}):o.jsx(Ca,{className:"w-4 h-4"})})]})}),o.jsx("div",{className:"absolute bottom-4 left-4 z-10",children:o.jsxs(Cn,{variant:"secondary",className:"bg-white/90 text-slate-700 border border-slate-200 dark:bg-slate-900/90 dark:text-slate-300 dark:border-slate-700",children:[D==="auto"&&f.devicePanel.auto,D==="video"&&o.jsxs(o.Fragment,{children:[o.jsx(sd,{className:"w-3 h-3 mr-1"}),f.devicePanel.video]}),D==="screenshot"&&o.jsxs(o.Fragment,{children:[o.jsx(_i,{className:"w-3 h-3 mr-1"}),f.devicePanel.imageRefresh]})]})}),ye&&o.jsxs("div",{className:"absolute bottom-4 right-4 z-20 flex items-center gap-2 px-3 py-2 bg-[#1d9bf0] text-white text-sm rounded-xl shadow-lg",children:[J==="error"&&o.jsx(Nn,{className:"w-4 h-4"}),J==="tap"&&o.jsx(rd,{className:"w-4 h-4"}),J==="swipe"&&o.jsx(nd,{className:"w-4 h-4"}),J==="success"&&o.jsx(Hn,{className:"w-4 h-4"}),o.jsx("span",{children:ye})]}),D==="video"||D==="auto"&&K&&!U?o.jsx(of,{deviceId:s,className:"w-full h-full",enableControl:!0,onFallback:Fr,onTapSuccess:()=>mt(f.devicePanel.tapped,2e3,"tap"),onTapError:H=>mt(f.devicePanel.tapError.replace("{error}",H),3e3,"error"),onSwipeSuccess:()=>mt(f.devicePanel.swiped,2e3,"swipe"),onSwipeError:H=>mt(f.devicePanel.swipeError.replace("{error}",H),3e3,"error"),onStreamReady:Di,fallbackTimeout:1e5}):o.jsx("div",{className:"w-full h-full flex items-center justify-center bg-muted/30 min-h-0",children:q&&q.success?o.jsxs("div",{className:"relative w-full h-full flex items-center justify-center min-h-0",children:[o.jsx("img",{src:`data:image/png;base64,${q.image}`,alt:"Device Screenshot",className:"max-w-full max-h-full object-contain",style:{width:q.width>q.height?"100%":"auto",height:q.width>q.height?"auto":"100%"}}),q.is_sensitive&&o.jsx("div",{className:"absolute top-12 right-2 px-2 py-1 bg-yellow-500 text-white text-xs rounded-lg",children:f.devicePanel.sensitiveContent})]}):q?.error?o.jsxs("div",{className:"text-center text-destructive",children:[o.jsx(Nn,{className:"w-8 h-8 mx-auto mb-2"}),o.jsx("p",{className:"font-medium",children:f.devicePanel.screenshotFailed}),o.jsx("p",{className:"text-xs mt-1 opacity-60",children:q.error})]}):o.jsxs("div",{className:"text-center text-muted-foreground",children:[o.jsx(hn,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),o.jsx("p",{className:"text-sm",children:f.devicePanel.loading})]})})]})]})}function aw({deviceId:s,deviceSerial:n,deviceName:r,isVisible:a}){const u=Dr(),[l,p]=v.useState([]),[b,f]=v.useState(""),[g,h]=v.useState(!1),[_,y]=v.useState(!1),[S,N]=v.useState(null),j=v.useRef(null),R=v.useRef(null),M=v.useRef(null),[F,A]=v.useState(!0),[G,q]=v.useState(!1),[X,K]=v.useState("auto"),[V,U]=v.useState(null),[I,D]=v.useState(null),[me,ye]=v.useState("success"),$=v.useRef(null),[J,T]=v.useState(!1),[O,re]=v.useState(!1),de=v.useRef(null),ue=v.useRef(null),Z=v.useRef(!1),[Se,je]=v.useState([]),[Fe,Ie]=v.useState(!1),[at,lt]=v.useState([]),[Ge,Te]=v.useState(!1),$e=(Q,ie=2e3,ge="success")=>{$.current&&clearTimeout($.current),ye(ge),D(Q),$.current=setTimeout(()=>{D(null)},ie)};v.useEffect(()=>{j.current?.scrollIntoView({behavior:"smooth"})},[l]),v.useEffect(()=>()=>{$.current&&clearTimeout($.current),R.current&&R.current.close()},[]);const mt=()=>{de.current&&clearTimeout(de.current),T(!0)},tt=()=>{de.current=setTimeout(()=>{T(!1)},500)};v.useEffect(()=>()=>{de.current&&clearTimeout(de.current)},[]);const At=()=>{re(Q=>!Q)};v.useEffect(()=>()=>{ue.current&&ue.current.close()},[s]),v.useEffect(()=>{(async()=>{try{const ie=await Yu();je(ie.workflows)}catch(ie){console.error("Failed to load workflows:",ie)}})()},[]),v.useEffect(()=>{if(Ge){const Q=jf(n);lt(Q)}},[Ge,n]);const Xe=Q=>{f(Q.text),Ie(!1)},gt=Q=>{const ie={id:`${Q.id}-user`,role:"user",content:Q.taskText,timestamp:Q.startTime},ge={id:`${Q.id}-agent`,role:"assistant",content:Q.finalMessage,timestamp:Q.endTime,steps:[],success:Q.success,isStreaming:!1};p([ie,ge]),Te(!1)},ne=()=>{confirm(u.history?.clearAllConfirm||"Clear all history?")&&(Mf(n),lt([]))},se=Q=>{Pf(n,Q),lt(ie=>ie.filter(ge=>ge.id!==Q))};v.useEffect(()=>{if(!s||!a||!(X==="screenshot"||X==="auto"&&G))return;const ie=async()=>{if(!Z.current){Z.current=!0;try{const Ke=await Na(s);Ke.success&&U(Ke)}catch(Ke){console.error("Failed to fetch screenshot:",Ke)}finally{Z.current=!1}}};ie();const ge=setInterval(ie,500);return()=>clearInterval(ge)},[s,G,X,a]);const L=v.useCallback(Q=>{ue.current=Q},[]),ee=v.useCallback(()=>{q(!0),A(!1)},[]),le=Q=>{K(Q)},ce=(Q,ie)=>{p(ge=>ge.map(Ke=>Ke.id===Q?{...Ke,steps:Ke.steps?.map(Ft=>Ft.id===ie?{...Ft,isExpanded:!Ft.isExpanded}:Ft)}:Ke))},Ce=v.useCallback(async()=>{const Q=b.trim();if(!Q||g)return;const ie={id:Date.now().toString(),role:"user",content:Q,timestamp:new Date};p(st=>[...st,ie]),f(""),h(!0),N(null);const ge=(Date.now()+1).toString(),Ke={id:ge,role:"assistant",content:"",timestamp:new Date,steps:[],isStreaming:!0};p(st=>[...st,Ke]);const Ft=new AbortController;M.current=Ft;try{const st=await fetch("/api/layered-agent/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:Q,device_id:s,session_id:s}),signal:Ft.signal});if(!st.ok){let Ct=`HTTP error! status: ${st.status}`;try{const Pt=await st.json();Pt.detail&&(Ct=Pt.detail)}catch{}throw new Error(Ct)}const en=st.body?.getReader();if(!en)throw new Error("No response body");const jt=new TextDecoder;let tn="";const Qe=[];for(;;){const{done:Ct,value:Pt}=await en.read();if(Ct)break;tn+=jt.decode(Pt,{stream:!0});const xr=tn.split(`
126
- `);tn=xr.pop()||"";for(const sr of xr)if(sr.startsWith("data: "))try{const He=JSON.parse(sr.slice(6));if(He.type==="tool_call"){const Mt={id:`step-${Date.now()}-${Math.random()}`,type:"tool_call",content:He.tool_name==="chat"?"发送指令给 Phone Agent":He.tool_name==="list_devices"?"获取设备列表":`调用工具: ${He.tool_name}`,toolName:He.tool_name,toolArgs:He.tool_args||{},timestamp:new Date,isExpanded:!0};Qe.push(Mt),p(wt=>wt.map(It=>It.id===ge?{...It,steps:[...Qe]}:It))}else if(He.type==="tool_result"){const Mt={id:`step-${Date.now()}-${Math.random()}`,type:"tool_result",content:He.tool_name==="chat"?"Phone Agent 执行结果":`${He.tool_name} 结果`,toolResult:He.result,timestamp:new Date,isExpanded:!0};Qe.push(Mt),p(wt=>wt.map(It=>It.id===ge?{...It,steps:[...Qe]}:It))}else if(He.type==="message")p(Mt=>Mt.map(wt=>wt.id===ge?{...wt,content:He.content}:wt));else if(He.type==="done"){const Mt={...Ke,content:He.content||"",isStreaming:!1,success:He.success,steps:[...Qe],timestamp:new Date};p(It=>It.map(An=>An.id===ge?Mt:An));const wt=fs(n,r,ie,{content:He.content||"",timestamp:new Date,success:He.success,steps:Qe.length});hs(n,wt)}else if(He.type==="error"){const Mt={...Ke,content:`错误: ${He.message}`,isStreaming:!1,success:!1,steps:[...Qe],timestamp:new Date};p(It=>It.map(An=>An.id===ge?Mt:An)),N(He.message);const wt=fs(n,r,ie,{content:`错误: ${He.message}`,timestamp:new Date,success:!1,steps:Qe.length});hs(n,wt)}}catch(He){console.error("Failed to parse SSE data:",He,sr)}}p(Ct=>Ct.map(Pt=>Pt.id===ge&&Pt.isStreaming?{...Pt,isStreaming:!1,success:!0}:Pt))}catch(st){if(st instanceof Error&&st.name==="AbortError"){console.log("Chat aborted by user");return}console.error("Chat error:",st);const en=mi(st);N(en),p(tn=>tn.map(Qe=>Qe.id===ge?{...Qe,content:`错误: ${en}`,isStreaming:!1,success:!1}:Qe));const jt=fs(n,r,ie,{content:`错误: ${en}`,timestamp:new Date,success:!1,steps:0});hs(n,jt)}finally{h(!1),M.current=null}},[b,g,s,n,r]),we=v.useCallback(()=>{if(M.current){y(!0);try{M.current.abort(),M.current=null,p(Q=>{const ie=Q[Q.length-1];return ie&&ie.role==="assistant"&&ie.isStreaming?Q.map((ge,Ke)=>Ke===Q.length-1?{...ge,content:ge.content||u.chat?.aborted||"任务已中断",isStreaming:!1,success:!1}:ge):Q}),dv(async()=>{const{abortLayeredAgentChat:Q}=await import("./index-UYYauTly.js").then(ie=>ie.ad);return{abortLayeredAgentChat:Q}},__vite__mapDeps([0,1])).then(({abortLayeredAgentChat:Q})=>{Q(s).catch(ie=>console.error("Backend abort failed:",ie))}),$e(u.chat?.aborted||"任务已中断",2e3,"success")}catch(Q){console.error("Failed to abort chat:",Q),$e(u.chat?.abortFailed||"中断失败",2e3,"error")}finally{h(!1),y(!1)}}},[u,s]),xt=v.useCallback(async()=>{M.current&&(M.current.abort(),M.current=null),p([]),N(null),R.current&&(R.current.close(),R.current=null);try{await fetch("/api/layered-agent/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:s})})}catch(Q){console.warn("Failed to reset backend session:",Q)}},[s]),bt=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key==="Enter"&&(Q.preventDefault(),Ce())};return o.jsxs("div",{className:"flex-1 flex gap-4 p-4 items-stretch justify-center min-h-0",children:[o.jsxs(er,{className:"flex-1 flex flex-col min-h-0 max-w-2xl overflow-hidden",children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-purple-500/10",children:o.jsx(ua,{className:"h-5 w-5 text-purple-500"})}),o.jsxs("div",{children:[o.jsx("h2",{className:"font-bold text-slate-900 dark:text-slate-100",children:u.chatkit?.title||"AI Agent"}),o.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:[r," • ",u.chatkit?.layeredAgent||"分层代理模式"]})]})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Cn,{variant:"secondary",className:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300",children:u.chatkit?.layeredAgent||"分层代理模式"}),o.jsxs(bi,{open:Ge,onOpenChange:Te,children:[o.jsx(yi,{asChild:!0,children:o.jsx(ve,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300",title:u.history?.title||"History",children:o.jsx(xi,{className:"h-4 w-4"})})}),o.jsxs(wi,{className:"w-96 p-0",align:"end",sideOffset:8,children:[o.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[o.jsx("h3",{className:"font-semibold text-sm text-slate-900 dark:text-slate-100",children:u.history?.title||"History"}),at.length>0&&o.jsx(ve,{variant:"ghost",size:"sm",onClick:ne,className:"h-7 text-xs",children:u.history?.clearAll||"Clear All"})]}),o.jsx(ds,{className:"h-[400px]",children:o.jsx("div",{className:"p-4 space-y-2",children:at.length>0?at.map(Q=>o.jsx(If,{item:Q,onSelect:gt,onDelete:se},Q.id)):o.jsxs("div",{className:"text-center py-8",children:[o.jsx(xi,{className:"h-12 w-12 text-slate-300 dark:text-slate-700 mx-auto mb-3"}),o.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:u.history?.noHistory||"No history yet"}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1",children:u.history?.noHistoryDescription||"Your completed tasks will appear here"})]})})})]})]}),o.jsx(ve,{variant:"ghost",size:"icon",onClick:xt,className:"h-8 w-8 rounded-full",title:"重置对话",children:o.jsx(id,{className:"h-4 w-4"})})]})]}),S&&o.jsxs("div",{className:"mx-4 mt-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl text-sm text-red-600 dark:text-red-400 flex items-center gap-2",children:[o.jsx(Nn,{className:"w-4 h-4 flex-shrink-0"}),S]}),o.jsx(ds,{className:"flex-1 min-h-0",children:o.jsxs("div",{className:"p-4 space-y-4",children:[l.length===0?o.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center py-12",children:[o.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-purple-100 dark:bg-purple-900/30 mb-4",children:o.jsx(ua,{className:"h-8 w-8 text-purple-500"})}),o.jsx("p",{className:"font-medium text-slate-900 dark:text-slate-100",children:u.chatkit?.title||"分层代理模式"}),o.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400 max-w-xs",children:u.chatkit?.layeredAgentDesc||"决策模型负责规划任务,视觉模型负责执行。你可以看到每一步的执行过程。"})]}):l.map(Q=>o.jsx("div",{className:"space-y-2",children:Q.role==="user"?o.jsx("div",{className:"flex justify-end",children:o.jsxs("div",{className:"max-w-[80%]",children:[o.jsx("div",{className:"bg-purple-600 text-white px-4 py-2 rounded-2xl rounded-br-sm",children:o.jsx("p",{className:"whitespace-pre-wrap",children:Q.content})}),o.jsx("p",{className:"text-xs text-slate-400 mt-1 text-right",children:Q.timestamp.toLocaleTimeString()})]})}):o.jsxs("div",{className:"space-y-3",children:[Q.steps&&Q.steps.length>0&&o.jsx("div",{className:"space-y-2",children:Q.steps.map((ie,ge)=>o.jsxs("div",{className:"bg-slate-50 dark:bg-slate-800/50 rounded-xl border border-slate-200 dark:border-slate-700 overflow-hidden",children:[o.jsxs("button",{onClick:()=>ce(Q.id,ie.id),className:"w-full flex items-center justify-between p-3 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("div",{className:`flex h-6 w-6 items-center justify-center rounded-full text-xs font-medium ${ie.type==="tool_call"?"bg-blue-100 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400":"bg-green-100 text-green-600 dark:bg-green-900/30 dark:text-green-400"}`,children:ie.type==="tool_call"?o.jsx(l1,{className:"w-3 h-3"}):o.jsx(Gu,{className:"w-3 h-3"})}),o.jsxs("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-300",children:["Step ",ge+1,": ",ie.content]})]}),ie.isExpanded?o.jsx(la,{className:"w-4 h-4 text-slate-400"}):o.jsx(aa,{className:"w-4 h-4 text-slate-400"})]}),ie.isExpanded&&o.jsxs("div",{className:"px-3 pb-3 space-y-2",children:[ie.type==="tool_call"&&ie.toolArgs&&o.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-3 text-sm",children:[o.jsx("p",{className:"text-xs text-slate-500 mb-1 font-medium",children:ie.toolName==="chat"?"发送给 Phone Agent 的指令:":"工具参数:"}),ie.toolName==="chat"?o.jsx("p",{className:"text-slate-700 dark:text-slate-300 whitespace-pre-wrap",children:ie.toolArgs.message||JSON.stringify(ie.toolArgs,null,2)}):o.jsx("pre",{className:"text-xs text-slate-600 dark:text-slate-400 overflow-x-auto",children:JSON.stringify(ie.toolArgs,null,2)})]}),ie.type==="tool_result"&&ie.toolResult&&o.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-3 text-sm",children:[o.jsx("p",{className:"text-xs text-slate-500 mb-1 font-medium",children:"执行结果:"}),o.jsx("pre",{className:"text-xs text-slate-600 dark:text-slate-400 overflow-x-auto whitespace-pre-wrap",children:typeof ie.toolResult=="string"?ie.toolResult:JSON.stringify(ie.toolResult,null,2)})]})]})]},ie.id))}),Q.content&&o.jsx("div",{className:"flex justify-start",children:o.jsx("div",{className:`max-w-[85%] rounded-2xl rounded-tl-sm px-4 py-3 ${Q.success===!1?"bg-red-100 dark:bg-red-900/20 text-red-600 dark:text-red-400":"bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300"}`,children:o.jsxs("div",{className:"flex items-start gap-2",children:[Q.success!==void 0&&o.jsx(Hn,{className:`w-5 h-5 flex-shrink-0 mt-0.5 ${Q.success?"text-green-500":"text-red-500"}`}),o.jsx("p",{className:"whitespace-pre-wrap",children:Q.content})]})})}),Q.isStreaming&&!Q.content&&o.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[o.jsx(hn,{className:"w-4 h-4 animate-spin"}),"正在思考和执行..."]})]})},Q.id)),o.jsx("div",{ref:j})]})}),o.jsx("div",{className:"p-4 border-t border-slate-200 dark:border-slate-800",children:o.jsxs("div",{className:"flex items-end gap-3",children:[o.jsx(td,{value:b,onChange:Q=>f(Q.target.value),onKeyDown:bt,placeholder:"描述你想要完成的任务... (Cmd+Enter 发送)",disabled:g,className:"flex-1 min-h-[40px] max-h-[120px] resize-none",rows:1}),o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsxs(bi,{open:Fe,onOpenChange:Ie,children:[o.jsx(yi,{asChild:!0,children:o.jsx(ve,{variant:"outline",size:"icon",className:"h-10 w-10 flex-shrink-0",children:o.jsx(Xu,{className:"w-4 h-4"})})}),o.jsx(wi,{align:"start",className:"w-72 p-3",children:o.jsxs("div",{className:"space-y-2",children:[o.jsx("h4",{className:"font-medium text-sm",children:u.workflows?.selectWorkflow||"Select Workflow"}),Se.length===0?o.jsxs("div",{className:"text-sm text-slate-500 dark:text-slate-400 space-y-1",children:[o.jsx("p",{children:u.workflows?.empty||"No workflows yet"}),o.jsxs("p",{children:["前往"," ",o.jsx("a",{href:"/workflows",className:"text-primary underline",children:"工作流"})," ","页面创建。"]})]}):o.jsx(ds,{className:"h-64",children:o.jsx("div",{className:"space-y-1",children:Se.map(Q=>o.jsxs("button",{onClick:()=>Xe(Q),className:"w-full text-left p-2 rounded hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:[o.jsx("div",{className:"font-medium text-sm",children:Q.name}),o.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400 line-clamp-2",children:Q.text})]},Q.uuid))})})]})})]})}),o.jsx(zn,{side:"top",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:u.devicePanel?.tooltips?.workflowButton||"Quick Workflow"}),o.jsx("p",{className:"text-xs opacity-80",children:u.devicePanel?.tooltips?.workflowButtonDesc||"Select a workflow to quickly fill in the task"})]})})]}),g&&o.jsx(ve,{onClick:we,disabled:_,size:"icon",variant:"destructive",className:"h-10 w-10 rounded-full flex-shrink-0",title:u.chat?.abortChat||"中断任务",children:_?o.jsx(hn,{className:"h-4 w-4 animate-spin"}):o.jsx(ld,{className:"h-4 w-4"})}),!g&&o.jsx(ve,{onClick:Ce,disabled:!b.trim(),size:"icon",className:"h-10 w-10 rounded-full flex-shrink-0 bg-purple-600 hover:bg-purple-700",children:o.jsx(od,{className:"h-4 w-4"})})]})})]}),o.jsxs(er,{className:"w-[320px] flex-shrink-0 relative min-h-0 overflow-hidden bg-background",onMouseEnter:mt,onMouseLeave:tt,children:[o.jsx("div",{className:`absolute top-4 right-4 z-10 transition-opacity duration-200 ${J?"opacity-100":"opacity-0 pointer-events-none"}`,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("div",{className:`flex items-center gap-1 bg-popover/90 backdrop-blur rounded-xl p-1 shadow-lg border border-border transition-all duration-300 ${O?"opacity-100 translate-x-0":"opacity-0 translate-x-4 pointer-events-none"}`,children:[o.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>le("auto"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${X==="auto"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:u.devicePanel?.auto||"Auto"}),o.jsxs(ve,{variant:"ghost",size:"sm",onClick:()=>le("video"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${X==="video"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[o.jsx(ud,{className:"w-3 h-3 mr-1"}),u.devicePanel?.video||"Video"]}),o.jsxs(ve,{variant:"ghost",size:"sm",onClick:()=>le("screenshot"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${X==="screenshot"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[o.jsx(_i,{className:"w-3 h-3 mr-1"}),u.devicePanel?.image||"Image"]})]}),o.jsx(ve,{variant:"ghost",size:"icon",onClick:At,className:"h-8 w-8 rounded-full bg-popover/90 backdrop-blur border border-border shadow-lg hover:bg-accent",title:O?"Hide controls":"Show controls",children:O?o.jsx(ka,{className:"w-4 h-4"}):o.jsx(Ca,{className:"w-4 h-4"})})]})}),o.jsx("div",{className:"absolute bottom-4 left-4 z-10",children:o.jsxs(Cn,{variant:"secondary",className:"bg-white/90 text-slate-700 border border-slate-200 dark:bg-slate-900/90 dark:text-slate-300 dark:border-slate-700",children:[X==="auto"&&(u.devicePanel?.auto||"Auto"),X==="video"&&o.jsxs(o.Fragment,{children:[o.jsx(sd,{className:"w-3 h-3 mr-1"}),u.devicePanel?.video||"Video"]}),X==="screenshot"&&o.jsxs(o.Fragment,{children:[o.jsx(_i,{className:"w-3 h-3 mr-1"}),u.devicePanel?.imageRefresh||"Screenshot"]})]})}),I&&o.jsxs("div",{className:"absolute bottom-4 right-4 z-20 flex items-center gap-2 px-3 py-2 bg-[#1d9bf0] text-white text-sm rounded-xl shadow-lg",children:[me==="error"&&o.jsx(Nn,{className:"w-4 h-4"}),me==="tap"&&o.jsx(rd,{className:"w-4 h-4"}),me==="swipe"&&o.jsx(nd,{className:"w-4 h-4"}),me==="success"&&o.jsx(Hn,{className:"w-4 h-4"}),o.jsx("span",{children:I})]}),X==="video"||X==="auto"&&F&&!G?o.jsx(of,{deviceId:s,className:"w-full h-full",enableControl:!0,onFallback:ee,onTapSuccess:()=>$e(u.devicePanel?.tapped||"Tapped",2e3,"tap"),onTapError:Q=>$e((u.devicePanel?.tapError||"Tap error: {error}").replace("{error}",Q),3e3,"error"),onSwipeSuccess:()=>$e(u.devicePanel?.swiped||"Swiped",2e3,"swipe"),onSwipeError:Q=>$e((u.devicePanel?.swipeError||"Swipe error: {error}").replace("{error}",Q),3e3,"error"),onStreamReady:L,fallbackTimeout:1e5}):o.jsx("div",{className:"w-full h-full flex items-center justify-center bg-muted/30 min-h-0",children:V&&V.success?o.jsxs("div",{className:"relative w-full h-full flex items-center justify-center min-h-0",children:[o.jsx("img",{src:`data:image/png;base64,${V.image}`,alt:"Device Screenshot",className:"max-w-full max-h-full object-contain",style:{width:V.width>V.height?"100%":"auto",height:V.width>V.height?"auto":"100%"}}),V.is_sensitive&&o.jsx("div",{className:"absolute top-12 right-2 px-2 py-1 bg-yellow-500 text-white text-xs rounded-lg",children:u.devicePanel?.sensitiveContent||"Sensitive Content"})]}):V?.error?o.jsxs("div",{className:"text-center text-destructive",children:[o.jsx(Nn,{className:"w-8 h-8 mx-auto mb-2"}),o.jsx("p",{className:"font-medium",children:u.devicePanel?.screenshotFailed||"Screenshot Failed"}),o.jsx("p",{className:"text-xs mt-1 opacity-60",children:V.error})]}):o.jsxs("div",{className:"text-center text-muted-foreground",children:[o.jsx(hn,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),o.jsx("p",{className:"text-sm",children:u.devicePanel?.loading||"Loading..."})]})})]})]})}function lw({message:s,type:n="info",onClose:r,duration:a=3e3}){v.useEffect(()=>{const p=setTimeout(()=>{r()},a);return()=>clearTimeout(p)},[a,r]);const u={success:"bg-green-500",error:"bg-red-500",info:"bg-blue-500",warning:"bg-amber-500"},l={success:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M5 13l4 4L19 7"})}),error:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})}),info:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),warning:o.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})};return o.jsx("div",{className:"fixed top-4 left-1/2 transform -translate-x-1/2 z-50 animate-fade-in-down",children:o.jsxs("div",{className:`${u[n]} text-white px-4 py-3 rounded-lg shadow-lg flex items-center gap-3 min-w-[300px]`,children:[l[n],o.jsx("span",{className:"font-medium",children:s}),o.jsx("button",{onClick:r,className:"ml-auto hover:bg-white/20 rounded-full p-1 transition-colors",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]})})}const is=[{name:"bigmodel",config:{base_url:"https://open.bigmodel.cn/api/paas/v4",model_name:"autoglm-phone"},apiKeyUrl:"https://bigmodel.cn/usercenter/proj-mgmt/apikeys"},{name:"modelscope",config:{base_url:"https://api-inference.modelscope.cn/v1",model_name:"ZhipuAI/AutoGLM-Phone-9B"},apiKeyUrl:"https://www.modelscope.cn/my/myaccesstoken"},{name:"custom",config:{base_url:"",model_name:"autoglm-phone-9b"}}],os=[{name:"bigmodel",config:{base_url:"https://open.bigmodel.cn/api/paas/v4",model_name:"glm-4.7"},apiKeyUrl:"https://bigmodel.cn/usercenter/proj-mgmt/apikeys"},{name:"modelscope",config:{base_url:"https://api-inference.modelscope.cn/v1",model_name:"ZhipuAI/GLM-4.7"},apiKeyUrl:"https://www.modelscope.cn/my/myaccesstoken"},{name:"custom",config:{base_url:"",model_name:""}}],cw=[{name:"glm",displayName:"GLM Agent",description:"基于 GLM 模型优化,成熟稳定,适合大多数任务",icon:Ov,defaultConfig:{}},{name:"mai",displayName:"MAI Agent",description:"阿里通义团队开发,支持多张历史截图上下文",icon:gi,defaultConfig:{history_n:3}}];function mw(){const s=Dr(),n=fv.useSearch(),r=hv(),[a,u]=v.useState([]),[l,p]=v.useState(""),[b,f]=v.useState("vision"),[g,h]=v.useState({}),[_,y]=v.useState(n.mode||"classic"),[S,N]=v.useState(!1),[j,R]=v.useState({message:"",type:"info",visible:!1}),M=(T,O="info")=>{R({message:T,type:O,visible:!0})},[F,A]=v.useState(null),[G,q]=v.useState(!1),[X,K]=v.useState(!1),[V,U]=v.useState(!1),[I,D]=v.useState({base_url:is[0].config.base_url,model_name:is[0].config.model_name,api_key:"",dual_model_enabled:!1,decision_base_url:os[0].config.base_url,decision_model_name:os[0].config.model_name,decision_api_key:"",agent_type:"glm",agent_config_params:{},default_max_steps:100});v.useEffect(()=>{(async()=>{try{const O=await mv();A({base_url:O.base_url,model_name:O.model_name,api_key:O.api_key||void 0,dual_model_enabled:O.dual_model_enabled||!1,decision_base_url:O.decision_base_url||void 0,decision_model_name:O.decision_model_name||void 0,decision_api_key:O.decision_api_key||void 0,agent_type:O.agent_type||"glm",agent_config_params:O.agent_config_params||void 0,default_max_steps:O.default_max_steps||100});const re=!O.base_url;D({base_url:re?is[0].config.base_url:O.base_url,model_name:re?is[0].config.model_name:O.model_name,api_key:O.api_key||"",dual_model_enabled:O.dual_model_enabled||!1,decision_base_url:O.decision_base_url||os[0].config.base_url,decision_model_name:O.decision_model_name||os[0].config.model_name,decision_api_key:O.decision_api_key||"",agent_type:O.agent_type||"glm",agent_config_params:O.agent_config_params||{},default_max_steps:O.default_max_steps||100}),re&&q(!0)}catch(O){console.error("Failed to load config:",O),q(!0)}})()},[]);const me=v.useCallback(async()=>{try{const O=(await pv()).devices.filter(Z=>Z.state!=="disconnected"),re=new Map,de=new Map;for(const Z of O)if(Z.serial){const Se=de.get(Z.serial)||[];Se.push(Z),de.set(Z.serial,Se)}else re.set(Z.id,Z);Array.from(de.values()).forEach(Z=>{const je=Z.find(Fe=>Fe.connection_type==="remote")||Z[0];re.set(je.id,je)});const ue=Array.from(re.values());if(u(ue),ue.length>0&&!S){const Z=n.serial;if(Z){const Se=ue.find(je=>je.serial===Z);p(Se?Se.id:ue[0].id)}else l||p(ue[0].id);N(!0)}l&&!ue.find(Z=>Z.id===l)&&p(ue[0]?.id||"")}catch(T){console.error("Failed to load devices:",T)}},[l,S,n.serial]);v.useEffect(()=>{const T=setTimeout(()=>{me()},0),O=setInterval(me,3e3);return()=>{clearTimeout(T),clearInterval(O)}},[me]),v.useEffect(()=>{const O=a.find(de=>de.id===l)?.serial;if(!S)return;(O!==n.serial||_!==n.mode)&&r({to:"/chat",search:{serial:O,mode:_},replace:!0})},[l,_,a,S,r,n.serial,n.mode]);const ye=async()=>{if(!I.base_url){M(s.chat.baseUrlRequired,"error");return}try{await gv({base_url:I.base_url,model_name:I.model_name||"autoglm-phone-9b",api_key:I.api_key||void 0,dual_model_enabled:I.dual_model_enabled,decision_base_url:I.decision_base_url||void 0,decision_model_name:I.decision_model_name||void 0,decision_api_key:I.decision_api_key||void 0,agent_type:I.agent_type,agent_config_params:Object.keys(I.agent_config_params).length>0?I.agent_config_params:void 0,default_max_steps:I.default_max_steps}),A({base_url:I.base_url,model_name:I.model_name,api_key:I.api_key||void 0,dual_model_enabled:I.dual_model_enabled,decision_base_url:I.decision_base_url||void 0,decision_model_name:I.decision_model_name||void 0,decision_api_key:I.decision_api_key||void 0,agent_type:I.agent_type,agent_config_params:Object.keys(I.agent_config_params).length>0?I.agent_config_params:void 0,default_max_steps:I.default_max_steps}),q(!1),M(s.toasts.configSaved,"success")}catch(T){console.error("Failed to save config:",T),M(`Failed to save: ${mi(T)}`,"error")}},$=async T=>{try{const O=await _v({device_id:T});O.success&&O.device_id?(p(O.device_id),M(s.toasts.wifiConnected,"success")):O.success||M(O.message||O.error||s.toasts.connectionFailed,"error")}catch(O){M(s.toasts.wifiConnectionError,"error"),console.error("Connect WiFi error:",O)}},J=async T=>{try{const O=await xv(T);O.success?M(s.toasts.wifiDisconnected,"success"):M(O.message||O.error||s.toasts.disconnectFailed,"error")}catch(O){M(s.toasts.wifiDisconnectError,"error"),console.error("Disconnect WiFi error:",O)}};return o.jsxs("div",{className:"h-full flex relative min-h-0",children:[j.visible&&o.jsx(lw,{message:j.message,type:j.type,onClose:()=>R(T=>({...T,visible:!1}))}),o.jsx(Vu,{open:G,onOpenChange:q,children:o.jsxs(Ku,{className:"sm:max-w-md h-[75vh] flex flex-col",children:[o.jsxs(Qu,{className:"flex-shrink-0",children:[o.jsxs(Ju,{className:"flex items-center gap-2",children:[o.jsx(ad,{className:"w-5 h-5 text-[#1d9bf0]"}),s.chat.configuration]}),o.jsx(Zu,{children:s.chat.configureApi})]}),o.jsxs("div",{className:"flex gap-1 p-1 bg-slate-100 dark:bg-slate-800 rounded-lg",children:[o.jsxs("button",{type:"button",onClick:()=>f("vision"),className:`flex-1 flex items-center justify-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all ${b==="vision"?"bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-300"}`,children:[o.jsx(us,{className:"w-4 h-4"}),s.chat.visionModel||"视觉模型"]}),o.jsxs("button",{type:"button",onClick:()=>f("decision"),className:`flex-1 flex items-center justify-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all ${b==="decision"?"bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-300"}`,children:[o.jsx(gi,{className:"w-4 h-4"}),s.chat.decisionModel||"决策模型"]})]}),o.jsx("div",{className:"space-y-4 pt-3 overflow-y-auto flex-1 min-h-0",children:b==="vision"?o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{className:"text-sm font-medium",children:s.chat.selectPreset}),o.jsx("div",{className:"grid grid-cols-1 gap-2",children:is.map(T=>o.jsxs("div",{className:"relative",children:[o.jsxs("button",{type:"button",onClick:()=>D(O=>({...O,base_url:T.config.base_url,model_name:T.config.model_name})),className:`w-full text-left p-3 rounded-lg border transition-all ${I.base_url===T.config.base_url&&(T.name!=="custom"||T.name==="custom"&&I.base_url==="")?"border-[#1d9bf0] bg-[#1d9bf0]/5":"border-slate-200 dark:border-slate-700 hover:border-[#1d9bf0]/50 hover:bg-slate-50 dark:hover:bg-slate-800/50"}`,children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(gu,{className:`w-4 h-4 ${I.base_url===T.config.base_url&&(T.name!=="custom"||T.name==="custom"&&I.base_url==="")?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),o.jsx("span",{className:"font-medium text-sm text-slate-900 dark:text-slate-100",children:s.presetConfigs[T.name].name})]}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1 ml-6",children:s.presetConfigs[T.name].description})]}),"apiKeyUrl"in T&&o.jsx("a",{href:T.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",onClick:O=>O.stopPropagation(),className:"absolute top-3 right-3 p-1.5 rounded-md hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors group",title:s.chat.getApiKey||"获取 API Key",children:o.jsx(pu,{className:"w-3.5 h-3.5 text-slate-400 group-hover:text-[#1d9bf0] transition-colors"})})]},T.name))})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs(Nt,{htmlFor:"base_url",children:[s.chat.baseUrl," *"]}),o.jsx($t,{id:"base_url",value:I.base_url,onChange:T=>D({...I,base_url:T.target.value}),placeholder:"http://localhost:8080/v1"}),!I.base_url&&o.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[o.jsx(Nn,{className:"w-3 h-3"}),s.chat.baseUrlRequired]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"api_key",children:s.chat.apiKey}),o.jsxs("div",{className:"relative",children:[o.jsx($t,{id:"api_key",type:X?"text":"password",value:I.api_key,onChange:T=>D({...I,api_key:T.target.value}),placeholder:"Leave empty if not required",className:"pr-10"}),o.jsx(ve,{type:"button",variant:"ghost",size:"icon",onClick:()=>K(!X),className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",children:X?o.jsx(mu,{className:"w-4 h-4 text-slate-400"}):o.jsx(us,{className:"w-4 h-4 text-slate-400"})})]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"model_name",children:s.chat.modelName}),o.jsx($t,{id:"model_name",value:I.model_name,onChange:T=>D({...I,model_name:T.target.value}),placeholder:"autoglm-phone-9b"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{className:"text-sm font-medium",children:s.chat.agentType||"Agent 类型"}),o.jsx("div",{className:"grid grid-cols-2 gap-2",children:cw.map(T=>o.jsxs("button",{type:"button",onClick:()=>D(O=>({...O,agent_type:T.name,agent_config_params:T.defaultConfig})),className:`text-left p-3 rounded-lg border transition-all ${I.agent_type===T.name?"border-[#1d9bf0] bg-[#1d9bf0]/5":"border-slate-200 dark:border-slate-700 hover:border-[#1d9bf0]/50 hover:bg-slate-50 dark:hover:bg-slate-800/50"}`,children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(T.icon,{className:`w-4 h-4 ${I.agent_type===T.name?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),o.jsx("span",{className:`font-medium text-sm ${I.agent_type===T.name?"text-[#1d9bf0]":"text-slate-900 dark:text-slate-100"}`,children:T.displayName})]}),o.jsx("p",{className:`text-xs mt-1 ml-6 ${I.agent_type===T.name?"text-[#1d9bf0]/70":"text-slate-500 dark:text-slate-400"}`,children:T.description})]},T.name))})]}),I.agent_type==="mai"&&o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"history_n",children:s.chat.history_n||"历史记录数量"}),o.jsx($t,{id:"history_n",type:"number",min:1,max:10,value:I.agent_config_params?.history_n||3,onChange:T=>{const O=parseInt(T.target.value)||3;D(re=>({...re,agent_config_params:{...re.agent_config_params,history_n:O}}))},className:"w-full"}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s.chat.history_n_hint||"包含的历史截图数量(1-10)"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"default_max_steps",children:s.chat.maxSteps||"最大执行步数"}),o.jsx($t,{id:"default_max_steps",type:"number",min:1,max:1e3,value:I.default_max_steps,onChange:T=>{const O=parseInt(T.target.value)||100;D(re=>({...re,default_max_steps:Math.min(1e3,Math.max(1,O))}))},className:"w-full"}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s.chat.maxStepsHint||"单次任务最大执行步数(1-1000)"})]})]}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{className:"text-sm font-medium",children:s.chat.selectPreset}),o.jsx("div",{className:"grid grid-cols-1 gap-2",children:os.map(T=>o.jsxs("div",{className:"relative",children:[o.jsxs("button",{type:"button",onClick:()=>D(O=>({...O,decision_base_url:T.config.base_url,decision_model_name:T.config.model_name})),className:`w-full text-left p-3 rounded-lg border transition-all ${I.decision_base_url===T.config.base_url&&(T.name!=="custom"||T.name==="custom"&&I.decision_base_url==="")?"border-[#1d9bf0] bg-[#1d9bf0]/5":"border-slate-200 dark:border-slate-700 hover:border-[#1d9bf0]/50 hover:bg-slate-50 dark:hover:bg-slate-800/50"}`,children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(gu,{className:`w-4 h-4 ${I.decision_base_url===T.config.base_url&&(T.name!=="custom"||T.name==="custom"&&I.decision_base_url==="")?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),o.jsx("span",{className:"font-medium text-sm text-slate-900 dark:text-slate-100",children:s.presetConfigs[T.name].name})]}),o.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1 ml-6",children:s.presetConfigs[T.name].description})]}),"apiKeyUrl"in T&&o.jsx("a",{href:T.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",onClick:O=>O.stopPropagation(),className:"absolute top-3 right-3 p-1.5 rounded-md hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors group",title:s.chat.getApiKey||"获取 API Key",children:o.jsx(pu,{className:"w-3.5 h-3.5 text-slate-400 group-hover:text-[#1d9bf0] transition-colors"})})]},T.name))})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs(Nt,{htmlFor:"decision_base_url",children:[s.chat.baseUrl," *"]}),o.jsx($t,{id:"decision_base_url",value:I.decision_base_url,onChange:T=>D({...I,decision_base_url:T.target.value}),placeholder:"http://localhost:8080/v1"})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"decision_api_key",children:s.chat.apiKey}),o.jsxs("div",{className:"relative",children:[o.jsx($t,{id:"decision_api_key",type:V?"text":"password",value:I.decision_api_key,onChange:T=>D({...I,decision_api_key:T.target.value}),placeholder:"Leave empty if not required",className:"pr-10"}),o.jsx(ve,{type:"button",variant:"ghost",size:"icon",onClick:()=>U(!V),className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",children:V?o.jsx(mu,{className:"w-4 h-4 text-slate-400"}):o.jsx(us,{className:"w-4 h-4 text-slate-400"})})]})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(Nt,{htmlFor:"decision_model_name",children:s.chat.modelName}),o.jsx($t,{id:"decision_model_name",value:I.decision_model_name,onChange:T=>D({...I,decision_model_name:T.target.value}),placeholder:"glm-4.7"})]})]})}),o.jsxs(ed,{className:"sm:justify-between gap-2 flex-shrink-0",children:[o.jsx(ve,{variant:"outline",onClick:()=>{q(!1),F&&D({base_url:F.base_url,model_name:F.model_name,api_key:F.api_key||"",dual_model_enabled:F.dual_model_enabled||!1,decision_base_url:F.decision_base_url||"",decision_model_name:F.decision_model_name||"",decision_api_key:F.decision_api_key||"",agent_type:F.agent_type||"glm",agent_config_params:F.agent_config_params||{},default_max_steps:F.default_max_steps||100})},children:s.chat.cancel}),o.jsxs(ve,{onClick:ye,variant:"twitter",children:[o.jsx(Hn,{className:"w-4 h-4 mr-2"}),s.chat.saveConfig]})]})]})}),o.jsx(X1,{devices:a,currentDeviceId:l,onSelectDevice:p,onOpenConfig:()=>q(!0),onConnectWifi:$,onDisconnectWifi:J}),o.jsxs("div",{className:"flex-1 flex flex-col min-h-0 relative",children:[o.jsx("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 z-20",children:o.jsxs("div",{className:"flex items-center gap-0.5 bg-white/95 dark:bg-slate-800/95 backdrop-blur-sm rounded-full p-1 shadow-lg border border-slate-200 dark:border-slate-700",children:[o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsxs("button",{onClick:()=>y("classic"),className:`flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-medium transition-all ${_==="classic"?"bg-slate-900 dark:bg-white text-white dark:text-slate-900 shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-700"}`,children:[o.jsx(as,{className:"w-4 h-4"}),s.chatkit?.classicMode||"经典模式"]})}),o.jsx(zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:s.chatkit?.classicMode||"经典模式"}),o.jsx("p",{className:"text-xs opacity-80",children:s.chatkit?.classicModeDesc||"视觉模型直接执行任务"})]})})]}),o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsxs("button",{onClick:()=>{y("dual"),F?.decision_api_key||M(s.toasts.decisionModelNotConfigured,"warning")},className:`flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-medium transition-all ${_==="dual"?"bg-purple-600 text-white shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-700"}`,children:[o.jsx(gi,{className:"w-4 h-4"}),s.chatkit?.dualMode||"双模型协作"]})}),o.jsx(zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:s.chatkit?.dualMode||"双模型协作"}),o.jsx("p",{className:"text-xs opacity-80",children:s.chatkit?.dualModeDesc||"决策模型逐步指导,视觉模型执行,精细控制"})]})})]}),o.jsxs(Un,{children:[o.jsx(Wn,{asChild:!0,children:o.jsxs("button",{onClick:()=>{y("chatkit"),F?.decision_api_key||M(s.toasts.decisionModelNotConfigured,"warning")},className:`flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-medium transition-all ${_==="chatkit"?"bg-indigo-600 text-white shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-700"}`,children:[o.jsx(ua,{className:"w-4 h-4"}),s.chatkit?.layeredMode||"分层代理"]})}),o.jsx(zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"font-medium",children:s.chatkit?.layeredMode||"分层代理"}),o.jsx("p",{className:"text-xs opacity-80",children:s.chatkit?.layeredModeDesc||"规划层分解任务,执行层独立完成子任务"})]})})]})]})}),o.jsx("div",{className:"flex-1 flex items-stretch justify-center min-h-0 px-4 py-4 pt-16",children:a.length===0?o.jsx("div",{className:"flex-1 flex items-center justify-center bg-slate-50 dark:bg-slate-950",children:o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800 mx-auto mb-4",children:o.jsx("svg",{className:"w-10 h-10 text-slate-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),o.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-100 mb-2",children:s.chat.welcomeTitle}),o.jsx("p",{className:"text-slate-500 dark:text-slate-400",children:s.chat.connectDevice})]})}):a.map(T=>o.jsx("div",{className:`w-full max-w-7xl flex items-stretch justify-center min-h-0 ${T.id===l?"":"hidden"}`,children:_==="chatkit"?o.jsx(aw,{deviceId:T.id,deviceSerial:T.serial,deviceName:T.model,isVisible:T.id===l}):o.jsx(ow,{deviceId:T.id,deviceSerial:T.serial,deviceName:T.model,config:F,isVisible:T.id===l,isConfigured:!!F?.base_url,thinkingMode:g[T.serial]||"deep",onThinkingModeChange:O=>{h(re=>({...re,[T.serial]:O}))},dualModelEnabled:_==="dual"})},T.serial))})]})]})}export{mw as component};