@hyperflow.fun/ghost 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -20
- package/dist/index.js +1328 -716
- package/dist/package.json +1 -1
- package/dist/skills/builtin/ask-user-questions/SKILL.md +48 -0
- package/dist/skills/builtin/event-judge/SKILL.md +52 -7
- package/dist/skills/builtin/trade-executor/SKILL.md +1 -1
- package/dist/web/dist/assets/{Chart-BOyhyITw.js → Chart-cnNd398J.js} +1 -1
- package/dist/web/dist/assets/{Config-CQyc8yqV.js → Config-Bui5kcW0.js} +1 -1
- package/dist/web/dist/assets/{Cost-BoAvnlDi.js → Cost-BDSIn5ub.js} +1 -1
- package/dist/web/dist/assets/{Cron-5mIZVsft.js → Cron-C7gaZhMu.js} +1 -1
- package/dist/web/dist/assets/{Dashboard-BRxSDtCD.js → Dashboard-qwYsK3Gi.js} +1 -1
- package/dist/web/dist/assets/{Logs-BpXqElSx.js → Logs-DyfS6kEe.js} +1 -1
- package/dist/web/dist/assets/{Memory-CcgSgCqJ.js → Memory-BPMmbFbx.js} +1 -1
- package/dist/web/dist/assets/SVN-RethinkSans-Bold-BIisIh3U.otf +0 -0
- package/dist/web/dist/assets/SVN-RethinkSans-Italic-8Q-lLPN5.otf +0 -0
- package/dist/web/dist/assets/SVN-RethinkSans-Medium-yLh4RBRv.otf +0 -0
- package/dist/web/dist/assets/SVN-RethinkSans-Regular-CVuIF6ni.otf +0 -0
- package/dist/web/dist/assets/{Sessions-BEIP55fW.js → Sessions-nANl57gZ.js} +1 -1
- package/dist/web/dist/assets/{Skills-4s4LDpzh.js → Skills-BPXH_m1K.js} +1 -1
- package/dist/web/dist/assets/{Tools-C-NcyONi.js → Tools-CypplonI.js} +1 -1
- package/dist/web/dist/assets/{activity-DJy9m_N9.js → activity-BLl_txfw.js} +1 -1
- package/dist/web/dist/assets/{clock-CFVWqojO.js → clock-CMLb2b5z.js} +1 -1
- package/dist/web/dist/assets/empty-notifications-C88Hm9lC.svg +62 -0
- package/dist/web/dist/assets/empty-token-search-aBFBwedz.svg +5 -0
- package/dist/web/dist/assets/{highlighted-body-OFNGDK62-y5VVuvTf.js → highlighted-body-OFNGDK62-CKxBaGN5.js} +1 -1
- package/dist/web/dist/assets/index-CKAK_IGv.js +59 -0
- package/dist/web/dist/assets/index-PX2emSv9.css +1 -0
- package/dist/web/dist/assets/{mermaid-GHXKKRXX-BvdvTI5r.js → mermaid-GHXKKRXX-BuHBmaw6.js} +3 -3
- package/dist/web/dist/assets/{refresh-cw-DlbQ5OE4.js → refresh-cw-DHCgoaOK.js} +1 -1
- package/dist/web/dist/assets/welcome-globe-analytics-sF4OWku9.svg +201 -0
- package/dist/web/dist/assets/welcome-globe-bars-COA7MJUP.svg +305 -0
- package/dist/web/dist/assets/welcome-news-card-BfM47ZZ3.svg +59 -0
- package/dist/web/dist/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/dist/assets/index-B1ED3P_d.css +0 -1
- package/dist/web/dist/assets/index-C6QRLmO2.js +0 -54
- package/dist/web/dist/assets/rethink-sans-latin-ext-CuoiHPIp.woff2 +0 -0
- package/dist/web/dist/assets/rethink-sans-latin-v3CgWhBT.woff2 +0 -0
- package/dist/web/dist/assets/welcome-illustration-B8_SJ7In.svg +0 -319
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid-GHXKKRXX-BvdvTI5r.js","assets/vendor-react-B0mWfPOm.js","assets/vendor-viem-wp7lz4Hc.js","assets/vendor-charts-CfOL2F-E.js","assets/Dashboard-BRxSDtCD.js","assets/clock-CFVWqojO.js","assets/activity-DJy9m_N9.js","assets/Tools-C-NcyONi.js","assets/Skills-4s4LDpzh.js","assets/Cron-5mIZVsft.js","assets/Memory-CcgSgCqJ.js","assets/refresh-cw-DlbQ5OE4.js","assets/Config-CQyc8yqV.js","assets/Cost-BoAvnlDi.js","assets/Logs-BpXqElSx.js","assets/Sessions-BEIP55fW.js","assets/Chart-BOyhyITw.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
var cs=Object.defineProperty;var ds=(t,r,s)=>r in t?cs(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var ce=(t,r,s)=>ds(t,typeof r!="symbol"?r+"":r,s);import{r as n,j as e,a as he,b as us,O as xs,R as ur,c as fs,d as ae,N as ps,e as hs,B as ms}from"./vendor-react-B0mWfPOm.js";import{c as yt,a as wt,b as Ce,p as bs,_ as ie}from"./vendor-viem-wp7lz4Hc.js";import{q as xr,R as gs,V as fr,n as ge,h as Je,K as vs,W as ys}from"./vendor-charts-CfOL2F-E.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))o(a);new MutationObserver(a=>{for(const l of a)if(l.type==="childList")for(const i of l.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&o(i)}).observe(document,{childList:!0,subtree:!0});function s(a){const l={};return a.integrity&&(l.integrity=a.integrity),a.referrerPolicy&&(l.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?l.credentials="include":a.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function o(a){if(a.ep)return;a.ep=!0;const l=s(a);fetch(a.href,l)}})();const Ct=800,ws=15e3,Cs=1.7;class js{constructor(r={}){ce(this,"ws",null);ce(this,"pending",new Map);ce(this,"seq",0);ce(this,"backoffMs",Ct);ce(this,"reconnectTimer",null);ce(this,"intentionallyClosed",!1);ce(this,"_connected",!1);ce(this,"url");ce(this,"opts");const s=window.location.protocol==="https:"?"wss:":"ws:";this.url=r.url??`${s}//${window.location.host}/ws`,this.opts=r}get connected(){return this._connected}start(){this.intentionallyClosed=!1,this.connect()}stop(){this.intentionallyClosed=!0,this.clearReconnectTimer(),this.rejectAllPending("Client stopped"),this.ws&&(this.ws.close(),this.ws=null),this._connected=!1}request(r,s,o=3e4){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)return Promise.reject(new Error("Gateway not connected"));const a=crypto.randomUUID();return new Promise((l,i)=>{const c=setTimeout(()=>{this.pending.delete(a),i(new Error(`Request timeout: ${r}`))},o);this.pending.set(a,{resolve:x=>{clearTimeout(c),l(x)},reject:x=>{clearTimeout(c),i(x)}}),this.ws.send(JSON.stringify({type:"req",id:a,method:r,payload:s}))})}connect(){this.clearReconnectTimer();try{this.ws=new WebSocket(this.url)}catch{this.scheduleReconnect();return}this.ws.onopen=()=>{this.ws.send(JSON.stringify({type:"connect"}))},this.ws.onmessage=r=>{let s;try{s=JSON.parse(r.data)}catch{return}this.handleFrame(s)},this.ws.onclose=()=>{var r,s;this._connected=!1,this.rejectAllPending("Connection closed"),(s=(r=this.opts).onClose)==null||s.call(r),this.scheduleReconnect()},this.ws.onerror=()=>{}}handleFrame(r){var s,o,a,l,i,c;switch(r.type){case"hello":this._connected=!0,this.backoffMs=Ct,(o=(s=this.opts).onHello)==null||o.call(s,{sessionId:r.sessionId});break;case"res":{const x=this.pending.get(r.id);if(!x)break;this.pending.delete(r.id),r.ok?x.resolve(r.payload):x.reject(new Error(r.error.message));break}case"event":{const x=r;x.seq>this.seq&&(this.seq=x.seq),(l=(a=this.opts).onEvent)==null||l.call(a,x);break}case"error":(c=(i=this.opts).onError)==null||c.call(i,r.message);break}}scheduleReconnect(){this.intentionallyClosed||(this.clearReconnectTimer(),this.reconnectTimer=setTimeout(()=>{this.backoffMs=Math.min(this.backoffMs*Cs,ws),this.connect()},this.backoffMs))}clearReconnectTimer(){this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}rejectAllPending(r){for(const[s,o]of this.pending)o.reject(new Error(r)),this.pending.delete(s)}}const pr=n.createContext(null);function te(){const t=n.useContext(pr);if(!t)throw new Error("useGateway must be used within a GatewayProvider");return t}function Ns(t){const[r,s]=n.useState(!1),[o,a]=n.useState(null),[l,i]=n.useState(null),c=n.useRef(null),x=n.useRef(new Set);n.useEffect(()=>{const d=new js({...t,onHello:f=>{s(!0),a(f.sessionId),i(null)},onClose:()=>{s(!1)},onError:f=>{i(f)},onEvent:f=>{for(const u of x.current)u(f)}});return c.current=d,d.start(),()=>{d.stop(),c.current=null}},[]);const p=n.useCallback((d,f)=>{const u=c.current;return u?u.request(d,f):Promise.reject(new Error("Gateway not initialized"))},[]),m=n.useCallback(d=>(x.current.add(d),()=>{x.current.delete(d)}),[]);return{client:c.current,connected:r,sessionId:o,error:l,request:p,subscribe:m}}const hr=n.createContext(null),jt=10*1e3,Be=500;function ks(){const{request:t,subscribe:r,connected:s}=te(),[o,a]=n.useState("idle"),[l,i]=n.useState([]),[c,x]=n.useState(null),[p,m]=n.useState([]),[d,f]=n.useState([]),[u,y]=n.useState([]),[h,v]=n.useState(new Set),g=n.useCallback(()=>v(new Set),[]),b=n.useRef(new Set),w=n.useRef(!1),[C,k]=n.useState(new Set),[E,M]=n.useState(null),N=n.useRef(null);n.useEffect(()=>{N.current=E},[E]);const j=n.useRef([]);n.useEffect(()=>{j.current=l},[l]);const[S,R]=n.useState(null),[P,$]=n.useState(!1),[L,I]=n.useState(Date.now()),W=n.useRef(null),T=n.useCallback(async()=>{var O,V;if(s){a("loading");try{const[z,K,se]=await Promise.allSettled([t("trading.wallets.list"),t("trading.portfolio.aggregate"),t("trading.notifications.list")]),G=z.status==="fulfilled"&&Array.isArray(z.value),Q=G?z.value:j.current;if(G&&i(Q),se.status==="fulfilled"&&Array.isArray(se.value)){const F=se.value.filter(_=>_.kind==="price_target");if(y(F),!w.current)b.current=new Set(F.map(_=>_.id)),w.current=!0;else{const _=F.map(D=>D.id).filter(D=>!b.current.has(D));if(_.length>0){v(D=>{const q=new Set(D);for(const X of _)q.add(X);return q});for(const D of _)b.current.add(D)}}}const ne=K.status==="fulfilled"?K.value:null;if(G&&Q.length===0){M(null),x(null),m([]),f([]),a("no-wallet"),R(null);return}if(!ne||!ne.connected){if(N.current||Q.length>0)return;const F=K.status==="rejected"?K.reason instanceof Error?K.reason.message:String(K.reason):null;a("error"),R(F??"Failed to load portfolio");return}const Y=((O=Q.find(F=>F.isDefault))==null?void 0:O.address)??((V=Q[0])==null?void 0:V.address),re=Y?ne.perWallet.find(F=>F.address.toLowerCase()===Y.toLowerCase()):null;if(!re){M(ne);return}if(re.error){M(ne);return}M(ne),x(re.balance??null),m(re.positions??[]),f(re.openOrders??[]),R(null),a("connected")}catch(z){a("error"),R(z instanceof Error?z.message:String(z))}finally{I(Date.now())}}},[s,t]);n.useEffect(()=>{s&&t("status").then(O=>{typeof O.paperMode=="boolean"&&$(O.paperMode)}).catch(()=>{})},[s,t]),n.useEffect(()=>{s&&T()},[s,T]),n.useEffect(()=>{let O=null;const V=()=>{O&&clearTimeout(O),O=setTimeout(()=>{s&&T()},Be)};return window.addEventListener("ghost-wallet-changed",V),()=>{window.removeEventListener("ghost-wallet-changed",V),O&&clearTimeout(O)}},[s,T]),n.useEffect(()=>{if(!(!s||l.length===0))return W.current=setInterval(T,jt),()=>{W.current&&clearInterval(W.current)}},[s,l.length,T]);const A=n.useMemo(()=>{let O=null;return()=>{O&&clearTimeout(O),O=setTimeout(T,Be)}},[T]),B=n.useMemo(()=>{const O=[Be,3e3,7e3];let V=[];return()=>{V.forEach(clearTimeout),V=O.map(z=>setTimeout(T,z))}},[T]);n.useEffect(()=>r(O=>{O.event==="chat.done"&&B()}),[r,B]),n.useEffect(()=>r(O=>{(O.event==="trading.alert.set"||O.event==="trading.alert.removed"||O.event==="chat.proactive")&&A()}),[r,A]);const Z=n.useCallback(async O=>{k(V=>{if(V.has(O))return V;const z=new Set(V);return z.add(O),z}),v(V=>{if(!V.has(O))return V;const z=new Set(V);return z.delete(O),z});try{await t("trading.notifications.dismiss",{id:O})}catch(V){console.warn("trading.notifications.dismiss failed",V)}},[t]),J=n.useMemo(()=>u.filter(O=>!C.has(O.id)),[u,C]);return{status:o,wallets:l,balance:c,positions:p,openOrders:d,notifications:J,unreadNotificationIds:h,markNotificationsRead:g,dismissNotification:Z,aggregate:E,error:S,paperMode:P,refresh:T,lastFetchedAt:L,pollIntervalMs:jt}}function me(){const t=n.useContext(hr);if(!t)throw new Error("usePortfolio must be used within PortfolioProvider");return t}function xe({color:t="var(--color-brand-default)"}={}){return e.jsx("span",{"data-pulse-dots":!0,className:"flex items-center gap-1",children:[0,1,2].map(r=>e.jsx("span",{className:"w-1 h-1 rounded-full",style:{background:t,animation:`pulse 1.4s ease-in-out ${r*.2}s infinite`}},r))})}/**
|
|
3
|
-
* @license lucide-react v0.468.0 - ISC
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the ISC license.
|
|
6
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/const Ss=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),mr=(...t)=>t.filter((r,s,o)=>!!r&&r.trim()!==""&&o.indexOf(r)===s).join(" ").trim();/**
|
|
8
|
-
* @license lucide-react v0.468.0 - ISC
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the ISC license.
|
|
11
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/var Ls={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
|
|
13
|
-
* @license lucide-react v0.468.0 - ISC
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the ISC license.
|
|
16
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/const Es=n.forwardRef(({color:t="currentColor",size:r=24,strokeWidth:s=2,absoluteStrokeWidth:o,className:a="",children:l,iconNode:i,...c},x)=>n.createElement("svg",{ref:x,...Ls,width:r,height:r,stroke:t,strokeWidth:o?Number(s)*24/Number(r):s,className:mr("lucide",a),...c},[...i.map(([p,m])=>n.createElement(p,m)),...Array.isArray(l)?l:[l]]));/**
|
|
18
|
-
* @license lucide-react v0.468.0 - ISC
|
|
19
|
-
*
|
|
20
|
-
* This source code is licensed under the ISC license.
|
|
21
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
-
*/const we=(t,r)=>{const s=n.forwardRef(({className:o,...a},l)=>n.createElement(Es,{ref:l,iconNode:r,className:mr(`lucide-${Ss(t)}`,o),...a}));return s.displayName=`${t}`,s};/**
|
|
23
|
-
* @license lucide-react v0.468.0 - ISC
|
|
24
|
-
*
|
|
25
|
-
* This source code is licensed under the ISC license.
|
|
26
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
27
|
-
*/const Nt=we("Loader",[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]]);/**
|
|
28
|
-
* @license lucide-react v0.468.0 - ISC
|
|
29
|
-
*
|
|
30
|
-
* This source code is licensed under the ISC license.
|
|
31
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
32
|
-
*/const Ms=we("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
|
|
33
|
-
* @license lucide-react v0.468.0 - ISC
|
|
34
|
-
*
|
|
35
|
-
* This source code is licensed under the ISC license.
|
|
36
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
37
|
-
*/const Ts=we("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
|
|
38
|
-
* @license lucide-react v0.468.0 - ISC
|
|
39
|
-
*
|
|
40
|
-
* This source code is licensed under the ISC license.
|
|
41
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
42
|
-
*/const Rs=we("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
|
|
43
|
-
* @license lucide-react v0.468.0 - ISC
|
|
44
|
-
*
|
|
45
|
-
* This source code is licensed under the ISC license.
|
|
46
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
47
|
-
*/const _s=we("Wallet",[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1",key:"18etb6"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4",key:"xoc0q4"}]]);/**
|
|
48
|
-
* @license lucide-react v0.468.0 - ISC
|
|
49
|
-
*
|
|
50
|
-
* This source code is licensed under the ISC license.
|
|
51
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
52
|
-
*/const Fe=we("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function As(){const[t,r]=n.useState([]);n.useEffect(()=>{const l=new Map,i=c=>{var p;const x=c.detail;!((p=x==null?void 0:x.info)!=null&&p.uuid)||!(x!=null&&x.provider)||(l.set(x.info.uuid,{info:x.info,provider:x.provider}),r([...l.values()]))};return window.addEventListener("eip6963:announceProvider",i),window.dispatchEvent(new Event("eip6963:requestProvider")),()=>window.removeEventListener("eip6963:announceProvider",i)},[]);const s=typeof window<"u"?window.ethereum:void 0,o=t.length>0?t:s?[{info:{uuid:"legacy",name:"Browser Wallet",icon:"",rdns:"legacy"},provider:s}]:[],a=n.useCallback(l=>{const i=t.find(c=>c.info.rdns===l);return i?i.provider:s||null},[t,s]);return{providers:o,getProviderByRdns:a}}function at(){const[t,r]=n.useState([]),[s,o]=n.useState(!1),[a,l]=n.useState(null),[i,c]=n.useState(null),[x,p]=n.useState(null),[m,d]=n.useState(null),{providers:f,getProviderByRdns:u}=As(),y=n.useCallback(async()=>{try{const C=await fetch("/api/wallets");C.ok&&r(await C.json())}catch{}},[]);n.useEffect(()=>{y()},[y]),n.useEffect(()=>{const C=()=>{y()};return window.addEventListener("ghost-wallet-changed",C),()=>window.removeEventListener("ghost-wallet-changed",C)},[y]);const h=n.useCallback(async C=>{o(!0),p(null),d(null);try{const k=yt({transport:wt(C.provider)});let E;try{await C.provider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),E=await k.getAddresses()}catch{E=await k.requestAddresses()}if(E.length===0)throw new Error("No account selected");const M=C.info.rdns,N=[];for(const j of E){const S=await fetch("/api/wallet/connect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:j,testnet:!1,source:M})});S.ok&&(await S.json()).isNew&&N.push(j)}if(await y(),N.length===0){const j=E.map(R=>`${R.slice(0,6)}…${R.slice(-4)}`).join(", "),S=E.length===1?"This wallet address":"Wallet addresses";return d(`${S} ${j} already connected. Switch account in your extension to add a different one.`),null}if(N.length===1){const j=N[0];d(`Wallet connected: ${j.slice(0,6)}…${j.slice(-4)}`)}else d(`${N.length} wallets connected`);return N[0]}catch(k){const E=(k==null?void 0:k.message)||"Failed to connect wallet";return p(E.length>120?E.slice(0,120)+"…":E),null}finally{o(!1)}},[y]),v=n.useCallback(async C=>{var k;l(C),c("generating"),p(null),d(null);try{const E=t.find(G=>G.address.toLowerCase()===C.toLowerCase()),M=E!=null&&E.source?u(E.source):null;if(!M)throw new Error("Wallet extension not found. Reconnect the wallet.");const N=yt({chain:Ce,transport:wt(M)}),j=await fetch("/api/wallet/generate-agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:C})}),S=await j.json();if(!j.ok)throw new Error(S.error||"Failed to generate API wallet");const{agentAddress:R,nonce:P}=S,$={type:"approveAgent",hyperliquidChain:"Mainnet",signatureChainId:"0xa4b1",agentAddress:R,agentName:"ghost",nonce:P};c("switching-chain");const L=await N.getChainId();if(L!==Ce.id)try{await N.switchChain({id:Ce.id})}catch(G){if((G==null?void 0:G.code)===4902)await N.addChain({chain:Ce});else throw G}const W=(await N.getAddresses()).find(G=>G.toLowerCase()===C.toLowerCase());if(!W)throw new Error(`Please switch to account ${C.slice(0,6)}...${C.slice(-4)} in your wallet extension before signing.`);const T={name:"HyperliquidSignTransaction",version:"1",chainId:42161,verifyingContract:"0x0000000000000000000000000000000000000000"},A={"HyperliquidTransaction:ApproveAgent":[{name:"hyperliquidChain",type:"string"},{name:"agentAddress",type:"address"},{name:"agentName",type:"string"},{name:"nonce",type:"uint64"}]},B={hyperliquidChain:"Mainnet",agentAddress:R,agentName:"ghost",nonce:BigInt(P)};c("signing");const Z=await N.signTypedData({account:W,domain:T,types:A,primaryType:"HyperliquidTransaction:ApproveAgent",message:B});L!==Ce.id&&N.switchChain({id:L}).catch(()=>{}),c("submitting");const{r:J,s:O,v:V}=bs(Z),z=await fetch("https://api.hyperliquid.xyz/exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:$,nonce:P,signature:{r:J,s:O,v:Number(V)}})});let K="ApproveAgent transaction failed on Hyperliquid";if(!z.ok){const G=await z.text().catch(()=>"");console.error("[addApiWallet] Hyperliquid response:",z.status,G);try{K=((k=JSON.parse(G))==null?void 0:k.error)||K}catch{}throw await fetch("/api/wallet/confirm-agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:C})}),new Error(K)}c("confirming");const se=await fetch("/api/wallet/confirm-agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:C,signature:Z})});if(!se.ok){const G=await se.json().catch(()=>({}));throw new Error(G.error||"Server rejected agent approval")}return await y(),window.dispatchEvent(new Event("ghost-wallet-changed")),!0}catch(E){const M=E==null?void 0:E.code;if(M===4001||M===4100)return!1;const N=(E==null?void 0:E.message)||"Failed to add API wallet";return p(N.length>120?N.slice(0,120)+"…":N),!1}finally{l(null),c(null)}},[y,t,u]),g=n.useCallback(async C=>{const k=await fetch("/api/wallet/remove",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:C})});if(!k.ok){const E=await k.json().catch(()=>({}));throw new Error(E.error||"Failed to remove wallet")}await y(),window.dispatchEvent(new Event("ghost-wallet-changed"))},[y]),b=n.useCallback(async C=>{const k=await fetch("/api/wallet/set-default",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:C})});if(k.ok)await y();else{const E=await k.json();p(E.error||"Failed to set default")}},[y]),w=n.useCallback(()=>{p(null),d(null)},[]);return{wallets:t,connecting:s,signingAddress:a,signingPhase:i,error:x,info:m,providers:f,connectWallet:h,addApiWallet:v,removeWallet:g,setDefaultWallet:b,clearMessages:w,refreshWallets:y}}const Is="inline-flex items-center justify-center rounded-full flex-shrink-0 transition-colors duration-fast ease-out btn-press disabled:cursor-default disabled:opacity-30",Fs={success:"bg-[rgba(0,255,136,0.1)] text-[#00ff88] hover:bg-[rgba(0,255,136,0.2)] focus-visible:bg-[rgba(0,255,136,0.2)] cursor-pointer",danger:"bg-[rgba(255,71,87,0.1)] text-[#ff4757] hover:bg-[rgba(255,71,87,0.2)] focus-visible:bg-[rgba(255,71,87,0.2)] cursor-pointer",ghost:"text-[var(--color-text-secondary)] hover:bg-white/[0.06] hover:text-[var(--color-text-primary)] focus-visible:bg-white/[0.06] focus-visible:text-[var(--color-text-primary)] cursor-pointer",primary:"bg-primary/15 text-primary hover:bg-primary/25 focus-visible:bg-primary/25 cursor-pointer"},Ds={sm:"w-6 h-6","sm-plus":"w-7 h-7",md:"w-8 h-8"},Ps=n.forwardRef(function({variant:r="ghost",size:s="md",className:o="",children:a,...l},i){return e.jsx("button",{ref:i,type:"button",className:`${Is} ${Fs[r]} ${Ds[s]} ${o}`.trim(),...l,children:a})});function Bs({dashed:t=!1,className:r="",children:s,...o}){const a=t?"border border-dashed border-[var(--color-border-strong)]":"border border-[var(--color-border-subtle)]";return e.jsx("div",{className:`bg-[var(--color-surface-base)] rounded-[2px] shadow-[0_0_20px_rgba(59,247,191,0.03)] ${a} ${r}`.trim(),...o,children:s})}function $s({icon:t,text:r,card:s=!0,dashed:o=!1}){const a=e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3",children:[t,e.jsx("span",{className:"text-caption text-[#3a4a5a]",children:r})]});return s?e.jsx(Bs,{dashed:o,children:a}):a}function Os(t){let r=0;for(let s=0;s<t.length;s++)r=r*31+t.charCodeAt(s)|0;return Math.abs(r)%360}function Ne({url:t,seed:r,label:s,size:o=36}){const a=(s.trim()[0]??"?").toUpperCase(),l=`hsl(${Os(r||s||"?")}, 45%, 35%)`,i=Math.round(o*.5),[c,x]=n.useState(!1);n.useEffect(()=>{x(!1)},[t]);const p=e.jsx("div",{"aria-hidden":"true",className:"rounded-full flex items-center justify-center text-white font-bold",style:{width:o,height:o,flex:`0 0 ${o}px`,background:l,fontSize:i},children:a});return!t||c?p:e.jsx("img",{src:t,alt:"",loading:"lazy",referrerPolicy:"no-referrer",className:"rounded-full object-cover",style:{width:o,height:o,flex:`0 0 ${o}px`,background:l},onError:()=>x(!0)})}const je=180,kt='a[href], area[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), iframe, object, embed, [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';function de({open:t,onClose:r,title:s,children:o,width:a=600,headerRight:l,preventClose:i,cardClassName:c,bodyClassName:x,hideHeader:p}){const[m,d]=n.useState(!1),[f,u]=n.useState(!1),y=n.useRef(null),h=n.useRef(null),v=n.useRef(null);n.useEffect(()=>{t?(u(!1),d(!0)):m&&!f&&(u(!0),y.current=setTimeout(()=>{d(!1),u(!1)},je))},[t]);const g=n.useCallback(()=>{i||f||(u(!0),y.current=setTimeout(()=>{d(!1),u(!1),r()},je))},[r,i,f]);if(n.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]),n.useEffect(()=>{if(!m||i)return;const k=E=>{E.key==="Escape"&&g()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[m,g,i]),n.useEffect(()=>{if(!m)return;const k=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=k}},[m]),n.useEffect(()=>{if(!m)return;v.current=document.activeElement??null;const k=requestAnimationFrame(()=>{const M=h.current;if(!M)return;const j=M.querySelectorAll(kt)[0];j?j.focus():M.focus()}),E=M=>{if(M.key!=="Tab")return;const N=h.current;if(!N)return;const j=Array.from(N.querySelectorAll(kt)).filter($=>!$.hasAttribute("disabled")&&$.offsetParent!==null);if(j.length===0){M.preventDefault();return}const S=j[0],R=j[j.length-1],P=document.activeElement;M.shiftKey?(P===S||!N.contains(P))&&(M.preventDefault(),R.focus()):(P===R||!N.contains(P))&&(M.preventDefault(),S.focus())};return window.addEventListener("keydown",E),()=>{cancelAnimationFrame(k),window.removeEventListener("keydown",E);const M=v.current;M&&typeof M.focus=="function"&&document.contains(M)&&M.focus()}},[m]),!m)return null;const b={animation:f?`tm-overlay-out ${je}ms ease-in forwards`:`tm-overlay-in ${je}ms ease-out`},w={animation:f?`tm-modal-out ${je}ms ease-in forwards`:"tm-modal-in 200ms ease-out"},C=e.jsx("div",{className:"fixed inset-0 z-[10010] bg-[var(--color-surface-scrim)] backdrop-blur-[4px] flex items-center justify-center",style:b,onClick:k=>{k.target===k.currentTarget&&g()},children:e.jsxs("div",{ref:h,className:(c??"bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[2px] shadow-[0_8px_32px_rgba(0,0,0,0.5)]")+" w-full max-h-[85vh] overflow-y-auto",style:{...w,maxWidth:a},role:"dialog","aria-modal":"true","aria-label":s,tabIndex:-1,children:[!p&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--color-border-subtle)]",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("span",{className:"text-body-lg-semibold text-text-primary",children:s})}),e.jsxs("div",{className:"flex items-center gap-2",children:[l,e.jsx(Ps,{variant:"ghost",size:"sm-plus",onClick:g,disabled:i,"aria-label":"Close",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsx("div",{className:x??"p-4",children:o})]})});return he.createPortal(C,document.body)}function ve(t,r=1e3){if(!Number.isFinite(t))return"$—";const s=t<0?"-":"",o=Math.abs(t);return o>=1e6?`${s}$${(o/1e6).toFixed(2)}M`:o>=Math.max(r,1e3)?`${s}$${(o/1e3).toFixed(2).replace(/\.00$/,"")}k`:o>=1e3?`${s}$${o.toLocaleString("en-US",{maximumFractionDigits:0})}`:`${s}$${o.toFixed(2)}`}function br(t,r=1e3){return Number.isFinite(t)?`${t>=0?"+":"-"}${ve(Math.abs(t),r)}`:"$—"}function Hs(t){return`${t>=0?"+":"-"}$${Math.abs(t).toFixed(2)}`}function St(t){return`${t.slice(0,10)}...${t.slice(-8)}`}const Lt=[{rdns:"io.metamask",name:"MetaMask",subtitle:"Browser extension",installUrl:"https://metamask.io/download/",iconUrl:"https://cdn.jsdelivr.net/gh/MetaMask/brand-resources@main/SVG/SVG_MetaMask_Icon_Color.svg",popular:!0},{rdns:"io.rabby",name:"Rabby Wallet",subtitle:"Browser extension",installUrl:"https://rabby.io/",iconUrl:"https://rabby.io/assets/images/logo-128.png"},{rdns:"com.coinbase.wallet",name:"Coinbase Wallet",subtitle:"Self-custody wallet",installUrl:"https://www.coinbase.com/wallet/downloads",iconUrl:"https://avatars.githubusercontent.com/u/1885080?s=200"},{rdns:"app.phantom",name:"Phantom",subtitle:"Solana & EVM support",installUrl:"https://phantom.app/download",iconUrl:"https://avatars.githubusercontent.com/u/78782331?s=200"}];function gr({open:t,onClose:r,onSuccess:s}){const{connecting:o,providers:a,connectWallet:l}=at(),[i,c]=n.useState(null),x=async d=>{c(d.info.rdns);try{await l(d),s==null||s(),r()}finally{c(null)}},p=new Set(a.map(d=>d.info.rdns.toLowerCase())),m=Lt.filter(d=>!p.has(d.rdns.toLowerCase()));return e.jsx(de,{open:t,onClose:r,title:"Connect Wallet",width:450,preventClose:o,hideHeader:!0,cardClassName:"bg-surface-base border border-border-default rounded-[2px] shadow-[0_8px_32px_rgba(0,0,0,0.5)]",bodyClassName:"p-5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-body-lg-semibold text-white",children:"Connect Wallet"}),e.jsx("button",{type:"button",onClick:r,disabled:o,"aria-label":"Close",className:"size-[28px] rounded-[4px] flex items-center justify-center bg-transparent border-none transition-colors duration-fast ease-out "+(o?"text-text-tertiary cursor-not-allowed":"text-text-tertiary cursor-pointer hover:text-text-primary hover:bg-white/[0.05]"),children:e.jsx(Fe,{size:14})})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[a.map(d=>{const f=i===d.info.rdns,u=Lt.find(v=>v.rdns.toLowerCase()===d.info.rdns.toLowerCase()),y=(u==null?void 0:u.subtitle)??"Browser extension",h=d.info.icon??(u==null?void 0:u.iconUrl);return e.jsx(Mt,{icon:e.jsx(Et,{src:h,fallback:d.info.name[0]}),name:d.info.name,subtitle:f?"Connecting…":y,popular:u==null?void 0:u.popular,disabled:o,onClick:()=>!o&&x(d)},d.info.uuid)}),m.map(d=>e.jsx(Mt,{icon:e.jsx(Et,{src:d.iconUrl,fallback:d.name[0]}),name:d.name,subtitle:"Install extension",popular:d.popular,disabled:o,onClick:()=>window.open(d.installUrl,"_blank","noopener,noreferrer")},d.rdns))]})]})})}function Et({src:t,fallback:r}){const[s,o]=n.useState(!1);return!t||s?e.jsx("div",{className:"size-[36px] rounded-[4px] bg-surface-overlay text-text-primary flex items-center justify-center text-body-sm-medium flex-shrink-0",children:r}):e.jsx("img",{src:t,alt:"",onError:()=>o(!0),className:"size-[36px] rounded-[4px] object-cover flex-shrink-0"})}function Mt({icon:t,name:r,subtitle:s,popular:o,disabled:a,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,disabled:a,className:"flex items-center gap-3 px-4 py-2.5 bg-surface-canvas border border-border-subtle rounded-[2px] text-left w-full transition-colors duration-fast ease-out "+(a?"cursor-not-allowed opacity-60":"cursor-pointer hover:border-border-default"),children:[t,e.jsxs("div",{className:"flex-1 flex flex-col gap-0.5 min-w-0 leading-[1.5]",children:[e.jsx("span",{className:"text-body-md-medium text-text-primary",children:r}),e.jsx("span",{className:"text-label-sm text-text-tertiary",children:s})]}),o&&e.jsx("span",{className:"text-footnote text-brand-default bg-[#0d3b2a] px-2 py-1 rounded-[4px] leading-none whitespace-nowrap",children:"Popular"}),e.jsx("span",{className:"font-mono text-caption text-[#484f58] leading-none",children:"›"})]})}function Vs({open:t,onClose:r}){const{wallets:s,connecting:o,signingAddress:a,signingPhase:l,error:i,info:c,providers:x,addApiWallet:p,removeWallet:m,clearMessages:d}=at(),{aggregate:f}=me(),[u,y]=n.useState(null),[h,v]=n.useState(null),[g,b]=n.useState(!1),w=()=>b(!0);function C(j){var $;const S=f==null?void 0:f.perWallet.find(L=>L.address.toLowerCase()===j.toLowerCase());if(!S)return null;const R=S.positions??[],P=R.reduce((L,I)=>L+I.unrealizedPnl,0);return{equity:(($=S.balance)==null?void 0:$.totalEquity)??0,posCount:R.length,pnl:P}}n.useEffect(()=>{t&&(d(),v(null))},[t,d]);const k=n.useCallback(()=>{v(null),d()},[d]);n.useEffect(()=>{if(!i&&!c&&!h)return;const j=setTimeout(k,5e3);return()=>clearTimeout(j)},[i,c,h,k]);const E=async j=>{y(j);try{await m(j)}catch(S){v((S==null?void 0:S.message)||"Failed to remove wallet")}finally{y(null)}},M=o||!!u,N=s.length>0?e.jsx("span",{className:"size-[22px] flex items-center justify-center px-2 pt-[2px] pb-[4px] bg-brand-subtle rounded-[4px] text-label-sm text-brand-default",children:s.length}):null;return e.jsxs(e.Fragment,{children:[e.jsx(de,{open:t,onClose:r,title:"Manage Wallets",width:600,preventClose:M,hideHeader:!0,cardClassName:"bg-surface-base border border-border-default rounded-[2px] shadow-[0_8px_32px_rgba(0,0,0,0.5)]",bodyClassName:"p-5",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-body-lg-semibold text-white",children:"Manage Wallets"}),N]}),e.jsx("button",{type:"button",onClick:r,disabled:M,"aria-label":"Close",className:"size-[28px] rounded-[4px] flex items-center justify-center bg-transparent border-none transition-colors duration-fast ease-out "+(M?"text-text-tertiary cursor-not-allowed":"text-text-tertiary cursor-pointer hover:text-text-primary hover:bg-white/[0.05]"),children:e.jsx(Fe,{size:14})})]}),i&&e.jsxs("div",{role:"alert","aria-live":"assertive",className:"px-2.5 py-2 text-footnote rounded-[4px] text-[var(--color-error-text)] bg-[rgba(255,71,87,0.06)] border border-[rgba(255,71,87,0.12)] flex justify-between items-start gap-2 leading-[1.4]",children:[e.jsx("span",{children:i}),e.jsx("button",{onClick:k,"aria-label":"Dismiss",className:"bg-transparent border-none text-[var(--color-error-text)] cursor-pointer p-0 flex-shrink-0 opacity-50 transition-opacity duration-fast ease-out hover:opacity-100 focus-visible:opacity-100",children:e.jsx(Fe,{size:10})})]}),(c||h)&&e.jsxs("div",{role:"status","aria-live":"polite",className:"px-2.5 py-2 text-footnote rounded-[4px] text-[var(--color-text-secondary)] bg-[rgba(127,143,158,0.06)] border border-[rgba(127,143,158,0.1)] flex justify-between items-start gap-2 leading-[1.4]",children:[e.jsx("span",{children:c||h}),e.jsx("button",{onClick:k,"aria-label":"Dismiss",className:"bg-transparent border-none text-[var(--color-text-secondary)] cursor-pointer p-0 flex-shrink-0 opacity-50 transition-opacity duration-fast ease-out hover:opacity-100 focus-visible:opacity-100",children:e.jsx(Fe,{size:10})})]}),s.length===0?e.jsxs("div",{className:"py-5 flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"w-11 h-11 rounded-[4px] bg-brand-subtle border border-brand-soft flex items-center justify-center",children:e.jsx(_s,{size:20,className:"text-text-muted"})}),e.jsxs("div",{className:"flex flex-col items-center gap-[3px]",children:[e.jsx("span",{className:"text-caption text-text-secondary",children:x.length>0?"No wallets connected":"No wallet extension detected"}),x.length===0&&e.jsx("span",{className:"text-footnote text-text-muted text-center max-w-[260px]",children:"Install a browser wallet like MetaMask or Rabby, then refresh this page"})]})]}):e.jsx("div",{className:"flex flex-col gap-2",children:s.map((j,S)=>{const R=a===j.address,P=C(j.address),$=u===j.address;return e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5 bg-surface-canvas border border-border-subtle rounded-[2px] [font-variant-numeric:tabular-nums]",children:[e.jsxs("div",{className:"flex flex-col gap-1.5 min-w-0 flex-1",children:[e.jsxs("span",{className:"text-label-sm text-text-secondary",children:["Account ",S+1]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-body-md text-[#c8d1db] whitespace-nowrap",children:St(j.address)}),j.isDefault&&e.jsx("span",{className:"bg-surface-raised px-1 py-px rounded-[4px] text-footnote text-text-secondary",children:"Default"})]}),P&&e.jsxs("div",{className:"flex items-center gap-2 text-label-sm text-text-tertiary whitespace-nowrap",children:[e.jsxs("span",{children:["Values ",ve(P.equity)]}),e.jsx("span",{className:"size-[2px] rounded-full bg-text-tertiary shrink-0"}),e.jsxs("span",{children:[P.posCount," position",P.posCount!==1?"s":""]}),P.pnl!==0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"size-[2px] rounded-full bg-text-tertiary shrink-0"}),e.jsxs("span",{children:["PnL ",e.jsx("span",{style:{color:P.pnl>=0?"var(--color-success-text)":"var(--color-error-text)"},children:Hs(P.pnl)})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 flex-shrink-0",children:[j.status!=="trading"&&(()=>{const L=R?l==="generating"?"Generating…":l==="switching-chain"?"Switch chain…":l==="signing"?"Signing…":l==="submitting"?"Submitting…":l==="confirming"?"Confirming…":"Enable Trading":"Enable Trading",I=a!==null;return e.jsxs("button",{type:"button",className:"btn-press flex items-center gap-1 h-[24px] px-1.5 py-1 border border-success-default bg-success-subtle text-success-text rounded-[4px] text-label-sm transition-[background,opacity] duration-base ease-out "+(I?"cursor-wait":"cursor-pointer hover:bg-[rgba(34,197,94,0.18)]"),onClick:()=>!I&&p(j.address),disabled:I,style:{opacity:I&&!R?.5:R?.7:1},children:[R?e.jsx(Nt,{size:14,className:"animate-spin motion-reduce:animate-none"}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),L]})})(),e.jsx("button",{type:"button",onClick:()=>!$&&E(j.address),disabled:$,"aria-label":`Remove ${St(j.address)}`,title:$?"Removing…":"Remove wallet",className:"bg-transparent border-none p-0 inline-flex items-center justify-center transition-colors duration-fast ease-out "+($?"cursor-wait text-text-tertiary":"cursor-pointer text-text-tertiary hover:text-[var(--color-error-text)]"),children:$?e.jsx(Nt,{size:18,className:"animate-spin motion-reduce:animate-none"}):e.jsx(Rs,{size:18})})]})]},j.address)})}),x.length>0&&e.jsxs("button",{type:"button",onClick:w,disabled:o,className:"btn-press flex items-center justify-center gap-1.5 w-full h-[43px] py-2.5 bg-transparent border border-border-default rounded-[4px] text-body-md-medium text-brand-default transition-colors duration-fast ease-out "+(o?"cursor-wait opacity-60":"cursor-pointer hover:bg-[rgba(59,247,191,0.04)] hover:border-brand-default"),children:[e.jsx(Ms,{size:17}),o?"CONNECTING…":"ADD WALLET"]})]})}),e.jsx(gr,{open:g,onClose:()=>b(!1)})]})}function Ye(t){return`$${Math.abs(t).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`}const vr=1e4;function yr(t){return`${t>=0?"+":"-"}${Ye(t)}`}function wr(t){return`${t>=0?"+":""}${t.toFixed(1)}%`}function Pe(t){return t.toFixed(t>=100?1:t>=1?2:4)}function ye(t){return t>=1e3?`$${t.toLocaleString("en-US",{maximumFractionDigits:0})}`:t>=1?`$${t.toFixed(2)}`:`$${t.toFixed(4)}`}function Cr(t,r){if(r===void 0)return{pnl:t.unrealizedPnl,pct:t.unrealizedPnlPct};const s=t.side==="long"?(r-t.entryPrice)*t.size:(t.entryPrice-r)*t.size,o=t.margin>0?s/t.margin*100:0;return{pnl:s,pct:o}}function Tt(t){return t.length<=14?t:`${t.slice(0,6)}...${t.slice(-8)}`}function Qe(t,r,s){const o=t.triggerPrice!=null;let a=o?"Trigger":"Limit",l="var(--color-text-tertiary)",i=o?"rgba(121,121,121,0.15)":"rgba(91,164,181,0.12)";if(t.orderType.toLowerCase().includes("stop"))a="SL",l="var(--color-error-default)",i="var(--color-error-soft)";else if(t.orderType.toLowerCase().includes("take"))a="TP",l="var(--color-brand-default)",i="var(--color-brand-soft)";else if(t.reduceOnly&&r&&s){const c=t.triggerPrice??t.price;c!=null&&((r==="long"?c<s:c>s)?(a="SL",l="var(--color-error-default)",i="var(--color-error-soft)"):(a="TP",l="var(--color-brand-default)",i="var(--color-brand-soft)"))}return{typeLabel:a,typeColor:l,typeBg:i,isTrigger:o}}function Ws(t,r){return r.filter(s=>s.symbol===t&&(s.triggerPrice!=null||s.reduceOnly))}function zs(t,r){return t.filter(s=>!r.has(s.symbol)||!s.triggerPrice&&!s.reduceOnly)}const Us="/_app/assets/hyperliquid-logo-Blr66fIk.svg";function Zs(){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"34",height:"34",viewBox:"0 0 34 34",fill:"none","aria-hidden":"true",className:"shrink-0",children:[e.jsx("rect",{width:"34",height:"34",rx:"17",fill:"#3BF7BF",fillOpacity:"0.08"}),e.jsx("rect",{x:"0.5",y:"0.5",width:"33",height:"33",rx:"16.5",stroke:"#3BF7BF",strokeOpacity:"0.08"}),e.jsx("path",{d:"M24.1482 21.3509C23.8507 19.4257 23.5472 17.4947 23.1157 15.5931C22.1368 11.279 21.4232 8.3046 15.918 8.84506C11.9038 9.2388 11.4055 13.2182 10.744 16.329C10.4206 17.8493 10.0733 19.5769 9.89166 21.112C9.84337 21.5175 9.75215 21.7498 10.0779 22.0875C10.8966 22.9362 12.3453 21.3863 13.1333 21.4283C13.6921 21.4586 13.981 21.9098 14.4371 22.0963C15.836 22.6692 16.1396 21.5551 17.0448 21.5728C17.6312 21.5846 17.8443 22.0344 18.3441 22.1723C19.7391 22.5572 20.0503 21.3819 21.0323 21.4239C21.3734 21.4386 21.6171 21.7004 21.9099 21.8383C22.599 22.1642 23.5043 22.6449 23.9818 22.0256C24.1305 21.8331 24.1834 21.5868 24.1466 21.3502L24.1482 21.3509ZM17.0011 17.3302C14.6778 17.3302 12.7945 15.6941 12.7945 13.676C12.7945 11.658 14.6778 10.0218 17.0011 10.0218C19.3245 10.0218 21.2078 11.658 21.2078 13.676C21.2078 15.6941 19.3245 17.3302 17.0011 17.3302Z",fill:"#3BF7BF"}),e.jsx("path",{d:"M12.198 25.5912C12.7556 25.5912 13.2076 25.157 13.2076 24.6214C13.2076 24.0858 12.7556 23.6516 12.198 23.6516C11.6404 23.6516 11.1884 24.0858 11.1884 24.6214C11.1884 25.157 11.6404 25.5912 12.198 25.5912Z",fill:"#3BF7BF"}),e.jsx("path",{d:"M16.9094 25.5912C17.467 25.5912 17.919 25.157 17.919 24.6214C17.919 24.0858 17.467 23.6516 16.9094 23.6516C16.3518 23.6516 15.8998 24.0858 15.8998 24.6214C15.8998 25.157 16.3518 25.5912 16.9094 25.5912Z",fill:"#3BF7BF"}),e.jsx("path",{d:"M21.6211 25.5912C22.1787 25.5912 22.6307 25.157 22.6307 24.6214C22.6307 24.0858 22.1787 23.6516 21.6211 23.6516C21.0635 23.6516 20.6115 24.0858 20.6115 24.6214C20.6115 25.157 21.0635 25.5912 21.6211 25.5912Z",fill:"#3BF7BF"})]})}function qs({size:t=16}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:[e.jsx("path",{d:"M8.66667 6.5H4.66667C4.39334 6.5 4.16667 6.27333 4.16667 6C4.16667 5.72667 4.39334 5.5 4.66667 5.5H8.66667C8.94001 5.5 9.16667 5.72667 9.16667 6C9.16667 6.27333 8.94001 6.5 8.66667 6.5Z",fill:"#3BF7BF"}),e.jsx("path",{d:"M12.6933 9.86662C11.6866 9.86662 10.8333 9.11995 10.7533 8.15995C10.6999 7.60662 10.9 7.06663 11.3 6.6733C11.6333 6.32663 12.1066 6.1333 12.6066 6.1333H13.9999C14.6599 6.1533 15.1666 6.67327 15.1666 7.31327V8.68665C15.1666 9.32665 14.66 9.84662 14.02 9.86662H12.6933ZM13.9799 7.1333H12.6133C12.3799 7.1333 12.1666 7.21996 12.0133 7.37996C11.82 7.56663 11.7266 7.81995 11.7533 8.07328C11.7866 8.51328 12.2133 8.86662 12.6933 8.86662H13.9999C14.0866 8.86662 14.1666 8.78665 14.1666 8.68665V7.31327C14.1666 7.21327 14.0866 7.13997 13.9799 7.1333Z",fill:"#3BF7BF"}),e.jsx("path",{d:"M10.6667 14.1667H4.66666C2.37333 14.1667 0.833328 12.6267 0.833328 10.3333V5.66666C0.833328 3.61333 2.09998 2.12667 4.06665 1.88C4.24665 1.85333 4.45333 1.83333 4.66666 1.83333H10.6667C10.8267 1.83333 11.0333 1.83999 11.2467 1.87333C13.2133 2.09999 14.5 3.59333 14.5 5.66666V6.63334C14.5 6.90667 14.2733 7.13334 14 7.13334H12.6133C12.38 7.13334 12.1667 7.22 12.0133 7.38L12.0067 7.38667C11.82 7.56667 11.7333 7.81331 11.7533 8.06665C11.7867 8.50664 12.2133 8.85998 12.6933 8.85998H14C14.2733 8.85998 14.5 9.08665 14.5 9.35998V10.3267C14.5 12.6267 12.96 14.1667 10.6667 14.1667ZM4.66666 2.83333C4.50666 2.83333 4.35332 2.84665 4.19999 2.86665C2.73332 3.05332 1.83333 4.11999 1.83333 5.66666V10.3333C1.83333 12.0533 2.94666 13.1667 4.66666 13.1667H10.6667C12.3867 13.1667 13.5 12.0533 13.5 10.3333V9.86665H12.6933C11.6866 9.86665 10.8333 9.11999 10.7533 8.15999C10.7 7.61332 10.9 7.06667 11.3 6.68001C11.6467 6.32667 12.1133 6.13334 12.6133 6.13334H13.5V5.66666C13.5 4.10666 12.5866 3.03331 11.1066 2.85998C10.9466 2.83331 10.8067 2.83333 10.6667 2.83333H4.66666Z",fill:"#3BF7BF"})]})}function Gs(){return e.jsx("img",{src:Us,alt:"",width:34,height:34,className:"size-[34px] shrink-0 object-cover","aria-hidden":"true"})}function Ks(){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"36",height:"12",viewBox:"0 0 36 12",fill:"none","aria-hidden":"true",className:"shrink-0",children:[e.jsx("line",{y1:"5.5",x2:"11",y2:"5.5",stroke:"#3BF7BF",strokeDasharray:"2 2"}),e.jsx("line",{x1:"22.9997",y1:"5.5",x2:"35.9997",y2:"5.5",stroke:"#3BF7BF",strokeDasharray:"2 2"}),e.jsx("path",{d:"M13.3333 4.665V7.335C13.3333 8.995 14.5083 9.67 15.9433 8.845L16.5833 8.475C16.7383 8.385 16.8333 8.22 16.8333 8.04V3.96C16.8333 3.78 16.7383 3.615 16.5833 3.525L15.9433 3.155C14.5083 2.33 13.3333 3.005 13.3333 4.665Z",fill:"#3BF7BF"}),e.jsx("path",{d:"M17.3333 4.395V7.61C17.3333 7.805 17.5433 7.925 17.7083 7.825L18.2583 7.505C19.6933 6.68 19.6933 5.32 18.2583 4.495L17.7083 4.175C17.5433 4.08 17.3333 4.2 17.3333 4.395Z",fill:"#3BF7BF"})]})}function Xs({onConnect:t}){return e.jsx("div",{className:"bg-[rgba(59,247,191,0.04)]",children:e.jsxs("div",{className:"flex flex-col gap-4 items-center px-4 pt-6 pb-8",children:[e.jsxs("div",{className:"flex flex-col gap-3 items-center w-full",children:[e.jsxs("div",{className:"flex gap-3 items-center",children:[e.jsx(Zs,{}),e.jsx(Ks,{}),e.jsx(Gs,{})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 items-center leading-[1.5]",children:[e.jsx("p",{className:"text-body-md-semibold text-white",children:"Connect Wallet"}),e.jsx("p",{className:"text-body-sm text-text-secondary text-center",children:"Connect your Hyperliquid wallet to unlock portfolio tracking, trading, and AI insights."})]})]}),e.jsxs("button",{type:"button",onClick:t,className:"btn-press border border-brand-default rounded-[4px] h-8 px-4 py-2.5 flex items-center justify-center gap-2.5 bg-transparent cursor-pointer transition-colors duration-fast ease-out hover:bg-[rgba(59,247,191,0.08)] focus-visible:bg-[rgba(59,247,191,0.08)]",children:[e.jsx(qs,{size:16}),e.jsx("span",{className:"text-label-md leading-none text-brand-default whitespace-nowrap",children:"Connect Wallet"})]})]})})}const Js="/_app/assets/ghost-symbol-xItVvoCA.svg",Ys=9e3;function Le({children:t,borderColor:r}){const{lastFetchedAt:s}=me(),[o,a]=n.useState(0),l=n.useRef(0);return n.useEffect(()=>{const i=Date.now();i-l.current<Ys||(l.current=i,a(c=>c+1))},[s]),e.jsxs("div",{className:"relative pt-8",children:[e.jsx("div",{className:"border rounded-[2px] overflow-hidden",style:{borderColor:r??"var(--color-border-subtle)"},children:t}),e.jsxs("div",{className:"absolute top-0 left-0 h-[43px]",style:{position:"absolute",zIndex:30,pointerEvents:"none"},children:[e.jsx("div",{className:"absolute left-0 -right-[7px] top-[32px] h-px bg-surface-canvas pointer-events-none"}),e.jsxs("div",{className:"relative flex items-end",children:[e.jsx("img",{src:Js,alt:"",width:35,height:43,className:"block ghost-symbol-bob","aria-hidden":"true"},o),e.jsx("span",{className:"text-body-md-semibold leading-none text-brand-default whitespace-nowrap pb-[2px] pl-3",children:"\\: PORTFOLIO"})]})]})]})}const Qs={"top-left":"top left","top-right":"top right","top-center":"top center","bottom-left":"bottom left","bottom-right":"bottom right"},Rt='[role="menuitem"], button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])',lt=n.forwardRef(function({open:r,children:s,origin:o="top-left",slideY:a=4,duration:l=160,className:i,style:c,role:x,"aria-label":p,initialFocus:m="none",onEscape:d,trapArrowKeys:f=!0,returnFocusOnClose:u=!0},y){const[h,v]=n.useState(r),[g,b]=n.useState(r?"enter":"exit"),w=n.useRef(null),C=n.useRef(null),k=n.useRef(null);if(n.useEffect(()=>(r?(w.current&&clearTimeout(w.current),v(!0),requestAnimationFrame(()=>requestAnimationFrame(()=>b("enter")))):(b("exit"),w.current=setTimeout(()=>v(!1),l)),()=>{w.current&&clearTimeout(w.current)}),[r,l]),n.useEffect(()=>{if(r){if(u){const N=document.activeElement;k.current=N&&N!==document.body?N:null}return m==="first"&&requestAnimationFrame(()=>{var j;const N=(j=C.current)==null?void 0:j.querySelector(Rt);N==null||N.focus()}),()=>{var N,j;u&&((j=(N=k.current)==null?void 0:N.focus)==null||j.call(N))}}},[r,m,u]),n.useEffect(()=>{if(!r)return;const N=C.current;if(!N)return;const j=S=>{var L;if(S.key==="Escape"&&d){S.stopPropagation(),d();return}if(!f||S.key!=="ArrowDown"&&S.key!=="ArrowUp")return;const R=Array.from(N.querySelectorAll(Rt));if(R.length===0)return;S.preventDefault();const P=R.indexOf(document.activeElement),$=S.key==="ArrowDown"?(P+1)%R.length:P<=0?R.length-1:P-1;(L=R[$])==null||L.focus()};return N.addEventListener("keydown",j),()=>N.removeEventListener("keydown",j)},[r,d,f]),!h)return null;const E=g==="enter",M={transformOrigin:Qs[o],opacity:E?1:0,transform:E?"translateY(0) scale(1)":`translateY(${-a}px) scale(0.96)`,transition:`opacity ${l}ms var(--ease-out, ease-out), transform ${l}ms var(--ease-out, ease-out)`,...c};return e.jsx("div",{ref:N=>{C.current=N,typeof y=="function"?y(N):y&&(y.current=N)},className:`will-change-[opacity,transform]${i?` ${i}`:""}`,style:M,role:x,"aria-label":p,children:s})}),Ee=n.memo(function({value:r,format:s,duration:o=320,className:a,style:l}){const[i,c]=n.useState(r),x=n.useRef(r),p=n.useRef(0),m=n.useRef(null);return n.useEffect(()=>{if(r===i)return;if(typeof window<"u"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches){c(r);return}x.current=i,p.current=performance.now();const f=u=>{const y=u-p.current,h=Math.min(1,y/o),v=1-Math.pow(1-h,3),g=x.current+(r-x.current)*v;c(h>=1?r:g),h<1?m.current=requestAnimationFrame(f):m.current=null};return m.current!==null&&cancelAnimationFrame(m.current),m.current=requestAnimationFrame(f),()=>{m.current!==null&&(cancelAnimationFrame(m.current),m.current=null)}},[r,o]),e.jsx("span",{className:`tabular-nums${a?` ${a}`:""}`,style:l,children:s(i)})}),en=({open:t})=>e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",className:`transition-transform duration-base ease-out ${t?"rotate-180":""}`,children:e.jsx("path",{d:"M8.95987 4.08997H5.84487H3.03987C2.55987 4.08997 2.31987 4.66997 2.65987 5.00997L5.24987 7.59997C5.66487 8.01497 6.33987 8.01497 6.75487 7.59997L7.73987 6.61497L9.34487 5.00997C9.67987 4.66997 9.43987 4.08997 8.95987 4.08997Z",fill:"currentColor"})}),tn=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M9.69992 14.9467C9.47992 14.9467 9.27325 14.8 9.21325 14.5733C9.13992 14.3067 9.29992 14.0333 9.57325 13.96C12.2799 13.2467 14.1666 10.7933 14.1666 7.99334C14.1666 4.59334 11.3999 1.82667 7.99992 1.82667C5.11325 1.82667 3.21992 3.51334 2.33325 4.53334H4.29325C4.56659 4.53334 4.79325 4.76 4.79325 5.03334C4.79325 5.30667 4.57325 5.54 4.29325 5.54H1.33992C1.30659 5.54 1.24659 5.53334 1.19992 5.52C1.13992 5.5 1.08659 5.47334 1.03992 5.44C0.979919 5.4 0.933252 5.34667 0.899919 5.28667C0.866585 5.22667 0.839919 5.15334 0.833252 5.08C0.833252 5.06 0.833252 5.04667 0.833252 5.02667V2C0.833252 1.72667 1.05992 1.5 1.33325 1.5C1.60659 1.5 1.83325 1.72667 1.83325 2V3.59334C2.91992 2.42667 4.96658 0.833336 7.99992 0.833336C11.9533 0.833336 15.1666 4.04667 15.1666 8C15.1666 11.2533 12.9733 14.1067 9.82658 14.9333C9.78658 14.94 9.73992 14.9467 9.69992 14.9467Z",fill:"currentColor"}),e.jsx("path",{d:"M10.2147 10C10.1369 10 10.0592 9.98255 9.9875 9.93602L8.13431 8.86005C7.674 8.59251 7.33325 8.00509 7.33325 7.48746V5.10287C7.33325 4.86441 7.5365 4.66666 7.7816 4.66666C8.0267 4.66666 8.22996 4.86441 8.22996 5.10287V7.48746C8.22996 7.69683 8.4093 8.00509 8.59462 8.10978L10.4478 9.18575C10.663 9.30789 10.7288 9.57542 10.6032 9.7848C10.5136 9.92439 10.3641 10 10.2147 10Z",fill:"currentColor"}),e.jsx("path",{d:"M7.52658 15.1533C7.51325 15.1533 7.49992 15.1467 7.49325 15.1467C6.77325 15.1 6.06659 14.94 5.39992 14.68C5.20659 14.6067 5.07325 14.4133 5.07992 14.2067C5.07992 14.1467 5.09325 14.0867 5.11325 14.0333C5.21325 13.78 5.51325 13.6533 5.75992 13.7467C6.33992 13.9733 6.94659 14.1067 7.55992 14.1533C7.81992 14.1667 8.02658 14.3933 8.02658 14.66L8.01992 14.6867C8.00658 14.9467 7.78658 15.1533 7.52658 15.1533ZM3.85325 13.72C3.73992 13.72 3.63325 13.68 3.53992 13.6133C2.97992 13.16 2.48659 12.6333 2.08659 12.0467C2.02659 11.96 1.99325 11.8667 1.99325 11.7667C1.99325 11.6 2.07325 11.4467 2.21325 11.3533C2.43325 11.2 2.75325 11.26 2.90659 11.4733C2.90659 11.48 2.90659 11.48 2.90659 11.48C2.91325 11.4867 2.91992 11.5 2.92658 11.5067C3.27325 12.0067 3.69325 12.4533 4.16658 12.8267C4.27992 12.92 4.35325 13.06 4.35325 13.2133C4.35325 13.3267 4.31992 13.44 4.24658 13.5333C4.14658 13.6533 4.00659 13.72 3.85325 13.72ZM1.62659 10.4667C1.40659 10.4667 1.21325 10.3267 1.15325 10.12C0.939919 9.43333 0.833252 8.72 0.833252 8V7.99333C0.839919 7.72 1.05992 7.5 1.33325 7.5C1.60659 7.5 1.83325 7.72667 1.83325 8C1.83325 8.62667 1.92659 9.24 2.10659 9.82C2.11992 9.87333 2.12659 9.92 2.12659 9.97333C2.12659 10.1867 1.98659 10.38 1.77325 10.4467C1.72659 10.46 1.67992 10.4667 1.62659 10.4667Z",fill:"currentColor"})]}),_t=({up:t})=>e.jsx("svg",{width:"8",height:"6",viewBox:"0 0 8 6",fill:"none","aria-hidden":"true",className:t?"":"rotate-180",children:e.jsx("path",{d:"M4 0L8 6H0L4 0Z",fill:t?"var(--color-success-text)":"var(--color-error-text)"})});function rn({selectedView:t,onSelect:r,onManageWallets:s}){const{wallets:o,paperMode:a}=me(),[l,i]=n.useState(!1),c=n.useRef(null),x=n.useRef(null),[p,m]=n.useState(null);n.useLayoutEffect(()=>{if(!l)return;const u=()=>{var h;const y=(h=c.current)==null?void 0:h.getBoundingClientRect();y&&m({top:y.bottom+4,left:y.left})};return u(),window.addEventListener("resize",u),window.addEventListener("scroll",u,!0),()=>{window.removeEventListener("resize",u),window.removeEventListener("scroll",u,!0)}},[l]),n.useEffect(()=>{if(!l)return;const u=y=>{var v,g;const h=y.target;(v=c.current)!=null&&v.contains(h)||(g=x.current)!=null&&g.contains(h)||i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[l]);const d=o.find(u=>u.isDefault)??o[0],f=o.length>1&&t==="all"?`All wallets (${o.length})`:Tt(t==="all"?(d==null?void 0:d.address)??"":t);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:c,onClick:()=>i(!l),"aria-haspopup":"menu","aria-expanded":l,className:"flex items-center gap-1.5 py-1 rounded-[4px] bg-transparent text-text-secondary text-body-sm cursor-pointer transition-colors duration-fast ease-out hover:text-text-tertiary",children:[e.jsx("span",{className:"whitespace-nowrap",children:f}),e.jsx(en,{open:l})]}),he.createPortal(e.jsxs(lt,{ref:x,open:l,origin:"top-left",slideY:4,className:"fixed z-50 bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[4px] shadow-[0_4px_16px_rgba(0,0,0,0.5)] min-w-[180px] max-h-[240px] overflow-y-auto",style:p?{top:p.top,left:p.left}:{top:-9999,left:-9999},children:[o.length>1&&e.jsxs("button",{onClick:()=>{r("all"),i(!1)},className:"flex items-center gap-1.5 w-full text-left px-2.5 py-2 text-body-sm border-none cursor-pointer transition-colors duration-fast ease-out "+(t==="all"?"bg-brand-subtle text-brand-default":"bg-transparent text-text-secondary hover:bg-white/[0.03]"),children:["All Wallets (",o.length,")"]}),o.map(u=>{const y=t===u.address||o.length===1&&t==="all";return e.jsxs("button",{onClick:()=>{r(o.length===1?"all":u.address),i(!1)},className:"flex items-center gap-1.5 w-full text-left px-2.5 py-2 text-body-sm border-none cursor-pointer transition-colors duration-fast ease-out "+(y?"bg-brand-subtle text-brand-default":"bg-transparent text-text-secondary hover:bg-white/[0.03]"),children:[e.jsx("span",{className:"w-[5px] h-[5px] rounded-full flex-shrink-0",style:{background:u.status==="trading"?"var(--color-brand-default)":"var(--color-text-muted)"}}),e.jsx("span",{className:"flex-1",children:Tt(u.address)})]},u.address)}),!a&&e.jsx("div",{className:"border-t border-[var(--color-border-default)]",children:e.jsxs("button",{onClick:()=>{i(!1),s()},className:"flex items-center gap-1 w-full px-2.5 py-2 text-body-sm bg-transparent text-text-secondary border-none cursor-pointer hover:bg-white/[0.03]",children:[e.jsx(Ts,{size:10})," Manage"]})})]}),document.body)]})}function sn({activeAddr:t,disabled:r}){const{addApiWallet:s,signingAddress:o,signingPhase:a}=at(),l=t!=null&&(o==null?void 0:o.toLowerCase())===t.toLowerCase(),i=l?a==="generating"?"Generating…":a==="switching-chain"?"Switch chain…":a==="signing"?"Signing…":a==="submitting"?"Submitting…":a==="confirming"?"Confirming…":"Enable Trading":"Enable Trading";return e.jsx("button",{type:"button",onClick:()=>t&&!l&&s(t),disabled:r||l,className:"btn-press h-[26px] px-2 py-1 border border-brand-default rounded-[4px] bg-transparent text-brand-default text-body-sm-medium leading-none whitespace-nowrap transition-colors duration-fast ease-out "+(r||l?"opacity-60 cursor-not-allowed":"cursor-pointer hover:bg-[rgba(59,247,191,0.08)]"),children:i})}function At({kind:t,price:r,size:s,symbol:o,pnl:a}){const l=t==="TP"?"text-success-text":"text-error-text",i=t==="TP"?"text-success-default":"text-error-default";return e.jsxs("div",{className:"flex h-[18px] items-center justify-between py-1",children:[e.jsx("span",{className:`${i} text-label-sm leading-none w-[35px] tracking-[0.24px]`,children:t}),e.jsx("span",{className:"text-body-sm text-text-primary w-[60px]",children:ye(r)}),e.jsxs("span",{className:"text-body-sm text-text-primary w-[90px]",children:[Pe(s)," ",o]}),e.jsx("span",{className:`${l} text-body-sm text-right w-[60px]`,children:br(a,vr)})]})}function nn({position:t,viewOrders:r,livePrices:s,getMarketPrice:o}){const a=t.side==="long",l=a?"LONG":"SHORT",i=a?"text-success-text":"text-error-text",c=a?"bg-success-subtle":"bg-error-subtle",x=Ws(t.symbol,r),p=g=>g.triggerPrice??g.price??0,m=x.filter(g=>Qe(g,t.side,t.entryPrice).typeLabel==="TP").sort((g,b)=>a?p(g)-p(b):p(b)-p(g)),d=x.filter(g=>Qe(g,t.side,t.entryPrice).typeLabel==="SL").sort((g,b)=>a?p(b)-p(g):p(g)-p(b)),f=o(t.symbol,t.markPrice),u=a?f>=t.entryPrice:f<=t.entryPrice,{pnl:y,pct:h}=Cr(t,s[t.symbol]),v=y>=0?"text-success-text":"text-error-text";return e.jsxs("div",{className:"flex flex-col gap-2 [font-variant-numeric:tabular-nums]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-body-md-medium text-text-primary",children:t.symbol}),e.jsxs("span",{className:`${c} ${i} h-[20px] flex items-center justify-center px-[7px] rounded-[2px] text-label-sm leading-none`,children:[l," ",t.leverage,"x"]})]}),e.jsxs("div",{className:`flex items-center gap-[7px] ${v}`,children:[e.jsx("span",{className:"text-body-md-medium",children:yr(y)}),e.jsxs("div",{className:"flex items-center gap-[2px]",children:[e.jsx(_t,{up:y>=0}),e.jsx("span",{className:"text-body-sm",children:wr(h)})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-number-sm text-text-tertiary",children:[e.jsxs("span",{children:["Size: ",Pe(t.size)," ",t.symbol]}),e.jsxs("span",{children:["Margin: ",ve(t.margin,vr)]})]}),e.jsxs("div",{className:"border-y border-dashed border-border-subtle flex h-[53px] items-stretch gap-5",children:[e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-[2px] justify-center",children:[e.jsx("span",{className:"text-number-sm text-text-tertiary",children:"Entry Price"}),e.jsx("span",{className:"text-body-sm text-text-primary",children:ye(t.entryPrice)})]}),e.jsx("div",{className:"self-stretch border-l border-dashed border-border-subtle"}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-[2px] justify-center",children:[e.jsx("span",{className:"text-number-sm text-text-tertiary",children:"Mark Price"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-body-sm text-text-primary",children:ye(f)}),e.jsx(_t,{up:u})]})]}),e.jsx("div",{className:"self-stretch border-l border-dashed border-border-subtle"}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-[2px] justify-center",children:[e.jsx("span",{className:"text-number-sm text-text-tertiary",children:"Liq.Price"}),e.jsx("span",{className:"text-body-sm text-warning-text",children:t.liquidationPrice!=null?ye(t.liquidationPrice):"N/A"})]})]})]}),(m.length>0||d.length>0)&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-[2px] text-number-sm text-text-tertiary",children:[e.jsx("span",{className:"w-[35px]",children:"Order"}),e.jsx("span",{className:"w-[60px]",children:"Price"}),e.jsx("span",{className:"w-[90px]",children:"Size"}),e.jsx("span",{className:"w-[60px] text-right",children:"PnL"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[m.map(g=>{const b=g.size>0?g.size:t.size,w=(p(g)-t.entryPrice)*b*(a?1:-1);return e.jsx(At,{kind:"TP",price:p(g),size:b,symbol:t.symbol,pnl:w},g.orderId)}),d.map(g=>{const b=g.size>0?g.size:t.size,w=(p(g)-t.entryPrice)*b*(a?1:-1);return e.jsx(At,{kind:"SL",price:p(g),size:b,symbol:t.symbol,pnl:w},g.orderId)})]})]})]})}function on({order:t}){const{typeLabel:r}=Qe(t),s=t.side==="buy",o=t.reduceOnly?s?"CLOSE SHORT":"CLOSE LONG":s?"BUY":"SELL",a=t.reduceOnly?"bg-[rgba(110,116,128,0.15)] text-text-tertiary":s?"bg-info-subtle text-info-text":"bg-error-subtle text-error-text",l=t.triggerPrice??t.price??0;return e.jsxs("div",{className:"flex flex-col gap-[7px] items-start w-full [font-variant-numeric:tabular-nums]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-body-md-medium text-text-primary",children:t.symbol}),e.jsxs("span",{className:`${a} h-5 flex items-center justify-center px-1.5 rounded-[2px] text-label-sm leading-none tracking-[0.24px]`,children:[r," ",o]})]}),e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("span",{className:"text-number-sm text-text-tertiary",children:["Size: ",Pe(t.size)," ",t.symbol]}),e.jsxs("span",{className:"text-number-sm text-text-tertiary",children:["Price: ",ye(l)]})]})]})}function an({selectedView:t,onSelect:r,onManageWallets:s,onOpenHistory:o,aggregate:a,viewBalance:l,viewPositions:i,livePrices:c}){const{wallets:x,paperMode:p}=me(),m=t==="all"&&a&&x.length>1,d=m?a.totalEquity:(l==null?void 0:l.totalEquity)??0,f=m?a.totalAvailable:(l==null?void 0:l.availableBalance)??0,u=m?a.perWallet.flatMap(M=>M.positions??[]):i,y=u.reduce((M,N)=>M+Cr(N,c[N.symbol]).pnl,0),h=u.reduce((M,N)=>M+N.unrealizedPnl,0),v=d+(y-h),g=f+(y-h),b=v>0?y/v*100:0,w=y>=0?"text-success-text":"text-error-text",C=x.find(M=>M.isDefault)??x[0],k=t==="all"?C:x.find(M=>M.address===t)??C,E=!p&&k!=null&&k.status!=="trading";return e.jsx("div",{className:"flex flex-col px-4 pt-6 [font-variant-numeric:tabular-nums]",children:e.jsxs("div",{className:"flex flex-col gap-2 pb-4",children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(rn,{selectedView:t,onSelect:r,onManageWallets:s}),e.jsxs("div",{className:"flex items-center gap-3",children:[E&&e.jsx(sn,{activeAddr:(k==null?void 0:k.address)??null,disabled:!1}),e.jsx("button",{type:"button",onClick:o,className:"size-[26px] flex items-center justify-center bg-transparent border-none text-text-secondary cursor-pointer transition-colors duration-fast ease-out hover:text-text-primary btn-press","aria-label":"Trade history",title:"Trade history",children:e.jsx(tn,{})})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 leading-[1.5]",children:[e.jsx("div",{className:"text-heading-md text-text-primary",children:e.jsx(Ee,{value:v,format:Ye})}),e.jsxs("div",{className:`text-body-md ${w}`,children:[e.jsx(Ee,{value:y,format:yr})," (",e.jsx(Ee,{value:b,format:wr}),") today"]})]})]}),e.jsx("div",{className:"flex h-[20px] items-center",children:e.jsxs("span",{className:"text-body-md text-text-secondary",children:["Available trade: ",e.jsx(Ee,{value:g,format:Ye})]})})]})})}const $e=10,ln=720;function cn({open:t,onClose:r,walletScope:s}){const{request:o}=te(),[a,l]=n.useState([]),[i,c]=n.useState(!1),[x,p]=n.useState(null),[m,d]=n.useState(1),f=()=>{let b=!1;c(!0),p(null);const w={lookbackHours:ln};return s==="all"?w.all=!0:w.address=s,o("trading.fills.list",w).then(C=>{b||(l(C.fills??[]),d(1))}).catch(C=>{if(b)return;const k=C instanceof Error?C.message:String(C);p(k),l([])}).finally(()=>{b||c(!1)}),()=>{b=!0}};n.useEffect(()=>{if(t)return f()},[t,s]);const u=Math.max(1,Math.ceil(a.length/$e)),y=(m-1)*$e,h=a.slice(y,y+$e),v=a.reduce((b,w)=>b+w.realizedPnl,0),g=a.reduce((b,w)=>b+w.fee,0);return e.jsx(de,{open:t,onClose:r,title:"Trade History",width:750,children:e.jsxs("div",{className:"flex flex-col gap-3 text-body-sm",children:[!i&&!x&&a.length>0&&e.jsxs("div",{className:"flex items-center gap-3 text-body-sm text-[var(--color-text-secondary)] [font-variant-numeric:tabular-nums] flex-wrap",children:[e.jsxs("span",{children:[a.length," fill",a.length!==1?"s":""]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Net PnL"," ",e.jsxs("span",{style:{color:v>=0?"var(--color-brand-default)":"var(--color-error-default)"},className:"font-bold",children:[v>=0?"+":"-",ve(Math.abs(v))]})]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Fees ",ve(g)]}),s==="all"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{children:"Aggregated"})]})]}),i&&e.jsx("div",{className:"text-center py-8 text-[var(--color-text-secondary)]",children:"Loading…"}),x&&!i&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border border-[var(--color-error-soft)] bg-[var(--color-error-subtle)] rounded text-[var(--color-error-default)]",children:[e.jsxs("span",{children:["Failed to load trade history: ",x]}),e.jsx("button",{type:"button",className:"text-body-sm text-[var(--color-error-default)] hover:underline btn-press ml-2",onClick:()=>f(),children:"Retry"})]}),!i&&!x&&a.length===0&&e.jsx("div",{className:"text-center py-8 text-[var(--color-text-secondary)]",children:"No trades yet. Place a trade and your fills will show up here."}),!i&&!x&&a.length>0&&e.jsxs("div",{className:"border border-[var(--color-surface-overlay)] rounded-[4px] overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[125px_80px_55px_90px_105px_105px_80px] gap-2 px-3 py-2.5 bg-[var(--color-surface-canvas)] border-b border-[var(--color-surface-overlay)] text-body-sm text-[var(--color-text-secondary)] tracking-[0.3px]",children:[e.jsx("span",{children:"Time"}),e.jsx("span",{children:"Symbol"}),e.jsx("span",{children:"Side"}),e.jsx("span",{className:"text-right",children:"Size"}),e.jsx("span",{className:"text-right",children:"Price"}),e.jsx("span",{className:"text-right",children:"PnL"}),e.jsx("span",{className:"text-right",children:"Fee"})]}),e.jsx("div",{className:"[font-variant-numeric:tabular-nums]",children:h.map(b=>{const w=new Date(b.timestamp),C=`${w.toLocaleDateString(void 0,{month:"short",day:"2-digit"})} ${w.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}`,k=b.side==="buy"?"var(--color-brand-default)":"var(--color-error-default)",E=b.realizedPnl>0?"var(--color-brand-default)":b.realizedPnl<0?"var(--color-error-default)":"var(--color-text-tertiary)";return e.jsxs("div",{className:"grid grid-cols-[125px_80px_55px_90px_105px_105px_80px] gap-2 px-3 py-2.5 border-b border-[var(--color-surface-overlay)] last:border-0 hover:bg-white/[0.02]",children:[e.jsx("span",{className:"text-[var(--color-text-secondary)] whitespace-nowrap",children:C}),e.jsx("span",{className:"text-white font-bold",children:b.symbol}),e.jsx("span",{className:"font-bold uppercase",style:{color:k},children:b.side}),e.jsx("span",{className:"text-right text-[var(--color-text-secondary)]",children:Pe(b.size)}),e.jsx("span",{className:"text-right text-[var(--color-text-secondary)]",children:ye(b.price)}),e.jsx("span",{className:"text-right font-bold",style:{color:E},children:b.realizedPnl!==0?br(b.realizedPnl):"—"}),e.jsx("span",{className:"text-right text-[var(--color-text-secondary)]",children:b.fee>0?ve(b.fee):"—"})]},b.tradeId)})}),u>1&&e.jsx(dn,{page:m,totalPages:u,onChange:d})]})]})})}function dn({page:t,totalPages:r,onChange:s}){const o=un(t,r);return e.jsxs("div",{className:"px-3 py-2 border-t border-[var(--color-surface-overlay)] flex items-center justify-end gap-1 text-body-sm",children:[e.jsx(Oe,{disabled:t===1,onClick:()=>s(t-1),"aria-label":"Previous page",children:"‹"}),o.map((a,l)=>a==="…"?e.jsx("span",{className:"px-1 text-[var(--color-text-secondary)]",children:"…"},`ellipsis-${l}`):e.jsx(Oe,{active:a===t,onClick:()=>s(a),"aria-label":`Page ${a}`,"aria-current":a===t?"page":void 0,children:a},a)),e.jsx(Oe,{disabled:t===r,onClick:()=>s(t+1),"aria-label":"Next page",children:"›"})]})}function un(t,r){if(r<=7)return Array.from({length:r},(l,i)=>i+1);const s=[1],o=Math.max(2,t-1),a=Math.min(r-1,t+1);o>2&&s.push("…");for(let l=o;l<=a;l++)s.push(l);return a<r-1&&s.push("…"),s.push(r),s}function Oe({children:t,onClick:r,active:s,disabled:o,...a}){return e.jsx("button",{type:"button",onClick:r,disabled:o,className:`min-w-[22px] px-1.5 py-0.5 rounded-[2px] border transition-colors duration-fast btn-press ${s?"bg-[var(--color-surface-overlay)] border-[var(--color-brand-default)]/40 text-[var(--color-brand-default)]":o?"border-transparent text-[var(--color-border-strong)] cursor-not-allowed":"border-[var(--color-surface-overlay)] text-[var(--color-text-secondary)] hover:text-white hover:border-[var(--color-surface-overlay)]"}`,...a,children:t})}function xn(){const{status:t,balance:r,positions:s,openOrders:o,aggregate:a,error:l}=me(),{subscribe:i}=te(),[c,x]=n.useState("all"),[p,m]=n.useState(!1),[d,f]=n.useState(!1),[u,y]=n.useState({});n.useEffect(()=>i(N=>{if(N.event==="trading.price.update"){const{symbol:j,price:S}=N.payload;y(R=>R[j]===S?R:{...R,[j]:S})}}),[i]);const h=n.useCallback((N,j)=>u[N]??j,[u]),[v,g]=n.useState(!1),b=e.jsxs(e.Fragment,{children:[e.jsx(Vs,{open:p,onClose:()=>m(!1)}),e.jsx(gr,{open:v,onClose:()=>g(!1),onSuccess:()=>m(!0)}),e.jsx(cn,{open:d,onClose:()=>f(!1),walletScope:c})]});if(t==="no-wallet"||t==="idle")return e.jsxs(e.Fragment,{children:[b,e.jsx(Le,{borderColor:"#00A58D",children:e.jsx(Xs,{onConnect:()=>g(!0)})})]});if(t==="loading"&&!r)return e.jsxs(e.Fragment,{children:[b,e.jsx(Le,{children:e.jsxs("div",{className:"px-4 pt-7 pb-6 flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"w-10 h-10 rounded-[4px] bg-[rgba(0,255,136,0.04)] border border-[rgba(0,255,136,0.1)] flex items-center justify-center",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-brand-default)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-60",children:[e.jsx("path",{d:"M21 12V7H5a2 2 0 0 1 0-4h14v4"}),e.jsx("path",{d:"M3 5v14a2 2 0 0 0 2 2h16v-5"}),e.jsx("path",{d:"M18 12a2 2 0 0 0 0 4h4v-4z"})]})}),e.jsxs("div",{className:"flex flex-col items-center gap-[3px]",children:[e.jsx("span",{className:"text-caption text-[var(--color-text-secondary)]",children:"Loading portfolio…"}),e.jsx("span",{className:"text-footnote text-[var(--color-text-secondary)] text-center leading-[1.4]",children:"Fetching balances and positions from Hyperliquid"})]}),e.jsx("div",{className:"mt-0.5",children:e.jsx(xe,{})})]})})]});if(!r){const N=l?`Failed to load portfolio: ${l}`:"Failed to load portfolio";return e.jsxs(e.Fragment,{children:[b,e.jsx(Le,{children:e.jsx("div",{className:"px-2.5 pt-7 pb-2.5 flex items-center gap-2",role:"alert",children:e.jsx("span",{className:"text-caption text-[var(--color-error-text)]",children:N})})})]})}let w=s,C=o,k=r;if(c==="all"&&a)w=a.perWallet.flatMap(N=>(N.positions??[]).map(j=>({...j,walletAddress:N.address}))),C=a.perWallet.flatMap(N=>N.openOrders??[]);else if(c!=="all"&&a){const N=a.perWallet.find(j=>j.address.toLowerCase()===c.toLowerCase());N&&(w=N.positions??[],C=N.openOrders??[],k=N.balance??r)}const E=new Set(w.map(N=>N.symbol)),M=zs(C,E);return e.jsxs(e.Fragment,{children:[b,e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Le,{children:e.jsx(an,{selectedView:c,onSelect:x,onManageWallets:()=>m(!0),onOpenHistory:()=>f(!0),aggregate:a,viewBalance:k,viewPositions:w,livePrices:u})}),e.jsx(fn,{positions:w,viewOrders:C,livePrices:u,getMarketPrice:h}),e.jsx(pn,{orders:M})]})]})}function fn({positions:t,viewOrders:r,livePrices:s,getMarketPrice:o}){return t.length===0?null:e.jsxs("section",{className:"flex flex-col gap-2.5 [font-variant-numeric:tabular-nums]",children:[e.jsx(jr,{label:"POSITIONS",count:t.length}),e.jsx("div",{className:"flex flex-col gap-3 pl-2.5 pb-2.5",children:t.map(a=>{const l=a.walletAddress?`${a.walletAddress}-${a.symbol}`:a.symbol;return e.jsx(nn,{position:a,viewOrders:r,livePrices:s,getMarketPrice:o},l)})})]})}function pn({orders:t}){return t.length===0?null:e.jsxs("section",{className:"flex flex-col gap-3 [font-variant-numeric:tabular-nums]",children:[e.jsx(jr,{label:"ORDER",count:t.length}),e.jsx("div",{className:"flex flex-col gap-3 pl-2.5 pb-2.5",children:t.map((r,s)=>e.jsx("div",{className:s<t.length-1?"pb-3 border-b border-border-subtle":"",children:e.jsx(on,{order:r})},r.orderId))})]})}function jr({label:t,count:r}){return e.jsxs("div",{className:"h-[38px] flex items-center justify-between px-2.5 bg-surface-base border-l border-border-subtle",children:[e.jsx("span",{className:"text-body-md-semibold text-text-secondary",children:t}),e.jsx("span",{className:"text-label-sm text-text-tertiary tracking-[0.24px]",children:r})]})}const Nr=n.createContext(null);function it(){return n.useContext(Nr)}function ct(t){const r=t.indexOf(":");return r===-1?{dex:null,base:t}:{dex:t.slice(0,r),base:t.slice(r+1)}}function hn(){return e.jsxs("svg",{width:"46",height:"33",viewBox:"0 0 46 33",fill:"none","aria-hidden":"true",children:[e.jsxs("g",{clipPath:"url(#empty-coins-clip)",children:[e.jsx("path",{d:"M19.5368 0.40625C32.6208 3.35985 36.7756 20.5949 26.2077 29.3535C16.7223 37.2163 2.27836 31.6287 0.239975 19.3779C0.159369 18.8942 0.172824 18.3439 0.0202484 17.8867C0.0662684 16.9891 -0.0430775 16.0313 0.0202484 15.1416C0.491517 8.48232 5.40862 2.4319 11.6824 0.661133L14.7673 0.0458984H17.448L19.5368 0.40625ZM19.5564 8.51465C17.6038 6.56204 14.4377 6.56203 12.4851 8.51465L8.02513 12.9746C6.07251 14.9272 6.07252 18.0933 8.02513 20.0459L12.4851 24.5059C14.4377 26.4585 17.6038 26.4585 19.5564 24.5059L24.0163 20.0459C25.969 18.0933 25.969 14.9272 24.0163 12.9746L19.5564 8.51465Z",fill:"#6E7480"}),e.jsx("path",{d:"M16.125 18.4349C15.51 18.4349 15 17.9249 15 17.3099V13.3149C15 12.6999 15.51 12.1899 16.125 12.1899C16.74 12.1899 17.25 12.6999 17.25 13.3149V17.3099C17.25 17.9399 16.74 18.4349 16.125 18.4349Z",fill:"#3BF7BF"}),e.jsx("circle",{cx:"16.15",cy:"20.3399",r:"1.15",fill:"#3BF7BF"}),e.jsx("path",{d:"M31.2376 0.0450013C38.6476 0.593641 44.9876 6.88039 45.8762 14.4188C47.2964 26.4653 36.1863 35.86 24.9178 32.1975C25.6 31.6646 26.338 31.2123 27.0145 30.6685C32.9745 25.8802 35.2497 17.6497 32.6502 10.3128C31.2463 6.34944 28.4423 3.01828 24.9187 0.87681C25.4283 0.644769 25.9992 0.503184 26.5452 0.386181C27.0912 0.269177 27.9232 0.0862968 28.4615 0.0440181C29.2417 -0.0179251 30.4556 -0.0139922 31.2386 0.0440181L31.2376 0.0450013Z",fill:"#6E7480"})]}),e.jsx("defs",{children:e.jsx("clipPath",{id:"empty-coins-clip",children:e.jsx("rect",{width:"46",height:"33",fill:"white"})})})]})}function mn({open:t,onClose:r,tokens:s,prices:o,prevDayPrices:a,maxLeverages:l,watchlistSet:i,searchQuery:c,onSearchChange:x,onToggle:p}){const m=n.useRef(null);n.useEffect(()=>{if(!t)return;const f=setTimeout(()=>{var u;return(u=m.current)==null?void 0:u.focus()},50);return()=>clearTimeout(f)},[t]),n.useEffect(()=>{if(!t)return;const f=u=>{u.key==="Escape"&&(u.preventDefault(),r())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[t,r]);const d=n.useMemo(()=>{if(!t)return s;const f=new Set,u=[];for(const y of s)f.has(y)||(f.add(y),u.push(y));return u},[t,c]);return he.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{"aria-hidden":"true","data-drawer-scrim":!0,onClick:r,className:"fixed inset-0 z-[10001] bg-[var(--color-surface-scrim)] transition-opacity duration-base ease-out "+(t?"opacity-100":"opacity-0 pointer-events-none")}),e.jsxs("aside",{role:"dialog","aria-label":"Add to watchlist","aria-modal":"true","data-drawer-panel":!0,className:"fixed top-0 left-0 h-screen w-[424px] z-[10002] bg-[var(--color-surface-base)] flex flex-col shadow-[20px_4px_24px_0px_rgba(0,0,0,0.25)] transition-transform duration-base ease-out "+(t?"translate-x-0":"-translate-x-full pointer-events-none"),children:[e.jsx(bn,{onClose:r}),e.jsx(gn,{inputRef:m,value:c,onChange:x,onEnter:()=>{d.length>0&&p(d[0])}}),e.jsx(vn,{tokens:d,prices:o,prevDayPrices:a,maxLeverages:l,watchlistSet:i,onToggle:p,searchQuery:c})]})]}),document.body)}function bn({onClose:t}){return e.jsxs("div",{className:"flex items-center justify-between px-4 pt-[27px] pb-4 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(kn,{}),e.jsx("span",{className:"text-body-md-semibold text-white",children:"Add watchlist"})]}),e.jsx("button",{type:"button","aria-label":"Close","data-watchlist-edit":!0,onClick:t,className:"w-7 h-7 inline-flex items-center justify-center rounded-[4px] bg-transparent border-none cursor-pointer text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] btn-press transition-colors duration-fast ease-out",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M3 3 L11 11 M11 3 L3 11",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]})}function gn({inputRef:t,value:r,onChange:s,onEnter:o}){return e.jsx("div",{className:"px-[17px] pb-3 shrink-0",children:e.jsxs("div",{className:"flex h-[45px] items-center gap-3 px-4 rounded-[4px] bg-[var(--color-surface-canvas)] border border-[var(--color-border-default)] focus-within:border-[var(--color-brand-default)] transition-colors duration-fast ease-out",children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none","aria-hidden":"true",className:"text-[var(--color-text-muted)] flex-none",children:[e.jsx("circle",{cx:"8",cy:"8",r:"5.5",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M12.5 12.5 L16 16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),e.jsx("input",{ref:t,type:"text",value:r,onChange:a=>s(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),o())},placeholder:"Search token","aria-label":"Search tokens",className:"flex-1 min-w-0 bg-transparent border-none text-body-md text-text-primary placeholder:text-[var(--color-text-muted)] outline-none focus:outline-none focus-visible:outline-none"})]})})}function vn({tokens:t,prices:r,prevDayPrices:s,maxLeverages:o,watchlistSet:a,onToggle:l,searchQuery:i}){return t.length===0?e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto pb-2",children:e.jsxs("div",{className:"flex flex-col items-center gap-[14px] pt-[90px] px-4",children:[e.jsx(hn,{}),e.jsx("p",{className:"m-0 text-body-md text-[var(--color-text-tertiary)] text-center",children:i?e.jsxs(e.Fragment,{children:["No results for “",i.toLowerCase(),"”"]}):"No tokens available"})]})}):e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto pb-2",children:t.map(c=>{const x=a.has(c),p=r[c],m=s[c],d=p!=null&&m!=null&&m>0?(p-m)/m*100:null,f=o[c];return e.jsx(yn,{symbol:c,isFav:x,price:p,change:d,maxLeverage:typeof f=="number"&&f>0?f:null,onToggle:()=>l(c)},c)})})}function yn({symbol:t,isFav:r,price:s,change:o,maxLeverage:a,onToggle:l}){return e.jsxs("button",{type:"button",onClick:l,"aria-pressed":r,"aria-label":r?`Remove ${t} from watchlist`:`Add ${t} to watchlist`,className:"group w-full flex h-[42px] items-center justify-between p-4 bg-transparent border-none text-left cursor-pointer transition-colors duration-fast ease-out hover:bg-white/[0.03] focus-visible:bg-white/[0.04]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(jn,{filled:r}),e.jsx(wn,{symbol:t}),a!=null&&e.jsx(Cn,{value:a})]}),e.jsxs("div",{className:"flex items-center gap-1 [font-variant-numeric:tabular-nums]",children:[e.jsx("span",{className:"text-body-sm text-text-primary",children:s!=null?Sn(s):"--"}),e.jsx(Nn,{pct:o})]})]})}function wn({symbol:t}){const{dex:r,base:s}=ct(t);return e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-body-md text-text-primary",children:s}),r&&e.jsx("span",{className:"inline-flex items-center justify-center h-[18px] px-2 rounded-[2px] bg-[rgba(59,247,191,0.08)] text-brand-default text-caption leading-none","aria-label":`HIP-3 dex ${r}`,title:`HIP-3 dex ${r}`,children:r.toUpperCase()})]})}function Cn({value:t}){return e.jsxs("span",{className:"inline-flex items-center justify-center h-[18px] px-2 rounded-[2px] bg-[rgba(59,247,191,0.08)] text-brand-default text-caption leading-none [font-variant-numeric:tabular-nums]","aria-label":`Max leverage ${t}x`,children:[t,"x"]})}function jn({filled:t}){const r=t?"var(--color-brand-default)":"var(--color-text-muted)";return e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:t?"var(--color-brand-default)":"none","aria-hidden":"true",children:e.jsx("path",{d:"M7 1.5L8.71 5.13L12.5 5.78L9.75 8.5L10.42 12.25L7 10.5L3.58 12.25L4.25 8.5L1.5 5.78L5.29 5.13L7 1.5Z",stroke:r,strokeWidth:"1",strokeLinejoin:"round"})})}function Nn({pct:t}){if(t==null)return e.jsx("span",{className:"text-body-sm text-text-muted",children:"--"});const r=t>=0,s=r?"var(--color-success-default)":"var(--color-error-text)";return e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"8",height:"6",viewBox:"0 0 8 6",fill:"none","aria-hidden":"true",className:r?"":"rotate-180",children:e.jsx("path",{d:"M4 0L8 6H0L4 0Z",fill:s})}),e.jsxs("span",{className:"text-body-sm [font-variant-numeric:tabular-nums]",style:{color:s},children:[Math.abs(t).toFixed(2),"%"]})]})}function kn(){return e.jsxs("svg",{width:"26",height:"31",viewBox:"0 0 26 31",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M24.8806 22.2613C24.4178 19.0825 23.946 15.8943 23.2747 12.7556C21.7517 5.63365 20.642 0.722784 12.0789 1.61512C5.83391 2.26514 5.05875 8.83489 4.03022 13.969C3.52713 16.4795 2.98681 19.3324 2.7042 21.8666C2.62905 22.5363 2.48706 22.9197 2.99373 23.4774C4.26743 24.8788 6.52132 22.3196 7.74681 22.3889C8.61626 22.4388 9.0658 23.1839 9.77514 23.4919C11.951 24.4377 12.4231 22.5982 13.831 22.6275C14.7434 22.647 15.0748 23.3899 15.8523 23.6177C18.0223 24.2533 18.5063 22.3132 20.0337 22.3826C20.5644 22.407 20.9437 22.8392 21.3993 23.0669C22.4715 23.6051 23.8797 24.3989 24.622 23.3766C24.8532 23.0588 24.9354 22.652 24.8781 22.2613H24.8806ZM13.7607 15.6231C10.1454 15.6231 7.21464 12.9213 7.21464 9.58951C7.21464 6.25775 10.1454 3.55598 13.7607 3.55598C17.376 3.55598 20.3067 6.25775 20.3067 9.58951C20.3067 12.9213 17.376 15.6231 13.7607 15.6231Z",fill:"var(--color-brand-default)"}),e.jsx("circle",{cx:"6.5",cy:"27.5",r:"1.5",fill:"var(--color-brand-default)"}),e.jsx("circle",{cx:"13.5",cy:"27.5",r:"1.5",fill:"var(--color-brand-default)"}),e.jsx("circle",{cx:"20.5",cy:"27.5",r:"1.5",fill:"var(--color-brand-default)"})]})}function Sn(t){return t>=1e4?`$${(t/1e3).toFixed(1)}k`:t>=1?`$${t.toFixed(2)}`:`$${t.toFixed(4)}`}function Ln({symbol:t,maxLeverages:r}){const{dex:s,base:o}=ct(t),a=r[t];return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-body-md text-white leading-[14px]",children:o}),a!=null&&e.jsxs("span",{className:"inline-flex items-center h-[14px] px-1 text-footnote leading-none rounded-[2px] bg-[rgba(0,255,136,0.12)] text-[#00ff88]","aria-label":`Max leverage ${a}×`,title:`Max leverage ${a}×`,children:[a,"x"]}),s&&e.jsx("span",{className:"inline-flex items-center h-[14px] px-1 text-footnote leading-none rounded-[2px] bg-[rgba(0,255,136,0.12)] text-[#00ff88]","aria-label":`HIP-3 dex ${s}`,title:`HIP-3 dex ${s}`,children:s.toUpperCase()})]})}const kr=n.createContext({isEditing:!1,setIsEditing:()=>{}});function En({children:t}){const[r,s]=n.useState(!1),o=n.useMemo(()=>({isEditing:r,setIsEditing:s}),[r]);return e.jsx(kr.Provider,{value:o,children:t})}function Sr(){const t=n.useContext(kr);return[t.isEditing,t.setIsEditing]}function It({title:t,subtitle:r}){return e.jsxs("div",{className:"px-4 py-6 flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"w-10 h-10 rounded-[4px] bg-[rgba(0,184,255,0.04)] border border-[rgba(0,184,255,0.1)] flex items-center justify-center",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#00b8ff",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-60",children:e.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}),e.jsxs("div",{className:"flex flex-col items-center gap-[3px]",children:[e.jsx("span",{className:"text-caption text-[var(--color-text-secondary)]",children:t}),e.jsx("span",{className:"text-footnote text-[var(--color-text-secondary)] text-center leading-[1.4]",children:r})]})]})}function Mn(t){const r=t>=1?2:4;return"$"+t.toLocaleString("en-US",{minimumFractionDigits:r,maximumFractionDigits:r})}const He="flex flex-col gap-2";function Ve(){const[t,r]=Sr();return e.jsxs("div",{className:"h-[38px] flex items-center justify-between px-2.5 bg-surface-base border-l border-border-subtle shrink-0",children:[e.jsx("span",{className:"text-body-md-semibold text-text-secondary",children:"WATCHLIST"}),e.jsx("button",{type:"button","data-watchlist-edit":!0,"aria-label":t?"Done editing watchlist":"Add token to watchlist","aria-pressed":t,onClick:s=>{s.stopPropagation(),r(!t)},className:"bg-transparent border-none cursor-pointer transition-colors duration-fast ease-out p-0 inline-flex items-center justify-center "+(t?"text-brand-default":"text-text-tertiary hover:text-text-primary"),children:t?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M2 6L5 9L10 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M6 1.5V10.5M1.5 6H10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]})}function Tn(t){const r=Math.abs(t),s=r>=100||r>=1?2:4,o=r.toLocaleString("en-US",{minimumFractionDigits:s,maximumFractionDigits:s});return(t>=0?"+":"-")+o}function Rn(t){return(t>=0?"+":"")+t.toFixed(2)+"%"}function _n(t){return t==null?"var(--color-text-secondary)":t>=0?"var(--color-success-default)":"var(--color-error-text)"}function An(){const[t,r]=n.useState([]),[s,o]=n.useState({tokens:[],prices:{},prevDayPrices:{},maxLeverages:{}}),[a,l]=Sr(),[i,c]=n.useState(""),{request:x,connected:p,subscribe:m}=te(),d=it(),f=n.useCallback(()=>{p&&x("trading.watchlist.list",{}).then(N=>r(N.items??[])).catch(()=>{})},[p,x]),u=n.useCallback(()=>{p&&x("trading.tokens.list",{}).then(N=>{o(j=>({...N,prices:Object.keys(N.prices).length>0?N.prices:j.prices,prevDayPrices:Object.keys(N.prevDayPrices).length>0?N.prevDayPrices:j.prevDayPrices,maxLeverages:Object.keys(N.maxLeverages).length>0?N.maxLeverages:j.maxLeverages}))}).catch(()=>{})},[p,x]);n.useEffect(()=>{f(),u()},[f,u]),n.useEffect(()=>{if(!p)return;const N=window.setInterval(()=>u(),4e3);return()=>window.clearInterval(N)},[p,u]),n.useEffect(()=>m(N=>{if((N.event==="trading.watchlist.changed"||N.event==="chat.done")&&f(),N.event==="trading.price.update"){const{symbol:j,price:S}=N.payload;o(R=>R.prices[j]===S?R:{...R,prices:{...R.prices,[j]:S}})}}),[m,f]),n.useEffect(()=>{a||c("")},[a]);const y=n.useMemo(()=>t.map(N=>N.symbol),[t]),h=n.useMemo(()=>new Set(y),[y]),{prices:v,prevDayPrices:g,maxLeverages:b,tokens:w}=s,C=Object.keys(v).length>0,k=n.useMemo(()=>{const N=i?w.filter(R=>R.toUpperCase().includes(i.toUpperCase())):w,j=N.filter(R=>h.has(R)),S=N.filter(R=>!h.has(R));return[...j,...S]},[w,i,h]),E=n.useCallback(N=>{const j=h.has(N)?"trading.watchlist.remove":"trading.watchlist.add";x(j,{symbol:N}).then(()=>f()).catch(()=>{})},[h,x,f]);function M(){return e.jsx(mn,{open:a,onClose:()=>l(!1),tokens:k,prices:v,prevDayPrices:g,maxLeverages:b,watchlistSet:h,searchQuery:i,onSearchChange:c,onToggle:E})}return y.length===0&&!C&&p?e.jsxs("div",{className:He,children:[e.jsx(Ve,{}),e.jsx(It,{title:"Loading prices…",subtitle:"Fetching latest market data"}),M()]}):y.length===0?e.jsxs("div",{className:He,children:[e.jsx(Ve,{}),e.jsx(It,{title:"No favorites yet",subtitle:"Click + to add tokens to your watchlist"}),M()]}):e.jsxs("div",{className:He,children:[e.jsx(Ve,{}),e.jsx("div",{className:"flex flex-col pb-2",children:y.map(N=>{const j=v[N],S=g[N],R=j!=null&&S!=null&&S>0,P=R?j-S:null,$=R?(j-S)/S*100:null,L=_n($);return e.jsxs("div",{className:"group flex h-[42px] items-center justify-between gap-2 py-4 px-2.5 cursor-pointer transition-colors duration-fast ease-out hover:bg-white/[0.03]",onClick:()=>d==null?void 0:d.open({symbol:N}),children:[e.jsx("div",{className:"flex items-center gap-1.5 text-body-md text-text-primary min-w-0",children:e.jsx(Ln,{symbol:N,maxLeverages:b})}),e.jsxs("div",{className:"flex items-center gap-3 text-body-sm [font-variant-numeric:tabular-nums]",children:[e.jsx("span",{className:"text-text-primary",children:j!=null?Mn(j):"--"}),e.jsx("span",{style:{color:L},children:P!=null?Tn(P):"--"}),e.jsx("span",{style:{color:L},children:$!=null?Rn($):"--"})]})]},N)})}),M()]})}const Ft="ghost.news.count",Dt="ghost.tweets.count";function Pt(t){try{return Number(localStorage.getItem(t))||0}catch{return 0}}function Bt(t,r){try{localStorage.setItem(t,String(r))}catch{}}const Lr=n.createContext({newsCount:0,tweetsCount:0,setNewsCount:()=>{},setTweetsCount:()=>{}});function Er(){return n.useContext(Lr)}const In=6e4,Me=10,Fn=420,$t=280,Dn="h-[14px] px-[5px] rounded text-footnote leading-none inline-flex items-center bg-[var(--color-brand-subtle)] text-[var(--color-brand-default)] border border-[var(--color-brand-soft)] box-border",Ot="flex items-center gap-2 w-full bg-transparent border-none px-3.5 py-2.5 text-body-sm text-[var(--color-text-primary)] cursor-pointer text-left transition-colors duration-fast ease-out hover:bg-white/[0.05] focus-visible:bg-white/[0.05]",Pn=/^RT @([A-Za-z0-9_]{1,15}): /;function Bn(t){const r=Pn.exec(t);return r?{originalHandle:r[1],content:t.slice(r[0].length)}:null}const Ht=new RegExp("(https?:\\/\\/\\S+)|(\\$[A-Za-z]{1,8}\\b)|((?<![A-Za-z0-9_])@[A-Za-z0-9_]{1,15}\\b)","g");function $n(t){const r=[];let s=0;Ht.lastIndex=0;let o;for(;(o=Ht.exec(t))!==null;)o.index>s&&r.push({kind:"text",value:t.slice(s,o.index)}),o[1]?r.push({kind:"url",value:o[1]}):o[2]?r.push({kind:"cashtag",value:o[2]}):o[3]&&r.push({kind:"mention",value:o[3]}),s=o.index+o[0].length;return s<t.length&&r.push({kind:"text",value:t.slice(s)}),r}function dt(t,r=Date.now()){const s=Math.floor(r/1e3)-t;return s<60?"just now":s<3600?`${Math.floor(s/60)}m ago`:s<86400?`${Math.floor(s/3600)}h ago`:`${Math.floor(s/86400)}d ago`}function On(t){return t>=1e6?(t/1e6).toFixed(1).replace(/\.0$/,"")+"M":t>=1e3?(t/1e3).toFixed(1).replace(/\.0$/,"")+"K":String(t)}const ke={cryptopanic:"CryptoPanic",coindesk:"CoinDesk",theblock:"The Block",decrypt:"Decrypt",cointelegraph:"CoinTelegraph",coingecko:"CoinGecko"},Hn={cryptopanic:"cryptopanic.com",coindesk:"coindesk.com",theblock:"theblock.co",decrypt:"decrypt.co",cointelegraph:"cointelegraph.com",coingecko:"coingecko.com"};function ut(t){const r=Hn[t];return r?`https://www.google.com/s2/favicons?sz=64&domain=${r}`:null}const Vt="flex items-center gap-2 w-full bg-transparent border-none px-3.5 py-2.5 text-body-sm text-[var(--color-text-primary)] cursor-pointer text-left transition-colors duration-fast ease-out hover:bg-white/[0.05] focus-visible:bg-white/[0.05]";function Vn(t){return t.replace(/^\s*(what\s+happened|who\s+is\s+affected|market\s+impact)\s*:\s*/gim,"").replace(/\n{3,}/g,`
|
|
53
|
-
|
|
54
|
-
`).trim()}function Mr({article:t,menuOpen:r,isLast:s,selected:o=!1,inDrawer:a=!1,menuRef:l,onOpen:i,onToggleMenu:c,onDismiss:x,onFilterSource:p,onCloseMenu:m}){const d=ke[t.sourceId]??t.sourceId;return e.jsxs("div",{className:"relative flex flex-col gap-2 py-3 px-4 cursor-pointer transition-colors duration-fast ease-out "+(o?"bg-surface-base ":"hover:bg-white/[0.02] ")+(a?"border-t border-l border-border-subtle":s?"":"border-b border-border-subtle"),onClick:()=>i(t.id),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ne,{url:ut(t.sourceId),seed:t.sourceId,label:d,size:24}),e.jsxs("div",{className:"flex flex-col leading-[1.5] min-w-0",children:[e.jsx("button",{type:"button",className:"bg-transparent border-none p-0 text-left text-number-sm text-text-primary whitespace-nowrap overflow-hidden text-ellipsis cursor-pointer hover:text-brand-default transition-colors duration-fast",title:`Filter by ${d}`,onClick:f=>{f.stopPropagation(),p(t.sourceId)},children:d}),e.jsx("span",{className:"text-footnote text-text-secondary",children:dt(t.publishedAt)})]})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[t.coins.length>0&&e.jsxs("div",{className:"flex items-center gap-1",children:[t.coins.slice(0,3).map(f=>e.jsx("span",{className:"bg-brand-subtle h-[20px] flex items-center justify-center px-[7px] rounded-[3px] text-label-sm text-brand-default whitespace-nowrap",children:f},f)),t.coins.length>3&&e.jsxs("span",{className:"bg-brand-subtle h-[20px] flex items-center justify-center px-[7px] rounded-[3px] text-label-sm text-brand-default opacity-60 whitespace-nowrap",children:["+",t.coins.length-3]})]}),e.jsx("button",{type:"button",className:"bg-transparent border-none cursor-pointer text-text-muted hover:text-text-primary hover:bg-white/[0.05] transition-colors duration-fast inline-flex items-center justify-center w-7 h-7 rounded-[4px] -mr-1",title:"More","aria-label":"Article actions",onClick:f=>{f.stopPropagation(),c(t.id)},children:e.jsx("svg",{width:"3.158",height:"12",viewBox:"0 0 3.1582 12",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M1.5791 8.8418C2.45102 8.84187 3.15812 9.54898 3.1582 10.4209C3.1582 11.2929 2.45107 11.9999 1.5791 12C0.707066 12 0 11.2929 0 10.4209C7.84657e-05 9.54894 0.707114 8.8418 1.5791 8.8418ZM1.5791 4.4209C2.45107 4.42097 3.1582 5.12802 3.1582 6C3.1582 6.87198 2.45107 7.57903 1.5791 7.5791C0.707066 7.5791 0 6.87203 0 6C6.57142e-06 5.12798 0.70707 4.4209 1.5791 4.4209ZM1.5791 0C2.45107 7.60165e-05 3.1582 0.70712 3.1582 1.5791C3.15812 2.45101 2.45102 3.15813 1.5791 3.1582C0.707117 3.1582 8.33614e-05 2.45106 0 1.5791C0 0.707073 0.707066 0 1.5791 0Z"})})})]})]}),r&&e.jsxs("div",{ref:l,className:"absolute right-3 top-10 z-50 bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[6px] shadow-[0_4px_16px_rgba(0,0,0,0.6)] min-w-[170px] py-1",onClick:f=>f.stopPropagation(),children:[e.jsx("button",{className:Vt,onClick:()=>{x(t.id),m()},children:"Dismiss"}),e.jsx("button",{className:Vt,onClick:()=>{window.open(t.url,"_blank","noopener,noreferrer"),m()},children:"Open article ↗"})]}),e.jsx("div",{className:"text-body-sm text-text-primary",children:t.title})]})}const Tr="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2022%2022'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='microscope'%3e%3cg%20id='Vector'%20opacity='0'%3e%3c/g%3e%3cpath%20id='Vector_2'%20d='M13.6033%209.99163L18.7917%206.51747C19.3142%206.16913%2019.4517%205.45413%2019.1033%204.9408L17.435%202.45663C17.0867%201.93413%2016.3717%201.79663%2015.8583%202.14497L10.67%205.61913L13.6033%209.99163Z'%20fill='var(--fill-0,%20%23FF61FF)'/%3e%3cpath%20id='Vector_3'%20d='M13.31%209.55164L11.6967%2010.6333L9.24916%2012.2741L8.92833%2012.485L8.78166%2012.265L6.72833%209.20331L6.58166%208.98331L10.9633%206.04998L13.31%209.55164Z'%20fill='var(--fill-0,%20%23FF61FF)'/%3e%3cpath%20id='Vector_4'%20d='M5.16998%2014.685L8.79081%2012.265L6.73748%209.20337L3.11664%2011.6234C2.69498%2011.9075%202.58498%2012.4759%202.86914%2012.8975L3.90498%2014.4375C4.17998%2014.8592%204.74831%2014.9692%205.16998%2014.685Z'%20fill='var(--fill-0,%20%23FF61FF)'/%3e%3cpath%20id='Vector_5'%20d='M15.18%2019.9925C15.0883%2020.0291%2014.9875%2020.0566%2014.8959%2020.0566C14.63%2020.0566%2014.3825%2019.9008%2014.2634%2019.6441L10.8442%2012.0908L7.37918%2019.6533C7.26002%2019.9008%207.01252%2020.0566%206.74668%2020.0566C6.65502%2020.0566%206.55418%2020.0291%206.46252%2019.9925C6.12335%2019.8275%205.96752%2019.4241%206.12335%2019.0758L9.24918%2012.2741L11.6967%2010.6333L15.5192%2019.085C15.675%2019.4241%2015.5192%2019.8366%2015.18%2019.9925Z'%20fill='var(--fill-0,%20%23FF61FF)'/%3e%3c/g%3e%3c/svg%3e",Rr="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2015%2015'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='filter'%3e%3cpath%20id='Vector'%20d='M12.875%202.5625V3.9375C12.875%204.4375%2012.5625%205.0625%2012.25%205.375L9.5625%207.75C9.1875%208.0625%208.9375%208.6875%208.9375%209.1875V11.875C8.9375%2012.25%208.6875%2012.75%208.375%2012.9375L7.5%2013.5C6.6875%2014%205.5625%2013.4375%205.5625%2012.4375V9.125C5.5625%208.6875%205.3125%208.125%205.0625%207.8125L4.76875%207.50625C4.575%207.3%204.5375%206.9875%204.69375%206.74375L7.89375%201.60625C8.00625%201.425%208.20625%201.3125%208.425%201.3125H11.625C12.3125%201.3125%2012.875%201.875%2012.875%202.5625Z'%20fill='%234A4F58'/%3e%3cpath%20id='Vector_2'%20d='M6.46875%202.26875L4.25%205.825C4.0375%206.16875%203.55%206.21875%203.26875%205.925L2.6875%205.3125C2.375%205%202.125%204.4375%202.125%204.0625V2.625C2.125%201.875%202.6875%201.3125%203.375%201.3125H5.9375C6.425%201.3125%206.725%201.85%206.46875%202.26875Z'%20fill='%234A4F58'/%3e%3cg%20id='Vector_3'%20opacity='0'%3e%3c/g%3e%3c/g%3e%3c/svg%3e";function Wn({open:t,articles:r,selectedId:s,onClose:o,onOpenPanel:a,onDismiss:l,onFilterSource:i,onOpenFilter:c}){const[x,p]=n.useState(null),m=n.useRef(null);return n.useEffect(()=>{if(!t)return;const d=f=>{f.key==="Escape"&&(f.preventDefault(),o())};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[t,o]),n.useEffect(()=>{if(!x)return;const d=f=>{m.current&&!m.current.contains(f.target)&&p(null)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[x]),he.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{"aria-hidden":"true","data-drawer-scrim":!0,onClick:o,className:"fixed inset-0 z-[10001] bg-[var(--color-surface-scrim)] transition-opacity duration-base ease-out "+(t?"opacity-100":"opacity-0 pointer-events-none")}),e.jsxs("aside",{role:"dialog","aria-label":"News articles","aria-modal":"true","data-drawer-panel":!0,className:"fixed top-0 right-0 h-screen w-[408px] z-[10002] bg-[var(--color-surface-raised)] flex flex-col shadow-[-20px_4px_24px_0px_rgba(0,0,0,0.25)] transition-transform duration-base ease-out "+(t?"translate-x-0":"translate-x-full pointer-events-none"),children:[e.jsx(zn,{onOpenFilter:c,onClose:o}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:r.map((d,f)=>e.jsx(Mr,{article:d,menuOpen:x===d.id,isLast:f===r.length-1,selected:d.id===s,inDrawer:!0,menuRef:m,onOpen:a,onToggleMenu:u=>p(y=>y===u?null:u),onDismiss:l,onFilterSource:i,onCloseMenu:()=>p(null)},d.id))})]})]}),document.body)}function zn({onOpenFilter:t,onClose:r}){return e.jsxs("div",{className:"flex h-[58px] items-center justify-between py-1 px-4 shrink-0 bg-surface-raised",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:Tr,alt:"","aria-hidden":"true",width:22,height:22,className:"block"}),e.jsx("span",{className:"text-body-md-semibold text-text-primary leading-[1.5]",children:"NEWS"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button","aria-label":"Manage news sources",title:"Manage news sources",onClick:t,className:"bg-transparent border-none cursor-pointer text-text-tertiary hover:text-text-primary transition-colors duration-fast ease-out p-0 inline-flex items-center justify-center",children:e.jsx("img",{src:Rr,alt:"","aria-hidden":"true",width:15,height:15,className:"block"})}),e.jsx("button",{type:"button","aria-label":"Close (Esc)",title:"Close (Esc)",onClick:r,className:"inline-flex items-center justify-center h-[21px] px-[10px] rounded-[2px] border border-[var(--color-border-strong)] bg-transparent text-[11px] leading-none text-text-secondary cursor-pointer transition-colors duration-fast ease-out hover:text-text-primary hover:border-[var(--color-text-tertiary)]",children:"ESC"})]})]})}const Un="#ff61ff";function Zn({article:t,compact:r,onClose:s}){const{request:o}=te(),[a,l]=n.useState({kind:"loading"});n.useEffect(()=>{const m=d=>{d.key==="Escape"&&(d.preventDefault(),d.stopPropagation(),s())};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[s]),n.useEffect(()=>{let m=!1;return l({kind:"loading"}),o("trading.news.deepSummary",{articleId:t.id}).then(d=>{m||(d.status==="ready"&&d.deepSummary?l({kind:"ready",deepSummary:d.deepSummary}):l({kind:"failed"}))}).catch(()=>{m||l({kind:"failed"})}),()=>{m=!0}},[t.id,o]);const i=ke[t.sourceId]??t.sourceId,c=new Date(t.publishedAt*1e3).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}),x=Vn((t.fullSummary??"").replace(/^\[partial\]/,"")),p=t.snippet.length>200?t.snippet.slice(0,200).trimEnd()+"…":t.snippet;return he.createPortal(e.jsx("aside",{role:"dialog","aria-label":t.title,"aria-modal":"false",className:"fixed top-0 h-screen w-[800px] z-[10003] bg-[var(--color-surface-base)] flex flex-col shadow-[-20px_4px_24px_0px_rgba(0,0,0,0.25)] transition-transform duration-base ease-out translate-x-0 "+(r?"right-0":"right-[408px]"),children:e.jsx("div",{className:"flex-1 overflow-y-auto w-full",children:e.jsxs("div",{className:"py-4 px-6 flex flex-col items-end gap-[19px] w-[725px] mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"inline-flex items-center justify-center rounded-full border bg-[#0f1012] shrink-0 overflow-hidden",style:{width:32,height:32,borderColor:"rgba(122,129,128,0.3)"},children:e.jsx(Ne,{url:ut(t.sourceId),seed:t.sourceId,label:i,size:24})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("span",{className:"text-label-lg text-text-primary leading-[1.5] truncate",children:i}),e.jsx("span",{className:"text-body-sm text-text-secondary leading-[1.5]",children:dt(t.publishedAt)})]})]}),e.jsxs("span",{className:"inline-flex items-center gap-2 py-[2px] rounded-[6px]",children:[e.jsx(Gn,{}),e.jsx("span",{className:"text-body-sm text-text-tertiary leading-[1.5] whitespace-nowrap",children:"Summary by AI"})]})]}),e.jsxs("div",{className:"flex flex-col items-start gap-2 w-full",children:[e.jsx("h1",{className:"text-heading-md text-text-primary leading-[1.5] m-0",children:t.title}),e.jsxs("div",{className:"text-body-md text-text-secondary leading-[1.5]",children:[e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"text-text-secondary underline hover:text-text-primary",children:i})," · Published ",c]}),p&&e.jsx("p",{className:"text-body-lg text-text-primary leading-[1.5] m-0",children:p})]}),t.imageUrl&&e.jsx("img",{src:t.imageUrl,alt:"",loading:"lazy",className:"w-full aspect-[1920/1080] object-cover rounded-[2px]"}),e.jsx(Kn,{state:a,fallbackSummary:x}),e.jsxs("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-1.5 h-9 px-3 rounded-[4px] bg-[var(--color-surface-overlay)] border border-[var(--color-border-strong)] text-body-md-medium text-text-secondary no-underline cursor-pointer transition-colors duration-fast ease-out btn-press hover:text-text-primary hover:border-[var(--color-text-tertiary)]",children:["Read full article",e.jsx(qn,{})]})]})})}),document.body)}function qn(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M5 11L11 5M11 5H6M11 5V10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Gn(){return e.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 17 17",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M8.5 2L9.7 5.8L13.5 7L9.7 8.2L8.5 12L7.3 8.2L3.5 7L7.3 5.8L8.5 2Z",fill:"currentColor",className:"text-text-tertiary"}),e.jsx("path",{d:"M13.5 10L14 11.5L15.5 12L14 12.5L13.5 14L13 12.5L11.5 12L13 11.5L13.5 10Z",fill:"currentColor",className:"text-text-tertiary"})]})}function Kn({state:t,fallbackSummary:r}){if(t.kind==="loading")return e.jsxs("div",{className:"flex items-center gap-2 text-body-sm text-text-secondary leading-[1.5]",children:[e.jsx("span",{children:"Generating summary"}),e.jsx(xe,{color:Un})]});if(t.kind==="failed")return r?e.jsx("p",{className:"text-body-lg text-text-primary leading-[1.5] m-0 whitespace-pre-wrap w-full",children:r}):null;const s=Xn(t.deepSummary);return e.jsx("div",{className:"flex flex-col gap-3 w-full",children:s.map((o,a)=>e.jsx("p",{className:"text-body-lg text-text-primary leading-[1.5] m-0",children:o},a))})}function Xn(t){const r=t.split(/\n{2,}/).map(a=>a.trim()).filter(Boolean);if(r.length>1)return r;const s=t.split(new RegExp("(?<=[.!?])\\s+")).map(a=>a.trim()).filter(Boolean);if(s.length<=3)return[t.trim()];const o=[];for(let a=0;a<s.length;a+=3)o.push(s.slice(a,a+3).join(" "));return o}const Jn=new Set(["cryptopanic","coindesk","theblock","decrypt","cointelegraph","coingecko"]),Yn=2048,Qn=600;function et(t){const r=/^https?:\/\//i.test(t)?t:`https://${t}`;try{return new URL(r).hostname}catch{return t}}function eo(t){const r=et(t);return!r||r===t?null:`https://www.google.com/s2/favicons?sz=64&domain=${r}`}function to({open:t,onClose:r}){const{request:s,connected:o}=te(),[a,l]=n.useState([]),[i,c]=n.useState(""),[x,p]=n.useState("idle"),[m,d]=n.useState([]),[f,u]=n.useState(null),y=n.useRef(0),h=n.useRef(0),v=n.useRef(null),g=n.useRef(!1),b=m[0]??null,w=Math.max(0,m.length-1),C=n.useCallback(()=>{o&&s("trading.news.sources.list").then(L=>l(L.sources??[])).catch(()=>{})},[o,s]);n.useEffect(()=>{t?(C(),c(""),d([]),u(null),p("idle")):(y.current+=1,h.current+=1,v.current&&(clearTimeout(v.current),v.current=null))},[t,C]),n.useEffect(()=>()=>{y.current+=1,h.current+=1,v.current&&clearTimeout(v.current)},[]);const k=n.useCallback(async L=>{const I=L.trim();if(!I){p("idle"),d([]),u(null);return}const W=++y.current;p("discovering"),d([]),u(null);try{const T=await s("trading.news.sources.discover",{site:I});if(W!==y.current)return;if(T.ok===!1){p("error"),u("Couldn't search for feeds. Try again."),d([]);return}const A=Array.isArray(T.candidates)?T.candidates:[];if(A.length===0){p("error"),u("No feed found at this URL."),d([]);return}d(A),p("ready"),u(null)}catch{if(W!==y.current)return;p("error"),u("Couldn't search for feeds. Try again."),d([])}},[s]);n.useEffect(()=>{if(!t)return;if(g.current){g.current=!1;return}v.current&&clearTimeout(v.current);const L=i.trim();if(!L){y.current+=1,p("idle"),d([]),u(null);return}return p("discovering"),d([]),u(null),v.current=setTimeout(()=>{k(L)},Qn),()=>{v.current&&(clearTimeout(v.current),v.current=null)}},[i,t,k]);const E=n.useCallback(L=>{c(L)},[]),M=n.useCallback(()=>{const L=i.trim();L&&(v.current&&(clearTimeout(v.current),v.current=null),g.current=!0,k(L))},[i,k]),N=n.useCallback((L,I)=>{s("trading.news.sources.toggle",{sourceId:L,enabled:I}).then(()=>C()).catch(()=>C())},[s,C]),j=n.useCallback(async()=>{if(!b||x==="adding")return;p("adding"),u(null);const L=++h.current;try{const I=await s("trading.news.sources.addCustom",{url:b.url,name:b.name||et(b.url)});if(L!==h.current)return;if(I.ok){c(""),d([]),p("idle"),u(null),C();return}const W=I.error??"Failed to add feed";p("error"),u(/already|exists|duplicate/i.test(W)?"This source is already in your list.":W)}catch{if(L!==h.current)return;p("error"),u("Couldn't add that source. Try again.")}},[b,x,s,C]),S=n.useCallback(L=>{s("trading.news.sources.remove",{sourceId:L}).then(()=>C()).catch(()=>C())},[s,C]),R=!!b&&(x==="ready"||x==="adding"),P=R?"opacity-0 pointer-events-none":"opacity-100",$=n.useMemo(()=>{var L;return b?((L=b.name)==null?void 0:L.trim())||et(b.url||i):""},[b,i]);return e.jsxs(de,{open:t,onClose:r,title:"News Sources",width:450,hideHeader:!0,cardClassName:"bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[2px]",bodyClassName:"flex flex-col gap-[17px] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("span",{className:"text-body-lg-semibold text-white",children:"News Sources"}),e.jsx("button",{type:"button",onClick:r,"aria-label":"Close",className:"flex items-center justify-center w-7 h-7 rounded-[4px] bg-transparent border-0 cursor-pointer hover:bg-[rgba(255,255,255,0.04)] focus-visible:outline-none focus-visible:bg-[rgba(255,255,255,0.04)]",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M1 1l12 12M13 1L1 13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"text-[var(--color-text-secondary)]"})})})]}),e.jsxs("div",{className:"flex flex-col gap-2 w-full pb-5 border-b border-dashed border-[var(--color-border-subtle)]",children:[e.jsx("label",{htmlFor:"news-add-feed",className:"text-body-sm text-[var(--color-text-secondary)]",children:"Add feed"}),e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{id:"news-add-feed",value:i,onChange:L=>E(L.target.value),onKeyDown:L=>{L.key==="Enter"&&(L.preventDefault(),M())},placeholder:"https://example.com",maxLength:Yn,disabled:x==="adding","aria-label":"RSS feed URL","aria-describedby":f?"news-add-feed-error":void 0,"aria-busy":x==="discovering",className:"w-full h-9 bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] rounded-[4px] px-4 pr-9 text-body-sm text-[var(--color-text-primary)] placeholder:text-[var(--color-text-muted)] outline-none focus:outline-none focus-visible:outline-none disabled:opacity-50"}),x==="discovering"&&e.jsx("span",{"aria-hidden":"true",className:"absolute right-3 top-1/2 -translate-y-1/2 inline-block w-3.5 h-3.5 rounded-full border-2 border-[var(--color-border-subtle)] border-t-[var(--color-text-secondary)] animate-spin"})]}),R&&b&&e.jsxs("div",{className:"flex items-center justify-between w-full pt-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ne,{url:eo(b.url),seed:b.url,label:$,size:28}),e.jsx("span",{className:"text-body-md text-[var(--color-text-primary)] truncate",children:$}),w>0&&e.jsx("span",{className:"text-footnote text-[var(--color-text-secondary)] flex-shrink-0",children:`(+${w} more)`})]}),e.jsx("button",{type:"button",onClick:j,disabled:x==="adding",className:"bg-transparent border-none p-0 text-body-md text-[var(--color-success-default,#3ecf8e)] cursor-pointer disabled:opacity-50",children:x==="adding"?"Adding…":"Add"})]}),f&&e.jsx("div",{id:"news-add-feed-error",className:"text-footnote text-[var(--color-error-default)]",children:f})]}),e.jsx("div",{className:`transition-opacity duration-fast ease-out ${P}`,"aria-hidden":R||void 0,children:a.length===0?e.jsx("div",{className:"text-body-sm text-[var(--color-text-secondary)] text-center py-2",children:"No sources available yet."}):e.jsx("div",{className:"flex flex-col gap-4 w-full",children:a.map(L=>{const I=Jn.has(L.sourceId),W=L.name||(ke[L.sourceId]??L.sourceId),T=!!L.enabled;return e.jsxs("div",{className:"group flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ne,{url:ut(L.sourceId),seed:L.sourceId,label:W,size:28}),e.jsx("span",{className:"text-body-md text-[var(--color-text-primary)] truncate",children:W})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!I&&e.jsx("button",{type:"button",onClick:()=>S(L.sourceId),title:"Remove feed","aria-label":`Remove ${W}`,className:"opacity-0 group-hover:opacity-60 focus-visible:opacity-60 hover:opacity-100 bg-transparent border-none p-0 text-[var(--color-text-secondary)] text-label-lg leading-none cursor-pointer inline-flex items-center justify-center w-5 h-5 transition-opacity duration-fast ease-out",children:"×"}),e.jsx("button",{type:"button",role:"switch","aria-checked":T,"aria-label":T?`Disable ${W}`:`Enable ${W}`,onClick:()=>N(L.sourceId,!T),className:"relative w-[29px] h-4 rounded-[9px] cursor-pointer border-none p-0 transition-colors duration-fast ease-out flex-shrink-0",style:{background:T?"var(--color-brand-default)":"var(--color-neutral-400, #6e7480)"},children:e.jsx("span",{"aria-hidden":"true",className:"absolute top-px w-3.5 h-3.5 rounded-full bg-white transition-[left] duration-fast ease-out",style:{left:T?14:1}})})]})]},L.sourceId)})})})]})}const Te=2e3,ro={news:{title:"News Filter",helper:"Tell the AI how you want your news. It will filter, sort, and summarize accordingly.",placeholder:"Only show macro news that could affect BTC in the next 24h. Skip altcoin pumps and exchange announcements. Summarize in one line from a trader's perspective.",getMethod:"trading.news.filter.get",setMethod:"trading.news.filter.set"},tweets:{title:"Tweets Filter",helper:"Tell the AI how you want your tweets. It will filter, sort, and summarize accordingly.",placeholder:"Only liquidations > $1M, and major exchange or regulator announcements. Skip memecoin shilling.",getMethod:"trading.tweets.filter.get",setMethod:"trading.tweets.filter.set"}};function _r({open:t,onClose:r,kind:s}){const{request:o,connected:a}=te(),l=ro[s],[i,c]=n.useState(""),[x,p]=n.useState(!1),[m,d]=n.useState(null);n.useEffect(()=>{if(!t||!a)return;let y=!1;return d(null),o(l.getMethod).then(h=>{y||c(h.prompt??"")}).catch(()=>{y||c("")}),()=>{y=!0}},[t,a,o,l.getMethod]);const f=n.useCallback(async()=>{if(x)return;const y=i.trim();if(y.length>Te){d(`Prompt exceeds ${Te} characters`);return}p(!0),d(null);try{const h=await o(l.setMethod,{prompt:y});h.ok?r():d(h.error??"Failed to save filter prompt")}catch{d("Failed to save filter prompt")}finally{p(!1)}},[i,x,o,l.setMethod,r]),u=Te-i.length;return e.jsxs(de,{open:t,onClose:r,title:l.title,width:450,hideHeader:!0,cardClassName:"bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[2px]",bodyClassName:"flex flex-col items-end gap-2 pt-4 pb-5 px-4",children:[e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("span",{className:"text-body-md-semibold text-[var(--color-text-primary)] leading-[1.5]",children:l.title}),e.jsx("button",{type:"button",onClick:r,"aria-label":"Close",className:"flex items-center justify-center w-7 h-7 rounded-[6px] bg-transparent border-0 cursor-pointer hover:bg-[rgba(255,255,255,0.04)] focus-visible:outline-none focus-visible:bg-[rgba(255,255,255,0.04)]",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M1 1l12 12M13 1L1 13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"text-[var(--color-text-secondary)]"})})})]}),e.jsxs("div",{className:"flex flex-col items-end gap-5 w-full",children:[e.jsxs("div",{className:"flex flex-col gap-1.5 w-full",children:[e.jsx("p",{className:"text-body-sm text-[var(--color-text-tertiary)] leading-[1.5] m-0",children:l.helper}),e.jsx("textarea",{value:i,onChange:y=>{c(y.target.value),m&&d(null)},placeholder:l.placeholder,"aria-label":l.title,maxLength:Te,disabled:x,className:"w-full h-[127px] bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] rounded-[4px] px-4 py-3 text-body-sm text-[var(--color-text-primary)] placeholder:text-[var(--color-text-muted)] leading-[1.5] outline-none focus:outline-none focus-visible:outline-none resize-none disabled:opacity-50"}),m&&e.jsx("div",{className:"text-footnote text-[var(--color-error-default)] m-0",children:m}),!m&&u<200&&e.jsxs("div",{className:"text-footnote text-[var(--color-text-tertiary)] m-0",children:[u," chars left"]})]}),e.jsx("button",{type:"button",onClick:f,disabled:x,className:"h-9 px-4 rounded-[4px] bg-[var(--color-brand-default)] text-[var(--color-text-on-brand)] text-body-md-semibold leading-[1.5] cursor-pointer border-0 hover:opacity-90 disabled:opacity-50 transition-opacity duration-fast ease-out",children:x?"Saving…":"Save"})]})]})}function so(t){return e.jsx(_r,{...t,kind:"news"})}function no(t){return e.jsx(_r,{...t,kind:"tweets"})}function Ar({trigger:t,triggerLabel:r,items:s,menuLabel:o}){const[a,l]=n.useState(!1),i=n.useRef(null);return n.useEffect(()=>{if(!a)return;const c=x=>{var p;(p=i.current)!=null&&p.contains(x.target)||l(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[a]),e.jsxs("div",{ref:i,className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>l(c=>!c),"aria-label":r,title:r,"aria-haspopup":"menu","aria-expanded":a,className:"bg-transparent border-none cursor-pointer text-text-tertiary hover:text-text-primary transition-colors duration-fast ease-out p-0 inline-flex items-center justify-center",children:t}),e.jsx(lt,{open:a,origin:"top-right",onEscape:()=>l(!1),initialFocus:"first",className:"absolute right-0 top-[calc(100%+6px)] z-50 min-w-[160px] bg-[var(--color-surface-raised)] border border-[var(--color-border-subtle)] drop-shadow-[0_16px_19px_rgba(0,0,0,0.45)] rounded-[4px] px-[14px] py-3 flex flex-col gap-4",role:"menu","aria-label":o,children:s.map(c=>e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),c.onSelect()},className:"flex items-center gap-2 w-full bg-transparent border-none p-0 text-left cursor-pointer text-text-secondary hover:text-text-primary focus-visible:text-text-primary transition-colors duration-fast ease-out btn-press",children:[e.jsx("span",{className:"inline-flex shrink-0 size-4 items-center justify-center",children:c.icon}),e.jsx("span",{className:"text-body-sm text-[var(--color-text-primary)] whitespace-nowrap",children:c.label})]},c.key))})]})}const oo=6e4,Re=10;function ao(t){const{request:r,connected:s}=te(),[o,a]=n.useState([]),[l,i]=n.useState(t),[c,x]=n.useState(!1),[p,m]=n.useState(!0),[d,f]=n.useState(!1),u=n.useRef(!1),y=n.useRef(null),h=n.useRef(null);n.useEffect(()=>{y.current=o[0]??null,h.current=o[o.length-1]??null},[o]);const v=n.useCallback(async()=>{if(!s)return;const C=y.current;try{const k={limit:Re};C&&(k.afterPublishedAt=C.publishedAt,k.afterId=C.id);const E=await r("trading.news.list",k),M=E.articles??[];typeof E.total=="number"&&i(E.total),C?M.length>0&&a(N=>[...M,...N]):(a(M),m(M.length>=Re),u.current=M.length>0),x(!0)}catch{}},[s,r]),g=n.useCallback(async()=>{if(!s||d)return;const C=h.current;if(C){f(!0);try{const k=await r("trading.news.list",{limit:Re,beforePublishedAt:C.publishedAt,beforeId:C.id}),E=k.articles??[];if(typeof k.total=="number"&&i(k.total),E.length===0){m(!1);return}a(M=>[...M,...E]),m(E.length>=Re)}catch{}finally{f(!1)}}},[s,r,d]);n.useEffect(()=>{let C=null,k=!1;const E=()=>{if(k)return;v();const M=u.current?oo:5e3;C=setTimeout(E,M)};return E(),()=>{k=!0,C&&clearTimeout(C)}},[v]);const b=n.useCallback(C=>a(C),[]),w=n.useCallback(C=>i(C),[]);return{articles:o,total:l,hasFetched:c,hasMore:p,loadingMore:d,loadMore:g,setArticlesDirect:b,setTotal:w}}const Ir="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2016%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='document-filter'%3e%3cpath%20id='Vector'%20d='M4.72001%2010.7333C4.48001%2010.7333%204.24002%2010.6733%204.02002%2010.5467C3.57335%2010.2933%203.30668%209.84%203.30668%209.33333V6.95333C3.30668%206.78%203.19334%206.48667%203.05334%206.32001L1.37333%204.55332C1.06%204.24666%200.833333%203.71333%200.833333%203.30666V2.27334C0.833333%201.46667%201.44665%200.82666%202.23332%200.82666H8.16667C8.94%200.82666%209.56665%201.45333%209.56665%202.22666V3.21334C9.56665%203.73334%209.26668%204.30666%208.97335%204.6L7.02002%206.32666C6.86669%206.45333%206.73999%206.76001%206.73999%206.98667V8.92C6.73999%209.38%206.46001%209.89334%206.09334%2010.1133L5.47998%2010.5133C5.23998%2010.66%204.98001%2010.7333%204.72001%2010.7333ZM2.23332%201.83333C2.00665%201.83333%201.83333%202.02668%201.83333%202.28001V3.31333C1.83333%203.42667%201.94668%203.71334%202.09334%203.86001L3.81331%205.66667C4.06665%205.98%204.31331%206.49333%204.31331%206.95333V9.33333C4.31331%209.53333%204.44002%209.63334%204.52002%209.67334C4.62669%209.73334%204.79999%209.76667%204.94666%209.67334L5.56665%209.27334C5.64665%209.22667%205.73999%209.04001%205.73999%208.92668V6.99333C5.73999%206.46666%205.99999%205.88666%206.36666%205.57332L8.28666%203.87333C8.40666%203.75333%208.56665%203.42667%208.56665%203.21334V2.22666C8.56665%202.00666%208.38667%201.82666%208.16667%201.82666H2.23332V1.83333Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_2'%20d='M10%2015.1667H6C2.38%2015.1667%200.833333%2013.62%200.833333%209.99999V7.99999C0.833333%207.72666%201.06%207.49999%201.33333%207.49999C1.60667%207.49999%201.83333%207.72666%201.83333%207.99999V9.99999C1.83333%2013.0733%202.92667%2014.1667%206%2014.1667H10C13.0733%2014.1667%2014.1667%2013.0733%2014.1667%209.99999V5.99999C14.1667%204.06666%2013.7133%202.94665%2012.6933%202.36665C12.5867%202.30665%2012.2333%202.14667%2011.22%201.98667C10.9467%201.94667%2010.76%201.68666%2010.8067%201.41332C10.8533%201.13999%2011.1133%200.953326%2011.38%200.999993C12.2533%201.13999%2012.8467%201.29999%2013.1867%201.49332C14.5334%202.25999%2015.1667%203.69333%2015.1667%205.99999V9.99999C15.1667%2013.62%2013.62%2015.1667%2010%2015.1667Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_3'%20d='M12%209.16667H8.66667C8.39333%209.16667%208.16667%208.94%208.16667%208.66667C8.16667%208.39333%208.39333%208.16667%208.66667%208.16667H12C12.2733%208.16667%2012.5%208.39333%2012.5%208.66667C12.5%208.94%2012.2733%209.16667%2012%209.16667Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_4'%20d='M12%2011.8333H7.33333C7.06%2011.8333%206.83333%2011.6067%206.83333%2011.3333C6.83333%2011.06%207.06%2010.8333%207.33333%2010.8333H12C12.2733%2010.8333%2012.5%2011.06%2012.5%2011.3333C12.5%2011.6067%2012.2733%2011.8333%2012%2011.8333Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cg%20id='Vector_5'%20opacity='0'%3e%3c/g%3e%3c/g%3e%3c/svg%3e",lo="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2016%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='document-code'%3e%3cpath%20id='Vector'%20d='M10.6667%2015.1667H5.33333C2.9%2015.1667%201.5%2013.7667%201.5%2011.3333V4.66667C1.5%202.23333%202.9%200.833333%205.33333%200.833333H10.6667C13.1%200.833333%2014.5%202.23333%2014.5%204.66667V11.3333C14.5%2013.7667%2013.1%2015.1667%2010.6667%2015.1667ZM5.33333%201.83333C3.42667%201.83333%202.5%202.76%202.5%204.66667V11.3333C2.5%2013.24%203.42667%2014.1667%205.33333%2014.1667H10.6667C12.5733%2014.1667%2013.5%2013.24%2013.5%2011.3333V4.66667C13.5%202.76%2012.5733%201.83333%2010.6667%201.83333H5.33333Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_2'%20d='M12.3333%206.16667H11C9.98667%206.16667%209.16667%205.34667%209.16667%204.33333V3C9.16667%202.72667%209.39333%202.5%209.66667%202.5C9.94%202.5%2010.1667%202.72667%2010.1667%203V4.33333C10.1667%204.79333%2010.54%205.16667%2011%205.16667H12.3333C12.6067%205.16667%2012.8333%205.39333%2012.8333%205.66667C12.8333%205.94%2012.6067%206.16667%2012.3333%206.16667Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_3'%20d='M6.66663%2011.8333C6.53996%2011.8333%206.41329%2011.7867%206.31329%2011.6867L4.97996%2010.3533C4.78663%2010.16%204.78663%209.83996%204.97996%209.64663L6.31329%208.31329C6.50663%208.11996%206.82663%208.11996%207.01996%208.31329C7.21329%208.50663%207.21329%208.82667%207.01996%209.02L6.03996%209.99998L7.01996%2010.98C7.21329%2011.1733%207.21329%2011.4933%207.01996%2011.6867C6.91996%2011.7867%206.79329%2011.8333%206.66663%2011.8333Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_4'%20d='M9.33329%2011.8333C9.20663%2011.8333%209.07996%2011.7867%208.97996%2011.6867C8.78663%2011.4933%208.78663%2011.1733%208.97996%2010.98L9.95996%209.99998L8.97996%209.02C8.78663%208.82667%208.78663%208.50663%208.97996%208.31329C9.17329%208.11996%209.49329%208.11996%209.68663%208.31329L11.02%209.64663C11.2133%209.83996%2011.2133%2010.16%2011.02%2010.3533L9.68663%2011.6867C9.58663%2011.7867%209.45996%2011.8333%209.33329%2011.8333Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cg%20id='Vector_5'%20opacity='0'%3e%3c/g%3e%3c/g%3e%3c/svg%3e",We="#ff61ff";function io({onOpenFilter:t,onOpenSources:r,children:s}){return e.jsxs("div",{className:"overflow-clip flex flex-col flex-1 min-h-0 first:pt-8",children:[e.jsxs("div",{className:"flex h-10 items-center justify-between py-1 px-4 shrink-0 bg-surface-raised border-y border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:Tr,alt:"","aria-hidden":"true",width:22,height:22,className:"block"}),e.jsx("span",{className:"text-body-md-semibold text-text-primary leading-[1.5]",children:"NEWS"})]}),e.jsx(Ar,{triggerLabel:"News options",menuLabel:"News options",trigger:e.jsx("img",{src:Rr,alt:"","aria-hidden":"true",width:15,height:15,className:"block"}),items:[{key:"filter",icon:e.jsx("img",{src:Ir,alt:"","aria-hidden":"true",width:16,height:16,className:"block"}),label:"News Filter",onSelect:t},{key:"sources",icon:e.jsx("img",{src:lo,alt:"","aria-hidden":"true",width:16,height:16,className:"block"}),label:"News Sources",onSelect:r}]})]}),s]})}function co(){const{request:t}=te(),{newsCount:r,setNewsCount:s}=Er(),{articles:o,total:a,hasFetched:l,hasMore:i,loadingMore:c,loadMore:x,setArticlesDirect:p,setTotal:m}=ao(r),[d,f]=n.useState(null),[u,y]=n.useState(null),[h,v]=n.useState(null),[g,b]=n.useState(null),[w,C]=n.useState(!1),[k,E]=n.useState(!1),[M,N]=n.useState(()=>typeof window>"u"?!1:window.matchMedia("(max-width: 1207px)").matches),j=n.useRef(null);n.useEffect(()=>{if(typeof window>"u")return;const A=window.matchMedia("(max-width: 1207px)"),B=Z=>N(Z.matches);return A.addEventListener("change",B),()=>A.removeEventListener("change",B)},[]),n.useEffect(()=>{s(a)},[a,s]);const S=n.useCallback(A=>{f(A),y(B=>B===A?B:A)},[]),R=n.useCallback(()=>{y(null),f(null)},[]),P=n.useCallback(A=>{t("trading.news.dismiss",{articleId:A}).catch(()=>{}),p(B=>B.filter(Z=>Z.id!==A)),m(B=>Math.max(0,B-1)),d===A&&f(null),u===A&&y(null)},[t,d,u,p,m]);n.useEffect(()=>{if(!g)return;const A=B=>{j.current&&!j.current.contains(B.target)&&b(null)};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[g]);const $=h?o.filter(A=>A.sourceId===h):o,L=!l&&o.length===0,I=d?o.find(A=>A.id===d)??null:null,W=u?o.find(A=>A.id===u)??null:null,T=e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:We,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2"}),e.jsx("path",{d:"M18 14h-8"}),e.jsx("path",{d:"M15 18h-5"}),e.jsx("path",{d:"M10 6h8v4h-8V6Z"})]});return e.jsxs(e.Fragment,{children:[e.jsx(io,{onOpenFilter:()=>E(!0),onOpenSources:()=>C(!0),children:L?e.jsxs("div",{className:"px-4 py-6 flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"size-[38px] rounded-[4px] bg-[rgba(255,97,255,0.08)] border border-[rgba(255,97,255,0.2)] flex items-center justify-center",children:T}),e.jsxs("div",{className:"flex flex-col items-center gap-1 leading-[1.5]",children:[e.jsx("span",{className:"text-body-md-semibold text-text-primary",children:o.length===0?"Fetching latest news…":"Summarizing with AI…"}),e.jsx("span",{className:"text-body-sm text-text-secondary text-center",children:"AI is scanning and summarizing crypto news for you"})]}),e.jsx(xe,{color:We})]}):e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto pb-2",children:[h&&e.jsx("div",{className:"px-4 pt-2 pb-1 flex gap-1",children:e.jsxs("button",{className:"bg-transparent border border-border-subtle rounded px-2 py-0.5 text-label-sm text-text-secondary cursor-pointer hover:border-border-default",onClick:()=>v(null),children:[ke[h]??h," ×"]})}),$.length===0?e.jsxs("div",{className:"px-4 py-6 flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"size-[38px] rounded-[4px] bg-[rgba(255,97,255,0.08)] border border-[rgba(255,97,255,0.2)] flex items-center justify-center",children:T}),e.jsxs("div",{className:"flex flex-col items-center gap-1 leading-[1.5]",children:[e.jsx("span",{className:"text-body-md-semibold text-text-primary",children:h?`No ${ke[h]??h} news`:"No news available"}),e.jsx("span",{className:"text-body-sm text-text-secondary text-center",children:"New articles will appear here automatically"})]})]}):$.map((A,B)=>e.jsx(Mr,{article:A,menuOpen:g===A.id,isLast:B===$.length-1&&!i,menuRef:j,onOpen:S,onToggleMenu:Z=>b(J=>J===Z?null:Z),onDismiss:P,onFilterSource:v,onCloseMenu:()=>b(null)},A.id)),!L&&i&&$.length>0&&e.jsx("div",{className:"h-11 flex items-center justify-center py-3",children:e.jsx("button",{type:"button",disabled:c,className:"bg-transparent border-none p-0 text-body-sm text-text-secondary inline-flex items-center gap-2 transition-colors duration-fast ease-out "+(c?"text-[#ff61ff] cursor-default":"cursor-pointer hover:text-text-primary focus-visible:text-text-primary"),onClick:x,children:c?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Loading"}),e.jsx(xe,{color:We})]}):"Load more"})})]})}),e.jsx(to,{open:w,onClose:()=>C(!1)}),e.jsx(so,{open:k,onClose:()=>E(!1)}),e.jsx(Wn,{open:I!==null&&!(M&&u!==null),articles:$,selectedId:u,onClose:R,onOpenPanel:S,onDismiss:P,onFilterSource:v,onOpenFilter:()=>C(!0)}),W&&e.jsx(Zn,{article:W,compact:M,onClose:R})]})}function tt({kind:t,text:r,onClose:s}){const o=t==="error",a=o?"var(--color-error-default)":"var(--color-success-default)",l=o?"border-[rgba(239,68,68,0.4)] bg-[var(--color-error-soft)] text-[var(--color-error-text)]":"border-[rgba(34,197,94,0.4)] bg-[var(--color-success-soft)] text-[var(--color-success-text)]";return e.jsxs("div",{className:`flex items-center gap-2 border rounded-[4px] px-3 py-2 text-caption ${l}`,children:[o?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"flex-shrink-0",children:[e.jsx("path",{d:"M6 1.2 11 10.5H1z",stroke:a,strokeWidth:"1.2",strokeLinejoin:"round"}),e.jsx("path",{d:"M6 5v2.2",stroke:a,strokeWidth:"1.2",strokeLinecap:"round"}),e.jsx("circle",{cx:"6",cy:"8.8",r:"0.6",fill:a})]}):e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"flex-shrink-0",children:e.jsx("path",{d:"M2.5 6.2 5 8.6l4.5-5",stroke:a,strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsx("span",{className:"flex-1",children:r}),e.jsx("button",{onClick:s,"aria-label":"Dismiss",className:"bg-transparent border-none p-0 ml-1 text-[color:currentColor] opacity-60 text-label-lg leading-none cursor-pointer hover:opacity-100 focus-visible:opacity-100 transition-opacity duration-fast ease-out",children:"×"})]})}const Wt="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2018%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='h4CksA.tif'%3e%3cpath%20id='Vector'%20d='M5.68244%200L9.65262%205.10376L14.1882%200H16.9412L10.9409%206.77529L18%2016H12.4767L8.10019%2010.4145L3.13031%2015.954L3.05322%2016H0.35292L6.77126%208.74747L0%200H5.68244ZM14.7176%2014.3451L14.2728%2013.7279L4.81747%201.55162H3.21165L13.2175%2014.3447H14.7176V14.3451Z'%20fill='var(--fill-0,%20%2340A6FF)'/%3e%3c/g%3e%3c/svg%3e",uo="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2014%2014'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='Frame'%3e%3cpath%20id='Vector'%20d='M3%203L11%2011M11%203L3%2011'%20stroke='var(--stroke-0,%20%236E7681)'%20stroke-width='1.5'%20stroke-linecap='round'/%3e%3c/g%3e%3c/svg%3e",xo="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2014%2014'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='Content'%3e%3crect%20id='Rectangle%207'%20width='14'%20height='14'%20rx='2'%20fill='var(--fill-0,%20%233BF7BF)'/%3e%3cpath%20id='Vector%20(Stroke)'%20d='M9.26864%204.24155C9.52026%203.95139%209.96228%203.91794%2010.2558%204.16673C10.5492%204.41559%2010.583%204.85275%2010.3314%205.143L6.33189%209.75841C6.19891%209.91186%206.00395%2010%205.7996%2010C5.59539%209.99989%205.40112%209.91176%205.26821%209.75841L3.66859%207.91225C3.41703%207.62199%203.45085%207.18483%203.74424%206.93598C4.03772%206.68719%204.47974%206.72063%204.73136%207.0108L5.7996%208.24308L9.26864%204.24155Z'%20fill='var(--fill-0,%20%230A0A0B)'/%3e%3c/g%3e%3c/svg%3e",fo="w-full bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] rounded-[4px] h-9 px-4 pr-10 text-body-sm text-[var(--color-text-primary)] placeholder:text-[var(--color-text-muted)] outline-none focus:outline-none focus-visible:outline-none",zt={32:"auth_token missing or expired. Re-copy from x.com cookies.",353:"Token or ct0 is invalid. Copy both values from x.com cookies and try again."};function po(t){if(!t)return"Failed";const r=t.replace(/^HTTP\s+\d+(:\s*)?/i,"").trim(),s=r.indexOf("{");if(s>=0)try{const l=JSON.parse(r.slice(s)).errors;if(Array.isArray(l)&&l.length>0){const i=l.map(c=>typeof(c==null?void 0:c.code)=="number"&&zt[c.code]?zt[c.code]:(c==null?void 0:c.message)??"").filter(Boolean);if(i.length>0)return i.join(" · ")}}catch{}return r.replace(/\{.*\}$/s,"").trim()||r||"Failed"}function Ut({num:t,children:r}){return e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("span",{className:"flex items-center justify-center w-[18px] h-[18px] rounded-full bg-[#0d8eff] border border-[rgba(13,142,255,0.2)] text-white text-label-sm leading-none flex-shrink-0",children:t}),e.jsx("span",{className:"text-body-sm text-[var(--color-text-primary)]",children:r})]})}function Zt({id:t,label:r,value:s,placeholder:o,onChange:a,onSubmit:l}){const i=async()=>{try{const c=await navigator.clipboard.readText();c&&a(c.trim())}catch{}};return e.jsxs("div",{className:"flex flex-col gap-1 pl-6 w-full",children:[e.jsx("label",{htmlFor:t,className:"text-body-sm text-[var(--color-text-secondary)]",children:r}),e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{id:t,value:s,onChange:c=>a(c.target.value),onKeyDown:c=>{c.key==="Enter"&&l&&l()},placeholder:o,className:fo}),e.jsx("button",{type:"button",onClick:i,"aria-label":"Paste from clipboard",title:"Paste from clipboard",className:"absolute right-3 top-1/2 -translate-y-1/2 bg-transparent border-0 p-0 cursor-pointer text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] transition-colors duration-fast ease-out inline-flex items-center",children:e.jsxs("svg",{width:"15",height:"16",viewBox:"0 0 15 16",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"3.5",y:"2",width:"8",height:"11",rx:"1",stroke:"currentColor",strokeWidth:"1.2",fill:"none"}),e.jsx("rect",{x:"5",y:"0.6",width:"5",height:"2.4",rx:"0.6",stroke:"currentColor",strokeWidth:"1.2",fill:"currentColor"})]})})]})]})}function qt({label:t,subtitle:r,checked:s,disabled:o,onToggle:a,withBottomBorder:l}){return e.jsxs("button",{type:"button",onClick:a,disabled:o,"aria-pressed":s,className:`flex items-center justify-between w-full py-4 bg-transparent border-0 text-left cursor-pointer disabled:cursor-default ${l?"border-b border-dashed border-[var(--color-border-subtle)]":""}`,children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:`text-body-md ${r?"text-[#c8d1db]":"text-[var(--color-text-primary)]"}`,children:t}),r?e.jsx("span",{className:"text-label-sm text-[var(--color-text-secondary)]",children:r}):null]}),s?e.jsx("img",{src:xo,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx("span",{"aria-hidden":"true",className:"w-3.5 h-3.5 rounded-[2px] border border-[var(--color-text-secondary)] flex-shrink-0"})]})}function Gt({handle:t,action:r,busy:s,error:o,onAdd:a,withBottomBorder:l}){return e.jsxs("div",{className:`flex items-center justify-between w-full py-3 ${l?"border-b border-dashed border-[var(--color-border-subtle)]":""}`,children:[e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("span",{className:"text-body-md text-[var(--color-text-primary)] truncate",children:`@${t}`}),o?e.jsx("span",{className:"text-label-sm text-[var(--color-text-danger,#ef4444)] truncate",children:o}):null]}),r==="tracked"?e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-label":"Already followed",className:"flex-shrink-0",children:e.jsx("path",{d:"M3 8.5l3 3 7-7",stroke:"#3DDC97",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}):e.jsx("button",{type:"button",onClick:a,disabled:s,className:"text-body-sm text-[#3DDC97] bg-transparent border-0 p-0 cursor-pointer disabled:opacity-50 disabled:cursor-default hover:underline focus-visible:underline focus-visible:outline-none",children:s?"Adding…":"Add"})]})}function ho({open:t,onClose:r,onSuccess:s}){const{request:o}=te(),[a,l]=n.useState(""),[i,c]=n.useState(""),[x,p]=n.useState(!1),[m,d]=n.useState(null),[f,u]=n.useState(null),[y,h]=n.useState(!1),[v,g]=n.useState(!1),[b,w]=n.useState([]),[C,k]=n.useState(""),[E,M]=n.useState(null),[N,j]=n.useState(null),[S,R]=n.useState(null),[P,$]=n.useState({}),[L,I]=n.useState(!1),[W,T]=n.useState(!1),[A,B]=n.useState(null),[Z,J]=n.useState(new Set),[O,V]=n.useState(!1),z=n.useCallback(()=>{o("trading.tweets.status").then(_=>{h(_.hasAuth),l(""),c(""),u(_.authUser),w(_.follows??[]),I(!!_.includeFollowing),B(_.followingCount??null)}).catch(()=>{d({ok:!1,text:"Could not verify X session — try Connect again."}),h(!1)})},[o]),K=async()=>{if(W)return;const _=!L;T(!0),I(_);const D=await o("trading.tweets.settings.set",{includeFollowing:_}).catch(()=>({ok:!1}));T(!1),D.ok?z():I(!_)};n.useEffect(()=>{t&&(d(null),k(""),M(null),j(null),$({}),g(!1),V(!1),z())},[t,z]),n.useEffect(()=>{if(!y)return;const _=C.trim().replace(/^@/,"");if(_.length<2){M(null),j(null);return}let D=!1;const q=setTimeout(async()=>{try{const X=await o("trading.tweets.follows.search",{query:_});if(D)return;M(X),j(null)}catch{if(D)return;M({followed:[],notFollow:[]}),j("Search unavailable — try again")}},350);return()=>{D=!0,clearTimeout(q)}},[C,y,o]);const se=async()=>{if(!a.trim()||!i.trim())return;p(!0),d(null);const _=await o("trading.tweets.auth",{auth_token:a.trim(),ct0:i.trim()}).catch(()=>({ok:!1,error:"Connection error"}));if(p(!1),_.ok){const D="user"in _?_.user:void 0;d({ok:!0,text:"Authenticated successfully"}),D&&u(D),h(!0),g(!1),s==null||s(),z()}else{const D="error"in _?_.error:void 0;d({ok:!1,text:po(D??"Failed")})}},G=async(_,D)=>{if(Z.has(_))return;const q=!D;J(ee=>new Set(ee).add(_)),w(ee=>ee.map(le=>le.username===_?{...le,enabled:q}:le));const X=await o("trading.tweets.follows.setEnabled",{username:_,enabled:q}).catch(()=>({ok:!1}));J(ee=>{const le=new Set(ee);return le.delete(_),le}),X.ok||w(ee=>ee.map(le=>le.username===_?{...le,enabled:D}:le))},Q=async _=>{const D=_.replace(/^@/,"");if(!D||S)return;R(D),$(X=>({...X,[D]:""}));const q=await o("trading.tweets.follows.add",{username:D}).catch(()=>({ok:!1,error:"Connection error"}));if(R(null),q.ok)M(X=>X&&{followed:[...X.followed,{username:D,enabled:!0,source:"manual"}],notFollow:X.notFollow.filter(ee=>ee.username.toLowerCase()!==D.toLowerCase())}),z();else{const X=("error"in q?q.error:null)??`@${D} not found`;$(ee=>({...ee,[D]:X}))}},ne=async()=>{await o("trading.tweets.unlink").catch(()=>{}),u(null),h(!1),g(!1),V(!1),l(""),c(""),d(null),k(""),M(null),z()},Y=x||!a.trim()||!i.trim(),re=!y||v,F=re?"Connect your X.com account":"Manage follower";return e.jsxs(de,{open:t,onClose:r,title:F,width:450,hideHeader:!0,cardClassName:"bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[2px]",bodyClassName:re?"flex flex-col gap-4 pt-4 pb-5 px-4":"flex flex-col gap-[13px] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("span",{className:"text-body-lg-semibold text-white",children:F}),e.jsx("button",{type:"button",onClick:r,"aria-label":"Close",className:"flex items-center justify-center w-7 h-7 rounded-[4px] bg-transparent border-0 cursor-pointer hover:bg-[rgba(255,255,255,0.04)] focus-visible:outline-none focus-visible:bg-[rgba(255,255,255,0.04)]",children:e.jsx("img",{src:uo,alt:"",className:"w-[14px] h-[14px]"})})]}),re?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col items-center gap-3 w-full",children:[e.jsx("div",{className:"flex items-center justify-center w-[38px] h-[38px] rounded-[10px] bg-[rgba(13,142,255,0.1)] border border-[rgba(13,142,255,0.2)]",children:e.jsx("img",{src:Wt,alt:"",className:"w-[18px] h-[16px]"})}),e.jsxs("div",{className:"flex flex-col gap-4 w-full",children:[e.jsx(Ut,{num:1,children:"Open x.com and press F12 → Application → Cookies → https://x.com"}),e.jsx(Ut,{num:2,children:"Copy auth_token and ct0 cookie values, then paste them below"})]})]}),e.jsx(Zt,{id:"xauth-auth_token-input",label:"auth_token",value:a,placeholder:"Paste auth_token",onChange:_=>{l(_),d(null)}}),e.jsx(Zt,{id:"xauth-ct0-input",label:"ct0",value:i,placeholder:"Paste ct0",onChange:_=>{c(_),d(null)},onSubmit:se}),e.jsxs("div",{className:"flex justify-end gap-2 w-full",children:[y&&v&&e.jsx("button",{onClick:()=>{g(!1),l(""),c(""),d(null)},className:"bg-transparent border border-[var(--color-border-default)] rounded-[4px] h-9 px-3 text-[var(--color-text-secondary)] text-body-sm cursor-pointer btn-press transition-colors duration-fast ease-out hover:border-muted-foreground hover:text-[var(--color-text-primary)] focus-visible:border-muted-foreground focus-visible:text-[var(--color-text-primary)]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:se,disabled:Y,className:"flex items-center justify-center h-9 px-3 rounded-[4px] bg-[var(--color-brand-default)] text-[var(--color-text-on-brand)] text-body-md-semibold cursor-pointer btn-press transition-opacity duration-fast ease-out hover:opacity-90 disabled:opacity-50 disabled:cursor-default",children:x?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{"data-pulse-dots":!0,className:"inline-flex gap-1",children:[0,1,2].map(_=>e.jsx("span",{className:"w-[3px] h-[3px] rounded-full bg-[color:currentColor]",style:{animation:`pulse 1.4s ease-in-out ${_*.2}s infinite`}},_))}),"Connecting"]}):"Connect"})]}),m&&e.jsx(tt,{kind:m.ok?"success":"error",text:m.text,onClose:()=>d(null)})]}):e.jsxs(e.Fragment,{children:[f&&e.jsxs("div",{className:"flex flex-col w-full",children:[e.jsxs("div",{className:"flex items-center justify-between w-full h-8 px-3 py-[5px] rounded-[3px] bg-[rgba(13,142,255,0.1)] border border-dashed border-[rgba(13,142,255,0.2)]",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("img",{src:Wt,alt:"",className:"w-4 h-3.5 flex-shrink-0"}),e.jsxs("span",{className:"text-body-sm text-[var(--color-text-primary)] truncate",children:["Connected to ",e.jsxs("span",{className:"text-[#40a6ff]",children:["@",f.screenName]})]})]}),O?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>V(!1),className:"text-body-sm text-[var(--color-text-secondary)] bg-transparent border-0 p-0 cursor-pointer hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)] focus-visible:outline-none",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ne,className:"text-body-sm text-[var(--color-text-danger,#ef4444)] bg-transparent border-0 p-0 cursor-pointer hover:underline focus-visible:underline focus-visible:outline-none",children:"Confirm"})]}):e.jsx("button",{type:"button",onClick:()=>V(!0),className:"text-body-sm text-[var(--color-text-secondary)] bg-transparent border-0 p-0 cursor-pointer transition-colors duration-fast ease-out hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)] focus-visible:outline-none",children:"Unlink"})]}),O&&e.jsxs("span",{className:"mt-1 text-label-sm text-[var(--color-text-secondary)]",children:["Unlink @",f.screenName,"? Tweets will stop ingesting from your following list."]})]}),e.jsxs("div",{className:"flex flex-col gap-1 w-full",children:[e.jsx("label",{htmlFor:"xauth-search-input",className:"text-body-sm text-[var(--color-text-secondary)]",children:"Search Accounts"}),e.jsx("input",{id:"xauth-search-input",value:C,onChange:_=>{k(_.target.value)},placeholder:"@account",className:"w-full h-9 bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] rounded-[4px] px-4 text-body-sm text-[var(--color-text-primary)] placeholder:text-[var(--color-text-muted)] outline-none focus:outline-none focus-visible:outline-none"})]}),C.trim()===""?e.jsxs("div",{className:"flex flex-col w-full max-h-[420px] overflow-y-auto pr-2",style:{scrollbarGutter:"stable"},children:[e.jsx(qt,{label:`Include accounts you follow on X.com (${A??"—"} followed)`,subtitle:"Auto-fetch tweets from your X.com following list.",checked:L,disabled:W,onToggle:K,withBottomBorder:b.length>0}),b.map((_,D)=>e.jsx(qt,{label:`@${_.username}`,checked:_.enabled!==!1,disabled:Z.has(_.username),onToggle:()=>G(_.username,_.enabled!==!1),withBottomBorder:D<b.length-1},_.username))]}):e.jsx("div",{className:"flex flex-col w-full max-h-[420px] overflow-y-auto pr-2",style:{scrollbarGutter:"stable"},children:N?e.jsx("span",{className:"text-label-sm text-[var(--color-text-secondary)] py-3",children:N}):E?E.followed.length===0&&E.notFollow.length===0?e.jsx("span",{className:"text-label-sm text-[var(--color-text-secondary)] py-3",children:"No matches in your following list."}):e.jsxs(e.Fragment,{children:[E.followed.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-label-sm text-[var(--color-text-secondary)] pt-3 pb-2",children:"Followed"}),E.followed.map((_,D)=>e.jsx(Gt,{handle:_.username,action:"tracked",withBottomBorder:D<E.followed.length-1},`f-${_.username}`))]}),E.notFollow.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-label-sm text-[var(--color-text-secondary)] pt-3 pb-2",children:"Not Follow"}),E.notFollow.map((_,D)=>e.jsx(Gt,{handle:_.username,action:"add",busy:S===_.username,error:P[_.username]||null,onAdd:()=>Q(_.username),withBottomBorder:D<E.notFollow.length-1},`n-${_.username}`))]})]}):e.jsx("span",{className:"text-label-sm text-[var(--color-text-secondary)] py-3",children:"Searching…"})}),m&&e.jsx(tt,{kind:m.ok?"success":"error",text:m.text,onClose:()=>d(null)})]})]})}const mo="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='18'%20height='18'%20viewBox='0%200%2018%2018'%20fill='none'%3e%3cpath%20d='M15.9751%205.685H11.7901C11.4976%205.685%2011.2651%205.4525%2011.2651%205.16C11.2651%204.8675%2011.4976%204.635%2011.7901%204.635H15.9751C16.2676%204.635%2016.5001%204.8675%2016.5001%205.16C16.5001%205.4525%2016.2676%205.685%2015.9751%205.685Z'%20fill='%236E7480'/%3e%3cpath%20d='M4.815%205.685H2.025C1.7325%205.685%201.5%205.4525%201.5%205.16C1.5%204.8675%201.7325%204.635%202.025%204.635H4.815C5.1075%204.635%205.34%204.8675%205.34%205.16C5.34%205.4525%205.1%205.685%204.815%205.685Z'%20fill='%236E7480'/%3e%3cpath%20d='M7.07813%208C8.45884%208%209.57812%206.88071%209.57812%205.5C9.57812%204.11929%208.45884%203%207.07813%203C5.69741%203%204.57812%204.11929%204.57812%205.5C4.57812%206.88071%205.69741%208%207.07813%208Z'%20fill='%236E7480'/%3e%3cpath%20d='M15.9749%2013.3575H13.1849C12.8924%2013.3575%2012.6599%2013.125%2012.6599%2012.8325C12.6599%2012.54%2012.8924%2012.3075%2013.1849%2012.3075H15.9749C16.2674%2012.3075%2016.4999%2012.54%2016.4999%2012.8325C16.4999%2013.125%2016.2674%2013.3575%2015.9749%2013.3575Z'%20fill='%236E7480'/%3e%3cpath%20d='M6.21%2013.3575H2.025C1.7325%2013.3575%201.5%2013.125%201.5%2012.8325C1.5%2012.54%201.7325%2012.3075%202.025%2012.3075H6.21C6.5025%2012.3075%206.735%2012.54%206.735%2012.8325C6.735%2013.125%206.495%2013.3575%206.21%2013.3575Z'%20fill='%236E7480'/%3e%3cpath%20d='M11.0781%2015C12.4588%2015%2013.5781%2013.8807%2013.5781%2012.5C13.5781%2011.1193%2012.4588%2010%2011.0781%2010C9.69741%2010%208.57812%2011.1193%208.57812%2012.5C8.57812%2013.8807%209.69741%2015%2011.0781%2015Z'%20fill='%236E7480'/%3e%3c/svg%3e",bo="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2016%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='personalcard'%3e%3cpath%20id='Vector'%20d='M11.3333%2014.5H4.66667C1.72667%2014.5%200.833333%2013.6067%200.833333%2010.6667V5.33333C0.833333%202.39333%201.72667%201.5%204.66667%201.5H11.3333C14.2733%201.5%2015.1667%202.39333%2015.1667%205.33333V10.6667C15.1667%2013.6067%2014.2733%2014.5%2011.3333%2014.5ZM4.66667%202.5C2.28%202.5%201.83333%202.95333%201.83333%205.33333V10.6667C1.83333%2013.0467%202.28%2013.5%204.66667%2013.5H11.3333C13.72%2013.5%2014.1667%2013.0467%2014.1667%2010.6667V5.33333C14.1667%202.95333%2013.72%202.5%2011.3333%202.5H4.66667Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_2'%20d='M12.6667%205.83333H9.33333C9.06%205.83333%208.83333%205.60667%208.83333%205.33333C8.83333%205.06%209.06%204.83333%209.33333%204.83333H12.6667C12.94%204.83333%2013.1667%205.06%2013.1667%205.33333C13.1667%205.60667%2012.94%205.83333%2012.6667%205.83333Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_3'%20d='M12.6667%208.5H10C9.72667%208.5%209.5%208.27333%209.5%208C9.5%207.72667%209.72667%207.5%2010%207.5H12.6667C12.94%207.5%2013.1667%207.72667%2013.1667%208C13.1667%208.27333%2012.94%208.5%2012.6667%208.5Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_4'%20d='M12.6667%2011.1667H11.3333C11.06%2011.1667%2010.8333%2010.94%2010.8333%2010.6667C10.8333%2010.3933%2011.06%2010.1667%2011.3333%2010.1667H12.6667C12.94%2010.1667%2013.1667%2010.3933%2013.1667%2010.6667C13.1667%2010.94%2012.94%2011.1667%2012.6667%2011.1667Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_5'%20d='M5.66667%208.02667C4.72667%208.02667%203.96%207.26%203.96%206.32C3.96%205.38%204.72667%204.61333%205.66667%204.61333C6.60667%204.61333%207.37333%205.38%207.37333%206.32C7.37333%207.26%206.60667%208.02667%205.66667%208.02667ZM5.66667%205.61333C5.28%205.61333%204.96%205.93333%204.96%206.32C4.96%206.70667%205.28%207.02667%205.66667%207.02667C6.05333%207.02667%206.37333%206.70667%206.37333%206.32C6.37333%205.93333%206.05333%205.61333%205.66667%205.61333Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_6'%20d='M8%2011.3867C7.74667%2011.3867%207.52667%2011.1933%207.5%2010.9333C7.42667%2010.2133%206.84667%209.63333%206.12%209.56667C5.81333%209.54%205.50667%209.54%205.2%209.56667C4.47333%209.63333%203.89333%2010.2067%203.82%2010.9333C3.79333%2011.2067%203.54667%2011.4133%203.27333%2011.38C3%2011.3533%202.8%2011.1067%202.82667%2010.8333C2.94667%209.63333%203.9%208.68%205.10667%208.57333C5.47333%208.54%205.84667%208.54%206.21333%208.57333C7.41333%208.68667%208.37333%209.64%208.49333%2010.8333C8.52%2011.1067%208.32%2011.3533%208.04667%2011.38C8.03333%2011.3867%208.01333%2011.3867%208%2011.3867Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cg%20id='Vector_7'%20opacity='0'%3e%3c/g%3e%3c/g%3e%3c/svg%3e",go={reply:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"}),retweet:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M17 1l4 4-4 4"}),e.jsx("path",{d:"M3 11V9a4 4 0 0 1 4-4h14"}),e.jsx("path",{d:"M7 23l-4-4 4-4"}),e.jsx("path",{d:"M21 13v2a4 4 0 0 1-4 4H3"})]}),heart:e.jsx("path",{d:"M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"}),views:e.jsxs(e.Fragment,{children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]})};function _e({kind:t,count:r,showZero:s=!1}){const o=s||typeof r=="number"&&r>0;return e.jsxs("span",{className:"inline-flex items-center gap-1 text-caption text-[var(--color-text-secondary)]",children:[e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:go[t]}),o&&e.jsx("span",{children:On(r??0)})]})}function vo({text:t}){const r=$n(t);return e.jsx(e.Fragment,{children:r.map((s,o)=>s.kind==="url"?e.jsx("span",{className:"text-[#00b8ff] underline cursor-pointer",onClick:a=>{a.stopPropagation(),window.open(s.value,"_blank","noopener,noreferrer")},children:s.value},o):s.kind==="cashtag"?e.jsx("span",{className:"text-[var(--color-brand-default)] font-semibold",children:s.value},o):s.kind==="mention"?e.jsx("span",{className:"text-[#1d9bf0]",children:s.value},o):e.jsx("span",{children:s.value},o))})}function yo({label:t}){return e.jsxs("div",{className:"flex items-center gap-1.5 text-caption text-[var(--color-text-secondary)] mb-1",children:[e.jsxs("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M17 1l4 4-4 4"}),e.jsx("path",{d:"M3 11V9a4 4 0 0 1 4-4h14"}),e.jsx("path",{d:"M7 23l-4-4 4-4"}),e.jsx("path",{d:"M21 13v2a4 4 0 0 1-4 4H3"})]}),e.jsxs("span",{children:[t," Retweeted"]})]})}function wo({tweet:t,now:r,isExpanded:s,menuOpen:o,menuRef:a,onToggleExpand:l,onToggleMenu:i,onDismiss:c,onCloseMenu:x}){var h,v,g,b;const p=Bn(t.content),m=p?p.content:t.content,d=m.length>$t,f=d&&!s?m.slice(0,$t).trimEnd()+"…":m,u=t.displayName||t.username,y=p?u||`@${t.username}`:null;return e.jsxs("div",{className:"relative px-4 py-3 border-b border-[rgba(32,36,54,0.6)] transition-colors duration-fast ease-out hover:bg-white/[0.02]",children:[y&&e.jsx(yo,{label:y}),e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(Ne,{url:t.avatarUrl,seed:t.username,label:u,size:28}),e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsx("span",{className:"text-body-sm-medium text-[var(--color-text-primary)] leading-[1.2] whitespace-nowrap overflow-hidden text-ellipsis",title:u,children:u}),e.jsxs("span",{className:"text-caption text-[var(--color-text-secondary)] leading-[1.3] whitespace-nowrap overflow-hidden text-ellipsis",children:["@",t.username," · ",dt(t.publishedAt,r)]})]}),e.jsx("button",{className:"ml-auto bg-transparent border-none text-[var(--color-text-secondary)] text-label-lg cursor-pointer leading-none flex-shrink-0 inline-flex items-center justify-center w-7 h-7 rounded-[4px] -mr-1 transition-colors duration-fast ease-out hover:text-[var(--color-text-primary)] hover:bg-white/[0.05] focus-visible:text-[var(--color-text-primary)]",title:"More",onClick:w=>{w.stopPropagation(),i(t.id)},children:"⋯"})]}),o&&e.jsxs("div",{ref:a,className:"absolute right-2 top-10 z-50 bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[6px] shadow-[0_4px_16px_rgba(0,0,0,0.6)] min-w-[170px] py-1",children:[e.jsx("button",{className:Ot,onClick:()=>{c(t.id),x()},children:"Dismiss"}),t.url&&e.jsx("button",{className:Ot,onClick:()=>{window.open(t.url,"_blank","noopener,noreferrer"),x()},children:"Open on X ↗"})]}),e.jsx("div",{className:"text-body-sm text-[var(--color-text-primary)] whitespace-pre-wrap break-words",children:e.jsx(vo,{text:f})}),d&&e.jsx("button",{className:"bg-transparent border-none p-0 mt-1 text-footnote text-[#00b8ff] cursor-pointer transition-colors duration-fast ease-out hover:text-[var(--color-brand-hover)] focus-visible:text-[var(--color-brand-hover)]",onClick:()=>l(t.id),children:s?"Read less":"Read more"}),t.coins.length>0&&e.jsx("div",{className:"flex gap-1.5 flex-wrap mt-1.5",children:t.coins.slice(0,5).map(w=>e.jsx("span",{className:Dn,children:w},w))}),e.jsxs("div",{className:"flex gap-5 mt-2",children:[e.jsx(_e,{kind:"reply",count:(h=t.stats)==null?void 0:h.replies}),e.jsx(_e,{kind:"retweet",count:(v=t.stats)==null?void 0:v.retweets}),e.jsx(_e,{kind:"heart",count:(g=t.stats)==null?void 0:g.likes}),e.jsx(_e,{kind:"views",count:((b=t.stats)==null?void 0:b.views)??0,showZero:!0}),t.url&&e.jsx("button",{onClick:w=>{w.stopPropagation(),window.open(t.url,"_blank","noopener,noreferrer")},title:"View on X","aria-label":"View on X",className:"ml-auto bg-transparent border-none p-0 text-[var(--color-text-secondary)] cursor-pointer inline-flex items-center transition-colors duration-fast ease-out hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)]",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})})})]})]})}const xt="#40a6ff",Fr=e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:xt,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})});function ft({children:t}){return e.jsx("div",{className:"size-[38px] rounded-[4px] bg-[rgba(13,142,255,0.1)] border border-[rgba(13,142,255,0.2)] flex items-center justify-center shrink-0",children:t})}function Co(){return e.jsx("div",{className:"px-4 py-6 flex flex-col items-center gap-2",children:e.jsx(ft,{children:e.jsx(xe,{color:xt})})})}function ze({title:t,subtitle:r,cta:s}){return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-[18px] px-[18px] pt-6 pb-8",children:[e.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[e.jsx(ft,{children:Fr}),e.jsxs("div",{className:"flex flex-col items-center gap-1 leading-[1.5]",children:[e.jsx("span",{className:"text-body-md-semibold text-text-primary",children:t}),r&&e.jsx("span",{className:"text-body-sm text-text-secondary text-center",children:r})]})]}),s&&e.jsx("button",{type:"button",onClick:s.onClick,className:"btn-press min-w-[96px] h-8 px-3 flex items-center justify-center border border-[#40a6ff] rounded-[4px] bg-transparent text-[#40a6ff] text-body-md-semibold whitespace-nowrap cursor-pointer transition-colors duration-fast ease-out hover:bg-[rgba(64,166,255,0.08)]",children:s.label})]})}function jo({running:t}){const r=t?"Fetching X timeline…":"Fetching tweets…",s=t?"This can take up to a minute on first connect.":null;return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 px-4 pb-8 pt-2",children:[e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(ft,{children:Fr}),e.jsxs("div",{className:"flex flex-col items-center gap-1 leading-[1.5]",children:[e.jsx("span",{className:"text-body-md-semibold text-text-primary",children:r}),s&&e.jsx("span",{className:"text-body-sm text-text-secondary text-center",children:s})]})]}),e.jsx(xe,{color:xt})]})}const No="#40a6ff";function ko(){return e.jsx("svg",{width:"18",height:"16",viewBox:"0 0 24 24",fill:No,"aria-hidden":"true",className:"shrink-0",children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})})}function So({children:t,authUser:r,onOpenFilter:s,onOpenFollows:o}){const a=!!(s&&o);return e.jsxs("div",{className:"overflow-hidden flex flex-col first:pt-8",children:[e.jsxs("div",{className:"bg-surface-base h-10 flex items-center gap-2 px-4 py-1 shrink-0 border-y border-border-subtle",children:[e.jsx(ko,{}),e.jsx("span",{className:"text-body-md-semibold text-text-primary",children:"TWEETS"}),e.jsxs("div",{className:"ml-auto flex items-center gap-3",children:[r&&e.jsxs("span",{className:"text-footnote text-[#40a6ff] whitespace-nowrap",children:["@",r.screenName,r.name?` (${r.name})`:""]}),a&&e.jsx(Ar,{triggerLabel:"Tweets options",menuLabel:"Tweets options",trigger:e.jsx("img",{src:mo,alt:"","aria-hidden":"true",className:"w-[18px] h-[18px] opacity-70 hover:opacity-100"}),items:[{key:"filter",icon:e.jsx("img",{src:Ir,alt:"","aria-hidden":"true",width:16,height:16,className:"block"}),label:"Tweets Filter",onSelect:s},{key:"follows",icon:e.jsx("img",{src:bo,alt:"","aria-hidden":"true",width:16,height:16,className:"block"}),label:"Manage Follower",onSelect:o}]})]})]}),t]})}function Lo(){const{request:t,subscribe:r,connected:s}=te(),[o,a]=n.useState([]),[l,i]=n.useState(null),[c,x]=n.useState(null),[p,m]=n.useState([]),[d,f]=n.useState(!1),[u,y]=n.useState(!0),[h,v]=n.useState(!1),[g,b]=n.useState(!1),[w,C]=n.useState(!1),[k,E]=n.useState(null),[M,N]=n.useState(!1),[j,S]=n.useState("idle"),[R,P]=n.useState(new Set),$=n.useCallback(F=>{P(_=>{const D=new Set(_);return D.has(F)?D.delete(F):D.add(F),D})},[]),L=n.useRef(null),[I,W]=n.useState(()=>Date.now());n.useEffect(()=>{const F=setInterval(()=>W(Date.now()),3e4);return()=>clearInterval(F)},[]);const T=n.useRef(null),A=n.useRef(null);n.useEffect(()=>{T.current=o[0]??null,A.current=o[o.length-1]??null},[o]);const{tweetsCount:B,setTweetsCount:Z}=Er(),[J,O]=n.useState(B);n.useEffect(()=>{Z(J)},[J,Z]);const V=n.useCallback(()=>{s&&t("trading.tweets.status").then(F=>{i(F.hasAuth),x(F.authUser??null),m(F.follows??[]),N(!!F.includeFollowing),S(F.fetchState??"idle")}).catch(()=>{})},[s,t]),z=n.useRef(!1),K=n.useCallback(async()=>{if(!s)return;const F=T.current;try{const _={limit:Me};F&&(_.afterPublishedAt=F.publishedAt,_.afterId=F.id);const D=await t("trading.tweets.list",_),q=D.tweets??[];typeof D.total=="number"&&O(D.total),F?q.length>0&&a(X=>[...q,...X]):(a(q),y(q.length>=Me),z.current=q.length>0),f(!0)}catch{}},[s,t]);n.useEffect(()=>{if(l!==!0||p.length===0&&!M)return;let F=null,_=!1;const D=()=>{if(_)return;K();const q=z.current?In:5e3;F=setTimeout(D,q)};return D(),()=>{_=!0,F&&clearTimeout(F)}},[l,p.length,M,K]),n.useEffect(()=>{V()},[V]),n.useEffect(()=>r(F=>{F.event==="trading.tweets.inserted"&&(K(),V())}),[r,K,V]),n.useEffect(()=>{if(j!=="running")return;const F=setInterval(V,5e3);return()=>clearInterval(F)},[j,V]);const se=n.useCallback(async()=>{if(!s||h)return;const F=A.current;if(F){v(!0);try{const _=await t("trading.tweets.list",{limit:Me,beforePublishedAt:F.publishedAt,beforeId:F.id}),D=_.tweets??[];if(typeof _.total=="number"&&O(_.total),D.length===0){y(!1);return}a(q=>[...q,...D]),y(D.length>=Me)}catch{}finally{v(!1)}}},[s,t,h]),G=n.useCallback(F=>{t("trading.tweets.dismiss",{id:F}).catch(()=>{}),a(_=>_.filter(D=>D.id!==F)),O(_=>Math.max(0,_-1))},[t]);n.useEffect(()=>{const F=()=>b(!0);return window.addEventListener("ghost:tweets-manage",F),window.addEventListener("ghost:tweets-open-settings",F),()=>{window.removeEventListener("ghost:tweets-manage",F),window.removeEventListener("ghost:tweets-open-settings",F)}},[]),n.useEffect(()=>{if(!k)return;const F=_=>{L.current&&!L.current.contains(_.target)&&E(null)};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[k]);const Q=n.useCallback(F=>{E(_=>_===F?null:F)},[]),ne=n.useCallback(()=>E(null),[]);let Y;l===null?Y=e.jsx(Co,{}):l?p.length===0&&!M?Y=e.jsx(ze,{title:"No accounts followed",subtitle:'Add an X account or enable "Include accounts you follow on X.com".',cta:{label:"Manage follows",onClick:()=>b(!0)}}):!d||o.length===0&&j==="running"?Y=e.jsx(jo,{running:j==="running"}):o.length===0?Y=e.jsx(ze,{title:"No tweets yet",subtitle:"New tweets from your followed accounts will appear here."}):Y=e.jsxs("div",{className:"overflow-y-auto",style:{maxHeight:Fn},children:[o.map(F=>e.jsx(wo,{tweet:F,now:I,isExpanded:R.has(F.id),menuOpen:k===F.id,menuRef:L,onToggleExpand:$,onToggleMenu:Q,onDismiss:G,onCloseMenu:ne},F.id)),u&&e.jsx("div",{className:"h-11 flex items-center justify-center py-3",children:e.jsx("button",{type:"button",disabled:h,className:"bg-transparent border-none p-0 text-body-sm text-text-secondary inline-flex items-center gap-2 transition-colors duration-fast ease-out "+(h?"text-[#00b8ff] cursor-default":"cursor-pointer hover:text-text-primary focus-visible:text-text-primary"),onClick:se,children:h?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Loading"}),e.jsx(xe,{color:"#00b8ff"})]}):"Load more"})})]}):Y=e.jsx(ze,{title:"Connect X to see tweets",subtitle:"Tweets from accounts you follow on X.",cta:{label:"Connect X",onClick:()=>b(!0)}});const re=l===!0;return e.jsxs(e.Fragment,{children:[e.jsx(So,{authUser:re?c:null,onOpenFilter:re?()=>C(!0):void 0,onOpenFollows:re?()=>b(!0):void 0,children:Y}),e.jsx(ho,{open:g,onClose:()=>{b(!1),V()},onSuccess:()=>{V()}}),e.jsx(no,{open:w,onClose:()=>C(!1)})]})}function Eo({widget:t}){const r=t.emptyIcon;return t.component?e.jsx(t.component,{}):e.jsx($s,{icon:r?e.jsx(r,{}):void 0,text:t.emptyText??""})}const pt="ghost.widgets.v5",rt="ghost-widget-visibility-change";function ht(){try{const t=localStorage.getItem(pt);if(!t)return null;const r=JSON.parse(t),s=Array.isArray(r.order)?r.order.filter(a=>typeof a=="string"):[],o=Array.isArray(r.hidden)?new Set(r.hidden.filter(a=>typeof a=="string")):new Set;return{order:s,hidden:o}}catch{return null}}function Mo(t,r){try{localStorage.setItem(pt,JSON.stringify({order:t,hidden:[...r]}))}catch{}try{window.dispatchEvent(new CustomEvent(rt))}catch{}}function To(t,r,s){const o=ht(),a=o!=null&&o.order.length?o.order:[...s],l=(o==null?void 0:o.hidden)??new Set;r?l.add(t):l.delete(t),Mo(a,l)}function Dr(t){const r=()=>t(),s=o=>{o.key===pt&&t()};return window.addEventListener(rt,r),window.addEventListener("storage",s),()=>{window.removeEventListener(rt,r),window.removeEventListener("storage",s)}}const Ro=new Set(["portfolio","watchlist"]),_o=new Set(["tweets","news"]),Pr=[{id:"portfolio",icon:"◈",iconColor:"var(--color-brand-default)",label:"Portfolio",component:xn},{id:"watchlist",icon:"◉",iconColor:"#00b8ff",label:"Watchlist",component:An},{id:"tweets",icon:"𝕏",iconColor:"#00b8ff",label:"Tweets",component:Lo},{id:"news",icon:"✦",iconColor:"#a136ff",label:"News",component:co}],pe=Pr.map(t=>t.id);function Kt(){const t=new Set(pe),r=ht();if(!r)return{order:[...pe],hidden:new Set};const o=[...r.order.filter(l=>t.has(l))];for(const l of pe){if(o.includes(l))continue;const i=pe.indexOf(l);let c=o.length;for(let x=i+1;x<pe.length;x++){const p=o.indexOf(pe[x]);if(p>=0){c=p;break}}o.splice(c,0,l)}const a=new Set;for(const l of r.hidden)t.has(l)&&a.add(l);return{order:o,hidden:a}}const Ao=new Set;function Xt({position:t="left"}){const{status:r}=me(),s=r!=="no-wallet"&&r!=="idle",[o,a]=n.useState(Kt);n.useEffect(()=>Dr(()=>a(Kt())),[]);const l=t==="left"?Ro:_o,i=Pr.filter(d=>l.has(d.id)&&(!Ao.has(d.id)||s)),x=o.order.filter(d=>!o.hidden.has(d)&&l.has(d)).map(d=>i.find(f=>f.id===d)).filter(Boolean),p="w-[320px] min-w-[320px] min-h-0 bg-[var(--color-surface-canvas)] flex flex-col",m=`flex-1 overflow-y-auto ${t==="right"?"":"px-4 pb-3 space-y-3"} -mt-8`;return e.jsx(En,{children:e.jsx("aside",{className:p,children:e.jsxs("div",{className:m,children:[x.length===0&&e.jsxs("div",{className:"bg-[var(--color-surface-base)] border border-white/10 rounded-[4px] px-4 py-6 flex flex-col items-center gap-2 text-center",children:[e.jsx("div",{className:"text-[24px] text-[var(--color-text-secondary)]",children:"☰"}),e.jsx("div",{className:"text-body-sm-medium text-[var(--color-text-secondary)]",children:"No widgets visible"})]}),x.map(d=>e.jsx(Eo,{widget:d},d.id))]})})})}const Io=String.raw`<(\w+)(\s[^>]*)?>([\s\S]*?)</\1>`;function Fo(t){if(!t)return{};const r={},s=/(\w+)="([^"]*)"/g;let o;for(;(o=s.exec(t))!==null;)r[o[1]]=o[2];return r}function Do(t,r,s,o){const a=Br(s);switch(t){case"pct":return e.jsx("span",{className:r.dir==="up"?"trade-pct-up":"trade-pct-down",children:a},o);case"price":case"lvl":return e.jsx("span",{className:"trade-price",children:a},o);case"pnl":return e.jsx("span",{className:r.dir==="up"?"trade-pnl-up":"trade-pnl-down",children:a},o);case"lev":return e.jsx("span",{className:"trade-leverage",children:a},o);case"side":return e.jsx("span",{className:r.dir==="long"?"trade-long":"trade-short",children:a},o);case"tag":return e.jsx("span",{className:`trade-tag trade-tag-${r.type??"entry"}`,children:a},o);case"risk":return e.jsx("span",{className:`trade-risk trade-risk-${r.level??"medium"}`,children:a},o);case"verdict":return e.jsx("span",{className:`trade-verdict trade-verdict-${r.type??"neutral"}`,children:a},o);case"ind":return e.jsx("span",{children:a},o);default:return null}}function Br(t){if(!t)return[];const r=[];let s=0,o=0;const a=new RegExp(Io,"g");let l;for(;(l=a.exec(t))!==null;){const[i,c,x,p]=l,m=l.index;m>s&&r.push(t.slice(s,m));const d=Do(c,Fo(x),p,o++);d===null?r.push(i):r.push(d),s=m+i.length}return s<t.length&&r.push(t.slice(s)),r}const Po={info:"var(--color-info-text)",risk:"var(--color-warning-text)",warning:"var(--color-warning-text)",success:"var(--color-success-text)"};function Bo({open:t,onClose:r,notifications:s,onDismiss:o}){return n.useEffect(()=>{if(!t)return;const a=l=>{l.key==="Escape"&&(l.preventDefault(),r())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[t,r]),he.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{"aria-hidden":"true","data-drawer-scrim":!0,onClick:r,className:"fixed inset-0 z-[10001] bg-[var(--color-surface-scrim)] transition-opacity duration-base ease-out "+(t?"opacity-100":"opacity-0 pointer-events-none")}),e.jsxs("aside",{role:"dialog","aria-label":"Notifications","aria-modal":"true","data-drawer-panel":!0,className:"fixed top-0 right-0 h-screen w-[408px] z-[10002] bg-[var(--color-surface-canvas)] backdrop-blur-[12px] flex flex-col shadow-[-20px_4px_24px_0px_rgba(0,0,0,0.25)] transition-transform duration-base ease-out "+(t?"translate-x-0":"translate-x-full pointer-events-none"),children:[e.jsx($o,{onClose:r}),e.jsx(Oo,{notifications:s,onDismiss:o})]})]}),document.body)}function $o({onClose:t}){return e.jsxs("div",{className:"flex items-center justify-between px-4 pt-4 pb-4 shrink-0",children:[e.jsx("span",{className:"text-body-lg-semibold text-white",children:"Notification"}),e.jsx("button",{type:"button","aria-label":"Close",onClick:t,className:"w-7 h-7 inline-flex items-center justify-center rounded-[4px] bg-transparent border-none cursor-pointer text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] btn-press transition-colors duration-fast ease-out",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M3 3 L11 11 M11 3 L3 11",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]})}function Oo({notifications:t,onDismiss:r}){return t.length===0?e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto pb-2",children:e.jsxs("div",{className:"flex flex-col items-center gap-[14px] pt-[90px] px-4",children:[e.jsx(Ho,{}),e.jsx("p",{className:"m-0 text-body-md text-[var(--color-text-tertiary)] text-center",children:"No notifications"})]})}):e.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:e.jsx("div",{className:"flex flex-col gap-2",children:t.map(s=>e.jsx(Vo,{item:s,onDismiss:r},s.id))})})}function Ho(){return e.jsxs("svg",{width:"27",height:"31",viewBox:"0 0 27 31",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M26.221 23.0376C25.6759 19.509 25.1195 15.9696 24.3286 12.4843C22.5345 4.57716 21.2265 -0.874473 11.1363 0.116119C3.77873 0.837778 2.86553 8.1314 1.65308 13.8331C1.0602 16.6197 0.423766 19.7861 0.0907987 22.5997C0.00228842 23.343 -0.164896 23.7687 0.432196 24.3877C1.93266 25.9431 4.58796 23.1025 6.03222 23.1795C7.05641 23.2349 7.58607 24.062 8.422 24.4039C10.986 25.4539 11.5423 23.4119 13.2015 23.4444C14.2763 23.466 14.6669 24.2904 15.5829 24.5431C18.1399 25.2485 18.7103 23.0943 20.51 23.1714C21.1352 23.1984 21.5819 23.6782 22.1186 23.9309C23.3816 24.5282 25.0408 25.4093 25.9161 24.2741C26.1887 23.9214 26.2856 23.47 26.2182 23.0362L26.221 23.0376ZM13.1215 15.6683C8.86315 15.6683 5.41125 12.6695 5.41125 8.97063C5.41125 5.27179 8.86315 2.27299 13.1215 2.27299C17.3798 2.27299 20.8317 5.27179 20.8317 8.97063C20.8317 12.6695 17.3798 15.6683 13.1215 15.6683Z",fill:"#6E7480"}),e.jsx("path",{d:"M13.2444 10.245C12.6294 10.245 12.1194 9.735 12.1194 9.12V5.125C12.1194 4.51 12.6294 4 13.2444 4C13.8594 4 14.3694 4.51 14.3694 5.125V9.12C14.3694 9.75 13.8594 10.245 13.2444 10.245Z",fill:"#3BF7BF"}),e.jsx("circle",{cx:"13.2694",cy:"12.15",r:"1.15",fill:"#3BF7BF"}),e.jsx("path",{d:"M4.31824 30.8098C5.34023 30.8098 6.16872 30.014 6.16872 29.0324C6.16872 28.0507 5.34023 27.2549 4.31824 27.2549C3.29626 27.2549 2.46777 28.0507 2.46777 29.0324C2.46777 30.014 3.29626 30.8098 4.31824 30.8098Z",fill:"#6E7480"}),e.jsx("path",{d:"M12.9535 30.8098C13.9755 30.8098 14.804 30.014 14.804 29.0324C14.804 28.0507 13.9755 27.2549 12.9535 27.2549C11.9315 27.2549 11.103 28.0507 11.103 29.0324C11.103 30.014 11.9315 30.8098 12.9535 30.8098Z",fill:"#6E7480"}),e.jsx("path",{d:"M21.5892 30.8098C22.6112 30.8098 23.4397 30.014 23.4397 29.0324C23.4397 28.0507 22.6112 27.2549 21.5892 27.2549C20.5673 27.2549 19.7388 28.0507 19.7388 29.0324C19.7388 30.014 20.5673 30.8098 21.5892 30.8098Z",fill:"#6E7480"})]})}function Vo({item:t,onDismiss:r}){return e.jsxs("div",{className:"group relative bg-[var(--color-surface-base)] border border-[var(--color-border-subtle)] rounded-[2px] px-4 py-3 drop-shadow-[20px_4px_12px_rgba(0,0,0,0.25)]",children:[e.jsxs("div",{className:"flex flex-col gap-1 w-full pr-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-body-md-semibold whitespace-nowrap",style:{color:Po[t.severity]},children:t.label}),e.jsx("span",{"aria-hidden":"true",className:"inline-block w-[2px] h-[2px] rounded-full bg-[var(--color-text-secondary)]"}),e.jsx("span",{className:"text-body-sm text-[var(--color-text-secondary)]",children:t.time})]}),e.jsx("p",{className:"text-body-sm text-white",children:Br(t.message)})]}),r&&e.jsx("button",{type:"button","aria-label":"Dismiss notification",onClick:()=>r(t.id),className:"absolute top-2 right-2 w-6 h-6 inline-flex items-center justify-center rounded-[4px] bg-transparent border-none cursor-pointer text-[var(--color-text-tertiary)] hover:text-[var(--color-text-primary)] btn-press transition-colors duration-fast ease-out",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M2 2 L8 8 M8 2 L2 8",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]})}const Wo="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2019%2019'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='notification-bing'%3e%3cpath%20id='Vector'%20d='M9.5%208.32833C9.17542%208.32833%208.90625%208.05917%208.90625%207.73458V5.09833C8.90625%204.77375%209.17542%204.50458%209.5%204.50458C9.82458%204.50458%2010.0938%204.77375%2010.0938%205.09833V7.73458C10.0938%208.06708%209.82458%208.32833%209.5%208.32833Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_2'%20d='M9.51583%2016.1104C7.47333%2016.1104%205.43875%2015.7858%203.49917%2015.1367C2.77875%2014.8992%202.2325%2014.3846%201.995%2013.7354C1.7575%2013.0863%201.83667%2012.3421%202.22458%2011.6929L3.23%2010.0146C3.45167%209.6425%203.64958%208.94583%203.64958%208.51042V6.84792C3.64958%203.61%206.27792%200.981667%209.51583%200.981667C12.7538%200.981667%2015.3821%203.61%2015.3821%206.84792V8.51042C15.3821%208.93792%2015.58%209.6425%2015.8017%2010.0146L16.8071%2011.6929C17.1792%2012.3104%2017.2425%2013.0467%2016.9971%2013.7196C16.7517%2014.3925%2016.2133%2014.9071%2015.5325%2015.1367C13.5929%2015.7938%2011.5583%2016.1104%209.51583%2016.1104ZM9.51583%202.17708C6.935%202.17708%204.83708%204.275%204.83708%206.85583V8.51833C4.83708%209.15958%204.58375%2010.0858%204.25125%2010.6321L3.24583%2012.3183C3.04%2012.6588%202.9925%2013.0229%203.11125%2013.3396C3.23%2013.6563%203.49917%2013.8937%203.87917%2014.0204C7.52083%2015.2317%2011.5267%2015.2317%2015.1683%2014.0204C15.5087%2013.9096%2015.77%2013.6563%2015.8887%2013.3238C16.0154%2012.9913%2015.9758%2012.6271%2015.7938%2012.3183L14.7883%2010.64C14.4558%2010.0938%2014.2025%209.1675%2014.2025%208.52625V6.86375C14.1946%204.275%2012.0967%202.17708%209.51583%202.17708Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_3'%20d='M9.5%2018.1292C8.65292%2018.1292%207.82167%2017.7808%207.22%2017.1792C6.61833%2016.5775%206.27%2015.7462%206.27%2014.8992H7.4575C7.4575%2015.4375%207.67917%2015.96%208.05917%2016.34C8.43917%2016.72%208.96167%2016.9417%209.5%2016.9417C10.6242%2016.9417%2011.5425%2016.0233%2011.5425%2014.8992H12.73C12.73%2016.6804%2011.2813%2018.1292%209.5%2018.1292Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cg%20id='Vector_4'%20opacity='0'%3e%3c/g%3e%3c/g%3e%3c/svg%3e";function zo(t){if(!Number.isFinite(t))return"";const r=Date.now()-t,s=Math.floor(r/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const o=Math.floor(s/60);if(o<24)return`${o}h ago`;const a=Math.floor(o/24);return a<7?`${a}d ago`:new Date(t).toLocaleDateString()}function Uo(){const{notifications:t,unreadNotificationIds:r,markNotificationsRead:s,dismissNotification:o}=me(),[a,l]=n.useState(!1),i=r.size,c=n.useMemo(()=>t.slice(0,50).map(p=>({id:p.id,severity:"info",label:"Price move",time:zo(new Date(p.ts).getTime()),message:p.body})),[t]);function x(){l(!0),i>0&&s()}return e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"relative inline-flex items-center justify-center w-8 h-8 rounded-full bg-[var(--color-surface-base)] border border-[var(--color-border-subtle)] cursor-pointer transition-colors duration-fast ease-out hover:border-[var(--color-border-default)]",onClick:x,"aria-label":"Notifications",title:"Notifications",children:[e.jsx("img",{src:Wo,alt:"",className:"w-[19px] h-[19px]"}),i>0&&e.jsx("span",{className:"absolute -top-0.5 -right-1 bg-destructive text-white text-footnote rounded-full min-w-[14px] h-[14px] px-[3px] flex items-center justify-center",children:i>99?"99+":i})]}),e.jsx(Bo,{open:a,onClose:()=>l(!1),notifications:c,onDismiss:o})]})}const Zo="data:image/svg+xml,%3csvg%20viewBox='0%200%2020%2020'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='mouse-circle'%3e%3cpath%20d='M13.6423%2018.9751C13.6339%2018.9751%2013.6339%2018.9751%2013.6256%2018.9751C12.7839%2018.9668%2012.0839%2018.4501%2011.8339%2017.6418L10.2922%2012.6834C10.0839%2012.0001%2010.2589%2011.2668%2010.7672%2010.7751C11.2672%2010.2834%2011.9923%2010.1001%2012.6589%2010.3084L17.6256%2011.8501C18.4256%2012.1001%2018.9506%2012.8001%2018.9589%2013.6418C18.9672%2014.4751%2018.4589%2015.1835%2017.6589%2015.4501L16.3006%2015.9084C16.1089%2015.9751%2015.9589%2016.1168%2015.9006%2016.3085L15.4339%2017.6751C15.1756%2018.4668%2014.4756%2018.9751%2013.6423%2018.9751ZM12.0923%2011.4751C11.8673%2011.4751%2011.7173%2011.6001%2011.6506%2011.6584C11.4756%2011.8334%2011.4173%2012.0751%2011.4923%2012.3168L13.0339%2017.2751C13.1672%2017.7001%2013.5339%2017.7168%2013.6506%2017.7251C13.7672%2017.7251%2014.1256%2017.6918%2014.2589%2017.2834L14.7256%2015.9168C14.9089%2015.3585%2015.3589%2014.9168%2015.9172%2014.7251L17.2756%2014.2668C17.6923%2014.1334%2017.7173%2013.7668%2017.7173%2013.6585C17.7173%2013.5501%2017.6839%2013.1835%2017.2673%2013.0501L12.3006%2011.5084C12.2173%2011.4834%2012.1506%2011.4751%2012.0923%2011.4751Z'%20fill='%233BF7BF'/%3e%3cpath%20d='M9.99959%2018.9582C5.05793%2018.9582%201.04126%2014.9416%201.04126%209.9999C1.04126%205.05823%205.05793%201.04156%209.99959%201.04156C14.9413%201.04156%2018.9579%205.05823%2018.9579%209.9999C18.9579%2010.3416%2018.6746%2010.6249%2018.3329%2010.6249C17.9913%2010.6249%2017.7079%2010.3416%2017.7079%209.9999C17.7079%205.7499%2014.2496%202.29156%209.99959%202.29156C5.74959%202.29156%202.29126%205.7499%202.29126%209.9999C2.29126%2014.2499%205.74959%2017.7082%209.99959%2017.7082C10.3413%2017.7082%2010.6246%2017.9916%2010.6246%2018.3332C10.6246%2018.6749%2010.3413%2018.9582%209.99959%2018.9582Z'%20fill='%233BF7BF'/%3e%3c/g%3e%3c/svg%3e",qo=[{name:"Tailscale Funnel",blurb:"Public HTTPS via Tailscale, no port forwarding, free for personal use.",cmd:"tailscale funnel 15401",docs:"https://tailscale.com/kb/1223/funnel"},{name:"Tailscale Serve (private)",blurb:"HTTPS within your tailnet only — devices you control, not the public internet.",cmd:"tailscale serve 15401",docs:"https://tailscale.com/kb/1242/tailscale-serve"},{name:"Cloudflare Tunnel",blurb:"Public HTTPS via Cloudflare, requires the cloudflared CLI.",cmd:"cloudflared tunnel --url http://localhost:15401",docs:"https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/"},{name:"ngrok",blurb:"Quick public HTTPS for testing. Free tier rotates URLs on restart.",cmd:"ngrok http 15401",docs:"https://ngrok.com/docs/getting-started/"}],Go=1200;function Ko(){return e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function Xo(){return e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}function Jo(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M5 11L11 5"}),e.jsx("path",{d:"M6 5h5v5"})]})}function Yo(){return e.jsx("img",{src:Zo,alt:"","aria-hidden":"true",className:"size-[20px] block"})}function Qo({open:t,onClose:r}){const[s,o]=n.useState(null),a=n.useCallback(l=>{navigator.clipboard.writeText(l).then(()=>{o(l),setTimeout(()=>o(i=>i===l?null:i),Go)}).catch(()=>{})},[]);return e.jsxs(de,{open:t,onClose:r,title:"Expose to Internet",width:720,hideHeader:!0,cardClassName:"bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[2px] shadow-[0_8px_32px_rgba(0,0,0,0.5)]",bodyClassName:"flex flex-col p-0",children:[e.jsx("div",{className:"flex items-center pl-6 pr-4 py-4 w-full",children:e.jsxs("div",{className:"flex-1 min-w-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-body-lg-semibold text-white",children:"Expose to Internet"}),e.jsx("button",{type:"button",onClick:r,"aria-label":"Close",className:"flex items-center justify-center w-7 h-7 rounded-[4px] bg-transparent border-0 cursor-pointer hover:bg-[rgba(255,255,255,0.04)] focus-visible:outline-none focus-visible:bg-[rgba(255,255,255,0.04)]",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M1 1l12 12M13 1L1 13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"text-[var(--color-text-secondary)]"})})})]})}),e.jsxs("div",{className:"flex flex-col items-center gap-5 px-6 pb-6 w-full",children:[e.jsx("div",{className:"size-[38px] rounded-[10px] flex items-center justify-center",style:{background:"rgba(59,247,191,0.08)",border:"1px solid rgba(59,247,191,0.08)"},children:e.jsx(Yo,{})}),e.jsx("p",{className:"text-body-md text-[var(--color-text-secondary)] leading-[1.5] m-0 w-full",children:"Ghost runs locally on port 15401 (replace with your configured port if different). To reach it from other devices, use one of these tunnels."}),e.jsx("div",{className:"flex flex-col gap-6 w-full",children:qo.map(l=>{const i=s===l.cmd;return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-body-md-medium text-[var(--color-text-primary)]",children:l.name}),e.jsxs("a",{href:l.docs,target:"_blank",rel:"noreferrer noopener",className:"btn-press inline-flex items-center gap-0.5 text-body-sm-medium text-[var(--color-brand-default)] no-underline hover:opacity-80 transition-opacity duration-fast ease-out",children:["Docs",e.jsx(Jo,{})]})]}),e.jsx("p",{className:"text-body-sm text-[var(--color-text-tertiary)] m-0",children:l.blurb})]}),e.jsxs("div",{className:"h-10 flex items-center justify-between gap-3 px-4 py-3.5 bg-[var(--color-surface-raised,var(--color-surface-canvas))] rounded-[2px]",style:{border:"1px dashed var(--color-border-strong)"},children:[e.jsx("pre",{className:"flex-1 m-0 text-body-md font-mono text-[var(--color-text-primary)] overflow-x-auto whitespace-nowrap",children:l.cmd}),e.jsx("button",{type:"button",onClick:()=>a(l.cmd),title:i?"Copied":"Copy command","aria-label":i?"Copied":`Copy ${l.name} command`,className:"btn-press bg-transparent border-none p-1 rounded inline-flex items-center cursor-pointer transition-colors duration-fast ease-out "+(i?"text-[var(--color-brand-default)]":"text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)]"),children:i?e.jsx(Xo,{}):e.jsx(Ko,{})})]})]},l.name)})})]})]})}const ea="data:image/svg+xml,%3csvg%20viewBox='0%200%2021.0777%2021.0776'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M18.3222%200.022104C19.936%20-0.188951%2021.2665%201.1408%2021.0556%202.75453C20.7471%205.11346%2019.8992%209.12093%2017.5039%2011.7037C16.7419%2012.5253%2015.8205%2013.2832%2014.874%2013.9577L15.1513%2015.8961C15.2292%2016.4413%2015.0456%2016.992%2014.6562%2017.3815L11.4746%2020.5631C10.455%2021.5827%208.70926%2021.0009%208.50486%2019.5739L8.08006%2016.6032L8.08494%2016.6022C7.81322%2016.471%207.56024%2016.2952%207.3408%2016.0758L5.00095%2013.736C4.78149%2013.5163%204.60574%2013.2628%204.47459%2012.9909L4.47361%2012.9977L1.50388%2012.5729C0.0764895%2012.3688%20-0.505016%2010.6228%200.514626%209.60316L3.69627%206.42054C4.08565%206.03136%204.63562%205.84867%205.18064%205.9264L7.11814%206.20277C7.79269%205.25617%208.55234%204.33495%209.374%203.57289C11.9567%201.17785%2015.9633%200.330658%2018.3222%200.022104ZM6.17088%2018.0885C6.46377%2017.7958%206.93857%2017.7957%207.23142%2018.0885C7.52427%2018.3814%207.52418%2018.8562%207.23142%2019.1491L5.81736%2020.5631C5.52445%2020.8558%205.04965%2020.856%204.75681%2020.5631C4.46401%2020.2703%204.46411%2019.7955%204.75681%2019.5026L6.17088%2018.0885ZM4.04978%2015.9664C4.3426%2015.6739%204.81751%2015.6739%205.11033%2015.9664C5.40318%2016.2593%205.40309%2016.7351%205.11033%2017.028L2.2822%2019.8561C1.98937%2020.1489%201.51456%2020.1488%201.22166%2019.8561C0.928772%2019.5632%200.928789%2019.0884%201.22166%2018.7955L4.04978%2015.9664ZM1.92869%2013.8453C2.22158%2013.5528%202.69643%2013.5526%202.98924%2013.8453C3.28203%2014.1381%203.28184%2014.613%202.98924%2014.9059L1.57517%2016.32C1.28228%2016.6128%200.807519%2016.6128%200.514626%2016.32C0.221803%2016.0271%200.221756%2015.5523%200.514626%2015.2594L1.92869%2013.8453ZM15.1865%205.89027C14.4056%205.10944%2013.1394%205.10965%2012.3584%205.89027C11.5773%206.67132%2011.5773%207.93832%2012.3584%208.71937C13.1394%209.49999%2014.4056%209.5002%2015.1865%208.71937C15.9675%207.93832%2015.9675%206.67132%2015.1865%205.89027Z'%20fill='%235DFAC9'/%3e%3c/svg%3e",Jt="ghost update",ta=1200;function ra({open:t,onClose:r}){const[s,o]=n.useState(!1),a=n.useCallback(()=>{navigator.clipboard.writeText(Jt).then(()=>{o(!0),setTimeout(()=>o(!1),ta)}).catch(()=>{})},[]);return e.jsxs(de,{open:t,onClose:r,title:"New version available!",width:450,hideHeader:!0,cardClassName:"bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[2px] shadow-[0_8px_32px_rgba(0,0,0,0.5)]",bodyClassName:"flex flex-col items-end gap-[15px] px-4 pt-4 pb-5",children:[e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("span",{className:"text-body-md-semibold text-text-primary",children:"New version available!"}),e.jsx("button",{type:"button","aria-label":"Close",onClick:r,className:"w-7 h-7 inline-flex items-center justify-center rounded-[6px] bg-transparent border-none cursor-pointer text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] btn-press transition-colors duration-fast ease-out",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M3 3 L11 11 M11 3 L3 11",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 w-full",children:[e.jsx("div",{className:"size-[38px] rounded-[10px] flex items-center justify-center",style:{background:"rgba(59,247,191,0.08)",border:"1px solid rgba(59,247,191,0.08)"},children:e.jsx(sa,{})}),e.jsxs("div",{className:"flex flex-col items-center gap-4 w-full",children:[e.jsx("p",{className:"text-body-sm text-[var(--color-text-tertiary)] m-0 w-full",children:"A new update is ready, bringing improvements and exciting new features. Updating takes just two simple steps:"}),e.jsx(Yt,{n:1,children:"Open your Terminal."}),e.jsxs("div",{className:"flex flex-col gap-2 w-full",children:[e.jsx(Yt,{n:2,children:"Run the following command:"}),e.jsx("div",{className:"pl-6 w-full",children:e.jsxs("div",{className:"flex items-center justify-between h-9 px-4 bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] rounded-[4px]",children:[e.jsx("code",{className:"text-body-sm text-[#5dfac9] font-mono",children:Jt}),e.jsx("button",{type:"button",onClick:a,title:s?"Copied":"Copy command","aria-label":s?"Copied":"Copy update command",className:"btn-press bg-transparent border-none p-0 inline-flex items-center cursor-pointer transition-colors duration-fast ease-out "+(s?"text-[var(--color-brand-default)]":"text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)]"),children:s?e.jsx(oa,{}):e.jsx(na,{})})]})})]}),e.jsx("p",{className:"text-body-sm text-[var(--color-text-tertiary)] m-0 w-full",children:"That's it! The update will run automatically — just make sure you're connected to the internet."})]})]})]})}function Yt({n:t,children:r}){return e.jsxs("div",{className:"flex items-center gap-1.5 w-full",children:[e.jsx("span",{className:"bg-[#2a2c31] inline-flex items-center justify-center rounded-full w-[18px] h-[18px] flex-none text-label-sm text-white",children:t}),e.jsx("span",{className:"text-body-sm text-text-primary",children:r})]})}function sa(){return e.jsx("img",{src:ea,alt:"","aria-hidden":"true",className:"size-[24px] block"})}function na(){return e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function oa(){return e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}const aa="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2018%2018'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='setting-2'%3e%3cpath%20id='Vector'%20d='M9%2011.8125C7.4475%2011.8125%206.1875%2010.5525%206.1875%209C6.1875%207.4475%207.4475%206.1875%209%206.1875C10.5525%206.1875%2011.8125%207.4475%2011.8125%209C11.8125%2010.5525%2010.5525%2011.8125%209%2011.8125ZM9%207.3125C8.07%207.3125%207.3125%208.07%207.3125%209C7.3125%209.93%208.07%2010.6875%209%2010.6875C9.93%2010.6875%2010.6875%209.93%2010.6875%209C10.6875%208.07%209.93%207.3125%209%207.3125Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cpath%20id='Vector_2'%20d='M11.4075%2016.6425C11.25%2016.6425%2011.0925%2016.62%2010.935%2016.5825C10.47%2016.455%2010.08%2016.1625%209.8325%2015.75L9.7425%2015.6C9.3%2014.835%208.6925%2014.835%208.25%2015.6L8.1675%2015.7425C7.92%2016.1625%207.53%2016.4625%207.065%2016.5825C6.5925%2016.71%206.105%2016.6425%205.6925%2016.395L4.4025%2015.6525C3.945%2015.39%203.615%2014.9625%203.4725%2014.445C3.3375%2013.9275%203.405%2013.395%203.6675%2012.9375C3.885%2012.555%203.945%2012.21%203.8175%2011.9925C3.69%2011.775%203.3675%2011.6475%202.925%2011.6475C1.83%2011.6475%200.9375%2010.755%200.9375%209.66V8.34C0.9375%207.245%201.83%206.3525%202.925%206.3525C3.3675%206.3525%203.69%206.225%203.8175%206.0075C3.945%205.79%203.8925%205.445%203.6675%205.0625C3.405%204.605%203.3375%204.065%203.4725%203.555C3.6075%203.0375%203.9375%202.61%204.4025%202.3475L5.7%201.605C6.5475%201.1025%207.665%201.395%208.175%202.2575L8.265%202.4075C8.7075%203.1725%209.315%203.1725%209.7575%202.4075L9.84%202.265C10.35%201.395%2011.4675%201.1025%2012.3225%201.6125L13.6125%202.355C14.07%202.6175%2014.4%203.045%2014.5425%203.5625C14.6775%204.08%2014.61%204.6125%2014.3475%205.07C14.13%205.4525%2014.07%205.7975%2014.1975%206.015C14.325%206.2325%2014.6475%206.36%2015.09%206.36C16.185%206.36%2017.0775%207.2525%2017.0775%208.3475V9.6675C17.0775%2010.7625%2016.185%2011.655%2015.09%2011.655C14.6475%2011.655%2014.325%2011.7825%2014.1975%2012C14.07%2012.2175%2014.1225%2012.5625%2014.3475%2012.945C14.61%2013.4025%2014.685%2013.9425%2014.5425%2014.4525C14.4075%2014.97%2014.0775%2015.3975%2013.6125%2015.66L12.315%2016.4025C12.03%2016.56%2011.7225%2016.6425%2011.4075%2016.6425ZM9%2013.8675C9.6675%2013.8675%2010.29%2014.2875%2010.7175%2015.03L10.8%2015.1725C10.89%2015.33%2011.04%2015.4425%2011.22%2015.4875C11.4%2015.5325%2011.58%2015.51%2011.73%2015.42L13.0275%2014.67C13.2225%2014.5575%2013.3725%2014.37%2013.4325%2014.145C13.4925%2013.92%2013.4625%2013.6875%2013.35%2013.4925C12.9225%2012.7575%2012.87%2012%2013.2%2011.4225C13.53%2010.845%2014.2125%2010.515%2015.0675%2010.515C15.5475%2010.515%2015.93%2010.1325%2015.93%209.6525V8.3325C15.93%207.86%2015.5475%207.47%2015.0675%207.47C14.2125%207.47%2013.53%207.14%2013.2%206.5625C12.87%205.985%2012.9225%205.2275%2013.35%204.4925C13.4625%204.2975%2013.4925%204.065%2013.4325%203.84C13.3725%203.615%2013.23%203.435%2013.035%203.315L11.7375%202.5725C11.415%202.3775%2010.9875%202.49%2010.7925%202.82L10.71%202.9625C10.2825%203.705%209.66%204.125%208.9925%204.125C8.325%204.125%207.7025%203.705%207.275%202.9625L7.1925%202.8125C7.005%202.4975%206.585%202.385%206.2625%202.5725L4.965%203.3225C4.77%203.435%204.62%203.6225%204.56%203.8475C4.5%204.0725%204.53%204.305%204.6425%204.5C5.07%205.235%205.1225%205.9925%204.7925%206.57C4.4625%207.1475%203.78%207.4775%202.925%207.4775C2.445%207.4775%202.0625%207.86%202.0625%208.34V9.66C2.0625%2010.1325%202.445%2010.5225%202.925%2010.5225C3.78%2010.5225%204.4625%2010.8525%204.7925%2011.43C5.1225%2012.0075%205.07%2012.765%204.6425%2013.5C4.53%2013.695%204.5%2013.9275%204.56%2014.1525C4.62%2014.3775%204.7625%2014.5575%204.9575%2014.6775L6.255%2015.42C6.4125%2015.5175%206.6%2015.54%206.7725%2015.495C6.9525%2015.45%207.1025%2015.33%207.2%2015.1725L7.2825%2015.03C7.71%2014.295%208.3325%2013.8675%209%2013.8675Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3cg%20id='Vector_3'%20opacity='0'%3e%3c/g%3e%3c/g%3e%3c/svg%3e",la="inline-flex items-center justify-center w-8 h-8 rounded-full bg-[var(--color-surface-base)] border border-[var(--color-border-subtle)] text-[var(--color-text-secondary)] cursor-pointer transition-colors duration-fast ease-out hover:border-[var(--color-border-default)] hover:text-[var(--color-text-primary)]";function Qt(){var t;return!(((t=ht())==null?void 0:t.hidden.has("tweets"))??!1)}function ia(){const{connected:t,request:r}=te(),[s,o]=n.useState({current:null,updateAvailable:null});return n.useEffect(()=>{if(!t)return;let a=!1;return r("status").then(l=>{a||o({current:typeof l.version=="string"&&l.version!=="unknown"?l.version:null,updateAvailable:!!l.updateAvailable})}).catch(()=>{a||o({current:null,updateAvailable:!1})}),()=>{a=!0}},[t,r]),s}function ca(){const[t,r]=n.useState(!1),[s,o]=n.useState(!1),[a,l]=n.useState(!1),[i,c]=n.useState(Qt),x=n.useRef(null),{current:p,updateAvailable:m}=ia();n.useEffect(()=>Dr(()=>c(Qt())),[]),n.useEffect(()=>{if(!t)return;const f=u=>{var y;(y=x.current)!=null&&y.contains(u.target)||r(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[t]);const d=n.useCallback(()=>{To("tweets",i,pe)},[i]);return e.jsxs("div",{ref:x,className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>r(f=>!f),"aria-label":"System menu","aria-expanded":t,className:la,children:e.jsx("img",{src:aa,alt:"",className:"w-[18px] h-[18px]"})}),e.jsxs(lt,{open:t,origin:"top-right",onEscape:()=>r(!1),initialFocus:"first",className:"absolute right-0 top-[calc(100%+8px)] z-50 min-w-[260px] bg-[var(--color-surface-raised)] border border-[var(--color-border-subtle)] drop-shadow-[0_16px_19px_rgba(0,0,0,0.45)] rounded-[4px] px-[14px] py-3 flex flex-col gap-3",role:"menu","aria-label":"System menu",children:[e.jsxs("div",{className:"flex flex-col gap-4 pb-4 border-b border-[var(--color-border-subtle)] w-full",children:[e.jsx(er,{icon:e.jsx(ua,{}),label:"Show X",onClick:d,trailing:e.jsx(da,{on:i})}),e.jsx(er,{icon:e.jsx(pa,{}),label:"Expose to internet",onClick:()=>{r(!1),o(!0)}})]}),e.jsx(xa,{label:p?`Version ${p}`:"Version",updateAvailable:!!m,onUpdateClick:()=>{r(!1),l(!0)}})]}),e.jsx(Qo,{open:s,onClose:()=>o(!1)}),e.jsx(ra,{open:a,onClose:()=>l(!1)})]})}function er({icon:t,label:r,trailing:s,onClick:o,disabled:a=!1}){return e.jsxs("button",{type:"button",role:"menuitem",onClick:a?void 0:o,"aria-disabled":a||void 0,title:a?"Coming soon":void 0,className:`flex items-center justify-between gap-2 w-full bg-transparent border-none p-0 text-left transition-colors duration-fast ease-out ${a?"cursor-not-allowed text-text-tertiary":"cursor-pointer text-text-secondary hover:text-text-primary focus-visible:text-text-primary btn-press"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex shrink-0 size-4 items-center justify-center",children:t}),e.jsx("span",{className:a?"text-body-sm":"text-body-sm text-text-primary",children:r})]}),s]})}function da({on:t}){return e.jsx("span",{className:"inline-flex shrink-0 items-center w-[29px] h-[16px] rounded-[9px] p-px transition-colors duration-fast ease-out "+(t?"bg-[var(--color-brand-default)]":"bg-[#2a2c31]"),"aria-hidden":"true",children:e.jsx("span",{className:"size-[14px] rounded-[8px] bg-white transition-transform duration-fast ease-out",style:{transform:t?"translateX(13px)":"translateX(0)"}})})}function ua(){return e.jsx("svg",{width:"14",height:"13",viewBox:"0 0 14 13",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M8.246 5.529L13.41 0H12.187L7.701 4.78 4.116 0H0l5.42 7.226L0 13h1.224l4.74-5.04L9.762 13H14L8.246 5.529ZM6.587 7.298l-.55-.717-4.37-5.687H3.55l3.531 4.595.55.717 4.586 5.965h-1.882L6.587 7.298Z",fill:"currentColor"})})}function xa({label:t,updateAvailable:r,onUpdateClick:s}){const o=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex shrink-0 size-4 items-center justify-center text-text-secondary",children:e.jsx(ha,{})}),e.jsx("span",{className:"text-body-sm text-text-primary",children:t})]}),r&&e.jsx(fa,{})]});return r?e.jsx("button",{type:"button",role:"menuitem",onClick:s,className:"flex items-center justify-between gap-2 w-full bg-transparent border-none p-0 text-left cursor-pointer transition-colors duration-fast ease-out btn-press",children:o}):e.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:o})}function fa(){return e.jsx("span",{className:"inline-flex items-center justify-center h-5 px-[7px] rounded-[2px] bg-[var(--color-warning-subtle)] text-warning-text text-footnote whitespace-nowrap",children:"Update New Version"})}function pa(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M10.9133 15.18C10.9066 15.18 10.9066 15.18 10.9 15.18C10.2266 15.1733 9.66664 14.76 9.46664 14.1134L8.23331 10.1467C8.06664 9.60001 8.20664 9.01334 8.61331 8.62C9.01331 8.22667 9.59331 8.08 10.1266 8.24667L14.1 9.48001C14.74 9.68001 15.16 10.24 15.1666 10.9133C15.1733 11.58 14.7666 12.1467 14.1266 12.36L13.04 12.7267C12.8866 12.78 12.7666 12.8933 12.72 13.0467L12.3466 14.14C12.14 14.7733 11.58 15.18 10.9133 15.18ZM9.67331 9.18C9.49331 9.18 9.37331 9.28 9.31998 9.32667C9.17998 9.46667 9.13331 9.66001 9.19331 9.85334L10.4266 13.82C10.5333 14.16 10.8266 14.1733 10.92 14.18C11.0133 14.18 11.3 14.1533 11.4066 13.8267L11.78 12.7333C11.9266 12.2867 12.2866 11.9334 12.7333 11.78L13.82 11.4133C14.1533 11.3067 14.1733 11.0134 14.1733 10.9267C14.1733 10.84 14.1466 10.5467 13.8133 10.44L9.83998 9.20667C9.77331 9.18667 9.71998 9.18 9.67331 9.18Z",fill:"currentColor"}),e.jsx("path",{d:"M8.00016 15.1667C4.04683 15.1667 0.833496 11.9533 0.833496 8C0.833496 4.04667 4.04683 0.833336 8.00016 0.833336C11.9535 0.833336 15.1668 4.04667 15.1668 8C15.1668 8.27334 14.9402 8.5 14.6668 8.5C14.3935 8.5 14.1668 8.27334 14.1668 8C14.1668 4.6 11.4002 1.83334 8.00016 1.83334C4.60016 1.83334 1.8335 4.6 1.8335 8C1.8335 11.4 4.60016 14.1667 8.00016 14.1667C8.2735 14.1667 8.50016 14.3933 8.50016 14.6667C8.50016 14.94 8.2735 15.1667 8.00016 15.1667Z",fill:"currentColor"})]})}function ha(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M8.00016 15.1667C4.04683 15.1667 0.833496 11.9533 0.833496 7.99999C0.833496 4.04666 4.04683 0.833328 8.00016 0.833328C11.9535 0.833328 15.1668 4.04666 15.1668 7.99999C15.1668 11.9533 11.9535 15.1667 8.00016 15.1667ZM8.00016 1.83333C4.60016 1.83333 1.8335 4.59999 1.8335 7.99999C1.8335 11.4 4.60016 14.1667 8.00016 14.1667C11.4002 14.1667 14.1668 11.4 14.1668 7.99999C14.1668 4.59999 11.4002 1.83333 8.00016 1.83333Z",fill:"currentColor"}),e.jsx("path",{d:"M8 9.16666C7.72667 9.16666 7.5 8.93999 7.5 8.66666V5.33333C7.5 5.05999 7.72667 4.83333 8 4.83333C8.27333 4.83333 8.5 5.05999 8.5 5.33333V8.66666C8.5 8.93999 8.27333 9.16666 8 9.16666Z",fill:"currentColor"}),e.jsx("path",{d:"M8.00016 11.3333C7.9135 11.3333 7.82683 11.3133 7.74683 11.28C7.66683 11.2467 7.5935 11.2 7.52683 11.14C7.46683 11.0733 7.42016 11.0067 7.38683 10.92C7.3535 10.84 7.3335 10.7533 7.3335 10.6667C7.3335 10.58 7.3535 10.4933 7.38683 10.4133C7.42016 10.3333 7.46683 10.26 7.52683 10.1933C7.5935 10.1333 7.66683 10.0867 7.74683 10.0533C7.90683 9.98668 8.0935 9.98668 8.2535 10.0533C8.3335 10.0867 8.40683 10.1333 8.4735 10.1933C8.5335 10.26 8.58016 10.3333 8.6135 10.4133C8.64683 10.4933 8.66683 10.58 8.66683 10.6667C8.66683 10.7533 8.64683 10.84 8.6135 10.92C8.58016 11.0067 8.5335 11.0733 8.4735 11.14C8.40683 11.2 8.3335 11.2467 8.2535 11.28C8.1735 11.3133 8.08683 11.3333 8.00016 11.3333Z",fill:"currentColor"})]})}function ma(t){if(t<0)return"just now";const r=Math.floor(t/1e3);if(r<60)return`${r}s ago`;const s=Math.floor(r/60);if(s<60)return`${s}m ago`;const o=Math.floor(s/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function ba(t){if(t.startsWith("{"))try{const s=JSON.parse(t);switch(s.code){case"telegram_unauthorized":case"telegram_invalid_token":return"Bot token is invalid — check with @BotFather";case"telegram_unreachable":return"Couldn't reach Telegram, try again";case"telegram_already_registered":return s.message??"Telegram is already connected.";case"locality_required":return s.message??"This action is only available from a local browser session.";case"telegram_unknown":default:return s.message??t}}catch{}const r=t.toLowerCase();return r.includes("rejected")||r.includes("unauthorized")||r.includes("401")?"Bot token is invalid — check with @BotFather":r.includes("timeout")||r.includes("fetch")||r.includes("network")?"Couldn't reach Telegram, try again":t}function ga(){const t=({n:r})=>e.jsx("span",{className:"bg-[#0d8eff] flex items-center justify-center rounded-full w-[18px] h-[18px] flex-none text-label-sm text-white",children:r});return e.jsxs("div",{className:"flex flex-col items-center gap-3 w-full",children:[e.jsx("div",{className:"size-[38px] rounded-[4px] bg-[rgba(13,142,255,0.1)] border border-[rgba(13,142,255,0.2)] flex items-center justify-center",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"22",height:"16",viewBox:"0 0 22 16",fill:"none","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.6433 4.81891C14.1523 5.10474 13.6653 5.39499 13.1797 5.68914C12.2722 6.23924 11.3579 6.8161 10.4253 7.34749C9.57263 7.83288 8.77152 8.38376 7.92063 8.87123C7.00368 9.39716 5.87371 9.95219 4.74374 9.65961C3.1436 9.24463 1.89394 9.07131 0.720713 8.66673C-0.453104 8.26267 -0.0338837 7.56394 0.846034 7.19677C1.72625 6.82909 11.4489 3.15329 11.4489 3.15329L17.5257 0.948226C18.0533 0.767632 18.5801 0.586259 19.1066 0.403326C19.4615 0.280159 19.8102 0.14192 20.1832 0.0673438C20.6057 -0.0171066 21.1099 -0.0563435 21.4918 0.160369C22.0384 0.470107 22.0378 1.14519 21.9679 1.6467C21.8325 2.62398 21.6654 3.59841 21.5004 4.57232C21.2818 5.85986 21.0557 7.14662 20.827 8.43287C20.624 9.57464 20.4184 10.7159 20.2113 11.8569C20.062 12.6803 19.9912 13.5293 19.7918 14.3436C19.7018 14.7118 19.564 15.0826 19.3249 15.3989C18.3226 16.7233 16.4437 15.5415 15.4159 14.8792C14.5689 14.3332 10.9802 12.2973 10.0914 11.7514C9.77409 11.5562 9.52582 11.2156 9.52937 10.8708C9.53411 10.3955 9.91896 10.0361 10.2929 9.73236C10.7518 9.35922 11.2261 8.99985 11.6818 8.62308C12.3658 8.05739 13.0496 7.49144 13.734 6.92549C14.3212 6.43958 14.9087 5.95392 15.4956 5.46827C15.82 5.20011 16.1279 4.92181 16.4152 4.62195C16.5018 4.53178 16.5619 4.46006 16.5717 4.34157C16.5785 4.25712 16.5589 4.17371 16.4864 4.11343C16.2165 3.89126 15.8817 4.11161 15.6396 4.24829C15.306 4.43668 14.9745 4.62688 14.6439 4.81943L14.6433 4.81891Z",fill:"#00AEED"})})}),e.jsxs("div",{className:"flex flex-col gap-4 w-full",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(t,{n:1}),e.jsxs("p",{className:"text-body-sm text-text-primary m-0",children:["Open ",e.jsx("span",{className:"text-[#40a6ff]",children:"@BotFather"})," on Telegram"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(t,{n:2}),e.jsxs("p",{className:"text-body-sm text-text-primary m-0",children:["Send ",e.jsx("span",{className:"text-[#40a6ff]",children:"/newbot"})," and copy the bot token"]})]})]})]})}function va({open:t,onClose:r,onSuccess:s,initialStatus:o}){const{request:a,subscribe:l}=te(),[i,c]=n.useState(o??null),[x,p]=n.useState([]),[m,d]=n.useState([]),[f,u]=n.useState(""),[y,h]=n.useState(!1),[v,g]=n.useState(null),[,b]=n.useState(0),w=n.useCallback(async()=>{try{const[T,A,B]=await Promise.all([a("channels.status",{id:"telegram",probe:!0}),a("channels.pairing.list",{id:"telegram"}),a("channels.allowlist.list",{id:"telegram"})]);c(T),p(A.requests),d(B.entries)}catch{}},[a]);n.useEffect(()=>{t&&(g(null),u(""),o&&c(o),w())},[t]),n.useEffect(()=>{if(t)return l(T=>{if(T.event==="pairing.request.created"||T.event==="pairing.request.approved"||T.event==="pairing.request.removed"||T.event==="pairing.allowlist.removed"){const A=T.payload;(A==null?void 0:A.channel)==="telegram"&&w()}else if(T.event==="channel.state.changed"){const A=T.payload;(A==null?void 0:A.channel)==="telegram"&&w()}})},[t,l,w]),n.useEffect(()=>{if(!t)return;const T=setInterval(()=>b(A=>A+1),3e4);return()=>clearInterval(T)},[t]);const C=i!==null,k=((i==null?void 0:i.enabled)&&i.healthy)??!1,E=i==null?void 0:i.detail.bot,M=f.trim().length>0,N=async()=>{const T=f.trim();if(!T){g({ok:!1,text:"Bot token is required"});return}h(!0),g(null);try{await a("channels.setup",{id:"telegram",token:T}),u(""),s==null||s(),await w()}catch(A){const B=A instanceof Error?A.message:"Connect failed";g({ok:!1,text:ba(B)})}finally{h(!1)}},j=async()=>{h(!0),g(null);try{await a("channels.remove",{id:"telegram"}),await w()}catch(T){const A=T instanceof Error?T.message:"Disconnect failed";g({ok:!1,text:A})}finally{h(!1)}},S=async T=>{h(!0);try{const A=await a("channels.pairing.approve",{id:"telegram",code:T,notify:!0});if(!A.ok)g({ok:!1,text:"Code already expired or approved"});else if(A.notifyError){const B=x.find(J=>J.code===T),Z=B!=null&&B.username?`@${B.username}`:`id:${(B==null?void 0:B.senderId)??"?"}`;g({ok:!0,text:`Approved ${Z} but DM failed: ${A.notifyError}`})}else g(null);await w()}catch(A){g({ok:!1,text:A instanceof Error?A.message:"Approve failed"})}finally{h(!1)}},R=async T=>{const A=m;d(B=>B.filter(Z=>Z.identity!==T));try{(await a("channels.allowlist.remove",{id:"telegram",identity:T})).ok||(d(A),g({ok:!1,text:"User was not on the authorized list"}))}catch(B){d(A),g({ok:!1,text:B instanceof Error?B.message:"Revoke failed"})}},P=y||!M,$=Date.now(),L=async()=>{try{const T=await navigator.clipboard.readText();T&&(u(T.trim()),g(null))}catch{g({ok:!1,text:"Clipboard read denied — paste manually"})}},I=!k,W=t&&!C;return e.jsxs(de,{open:t,onClose:r,title:"Connect your Telegram Bot",width:450,hideHeader:!0,cardClassName:"bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[2px] shadow-[0_8px_32px_rgba(0,0,0,0.5)]",bodyClassName:W?"flex items-center justify-center p-6 min-h-[260px]":I?"flex flex-col items-end gap-4 px-4 pt-4 pb-5":"flex flex-col gap-3 px-4 pt-4 pb-5",children:[!W&&e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("span",{className:"text-body-lg-semibold text-white",children:"Connect your Telegram Bot"}),e.jsx("button",{type:"button","aria-label":"Close",onClick:r,className:"w-7 h-7 inline-flex items-center justify-center rounded-[6px] bg-transparent border-none cursor-pointer text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] btn-press transition-colors duration-fast ease-out",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M3 3 L11 11 M11 3 L3 11",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]}),W?e.jsx("span",{className:"inline-flex gap-1.5 text-[var(--color-text-secondary)]","aria-label":"Loading",children:[0,1,2].map(T=>e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current",style:{animation:`pulse 1.4s ease-in-out ${T*.2}s infinite`}},T))}):k?e.jsxs("a",{href:E?`https://t.me/${E}`:void 0,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-3 py-2 bg-[rgba(0,184,255,0.04)] border border-[rgba(0,184,255,0.12)] rounded-[4px] text-body-sm text-[var(--color-text-secondary)] btn-press transition-colors duration-fast ease-out hover:border-[rgba(0,184,255,0.3)] hover:text-[var(--color-text-primary)] focus-visible:border-[rgba(0,184,255,0.3)] focus-visible:text-[var(--color-text-primary)] outline-none no-underline",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",className:"flex-shrink-0 fill-[#00b8ff] opacity-90",children:e.jsx("path",{d:"M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0Zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.231-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.244-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"})}),e.jsxs("span",{className:"flex-1 truncate",children:["DM ",e.jsx("span",{className:"text-[#00b8ff]",children:E?`@${E}`:"the bot"})," to request pairing"]}),e.jsx("span",{className:"opacity-60 flex-shrink-0","aria-hidden":"true",children:"↗"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ga,{}),e.jsxs("div",{className:"flex flex-col gap-1 pl-6 w-full",children:[e.jsx("label",{htmlFor:"telegram-token-input",className:"text-body-sm text-[var(--color-text-secondary)]",children:"Bot token"}),e.jsxs("div",{className:"flex items-center bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] rounded-[4px] h-9 px-4 w-full focus-within:border-[var(--color-brand-default)] transition-colors duration-fast ease-out",children:[e.jsx("input",{id:"telegram-token-input",type:"password",autoComplete:"off",spellCheck:!1,value:f,onChange:T=>{u(T.target.value),g(null)},placeholder:"1234567890:ABC",onKeyDown:T=>{T.key==="Enter"&&!P&&N()},className:"flex-1 min-w-0 bg-transparent border-none outline-none focus:outline-none focus-visible:outline-none text-body-sm text-text-primary placeholder:text-[var(--color-text-muted)]"}),e.jsx("button",{type:"button",onClick:L,"aria-label":"Paste from clipboard",title:"Paste from clipboard",className:"ml-3 bg-transparent border-none cursor-pointer text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] transition-colors duration-fast ease-out flex-none inline-flex items-center",children:e.jsxs("svg",{width:"15",height:"16",viewBox:"0 0 15 16",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"3.5",y:"2",width:"8",height:"11",rx:"1",stroke:"currentColor",strokeWidth:"1.2",fill:"none"}),e.jsx("rect",{x:"5",y:"0.6",width:"5",height:"2.4",rx:"0.6",stroke:"currentColor",strokeWidth:"1.2",fill:"currentColor"})]})})]}),e.jsx("p",{className:"text-body-sm text-[var(--color-text-secondary)] m-0",children:"Token is stored encrypted on this device. Ghost validates with Telegram before saving."})]}),e.jsx("button",{onClick:N,disabled:P,className:"bg-[var(--color-brand-default)] hover:bg-[var(--color-brand-hover)] h-9 px-3 rounded-[4px] flex items-center justify-center text-body-md-semibold text-[var(--color-text-on-brand)] border-none cursor-pointer btn-press transition-colors duration-fast ease-out disabled:cursor-default disabled:opacity-60",children:y?e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{"data-pulse-dots":!0,className:"inline-flex gap-1",children:[0,1,2].map(T=>e.jsx("span",{className:"w-[3px] h-[3px] rounded-full bg-[color:currentColor]",style:{animation:`pulse 1.4s ease-in-out ${T*.2}s infinite`}},T))}),"Connecting"]}):"Connect"})]}),v&&e.jsx("div",{className:I?"w-full":"mt-2",children:e.jsx(tt,{kind:v.ok?"success":"error",text:v.text,onClose:()=>g(null)})}),k&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col items-start gap-[5px] w-full",children:[e.jsx("span",{className:"text-body-sm text-text-primary",children:"Users"}),x.length===0&&m.length===0?e.jsx("div",{className:"bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] h-10 flex items-center justify-center px-4 w-full",children:e.jsx("span",{className:"text-body-sm text-text-secondary",children:"No users yet — share the bot to start pairing"})}):e.jsxs("div",{className:"flex flex-col items-start w-full",children:[x.map((T,A)=>{const B=T.username?`@${T.username}`:`id:${T.senderId}`,Z=A===x.length-1&&m.length===0;return e.jsxs("div",{className:"bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] flex h-10 items-center justify-between px-4 w-full "+(Z?"":"-mb-px"),title:`Pending · ${ma($-T.createdAt)} · code ${T.code}`,children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"status-dot-live w-[7px] h-[7px] rounded-full bg-[var(--color-brand-default)] flex-shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"text-body-md text-text-primary truncate",children:B})]}),e.jsx("button",{onClick:()=>S(T.code),disabled:y,className:"bg-transparent border-none cursor-pointer btn-press text-body-md-semibold text-[var(--color-brand-default)] transition-opacity duration-fast ease-out hover:opacity-80 disabled:cursor-default disabled:opacity-60",children:"Approve"})]},`pending:${T.code}`)}),m.map((T,A)=>{const B=T.identityKind==="username"?`@${T.identity}`:T.displayName?`@${T.displayName}`:`id:${T.identity}`,Z=A===m.length-1;return e.jsxs("div",{className:"bg-[var(--color-surface-canvas)] border border-[var(--color-border-subtle)] flex h-10 items-center justify-between px-4 w-full "+(Z?"":"-mb-px"),children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"status-dot-live w-[7px] h-[7px] rounded-full bg-[var(--color-brand-default)] flex-shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"text-body-md text-text-primary truncate",children:B})]}),e.jsx("button",{onClick:()=>R(T.identity),"aria-label":`Revoke ${B}`,title:`Revoke ${B}`,className:"inline-flex items-center justify-center w-[18px] h-[18px] bg-transparent border-none cursor-pointer text-text-secondary hover:text-[var(--color-error-default)] transition-colors duration-fast ease-out flex-shrink-0",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M1.5 1.5 L8.5 8.5 M8.5 1.5 L1.5 8.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})]},`approved:${T.identityKind}:${T.identity}`)})]})]}),e.jsx("div",{className:"flex items-center justify-end mt-2 w-full",children:e.jsx("button",{onClick:j,disabled:y,className:"h-9 px-4 inline-flex items-center justify-center rounded-[4px] bg-transparent border border-[var(--color-border-subtle)] text-body-md-semibold text-[var(--color-error-text)] cursor-pointer btn-press transition-colors duration-fast ease-out hover:border-[var(--color-error-default)] hover:text-[var(--color-error-default)] focus-visible:border-[var(--color-error-default)] disabled:cursor-default disabled:opacity-60",children:"Disconnect"})})]})]})}const ya="data:image/svg+xml,%3csvg%20viewBox='0%200%2032%2032'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20x='0.5'%20y='0.5'%20width='31'%20height='31'%20rx='15.5'%20fill='%230A0A0B'/%3e%3crect%20x='0.5'%20y='0.5'%20width='31'%20height='31'%20rx='15.5'%20stroke='%2300AEED'%20stroke-dasharray='2%202'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M18.6496%2013.6142C18.2926%2013.8286%2017.9384%2014.0462%2017.5852%2014.2669C16.9253%2014.6794%2016.2603%2015.1121%2015.582%2015.5106C14.9619%2015.8747%2014.3793%2016.2878%2013.7605%2016.6534C13.0936%2017.0479%2012.2718%2017.4641%2011.45%2017.2447C10.2863%2016.9335%209.37741%2016.8035%208.52415%2016.5C7.67047%2016.197%207.97536%2015.673%208.6153%2015.3976C9.25545%2015.1218%2016.3265%2012.365%2016.3265%2012.365L20.7459%2010.7112C21.1297%2010.5757%2021.5128%2010.4397%2021.8957%2010.3025C22.1538%2010.2101%2022.4074%2010.1064%2022.6787%2010.0505C22.9859%209.98717%2023.3527%209.95774%2023.6304%2010.1203C24.0279%2010.3526%2024.0275%2010.8589%2023.9767%2011.235C23.8782%2011.968%2023.7567%2012.6988%2023.6367%2013.4292C23.4776%2014.3949%2023.3132%2015.36%2023.1469%2016.3247C22.9993%2017.181%2022.8498%2018.0369%2022.6992%2018.8927C22.5906%2019.5102%2022.5391%2020.1469%2022.3941%2020.7577C22.3285%2021.0339%2022.2284%2021.312%2022.0545%2021.5491C21.3255%2022.5425%2019.959%2021.6561%2019.2116%2021.1594C18.5956%2020.7499%2015.9856%2019.223%2015.3392%2018.8135C15.1084%2018.6672%2014.9279%2018.4117%2014.9305%2018.1531C14.9339%2017.7966%2015.2138%2017.5271%2015.4857%2017.2993C15.8195%2017.0194%2016.1644%2016.7499%2016.4958%2016.4673C16.9933%2016.043%2017.4906%2015.6186%2017.9884%2015.1941C18.4154%2014.8297%2018.8427%2014.4654%2019.2695%2014.1012C19.5055%2013.9001%2019.7294%2013.6914%2019.9384%2013.4665C20.0013%2013.3988%2020.045%2013.345%2020.0521%2013.2562C20.0571%2013.1928%2020.0429%2013.1303%2019.9901%2013.0851C19.7938%2012.9184%2019.5503%2013.0837%2019.3743%2013.1862C19.1316%2013.3275%2018.8905%2013.4702%2018.6501%2013.6146L18.6496%2013.6142Z'%20fill='%2300AEED'/%3e%3c/svg%3e",wa="data:image/svg+xml,%3csvg%20preserveAspectRatio='none'%20width='100%25'%20height='100%25'%20overflow='visible'%20style='display:%20block;'%20viewBox='0%200%2016%2012'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20id='Vector'%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M10.6496%203.61418C10.2926%203.82856%209.93839%204.04624%209.58523%204.26686C8.92526%204.67943%208.26032%205.11207%207.58203%205.51061C6.96191%205.87466%206.37928%206.28782%205.76046%206.65342C5.09359%207.04787%204.27179%207.46415%203.45%207.2447C2.28625%206.93347%201.37741%206.80348%200.524155%206.50005C-0.32953%206.197%20-0.0246427%205.67295%200.615298%205.39758C1.25545%205.12182%208.32647%202.36497%208.32647%202.36497L12.7459%200.71117C13.1297%200.575724%2013.5128%200.439694%2013.8957%200.302495C14.1538%200.210119%2014.4074%200.10644%2014.6787%200.0505078C14.9859%20-0.0128299%2015.3527%20-0.0422576%2015.6304%200.120277C16.0279%200.35258%2016.0275%200.858893%2015.9767%201.23502C15.8782%201.96799%2015.7567%202.69881%2015.6367%203.42924C15.4776%204.39489%2015.3132%205.35997%2015.1469%206.32465C14.9993%207.18098%2014.8498%208.03691%2014.6992%208.89266C14.5906%209.51025%2014.5391%2010.1469%2014.3941%2010.7577C14.3285%2011.0339%2014.2284%2011.312%2014.0545%2011.5491C13.3255%2012.5425%2011.959%2011.6561%2011.2116%2011.1594C10.5956%2010.7499%207.9856%209.22299%207.33919%208.81353C7.10843%208.66717%206.92787%208.41168%206.93045%208.15307C6.9339%207.79662%207.21379%207.52709%207.48571%207.29927C7.81947%207.01942%208.16444%206.74989%208.49583%206.46731C8.99334%206.04304%209.49064%205.61858%209.98837%205.19412C10.4154%204.82968%2010.8427%204.46544%2011.2695%204.1012C11.5055%203.90008%2011.7294%203.69136%2011.9384%203.46646C12.0013%203.39884%2012.045%203.34505%2012.0521%203.25618C12.0571%203.19284%2012.0429%203.13028%2011.9901%203.08507C11.7938%202.91844%2011.5503%203.08371%2011.3743%203.18622C11.1316%203.32751%2010.8905%203.47016%2010.6501%203.61457L10.6496%203.61418Z'%20fill='var(--fill-0,%20%23B0B4BD)'/%3e%3c/svg%3e",Ca="data:image/svg+xml,%3csvg%20viewBox='0%200%2013%2013'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='6.5'%20cy='6.5'%20r='6.5'%20fill='%2322C55E'/%3e%3cpath%20d='M8.91516%208.84886C8.17061%208.84886%207.48368%208.49875%207.03607%207.88273C6.9297%207.73648%206.96072%207.52818%207.10697%207.41739C7.25322%207.30659%207.46152%207.34205%207.57232%207.4883C7.89584%207.92705%208.38334%208.17966%208.91516%208.17966C9.84141%208.17966%2010.5992%207.42625%2010.5992%206.49557C10.5992%205.56489%209.84584%204.81148%208.91516%204.81148C8.28584%204.81148%207.69197%205.1483%207.36845%205.68455L6.19402%207.63898C5.75084%208.37909%204.93982%208.83557%204.08004%208.83557C2.78595%208.83557%201.73118%207.7808%201.73118%206.4867C1.73118%205.19261%202.78595%204.13784%204.08004%204.13784C4.82459%204.13784%205.51152%204.48795%205.95913%205.10398C6.0655%205.25023%206.03447%205.45852%205.88822%205.56932C5.73754%205.68011%205.53368%205.64466%205.42288%205.49841C5.10379%205.06852%204.61629%204.81591%204.08447%204.81591C3.15822%204.81591%202.40038%205.56932%202.40038%206.5C2.40038%207.43068%203.15379%208.18409%204.08447%208.18409C4.71379%208.18409%205.30766%207.84727%205.63118%207.31102L6.80561%205.35659C7.24879%204.61648%208.05982%204.16%208.91959%204.16C10.2137%204.16%2011.2685%205.21477%2011.2685%206.50886C11.2685%207.80296%2010.2092%208.84886%208.91516%208.84886Z'%20fill='white'%20stroke='white'%20stroke-width='0.3'/%3e%3c/svg%3e";function ja(){const[t,r]=n.useState(!1),s=Na(t);return e.jsxs("header",{className:"relative z-20 flex items-center justify-end px-6 py-4 h-[53px] flex-shrink-0 bg-[var(--color-surface-canvas)]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[s?e.jsxs("button",{type:"button",onClick:()=>r(!0),className:"relative w-8 h-8 shrink-0 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[var(--color-border-default)] rounded-full","aria-label":"Telegram connected",title:"Telegram connected",children:[e.jsx("img",{src:ya,alt:"",className:"block w-8 h-8"}),e.jsx("img",{src:Ca,alt:"",className:"absolute top-[0.5px] left-[22px] w-[13px] h-[13px]"})]}):e.jsxs("button",{type:"button",onClick:()=>r(!0),className:"h-8 inline-flex items-center justify-center gap-2 px-3 py-[5px] rounded-[40px] bg-[var(--color-surface-base)] border border-dashed border-[var(--color-border-strong)] text-label-md text-[var(--color-text-secondary)] transition-colors duration-fast ease-out cursor-pointer btn-press hover:text-[var(--color-text-primary)] hover:border-[var(--color-brand-default)] focus-visible:text-[var(--color-text-primary)]","aria-label":"Connect Telegram",title:"Connect Telegram",children:[e.jsx("span",{children:"Connect"}),e.jsx("img",{src:wa,alt:"","aria-hidden":"true",width:16,height:12,className:"block"})]}),e.jsx(Uo,{}),e.jsx(ca,{})]}),e.jsx(va,{open:t,onClose:()=>r(!1)})]})}function Na(t){const{connected:r,request:s,subscribe:o}=te(),[a,l]=n.useState(!1);return n.useEffect(()=>{if(!r)return;let i=!1;const c=()=>{s("channels.status",{id:"telegram"}).then(p=>{i||l(!!(p!=null&&p.enabled))}).catch(()=>{i||l(!1)})};t||c();const x=o(p=>{if(p.event!=="channel.state.changed")return;const m=p.payload;(m==null?void 0:m.channel)==="telegram"&&c()});return()=>{i=!0,x()}},[r,t,s,o]),a}function ka({children:t}){const r=ks();return e.jsx(hr.Provider,{value:r,children:t})}function Sa({children:t}){const[r,s]=n.useState(()=>Pt(Ft)),[o,a]=n.useState(()=>Pt(Dt)),l=n.useCallback(c=>{s(c),Bt(Ft,c)},[]),i=n.useCallback(c=>{a(c),Bt(Dt,c)},[]);return e.jsx(Lr.Provider,{value:{newsCount:r,tweetsCount:o,setNewsCount:l,setTweetsCount:i},children:t})}const Ae=new Map;function La(t,r,s){return`${t}|${r??"4h"}|${s??""}`}function $r(t,r,s){const o=La(t,r,s),a=Ae.get(o)??null,[l,i]=n.useState(a),[c,x]=n.useState(!a),[p,m]=n.useState(null);return n.useEffect(()=>{if(Ae.has(o)){i(Ae.get(o)),x(!1);return}let d=!1;async function f(){x(!0),m(null);const u=new URLSearchParams({symbol:t});r&&u.set("interval",r),s&&u.set("indicators",s);try{const y=await fetch(`/api/chart-data?${u.toString()}`);if(!y.ok){const v=await y.json().catch(()=>null),g=v&&typeof v=="object"&&"error"in v?String(v.error):`HTTP ${y.status}`;throw new Error(g)}const h=await y.json();d||(Ae.set(o,h),i(h))}catch(y){d||m(y instanceof Error?y.message:"Failed to load chart data")}finally{d||x(!1)}}return f(),()=>{d=!0}},[t,r,s,o]),{data:l,loading:c,error:p}}const Ea=n.createContext(null);function Ma(){return n.useContext(Ea)}function Ta(t,r,s){return`${t}|${r??"4h"}|${s??""}`}const Ra="#111114",mt="#7f8f9e",tr="rgba(121,121,121,0.06)",rr="rgba(121,121,121,0.15)",Ue="#26a69a",Ze="#ef5350",Or="#26a69a",Hr="#ef5350",Vr=180,_a=300,Aa=.15,st=80,Ia='"JetBrains Mono", monospace',Fa=10;function Wr(t){return t.startsWith("rgba(")||t.startsWith("#")?t:t.startsWith("rgb(")?t.replace("rgb(","rgba(").replace(")",", 0.5)"):t}const zr=t=>`line:${t}`,Ur=t=>`band:${t}`,Zr=t=>`level:${t}`;function Da(t){return t.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:4})}function Pa(t){return`${t.label?t.label.length>20?t.label.slice(0,20)+"…":t.label:t.side?t.side==="support"?"Support":"Resistance":"Level"} ${Da(t.price)}`}function Ba(t){return t==="support"?Or:t==="resistance"?Hr:mt}function $a({lines:t,bands:r,levels:s,hidden:o,onToggle:a}){const l="absolute top-2 left-2 z-10 flex max-h-[40%] flex-col gap-1 overflow-y-auto rounded-[4px] border border-[rgba(121,121,121,0.15)] bg-[rgba(11,17,24,0.85)] px-2 py-2 text-footnote text-[var(--color-text-secondary)]",i="flex items-center gap-2 border-none bg-transparent px-0 py-px text-left text-footnote text-inherit cursor-pointer";return e.jsxs("div",{className:l,children:[t.map(c=>{const x=zr(c.label),p=o.has(x);return e.jsxs("button",{type:"button",className:i,style:{opacity:p?.4:1},"aria-pressed":!p,"aria-label":`Toggle ${c.label}`,onClick:()=>a(x),children:[e.jsx("span",{className:"h-[2px] w-3 flex-shrink-0",style:{background:p?"transparent":c.color,border:`1px solid ${c.color}`}}),e.jsx("span",{children:c.label})]},x)}),r.map(c=>{const x=Ur(c.label),p=o.has(x),m=Wr(c.color);return e.jsxs("button",{type:"button",className:i,style:{opacity:p?.4:1},"aria-pressed":!p,"aria-label":`Toggle ${c.label}`,onClick:()=>a(x),children:[e.jsx("span",{className:"h-[2px] w-3 flex-shrink-0",style:{background:p?"transparent":m,border:`1px solid ${m}`}}),e.jsx("span",{children:c.label})]},x)}),s.map(c=>{const x=Zr(c.price),p=o.has(x),m=Ba(c.side),d=Pa(c);return e.jsxs("button",{type:"button",className:i,style:{opacity:p?.4:1},"aria-pressed":!p,"aria-label":`Toggle ${d}`,onClick:()=>a(x),children:[e.jsx("span",{className:"h-[2px] w-3 flex-shrink-0",style:{background:p?"transparent":m,border:`1px solid ${m}`}}),e.jsx("span",{children:d})]},x)})]})}function De(t,r){const s=t.toLowerCase(),o=r.toLowerCase();return o==="ema"?s.startsWith("ema"):s===o}function Oa(t){if(!t)return null;const r=t.split(",").map(a=>a.trim());if(r.length!==2)return null;const s=Math.floor(new Date(r[0]).getTime()/1e3),o=Math.floor(new Date(r[1]).getTime()/1e3);return Number.isNaN(s)||Number.isNaN(o)?null:[s,o]}function Ha(t){if(!t)return null;const r=t.split(",").map(s=>parseFloat(s.trim()));return r.length!==2||r.some(Number.isNaN)?null:[r[0],r[1]]}function Va(t){return t?t.split(",").map(r=>parseFloat(r.trim())).filter(r=>!Number.isNaN(r)):[]}function qr(t,r,s){const o=(s==null?void 0:s.kind)==="indicator"?s.name:null,a=(s==null?void 0:s.kind)==="level"?s.price:null,l=a!==null?[]:o!==null?t.lineOverlays.filter(d=>De(d.label,o)):t.lineOverlays,i=a!==null?[]:o!==null?t.bandOverlays.filter(d=>De(d.label,o)):t.bandOverlays,c=d=>a!==null&&Math.abs(d-a)/a<.005,p=o!==null?[]:[...t.levels.map(d=>({price:d.price,label:d.label,side:d.side,isTarget:c(d.price)})),...r.map(d=>({price:d,label:"",isTarget:c(d)}))],m=a!==null?[...p.filter(d=>d.isTarget),...p.filter(d=>!d.isTarget)]:p;return{lines:l,bands:i,levels:m}}function Gr(t,r){return{height:t,autoSize:!0,layout:{background:{type:ys.Solid,color:Ra},textColor:mt,fontFamily:Ia,fontSize:Fa},grid:{vertLines:{color:tr},horzLines:{color:tr}},crosshair:{mode:vs.Normal},rightPriceScale:{borderColor:rr,scaleMargins:{top:.03,bottom:.08}},timeScale:{borderColor:rr,timeVisible:!0,secondsVisible:!1,visible:r},handleScroll:{vertTouchDrag:!1}}}function Kr(t,r,s,o,a,l,i=!1,c,x){const p=(c==null?void 0:c.kind)==="indicator"?c.name:null,m=qr(r,o,c),d=h=>(x==null?void 0:x.has(h))??!1,f=xr(t,{...Gr(s,!0),width:t.clientWidth||600}),u=f.addSeries(gs,{upColor:Ue,downColor:Ze,borderDownColor:Ze,borderUpColor:Ue,wickDownColor:Ze,wickUpColor:Ue});if(u.setData(r.candles),r.volumes.length>0){const h=f.addSeries(fr,{priceFormat:{type:"volume"},priceScaleId:"volume"});f.priceScale("volume").applyOptions({scaleMargins:{top:1-Aa,bottom:0}}),h.setData(r.volumes)}for(const h of m.lines){if(d(zr(h.label)))continue;const v=p!==null&&De(h.label,p);f.addSeries(ge,{color:h.color,lineWidth:v?2:1,priceLineVisible:!1,lastValueVisible:!1,crosshairMarkerVisible:!1}).setData(h.data)}for(const h of m.bands){if(d(Ur(h.label)))continue;const v=Wr(h.color);f.addSeries(ge,{color:v,lineWidth:1,priceLineVisible:!1,lastValueVisible:!1,crosshairMarkerVisible:!1}).setData(h.upperData),f.addSeries(ge,{color:v,lineWidth:1,priceLineVisible:!1,lastValueVisible:!1,crosshairMarkerVisible:!1}).setData(h.lowerData)}const y=(c==null?void 0:c.kind)==="level";for(const h of m.levels){if(d(Zr(h.price)))continue;const v=h.side?h.side==="support"?Or:Hr:mt,g=y&&!h.isTarget?v+"55":v,b=y&&!h.isTarget,w=b||i&&!h.isTarget,C=!h.label||w?"":h.label.length>20?h.label.slice(0,20)+"…":h.label;u.createPriceLine({price:h.price,color:g,lineWidth:h.isTarget?2:1,lineStyle:h.isTarget?Je.Solid:Je.Dashed,axisLabelVisible:h.isTarget||!i&&!b,title:C})}if(a)f.timeScale().setVisibleRange({from:a[0],to:a[1]});else{const h=r.candles.length,v=Math.min(50,h);f.timeScale().setVisibleLogicalRange({from:h-v,to:h-1})}if(l){const h=(l[1]-l[0])*.05;f.priceScale("right").applyOptions({autoScale:!1,scaleMargins:{top:.02,bottom:.15}}),u.applyOptions({autoscaleInfoProvider:()=>({priceRange:{minValue:l[0]-h,maxValue:l[1]+h}})})}return f}function Wa(t,r){const s=xr(t,{...Gr(st,!1),width:t.clientWidth||600});if(s.priceScale("right").applyOptions({scaleMargins:{top:.1,bottom:.1}}),r.type==="macd")r.histogramData&&r.histogramData.length>0&&s.addSeries(fr,{priceFormat:{type:"price",precision:2,minMove:.01},priceLineVisible:!1,lastValueVisible:!1}).setData(r.histogramData),r.data.length>0&&s.addSeries(ge,{color:r.color,lineWidth:1,priceLineVisible:!1,lastValueVisible:!1,crosshairMarkerVisible:!1}).setData(r.data),r.signalData&&r.signalData.length>0&&s.addSeries(ge,{color:"#ff9800",lineWidth:1,priceLineVisible:!1,lastValueVisible:!1,crosshairMarkerVisible:!1}).setData(r.signalData);else{const o=s.addSeries(ge,{color:r.color,lineWidth:1,priceLineVisible:!1,lastValueVisible:!1,crosshairMarkerVisible:!1});if(o.setData(r.data),r.zones)for(const a of r.zones)o.createPriceLine({price:a.value,color:a.color,lineWidth:1,lineStyle:Je.Dotted,axisLabelVisible:!1,title:""})}return s.timeScale().fitContent(),s}function za(t,r){let s=!1;function o(i){if(!(s||!i)){s=!0;for(const c of r)c.timeScale().setVisibleLogicalRange(i);s=!1}}function a(i){return c=>{if(!(s||!c)){s=!0,t.timeScale().setVisibleLogicalRange(c);for(let x=0;x<r.length;x++)x!==i&&r[x].timeScale().setVisibleLogicalRange(c);s=!1}}}t.timeScale().subscribeVisibleLogicalRangeChange(o);const l=r.map((i,c)=>{const x=a(c);return i.timeScale().subscribeVisibleLogicalRangeChange(x),{sub:i,handler:x}});return()=>{t.timeScale().unsubscribeVisibleLogicalRangeChange(o);for(const{sub:i,handler:c}of l)i.timeScale().unsubscribeVisibleLogicalRangeChange(c)}}function nt({data:t,extraLevels:r,focusTime:s,focusPrice:o,focus:a,onClose:l,mode:i="fullscreen",panelHeight:c=351,interval:x,onIntervalChange:p}){const m=n.useRef(null),d=n.useRef([]),[f,u]=n.useState(()=>new Set),y=n.useCallback(j=>{u(S=>{const R=new Set(S);return R.has(j)?R.delete(j):R.add(j),R})},[]),h=n.useMemo(()=>qr(t,r,a),[t,r,a]),v=n.useMemo(()=>{if(!a)return t.subPanes;if(a.kind==="indicator"){const j=t.subPanes.find(S=>De(S.label,a.name));return j?[j]:[]}return[]},[t.subPanes,a]),g=n.useMemo(()=>{if(o)return o;if((a==null?void 0:a.kind)!=="level"||t.candles.length===0)return null;const j=a.price,S=Math.min(...t.candles.map($=>$.low)),R=Math.max(...t.candles.map($=>$.high));if(j>=S&&j<=R)return null;const P=(R-S)*.08||R*.01;return[Math.min(S,j)-P,Math.max(R,j)+P]},[o,a,t.candles]);n.useEffect(()=>{var W,T;const j=m.current;if(!j)return;const S=v.length,P=(i==="panel"?c:i==="headless"?((T=(W=j.parentElement)==null?void 0:W.parentElement)==null?void 0:T.clientHeight)??window.innerHeight:window.innerHeight)-52-S*(st+4),$=Kr(j,t,Math.max(P,_a),r,s,g,!1,a,f),L=[];for(let A=0;A<S;A++){const B=d.current[A];B&&L.push(Wa(B,v[A]))}const I=L.length>0?za($,L):void 0;return()=>{I==null||I();for(const A of L)A.remove();$.remove()}},[t,r,s,g,a,v,f,i,c]),n.useEffect(()=>{const j=S=>{S.key==="Escape"&&l()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[l]);const b=t.candles[t.candles.length-1],w=t.candles[0],C=(b==null?void 0:b.close)??null,k=b&&w&&w.close>0?(b.close-w.close)/w.close*100:null,E=k==null?"text-text-secondary":k>=0?"text-[var(--color-success-default)]":"text-[var(--color-error-default)]",M=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative min-h-[160px] flex-1",children:[e.jsx("div",{ref:m,className:"h-full w-full"}),h.lines.length+h.bands.length+h.levels.length>0&&e.jsx($a,{lines:h.lines,bands:h.bands,levels:h.levels,hidden:f,onToggle:y})]}),v.map((j,S)=>e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"pointer-events-none absolute top-1 left-2 z-10 text-footnote text-[var(--color-text-secondary)] opacity-70",children:j.label}),e.jsx("div",{ref:R=>{R&&(d.current[S]=R)},style:{height:st}})]},j.label))]});if(i==="headless")return e.jsx("div",{className:"relative flex flex-col w-full h-full px-2 py-2 gap-1 min-h-0",children:M});if(i==="panel")return e.jsxs("div",{className:"relative flex flex-col bg-[var(--color-surface-base)] border-t border-b border-[var(--color-border-subtle)]",style:{height:c},children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ua,{symbol:t.symbol}),C!=null&&e.jsxs("span",{className:"text-body-sm text-text-primary [font-variant-numeric:tabular-nums]",children:["$",C.toLocaleString(void 0,{maximumFractionDigits:C>=100?2:4})]}),k!=null&&e.jsxs("span",{className:`text-body-sm [font-variant-numeric:tabular-nums] ${E}`,children:[k>=0?"▲":"▼"," ",Math.abs(k).toFixed(2),"%"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[p&&x&&e.jsx("div",{className:"flex items-center gap-0.5 rounded-[4px] border border-[var(--color-border-strong)] p-0.5",children:["15m","1h","4h","1d"].map(j=>{const S=j===x;return e.jsx("button",{type:"button",onClick:()=>p(j),className:"cursor-pointer rounded-[2px] px-2 py-0.5 text-caption transition-colors duration-fast ease-out btn-press "+(S?"bg-[var(--color-brand-subtle)] text-brand-default":"bg-transparent text-text-secondary hover:text-text-primary"),"aria-pressed":S,children:j},j)})}),e.jsx("button",{type:"button",onClick:l,"aria-label":"Close chart panel",className:"cursor-pointer rounded-[4px] border border-[var(--color-border-strong)] bg-transparent px-3 py-1 text-caption text-text-secondary hover:text-text-primary hover:border-[var(--color-border-default)] transition-colors duration-fast ease-out btn-press",children:"ESC"})]})]}),e.jsx("div",{className:"flex flex-1 flex-col gap-1 min-h-0",children:M})]});const N=e.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col bg-black/70 backdrop-blur-[10px]",onClick:l,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 text-body-sm text-[var(--color-text-primary)]",onClick:j=>j.stopPropagation(),children:[e.jsxs("span",{children:[t.symbol," ",t.interval," — ",t.candles.length," candles"]}),e.jsx("button",{className:"cursor-pointer rounded-[2px] border border-[rgba(121,121,121,0.15)] bg-transparent px-3 py-1 text-caption text-[var(--color-text-primary)]",onClick:l,children:"ESC"})]}),e.jsx("div",{className:"flex flex-1 flex-col gap-1 px-2 pb-2",onClick:j=>j.stopPropagation(),children:M})]});return he.createPortal(N,document.body)}function Ua({symbol:t}){const{dex:r,base:s}=ct(t);return e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-body-md-medium text-text-primary",children:s}),r&&e.jsx("span",{className:"inline-flex items-center justify-center h-[18px] px-2 rounded-[2px] bg-[rgba(59,247,191,0.08)] text-brand-default text-caption leading-none","aria-label":`HIP-3 dex ${r}`,title:`HIP-3 dex ${r}`,children:r.toUpperCase()})]})}function Za(){return e.jsx("div",{className:"mt-2 w-full cursor-default rounded-[2px] border border-[rgba(121,121,121,0.15)] bg-[#0b1118] [animation:pulse_1.5s_ease-in-out_infinite]",style:{height:Vr}})}const ji=n.memo(function(r){const{symbol:s,interval:o,indicators:a,levels:l,"focus-time":i,"focus-price":c}=r,{data:x,loading:p,error:m}=$r(s,o,a),d=Ma(),[f,u]=n.useState(!1);n.useEffect(()=>{x&&d&&d.set(Ta(s,o,a),x)},[x,d,s,o,a]);const y=n.useRef(null),h=n.useCallback(()=>u(!0),[]),v=n.useCallback(()=>u(!1),[]),g=n.useMemo(()=>Va(l),[l]),b=n.useMemo(()=>Oa(i),[i]),w=n.useMemo(()=>Ha(c),[c]);return n.useEffect(()=>{const C=y.current;if(!C||!x||x.candles.length===0)return;const k=Kr(C,x,Vr,g,b,w,!0);return()=>{k.remove()}},[x,g,b,w]),p?r.headless?e.jsx("div",{className:"w-full h-full bg-[#0b1118]"}):e.jsx(Za,{}):m?e.jsxs("div",{className:"py-2 text-caption text-[var(--color-text-secondary)] opacity-70",children:["Chart unavailable: ",m]}):!x||x.candles.length===0?null:r.headless?e.jsx(nt,{data:x,extraLevels:g,focusTime:b,focusPrice:w,onClose:()=>{},mode:"headless"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mt-2 w-full cursor-pointer",onClick:h,role:"button",tabIndex:0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&h()},children:[e.jsx("div",{ref:y,className:"w-full overflow-hidden rounded-[2px] border border-[rgba(121,121,121,0.12)]"}),e.jsxs("div",{className:"pointer-events-none absolute top-2 right-2 z-10 flex items-center gap-1 rounded-[2px] border border-[rgba(121,121,121,0.15)] bg-[rgba(11,17,24,0.8)] px-2 py-1 text-footnote text-[var(--color-text-secondary)]",children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}),e.jsx("span",{children:"Expand"})]})]}),f&&e.jsx(nt,{data:x,extraLevels:g,focusTime:b,focusPrice:w,onClose:v})]})}),qa="4h",qe=351;function Ga({children:t}){const[r,s]=n.useState(null),o=n.useCallback(i=>s(i),[]),a=n.useCallback(()=>s(null),[]),l=us();return n.useEffect(()=>{s(null)},[l.pathname]),e.jsx(Nr.Provider,{value:{request:r,open:o,close:a},children:t})}function Ka(){var p,m,d;const t=it(),r=((p=t==null?void 0:t.request)==null?void 0:p.symbol)??null,s=((m=t==null?void 0:t.request)==null?void 0:m.interval)??qa,o=(d=t==null?void 0:t.request)==null?void 0:d.focus,[a,l]=n.useState(s);n.useEffect(()=>{l(s)},[r,s]);const i=(o==null?void 0:o.kind)==="indicator"?o.name:void 0,{data:c,error:x}=$r(r??"",a,i);return n.useEffect(()=>{if(!(t!=null&&t.request))return;const f=u=>{u.key==="Escape"&&t.close()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[t]),!(t!=null&&t.request)||!r?null:x&&!c?e.jsx("div",{className:"relative flex items-center justify-center bg-[var(--color-surface-base)] border-t border-b border-[var(--color-border-subtle)]",style:{height:qe},children:e.jsx("span",{className:"text-[var(--color-error-text)] text-caption",children:x})}):c?e.jsx(nt,{mode:"panel",panelHeight:qe,data:c,extraLevels:[],focusTime:null,focusPrice:null,focus:o,interval:a,onIntervalChange:l,onClose:t.close}):e.jsx("div",{className:"relative flex items-center justify-center bg-[var(--color-surface-base)] border-t border-b border-[var(--color-border-subtle)]",style:{height:qe},children:e.jsxs("span",{className:"text-text-secondary text-caption",children:["Loading ",r,"…"]})})}function Xa(){const{connected:t,request:r}=te(),[s,o]=n.useState(null);return n.useEffect(()=>{if(!t)return;let a=!1;return r("status").then(l=>{a||o(l.model)}).catch(()=>{}),()=>{a=!0}},[t,r]),s}function Ja(){return e.jsx("svg",{width:"7",height:"11",viewBox:"0 0 7 11",fill:"none","aria-hidden":"true",className:"shrink-0",children:e.jsx("path",{d:"M1.42871 7.52148C2.21729 7.52172 2.85645 8.16156 2.85645 8.9502C2.85633 9.73873 2.21722 10.3777 1.42871 10.3779C0.639995 10.3779 0.000113696 9.73888 0 8.9502C0 8.16142 0.639925 7.52148 1.42871 7.52148ZM5.18945 7.52148C5.97815 7.52159 6.61719 8.16148 6.61719 8.9502C6.61707 9.73881 5.97808 10.3778 5.18945 10.3779C4.40074 10.3779 3.76086 9.73888 3.76074 8.9502C3.76074 8.16142 4.40067 7.52148 5.18945 7.52148ZM1.42871 3.76074C2.21729 3.76098 2.85645 4.40082 2.85645 5.18945C2.85633 5.97799 2.21722 6.61695 1.42871 6.61719C0.639995 6.61719 0.000114212 5.97814 0 5.18945C0 4.40067 0.639925 3.76074 1.42871 3.76074ZM5.18945 3.76074C5.97815 3.76084 6.61719 4.40074 6.61719 5.18945C6.61707 5.97807 5.97808 6.61708 5.18945 6.61719C4.40074 6.61719 3.76086 5.97814 3.76074 5.18945C3.76074 4.40067 4.40067 3.76074 5.18945 3.76074ZM1.42871 0C2.21711 0.000263058 2.85619 0.639337 2.85645 1.42773C2.85645 2.21635 2.21727 2.85618 1.42871 2.85645C0.639925 2.85645 0 2.21651 0 1.42773C0.000257835 0.639174 0.640084 0 1.42871 0ZM5.18945 0C5.97815 0.000102745 6.61719 0.639995 6.61719 1.42871C6.61694 2.21721 5.978 2.85634 5.18945 2.85645C4.40082 2.85645 3.76099 2.21728 3.76074 1.42871C3.76074 0.639931 4.40067 0 5.18945 0Z",fill:"#3BF7BF"})})}function Ya(){const t=Xa(),r=it(),s=(r==null?void 0:r.request)!=null;return e.jsx(ka,{children:e.jsx(Sa,{children:e.jsxs("div",{className:"flex flex-col h-[100dvh] overflow-hidden bg-[var(--color-surface-canvas)] text-[var(--color-text-primary)]",children:[e.jsx(ja,{}),e.jsxs("div",{className:"flex flex-1 min-h-0",children:[e.jsx(Xt,{position:"left"}),e.jsxs("div",{className:"relative flex flex-1 min-w-0",children:[e.jsxs("main",{className:"flex-1 min-w-0 flex flex-col overflow-hidden border-t border-l border-r border-[var(--color-border-subtle)]",children:[e.jsx(Ka,{}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:e.jsx(xs,{})})]}),e.jsxs("div",{className:"absolute left-0 -top-[9px] z-30 flex items-center gap-[2px]",children:[e.jsxs("div",{"aria-hidden":"true",className:"pointer-events-none inline-flex items-center gap-2 px-[7px] h-[18px] rounded-[4px] bg-[#2a2c31] text-text-primary text-label-sm leading-none font-sans",children:[e.jsx(Ja,{}),"GHOST :/ ",t??"…"]}),s&&e.jsxs("button",{type:"button",onClick:()=>r==null?void 0:r.close(),"aria-label":"Close trading view",className:"btn-press inline-flex items-center gap-2 pl-2 pr-1.5 h-[18px] rounded-[4px] bg-[#2a2c31] text-text-primary text-label-sm leading-none font-sans cursor-pointer transition-colors duration-fast ease-out hover:bg-[#3a3c42]",children:["Trading view",e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M1.5 1.5L8.5 8.5M8.5 1.5L1.5 8.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})]})]})]}),e.jsx(Xt,{position:"right"})]})]})})})}function Qa({children:t}){const r=Ns();return ur.createElement(pr.Provider,{value:r},t)}function be(t){return t.replace(/<tool_call[\s\S]*?<\/tool_call>/g,"").replace(/<tool_use[\s\S]*?<\/tool_use>/g,"").replace(/<tool_result[\s\S]*?<\/tool_result>/g,"").replace(/<\/?tool_(?:call|use|result)[^>]*>/g,"").replace(/\[(?:mcp__ghost__)?ghost_\w+[^\]]*\]/g,"").trim()}function Ge(t){if(typeof t=="string")return t;if(!Array.isArray(t))return"";const r=[];for(const s of t)typeof s=="string"?r.push(s):s&&typeof s=="object"&&"text"in s&&r.push(String(s.text));return r.join("")}function el(t){if(!Array.isArray(t))return[];const r=[];for(const s of t)if(s&&typeof s=="object"&&"type"in s){const o=s;o.type==="toolCall"&&typeof o.id=="string"&&typeof o.name=="string"&&r.push(o)}return r}function tl(t){try{const r=typeof t=="string"?t:JSON.stringify(t);return r.length>80?r.slice(0,80)+"…":r}catch{return""}}function rl(t){try{return typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return String(t)}}function sl(t,r=!1){const s=[],o=new Map;for(const l of t)if(l.role==="toolResult"){const i=l;o.set(i.toolCallId,i)}let a=[];for(const l of t)if(l.role==="user"){const i=Ge(l.content).trim();if(!i)continue;s.push({id:crypto.randomUUID(),role:"user",content:i,timestamp:l.timestamp?new Date(l.timestamp):new Date})}else if(l.role==="assistant"){const i=be(Ge(l.content)),c=r?el(l.content):[];if(c.length>0){const m=c.map(d=>{const f=o.get(d.id);return{toolCallId:d.id,name:d.name,argsHint:tl(d.arguments),argsFull:rl(d.arguments),result:f?Ge(f.content):void 0,success:f?!f.isError:void 0,status:"done"}});a.push(...m)}if(!i)continue;const x=s[s.length-1];if((x==null?void 0:x.role)==="assistant"&&x.content===i)continue;const p=r&&a.length>0?[...a]:void 0;a=[],s.push({id:l.id??crypto.randomUUID(),role:"assistant",content:i,timestamp:l.timestamp?new Date(l.timestamp):new Date,toolCalls:p})}return s}const nl=["AUTH_FAILED","RATE_LIMITED","CONTEXT_OVERFLOW","PROVIDER_DOWN","TOOL_BLOCKED","UNKNOWN"];function ol(t){return typeof t=="string"&&nl.includes(t)}function al(t){switch(t){case"RATE_LIMITED":return"I'm being rate-limited right now — give me a moment and try again";case"PROVIDER_DOWN":return"I can't reach the model right now — looks like a connectivity hiccup";case"TOOL_BLOCKED":return"I can't run that — security policy is blocking it";case"AUTH_FAILED":return"Your API key isn't working — please check it and I'll try again";case"CONTEXT_OVERFLOW":return"We've talked too much for me to keep track — let's start a new session";case"UNKNOWN":default:return"Something tripped me up — mind retrying?"}}function Ie(t){t.streamRef.current=[],t.toolCallsRef.current=new Map,t.setChatRunId(null),t.chatRunIdRef.current=null,t.setChatSending(!1),t.setActiveToolCalls([]),t.setThinkingPhase(null),t.setThinkingDetail(null)}function ue(t){t.streamingRafRef.current&&(cancelAnimationFrame(t.streamingRafRef.current),t.streamingRafRef.current=null),t.streamingMsgIdRef.current=null,t.streamingTextRef.current=""}function ll(t){const r=n.useRef(t);r.current=t;const s=n.useRef(""),o=n.useRef(""),a=n.useRef(null),l=n.useRef(null),i=n.useRef(""),c=n.useRef(null),x={streamingRafRef:c,streamingMsgIdRef:l,streamingTextRef:i};function p(m,d,f){const{streaming:u,...y}=m;return{...y,content:d,...f?{toolCalls:f}:{}}}n.useEffect(()=>{const m=t.subscribe(d=>{const f=r.current,u=d.payload,y=u==null?void 0:u.runId;if(!(y&&f.chatRunIdRef.current&&y!==f.chatRunIdRef.current))switch(d.event){case"chat.delta":{const h=String((u==null?void 0:u.delta)??"");f.streamRef.current.push(h),o.current+=h,i.current+=h,l.current||(f.setThinkingPhase(null),f.setThinkingDetail(null),l.current=crypto.randomUUID(),f.setMessages(v=>[...v,{id:l.current,role:"assistant",content:"",timestamp:new Date,streaming:!0}])),c.current||(c.current=requestAnimationFrame(()=>{c.current=null;const v=l.current;if(v){const g=i.current;f.setMessages(b=>b.map(w=>w.id===v?{...w,content:g}:w))}}));break}case"chat.turn":{const h=l.current,v=i.current;if(ue(x),h){const g=be(v);g?f.setMessages(b=>b.map(w=>w.id===h?p(w,g):w)):f.setMessages(b=>b.filter(w=>w.id!==h))}s.current=o.current,f.streamRef.current=[];break}case"chat.tool_call":{const h=String((u==null?void 0:u.name)??""),v=h.replace(/^mcp__ghost__/,"").replace(/^ghost_/,"");if(f.setThinkingPhase("fetching"),f.setThinkingDetail(v),!f.showToolCalls)break;const g={toolCallId:String((u==null?void 0:u.toolCallId)??""),name:h,argsHint:String((u==null?void 0:u.argsHint)??""),argsFull:u==null?void 0:u.argsFull,status:"running"};f.toolCallsRef.current.set(g.toolCallId,g),f.setActiveToolCalls([...f.toolCallsRef.current.values()]);break}case"chat.tool_result":{f.setThinkingPhase("analyzing"),f.setThinkingDetail(null);const h=String((u==null?void 0:u.toolCallId)??""),v=u==null?void 0:u.success,g=a.current;if(g){const w=v===!1?"failed":"executed";a.current=null,f.setMessages(C=>C.map(k=>k.id===g?{...k,status:w}:k))}if(!f.showToolCalls)break;const b=f.toolCallsRef.current.get(h);if(b){const w={...b,success:v,durationSecs:u==null?void 0:u.durationSecs,result:u==null?void 0:u.result,status:"done"};f.toolCallsRef.current.set(h,w),f.setActiveToolCalls([...f.toolCallsRef.current.values()])}break}case"chat.done":{if(f.suppressResponseRef.current){f.suppressResponseRef.current=!1;const w=l.current;ue(x),w&&f.setMessages(C=>C.filter(k=>k.id!==w)),s.current="",o.current="",Ie(f);break}const h=l.current;ue(x);let v=be(String((u==null?void 0:u.response)??f.streamRef.current.join("")));const g=be(s.current);g&&v.startsWith(g)&&(v=v.slice(g.length).trim()),s.current="",o.current="";const b=f.showToolCalls&&f.toolCallsRef.current.size>0?[...f.toolCallsRef.current.values()]:void 0;h&&v?f.setMessages(w=>w.map(C=>C.id===h?p(C,v,b):C)):h&&!v?f.setMessages(w=>w.filter(C=>C.id!==h)):v&&f.setMessages(w=>[...w,{id:crypto.randomUUID(),role:"assistant",content:v,timestamp:new Date,toolCalls:b}]),Ie(f),f.loadSessions(),setTimeout(f.flushQueue,0);break}case"chat.error":{const h=l.current;ue(x),h&&f.setMessages(b=>b.filter(w=>w.id!==h)),s.current="",o.current="";const v=u==null?void 0:u.errorType;let g;v==null?g=void 0:ol(v)?g=v:(console.warn("[useChatEvents] unknown errorType from backend, falling back to UNKNOWN copy:",v),g="UNKNOWN"),f.setMessages(b=>[...b,{id:crypto.randomUUID(),role:"assistant",content:al(g),timestamp:new Date,type:"error"}]),Ie(f);break}case"chat.proactive":{const h=String((u==null?void 0:u.content)??""),v=String((u==null?void 0:u.id)??`proactive-${crypto.randomUUID()}`);if(!h)break;f.setMessages(g=>g.some(b=>b.id===v)?g:[...g,{id:v,role:"assistant",content:h,timestamp:new Date}]);break}case"chat.aborted":{const h=l.current;ue(x),h&&f.setMessages(v=>v.filter(g=>g.id!==h)),s.current="",o.current="",Ie(f);break}case"trading.approval.requested":{const h=u==null?void 0:u.preview,v=u==null?void 0:u.approvalId;if(h&&v){const g=l.current;ue(x);const b=f.streamRef.current.join(""),w=(u==null?void 0:u.preText)??"",C=w.length>b.length?w:b,k=be(C);s.current=o.current,f.streamRef.current=[],g&&k&&f.setMessages(E=>E.map(M=>M.id===g?p(M,k):M)),f.setMessages(E=>{const M=[...E];return k&&!g&&M.push({id:crypto.randomUUID(),role:"assistant",content:k,timestamp:new Date}),M.push({id:v,role:"assistant",content:h.summary??"",timestamp:new Date,type:"confirmation",data:{...h,approvalId:v},status:"pending"}),M})}break}case"trading.approval.resolved":{const h=u==null?void 0:u.approvalId,v=u==null?void 0:u.decision;h&&v==="approved"?(a.current=h,f.setMessages(g=>g.map(b=>b.id===h?{...b,status:"executing"}:b))):h&&v==="rejected"?f.setMessages(g=>g.map(b=>b.id===h?{...b,status:"rejected"}:b)):h&&v==="expired"&&(f.suppressResponseRef.current=!0,f.setMessages(g=>g.map(b=>b.id===h?{...b,status:"expired"}:b)));break}case"mcp.tool_result":{const h=a.current;if(h){const g=(u==null?void 0:u.success)===!1?"failed":"executed";a.current=null,f.setMessages(b=>b.map(w=>w.id===h?{...w,status:g}:w))}break}case"wallet.changed":{window.dispatchEvent(new Event("ghost-wallet-changed"));break}case"tool.approval.requested":{const h=u==null?void 0:u.preview,v=u==null?void 0:u.approvalId;if(h&&v){const g=l.current;ue(x);const b=f.streamRef.current.join(""),w=be(b);s.current=o.current,f.streamRef.current=[],g&&w&&f.setMessages(C=>C.map(k=>k.id===g?p(k,w):k)),f.setMessages(C=>{const k=[...C];return w&&!g&&k.push({id:crypto.randomUUID(),role:"assistant",content:w,timestamp:new Date}),k.push({id:v,role:"assistant",content:h.summary??"",timestamp:new Date,type:"confirmation",data:{...h,approvalId:v},status:"pending"}),k})}break}case"tool.approval.resolved":{const h=u==null?void 0:u.approvalId,v=u==null?void 0:u.decision;h&&v==="approved"?f.setMessages(g=>g.map(b=>b.id===h?{...b,status:"approved"}:b)):h&&f.setMessages(g=>g.map(b=>b.id===h?{...b,status:"rejected"}:b));break}}});return()=>{m(),ue(x)}},[t.subscribe])}const il=new Set(["/stop","stop","abort","esc"]);function cl(){const{request:t,connected:r,subscribe:s,client:o}=te(),[a,l]=n.useState([]),[i,c]=n.useState(null),[x,p]=n.useState(!1),[m,d]=n.useState("default"),[f,u]=n.useState([]),[y,h]=n.useState(!1),[v,g]=n.useState(!1),[b,w]=n.useState([]),[C,k]=n.useState([]),[E,M]=n.useState(!1),[N,j]=n.useState(!1),S=n.useRef(!1);r&&(S.current=!0);const R=!r&&S.current,[P,$]=n.useState(!1),[L,I]=n.useState(!1),[W,T]=n.useState(null),[A,B]=n.useState(null),Z=n.useRef(null),J=n.useRef(null),O=n.useRef(null),V=n.useRef(m),z=n.useRef([]),K=n.useRef([]),se=n.useRef(new Map),G=n.useRef(!1);O.current=i,V.current=m,z.current=b;const Q=n.useRef(null),ne=n.useCallback(()=>{const H=J.current;if(!H)return;const U=H.scrollHeight-H.scrollTop-H.clientHeight<100;$(!U),U&&I(!1)},[]),Y=n.useCallback(H=>{Q.current!==null&&cancelAnimationFrame(Q.current),Q.current=requestAnimationFrame(()=>{var U;Q.current=null,(U=Z.current)==null||U.scrollIntoView({behavior:H?"smooth":"auto"})})},[]),re=n.useCallback(()=>{Y(!0),$(!1),I(!1)},[Y]);n.useEffect(()=>{const H=J.current;if(H)return H.addEventListener("scroll",ne),()=>H.removeEventListener("scroll",ne)},[ne]),n.useEffect(()=>()=>{Q.current!==null&&cancelAnimationFrame(Q.current)},[]);const F=n.useRef(a.length);n.useEffect(()=>{const H=F.current;if(F.current=a.length,!P){Y(!1);return}a.length>H&&I(!0)},[a,P,Y]);const _=n.useCallback(()=>{r&&t("sessions.list",{limit:100}).then(H=>u(H.sessions)).catch(()=>{})},[r,t]),D=n.useCallback(H=>{l(U=>[...U,{id:crypto.randomUUID(),role:"assistant",content:H,timestamp:new Date,type:"error"}])},[]),q=n.useRef(E);q.current=E;const X=n.useCallback(H=>{r&&(g(!0),t("chat.history",{sessionKey:H,limit:200}).then(U=>{l(sl(U.messages,q.current)),g(!1)}).catch(U=>{console.warn("Failed to load history:",U),g(!1)}))},[r,t]);n.useEffect(()=>{r&&(X(m),_(),t("status").then(H=>{typeof H.showToolCalls=="boolean"&&M(H.showToolCalls),typeof H.paperMode=="boolean"&&j(H.paperMode)}).catch(()=>{}))},[r]);const ee=n.useCallback(H=>{const U=H.trim();if(!U||!r)return;l(fe=>[...fe,{id:crypto.randomUUID(),role:"user",content:U,timestamp:new Date}]),K.current=[],p(!0);const oe=crypto.randomUUID();c(oe),O.current=oe,T("thinking"),B(null),t("chat.send",{message:U,sessionKey:V.current,idempotencyKey:oe}).then(()=>p(!1)).catch(()=>{p(!1),c(null),O.current=null,T(null),B(null),D("I couldn't send that — let me put it back in the queue and you can try again"),w(fe=>[...fe,{id:crypto.randomUUID(),text:U}])})},[r,t,D]),le=n.useCallback(()=>{const H=z.current;H.length!==0&&(w(U=>U.slice(1)),ee(H[0].text))},[ee]),Yr=n.useCallback(H=>{w(U=>U.filter(oe=>oe.id!==H))},[]),Qr=n.useCallback(H=>{const U=H.trim();if(!(!U||!r)){if(il.has(U.toLowerCase())){t("chat.abort",{runId:O.current??void 0}).catch(oe=>{console.warn("Failed to abort:",oe)});return}if(O.current!==null||x){w(oe=>[...oe,{id:crypto.randomUUID(),text:U}]);return}ee(U)}},[r,t,x,ee]),es=n.useCallback(()=>{t("chat.abort",{runId:O.current??void 0}).catch(()=>{})},[t]),ts=n.useCallback(()=>{o&&(o.stop(),o.start())},[o]);ll({subscribe:s,chatRunIdRef:O,streamRef:K,toolCallsRef:se,suppressResponseRef:G,setMessages:l,setChatRunId:c,setChatSending:p,setActiveToolCalls:k,setThinkingPhase:T,setThinkingDetail:B,loadSessions:_,flushQueue:le,showToolCalls:E});const rs=n.useCallback(H=>{if(H===m){h(!1);return}l([]),K.current=[],se.current=new Map,k([]),c(null),O.current=null,p(!1),T(null),B(null),w([]),d(H),V.current=H,h(!1),X(H)},[m,X]),Se=n.useCallback((H,U,oe)=>{var gt;if(!r)return;const fe=a.find(vt=>vt.id===H),ls=((gt=fe==null?void 0:fe.data)==null?void 0:gt.action)??"",is=["exec","read_file","write_file","edit_file"].includes(ls)?"tool.approval.resolve":"trading.approval.resolve",bt={approvalId:H,decision:U};U==="rejected"&&oe&&oe.length>0&&(bt.reason=oe),t(is,bt).catch(()=>{D(`I couldn't ${U==="approved"?"approve":"reject"} that — try again in a moment`)})},[r,t,a,D]),ss=n.useCallback(H=>{Se(H,"approved")},[Se]),ns=n.useCallback((H,U)=>{Se(H,"rejected",U)},[Se]),os=i!==null||x,as=a.length===0&&!i&&!v;return{messages:a,chatRunId:i,sessionKey:m,sessions:f,sessionDropdownOpen:y,setSessionDropdownOpen:h,sessionLoading:v,queue:b,activeToolCalls:C,userScrolledUp:P,hasNewContent:L,thinkingPhase:W,thinkingDetail:A,messagesEndRef:Z,scrollContainerRef:J,scrollToBottom:re,handleSend:Qr,handleAbort:es,handleReconnect:ts,handleApprove:ss,handleReject:ns,switchSession:rs,removeFromQueue:Yr,connected:r,disconnected:R,isBusy:os,showEmptyState:as,paperMode:N}}function dl({commands:t,selectedIndex:r,onSelect:s}){const o=n.useRef(null);return n.useEffect(()=>{var l;const a=(l=o.current)==null?void 0:l.children[r];a==null||a.scrollIntoView({block:"nearest"})},[r]),t.length===0?null:e.jsx("div",{ref:o,className:"absolute bottom-full left-0 right-0 mb-1.5 bg-[var(--color-surface-base)] border border-[var(--color-border-default)] rounded-[4px] overflow-y-auto max-h-60 z-10 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:t.map((a,l)=>{const i=l===r;return e.jsxs("div",{className:"flex items-center gap-3 px-3.5 py-2 cursor-pointer transition-colors duration-fast ease-out "+(i?"bg-[var(--color-brand-subtle)] text-white":"bg-transparent text-[var(--color-text-secondary)]"),onMouseDown:c=>{c.preventDefault(),s(a.cmd)},children:[e.jsx("span",{className:"text-body-sm-medium text-[var(--color-brand-default)]",children:a.cmd}),e.jsx("span",{className:"text-caption text-[var(--color-text-secondary)]",children:a.desc})]},a.cmd)})})}const ul=[{cmd:"/news",desc:"Latest crypto news summary"},{cmd:"/analyze",desc:"Analyze current market"},{cmd:"/alerts",desc:"List active price alerts"},{cmd:"/help",desc:"Show available commands"}],xl=new Set(["/news","/analyze","/alerts","/help"]);function fl(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function pl(t){var s;switch((s=t.trim().split(/\s+/)[0])==null?void 0:s.toLowerCase()){case"/news":return"Summarize the latest crypto news";case"/analyze":return"Analyze the current market";case"/alerts":return"List my active price alerts with current price and distance to target.";case"/help":return"What commands and features are available?";default:return null}}const hl="w-full bg-transparent border-none p-0 text-text-primary text-body-md outline-none resize-none min-h-[21px] max-h-[160px] box-border block leading-[1.5]",ml="absolute top-0 left-0 right-0 text-text-tertiary text-body-md leading-[1.5] pointer-events-none whitespace-nowrap overflow-hidden text-ellipsis";function bl({onSend:t,disabled:r,placeholder:s,isBusy:o,onAbort:a}){const[l,i]=n.useState(""),[c,x]=n.useState(!1),[p,m]=n.useState(0),[d,f]=n.useState(!1),u=n.useRef(!1),y=n.useRef(null),h=l.startsWith("/")&&c&&!d?ul.filter(L=>L.cmd.startsWith(l.split(/\s/)[0]??"")):[],v=n.useCallback(L=>{const I=L.trim();if(!I||r)return;const W=I.startsWith("/")?pl(I):null;t(W??I),i(""),m(0),f(!1)},[r,t]),g=n.useCallback(L=>{var I;xl.has(L)?v(L):(i(L+" "),f(!0),m(0),(I=y.current)==null||I.focus())},[v]),b=L=>{if(h.length>0){if(L.key==="ArrowUp"){L.preventDefault(),m(I=>I>0?I-1:h.length-1);return}if(L.key==="ArrowDown"){L.preventDefault(),m(I=>I<h.length-1?I+1:0);return}if(L.key==="Tab"){L.preventDefault();const I=h[p];I&&g(I.cmd);return}if(L.key==="Enter"&&!L.shiftKey&&!u.current){L.preventDefault();const I=h[p];I&&g(I.cmd);return}if(L.key==="Escape"){f(!0);return}}L.key==="Enter"&&!L.shiftKey&&!u.current&&(L.preventDefault(),v(l)),L.key==="Escape"&&o&&a()},w=L=>{i(L.target.value),m(0),f(!1);const I=L.target;I.style.height="auto",I.style.height=`${Math.min(I.scrollHeight,160)}px`};n.useEffect(()=>{!l&&y.current&&(y.current.style.height="auto")},[l]),n.useEffect(()=>{var L;r||(L=y.current)==null||L.focus()},[r]);const C=!r&&l.trim().length>0,k=!l,E=!r,[M,N]=n.useState(""),[j,S]=n.useState(!1),R=n.useRef(s);n.useEffect(()=>{s!==R.current&&(R.current=s,N(""),S(!1))},[s]),n.useEffect(()=>{if(!E||j)return;if(fl()){N(s),S(!0);return}if(M.length>=s.length){S(!0);return}const L=30+Math.random()*25,I=setTimeout(()=>{N(s.slice(0,M.length+1))},L);return()=>clearTimeout(I)},[M,s,j,E]);const P=E?M:s,$=E&&!j&&k;return e.jsx("div",{className:"flex justify-center px-4 pt-2 pb-4 bg-[var(--color-surface-scrim)]",children:e.jsxs("div",{className:"relative w-full max-w-[800px] bg-surface-overlay rounded-[9px] border border-[rgba(59,247,191,0.18)] shadow-[0_1px_8px_rgba(0,0,0,0.45)] flex flex-col gap-3 px-5 py-[14px] transition-opacity duration-base ease-out",style:{opacity:r?.6:1},children:[h.length>0&&e.jsx(dl,{commands:h,selectedIndex:p,onSelect:g}),e.jsxs("div",{className:"relative",children:[e.jsx("label",{htmlFor:"chat-input-textarea",className:"sr-only",children:"Message"}),e.jsx("textarea",{id:"chat-input-textarea",ref:y,value:l,onChange:w,onKeyDown:b,onCompositionStart:()=>{u.current=!0},onCompositionEnd:()=>{u.current=!1},onFocus:()=>x(!0),onBlur:()=>x(!1),disabled:r,rows:1,"aria-label":"Message",className:hl}),k&&e.jsxs("div",{className:ml,"aria-hidden":"true",children:[e.jsx("span",{children:P}),$&&e.jsx("span",{"data-blink":!0,className:"opacity-60",style:{animation:"blink 1s step-end infinite"},children:"|"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-number-sm text-text-tertiary select-none",children:"Type / for commands"}),o?e.jsx("button",{type:"button",onClick:a,"aria-label":"Stop response",className:"btn-press inline-flex items-center justify-center w-[30px] h-[30px] rounded-full bg-error-soft text-error-text hover:bg-error-default hover:text-white focus-visible:bg-error-default focus-visible:text-white transition-colors duration-fast ease-out cursor-pointer",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}):e.jsx("button",{type:"button",onClick:()=>v(l),disabled:!C,"aria-label":"Send message",className:"btn-press inline-flex items-center justify-center w-[30px] h-[30px] rounded-full transition-colors duration-fast ease-out "+(C?"bg-brand-default text-text-on-brand hover:bg-[var(--color-brand-hover)] focus-visible:bg-[var(--color-brand-hover)] cursor-pointer":"bg-surface-raised text-text-tertiary cursor-default opacity-60"),children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})})}const gl="/_app/assets/welcome-illustration-B8_SJ7In.svg",Xr=["What can you do?","Analyze BTC market","Latest crypto news"],vl=["Connect Hyperliquid account",...Xr];function yl({onSelect:t,suggestions:r,hasWallet:s}){const o=r??(s?Xr:vl);return e.jsx("div",{className:"flex flex-wrap gap-2.5",children:o.map((a,l)=>{const i=l===0;return e.jsx("button",{onClick:()=>t(a),className:"bg-transparent rounded-[4px] h-7 px-3.5 inline-flex items-center justify-center text-body-sm text-[var(--color-text-secondary)] cursor-pointer transition-colors duration-fast ease-out "+(i?"border border-[rgba(45,51,59,0.5)] hover:bg-white/[0.04] focus-visible:bg-white/[0.04]":"border border-[var(--color-border-subtle)] hover:bg-white/[0.04] focus-visible:bg-white/[0.04]"),children:a},a)})})}const wl=["Market analysis","News insights","Trade execution"];function Cl({hasWallet:t}){const r=t?"Your AI companion for HyperLiquid perpetual trading. Ask about crypto markets, get news summaries, or explore trading strategies.":"Start by connecting your Hyperliquid wallet to unlock the full experience, or ask about crypto markets and latest news.";return e.jsxs("div",{className:"flex flex-col items-center gap-8 py-10 px-5",children:[e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("img",{src:gl,alt:"",width:334,height:225,className:"block select-none",draggable:!1,"aria-hidden":"true"}),e.jsx("p",{className:"text-heading-md text-text-primary whitespace-nowrap",children:"Ghost is ready"})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("p",{className:"text-body-md text-[#7f8b99] text-center max-w-[620px]",children:r}),e.jsx("div",{className:"flex items-center gap-6",children:wl.map(s=>e.jsx(jl,{label:s},s))})]})]})}function jl({label:t}){return e.jsxs("span",{className:"flex items-center gap-1.5 text-body-sm text-[#7f8b99] whitespace-nowrap",children:[e.jsx("span",{className:"w-[5px] h-[5px] rounded-full bg-brand-default flex-shrink-0","aria-hidden":"true"}),t]})}const Nl=[{test:/not connected|connection closed|websocket/i,message:"Ghost is not running — please start Ghost first"},{test:/coingecko.*rate|coingecko.*429/i,message:"CoinGecko rate limit — wait a minute"},{test:/hyperliquid.*429|hyperliquid.*rate|hyperliquid.*too many/i,message:"Hyperliquid rate limit — try again shortly"},{test:/openrouter.*429|openrouter.*rate/i,message:"OpenRouter rate limit — try again shortly"},{test:/anthropic.*429|anthropic.*rate|anthropic.*overloaded/i,message:"Anthropic rate limit — try again shortly"},{test:/openai.*429|openai.*rate/i,message:"OpenAI rate limit — try again shortly"},{test:/google.*429|google.*rate/i,message:"Google rate limit — try again shortly"},{test:/Rate limit exceeded/i,message:"Too many requests — try again in a moment"},{test:/429|rate.?limit|too many/i,message:"Rate limit hit — try again shortly"},{test:/overloaded/i,message:"AI provider overloaded — try again shortly"},{test:/insufficient.*credit|quota.*exceeded|billing/i,message:"AI provider quota exceeded — check your API credits"},{test:/invalid.*api.?key|invalid.*key/i,message:"Invalid API key — check provider settings"},{test:/model.*not.*found|model.*unavailable/i,message:"Model not available — check provider settings"},{test:/500|internal/i,message:"Internal error — try again or restart Ghost"},{test:/503|service unavailable/i,message:"Service unavailable — try again in a moment"},{test:/unauthorized|session expired/i,message:"Session expired — please refresh"},{test:/timeout/i,message:"Request timed out — try again"},{test:/abort/i,message:"Request was cancelled"}];function kl(t){for(const{test:r,message:s}of Nl)if(r.test(t))return{message:s,detail:t};return{message:"Unexpected error — try again or restart Ghost",detail:t}}function Sl({raw:t,onDismiss:r,onRetry:s}){const[o,a]=n.useState(!1),{message:l,detail:i}=kl(t);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{role:"alert","aria-live":"assertive",className:"px-4 py-2 bg-[rgba(255,71,87,0.06)] border-b border-[rgba(255,71,87,0.3)] flex items-center gap-2 text-body-sm text-[var(--color-error-text)]",style:{animation:"error-banner-slide-in 260ms var(--ease-out, ease-out) both"},children:[e.jsxs("span",{className:"flex-1",children:["⚠ ",l]}),e.jsx("button",{onClick:()=>a(c=>!c),className:"bg-transparent border-none text-[var(--color-text-secondary)] text-footnote cursor-pointer px-1","aria-expanded":o,children:o?"▾ Hide":"▸ Details"}),s&&e.jsx("button",{onClick:s,className:"flex items-center gap-1 px-2 py-1 bg-[rgba(255,71,87,0.08)] border border-[rgba(255,71,87,0.3)] rounded-[4px] text-[var(--color-error-text)] text-footnote cursor-pointer transition-colors duration-fast ease-out hover:bg-[rgba(255,71,87,0.15)] focus-visible:bg-[rgba(255,71,87,0.15)]",children:"↻ Retry"}),r&&e.jsx("button",{onClick:()=>{r(),a(!1)},className:"bg-transparent border-none text-[var(--color-error-text)] cursor-pointer p-1.5","aria-label":"Dismiss error",children:"✕"})]}),o&&e.jsx("div",{className:"text-footnote text-[var(--color-text-secondary)] px-4 pt-1 pb-2 bg-[rgba(255,71,87,0.06)]",children:i})]})}const Ll=n.lazy(()=>ie(()=>import("./mermaid-GHXKKRXX-BvdvTI5r.js").then(t=>t.S),__vite__mapDeps([0,1,2,3])).then(t=>({default:t.StreamingMarkdown})));function El({content:t}){return e.jsx("div",{className:"chat-md",children:e.jsx("p",{className:"whitespace-pre-wrap",children:t})})}function Ml(t){return e.jsx(n.Suspense,{fallback:e.jsx(El,{content:t.content}),children:e.jsx(Ll,{...t})})}function Tl(t){const s=/\b(long|short)\s+([A-Za-z]{2,10}(?:\s+[A-Za-z]{2,10})?)/i.exec(t);if(!s||s.index===void 0)return t;const o=t.slice(0,s.index),a=t.slice(s.index+s[0].length),l=s[1].toLowerCase()==="long"?"text-[var(--color-success-text)]":"text-[var(--color-error-text)]";return e.jsxs(e.Fragment,{children:[o,e.jsxs("span",{className:l,children:[s[1].charAt(0).toUpperCase()+s[1].slice(1).toLowerCase()," ",s[2].toUpperCase()]}),a]})}function Rl(t){const r=[];if(t.summary&&r.push(t.summary),t.details)for(const[s,o]of Object.entries(t.details))r.push(`${s}: ${typeof o=="number"?o:String(o)}`);if(t.warnings)for(const s of t.warnings)r.push(`⚠ ${s}`);return r}function _l(t){const r=t.actionLabel.trim();return r.endsWith("?")||r.endsWith("?")?r:`${r}?`}function Al({status:t,detail:r}){if(t==="pending"||t==="approved"||t==="rejected")return null;let s,o,a;switch(t){case"executing":s="↻",o="Executing…",a="text-[var(--color-info-text)]";break;case"executed":s="✓",o="Executed",a="text-[var(--color-success-text)]";break;case"failed":s="✕",o="Failed",a="text-[var(--color-error-text)]";break;case"expired":s="⏱",o="Expired",a="text-text-tertiary";break}return e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1",children:[e.jsxs("div",{className:`flex items-center gap-2 text-body-sm-medium ${a}`,children:[e.jsx("span",{"aria-hidden":"true",className:t==="executing"?"inline-block animate-spin":"inline-block",children:s}),e.jsx("span",{children:o})]}),r&&e.jsx("div",{className:`pl-[22px] text-caption text-text-tertiary ${t==="failed"?"italic":""}`,children:r})]})}const Il="bg-surface-raised border border-[var(--color-brand-subtle)] rounded-[var(--radius-fig-sm)] p-5 text-body-md text-text-primary shadow-[0_1px_3px_rgba(0,0,0,0.45)] relative w-full flex flex-col gap-2.5",Fl=n.memo(function({data:r,status:s,onApprove:o,onReject:a}){const l=s==="pending",i=n.useRef(null),c=n.useRef(null),x=n.useRef(null),p=n.useRef(null),[m,d]=n.useState(0),[f,u]=n.useState(""),y=n.useRef(!1),h=r.steps&&r.steps.length>0?r.steps:void 0,v=n.useMemo(()=>r.lines!==void 0?r.lines:h?[]:Rl(r),[r,h]),g=n.useMemo(()=>Tl(_l(r)),[r]);n.useEffect(()=>{if(!l)return;const S=setTimeout(()=>{var R;return(R=x.current)==null?void 0:R.focus()},0);return()=>clearTimeout(S)},[l]);function b(){const S=document.querySelectorAll("[data-confirm-card-pending]");return S.length<=1?!0:S[S.length-1].getAttribute("data-confirm-card-pending")===r.approvalId}function w(S){var R,P;d(S),S===0?(R=x.current)==null||R.focus():(P=p.current)==null||P.focus()}function C(){var S;d(-1),(S=c.current)==null||S.focus()}function k(){y.current||(y.current=!0,o(r.approvalId))}function E(){y.current||(y.current=!0,a(r.approvalId))}function M(){if(y.current)return;const S=f.trim();S.length!==0&&(y.current=!0,a(r.approvalId,S))}function N(S){if(!l||!b())return;if(S.target===c.current){S.key==="Enter"?(S.preventDefault(),M()):S.key==="Escape"&&(S.preventDefault(),u(""),w(0));return}switch(S.key){case"ArrowDown":S.preventDefault(),m===0?w(1):m===1&&C();break;case"ArrowUp":S.preventDefault(),m===1&&w(0);break;case"1":S.preventDefault(),w(0);break;case"2":S.preventDefault(),w(1);break;case"Enter":S.preventDefault(),m===0?k():m===1&&E();break;case"Escape":S.preventDefault(),E();break}}const j=n.useMemo(()=>{if(s==="failed"&&r.warnings&&r.warnings[0])return r.warnings[0]},[s,r.warnings]);return e.jsxs("div",{ref:i,className:Il,role:"region","aria-label":r.actionLabel,"aria-live":"polite","data-confirm-card-pending":l?r.approvalId:void 0,onKeyDown:N,style:{viewTransitionName:`confirm-${r.approvalId}`},children:[e.jsxs("div",{className:`flex items-start justify-between gap-3 ${s==="executing"?"opacity-60":""}`,children:[e.jsx("div",{className:"text-body-md-semibold text-text-primary",children:g}),l&&e.jsx("button",{type:"button","aria-label":"Dismiss",onClick:E,className:"bg-transparent border-none text-text-tertiary hover:text-text-primary cursor-pointer p-0 flex items-center justify-center w-5 h-5 rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--color-border-focus)] focus-visible:outline-offset-2",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(h||v.length>0)&&e.jsxs("ul",{className:`list-none m-0 p-0 pl-4 text-text-primary ${s==="executing"?"opacity-60":""}`,children:[h==null?void 0:h.map((S,R)=>e.jsxs("li",{className:"relative pl-[22px] py-px text-body-sm",children:[e.jsxs("span",{"aria-hidden":"true",className:"absolute left-0 top-0 text-body-sm text-text-primary",children:[R+1,"."]}),S]},`s-${R}`)),v.map((S,R)=>{const P=/^net:|^remaining:/i.test(S);return e.jsxs("li",{className:`relative pl-[14px] py-px text-body-sm ${P?"text-text-tertiary":""}`,children:[e.jsx("span",{"aria-hidden":"true",className:"absolute left-0 top-0 text-body-sm text-text-tertiary",children:"•"}),S]},`l-${R}`)})]}),l?e.jsxs("div",{className:"flex flex-col gap-[11px]",children:[e.jsx(sr,{ref:x,num:1,label:"Confirm",tone:"execute",selected:m===0,onClick:()=>{w(0),k()},onFocus:()=>d(0)}),e.jsx(sr,{ref:p,num:2,label:"Cancel",tone:"cancel",selected:m===1,onClick:()=>{w(1),E()},onFocus:()=>d(1)}),e.jsx(Dl,{inputRef:c,value:f,active:m===-1,onChange:u,onFocus:()=>d(-1)})]}):e.jsx(Al,{status:s,detail:j})]})}),sr=n.forwardRef(function({num:r,label:s,tone:o,selected:a,onClick:l,onFocus:i},c){return e.jsx("div",{ref:c,role:"button",tabIndex:0,"data-confirm-opt":!0,onClick:l,onFocus:i,onKeyDown:p=>{p.key===" "&&(p.preventDefault(),l())},className:"flex h-10 items-center justify-start px-6 cursor-pointer select-none border rounded-[var(--radius-fig-sm)] transition-colors duration-fast ease-out "+"border-[var(--color-border-default)] text-text-primary hover:bg-[var(--color-brand-subtle)] hover:border-[var(--color-brand-subtle)] hover:text-[var(--color-brand-default)] focus:bg-[var(--color-brand-subtle)] focus:border-[var(--color-brand-subtle)] focus:text-[var(--color-brand-default)]",children:e.jsx("span",{className:"text-body-md uppercase",children:s})})});function Dl({inputRef:t,value:r,active:s,onChange:o,onFocus:a}){return e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"15",height:"15",viewBox:"0 0 15 15",fill:"none","aria-hidden":"true",className:"flex-none",children:e.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8.51502 0.586544C9.29548 -0.195096 10.5613 -0.195575 11.3424 0.585473L13.0326 2.27574C13.807 3.05012 13.8151 4.30377 13.0507 5.08804L11.9292 6.23869L7.39688 1.70638L8.51502 0.586544ZM6.33703 2.76784L10.8821 7.31296L5.55501 12.7786C4.99058 13.3577 4.21646 13.6843 3.40811 13.6843L1.4994 13.6842C0.646564 13.6841 -0.0345123 12.9732 0.00135446 12.1205L0.0842832 10.1489C0.115882 9.39771 0.428106 8.68572 0.959173 8.15384L6.33703 2.76784ZM8.27521 13.6225C8.27521 14.0369 8.61087 14.3728 9.02493 14.3728H14.2212C14.6353 14.3728 14.9709 14.0369 14.9709 13.6225C14.9709 13.2082 14.6353 12.8723 14.2212 12.8723H9.02493C8.61087 12.8723 8.27521 13.2082 8.27521 13.6225Z",fill:"var(--color-text-secondary)"})}),e.jsx("input",{ref:t,type:"text",value:r,onChange:l=>o(l.target.value),onFocus:a,placeholder:"Type here to discuss more","aria-label":"Feedback to Ghost",className:"flex-1 bg-transparent border-none outline-none text-body-md text-text-primary placeholder:text-text-tertiary py-0 px-0 caret-[var(--color-brand-default)]"})]})}const nr=300*1e3,Pl={pending:"var(--color-warning-text)",yes:"var(--color-success-text)",no:"var(--color-error-text)",expired:"var(--color-text-muted)"},Bl={pending:"🟡",yes:"✅",no:"❌",expired:"⏱"};function $l(t){if(t<=0)return"0:00";const r=Math.ceil(t/1e3);return`${Math.floor(r/60)}:${(r%60).toString().padStart(2,"0")}`}function Ol({onAction:t}){const[r,s]=n.useState("pending"),[o]=n.useState(Date.now),[a,l]=n.useState(nr),i=r==="pending";n.useEffect(()=>{if(!i)return;const m=setInterval(()=>{const d=Math.max(0,nr-(Date.now()-o));l(d),d<=0&&s("expired")},1e3);return()=>clearInterval(m)},[i,o]),n.useEffect(()=>{if(!i)return;const m=d=>{var u;const f=(u=d.target)==null?void 0:u.tagName;f==="INPUT"||f==="TEXTAREA"||f==="SELECT"||(d.key==="Enter"?(d.preventDefault(),d.stopImmediatePropagation(),s("yes"),t("yes")):d.key==="Escape"&&(d.preventDefault(),d.stopImmediatePropagation(),s("no"),t("no")))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[i,t]);const c=n.useCallback(()=>{i&&(s("yes"),t("yes"))},[i,t]),x=n.useCallback(()=>{i&&(s("no"),t("no"))},[i,t]),p=Pl[r];return e.jsxs("div",{className:"mt-2.5 pt-2.5 border-t border-[rgba(121,121,121,0.15)] flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-caption uppercase tracking-[0.5px]",style:{color:p},children:[e.jsx("span",{children:Bl[r]}),e.jsx("span",{children:i?"Awaiting Confirmation":r==="yes"?"Approved":r==="no"?"Rejected":"Expired"})]}),i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-end gap-2.5",children:[e.jsx("button",{onClick:x,className:"bg-transparent border border-[var(--color-border-default)] rounded-[4px] px-4 py-1.5 text-[var(--color-text-secondary)] text-body-sm-medium cursor-pointer transition-colors duration-base ease-out hover:bg-[var(--color-error-subtle)] hover:border-[rgba(239,68,68,0.3)] hover:text-[var(--color-error-text)] focus-visible:bg-[var(--color-error-subtle)] focus-visible:border-[rgba(239,68,68,0.3)] focus-visible:text-[var(--color-error-text)]",children:"Reject"}),e.jsxs("button",{onClick:c,className:"bg-[var(--color-success-subtle)] border border-[rgba(34,197,94,0.35)] rounded-[4px] px-4 py-1.5 text-[var(--color-success-text)] text-body-sm-medium cursor-pointer transition-colors duration-base ease-out hover:bg-[var(--color-success-soft)] hover:border-[rgba(34,197,94,0.5)] focus-visible:bg-[var(--color-success-soft)] focus-visible:border-[rgba(34,197,94,0.5)]",children:["✓"," Approve"]})]}),e.jsxs("div",{className:"text-footnote text-[var(--color-text-secondary)] text-center",children:["⌨"," Enter to approve · Esc to reject · ",$l(a)," left"]})]}):null]})}const Hl=/Confirm\b.*\?\s*\*{0,2}Yes\s*\/\s*No\*{0,2}\s*$/i;function ot(t){return Hl.test(t)}function Vl(t){return t.replace(/Confirm\b.*\?\s*\*{0,2}Yes\s*\/\s*No\*{0,2}\s*$/i,"").trimEnd()}function Wl(t,r){if(ot(t)&&ot(t))return"var(--color-warning-text)"}function zl(t){return t.status==="running"?"var(--color-warning-text)":t.success?"var(--color-success-text)":"var(--color-error-default)"}function Ul(t){return t.replace(/^mcp__ghost__/,"").replace(/^ghost_/,"")}const Jr=n.memo(function({toolCalls:r,onSelect:s}){return r.length===0?null:e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:r.map(o=>e.jsxs("button",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-[4px] text-caption border border-[var(--color-border-default)] bg-[rgba(15,22,33,0.6)] text-[var(--color-text-secondary)] cursor-pointer transition-colors duration-fast ease-out hover:border-[var(--color-border-strong)] hover:text-[var(--color-text-primary)] focus-visible:border-[var(--color-border-strong)] focus-visible:text-[var(--color-text-primary)]",title:o.argsHint,onClick:()=>s(o),children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:zl(o)}}),e.jsx("span",{children:Ul(o.name)}),o.durationSecs!=null&&e.jsxs("span",{className:"text-footnote text-[var(--color-text-secondary)]",children:[o.durationSecs,"s"]})]},o.toolCallId))})}),Zl=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function or(t){return String(t).padStart(2,"0")}function ql(t){const r=new Date,s=t.getFullYear()===r.getFullYear()&&t.getMonth()===r.getMonth()&&t.getDate()===r.getDate(),o=`${or(t.getHours())}:${or(t.getMinutes())}`;return s?`Today ${o}`:`${Zl[t.getMonth()]} ${t.getDate()} · ${o}`}const Gl=1200,Kl="max-w-[75%] self-end bg-[var(--color-brand-soft)] rounded-[15px_15px_0px_15px] px-4 py-3 text-[15px] leading-[1.5] text-text-primary break-words whitespace-pre-wrap",Xl="max-w-[92%] self-start bg-[var(--color-surface-base)] border border-[var(--color-border-subtle)] rounded-[0px_15px_15px_15px] px-4 py-3 text-[15px] leading-[1.5] text-text-primary break-words",ar="bg-transparent border-none p-1.5 rounded-[4px] flex items-center justify-center cursor-pointer transition-colors duration-fast ease-out",Jl=n.memo(function({message:r,onAction:s,onApprove:o,onReject:a,onToolCallSelect:l,onRetry:i,errorRetryText:c}){const[x,p]=n.useState(!1),m=r.role==="user",d=r.type==="error",f=!m&&!r.type&&s&&ot(r.content),u=f?Vl(r.content):r.content,y=f?Wl(r.content):void 0,h=n.useCallback(()=>{navigator.clipboard.writeText(r.content).then(()=>{p(!0),setTimeout(()=>p(!1),Gl)}).catch(()=>{})},[r.content]),v=n.useCallback(()=>{i&&i(r.content)},[i,r.content]),g=n.useCallback(()=>{i&&c&&i(c)},[i,c]),b=e.jsx("button",{className:`mb-actions ${ar} `+(x?"text-[var(--color-success-text)]":"text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)]"),title:"Copy","aria-label":x?"Copied":"Copy message",onClick:h,children:x?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})},"copy"),w=e.jsx("button",{className:`mb-actions ${ar} text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)]`,title:"Retry","aria-label":"Retry this message",onClick:v,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("polyline",{points:"1 20 1 14 7 14"}),e.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]})},"retry"),C=e.jsx("span",{className:"text-number-sm text-[var(--color-text-secondary)]",children:ql(r.timestamp)},"time");let k;return d?k=[C]:m?k=i?[w,b,C]:[b,C]:k=[C,b],e.jsxs("div",{className:`mb-row message-enter flex flex-col gap-0 ${m?"items-end":"items-start"}`,children:[r.type==="confirmation"&&r.data&&o&&a?e.jsx(Fl,{data:r.data,status:r.status??"pending",onApprove:o,onReject:a}):d?e.jsxs("div",{className:"max-w-[92%] self-start bg-[var(--color-error-subtle)] rounded-[var(--radius-fig-sm)_var(--radius-fig-sm)_var(--radius-fig-sm)_0] px-3.5 py-2.5 flex items-start gap-2.5 text-body-md text-text-primary break-words",style:{borderLeft:"3px solid var(--color-error-default)"},role:"status","aria-live":"polite",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:"flex-none mt-0.5 text-[var(--color-error-text)]",children:[e.jsx("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("span",{className:"flex-1",children:r.content}),i&&c&&e.jsxs("button",{type:"button",onClick:g,className:"flex-none inline-flex items-center gap-1 text-label-sm text-[var(--color-error-text)] hover:text-text-primary focus-visible:text-text-primary bg-transparent hover:bg-[var(--color-error-soft)] focus-visible:bg-[var(--color-error-soft)] border border-[var(--color-error-soft)] hover:border-[var(--color-error-default)] rounded-[var(--radius-fig-sm)] px-2 py-1 cursor-pointer transition-colors duration-fast ease-out btn-press","aria-label":"Retry the previous message",children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("polyline",{points:"1 20 1 14 7 14"}),e.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]}),"Retry"]})]}):e.jsxs("div",{className:m?Kl:Xl,style:y?{borderLeft:`3px solid ${y}`}:void 0,children:[m?r.content:e.jsx(Ml,{content:u,streaming:r.streaming}),f&&s&&e.jsx(Ol,{onAction:s})]}),!m&&r.toolCalls&&r.toolCalls.length>0&&l&&e.jsx(Jr,{toolCalls:r.toolCalls,onSelect:l}),!r.streaming&&r.type!=="confirmation"&&e.jsx("div",{className:`mb-actions flex items-center gap-1.5 mt-0.5 ${m?"self-end":""}`,children:k})]})});function Yl({visible:t,hasNew:r,onClick:s}){if(!t)return null;const o=r?"New message":"Scroll to latest";return e.jsx("button",{type:"button",onClick:s,"aria-label":o,title:o,className:"pointer-events-auto inline-flex items-center justify-center w-7 h-7 rounded-[5px] bg-[var(--color-brand-subtle)] text-[var(--color-brand-default)] cursor-pointer border-none btn-press transition-colors duration-fast ease-out hover:bg-[var(--color-brand-soft)]",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M7.5 12.1875C7.09619 12.1875 6.69239 12.0305 6.38665 11.7222L2.62547 7.93045C2.45818 7.76179 2.45818 7.48264 2.62547 7.31399C2.79276 7.14534 3.06966 7.14534 3.23695 7.31399L6.99813 11.1058C7.27502 11.3849 7.72498 11.3849 8.00187 11.1058L11.7631 7.31399C11.9303 7.14534 12.2072 7.14534 12.3745 7.31399C12.5418 7.48264 12.5418 7.76179 12.3745 7.93045L8.61335 11.7222C8.30761 12.0305 7.90381 12.1875 7.5 12.1875Z",fill:"currentColor"}),e.jsx("path",{d:"M7.5 7.8125C7.09619 7.8125 6.69239 7.65548 6.38665 7.34725L2.62547 3.55545C2.45818 3.38679 2.45818 3.10764 2.62547 2.93899C2.79276 2.77034 3.06966 2.77034 3.23695 2.93899L6.99813 6.73079C7.27502 7.00994 7.72498 7.00994 8.00187 6.73079L11.7631 2.93899C11.9303 2.77034 12.2072 2.77034 12.3745 2.93899C12.5418 3.10764 12.5418 3.38679 12.3745 3.55545L8.61335 7.34725C8.30761 7.65548 7.90381 7.8125 7.5 7.8125Z",fill:"currentColor"})]})})}const lr={thinking:"Thinking",fetching:"Fetching data",analyzing:"Analyzing"},Ql={get_price:"price",get_positions:"positions",get_balance:"balance",get_orders:"orders",market_overview:"market",get_funding_rates:"funding",get_indicators:"indicators",get_levels:"support/resistance",get_news:"news",get_trades:"trade history",place_order:"placing order",cancel_order:"cancelling",close_position:"closing position",set_leverage:"leverage",set_sl_tp:"SL/TP"};function ei(t,r){if(t==="fetching"&&r){const s=Ql[r]??r;return`${lr.fetching} ${s}`}return lr[t]}function ti({phase:t,detail:r}){return e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap text-body-sm text-[var(--color-text-secondary)] transition-opacity duration-base ease-out",children:[e.jsx("span",{"data-pulse-dots":!0,className:"flex items-center gap-1",children:[0,1,2].map(s=>e.jsx("span",{className:"w-1 h-1 rounded-full bg-[var(--color-brand-default)]",style:{animation:`pulse 1.4s ease-in-out ${s*.2}s infinite`}},s))}),e.jsx("span",{className:"transition-opacity duration-base ease-out",children:ei(t,r)})]})}const ir=420,Ke=200,cr="m-0 p-2.5 rounded-[4px] bg-[var(--color-surface-canvas)] border border-[var(--color-border-default)] text-caption text-[var(--color-text-primary)] overflow-x-auto whitespace-pre-wrap break-all max-h-[300px] overflow-y-auto",Xe="inline-flex items-center gap-1 px-1.5 py-0.5 rounded-[4px] text-footnote";function ri({entry:t}){return t.status==="running"?e.jsx("span",{className:`${Xe} bg-[var(--color-warning-soft)] text-[var(--color-warning-text)]`,children:"running"}):t.success?e.jsx("span",{className:`${Xe} bg-[var(--color-success-soft)] text-[var(--color-success-text)]`,children:"success"}):e.jsx("span",{className:`${Xe} bg-[rgba(255,71,87,0.15)] text-[var(--color-error-text)]`,children:"error"})}function dr(t){try{const r=JSON.parse(t);return JSON.stringify(r,null,2)}catch{return t}}const si=n.memo(function({entry:r,onClose:s}){const[o,a]=n.useState(!1);n.useEffect(()=>{r?requestAnimationFrame(()=>a(!0)):a(!1)},[r]);const l=()=>{a(!1),setTimeout(s,Ke)};return r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[900] bg-black/35",style:{opacity:o?1:0,transition:`opacity ${Ke}ms ease`},onClick:l}),e.jsxs("div",{className:"fixed top-0 right-0 bottom-0 max-w-screen z-[901] bg-[#0a0f18] border-l border-[var(--color-border-default)] flex flex-col",style:{width:ir,transform:o?"translateX(0)":`translateX(${ir}px)`,transition:`transform ${Ke}ms ease`},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--color-border-default)] flex-shrink-0",children:[e.jsx("span",{className:"text-body-sm-medium text-[var(--color-success-text)] overflow-hidden text-ellipsis whitespace-nowrap",children:r.name}),e.jsx("button",{onClick:l,"aria-label":"Close tool call panel",className:"bg-transparent border-none p-1.5 rounded-[4px] cursor-pointer flex items-center justify-center text-[var(--color-text-secondary)] transition-colors duration-fast ease-out hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)]",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex gap-3 text-caption text-[var(--color-text-secondary)]",children:[e.jsx(ri,{entry:r}),r.durationSecs!=null&&e.jsxs("span",{children:[r.durationSecs,"s"]}),e.jsx("span",{className:"text-[var(--color-text-secondary)]",children:r.toolCallId.slice(0,8)})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-footnote text-[var(--color-text-secondary)] uppercase tracking-[0.05em]",children:"Arguments"}),e.jsx("pre",{className:cr,children:dr(r.argsFull??r.argsHint??"(none)")})]}),r.result&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-footnote text-[var(--color-text-secondary)] uppercase tracking-[0.05em]",children:"Result"}),e.jsx("pre",{className:cr,children:dr(r.result)})]})]})]})]}):null});function ni(t,r){var s;if(!(r<0||r>=t.length)&&((s=t[r])==null?void 0:s.type)==="error")for(let o=r-1;o>=0;o--){const a=t[o];if(a&&a.role==="user")return a.content}}function oi(){const t=cl(),[r,s]=n.useState(null),[o,a]=n.useState(!1);n.useEffect(()=>{const p=()=>{fetch("/api/wallets").then(m=>m.json()).then(m=>a(m.length>0)).catch(()=>{})};return p(),window.addEventListener("ghost-wallet-changed",p),()=>window.removeEventListener("ghost-wallet-changed",p)},[]);const l="How can I help you today?",i=t.messages.find(p=>p.type==="confirmation"&&p.status==="pending"),c=n.useCallback(p=>{s(p)},[]),x=n.useCallback(()=>{s(null)},[]);return e.jsxs("section",{className:"flex flex-col h-full bg-[var(--color-surface-scrim)] overflow-hidden pt-6",children:[t.disconnected&&e.jsx(Sl,{raw:"connection closed",onRetry:t.handleReconnect}),e.jsx("div",{ref:t.scrollContainerRef,className:"flex-1 overflow-y-auto px-4 flex flex-col relative",children:e.jsxs("div",{className:"max-w-[800px] w-full mx-auto flex flex-col gap-3"+(t.showEmptyState?" flex-1 justify-center":""),children:[t.sessionLoading&&e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(xe,{})}),t.showEmptyState&&e.jsx(Cl,{hasWallet:o}),t.messages.map((p,m)=>e.jsx(Jl,{message:p,onAction:t.handleSend,onApprove:t.handleApprove,onReject:t.handleReject,onToolCallSelect:c,onRetry:t.handleSend,errorRetryText:ni(t.messages,m)},p.id)),t.chatRunId&&!t.messages.some(p=>p.type==="confirmation"&&p.status==="pending")&&e.jsxs(e.Fragment,{children:[e.jsx(ti,{phase:t.thinkingPhase??"thinking",detail:t.thinkingDetail??void 0}),t.activeToolCalls.length>0&&e.jsx(Jr,{toolCalls:t.activeToolCalls,onSelect:c})]}),e.jsx("div",{ref:t.messagesEndRef})]})}),e.jsx("div",{className:"relative h-0 z-10",children:e.jsx("div",{className:"absolute -top-3 inset-x-0 px-4 flex justify-center pointer-events-none -translate-y-full",children:e.jsx("div",{className:"w-full max-w-[800px] flex justify-end",children:e.jsx(Yl,{visible:t.userScrolledUp,hasNew:t.hasNewContent,onClick:t.scrollToBottom})})})}),t.queue.length>0&&e.jsx("div",{className:"border-t border-[var(--color-border-default)] bg-[var(--color-surface-base)] px-4 py-2 flex flex-col items-center",children:e.jsxs("div",{className:"max-w-[800px] w-full",children:[e.jsxs("div",{className:"text-caption text-[var(--color-text-secondary)] mb-1",children:["Queued (",t.queue.length,")"]}),t.queue.map(p=>e.jsxs("div",{className:"flex items-center justify-between bg-[var(--color-surface-canvas)] rounded-[4px] px-2.5 py-1.5 text-body-sm text-[var(--color-text-secondary)] mb-1",children:[e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap mr-2",children:p.text}),e.jsx("button",{onClick:()=>t.removeFromQueue(p.id),"aria-label":"Remove from queue",className:"bg-transparent border-0 text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] focus-visible:text-[var(--color-text-primary)] cursor-pointer flex-shrink-0 p-0.5 transition-colors duration-fast ease-out",children:"✕"})]},p.id))]})}),t.showEmptyState&&!t.isBusy&&e.jsx("div",{className:"px-5 pt-3 pb-2 flex justify-center",children:e.jsx("div",{className:"max-w-[800px] w-full",children:e.jsx(yl,{onSelect:t.handleSend,hasWallet:o})})}),!i&&e.jsx(bl,{onSend:t.handleSend,disabled:!t.connected||t.isBusy,placeholder:t.connected?t.thinkingPhase==="fetching"?"Ghost is fetching data…":t.thinkingPhase==="analyzing"?"Ghost is analyzing…":t.isBusy?"Ghost is thinking…":l:"Connecting…",isBusy:t.isBusy,onAbort:t.handleAbort}),e.jsx(si,{entry:r,onClose:x})]})}const ai=n.createContext({locale:"en",setAppLocale:t=>{}}),li=n.lazy(()=>ie(()=>import("./Dashboard-BRxSDtCD.js"),__vite__mapDeps([4,1,5,6,2,3]))),ii=n.lazy(()=>ie(()=>import("./Tools-C-NcyONi.js"),__vite__mapDeps([7,1,2,3]))),ci=n.lazy(()=>ie(()=>import("./Skills-4s4LDpzh.js"),__vite__mapDeps([8,1,2,3]))),di=n.lazy(()=>ie(()=>import("./Cron-5mIZVsft.js"),__vite__mapDeps([9,1,5,2,3]))),ui=n.lazy(()=>ie(()=>import("./Memory-CcgSgCqJ.js"),__vite__mapDeps([10,1,11,2,3]))),xi=n.lazy(()=>ie(()=>import("./Config-CQyc8yqV.js"),__vite__mapDeps([12,1,2,3]))),fi=n.lazy(()=>ie(()=>import("./Cost-BoAvnlDi.js"),__vite__mapDeps([13,1,2,3]))),pi=n.lazy(()=>ie(()=>import("./Logs-BpXqElSx.js"),__vite__mapDeps([14,1,6,2,3]))),hi=n.lazy(()=>ie(()=>import("./Sessions-BEIP55fW.js"),__vite__mapDeps([15,1,11,2,3]))),mi=n.lazy(()=>ie(()=>import("./Chart-BOyhyITw.js"),__vite__mapDeps([16,1,2,3])));function bi(){const[t,r]=n.useState("en"),s=o=>{r(o)};return e.jsx(Qa,{children:e.jsx(ai.Provider,{value:{locale:t,setAppLocale:s},children:e.jsx(Ga,{children:e.jsx("div",{className:"app-fade-in",style:{minHeight:"100dvh"},children:e.jsx(n.Suspense,{fallback:e.jsx("div",{"aria-busy":"true"}),children:e.jsx(fs,{children:e.jsxs(ae,{element:e.jsx(Ya,{}),children:[e.jsx(ae,{path:"/",element:e.jsx(oi,{})}),e.jsx(ae,{path:"/dashboard",element:e.jsx(li,{})}),e.jsx(ae,{path:"/tools",element:e.jsx(ii,{})}),e.jsx(ae,{path:"/skills",element:e.jsx(ci,{})}),e.jsx(ae,{path:"/cron",element:e.jsx(di,{})}),e.jsx(ae,{path:"/memory",element:e.jsx(ui,{})}),e.jsx(ae,{path:"/config",element:e.jsx(xi,{})}),e.jsx(ae,{path:"/cost",element:e.jsx(fi,{})}),e.jsx(ae,{path:"/logs",element:e.jsx(pi,{})}),e.jsx(ae,{path:"/sessions",element:e.jsx(hi,{})}),e.jsx(ae,{path:"/chart",element:e.jsx(mi,{})}),e.jsx(ae,{path:"*",element:e.jsx(ps,{to:"/",replace:!0})})]})})})})})})})}hs.createRoot(document.getElementById("root")).render(e.jsx(ur.StrictMode,{children:e.jsx(ms,{basename:"/",children:e.jsx(bi,{})})}));export{rr as B,ji as C,Fa as F,tr as G,Ms as P,Hr as R,Ts as S,de as T,Fe as X,$r as a,Rs as b,we as c,Ea as d,Ue as e,Ze as f,st as g,Ia as h,mt as i,Ra as j,Ma as k,it as l,Or as m,Ta as n,te as u};
|