autoglm-gui 1.3.1__py3-none-any.whl → 1.4.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.
@@ -0,0 +1,125 @@
1
+ import{c as Oe,j as a,u as Mr,r as v,e as Ht,B as _e,f as hs,R as We,g as yn,h as ra,i as ba,P as Zt,k as dt,m as ya,n as Kn,o as gr,p as nr,q as ii,s as U_,t as W_,v as z_,w as H_,x as G_,S as ns,y as lu,z as $_,A as wa,C as q_,D as cu,E as uu,F as X_,M as Wu,G as zu,H as Y_,I as Hu,J as V_,K as K_,L as Q_,N as J_,O as Z_,Q as ev,T as tv,U as nv,V as rv,W as sv,X as iv,Y as ov,Z as av,_ as Qn,$ as Jn,a0 as Zn,a1 as Gu,l as $u,a2 as lv,a3 as cv,a4 as uv,a5 as dv,a6 as fv,a7 as hv,a8 as pv}from"./index-DHF1NZh0.js";import{L as Jt,P as mv,D as qu,d as Xu,e as Yu,f as Vu,j as Ku,g as zt,I as hn,i as Qu,C as er,k as gv,R as xv,u as _v,F as vv,T as bv,h as Ju}from"./dialog-BfdcBs1x.js";const yv=[["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"}]],Zu=Oe("arrow-up-down",yv);const wv=[["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"}]],sa=Oe("brain",wv);const Ev=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],ia=Oe("chevron-down",Ev);const Sv=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Ea=Oe("chevron-left",Sv);const Nv=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Sa=Oe("chevron-right",Nv);const Cv=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],oa=Oe("chevron-up",Cv);const kv=[["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"}]],Cn=Oe("circle-alert",kv);const Tv=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Rv=Oe("circle-check-big",Tv);const Av=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],kn=Oe("circle-check",Av);const Pv=[["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"}]],hi=Oe("circle-x",Pv);const jv=[["path",{d:"M12 6v6l4 2",key:"mmk7yg"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Iv=Oe("clock",jv);const Dv=[["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"}]],du=Oe("external-link",Dv);const Mv=[["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"}]],fu=Oe("eye-off",Mv);const Lv=[["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"}]],ls=Oe("eye",Lv);const Ov=[["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"}]],ed=Oe("fingerprint-pattern",Ov);const Fv=[["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"}]],pi=Oe("history",Fv);const Bv=[["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"}]],mi=Oe("image",Bv);const Uv=[["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"}]],aa=Oe("layers",Uv);const Wv=[["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"}]],td=Oe("monitor-play",Wv);const zv=[["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"}]],Hv=Oe("plug",zv);const Gv=[["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"}]],$v=Oe("rocket",Gv);const qv=[["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"}]],nd=Oe("rotate-ccw",qv);const Xv=[["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"}]],rd=Oe("send",Xv);const Yv=[["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"}]],hu=Oe("server",Yv);const Vv=[["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"}]],sd=Oe("settings",Vv);const Kv=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],la=Oe("smartphone",Kv);const Qv=[["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"}]],is=Oe("sparkles",Qv);const Jv=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],id=Oe("square",Jv);const Zv=[["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"}]],od=Oe("target",Zv);const e1=[["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"}]],ad=Oe("video",e1);const t1=[["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"}]],pu=Oe("wifi-off",t1);const n1=[["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"}]],ca=Oe("wifi",n1);const r1=[["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"}]],s1=Oe("wrench",r1);const i1=[["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"}]],ua=Oe("zap",i1);function mu({isOpen:i,title:n,content:r,onConfirm:o,onCancel:u,confirmText:l="确认",cancelText:h="取消"}){return i?a.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:a.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:[a.jsxs("div",{className:"p-6",children:[a.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2",children:n}),a.jsx("p",{className:"text-gray-500 dark:text-gray-400 text-sm leading-relaxed whitespace-pre-wrap",children:r})]}),a.jsxs("div",{className:"bg-gray-50 dark:bg-gray-700/50 px-6 py-4 flex justify-end gap-3",children:[a.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:h}),a.jsx("button",{onClick:b=>{b.stopPropagation(),o()},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 o1({id:i,serial:n,model:r,status:o,connectionType:u,agent:l,isActive:h,onClick:b,onConnectWifi:f,onDisconnectWifi:g}){const p=Mr(),_=o==="device",y=u==="usb",S=u==="remote",[N,P]=v.useState(!1),[T,I]=v.useState(!1),[F,A]=v.useState(!1),$=r||p.deviceCard.unknownDevice,q=O=>{O.stopPropagation(),!(N||!f)&&I(!0)},X=O=>{O.stopPropagation(),!(N||!g)&&A(!0)},K=async()=>{I(!1),P(!0);try{f&&await f()}finally{P(!1)}},V=async()=>{A(!1),P(!0);try{g&&await g()}finally{P(!1)}};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{onClick:b,role:"button",tabIndex:0,onKeyDown:O=>{(O.key==="Enter"||O.key===" ")&&b()},className:`
2
+ group relative w-full text-left p-4 rounded-xl transition-all duration-200 cursor-pointer
3
+ border-2
4
+ ${h?"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"}
5
+ `,children:[h&&a.jsx("div",{className:"absolute left-0 top-2 bottom-2 w-1 bg-[#1d9bf0] rounded-r"}),a.jsxs("div",{className:"flex items-center gap-3 pl-2",children:[a.jsx("div",{className:`relative flex-shrink-0 ${_?"status-online":"status-offline"} w-3 h-3 rounded-full transition-all ${h?"scale-110":""}`}),a.jsxs("div",{className:"flex-1 min-w-0 flex flex-col justify-center gap-0.5",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(la,{className:`w-4 h-4 flex-shrink-0 ${h?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),a.jsx("span",{className:`font-semibold text-sm truncate ${h?"text-slate-900 dark:text-slate-100":"text-slate-700 dark:text-slate-300"}`,children:$})]}),a.jsx("span",{className:`text-xs font-mono truncate ${h?"text-slate-500 dark:text-slate-400":"text-slate-400 dark:text-slate-500"}`,children:r||i}),l&&a.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[l.state==="busy"&&a.jsxs(Ht,{variant:"secondary",className:"text-xs px-1.5 py-0 bg-[#1d9bf0]/10 text-[#1d9bf0] hover:bg-[#1d9bf0]/20",children:[a.jsx(Jt,{className:"w-2.5 h-2.5 animate-spin mr-1"}),p.deviceCard.agentBusy]}),l.state==="idle"&&a.jsxs(Ht,{variant:"secondary",className:"text-xs px-1.5 py-0 bg-green-50 text-green-700 dark:bg-green-900/20 dark:text-green-400",children:[a.jsx(kn,{className:"w-2.5 h-2.5 mr-1"}),p.deviceCard.agentIdle]}),l.state==="error"&&a.jsxs(Ht,{variant:"secondary",className:"text-xs px-1.5 py-0 bg-red-50 text-red-700 dark:bg-red-900/20 dark:text-red-400",children:[a.jsx(hi,{className:"w-2.5 h-2.5 mr-1"}),p.deviceCard.agentError]}),l.state==="initializing"&&a.jsxs(Ht,{variant:"secondary",className:"text-xs px-1.5 py-0 bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-400",children:[a.jsx(Iv,{className:"w-2.5 h-2.5 mr-1"}),p.deviceCard.agentInitializing]})]})]}),y&&a.jsx(Ht,{variant:"outline",className:"flex-shrink-0 text-xs border-slate-200 text-slate-600 dark:border-slate-700 dark:text-slate-400",children:"USB"}),S&&a.jsxs(Ht,{variant:"outline",className:"flex-shrink-0 text-xs border-slate-200 text-slate-600 dark:border-slate-700 dark:text-slate-400",children:[a.jsx(pu,{className:"w-2.5 h-2.5 mr-1"}),"Remote"]}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[f&&y&&a.jsx(_e,{variant:"ghost",size:"icon",onClick:q,disabled:N,className:"h-7 w-7 text-slate-400 hover:text-[#1d9bf0]",title:p.deviceCard.connectViaWifi,children:N?a.jsx(Jt,{className:"w-3.5 h-3.5 animate-spin"}):a.jsx(ca,{className:"w-3.5 h-3.5"})}),g&&S&&a.jsx(_e,{variant:"ghost",size:"icon",onClick:X,disabled:N,className:"h-7 w-7 text-slate-400 hover:text-orange-500",title:p.deviceCard.disconnectWifi,children:N?a.jsx(Jt,{className:"w-3.5 h-3.5 animate-spin"}):a.jsx(pu,{className:"w-3.5 h-3.5"})})]})]})]}),a.jsx(mu,{isOpen:T,title:p.deviceCard.connectWifiTitle,content:p.deviceCard.connectWifiContent,onConfirm:K,onCancel:()=>I(!1)}),a.jsx(mu,{isOpen:F,title:p.deviceCard.disconnectWifiTitle,content:p.deviceCard.disconnectWifiContent,onConfirm:V,onCancel:()=>A(!1)})]})}function a1(i){const n=i+"CollectionProvider",[r,o]=hs(n),[u,l]=r(n,{collectionRef:{current:null},itemMap:new Map}),h=P=>{const{scope:T,children:I}=P,F=We.useRef(null),A=We.useRef(new Map).current;return a.jsx(u,{scope:T,itemMap:A,collectionRef:F,children:I})};h.displayName=n;const b=i+"CollectionSlot",f=ra(b),g=We.forwardRef((P,T)=>{const{scope:I,children:F}=P,A=l(b,I),$=yn(T,A.collectionRef);return a.jsx(f,{ref:$,children:F})});g.displayName=b;const p=i+"CollectionItemSlot",_="data-radix-collection-item",y=ra(p),S=We.forwardRef((P,T)=>{const{scope:I,children:F,...A}=P,$=We.useRef(null),q=yn(T,$),X=l(p,I);return We.useEffect(()=>(X.itemMap.set($,{ref:$,...A}),()=>void X.itemMap.delete($))),a.jsx(y,{[_]:"",ref:q,children:F})});S.displayName=p;function N(P){const T=l(i+"CollectionConsumer",P);return We.useCallback(()=>{const F=T.collectionRef.current;if(!F)return[];const A=Array.from(F.querySelectorAll(`[${_}]`));return Array.from(T.itemMap.values()).sort((X,K)=>A.indexOf(X.ref.current)-A.indexOf(K.ref.current))},[T.collectionRef,T.itemMap])}return[{Provider:h,Slot:g,ItemSlot:S},N,o]}var l1=v.createContext(void 0);function Na(i){const n=v.useContext(l1);return i||n||"ltr"}var $o="rovingFocusGroup.onEntryFocus",c1={bubbles:!1,cancelable:!0},ps="RovingFocusGroup",[da,ld,u1]=a1(ps),[d1,cd]=hs(ps,[u1]),[f1,h1]=d1(ps),ud=v.forwardRef((i,n)=>a.jsx(da.Provider,{scope:i.__scopeRovingFocusGroup,children:a.jsx(da.Slot,{scope:i.__scopeRovingFocusGroup,children:a.jsx(p1,{...i,ref:n})})}));ud.displayName=ps;var p1=v.forwardRef((i,n)=>{const{__scopeRovingFocusGroup:r,orientation:o,loop:u=!1,dir:l,currentTabStopId:h,defaultCurrentTabStopId:b,onCurrentTabStopIdChange:f,onEntryFocus:g,preventScrollOnEntryFocus:p=!1,..._}=i,y=v.useRef(null),S=yn(n,y),N=Na(l),[P,T]=ya({prop:h,defaultProp:b??null,onChange:f,caller:ps}),[I,F]=v.useState(!1),A=Kn(g),$=ld(r),q=v.useRef(!1),[X,K]=v.useState(0);return v.useEffect(()=>{const V=y.current;if(V)return V.addEventListener($o,A),()=>V.removeEventListener($o,A)},[A]),a.jsx(f1,{scope:r,orientation:o,dir:N,loop:u,currentTabStopId:P,onItemFocus:v.useCallback(V=>T(V),[T]),onItemShiftTab:v.useCallback(()=>F(!0),[]),onFocusableItemAdd:v.useCallback(()=>K(V=>V+1),[]),onFocusableItemRemove:v.useCallback(()=>K(V=>V-1),[]),children:a.jsx(Zt.div,{tabIndex:I||X===0?-1:0,"data-orientation":o,..._,ref:S,style:{outline:"none",...i.style},onMouseDown:dt(i.onMouseDown,()=>{q.current=!0}),onFocus:dt(i.onFocus,V=>{const O=!q.current;if(V.target===V.currentTarget&&O&&!I){const B=new CustomEvent($o,c1);if(V.currentTarget.dispatchEvent(B),!B.defaultPrevented){const M=$().filter(R=>R.focusable),me=M.find(R=>R.active),ye=M.find(R=>R.id===P),J=[me,ye,...M].filter(Boolean).map(R=>R.ref.current);hd(J,p)}}q.current=!1}),onBlur:dt(i.onBlur,()=>F(!1))})})}),dd="RovingFocusGroupItem",fd=v.forwardRef((i,n)=>{const{__scopeRovingFocusGroup:r,focusable:o=!0,active:u=!1,tabStopId:l,children:h,...b}=i,f=ba(),g=l||f,p=h1(dd,r),_=p.currentTabStopId===g,y=ld(r),{onFocusableItemAdd:S,onFocusableItemRemove:N,currentTabStopId:P}=p;return v.useEffect(()=>{if(o)return S(),()=>N()},[o,S,N]),a.jsx(da.ItemSlot,{scope:r,id:g,focusable:o,active:u,children:a.jsx(Zt.span,{tabIndex:_?0:-1,"data-orientation":p.orientation,...b,ref:n,onMouseDown:dt(i.onMouseDown,T=>{o?p.onItemFocus(g):T.preventDefault()}),onFocus:dt(i.onFocus,()=>p.onItemFocus(g)),onKeyDown:dt(i.onKeyDown,T=>{if(T.key==="Tab"&&T.shiftKey){p.onItemShiftTab();return}if(T.target!==T.currentTarget)return;const I=x1(T,p.orientation,p.dir);if(I!==void 0){if(T.metaKey||T.ctrlKey||T.altKey||T.shiftKey)return;T.preventDefault();let A=y().filter($=>$.focusable).map($=>$.ref.current);if(I==="last")A.reverse();else if(I==="prev"||I==="next"){I==="prev"&&A.reverse();const $=A.indexOf(T.currentTarget);A=p.loop?_1(A,$+1):A.slice($+1)}setTimeout(()=>hd(A))}}),children:typeof h=="function"?h({isCurrentTabStop:_,hasTabStop:P!=null}):h})})});fd.displayName=dd;var m1={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function g1(i,n){return n!=="rtl"?i:i==="ArrowLeft"?"ArrowRight":i==="ArrowRight"?"ArrowLeft":i}function x1(i,n,r){const o=g1(i.key,r);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(o))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(o)))return m1[o]}function hd(i,n=!1){const r=document.activeElement;for(const o of i)if(o===r||(o.focus({preventScroll:n}),document.activeElement!==r))return}function _1(i,n){return i.map((r,o)=>i[(n+o)%i.length])}var v1=ud,b1=fd,wi="Tabs",[y1]=hs(wi,[cd]),pd=cd(),[w1,Ca]=y1(wi),md=v.forwardRef((i,n)=>{const{__scopeTabs:r,value:o,onValueChange:u,defaultValue:l,orientation:h="horizontal",dir:b,activationMode:f="automatic",...g}=i,p=Na(b),[_,y]=ya({prop:o,onChange:u,defaultProp:l??"",caller:wi});return a.jsx(w1,{scope:r,baseId:ba(),value:_,onValueChange:y,orientation:h,dir:p,activationMode:f,children:a.jsx(Zt.div,{dir:p,"data-orientation":h,...g,ref:n})})});md.displayName=wi;var gd="TabsList",xd=v.forwardRef((i,n)=>{const{__scopeTabs:r,loop:o=!0,...u}=i,l=Ca(gd,r),h=pd(r);return a.jsx(v1,{asChild:!0,...h,orientation:l.orientation,dir:l.dir,loop:o,children:a.jsx(Zt.div,{role:"tablist","aria-orientation":l.orientation,...u,ref:n})})});xd.displayName=gd;var _d="TabsTrigger",vd=v.forwardRef((i,n)=>{const{__scopeTabs:r,value:o,disabled:u=!1,...l}=i,h=Ca(_d,r),b=pd(r),f=wd(h.baseId,o),g=Ed(h.baseId,o),p=o===h.value;return a.jsx(b1,{asChild:!0,...b,focusable:!u,active:p,children:a.jsx(Zt.button,{type:"button",role:"tab","aria-selected":p,"aria-controls":g,"data-state":p?"active":"inactive","data-disabled":u?"":void 0,disabled:u,id:f,...l,ref:n,onMouseDown:dt(i.onMouseDown,_=>{!u&&_.button===0&&_.ctrlKey===!1?h.onValueChange(o):_.preventDefault()}),onKeyDown:dt(i.onKeyDown,_=>{[" ","Enter"].includes(_.key)&&h.onValueChange(o)}),onFocus:dt(i.onFocus,()=>{const _=h.activationMode!=="manual";!p&&!u&&_&&h.onValueChange(o)})})})});vd.displayName=_d;var bd="TabsContent",yd=v.forwardRef((i,n)=>{const{__scopeTabs:r,value:o,forceMount:u,children:l,...h}=i,b=Ca(bd,r),f=wd(b.baseId,o),g=Ed(b.baseId,o),p=o===b.value,_=v.useRef(p);return v.useEffect(()=>{const y=requestAnimationFrame(()=>_.current=!1);return()=>cancelAnimationFrame(y)},[]),a.jsx(gr,{present:u||p,children:({present:y})=>a.jsx(Zt.div,{"data-state":p?"active":"inactive","data-orientation":b.orientation,role:"tabpanel","aria-labelledby":f,hidden:!y,id:g,tabIndex:0,...h,ref:n,style:{...i.style,animationDuration:_.current?"0s":void 0},children:y&&l})})});yd.displayName=bd;function wd(i,n){return`${i}-trigger-${n}`}function Ed(i,n){return`${i}-content-${n}`}var E1=md,S1=xd,N1=vd,C1=yd;function k1({className:i,...n}){return a.jsx(E1,{"data-slot":"tabs",className:nr("flex flex-col gap-2",i),...n})}function T1({className:i,...n}){return a.jsx(S1,{"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]",i),...n})}function gu({className:i,...n}){return a.jsx(N1,{"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",i),...n})}function xu({className:i,...n}){return a.jsx(C1,{"data-slot":"tabs-content",className:nr("flex-1 outline-none",i),...n})}var R1=Object.defineProperty,gi=Object.getOwnPropertySymbols,Sd=Object.prototype.hasOwnProperty,Nd=Object.prototype.propertyIsEnumerable,_u=(i,n,r)=>n in i?R1(i,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[n]=r,fa=(i,n)=>{for(var r in n||(n={}))Sd.call(n,r)&&_u(i,r,n[r]);if(gi)for(var r of gi(n))Nd.call(n,r)&&_u(i,r,n[r]);return i},ha=(i,n)=>{var r={};for(var o in i)Sd.call(i,o)&&n.indexOf(o)<0&&(r[o]=i[o]);if(i!=null&&gi)for(var o of gi(i))n.indexOf(o)<0&&Nd.call(i,o)&&(r[o]=i[o]);return r};var mr;(i=>{const n=class Ae{constructor(f,g,p,_){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(p);if(this.drawCodewords(S),_==-1){let N=1e9;for(let P=0;P<8;P++){this.applyMask(P),this.drawFormatBits(P);const T=this.getPenaltyScore();T<N&&(_=P,N=T),this.applyMask(P)}}u(0<=_&&_<=7),this.mask=_,this.applyMask(_),this.drawFormatBits(_),this.isFunction=[]}static encodeText(f,g){const p=i.QrSegment.makeSegments(f);return Ae.encodeSegments(p,g)}static encodeBinary(f,g){const p=i.QrSegment.makeBytes(f);return Ae.encodeSegments([p],g)}static encodeSegments(f,g,p=1,_=40,y=-1,S=!0){if(!(Ae.MIN_VERSION<=p&&p<=_&&_<=Ae.MAX_VERSION)||y<-1||y>7)throw new RangeError("Invalid value");let N,P;for(N=p;;N++){const A=Ae.getNumDataCodewords(N,g)*8,$=h.getTotalBits(f,N);if($<=A){P=$;break}if(N>=_)throw new RangeError("Data too long")}for(const A of[Ae.Ecc.MEDIUM,Ae.Ecc.QUARTILE,Ae.Ecc.HIGH])S&&P<=Ae.getNumDataCodewords(N,A)*8&&(g=A);let T=[];for(const A of f){r(A.mode.modeBits,4,T),r(A.numChars,A.mode.numCharCountBits(N),T);for(const $ of A.getData())T.push($)}u(T.length==P);const I=Ae.getNumDataCodewords(N,g)*8;u(T.length<=I),r(0,Math.min(4,I-T.length),T),r(0,(8-T.length%8)%8,T),u(T.length%8==0);for(let A=236;T.length<I;A^=253)r(A,8,T);let F=[];for(;F.length*8<T.length;)F.push(0);return T.forEach((A,$)=>F[$>>>3]|=A<<7-($&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 p=0;p<this.size;p++)this.setFunctionModule(6,p,p%2==0),this.setFunctionModule(p,6,p%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 p=0;p<g;p++)for(let _=0;_<g;_++)p==0&&_==0||p==0&&_==g-1||p==g-1&&_==0||this.drawAlignmentPattern(f[p],f[_]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(f){const g=this.errorCorrectionLevel.formatBits<<3|f;let p=g;for(let y=0;y<10;y++)p=p<<1^(p>>>9)*1335;const _=(g<<10|p)^21522;u(_>>>15==0);for(let y=0;y<=5;y++)this.setFunctionModule(8,y,o(_,y));this.setFunctionModule(8,7,o(_,6)),this.setFunctionModule(8,8,o(_,7)),this.setFunctionModule(7,8,o(_,8));for(let y=9;y<15;y++)this.setFunctionModule(14-y,8,o(_,y));for(let y=0;y<8;y++)this.setFunctionModule(this.size-1-y,8,o(_,y));for(let y=8;y<15;y++)this.setFunctionModule(8,this.size-15+y,o(_,y));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let f=this.version;for(let p=0;p<12;p++)f=f<<1^(f>>>11)*7973;const g=this.version<<12|f;u(g>>>18==0);for(let p=0;p<18;p++){const _=o(g,p),y=this.size-11+p%3,S=Math.floor(p/3);this.setFunctionModule(y,S,_),this.setFunctionModule(S,y,_)}}drawFinderPattern(f,g){for(let p=-4;p<=4;p++)for(let _=-4;_<=4;_++){const y=Math.max(Math.abs(_),Math.abs(p)),S=f+_,N=g+p;0<=S&&S<this.size&&0<=N&&N<this.size&&this.setFunctionModule(S,N,y!=2&&y!=4)}}drawAlignmentPattern(f,g){for(let p=-2;p<=2;p++)for(let _=-2;_<=2;_++)this.setFunctionModule(f+_,g+p,Math.max(Math.abs(_),Math.abs(p))!=1)}setFunctionModule(f,g,p){this.modules[g][f]=p,this.isFunction[g][f]=!0}addEccAndInterleave(f){const g=this.version,p=this.errorCorrectionLevel;if(f.length!=Ae.getNumDataCodewords(g,p))throw new RangeError("Invalid argument");const _=Ae.NUM_ERROR_CORRECTION_BLOCKS[p.ordinal][g],y=Ae.ECC_CODEWORDS_PER_BLOCK[p.ordinal][g],S=Math.floor(Ae.getNumRawDataModules(g)/8),N=_-S%_,P=Math.floor(S/_);let T=[];const I=Ae.reedSolomonComputeDivisor(y);for(let A=0,$=0;A<_;A++){let q=f.slice($,$+P-y+(A<N?0:1));$+=q.length;const X=Ae.reedSolomonComputeRemainder(q,I);A<N&&q.push(0),T.push(q.concat(X))}let F=[];for(let A=0;A<T[0].length;A++)T.forEach(($,q)=>{(A!=P-y||q>=N)&&F.push($[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 p=this.size-1;p>=1;p-=2){p==6&&(p=5);for(let _=0;_<this.size;_++)for(let y=0;y<2;y++){const S=p-y,P=(p+1&2)==0?this.size-1-_:_;!this.isFunction[P][S]&&g<f.length*8&&(this.modules[P][S]=o(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 p=0;p<this.size;p++){let _;switch(f){case 0:_=(p+g)%2==0;break;case 1:_=g%2==0;break;case 2:_=p%3==0;break;case 3:_=(p+g)%3==0;break;case 4:_=(Math.floor(p/3)+Math.floor(g/2))%2==0;break;case 5:_=p*g%2+p*g%3==0;break;case 6:_=(p*g%2+p*g%3)%2==0;break;case 7:_=((p+g)%2+p*g%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[g][p]&&_&&(this.modules[g][p]=!this.modules[g][p])}}getPenaltyScore(){let f=0;for(let y=0;y<this.size;y++){let S=!1,N=0,P=[0,0,0,0,0,0,0];for(let T=0;T<this.size;T++)this.modules[y][T]==S?(N++,N==5?f+=Ae.PENALTY_N1:N>5&&f++):(this.finderPenaltyAddHistory(N,P),S||(f+=this.finderPenaltyCountPatterns(P)*Ae.PENALTY_N3),S=this.modules[y][T],N=1);f+=this.finderPenaltyTerminateAndCount(S,N,P)*Ae.PENALTY_N3}for(let y=0;y<this.size;y++){let S=!1,N=0,P=[0,0,0,0,0,0,0];for(let T=0;T<this.size;T++)this.modules[T][y]==S?(N++,N==5?f+=Ae.PENALTY_N1:N>5&&f++):(this.finderPenaltyAddHistory(N,P),S||(f+=this.finderPenaltyCountPatterns(P)*Ae.PENALTY_N3),S=this.modules[T][y],N=1);f+=this.finderPenaltyTerminateAndCount(S,N,P)*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 p=this.size*this.size,_=Math.ceil(Math.abs(g*20-p*10)/p)-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 p=[6];for(let _=this.size-7;p.length<f;_-=g)p.splice(1,0,_);return p}}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 p=Math.floor(f/7)+2;g-=(25*p-10)*p-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 p=1;for(let _=0;_<f;_++){for(let y=0;y<g.length;y++)g[y]=Ae.reedSolomonMultiply(g[y],p),y+1<g.length&&(g[y]^=g[y+1]);p=Ae.reedSolomonMultiply(p,2)}return g}static reedSolomonComputeRemainder(f,g){let p=g.map(_=>0);for(const _ of f){const y=_^p.shift();p.push(0),g.forEach((S,N)=>p[N]^=Ae.reedSolomonMultiply(S,y))}return p}static reedSolomonMultiply(f,g){if(f>>>8||g>>>8)throw new RangeError("Byte out of range");let p=0;for(let _=7;_>=0;_--)p=p<<1^(p>>>7)*285,p^=(g>>>_&1)*f;return u(p>>>8==0),p}finderPenaltyCountPatterns(f){const g=f[1];u(g<=this.size*3);const p=g>0&&f[2]==g&&f[3]==g*3&&f[4]==g&&f[5]==g;return(p&&f[0]>=g*4&&f[6]>=g?1:0)+(p&&f[6]>=g*4&&f[0]>=g?1:0)}finderPenaltyTerminateAndCount(f,g,p){return f&&(this.finderPenaltyAddHistory(g,p),g=0),g+=this.size,this.finderPenaltyAddHistory(g,p),this.finderPenaltyCountPatterns(p)}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]],i.QrCode=n;function r(b,f,g){if(f<0||f>31||b>>>f)throw new RangeError("Value out of range");for(let p=f-1;p>=0;p--)g.push(b>>>p&1)}function o(b,f){return(b>>>f&1)!=0}function u(b){if(!b)throw new Error("Assertion error")}const l=class ot{constructor(f,g,p){if(this.mode=f,this.numChars=g,this.bitData=p,g<0)throw new RangeError("Invalid argument");this.bitData=p.slice()}static makeBytes(f){let g=[];for(const p of f)r(p,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 p=0;p<f.length;){const _=Math.min(f.length-p,3);r(parseInt(f.substring(p,p+_),10),_*3+1,g),p+=_}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=[],p;for(p=0;p+2<=f.length;p+=2){let _=ot.ALPHANUMERIC_CHARSET.indexOf(f.charAt(p))*45;_+=ot.ALPHANUMERIC_CHARSET.indexOf(f.charAt(p+1)),r(_,11,g)}return p<f.length&&r(ot.ALPHANUMERIC_CHARSET.indexOf(f.charAt(p)),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 p=0;for(const _ of f){const y=_.mode.numCharCountBits(g);if(_.numChars>=1<<y)return 1/0;p+=4+y+_.bitData.length}return p}static toUtf8ByteArray(f){f=encodeURI(f);let g=[];for(let p=0;p<f.length;p++)f.charAt(p)!="%"?g.push(f.charCodeAt(p)):(g.push(parseInt(f.substring(p+1,p+3),16)),p+=2);return g}};l.NUMERIC_REGEX=/^[0-9]*$/,l.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,l.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let h=l;i.QrSegment=l})(mr||(mr={}));(i=>{(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})(i.QrCode||(i.QrCode={}))})(mr||(mr={}));(i=>{(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})(i.QrSegment||(i.QrSegment={}))})(mr||(mr={}));var jr=mr;var A1={L:jr.QrCode.Ecc.LOW,M:jr.QrCode.Ecc.MEDIUM,Q:jr.QrCode.Ecc.QUARTILE,H:jr.QrCode.Ecc.HIGH},Cd=128,kd="L",Td="#FFFFFF",Rd="#000000",Ad=!1,Pd=1,P1=4,j1=0,I1=.1;function jd(i,n=0){const r=[];return i.forEach(function(o,u){let l=null;o.forEach(function(h,b){if(!h&&l!==null){r.push(`M${l+n} ${u+n}h${b-l}v1H${l+n}z`),l=null;return}if(b===o.length-1){if(!h)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}h&&l===null&&(l=b)})}),r.join("")}function Id(i,n){return i.slice().map((r,o)=>o<n.y||o>=n.y+n.h?r:r.map((u,l)=>l<n.x||l>=n.x+n.w?u:!1))}function D1(i,n,r,o){if(o==null)return null;const u=i.length+r*2,l=Math.floor(n*I1),h=u/n,b=(o.width||l)*h,f=(o.height||l)*h,g=o.x==null?i.length/2-b/2:o.x*h,p=o.y==null?i.length/2-f/2:o.y*h,_=o.opacity==null?1:o.opacity;let y=null;if(o.excavate){let N=Math.floor(g),P=Math.floor(p),T=Math.ceil(b+g-N),I=Math.ceil(f+p-P);y={x:N,y:P,w:T,h:I}}const S=o.crossOrigin;return{x:g,y:p,h:f,w:b,excavation:y,opacity:_,crossOrigin:S}}function M1(i,n){return n!=null?Math.max(Math.floor(n),0):i?P1:j1}function Dd({value:i,level:n,minVersion:r,includeMargin:o,marginSize:u,imageSettings:l,size:h,boostLevel:b}){let f=We.useMemo(()=>{const N=(Array.isArray(i)?i:[i]).reduce((P,T)=>(P.push(...jr.QrSegment.makeSegments(T)),P),[]);return jr.QrCode.encodeSegments(N,A1[n],r,void 0,void 0,b)},[i,n,r,b]);const{cells:g,margin:p,numCells:_,calculatedImageSettings:y}=We.useMemo(()=>{let S=f.getModules();const N=M1(o,u),P=S.length+N*2,T=D1(S,h,N,l);return{cells:S,margin:N,numCells:P,calculatedImageSettings:T}},[f,h,l,o,u]);return{qrcode:f,margin:p,cells:g,numCells:_,calculatedImageSettings:y}}var L1=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),O1=We.forwardRef(function(n,r){const o=n,{value:u,size:l=Cd,level:h=kd,bgColor:b=Td,fgColor:f=Rd,includeMargin:g=Ad,minVersion:p=Pd,boostLevel:_,marginSize:y,imageSettings:S}=o,P=ha(o,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:T}=P,I=ha(P,["style"]),F=S?.src,A=We.useRef(null),$=We.useRef(null),q=We.useCallback(G=>{A.current=G,typeof r=="function"?r(G):r&&(r.current=G)},[r]),[X,K]=We.useState(!1),{margin:V,cells:O,numCells:B,calculatedImageSettings:M}=Dd({value:u,level:h,minVersion:p,boostLevel:_,includeMargin:g,marginSize:y,imageSettings:S,size:l});We.useEffect(()=>{if(A.current!=null){const G=A.current,J=G.getContext("2d");if(!J)return;let R=O;const W=$.current,oe=M!=null&&W!==null&&W.complete&&W.naturalHeight!==0&&W.naturalWidth!==0;oe&&M.excavation!=null&&(R=Id(O,M.excavation));const de=window.devicePixelRatio||1;G.height=G.width=l*de;const ue=l/B*de;J.scale(ue,ue),J.fillStyle=b,J.fillRect(0,0,B,B),J.fillStyle=f,L1?J.fill(new Path2D(jd(R,V))):O.forEach(function(Z,Se){Z.forEach(function(Pe,Fe){Pe&&J.fillRect(Fe+V,Se+V,1,1)})}),M&&(J.globalAlpha=M.opacity),oe&&J.drawImage(W,M.x+V,M.y+V,M.w,M.h)}}),We.useEffect(()=>{K(!1)},[F]);const me=fa({height:l,width:l},T);let ye=null;return F!=null&&(ye=We.createElement("img",{src:F,key:F,style:{display:"none"},onLoad:()=>{K(!0)},ref:$,crossOrigin:M?.crossOrigin})),We.createElement(We.Fragment,null,We.createElement("canvas",fa({style:me,height:l,width:l,ref:q,role:"img"},I)),ye)});O1.displayName="QRCodeCanvas";var Md=We.forwardRef(function(n,r){const o=n,{value:u,size:l=Cd,level:h=kd,bgColor:b=Td,fgColor:f=Rd,includeMargin:g=Ad,minVersion:p=Pd,boostLevel:_,title:y,marginSize:S,imageSettings:N}=o,P=ha(o,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:T,cells:I,numCells:F,calculatedImageSettings:A}=Dd({value:u,level:h,minVersion:p,boostLevel:_,includeMargin:g,marginSize:S,imageSettings:N,size:l});let $=I,q=null;N!=null&&A!=null&&(A.excavation!=null&&($=Id(I,A.excavation)),q=We.createElement("image",{href:N.src,height:A.h,width:A.w,x:A.x+T,y:A.y+T,preserveAspectRatio:"none",opacity:A.opacity,crossOrigin:A.crossOrigin}));const X=jd($,T);return We.createElement("svg",fa({height:l,width:l,viewBox:`0 0 ${F} ${F}`,ref:r,role:"img"},P),!!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)});Md.displayName="QRCodeSVG";var os={exports:{}};var F1=os.exports,vu;function B1(){return vu||(vu=1,(function(i,n){(function(){var r,o="4.17.21",u=200,l="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",h="Expected a function",b="Invalid `variable` option passed into `_.template`",f="__lodash_hash_undefined__",g=500,p="__lodash_placeholder__",_=1,y=2,S=4,N=1,P=2,T=1,I=2,F=4,A=8,$=16,q=32,X=64,K=128,V=256,O=512,B=30,M="...",me=800,ye=16,G=1,J=2,R=3,W=1/0,oe=9007199254740991,de=17976931348623157e292,ue=NaN,Z=4294967295,Se=Z-1,Pe=Z>>>1,Fe=[["ary",K],["bind",T],["bindKey",I],["curry",A],["curryRight",$],["flip",O],["partial",q],["partialRight",X],["rearg",V]],Le="[object Arguments]",at="[object Array]",lt="[object AsyncFunction]",Ge="[object Boolean]",Te="[object Date]",$e="[object DOMException]",mt="[object Error]",tt="[object Function]",Tt="[object GeneratorFunction]",Xe="[object Map]",gt="[object Number]",ne="[object Null]",re="[object Object]",D="[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]",Mt="[object Float64Array]",st="[object Int8Array]",en="[object Int16Array]",Rt="[object Int32Array]",tn="[object Uint8Array]",Qe="[object Uint8ClampedArray]",Gt="[object Uint16Array]",nn="[object Uint32Array]",xr=/\b__p \+= '';/g,sr=/\b(__p \+=) '' \+/g,He=/(__e\(.*?\)|\b__t\)) \+\n'';/g,At=/&(?:amp|lt|gt|quot|#39);/g,wt=/[&<>"']/g,Pt=RegExp(At.source),Pn=RegExp(wt.source),Or=/<%-([\s\S]+?)%>/g,Ri=/<%([\s\S]+?)%>/g,gs=/<%=([\s\S]+?)%>/g,Ai=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Pi=/^\w*$/,ji=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Fr=/[\\^$.*+?()[\]{}|]/g,Br=RegExp(Fr.source),H=/^\s+/,je=/\s/,ve=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,nt=/\{\n\/\* \[wrapped with (.+)\] \*/,wn=/,? & /,ft=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Je=/[()=,{}\[\]\/\s]/,ht=/\\(\\)?/g,Lt=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Ur=/\w*$/,Ii=/^[-+]0x[0-9a-f]+$/i,Ze=/^0b[01]+$/i,Ot=/^\[object .+?Constructor\]$/,$t=/^0o[0-7]+$/i,rn=/^(?:0|[1-9]\d*)$/,ir=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,xs=/($^)/,jf=/['\n\r\u2028\u2029\\]/g,_s="\\ud800-\\udfff",If="\\u0300-\\u036f",Df="\\ufe20-\\ufe2f",Mf="\\u20d0-\\u20ff",Oa=If+Df+Mf,Fa="\\u2700-\\u27bf",Ba="a-z\\xdf-\\xf6\\xf8-\\xff",Lf="\\xac\\xb1\\xd7\\xf7",Of="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Ff="\\u2000-\\u206f",Bf=" \\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",Ua="A-Z\\xc0-\\xd6\\xd8-\\xde",Wa="\\ufe0e\\ufe0f",za=Lf+Of+Ff+Bf,Di="['’]",Uf="["+_s+"]",Ha="["+za+"]",vs="["+Oa+"]",Ga="\\d+",Wf="["+Fa+"]",$a="["+Ba+"]",qa="[^"+_s+za+Ga+Fa+Ba+Ua+"]",Mi="\\ud83c[\\udffb-\\udfff]",zf="(?:"+vs+"|"+Mi+")",Xa="[^"+_s+"]",Li="(?:\\ud83c[\\udde6-\\uddff]){2}",Oi="[\\ud800-\\udbff][\\udc00-\\udfff]",_r="["+Ua+"]",Ya="\\u200d",Va="(?:"+$a+"|"+qa+")",Hf="(?:"+_r+"|"+qa+")",Ka="(?:"+Di+"(?:d|ll|m|re|s|t|ve))?",Qa="(?:"+Di+"(?:D|LL|M|RE|S|T|VE))?",Ja=zf+"?",Za="["+Wa+"]?",Gf="(?:"+Ya+"(?:"+[Xa,Li,Oi].join("|")+")"+Za+Ja+")*",$f="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",qf="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",el=Za+Ja+Gf,Xf="(?:"+[Wf,Li,Oi].join("|")+")"+el,Yf="(?:"+[Xa+vs+"?",vs,Li,Oi,Uf].join("|")+")",Vf=RegExp(Di,"g"),Kf=RegExp(vs,"g"),Fi=RegExp(Mi+"(?="+Mi+")|"+Yf+el,"g"),Qf=RegExp([_r+"?"+$a+"+"+Ka+"(?="+[Ha,_r,"$"].join("|")+")",Hf+"+"+Qa+"(?="+[Ha,_r+Va,"$"].join("|")+")",_r+"?"+Va+"+"+Ka,_r+"+"+Qa,qf,$f,Ga,Xf].join("|"),"g"),Jf=RegExp("["+Ya+_s+Oa+Wa+"]"),Zf=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,eh=["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"],th=-1,Ve={};Ve[Ke]=Ve[Mt]=Ve[st]=Ve[en]=Ve[Rt]=Ve[tn]=Ve[Qe]=Ve[Gt]=Ve[nn]=!0,Ve[Le]=Ve[at]=Ve[ie]=Ve[Ge]=Ve[ge]=Ve[Te]=Ve[mt]=Ve[tt]=Ve[Xe]=Ve[gt]=Ve[re]=Ve[le]=Ve[ce]=Ve[Ce]=Ve[bt]=!1;var Ye={};Ye[Le]=Ye[at]=Ye[ie]=Ye[ge]=Ye[Ge]=Ye[Te]=Ye[Ke]=Ye[Mt]=Ye[st]=Ye[en]=Ye[Rt]=Ye[Xe]=Ye[gt]=Ye[re]=Ye[le]=Ye[ce]=Ye[Ce]=Ye[we]=Ye[tn]=Ye[Qe]=Ye[Gt]=Ye[nn]=!0,Ye[mt]=Ye[tt]=Ye[bt]=!1;var nh={À:"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"},rh={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},sh={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},ih={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},oh=parseFloat,ah=parseInt,tl=typeof ii=="object"&&ii&&ii.Object===Object&&ii,lh=typeof self=="object"&&self&&self.Object===Object&&self,Et=tl||lh||Function("return this")(),Bi=n&&!n.nodeType&&n,or=Bi&&!0&&i&&!i.nodeType&&i,nl=or&&or.exports===Bi,Ui=nl&&tl.process,sn=(function(){try{var C=or&&or.require&&or.require("util").types;return C||Ui&&Ui.binding&&Ui.binding("util")}catch{}})(),rl=sn&&sn.isArrayBuffer,sl=sn&&sn.isDate,il=sn&&sn.isMap,ol=sn&&sn.isRegExp,al=sn&&sn.isSet,ll=sn&&sn.isTypedArray;function qt(C,L,j){switch(j.length){case 0:return C.call(L);case 1:return C.call(L,j[0]);case 2:return C.call(L,j[0],j[1]);case 3:return C.call(L,j[0],j[1],j[2])}return C.apply(L,j)}function ch(C,L,j,se){for(var xe=-1,Be=C==null?0:C.length;++xe<Be;){var _t=C[xe];L(se,_t,j(_t),C)}return se}function on(C,L){for(var j=-1,se=C==null?0:C.length;++j<se&&L(C[j],j,C)!==!1;);return C}function uh(C,L){for(var j=C==null?0:C.length;j--&&L(C[j],j,C)!==!1;);return C}function cl(C,L){for(var j=-1,se=C==null?0:C.length;++j<se;)if(!L(C[j],j,C))return!1;return!0}function Wn(C,L){for(var j=-1,se=C==null?0:C.length,xe=0,Be=[];++j<se;){var _t=C[j];L(_t,j,C)&&(Be[xe++]=_t)}return Be}function bs(C,L){var j=C==null?0:C.length;return!!j&&vr(C,L,0)>-1}function Wi(C,L,j){for(var se=-1,xe=C==null?0:C.length;++se<xe;)if(j(L,C[se]))return!0;return!1}function et(C,L){for(var j=-1,se=C==null?0:C.length,xe=Array(se);++j<se;)xe[j]=L(C[j],j,C);return xe}function zn(C,L){for(var j=-1,se=L.length,xe=C.length;++j<se;)C[xe+j]=L[j];return C}function zi(C,L,j,se){var xe=-1,Be=C==null?0:C.length;for(se&&Be&&(j=C[++xe]);++xe<Be;)j=L(j,C[xe],xe,C);return j}function dh(C,L,j,se){var xe=C==null?0:C.length;for(se&&xe&&(j=C[--xe]);xe--;)j=L(j,C[xe],xe,C);return j}function Hi(C,L){for(var j=-1,se=C==null?0:C.length;++j<se;)if(L(C[j],j,C))return!0;return!1}var fh=Gi("length");function hh(C){return C.split("")}function ph(C){return C.match(ft)||[]}function ul(C,L,j){var se;return j(C,function(xe,Be,_t){if(L(xe,Be,_t))return se=Be,!1}),se}function ys(C,L,j,se){for(var xe=C.length,Be=j+(se?1:-1);se?Be--:++Be<xe;)if(L(C[Be],Be,C))return Be;return-1}function vr(C,L,j){return L===L?Ch(C,L,j):ys(C,dl,j)}function mh(C,L,j,se){for(var xe=j-1,Be=C.length;++xe<Be;)if(se(C[xe],L))return xe;return-1}function dl(C){return C!==C}function fl(C,L){var j=C==null?0:C.length;return j?qi(C,L)/j:ue}function Gi(C){return function(L){return L==null?r:L[C]}}function $i(C){return function(L){return C==null?r:C[L]}}function hl(C,L,j,se,xe){return xe(C,function(Be,_t,qe){j=se?(se=!1,Be):L(j,Be,_t,qe)}),j}function gh(C,L){var j=C.length;for(C.sort(L);j--;)C[j]=C[j].value;return C}function qi(C,L){for(var j,se=-1,xe=C.length;++se<xe;){var Be=L(C[se]);Be!==r&&(j=j===r?Be:j+Be)}return j}function Xi(C,L){for(var j=-1,se=Array(C);++j<C;)se[j]=L(j);return se}function xh(C,L){return et(L,function(j){return[j,C[j]]})}function pl(C){return C&&C.slice(0,_l(C)+1).replace(H,"")}function Xt(C){return function(L){return C(L)}}function Yi(C,L){return et(L,function(j){return C[j]})}function Wr(C,L){return C.has(L)}function ml(C,L){for(var j=-1,se=C.length;++j<se&&vr(L,C[j],0)>-1;);return j}function gl(C,L){for(var j=C.length;j--&&vr(L,C[j],0)>-1;);return j}function _h(C,L){for(var j=C.length,se=0;j--;)C[j]===L&&++se;return se}var vh=$i(nh),bh=$i(rh);function yh(C){return"\\"+ih[C]}function wh(C,L){return C==null?r:C[L]}function br(C){return Jf.test(C)}function Eh(C){return Zf.test(C)}function Sh(C){for(var L,j=[];!(L=C.next()).done;)j.push(L.value);return j}function Vi(C){var L=-1,j=Array(C.size);return C.forEach(function(se,xe){j[++L]=[xe,se]}),j}function xl(C,L){return function(j){return C(L(j))}}function Hn(C,L){for(var j=-1,se=C.length,xe=0,Be=[];++j<se;){var _t=C[j];(_t===L||_t===p)&&(C[j]=p,Be[xe++]=j)}return Be}function ws(C){var L=-1,j=Array(C.size);return C.forEach(function(se){j[++L]=se}),j}function Nh(C){var L=-1,j=Array(C.size);return C.forEach(function(se){j[++L]=[se,se]}),j}function Ch(C,L,j){for(var se=j-1,xe=C.length;++se<xe;)if(C[se]===L)return se;return-1}function kh(C,L,j){for(var se=j+1;se--;)if(C[se]===L)return se;return se}function yr(C){return br(C)?Rh(C):fh(C)}function gn(C){return br(C)?Ah(C):hh(C)}function _l(C){for(var L=C.length;L--&&je.test(C.charAt(L)););return L}var Th=$i(sh);function Rh(C){for(var L=Fi.lastIndex=0;Fi.test(C);)++L;return L}function Ah(C){return C.match(Fi)||[]}function Ph(C){return C.match(Qf)||[]}var jh=(function C(L){L=L==null?Et:wr.defaults(Et.Object(),L,wr.pick(Et,eh));var j=L.Array,se=L.Date,xe=L.Error,Be=L.Function,_t=L.Math,qe=L.Object,Ki=L.RegExp,Ih=L.String,an=L.TypeError,Es=j.prototype,Dh=Be.prototype,Er=qe.prototype,Ss=L["__core-js_shared__"],Ns=Dh.toString,ze=Er.hasOwnProperty,Mh=0,vl=(function(){var e=/[^.]+$/.exec(Ss&&Ss.keys&&Ss.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""})(),Cs=Er.toString,Lh=Ns.call(qe),Oh=Et._,Fh=Ki("^"+Ns.call(ze).replace(Fr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ks=nl?L.Buffer:r,Gn=L.Symbol,Ts=L.Uint8Array,bl=ks?ks.allocUnsafe:r,Rs=xl(qe.getPrototypeOf,qe),yl=qe.create,wl=Er.propertyIsEnumerable,As=Es.splice,El=Gn?Gn.isConcatSpreadable:r,zr=Gn?Gn.iterator:r,ar=Gn?Gn.toStringTag:r,Ps=(function(){try{var e=fr(qe,"defineProperty");return e({},"",{}),e}catch{}})(),Bh=L.clearTimeout!==Et.clearTimeout&&L.clearTimeout,Uh=se&&se.now!==Et.Date.now&&se.now,Wh=L.setTimeout!==Et.setTimeout&&L.setTimeout,js=_t.ceil,Is=_t.floor,Qi=qe.getOwnPropertySymbols,zh=ks?ks.isBuffer:r,Sl=L.isFinite,Hh=Es.join,Gh=xl(qe.keys,qe),vt=_t.max,Nt=_t.min,$h=se.now,qh=L.parseInt,Nl=_t.random,Xh=Es.reverse,Ji=fr(L,"DataView"),Hr=fr(L,"Map"),Zi=fr(L,"Promise"),Sr=fr(L,"Set"),Gr=fr(L,"WeakMap"),$r=fr(qe,"create"),Ds=Gr&&new Gr,Nr={},Yh=hr(Ji),Vh=hr(Hr),Kh=hr(Zi),Qh=hr(Sr),Jh=hr(Gr),Ms=Gn?Gn.prototype:r,qr=Ms?Ms.valueOf:r,Cl=Ms?Ms.toString:r;function m(e){if(it(e)&&!be(e)&&!(e instanceof Ie)){if(e instanceof ln)return e;if(ze.call(e,"__wrapped__"))return kc(e)}return new ln(e)}var Cr=(function(){function e(){}return function(t){if(!rt(t))return{};if(yl)return yl(t);e.prototype=t;var s=new e;return e.prototype=r,s}})();function Ls(){}function ln(e,t){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=r}m.templateSettings={escape:Or,evaluate:Ri,interpolate:gs,variable:"",imports:{_:m}},m.prototype=Ls.prototype,m.prototype.constructor=m,ln.prototype=Cr(Ls.prototype),ln.prototype.constructor=ln;function Ie(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=Z,this.__views__=[]}function Zh(){var e=new Ie(this.__wrapped__);return e.__actions__=Ft(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=Ft(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=Ft(this.__views__),e}function ep(){if(this.__filtered__){var e=new Ie(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e}function tp(){var e=this.__wrapped__.value(),t=this.__dir__,s=be(e),c=t<0,d=s?e.length:0,x=hm(0,d,this.__views__),w=x.start,E=x.end,k=E-w,U=c?E:w-1,z=this.__iteratees__,Y=z.length,te=0,ae=Nt(k,this.__takeCount__);if(!s||!c&&d==k&&ae==k)return Kl(e,this.__actions__);var he=[];e:for(;k--&&te<ae;){U+=t;for(var Ne=-1,pe=e[U];++Ne<Y;){var Re=z[Ne],De=Re.iteratee,Kt=Re.type,Dt=De(pe);if(Kt==J)pe=Dt;else if(!Dt){if(Kt==G)continue e;break e}}he[te++]=pe}return he}Ie.prototype=Cr(Ls.prototype),Ie.prototype.constructor=Ie;function lr(e){var t=-1,s=e==null?0:e.length;for(this.clear();++t<s;){var c=e[t];this.set(c[0],c[1])}}function np(){this.__data__=$r?$r(null):{},this.size=0}function rp(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}function sp(e){var t=this.__data__;if($r){var s=t[e];return s===f?r:s}return ze.call(t,e)?t[e]:r}function ip(e){var t=this.__data__;return $r?t[e]!==r:ze.call(t,e)}function op(e,t){var s=this.__data__;return this.size+=this.has(e)?0:1,s[e]=$r&&t===r?f:t,this}lr.prototype.clear=np,lr.prototype.delete=rp,lr.prototype.get=sp,lr.prototype.has=ip,lr.prototype.set=op;function jn(e){var t=-1,s=e==null?0:e.length;for(this.clear();++t<s;){var c=e[t];this.set(c[0],c[1])}}function ap(){this.__data__=[],this.size=0}function lp(e){var t=this.__data__,s=Os(t,e);if(s<0)return!1;var c=t.length-1;return s==c?t.pop():As.call(t,s,1),--this.size,!0}function cp(e){var t=this.__data__,s=Os(t,e);return s<0?r:t[s][1]}function up(e){return Os(this.__data__,e)>-1}function dp(e,t){var s=this.__data__,c=Os(s,e);return c<0?(++this.size,s.push([e,t])):s[c][1]=t,this}jn.prototype.clear=ap,jn.prototype.delete=lp,jn.prototype.get=cp,jn.prototype.has=up,jn.prototype.set=dp;function In(e){var t=-1,s=e==null?0:e.length;for(this.clear();++t<s;){var c=e[t];this.set(c[0],c[1])}}function fp(){this.size=0,this.__data__={hash:new lr,map:new(Hr||jn),string:new lr}}function hp(e){var t=Vs(this,e).delete(e);return this.size-=t?1:0,t}function pp(e){return Vs(this,e).get(e)}function mp(e){return Vs(this,e).has(e)}function gp(e,t){var s=Vs(this,e),c=s.size;return s.set(e,t),this.size+=s.size==c?0:1,this}In.prototype.clear=fp,In.prototype.delete=hp,In.prototype.get=pp,In.prototype.has=mp,In.prototype.set=gp;function cr(e){var t=-1,s=e==null?0:e.length;for(this.__data__=new In;++t<s;)this.add(e[t])}function xp(e){return this.__data__.set(e,f),this}function _p(e){return this.__data__.has(e)}cr.prototype.add=cr.prototype.push=xp,cr.prototype.has=_p;function xn(e){var t=this.__data__=new jn(e);this.size=t.size}function vp(){this.__data__=new jn,this.size=0}function bp(e){var t=this.__data__,s=t.delete(e);return this.size=t.size,s}function yp(e){return this.__data__.get(e)}function wp(e){return this.__data__.has(e)}function Ep(e,t){var s=this.__data__;if(s instanceof jn){var c=s.__data__;if(!Hr||c.length<u-1)return c.push([e,t]),this.size=++s.size,this;s=this.__data__=new In(c)}return s.set(e,t),this.size=s.size,this}xn.prototype.clear=vp,xn.prototype.delete=bp,xn.prototype.get=yp,xn.prototype.has=wp,xn.prototype.set=Ep;function kl(e,t){var s=be(e),c=!s&&pr(e),d=!s&&!c&&Vn(e),x=!s&&!c&&!d&&Ar(e),w=s||c||d||x,E=w?Xi(e.length,Ih):[],k=E.length;for(var U in e)(t||ze.call(e,U))&&!(w&&(U=="length"||d&&(U=="offset"||U=="parent")||x&&(U=="buffer"||U=="byteLength"||U=="byteOffset")||On(U,k)))&&E.push(U);return E}function Tl(e){var t=e.length;return t?e[uo(0,t-1)]:r}function Sp(e,t){return Ks(Ft(e),ur(t,0,e.length))}function Np(e){return Ks(Ft(e))}function eo(e,t,s){(s!==r&&!_n(e[t],s)||s===r&&!(t in e))&&Dn(e,t,s)}function Xr(e,t,s){var c=e[t];(!(ze.call(e,t)&&_n(c,s))||s===r&&!(t in e))&&Dn(e,t,s)}function Os(e,t){for(var s=e.length;s--;)if(_n(e[s][0],t))return s;return-1}function Cp(e,t,s,c){return $n(e,function(d,x,w){t(c,d,s(d),w)}),c}function Rl(e,t){return e&&Sn(t,yt(t),e)}function kp(e,t){return e&&Sn(t,Ut(t),e)}function Dn(e,t,s){t=="__proto__"&&Ps?Ps(e,t,{configurable:!0,enumerable:!0,value:s,writable:!0}):e[t]=s}function to(e,t){for(var s=-1,c=t.length,d=j(c),x=e==null;++s<c;)d[s]=x?r:Lo(e,t[s]);return d}function ur(e,t,s){return e===e&&(s!==r&&(e=e<=s?e:s),t!==r&&(e=e>=t?e:t)),e}function cn(e,t,s,c,d,x){var w,E=t&_,k=t&y,U=t&S;if(s&&(w=d?s(e,c,d,x):s(e)),w!==r)return w;if(!rt(e))return e;var z=be(e);if(z){if(w=mm(e),!E)return Ft(e,w)}else{var Y=Ct(e),te=Y==tt||Y==Tt;if(Vn(e))return Zl(e,E);if(Y==re||Y==Le||te&&!d){if(w=k||te?{}:_c(e),!E)return k?sm(e,kp(w,e)):rm(e,Rl(w,e))}else{if(!Ye[Y])return d?e:{};w=gm(e,Y,E)}}x||(x=new xn);var ae=x.get(e);if(ae)return ae;x.set(e,w),Xc(e)?e.forEach(function(pe){w.add(cn(pe,t,s,pe,e,x))}):$c(e)&&e.forEach(function(pe,Re){w.set(Re,cn(pe,t,s,Re,e,x))});var he=U?k?wo:yo:k?Ut:yt,Ne=z?r:he(e);return on(Ne||e,function(pe,Re){Ne&&(Re=pe,pe=e[Re]),Xr(w,Re,cn(pe,t,s,Re,e,x))}),w}function Tp(e){var t=yt(e);return function(s){return Al(s,e,t)}}function Al(e,t,s){var c=s.length;if(e==null)return!c;for(e=qe(e);c--;){var d=s[c],x=t[d],w=e[d];if(w===r&&!(d in e)||!x(w))return!1}return!0}function Pl(e,t,s){if(typeof e!="function")throw new an(h);return es(function(){e.apply(r,s)},t)}function Yr(e,t,s,c){var d=-1,x=bs,w=!0,E=e.length,k=[],U=t.length;if(!E)return k;s&&(t=et(t,Xt(s))),c?(x=Wi,w=!1):t.length>=u&&(x=Wr,w=!1,t=new cr(t));e:for(;++d<E;){var z=e[d],Y=s==null?z:s(z);if(z=c||z!==0?z:0,w&&Y===Y){for(var te=U;te--;)if(t[te]===Y)continue e;k.push(z)}else x(t,Y,c)||k.push(z)}return k}var $n=sc(En),jl=sc(ro,!0);function Rp(e,t){var s=!0;return $n(e,function(c,d,x){return s=!!t(c,d,x),s}),s}function Fs(e,t,s){for(var c=-1,d=e.length;++c<d;){var x=e[c],w=t(x);if(w!=null&&(E===r?w===w&&!Vt(w):s(w,E)))var E=w,k=x}return k}function Ap(e,t,s,c){var d=e.length;for(s=Ee(s),s<0&&(s=-s>d?0:d+s),c=c===r||c>d?d:Ee(c),c<0&&(c+=d),c=s>c?0:Vc(c);s<c;)e[s++]=t;return e}function Il(e,t){var s=[];return $n(e,function(c,d,x){t(c,d,x)&&s.push(c)}),s}function St(e,t,s,c,d){var x=-1,w=e.length;for(s||(s=_m),d||(d=[]);++x<w;){var E=e[x];t>0&&s(E)?t>1?St(E,t-1,s,c,d):zn(d,E):c||(d[d.length]=E)}return d}var no=ic(),Dl=ic(!0);function En(e,t){return e&&no(e,t,yt)}function ro(e,t){return e&&Dl(e,t,yt)}function Bs(e,t){return Wn(t,function(s){return Fn(e[s])})}function dr(e,t){t=Xn(t,e);for(var s=0,c=t.length;e!=null&&s<c;)e=e[Nn(t[s++])];return s&&s==c?e:r}function Ml(e,t,s){var c=t(e);return be(e)?c:zn(c,s(e))}function jt(e){return e==null?e===r?xt:ne:ar&&ar in qe(e)?fm(e):Nm(e)}function so(e,t){return e>t}function Pp(e,t){return e!=null&&ze.call(e,t)}function jp(e,t){return e!=null&&t in qe(e)}function Ip(e,t,s){return e>=Nt(t,s)&&e<vt(t,s)}function io(e,t,s){for(var c=s?Wi:bs,d=e[0].length,x=e.length,w=x,E=j(x),k=1/0,U=[];w--;){var z=e[w];w&&t&&(z=et(z,Xt(t))),k=Nt(z.length,k),E[w]=!s&&(t||d>=120&&z.length>=120)?new cr(w&&z):r}z=e[0];var Y=-1,te=E[0];e:for(;++Y<d&&U.length<k;){var ae=z[Y],he=t?t(ae):ae;if(ae=s||ae!==0?ae:0,!(te?Wr(te,he):c(U,he,s))){for(w=x;--w;){var Ne=E[w];if(!(Ne?Wr(Ne,he):c(e[w],he,s)))continue e}te&&te.push(he),U.push(ae)}}return U}function Dp(e,t,s,c){return En(e,function(d,x,w){t(c,s(d),x,w)}),c}function Vr(e,t,s){t=Xn(t,e),e=wc(e,t);var c=e==null?e:e[Nn(dn(t))];return c==null?r:qt(c,e,s)}function Ll(e){return it(e)&&jt(e)==Le}function Mp(e){return it(e)&&jt(e)==ie}function Lp(e){return it(e)&&jt(e)==Te}function Kr(e,t,s,c,d){return e===t?!0:e==null||t==null||!it(e)&&!it(t)?e!==e&&t!==t:Op(e,t,s,c,Kr,d)}function Op(e,t,s,c,d,x){var w=be(e),E=be(t),k=w?at:Ct(e),U=E?at:Ct(t);k=k==Le?re:k,U=U==Le?re:U;var z=k==re,Y=U==re,te=k==U;if(te&&Vn(e)){if(!Vn(t))return!1;w=!0,z=!1}if(te&&!z)return x||(x=new xn),w||Ar(e)?mc(e,t,s,c,d,x):um(e,t,k,s,c,d,x);if(!(s&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 xn),d(Ne,pe,s,c,x)}}return te?(x||(x=new xn),dm(e,t,s,c,d,x)):!1}function Fp(e){return it(e)&&Ct(e)==Xe}function oo(e,t,s,c){var d=s.length,x=d,w=!c;if(e==null)return!x;for(e=qe(e);d--;){var E=s[d];if(w&&E[2]?E[1]!==e[E[0]]:!(E[0]in e))return!1}for(;++d<x;){E=s[d];var k=E[0],U=e[k],z=E[1];if(w&&E[2]){if(U===r&&!(k in e))return!1}else{var Y=new xn;if(c)var te=c(U,z,k,e,t,Y);if(!(te===r?Kr(z,U,N|P,c,Y):te))return!1}}return!0}function Ol(e){if(!rt(e)||bm(e))return!1;var t=Fn(e)?Fh:Ot;return t.test(hr(e))}function Bp(e){return it(e)&&jt(e)==le}function Up(e){return it(e)&&Ct(e)==ce}function Wp(e){return it(e)&&ni(e.length)&&!!Ve[jt(e)]}function Fl(e){return typeof e=="function"?e:e==null?Wt:typeof e=="object"?be(e)?Wl(e[0],e[1]):Ul(e):ou(e)}function ao(e){if(!Zr(e))return Gh(e);var t=[];for(var s in qe(e))ze.call(e,s)&&s!="constructor"&&t.push(s);return t}function zp(e){if(!rt(e))return Sm(e);var t=Zr(e),s=[];for(var c in e)c=="constructor"&&(t||!ze.call(e,c))||s.push(c);return s}function lo(e,t){return e<t}function Bl(e,t){var s=-1,c=Bt(e)?j(e.length):[];return $n(e,function(d,x,w){c[++s]=t(d,x,w)}),c}function Ul(e){var t=So(e);return t.length==1&&t[0][2]?bc(t[0][0],t[0][1]):function(s){return s===e||oo(s,e,t)}}function Wl(e,t){return Co(e)&&vc(t)?bc(Nn(e),t):function(s){var c=Lo(s,e);return c===r&&c===t?Oo(s,e):Kr(t,c,N|P)}}function Us(e,t,s,c,d){e!==t&&no(t,function(x,w){if(d||(d=new xn),rt(x))Hp(e,t,w,s,Us,c,d);else{var E=c?c(To(e,w),x,w+"",e,t,d):r;E===r&&(E=x),eo(e,w,E)}},Ut)}function Hp(e,t,s,c,d,x,w){var E=To(e,s),k=To(t,s),U=w.get(k);if(U){eo(e,s,U);return}var z=x?x(E,k,s+"",e,t,w):r,Y=z===r;if(Y){var te=be(k),ae=!te&&Vn(k),he=!te&&!ae&&Ar(k);z=k,te||ae||he?be(E)?z=E:ct(E)?z=Ft(E):ae?(Y=!1,z=Zl(k,!0)):he?(Y=!1,z=ec(k,!0)):z=[]:ts(k)||pr(k)?(z=E,pr(E)?z=Kc(E):(!rt(E)||Fn(E))&&(z=_c(k))):Y=!1}Y&&(w.set(k,z),d(z,k,c,x,w),w.delete(k)),eo(e,s,z)}function zl(e,t){var s=e.length;if(s)return t+=t<0?s:0,On(t,s)?e[t]:r}function Hl(e,t,s){t.length?t=et(t,function(x){return be(x)?function(w){return dr(w,x.length===1?x[0]:x)}:x}):t=[Wt];var c=-1;t=et(t,Xt(fe()));var d=Bl(e,function(x,w,E){var k=et(t,function(U){return U(x)});return{criteria:k,index:++c,value:x}});return gh(d,function(x,w){return nm(x,w,s)})}function Gp(e,t){return Gl(e,t,function(s,c){return Oo(e,c)})}function Gl(e,t,s){for(var c=-1,d=t.length,x={};++c<d;){var w=t[c],E=dr(e,w);s(E,w)&&Qr(x,Xn(w,e),E)}return x}function $p(e){return function(t){return dr(t,e)}}function co(e,t,s,c){var d=c?mh:vr,x=-1,w=t.length,E=e;for(e===t&&(t=Ft(t)),s&&(E=et(e,Xt(s)));++x<w;)for(var k=0,U=t[x],z=s?s(U):U;(k=d(E,z,k,c))>-1;)E!==e&&As.call(E,k,1),As.call(e,k,1);return e}function $l(e,t){for(var s=e?t.length:0,c=s-1;s--;){var d=t[s];if(s==c||d!==x){var x=d;On(d)?As.call(e,d,1):po(e,d)}}return e}function uo(e,t){return e+Is(Nl()*(t-e+1))}function qp(e,t,s,c){for(var d=-1,x=vt(js((t-e)/(s||1)),0),w=j(x);x--;)w[c?x:++d]=e,e+=s;return w}function fo(e,t){var s="";if(!e||t<1||t>oe)return s;do t%2&&(s+=e),t=Is(t/2),t&&(e+=e);while(t);return s}function ke(e,t){return Ro(yc(e,t,Wt),e+"")}function Xp(e){return Tl(Pr(e))}function Yp(e,t){var s=Pr(e);return Ks(s,ur(t,0,s.length))}function Qr(e,t,s,c){if(!rt(e))return e;t=Xn(t,e);for(var d=-1,x=t.length,w=x-1,E=e;E!=null&&++d<x;){var k=Nn(t[d]),U=s;if(k==="__proto__"||k==="constructor"||k==="prototype")return e;if(d!=w){var z=E[k];U=c?c(z,k,E):r,U===r&&(U=rt(z)?z:On(t[d+1])?[]:{})}Xr(E,k,U),E=E[k]}return e}var ql=Ds?function(e,t){return Ds.set(e,t),e}:Wt,Vp=Ps?function(e,t){return Ps(e,"toString",{configurable:!0,enumerable:!1,value:Bo(t),writable:!0})}:Wt;function Kp(e){return Ks(Pr(e))}function un(e,t,s){var c=-1,d=e.length;t<0&&(t=-t>d?0:d+t),s=s>d?d:s,s<0&&(s+=d),d=t>s?0:s-t>>>0,t>>>=0;for(var x=j(d);++c<d;)x[c]=e[c+t];return x}function Qp(e,t){var s;return $n(e,function(c,d,x){return s=t(c,d,x),!s}),!!s}function Ws(e,t,s){var c=0,d=e==null?c:e.length;if(typeof t=="number"&&t===t&&d<=Pe){for(;c<d;){var x=c+d>>>1,w=e[x];w!==null&&!Vt(w)&&(s?w<=t:w<t)?c=x+1:d=x}return d}return ho(e,t,Wt,s)}function ho(e,t,s,c){var d=0,x=e==null?0:e.length;if(x===0)return 0;t=s(t);for(var w=t!==t,E=t===null,k=Vt(t),U=t===r;d<x;){var z=Is((d+x)/2),Y=s(e[z]),te=Y!==r,ae=Y===null,he=Y===Y,Ne=Vt(Y);if(w)var pe=c||he;else U?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 Nt(x,Se)}function Xl(e,t){for(var s=-1,c=e.length,d=0,x=[];++s<c;){var w=e[s],E=t?t(w):w;if(!s||!_n(E,k)){var k=E;x[d++]=w===0?0:w}}return x}function Yl(e){return typeof e=="number"?e:Vt(e)?ue:+e}function Yt(e){if(typeof e=="string")return e;if(be(e))return et(e,Yt)+"";if(Vt(e))return Cl?Cl.call(e):"";var t=e+"";return t=="0"&&1/e==-W?"-0":t}function qn(e,t,s){var c=-1,d=bs,x=e.length,w=!0,E=[],k=E;if(s)w=!1,d=Wi;else if(x>=u){var U=t?null:lm(e);if(U)return ws(U);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=s||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,s)||(k!==E&&k.push(Y),E.push(z))}return E}function po(e,t){return t=Xn(t,e),e=wc(e,t),e==null||delete e[Nn(dn(t))]}function Vl(e,t,s,c){return Qr(e,t,s(dr(e,t)),c)}function zs(e,t,s,c){for(var d=e.length,x=c?d:-1;(c?x--:++x<d)&&t(e[x],x,e););return s?un(e,c?0:x,c?x+1:d):un(e,c?x+1:0,c?d:x)}function Kl(e,t){var s=e;return s instanceof Ie&&(s=s.value()),zi(t,function(c,d){return d.func.apply(d.thisArg,zn([c],d.args))},s)}function mo(e,t,s){var c=e.length;if(c<2)return c?qn(e[0]):[];for(var d=-1,x=j(c);++d<c;)for(var w=e[d],E=-1;++E<c;)E!=d&&(x[d]=Yr(x[d]||w,e[E],t,s));return qn(St(x,1),t,s)}function Ql(e,t,s){for(var c=-1,d=e.length,x=t.length,w={};++c<d;){var E=c<x?t[c]:r;s(w,e[c],E)}return w}function go(e){return ct(e)?e:[]}function xo(e){return typeof e=="function"?e:Wt}function Xn(e,t){return be(e)?e:Co(e,t)?[e]:Cc(Ue(e))}var Jp=ke;function Yn(e,t,s){var c=e.length;return s=s===r?c:s,!t&&s>=c?e:un(e,t,s)}var Jl=Bh||function(e){return Et.clearTimeout(e)};function Zl(e,t){if(t)return e.slice();var s=e.length,c=bl?bl(s):new e.constructor(s);return e.copy(c),c}function _o(e){var t=new e.constructor(e.byteLength);return new Ts(t).set(new Ts(e)),t}function Zp(e,t){var s=t?_o(e.buffer):e.buffer;return new e.constructor(s,e.byteOffset,e.byteLength)}function em(e){var t=new e.constructor(e.source,Ur.exec(e));return t.lastIndex=e.lastIndex,t}function tm(e){return qr?qe(qr.call(e)):{}}function ec(e,t){var s=t?_o(e.buffer):e.buffer;return new e.constructor(s,e.byteOffset,e.length)}function tc(e,t){if(e!==t){var s=e!==r,c=e===null,d=e===e,x=Vt(e),w=t!==r,E=t===null,k=t===t,U=Vt(t);if(!E&&!U&&!x&&e>t||x&&w&&k&&!E&&!U||c&&w&&k||!s&&k||!d)return 1;if(!c&&!x&&!U&&e<t||U&&s&&d&&!c&&!x||E&&s&&d||!w&&d||!k)return-1}return 0}function nm(e,t,s){for(var c=-1,d=e.criteria,x=t.criteria,w=d.length,E=s.length;++c<w;){var k=tc(d[c],x[c]);if(k){if(c>=E)return k;var U=s[c];return k*(U=="desc"?-1:1)}}return e.index-t.index}function nc(e,t,s,c){for(var d=-1,x=e.length,w=s.length,E=-1,k=t.length,U=vt(x-w,0),z=j(k+U),Y=!c;++E<k;)z[E]=t[E];for(;++d<w;)(Y||d<x)&&(z[s[d]]=e[d]);for(;U--;)z[E++]=e[d++];return z}function rc(e,t,s,c){for(var d=-1,x=e.length,w=-1,E=s.length,k=-1,U=t.length,z=vt(x-E,0),Y=j(z+U),te=!c;++d<z;)Y[d]=e[d];for(var ae=d;++k<U;)Y[ae+k]=t[k];for(;++w<E;)(te||d<x)&&(Y[ae+s[w]]=e[d++]);return Y}function Ft(e,t){var s=-1,c=e.length;for(t||(t=j(c));++s<c;)t[s]=e[s];return t}function Sn(e,t,s,c){var d=!s;s||(s={});for(var x=-1,w=t.length;++x<w;){var E=t[x],k=c?c(s[E],e[E],E,s,e):r;k===r&&(k=e[E]),d?Dn(s,E,k):Xr(s,E,k)}return s}function rm(e,t){return Sn(e,No(e),t)}function sm(e,t){return Sn(e,gc(e),t)}function Hs(e,t){return function(s,c){var d=be(s)?ch:Cp,x=t?t():{};return d(s,e,fe(c,2),x)}}function kr(e){return ke(function(t,s){var c=-1,d=s.length,x=d>1?s[d-1]:r,w=d>2?s[2]:r;for(x=e.length>3&&typeof x=="function"?(d--,x):r,w&&It(s[0],s[1],w)&&(x=d<3?r:x,d=1),t=qe(t);++c<d;){var E=s[c];E&&e(t,E,c,x)}return t})}function sc(e,t){return function(s,c){if(s==null)return s;if(!Bt(s))return e(s,c);for(var d=s.length,x=t?d:-1,w=qe(s);(t?x--:++x<d)&&c(w[x],x,w)!==!1;);return s}}function ic(e){return function(t,s,c){for(var d=-1,x=qe(t),w=c(t),E=w.length;E--;){var k=w[e?E:++d];if(s(x[k],k,x)===!1)break}return t}}function im(e,t,s){var c=t&T,d=Jr(e);function x(){var w=this&&this!==Et&&this instanceof x?d:e;return w.apply(c?s:this,arguments)}return x}function oc(e){return function(t){t=Ue(t);var s=br(t)?gn(t):r,c=s?s[0]:t.charAt(0),d=s?Yn(s,1).join(""):t.slice(1);return c[e]()+d}}function Tr(e){return function(t){return zi(su(ru(t).replace(Vf,"")),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 s=Cr(e.prototype),c=e.apply(s,t);return rt(c)?c:s}}function om(e,t,s){var c=Jr(e);function d(){for(var x=arguments.length,w=j(x),E=x,k=Rr(d);E--;)w[E]=arguments[E];var U=x<3&&w[0]!==k&&w[x-1]!==k?[]:Hn(w,k);if(x-=U.length,x<s)return dc(e,t,Gs,d.placeholder,r,w,U,r,r,s-x);var z=this&&this!==Et&&this instanceof d?c:e;return qt(z,this,w)}return d}function ac(e){return function(t,s,c){var d=qe(t);if(!Bt(t)){var x=fe(s,3);t=yt(t),s=function(E){return x(d[E],E,d)}}var w=e(t,s,c);return w>-1?d[x?t[w]:w]:r}}function lc(e){return Ln(function(t){var s=t.length,c=s,d=ln.prototype.thru;for(e&&t.reverse();c--;){var x=t[c];if(typeof x!="function")throw new an(h);if(d&&!w&&Ys(x)=="wrapper")var w=new ln([],!0)}for(c=w?c:s;++c<s;){x=t[c];var E=Ys(x),k=E=="wrapper"?Eo(x):r;k&&ko(k[0])&&k[1]==(K|A|q|V)&&!k[4].length&&k[9]==1?w=w[Ys(k[0])].apply(w,k[3]):w=x.length==1&&ko(x)?w[E]():w.thru(x)}return function(){var U=arguments,z=U[0];if(w&&U.length==1&&be(z))return w.plant(z).value();for(var Y=0,te=s?t[Y].apply(this,U):z;++Y<s;)te=t[Y].call(this,te);return te}})}function Gs(e,t,s,c,d,x,w,E,k,U){var z=t&K,Y=t&T,te=t&I,ae=t&(A|$),he=t&O,Ne=te?r:Jr(e);function pe(){for(var Re=arguments.length,De=j(Re),Kt=Re;Kt--;)De[Kt]=arguments[Kt];if(ae)var Dt=Rr(pe),Qt=_h(De,Dt);if(c&&(De=nc(De,c,d,ae)),x&&(De=rc(De,x,w,ae)),Re-=Qt,ae&&Re<U){var ut=Hn(De,Dt);return dc(e,t,Gs,pe.placeholder,s,De,ut,E,k,U-Re)}var vn=Y?s:this,Un=te?vn[e]:e;return Re=De.length,E?De=Cm(De,E):he&&Re>1&&De.reverse(),z&&k<Re&&(De.length=k),this&&this!==Et&&this instanceof pe&&(Un=Ne||Jr(Un)),Un.apply(vn,De)}return pe}function cc(e,t){return function(s,c){return Dp(s,e,t(c),{})}}function $s(e,t){return function(s,c){var d;if(s===r&&c===r)return t;if(s!==r&&(d=s),c!==r){if(d===r)return c;typeof s=="string"||typeof c=="string"?(s=Yt(s),c=Yt(c)):(s=Yl(s),c=Yl(c)),d=e(s,c)}return d}}function vo(e){return Ln(function(t){return t=et(t,Xt(fe())),ke(function(s){var c=this;return e(t,function(d){return qt(d,c,s)})})})}function qs(e,t){t=t===r?" ":Yt(t);var s=t.length;if(s<2)return s?fo(t,e):t;var c=fo(t,js(e/yr(t)));return br(t)?Yn(gn(c),0,e).join(""):c.slice(0,e)}function am(e,t,s,c){var d=t&T,x=Jr(e);function w(){for(var E=-1,k=arguments.length,U=-1,z=c.length,Y=j(z+k),te=this&&this!==Et&&this instanceof w?x:e;++U<z;)Y[U]=c[U];for(;k--;)Y[U++]=arguments[++E];return qt(te,d?s:this,Y)}return w}function uc(e){return function(t,s,c){return c&&typeof c!="number"&&It(t,s,c)&&(s=c=r),t=Bn(t),s===r?(s=t,t=0):s=Bn(s),c=c===r?t<s?1:-1:Bn(c),qp(t,s,c,e)}}function Xs(e){return function(t,s){return typeof t=="string"&&typeof s=="string"||(t=fn(t),s=fn(s)),e(t,s)}}function dc(e,t,s,c,d,x,w,E,k,U){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,U],pe=s.apply(r,Ne);return ko(e)&&Ec(pe,Ne),pe.placeholder=c,Sc(pe,e,t)}function bo(e){var t=_t[e];return function(s,c){if(s=fn(s),c=c==null?0:Nt(Ee(c),292),c&&Sl(s)){var d=(Ue(s)+"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(s)}}var lm=Sr&&1/ws(new Sr([,-0]))[1]==W?function(e){return new Sr(e)}:zo;function fc(e){return function(t){var s=Ct(t);return s==Xe?Vi(t):s==ce?Nh(t):xh(t,e(t))}}function Mn(e,t,s,c,d,x,w,E){var k=t&I;if(!k&&typeof e!="function")throw new an(h);var U=c?c.length:0;if(U||(t&=-97,c=d=r),w=w===r?w:vt(Ee(w),0),E=E===r?E:Ee(E),U-=d?d.length:0,t&X){var z=c,Y=d;c=d=r}var te=k?r:Eo(e),ae=[e,t,s,c,d,z,Y,x,w,E];if(te&&Em(ae,te),e=ae[0],t=ae[1],s=ae[2],c=ae[3],d=ae[4],E=ae[9]=ae[9]===r?k?0:e.length:vt(ae[9]-U,0),!E&&t&(A|$)&&(t&=-25),!t||t==T)var he=im(e,t,s);else t==A||t==$?he=om(e,t,E):(t==q||t==(T|q))&&!d.length?he=am(e,t,s,c):he=Gs.apply(r,ae);var Ne=te?ql:Ec;return Sc(Ne(he,ae),e,t)}function hc(e,t,s,c){return e===r||_n(e,Er[s])&&!ze.call(c,s)?t:e}function pc(e,t,s,c,d,x){return rt(e)&&rt(t)&&(x.set(t,e),Us(e,t,r,pc,x),x.delete(t)),e}function cm(e){return ts(e)?r:e}function mc(e,t,s,c,d,x){var w=s&N,E=e.length,k=t.length;if(E!=k&&!(w&&k>E))return!1;var U=x.get(e),z=x.get(t);if(U&&z)return U==t&&z==e;var Y=-1,te=!0,ae=s&P?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(!Hi(t,function(Re,De){if(!Wr(ae,De)&&(he===Re||d(he,Re,s,c,x)))return ae.push(De)})){te=!1;break}}else if(!(he===Ne||d(he,Ne,s,c,x))){te=!1;break}}return x.delete(e),x.delete(t),te}function um(e,t,s,c,d,x,w){switch(s){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 Ts(e),new Ts(t)));case Ge:case Te:case gt:return _n(+e,+t);case mt:return e.name==t.name&&e.message==t.message;case le:case Ce:return e==t+"";case Xe:var E=Vi;case ce:var k=c&N;if(E||(E=ws),e.size!=t.size&&!k)return!1;var U=w.get(e);if(U)return U==t;c|=P,w.set(e,t);var z=mc(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 dm(e,t,s,c,d,x){var w=s&N,E=yo(e),k=E.length,U=yo(t),z=U.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 Kt=w?c(De,Re,te,t,e,x):c(Re,De,te,e,t,x);if(!(Kt===r?Re===De||d(Re,De,s,c,x):Kt)){Ne=!1;break}pe||(pe=te=="constructor")}if(Ne&&!pe){var Dt=e.constructor,Qt=t.constructor;Dt!=Qt&&"constructor"in e&&"constructor"in t&&!(typeof Dt=="function"&&Dt instanceof Dt&&typeof Qt=="function"&&Qt instanceof Qt)&&(Ne=!1)}return x.delete(e),x.delete(t),Ne}function Ln(e){return Ro(yc(e,r,Ac),e+"")}function yo(e){return Ml(e,yt,No)}function wo(e){return Ml(e,Ut,gc)}var Eo=Ds?function(e){return Ds.get(e)}:zo;function Ys(e){for(var t=e.name+"",s=Nr[t],c=ze.call(Nr,t)?s.length:0;c--;){var d=s[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||Uo;return e=e===Uo?Fl:e,arguments.length?e(arguments[0],arguments[1]):e}function Vs(e,t){var s=e.__data__;return vm(t)?s[typeof t=="string"?"string":"hash"]:s.map}function So(e){for(var t=yt(e),s=t.length;s--;){var c=t[s],d=e[c];t[s]=[c,d,vc(d)]}return t}function fr(e,t){var s=wh(e,t);return Ol(s)?s:r}function fm(e){var t=ze.call(e,ar),s=e[ar];try{e[ar]=r;var c=!0}catch{}var d=Cs.call(e);return c&&(t?e[ar]=s:delete e[ar]),d}var No=Qi?function(e){return e==null?[]:(e=qe(e),Wn(Qi(e),function(t){return wl.call(e,t)}))}:Ho,gc=Qi?function(e){for(var t=[];e;)zn(t,No(e)),e=Rs(e);return t}:Ho,Ct=jt;(Ji&&Ct(new Ji(new ArrayBuffer(1)))!=ge||Hr&&Ct(new Hr)!=Xe||Zi&&Ct(Zi.resolve())!=D||Sr&&Ct(new Sr)!=ce||Gr&&Ct(new Gr)!=bt)&&(Ct=function(e){var t=jt(e),s=t==re?e.constructor:r,c=s?hr(s):"";if(c)switch(c){case Yh:return ge;case Vh:return Xe;case Kh:return D;case Qh:return ce;case Jh:return bt}return t});function hm(e,t,s){for(var c=-1,d=s.length;++c<d;){var x=s[c],w=x.size;switch(x.type){case"drop":e+=w;break;case"dropRight":t-=w;break;case"take":t=Nt(t,e+w);break;case"takeRight":e=vt(e,t-w);break}}return{start:e,end:t}}function pm(e){var t=e.match(nt);return t?t[1].split(wn):[]}function xc(e,t,s){t=Xn(t,e);for(var c=-1,d=t.length,x=!1;++c<d;){var w=Nn(t[c]);if(!(x=e!=null&&s(e,w)))break;e=e[w]}return x||++c!=d?x:(d=e==null?0:e.length,!!d&&ni(d)&&On(w,d)&&(be(e)||pr(e)))}function mm(e){var t=e.length,s=new e.constructor(t);return t&&typeof e[0]=="string"&&ze.call(e,"index")&&(s.index=e.index,s.input=e.input),s}function _c(e){return typeof e.constructor=="function"&&!Zr(e)?Cr(Rs(e)):{}}function gm(e,t,s){var c=e.constructor;switch(t){case ie:return _o(e);case Ge:case Te:return new c(+e);case ge:return Zp(e,s);case Ke:case Mt:case st:case en:case Rt:case tn:case Qe:case Gt:case nn:return ec(e,s);case Xe:return new c;case gt:case Ce:return new c(e);case le:return em(e);case ce:return new c;case we:return tm(e)}}function xm(e,t){var s=t.length;if(!s)return e;var c=s-1;return t[c]=(s>1?"& ":"")+t[c],t=t.join(s>2?", ":" "),e.replace(ve,`{
6
+ /* [wrapped with `+t+`] */
7
+ `)}function _m(e){return be(e)||pr(e)||!!(El&&e&&e[El])}function On(e,t){var s=typeof e;return t=t??oe,!!t&&(s=="number"||s!="symbol"&&rn.test(e))&&e>-1&&e%1==0&&e<t}function It(e,t,s){if(!rt(s))return!1;var c=typeof t;return(c=="number"?Bt(s)&&On(t,s.length):c=="string"&&t in s)?_n(s[t],e):!1}function Co(e,t){if(be(e))return!1;var s=typeof e;return s=="number"||s=="symbol"||s=="boolean"||e==null||Vt(e)?!0:Pi.test(e)||!Ai.test(e)||t!=null&&e in qe(t)}function vm(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function ko(e){var t=Ys(e),s=m[t];if(typeof s!="function"||!(t in Ie.prototype))return!1;if(e===s)return!0;var c=Eo(s);return!!c&&e===c[0]}function bm(e){return!!vl&&vl in e}var ym=Ss?Fn:Go;function Zr(e){var t=e&&e.constructor,s=typeof t=="function"&&t.prototype||Er;return e===s}function vc(e){return e===e&&!rt(e)}function bc(e,t){return function(s){return s==null?!1:s[e]===t&&(t!==r||e in qe(s))}}function wm(e){var t=ei(e,function(c){return s.size===g&&s.clear(),c}),s=t.cache;return t}function Em(e,t){var s=e[1],c=t[1],d=s|c,x=d<(T|I|K),w=c==K&&s==A||c==K&&s==V&&e[7].length<=t[8]||c==(K|V)&&t[7].length<=t[8]&&s==A;if(!(x||w))return e;c&T&&(e[2]=t[2],d|=s&T?0:F);var E=t[3];if(E){var k=e[3];e[3]=k?nc(k,E,t[4]):E,e[4]=k?Hn(e[3],p):t[4]}return E=t[5],E&&(k=e[5],e[5]=k?rc(k,E,t[6]):E,e[6]=k?Hn(e[5],p):t[6]),E=t[7],E&&(e[7]=E),c&K&&(e[8]=e[8]==null?t[8]:Nt(e[8],t[8])),e[9]==null&&(e[9]=t[9]),e[0]=t[0],e[1]=d,e}function Sm(e){var t=[];if(e!=null)for(var s in qe(e))t.push(s);return t}function Nm(e){return Cs.call(e)}function yc(e,t,s){return t=vt(t===r?e.length-1:t,0),function(){for(var c=arguments,d=-1,x=vt(c.length-t,0),w=j(x);++d<x;)w[d]=c[t+d];d=-1;for(var E=j(t+1);++d<t;)E[d]=c[d];return E[t]=s(w),qt(e,this,E)}}function wc(e,t){return t.length<2?e:dr(e,un(t,0,-1))}function Cm(e,t){for(var s=e.length,c=Nt(t.length,s),d=Ft(e);c--;){var x=t[c];e[c]=On(x,s)?d[x]:r}return e}function To(e,t){if(!(t==="constructor"&&typeof e[t]=="function")&&t!="__proto__")return e[t]}var Ec=Nc(ql),es=Wh||function(e,t){return Et.setTimeout(e,t)},Ro=Nc(Vp);function Sc(e,t,s){var c=t+"";return Ro(e,xm(c,km(pm(c),s)))}function Nc(e){var t=0,s=0;return function(){var c=$h(),d=ye-(c-s);if(s=c,d>0){if(++t>=me)return arguments[0]}else t=0;return e.apply(r,arguments)}}function Ks(e,t){var s=-1,c=e.length,d=c-1;for(t=t===r?c:t;++s<t;){var x=uo(s,d),w=e[x];e[x]=e[s],e[s]=w}return e.length=t,e}var Cc=wm(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(ji,function(s,c,d,x){t.push(d?x.replace(ht,"$1"):c||s)}),t});function Nn(e){if(typeof e=="string"||Vt(e))return e;var t=e+"";return t=="0"&&1/e==-W?"-0":t}function hr(e){if(e!=null){try{return Ns.call(e)}catch{}try{return e+""}catch{}}return""}function km(e,t){return on(Fe,function(s){var c="_."+s[0];t&s[1]&&!bs(e,c)&&e.push(c)}),e.sort()}function kc(e){if(e instanceof Ie)return e.clone();var t=new ln(e.__wrapped__,e.__chain__);return t.__actions__=Ft(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t}function Tm(e,t,s){(s?It(e,t,s):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=j(js(c/t));d<c;)w[x++]=un(e,d,d+=t);return w}function Rm(e){for(var t=-1,s=e==null?0:e.length,c=0,d=[];++t<s;){var x=e[t];x&&(d[c++]=x)}return d}function Am(){var e=arguments.length;if(!e)return[];for(var t=j(e-1),s=arguments[0],c=e;c--;)t[c-1]=arguments[c];return zn(be(s)?Ft(s):[s],St(t,1))}var Pm=ke(function(e,t){return ct(e)?Yr(e,St(t,1,ct,!0)):[]}),jm=ke(function(e,t){var s=dn(t);return ct(s)&&(s=r),ct(e)?Yr(e,St(t,1,ct,!0),fe(s,2)):[]}),Im=ke(function(e,t){var s=dn(t);return ct(s)&&(s=r),ct(e)?Yr(e,St(t,1,ct,!0),r,s):[]});function Dm(e,t,s){var c=e==null?0:e.length;return c?(t=s||t===r?1:Ee(t),un(e,t<0?0:t,c)):[]}function Mm(e,t,s){var c=e==null?0:e.length;return c?(t=s||t===r?1:Ee(t),t=c-t,un(e,0,t<0?0:t)):[]}function Lm(e,t){return e&&e.length?zs(e,fe(t,3),!0,!0):[]}function Om(e,t){return e&&e.length?zs(e,fe(t,3),!0):[]}function Fm(e,t,s,c){var d=e==null?0:e.length;return d?(s&&typeof s!="number"&&It(e,t,s)&&(s=0,c=d),Ap(e,t,s,c)):[]}function Tc(e,t,s){var c=e==null?0:e.length;if(!c)return-1;var d=s==null?0:Ee(s);return d<0&&(d=vt(c+d,0)),ys(e,fe(t,3),d)}function Rc(e,t,s){var c=e==null?0:e.length;if(!c)return-1;var d=c-1;return s!==r&&(d=Ee(s),d=s<0?vt(c+d,0):Nt(d,c-1)),ys(e,fe(t,3),d,!0)}function Ac(e){var t=e==null?0:e.length;return t?St(e,1):[]}function Bm(e){var t=e==null?0:e.length;return t?St(e,W):[]}function Um(e,t){var s=e==null?0:e.length;return s?(t=t===r?1:Ee(t),St(e,t)):[]}function Wm(e){for(var t=-1,s=e==null?0:e.length,c={};++t<s;){var d=e[t];c[d[0]]=d[1]}return c}function Pc(e){return e&&e.length?e[0]:r}function zm(e,t,s){var c=e==null?0:e.length;if(!c)return-1;var d=s==null?0:Ee(s);return d<0&&(d=vt(c+d,0)),vr(e,t,d)}function Hm(e){var t=e==null?0:e.length;return t?un(e,0,-1):[]}var Gm=ke(function(e){var t=et(e,go);return t.length&&t[0]===e[0]?io(t):[]}),$m=ke(function(e){var t=dn(e),s=et(e,go);return t===dn(s)?t=r:s.pop(),s.length&&s[0]===e[0]?io(s,fe(t,2)):[]}),qm=ke(function(e){var t=dn(e),s=et(e,go);return t=typeof t=="function"?t:r,t&&s.pop(),s.length&&s[0]===e[0]?io(s,r,t):[]});function Xm(e,t){return e==null?"":Hh.call(e,t)}function dn(e){var t=e==null?0:e.length;return t?e[t-1]:r}function Ym(e,t,s){var c=e==null?0:e.length;if(!c)return-1;var d=c;return s!==r&&(d=Ee(s),d=d<0?vt(c+d,0):Nt(d,c-1)),t===t?kh(e,t,d):ys(e,dl,d,!0)}function Vm(e,t){return e&&e.length?zl(e,Ee(t)):r}var Km=ke(jc);function jc(e,t){return e&&e.length&&t&&t.length?co(e,t):e}function Qm(e,t,s){return e&&e.length&&t&&t.length?co(e,t,fe(s,2)):e}function Jm(e,t,s){return e&&e.length&&t&&t.length?co(e,t,r,s):e}var Zm=Ln(function(e,t){var s=e==null?0:e.length,c=to(e,t);return $l(e,et(t,function(d){return On(d,s)?+d:d}).sort(tc)),c});function e0(e,t){var s=[];if(!(e&&e.length))return s;var c=-1,d=[],x=e.length;for(t=fe(t,3);++c<x;){var w=e[c];t(w,c,e)&&(s.push(w),d.push(c))}return $l(e,d),s}function Ao(e){return e==null?e:Xh.call(e)}function t0(e,t,s){var c=e==null?0:e.length;return c?(s&&typeof s!="number"&&It(e,t,s)?(t=0,s=c):(t=t==null?0:Ee(t),s=s===r?c:Ee(s)),un(e,t,s)):[]}function n0(e,t){return Ws(e,t)}function r0(e,t,s){return ho(e,t,fe(s,2))}function s0(e,t){var s=e==null?0:e.length;if(s){var c=Ws(e,t);if(c<s&&_n(e[c],t))return c}return-1}function i0(e,t){return Ws(e,t,!0)}function o0(e,t,s){return ho(e,t,fe(s,2),!0)}function a0(e,t){var s=e==null?0:e.length;if(s){var c=Ws(e,t,!0)-1;if(_n(e[c],t))return c}return-1}function l0(e){return e&&e.length?Xl(e):[]}function c0(e,t){return e&&e.length?Xl(e,fe(t,2)):[]}function u0(e){var t=e==null?0:e.length;return t?un(e,1,t):[]}function d0(e,t,s){return e&&e.length?(t=s||t===r?1:Ee(t),un(e,0,t<0?0:t)):[]}function f0(e,t,s){var c=e==null?0:e.length;return c?(t=s||t===r?1:Ee(t),t=c-t,un(e,t<0?0:t,c)):[]}function h0(e,t){return e&&e.length?zs(e,fe(t,3),!1,!0):[]}function p0(e,t){return e&&e.length?zs(e,fe(t,3)):[]}var m0=ke(function(e){return qn(St(e,1,ct,!0))}),g0=ke(function(e){var t=dn(e);return ct(t)&&(t=r),qn(St(e,1,ct,!0),fe(t,2))}),x0=ke(function(e){var t=dn(e);return t=typeof t=="function"?t:r,qn(St(e,1,ct,!0),r,t)});function _0(e){return e&&e.length?qn(e):[]}function v0(e,t){return e&&e.length?qn(e,fe(t,2)):[]}function b0(e,t){return t=typeof t=="function"?t:r,e&&e.length?qn(e,r,t):[]}function Po(e){if(!(e&&e.length))return[];var t=0;return e=Wn(e,function(s){if(ct(s))return t=vt(s.length,t),!0}),Xi(t,function(s){return et(e,Gi(s))})}function Ic(e,t){if(!(e&&e.length))return[];var s=Po(e);return t==null?s:et(s,function(c){return qt(t,r,c)})}var y0=ke(function(e,t){return ct(e)?Yr(e,t):[]}),w0=ke(function(e){return mo(Wn(e,ct))}),E0=ke(function(e){var t=dn(e);return ct(t)&&(t=r),mo(Wn(e,ct),fe(t,2))}),S0=ke(function(e){var t=dn(e);return t=typeof t=="function"?t:r,mo(Wn(e,ct),r,t)}),N0=ke(Po);function C0(e,t){return Ql(e||[],t||[],Xr)}function k0(e,t){return Ql(e||[],t||[],Qr)}var T0=ke(function(e){var t=e.length,s=t>1?e[t-1]:r;return s=typeof s=="function"?(e.pop(),s):r,Ic(e,s)});function Dc(e){var t=m(e);return t.__chain__=!0,t}function R0(e,t){return t(e),e}function Qs(e,t){return t(e)}var A0=Ln(function(e){var t=e.length,s=t?e[0]:0,c=this.__wrapped__,d=function(x){return to(x,e)};return t>1||this.__actions__.length||!(c instanceof Ie)||!On(s)?this.thru(d):(c=c.slice(s,+s+(t?1:0)),c.__actions__.push({func:Qs,args:[d],thisArg:r}),new ln(c,this.__chain__).thru(function(x){return t&&!x.length&&x.push(r),x}))});function P0(){return Dc(this)}function j0(){return new ln(this.value(),this.__chain__)}function I0(){this.__values__===r&&(this.__values__=Yc(this.value()));var e=this.__index__>=this.__values__.length,t=e?r:this.__values__[this.__index__++];return{done:e,value:t}}function D0(){return this}function M0(e){for(var t,s=this;s instanceof Ls;){var c=kc(s);c.__index__=0,c.__values__=r,t?d.__wrapped__=c:t=c;var d=c;s=s.__wrapped__}return d.__wrapped__=e,t}function L0(){var e=this.__wrapped__;if(e instanceof Ie){var t=e;return this.__actions__.length&&(t=new Ie(this)),t=t.reverse(),t.__actions__.push({func:Qs,args:[Ao],thisArg:r}),new ln(t,this.__chain__)}return this.thru(Ao)}function O0(){return Kl(this.__wrapped__,this.__actions__)}var F0=Hs(function(e,t,s){ze.call(e,s)?++e[s]:Dn(e,s,1)});function B0(e,t,s){var c=be(e)?cl:Rp;return s&&It(e,t,s)&&(t=r),c(e,fe(t,3))}function U0(e,t){var s=be(e)?Wn:Il;return s(e,fe(t,3))}var W0=ac(Tc),z0=ac(Rc);function H0(e,t){return St(Js(e,t),1)}function G0(e,t){return St(Js(e,t),W)}function $0(e,t,s){return s=s===r?1:Ee(s),St(Js(e,t),s)}function Mc(e,t){var s=be(e)?on:$n;return s(e,fe(t,3))}function Lc(e,t){var s=be(e)?uh:jl;return s(e,fe(t,3))}var q0=Hs(function(e,t,s){ze.call(e,s)?e[s].push(t):Dn(e,s,[t])});function X0(e,t,s,c){e=Bt(e)?e:Pr(e),s=s&&!c?Ee(s):0;var d=e.length;return s<0&&(s=vt(d+s,0)),ri(e)?s<=d&&e.indexOf(t,s)>-1:!!d&&vr(e,t,s)>-1}var Y0=ke(function(e,t,s){var c=-1,d=typeof t=="function",x=Bt(e)?j(e.length):[];return $n(e,function(w){x[++c]=d?qt(t,w,s):Vr(w,t,s)}),x}),V0=Hs(function(e,t,s){Dn(e,s,t)});function Js(e,t){var s=be(e)?et:Bl;return s(e,fe(t,3))}function K0(e,t,s,c){return e==null?[]:(be(t)||(t=t==null?[]:[t]),s=c?r:s,be(s)||(s=s==null?[]:[s]),Hl(e,t,s))}var Q0=Hs(function(e,t,s){e[s?0:1].push(t)},function(){return[[],[]]});function J0(e,t,s){var c=be(e)?zi:hl,d=arguments.length<3;return c(e,fe(t,4),s,d,$n)}function Z0(e,t,s){var c=be(e)?dh:hl,d=arguments.length<3;return c(e,fe(t,4),s,d,jl)}function eg(e,t){var s=be(e)?Wn:Il;return s(e,ti(fe(t,3)))}function tg(e){var t=be(e)?Tl:Xp;return t(e)}function ng(e,t,s){(s?It(e,t,s):t===r)?t=1:t=Ee(t);var c=be(e)?Sp:Yp;return c(e,t)}function rg(e){var t=be(e)?Np:Kp;return t(e)}function sg(e){if(e==null)return 0;if(Bt(e))return ri(e)?yr(e):e.length;var t=Ct(e);return t==Xe||t==ce?e.size:ao(e).length}function ig(e,t,s){var c=be(e)?Hi:Qp;return s&&It(e,t,s)&&(t=r),c(e,fe(t,3))}var og=ke(function(e,t){if(e==null)return[];var s=t.length;return s>1&&It(e,t[0],t[1])?t=[]:s>2&&It(t[0],t[1],t[2])&&(t=[t[0]]),Hl(e,St(t,1),[])}),Zs=Uh||function(){return Et.Date.now()};function ag(e,t){if(typeof t!="function")throw new an(h);return e=Ee(e),function(){if(--e<1)return t.apply(this,arguments)}}function Oc(e,t,s){return t=s?r:t,t=e&&t==null?e.length:t,Mn(e,K,r,r,r,r,t)}function Fc(e,t){var s;if(typeof t!="function")throw new an(h);return e=Ee(e),function(){return--e>0&&(s=t.apply(this,arguments)),e<=1&&(t=r),s}}var jo=ke(function(e,t,s){var c=T;if(s.length){var d=Hn(s,Rr(jo));c|=q}return Mn(e,c,t,s,d)}),Bc=ke(function(e,t,s){var c=T|I;if(s.length){var d=Hn(s,Rr(Bc));c|=q}return Mn(t,c,e,s,d)});function Uc(e,t,s){t=s?r:t;var c=Mn(e,A,r,r,r,r,r,t);return c.placeholder=Uc.placeholder,c}function Wc(e,t,s){t=s?r:t;var c=Mn(e,$,r,r,r,r,r,t);return c.placeholder=Wc.placeholder,c}function zc(e,t,s){var c,d,x,w,E,k,U=0,z=!1,Y=!1,te=!0;if(typeof e!="function")throw new an(h);t=fn(t)||0,rt(s)&&(z=!!s.leading,Y="maxWait"in s,x=Y?vt(fn(s.maxWait)||0,t):x,te="trailing"in s?!!s.trailing:te);function ae(ut){var vn=c,Un=d;return c=d=r,U=ut,w=e.apply(Un,vn),w}function he(ut){return U=ut,E=es(Re,t),z?ae(ut):w}function Ne(ut){var vn=ut-k,Un=ut-U,au=t-vn;return Y?Nt(au,x-Un):au}function pe(ut){var vn=ut-k,Un=ut-U;return k===r||vn>=t||vn<0||Y&&Un>=x}function Re(){var ut=Zs();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 Kt(){E!==r&&Jl(E),U=0,c=k=d=E=r}function Dt(){return E===r?w:De(Zs())}function Qt(){var ut=Zs(),vn=pe(ut);if(c=arguments,d=this,k=ut,vn){if(E===r)return he(k);if(Y)return Jl(E),E=es(Re,t),ae(k)}return E===r&&(E=es(Re,t)),w}return Qt.cancel=Kt,Qt.flush=Dt,Qt}var lg=ke(function(e,t){return Pl(e,1,t)}),cg=ke(function(e,t,s){return Pl(e,fn(t)||0,s)});function ug(e){return Mn(e,O)}function ei(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new an(h);var s=function(){var c=arguments,d=t?t.apply(this,c):c[0],x=s.cache;if(x.has(d))return x.get(d);var w=e.apply(this,c);return s.cache=x.set(d,w)||x,w};return s.cache=new(ei.Cache||In),s}ei.Cache=In;function ti(e){if(typeof e!="function")throw new an(h);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 dg(e){return Fc(2,e)}var fg=Jp(function(e,t){t=t.length==1&&be(t[0])?et(t[0],Xt(fe())):et(St(t,1),Xt(fe()));var s=t.length;return ke(function(c){for(var d=-1,x=Nt(c.length,s);++d<x;)c[d]=t[d].call(this,c[d]);return qt(e,this,c)})}),Io=ke(function(e,t){var s=Hn(t,Rr(Io));return Mn(e,q,r,t,s)}),Hc=ke(function(e,t){var s=Hn(t,Rr(Hc));return Mn(e,X,r,t,s)}),hg=Ln(function(e,t){return Mn(e,V,r,r,r,t)});function pg(e,t){if(typeof e!="function")throw new an(h);return t=t===r?t:Ee(t),ke(e,t)}function mg(e,t){if(typeof e!="function")throw new an(h);return t=t==null?0:vt(Ee(t),0),ke(function(s){var c=s[t],d=Yn(s,0,t);return c&&zn(d,c),qt(e,this,d)})}function gg(e,t,s){var c=!0,d=!0;if(typeof e!="function")throw new an(h);return rt(s)&&(c="leading"in s?!!s.leading:c,d="trailing"in s?!!s.trailing:d),zc(e,t,{leading:c,maxWait:t,trailing:d})}function xg(e){return Oc(e,1)}function _g(e,t){return Io(xo(t),e)}function vg(){if(!arguments.length)return[];var e=arguments[0];return be(e)?e:[e]}function bg(e){return cn(e,S)}function yg(e,t){return t=typeof t=="function"?t:r,cn(e,S,t)}function wg(e){return cn(e,_|S)}function Eg(e,t){return t=typeof t=="function"?t:r,cn(e,_|S,t)}function Sg(e,t){return t==null||Al(e,t,yt(t))}function _n(e,t){return e===t||e!==e&&t!==t}var Ng=Xs(so),Cg=Xs(function(e,t){return e>=t}),pr=Ll((function(){return arguments})())?Ll:function(e){return it(e)&&ze.call(e,"callee")&&!wl.call(e,"callee")},be=j.isArray,kg=rl?Xt(rl):Mp;function Bt(e){return e!=null&&ni(e.length)&&!Fn(e)}function ct(e){return it(e)&&Bt(e)}function Tg(e){return e===!0||e===!1||it(e)&&jt(e)==Ge}var Vn=zh||Go,Rg=sl?Xt(sl):Lp;function Ag(e){return it(e)&&e.nodeType===1&&!ts(e)}function Pg(e){if(e==null)return!0;if(Bt(e)&&(be(e)||typeof e=="string"||typeof e.splice=="function"||Vn(e)||Ar(e)||pr(e)))return!e.length;var t=Ct(e);if(t==Xe||t==ce)return!e.size;if(Zr(e))return!ao(e).length;for(var s in e)if(ze.call(e,s))return!1;return!0}function jg(e,t){return Kr(e,t)}function Ig(e,t,s){s=typeof s=="function"?s:r;var c=s?s(e,t):r;return c===r?Kr(e,t,r,s):!!c}function Do(e){if(!it(e))return!1;var t=jt(e);return t==mt||t==$e||typeof e.message=="string"&&typeof e.name=="string"&&!ts(e)}function Dg(e){return typeof e=="number"&&Sl(e)}function Fn(e){if(!rt(e))return!1;var t=jt(e);return t==tt||t==Tt||t==lt||t==ee}function Gc(e){return typeof e=="number"&&e==Ee(e)}function ni(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=oe}function rt(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}function it(e){return e!=null&&typeof e=="object"}var $c=il?Xt(il):Fp;function Mg(e,t){return e===t||oo(e,t,So(t))}function Lg(e,t,s){return s=typeof s=="function"?s:r,oo(e,t,So(t),s)}function Og(e){return qc(e)&&e!=+e}function Fg(e){if(ym(e))throw new xe(l);return Ol(e)}function Bg(e){return e===null}function Ug(e){return e==null}function qc(e){return typeof e=="number"||it(e)&&jt(e)==gt}function ts(e){if(!it(e)||jt(e)!=re)return!1;var t=Rs(e);if(t===null)return!0;var s=ze.call(t,"constructor")&&t.constructor;return typeof s=="function"&&s instanceof s&&Ns.call(s)==Lh}var Mo=ol?Xt(ol):Bp;function Wg(e){return Gc(e)&&e>=-oe&&e<=oe}var Xc=al?Xt(al):Up;function ri(e){return typeof e=="string"||!be(e)&&it(e)&&jt(e)==Ce}function Vt(e){return typeof e=="symbol"||it(e)&&jt(e)==we}var Ar=ll?Xt(ll):Wp;function zg(e){return e===r}function Hg(e){return it(e)&&Ct(e)==bt}function Gg(e){return it(e)&&jt(e)==Q}var $g=Xs(lo),qg=Xs(function(e,t){return e<=t});function Yc(e){if(!e)return[];if(Bt(e))return ri(e)?gn(e):Ft(e);if(zr&&e[zr])return Sh(e[zr]());var t=Ct(e),s=t==Xe?Vi:t==ce?ws:Pr;return s(e)}function Bn(e){if(!e)return e===0?e:0;if(e=fn(e),e===W||e===-W){var t=e<0?-1:1;return t*de}return e===e?e:0}function Ee(e){var t=Bn(e),s=t%1;return t===t?s?t-s:t:0}function Vc(e){return e?ur(Ee(e),0,Z):0}function fn(e){if(typeof e=="number")return e;if(Vt(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=pl(e);var s=Ze.test(e);return s||$t.test(e)?ah(e.slice(2),s?2:8):Ii.test(e)?ue:+e}function Kc(e){return Sn(e,Ut(e))}function Xg(e){return e?ur(Ee(e),-oe,oe):e===0?e:0}function Ue(e){return e==null?"":Yt(e)}var Yg=kr(function(e,t){if(Zr(t)||Bt(t)){Sn(t,yt(t),e);return}for(var s in t)ze.call(t,s)&&Xr(e,s,t[s])}),Qc=kr(function(e,t){Sn(t,Ut(t),e)}),si=kr(function(e,t,s,c){Sn(t,Ut(t),e,c)}),Vg=kr(function(e,t,s,c){Sn(t,yt(t),e,c)}),Kg=Ln(to);function Qg(e,t){var s=Cr(e);return t==null?s:Rl(s,t)}var Jg=ke(function(e,t){e=qe(e);var s=-1,c=t.length,d=c>2?t[2]:r;for(d&&It(t[0],t[1],d)&&(c=1);++s<c;)for(var x=t[s],w=Ut(x),E=-1,k=w.length;++E<k;){var U=w[E],z=e[U];(z===r||_n(z,Er[U])&&!ze.call(e,U))&&(e[U]=x[U])}return e}),Zg=ke(function(e){return e.push(r,pc),qt(Jc,r,e)});function ex(e,t){return ul(e,fe(t,3),En)}function tx(e,t){return ul(e,fe(t,3),ro)}function nx(e,t){return e==null?e:no(e,fe(t,3),Ut)}function rx(e,t){return e==null?e:Dl(e,fe(t,3),Ut)}function sx(e,t){return e&&En(e,fe(t,3))}function ix(e,t){return e&&ro(e,fe(t,3))}function ox(e){return e==null?[]:Bs(e,yt(e))}function ax(e){return e==null?[]:Bs(e,Ut(e))}function Lo(e,t,s){var c=e==null?r:dr(e,t);return c===r?s:c}function lx(e,t){return e!=null&&xc(e,t,Pp)}function Oo(e,t){return e!=null&&xc(e,t,jp)}var cx=cc(function(e,t,s){t!=null&&typeof t.toString!="function"&&(t=Cs.call(t)),e[t]=s},Bo(Wt)),ux=cc(function(e,t,s){t!=null&&typeof t.toString!="function"&&(t=Cs.call(t)),ze.call(e,t)?e[t].push(s):e[t]=[s]},fe),dx=ke(Vr);function yt(e){return Bt(e)?kl(e):ao(e)}function Ut(e){return Bt(e)?kl(e,!0):zp(e)}function fx(e,t){var s={};return t=fe(t,3),En(e,function(c,d,x){Dn(s,t(c,d,x),c)}),s}function hx(e,t){var s={};return t=fe(t,3),En(e,function(c,d,x){Dn(s,d,t(c,d,x))}),s}var px=kr(function(e,t,s){Us(e,t,s)}),Jc=kr(function(e,t,s,c){Us(e,t,s,c)}),mx=Ln(function(e,t){var s={};if(e==null)return s;var c=!1;t=et(t,function(x){return x=Xn(x,e),c||(c=x.length>1),x}),Sn(e,wo(e),s),c&&(s=cn(s,_|y|S,cm));for(var d=t.length;d--;)po(s,t[d]);return s});function gx(e,t){return Zc(e,ti(fe(t)))}var xx=Ln(function(e,t){return e==null?{}:Gp(e,t)});function Zc(e,t){if(e==null)return{};var s=et(wo(e),function(c){return[c]});return t=fe(t),Gl(e,s,function(c,d){return t(c,d[0])})}function _x(e,t,s){t=Xn(t,e);var c=-1,d=t.length;for(d||(d=1,e=r);++c<d;){var x=e==null?r:e[Nn(t[c])];x===r&&(c=d,x=s),e=Fn(x)?x.call(e):x}return e}function vx(e,t,s){return e==null?e:Qr(e,t,s)}function bx(e,t,s,c){return c=typeof c=="function"?c:r,e==null?e:Qr(e,t,s,c)}var eu=fc(yt),tu=fc(Ut);function yx(e,t,s){var c=be(e),d=c||Vn(e)||Ar(e);if(t=fe(t,4),s==null){var x=e&&e.constructor;d?s=c?new x:[]:rt(e)?s=Fn(x)?Cr(Rs(e)):{}:s={}}return(d?on:En)(e,function(w,E,k){return t(s,w,E,k)}),s}function wx(e,t){return e==null?!0:po(e,t)}function Ex(e,t,s){return e==null?e:Vl(e,t,xo(s))}function Sx(e,t,s,c){return c=typeof c=="function"?c:r,e==null?e:Vl(e,t,xo(s),c)}function Pr(e){return e==null?[]:Yi(e,yt(e))}function Nx(e){return e==null?[]:Yi(e,Ut(e))}function Cx(e,t,s){return s===r&&(s=t,t=r),s!==r&&(s=fn(s),s=s===s?s:0),t!==r&&(t=fn(t),t=t===t?t:0),ur(fn(e),t,s)}function kx(e,t,s){return t=Bn(t),s===r?(s=t,t=0):s=Bn(s),e=fn(e),Ip(e,t,s)}function Tx(e,t,s){if(s&&typeof s!="boolean"&&It(e,t,s)&&(t=s=r),s===r&&(typeof t=="boolean"?(s=t,t=r):typeof e=="boolean"&&(s=e,e=r)),e===r&&t===r?(e=0,t=1):(e=Bn(e),t===r?(t=e,e=0):t=Bn(t)),e>t){var c=e;e=t,t=c}if(s||e%1||t%1){var d=Nl();return Nt(e+d*(t-e+oh("1e-"+((d+"").length-1))),t)}return uo(e,t)}var Rx=Tr(function(e,t,s){return t=t.toLowerCase(),e+(s?nu(t):t)});function nu(e){return Fo(Ue(e).toLowerCase())}function ru(e){return e=Ue(e),e&&e.replace(ir,vh).replace(Kf,"")}function Ax(e,t,s){e=Ue(e),t=Yt(t);var c=e.length;s=s===r?c:ur(Ee(s),0,c);var d=s;return s-=t.length,s>=0&&e.slice(s,d)==t}function Px(e){return e=Ue(e),e&&Pn.test(e)?e.replace(wt,bh):e}function jx(e){return e=Ue(e),e&&Br.test(e)?e.replace(Fr,"\\$&"):e}var Ix=Tr(function(e,t,s){return e+(s?"-":"")+t.toLowerCase()}),Dx=Tr(function(e,t,s){return e+(s?" ":"")+t.toLowerCase()}),Mx=oc("toLowerCase");function Lx(e,t,s){e=Ue(e),t=Ee(t);var c=t?yr(e):0;if(!t||c>=t)return e;var d=(t-c)/2;return qs(Is(d),s)+e+qs(js(d),s)}function Ox(e,t,s){e=Ue(e),t=Ee(t);var c=t?yr(e):0;return t&&c<t?e+qs(t-c,s):e}function Fx(e,t,s){e=Ue(e),t=Ee(t);var c=t?yr(e):0;return t&&c<t?qs(t-c,s)+e:e}function Bx(e,t,s){return s||t==null?t=0:t&&(t=+t),qh(Ue(e).replace(H,""),t||0)}function Ux(e,t,s){return(s?It(e,t,s):t===r)?t=1:t=Ee(t),fo(Ue(e),t)}function Wx(){var e=arguments,t=Ue(e[0]);return e.length<3?t:t.replace(e[1],e[2])}var zx=Tr(function(e,t,s){return e+(s?"_":"")+t.toLowerCase()});function Hx(e,t,s){return s&&typeof s!="number"&&It(e,t,s)&&(t=s=r),s=s===r?Z:s>>>0,s?(e=Ue(e),e&&(typeof t=="string"||t!=null&&!Mo(t))&&(t=Yt(t),!t&&br(e))?Yn(gn(e),0,s):e.split(t,s)):[]}var Gx=Tr(function(e,t,s){return e+(s?" ":"")+Fo(t)});function $x(e,t,s){return e=Ue(e),s=s==null?0:ur(Ee(s),0,e.length),t=Yt(t),e.slice(s,s+t.length)==t}function qx(e,t,s){var c=m.templateSettings;s&&It(e,t,s)&&(t=r),e=Ue(e),t=si({},t,c,hc);var d=si({},t.imports,c.imports,hc),x=yt(d),w=Yi(d,x),E,k,U=0,z=t.interpolate||xs,Y="__p += '",te=Ki((t.escape||xs).source+"|"+z.source+"|"+(z===gs?Lt:xs).source+"|"+(t.evaluate||xs).source+"|$","g"),ae="//# sourceURL="+(ze.call(t,"sourceURL")?(t.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++th+"]")+`
8
+ `;e.replace(te,function(pe,Re,De,Kt,Dt,Qt){return De||(De=Kt),Y+=e.slice(U,Qt).replace(jf,yh),Re&&(E=!0,Y+=`' +
9
+ __e(`+Re+`) +
10
+ '`),Dt&&(k=!0,Y+=`';
11
+ `+Dt+`;
12
+ __p += '`),De&&(Y+=`' +
13
+ ((__t = (`+De+`)) == null ? '' : __t) +
14
+ '`),U=Qt+pe.length,pe}),Y+=`';
15
+ `;var he=ze.call(t,"variable")&&t.variable;if(!he)Y=`with (obj) {
16
+ `+Y+`
17
+ }
18
+ `;else if(Je.test(he))throw new xe(b);Y=(k?Y.replace(xr,""):Y).replace(sr,"$1").replace(He,"$1;"),Y="function("+(he||"obj")+`) {
19
+ `+(he?"":`obj || (obj = {});
20
+ `)+"var __t, __p = ''"+(E?", __e = _.escape":"")+(k?`, __j = Array.prototype.join;
21
+ function print() { __p += __j.call(arguments, '') }
22
+ `:`;
23
+ `)+Y+`return __p
24
+ }`;var Ne=iu(function(){return Be(x,ae+"return "+Y).apply(r,w)});if(Ne.source=Y,Do(Ne))throw Ne;return Ne}function Xx(e){return Ue(e).toLowerCase()}function Yx(e){return Ue(e).toUpperCase()}function Vx(e,t,s){if(e=Ue(e),e&&(s||t===r))return pl(e);if(!e||!(t=Yt(t)))return e;var c=gn(e),d=gn(t),x=ml(c,d),w=gl(c,d)+1;return Yn(c,x,w).join("")}function Kx(e,t,s){if(e=Ue(e),e&&(s||t===r))return e.slice(0,_l(e)+1);if(!e||!(t=Yt(t)))return e;var c=gn(e),d=gl(c,gn(t))+1;return Yn(c,0,d).join("")}function Qx(e,t,s){if(e=Ue(e),e&&(s||t===r))return e.replace(H,"");if(!e||!(t=Yt(t)))return e;var c=gn(e),d=ml(c,gn(t));return Yn(c,d).join("")}function Jx(e,t){var s=B,c=M;if(rt(t)){var d="separator"in t?t.separator:d;s="length"in t?Ee(t.length):s,c="omission"in t?Yt(t.omission):c}e=Ue(e);var x=e.length;if(br(e)){var w=gn(e);x=w.length}if(s>=x)return e;var E=s-yr(c);if(E<1)return c;var k=w?Yn(w,0,E).join(""):e.slice(0,E);if(d===r)return k+c;if(w&&(E+=k.length-E),Mo(d)){if(e.slice(E).search(d)){var U,z=k;for(d.global||(d=Ki(d.source,Ue(Ur.exec(d))+"g")),d.lastIndex=0;U=d.exec(z);)var Y=U.index;k=k.slice(0,Y===r?E:Y)}}else if(e.indexOf(Yt(d),E)!=E){var te=k.lastIndexOf(d);te>-1&&(k=k.slice(0,te))}return k+c}function Zx(e){return e=Ue(e),e&&Pt.test(e)?e.replace(At,Th):e}var e_=Tr(function(e,t,s){return e+(s?" ":"")+t.toUpperCase()}),Fo=oc("toUpperCase");function su(e,t,s){return e=Ue(e),t=s?r:t,t===r?Eh(e)?Ph(e):ph(e):e.match(t)||[]}var iu=ke(function(e,t){try{return qt(e,r,t)}catch(s){return Do(s)?s:new xe(s)}}),t_=Ln(function(e,t){return on(t,function(s){s=Nn(s),Dn(e,s,jo(e[s],e))}),e});function n_(e){var t=e==null?0:e.length,s=fe();return e=t?et(e,function(c){if(typeof c[1]!="function")throw new an(h);return[s(c[0]),c[1]]}):[],ke(function(c){for(var d=-1;++d<t;){var x=e[d];if(qt(x[0],this,c))return qt(x[1],this,c)}})}function r_(e){return Tp(cn(e,_))}function Bo(e){return function(){return e}}function s_(e,t){return e==null||e!==e?t:e}var i_=lc(),o_=lc(!0);function Wt(e){return e}function Uo(e){return Fl(typeof e=="function"?e:cn(e,_))}function a_(e){return Ul(cn(e,_))}function l_(e,t){return Wl(e,cn(t,_))}var c_=ke(function(e,t){return function(s){return Vr(s,e,t)}}),u_=ke(function(e,t){return function(s){return Vr(e,s,t)}});function Wo(e,t,s){var c=yt(t),d=Bs(t,c);s==null&&!(rt(t)&&(d.length||!c.length))&&(s=t,t=e,e=this,d=Bs(t,yt(t)));var x=!(rt(s)&&"chain"in s)||!!s.chain,w=Fn(e);return on(d,function(E){var k=t[E];e[E]=k,w&&(e.prototype[E]=function(){var U=this.__chain__;if(x||U){var z=e(this.__wrapped__),Y=z.__actions__=Ft(this.__actions__);return Y.push({func:k,args:arguments,thisArg:e}),z.__chain__=U,z}return k.apply(e,zn([this.value()],arguments))})}),e}function d_(){return Et._===this&&(Et._=Oh),this}function zo(){}function f_(e){return e=Ee(e),ke(function(t){return zl(t,e)})}var h_=vo(et),p_=vo(cl),m_=vo(Hi);function ou(e){return Co(e)?Gi(Nn(e)):$p(e)}function g_(e){return function(t){return e==null?r:dr(e,t)}}var x_=uc(),__=uc(!0);function Ho(){return[]}function Go(){return!1}function v_(){return{}}function b_(){return""}function y_(){return!0}function w_(e,t){if(e=Ee(e),e<1||e>oe)return[];var s=Z,c=Nt(e,Z);t=fe(t),e-=Z;for(var d=Xi(c,t);++s<e;)t(s);return d}function E_(e){return be(e)?et(e,Nn):Vt(e)?[e]:Ft(Cc(Ue(e)))}function S_(e){var t=++Mh;return Ue(e)+t}var N_=$s(function(e,t){return e+t},0),C_=bo("ceil"),k_=$s(function(e,t){return e/t},1),T_=bo("floor");function R_(e){return e&&e.length?Fs(e,Wt,so):r}function A_(e,t){return e&&e.length?Fs(e,fe(t,2),so):r}function P_(e){return fl(e,Wt)}function j_(e,t){return fl(e,fe(t,2))}function I_(e){return e&&e.length?Fs(e,Wt,lo):r}function D_(e,t){return e&&e.length?Fs(e,fe(t,2),lo):r}var M_=$s(function(e,t){return e*t},1),L_=bo("round"),O_=$s(function(e,t){return e-t},0);function F_(e){return e&&e.length?qi(e,Wt):0}function B_(e,t){return e&&e.length?qi(e,fe(t,2)):0}return m.after=ag,m.ary=Oc,m.assign=Yg,m.assignIn=Qc,m.assignInWith=si,m.assignWith=Vg,m.at=Kg,m.before=Fc,m.bind=jo,m.bindAll=t_,m.bindKey=Bc,m.castArray=vg,m.chain=Dc,m.chunk=Tm,m.compact=Rm,m.concat=Am,m.cond=n_,m.conforms=r_,m.constant=Bo,m.countBy=F0,m.create=Qg,m.curry=Uc,m.curryRight=Wc,m.debounce=zc,m.defaults=Jg,m.defaultsDeep=Zg,m.defer=lg,m.delay=cg,m.difference=Pm,m.differenceBy=jm,m.differenceWith=Im,m.drop=Dm,m.dropRight=Mm,m.dropRightWhile=Lm,m.dropWhile=Om,m.fill=Fm,m.filter=U0,m.flatMap=H0,m.flatMapDeep=G0,m.flatMapDepth=$0,m.flatten=Ac,m.flattenDeep=Bm,m.flattenDepth=Um,m.flip=ug,m.flow=i_,m.flowRight=o_,m.fromPairs=Wm,m.functions=ox,m.functionsIn=ax,m.groupBy=q0,m.initial=Hm,m.intersection=Gm,m.intersectionBy=$m,m.intersectionWith=qm,m.invert=cx,m.invertBy=ux,m.invokeMap=Y0,m.iteratee=Uo,m.keyBy=V0,m.keys=yt,m.keysIn=Ut,m.map=Js,m.mapKeys=fx,m.mapValues=hx,m.matches=a_,m.matchesProperty=l_,m.memoize=ei,m.merge=px,m.mergeWith=Jc,m.method=c_,m.methodOf=u_,m.mixin=Wo,m.negate=ti,m.nthArg=f_,m.omit=mx,m.omitBy=gx,m.once=dg,m.orderBy=K0,m.over=h_,m.overArgs=fg,m.overEvery=p_,m.overSome=m_,m.partial=Io,m.partialRight=Hc,m.partition=Q0,m.pick=xx,m.pickBy=Zc,m.property=ou,m.propertyOf=g_,m.pull=Km,m.pullAll=jc,m.pullAllBy=Qm,m.pullAllWith=Jm,m.pullAt=Zm,m.range=x_,m.rangeRight=__,m.rearg=hg,m.reject=eg,m.remove=e0,m.rest=pg,m.reverse=Ao,m.sampleSize=ng,m.set=vx,m.setWith=bx,m.shuffle=rg,m.slice=t0,m.sortBy=og,m.sortedUniq=l0,m.sortedUniqBy=c0,m.split=Hx,m.spread=mg,m.tail=u0,m.take=d0,m.takeRight=f0,m.takeRightWhile=h0,m.takeWhile=p0,m.tap=R0,m.throttle=gg,m.thru=Qs,m.toArray=Yc,m.toPairs=eu,m.toPairsIn=tu,m.toPath=E_,m.toPlainObject=Kc,m.transform=yx,m.unary=xg,m.union=m0,m.unionBy=g0,m.unionWith=x0,m.uniq=_0,m.uniqBy=v0,m.uniqWith=b0,m.unset=wx,m.unzip=Po,m.unzipWith=Ic,m.update=Ex,m.updateWith=Sx,m.values=Pr,m.valuesIn=Nx,m.without=y0,m.words=su,m.wrap=_g,m.xor=w0,m.xorBy=E0,m.xorWith=S0,m.zip=N0,m.zipObject=C0,m.zipObjectDeep=k0,m.zipWith=T0,m.entries=eu,m.entriesIn=tu,m.extend=Qc,m.extendWith=si,Wo(m,m),m.add=N_,m.attempt=iu,m.camelCase=Rx,m.capitalize=nu,m.ceil=C_,m.clamp=Cx,m.clone=bg,m.cloneDeep=wg,m.cloneDeepWith=Eg,m.cloneWith=yg,m.conformsTo=Sg,m.deburr=ru,m.defaultTo=s_,m.divide=k_,m.endsWith=Ax,m.eq=_n,m.escape=Px,m.escapeRegExp=jx,m.every=B0,m.find=W0,m.findIndex=Tc,m.findKey=ex,m.findLast=z0,m.findLastIndex=Rc,m.findLastKey=tx,m.floor=T_,m.forEach=Mc,m.forEachRight=Lc,m.forIn=nx,m.forInRight=rx,m.forOwn=sx,m.forOwnRight=ix,m.get=Lo,m.gt=Ng,m.gte=Cg,m.has=lx,m.hasIn=Oo,m.head=Pc,m.identity=Wt,m.includes=X0,m.indexOf=zm,m.inRange=kx,m.invoke=dx,m.isArguments=pr,m.isArray=be,m.isArrayBuffer=kg,m.isArrayLike=Bt,m.isArrayLikeObject=ct,m.isBoolean=Tg,m.isBuffer=Vn,m.isDate=Rg,m.isElement=Ag,m.isEmpty=Pg,m.isEqual=jg,m.isEqualWith=Ig,m.isError=Do,m.isFinite=Dg,m.isFunction=Fn,m.isInteger=Gc,m.isLength=ni,m.isMap=$c,m.isMatch=Mg,m.isMatchWith=Lg,m.isNaN=Og,m.isNative=Fg,m.isNil=Ug,m.isNull=Bg,m.isNumber=qc,m.isObject=rt,m.isObjectLike=it,m.isPlainObject=ts,m.isRegExp=Mo,m.isSafeInteger=Wg,m.isSet=Xc,m.isString=ri,m.isSymbol=Vt,m.isTypedArray=Ar,m.isUndefined=zg,m.isWeakMap=Hg,m.isWeakSet=Gg,m.join=Xm,m.kebabCase=Ix,m.last=dn,m.lastIndexOf=Ym,m.lowerCase=Dx,m.lowerFirst=Mx,m.lt=$g,m.lte=qg,m.max=R_,m.maxBy=A_,m.mean=P_,m.meanBy=j_,m.min=I_,m.minBy=D_,m.stubArray=Ho,m.stubFalse=Go,m.stubObject=v_,m.stubString=b_,m.stubTrue=y_,m.multiply=M_,m.nth=Vm,m.noConflict=d_,m.noop=zo,m.now=Zs,m.pad=Lx,m.padEnd=Ox,m.padStart=Fx,m.parseInt=Bx,m.random=Tx,m.reduce=J0,m.reduceRight=Z0,m.repeat=Ux,m.replace=Wx,m.result=_x,m.round=L_,m.runInContext=C,m.sample=tg,m.size=sg,m.snakeCase=zx,m.some=ig,m.sortedIndex=n0,m.sortedIndexBy=r0,m.sortedIndexOf=s0,m.sortedLastIndex=i0,m.sortedLastIndexBy=o0,m.sortedLastIndexOf=a0,m.startCase=Gx,m.startsWith=$x,m.subtract=O_,m.sum=F_,m.sumBy=B_,m.template=qx,m.times=w_,m.toFinite=Bn,m.toInteger=Ee,m.toLength=Vc,m.toLower=Xx,m.toNumber=fn,m.toSafeInteger=Xg,m.toString=Ue,m.toUpper=Yx,m.trim=Vx,m.trimEnd=Kx,m.trimStart=Qx,m.truncate=Jx,m.unescape=Zx,m.uniqueId=S_,m.upperCase=e_,m.upperFirst=Fo,m.each=Mc,m.eachRight=Lc,m.first=Pc,Wo(m,(function(){var e={};return En(m,function(t,s){ze.call(m.prototype,s)||(e[s]=t)}),e})(),{chain:!1}),m.VERSION=o,on(["bind","bindKey","curry","curryRight","partial","partialRight"],function(e){m[e].placeholder=m}),on(["drop","take"],function(e,t){Ie.prototype[e]=function(s){s=s===r?1:vt(Ee(s),0);var c=this.__filtered__&&!t?new Ie(this):this.clone();return c.__filtered__?c.__takeCount__=Nt(s,c.__takeCount__):c.__views__.push({size:Nt(s,Z),type:e+(c.__dir__<0?"Right":"")}),c},Ie.prototype[e+"Right"]=function(s){return this.reverse()[e](s).reverse()}}),on(["filter","map","takeWhile"],function(e,t){var s=t+1,c=s==G||s==R;Ie.prototype[e]=function(d){var x=this.clone();return x.__iteratees__.push({iteratee:fe(d,3),type:s}),x.__filtered__=x.__filtered__||c,x}}),on(["head","last"],function(e,t){var s="take"+(t?"Right":"");Ie.prototype[e]=function(){return this[s](1).value()[0]}}),on(["initial","tail"],function(e,t){var s="drop"+(t?"":"Right");Ie.prototype[e]=function(){return this.__filtered__?new Ie(this):this[s](1)}}),Ie.prototype.compact=function(){return this.filter(Wt)},Ie.prototype.find=function(e){return this.filter(e).head()},Ie.prototype.findLast=function(e){return this.reverse().find(e)},Ie.prototype.invokeMap=ke(function(e,t){return typeof e=="function"?new Ie(this):this.map(function(s){return Vr(s,e,t)})}),Ie.prototype.reject=function(e){return this.filter(ti(fe(e)))},Ie.prototype.slice=function(e,t){e=Ee(e);var s=this;return s.__filtered__&&(e>0||t<0)?new Ie(s):(e<0?s=s.takeRight(-e):e&&(s=s.drop(e)),t!==r&&(t=Ee(t),s=t<0?s.dropRight(-t):s.take(t-e)),s)},Ie.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},Ie.prototype.toArray=function(){return this.take(Z)},En(Ie.prototype,function(e,t){var s=/^(?: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 Ie,U=E[0],z=k||be(w),Y=function(Re){var De=d.apply(m,zn([Re],E));return c&&te?De[0]:De};z&&s&&typeof U=="function"&&U.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 Ie(this);var pe=e.apply(w,E);return pe.__actions__.push({func:Qs,args:[Y],thisArg:r}),new ln(pe,te)}return he&&Ne?e.apply(this,E):(pe=this.thru(Y),he?c?pe.value()[0]:pe.value():pe)})}),on(["pop","push","shift","sort","splice","unshift"],function(e){var t=Es[e],s=/^(?: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[s](function(w){return t.apply(be(w)?w:[],d)})}}),En(Ie.prototype,function(e,t){var s=m[t];if(s){var c=s.name+"";ze.call(Nr,c)||(Nr[c]=[]),Nr[c].push({name:t,func:s})}}),Nr[Gs(r,I).name]=[{name:"wrapper",func:r}],Ie.prototype.clone=Zh,Ie.prototype.reverse=ep,Ie.prototype.value=tp,m.prototype.at=A0,m.prototype.chain=P0,m.prototype.commit=j0,m.prototype.next=I0,m.prototype.plant=M0,m.prototype.reverse=L0,m.prototype.toJSON=m.prototype.valueOf=m.prototype.value=O0,m.prototype.first=m.prototype.head,zr&&(m.prototype[zr]=D0),m}),wr=jh();or?((or.exports=wr)._=wr,Bi._=wr):Et._=wr}).call(F1)})(os,os.exports)),os.exports}var Ld=B1();const U1=U_(Ld);function W1(i,n){const[r,o]=v.useState(i),u=v.useRef(U1.debounce(o,n)),l=v.useCallback(h=>{u.current(h)},[]);return[r,l]}const z1=()=>{try{const i=localStorage.getItem("sidebar-collapsed");return i!==null?JSON.parse(i):!1}catch(i){return console.warn("Failed to load sidebar collapsed state:",i),!1}};function H1({devices:i,currentDeviceId:n,onSelectDevice:r,onOpenConfig:o,onConnectWifi:u,onDisconnectWifi:l}){const h=Mr(),[b,f]=v.useState(z1),[g,p]=v.useState(!1),[_,y]=v.useState(""),[S,N]=v.useState("5555"),[P,T]=v.useState(""),[I,F]=v.useState(""),[A,$]=v.useState("direct"),[q,X]=v.useState(""),[K,V]=v.useState(""),[O,B]=v.useState("5555"),[M,me]=v.useState(""),[ye,G]=v.useState(!1),[J,R]=v.useState([]),[W,oe]=W1(!1,300),[de,ue]=v.useState(""),[Z,Se]=v.useState(null),[Pe,Fe]=v.useState(!1),Le=v.useRef(null);v.useEffect(()=>{localStorage.setItem("sidebar-collapsed",JSON.stringify(b))},[b]),v.useEffect(()=>{const D=ee=>{(ee.metaKey||ee.ctrlKey)&&ee.key==="b"&&(ee.preventDefault(),f(!b))};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[b]);const at=()=>{f(!b)},lt=D=>/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(D)?D.split(".").every(ce=>{const Ce=parseInt(ce,10);return Ce>=0&&Ce<=255}):!1,Ge=D=>{const ee=parseInt(D,10);return!isNaN(ee)&&ee>=1&&ee<=65535},Te=D=>/^\d{6}$/.test(D),$e=async()=>{T(""),F("");let D=!1;if(lt(_)||(T(h.deviceSidebar.invalidIpError),D=!0),Ge(S)||(F(h.deviceSidebar.invalidPortError),D=!0),!D){G(!0);try{const ee=await lu({ip:_,port:parseInt(S,10)});ee.success?(p(!1),y(""),N("5555")):T(ee.message||h.toasts.wifiManualConnectError)}catch{T(h.toasts.wifiManualConnectError)}finally{G(!1)}}},mt=async()=>{me(""),T(""),F("");let D=!1;if(lt(_)||(T(h.deviceSidebar.invalidIpError),D=!0),Ge(K)||(F(h.deviceSidebar.invalidPortError),D=!0),Ge(O)||(F(h.deviceSidebar.invalidPortError),D=!0),Te(q)||(me(h.deviceSidebar.invalidPairingCodeError),D=!0),!D){G(!0);try{const ee=await $_({ip:_,pairing_port:parseInt(K,10),pairing_code:q,connection_port:parseInt(O,10)});ee.success?(p(!1),y(""),N("5555"),X(""),V(""),B("5555"),$("direct")):ee.error==="invalid_pairing_code"?me(ee.message):ee.error==="invalid_ip"?T(ee.message):T(ee.message||h.toasts.wifiPairError)}catch{T(h.toasts.wifiPairError)}finally{G(!1)}}},tt=v.useCallback(()=>{Le.current!==null&&(clearInterval(Le.current),Le.current=null)},[]),Tt=v.useCallback(D=>{tt(),Le.current=window.setInterval(async()=>{try{const ee=await W_(D);Se(le=>le?{...le,status:ee.status}:null),["connected","timeout","error"].includes(ee.status)&&(tt(),ee.status==="connected"&&setTimeout(()=>{p(!1),Se(null)},2e3))}catch(ee){console.error("[QR Pairing] Status poll failed:",ee)}},1e3)},[tt]),Xe=v.useCallback(async()=>{Fe(!0);try{const D=await z_();D.success&&D.qr_payload&&D.session_id&&(Se({sessionId:D.session_id,payload:D.qr_payload,status:"listening",expiresAt:D.expires_at??Date.now()+12e4}),Tt(D.session_id))}catch(D){console.error("[QR Pairing] Generation failed:",D)}finally{Fe(!1)}},[Tt]),gt=v.useCallback(async()=>{if(Z)try{await H_(Z.sessionId),Se(null),tt()}catch(D){console.error("[QR Pairing] Cancel failed:",D)}},[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&&!Pe&&Xe()},[g,A,Z,Pe,Xe]);const ne=v.useCallback(async()=>{oe(!0),ue("");try{const D=await G_();D.success?R(D.devices):(ue(D.error||h.deviceSidebar.scanError.replace("{error}","Unknown error")),R([]))}catch(D){ue(h.deviceSidebar.scanError.replace("{error}",String(D))),R([])}finally{oe(!1)}},[h.deviceSidebar.scanError,oe]),re=async(D,ee)=>{if(!ee&&!D.has_pairing){G(!0),T("");try{const le=await lu({ip:D.ip,port:D.port});le.success?p(!1):T(le.message||h.toasts.wifiManualConnectError)}catch(le){T(h.toasts.wifiManualConnectError),console.error("[DeviceSidebar] Error connecting:",le)}finally{G(!1)}}else ee&&D.has_pairing&&(y(D.ip),V(D.pairing_port?String(D.pairing_port):""),B(String(D.port)),setTimeout(()=>{document.getElementById("pairing-code")?.focus()},100))};return v.useEffect(()=>{if(g){ne();const D=setInterval(()=>{ne()},5e3);return()=>{clearInterval(D)}}},[g,ne]),a.jsxs(a.Fragment,{children:[b&&a.jsx(_e,{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:a.jsx(Sa,{className:"h-4 w-4"})}),a.jsxs("div",{className:`
25
+ ${b?"w-0 -ml-4 opacity-0":"w-80 opacity-100"}
26
+ transition-all duration-300 ease-in-out
27
+ h-full min-h-0
28
+ bg-white dark:bg-slate-950
29
+ border-r border-slate-200 dark:border-slate-800
30
+ flex flex-col
31
+ overflow-hidden
32
+ `,children:[a.jsxs("div",{className:"flex items-center justify-between p-4",children:[a.jsx("div",{className:"flex items-center gap-2",children:a.jsxs("div",{children:[a.jsx("h2",{className:"text-base font-bold text-slate-900 dark:text-slate-100",children:"AutoGLM"}),a.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:[i.length," ",(i.length===1,h.deviceSidebar.devices)]})]})}),a.jsx(_e,{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:a.jsx(Ea,{className:"h-4 w-4"})})]}),a.jsx(ns,{className:"mx-4"}),a.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-2 min-h-0",children:i.length===0?a.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[a.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800",children:a.jsx(Hv,{className:"h-8 w-8 text-slate-400"})}),a.jsx("p",{className:"mt-4 font-medium text-slate-900 dark:text-slate-100",children:h.deviceSidebar.noDevicesConnected}),a.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:h.deviceSidebar.clickToRefresh})]}):i.map(D=>a.jsx(o1,{id:D.id,serial:D.serial,model:D.model,status:D.status,connectionType:D.connection_type,agent:D.agent,isActive:n===D.id,onClick:()=>r(D.id),onConnectWifi:async()=>{await u(D.id)},onDisconnectWifi:async()=>{await l(D.id)}},D.id))}),a.jsx(ns,{className:"mx-4"}),a.jsxs("div",{className:"p-3 space-y-2",children:[a.jsxs(_e,{variant:"outline",onClick:()=>p(!0),className:"w-full justify-start gap-2 rounded-full border-slate-200 dark:border-slate-700",children:[a.jsx(mv,{className:"h-4 w-4"}),h.deviceSidebar.addDevice]}),a.jsxs(_e,{variant:"outline",onClick:o,className:"w-full justify-start gap-2 rounded-full border-slate-200 dark:border-slate-700",children:[a.jsx(sd,{className:"h-4 w-4"}),h.deviceSidebar.settings]})]}),a.jsx(qu,{open:g,onOpenChange:p,children:a.jsxs(Xu,{className:"sm:max-w-md max-h-[80vh] overflow-y-auto",children:[a.jsxs(Yu,{children:[a.jsx(Vu,{children:h.deviceSidebar.manualConnectTitle}),a.jsx(Ku,{children:h.deviceSidebar.manualConnectDescription})]}),a.jsxs(k1,{value:A,onValueChange:$,className:"w-full",children:[a.jsxs(T1,{className:"grid w-full grid-cols-2",children:[a.jsx(gu,{value:"direct",children:h.deviceSidebar.directConnectTab}),a.jsx(gu,{value:"pair",children:h.deviceSidebar.pairTab})]}),a.jsxs(xu,{value:"direct",className:"space-y-4 mt-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:h.deviceSidebar.discoveredDevices}),a.jsx(_e,{variant:"outline",size:"sm",onClick:ne,disabled:W,className:"h-8",children:W?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mr-2 h-3 w-3 animate-spin rounded-full border-2 border-slate-400 border-t-transparent"}),h.deviceSidebar.scanning]}):h.deviceSidebar.scanAgain})]}),de&&a.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-950/20 p-3",children:a.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:de})}),(()=>{const D=J.filter(ee=>!ee.has_pairing);return!W&&D.length===0?a.jsxs("div",{className:"rounded-lg bg-slate-50 dark:bg-slate-900 p-4 text-center",children:[a.jsx(ca,{className:"mx-auto h-8 w-8 text-slate-400"}),a.jsx("p",{className:"mt-2 text-sm text-slate-500 dark:text-slate-400",children:h.deviceSidebar.noDirectDevices})]}):D.length>0?a.jsx("div",{className:"space-y-2",children:D.map(ee=>a.jsx("button",{onClick:()=>re(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:a.jsx("div",{className:"flex items-start justify-between",children:a.jsxs("div",{className:"flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(la,{className:"h-4 w-4 text-[#1d9bf0]"}),a.jsx("span",{className:"font-medium text-slate-900 dark:text-slate-100",children:ee.name})]}),a.jsxs("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:[ee.ip,":",ee.port]})]})})},`${ee.ip}:${ee.port}`))}):null})(),P&&A==="direct"&&a.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-950/20 p-3",children:a.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:P})}),a.jsxs("div",{className:"relative my-4",children:[a.jsx(ns,{}),a.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:h.deviceSidebar.orManualConnect})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("div",{className:"rounded-lg bg-amber-50 dark:bg-amber-950/20 p-3 text-sm",children:a.jsx("p",{className:"text-amber-800 dark:text-amber-200",children:h.deviceSidebar.directConnectNote})}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"ip",children:h.deviceSidebar.ipAddress}),a.jsx(hn,{id:"ip",placeholder:"192.168.1.100",value:_,onChange:D=>y(D.target.value),onKeyDown:D=>D.key==="Enter"&&$e(),className:P?"border-red-500":""})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"port",children:h.deviceSidebar.port}),a.jsx(hn,{id:"port",type:"number",value:S,onChange:D=>N(D.target.value),onKeyDown:D=>D.key==="Enter"&&$e(),className:I?"border-red-500":""}),I&&a.jsx("p",{className:"text-sm text-red-500",children:I})]}),a.jsx(_e,{onClick:$e,disabled:ye,className:"w-full",children:ye?h.common.loading:h.deviceSidebar.connect})]})]}),a.jsxs(xu,{value:"pair",className:"space-y-4 mt-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:h.deviceSidebar.discoveredDevices}),a.jsx(_e,{variant:"outline",size:"sm",onClick:ne,disabled:W,className:"h-8",children:W?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mr-2 h-3 w-3 animate-spin rounded-full border-2 border-slate-400 border-t-transparent"}),h.deviceSidebar.scanning]}):h.deviceSidebar.scanAgain})]}),de&&a.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-950/20 p-3",children:a.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:de})}),(()=>{const D=J.filter(ee=>ee.has_pairing);return!W&&D.length===0?a.jsxs("div",{className:"rounded-lg bg-slate-50 dark:bg-slate-900 p-4 text-center",children:[a.jsx(ca,{className:"mx-auto h-8 w-8 text-slate-400"}),a.jsx("p",{className:"mt-2 text-sm text-slate-500 dark:text-slate-400",children:h.deviceSidebar.noPairingDevices})]}):D.length>0?a.jsx("div",{className:"space-y-2",children:D.map(ee=>a.jsx("button",{onClick:()=>re(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:a.jsx("div",{className:"flex items-start justify-between",children:a.jsxs("div",{className:"flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(la,{className:"h-4 w-4 text-[#1d9bf0]"}),a.jsx("span",{className:"font-medium text-slate-900 dark:text-slate-100",children:ee.name})]}),a.jsxs("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:[ee.ip,":",ee.port]}),a.jsxs("div",{className:"mt-2 flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400",children:[a.jsx(Cn,{className:"h-3 w-3"}),a.jsx("span",{children:h.deviceSidebar.pairingRequired})]})]})})},`${ee.ip}:${ee.port}`))}):null})(),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"relative my-4",children:[a.jsx(ns,{}),a.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:h.deviceSidebar.orQrPair})]}),a.jsxs("div",{className:"rounded-lg bg-purple-50 dark:bg-purple-950/20 p-3 text-sm",children:[a.jsx("p",{className:"font-medium text-purple-900 dark:text-purple-100 mb-2",children:h.deviceSidebar.qrPairingTitle}),a.jsxs("ol",{className:"space-y-1 text-purple-700 dark:text-purple-300 text-xs",children:[a.jsx("li",{children:h.deviceSidebar.qrStep1}),a.jsx("li",{children:h.deviceSidebar.qrStep2}),a.jsx("li",{children:h.deviceSidebar.qrStep3})]})]}),Z&&a.jsx("div",{className:"rounded-lg border border-slate-200 dark:border-slate-700 p-4 bg-white dark:bg-slate-900",children:a.jsxs("div",{className:"flex flex-col items-center space-y-3",children:[a.jsx("div",{className:"bg-white p-4 rounded-lg",children:a.jsx(Md,{value:Z.payload,size:200,level:"M"})}),a.jsxs("div",{className:"flex items-center gap-2",children:[Z.status==="listening"&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"h-2 w-2 rounded-full bg-blue-500 animate-pulse"}),a.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:h.deviceSidebar.qrWaitingForScan})]}),Z.status==="pairing"&&a.jsxs(a.Fragment,{children:[a.jsx(Jt,{className:"h-4 w-4 animate-spin text-blue-500"}),a.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:h.deviceSidebar.qrPairing})]}),Z.status==="connected"&&a.jsxs(a.Fragment,{children:[a.jsx(Rv,{className:"h-4 w-4 text-green-500"}),a.jsx("span",{className:"text-sm text-green-600 dark:text-green-400",children:h.deviceSidebar.qrConnected})]}),Z.status==="timeout"&&a.jsxs(a.Fragment,{children:[a.jsx(hi,{className:"h-4 w-4 text-amber-500"}),a.jsx("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:h.deviceSidebar.qrTimeout})]}),Z.status==="error"&&a.jsxs(a.Fragment,{children:[a.jsx(hi,{className:"h-4 w-4 text-red-500"}),a.jsx("span",{className:"text-sm text-red-600 dark:text-red-400",children:h.deviceSidebar.qrError})]})]}),a.jsxs("div",{className:"flex gap-2 w-full",children:[(Z.status==="timeout"||Z.status==="error")&&a.jsx(_e,{variant:"outline",onClick:Xe,className:"flex-1",children:h.deviceSidebar.qrRegenerate}),Z.status==="listening"&&a.jsx(_e,{variant:"outline",onClick:gt,className:"flex-1",children:h.common.cancel}),Z.status==="connected"&&a.jsx(_e,{onClick:()=>p(!1),className:"flex-1",children:h.common.confirm})]})]})}),!Z&&Pe&&a.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-slate-600 dark:text-slate-400",children:[a.jsx(Jt,{className:"h-4 w-4 animate-spin"}),a.jsx("span",{className:"text-sm",children:h.common.loading})]})]}),a.jsxs("div",{className:"relative my-4",children:[a.jsx(ns,{}),a.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:h.deviceSidebar.orManualPair})]}),a.jsxs("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-950/20 p-3 text-sm",children:[a.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100 mb-2",children:h.deviceSidebar.pairingInstructions}),a.jsxs("ol",{className:"space-y-1 text-blue-700 dark:text-blue-300 text-xs",children:[a.jsx("li",{children:h.deviceSidebar.pairingStep1}),a.jsx("li",{children:h.deviceSidebar.pairingStep2}),a.jsx("li",{children:h.deviceSidebar.pairingStep3}),a.jsx("li",{children:h.deviceSidebar.pairingStep4})]}),a.jsx("p",{className:"mt-2 text-xs text-blue-600 dark:text-blue-400",children:h.deviceSidebar.pairingNote})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"pair-ip",children:h.deviceSidebar.ipAddress}),a.jsx(hn,{id:"pair-ip",placeholder:"192.168.1.100",value:_,onChange:D=>y(D.target.value),className:P?"border-red-500":""}),P&&A==="pair"&&a.jsx("p",{className:"text-sm text-red-500",children:P})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"pairing-port",children:h.deviceSidebar.pairingPort}),a.jsx(hn,{id:"pairing-port",type:"number",placeholder:"37831",value:K,onChange:D=>V(D.target.value),className:I?"border-red-500":""}),I&&a.jsx("p",{className:"text-sm text-red-500",children:I})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"pairing-code",children:h.deviceSidebar.pairingCode}),a.jsx(hn,{id:"pairing-code",type:"text",placeholder:"123456",maxLength:6,value:q,onChange:D=>X(D.target.value.replace(/\D/g,"")),onKeyDown:D=>D.key==="Enter"&&mt(),className:M?"border-red-500":""}),M&&a.jsx("p",{className:"text-sm text-red-500",children:M})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"connection-port",children:h.deviceSidebar.connectionPort}),a.jsx(hn,{id:"connection-port",type:"number",value:O,onChange:D=>B(D.target.value),onKeyDown:D=>D.key==="Enter"&&mt()})]}),a.jsx(_e,{onClick:mt,disabled:ye,className:"w-full",children:ye?h.common.loading:h.deviceSidebar.pairAndConnect})]})]})]}),a.jsx(Qu,{children:a.jsx(_e,{variant:"outline",onClick:()=>{p(!1),T(""),F(""),me(""),ue(""),y(""),N("5555"),X(""),V(""),B("5555"),$("direct"),R([])},children:h.common.cancel})})]})})]})]})}const Rn=Object.create(null);Rn.open="0";Rn.close="1";Rn.ping="2";Rn.pong="3";Rn.message="4";Rn.upgrade="5";Rn.noop="6";const li=Object.create(null);Object.keys(Rn).forEach(i=>{li[Rn[i]]=i});const pa={type:"error",data:"parser error"},Od=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",Fd=typeof ArrayBuffer=="function",Bd=i=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(i):i&&i.buffer instanceof ArrayBuffer,ka=({type:i,data:n},r,o)=>Od&&n instanceof Blob?r?o(n):bu(n,o):Fd&&(n instanceof ArrayBuffer||Bd(n))?r?o(n):bu(new Blob([n]),o):o(Rn[i]+(n||"")),bu=(i,n)=>{const r=new FileReader;return r.onload=function(){const o=r.result.split(",")[1];n("b"+(o||""))},r.readAsDataURL(i)};function yu(i){return i instanceof Uint8Array?i:i instanceof ArrayBuffer?new Uint8Array(i):new Uint8Array(i.buffer,i.byteOffset,i.byteLength)}let qo;function G1(i,n){if(Od&&i.data instanceof Blob)return i.data.arrayBuffer().then(yu).then(n);if(Fd&&(i.data instanceof ArrayBuffer||Bd(i.data)))return n(yu(i.data));ka(i,!1,r=>{qo||(qo=new TextEncoder),n(qo.encode(r))})}const wu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",as=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let i=0;i<wu.length;i++)as[wu.charCodeAt(i)]=i;const $1=i=>{let n=i.length*.75,r=i.length,o,u=0,l,h,b,f;i[i.length-1]==="="&&(n--,i[i.length-2]==="="&&n--);const g=new ArrayBuffer(n),p=new Uint8Array(g);for(o=0;o<r;o+=4)l=as[i.charCodeAt(o)],h=as[i.charCodeAt(o+1)],b=as[i.charCodeAt(o+2)],f=as[i.charCodeAt(o+3)],p[u++]=l<<2|h>>4,p[u++]=(h&15)<<4|b>>2,p[u++]=(b&3)<<6|f&63;return g},q1=typeof ArrayBuffer=="function",Ta=(i,n)=>{if(typeof i!="string")return{type:"message",data:Ud(i,n)};const r=i.charAt(0);return r==="b"?{type:"message",data:X1(i.substring(1),n)}:li[r]?i.length>1?{type:li[r],data:i.substring(1)}:{type:li[r]}:pa},X1=(i,n)=>{if(q1){const r=$1(i);return Ud(r,n)}else return{base64:!0,data:i}},Ud=(i,n)=>{switch(n){case"blob":return i instanceof Blob?i:new Blob([i]);case"arraybuffer":default:return i instanceof ArrayBuffer?i:i.buffer}},Wd="",Y1=(i,n)=>{const r=i.length,o=new Array(r);let u=0;i.forEach((l,h)=>{ka(l,!1,b=>{o[h]=b,++u===r&&n(o.join(Wd))})})},V1=(i,n)=>{const r=i.split(Wd),o=[];for(let u=0;u<r.length;u++){const l=Ta(r[u],n);if(o.push(l),l.type==="error")break}return o};function K1(){return new TransformStream({transform(i,n){G1(i,r=>{const o=r.length;let u;if(o<126)u=new Uint8Array(1),new DataView(u.buffer).setUint8(0,o);else if(o<65536){u=new Uint8Array(3);const l=new DataView(u.buffer);l.setUint8(0,126),l.setUint16(1,o)}else{u=new Uint8Array(9);const l=new DataView(u.buffer);l.setUint8(0,127),l.setBigUint64(1,BigInt(o))}i.data&&typeof i.data!="string"&&(u[0]|=128),n.enqueue(u),n.enqueue(r)})}})}let Xo;function oi(i){return i.reduce((n,r)=>n+r.length,0)}function ai(i,n){if(i[0].length===n)return i.shift();const r=new Uint8Array(n);let o=0;for(let u=0;u<n;u++)r[u]=i[0][o++],o===i[0].length&&(i.shift(),o=0);return i.length&&o<i[0].length&&(i[0]=i[0].slice(o)),r}function Q1(i,n){Xo||(Xo=new TextDecoder);const r=[];let o=0,u=-1,l=!1;return new TransformStream({transform(h,b){for(r.push(h);;){if(o===0){if(oi(r)<1)break;const f=ai(r,1);l=(f[0]&128)===128,u=f[0]&127,u<126?o=3:u===126?o=1:o=2}else if(o===1){if(oi(r)<2)break;const f=ai(r,2);u=new DataView(f.buffer,f.byteOffset,f.length).getUint16(0),o=3}else if(o===2){if(oi(r)<8)break;const f=ai(r,8),g=new DataView(f.buffer,f.byteOffset,f.length),p=g.getUint32(0);if(p>Math.pow(2,21)-1){b.enqueue(pa);break}u=p*Math.pow(2,32)+g.getUint32(4),o=3}else{if(oi(r)<u)break;const f=ai(r,u);b.enqueue(Ta(l?f:Xo.decode(f),n)),o=0}if(u===0||u>i){b.enqueue(pa);break}}}})}const zd=4;function pt(i){if(i)return J1(i)}function J1(i){for(var n in pt.prototype)i[n]=pt.prototype[n];return i}pt.prototype.on=pt.prototype.addEventListener=function(i,n){return this._callbacks=this._callbacks||{},(this._callbacks["$"+i]=this._callbacks["$"+i]||[]).push(n),this};pt.prototype.once=function(i,n){function r(){this.off(i,r),n.apply(this,arguments)}return r.fn=n,this.on(i,r),this};pt.prototype.off=pt.prototype.removeListener=pt.prototype.removeAllListeners=pt.prototype.removeEventListener=function(i,n){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var r=this._callbacks["$"+i];if(!r)return this;if(arguments.length==1)return delete this._callbacks["$"+i],this;for(var o,u=0;u<r.length;u++)if(o=r[u],o===n||o.fn===n){r.splice(u,1);break}return r.length===0&&delete this._callbacks["$"+i],this};pt.prototype.emit=function(i){this._callbacks=this._callbacks||{};for(var n=new Array(arguments.length-1),r=this._callbacks["$"+i],o=1;o<arguments.length;o++)n[o-1]=arguments[o];if(r){r=r.slice(0);for(var o=0,u=r.length;o<u;++o)r[o].apply(this,n)}return this};pt.prototype.emitReserved=pt.prototype.emit;pt.prototype.listeners=function(i){return this._callbacks=this._callbacks||{},this._callbacks["$"+i]||[]};pt.prototype.hasListeners=function(i){return!!this.listeners(i).length};const Ei=typeof Promise=="function"&&typeof Promise.resolve=="function"?n=>Promise.resolve().then(n):(n,r)=>r(n,0),pn=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Z1="arraybuffer";function Hd(i,...n){return n.reduce((r,o)=>(i.hasOwnProperty(o)&&(r[o]=i[o]),r),{})}const eb=pn.setTimeout,tb=pn.clearTimeout;function Si(i,n){n.useNativeTimers?(i.setTimeoutFn=eb.bind(pn),i.clearTimeoutFn=tb.bind(pn)):(i.setTimeoutFn=pn.setTimeout.bind(pn),i.clearTimeoutFn=pn.clearTimeout.bind(pn))}const nb=1.33;function rb(i){return typeof i=="string"?sb(i):Math.ceil((i.byteLength||i.size)*nb)}function sb(i){let n=0,r=0;for(let o=0,u=i.length;o<u;o++)n=i.charCodeAt(o),n<128?r+=1:n<2048?r+=2:n<55296||n>=57344?r+=3:(o++,r+=4);return r}function Gd(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function ib(i){let n="";for(let r in i)i.hasOwnProperty(r)&&(n.length&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(i[r]));return n}function ob(i){let n={},r=i.split("&");for(let o=0,u=r.length;o<u;o++){let l=r[o].split("=");n[decodeURIComponent(l[0])]=decodeURIComponent(l[1])}return n}class ab extends Error{constructor(n,r,o){super(n),this.description=r,this.context=o,this.type="TransportError"}}class Ra extends pt{constructor(n){super(),this.writable=!1,Si(this,n),this.opts=n,this.query=n.query,this.socket=n.socket,this.supportsBinary=!n.forceBase64}onError(n,r,o){return super.emitReserved("error",new ab(n,r,o)),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=Ta(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=ib(n);return r.length?"?"+r:""}}class lb extends Ra{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 o=0;this._polling&&(o++,this.once("pollComplete",function(){--o||r()})),this.writable||(o++,this.once("drain",function(){--o||r()}))}else r()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(n){const r=o=>{if(this.readyState==="opening"&&o.type==="open"&&this.onOpen(),o.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(o)};V1(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,Y1(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]=Gd()),!this.supportsBinary&&!r.sid&&(r.b64=1),this.createUri(n,r)}}let $d=!1;try{$d=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const cb=$d;function ub(){}class db extends lb{constructor(n){if(super(n),typeof location<"u"){const r=location.protocol==="https:";let o=location.port;o||(o=r?"443":"80"),this.xd=typeof location<"u"&&n.hostname!==location.hostname||o!==n.port}}doWrite(n,r){const o=this.request({method:"POST",data:n});o.on("success",r),o.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,o)=>{this.onError("xhr poll error",r,o)}),this.pollXhr=n}}class Tn extends pt{constructor(n,r,o){super(),this.createRequest=n,Si(this,o),this._opts=o,this._method=o.method||"GET",this._uri=r,this._data=o.data!==void 0?o.data:null,this._create()}_create(){var n;const r=Hd(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");r.xdomain=!!this._opts.xd;const o=this._xhr=this.createRequest(r);try{o.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){o.setDisableHeaderCheck&&o.setDisableHeaderCheck(!0);for(let u in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(u)&&o.setRequestHeader(u,this._opts.extraHeaders[u])}}catch{}if(this._method==="POST")try{o.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{o.setRequestHeader("Accept","*/*")}catch{}(n=this._opts.cookieJar)===null||n===void 0||n.addCookies(o),"withCredentials"in o&&(o.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(o.timeout=this._opts.requestTimeout),o.onreadystatechange=()=>{var u;o.readyState===3&&((u=this._opts.cookieJar)===null||u===void 0||u.parseCookies(o.getResponseHeader("set-cookie"))),o.readyState===4&&(o.status===200||o.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof o.status=="number"?o.status:0)},0))},o.send(this._data)}catch(u){this.setTimeoutFn(()=>{this._onError(u)},0);return}typeof document<"u"&&(this._index=Tn.requestsCount++,Tn.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=ub,n)try{this._xhr.abort()}catch{}typeof document<"u"&&delete Tn.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()}}Tn.requestsCount=0;Tn.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",Eu);else if(typeof addEventListener=="function"){const i="onpagehide"in pn?"pagehide":"unload";addEventListener(i,Eu,!1)}}function Eu(){for(let i in Tn.requests)Tn.requests.hasOwnProperty(i)&&Tn.requests[i].abort()}const fb=(function(){const i=qd({xdomain:!1});return i&&i.responseType!==null})();class hb extends db{constructor(n){super(n);const r=n&&n.forceBase64;this.supportsBinary=fb&&!r}request(n={}){return Object.assign(n,{xd:this.xd},this.opts),new Tn(qd,this.uri(),n)}}function qd(i){const n=i.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!n||cb))return new XMLHttpRequest}catch{}if(!n)try{return new pn[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const Xd=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class pb extends Ra{get name(){return"websocket"}doOpen(){const n=this.uri(),r=this.opts.protocols,o=Xd?{}:Hd(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(o.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(n,r,o)}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 o=n[r],u=r===n.length-1;ka(o,this.supportsBinary,l=>{try{this.doWrite(o,l)}catch{}u&&Ei(()=>{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]=Gd()),this.supportsBinary||(r.b64=1),this.createUri(n,r)}}const Yo=pn.WebSocket||pn.MozWebSocket;class mb extends pb{createSocket(n,r,o){return Xd?new Yo(n,r,o):r?new Yo(n,r):new Yo(n)}doWrite(n,r){this.ws.send(r)}}class gb extends Ra{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=Q1(Number.MAX_SAFE_INTEGER,this.socket.binaryType),o=n.readable.pipeThrough(r).getReader(),u=K1();u.readable.pipeTo(n.writable),this._writer=u.writable.getWriter();const l=()=>{o.read().then(({done:b,value:f})=>{b||(this.onPacket(f),l())}).catch(b=>{})};l();const h={type:"open"};this.query.sid&&(h.data=`{"sid":"${this.query.sid}"}`),this._writer.write(h).then(()=>this.onOpen())})})}write(n){this.writable=!1;for(let r=0;r<n.length;r++){const o=n[r],u=r===n.length-1;this._writer.write(o).then(()=>{u&&Ei(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var n;(n=this._transport)===null||n===void 0||n.close()}}const xb={websocket:mb,webtransport:gb,polling:hb},_b=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,vb=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ma(i){if(i.length>8e3)throw"URI too long";const n=i,r=i.indexOf("["),o=i.indexOf("]");r!=-1&&o!=-1&&(i=i.substring(0,r)+i.substring(r,o).replace(/:/g,";")+i.substring(o,i.length));let u=_b.exec(i||""),l={},h=14;for(;h--;)l[vb[h]]=u[h]||"";return r!=-1&&o!=-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=bb(l,l.path),l.queryKey=yb(l,l.query),l}function bb(i,n){const r=/\/{2,9}/g,o=n.replace(r,"/").split("/");return(n.slice(0,1)=="/"||n.length===0)&&o.splice(0,1),n.slice(-1)=="/"&&o.splice(o.length-1,1),o}function yb(i,n){const r={};return n.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(o,u,l){u&&(r[u]=l)}),r}const ga=typeof addEventListener=="function"&&typeof removeEventListener=="function",ci=[];ga&&addEventListener("offline",()=>{ci.forEach(i=>i())},!1);class tr extends pt{constructor(n,r){if(super(),this.binaryType=Z1,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 o=ma(n);r.hostname=o.host,r.secure=o.protocol==="https"||o.protocol==="wss",r.port=o.port,o.query&&(r.query=o.query)}else r.host&&(r.hostname=ma(r.host).host);Si(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(o=>{const u=o.prototype.name;this.transports.push(u),this._transportsByName[u]=o}),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=ob(this.opts.query)),ga&&(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"})},ci.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(n){const r=Object.assign({},this.opts.query);r.EIO=zd,r.transport=n,this.id&&(r.sid=this.id);const o=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](o)}_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 o=0;o<this.writeBuffer.length;o++){const u=this.writeBuffer[o].data;if(u&&(r+=rb(u)),o>0&&r>this._maxPayload)return this.writeBuffer.slice(0,o);r+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const n=Date.now()>this._pingTimeoutTime;return n&&(this._pingTimeoutTime=0,Ei(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),n}write(n,r,o){return this._sendPacket("message",n,r,o),this}send(n,r,o){return this._sendPacket("message",n,r,o),this}_sendPacket(n,r,o,u){if(typeof r=="function"&&(u=r,r=void 0),typeof o=="function"&&(u=o,o=null),this.readyState==="closing"||this.readyState==="closed")return;o=o||{},o.compress=o.compress!==!1;const l={type:n,data:r,options:o};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()},o=()=>{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?o():n()}):this.upgrading?o():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(),ga&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const o=ci.indexOf(this._offlineEventListener);o!==-1&&ci.splice(o,1)}this.readyState="closed",this.id=null,this.emitReserved("close",n,r),this.writeBuffer=[],this._prevBufferLen=0}}}tr.protocol=zd;class wb 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),o=!1;tr.priorWebsocketSuccess=!1;const u=()=>{o||(r.send([{type:"ping",data:"probe"}]),r.once("packet",_=>{if(!o)if(_.type==="pong"&&_.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",r),!r)return;tr.priorWebsocketSuccess=r.name==="websocket",this.transport.pause(()=>{o||this.readyState!=="closed"&&(p(),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(){o||(o=!0,p(),r.close(),r=null)}const h=_=>{const y=new Error("probe error: "+_);y.transport=r.name,l(),this.emitReserved("upgradeError",y)};function b(){h("transport closed")}function f(){h("socket closed")}function g(_){r&&_.name!==r.name&&l()}const p=()=>{r.removeListener("open",u),r.removeListener("error",h),r.removeListener("close",b),this.off("close",f),this.off("upgrading",g)};r.once("open",u),r.once("error",h),r.once("close",b),this.once("close",f),this.once("upgrading",g),this._upgrades.indexOf("webtransport")!==-1&&n!=="webtransport"?this.setTimeoutFn(()=>{o||r.open()},200):r.open()}onHandshake(n){this._upgrades=this._filterUpgrades(n.upgrades),super.onHandshake(n)}_filterUpgrades(n){const r=[];for(let o=0;o<n.length;o++)~this.transports.indexOf(n[o])&&r.push(n[o]);return r}}let Eb=class extends wb{constructor(n,r={}){const o=typeof n=="object"?n:r;(!o.transports||o.transports&&typeof o.transports[0]=="string")&&(o.transports=(o.transports||["polling","websocket","webtransport"]).map(u=>xb[u]).filter(u=>!!u)),super(n,o)}};function Sb(i,n="",r){let o=i;r=r||typeof location<"u"&&location,i==null&&(i=r.protocol+"//"+r.host),typeof i=="string"&&(i.charAt(0)==="/"&&(i.charAt(1)==="/"?i=r.protocol+i:i=r.host+i),/^(https?|wss?):\/\//.test(i)||(typeof r<"u"?i=r.protocol+"//"+i:i="https://"+i),o=ma(i)),o.port||(/^(http|ws)$/.test(o.protocol)?o.port="80":/^(http|ws)s$/.test(o.protocol)&&(o.port="443")),o.path=o.path||"/";const l=o.host.indexOf(":")!==-1?"["+o.host+"]":o.host;return o.id=o.protocol+"://"+l+":"+o.port+n,o.href=o.protocol+"://"+l+(r&&r.port===o.port?"":":"+o.port),o}const Nb=typeof ArrayBuffer=="function",Cb=i=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(i):i.buffer instanceof ArrayBuffer,Yd=Object.prototype.toString,kb=typeof Blob=="function"||typeof Blob<"u"&&Yd.call(Blob)==="[object BlobConstructor]",Tb=typeof File=="function"||typeof File<"u"&&Yd.call(File)==="[object FileConstructor]";function Aa(i){return Nb&&(i instanceof ArrayBuffer||Cb(i))||kb&&i instanceof Blob||Tb&&i instanceof File}function ui(i,n){if(!i||typeof i!="object")return!1;if(Array.isArray(i)){for(let r=0,o=i.length;r<o;r++)if(ui(i[r]))return!0;return!1}if(Aa(i))return!0;if(i.toJSON&&typeof i.toJSON=="function"&&arguments.length===1)return ui(i.toJSON(),!0);for(const r in i)if(Object.prototype.hasOwnProperty.call(i,r)&&ui(i[r]))return!0;return!1}function Rb(i){const n=[],r=i.data,o=i;return o.data=xa(r,n),o.attachments=n.length,{packet:o,buffers:n}}function xa(i,n){if(!i)return i;if(Aa(i)){const r={_placeholder:!0,num:n.length};return n.push(i),r}else if(Array.isArray(i)){const r=new Array(i.length);for(let o=0;o<i.length;o++)r[o]=xa(i[o],n);return r}else if(typeof i=="object"&&!(i instanceof Date)){const r={};for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&(r[o]=xa(i[o],n));return r}return i}function Ab(i,n){return i.data=_a(i.data,n),delete i.attachments,i}function _a(i,n){if(!i)return i;if(i&&i._placeholder===!0){if(typeof i.num=="number"&&i.num>=0&&i.num<n.length)return n[i.num];throw new Error("illegal attachments")}else if(Array.isArray(i))for(let r=0;r<i.length;r++)i[r]=_a(i[r],n);else if(typeof i=="object")for(const r in i)Object.prototype.hasOwnProperty.call(i,r)&&(i[r]=_a(i[r],n));return i}const Pb=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],jb=5;var Me;(function(i){i[i.CONNECT=0]="CONNECT",i[i.DISCONNECT=1]="DISCONNECT",i[i.EVENT=2]="EVENT",i[i.ACK=3]="ACK",i[i.CONNECT_ERROR=4]="CONNECT_ERROR",i[i.BINARY_EVENT=5]="BINARY_EVENT",i[i.BINARY_ACK=6]="BINARY_ACK"})(Me||(Me={}));class Ib{constructor(n){this.replacer=n}encode(n){return(n.type===Me.EVENT||n.type===Me.ACK)&&ui(n)?this.encodeAsBinary({type:n.type===Me.EVENT?Me.BINARY_EVENT:Me.BINARY_ACK,nsp:n.nsp,data:n.data,id:n.id}):[this.encodeAsString(n)]}encodeAsString(n){let r=""+n.type;return(n.type===Me.BINARY_EVENT||n.type===Me.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=Rb(n),o=this.encodeAsString(r.packet),u=r.buffers;return u.unshift(o),u}}function Su(i){return Object.prototype.toString.call(i)==="[object Object]"}class Pa 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 o=r.type===Me.BINARY_EVENT;o||r.type===Me.BINARY_ACK?(r.type=o?Me.EVENT:Me.ACK,this.reconstructor=new Db(r),r.attachments===0&&super.emitReserved("decoded",r)):super.emitReserved("decoded",r)}else if(Aa(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 o={type:Number(n.charAt(0))};if(Me[o.type]===void 0)throw new Error("unknown packet type "+o.type);if(o.type===Me.BINARY_EVENT||o.type===Me.BINARY_ACK){const l=r+1;for(;n.charAt(++r)!=="-"&&r!=n.length;);const h=n.substring(l,r);if(h!=Number(h)||n.charAt(r)!=="-")throw new Error("Illegal attachments");o.attachments=Number(h)}if(n.charAt(r+1)==="/"){const l=r+1;for(;++r&&!(n.charAt(r)===","||r===n.length););o.nsp=n.substring(l,r)}else o.nsp="/";const u=n.charAt(r+1);if(u!==""&&Number(u)==u){const l=r+1;for(;++r;){const h=n.charAt(r);if(h==null||Number(h)!=h){--r;break}if(r===n.length)break}o.id=Number(n.substring(l,r+1))}if(n.charAt(++r)){const l=this.tryParse(n.substr(r));if(Pa.isPayloadValid(o.type,l))o.data=l;else throw new Error("invalid payload")}return o}tryParse(n){try{return JSON.parse(n,this.reviver)}catch{return!1}}static isPayloadValid(n,r){switch(n){case Me.CONNECT:return Su(r);case Me.DISCONNECT:return r===void 0;case Me.CONNECT_ERROR:return typeof r=="string"||Su(r);case Me.EVENT:case Me.BINARY_EVENT:return Array.isArray(r)&&(typeof r[0]=="number"||typeof r[0]=="string"&&Pb.indexOf(r[0])===-1);case Me.ACK:case Me.BINARY_ACK:return Array.isArray(r)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Db{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=Ab(this.reconPack,this.buffers);return this.finishedReconstruction(),r}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Mb=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Pa,Encoder:Ib,get PacketType(){return Me},protocol:jb},Symbol.toStringTag,{value:"Module"}));function bn(i,n,r){return i.on(n,r),function(){i.off(n,r)}}const Lb=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Vd extends pt{constructor(n,r,o){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,o&&o.auth&&(this.auth=o.auth),this._opts=Object.assign({},o),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const n=this.io;this.subs=[bn(n,"open",this.onopen.bind(this)),bn(n,"packet",this.onpacket.bind(this)),bn(n,"error",this.onerror.bind(this)),bn(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 o,u,l;if(Lb.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 h={type:Me.EVENT,data:r};if(h.options={},h.options.compress=this.flags.compress!==!1,typeof r[r.length-1]=="function"){const p=this.ids++,_=r.pop();this._registerAckCallback(p,_),h.id=p}const b=(u=(o=this.io.engine)===null||o===void 0?void 0:o.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(h),this.packet(h)):this.sendBuffer.push(h)),this.flags={},this}_registerAckCallback(n,r){var o;const u=(o=this.flags.timeout)!==null&&o!==void 0?o: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),h=(...b)=>{this.io.clearTimeoutFn(l),r.apply(this,b)};h.withError=!0,this.acks[n]=h}emitWithAck(n,...r){return new Promise((o,u)=>{const l=(h,b)=>h?u(h):o(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 o={id:this._queueSeq++,tryCount:0,pending:!1,args:n,flags:Object.assign({fromQueue:!0},this.flags)};n.push((u,...l)=>o!==this._queue[0]?void 0:(u!==null?o.tryCount>this._opts.retries&&(this._queue.shift(),r&&r(u)):(this._queue.shift(),r&&r(null,...l)),o.pending=!1,this._drainQueue())),this._queue.push(o),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:Me.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(o=>String(o.id)===n)){const o=this.acks[n];delete this.acks[n],o.withError&&o.call(this,new Error("socket has been disconnected"))}})}onpacket(n){if(n.nsp===this.nsp)switch(n.type){case Me.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 Me.EVENT:case Me.BINARY_EVENT:this.onevent(n);break;case Me.ACK:case Me.BINARY_ACK:this.onack(n);break;case Me.DISCONNECT:this.ondisconnect();break;case Me.CONNECT_ERROR:this.destroy();const o=new Error(n.data.message);o.data=n.data.data,this.emitReserved("connect_error",o);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 o of r)o.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 o=!1;return function(...u){o||(o=!0,r.packet({type:Me.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:Me.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 o=0;o<r.length;o++)if(n===r[o])return r.splice(o,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 o=0;o<r.length;o++)if(n===r[o])return r.splice(o,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 o of r)o.apply(this,n.data)}}}function Lr(i){i=i||{},this.ms=i.min||100,this.max=i.max||1e4,this.factor=i.factor||2,this.jitter=i.jitter>0&&i.jitter<=1?i.jitter:0,this.attempts=0}Lr.prototype.duration=function(){var i=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var n=Math.random(),r=Math.floor(n*this.jitter*i);i=(Math.floor(n*10)&1)==0?i-r:i+r}return Math.min(i,this.max)|0};Lr.prototype.reset=function(){this.attempts=0};Lr.prototype.setMin=function(i){this.ms=i};Lr.prototype.setMax=function(i){this.max=i};Lr.prototype.setJitter=function(i){this.jitter=i};class va extends pt{constructor(n,r){var o;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,Si(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((o=r.randomizationFactor)!==null&&o!==void 0?o:.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||Mb;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 Eb(this.uri,this.opts);const r=this.engine,o=this;this._readyState="opening",this.skipReconnect=!1;const u=bn(r,"open",function(){o.onopen(),n&&n()}),l=b=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",b),n?n(b):this.maybeReconnectOnOpen()},h=bn(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(h),this}connect(n){return this.open(n)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const n=this.engine;this.subs.push(bn(n,"ping",this.onping.bind(this)),bn(n,"data",this.ondata.bind(this)),bn(n,"error",this.onerror.bind(this)),bn(n,"close",this.onclose.bind(this)),bn(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){Ei(()=>{this.emitReserved("packet",n)},this.setTimeoutFn)}onerror(n){this.emitReserved("error",n)}socket(n,r){let o=this.nsps[n];return o?this._autoConnect&&!o.active&&o.connect():(o=new Vd(this,n,r),this.nsps[n]=o),o}_destroy(n){const r=Object.keys(this.nsps);for(const o of r)if(this.nsps[o].active)return;this._close()}_packet(n){const r=this.encoder.encode(n);for(let o=0;o<r.length;o++)this.engine.write(r[o],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 o;this.cleanup(),(o=this.engine)===null||o===void 0||o.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 o=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&&o.unref(),this.subs.push(()=>{this.clearTimeoutFn(o)})}}onreconnect(){const n=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",n)}}const rs={};function di(i,n){typeof i=="object"&&(n=i,i=void 0),n=n||{};const r=Sb(i,n.path||"/socket.io"),o=r.source,u=r.id,l=r.path,h=rs[u]&&l in rs[u].nsps,b=n.forceNew||n["force new connection"]||n.multiplex===!1||h;let f;return b?f=new va(o,n):(rs[u]||(rs[u]=new va(o,n)),f=rs[u]),r.query&&!n.query&&(n.query=r.queryKey),f.socket(r.path,n)}Object.assign(di,{Manager:va,Socket:Vd,io:di,connect:di});function Ob(i,n){return(i[n]|i[n+1]<<8|i[n+2]<<16|i[n+3]<<24)>>>0}const fi={H264:1748121140,H265:1748121141,AV1:6387249},{WritableStream:Fb}=globalThis;class Bb{#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 Ub={SequenceHeader:1,TemporalDelimiter:2,FrameHeader:3,TileGroup:4,Metadata:5,Frame:6,RedundantFrameHeader:7,TileList:8,Padding:15},Wb={Bt709:1,Unspecified:2,Bt470M:4,Bt470BG:5,Bt601:6,Smpte240:7,GenericFilm:8,Bt2020:9,Xyz:10,Smpte431:11,Smpte432:12,Ebu3213:22},zb={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},Hb={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 kt extends Bb{static ObuType=Ub;static ColorPrimaries=Wb;static TransferCharacteristics=zb;static MatrixCoefficients=Hb;#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 o=this.f(8);if(n|=BigInt(o&127)<<7n*r,this.#e+=1,(o&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 o=this.openBitstreamUnit(r);o&&(yield o),n-=r}}#t=0;openBitstreamUnit(n){const r=this.obuHeader();let o;if(r.obu_has_size_field)o=this.leb128();else if(n!==void 0)o=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!==kt.ObuType.SequenceHeader&&r.obu_type!==kt.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(o));return}}let l;switch(r.obu_type){case kt.ObuType.SequenceHeader:l=this.sequenceHeaderObu();break}const h=this.getPosition(),b=(h[0]-u[0])*8+(u[1]-h[1]);return o>0&&this.skip(Number(o)*8-b),{obu_header:r,obu_size:o,sequence_header_obu:l}}obuHeader(){if(!!this.f1())throw new Error("Invalid data");const r=this.f(4),o=!!this.f1(),u=!!this.f1();this.f1();let l;return o&&(l=this.obuExtensionHeader()),{obu_type:r,obu_extension_flag:o,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(),o=!!this.f1();let u=!1,l,h=!1,b,f=!1,g=0;const p=[],_=[],y=[],S=[],N=[];let P,T;if(o)p[0]=0,_[0]=this.f(5),y[0]=0,S[0]=!1,N[0]=!1;else{u=!!this.f1(),u&&(l=this.timingInfo(),h=!!this.f1(),h&&(b=this.decoderModelInfo(),P=[])),f=!!this.f1(),f&&(T=[]),g=this.f(5);for(let Te=0;Te<=g;Te+=1)p[Te]=this.f(12),_[Te]=this.f(5),_[Te]>7?y[Te]=this.f1():y[Te]=0,h?(S[Te]=!!this.f1(),S[Te]&&(P[Te]=this.operatingParametersInfo(b))):S[Te]=!1,f&&(N[Te]=!!this.f1(),N[Te]&&(T[Te]=this.f(4)))}const I=this.chooseOperatingPoint();this.#t=p[I];const F=this.f(4),A=this.f(4),$=this.f(F+1),q=this.f(A+1);let X=!1,K,V;o||(X=!!this.f1(),X&&(K=this.f(4),V=this.f(3)));const O=!!this.f1(),B=!!this.f1(),M=!!this.f1();let me=!1,ye=!1,G=!1,J=!1,R=!1,W=!1,oe=!1,de=!1,ue=kt.SelectScreenContentTools,Z=!1,Se=kt.SelectIntegerMv,Pe;o||(me=!!this.f1(),ye=!!this.f1(),G=!!this.f1(),J=!!this.f1(),R=!!this.f1(),R&&(W=!!this.f1(),oe=!!this.f1()),de=!!this.f1(),de||(ue=this.f1()),ue>0&&(Z=!!this.f1(),Z||(Se=this.f1())),R&&(Pe=this.f(3)));const Fe=!!this.f1(),Le=!!this.f1(),at=!!this.f1(),lt=this.colorConfig(n),Ge=!!this.f1();return{seq_profile:n,still_picture:r,reduced_still_picture_header:o,timing_info_present_flag:u,timing_info:l,decoder_model_info_present_flag:h,decoder_model_info:b,initial_display_delay_present_flag:f,initial_display_delay_minus_1:T,operating_points_cnt_minus_1:g,operating_point_idc:p,seq_level_idx:_,seq_tier:y,decoder_model_present_for_this_op:S,operating_parameters_info:P,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:$,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:O,enable_filter_intra:B,enable_intra_edge_filter:M,enable_interintra_compound:me,enable_masked_compound:ye,enable_warped_motion:G,enable_dual_filter:J,enable_order_hint:R,enable_jnt_comp:W,enable_ref_frame_mvs:oe,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:Pe,enable_superres:Fe,enable_cdef:Le,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),o=!!this.f1();let u;return o&&(u=this.uvlc()),{num_units_in_display_tick:n,time_scale:r,equal_picture_interval:o,num_ticks_per_picture_minus_1:u}}decoderModelInfo(){const n=this.f(5),r=this.f(32),o=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:o,frame_presentation_time_length_minus_1:u}}operatingParametersInfo(n){const r=n.buffer_delay_length_minus_1+1,o=this.f(r),u=this.f(r),l=!!this.f1();return{decoder_buffer_delay:o,encoder_buffer_delay:u,low_delay_mode_flag:l}}chooseOperatingPoint(){return 0}colorConfig(n){const r=!!this.f1();let o=!1,u=8;n===2&&r?(o=!!this.f1(),u=o?12:10):n<=2&&(u=r?10:8);let l=!1;n===1&&(l=!!this.f1());const h=!!this.f1();let b=kt.ColorPrimaries.Unspecified,f=kt.TransferCharacteristics.Unspecified,g=kt.MatrixCoefficients.Unspecified;h&&(b=this.f(8),f=this.f(8),g=this.f(8));let p=!1,_,y,S=0,N=!1;if(l)p=!!this.f1(),_=!0,y=!0;else{if(b===kt.ColorPrimaries.Bt709&&f===kt.TransferCharacteristics.Srgb&&g===kt.MatrixCoefficients.Identity)p=!0,_=!1,y=!1;else{switch(p=!!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:o,BitDepth:u,mono_chrome:l,color_description_present_flag:h,color_primaries:b,transfer_characteristics:f,matrix_coefficients:g,color_range:p,subsampling_x:_,subsampling_y:y,chroma_sample_position:S,separate_uv_delta_q:N}}}function*Kd(i){let n=-1,r=0,o=!1;for(let u=0;u<i.length;u+=1){const l=i[u];if(o){if(l>3)throw new Error("Invalid data");o=!1;continue}if(l===0){r+=1;continue}const h=r;if(r=0,n===-1){if(h>=2&&l===1){n=u+1;continue}throw new Error("Invalid data")}if(!(h<2)){if(l===1){yield i.subarray(n,u-h),n=u+1;continue}if(h>2)throw new Error("Invalid data");switch(l){case 2:throw new Error("Invalid data");case 3:o=!0;break}}}if(o)throw new Error("Invalid data");yield i.subarray(n,i.length)}class Ni{#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 o=n[r];for(let u=0;u<8;u+=1)if((o>>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 o=0;o<n;o+=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(),o=this.read(n);return this.#a(r),o}readBytes(n){const r=new Uint8Array(n);for(let o=0;o<n;o+=1)r[o]=this.read(8);return r}peekBytes(n){const r=this.#d(),o=this.readBytes(n);return this.#a(r),o}}function Gb(i){const n=new Ni(i);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),h=!!n.next(),b=!!n.next(),f=!!n.next(),g=!!n.next(),p=!!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 O=0;O<(K!==3?8:12);O+=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 P=n.decodeExponentialGolombNumber(),T=n.decodeExponentialGolombNumber(),I=n.next();I||n.next(),n.next();const F=!!n.next();let A,$,q,X;return F?(A=n.decodeExponentialGolombNumber(),$=n.decodeExponentialGolombNumber(),q=n.decodeExponentialGolombNumber(),X=n.decodeExponentialGolombNumber()):(A=0,$=0,q=0,X=0),n.next(),{profile_idc:u,constraint_set:l,constraint_set0_flag:h,constraint_set1_flag:b,constraint_set2_flag:f,constraint_set3_flag:g,constraint_set4_flag:p,constraint_set5_flag:_,level_idc:y,seq_parameter_set_id:S,pic_width_in_mbs_minus1:P,pic_height_in_map_units_minus1:T,frame_mbs_only_flag:I,frame_cropping_flag:F,frame_crop_left_offset:A,frame_crop_right_offset:$,frame_crop_top_offset:q,frame_crop_bottom_offset:X}}function $b(i){let n,r;for(const o of Kd(i))switch(o[0]&31){case 7:if(n=o,r)return{sequenceParameterSet:n,pictureParameterSet:r};break;case 8:if(r=o,n)return{sequenceParameterSet:n,pictureParameterSet:r};break}throw new Error("Invalid data")}function qb(i){const{sequenceParameterSet:n,pictureParameterSet:r}=$b(i),{profile_idc:o,constraint_set:u,level_idc:l,pic_width_in_mbs_minus1:h,pic_height_in_map_units_minus1:b,frame_mbs_only_flag:f,frame_crop_left_offset:g,frame_crop_right_offset:p,frame_crop_top_offset:_,frame_crop_bottom_offset:y}=Gb(n),S=(h+1)*16,N=(b+1)*(2-f)*16,P=g*2,T=p*2,I=_*2,F=y*2,A=S-P-T,$=N-I-F;return{pictureParameterSet:r,sequenceParameterSet:n,profileIndex:o,constraintSet:u,levelIndex:l,encodedWidth:S,encodedHeight:N,cropLeft:P,cropRight:T,cropTop:I,cropBottom:F,croppedWidth:A,croppedHeight:$}}function Xb(i){switch(i){case 0:case 3:return 1;case 1:case 2:return 2;default:throw new Error("Invalid chroma_format_idc")}}function Yb(i){switch(i){case 0:case 2:case 3:return 1;case 1:return 2;default:throw new Error("Invalid chroma_format_idc")}}function Vb(i){const n=new Ni(i);if(n.next()!==0)throw new Error("Invalid NALU header");const r=n.read(6),o=n.read(6),u=n.read(3);return{nal_unit_type:r,nuh_layer_id:o,nuh_temporal_id_plus1:u}}function Kb(i){const n=new Ni(i),r=n.read(4),o=!!n.next(),u=!!n.next(),l=n.read(6),h=n.read(3),b=!!n.next();n.skip(16);const f=Qd(n,!0,h),g=!!n.next(),p=[],_=[],y=[];for(let B=g?0:h;B<=h;B+=1)p[B]=n.decodeExponentialGolombNumber(),_[B]=n.decodeExponentialGolombNumber(),y[B]=n.decodeExponentialGolombNumber();const S=n.read(6),N=n.decodeExponentialGolombNumber(),P=[];for(let B=1;B<=N;B+=1){P[B]=[];for(let M=0;M<=S;M+=1)P[B][M]=!!n.next()}const T=!!n.next();let I,F,A,$,q,X,K,V;if(T){I=n.read(32),F=n.read(32),A=!!n.next(),A&&($=n.decodeExponentialGolombNumber()),q=n.decodeExponentialGolombNumber(),X=[],K=[!0],V=[];for(let B=0;B<q;B+=1)X[B]=n.decodeExponentialGolombNumber(),B>0&&(K[B]=!!n.next()),V[B]=Jd(n,K[B],h)}const O=!!n.next();return{vps_video_parameter_set_id:r,vps_base_layer_internal_flag:o,vps_base_layer_available_flag:u,vps_max_layers_minus1:l,vps_max_sub_layers_minus1:h,vps_temporal_id_nesting_flag:b,profileTierLevel:f,vps_sub_layer_ordering_info_present_flag:g,vps_max_dec_pic_buffering_minus1:p,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:P,vps_timing_info_present_flag:T,vps_num_units_in_tick:I,vps_time_scale:F,vps_poc_proportional_to_timing_flag:A,vps_num_ticks_poc_diff_one_minus1:$,vps_num_hrd_parameters:q,hrd_layer_set_idx:X,cprms_present_flag:K,hrdParameters:V,vps_extension_flag:O}}function Qb(i){const n=new Ni(i),r=n.read(4),o=n.read(3),u=!!n.next(),l=Qd(n,!0,o),h=n.decodeExponentialGolombNumber(),b=n.decodeExponentialGolombNumber();let f;b===3&&(f=!!n.next());const g=n.decodeExponentialGolombNumber(),p=n.decodeExponentialGolombNumber(),_=!!n.next();let y,S,N,P;_&&(y=n.decodeExponentialGolombNumber(),S=n.decodeExponentialGolombNumber(),N=n.decodeExponentialGolombNumber(),P=n.decodeExponentialGolombNumber());const T=n.decodeExponentialGolombNumber(),I=n.decodeExponentialGolombNumber(),F=n.decodeExponentialGolombNumber(),A=[],$=[],q=[],X=!!n.next();for(let we=X?0:o;we<=o;we+=1)A[we]=n.decodeExponentialGolombNumber(),$[we]=n.decodeExponentialGolombNumber(),q[we]=n.decodeExponentialGolombNumber();const K=n.decodeExponentialGolombNumber(),V=n.decodeExponentialGolombNumber(),O=n.decodeExponentialGolombNumber(),B=n.decodeExponentialGolombNumber(),M=n.decodeExponentialGolombNumber(),me=n.decodeExponentialGolombNumber(),ye=!!n.next();let G,J;ye&&(G=!!n.next(),G&&(J=Jb(n)));const R=!!n.next(),W=!!n.next(),oe=!!n.next();let de,ue,Z,Se,Pe;oe&&(de=n.read(4),ue=n.read(4),Z=n.read(4),Se=n.read(4),Pe=!!n.next());const Fe=n.decodeExponentialGolombNumber(),Le=[];for(let we=0;we<Fe;we+=1)Le[we]=Zb(n,we,Fe,Le);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 Tt;tt&&(Tt=ey(n,o));const Xe=!!n.next();let gt,ne,re,D,ee;if(Xe&&(gt=!!n.next(),ne=!!n.next(),re=!!n.next(),D=!!n.next(),ee=n.read(4)),gt)throw new Error("Not implemented");let le;ne&&(le=ny(n));let ce;if(re&&(ce=ry(n)),D)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:o,sps_temporal_id_nesting_flag:u,profileTierLevel:l,sps_seq_parameter_set_id:h,chroma_format_idc:b,separate_colour_plane_flag:f,pic_width_in_luma_samples:g,pic_height_in_luma_samples:p,conformance_window_flag:_,conf_win_left_offset:y,conf_win_right_offset:S,conf_win_top_offset:N,conf_win_bottom_offset:P,bit_depth_luma_minus8:T,bit_depth_chroma_minus8:I,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:$,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:O,log2_diff_max_min_luma_transform_block_size:B,max_transform_hierarchy_depth_inter:M,max_transform_hierarchy_depth_intra:me,scaling_list_enabled_flag:ye,sps_scaling_list_data_present_flag:G,scalingListData:J,amp_enabled_flag:R,sample_adaptive_offset_enabled_flag:W,pcm_enabled_flag:oe,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:Pe,num_short_term_ref_pic_sets:Fe,shortTermRefPicSets:Le,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:Tt,sps_extension_present_flag:Xe,sps_range_extension_flag:gt,sps_multilayer_extension_flag:ne,sps_3d_extension_flag:re,sps_scc_extension_flag:D,sps_extension_4bits:ee,spsMultilayerExtension:le,sps3dExtension:ce,sps_extension_data_flag:Ce}}function Nu(i){const n=i.read(2),r=!!i.next(),o=i.read(5),u=i.peekBytes(4),l=[];for(let X=0;X<32;X+=1)l[X]=!!i.next();const h=i.peekBytes(6),b=!!i.next(),f=!!i.next(),g=!!i.next(),p=!!i.next();let _,y,S,N,P,T,I,F,A,$;o===4||l[4]||o===5||l[5]||o===6||l[6]||o===7||l[7]||o===8||l[8]||o===9||l[9]||o===10||l[10]||o===11||l[11]?(_=!!i.next(),y=!!i.next(),S=!!i.next(),N=!!i.next(),P=!!i.next(),T=!!i.next(),I=!!i.next(),F=!!i.next(),A=!!i.next(),o===5||l[5]||o===9||l[9]||o===10||l[10]||o===11||l[11]?($=!!i.next(),i.skip(33)):i.skip(34)):o===2||l[2]?(i.skip(7),F=!!i.next(),i.skip(35)):i.skip(43);let q;return o===1||l[1]||o===2||l[2]||o===3||l[3]||o===4||l[4]||o===5||l[5]||o===9||l[9]||o===11||l[11]?q=!!i.next():i.skip(1),{profile_space:n,tier_flag:r,profile_idc:o,profileCompatibilitySet:u,profile_compatibility_flag:l,constraintSet:h,progressive_source_flag:b,interlaced_source_flag:f,non_packed_constraint_flag:g,frame_only_constraint_flag:p,max_12bit_constraint_flag:_,max_10bit_constraint_flag:y,max_8bit_constraint_flag:S,max_422chroma_constraint_flag:N,max_420chroma_constraint_flag:P,max_monochrome_constraint_flag:T,intra_constraint_flag:I,one_picture_only_constraint_flag:F,lower_bit_rate_constraint_flag:A,max_14bit_constraint_flag:$,inbld_flag:q}}function Qd(i,n,r){let o;o=Nu(i);const u=i.read(8),l=[],h=[];for(let g=0;g<r;g+=1)l[g]=!!i.next(),h[g]=!!i.next();if(r>0)for(let g=r;g<8;g+=1)i.read(2);const b=[],f=[];for(let g=0;g<r;g+=1)l[g]&&(b[g]=Nu(i)),h[g]&&(f[g]=i.read(8));return{generalProfileTier:o,general_level_idc:u,sub_layer_profile_present_flag:l,sub_layer_level_present_flag:h,subLayerProfileTier:b,sub_layer_level_idc:f}}function Jb(i){const n=[];for(let r=0;r<4;r+=1){n[r]=[];for(let o=0;o<6;o+=r===3?3:1)if(!!!i.next())i.decodeExponentialGolombNumber();else{let l=8;const h=Math.min(64,1<<4+(r<<1));r>1&&(l=i.decodeExponentialGolombNumber()+8),n[r][o]=[];for(let b=0;b<h;b+=1){const f=i.decodeExponentialGolombNumber();l=(l+f+256)%256,n[r][o][b]=l}}}return n}function Zb(i,n,r,o){let u=!1;n!==0&&(u=!!i.next());let l=0,h=!1,b=0;const f=[],g=[];let p=0,_=0;const y=[],S=[],N=[],P=[];if(u){n===r&&(l=i.decodeExponentialGolombNumber()),h=!!i.next(),b=i.decodeExponentialGolombNumber();const T=n-(l+1),I=o[T],F=I.num_negative_pics+I.num_positive_pics;for(let M=0;M<=F;M+=1)f[M]=!!i.next(),f[M]?g[M]=!0:g[M]=!!i.next();const A=(1-2*Number(h))*(b+1),$=[],q=[],X=[],K=[];let V=0;for(let M=0;M<I.num_negative_pics;M+=1)V-=I.delta_poc_s0_minus1[M]+1,$[M]=V;V=0;for(let M=0;M<I.num_positive_pics;M+=1)V+=I.delta_poc_s1_minus1[M]+1,q[M]=V;let O=0;if(I.num_positive_pics>0)for(let M=I.num_positive_pics-1;M>=0;M-=1)V=q[M]+A,V<0&&g[I.num_negative_pics+M]&&(X[O]=V,S[O]=f[I.num_negative_pics+M],O+=1);A<0&&g[F]&&(X[O]=A,S[O]=f[F],O+=1);for(let M=0;M<I.num_negative_pics;M+=1)V=$[M]+A,V<0&&g[M]&&(X[O]=V,S[O]=f[M],O+=1);p=O;let B=0;for(O=0;O<p;O+=1){const M=X[O];y[O]=-(M-B-1),B=M}if(O=0,I.num_negative_pics>0)for(let M=I.num_negative_pics-1;M>=0;M-=1)V=$[M]+A,V>0&&g[M]&&(K[O]=V,P[O]=f[M],O+=1);A>0&&g[F]&&(K[O]=A,P[O]=f[F],O+=1);for(let M=0;M<I.num_positive_pics;M+=1)V=q[M]+A,V>0&&g[I.num_negative_pics+M]&&(K[O]=V,P[O]=f[I.num_negative_pics+M],O+=1);for(_=O,B=0,O=0;O<_;O+=1){const M=K[O];N[O]=M-B-1,B=M}}else{p=i.decodeExponentialGolombNumber(),_=i.decodeExponentialGolombNumber();for(let T=0;T<p;T+=1)y[T]=i.decodeExponentialGolombNumber(),S[T]=!!i.next();for(let T=0;T<_;T+=1)N[T]=i.decodeExponentialGolombNumber(),P[T]=!!i.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:h,abs_delta_rps_minus1:b,used_by_curr_pic_flag:f,use_delta_flag:g,num_negative_pics:p,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:P}}function ey(i,n){const r=!!i.next();let o,u,l;r&&(o=i.read(8),o===255&&(u=i.read(16),l=i.read(16)));const h=!!i.next();let b;h&&(b=!!i.next());const f=!!i.next();let g,p,_,y,S,N;f&&(g=i.read(3),p=!!i.next(),_=!!i.next(),_&&(y=i.read(8),S=i.read(8),N=i.read(8)));const P=!!i.next();let T,I;P&&(T=i.decodeExponentialGolombNumber(),I=i.decodeExponentialGolombNumber());const F=!!i.next(),A=!!i.next(),$=!!i.next(),q=!!i.next();let X,K,V,O;q&&(X=i.decodeExponentialGolombNumber(),K=i.decodeExponentialGolombNumber(),V=i.decodeExponentialGolombNumber(),O=i.decodeExponentialGolombNumber());const B=!!i.next();let M,me,ye,G,J,R;B&&(M=i.read(32),me=i.read(32),ye=!!i.next(),ye&&(G=i.decodeExponentialGolombNumber()),J=!!i.next(),J&&(R=Jd(i,!0,n)));const W=!!i.next();let oe,de,ue,Z,Se,Pe,Fe,Le;return W&&(oe=!!i.next(),de=!!i.next(),ue=!!i.next(),Z=i.decodeExponentialGolombNumber(),Se=i.decodeExponentialGolombNumber(),Pe=i.decodeExponentialGolombNumber(),Fe=i.decodeExponentialGolombNumber(),Le=i.decodeExponentialGolombNumber()),{aspect_ratio_info_present_flag:r,aspect_ratio_idc:o,sar_width:u,sar_height:l,overscan_info_present_flag:h,overscan_appropriate_flag:b,video_signal_type_present_flag:f,video_format:g,video_full_range_flag:p,colour_description_present_flag:_,colour_primaries:y,transfer_characteristics:S,matrix_coeffs:N,chroma_loc_info_present_flag:P,chroma_sample_loc_type_top_field:T,chroma_sample_loc_type_bottom_field:I,neutral_chroma_indication_flag:F,field_seq_flag:A,frame_field_info_present_flag:$,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:O,vui_timing_info_present_flag:B,vui_num_units_in_tick:M,vui_time_scale:me,vui_poc_proportional_to_timing_flag:ye,vui_num_ticks_poc_diff_one_minus1:G,vui_hrd_parameters_present_flag:J,vui_hrd_parameters:R,bitstream_restriction_flag:W,tiles_fixed_structure_flag:oe,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:Pe,log2_max_mv_length_horizontal:Fe,log2_max_mv_length_vertical:Le}}function Jd(i,n,r){let o,u,l,h,b,f,g,p,_,y,S,N,P;n&&(o=!!i.next(),u=!!i.next(),(o||u)&&(l=!!i.next(),l&&(h=i.read(8),b=i.read(5),f=!!i.next(),g=i.read(5)),p=i.read(4),_=i.read(4),l&&(y=i.read(4)),S=i.read(5),N=i.read(5),P=i.read(5)));const T=[],I=[],F=[],A=[],$=[],q=[],X=[];for(let K=0;K<=r;K+=1)T[K]=!!i.next(),T[K]||(I[K]=!!i.next()),I[K]?F[K]=i.decodeExponentialGolombNumber():A[K]=!!i.next(),A[K]||($[K]=i.decodeExponentialGolombNumber()),o&&(q[K]=Cu(i,K,ku($[K]))),u&&(X[K]=Cu(i,K,ku($[K])));return{nal_hrd_parameters_present_flag:o,vcl_hrd_parameters_present_flag:u,sub_pic_hrd_params_present_flag:l,tick_divisor_minus2:h,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:p,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:P,fixed_pic_rate_general_flag:T,fixed_pic_rate_within_cvs_flag:I,elemental_duration_in_tc_minus1:F,low_delay_hrd_flag:A,cpb_cnt_minus1:$,nalHrdParameters:q,vclHrdParameters:X}}function Cu(i,n,r){const o=[],u=[],l=[],h=[],b=[];for(let f=0;f<r;f+=1)o[f]=i.decodeExponentialGolombNumber(),u[f]=i.decodeExponentialGolombNumber(),n>0&&(b[f]=!!i.next());return{bit_rate_value_minus1:o,cpb_size_value_minus1:u,cpb_size_du_value_minus1:l,bit_rate_du_value_minus1:h,cbr_flag:b}}function ku(i){return i+1}function ty(i){let n,r,o,u=0;for(const l of Kd(i)){const h=Vb(l),b={...h,data:l,rbsp:l.subarray(2)};switch(h.nal_unit_type){case 32:n=b;break;case 33:r=b;break;case 34:o=b;break;default:continue}if(u+=1,u===3)return{videoParameterSet:n,sequenceParameterSet:r,pictureParameterSet:o}}throw new Error("Invalid data")}function ny(i){return{inter_view_mv_vert_constraint_flag:!!i.next()}}function ry(i){const n=[],r=[];n[0]=!!i.next(),r[0]=!!i.next();const o=i.decodeExponentialGolombNumber(),u=!!i.next(),l=!!i.next(),h=!!i.next(),b=!!i.next();n[1]=!!i.next(),r[1]=!!i.next();const f=!!i.next(),g=i.decodeExponentialGolombNumber(),p=!!i.next(),_=!!i.next(),y=!!i.next(),S=!!i.next(),N=!!i.next();return{iv_di_mc_enabled_flag:n,iv_mv_scal_enabled_flag:r,log2_ivmc_sub_pb_size_minus3:o,iv_res_pred_enabled_flag:u,depth_ref_enabled_flag:l,vsp_mc_enabled_flag:h,dbbp_enabled_flag:b,tex_mc_enabled_flag:f,log2_texmc_sub_pb_size_minus3:g,intra_contour_enabled_flag:p,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 sy(i){const{videoParameterSet:n,sequenceParameterSet:r,pictureParameterSet:o}=ty(i),{profileTierLevel:{generalProfileTier:{profile_space:u,tier_flag:l,profile_idc:h,profileCompatibilitySet:b,constraintSet:f},general_level_idc:g}}=Kb(n.rbsp),{chroma_format_idc:p,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:P=0,conf_win_bottom_offset:T=0}=Qb(r.rbsp),I=Xb(p),F=Yb(p),A=_-I*(S+N),$=y-F*(P+T);return{videoParameterSet:n,sequenceParameterSet:r,pictureParameterSet:o,generalProfileSpace:u,generalProfileIndex:h,generalProfileCompatibilitySet:b,generalTierFlag:l,generalLevelIndex:g,generalConstraintSet:f,encodedWidth:_,encodedHeight:y,cropLeft:S,cropRight:N,cropTop:P,cropBottom:T,croppedWidth:A,croppedHeight:$}}function Tu(i){return i.toString(16).toUpperCase()}function Vo(i){return i.toString(16).toUpperCase().padStart(2,"0")}function ss(i){return i.toString(10).padStart(2,"0")}class iy{#e;#t;constructor(n,r){this.#e=n,this.#t=r}#n(n){const o=new kt(n).searchSequenceHeaderObu();if(!o)return;const{seq_profile:u,seq_level_idx:[l=0],max_frame_width_minus_1:h,max_frame_height_minus_1:b,color_config:{BitDepth:f,mono_chrome:g,subsampling_x:p,subsampling_y:_,chroma_sample_position:y,color_description_present_flag:S}}=o;let N,P,T,I;S?{color_primaries:N,transfer_characteristics:P,matrix_coefficients:T,color_range:I}=o.color_config:(N=kt.ColorPrimaries.Bt709,P=kt.TransferCharacteristics.Bt709,T=kt.MatrixCoefficients.Bt709,I=!1);const F=h+1,A=b+1;this.#t(F,A);const $=["av01",u.toString(16),ss(l)+(o.seq_tier[0]?"H":"M"),ss(f),g?"1":"0",(p?"1":"0")+(_?"1":"0")+y.toString(),ss(N),ss(P),ss(T),I?"1":"0"].join(".");this.#e.configure({codec:$,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 Zd{#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 oy extends Zd{#e;#t;constructor(n,r){super(n),this.#e=n,this.#t=r}configure(n){const{profileIndex:r,constraintSet:o,levelIndex:u,croppedWidth:l,croppedHeight:h}=qb(n);this.#t(l,h);const b="avc1."+Vo(r)+Vo(o)+Vo(u);this.#e.configure({codec:b,optimizeForLatency:!0})}}class ay extends Zd{#e;#t;constructor(n,r){super(n),this.#e=n,this.#t=r}configure(n){const{generalProfileSpace:r,generalProfileIndex:o,generalProfileCompatibilitySet:u,generalTierFlag:l,generalLevelIndex:h,generalConstraintSet:b,croppedWidth:f,croppedHeight:g}=sy(n);this.#t(f,g);const p=["hev1",["","A","B","C"][r]+o.toString(),Tu(Ob(u,0)),(l?"H":"L")+h.toString(),...Array.from(b,Tu)].join(".");this.#e.configure({codec:p,codedWidth:f,codedHeight:g,optimizeForLatency:!0})}}class ly{listeners=[];constructor(){this.event=this.event.bind(this)}addEventListener(n){this.listeners.push(n);const r=()=>{const o=this.listeners.indexOf(n);o!==-1&&this.listeners.splice(o,1)};return r.dispose=r,r}event=(n,r,...o)=>{const u={listener:n,thisArg:r,args:o};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 cy{#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 uy{#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((o,u)=>{this.#e.toBlob(l=>{l?o(l):u(new Error("Failed to convert canvas to blob"))},"image/png")})}}const Ru=new cy(()=>new uy,4);class Au{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 ly;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:o=>{if(this.#f?.close(),this.#f=o.clone(),this.#p){this.#u&&(this.#u.close(),this.#c+=1),this.#u=o;return}this.#x(o)},error:o=>{this.#g(o)}}),this.#e){case fi.H264:this.#t=new oy(this.#a,this.#h);break;case fi.H265:this.#t=new ay(this.#a,this.#h);break;case fi.AV1:this.#t=new iy(this.#a,this.#h);break;default:throw new Error(`Unsupported codec: ${this.#e}`)}this.#n=new Fb({start:o=>{this.#r?o.error(this.#r):this.#i=o},write:o=>{this.#t.decode(o)}}),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 Ru.borrow(),o=await r.capture(n);return Ru.return(r),o}dispose(){cancelAnimationFrame(this.#m),this.#a.state!=="closed"&&this.#a.close(),this.#u?.close(),this.#f?.close()}}var Ko={exports:{}},Qo={exports:{}},Pu;function ja(){return Pu||(Pu=1,(function(){function i(n,r){throw new Error("abstract")}i.prototype.drawFrame=function(n){throw new Error("abstract")},i.prototype.clear=function(){throw new Error("abstract")},Qo.exports=i})()),Qo.exports}var Jo={exports:{}},Zo={exports:{}},ea={exports:{}},ju;function dy(){return ju||(ju=1,(function(){function i(n){for(var r=0,o=n>>1;o!=0;)o=o>>1,r++;if(n!==1<<r)throw"chroma plane dimensions must be power of 2 ratio to luma plane dimensions; got "+n;return r}ea.exports=i})()),ea.exports}var Iu;function fy(){return Iu||(Iu=1,(function(){var i=dy();function n(r,o){var u=r.format.width|0,l=r.format.height|0,h=i(r.format.width/r.format.chromaWidth)|0,b=i(r.format.height/r.format.chromaHeight)|0,f=r.y.bytes,g=r.u.bytes,p=r.v.bytes,_=r.y.stride|0,y=r.u.stride|0,S=r.v.stride|0,N=u<<2,P=0,T=0,I=0,F=0,A=0,$=0,q=0,X=0,K=0,V=0,O=0,B=0,M=0,me=0,ye=0,G=0,J=0,R=0;if(h==1&&b==1)for(q=0,X=N,R=0,G=0;G<l;G+=2){for(T=G*_|0,I=T+_|0,F=R*y|0,A=R*S|0,ye=0;ye<u;ye+=2)K=g[F++]|0,V=p[A++]|0,B=(409*V|0)-57088|0,M=(100*K|0)+(208*V|0)-34816|0,me=(516*K|0)-70912|0,O=298*f[T++]|0,o[q]=O+B>>8,o[q+1]=O-M>>8,o[q+2]=O+me>>8,q+=4,O=298*f[T++]|0,o[q]=O+B>>8,o[q+1]=O-M>>8,o[q+2]=O+me>>8,q+=4,O=298*f[I++]|0,o[X]=O+B>>8,o[X+1]=O-M>>8,o[X+2]=O+me>>8,X+=4,O=298*f[I++]|0,o[X]=O+B>>8,o[X+1]=O-M>>8,o[X+2]=O+me>>8,X+=4;q+=N,X+=N,R++}else for($=0,G=0;G<l;G++)for(J=0,R=G>>b,P=G*_|0,F=R*y|0,A=R*S|0,ye=0;ye<u;ye++)J=ye>>h,K=g[F+J]|0,V=p[A+J]|0,B=(409*V|0)-57088|0,M=(100*K|0)+(208*V|0)-34816|0,me=(516*K|0)-70912|0,O=298*f[P++]|0,o[$]=O+B>>8,o[$+1]=O-M>>8,o[$+2]=O+me>>8,$+=4}Zo.exports={convertYCbCr:n}})()),Zo.exports}var Du;function hy(){return Du||(Du=1,(function(){var i=ja(),n=fy();function r(o){var u=this,l=o.getContext("2d"),h=null,b=null,f=null;function g(_,y){h=l.createImageData(_,y);for(var S=h.data,N=_*y*4,P=0;P<N;P+=4)S[P+3]=255}function p(_,y){b=document.createElement("canvas"),b.width=_,b.height=y,f=b.getContext("2d")}return u.drawFrame=function(y){var S=y.format;(o.width!==S.displayWidth||o.height!==S.displayHeight)&&(o.width=S.displayWidth,o.height=S.displayHeight),(h===null||h.width!=S.width||h.height!=S.height)&&g(S.width,S.height),n.convertYCbCr(y,h.data);var N=S.cropWidth!=S.displayWidth||S.cropHeight!=S.displayHeight,P;N?(b||p(S.cropWidth,S.cropHeight),P=f):P=l,P.putImageData(h,-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,o.width,o.height)},u}r.prototype=Object.create(i.prototype),Jo.exports=r})()),Jo.exports}var ta={exports:{}},na,Mu;function py(){return Mu||(Mu=1,na={vertex:`precision mediump float;
33
+
34
+ attribute vec2 aPosition;
35
+ attribute vec2 aLumaPosition;
36
+ attribute vec2 aChromaPosition;
37
+ varying vec2 vLumaPosition;
38
+ varying vec2 vChromaPosition;
39
+ void main() {
40
+ gl_Position = vec4(aPosition, 0, 1);
41
+ vLumaPosition = aLumaPosition;
42
+ vChromaPosition = aChromaPosition;
43
+ }
44
+ `,fragment:`// inspired by https://github.com/mbebenita/Broadway/blob/master/Player/canvas.js
45
+
46
+ precision mediump float;
47
+
48
+ uniform sampler2D uTextureY;
49
+ uniform sampler2D uTextureCb;
50
+ uniform sampler2D uTextureCr;
51
+ varying vec2 vLumaPosition;
52
+ varying vec2 vChromaPosition;
53
+ void main() {
54
+ // Y, Cb, and Cr planes are uploaded as ALPHA textures.
55
+ float fY = texture2D(uTextureY, vLumaPosition).w;
56
+ float fCb = texture2D(uTextureCb, vChromaPosition).w;
57
+ float fCr = texture2D(uTextureCr, vChromaPosition).w;
58
+
59
+ // Premultipy the Y...
60
+ float fYmul = fY * 1.1643828125;
61
+
62
+ // And convert that to RGB!
63
+ gl_FragColor = vec4(
64
+ fYmul + 1.59602734375 * fCr - 0.87078515625,
65
+ fYmul - 0.39176171875 * fCb - 0.81296875 * fCr + 0.52959375,
66
+ fYmul + 2.017234375 * fCb - 1.081390625,
67
+ 1
68
+ );
69
+ }
70
+ `,vertexStripe:`precision mediump float;
71
+
72
+ attribute vec2 aPosition;
73
+ attribute vec2 aTexturePosition;
74
+ varying vec2 vTexturePosition;
75
+
76
+ void main() {
77
+ gl_Position = vec4(aPosition, 0, 1);
78
+ vTexturePosition = aTexturePosition;
79
+ }
80
+ `,fragmentStripe:`// extra 'stripe' texture fiddling to work around IE 11's poor performance on gl.LUMINANCE and gl.ALPHA textures
81
+
82
+ precision mediump float;
83
+
84
+ uniform sampler2D uStripe;
85
+ uniform sampler2D uTexture;
86
+ varying vec2 vTexturePosition;
87
+ void main() {
88
+ // Y, Cb, and Cr planes are mapped into a pseudo-RGBA texture
89
+ // so we can upload them without expanding the bytes on IE 11
90
+ // which doesn't allow LUMINANCE or ALPHA textures
91
+ // The stripe textures mark which channel to keep for each pixel.
92
+ // Each texture extraction will contain the relevant value in one
93
+ // channel only.
94
+
95
+ float fLuminance = dot(
96
+ texture2D(uStripe, vTexturePosition),
97
+ texture2D(uTexture, vTexturePosition)
98
+ );
99
+
100
+ gl_FragColor = vec4(0, 0, 0, fLuminance);
101
+ }
102
+ `}),na}var Lu;function my(){return Lu||(Lu=1,(function(){var i=ja(),n=py();function r(o){var u=this,l=r.contextForCanvas(o);if(l===null)throw new Error("WebGL unavailable");function h(G,J){var R=l.createShader(G);if(l.shaderSource(R,J),l.compileShader(R),!l.getShaderParameter(R,l.COMPILE_STATUS)){var W=l.getShaderInfoLog(R);throw l.deleteShader(R),new Error("GL shader compilation for "+G+" failed: "+W)}return R}var b,f,g=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),p={},_={},y={},S,N,P,T,I,F,A,$,q,X;function K(G,J){return(!p[G]||J)&&(p[G]=l.createTexture()),p[G]}function V(G,J,R,W,oe){var de=!p[G]||J,ue=K(G,J);if(l.activeTexture(l.TEXTURE0),r.stripe){var Z=!p[G+"_temp"]||J,Se=K(G+"_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,R/4,W,0,l.RGBA,l.UNSIGNED_BYTE,oe)):l.texSubImage2D(l.TEXTURE_2D,0,0,0,R/4,W,l.RGBA,l.UNSIGNED_BYTE,oe);var Pe=p[G+"_stripe"],Fe=!Pe||J;Fe&&(Pe=K(G+"_stripe",J)),l.bindTexture(l.TEXTURE_2D,Pe),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,R,1,0,l.RGBA,l.UNSIGNED_BYTE,M(R)))}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,R,W,0,l.ALPHA,l.UNSIGNED_BYTE,oe)):l.texSubImage2D(l.TEXTURE_2D,0,0,0,R,W,l.ALPHA,l.UNSIGNED_BYTE,oe)}function O(G,J,R,W){var oe=p[G];l.useProgram(f);var de=_[G];(!de||J)&&(l.activeTexture(l.TEXTURE0),l.bindTexture(l.TEXTURE_2D,oe),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,R,W,0,l.RGBA,l.UNSIGNED_BYTE,null),de=_[G]=l.createFramebuffer()),l.bindFramebuffer(l.FRAMEBUFFER,de),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,oe,0);var ue=p[G+"_temp"];l.activeTexture(l.TEXTURE1),l.bindTexture(l.TEXTURE_2D,ue),l.uniform1i(F,1);var Z=p[G+"_stripe"];l.activeTexture(l.TEXTURE2),l.bindTexture(l.TEXTURE_2D,Z),l.uniform1i(I,2),l.bindBuffer(l.ARRAY_BUFFER,S),l.enableVertexAttribArray(N),l.vertexAttribPointer(N,2,l.FLOAT,!1,0,0),l.bindBuffer(l.ARRAY_BUFFER,P),l.enableVertexAttribArray(T),l.vertexAttribPointer(T,2,l.FLOAT,!1,0,0),l.viewport(0,0,R,W),l.drawArrays(l.TRIANGLES,0,g.length/2),l.bindFramebuffer(l.FRAMEBUFFER,null)}function B(G,J,R){l.activeTexture(J),l.bindTexture(l.TEXTURE_2D,p[G]),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,G),R)}function M(G){if(y[G])return y[G];for(var J=G,R=new Uint32Array(J),W=0;W<J;W+=4)R[W]=255,R[W+1]=65280,R[W+2]=16711680,R[W+3]=4278190080;return y[G]=new Uint8Array(R.buffer)}function me(G,J){var R=h(l.VERTEX_SHADER,G),W=h(l.FRAGMENT_SHADER,J),oe=l.createProgram();if(l.attachShader(oe,R),l.attachShader(oe,W),l.linkProgram(oe),!l.getProgramParameter(oe,l.LINK_STATUS)){var de=l.getProgramInfoLog(oe);throw l.deleteProgram(oe),new Error("GL program linking failed: "+de)}return oe}function ye(){if(r.stripe){f=me(n.vertexStripe,n.fragmentStripe),l.getAttribLocation(f,"aPosition"),P=l.createBuffer();var G=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]);l.bindBuffer(l.ARRAY_BUFFER,P),l.bufferData(l.ARRAY_BUFFER,G,l.STATIC_DRAW),T=l.getAttribLocation(f,"aTexturePosition"),I=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(),$=l.getAttribLocation(b,"aLumaPosition"),q=l.createBuffer(),X=l.getAttribLocation(b,"aChromaPosition")}return u.drawFrame=function(G){var J=G.format,R=!b||o.width!==J.displayWidth||o.height!==J.displayHeight;if(R&&(o.width=J.displayWidth,o.height=J.displayHeight,u.clear()),b||ye(),R){var W=function(oe,de,ue){var Z=J.cropLeft/ue,Se=(J.cropLeft+J.cropWidth)/ue,Pe=(J.cropTop+J.cropHeight)/J.height,Fe=J.cropTop/J.height,Le=new Float32Array([Z,Pe,Se,Pe,Z,Fe,Z,Fe,Se,Pe,Se,Fe]);l.bindBuffer(l.ARRAY_BUFFER,oe),l.bufferData(l.ARRAY_BUFFER,Le,l.STATIC_DRAW)};W(A,$,G.y.stride),W(q,X,G.u.stride*J.width/J.chromaWidth)}V("uTextureY",R,G.y.stride,J.height,G.y.bytes),V("uTextureCb",R,G.u.stride,J.chromaHeight,G.u.bytes),V("uTextureCr",R,G.v.stride,J.chromaHeight,G.v.bytes),r.stripe&&(O("uTextureY",R,G.y.stride,J.height),O("uTextureCb",R,G.u.stride,J.chromaHeight),O("uTextureCr",R,G.v.stride,J.chromaHeight)),l.useProgram(b),l.viewport(0,0,o.width,o.height),B("uTextureY",l.TEXTURE0,0),B("uTextureCb",l.TEXTURE1,1),B("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($),l.vertexAttribPointer($,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,o.width,o.height),l.clearColor(0,0,0,0),l.clear(l.COLOR_BUFFER_BIT)},u.clear(),u}r.stripe=!1,r.contextForCanvas=function(o){var u={preferLowPowerToHighPerformance:!0,powerPreference:"low-power",failIfMajorPerformanceCaveat:!0,preserveDrawingBuffer:!0};return o.getContext("webgl",u)||o.getContext("experimental-webgl",u)},r.isAvailable=function(){var o=document.createElement("canvas"),u;o.width=1,o.height=1;try{u=r.contextForCanvas(o)}catch{return!1}if(u){var l=u.TEXTURE0,h=4,b=4,f=u.createTexture(),g=new Uint8Array(h*b),p=r.stripe?h/4:h,_=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,_,p,b,0,_,u.UNSIGNED_BYTE,g);var S=u.getError();return!S}else return!1},r.prototype=Object.create(i.prototype),ta.exports=r})()),ta.exports}var Ou;function gy(){return Ou||(Ou=1,(function(){var i=ja(),n=hy(),r=my(),o={FrameSink:i,SoftwareFrameSink:n,WebGLFrameSink:r,attach:function(u,l){l=l||{};var h="webGL"in l?l.webGL:r.isAvailable();return h?new r(u,l):new n(u,l)}};Ko.exports=o})()),Ko.exports}gy();function ef(){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 tf{#e;get canvas(){return this.#e}constructor(n){n?this.#e=n:this.#e=ef()}setSize(n,r){(this.#e.width!==n||this.#e.height!==r)&&(this.#e.width=n,this.#e.height=r)}}class xy extends tf{#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 _y=Promise.resolve();function Fu(i,n){const r={powerPreference:"low-power",alpha:!1,failIfMajorPerformanceCaveat:!0,preserveDrawingBuffer:!!n};return i.getContext("webgl2",r)||i.getContext("webgl",r)}class fs extends tf{static vertexShaderSource=`
103
+ attribute vec2 xy;
104
+
105
+ varying highp vec2 uv;
106
+
107
+ void main(void) {
108
+ gl_Position = vec4(xy, 0.0, 1.0);
109
+ // Map vertex coordinates (-1 to +1) to UV coordinates (0 to 1).
110
+ // UV coordinates are Y-flipped relative to vertex coordinates.
111
+ uv = vec2((1.0 + xy.x) / 2.0, (1.0 - xy.y) / 2.0);
112
+ }
113
+ `;static fragmentShaderSource=`
114
+ varying highp vec2 uv;
115
+
116
+ uniform sampler2D texture;
117
+
118
+ void main(void) {
119
+ gl_FragColor = texture2D(texture, uv);
120
+ }
121
+ `;static get isSupported(){const n=ef();return!!Fu(n)}#e;constructor(n,r){super(n);const o=Fu(this.canvas,r);if(!o)throw new Error("WebGL not supported");this.#e=o;const u=o.createShader(o.VERTEX_SHADER);if(o.shaderSource(u,fs.vertexShaderSource),o.compileShader(u),!o.getShaderParameter(u,o.COMPILE_STATUS))throw new Error(o.getShaderInfoLog(u));const l=o.createShader(o.FRAGMENT_SHADER);if(o.shaderSource(l,fs.fragmentShaderSource),o.compileShader(l),!o.getShaderParameter(l,o.COMPILE_STATUS))throw new Error(o.getShaderInfoLog(l));const h=o.createProgram();if(o.attachShader(h,u),o.attachShader(h,l),o.linkProgram(h),!o.getProgramParameter(h,o.LINK_STATUS))throw new Error(o.getProgramInfoLog(h));o.useProgram(h);const b=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,b),o.bufferData(o.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),o.STATIC_DRAW);const f=o.getAttribLocation(h,"xy");o.vertexAttribPointer(f,2,o.FLOAT,!1,0,0),o.enableVertexAttribArray(f);const g=o.createTexture();o.bindTexture(o.TEXTURE_2D,g),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.NEAREST),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.NEAREST),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.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),_y}}const Bu=50,vy=300;function nf({deviceId:i,className:n,onFallback:r,fallbackTimeout:o=5e3,enableControl:u=!1,onTapSuccess:l,onTapError:h,onSwipeSuccess:b,onSwipeError:f,onStreamReady:g}){const p=v.useRef(null),_=v.useRef(null),y=v.useRef(null),S=v.useRef(null),N=v.useRef(null),P=v.useRef(null),T=v.useRef(null),I=v.useRef(!1),F=v.useRef(!1),A=v.useRef(r),$=v.useRef(o),q=v.useRef(g),[X,K]=v.useState("connecting"),[V,O]=v.useState(null),[B,M]=v.useState(null),[me,ye]=v.useState(null),G=v.useRef(!1),J=v.useRef(null),R=v.useRef(!1),W=v.useRef(0),oe=v.useRef(null),de=v.useRef(null),ue=v.useRef(null),Z=v.useRef(null);v.useEffect(()=>{A.current=r,$.current=o,q.current=g},[r,o,g]),v.useEffect(()=>{(async()=>{try{const re=await wa(i);re.success&&ye({width:re.width,height:re.height})}catch(re){console.error("[ScrcpyPlayer] Failed to fetch device resolution:",re)}})()},[i]);const Se=v.useCallback(()=>{const ne=S.current,re=y.current;if(!ne||!re||!B)return;const D=re.clientWidth,ee=re.clientHeight,{width:le,height:ce}=B,Ce=le/ce;let we=D,xt=D/Ce;xt>ee&&(xt=ee,we=ee*Ce),ne.width=le,ne.height=ce,ne.style.width=`${we}px`,ne.style.height=`${xt}px`},[B]);v.useEffect(()=>{const ne=()=>Se();return window.addEventListener("resize",ne),()=>window.removeEventListener("resize",ne)},[Se]),v.useEffect(()=>{Se()},[B,Se]);const Pe=v.useCallback(async()=>{if(fs.isSupported){const re=new fs;return{renderer:re,element:re.canvas}}const ne=new xy;return{renderer:ne,element:ne.canvas}},[]),Fe=v.useCallback(async ne=>{if(!Au.isSupported)throw new Error("Current browser does not support WebCodecs API. Please use the latest Chrome/Edge.");const{renderer:re,element:D}=await Pe();return S.current=D,y.current&&!D.parentElement&&y.current.appendChild(D),new Au({codec:ne,renderer:re})},[Pe]),Le=v.useCallback(()=>{I.current||(I.current=!0,N.current&&(clearTimeout(N.current),N.current=null))},[]),at=v.useCallback(ne=>{let re=!1,D=[];const ee=new TransformStream({transform(ce,Ce){if(ce.type==="configuration"){Ce.enqueue(ce),re=!0,D.length>0&&(D.forEach(we=>Ce.enqueue(we)),D=[]);return}if(ce.type==="data"&&!re){D.push(ce);return}Ce.enqueue(ce)}});return new ReadableStream({start(ce){let Ce=!1;const we=ie=>{if(!Ce)try{Le();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=()=>{p.current?.off("video-data",we),p.current?.off("error",xt),p.current?.off("disconnect",bt)};return p.current?.on("video-data",we),p.current?.on("error",xt),p.current?.on("disconnect",bt),()=>{Ce=!0,Q()}}}).pipeThrough(ee)},[Le]),lt=v.useCallback((ne=!1)=>{if(ne&&(F.current=!0),_.current){try{_.current.dispose()}catch(re){console.error("[ScrcpyPlayer] Failed to dispose decoder:",re)}_.current=null}S.current=null,p.current&&(p.current.disconnect(),p.current=null),q.current?.(null),P.current&&(clearTimeout(P.current),P.current=null),N.current&&(clearTimeout(N.current),N.current=null),K("disconnected"),M(null),O(null)},[]),Ge=v.useCallback(()=>{lt(!0),I.current=!1,K("connecting"),O(null);const ne=di({path:"/socket.io",transports:["websocket"],timeout:1e4});p.current=ne,ne.on("connect",()=>{ne.emit("connect-device",{device_id:i,maxSize:1280,bitRate:4e6}),N.current=setTimeout(()=>{I.current||(K("error"),O("Video stream timeout"),F.current=!0,ne.close(),A.current?.())},$.current)}),ne.on("video-metadata",async re=>{try{_.current&&(_.current.dispose(),_.current=null);const D=re?.codec?re.codec:fi.H264;_.current=await Fe(D),_.current.sizeChanged(({width:le,height:ce})=>{M({width:le,height:ce})}),at(re).pipeTo(_.current.writable).catch(le=>{console.error("[ScrcpyPlayer] Video stream error:",le)}),K("connected"),q.current?.({close:()=>ne.close()})}catch(D){console.error("[ScrcpyPlayer] Decoder initialization failed:",D),K("error"),O("Decoder initialization failed"),F.current=!0,ne.close(),A.current?.()}}),ne.on("error",re=>{console.error("[ScrcpyPlayer] Socket error:",re),K("error"),O(re?.message||"Socket error")}),ne.on("disconnect",()=>{if(F.current){F.current=!1;return}K("disconnected"),q.current?.(null),P.current||(P.current=setTimeout(()=>{P.current=null,T.current?.()},3e3))})},[i,lt,Fe,at]);v.useEffect(()=>{T.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(B)return{width:B.width,height:B.height};const ne=S.current;return ne?{width:ne.width,height:ne.height}:null},$e=(ne,re)=>{const D=S.current,ee=Te();if(!D||!ee)return null;const le=D.getBoundingClientRect();if(ne<le.left||ne>le.right||re<le.top||re>le.bottom)return null;const ce=ne-le.left,Ce=re-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 re=$e(ne.clientX,ne.clientY);if(re){G.current=!0,R.current=!1,J.current={x:ne.clientX,y:ne.clientY};try{await X_(re.x,re.y,i)}catch(D){console.error("[ScrcpyPlayer] Touch down failed:",D)}}},tt=ne=>{if(!G.current||X!=="connected")return;const re=Date.now(),D=$e(ne.clientX,ne.clientY);if(D){if(J.current){const ee=ne.clientX-J.current.x,le=ne.clientY-J.current.y;Math.hypot(ee,le)>4&&(R.current=!0)}if(oe.current=D,re-W.current<Bu){de.current||(de.current=setTimeout(()=>{de.current=null,oe.current&&(uu(oe.current.x,oe.current.y,i).catch(ee=>{console.error("[ScrcpyPlayer] Touch move failed:",ee)}),oe.current=null,W.current=Date.now())},Bu));return}W.current=re,uu(D.x,D.y,i).catch(ee=>{console.error("[ScrcpyPlayer] Touch move failed:",ee)})}},Tt=async ne=>{if(!G.current||X!=="connected")return;const re=$e(ne.clientX,ne.clientY);if(G.current=!1,J.current=null,!!re)try{await cu(re.x,re.y,i),R.current?b?.():l?.()}catch(D){const ee=String(D);R.current?f?.(ee):h?.(ee)}},Xe=async ne=>{if(!G.current||X!=="connected")return;const re=$e(ne.clientX,ne.clientY);if(G.current=!1,J.current=null,!!re)try{await cu(re.x,re.y,i)}catch(D){console.error("[ScrcpyPlayer] Touch cancel failed:",D)}},gt=ne=>{if(!u||X!=="connected")return;ne.preventDefault();const re=ne.deltaY;Z.current||(Z.current={deltaY:0}),Z.current.deltaY+=re,ue.current&&clearTimeout(ue.current),ue.current=setTimeout(async()=>{const D=Z.current;if(Z.current=null,!D)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(D.deltaY,600),-600),Q=we+bt,ie=$e(Ce,Q);if(ie)try{const ge=await q_(xt.x,xt.y,ie.x,ie.y,300,i);ge.success?b?.():f?.(ge.error||"Scroll failed")}catch(ge){f?.(String(ge))}},vy)};return a.jsx("div",{className:`relative w-full h-full flex items-center justify-center ${n||""}`,children:a.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:Tt,onMouseLeave:Xe,onWheel:gt,children:X!=="connected"&&a.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 rf=v.forwardRef(({className:i,value:n=0,max:r=100,...o},u)=>{const l=Math.min(Math.max(n/r*100,0),100);return a.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",i),...o,children:a.jsx("div",{className:"h-full bg-primary transition-all duration-300 ease-in-out",style:{width:`${l}%`}})})});rf.displayName="Progress";function by({state:i,isStreaming:n,className:r="",decisionModelName:o="Decision Model",visionModelName:u="Vision Model"}){const[l,h]=We.useState("decision"),b=g=>{h(p=>p===g?null:g)},f=i.totalSteps>0?Math.round(i.currentStep/i.totalSteps*100):0;return a.jsxs("div",{className:`space-y-3 ${r}`,children:[n&&a.jsxs("div",{className:"space-y-1",children:[a.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-500 dark:text-slate-400",children:[a.jsxs("span",{children:["Step ",i.currentStep," / ",i.totalSteps||"?"]}),a.jsxs("span",{children:[f,"%"]})]}),a.jsx(rf,{value:f,className:"h-1.5"})]}),i.taskPlan.length>0&&a.jsxs(er,{className:"p-3 bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-800",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx(od,{className:"w-4 h-4 text-blue-500"}),a.jsx("span",{className:"text-xs font-medium text-slate-700 dark:text-slate-300",children:"Task Plan"})]}),a.jsx("ul",{className:"space-y-1",children:i.taskPlan.map((g,p)=>a.jsxs("li",{className:`text-xs flex items-start gap-2 ${p<i.currentStep?"text-green-600 dark:text-green-400":p===i.currentStep?"text-blue-600 dark:text-blue-400 font-medium":"text-slate-500 dark:text-slate-400"}`,children:[a.jsx("span",{className:"flex-shrink-0 w-4 h-4 rounded-full border flex items-center justify-center text-[10px]",children:p<i.currentStep?a.jsx(kn,{className:"w-3 h-3"}):p+1}),a.jsx("span",{className:"line-clamp-1",children:g})]},p))})]}),a.jsxs(er,{className:`overflow-hidden transition-all duration-200 ${i.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:[a.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:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${i.decisionActive?"bg-purple-100 dark:bg-purple-900/30":"bg-slate-100 dark:bg-slate-800"}`,children:a.jsx(sa,{className:`w-4 h-4 ${i.decisionActive?"text-purple-600 dark:text-purple-400":"text-slate-400"}`})}),a.jsxs("div",{className:"text-left",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:o}),a.jsx(Ht,{variant:i.decisionActive?"default":"secondary",className:"text-[10px] px-1.5 py-0",children:"决策模型"})]}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:i.decisionStage==="analyzing"?"Analyzing task...":i.decisionStage==="deciding"?"Making decision...":i.decisionStage==="generating"?"Generating content...":i.decisionActive?"Active":"Idle"})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[i.decisionActive&&a.jsx(Jt,{className:"w-4 h-4 text-purple-500 animate-spin"}),l==="decision"?a.jsx(oa,{className:"w-4 h-4 text-slate-400"}):a.jsx(ia,{className:"w-4 h-4 text-slate-400"})]})]}),l==="decision"&&a.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-slate-100 dark:border-slate-800",children:[i.decisionThinking&&a.jsxs("div",{className:"mt-2 p-2 bg-purple-50 dark:bg-purple-900/20 rounded-lg",children:[a.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[a.jsx(Wu,{className:"w-3 h-3 text-purple-500"}),a.jsx("span",{className:"text-[10px] font-medium text-purple-600 dark:text-purple-400",children:"Thinking"})]}),a.jsxs("p",{className:"text-xs text-purple-700 dark:text-purple-300 whitespace-pre-wrap",children:[i.decisionThinking,i.decisionActive&&a.jsx("span",{className:"inline-block w-1 h-3 ml-0.5 bg-purple-500 animate-pulse"})]})]}),i.decisionResult&&a.jsxs("div",{className:"mt-2 p-2 bg-slate-50 dark:bg-slate-900/50 rounded-lg",children:[a.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[a.jsx(ua,{className:"w-3 h-3 text-amber-500"}),a.jsx("span",{className:"text-[10px] font-medium text-slate-600 dark:text-slate-400",children:"Decision"})]}),a.jsx("p",{className:"text-xs text-slate-700 dark:text-slate-300",children:i.decisionResult})]}),i.decisions.length>0&&a.jsxs("details",{className:"mt-2",children:[a.jsxs("summary",{className:"text-[10px] text-slate-500 cursor-pointer hover:text-slate-700 dark:hover:text-slate-300",children:["View decision history (",i.decisions.length,")"]}),a.jsx("div",{className:"mt-1 space-y-1 max-h-32 overflow-y-auto",children:i.decisions.slice(-5).map((g,p)=>a.jsxs("div",{className:"text-[10px] p-1.5 bg-slate-100 dark:bg-slate-800 rounded",children:[a.jsxs("span",{className:"text-purple-600 dark:text-purple-400",children:["[",g.decision.action,"]"]})," ",g.decision.target]},p))})]})]})]}),a.jsxs(er,{className:`overflow-hidden transition-all duration-200 ${i.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:[a.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:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${i.visionActive?"bg-green-100 dark:bg-green-900/30":"bg-slate-100 dark:bg-slate-800"}`,children:a.jsx(ls,{className:`w-4 h-4 ${i.visionActive?"text-green-600 dark:text-green-400":"text-slate-400"}`})}),a.jsxs("div",{className:"text-left",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:u}),a.jsx(Ht,{variant:i.visionActive?"success":"secondary",className:"text-[10px] px-1.5 py-0",children:"视觉模型"})]}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:i.visionStage==="capturing"?"Capturing screen...":i.visionStage==="recognizing"?"Recognizing elements...":i.visionStage==="executing"?"Executing action...":i.visionActive?"Active":"Idle"})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[i.visionActive&&a.jsx(Jt,{className:"w-4 h-4 text-green-500 animate-spin"}),l==="vision"?a.jsx(oa,{className:"w-4 h-4 text-slate-400"}):a.jsx(ia,{className:"w-4 h-4 text-slate-400"})]})]}),l==="vision"&&a.jsxs("div",{className:"px-3 pb-3 space-y-2 border-t border-slate-100 dark:border-slate-800",children:[i.visionDescription&&a.jsxs("div",{className:"mt-2 p-2 bg-green-50 dark:bg-green-900/20 rounded-lg",children:[a.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[a.jsx(ls,{className:"w-3 h-3 text-green-500"}),a.jsx("span",{className:"text-[10px] font-medium text-green-600 dark:text-green-400",children:"Screen Recognition"})]}),a.jsx("p",{className:"text-xs text-green-700 dark:text-green-300 line-clamp-3",children:i.visionDescription})]}),i.visionAction&&a.jsxs("div",{className:"mt-2 p-2 bg-slate-50 dark:bg-slate-900/50 rounded-lg",children:[a.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[a.jsx(ua,{className:"w-3 h-3 text-amber-500"}),a.jsx("span",{className:"text-[10px] font-medium text-slate-600 dark:text-slate-400",children:"Action"})]}),a.jsx("p",{className:"text-xs text-slate-700 dark:text-slate-300",children:i.visionAction})]}),i.actions.length>0&&a.jsxs("details",{className:"mt-2",children:[a.jsxs("summary",{className:"text-[10px] text-slate-500 cursor-pointer hover:text-slate-700 dark:hover:text-slate-300",children:["View action history (",i.actions.length,")"]}),a.jsx("div",{className:"mt-1 space-y-1 max-h-32 overflow-y-auto",children:i.actions.slice(-5).map((g,p)=>a.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?a.jsx(kn,{className:"w-3 h-3 text-green-500"}):a.jsx(hi,{className:"w-3 h-3 text-red-500"}),a.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]})]},p))})]})]})]})]})}function yy(){const[i,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}})},[]),o=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:i,handleEvent:r,reset:o}}var Ci="Popover",[sf]=hs(Ci,[zu]),ms=zu(),[wy,rr]=sf(Ci),of=i=>{const{__scopePopover:n,children:r,open:o,defaultOpen:u,onOpenChange:l,modal:h=!1}=i,b=ms(n),f=v.useRef(null),[g,p]=v.useState(!1),[_,y]=ya({prop:o,defaultProp:u??!1,onChange:l,caller:Ci});return a.jsx(Y_,{...b,children:a.jsx(wy,{scope:n,contentId:ba(),triggerRef:f,open:_,onOpenChange:y,onOpenToggle:v.useCallback(()=>y(S=>!S),[y]),hasCustomAnchor:g,onCustomAnchorAdd:v.useCallback(()=>p(!0),[]),onCustomAnchorRemove:v.useCallback(()=>p(!1),[]),modal:h,children:r})})};of.displayName=Ci;var af="PopoverAnchor",Ey=v.forwardRef((i,n)=>{const{__scopePopover:r,...o}=i,u=rr(af,r),l=ms(r),{onCustomAnchorAdd:h,onCustomAnchorRemove:b}=u;return v.useEffect(()=>(h(),()=>b()),[h,b]),a.jsx(Hu,{...l,...o,ref:n})});Ey.displayName=af;var lf="PopoverTrigger",cf=v.forwardRef((i,n)=>{const{__scopePopover:r,...o}=i,u=rr(lf,r),l=ms(r),h=yn(n,u.triggerRef),b=a.jsx(Zt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":u.open,"aria-controls":u.contentId,"data-state":pf(u.open),...o,ref:h,onClick:dt(i.onClick,u.onOpenToggle)});return u.hasCustomAnchor?b:a.jsx(Hu,{asChild:!0,...l,children:b})});cf.displayName=lf;var Ia="PopoverPortal",[Sy,Ny]=sf(Ia,{forceMount:void 0}),uf=i=>{const{__scopePopover:n,forceMount:r,children:o,container:u}=i,l=rr(Ia,n);return a.jsx(Sy,{scope:n,forceMount:r,children:a.jsx(gr,{present:r||l.open,children:a.jsx(V_,{asChild:!0,container:u,children:o})})})};uf.displayName=Ia;var Ir="PopoverContent",df=v.forwardRef((i,n)=>{const r=Ny(Ir,i.__scopePopover),{forceMount:o=r.forceMount,...u}=i,l=rr(Ir,i.__scopePopover);return a.jsx(gr,{present:o||l.open,children:l.modal?a.jsx(ky,{...u,ref:n}):a.jsx(Ty,{...u,ref:n})})});df.displayName=Ir;var Cy=ra("PopoverContent.RemoveScroll"),ky=v.forwardRef((i,n)=>{const r=rr(Ir,i.__scopePopover),o=v.useRef(null),u=yn(n,o),l=v.useRef(!1);return v.useEffect(()=>{const h=o.current;if(h)return gv(h)},[]),a.jsx(xv,{as:Cy,allowPinchZoom:!0,children:a.jsx(ff,{...i,ref:u,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:dt(i.onCloseAutoFocus,h=>{h.preventDefault(),l.current||r.triggerRef.current?.focus()}),onPointerDownOutside:dt(i.onPointerDownOutside,h=>{const b=h.detail.originalEvent,f=b.button===0&&b.ctrlKey===!0,g=b.button===2||f;l.current=g},{checkForDefaultPrevented:!1}),onFocusOutside:dt(i.onFocusOutside,h=>h.preventDefault(),{checkForDefaultPrevented:!1})})})}),Ty=v.forwardRef((i,n)=>{const r=rr(Ir,i.__scopePopover),o=v.useRef(!1),u=v.useRef(!1);return a.jsx(ff,{...i,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{i.onCloseAutoFocus?.(l),l.defaultPrevented||(o.current||r.triggerRef.current?.focus(),l.preventDefault()),o.current=!1,u.current=!1},onInteractOutside:l=>{i.onInteractOutside?.(l),l.defaultPrevented||(o.current=!0,l.detail.originalEvent.type==="pointerdown"&&(u.current=!0));const h=l.target;r.triggerRef.current?.contains(h)&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&u.current&&l.preventDefault()}})}),ff=v.forwardRef((i,n)=>{const{__scopePopover:r,trapFocus:o,onOpenAutoFocus:u,onCloseAutoFocus:l,disableOutsidePointerEvents:h,onEscapeKeyDown:b,onPointerDownOutside:f,onFocusOutside:g,onInteractOutside:p,..._}=i,y=rr(Ir,r),S=ms(r);return _v(),a.jsx(vv,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:u,onUnmountAutoFocus:l,children:a.jsx(K_,{asChild:!0,disableOutsidePointerEvents:h,onInteractOutside:p,onEscapeKeyDown:b,onPointerDownOutside:f,onFocusOutside:g,onDismiss:()=>y.onOpenChange(!1),children:a.jsx(Q_,{"data-state":pf(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)"}})})})}),hf="PopoverClose",Ry=v.forwardRef((i,n)=>{const{__scopePopover:r,...o}=i,u=rr(hf,r);return a.jsx(Zt.button,{type:"button",...o,ref:n,onClick:dt(i.onClick,()=>u.onOpenChange(!1))})});Ry.displayName=hf;var Ay="PopoverArrow",Py=v.forwardRef((i,n)=>{const{__scopePopover:r,...o}=i,u=ms(r);return a.jsx(J_,{...u,...o,ref:n})});Py.displayName=Ay;function pf(i){return i?"open":"closed"}var jy=of,Iy=cf,Dy=uf,My=df;function xi({...i}){return a.jsx(jy,{"data-slot":"popover",...i})}function _i({...i}){return a.jsx(Iy,{"data-slot":"popover-trigger",...i})}function vi({className:i,align:n="center",sideOffset:r=4,...o}){return a.jsx(Dy,{children:a.jsx(My,{"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",i),...o})})}function Ly(i,[n,r]){return Math.min(r,Math.max(n,i))}function Oy(i,n){return v.useReducer((r,o)=>n[r][o]??r,i)}var Da="ScrollArea",[mf]=hs(Da),[Fy,mn]=mf(Da),gf=v.forwardRef((i,n)=>{const{__scopeScrollArea:r,type:o="hover",dir:u,scrollHideDelay:l=600,...h}=i,[b,f]=v.useState(null),[g,p]=v.useState(null),[_,y]=v.useState(null),[S,N]=v.useState(null),[P,T]=v.useState(null),[I,F]=v.useState(0),[A,$]=v.useState(0),[q,X]=v.useState(!1),[K,V]=v.useState(!1),O=yn(n,M=>f(M)),B=Na(u);return a.jsx(Fy,{scope:r,type:o,dir:B,scrollHideDelay:l,scrollArea:b,viewport:g,onViewportChange:p,content:_,onContentChange:y,scrollbarX:S,onScrollbarXChange:N,scrollbarXEnabled:q,onScrollbarXEnabledChange:X,scrollbarY:P,onScrollbarYChange:T,scrollbarYEnabled:K,onScrollbarYEnabledChange:V,onCornerWidthChange:F,onCornerHeightChange:$,children:a.jsx(Zt.div,{dir:B,...h,ref:O,style:{position:"relative","--radix-scroll-area-corner-width":I+"px","--radix-scroll-area-corner-height":A+"px",...i.style}})})});gf.displayName=Da;var xf="ScrollAreaViewport",_f=v.forwardRef((i,n)=>{const{__scopeScrollArea:r,children:o,nonce:u,...l}=i,h=mn(xf,r),b=v.useRef(null),f=yn(n,b,h.onViewportChange);return a.jsxs(a.Fragment,{children:[a.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}),a.jsx(Zt.div,{"data-radix-scroll-area-viewport":"",...l,ref:f,style:{overflowX:h.scrollbarXEnabled?"scroll":"hidden",overflowY:h.scrollbarYEnabled?"scroll":"hidden",...i.style},children:a.jsx("div",{ref:h.onContentChange,style:{minWidth:"100%",display:"table"},children:o})})]})});_f.displayName=xf;var An="ScrollAreaScrollbar",vf=v.forwardRef((i,n)=>{const{forceMount:r,...o}=i,u=mn(An,i.__scopeScrollArea),{onScrollbarXEnabledChange:l,onScrollbarYEnabledChange:h}=u,b=i.orientation==="horizontal";return v.useEffect(()=>(b?l(!0):h(!0),()=>{b?l(!1):h(!1)}),[b,l,h]),u.type==="hover"?a.jsx(By,{...o,ref:n,forceMount:r}):u.type==="scroll"?a.jsx(Uy,{...o,ref:n,forceMount:r}):u.type==="auto"?a.jsx(bf,{...o,ref:n,forceMount:r}):u.type==="always"?a.jsx(Ma,{...o,ref:n}):null});vf.displayName=An;var By=v.forwardRef((i,n)=>{const{forceMount:r,...o}=i,u=mn(An,i.__scopeScrollArea),[l,h]=v.useState(!1);return v.useEffect(()=>{const b=u.scrollArea;let f=0;if(b){const g=()=>{window.clearTimeout(f),h(!0)},p=()=>{f=window.setTimeout(()=>h(!1),u.scrollHideDelay)};return b.addEventListener("pointerenter",g),b.addEventListener("pointerleave",p),()=>{window.clearTimeout(f),b.removeEventListener("pointerenter",g),b.removeEventListener("pointerleave",p)}}},[u.scrollArea,u.scrollHideDelay]),a.jsx(gr,{present:r||l,children:a.jsx(bf,{"data-state":l?"visible":"hidden",...o,ref:n})})}),Uy=v.forwardRef((i,n)=>{const{forceMount:r,...o}=i,u=mn(An,i.__scopeScrollArea),l=i.orientation==="horizontal",h=Ti(()=>f("SCROLL_END"),100),[b,f]=Oy("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,p=l?"scrollLeft":"scrollTop";if(g){let _=g[p];const y=()=>{const S=g[p];_!==S&&(f("SCROLL"),h()),_=S};return g.addEventListener("scroll",y),()=>g.removeEventListener("scroll",y)}},[u.viewport,l,f,h]),a.jsx(gr,{present:r||b!=="hidden",children:a.jsx(Ma,{"data-state":b==="hidden"?"hidden":"visible",...o,ref:n,onPointerEnter:dt(i.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:dt(i.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),bf=v.forwardRef((i,n)=>{const r=mn(An,i.__scopeScrollArea),{forceMount:o,...u}=i,[l,h]=v.useState(!1),b=i.orientation==="horizontal",f=Ti(()=>{if(r.viewport){const g=r.viewport.offsetWidth<r.viewport.scrollWidth,p=r.viewport.offsetHeight<r.viewport.scrollHeight;h(b?g:p)}},10);return Dr(r.viewport,f),Dr(r.content,f),a.jsx(gr,{present:o||l,children:a.jsx(Ma,{"data-state":l?"visible":"hidden",...u,ref:n})})}),Ma=v.forwardRef((i,n)=>{const{orientation:r="vertical",...o}=i,u=mn(An,i.__scopeScrollArea),l=v.useRef(null),h=v.useRef(0),[b,f]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),g=Nf(b.viewport,b.content),p={...o,sizes:b,onSizesChange:f,hasThumb:g>0&&g<1,onThumbChange:y=>l.current=y,onThumbPointerUp:()=>h.current=0,onThumbPointerDown:y=>h.current=y};function _(y,S){return qy(y,h.current,b,S)}return r==="horizontal"?a.jsx(Wy,{...p,ref:n,onThumbPositionChange:()=>{if(u.viewport&&l.current){const y=u.viewport.scrollLeft,S=Uu(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"?a.jsx(zy,{...p,ref:n,onThumbPositionChange:()=>{if(u.viewport&&l.current){const y=u.viewport.scrollTop,S=Uu(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}),Wy=v.forwardRef((i,n)=>{const{sizes:r,onSizesChange:o,...u}=i,l=mn(An,i.__scopeScrollArea),[h,b]=v.useState(),f=v.useRef(null),g=yn(n,f,l.onScrollbarXChange);return v.useEffect(()=>{f.current&&b(getComputedStyle(f.current))},[f]),a.jsx(wf,{"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":ki(r)+"px",...i.style},onThumbPointerDown:p=>i.onThumbPointerDown(p.x),onDragScroll:p=>i.onDragScroll(p.x),onWheelScroll:(p,_)=>{if(l.viewport){const y=l.viewport.scrollLeft+p.deltaX;i.onWheelScroll(y),kf(y,_)&&p.preventDefault()}},onResize:()=>{f.current&&l.viewport&&h&&o({content:l.viewport.scrollWidth,viewport:l.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:yi(h.paddingLeft),paddingEnd:yi(h.paddingRight)}})}})}),zy=v.forwardRef((i,n)=>{const{sizes:r,onSizesChange:o,...u}=i,l=mn(An,i.__scopeScrollArea),[h,b]=v.useState(),f=v.useRef(null),g=yn(n,f,l.onScrollbarYChange);return v.useEffect(()=>{f.current&&b(getComputedStyle(f.current))},[f]),a.jsx(wf,{"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":ki(r)+"px",...i.style},onThumbPointerDown:p=>i.onThumbPointerDown(p.y),onDragScroll:p=>i.onDragScroll(p.y),onWheelScroll:(p,_)=>{if(l.viewport){const y=l.viewport.scrollTop+p.deltaY;i.onWheelScroll(y),kf(y,_)&&p.preventDefault()}},onResize:()=>{f.current&&l.viewport&&h&&o({content:l.viewport.scrollHeight,viewport:l.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:yi(h.paddingTop),paddingEnd:yi(h.paddingBottom)}})}})}),[Hy,yf]=mf(An),wf=v.forwardRef((i,n)=>{const{__scopeScrollArea:r,sizes:o,hasThumb:u,onThumbChange:l,onThumbPointerUp:h,onThumbPointerDown:b,onThumbPositionChange:f,onDragScroll:g,onWheelScroll:p,onResize:_,...y}=i,S=mn(An,r),[N,P]=v.useState(null),T=yn(n,O=>P(O)),I=v.useRef(null),F=v.useRef(""),A=S.viewport,$=o.content-o.viewport,q=Kn(p),X=Kn(f),K=Ti(_,10);function V(O){if(I.current){const B=O.clientX-I.current.left,M=O.clientY-I.current.top;g({x:B,y:M})}}return v.useEffect(()=>{const O=B=>{const M=B.target;N?.contains(M)&&q(B,$)};return document.addEventListener("wheel",O,{passive:!1}),()=>document.removeEventListener("wheel",O,{passive:!1})},[A,N,$,q]),v.useEffect(X,[o,X]),Dr(N,K),Dr(S.content,K),a.jsx(Hy,{scope:r,scrollbar:N,hasThumb:u,onThumbChange:Kn(l),onThumbPointerUp:Kn(h),onThumbPositionChange:X,onThumbPointerDown:Kn(b),children:a.jsx(Zt.div,{...y,ref:T,style:{position:"absolute",...y.style},onPointerDown:dt(i.onPointerDown,O=>{O.button===0&&(O.target.setPointerCapture(O.pointerId),I.current=N.getBoundingClientRect(),F.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",S.viewport&&(S.viewport.style.scrollBehavior="auto"),V(O))}),onPointerMove:dt(i.onPointerMove,V),onPointerUp:dt(i.onPointerUp,O=>{const B=O.target;B.hasPointerCapture(O.pointerId)&&B.releasePointerCapture(O.pointerId),document.body.style.webkitUserSelect=F.current,S.viewport&&(S.viewport.style.scrollBehavior=""),I.current=null})})})}),bi="ScrollAreaThumb",Ef=v.forwardRef((i,n)=>{const{forceMount:r,...o}=i,u=yf(bi,i.__scopeScrollArea);return a.jsx(gr,{present:r||u.hasThumb,children:a.jsx(Gy,{ref:n,...o})})}),Gy=v.forwardRef((i,n)=>{const{__scopeScrollArea:r,style:o,...u}=i,l=mn(bi,r),h=yf(bi,r),{onThumbPositionChange:b}=h,f=yn(n,_=>h.onThumbChange(_)),g=v.useRef(void 0),p=Ti(()=>{g.current&&(g.current(),g.current=void 0)},100);return v.useEffect(()=>{const _=l.viewport;if(_){const y=()=>{if(p(),!g.current){const S=Xy(_,b);g.current=S,b()}};return b(),_.addEventListener("scroll",y),()=>_.removeEventListener("scroll",y)}},[l.viewport,p,b]),a.jsx(Zt.div,{"data-state":h.hasThumb?"visible":"hidden",...u,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...o},onPointerDownCapture:dt(i.onPointerDownCapture,_=>{const S=_.target.getBoundingClientRect(),N=_.clientX-S.left,P=_.clientY-S.top;h.onThumbPointerDown({x:N,y:P})}),onPointerUp:dt(i.onPointerUp,h.onThumbPointerUp)})});Ef.displayName=bi;var La="ScrollAreaCorner",Sf=v.forwardRef((i,n)=>{const r=mn(La,i.__scopeScrollArea),o=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&o?a.jsx($y,{...i,ref:n}):null});Sf.displayName=La;var $y=v.forwardRef((i,n)=>{const{__scopeScrollArea:r,...o}=i,u=mn(La,r),[l,h]=v.useState(0),[b,f]=v.useState(0),g=!!(l&&b);return Dr(u.scrollbarX,()=>{const p=u.scrollbarX?.offsetHeight||0;u.onCornerHeightChange(p),f(p)}),Dr(u.scrollbarY,()=>{const p=u.scrollbarY?.offsetWidth||0;u.onCornerWidthChange(p),h(p)}),g?a.jsx(Zt.div,{...o,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,...i.style}}):null});function yi(i){return i?parseInt(i,10):0}function Nf(i,n){const r=i/n;return isNaN(r)?0:r}function ki(i){const n=Nf(i.viewport,i.content),r=i.scrollbar.paddingStart+i.scrollbar.paddingEnd,o=(i.scrollbar.size-r)*n;return Math.max(o,18)}function qy(i,n,r,o="ltr"){const u=ki(r),l=u/2,h=n||l,b=u-h,f=r.scrollbar.paddingStart+h,g=r.scrollbar.size-r.scrollbar.paddingEnd-b,p=r.content-r.viewport,_=o==="ltr"?[0,p]:[p*-1,0];return Cf([f,g],_)(i)}function Uu(i,n,r="ltr"){const o=ki(n),u=n.scrollbar.paddingStart+n.scrollbar.paddingEnd,l=n.scrollbar.size-u,h=n.content-n.viewport,b=l-o,f=r==="ltr"?[0,h]:[h*-1,0],g=Ly(i,f);return Cf([0,h],[0,b])(g)}function Cf(i,n){return r=>{if(i[0]===i[1]||n[0]===n[1])return n[0];const o=(n[1]-n[0])/(i[1]-i[0]);return n[0]+o*(r-i[0])}}function kf(i,n){return i>0&&i<n}var Xy=(i,n=()=>{})=>{let r={left:i.scrollLeft,top:i.scrollTop},o=0;return(function u(){const l={left:i.scrollLeft,top:i.scrollTop},h=r.left!==l.left,b=r.top!==l.top;(h||b)&&n(),r=l,o=window.requestAnimationFrame(u)})(),()=>window.cancelAnimationFrame(o)};function Ti(i,n){const r=Kn(i),o=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(o.current),[]),v.useCallback(()=>{window.clearTimeout(o.current),o.current=window.setTimeout(r,n)},[r,n])}function Dr(i,n){const r=Kn(n);Z_(()=>{let o=0;if(i){const u=new ResizeObserver(()=>{cancelAnimationFrame(o),o=window.requestAnimationFrame(r)});return u.observe(i),()=>{window.cancelAnimationFrame(o),u.unobserve(i)}}},[i,r])}var Yy=gf,Vy=_f,Ky=Sf;function cs({className:i,children:n,...r}){return a.jsxs(Yy,{"data-slot":"scroll-area",className:nr("relative",i),...r,children:[a.jsx(Vy,{"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}),a.jsx(Qy,{}),a.jsx(Ky,{})]})}function Qy({className:i,orientation:n="vertical",...r}){return a.jsx(vf,{"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",i),...r,children:a.jsx(Ef,{"data-slot":"scroll-area-thumb",className:"bg-border relative flex-1 rounded-full"})})}const Jy=100,Zy=20;function us(i,n,r,o){return{id:Date.now().toString(),deviceId:i||"unknown",deviceName:n||"Unknown Device",taskText:r?.content||"No task description",success:o?.success??!1,steps:o?.steps??0,startTime:r?.timestamp||new Date,endTime:o?.timestamp||new Date,duration:(o?.timestamp?.getTime()||Date.now())-(r?.timestamp?.getTime()||Date.now()),thinking:o?.thinking??[],actions:o?.actions??[],finalMessage:o?.content||"No result message",errorMessage:o?.success===!1?o?.content||"Unknown error":void 0}}function ds(i,n){try{const r=`history-${i}`,o=localStorage.getItem(r),u=o?JSON.parse(o):[];u.unshift(n);const l=u.slice(0,Jy);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 o=`history-${i}`,u=localStorage.getItem(o),h=(u?JSON.parse(u):[]).slice(0,Zy);h.unshift(n),localStorage.setItem(o,JSON.stringify(h))}catch(o){console.error("Failed to save history even after reduction:",o)}}else console.warn("Failed to save history:",r)}}function Tf(i){try{const n=`history-${i}`,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 Rf(i,n){try{const r=`history-${i}`,o=localStorage.getItem(r);if(!o)return;const l=JSON.parse(o).filter(h=>h.id!==n);localStorage.setItem(r,JSON.stringify(l))}catch(r){console.warn("Failed to delete history item:",r)}}function Af(i){try{const n=`history-${i}`;localStorage.removeItem(n)}catch(n){console.warn("Failed to clear history:",n)}}function ew(i){const r=new Date().getTime()-i.getTime(),o=Math.floor(r/6e4),u=Math.floor(r/36e5),l=Math.floor(r/864e5);return o<1?"Just now":o<60?`${o}m ago`:u<24?`${u}h ago`:l<7?`${l}d ago`:i.toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function tw(i){const n=Math.floor(i/1e3),r=Math.floor(n/60),o=n%60;return r===0?`${o}s`:`${r}m ${o}s`}function Pf({item:i,onSelect:n,onDelete:r}){const o=Mr(),u=l=>{l.stopPropagation(),confirm(o.history.deleteConfirm)&&r(i.id)};return a.jsx(er,{className:"hover:bg-slate-50 dark:hover:bg-slate-800/50 transition-colors cursor-pointer group",onClick:()=>n(i),children:a.jsxs("div",{className:"p-3 space-y-2",children:[a.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100 line-clamp-2",children:i.taskText}),a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[a.jsx("span",{children:ew(i.startTime)}),a.jsx("span",{children:"•"}),a.jsxs("span",{children:[i.steps," ",i.steps===1?"step":"steps"]}),a.jsx("span",{children:"•"}),a.jsx("span",{children:tw(i.duration)})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ht,{variant:i.success?"success":"destructive",className:"shrink-0",children:i.success?a.jsxs(a.Fragment,{children:[a.jsx(kn,{className:"w-3 h-3 mr-1"}),o.history.success]}):a.jsxs(a.Fragment,{children:[a.jsx(Cn,{className:"w-3 h-3 mr-1"}),o.history.failed]})}),a.jsx(_e,{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:o.history.deleteItem,children:a.jsx(bv,{className:"w-3 h-3"})})]})]})]})})}function nw({deviceId:i,deviceSerial:n,deviceName:r,config:o,isConfigured:u,thinkingMode:l="deep",onThinkingModeChange:h,dualModelEnabled:b=!1}){const f=Mr(),[g,p]=v.useState([]),[_,y]=v.useState(""),[S,N]=v.useState(!1),[P,T]=v.useState(!1),[I,F]=v.useState(null),[A,$]=v.useState(!1),[q,X]=v.useState(null),[K,V]=v.useState(!0),[O,B]=v.useState(!1),[M,me]=v.useState("auto"),[ye,G]=v.useState(null),[J,R]=v.useState("success"),[W,oe]=v.useState(!1),[de,ue]=v.useState([]),[Z,Se]=v.useState([]),[Pe,Fe]=v.useState(!1),[Le,at]=v.useState(!1),{state:lt,handleEvent:Ge,reset:Te}=yy(),$e=v.useRef(null),mt=(H,je=2e3,ve="success")=>{$e.current&&clearTimeout($e.current),R(ve),G(H),$e.current=setTimeout(()=>{G(null)},je)};v.useEffect(()=>()=>{$e.current&&clearTimeout($e.current)},[]);const[tt,Tt]=v.useState(!1),[Xe,gt]=v.useState(!1),ne=v.useRef(null),re=()=>{ne.current&&clearTimeout(ne.current),Tt(!0)},D=()=>{ne.current=setTimeout(()=>{Tt(!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),[Mt,st]=v.useState(!0),[en,Rt]=v.useState(!1),tn=v.useRef(Ld.throttle(()=>{const H=xt.current;if(!H)return;const je=80,ve=H.scrollHeight-H.scrollTop-H.clientHeight,nt=ve<=1;st(nt),ve<=je&&Rt(!1)},100));v.useEffect(()=>{const H=tn.current;return()=>{H.cancel()}},[]);const Qe=v.useCallback(async()=>{if(o)try{await ev({model_config:{base_url:o.base_url||void 0,api_key:o.api_key||void 0,model_name:o.model_name||void 0},agent_config:{device_id:i}}),$(!0),F(null)}catch(H){const je=H instanceof Error?H.message:"Initialization failed";F(je)}},[i,o]),Gt=v.useCallback(async()=>{if(o)try{await tv({device_id:i,decision_base_url:o.decision_base_url||"",decision_api_key:o.decision_api_key||"",decision_model_name:o.decision_model_name||"",vision_base_url:o.base_url,vision_api_key:o.api_key,vision_model_name:o.model_name,thinking_mode:l}),at(!0),F(null)}catch(H){const je=H instanceof Error?H.message:"Dual model initialization failed";F(je)}},[i,o,l]);v.useEffect(()=>{b&&!Le&&Gt()},[b,Le,Gt]),v.useEffect(()=>{b&&Le&&Gt()},[l]),v.useEffect(()=>{u&&o&&!A&&!Q.current&&(Q.current=!0,Qe())},[u,o,A,Qe]),v.useEffect(()=>{if(W){const H=Tf(n);ue(H)}},[W,n]);const nn=H=>{const je={id:`${H.id}-user`,role:"user",content:H.taskText,timestamp:H.startTime},ve={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=[je,ve];p(nt),ge.current=nt.length,Ke.current=[ve.id,ve.content?.length??0,ve.currentThinking?.length??0,ve.thinking?JSON.stringify(ve.thinking).length:0,ve.steps??"",ve.isStreaming?1:0].join("|"),Rt(!1),st(!0),oe(!1)},xr=()=>{confirm(f.history.clearAllConfirm)&&(Af(n),ue([]))},sr=H=>{Rf(n,H),ue(je=>je.filter(ve=>ve.id!==H))};v.useEffect(()=>{if(!A||!o)return;const H=ie.current;H&&(H.base_url!==o.base_url||H.model_name!==o.model_name||H.api_key!==o.api_key)&&(console.log(`[DevicePanel] Config changed for device ${i}, re-initializing...`),Qe()),ie.current=o},[o,A,i,Qe]);const He=v.useCallback(async()=>{const H=_.trim();if(!H||S)return;A||await Qe();const je={id:Date.now().toString(),role:"user",content:H,timestamp:new Date};p(Ze=>[...Ze,je]),y(""),N(!0),F(null);const ve=[],nt=[];let wn="";const ft=[];let Je=null;const ht=(Date.now()+1).toString(),Lt={id:ht,role:"assistant",content:"",timestamp:new Date,thinking:[],actions:[],isStreaming:!0,currentThinking:""};p(Ze=>[...Ze,Lt]);const Ur=()=>{if(ft.length>0){const Ze=ft.join("");ft.length=0,wn+=Ze,p(Ot=>Ot.map($t=>$t.id===ht?{...$t,currentThinking:wn}:$t))}Je=null},Ii=nv(je.content,i,Ze=>{ft.push(Ze.chunk),Je===null&&(Je=setTimeout(Ur,50))},Ze=>{Je!==null&&(clearTimeout(Je),Ur());const Ot=Ze.thinking&&Ze.thinking.length>0?Ze.thinking:wn;Ot&&ve.push(Ot),wn="",nt.push(Ze.action),p($t=>$t.map(rn=>rn.id===ht?{...rn,thinking:[...ve],actions:[...nt],steps:Ze.step,currentThinking:""}:rn))},Ze=>{Je!==null&&clearTimeout(Je);const Ot={...Lt,content:Ze.message,success:Ze.success,isStreaming:!1,steps:Ze.steps,thinking:[...ve],actions:[...nt],timestamp:new Date,currentThinking:void 0};p(rn=>rn.map(ir=>ir.id===ht?Ot:ir)),N(!1),le.current=null;const $t=us(n,r,je,Ot);ds(n,$t)},Ze=>{Je!==null&&clearTimeout(Je);const Ot={...Lt,content:`Error: ${Ze.message}`,success:!1,isStreaming:!1,thinking:[...ve],actions:[...nt],timestamp:new Date,currentThinking:void 0};p(rn=>rn.map(ir=>ir.id===ht?Ot:ir)),N(!1),F(Ze.message),le.current=null;const $t=us(n,r,je,Ot);ds(n,$t)},Ze=>{Je!==null&&clearTimeout(Je);const Ot={...Lt,content:Ze.message||"Chat aborted by user",success:!1,isStreaming:!1,thinking:[...ve],actions:[...nt],timestamp:new Date,currentThinking:void 0};p($t=>$t.map(rn=>rn.id===ht?Ot:rn)),N(!1),le.current=null,G(f.chat.aborted),R("success"),setTimeout(()=>G(null),2e3)});le.current=Ii},[_,S,A,i,n,r,Qe,f,G,R]),At=v.useCallback(async()=>{const H=_.trim();if(!H||S)return;Le||await Gt();const je={id:Date.now().toString(),role:"user",content:H,timestamp:new Date};p(ft=>[...ft,je]),y(""),N(!0),F(null),Te();const ve=(Date.now()+1).toString(),nt={id:ve,role:"assistant",content:"",timestamp:new Date,thinking:[],actions:[],isStreaming:!0};p(ft=>[...ft,nt]);const wn=rv(je.content,i,ft=>{if(Ge(ft),ft.type==="task_complete"){const Je=ft;p(ht=>ht.map(Lt=>Lt.id===ve?{...Lt,content:Je.message,success:Je.success,steps:Je.steps,isStreaming:!1}:Lt)),N(!1),ce.current=null}else if(ft.type==="error"){const Je=ft;p(ht=>ht.map(Lt=>Lt.id===ve?{...Lt,content:`Error: ${Je.message}`,success:!1,isStreaming:!1}:Lt)),N(!1),F(Je.message),ce.current=null}else ft.type==="aborted"&&(p(Je=>Je.map(ht=>ht.id===ve?{...ht,content:"Task aborted",success:!1,isStreaming:!1}:ht)),N(!1),ce.current=null)},ft=>{p(Je=>Je.map(ht=>ht.id===ve?{...ht,content:`Error: ${ft.message}`,success:!1,isStreaming:!1}:ht)),N(!1),F(ft.message),ce.current=null});ce.current=wn},[_,S,Le,i,Gt,Ge,Te]),wt=v.useCallback(async()=>{b?await At():await He()},[b,At,He]),Pt=v.useCallback(async()=>{le.current&&le.current.close(),ce.current&&ce.current.close(),p([]),N(!1),F(null),Rt(!1),st(!0),le.current=null,ce.current=null,ge.current=0,Ke.current=null,Te(),b?await sv(i):await iv(i)},[i,b,Te]),Pn=v.useCallback(async()=>{if(!(!le.current&&!ce.current)){T(!0);try{le.current&&(le.current.close(),le.current=null),ce.current&&(ce.current.close(),ce.current=null),p(H=>{const je=H[H.length-1];return je&&je.role==="assistant"&&je.isStreaming?H.map((ve,nt)=>nt===H.length-1?{...ve,content:ve.content||f.chat.aborted,isStreaming:!1,success:!1,currentThinking:void 0}:ve):H}),b?ov(i).catch(H=>console.error("Backend abort failed:",H)):av(i).catch(H=>console.error("Backend abort failed:",H)),G(f.chat.aborted),R("success"),setTimeout(()=>G(null),2e3)}catch(H){console.error("Failed to abort chat:",H),G(f.chat.abortFailed),R("error"),setTimeout(()=>G(null),2e3)}finally{N(!1),T(!1)}}},[i,b,f]),Or=v.useCallback(()=>{we.current?.scrollIntoView({behavior:"smooth"})},[]);v.useEffect(()=>{const H=g[g.length-1],je=H?.thinking?JSON.stringify(H.thinking).length:0,ve=H?[H.id,H.content?.length??0,H.currentThinking?.length??0,je,H.steps??"",H.isStreaming?1:0].join("|"):null,nt=g.length>ge.current,wn=ve!==Ke.current&&g.length>0;if(ge.current=g.length,Ke.current=ve,Mt){Or(),Rt(!1);return}if(g.length===0){Rt(!1);return}(nt||wn)&&Rt(!0)},[g,Mt,Or]),v.useEffect(()=>()=>{le.current&&le.current.close(),ce.current&&ce.current.close(),Ce.current&&Ce.current.close()},[i]),v.useEffect(()=>{(async()=>{try{const je=await $u();Se(je.workflows)}catch(je){console.error("Failed to load workflows:",je)}})()},[]);const Ri=H=>{y(H.text),Fe(!1)},gs=()=>{tn.current()},Ai=()=>{Or(),Rt(!1),st(!0)};v.useEffect(()=>{if(!i||!(M==="screenshot"||M==="auto"&&O))return;const je=async()=>{if(!bt.current){bt.current=!0;try{const nt=await wa(i);nt.success&&X(nt)}catch(nt){console.error("Failed to fetch screenshot:",nt)}finally{bt.current=!1}}};je();const ve=setInterval(je,500);return()=>clearInterval(ve)},[i,O,M]);const Pi=H=>{(H.metaKey||H.ctrlKey)&&H.key==="Enter"&&(H.preventDefault(),wt())},ji=v.useCallback(H=>{Ce.current=H},[]),Fr=v.useCallback(()=>{B(!0),V(!1)},[]),Br=H=>{me(H)};return a.jsxs("div",{className:"flex-1 flex gap-4 p-4 items-stretch justify-center min-h-0",children:[a.jsxs(er,{className:"flex-1 flex flex-col min-h-0 max-w-2xl",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:a.jsx(is,{className:"h-5 w-5 text-[#1d9bf0]"})}),a.jsxs("div",{className:"group",children:[a.jsx("div",{className:"flex items-center gap-1",children:a.jsx("h2",{className:"font-bold text-slate-900 dark:text-slate-100",children:r})}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 font-mono",children:i})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(xi,{open:W,onOpenChange:oe,children:[a.jsx(_i,{asChild:!0,children:a.jsx(_e,{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:a.jsx(pi,{className:"h-4 w-4"})})}),a.jsxs(vi,{className:"w-96 p-0",align:"end",sideOffset:8,children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[a.jsx("h3",{className:"font-semibold text-sm text-slate-900 dark:text-slate-100",children:f.history.title}),de.length>0&&a.jsx(_e,{variant:"ghost",size:"sm",onClick:xr,className:"h-7 text-xs",children:f.history.clearAll})]}),a.jsx(cs,{className:"h-[400px]",children:a.jsx("div",{className:"p-4 space-y-2",children:de.length>0?de.map(H=>a.jsx(Pf,{item:H,onSelect:nn,onDelete:sr},H.id)):a.jsxs("div",{className:"text-center py-8",children:[a.jsx(pi,{className:"h-12 w-12 text-slate-300 dark:text-slate-700 mx-auto mb-3"}),a.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:f.history.noHistory}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1",children:f.history.noHistoryDescription})]})})})]})]}),u?A?a.jsxs(Ht,{variant:"success",children:[a.jsx(kn,{className:"w-3 h-3 mr-1"}),f.devicePanel.ready]}):a.jsx(_e,{onClick:Qe,disabled:!u||!o,size:"sm",variant:"twitter",children:f.devicePanel.initializing}):a.jsxs(Ht,{variant:"warning",children:[a.jsx(Cn,{className:"w-3 h-3 mr-1"}),f.devicePanel.noConfig]}),b&&h&&a.jsxs(a.Fragment,{children:[a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.jsx(_e,{variant:l==="fast"?"default":"ghost",size:"icon",onClick:()=>h("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:a.jsx(ua,{className:"h-4 w-4"})})}),a.jsx(Zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.fastMode}),a.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.fastModeDesc})]})})]}),a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.jsx(_e,{variant:l==="deep"?"default":"ghost",size:"icon",onClick:()=>h("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:a.jsx(od,{className:"h-4 w-4"})})}),a.jsx(Zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.deepMode}),a.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.deepModeDesc})]})})]}),a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.jsx(_e,{variant:l==="turbo"?"default":"ghost",size:"icon",onClick:()=>h("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:a.jsx($v,{className:"h-4 w-4"})})}),a.jsx(Zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.turboMode}),a.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.turboModeDesc})]})})]})]}),a.jsx(_e,{variant:"ghost",size:"icon",onClick:Pt,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:a.jsx(nd,{className:"h-4 w-4"})})]})]}),b&&a.jsx("div",{className:"border-b border-slate-200 dark:border-slate-800 p-4",children:a.jsx(by,{state:lt,isStreaming:S,className:"",decisionModelName:o?.decision_model_name||"",visionModelName:o?.model_name||"autoglm-phone"})}),I&&a.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:[a.jsx(Cn,{className:"w-4 h-4 flex-shrink-0"}),I]}),a.jsxs("div",{className:"flex-1 min-h-0 relative",children:[a.jsxs("div",{className:"h-full overflow-y-auto p-4",ref:xt,onScroll:gs,children:[g.length===0?a.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center min-h-[calc(100%-1rem)]",children:[a.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800 mb-4",children:a.jsx(is,{className:"h-8 w-8 text-slate-400"})}),a.jsx("p",{className:"font-medium text-slate-900 dark:text-slate-100",children:f.devicePanel.readyToHelp}),a.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:f.devicePanel.describeTask})]}):g.map(H=>a.jsx("div",{className:`flex ${H.role==="user"?"justify-end":"justify-start"}`,children:H.role==="assistant"?a.jsxs("div",{className:"max-w-[85%] space-y-3",children:[H.thinking?.map((je,ve)=>a.jsxs("div",{className:"bg-slate-100 dark:bg-slate-800 rounded-2xl rounded-tl-sm px-4 py-3",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:a.jsx(is,{className:"h-3 w-3 text-[#1d9bf0]"})}),a.jsxs("span",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:["Step ",ve+1]})]}),a.jsx("p",{className:"text-sm whitespace-pre-wrap text-slate-700 dark:text-slate-300",children:je}),H.actions?.[ve]&&a.jsxs("details",{className:"mt-2 text-xs",children:[a.jsx("summary",{className:"cursor-pointer text-[#1d9bf0] hover:text-[#1a8cd8]",children:"View action"}),a.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[ve],null,2)})]})]},ve)),H.currentThinking&&a.jsxs("div",{className:"bg-slate-100 dark:bg-slate-800 rounded-2xl rounded-tl-sm px-4 py-3",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:a.jsx(is,{className:"h-3 w-3 text-[#1d9bf0] animate-pulse"})}),a.jsx("span",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:"Thinking..."})]}),a.jsxs("p",{className:"text-sm whitespace-pre-wrap text-slate-700 dark:text-slate-300",children:[H.currentThinking,a.jsx("span",{className:"inline-block w-1 h-4 ml-0.5 bg-[#1d9bf0] animate-pulse"})]})]}),H.content&&a.jsxs("div",{className:`
122
+ rounded-2xl px-4 py-3 flex items-start gap-2
123
+ ${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"}
124
+ `,children:[a.jsx(kn,{className:`w-5 h-5 flex-shrink-0 mt-0.5 ${H.success===!1?"text-red-500":"text-green-500"}`}),a.jsxs("div",{children:[a.jsx("p",{className:"whitespace-pre-wrap",children:H.content}),H.steps!==void 0&&a.jsxs("p",{className:"text-xs mt-2 opacity-60 text-slate-500 dark:text-slate-400",children:[H.steps," steps completed"]})]})]}),H.isStreaming&&a.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400",children:[a.jsx(Jt,{className:"w-4 h-4 animate-spin"}),"Processing..."]})]}):a.jsxs("div",{className:"max-w-[75%]",children:[a.jsx("div",{className:"chat-bubble-user px-4 py-3",children:a.jsx("p",{className:"whitespace-pre-wrap",children:H.content})}),a.jsx("p",{className:"text-xs text-slate-400 dark:text-slate-500 mt-1 text-right",children:H.timestamp.toLocaleTimeString()})]})},H.id)),a.jsx("div",{ref:we})]}),en&&a.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-4 flex justify-center",children:a.jsx(_e,{onClick:Ai,size:"sm",className:"pointer-events-auto shadow-lg bg-[#1d9bf0] text-white hover:bg-[#1a8cd8]","aria-label":f.devicePanel.newMessages,children:f.devicePanel.newMessages})})]}),a.jsx("div",{className:"p-4 border-t border-slate-200 dark:border-slate-800",children:a.jsxs("div",{className:"flex items-end gap-3",children:[a.jsx(Ju,{value:_,onChange:H=>y(H.target.value),onKeyDown:Pi,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}),a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.jsxs(xi,{open:Pe,onOpenChange:Fe,children:[a.jsx(_i,{asChild:!0,children:a.jsx(_e,{variant:"outline",size:"icon",className:"h-10 w-10 flex-shrink-0",children:a.jsx(Gu,{className:"w-4 h-4"})})}),a.jsx(vi,{align:"start",className:"w-72 p-3",children:a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"font-medium text-sm",children:f.workflows.selectWorkflow}),Z.length===0?a.jsxs("div",{className:"text-sm text-slate-500 dark:text-slate-400 space-y-1",children:[a.jsx("p",{children:f.workflows.empty}),a.jsxs("p",{children:["前往"," ",a.jsx("a",{href:"/workflows",className:"text-primary underline",children:"工作流"})," ","页面创建。"]})]}):a.jsx(cs,{className:"h-64",children:a.jsx("div",{className:"space-y-1",children:Z.map(H=>a.jsxs("button",{onClick:()=>Ri(H),className:"w-full text-left p-2 rounded hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:[a.jsx("div",{className:"font-medium text-sm",children:H.name}),a.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400 line-clamp-2",children:H.text})]},H.uuid))})})]})})]})}),a.jsx(Zn,{side:"top",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:f.devicePanel.tooltips.workflowButton}),a.jsx("p",{className:"text-xs opacity-80",children:f.devicePanel.tooltips.workflowButtonDesc})]})})]}),S&&a.jsx(_e,{onClick:Pn,disabled:P,size:"icon",variant:"destructive",className:"h-10 w-10 rounded-full flex-shrink-0",title:f.chat.abortChat,children:P?a.jsx(Jt,{className:"h-4 w-4 animate-spin"}):a.jsx(id,{className:"h-4 w-4"})}),!S&&a.jsx(_e,{onClick:wt,disabled:!_.trim(),size:"icon",variant:"twitter",className:"h-10 w-10 rounded-full flex-shrink-0",children:a.jsx(rd,{className:"h-4 w-4"})})]})})]}),a.jsxs(er,{className:"w-[320px] flex-shrink-0 relative min-h-0 overflow-hidden bg-background",onMouseEnter:re,onMouseLeave:D,children:[a.jsx("div",{className:`absolute top-4 right-4 z-10 transition-opacity duration-200 ${tt?"opacity-100":"opacity-0 pointer-events-none"}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.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:[a.jsx(_e,{variant:"ghost",size:"sm",onClick:()=>Br("auto"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${M==="auto"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:f.devicePanel.auto}),a.jsxs(_e,{variant:"ghost",size:"sm",onClick:()=>Br("video"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${M==="video"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[a.jsx(ad,{className:"w-3 h-3 mr-1"}),f.devicePanel.video]}),a.jsxs(_e,{variant:"ghost",size:"sm",onClick:()=>Br("screenshot"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${M==="screenshot"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[a.jsx(mi,{className:"w-3 h-3 mr-1"}),f.devicePanel.image]})]}),a.jsx(_e,{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?a.jsx(Sa,{className:"w-4 h-4"}):a.jsx(Ea,{className:"w-4 h-4"})})]})}),a.jsx("div",{className:"absolute bottom-4 left-4 z-10",children:a.jsxs(Ht,{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:[M==="auto"&&f.devicePanel.auto,M==="video"&&a.jsxs(a.Fragment,{children:[a.jsx(td,{className:"w-3 h-3 mr-1"}),f.devicePanel.video]}),M==="screenshot"&&a.jsxs(a.Fragment,{children:[a.jsx(mi,{className:"w-3 h-3 mr-1"}),f.devicePanel.imageRefresh]})]})}),ye&&a.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"&&a.jsx(Cn,{className:"w-4 h-4"}),J==="tap"&&a.jsx(ed,{className:"w-4 h-4"}),J==="swipe"&&a.jsx(Zu,{className:"w-4 h-4"}),J==="success"&&a.jsx(kn,{className:"w-4 h-4"}),a.jsx("span",{children:ye})]}),M==="video"||M==="auto"&&K&&!O?a.jsx(nf,{deviceId:i,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:ji,fallbackTimeout:1e5}):a.jsx("div",{className:"w-full h-full flex items-center justify-center bg-muted/30 min-h-0",children:q&&q.success?a.jsxs("div",{className:"relative w-full h-full flex items-center justify-center min-h-0",children:[a.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&&a.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?a.jsxs("div",{className:"text-center text-destructive",children:[a.jsx(Cn,{className:"w-8 h-8 mx-auto mb-2"}),a.jsx("p",{className:"font-medium",children:f.devicePanel.screenshotFailed}),a.jsx("p",{className:"text-xs mt-1 opacity-60",children:q.error})]}):a.jsxs("div",{className:"text-center text-muted-foreground",children:[a.jsx(Jt,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),a.jsx("p",{className:"text-sm",children:f.devicePanel.loading})]})})]})]})}function rw({deviceId:i,deviceSerial:n,deviceName:r,isVisible:o}){const u=Mr(),[l,h]=v.useState([]),[b,f]=v.useState(""),[g,p]=v.useState(!1),[_,y]=v.useState(!1),[S,N]=v.useState(null),P=v.useRef(null),T=v.useRef(null),I=v.useRef(null),[F,A]=v.useState(!0),[$,q]=v.useState(!1),[X,K]=v.useState("auto"),[V,O]=v.useState(null),[B,M]=v.useState(null),[me,ye]=v.useState("success"),G=v.useRef(null),[J,R]=v.useState(!1),[W,oe]=v.useState(!1),de=v.useRef(null),ue=v.useRef(null),Z=v.useRef(!1),[Se,Pe]=v.useState([]),[Fe,Le]=v.useState(!1),[at,lt]=v.useState([]),[Ge,Te]=v.useState(!1),$e=(Q,ie=2e3,ge="success")=>{G.current&&clearTimeout(G.current),ye(ge),M(Q),G.current=setTimeout(()=>{M(null)},ie)};v.useEffect(()=>{P.current?.scrollIntoView({behavior:"smooth"})},[l]),v.useEffect(()=>()=>{G.current&&clearTimeout(G.current),T.current&&T.current.close()},[]);const mt=()=>{de.current&&clearTimeout(de.current),R(!0)},tt=()=>{de.current=setTimeout(()=>{R(!1)},500)};v.useEffect(()=>()=>{de.current&&clearTimeout(de.current)},[]);const Tt=()=>{oe(Q=>!Q)};v.useEffect(()=>()=>{ue.current&&ue.current.close()},[i]),v.useEffect(()=>{(async()=>{try{const ie=await $u();Pe(ie.workflows)}catch(ie){console.error("Failed to load workflows:",ie)}})()},[]),v.useEffect(()=>{if(Ge){const Q=Tf(n);lt(Q)}},[Ge,n]);const Xe=Q=>{f(Q.text),Le(!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};h([ie,ge]),Te(!1)},ne=()=>{confirm(u.history?.clearAllConfirm||"Clear all history?")&&(Af(n),lt([]))},re=Q=>{Rf(n,Q),lt(ie=>ie.filter(ge=>ge.id!==Q))};v.useEffect(()=>{if(!i||!o||!(X==="screenshot"||X==="auto"&&$))return;const ie=async()=>{if(!Z.current){Z.current=!0;try{const Ke=await wa(i);Ke.success&&O(Ke)}catch(Ke){console.error("Failed to fetch screenshot:",Ke)}finally{Z.current=!1}}};ie();const ge=setInterval(ie,500);return()=>clearInterval(ge)},[i,$,X,o]);const D=v.useCallback(Q=>{ue.current=Q},[]),ee=v.useCallback(()=>{q(!0),A(!1)},[]),le=Q=>{K(Q)},ce=(Q,ie)=>{h(ge=>ge.map(Ke=>Ke.id===Q?{...Ke,steps:Ke.steps?.map(Mt=>Mt.id===ie?{...Mt,isExpanded:!Mt.isExpanded}:Mt)}: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};h(st=>[...st,ie]),f(""),p(!0),N(null);const ge=(Date.now()+1).toString(),Ke={id:ge,role:"assistant",content:"",timestamp:new Date,steps:[],isStreaming:!0};h(st=>[...st,Ke]);const Mt=new AbortController;I.current=Mt;try{const st=await fetch("/api/layered-agent/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:Q,device_id:i,session_id:i}),signal:Mt.signal});if(!st.ok)throw new Error(`HTTP error! status: ${st.status}`);const en=st.body?.getReader();if(!en)throw new Error("No response body");const Rt=new TextDecoder;let tn="";const Qe=[];for(;;){const{done:Gt,value:nn}=await en.read();if(Gt)break;tn+=Rt.decode(nn,{stream:!0});const xr=tn.split(`
125
+ `);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 At={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(At),h(wt=>wt.map(Pt=>Pt.id===ge?{...Pt,steps:[...Qe]}:Pt))}else if(He.type==="tool_result"){const At={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(At),h(wt=>wt.map(Pt=>Pt.id===ge?{...Pt,steps:[...Qe]}:Pt))}else if(He.type==="message")h(At=>At.map(wt=>wt.id===ge?{...wt,content:He.content}:wt));else if(He.type==="done"){const At={...Ke,content:He.content||"",isStreaming:!1,success:He.success,steps:[...Qe],timestamp:new Date};h(Pt=>Pt.map(Pn=>Pn.id===ge?At:Pn));const wt=us(n,r,ie,{content:He.content||"",timestamp:new Date,success:He.success,steps:Qe.length});ds(n,wt)}else if(He.type==="error"){const At={...Ke,content:`错误: ${He.message}`,isStreaming:!1,success:!1,steps:[...Qe],timestamp:new Date};h(Pt=>Pt.map(Pn=>Pn.id===ge?At:Pn)),N(He.message);const wt=us(n,r,ie,{content:`错误: ${He.message}`,timestamp:new Date,success:!1,steps:Qe.length});ds(n,wt)}}catch(He){console.error("Failed to parse SSE data:",He,sr)}}h(Gt=>Gt.map(nn=>nn.id===ge&&nn.isStreaming?{...nn,isStreaming:!1,success:!0}:nn))}catch(st){if(st instanceof Error&&st.name==="AbortError"){console.log("Chat aborted by user");return}console.error("Chat error:",st);const en=st instanceof Error?st.message:"Unknown error";N(en),h(tn=>tn.map(Qe=>Qe.id===ge?{...Qe,content:`错误: ${en}`,isStreaming:!1,success:!1}:Qe));const Rt=us(n,r,ie,{content:`错误: ${en}`,timestamp:new Date,success:!1,steps:0});ds(n,Rt)}finally{p(!1),I.current=null}},[b,g,i,n,r]),we=v.useCallback(()=>{if(I.current){y(!0);try{I.current.abort(),I.current=null,h(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}),$e(u.chat?.aborted||"任务已中断",2e3,"success")}catch(Q){console.error("Failed to abort chat:",Q),$e(u.chat?.abortFailed||"中断失败",2e3,"error")}finally{p(!1),y(!1)}}},[u]),xt=v.useCallback(async()=>{I.current&&(I.current.abort(),I.current=null),h([]),N(null),T.current&&(T.current.close(),T.current=null);try{await fetch("/api/layered-agent/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:i})})}catch(Q){console.warn("Failed to reset backend session:",Q)}},[i]),bt=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key==="Enter"&&(Q.preventDefault(),Ce())};return a.jsxs("div",{className:"flex-1 flex gap-4 p-4 items-stretch justify-center min-h-0",children:[a.jsxs(er,{className:"flex-1 flex flex-col min-h-0 max-w-2xl overflow-hidden",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-purple-500/10",children:a.jsx(aa,{className:"h-5 w-5 text-purple-500"})}),a.jsxs("div",{children:[a.jsx("h2",{className:"font-bold text-slate-900 dark:text-slate-100",children:u.chatkit?.title||"AI Agent"}),a.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:[r," • ",u.chatkit?.layeredAgent||"分层代理模式"]})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ht,{variant:"secondary",className:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300",children:u.chatkit?.layeredAgent||"分层代理模式"}),a.jsxs(xi,{open:Ge,onOpenChange:Te,children:[a.jsx(_i,{asChild:!0,children:a.jsx(_e,{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:a.jsx(pi,{className:"h-4 w-4"})})}),a.jsxs(vi,{className:"w-96 p-0",align:"end",sideOffset:8,children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[a.jsx("h3",{className:"font-semibold text-sm text-slate-900 dark:text-slate-100",children:u.history?.title||"History"}),at.length>0&&a.jsx(_e,{variant:"ghost",size:"sm",onClick:ne,className:"h-7 text-xs",children:u.history?.clearAll||"Clear All"})]}),a.jsx(cs,{className:"h-[400px]",children:a.jsx("div",{className:"p-4 space-y-2",children:at.length>0?at.map(Q=>a.jsx(Pf,{item:Q,onSelect:gt,onDelete:re},Q.id)):a.jsxs("div",{className:"text-center py-8",children:[a.jsx(pi,{className:"h-12 w-12 text-slate-300 dark:text-slate-700 mx-auto mb-3"}),a.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:u.history?.noHistory||"No history yet"}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1",children:u.history?.noHistoryDescription||"Your completed tasks will appear here"})]})})})]})]}),a.jsx(_e,{variant:"ghost",size:"icon",onClick:xt,className:"h-8 w-8 rounded-full",title:"重置对话",children:a.jsx(nd,{className:"h-4 w-4"})})]})]}),S&&a.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:[a.jsx(Cn,{className:"w-4 h-4 flex-shrink-0"}),S]}),a.jsx(cs,{className:"flex-1 min-h-0",children:a.jsxs("div",{className:"p-4 space-y-4",children:[l.length===0?a.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center py-12",children:[a.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:a.jsx(aa,{className:"h-8 w-8 text-purple-500"})}),a.jsx("p",{className:"font-medium text-slate-900 dark:text-slate-100",children:u.chatkit?.title||"分层代理模式"}),a.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400 max-w-xs",children:u.chatkit?.layeredAgentDesc||"决策模型负责规划任务,视觉模型负责执行。你可以看到每一步的执行过程。"})]}):l.map(Q=>a.jsx("div",{className:"space-y-2",children:Q.role==="user"?a.jsx("div",{className:"flex justify-end",children:a.jsxs("div",{className:"max-w-[80%]",children:[a.jsx("div",{className:"bg-purple-600 text-white px-4 py-2 rounded-2xl rounded-br-sm",children:a.jsx("p",{className:"whitespace-pre-wrap",children:Q.content})}),a.jsx("p",{className:"text-xs text-slate-400 mt-1 text-right",children:Q.timestamp.toLocaleTimeString()})]})}):a.jsxs("div",{className:"space-y-3",children:[Q.steps&&Q.steps.length>0&&a.jsx("div",{className:"space-y-2",children:Q.steps.map((ie,ge)=>a.jsxs("div",{className:"bg-slate-50 dark:bg-slate-800/50 rounded-xl border border-slate-200 dark:border-slate-700 overflow-hidden",children:[a.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:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.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"?a.jsx(s1,{className:"w-3 h-3"}):a.jsx(Wu,{className:"w-3 h-3"})}),a.jsxs("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-300",children:["Step ",ge+1,": ",ie.content]})]}),ie.isExpanded?a.jsx(oa,{className:"w-4 h-4 text-slate-400"}):a.jsx(ia,{className:"w-4 h-4 text-slate-400"})]}),ie.isExpanded&&a.jsxs("div",{className:"px-3 pb-3 space-y-2",children:[ie.type==="tool_call"&&ie.toolArgs&&a.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-3 text-sm",children:[a.jsx("p",{className:"text-xs text-slate-500 mb-1 font-medium",children:ie.toolName==="chat"?"发送给 Phone Agent 的指令:":"工具参数:"}),ie.toolName==="chat"?a.jsx("p",{className:"text-slate-700 dark:text-slate-300 whitespace-pre-wrap",children:ie.toolArgs.message||JSON.stringify(ie.toolArgs,null,2)}):a.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&&a.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-3 text-sm",children:[a.jsx("p",{className:"text-xs text-slate-500 mb-1 font-medium",children:"执行结果:"}),a.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&&a.jsx("div",{className:"flex justify-start",children:a.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:a.jsxs("div",{className:"flex items-start gap-2",children:[Q.success!==void 0&&a.jsx(kn,{className:`w-5 h-5 flex-shrink-0 mt-0.5 ${Q.success?"text-green-500":"text-red-500"}`}),a.jsx("p",{className:"whitespace-pre-wrap",children:Q.content})]})})}),Q.isStreaming&&!Q.content&&a.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[a.jsx(Jt,{className:"w-4 h-4 animate-spin"}),"正在思考和执行..."]})]})},Q.id)),a.jsx("div",{ref:P})]})}),a.jsx("div",{className:"p-4 border-t border-slate-200 dark:border-slate-800",children:a.jsxs("div",{className:"flex items-end gap-3",children:[a.jsx(Ju,{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}),a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.jsxs(xi,{open:Fe,onOpenChange:Le,children:[a.jsx(_i,{asChild:!0,children:a.jsx(_e,{variant:"outline",size:"icon",className:"h-10 w-10 flex-shrink-0",children:a.jsx(Gu,{className:"w-4 h-4"})})}),a.jsx(vi,{align:"start",className:"w-72 p-3",children:a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"font-medium text-sm",children:u.workflows?.selectWorkflow||"Select Workflow"}),Se.length===0?a.jsxs("div",{className:"text-sm text-slate-500 dark:text-slate-400 space-y-1",children:[a.jsx("p",{children:u.workflows?.empty||"No workflows yet"}),a.jsxs("p",{children:["前往"," ",a.jsx("a",{href:"/workflows",className:"text-primary underline",children:"工作流"})," ","页面创建。"]})]}):a.jsx(cs,{className:"h-64",children:a.jsx("div",{className:"space-y-1",children:Se.map(Q=>a.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:[a.jsx("div",{className:"font-medium text-sm",children:Q.name}),a.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400 line-clamp-2",children:Q.text})]},Q.uuid))})})]})})]})}),a.jsx(Zn,{side:"top",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:u.devicePanel?.tooltips?.workflowButton||"Quick Workflow"}),a.jsx("p",{className:"text-xs opacity-80",children:u.devicePanel?.tooltips?.workflowButtonDesc||"Select a workflow to quickly fill in the task"})]})})]}),g&&a.jsx(_e,{onClick:we,disabled:_,size:"icon",variant:"destructive",className:"h-10 w-10 rounded-full flex-shrink-0",title:u.chat?.abortChat||"中断任务",children:_?a.jsx(Jt,{className:"h-4 w-4 animate-spin"}):a.jsx(id,{className:"h-4 w-4"})}),!g&&a.jsx(_e,{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:a.jsx(rd,{className:"h-4 w-4"})})]})})]}),a.jsxs(er,{className:"w-[320px] flex-shrink-0 relative min-h-0 overflow-hidden bg-background",onMouseEnter:mt,onMouseLeave:tt,children:[a.jsx("div",{className:`absolute top-4 right-4 z-10 transition-opacity duration-200 ${J?"opacity-100":"opacity-0 pointer-events-none"}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.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 ${W?"opacity-100 translate-x-0":"opacity-0 translate-x-4 pointer-events-none"}`,children:[a.jsx(_e,{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"}),a.jsxs(_e,{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:[a.jsx(ad,{className:"w-3 h-3 mr-1"}),u.devicePanel?.video||"Video"]}),a.jsxs(_e,{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:[a.jsx(mi,{className:"w-3 h-3 mr-1"}),u.devicePanel?.image||"Image"]})]}),a.jsx(_e,{variant:"ghost",size:"icon",onClick:Tt,className:"h-8 w-8 rounded-full bg-popover/90 backdrop-blur border border-border shadow-lg hover:bg-accent",title:W?"Hide controls":"Show controls",children:W?a.jsx(Sa,{className:"w-4 h-4"}):a.jsx(Ea,{className:"w-4 h-4"})})]})}),a.jsx("div",{className:"absolute bottom-4 left-4 z-10",children:a.jsxs(Ht,{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"&&a.jsxs(a.Fragment,{children:[a.jsx(td,{className:"w-3 h-3 mr-1"}),u.devicePanel?.video||"Video"]}),X==="screenshot"&&a.jsxs(a.Fragment,{children:[a.jsx(mi,{className:"w-3 h-3 mr-1"}),u.devicePanel?.imageRefresh||"Screenshot"]})]})}),B&&a.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"&&a.jsx(Cn,{className:"w-4 h-4"}),me==="tap"&&a.jsx(ed,{className:"w-4 h-4"}),me==="swipe"&&a.jsx(Zu,{className:"w-4 h-4"}),me==="success"&&a.jsx(kn,{className:"w-4 h-4"}),a.jsx("span",{children:B})]}),X==="video"||X==="auto"&&F&&!$?a.jsx(nf,{deviceId:i,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:D,fallbackTimeout:1e5}):a.jsx("div",{className:"w-full h-full flex items-center justify-center bg-muted/30 min-h-0",children:V&&V.success?a.jsxs("div",{className:"relative w-full h-full flex items-center justify-center min-h-0",children:[a.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&&a.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?a.jsxs("div",{className:"text-center text-destructive",children:[a.jsx(Cn,{className:"w-8 h-8 mx-auto mb-2"}),a.jsx("p",{className:"font-medium",children:u.devicePanel?.screenshotFailed||"Screenshot Failed"}),a.jsx("p",{className:"text-xs mt-1 opacity-60",children:V.error})]}):a.jsxs("div",{className:"text-center text-muted-foreground",children:[a.jsx(Jt,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),a.jsx("p",{className:"text-sm",children:u.devicePanel?.loading||"Loading..."})]})})]})]})}function sw({message:i,type:n="info",onClose:r,duration:o=3e3}){v.useEffect(()=>{const h=setTimeout(()=>{r()},o);return()=>clearTimeout(h)},[o,r]);const u={success:"bg-green-500",error:"bg-red-500",info:"bg-blue-500"},l={success:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M5 13l4 4L19 7"})}),error:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})}),info:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.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"})})};return a.jsx("div",{className:"fixed top-4 left-1/2 transform -translate-x-1/2 z-50 animate-fade-in-down",children:a.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],a.jsx("span",{className:"font-medium",children:i}),a.jsx("button",{onClick:r,className:"ml-auto hover:bg-white/20 rounded-full p-1 transition-colors",children:a.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]})})}const iw=[{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"}}],ow=[{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:""}}];function fw(){const i=Mr(),n=lv.useSearch(),r=cv(),[o,u]=v.useState([]),[l,h]=v.useState(""),[b,f]=v.useState("vision"),[g,p]=v.useState({}),[_,y]=v.useState(n.mode||"classic"),[S,N]=v.useState(!1),[P,T]=v.useState({message:"",type:"info",visible:!1}),I=(R,W="info")=>{T({message:R,type:W,visible:!0})},[F,A]=v.useState(null),[$,q]=v.useState(!1),[X,K]=v.useState(!1),[V,O]=v.useState(!1),[B,M]=v.useState({base_url:"",model_name:"",api_key:"",dual_model_enabled:!1,decision_base_url:"",decision_model_name:"",decision_api_key:""});v.useEffect(()=>{(async()=>{try{const W=await dv();A({base_url:W.base_url,model_name:W.model_name,api_key:W.api_key||void 0,dual_model_enabled:W.dual_model_enabled||!1,decision_base_url:W.decision_base_url||void 0,decision_model_name:W.decision_model_name||void 0,decision_api_key:W.decision_api_key||void 0}),M({base_url:W.base_url,model_name:W.model_name,api_key:W.api_key||"",dual_model_enabled:W.dual_model_enabled||!1,decision_base_url:W.decision_base_url||"",decision_model_name:W.decision_model_name||"",decision_api_key:W.decision_api_key||""}),W.base_url||q(!0)}catch(W){console.error("Failed to load config:",W),q(!0)}})()},[]);const me=v.useCallback(async()=>{try{const W=(await uv()).devices.filter(Z=>Z.state!=="disconnected"),oe=new Map,de=new Map;for(const Z of W)if(Z.serial){const Se=de.get(Z.serial)||[];Se.push(Z),de.set(Z.serial,Se)}else oe.set(Z.id,Z);Array.from(de.values()).forEach(Z=>{const Pe=Z.find(Fe=>Fe.connection_type==="remote")||Z[0];oe.set(Pe.id,Pe)});const ue=Array.from(oe.values());if(u(ue),ue.length>0&&!S){const Z=n.serial;if(Z){const Se=ue.find(Pe=>Pe.serial===Z);h(Se?Se.id:ue[0].id)}else l||h(ue[0].id);N(!0)}l&&!ue.find(Z=>Z.id===l)&&h(ue[0]?.id||"")}catch(R){console.error("Failed to load devices:",R)}},[l,S,n.serial]);v.useEffect(()=>{const R=setTimeout(()=>{me()},0),W=setInterval(me,3e3);return()=>{clearTimeout(R),clearInterval(W)}},[me]),v.useEffect(()=>{const W=o.find(de=>de.id===l)?.serial;if(!S)return;(W!==n.serial||_!==n.mode)&&r({to:"/chat",search:{serial:W,mode:_},replace:!0})},[l,_,o,S,r,n.serial,n.mode]);const ye=async()=>{if(!B.base_url){I(i.chat.baseUrlRequired,"error");return}try{await fv({base_url:B.base_url,model_name:B.model_name||"autoglm-phone-9b",api_key:B.api_key||void 0,dual_model_enabled:B.dual_model_enabled,decision_base_url:B.decision_base_url||void 0,decision_model_name:B.decision_model_name||void 0,decision_api_key:B.decision_api_key||void 0}),A({base_url:B.base_url,model_name:B.model_name,api_key:B.api_key||void 0,dual_model_enabled:B.dual_model_enabled,decision_base_url:B.decision_base_url||void 0,decision_model_name:B.decision_model_name||void 0,decision_api_key:B.decision_api_key||void 0}),q(!1),I(i.toasts.configSaved,"success")}catch(R){console.error("Failed to save config:",R),I(`Failed to save: ${R instanceof Error?R.message:"Unknown error"}`,"error")}},G=async R=>{try{const W=await pv({device_id:R});W.success&&W.device_id?(h(W.device_id),I(i.toasts.wifiConnected,"success")):W.success||I(W.message||W.error||i.toasts.connectionFailed,"error")}catch(W){I(i.toasts.wifiConnectionError,"error"),console.error("Connect WiFi error:",W)}},J=async R=>{try{const W=await hv(R);W.success?I(i.toasts.wifiDisconnected,"success"):I(W.message||W.error||i.toasts.disconnectFailed,"error")}catch(W){I(i.toasts.wifiDisconnectError,"error"),console.error("Disconnect WiFi error:",W)}};return a.jsxs("div",{className:"h-full flex relative min-h-0",children:[P.visible&&a.jsx(sw,{message:P.message,type:P.type,onClose:()=>T(R=>({...R,visible:!1}))}),a.jsx(qu,{open:$,onOpenChange:q,children:a.jsxs(Xu,{className:"sm:max-w-md h-[75vh] flex flex-col",children:[a.jsxs(Yu,{className:"flex-shrink-0",children:[a.jsxs(Vu,{className:"flex items-center gap-2",children:[a.jsx(sd,{className:"w-5 h-5 text-[#1d9bf0]"}),i.chat.configuration]}),a.jsx(Ku,{children:i.chat.configureApi})]}),a.jsxs("div",{className:"flex gap-1 p-1 bg-slate-100 dark:bg-slate-800 rounded-lg",children:[a.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:[a.jsx(ls,{className:"w-4 h-4"}),i.chat.visionModel||"视觉模型"]}),a.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:[a.jsx(sa,{className:"w-4 h-4"}),i.chat.decisionModel||"决策模型"]})]}),a.jsx("div",{className:"space-y-4 pt-3 overflow-y-auto flex-1 min-h-0",children:b==="vision"?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{className:"text-sm font-medium",children:i.chat.selectPreset}),a.jsx("div",{className:"grid grid-cols-1 gap-2",children:iw.map(R=>a.jsxs("div",{className:"relative",children:[a.jsxs("button",{type:"button",onClick:()=>M(W=>({...W,base_url:R.config.base_url,model_name:R.config.model_name})),className:`w-full text-left p-3 rounded-lg border transition-all ${B.base_url===R.config.base_url&&(R.name!=="custom"||R.name==="custom"&&B.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:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(hu,{className:`w-4 h-4 ${B.base_url===R.config.base_url&&(R.name!=="custom"||R.name==="custom"&&B.base_url==="")?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),a.jsx("span",{className:"font-medium text-sm text-slate-900 dark:text-slate-100",children:i.presetConfigs[R.name].name})]}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1 ml-6",children:i.presetConfigs[R.name].description})]}),"apiKeyUrl"in R&&a.jsx("a",{href:R.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.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:i.chat.getApiKey||"获取 API Key",children:a.jsx(du,{className:"w-3.5 h-3.5 text-slate-400 group-hover:text-[#1d9bf0] transition-colors"})})]},R.name))})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs(zt,{htmlFor:"base_url",children:[i.chat.baseUrl," *"]}),a.jsx(hn,{id:"base_url",value:B.base_url,onChange:R=>M({...B,base_url:R.target.value}),placeholder:"http://localhost:8080/v1"}),!B.base_url&&a.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[a.jsx(Cn,{className:"w-3 h-3"}),i.chat.baseUrlRequired]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"api_key",children:i.chat.apiKey}),a.jsxs("div",{className:"relative",children:[a.jsx(hn,{id:"api_key",type:X?"text":"password",value:B.api_key,onChange:R=>M({...B,api_key:R.target.value}),placeholder:"Leave empty if not required",className:"pr-10"}),a.jsx(_e,{type:"button",variant:"ghost",size:"icon",onClick:()=>K(!X),className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",children:X?a.jsx(fu,{className:"w-4 h-4 text-slate-400"}):a.jsx(ls,{className:"w-4 h-4 text-slate-400"})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"model_name",children:i.chat.modelName}),a.jsx(hn,{id:"model_name",value:B.model_name,onChange:R=>M({...B,model_name:R.target.value}),placeholder:"autoglm-phone-9b"})]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{className:"text-sm font-medium",children:i.chat.selectPreset}),a.jsx("div",{className:"grid grid-cols-1 gap-2",children:ow.map(R=>a.jsxs("div",{className:"relative",children:[a.jsxs("button",{type:"button",onClick:()=>M(W=>({...W,decision_base_url:R.config.base_url,decision_model_name:R.config.model_name})),className:`w-full text-left p-3 rounded-lg border transition-all ${B.decision_base_url===R.config.base_url&&(R.name!=="custom"||R.name==="custom"&&B.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:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(hu,{className:`w-4 h-4 ${B.decision_base_url===R.config.base_url&&(R.name!=="custom"||R.name==="custom"&&B.decision_base_url==="")?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),a.jsx("span",{className:"font-medium text-sm text-slate-900 dark:text-slate-100",children:i.presetConfigs[R.name].name})]}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1 ml-6",children:i.presetConfigs[R.name].description})]}),"apiKeyUrl"in R&&a.jsx("a",{href:R.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.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:i.chat.getApiKey||"获取 API Key",children:a.jsx(du,{className:"w-3.5 h-3.5 text-slate-400 group-hover:text-[#1d9bf0] transition-colors"})})]},R.name))})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs(zt,{htmlFor:"decision_base_url",children:[i.chat.baseUrl," *"]}),a.jsx(hn,{id:"decision_base_url",value:B.decision_base_url,onChange:R=>M({...B,decision_base_url:R.target.value}),placeholder:"http://localhost:8080/v1"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"decision_api_key",children:i.chat.apiKey}),a.jsxs("div",{className:"relative",children:[a.jsx(hn,{id:"decision_api_key",type:V?"text":"password",value:B.decision_api_key,onChange:R=>M({...B,decision_api_key:R.target.value}),placeholder:"Leave empty if not required",className:"pr-10"}),a.jsx(_e,{type:"button",variant:"ghost",size:"icon",onClick:()=>O(!V),className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",children:V?a.jsx(fu,{className:"w-4 h-4 text-slate-400"}):a.jsx(ls,{className:"w-4 h-4 text-slate-400"})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(zt,{htmlFor:"decision_model_name",children:i.chat.modelName}),a.jsx(hn,{id:"decision_model_name",value:B.decision_model_name,onChange:R=>M({...B,decision_model_name:R.target.value}),placeholder:"glm-4.7"})]})]})}),a.jsxs(Qu,{className:"sm:justify-between gap-2 flex-shrink-0",children:[a.jsx(_e,{variant:"outline",onClick:()=>{q(!1),F&&M({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||""})},children:i.chat.cancel}),a.jsxs(_e,{onClick:ye,variant:"twitter",children:[a.jsx(kn,{className:"w-4 h-4 mr-2"}),i.chat.saveConfig]})]})]})}),a.jsx(H1,{devices:o,currentDeviceId:l,onSelectDevice:h,onOpenConfig:()=>q(!0),onConnectWifi:G,onDisconnectWifi:J}),a.jsxs("div",{className:"flex-1 flex flex-col min-h-0 relative",children:[a.jsx("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 z-20",children:a.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:[a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.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:[a.jsx(is,{className:"w-4 h-4"}),i.chatkit?.classicMode||"经典模式"]})}),a.jsx(Zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:i.chatkit?.classicMode||"经典模式"}),a.jsx("p",{className:"text-xs opacity-80",children:i.chatkit?.classicModeDesc||"视觉模型直接执行任务"})]})})]}),a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.jsxs("button",{onClick:()=>y("dual"),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:[a.jsx(sa,{className:"w-4 h-4"}),i.chatkit?.dualMode||"双模型协作"]})}),a.jsx(Zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:i.chatkit?.dualMode||"双模型协作"}),a.jsx("p",{className:"text-xs opacity-80",children:i.chatkit?.dualModeDesc||"决策模型逐步指导,视觉模型执行,精细控制"})]})})]}),a.jsxs(Qn,{children:[a.jsx(Jn,{asChild:!0,children:a.jsxs("button",{onClick:()=>y("chatkit"),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:[a.jsx(aa,{className:"w-4 h-4"}),i.chatkit?.layeredMode||"分层代理"]})}),a.jsx(Zn,{side:"bottom",sideOffset:8,className:"max-w-xs",children:a.jsxs("div",{className:"space-y-1",children:[a.jsx("p",{className:"font-medium",children:i.chatkit?.layeredMode||"分层代理"}),a.jsx("p",{className:"text-xs opacity-80",children:i.chatkit?.layeredModeDesc||"规划层分解任务,执行层独立完成子任务"})]})})]})]})}),a.jsx("div",{className:"flex-1 flex items-stretch justify-center min-h-0 px-4 py-4 pt-16",children:o.length===0?a.jsx("div",{className:"flex-1 flex items-center justify-center bg-slate-50 dark:bg-slate-950",children:a.jsxs("div",{className:"text-center",children:[a.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:a.jsx("svg",{className:"w-10 h-10 text-slate-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:a.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"})})}),a.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-100 mb-2",children:i.chat.welcomeTitle}),a.jsx("p",{className:"text-slate-500 dark:text-slate-400",children:i.chat.connectDevice})]})}):o.map(R=>a.jsx("div",{className:`w-full max-w-7xl flex items-stretch justify-center min-h-0 ${R.id===l?"":"hidden"}`,children:_==="chatkit"?a.jsx(rw,{deviceId:R.id,deviceSerial:R.serial,deviceName:R.model,isVisible:R.id===l}):a.jsx(nw,{deviceId:R.id,deviceSerial:R.serial,deviceName:R.model,config:F,isVisible:R.id===l,isConfigured:!!F?.base_url,thinkingMode:g[R.serial]||"deep",onThinkingModeChange:W=>{p(oe=>({...oe,[R.serial]:W}))},dualModelEnabled:_==="dual"})},R.serial))})]})]})}export{fw as component};