PageSourceSearch

https://app.alphractal.com/_next/static/chunks/1082-25ba9e64802dac5f.js

js alphractal.com collected 2026-10-05 05:28:13 UTC 132,669 bytes, 3 lines download raw bytes

1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._posthogChunkIds=e._posthogChunkIds||{},e._posthogChunkIds[n]="01a109f9-0ecc-7601-84bc-9ca183ed550b")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1082],{31082:function(e,t,l){l.r(t),l.d(t,{default:function(){return e8}});var a=l(57437),r=l(2265),n=l(99376);function i(e,t){let l=null,n=null,i=()=>(null!=n||(n=e().then(e=>l=e.default,e=>{throw n=null,e})),n);return function(e){let[n,o]=(0,r.useState)(()=>l),[s,c]=(0,r.useState)(null);if((0,r.useEffect)(()=>{if(n)return;let e=!0;return i().then(t=>{e&&o(()=>t)},t=>{e&&c({error:t})}),()=>{e=!1}},[]),s)throw s.error;return n?(0,a.jsx)(n,{...e}):(0,a.jsx)(a.Fragment,{children:t()})}}var o=l(72035),s=l(3889),c=l(9251),d=l(64635),u=l(59089),m=l(95675),h=l(60702),v=l(58048),f=l(73172),g=l(56999),p=l(14362),x=l(52326),b=l(12988),y=l(59755),C=l(90486),w=l(44703),S=l(12706),N=l(54418),j=l(89371),A=l(23340),T=l(583),E=l(42058),M=l(27727),I=l(62266),D=l(63583),k=l(5152),_=l(28362),O=l(2695),P=l(99892),L=l(3532),F=l(30326),R=l(14479),U=l(97362),W=l(30380),V=l(43589),Z=l(91854),B=l(40448),Q=l(52178),z=l(30469);let Y=[{value:"1m",label:"1 min"},{value:"5m",label:"5 Min"},{value:"15m",label:"15 Min"},{value:"30m",label:"30 Min"},{value:"1h",label:"1 Hour"},{value:"4h",label:"4 Hours"},{value:"6h",label:"6 Hours"},{value:"12h",label:"12 Hours"},{value:"1d",label:"1 Day"}],K=e=>e&&0!==e.length&&e.some(e=>B.Uh.includes(e.code))?(0,Q.mC)(B.pS):(0,Q.mC)(Y),q=[{value:"open_Interest_Usd",label:"Usd"},{value:"open_Interest",label:"Coin"}],H={binance:"#E63946",bit:"#F25C3A",bitfinex:"#F4845F",bitget:"#F7A84B",bitmex:"#F7C948",bullish:"#C5D631",bybit:"#73C936",coinbase:"#36B37E",cryptodotcom:"#00B4D8",deribit:"#0096E0",dydxv4:"#3A7BF2",ftx:"#5B5DF0",gateio:"#7C4DFF",htx:"#9C42D7",hyperliquid:"#C746D7",kraken:"#E84393",kucoin:"#F06595",okx:"#F2B50B"},J=["#E63946","#F25C3A","#F4845F","#F7A84B","#F7C948","#C5D631","#73C936","#36B37E","#00B4D8","#0096E0","#3A7BF2","#5B5DF0","#7C4DFF","#9C42D7","#C746D7","#E84393","#F06595","#FF8FA3","#FF6B81","#FFB3C1"],X={spot:"#36B37E",swap:"#3A7BF2",future:"#F7A84B",all:"#7C4DFF"},G=e=>{for(let t of Object.keys(H))if(e.endsWith("_".concat(t)))return t;return null},$=(e,t,l,a)=>a&&(null==l?void 0:l[a])?l[a]:e&&H[e]?H[e]:J[t%J.length];var ee=e=>{var t,l,i,o,Q,Y,H,J;let{asset:ee,category:et,chartMetrics:el,chartInfo:ea,stacked:er,combineYaxis:en,description:ei,metricName:eo,chartTier:es,dashboard:ec=!1,subCategory:ed,chartId:eu,metricScale:em="value",prefetchedData:eh,initialWorkbenchChart:ev,initialWorkbenchEditing:ef=!1}
1=e,eg=(0,n.useRouter)(),ep=(0,n.useSearchParams)(),{user:ex}=(0,p.a)(),{toast:eb}=(0,A.pm)(),{trackEvent:ey,trackFirstEvent:eC}=(0,x.z)(),ew=(0,r.useRef)(""),eS=(0,r.useRef)(null),[eN,ej]=(0,r.useState)("line"),[eA,eT]=(0,r.useState)(!1),[eE,eM]=(0,r.useState)(),[eI,eD]=(0,r.useState)("");(0,D.Zf)({surface:"derivatives",label:(null==ea?void 0:ea.name)||"",metricName:(null==ea?void 0:ea.name)||void 0,metricDescription:(null==ei?void 0:ei[0])||void 0,assetName:eI||void 0,assetId:ee||void 0,category:et,subCategory:ed});let[ek,e_]=(0,r.useState)(!1),[eO,eP]=(0,r.useState)(""),[eL,eF]=(0,r.useState)(null),[eR,eU]=(0,r.useState)(null),[eW,eV]=(0,r.useState)([]),[eZ,eB]=(0,r.useState)([]),[eQ,ez]=(0,r.useState)(!1),[eY,eK]=(0,r.useState)(null),[eq,eH]=(0,r.useState)("1d"),[eJ,eX]=(0,r.useState)("log"),[eG,e$]=(0,r.useState)((0,O.fb)(em||"value")),[e0,e1]=(0,r.useState)([]),[e2,e4]=(0,r.useState)([]),[e3,e5]=(0,r.useState)(!1),[e9,e8]=(0,r.useState)([]),[e6,e7]=(0,r.useState)([]),[te,tt]=(0,r.useState)([]),[tl,ta]=(0,r.useState)([]),tr=(null==ea?void 0:ea.name)==="Open Interest"||(null==el?void 0:el.some(e=>{var t;return"open_Interest"===e.code||"open_Interest_Usd"===e.code||(null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("open interest"))})),tn=(null==ea?void 0:ea.name)==="Open Interest by Exchange (Stacked)",ti=(null==ea?void 0:ea.name)==="Funding Rate"||(null==el?void 0:el.some(e=>{var t;return"value"===e.code||(null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("funding rate"))})),to=(0,r.useMemo)(()=>{var e;return!tr&&!ti&&null!==(e=null==el?void 0:el.some(e=>B.Uh.includes(e.code)))&&void 0!==e&&e},[el,tr,ti]),ts=(0,r.useMemo)(()=>{if(tr||ti||to)return{};let e=null==el?void 0:el.find(e=>Object.keys((0,z.an)(null==e?void 0:e.code)).length>0);return(0,z.an)(null==e?void 0:e.code)},[el,tr,ti,to]),tc=Object.keys(ts).length>0,[td,tu]=(0,r.useState)("All Exchanges"),[tm,th]=(0,r.useState)(""),[tv,tf]=(0,r.useState)([""]),[tg,tp]=(0,r.useState)("open_Interest_Usd"),[tx,tb]=(0,r.useState)((null==el?void 0:el.map(()=>(0,N.hj)(ee).assetColor))||[]),[ty,tC]=(0,r.useState)("none"),[tw,tS]=(0,r.useState)("absolute"),[tN,tj]=(0,r.useState)(!0),[tA,tT]=(0,r.useState)({}),[tE,tM]=(0,r.useState)("normal"),[tI,tD]=(0,r.useState)([]),[tk,t_]=(0,r.useState)([]),[tO,tP]=(0,r.useState)(""),[tL,tF]=(0,r.useState)(!1),[tR,tU]=(0,r.useState)("all"),[tW,tV]=(0,r.useState)(["all"]),[tZ,tB]=(0,r.useState)(B.yj),tQ=e=>(0,B.w8)(e),tz=(0,r.useMemo)(()=>tr?(tn?tv&&tv.length>0?tv:[""]:tm?[tm]:[""]).map(e=>({value:e,label:tQ(e),metricCode:e?"".concat(tg,"_").concat(e):tg})):[],[tr,tn,tv,tm,tg]),tY=(0,r.useMemo)(()=>{if(tc&&ts.marketTypeMultiSelect&&el&&el.length>0){let e=tW&&tW.length>0?tW:["all"];if(e.length>1)return el.flatMap(t=>e.map(e=>{let l="all"===e?"All":e.charAt(0).toUpperCase()+e.slice(1);return{...t,name:"".concat(t.name," — ").concat(l),code:"".concat(t.code,"_").concat("all"===e?"all":e),stacked:!1}}))}if(tr){let e="open_Interest_Usd"===tg?"USD":"Coin",t=tz.length>0?tz:[{value:"",label:"All Exchanges",metricCode:tg}];return t.map(l=>{let a=l.label||"All Exchanges";return{collection:"derivatives",name:tn?a:"Open Interest - ".concat(a," [").concat(e,"]"),description:"Total value in open derivative contracts",code:l.metricCode,chartStyle:"line",priceScale:"log",metricScale:"value",stacked:t.length>1,url:"",combineYaxis:!1}})}return el||[]},[tr,tg,el,tz,tc,ts.marketTypeMultiSelect,tW]),tK=(0,r.useMemo)(()=>K(tY),[tY]),tq=(0,r.useMemo)(()=>null==tY?void 0:tY.some(e=>"value"===e.code),[tY]);(0,r.useEffect)(()=>{tr&&tb(()=>tY.map((e,t)=>tn?$(G(e.code),t,tA,e.code):(0,N.hj)(ee).assetColor))},[tg,tr,tn,ee,tY,tA]),(0,r.useEffect)(()=>{tc&&ts.marketTypeMultiSelect&&tb(tY.map((e,t)=>{let l=e.code.split("_");return X[l[l.length-1]]||(0,N.hj)(ee).assetColor}))},[tc,ts.marketTypeMultiSelect,tY,ee]);let[tH,tJ]=(0,r.useState)(1),[tX,tG]=(0,r.useState)(!1),[t$,t0]=(0,r.useState)(null),t1=!["Exchange Inflow","Exchange Inflow (USD)","Exchange Outflow","Exchange Outflow (USD)","Exchange Withdrawal Count"].includes((null==ea?void 0:ea.name)||"")||!["btc","eth"].includes(ee),t2="".concat(ee,"-").concat((null==ea?void 0:ea.id)||(null==ea?void 0:ea.name)||et||"crypto");(0,r.useEffect)(()=>{try{let e=localStorage.getItem("crypto_ma_state_".concat(t2));if(e){let t=JSON.parse(e);
1Array.isArray(t.movingAveragePeriods)&&e1(t.movingAveragePeriods),Array.isArray(t.emaPeriods)&&e4(t.emaPeriods),Array.isArray(t.maColors)&&e8(t.maColors),Array.isArray(t.emaColors)&&e7(t.emaColors),Array.isArray(t.maDashed)&&tt(t.maDashed),Array.isArray(t.emaDashed)&&ta(t.emaDashed),Array.isArray(t.metricColors)?tb(t.metricColors):tb((null==el?void 0:el.map(()=>(0,N.hj)(ee).assetColor))||[]),t.exchangeColorMap&&"object"==typeof t.exchangeColorMap&&tT(t.exchangeColorMap),"boolean"==typeof t.colorByValue&&tj(t.colorByValue)}else tb((null==el?void 0:el.map(()=>(0,N.hj)(ee).assetColor))||[]);let t=localStorage.getItem("derivatives_roc_mode_".concat(t2));("percent"===t||"absolute"===t)&&tS(t)}catch(e){console.error("Erro ao restaurar estado do localStorage:",e),tb((null==el?void 0:el.map(()=>(0,N.hj)(ee).assetColor))||[])}},[t2,ee,el]),(0,r.useEffect)(()=>{tn?(0===tv.length||1===tv.length&&""===tv[0])&&tI.length>0&&tf(tI.filter(e=>""!==e.value).map(e=>e.value)):tr&&!tn&&tv.length>0&&""!==tv[0]&&tf([""])},[tn,null==ea?void 0:ea.name,tI]),(0,r.useEffect)(()=>{var e;if(!to&&!ti&&!(tc&&ts.exchange)){tD([]);return}let t=tc&&ts.exchange,l=t?ts.marketTypeMultiSelect?void 0:tR:void 0,a=ti?"funding_rate":null==el?void 0:null===(e=el[0])||void 0===e?void 0:e.code;(t?(0,g.xro)(ee,l):(0,g.K2j)(ee,a)).then(e=>{tD([{value:"",label:"All Exchanges"},...(e||[]).map(e=>e.exchange).filter(e=>e&&""!==e).map(e=>({value:e,label:(0,B.w8)(e)}))])}).catch(()=>tD([]))},[ee,to,ti,tc,ts.exchange,ts.marketTypeMultiSelect,tR,el]),(0,r.useEffect)(()=>{tr&&(0,g.htJ)(ee).then(e=>{let t=(e||[]).map(e=>e.exchange).filter(e=>e&&""!==e);if(0===t.length){tD([]);return}tD([{value:"",label:"All Exchanges"},...t.map(e=>({value:e,label:(0,B.w8)(e)}))])}).catch(()=>tD([]))},[ee,tr]),(0,r.useEffect)(()=>{tr&&(tF(!0),(0,g.t38)(ee).then(e=>{t_((e||[]).map(e=>e.symbol).filter(e=>e&&""!==e))}).catch(()=>t_([])).finally(()=>tF(!1)))},[ee,tr]),(0,r.useEffect)(()=>{var e;if(!(to||tc&&ts.symbol)){tr||t_([]);return}tF(!0);let t=tc&&ts.symbol,l=t?ts.marketTypeMultiSelect?void 0:tR:void 0;(t?(0,g.VAr)(ee,tm||void 0,l):(0,g.olg)(ee,tm||void 0,null==el?void 0:null===(e=el[0])||void 0===e?void 0:e.code)).then(e=>{t_((e||[]).map(e=>e.symbol).filter(e=>e&&""!==e))}).catch(()=>t_([])).finally(()=>tF(!1))},[ee,to,tc,ts.symbol,ts.marketTypeMultiSelect,tr,tm,tR,el]),(0,r.useEffect)(()=>{(tr||to||tc)&&tP("")},[ee,tm,tr,to,tc]),(0,r.useEffect)(()=>{if(!(tc&&ts.marketType)){tB([]);return}(0,g.Ovq)(ee,tm||void 0,tO||void 0).then(e=>{let t=(e||[]).map(e=>e.market_type).filter(e=>e&&""!==e),l=e=>{var t;return null!==(t=B.Ym[e])&&void 0!==t?t:e.charAt(0).toUpperCase()+e.slice(1)};tB([{value:"all",label:B.Ym.all},...t.map(e=>({value:e,label:l(e)}))])}).catch(()=>tB(B.yj))},[ee,tc,ts.marketType,tm,tO]),(0,r.useEffect)(()=>{em&&e$((0,O.fb)(em))},[em]),(0,r.useEffect)(()=>{try{localStorage.setItem("crypto_ma_state_".concat(t2),JSON.stringify({movingAveragePeriods:e0,emaPeriods:e2,maColors:e9,emaColors:e6,maDashed:te,emaDashed:tl,metricColors:tx,exchangeColorMap:tA,colorByValue:tN}))}catch(e){console.error("Erro ao salvar estado no localStorage:",e)}},[t2,e0,e2,e9,e6,te,tl,tx,tA,tN]),(0,r.useEffect)(()=>{try{localStorage.setItem("derivatives_roc_mode_".concat(t2),tw)}catch(e){}},[t2,tw]),(0,r.useEffect)(()=>{if(!(tx.length>0))try{let e=localStorage.getItem("crypto_ma_state_".concat(t2));if(!e||!JSON.parse(e).metricColors){let e=(null==tY?void 0:tY.map((e,t)=>{if(tn){let l=G(e.code);return $(l,t)}return(0,N.hj)(ee).assetColor}))||(null==el?void 0:el.map(()=>(0,N.hj)(ee).assetColor))||[];e.length>0&&tb(e)}}catch(t){console.error("Erro ao verificar cores salvas no localStorage:",t);let e=(null==tY?void 0:tY.map((e,t)=>tn?$(G(e.code),t):(0,N.hj)(ee).assetColor))||(null==el?void 0:el.map(()=>(0,N.hj)(ee).assetColor))||[];e.length>0&&0===tx.length&&tb(e)}},[ee,t2,el,tY,tn]),(0,r.useEffect)(()=>{tt(e=>{let t=[...e];for(;t.length<e0.length;)t.push(!1);return t.slice(0,e0.length)})},[e0]),(0,r.useEffect)(()=>{ta(e=>{let t=[...e];for(;t.length<e2.length;)t.push(!1);return t.slice(0,e2.length)})},[e2]);let t4=e=>{tt(t=>{let l=[...t];return l[e]=!l[e],l})},t3=e=>{ta(t=>{let l=[...t];return l[e]=!l[e],l})};(0,r.useEffect)(()=>{ee&&(async()=>{try{let e=await (0,g.h9)(ee);eM(null==e?void 0:e.urlImage),eD((null==e?void 0:e.name)||ee.toUpperCase())}catch(e){eM(void 0),eD(ee.toUpperCase())}})()},[ee]),(0,r.useEffect)(()=>
1{if((null==eh?void 0:eh.userTier)!=null){tJ(eh.userTier),tG(!1);return}(async()=>{if(!(null==ex?void 0:ex.uid)){tJ(1);return}tG(!0),t0(null);try{let e=await (0,g.ET7)();tJ(e.data)}catch(e){console.error("Failed to fetch user tier:",e),t0(e.message||"Failed to fetch user tier"),tJ(null)}finally{tG(!1)}})()},[null==ex?void 0:ex.uid,null==eh?void 0:eh.userTier]);let t5=!tX&&!(0,E.B)({user:ex,userTier:tH,requiredTier:es}).isLocked,t9=async(e,t)=>{var l,a,r,n,i,o;if(!t5){eV([]),eB([]),eU(null),eT(!1);return}if(!tY||0===tY.length){eU("No metrics available for this chart");return}eT(!0),eU(null);try{if(tr){let a=tz.length>0?tz:[{value:"",label:"All Exchanges",metricCode:tg}],r=tO?{symbol:tO}:void 0,[n,i]=await Promise.all([Promise.all(a.map(l=>(0,g.OOv)(e,"derivatives/Open_Interest",t,l.value,"Open_Interest",r))),(0,g.urE)(e,t)]),o=new Map(i.map(e=>[(0,N.SX)(e.time,t),e.priceUSD||e.price||0])),s=n.map(e=>(null==e?void 0:e.data)||e||[]);if(!s.some(e=>Array.isArray(e)&&e.length>0)){if(!tn&&""!==tm){let e=tQ(tm);eb({title:"No data available",description:'No records found for "'.concat(e,'". Switching to All Exchanges.'),variant:"destructive"}),th(""),eV([]),eB([]),eT(!1);return}let e=(null===(l=tK.find(e=>e.value===t))||void 0===l?void 0:l.label)||t;"1d"!==t?(eb({title:"No data available",description:"No records found for the selected timeframe (".concat(e,"). Switching to 1 Day."),variant:"destructive"}),eH("1d")):eb({title:"No data available",description:"No records found for the selected timeframe (".concat(e,")."),variant:"destructive"}),eV([]),eB([]),eT(!1);return}let c=new Map;a.forEach((e,l)=>{(Array.isArray(s[l])?s[l]:[]).forEach(l=>{var a,r,n,i,s,d;let u=l.time||l.timestamp;if(!u)return;let m=(0,N.SX)(u,t),h=c.get(m)||(()=>{let e={time:m,price:Number(o.get(m))||0};return c.set(m,e),e})(),v="open_Interest_Usd"===tg?null!==(n=null!==(r=null!==(a=l.open_Interest_Usd)&&void 0!==a?a:l.open_interest_usd)&&void 0!==r?r:l.openInterestUsd)&&void 0!==n?n:null:null!==(d=null!==(s=null!==(i=l.open_Interest)&&void 0!==i?i:l.open_interest)&&void 0!==s?s:l.openInterest)&&void 0!==d?d:null;h[e.metricCode]=null!=v?Number(v):null})});let d=Array.from(c.values()).sort((e,t)=>new Date(e.time).getTime()-new Date(t.time).getTime());eV(d),eB(d),eT(!1);return}if(ti){let[l,r]=await Promise.all([(0,g.OOv)(e,"derivatives/Funding_Rate",t,tm,"Funding_Rate"),(0,g.urE)(e,t)]),n=(null==l?void 0:l.data)||l||[];if(!Array.isArray(n))throw Error("Invalid data format received from API");let i=new Map(r.map(e=>[(0,N.SX)(e.time,t),e.priceUSD||e.price||0]));if(0===n.length){if(""!==tm){let e=tQ(tm);eb({title:"No data available",description:'No records found for "'.concat(e,'". Switching to All Exchanges.'),variant:"destructive"}),th(""),eV([]),eB([]),eT(!1);return}let e=(null===(a=tK.find(e=>e.value===t))||void 0===a?void 0:a.label)||t;"1d"!==t?(eb({title:"No data available",description:"No records found for the selected timeframe (".concat(e,"). Switching to 1 Day."),variant:"destructive"}),eH("1d")):eb({title:"No data available",description:"No records found for the selected timeframe (".concat(e,")."),variant:"destructive"}),eV([]),eB([]),eT(!1);return}let o=n.map(e=>{var l,a,r;let n=(0,N.SX)(e.time||e.timestamp,t),o={time:e.time||e.timestamp,price:Number(i.get(n))||0},s=null!==(r=null!==(a=null!==(l=e.value)&&void 0!==l?l:e.funding_rate)&&void 0!==a?a:e.fundingRate)&&void 0!==r?r:null;return o.value=null!=s?Number(s):null,o});eV(o),eB(o),eT(!1);return}let i=tc&&ts.enforceSameExchangePrice&&!!tm,o=i?(0,g.urE)(e,t,{exchange:tm,marketType:"all"===tR?void 0:tR,symbol:tO||void 0}):(0,g.urE)(e,t),s=[null];tc&&ts.marketType&&(s=ts.marketTypeMultiSelect?tW&&tW.length>0?tW:["all"]:[tR||"all"]);let c=to&&!tc,d=e=>{if(tc){let t={};return tm&&(t.exchange=tm),tO&&(t.symbol=tO),e&&"all"!==e?t.market_type=e:ts.marketType&&(t.market_type="all"),Object.keys(t).length>0?t:void 0}if(c)return{...tm?{exchange:tm}:{},...tO?{symbol:tO}:{}}},u=tY.flatMap(e=>s.map(t=>({metric:e,marketType:t}))),m=Promise.all(u.map(l=>{let{metric:a,marketType:r}=l;return(0,g.OOv)(e,a.url||"".concat(et,"/").concat(a.code),tc||c?t:"all",tc||c?void 0:td,a.code,d(r))})),[h,v]=await Promise.all([o,m]);if(i&&(!h||0===h.length)){let e=tQ(tm);eb({title:"No price data for this combination",description:'No price series found for "'.concat(e,'"').concat(tR&&"all"!==tR?" + ".concat(tR):"",". Switching to All Exchanges."),variant:"destructive"}),th(""),eV([]),eB([]),eT(!1);return}let f=new Map(h.map(e=>[(0,N.SX)(e.time,t),e.priceUSD])),p=new Date,x=new Date;switch(t){case"30d":x.setDate(p.getDate()-30);break;case"90d":x.setDate(p.getDate()-90);break;case"1y":x.setFullYear(p.getFullYear()-1);break;case"5y":x.setFullYear(p.getFullYear()-5);break;default:x.setFullYear(2e3)}let b=v.map(e=>e.filter(e=>new Date(e.time)>=x)),y=(()=>
1{if(0===b.length)return!1;for(let e of b)if(Array.isArray(e)){for(let t of e)if(t)for(let[e,l]of Object.entries(t)){if("time"===e||"timestamp"===e||null==l)continue;let t=Number(l);if(!Number.isNaN(t)&&0!==t)return!0}}return!1})();if(0===b.length||0===b[0].length||!y){if(tc&&ts.marketType){if(ts.marketTypeMultiSelect){if((tW||[]).filter(e=>"all"!==e).length>0){eb({title:"No data available",description:"No records for the selected market type(s). Switching to All.",variant:"destructive"}),tV(["all"]),eV([]),eB([]),eT(!1);return}}else if(tR&&"all"!==tR){let e=null!==(n=B.Ym[tR])&&void 0!==n?n:tR;eb({title:"No data available",description:'No records for market type "'.concat(e,'". Switching to All.'),variant:"destructive"}),tU("all"),eV([]),eB([]),eT(!1);return}}if((to||tc)&&""!==tm){let e=tQ(tm);eb({title:"No data available",description:'No records found for "'.concat(e,'". Switching to All Exchanges.'),variant:"destructive"}),th(""),eV([]),eB([]),eT(!1);return}let e=(null===(r=tK.find(e=>e.value===t))||void 0===r?void 0:r.label)||t;"1d"!==t?(eb({title:"No data available",description:"No records found for the selected timeframe (".concat(e,"). Switching to 1 Day."),variant:"destructive"}),eH("1d")):eb({title:"No data available",description:"No records found for the selected timeframe (".concat(e,")."),variant:"destructive"}),eV([]),eB([]),eT(!1);return}let C=tc&&!!ts.marketTypeMultiSelect&&s.length>1,w=e=>{let l=new Map;return u.forEach((a,r)=>{let{metric:n,marketType:i}=a,o=n.code.charAt(0).toLowerCase()+n.code.slice(1),s=C&&i?"".concat(o,"_").concat(i):o;e[r].forEach(e=>{var a,r;let i=e.time;if(!i)return;let c=(0,N.SX)(i,t),d=l.get(c);d||(d={time:i,price:Number(f.get(c))||0},l.set(c,d)),d[s]=null!==(r=null!==(a=null==e?void 0:e[o])&&void 0!==a?a:null==e?void 0:e[n.code])&&void 0!==r?r:null})}),Array.from(l.values()).sort((e,t)=>new Date(e.time).getTime()-new Date(t.time).getTime())},S=w(b),j=w(v);eV(S),eB(j)}catch(e){eU("Error fetching data: "+((null===(o=e.response)||void 0===o?void 0:null===(i=o.data)||void 0===i?void 0:i.error)||e.message||String(e))),console.error("Error fetching data:",e),eV([]),eB([])}finally{eT(!1)}};(0,r.useEffect)(()=>{let e=tY.length>0&&tY[0].chartStyle||"line";ej(e),e5("area"===e)},[tY]),(0,r.useEffect)(()=>{if(!t5){eV([]),eB([]),eT(!1);return}t9(ee,eq)},[ee,eq,tY,td,tg,tv,tm,tO,tR,tW,tr,ti,to,tc,t5]),(0,r.useEffect)(()=>{var e;if(0===eW.length)return;let t="".concat(ee,"::").concat(null!=eu?eu:"","::").concat(null!==(e=null==ea?void 0:ea.id)&&void 0!==e?e:"");ew.current!==t&&(ew.current=t,(0,w.h8)("derivatives-chart",t,Date.now())&&(ey("chart_viewed",{chartId:null!=eu?eu:null==ea?void 0:ea.id,chartName:null==ea?void 0:ea.name,asset:ee,category:et,...ec||tq?{}:{resolution:eq}}),eC("chart_viewed","first_chart_viewed",{chartType:"derivatives",asset:ee,chartName:null==ea?void 0:ea.name}),(0,C.DI)("first_chart_viewed","first_chart_viewed",{chartType:"derivatives",asset:ee,chartName:null==ea?void 0:ea.name})))},[eW]);let t8=(0,r.useMemo)(()=>{var e,t;return{surface:"derivatives_chart",chartId:null!==(e=null!=eu?eu:null==ea?void 0:ea.id)&&void 0!==e?e:null,chartName:null!==(t=null==ea?void 0:ea.name)&&void 0!==t?t:null,asset:null!=ee?ee:null,category:null!=et?et:null}},[eu,null==ea?void 0:ea.id,null==ea?void 0:ea.name,ee,et]),t6=e=>{tK.some(t=>t.value===e)&&(0,y.q1)(t8,eq,e),eH(e)},t7=e=>{eX(e)},le=e=>{e$(e)},lt=e=>{ej(e),"area"===e?e5(!0):e5(!1)},ll=(0,r.useRef)(null),la=e=>{if(tC(e),"none"!==e&&"none"===ty)ll.current=eN,ej("area"),e5(!0);else if("none"===e&&"none"!==ty){let e=ll.current;ll.current=null,e&&(ej(e),e5("area"===e))}},lr=e=>{e1(t=>{let l=t.indexOf(e);return l>-1?(e8(e=>e.filter((e,t)=>t!==l)),tt(e=>e.filter((e,t)=>t!==l)),t.filter(t=>t!==e)):(e8(e=>[...e,void 0]),tt(e=>[...e,!1]),[...t,e])})},ln=e=>{e4(t=>{let l=t.indexOf(e);return l>-1?(e7(e=>e.filter((e,t)=>t!==l)),ta(e=>e.filter((e,t)=>t!==l)),t.filter(t=>t!==e)):(e7(e=>[...e,void 0]),ta(e=>[...e,!1]),[...t,e])})},li=(e,t)=>{e8(l=>{let a=[...l];return a[e]=t,a})},lo=(e,t)=>{e7(l=>{let a=[...l];return a[e]=t,a})},ls=(e,t)=>{tb(l=>{let a=[...l];return a[e]=t,a}),tn&&tY[e]&&tT(l=>({...l,[tY[e].code]:t}))},lc=(0,r.useMemo)(()=>
1{if(!tn)return;let e={};return tY.forEach((t,l)=>{let a=G(t.code);e[t.code]=$(a,l,tA,t.code)}),e},[tn,tY,tA]),ld=!!(ev||ep.get("myChartId")||"My Charts"===et||"My Charts"===ed),lu=(0,r.useMemo)(()=>({exchange:tm,exchanges:(null==tv?void 0:tv.length)?tv:[""],metric:tg,symbol:tO,marketType:tR,marketTypes:(null==tW?void 0:tW.length)?tW:["all"],stackType:tE}),[tm,tv,tg,tO,tR,tW,tE]),{workbenchChart:lm,setWorkbenchChart:lh,isWorkbenchEditing:lv,openWorkbench:lf,handleWorkbenchSaved:lg,handleWorkbenchChartChange:lp,discardWorkbenchDraft:lx}=(0,U.W)({router:eg,searchParams:ep,initialWorkbenchChart:ev,initialWorkbenchEditing:ef,resetDeps:[ee,null==ea?void 0:ea.id,null==ea?void 0:ea.name,et,ed,ev,ef],buildOpenConfig:e=>{let t=e||(0,L.AS)({asset:ee,category:et,subCategory:ed,chartInfo:ea,chartMetrics:tY,area:"derivatives",interval:eq||"1d",chartType:eN||"line",metricColors:tx,metricScale:eG,priceScale:eJ,includePriceSeries:!0});return{...t,settings:{...t.settings,timeframe:eq,interval:eq||t.settings.interval,chartType:eN||t.settings.chartType,derivatives:lu}}},buildSavedUrl:e=>"/cryptos/derivatives/chart?asset=".concat(encodeURIComponent(e.baseAsset||ee||"btc"),"&category=My%20Charts&subCategory=My%20Charts&chart=").concat(encodeURIComponent(e.name),"&myChartId=").concat(encodeURIComponent(e.id)),decorateChartChange:e=>({...e,settings:{...e.settings,timeframe:eq,interval:eq||e.settings.interval,chartType:eN||e.settings.chartType,derivatives:lu}}),computeSyncedChart:(e,t)=>{let{isWorkbenchEditing:l}=t,a=l||!!ev,r=a?e.series:e.series.map(e=>{let t=e.source.match(/^metric_(\d+)$/);if(t){var l;let a=Number(t[1])-1;return{...e,color:tx[a]||e.color,style:eN||e.style,scale:(0,Z.J)((null==tY?void 0:null===(l=tY[a])||void 0===l?void 0:l.metricScale)||eG)}}return e.source.startsWith("price_usd")?{...e,asset:e.asset||ee,label:"".concat((e.asset||ee).toUpperCase(),": Price USD"),scale:(0,Z.J)(eJ)}:e});return{...e,baseAsset:ee,settings:{...e.settings,...a?{}:{timeframe:eq,interval:eq||e.settings.interval,chartType:eN||e.settings.chartType},derivatives:lu},series:r,updatedAt:new Date().toISOString()}},syncDeps:[ee,tY,ev,tx,eJ,eG,lu,eq,eN]}),lb=()=>{ey(b.s6.WORKBENCH_OPENED,{surface:"derivatives",asset:ee,category:et,chartName:null==ea?void 0:ea.name}),lf()};(0,U.m)(!!(ex&&!ec&&t5&&(null==ea?void 0:ea.id)&&tY.length),lb);let ly=(0,r.useMemo)(()=>{var e,t;let l=(null==lm?void 0:null===(e=lm.name)||void 0===e?void 0:e.trim())||(null==ev?void 0:null===(t=ev.name)||void 0===t?void 0:t.trim())||"";if((lv||ld)&&l)return l;if(tr&&!tn){let e="open_Interest_Usd"===tg?"USD":"Coin",t=tQ(tm);return"Open Interest - ".concat(t," [").concat(e,"]")}return(null==ea?void 0:ea.name)||""},[null==ea?void 0:ea.name,null==ev?void 0:ev.name,ld,tr,tn,lv,tm,tg,null==lm?void 0:lm.name]),lC=(lv||ld)&&((null==lm?void 0:null===(t=lm.name)||void 0===t?void 0:t.trim())||(null==ev?void 0:null===(l=ev.name)||void 0===l?void 0:l.trim()))?"".concat(eI||ee.toUpperCase(),": ").concat((null==lm?void 0:null===(i=lm.name)||void 0===i?void 0:i.trim())||(null==ev?void 0:null===(o=ev.name)||void 0===o?void 0:o.trim())):void 0,lw=tv.filter(e=>e&&""!==e).length,lS=tn?lw>1:!tr&&er;(0,r.useEffect)(()=>{var e,t,l,a,r;if(!ev){eS.current=null;return}if(eS.current===ev.id)return;eS.current=ev.id;let n=null===(e=ev.settings)||void 0===e?void 0:e.derivatives;(null===(t=ev.settings)||void 0===t?void 0:t.timeframe)&&eH(ev.settings.timeframe),((null===(l=ev.settings)||void 0===l?void 0:l.chartType)==="line"||(null===(a=ev.settings)||void 0===a?void 0:a.chartType)==="bar"||(null===(r=ev.settings)||void 0===r?void 0:r.chartType)==="area")&&ej(ev.settings.chartType),n&&(void 0!==n.exchange&&th(n.exchange),Array.isArray(n.exchanges)&&tf(n.exchanges.length?n.exchanges:[""]),("open_Interest"===n.metric||"open_Interest_Usd"===n.metric)&&tp(n.metric),void 0!==n.symbol&&tP(n.symbol),void 0!==n.marketType&&tU(n.marketType||"all"),Array.isArray(n.marketTypes)&&tV(n.marketTypes.length?n.marketTypes:["all"]),("none"===n.stackType||"normal"===n.stackType||"percent"===n.stackType)&&tM(n.stackType))},[ev]);let lN=ep.get("myChartId"),lj=(e,t)=>{let l=(0,O.fb)(t);if("price"===e&&eX(l),"metric"===e&&e$(l),!lm)return;let a=(0,F.C)(lm,e,(0,Z.J)(t));a!==lm&&(lh(a),lN&&(0,W.b4)().save(a).then(e=>lh(e)).catch(()=>{}))},lA=(0,r.useMemo)(()=>
1{if(lm&&!lv)return(0,F.c)(lm).map(e=>({id:e.id,label:e.label,value:e.value,onChange:t=>lj(e.id,t)}))},[lN,lv,lm]),lT=(0,V.a)(lm),lE=ec?"":ep.get("chart")||(null==ea?void 0:ea.name)||"",lM=(0,f.Fg)(eW,null==el?void 0:null===(Q=el[0])||void 0===Q?void 0:Q.code),lI=e=>{var t,l,a,r,n;if(null==lM)return;let i=!tO&&!tm&&tv.every(e=>!e)&&"all"===tR&&tW.every(e=>"all"===e)&&(!tr||"open_Interest_Usd"===tg)&&"none"===ty&&("1d"===eq||"all"===eq),o=Number(lM.toPrecision(6));ey(b.s6.CHART_ALERT_PREFILL_CLICKED,{metric:(null==el?void 0:null===(t=el[0])||void 0===t?void 0:t.code)||"",chart:lE,asset:ee,level:o,direction:e,surface:"chart_toolbar"}),eK({asset:ee,metric:(null==el?void 0:null===(l=el[0])||void 0===l?void 0:l.name)||"",metricCode:(null==el?void 0:null===(a=el[0])||void 0===a?void 0:a.code)||"",category:et,subCategory:ed,chart:lE,chartType:ep.get("chartType")||null,chartId:(null==ea?void 0:ea.id)?parseInt(ea.id.toString()):eu?parseInt(String(eu),10):void 0,chartSource:"crypto",presetOperator:"above"===e?"Gt":"Lt",presetValue:i?o:void 0,openCreate:!0,exchange:"",setupNotice:i?void 0:"This setup monitors the base metric. Symbol, market-type and display transformations are not applied. Choose a level for the unfiltered series.",presetFrequency:"OnlyOnce",presetTitle:"".concat(ee.toUpperCase()," ").concat((null==el?void 0:null===(r=el[0])||void 0===r?void 0:r.name)||lE," alert"),smartReference:i?(0,s.N3)((0,f.IQ)(eW.slice(-31),null==el?void 0:null===(n=el[0])||void 0===n?void 0:n.code),eq):void 0}),ez(!0)};return((0,_.G)({ready:!ec&&!tX&&!eA&&!eR&&eW.length>0&&!(0,E.B)({user:ex,userTier:tH,requiredTier:es}).isLocked,tourKey:"chart_actions_tour_v1",onOpenAi:e=>{eF({text:(0,k._Y)("Explain this metric for ".concat(e.asset.toUpperCase(),". What does the latest reading mean, and what should I compare it with?"),e.knowledgeLevel),revision:Date.now()}),e_(!0)}}),!0==ec)?(0,a.jsx)(S.Z,{isLoading:tX,user:ex,userTier:tH,requiredTier:es,minHeightClass:"h-full",compact:!0,children:(0,a.jsxs)("div",{id:"full",className:"flex flex-col h-full w-full bg-transparent",children:[(0,a.jsx)("div",{className:"px-4 pt-2",children:(0,a.jsx)(j.Z,{asset:ee,category:et,title:(null==ea?void 0:ea.name)||"",chartInfo:ea,subCategory:ed,chartId:eu,timeframe:eq,typeChart:eN,scalePrice:eJ,scaleTransactionCount:eG,combineYaxis:en,movingAveragePeriods:e0,emaPeriods:e2,maColors:e9,emaColors:e6,maDashed:te,emaDashed:tl,metricColors:tx,chartMetrics:tY,onTimeframeChange:t6,onChartTypeChange:lt,onScalePriceChange:t7,onScaleTransactionCount:le,onAddMovingAveragePeriod:lr,onAddEmaPeriod:ln,onMaColorChange:li,onEmaColorChange:lo,onToggleMaDashed:t4,onToggleEmaDashed:t3,onMetricColorChange:ls,rateOfChange:ty,onRateOfChangeChange:la,rateOfChangeMode:tw,onRateOfChangeModeChange:tS,colorByValue:tN,onColorByValueChange:tj})}),(0,a.jsx)(c.Z,{transactionData:eW,fullData:eZ,asset:ee,scalePrice:eJ,scaleTransactionCount:eG,timeframe:eq,isLoading:eA,typeChart:eN,movingAveragePeriods:e0,emaPeriods:e2,maColors:e9,emaColors:e6,maDashed:te,emaDashed:tl,screenShotTitle:ly,chartMetrics:tY,isStacked:lS,combineYaxis:en,selectedEntity:td,title:ly,metricColors:tx,metricColorsMap:lc,dashboard:ec,chartId:eu,stackType:tn?tE:void 0,rateOfChange:ty,rateOfChangeMode:tw,colorByValue:tN})]})}):(0,a.jsxs)("div",{className:"relative w-full h-full",children:[(0,a.jsxs)("div",{className:"relative h-full transition-all duration-300 ease-out ".concat(ek?"pr-[420px] xl:pr-[520px]":"pr-0"),children:[(0,a.jsx)(S.Z,{isLoading:tX,user:ex,userTier:tH,requiredTier:es,title:ly,assetIcon:eE,children:(0,a.jsxs)("div",{className:"flex flex-col w-full h-full gap-2",children:[!ec&&(0,a.jsx)(R.Z,{variant:"chart",ready:!eA&&!eR&&eW.length>0&&!lv&&!ek&&!eQ}),(0,a.jsx)("div",{id:"full",className:"w-full h-full bg-card rounded-lg shadow-md p-4 ".concat(T.C),children:(0,a.jsxs)("div",{className:"w-full h-full flex flex-col gap-2",children:[(0,a.jsx)("div",{className:"flex",children:(0,a.jsx)(m.Z,{typeChart:eN,onChartTypeChange:lt,onToggleArea:()=>{e5(e=>!e)},showArea:e3,asset:ee,category:et,selectedEntity:td,onEntityChange:e=>{tu(e)},scalePrice:eJ,scaleTransactionCount:eG,timeframe:eq,emaPeriods:e2,maColors:e9,emaColors:e6,maDashed:te,emaDashed:tl,onAssetChange:e=>{tu("All Exchanges"),eg.push("?asset=".concat(e))},onTimeframeChange:t6,onScalePriceChange:t7,onScaleTransactionCount:le,onAddMovingAveragePerio
1d:lr,movingAveragePeriods:e0,onAddEmaPeriod:ln,onMaColorChange:li,onEmaColorChange:lo,onToggleMaDashed:t4,onToggleEmaDashed:t3,title:ly,customHeaderTitle:lC,chartInfo:ea,combineYaxis:en,showExchangeSelector:t1,metricColors:tx,onMetricColorChange:ls,rateOfChange:ty,onRateOfChangeChange:la,rateOfChangeMode:tw,onRateOfChangeModeChange:tS,colorByValue:tN,onColorByValueChange:tj,shareUrl:lm?lT||"":void 0,shareTitle:lm?"Share ".concat(lm.name):void 0,chartMetrics:tY,timeframeOptions:tK,timeframePlacement:"left",hideResolutionSelector:tq,exchange:ti||tr&&!tn||to||tc&&ts.exchange?tm||"":void 0,selectedMetric:tr?tg:void 0,onExchangeChange:ti||tr&&!tn||to||tc&&ts.exchange?e=>{th(e)}:void 0,onMetricChange:tr?e=>{tp(e)}:void 0,exchangeOptions:ti?tI.filter(e=>""===e.value||!B.I8.has(e.value)):tr||to||tc&&ts.exchange?tI:void 0,selectedExchanges:tn?tv:void 0,onExchangesChange:tn?e=>{if(!e||0===e.length){tf([""]);return}tf(Array.from(new Set(e)))}:void 0,enableMultiExchange:tn,metricOptions:tr?q:void 0,stackType:tn?tE:void 0,onStackTypeChange:tn?e=>{tM(e)}:void 0,symbolOptions:tr||to||tc&&ts.symbol?tk:void 0,selectedSymbol:tr||to||tc&&ts.symbol?tO:void 0,onSymbolChange:tr||to||tc&&ts.symbol?tP:void 0,isLoadingSymbols:tL,marketType:tc&&ts.marketType&&!ts.marketTypeMultiSelect?tR:void 0,onMarketTypeChange:tc&&ts.marketType&&!ts.marketTypeMultiSelect?tU:void 0,marketTypeOptions:tc&&ts.marketType?tZ:void 0,selectedMarketTypes:tc&&ts.marketTypeMultiSelect?tW:void 0,onMarketTypesChange:tc&&ts.marketTypeMultiSelect?tV:void 0,enableMultiMarketType:!!(tc&&ts.marketTypeMultiSelect),onWorkbenchOpen:ec?void 0:lb,reading:!ec&&lE?(0,a.jsx)(f.ZP,{compact:!0,asset:ee,chartName:lE,currentValue:null!=lM?(0,f.aI)(lM):null,onAlertAt:lI,points:(0,f.IQ)(eW,null==el?void 0:null===(Y=el[0])||void 0===Y?void 0:Y.code),timeframe:eq,metricLabel:(null==el?void 0:null===(H=el[0])||void 0===H?void 0:H.name)||lE,onExplain:e=>{eP(e),e_(!0)}}):void 0,onAlertsClick:()=>lI("above"),scaleAxisRows:lA})}),!ec&&lm&&lv&&(0,a.jsx)(P.Z,{chart:lm,onChartChange:lp,onSaved:lg,onCancel:lx,hideShareButton:!0,captureElementId:"derivatives-workbench-chart",defaultAsset:ee}),(0,a.jsx)(u.Z,{error:eR,isLoading:eA}),(0,a.jsx)("div",{"data-tour":ec?void 0:"chart-data",className:"flex w-full flex-1 min-h-0 relative",children:lm?(0,a.jsx)("div",{id:"derivatives-workbench-chart",className:"h-full w-full",children:(0,a.jsx)(d.Z,{transactionData:eW,fullData:eZ,asset:ee,scalePrice:eJ,scaleTransactionCount:eG,timeframe:eq,isLoading:eA,typeChart:eN,movingAveragePeriods:e0,emaPeriods:e2,maColors:e9,emaColors:e6,maDashed:te,emaDashed:tl,screenShotTitle:ly,chartMetrics:tY,isStacked:lS,combineYaxis:en,selectedEntity:td,title:ly,metricColors:tx,dashboard:ec,chartId:eu,workbenchChart:lm,workbenchDrawingEditable:lv,rateOfChange:ty,rateOfChangeMode:tw,colorByValue:tN})}):(0,a.jsx)(c.Z,{transactionData:eW,fullData:eZ,asset:ee,scalePrice:eJ,scaleTransactionCount:eG,timeframe:eq,isLoading:eA,typeChart:eN,movingAveragePeriods:e0,emaPeriods:e2,maColors:e9,emaColors:e6,maDashed:te,emaDashed:tl,screenShotTitle:ly,chartMetrics:tY,isStacked:lS,combineYaxis:en,selectedEntity:td,title:ly,metricColors:tx,metricColorsMap:lc,chartId:eu,metricScale:em,stackType:tn?tE:void 0,rateOfChange:ty,rateOfChangeMode:tw,colorByValue:tN})})]})})]})}),(0,a.jsx)(h.Z,{onCsvDownload:()=>{if((null!=tH?tH:1)<2){eb({title:"CSV download is available for Pro plan users and above."}),eg.push("/plans");return}if(0===eW.length){eb({title:"No data available to download."});return}let e=Object.keys(eW[0]),t=new Blob([[e.join(","),...eW.map(t=>e.map(e=>t[e]).join(","))].join("\n")],{type:"text/csv;charset=utf-8;"}),l=URL.createObjectURL(t),a=document.createElement("a");a.setAttribute("href",l),a.setAttribute("download","".concat(ee,"-").concat((null==ea?void 0:ea.name)||"chart","-data.csv")),document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(l)},chartMetrics:tY,description:ei,metricName:eo,userTier:null!=tH?tH:1,chartId:null==ea?void 0:ea.id,area:"derivatives"}),(0,a.jsx)(v.Z,{isOpen:eQ,onClose:()=>ez(!1),initialContext:eY})]}),(0,a.jsx)(M.default,{isOpen:ek,onToggle:()=>e_(!ek),metricName:(null==ea?void 0:ea.name)||"",assetName:eI,chartId:(null==ea?void 0:ea.id)||(eu?parseInt(String(eu),10):0),assetId:ee,initialQuery:eO,initialDraft:null==eL?void 0:eL.text,draftRevision:null!==(J=null==eL?void 0:eL.revision)&&void 0!==J?J:0,onInitialQuerySent:()=>eP("")}),(0,a.jsx)(I.default,{chartId:(null==ea?void 0:ea.id)||(eu?parseInt(String(eu),10):0),metricName:(null==ea?void 0:ea.name)||"",assetName:eI,assetId:ee,hidden:tX||(0,E.B)({user:ex,userTier:tH,requiredTier:es}).isLocked,isDockOpen:ek,onToggleDock:()=>e_(!ek),onSendFromExpanded:e=>{eP(e),e_(!0)}})]})},et=l(43379),el=l(49871),ea=l(71621),er=l(55453),en=l(1944),ei=l(49108),eo=l(24457),es=l.n(eo),ec=l(92735),ed=l(61649),eu=l(53581),em=l(68919),eh=l(47416),ev=l(2207),ef=l(18930),eg=l(29686),ep=l(40686),ex=l(46397),eb=l(41208),ey=l(66143),eC=l(5798),ew=l(60717),eS=l(61749),eN=l(68116);function ej(e){return"wb:".concat(e.id)}function eA(e){let{chartId:t}=e,l=(0,n.useRouter)(),{user:i,loading:o}=(0,p.a)(),{trackEvent:s}=(0,x.z)(),[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(null),[h,v]=(0,r.useState)(!1),[f,g]=(0,r.useState)(!1),[y,C]=(0,r.useState)(null),{userTier:w,loading:S}
1=(0,er.J)(!!i),[N,j]=(0,r.useState)(!1),[A,E]=(0,r.useState)(!0),[D,k]=(0,r.useState)(null),[_,O]=(0,r.useState)(!1),[L,R]=(0,r.useState)(!1),[U,Z]=(0,r.useState)("");(0,r.useEffect)(()=>{if(o)return;let e=!1;return E(!0),d(null),m(null),v(!1),g(!1),C(null),(0,W.b4)().get(t).then(t=>{!e&&(d(t),t&&s(b.s6.WORKBENCH_SAVED_CHART_OPENED,{chart_id:t.id,chartName:t.name,asset:t.baseAsset}))}).catch(()=>{e||d(null)}).finally(()=>{e||E(!1)}),()=>{e=!0}},[t,o,null==i?void 0:i.uid]),function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],l=(0,r.useRef)(e);l.current=e,(0,r.useEffect)(()=>{if(!t)return;let e=()=>l.current();return window.addEventListener(W.mK,e),()=>{window.removeEventListener(W.mK,e)}},[t])}(()=>{h||(0,W.b4)().get(t).then(e=>{e&&d(e)}).catch(()=>{})},!o),(0,r.useEffect)(()=>{if(!(null==i?void 0:i.uid)){k(null);return}let e=!1;return(0,W.b4)().usage().then(t=>{!e&&t&&k({usage:t.usage,limit:t.limit})}).catch(()=>{}),()=>{e=!0}},[null==i?void 0:i.uid,null==c?void 0:c.id]);let B=!S&&(null!=w?w:1)>=2,Q=e=>{d(e),m(null),v(!1),g(!1),l.replace((0,eb.q)(e,e.baseAsset||"btc"))},z=()=>{m(null),v(!1),g(!1)};(0,r.useEffect)(()=>{if(h&&u&&f)return(0,ey.H)({hasUnsavedChanges:()=>!0,save:async()=>{let e=await (0,eC.y)(u,{showSuccess:!1});return!!e&&(d(e),m(null),v(!1),g(!1),!0)},discard:z})},[u,h,f]);let Y=async()=>S?(await (0,eg.t)({icon:"info",title:"Checking license",text:"Wait a moment while we verify your plan."}),!1):!!B||(s(b.s6.PAYWALL_HIT,{feature:"data_export",surface:"my_charts",requiredTier:2,currentTier:w}),(await (0,eg.q)({icon:"warning",title:"Export unavailable",text:"Excel and CSV downloads are available for Pro plan users and above.",confirmButtonText:"View plans",cancelButtonText:"Cancel"})).isConfirmed&&(s(b.s6.UPGRADE_CTA_CLICKED,{source:"my_charts_export",requiredTier:2,currentTier:w}),l.push("/plans")),!1),K=async()=>await Y()?(null==y?void 0:y.rows.length)?y:(await (0,eg.t)({icon:"info",title:"No data available",text:"Wait until the chart finishes loading before exporting."}),null):null,q=async()=>{if(!c)return;let e=await K();e&&(s(b.s6.DATA_EXPORTED,{format:"csv",surface:"my_charts",chartName:c.name,asset:c.baseAsset,rows:e.rows.length,tier:w}),(0,eS.dT)(e,"".concat(c.name,"-data")))},H=async()=>{if(!c)return;let e=await K();e&&(s(b.s6.DATA_EXPORTED,{format:"excel",surface:"my_charts",chartName:c.name,asset:c.baseAsset,rows:e.rows.length,tier:w}),(0,eS.uX)(e,"".concat(c.name,"-data")))},J=async()=>{if(!c)return;let e=document.getElementById("full");if(e){s(b.s6.DATA_EXPORTED,{format:"png",surface:"my_charts",chartName:c.name,asset:c.baseAsset});try{let t=await es()(e,{backgroundColor:null,scale:2,useCORS:!0}),l=document.createElement("a");l.download="".concat(c.name||"my-chart",".png"),l.href=t.toDataURL("image/png"),l.click()}catch(e){await (0,eg.t)({icon:"error",title:"Screenshot failed",text:(null==e?void 0:e.message)||"Could not capture this chart."})}}};(0,r.useEffect)(()=>{let e=()=>{var e;j((null===(e=document.fullscreenElement)||void 0===e?void 0:e.id)==="full")};return document.addEventListener("fullscreenchange",e),e(),()=>{document.removeEventListener("fullscreenchange",e)}},[]);let X=async()=>{c&&(await (0,eg.q)({icon:"warning",title:"Delete chart?",text:'Delete "'.concat(c.name,'" from My Charts?'),confirmButtonText:"Delete",confirmButtonColor:"#dc2626"})).isConfirmed&&(await (0,W.b4)().delete(c.id),s(b.s6.WORKBENCH_CHART_DELETED,{chart_id:c.id,chartName:c.name}),l.push("/cryptos/chart?asset=".concat(encodeURIComponent(c.baseAsset||"btc"))))},G=(0,r.useMemo)(()=>(0,eN.D)(y),[y]),$=(0,r.useMemo)(()=>c?(0,F.c)(c).map(e=>({id:e.id,label:e.label,value:e.value,onChange:async t=>{if(!c)return;let l=(0,F.C)(c,e.id,t);d(l);try{let e=await (0,W.b4)().save(l);d(e)}catch(e){}}})):[],[c]),ee=c?h&&u?u:c:null,et=(0,V.a)(ee);if(A)return(0,a.jsx)("div",{className:"w-full h-full flex items-center justify-center p-4",children:(0,a.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading chart…"})});if(!c)return(0,a.jsx)("div",{className:"w-full h-full flex items-center justify-center p-4",children:(0,a.jsxs)("div",{className:"text-center text-foreground",children:[(0,a.jsx)("div",{className:"text-lg font-semibold mb-2",children:"Chart not found"}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground",children:"This chart isn’t in your account, or you need to log in to view it."})]})});let el=h&&u?u:c,ea=el.series.filter(e=>!1!==e.visible);return(0,a.jsxs)("div",{className:"w-full h-full",children:[(0,a.jsx)("div",{className:"relative h-full transition-all duration-300 ease-out",children:(0,a.jsx)("div",{id:"full",className:"w-full h-full bg-card rounded-lg shadow-md p-2 sm:p-4 ".concat(T.C," fullscreen:h-screen fullscreen:w-screen fullscreen:min-h-screen fullscreen:overflow-hidden fullscreen:rounded-none fullscreen:p-3 sm:fullscreen:p-4"),children:(0,a.jsxs)("div",{className:"flex h-full flex-col",children:[h&&u?(0,a.jsx)(P.Z,{chart:u,onCh
1artChange:e=>{m(e),g(!0)},onSaved:e=>{Q(e),m(null),v(!1)},onCancel:z,onDelete:X,latestLabel:G}):(0,a.jsxs)("div",{className:"mb-3 border-b border-border/40 pb-3",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"rounded bg-primary/10 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide text-primary",children:"My Charts"}),D&&(0,a.jsxs)("span",{className:"rounded border border-border/50 px-2 py-0.5 text-[10px] font-medium text-muted-foreground",title:"Charts saved / plan limit",children:[D.usage,"/",D.limit," saved"]}),c.originalCategory&&(0,a.jsx)("span",{className:"rounded border border-border/50 px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:c.originalCategory}),c.originalSubCategory&&(0,a.jsx)("span",{className:"rounded border border-border/50 px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:c.originalSubCategory})]}),(0,a.jsx)("h1",{className:"truncate text-lg font-semibold text-foreground sm:text-xl",children:c.name}),(0,a.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:[c.originalChartName&&(0,a.jsxs)("span",{children:["Original: ",c.originalChartName]}),G&&(0,a.jsxs)("span",{children:["Latest: ",(0,a.jsx)("span",{className:"text-foreground",children:G})]}),(0,a.jsxs)("span",{children:[ea.length," series"]})]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-start gap-1 lg:justify-end",children:[$.length>0&&(0,a.jsxs)("div",{className:"mr-1 flex flex-col gap-1",children:[(0,a.jsx)("span",{className:"text-[8px] font-medium uppercase text-muted-foreground",children:"Scale"}),(0,a.jsx)(ew.Z,{rows:$})]}),(0,a.jsxs)("button",{type:"button",onClick:q,disabled:S||!B,className:"flex items-center gap-1 sm:gap-1.5 px-1.5 sm:px-2 py-1 text-[10px] sm:text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-secondary/50 rounded transition-colors whitespace-nowrap disabled:cursor-not-allowed disabled:opacity-50",title:B?"Download CSV":"Available for Pro plan and above",children:[(0,a.jsx)(ec.Z,{className:"size-3"}),"CSV"]}),(0,a.jsxs)("button",{type:"button",onClick:H,disabled:S||!B,className:"flex items-center gap-1 sm:gap-1.5 px-1.5 sm:px-2 py-1 text-[10px] sm:text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-secondary/50 rounded transition-colors whitespace-nowrap disabled:cursor-not-allowed disabled:opacity-50",title:B?"Download Excel":"Available for Pro plan and above",children:[(0,a.jsx)(ed.Z,{className:"size-3"}),"Excel"]}),(0,a.jsx)("button",{type:"button",onClick:J,className:"p-1 sm:p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary/50 rounded transition-colors",title:"Screenshot",children:(0,a.jsx)(eu.Z,{className:"size-3 sm:size-3.5"})}),(0,a.jsxs)("button",{type:"button",onClick:()=>R(!0),disabled:!et,className:"flex items-center gap-1 sm:gap-1.5 px-1.5 sm:px-2 py-1 text-[10px] sm:text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-secondary/50 rounded transition-colors whitespace-nowrap disabled:cursor-not-allowed disabled:opacity-50",title:"Share chart copy",children:[(0,a.jsx)(em.Z,{className:"size-3"}),"Share"]}),(0,a.jsx)("button",{type:"button",onClick:()=>{let e=document.getElementById("full");if(e){if(document.fullscreenElement===e){var t,l;null===(t=(l=document).exitFullscreen)||void 0===t||t.call(l);return}e.requestFullscreen&&e.requestFullscreen()}},className:"p-1 sm:p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary/50 rounded transition-colors",title:"Fullscreen",children:(0,a.jsx)(eh.Z,{className:"size-3 sm:size-3.5"})}),(0,a.jsxs)("button",{type:"button",onClick:()=>{s(b.s6.WORKBENCH_OPENED,{surface:"my_charts",asset:null==c?void 0:c.baseAsset,chartName:null==c?void 0:c.name}),m(c),v(!0)},className:"flex items-center gap-1 sm:gap-1.5 px-1.5 sm:px-2 py-1 text-[10px] sm:text-xs font-medium text-blue-500 hover:bg-blue-500/10 hover:text-blue-400 rounded transition-colors whitespace-nowrap",title:"Edit chart",children:[(0,a.jsx)(ev.Z,{className:"size-3"}),"Edit"]}),(0,a.jsxs)("button",{type:"button",onClick:X,className:"flex items-center gap-1 sm:gap-1.5 px-1.5 sm:px-2 py-1 text-[10px] sm:text-xs font-medium text-red-500 hover:bg-red-500/10 rounded transition-colors whitespace-nowrap",title:"Delete chart",children:[(0,a.jsx)(ef.Z,{className:"size-3"}),"Delete"]})]})]}),(0,a.jsx)("div",{className:"mt-3 flex flex-wrap gap-2",children:ea.map((e,t)=>(0,a.jsxs)("span",{className:"inline-flex h-8 max-w-[260px] items-center gap-2 rounded-lg border border-border/50 bg-secondary/30 px-3 text-xs font-medium text-muted-foreground",children:[(0,a.jsx)("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:e.color||"#94a3b8"}}),(0,a.jsx)("span",{className:"truncate",children:e.label})]},e.id||"".concat(e.source,"-").concat(t)))})]}),(0,a.jsx)("div",{id:"workbench-platform-chart",className:"min-h-[760px] flex-1 fullscreen:min-h-0",style:{height:N?"calc(100vh - 124px)":"calc(100vh - 180px)"},children:(0,a.jsx)(ep.Z,{chart:el,height:"100%",onExportData:C,drawingsEditable:h})})]})})}),(0,a.jsx)(ex.Z,{isOpen:L,onClose:()=>R(!1),url:et||"",title:"Share ".concat(el.name),onScreenshot:J}),i&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(I.default,{mode:"workbench",workbenchContextKey:ej(c),chartId:0,metricName:c.name,assetName:c.baseAsset,assetId:c.baseAsset||"btc",isDockOpen:_,onToggleDock:()=>O(e=>!e),onSendFromExpanded:e=>{Z(e),O(!0)}}),(0,a.jsx)(M.default,{mode:"workbench",workbenchChartContext:function(e){var t,l,a,r;let n=[],i=e.originalChartName?", original: ".concat(e.originalChartName):"";
1for(let l of(n.push('Current chart: "'.concat(e.name,'" (workbench, baseAsset: ').concat(e.baseAsset).concat(i,")")),n.push("Timeframe: ".concat(e.settings.timeframe," | Interval: ").concat(e.settings.interval," | Type: ").concat(e.settings.chartType)),n.push(""),n.push("Series (".concat(e.series.length,"):")),e.series)){let e=[l.type,"axis: ".concat(l.axis),"style: ".concat(l.style)];l.scale&&e.push("scale: ".concat(l.scale)),n.push('  - "'.concat(l.label,'" [').concat(e.join(", "),"]")),"metric"===l.type&&l.metric?n.push("      metric: ".concat(l.metric.metricCode," (").concat(l.metric.metricName,", area: ").concat(l.metric.area,")")):"formula"===l.type&&l.expression&&n.push("      expression: ".concat(l.expression));let a=(l.smoothings&&l.smoothings.length>0?l.smoothings:l.smoothing?[l.smoothing]:[]).map(e=>"".concat(e.type,"(").concat(e.period,")")).join(", ");a&&n.push("      smoothings: ".concat(a)),l.rateOfChange&&"none"!==l.rateOfChange&&n.push("      rateOfChange: ".concat(l.rateOfChange," (").concat(null!==(t=l.rateOfChangeMode)&&void 0!==t?t:"percent",")"))}let o=null!==(l=e.markLines)&&void 0!==l?l:[],s=null!==(a=e.colorRanges)&&void 0!==a?a:[],c=null!==(r=e.drawings)&&void 0!==r?r:[];if(o.length>0&&(n.push(""),n.push("MarkLines (".concat(o.length,"): ").concat(o.map(e=>'"'.concat(e.label,'" @ ').concat(e.value)).join("; ")))),s.length>0&&n.push("ColorRanges (".concat(s.length,"): ").concat(s.map(e=>'"'.concat(e.label,'" (').concat(e.mode,")")).join("; "))),c.length>0){let e=Object.entries(c.reduce((e,t)=>{var l;return e[t.type]=(null!==(l=e[t.type])&&void 0!==l?l:0)+1,e},{})).map(e=>{let[t,l]=e;return"".concat(l," ").concat(t)}).join(", ");n.push("Drawings (".concat(c.length,"): ").concat(e))}return n.join("\n")}(el),workbenchContextKey:ej(c),isOpen:_,onToggle:()=>O(!1),chartId:0,metricName:c.name,assetName:c.baseAsset,assetId:c.baseAsset||"btc",initialQuery:U,onInitialQuerySent:()=>Z("")})]})]})}var eT=l(21357);let eE=i(()=>Promise.all([l.e(309),l.e(4639)]).then(l.bind(l,94639)),()=>(0,a.jsx)(ea.MQ,{})),eM=i(()=>Promise.all([l.e(8447),l.e(309),l.e(8637)]).then(l.bind(l,38637)),()=>(0,a.jsx)(ea.MQ,{})),eI=i(()=>Promise.all([l.e(8447),l.e(309),l.e(6158)]).then(l.bind(l,56158)),()=>(0,a.jsx)(ea.MQ,{})),eD=i(()=>Promise.all([l.e(8447),l.e(309),l.e(8450)]).then(l.bind(l,48450)),()=>(0,a.jsx)(ea.MQ,{})),ek=i(()=>Promise.all([l.e(8447),l.e(309),l.e(2789)]).then(l.bind(l,42789)),()=>(0,a.jsx)(ea.MQ,{})),e_=i(()=>Promise.all([l.e(8447),l.e(309),l.e(5272)]).then(l.bind(l,95272)),()=>(0,a.jsx)(ea.MQ,{})),eO=i(()=>Promise.all([l.e(8447),l.e(309),l.e(9483)]).then(l.bind(l,29483)),()=>(0,a.jsx)(ea.MQ,{})),eP=i(()=>Promise.all([l.e(8447),l.e(309),l.e(9199)]).then(l.bind(l,39199)),()=>(0,a.jsx)(ea.MQ,{})),eL=i(()=>Promise.all([l.e(8447),l.e(309),l.e(1431)]).then(l.bind(l,61431)),()=>(0,a.jsx)(ea.MQ,{})),eF=i(()=>Promise.all([l.e(8447),l.e(309),l.e(7386)]).then(l.bind(l,44197)),()=>(0,a.jsx)(ea.MQ,{})),eR=i(()=>Promise.all([l.e(8447),l.e(309),l.e(6854)]).then(l.bind(l,51115)),()=>(0,a.jsx)(ea.MQ,{})),eU=i(()=>Promise.all([l.e(8447),l.e(309),l.e(4291)]).then(l.bind(l,64291)),()=>(0,a.jsx)(ea.MQ,{})),eW=i(()=>Promise.all([l.e(8447),l.e(309),l.e(770)]).then(l.bind(l,43743)),()=>(0,a.jsx)(ea.MQ,{})),eV=i(()=>Promise.all([l.e(8447),l.e(2391)]).then(l.bind(l,12391)),()=>(0,a.jsx)(ea.MQ,{})),eZ=i(()=>Promise.all([l.e(8447),l.e(309),l.e(3261)]).then(l.bind(l,83261)),()=>(0,a.jsx)(ea.MQ,{})),eB=i(()=>Promise.all([l.e(8447),l.e(309),l.e(7946)]).then(l.bind(l,27946)),()=>(0,a.jsx)(ea.MQ,{})),eQ=i(()=>Promise.all([l.e(8447),l.e(309),l.e(9036)]).then(l.bind(l,9036)),()=>(0,a.jsx)(ea.MQ,{})),ez=i(()=>Promise.all([l.e(8447),l.e(309),l.e(6730)]).then(l.bind(l,56730)),()=>(0,a.jsx)(ea.MQ,{})),eY=i(()=>Promise.all([l.e(309),l.e(484)]).then(l.bind(l,80484)),()=>(0,a.jsx)(ea.MQ,{})),eK=i(()=>Promise.all([l.e(309),l.e(6256)]).then(l.bind(l,96256)),()=>(0,a.jsx)(ea.MQ,{})),eq=i(()=>Promise.all([l.e(309),l.e(4726)]).then(l.bind(l,14726)),()=>(0,a.jsx)(ea.MQ,{})),eH=i(()=>Promise.all([l.e(8447),l.e(309),l.e(6674)]).then(l.bind(l,6674)),()=>(0,a.jsx)(ea.MQ,{})),eJ=i(()=>Promise.all([l.e(8447),l.e(309),l.e(8885)]).then(l.bind(l,18885)),()=>(0,a.jsx)(ea.MQ,{})),eX=i(()=>Promise.all([l.e(8447),l.e(309),l.e(7459)]).then(l.bind(l,77459)),()=>(0,a.jsx)(ea.MQ,{})),eG=i(()=>Promise.all([l.e(309),l.e(7859)]).then(l.bind(l,20102)),()=>(0,a.jsx)(ea.MQ,{})),e$=i(()=>
1Promise.all([l.e(309),l.e(4991)]).then(l.bind(l,54991)),()=>(0,a.jsx)(ea.MQ,{})),e0=i(()=>Promise.all([l.e(309),l.e(224)]).then(l.bind(l,224)),()=>(0,a.jsx)(ea.MQ,{})),e1=i(()=>Promise.all([l.e(8447),l.e(309),l.e(6191)]).then(l.bind(l,76191)),()=>(0,a.jsx)(ea.MQ,{})),e2=i(()=>Promise.all([l.e(8447),l.e(309),l.e(7243)]).then(l.bind(l,7243)),()=>(0,a.jsx)(ea.MQ,{})),e4=i(()=>Promise.all([l.e(8447),l.e(309),l.e(4008),l.e(8162)]).then(l.bind(l,4008)),()=>(0,a.jsx)(ea.MQ,{})),e3=i(()=>Promise.all([l.e(309),l.e(4717),l.e(7488),l.e(2929)]).then(l.bind(l,12929)),()=>(0,a.jsx)(ea.MQ,{})),e5=new Set(["C001","C002","C003","C004","C005","C006","C007","C008","C009","C010","C011","C012","C013","C014","C015","C016","C017","C018","C019","C020","C021","C022","C023","C024","C025","C026","D000","D001","D002",...et.tu.map(e=>e.chartCode)]),e9=new Set(["C005","C006","C008","C009","C010","C018","C019"]);function e8(e){return(0,a.jsx)(el.t.Provider,{value:e.category||null,children:(0,a.jsx)(e6,{...e})})}function e6(e){var t,l,i,s,c,d,u,m,h,v,f,b,y,N;let{asset:j,category:A,subCategory:T,chart:M,dashboard:I,chartType:D,hideHeader:k,initialChartId:_,alertTriggerConditions:O,timeframe:P,onTimeframeChange:L,myChartId:F}=e,R=(0,n.useRouter)(),{user:U,loading:V}=(0,p.a)(),{userTier:Z,loading:B}=(0,er.J)(!!U&&!!I),{trackEvent:Q,trackFirstEvent:Y}=(0,x.z)(),K=(0,r.useRef)(""),[q,H]=(0,r.useState)(null),[J,X]=(0,r.useState)(null),[G,$]=(0,r.useState)(null),[el,eo]=(0,r.useState)(void 0),[es,ec]=(0,r.useState)(!1),[ed,eu]=(0,r.useState)(!0),[em,eh]=(0,r.useState)(null),[ev,ef]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=!1;if(!F){ef(null);return}if(V)return;let t=()=>{(0,W.b4)().get(F).then(t=>{e||ef(t)}).catch(()=>{e||ef(null)})};return t(),window.addEventListener(W.mK,t),()=>{e=!0,window.removeEventListener(W.mK,t)}},[F,V,U]);let eg=(null==ev?void 0:ev.baseAsset)||j,ep=(null==ev?void 0:ev.originalCategory)||A,ex=(null==ev?void 0:ev.originalSubCategory)||T,ey=(null==ev?void 0:ev.originalChartName)||M,eC="C001"===D,ew="C002"===D,eS="C003"===D,eN="C004"===D,ej="C005"===D,e8="C006"===D,e6="C007"===D,e7="C008"===D,te="C009"===D,tt="C010"===D,tl="C011"===D,ta="C012"===D,tr="C013"===D,tn="C014"===D,ti="C015"===D,to="C016"===D,ts="C017"===D,tc="C018"===D,td="C019"===D,tu="C020"===D,tm="C021"===D,th="C022"===D,tv="C023"===D,tf="C024"===D,tg="C025"===D,tp="C026"===D,tx="D000"===D,tb="D001"===D,ty="D002"===D,tC=(0,et.NI)(D),tw=null!=D&&e5.has(D),tS=(null==ev?void 0:null===(t=ev.originalCategory)||void 0===t?void 0:t.toLowerCase())||"",tN=!!(F&&ev&&(!ev.originalChartName||tS.includes("macro")||tS.includes("sentiment"))),tj=!!(F&&ev&&tS.includes("macro"));(0,r.useEffect)(()=>{tj&&ev&&R.replace((0,eb.q)(ev,eg||"btc"))},[eg,ev,R,tj]),(0,r.useEffect)(()=>{if(!V&&(!F||ev)){if(H(null),ec(!1),eu(!0),$(null),eh(null),tN){X((null==ev?void 0:ev.id)||null),eo(1),ec(!0);return}if(tw&&null!=_&&""!==_){X(String(_)),eo("C024"===D?2:1),ec(!0);return}(async()=>{try{var e,t,l,a;let r=await (0,g.HrF)(ey);if(!r||!r.data||!r.data.chart)throw Error("Invalid API response: ".concat(JSON.stringify(r)));let n=r.data.chart,i=r.data.metrics;if(H(r),X(n.id.toString()),eo(tf?2:null!==(e=n.tier)&&void 0!==e?e:1),eu(!0),tw)return;let o=1;if(null==U?void 0:U.uid)try{let e=await (0,g.ET7)();o=null!==(t=e.data)&&void 0!==t?t:1}catch(e){o=1}if((0,E.B)({user:U,userTier:o,requiredTier:n.tier}).isLocked){eh(null),H({...r,data:{...r.data,metrics:i}});return}let s=await (0,g.G3r)(ey,eg);if(!s||!s.data||!s.data.chart)throw Error("Invalid API response: ".concat(JSON.stringify(s)));let c={success:s.success,errors:s.errors,data:{chart:s.data.chart,metrics:s.data.metrics}};H(c),X(s.data.chart.id.toString()),eo(tf?2:null!==(a=null!==(l=s.data.chart.tier)&&void 0!==l?l:n.tier)&&void 0!==a?a:1),eh({metrics:s.data.metrics,priceData:s.data.priceData,userTier:s.data.userTier})}catch(e){$(e.message||"Error loading chart")}finally{ec(!0)}})()}},[ex,ey,eg,V,D,_,F,ev,tN]),(0,r.useEffect)(()=>{var e,t,l,a;if(!es||!tw||!J)return;let r="".concat(null!=D?D:"","::").concat(j,"::").concat(J);if(K.current===r||(K.current=r,!(0,w.h8)("custom-chart",r,Date.now())))return;let n=null!==(a=null!==(l=null==q?void 0:null===(t=q.data)||void 0===t?void 0:null===(e=t.chart)||void 0===e?void 0:e.name)&&void 0!==l?l:D)&&void 0!==a?a:"";Q("chart_viewed",{chartId:J,chartName:n,chartType:D,asset:j,category:A}),Y("chart_viewed","first_chart_viewed",{chartType:D,asset:j,chartName:n}),(0,C.DI)("first_chart_viewed","first_chart_viewed",{chartType:D,asset:j,chartName:n})},[es,J,D,j]);let tA=()=>(0,a.jsx)("div",{className:"w-full h-full flex items-center justify-center p-4",children:(0,a.jsxs)("div",{className:"text-center text-foreground",children:[(0,a.jsx)("div",{className:"text-lg font-semibold mb-2",children:"This chart is not available for this asset."}),(0,a.jsx)("div",{className:"text-sm",children:"Please select a metric from the Sidebar on the left."})]})}),tT=["btc","ltc","doge","dash","zec","bch","xec"],tE=(eg||"btc").toLowerCase(),tM=tl&&tT.includes(tE),tI=tl&&!tT.includes(tE),tD=ta&&tT.includes(tE),tk=ta&&!tT.includes(tE),t_=tf&&"btc"===tE;if(D&&e9.has(D)&&(0,eT.D)(tE)||tI||tk||tf&&!t_)return(0,a.jsx)(tA,{});let tO={alertTriggerConditions:O};if(F&&!ev||tj)return(0,a.jsx)(ea.MQ,{});if(F&&ev&&tN)return(0,a.jsx)(eA,{chartId:F});if(I&&es){if(B)return(0,a.jsx)(S.Z,{isLoading:!0,user:U,userTier:Z,requiredTier:el,minHeightClass:"h-full",compact:!0});if((0,E.B)({user:U,userTier:Z,requiredTier:el}).isLocked)return(0,a.jsx)(S.Z,{user:U,userTier:Z,requiredTier:el,minHeightClass:"h-full",compact:!0})}if(es&&tC)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(e3,{chartType:tC.chartCode,asset:j,dashboard:I})});if(es&&eC)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eM,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&ew)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eI,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&eS)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eD,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&eN)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(ek,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&ej)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(e_,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&e8)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eO,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&e6)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eP,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&e7)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eL,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&te)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eF,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tg)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(e$,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tp)return"btc"!==j.toLowerCase()?(0,a.jsx)(tA,{}):(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(e0,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tt)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eV,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tl)return tM?(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eR,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})}):(0,a.jsx)(tA,{});if(es&&ta)return tD?(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eU,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})}):(0,a.jsx)(tA,{});if(es&&tr)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eZ,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tf)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eB,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tn)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eW,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&ti)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eQ,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&to)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(ez,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&ts)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eY,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tv)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eG,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tc)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eK,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&td)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eq,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tu)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eH,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&tm)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eJ,{asset:j,chartTier:el,dashboard:I,chartId:J,...tO})});if(es&&th){let e=void 0!==el?el:3;return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eX,{asset:j,chartTier:e,dashboard:I,chartId:J,...tO})})}if(es&&tx&&(null==q?void 0:null===(l=q.data)||void 0===l?void 0:l.chart))return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(e1,{asset:j,chartTier:el,chartInfo:q.data.chart,chartId:null!=J?J:void 0,category:A,subCategory:T,dashboard:I})});if(es&&tb&&(null==q?void 0:null===(i=q.data)||void 0===i?void 0:i.chart))return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(e2,{asset:j,chartTier:el,chartInfo:q.data.chart,chartId:null!=J?J:void 0,category:A,subCategory:T,dashboard:I})});if(es&&ty&&(null==q?void 0:null===(s=q.data)||void 0===s?void 0:s.chart))return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(e4,{asset:j,chartTier:el,chartInfo:q.data.chart,chartId:null!=J?J:void 0,category:A,subCategory:T,dashboard:I,showRefresh:!k})});if(G)return(0,a.jsx)("div",{className:"w-full h-full flex items-center justify-center p-4",children:(0,a.jsxs)("div",{className:"text-center text-foreground",children:[(0,a.jsx)("div",{className:"text-lg font-semibold mb-2",children:"This chart is not available"}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground",children:"Please select a metric from the Sidebar on the left."})]})});if(!q||!q.data)return es?(0,a.jsx)("div",{className:"w-full h-full flex items-center justify-center p-4",children:(0,a.jsxs)("div",{className:"text-center text-foreground",children:[(0,a.jsx)("div",{className:"text-lg font-semibold mb-2",children:"Chart not available"}),(0,a.jsx)("div",{className:"text-sm mb-2",children:"The chart was not found or did not return data."}),(0,a.jsxs)("div",{className:"text-xs text-muted-foreground mb-4",children:["Chart: ",M," | Asset: ",j]}),(0,a.jsx)("div",{className:"text-sm",children:"Please select a different metric from the sidebar."})]})}):(0,a.jsx)(ea.MQ,{});let tP=null===(c=q.data)||void 0===c?void 0:c.metrics;if(es&&(!Array.isArray(tP)||0===tP.length))return(0,a.jsx)("div",{className:"w-full h-full flex items-center justify-center p-4",children:(0,a.jsxs)("div",{className:"text-center text-foreground",children:[(0,a.jsx)("div",{className:"text-lg font-semibold mb-2",children:"Chart with no available metrics"}),(0,a.jsx)("div",{className:"text-sm mb-2",children:"The chart was found but has no associated metrics."}),(0,a.jsxs)("div",{className:"text-xs text-muted-foreground mb-4",children:["Chart: ",M," | Asset: ",j," | Chart ID: ",null===(b=q.data)||void 0===b?void 0:null===(f=b.chart)||void 0===f?void 0:f.id]}),(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:"This may indicate that the chart needs to be populated in the database."})]})});if(!es)return(0,a.jsx)(ea.MQ,{});if(!q.data.metrics||!Array.isArray(q.data.metrics)||0===q.data.metrics.length)return(0,a.jsx)("div",{className:"w-full h-full flex items-center justify-center p-4",children:(0,a.jsxs)("div",{className:"text-center text-foreground",children:[(0,a.jsx)("div",{className:"text-lg font-semibold mb-2",children:"Error rendering chart"}),(0,a.jsx)("div",{className:"text-sm mb-2",children:"The chart data is not in the expected format."})]})});let tL=(0,ei.b)(q.data.chart,q.data.metrics);if(I&&!k)return(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(eE,{asset:eg,category:ep,subCategory:ex,chart:ey,chartMetrics:q.data.metrics,chartInfo:q.data.chart,chartTier:el,chartType:D,chartId:J,stacked:q.data.metrics.some(e=>e.stacked),combineYaxis:tL,description:q.data.metrics.map(e=>e.description),metricName:q.data.metrics.map(e=>e.name),timeframe:P,onTimeframeChange:L})});let tF=(null===(d=q.data.chart)||void 0===d?void 0:d.name)||"",tR="Open Interest"===tF||"Funding Rate"===tF||"Open Interest by Exchange (Stacked)"===tF||(null===(u=q.data.metrics)||void 0===u?void 0:u.some(e=>"open_Interest"===e.code||"open_Interest_Usd"===e.code||e.name&&e.name.toLowerCase().includes("funding rate"))),tU=(0,z.q7)(null===(m=q.data.metrics)||void 0===m?void 0:m.map(e=>null==e?void 0:e.code));return tR||tU?(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(ee,{asset:eg,category:ep,chartMetrics:q.data.metrics,chartInfo:q.data.chart,stacked:q.data.metrics.some(e=>e.stacked),combineYaxis:tL,description:q.data.metrics.map(e=>e.description),metricName:q.data.metrics.map(e=>e.name),chartTier:el,dashboard:I,subCategory:ex,chartId:J,metricScale:(0,en.V)(null===(N=q.data.metrics)||void 0===N?void 0:null===(y=N[0])||void 0===y?void 0:y.metricScale),prefetchedData:em,initialWorkbenchChart:ev,initialWorkbenchEditing:!1})}):(0,a.jsx)("div",{className:"w-full h-full",children:(0,a.jsx)(o.Z,{asset:eg,category:ep,chartMetrics:q.data.metrics,chartInfo:q.data.chart,stacked:q.data.metrics.some(e=>e.stacked),combineYaxis:tL,description:q.data.metrics.map(e=>e.description),metricName:q.data.metrics.map(e=>e.name),chartTier:el,dashboard:I,subCategory:ex,chartId:J,chartType:D,hideHeader:k,metricScale:(0,en.V)(null===(v=q.data.metrics)||void 0===v?void 0:null===(h=v[0])||void 0===h?void 0:h.metricScale),alertTriggerConditions:O,prefetchedData:em,initialWorkbenchChart:ev,initialWorkbenchEditing:!1})})}},72035:function(e,t,l){l.d(t,{Z:function(){return ef}}
1);var a=l(57437),r=l(3889),n=l(2265),i=l(99376),o=l(64635),s=l(59089),c=l(95675),d=l(79810),u=l(73274),m=l(56999),h=l(14362),v=l(52326),f=l(12988),g=l(59755),p=l(90486),x=l(44703),b=l(14479),y=l(97362),C=l(42058),w=l(54418),S=l(27727),N=l(62266),j=l(23340),A=l(58048),T=l(73172),E=l(71621),M=l(12706),I=l(583),D=l(16094),k=l(60825),_=l(29847),O=l(40448),P=l(99892),L=l(3532),F=l(63583),R=l(5152),U=l(28362),W=l(19797);let V="ai_overlay_";function Z(e){return e.source.startsWith(V)}let B=["#A855F7","#14B8A6","#F97316","#EC4899"];var Q=l(30326),z=l(66143),Y=l(30380),K=l(41208),q=l(5798),H=l(43589),J=l(91854),X=l(37789),G=l(2695),$=l(61749),ee=l(24763),et=l(68116),el=l(32489),ea=l(92735),er=l(61649),en=l(49108);let ei={until:null,from:null,reason:null,active:!1};function eo(e){let t=new Date(e);return t.setHours(23,59,59,999),t}function es(e,t){return e.active&&e.until?"Through ".concat(e.until.toLocaleDateString(t,{day:"numeric",month:"short"})):null}var ec=l(93448);function ed(e){let{delay:t,surface:l="chart",metricName:r,className:o}=e,s=(0,i.useRouter)(),{trackEvent:c}=(0,v.z)();if((0,n.useEffect)(()=>{var e;t.active&&c(f.s6.PAYWALL_HIT,{feature:"delayed_data",surface:l,metricName:r,delayedUntil:null===(e=t.until)||void 0===e?void 0:e.toISOString()})},[t.active]),!t.active)return null;let d=es(t);return(0,a.jsxs)("div",{className:(0,ec.cn)("pointer-events-none absolute inset-y-0 right-0 z-20 w-[18%] min-w-[92px] max-w-[220px]",o),"data-testid":"delayed-data-band",children:[(0,a.jsx)("div",{className:"absolute inset-0 rounded-r-md bg-gradient-to-r from-transparent via-background/70 to-background/90 backdrop-blur-[2px]"}),(0,a.jsx)("div",{className:"absolute inset-y-0 left-0 w-px bg-border-strong/70"}),(0,a.jsxs)("div",{className:"pointer-events-auto absolute inset-0 flex flex-col items-center justify-center gap-1.5 px-2 text-center",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"This month"}),d&&(0,a.jsxs)("span",{className:"text-[10px] leading-tight text-muted-foreground/80",children:["You have data ",d.toLowerCase()]}),(0,a.jsx)("button",{type:"button",onClick:()=>{c(f.s6.UPGRADE_CTA_CLICKED,{source:"delayed_data_band",surface:l,metricName:r}),s.push("/plans")},className:"mt-0.5 rounded-md border border-primary/40 bg-primary/10 px-2 py-1 text-[11px] font-semibold text-primary transition-colors hover:bg-primary hover:text-primary-foreground",children:"Unlock"})]})]})}var eu=l(60001);function em(e,t){return(null==t?void 0:t.map(()=>(0,w.hj)(e).assetColor))||[]}function eh(e,t){let l=null==e?void 0:e.metricColorsByAsset;if(l&&"object"==typeof l&&!Array.isArray(l)){let e=l[t];if(Array.isArray(e)){let t=e.filter(e=>"string"==typeof e);return t.length>0?t:null}}if((null==e?void 0:e.metricColorsAsset)===t&&Array.isArray(e.metricColors)){let t=e.metricColors.filter(e=>"string"==typeof e);return t.length>0?t:null}if((null==e?void 0:e.metricColorsAsset)==null&&(null==e?void 0:e.metricColorsByAsset)==null&&Array.isArray(null==e?void 0:e.metricColors)){let t=e.metricColors.filter(e=>"string"==typeof e);return t.length>0?t:null}return null}function ev(e){var t,l,E,ec,ev;let{asset:ef,category:eg,chartMetrics:ep,chartInfo:ex,stacked:eb,combineYaxis:ey,description:eC,metricName:ew,chartTier:eS,dashboard:eN=!1,subCategory:ej,chartId:eA,metricScale:eT="value",hideHeader:eE=!1,chartType:eM,initialTimeframe:eI,alertTriggerConditions:eD,prefetchedData:ek,initialWorkbenchChart:e_,initialWorkbenchEditing:eO=!1}=e,eP=(0,i.useRouter)(),eL=(0,i.useSearchParams)(),{user:eF}=(0,h.a)(),{toast:eR}=(0,j.pm)(),{trackEvent:eU,trackFirstEvent:eW}=(0,v.z)(),eV=(0,n.useRef)(""),eZ=(0,n.useRef)(0),eB=String(ef||"").trim().toLowerCase(),[eQ,ez]=(0,n.useState)("line"),[eY,eK]=(0,n.useState)(!1),[eq,eH]=(0,n.useState)(null),[eJ,eX]=(0,n.useState)([]),[eG,e$]=(0,n.useState)([]),[e0,e1]=(0,n.useState)(null),[e2,e4]=(0,n.useState)(eI||"all"),[e3,e5]=(0,n.useState)("1d"),[e9,e8]=(0,n.use
1State)("log"),[e6,e7]=(0,n.useState)((0,G.fb)(eT||"value")),[te,tt]=(0,n.useState)([]),[tl,ta]=(0,n.useState)([]),[tr,tn]=(0,n.useState)(null),[ti,to]=(0,n.useState)(!1),[ts,tc]=(0,n.useState)([]),[td,tu]=(0,n.useState)([]),[tm,th]=(0,n.useState)([]),[tv,tf]=(0,n.useState)([]),[tg,tp]=(0,n.useState)([]),[tx,tb]=(0,n.useState)([]),[ty,tC]=(0,n.useState)(""),[tw,tS]=(0,n.useState)(),[tN,tj]=(0,n.useState)([]),[tA,tT]=(0,n.useState)([]),[tE,tM]=(0,n.useState)([]),[tI,tD]=(0,n.useState)([]),[tk,t_]=(0,n.useState)(!1),[tO,tP]=(0,n.useState)(!1),[tL,tF]=(0,n.useState)(""),[tR,tU]=(0,n.useState)(null),[tW,tV]=(0,n.useState)("All Exchanges"),[tZ,tB]=(0,n.useState)(em(ef,ep)),[tQ,tz]=(0,n.useState)(eB),[tY,tK]=(0,n.useState)("none"),[tq,tH]=(0,n.useState)("absolute"),[tJ,tX]=(0,n.useState)(!0),[tG,t$]=(0,n.useState)(e_||null),[t0,t1]=(0,n.useState)(!!(e_&&eO)),[t2,t4]=(0,n.useState)(!1),[t3,t5]=(0,n.useState)(!1),t9=!!(tG&&(t0||e_||t3)),t8=(0,n.useMemo)(()=>{var e;return null!==(e=null==ep?void 0:ep.some(e=>O.Uh.includes(e.code)))&&void 0!==e&&e},[ep]),t6=t8&&!t0&&!eE,t7=(0,n.useMemo)(()=>{var e,t;return{surface:"chart",chartId:null!==(e=null!=eA?eA:null==ex?void 0:ex.id)&&void 0!==e?e:null,chartName:null!==(t=null==ex?void 0:ex.name)&&void 0!==t?t:null,asset:null!=ef?ef:null,category:null!=eg?eg:null}},[eA,null==ex?void 0:ex.id,null==ex?void 0:ex.name,ef,eg]),[le,lt]=(0,n.useState)(""),[ll,la]=(0,n.useState)(""),[lr,ln]=(0,n.useState)([]),[li,lo]=(0,n.useState)([]),[ls,lc]=(0,n.useState)(!1),ld=null==ep?void 0:null===(t=ep[0])||void 0===t?void 0:t.code,lu=(0,n.useMemo)(()=>(0,en.b)(ex,ep,ey),[ex,ep,ey]);(0,n.useEffect)(()=>{t$(e_||null),t1(!!(e_&&eO)),t4(!1),t5(!1)},[ef,null==ex?void 0:ex.id,null==ex?void 0:ex.name,eg,ej,e_,eO]),(0,F.Zf)({surface:"chart",label:(null==ex?void 0:ex.name)||"",metricName:(null==ex?void 0:ex.name)||void 0,metricDescription:(null==eC?void 0:eC[0])||void 0,assetName:ty||void 0,assetId:ef||void 0,category:eg,subCategory:ej});let lm=(0,n.useCallback)(e=>{t$(t=>(function(e,t){let l="".concat(V).concat(t.code);if(e.series.some(e=>e.source===l))return e;let a=e.series.filter(Z).length;return{...e,series:[...e.series,function(e){var t;let{metric:l,chart:a,existingOverlays:r}=e,n="".concat(V).concat(l.code),i={area:function(e){let t=(0,W.nC)(e);return"macro_liquidity"===t?"macro":t}(l),metricCode:l.code,metricName:l.name,categoryName:l.collection,url:l.url,collection:l.collection};return{id:n,type:"metric",label:l.name,source:n,expression:null,asset:(null===(t=l.assetId)||void 0===t?void 0:t.toLowerCase())||a.baseAsset||"btc",axis:"right",color:B[r%B.length],style:l.chartStyle||"line",lineWidth:2,scale:null,smoothing:null,metric:i}}({metric:t,chart:e,existingOverlays:a})]}})(t||(0,L.AS)({asset:ef,category:eg,subCategory:ej,chartInfo:ex,chartMetrics:ep,interval:t8?e3:"1d",chartType:eQ||"line",metricColors:tZ,metricScale:lu?e9:e6,priceScale:e9,combineYaxis:lu,includePriceSeries:!0}),e))},[ef,eg,ej,ex,ep,t8,e3,eQ,tZ,lu,e9,e6]),lh=(0,n.useCallback)(e=>{t$(t=>t?{...t,series:t.series.filter(t=>t.source!==e)}:t)},[]),lv=(0,n.useMemo)(()=>{var e;return(null!==(e=null==tG?void 0:tG.series)&&void 0!==e?e:[]).filter(Z)},[tG]),lf=()=>{eU(f.s6.WORKBENCH_OPENED,{surface:"cryptos",asset:ef,category:eg,chartName:null==ex?void 0:ex.name}),t$(e=>e||(0,L.AS)({asset:ef,category:eg,subCategory:ej,chartInfo:ex,chartMetrics:ep,interval:t8?e3:"1d",chartType:eQ||"line",metricColors:tZ,metricScale:lu?e9:e6,priceScale:e9,combineYaxis:lu,includePriceSeries:!0})),t1(!0)},lg=()=>{e_?t$(e_):t$(null),t1(!1),t4(!1)};(0,n.useEffect)(()=>{if(t0&&tG&&t2)return(0,z.H)({hasUnsavedChanges:()=>!0,save:async()=>{let e=await (0,q.y)(tG,{showSuccess:!1});return!!e&&(t$(e),t1(!1),t4(!1),!0)},discard:lg})},[e_,t2,t0,tG]),(0,n.useEffect)(()=>{t$(e=>{if(!e)return e;let t=t8?e3:"1d",l=t0||!!e_,a=l?e.series:e.series.map(e=>{let t=e.source.match(/^metric_(\d+)$/);if(t){var l;let a=Number(t[1])-1;return{...e,color:tZ[a]||e.color,style:eQ||e.style,scale:(0,J.J)(lu?e9:(null==ep?void 0:null===(l=ep[a])||void 0===l?void 0:l.metricScale)||e6)}}return e.source.startsWith("price_usd")?{...e,asset:e.asset||ef,label:"".concat((e.asset||ef).toUpperCase(),": Price USD"),scale:(0,J.J)(e9)}:e}),r={...e,baseAsset:ef,settings:l?e.settings:{...e.settings,timeframe:e2,interval:t,chartType:eQ||e.settings.chartType},series:a,updatedAt:new Date().toISOString()};return JSON.stringify(r)===JSON.stringify(e)?e:r})},[ef,ep,lu,e_,t8,t0,tZ,e3,e9,e6,e2,eQ]),(0,n.useEffect)(()=>
1{if(!t8){ln([]);return}(0,m.K2j)(ef,ld).then(e=>{ln([{value:"",label:"All Exchanges"},...(e||[]).map(e=>e.exchange).filter(e=>e&&""!==e).map(e=>({value:e,label:(0,O.w8)(e)}))])}).catch(()=>ln([{value:"",label:"All Exchanges"}]))},[ef,t8,ld]),(0,n.useEffect)(()=>{if(!t8){lo([]);return}la(""),lc(!0),(0,m.olg)(ef,le||void 0,ld).then(e=>{lo((e||[]).map(e=>e.symbol).filter(e=>e&&""!==e))}).catch(()=>lo([])).finally(()=>lc(!1))},[ef,t8,le,ld]),(0,n.useEffect)(()=>{eI&&e4(eI)},[eI]);let[lp,lx]=(0,n.useState)(null),[lb,ly]=(0,n.useState)(!0),[lC,lw]=(0,n.useState)(null),lS=!["Exchange Inflow","Exchange Inflow (USD)","Exchange Outflow","Exchange Outflow (USD)","Exchange Withdrawal Count"].includes((null==ex?void 0:ex.name)||"")||!["btc","eth"].includes(ef),lN="".concat(ef,"-").concat((null==ex?void 0:ex.id)||(null==ex?void 0:ex.name)||eg||"crypto");(0,n.useEffect)(()=>{(async()=>{try{let e=await (0,m.h9)(ef);tC((null==e?void 0:e.name)||ef.toUpperCase()),tS(null==e?void 0:e.urlImage)}catch(e){tC(ef.toUpperCase()),tS(void 0)}})()},[ef]),(0,n.useEffect)(()=>{let e=em(ef,ep);try{let t=localStorage.getItem("crypto_ma_state_".concat(lN));if(t){let l=JSON.parse(t);Array.isArray(l.movingAveragePeriods)&&tt(l.movingAveragePeriods.map(e=>Number(e))),Array.isArray(l.emaPeriods)&&ta(l.emaPeriods.map(e=>Number(e))),Array.isArray(l.maColors)&&tc(l.maColors),Array.isArray(l.emaColors)&&tu(l.emaColors),Array.isArray(l.maDashed)&&th(l.maDashed),Array.isArray(l.emaDashed)&&tj(l.emaDashed),Array.isArray(l.maLineStyles)&&tf(l.maLineStyles),Array.isArray(l.emaLineStyles)&&tT(l.emaLineStyles),Array.isArray(l.maLineWidths)&&tp(l.maLineWidths.map(e=>Number(e)||2)),Array.isArray(l.emaLineWidths)&&tM(l.emaLineWidths.map(e=>Number(e)||2)),Array.isArray(l.maVisualStyles)&&tb(l.maVisualStyles),Array.isArray(l.emaVisualStyles)&&tD(l.emaVisualStyles),tB(eh(l,eB)||e),tz(eB),"boolean"==typeof l.colorByValue&&tX(l.colorByValue)}else tB(e),tz(eB);let l=localStorage.getItem("crypto_roc_mode_".concat(lN));("percent"===l||"absolute"===l)&&tH(l)}catch(t){console.error("Erro ao restaurar estado do localStorage:",t),tB(e),tz(eB)}},[lN,ef,eB,ep]),(0,n.useEffect)(()=>{if(lu){e7(e=>e===e9?e:e9);return}eT&&e7((0,G.fb)(eT))},[lu,eT,e9]),(0,n.useEffect)(()=>{if(tQ===eB)try{let e="crypto_ma_state_".concat(lN),t={};{let l=localStorage.getItem(e);if(l)try{let e=JSON.parse(l);e.metricColorsByAsset&&"object"==typeof e.metricColorsByAsset&&!Array.isArray(e.metricColorsByAsset)&&(t=e.metricColorsByAsset)}catch(e){}}t={...t,[eB]:tZ};let l={movingAveragePeriods:te,emaPeriods:tl,maColors:ts,emaColors:td,maDashed:tm,emaDashed:tN,maLineStyles:tv,emaLineStyles:tA,maLineWidths:tg,emaLineWidths:tE,maVisualStyles:tx,emaVisualStyles:tI,metricColors:tZ,metricColorsAsset:eB,metricColorsByAsset:t,colorByValue:tJ};localStorage.setItem(e,JSON.stringify(l))}catch(e){console.error("Erro ao salvar estado no localStorage:",e)}},[lN,eB,tQ,te,tl,ts,td,tm,tN,tv,tA,tg,tE,tx,tI,tZ,tJ]),(0,n.useEffect)(()=>{localStorage.setItem("crypto_roc_mode_".concat(lN),tq)},[tq,lN]),(0,n.useEffect)(()=>{let e=em(ef,ep);try{let t=localStorage.getItem("crypto_ma_state_".concat(lN));if(t){let l=JSON.parse(t);tB(eh(l,eB)||e)}else tB(e);tz(eB)}catch(t){console.error("Erro ao verificar cores salvas no localStorage:",t),tB(e),tz(eB)}},[ef,eB,lN,ep]),(0,n.useEffect)(()=>{th(e=>{let t=[...e];for(;t.length<te.length;)t.push(!1);return t.slice(0,te.length)}),tf(e=>{let t=[...e];for(;t.length<te.length;)t.push("solid");return t.slice(0,te.length)}),tp(e=>{let t=[...e];for(;t.length<te.length;)t.push(2);return t.slice(0,te.length)}),tb(e=>{let t=[...e];for(;t.length<te.length;)t.push("line");return t.slice(0,te.length)})},[te]),(0,n.useEffect)(()=>{tj(e=>{let t=[...e];for(;t.length<tl.length;)t.push(!1);return t.slice(0,tl.length)}),tT(e=>{let t=[...e];for(;t.length<tl.length;)t.push("solid");return t.slice(0,tl.length)}),tM(e=>{let t=[...e];for(;t.length<tl.length;)t.push(2);return t.slice(0,tl.length)}),tD(e=>{let t=[...e];for(;t.length<tl.length;)t.push("line");return t.slice(0,tl.length)})},[tl]);let lj=eN?"":eL.get("chart")||(null==ex?void 0:ex.name)||"",lA=(0,T.Fg)(eJ,ld),lT=e=>{var t,l,a,n;if(null==lA)return;let i=eL.get("chartType"),o=!ll&&!le&&"All Exchanges"===tW&&"none"===tY&&("1d"===e2||"all"===e2),s=Number(lA.toPrecision(6));eU(f.s6.CHART_ALERT_PREFILL_CLICKED,{metric:(null==ep?void 0:null===(t=ep[0])||void 0===t?void 0:t.code)||"",chart:lj,asset:ef,level:s,direction:e}),tn({asset:ef,metric:(null==ep?void 0:null===(l=ep[0])||void 0===l?void 0:l.name)||"",metricCode:(null==ep?void 0:null===(a=ep[0])||void 0===a?void 0:a.code)||"",category:eg,subCategory:ej,chart:lj,chartType:i||null,chartId:(null==ex?void 0:ex.id)?parseInt(ex.id.toString()):eA?parseInt(eA):void 0,chartSource:"crypto",presetOperator:"above"===e?"Gt":"Lt",presetValue:o?s:void 0,openCreate:!0,exchange:"",setupNotice:o?void 0:"This setup monitors the base metric. Symbol, market-type and display transformations are not applied. Choose a level for the unfiltered series.",presetFrequency:"OnlyOnce",presetTitle:"".concat(ef.toUpperCase()," ").concat((null==ep?void 0:null===(n=ep[0])||void 0===n?void 0:n.name)||lj," alert"),smartReference:o?(0,r.N3)((0,T.IQ)(eJ.slice(-31),ld),e2):void 0}),t_(!0)};(0,C.h)(lp,eS);let lE=!lb&&!(0,C.B)({user:eF,userTier:lp,requiredTier:eS}).isLocked;(0,y.m)(!!(eF&&!eN&&lE&&(null==ex?void 0:ex.id)&&ep.length),lf),(0,n.useEffect)(()=>
1{if((null==ek?void 0:ek.userTier)!=null){lx(ek.userTier),ly(!1);return}(async()=>{if(!(null==eF?void 0:eF.uid)){lx(1),ly(!1);return}ly(!0),lw(null);try{let e=await (0,m.ET7)();lx(e.data)}catch(e){console.error("Failed to fetch user tier:",e),lw(e.message||"Failed to fetch user tier"),lx(null)}finally{ly(!1)}})()},[null==eF?void 0:eF.uid,null==ek?void 0:ek.userTier]);let lM=t9&&(null==tG?void 0:tG.name)?tG.name:(null==ex?void 0:ex.name)||"",lI=tY&&"none"!==tY?"".concat(lM," (").concat(null!==(E=_.i1[tY])&&void 0!==E?E:tY.toUpperCase(),")"):lM,lD=(0,n.useMemo)(()=>(null==e0?void 0:e0.rows.length)?e0:(0,$.bg)(eJ,lM||"chart"),[e0,eJ,lM]),lk=()=>lD,l_=()=>"".concat(ef,"-").concat(lM||"chart","-data"),lO=(0,n.useMemo)(()=>{let e=function(e){if(!e)return null;let t=new URLSearchParams(e).get("previewDelay");if(!t)return null;let l=/^\d{4}-\d{2}-\d{2}$/.test(t)?new Date("".concat(t,"T23:59:59")):function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date;return eo(new Date(e.getFullYear(),e.getMonth(),0))}();return Number.isNaN(l.getTime())?null:{dataDelayedUntil:l.toISOString(),delayReason:"tier"}}(window.location.search);return function(e){var t;let l=null==e?void 0:e.dataDelayedUntil;if(!l)return ei;let a=new Date(l);if(Number.isNaN(a.getTime()))return ei;let r=new Date(a);return r.setDate(r.getDate()+1),r.setHours(0,0,0,0),{until:eo(a),from:r,reason:null!==(t=null==e?void 0:e.delayReason)&&void 0!==t?t:"tier",active:!0}}(null!=e?e:ek)},[ek]),lP=(0,n.useMemo)(()=>lO.active?es(lO):(0,et.D)(lD),[lD,lO]),lL=async(e,t)=>{var l,a,r,n,i;let o=++eZ.current;if(!lE){eX([]),e$([]),eH(null),eK(!1);return}if(!ep||0===ep.length){eH("No metrics available for this chart"),eK(!1);return}eK(!0),eH(null);try{let n,i;let s=t8?e3:"all",c=(0,ee.Vj)({area:"crypto",asset:e,category:eg,chartId:null!==(l=null!=eA?eA:null==ex?void 0:ex.id)&&void 0!==l?l:null,chartName:null!==(a=null==ex?void 0:ex.name)&&void 0!==a?a:null,metrics:ep.map(e=>({code:e.code,url:e.url,collection:e.collection})),selectedEntity:t8?null:tW,selectedExchange:t8&&le||null,selectedSymbol:t8&&ll||null,apiTimeframe:s}),d=ek&&"All Exchanges"===tW&&!le&&!ll&&(!t8||"1d"===e3);if(d||(0,ee.xE)(c)||(eX([]),e$([])),d)n=(n=ek.priceData||[]).map(e=>{var t,l;return{...e,priceUSD:null!==(l=null!==(t=e.PriceUSD)&&void 0!==t?t:e.priceUSD)&&void 0!==l?l:e.price}}),i=ek.metrics.map(e=>e.accessDenied||e.error||!e.data?[]:Array.isArray(e.data)?e.data:[]),(0,ee.ho)(c,{priceData:n,results:i});else{if(!lE){o===eZ.current&&(eX([]),e$([]),eK(!1));return}try{let t=await (0,ee.xo)(c,async()=>{let t=(0,m.urE)(e,s),l=Promise.all(ep.map(t=>(0,m.OOv)(e,t.url||"".concat(eg,"/").concat(t.code),s,t8?void 0:tW,t.code,t8?{...le?{exchange:le}:{},...ll?{symbol:ll}:{}}:void 0))),[a,r]=await Promise.all([t,l]);return{priceData:a,results:r}});n=t.priceData,i=t.results}catch(e){o===eZ.current&&(eH("Failed to fetch data: ".concat(e.message||"Unknown error")),eK(!1));return}}if(o!==eZ.current)return;let u=t8?e3:"1d",h=new Map(n.map(e=>{var t,l;return[(0,w.SX)(e.time,u),null!==(l=null!==(t=e.priceUSD)&&void 0!==t?t:e.PriceUSD)&&void 0!==l?l:e.price]})),v=new Date,f=i.map(e=>(0,X.K3)(e,t,e=>e.time,v,2e3));if(0===f.length||f.every(e=>0===e.length)){"All Exchanges"!==tW&&(eR({title:"No data available",description:'No records found for "'.concat(tW,'". Switching to All Exchanges.'),variant:"destructive"}),tV("All Exchanges")),o===eZ.current&&(eX([]),e$([]),eK(!1));return}let g=e=>{let t=new Map;return ep.forEach((l,a)=>{let r=(0,k.hi)(l),n=(0,k.Le)(r,tW),i=tW&&"All Exchanges"!==tW?"".concat(r,"_").concat(tW.replace(/\s+/g,"_")):null,o=[...i?[i]:[],r,l.code,l.code.toLowerCase(),l.code.toUpperCase(),l.code.charAt(0).toUpperCase()+l.code.slice(1).toLowerCase(),...i?[]:["value"]];e[a].forEach(e=>{let l=e.time;if(!l)return;let a=(0,w.SX)(l,u),r=t.get(a);r||(r={time:l,price:Number(h.get(a))||0},t.set(a,r));let i=o.find(t=>void 0!==e[t]&&null!==e[t]);r[n]=void 0!==i?e[i]:null})}),Array.from(t.values()).sort((e,t)=>new Date(e.time).getTime()-new Date(t.time).getTime())},b=g(f),y=g(i);if(o!==eZ.current)return;eX(b),e$(y);let C="".concat(e,"::").concat(null!=eA?eA:"","::").concat(null!==(r=null==ex?void 0:ex.id)&&void 0!==r?r:"");eV.current!==C&&(eV.current=C,(0,x.h8)("chart",C,Date.now())&&(eU("chart_viewed",{chartId:null!=eA?eA:null==ex?void 0:ex.id,chartName:null==ex?void 0:ex.name,asset:e,category:eg,timeframe:t,...t6?{resolution:e3}:{}}),eW("chart_viewed","first_chart_viewed",{chartType:eQ,asset:e,chartName:null==ex?void 0:ex.name}),(0,p.DI)("first_chart_viewed","first_chart_viewed",{chartType:eQ,asset:e,chartName:null==ex?void 0:ex.name})))}catch(e){if(o!==eZ.current)return;eH("Error fetching data: "+((null===(i=e.response)||void 0===i?void 0:null===(n=i.data)||void 0===n?void 0:n.error)||e.message||String(e))),c
1onsole.error("Error fetching data:",e),eX([]),e$([])}finally{o===eZ.current&&eK(!1)}};(0,n.useEffect)(()=>{let e=ep&&ep.length>0&&ep[0].chartStyle||"line";ez(e),to("area"===e)},[ep]),(0,n.useEffect)(()=>{if(!lE){eZ.current+=1,eX([]),e$([]),eK(!1);return}ep&&ep.length>0?lL(ef,e2):(eZ.current+=1,eX([]),e$([]),eK(!1))},[ef,e2,e3,ep,tW,le,ll,t8,lE,eg,eA,null==ex?void 0:ex.id,null==ex?void 0:ex.name]);let lF=eL.get("myChartId"),lR=(e,t)=>{let l=(0,G.fb)(t);if("price"===e&&e8(l),"metric"===e&&e7(l),!tG)return;let a=(0,Q.C)(tG,e,(0,J.J)(t));a!==tG&&(t$(a),lF&&(0,Y.b4)().save(a).then(e=>t$(e)).catch(()=>{}))},lU=(0,n.useMemo)(()=>{if(tG&&t9&&!t0)return(0,Q.c)(tG).map(e=>({id:e.id,label:e.label,value:e.value,onChange:t=>lR(e.id,t)}))},[lF,t9,t0,tG]),lW=(0,H.a)(t9?tG:null),lV=(0,n.useRef)(null);(0,U.G)({ready:!eN&&!lb&&!eY&&!eq&&eJ.length>0&&!(0,C.B)({user:eF,userTier:lp,requiredTier:eS}).isLocked,tourKey:"chart_actions_tour_v1",onOpenAi:e=>{tU({text:(0,R._Y)("Explain this metric for ".concat(e.asset.toUpperCase(),". What does the latest reading mean, and what should I compare it with?"),e.knowledgeLevel),revision:Date.now()}),tP(!0)}});let lZ=lb||eY;return(0,a.jsx)("div",{className:"relative w-full h-full",children:(0,a.jsxs)("div",{className:"relative h-full transition-all duration-300 ease-out ".concat(tO&&!eN?"pr-[420px] xl:pr-[520px]":"pr-0"),children:[(0,a.jsx)(M.Z,{isLoading:lb,user:eF,userTier:lp,requiredTier:eS,minHeightClass:eN?"h-full":void 0,compact:!!eN,title:eN?void 0:lM,description:eN?void 0:null==ex?void 0:ex.description,assetIcon:eN?void 0:tw,children:(0,a.jsxs)("div",{className:"flex flex-col w-full h-full ".concat(eN?"":"gap-2"),style:{overflow:eN?"hidden":"visible"},children:[!eN&&(0,a.jsx)(b.Z,{variant:"chart",ready:!eY&&!eq&&eJ.length>0&&!t0&&!tO&&!tk}),(0,a.jsxs)("div",{id:"full",className:"w-full h-full flex flex-col ".concat(eN?"":"bg-card rounded-lg shadow-md p-4 ".concat(I.C)),style:{overflow:eN?"hidden":"visible"},children:[!t0&&!(eN&&eE)&&(0,a.jsx)(c.Z,{dashboard:eN,hideHeaderTitle:eE,hideControlBar:eE,typeChart:eQ,onChartTypeChange:e=>{ez(e),"area"===e?to(!0):to(!1)},onToggleArea:()=>{to(e=>!e)},showArea:ti,asset:ef,category:eg,subCategory:ej,selectedEntity:tW,onEntityChange:e=>{tV(e)},scalePrice:e9,scaleTransactionCount:e6,timeframe:e2,emaPeriods:tl,maColors:ts,emaColors:td,maDashed:tm,emaDashed:tN,maLineStyles:tv,emaLineStyles:tA,maLineWidths:tg,emaLineWidths:tE,maVisualStyles:tx,emaVisualStyles:tI,onAssetChange:e=>{tV("All Exchanges"),eP.push("?asset=".concat(e))},onTimeframeChange:e=>{if(function(e,t){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Date;if(!t.active||!t.until)return!1;let a=/^(\d+)([dwmy])$/.exec(e);if(a){let[,e,r]=a,n=new Date(l),i=Number(e);return"d"===r&&n.setDate(n.getDate()-i),"w"===r&&n.setDate(n.getDate()-7*i),"m"===r&&n.setMonth(n.getMonth()-i),"y"===r&&n.setFullYear(n.getFullYear()-i),n>t.until}return"mtd"===e&&new Date(l.getFullYear(),l.getMonth(),1)>t.until}(e,lO)){var t;eU(f.s6.PAYWALL_HIT,{feature:"delayed_data",surface:"timeframe",timeframe:e,delayedUntil:null===(t=lO.until)||void 0===t?void 0:t.toISOString()}),eR({title:"Not on your plan",description:"That range is inside the current month. You have data ".concat((es(lO)||"").toLowerCase()," — upgrade to see it up to today.")});return}(0,g.BW)(t7,e2,e),e4(e)},onScalePriceChange:e=>{e8(e),lu&&e7(e)},onScaleTransactionCount:e=>{e7(e),lu&&e8(e)},onAddMovingAveragePeriod:e=>{tt(t=>{let l=t.findIndex(t=>Number(t)===Number(e));return l>-1?(tc(e=>e.filter((e,t)=>t!==l)),th(e=>e.filter((e,t)=>t!==l)),tf(e=>e.filter((e,t)=>t!==l)),tp(e=>e.filter((e,t)=>t!==l)),tb(e=>e.filter((e,t)=>t!==l)),t.filter(t=>Number(t)!==Number(e))):(tc(e=>[...e,void 0]),th(e=>[...e,!1]),tf(e=>[...e,"solid"]),tp(e=>[...e,2]),tb(e=>[...e,"line"]),[...t,e])})},movingAveragePeriods:te,onAddEmaPeriod:e=>{ta(t=>{let l=t.findIndex(t=>Number(t)===Number(e));return l>-1?(tu(e=>e.filter((e,t)=>t!==l)),tj(e=>e.filter((e,t)=>t!==l)),tT(e=>e.filter((e,t)=>t!==l)),tM(e=>e.filter((e,t)=>t!==l)),tD(e=>e.filter((e,t)=>t!==l)),t.filter(t=>Number(t)!==Number(e))):(tu(e=>[...e,void 0]),tj(e=>[...e,!1]),tT(e=>[...e,"solid"]),tM(e=>[...e,2]),tD(e=>[...e,"line"]),[...t,e])})},onMaColorChange:(e,t)=>
1{tc(l=>{let a=[...l];return a[e]=t,a})},onEmaColorChange:(e,t)=>{tu(l=>{let a=[...l];return a[e]=t,a})},onToggleMaDashed:e=>{th(t=>{let l=[...t];return l[e]=!l[e],l})},onToggleEmaDashed:e=>{tj(t=>{let l=[...t];return l[e]=!l[e],l})},onMaLineStyleChange:(e,t)=>{tf(l=>{let a=[...l];return a[e]=t,a}),th(l=>{let a=[...l];return a[e]="dashed"===t,a})},onEmaLineStyleChange:(e,t)=>{tT(l=>{let a=[...l];return a[e]=t,a}),tj(l=>{let a=[...l];return a[e]="dashed"===t,a})},onMaLineWidthChange:(e,t)=>{tp(l=>{let a=[...l];return a[e]=t,a})},onEmaLineWidthChange:(e,t)=>{tM(l=>{let a=[...l];return a[e]=t,a})},onMaVisualStyleChange:(e,t)=>{tb(l=>{let a=[...l];return a[e]=t,a})},onEmaVisualStyleChange:(e,t)=>{tD(l=>{let a=[...l];return a[e]=t,a})},title:lI,chartInfo:ex,combineYaxis:lu,showExchangeSelector:lS,metricColors:tZ,onMetricColorChange:(e,t)=>{tB(l=>{let a=[...l];return a[e]=t,a})},chartMetrics:ep,onToggleDock:()=>tP(!tO),isDockOpen:tO,onAlertsClick:()=>{var e,t;if(!eN&&null!=lA){lT("above");return}let l=eN?(null==ex?void 0:ex.name)||"":eL.get("chart")||(null==ex?void 0:ex.name)||"",a=eN?eM||null:eL.get("chartType");tn({asset:ef,metric:(null==ep?void 0:null===(e=ep[0])||void 0===e?void 0:e.name)||"",metricCode:(null==ep?void 0:null===(t=ep[0])||void 0===t?void 0:t.code)||"",category:eg,subCategory:ej,chart:l,chartType:a||null,chartId:(null==ex?void 0:ex.id)?parseInt(ex.id.toString()):eA?parseInt(eA):void 0}),t_(!0)},rateOfChange:tY,onRateOfChangeChange:e=>{if(tK(e),"none"!==e&&"none"===tY)lV.current=eQ,ez("area"),to(!0);else if("none"===e&&"none"!==tY){let e=lV.current;lV.current=null,e&&(ez(e),to("area"===e))}},rateOfChangeMode:tq,onRateOfChangeModeChange:tH,colorByValue:tJ,onColorByValueChange:tX,resolution:t8?e3:void 0,onResolutionChange:t8?e=>{(0,g.q1)(t7,e3,e),e5(e)}:void 0,resolutionOptions:t8?O.pS:void 0,exchange:t8?le||"":void 0,onExchangeChange:t8?lt:void 0,exchangeOptions:t8?lr:void 0,symbolOptions:t8?li:void 0,selectedSymbol:t8?ll:void 0,onSymbolChange:t8?la:void 0,isLoadingSymbols:ls,onWorkbenchOpen:eN?void 0:lf,reading:!eN&&lj?(0,a.jsx)(T.ZP,{compact:!0,asset:ef,chartName:lj,currentValue:null!=lA?(0,T.aI)(lA):null,onAlertAt:lT,points:(0,T.IQ)(eJ,ld),timeframe:e2,metricLabel:(null==ep?void 0:null===(l=ep[0])||void 0===l?void 0:l.name)||lj,onExplain:e=>{tF(e),tP(!0)}}):void 0,latestLabel:lP,scaleAxisRows:lU,shareUrl:t9?lW||"":void 0,shareTitle:t9?"Share ".concat(tG.name):void 0}),!eN&&tG&&t0&&(0,a.jsx)(P.Z,{chart:tG,onChartChange:e=>{t$(e),t4(!0)},onSaved:e=>{t$(e),t1(!1),t4(!1),t5(!0);let t=(0,K.q)(e,ef||"btc");eL.get("myChartId")?eP.replace(t):eP.push(t)},onCancel:lg,hideShareButton:!0,defaultAsset:ef,latestLabel:lP}),(0,a.jsx)(s.Z,{error:eq,isLoading:lZ}),!eN&&(0,a.jsx)(D.ZP,{items:(0,D.Ye)(eJ,null!==(ec=null==ep?void 0:ep.map(e=>({label:e.name,dataKey:(0,k.Le)((0,k.hi)(e),tW)})))&&void 0!==ec?ec:[])}),lv.length>0&&(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 px-1 pb-1.5",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Added by Alpha AI"}),lv.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-border/60 bg-card/60 px-2 py-0.5 text-[11px] text-foreground",children:[(0,a.jsx)("span",{"aria-hidden":!0,className:"size-2 rounded-sm",style:{backgroundColor:e.color}}),e.label,(0,a.jsx)("button",{type:"button",onClick:()=>lh(e.source),"aria-label":"Remove ".concat(e.label," from this chart"),className:"-mr-0.5 rounded-sm p-0.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:(0,a.jsx)(el.Z,{className:"size-3"})})]},e.source))]}),(0,a.jsxs)("div",{"data-tour":eN?void 0:"chart-data",className:"flex w-full flex-1 min-h-0 relative",style:{overflow:eN?"hidden":"visible"},children:[(0,a.jsx)(ed,{delay:lO,surface:"chart",metricName:lM}),(0,a.jsx)(o.Z,{transactionData:eJ,fullData:eG,asset:ef,scalePrice:e9,scaleTransactionCount:e6,timeframe:e2,isLoading:lZ,typeChart:eQ,movingAveragePeriods:te,emaPeriods:tl,maColors:ts,emaColors:td,maDashed:tm,emaDashed:tN,maLineStyles:tv,emaLineStyles:tA,maLineWidths:tg,emaLineWidths:tE,maVisualStyles:tx,emaVisualStyles:tI,screenShotTitle:lI,chartMetrics:ep,isStacked:eb,combineYaxis:lu,selectedEntity:tW,title:lI,metricColors:tZ,rateOfChange:tY,rateOfChangeMode:tq,colorByValue:tJ,dashboard:eN,chartId:eA,alertTriggerConditions:eD,workbenchChart:tG,workbenchDrawingEditable:t0,onExportData:e1})]}),!eN&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(S.default,{isOpen:tO,onToggle:()=>tP(!tO),metricName:(null==ex?void 0:ex.name)||"",assetName:ty,chartId:(null==ex?void 0:ex.id)||0,assetId:ef,initialQuery:tL,initialDraft:null==tR?void 0:tR.text,draftRevision:null!==(ev=null==tR?void 0:tR.revision)&&void 0!==ev?ev:0,onInitialQuerySent:()=>tF(""),onOverlayMetric:lm}),(0,a.jsx)(N.default,{chartId:(null==ex?void 0:ex.id)||(eA?parseInt(String(eA),10):0),metricName:(null==ex?void 0:ex.name)||"",assetName:ty,assetId:ef,hidden:lb||(0,C.B)({user:eF,userTier:lp,requiredTier:eS}).isLocked,isDockOpen:tO,onToggleDock:()=>tP(!tO),onSendFromExpanded:e=>{tF(e),tP(!0)}})]}),(0,a.jsx)(A.Z,{isOpen:tk,onClose:()=>t_(!1),initialContext:tr})]})]})}),!eN&&(0,a.jsxs)("div",{className:"w-full border-t border-border/30 pt-6 pb-4 px-4 mt-4 mb-24",children:[eC&&eC.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,a.jsx)("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,a.jsx)("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"About this metric"})]}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground leading-relaxed mb-5",children:eC[0]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,a.jsxs)("button",{onClick:()=>window.open(eu.E,"_blank"),className:"flex items-center gap-2 px-4 py-2 text-xs font-medium text-foreground bg-muted/50 hover:bg-muted border border-border rounded-lg transition-all hover:shadow-sm",children:[(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),"View API Docs"]}),(0,a.jsxs)("button",{onClick:()=>
1{if((null!=lp?lp:1)<2){eU(f.s6.PAYWALL_HIT,{feature:"data_export",format:"csv",surface:"chart",requiredTier:2,currentTier:null!=lp?lp:1,asset:ef,chartName:null==ex?void 0:ex.name}),eR({title:"CSV download is available for Pro plan users and above."}),eP.push("/plans");return}let e=lk();if(!e){eR({title:"No data available to download."});return}eU(f.s6.DATA_EXPORTED,{format:"csv",surface:"chart",asset:ef,chartName:null==ex?void 0:ex.name,category:eg,rows:e.rows.length,tier:lp}),(0,$.dT)(e,l_())},disabled:(null!=lp?lp:1)<2,className:"flex items-center gap-2 px-4 py-2 text-xs font-medium text-foreground bg-muted/50 hover:bg-muted border border-border rounded-lg transition-all hover:shadow-sm disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:shadow-none",title:(null!=lp?lp:1)<2?"Available for Pro plan and above":"Download CSV",children:[(0,a.jsx)(ea.Z,{className:"w-4 h-4"}),"CSV Download"]}),(0,a.jsxs)("button",{onClick:()=>{if((null!=lp?lp:1)<2){eU(f.s6.PAYWALL_HIT,{feature:"data_export",format:"excel",surface:"chart",requiredTier:2,currentTier:null!=lp?lp:1,asset:ef,chartName:null==ex?void 0:ex.name}),eR({title:"Excel download is available for Pro plan users and above."}),eP.push("/plans");return}let e=lk();if(!e){eR({title:"No data available to download."});return}eU(f.s6.DATA_EXPORTED,{format:"excel",surface:"chart",asset:ef,chartName:null==ex?void 0:ex.name,category:eg,rows:e.rows.length,tier:lp}),(0,$.uX)(e,l_())},disabled:(null!=lp?lp:1)<2,className:"flex items-center gap-2 px-4 py-2 text-xs font-medium text-foreground bg-muted/50 hover:bg-muted border border-border rounded-lg transition-all hover:shadow-sm disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:shadow-none",title:(null!=lp?lp:1)<2?"Available for Pro plan and above":"Download Excel",children:[(0,a.jsx)(er.Z,{className:"w-4 h-4"}),"Excel Download"]}),(0,a.jsx)(u.Z,{})]}),(0,a.jsx)(d.Z,{asset:ef,chartId:null==ex?void 0:ex.id})]})]})})}var ef=e=>(0,a.jsx)(n.Suspense,{fallback:(0,a.jsx)(E.MQ,{}),children:(0,a.jsx)(ev,{...e})})},73172:function(e,t,l){l.d(t,{Fg:function(){return h},IQ:function(){return v},ZP:function(){return g},aI:function(){return d}});var a=l(57437),r=l(2265),n=l(69824),i=l(12522),o=l(93448),s=l(52326),c=l(12988);function d(e){let t=Math.abs(e);return t>=1e9?"".concat((e/1e9).toFixed(2),"B"):t>=1e6?"".concat((e/1e6).toFixed(2),"M"):t>=1e3?"".concat((e/1e3).toFixed(1),"K"):t>=1?e.toFixed(2):e.toPrecision(3)}let u=["time","timestamp","date","price"];function m(e,t){if(t&&"number"==typeof e[t]&&Number.isFinite(e[t]))return t;let l=Object.entries(e).filter(e=>{let[t,l]=e;return!u.includes(t)&&"number"==typeof l&&Number.isFinite(l)});return 1===l.length?l[0][0]:null}function h(e,t){if(0===e.length)return null;let l=e[e.length-1],a=m(l,t);return a?l[a]:null}function v(e,t){if(0===e.length)return[];let l=m(e[e.length-1],t);if(!l)return[];let a=[];for(let t of e){var r,n,i;let e=t[l];"number"==typeof e&&Number.isFinite(e)&&a.push({t:String(null!==(i=null!==(n=null!==(r=t.time)&&void 0!==r?r:t.timestamp)&&void 0!==n?n:t.date)&&void 0!==i?i:""),v:e})}return a}let f=e=>"".concat(e>=0?"+":"−").concat(Math.abs(100*e).toFixed(.1>Math.abs(e)?1:0),"%");function g(e){let{asset:t,chartName:l,currentValue:d,points:u,timeframe:m,metricLabel:h,onExplain:v,compact:g=!1,className:p}=e,{trackEvent:x}=(0,s.z)(),b=(0,r.useMemo)(()=>{if(!u||u.length<8)return null;let e=u[u.length-1].v,t=u[u.length-8].v,l=0!==t?e/t-1:null,a=u.slice(-90),r=a.filter(t=>t.v<=e).length/a.length,n=!m||"1d"===m||"all"===m,i=n?"".concat(a.length,"d"):"".concat(a.length," \xd7 ").concat(m);return{change:l,rankText:r>=.5?"top ".concat(Math.max(1,Math.round((1-r)*100)),"% of ").concat(i):"bottom ".concat(Math.max(1,Math.round(100*r)),"% of ").concat(i),tone:null==l||0===l?"neutral":l>0?"up":"down",stepLabel:n?"7d":"7 \xd7 ".concat(m),windowLabel:i}},[u,m]);return b&&d?(0,a.jsxs)("section",{className:(0,o.cn)("flex flex-wrap items-center gap-x-3 gap-y-1",g?"px-1":"mt-3 border-t border-border/50 px-1 py-2",p),"aria-label":"Chart reading",children:[(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-2.5 gap-y-1 text-[12px]",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:"Latest"}),(0,a.jsx)("span",{className:"font-semibold tabular-nums text-foreground",children:d}),null!=b.change&&(0,a.jsxs)("span",{className:(0,o.cn)("tabular-nums",i.em[b.tone]),children:[i.b2[b.tone]&&(0,a.jsx)("span",{className:"mr-0.5 text-[9px]","aria-hidden":!0,
1children:i.b2[b.tone]}),f(b.change)," ",(0,a.jsx)("span",{className:"text-muted-foreground",children:b.stepLabel})]})]}),v&&(0,a.jsxs)("button",{type:"button",onClick:()=>{if(!b||!d||!v)return;let e=null!=b.change?"".concat(f(b.change)," over the last ").concat(b.stepLabel):"no change data",a="Explain today's reading of ".concat(h||l," for ").concat(t.toUpperCase(),": ").concat(d,", ").concat(e,", ").concat(b.rankText,". What does it imply for the next few days?");x(c.s6.CHART_READ_EXPLAIN_CLICKED,{chart:l,asset:t,value:d,change:b.change,rank:b.rankText,ui_version:"chart_footer_v2"}),v(a)},className:"inline-flex min-h-8 items-center gap-1.5 rounded-md px-2 text-[12px] font-medium text-primary hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/60",children:[(0,a.jsx)(n.Z,{className:"size-[18px]"}),g?"Alpha AI":"Explain with Alpha AI"]})]}):null}},40686:function(e,t,l){l.d(t,{Z:function(){return J}});var a=l(57437),r=l(2265),n=l(94373),i=l(49322),o=l(46166),s=l(25922),c=l(3532),d=l(60825),u=l(90701),m=l(24422),h=l(12705),v=l(91767),f=l(35840),g=l(61749),p=l(1247),x=l(62984),b=l(31155),y=l(49184),C=l(80865),w=l(26389),S=l(79414),N=l(79896),j=l(91854);function A(e,t,l){return t<=1?l:("right"===e?54:58)+(t-1)*44}let T=e=>"object"==typeof e&&null!=e&&"kind"in e&&"series"===e.kind;function E(e,t){return"new"===e?t:"right"===e||"left"===e||(0,j.ye)(e)?e:"left"}function M(e,t){let l=Number(e);return Number.isFinite(l)?"price"===t?"$".concat((0,d.T4)(l)):"percent"===t?"".concat(l.toFixed(2),"%"):(0,d.uf)(l):"-"}function I(e,t,l){if(l)return l;if(null==t?void 0:t.valueFormat)return t.valueFormat;let a=String(e||"").match(/\((WoW|MoM|QoQ|HoH|YoY)(?:\s+(%|Abs))?\)/i);if(a){var r;return(null===(r=a[2])||void 0===r?void 0:r.toLowerCase())==="abs"?"number":"percent"}return(0,y.lc)(e)?"price":"number"}function D(e){return"log"===e}function k(e,t){if(!Number.isFinite(e)||!Number.isFinite(t))return{min:0,max:1};if(e===t){let l=.08*Math.abs(e||1);return{min:e-l,max:t+l}}let l=t-e;return t<=0?{min:e-.02*l,max:t+(t<0?Math.min(.01*l,.03*Math.abs(t)):0)}:{min:e-.015*l,max:t+.025*l}}function _(e){var t;return e.some(e=>"log"===e.scale)?"log":(null===(t=e[0])||void 0===t?void 0:t.scale)||"linear"}function O(e){let t=Array.from(new Set(e.map(e=>e.axisKey))),l=t.filter(e=>(0,j.ye)(e)).sort((e,t)=>Number(e.slice(1))-Number(t.slice(1))),a=t.filter(e=>e.startsWith("new-")||e.startsWith("smooth-")),r=t.filter(e=>"left"!==e&&"right"!==e&&!(0,j.ye)(e)&&!a.includes(e));return[...t.includes("left")?["left"]:[],...l,...a,...r,...t.includes("right")?["right"]:[]]}function P(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];let l=Math.min(e.length-1,Math.max(0,t*(e.length-1))),a=Math.floor(l),r=Math.ceil(l);if(a===r)return e[a];let n=l-a;return e[a]*(1-n)+e[r]*n}function L(e){for(let l=e.points.length-1;l>=0;l-=1){var t;let a=Number(null===(t=e.points[l])||void 0===t?void 0:t.value);if(Number.isFinite(a))return a}return null}function F(e,t){let l=D(t),a=e.flatMap(e=>e.points.map(e=>Number(e.value)).filter(e=>Number.isFinite(e)&&(!l||e>0)));if(0===a.length)return l?{min:1,max:10}:{min:0,max:1};let r=(0,o.G)(a),n=(0,o.u)(a);return l?{min:Math.max(.8*r,Number.MIN_VALUE),max:n===r?1.2*n:1.12*n}:e.some(e=>e.source.rateOfChange&&"none"!==e.source.rateOfChange)?function(e,t){let l=(0,o.G)(e),a=(0,o.u)(e);if(!(l<0&&a>0)||e.length<20)return k(l,a);let r=[...e].sort((e,t)=>e-t),n=r.filter(e=>e<0),i=r.filter(e=>e>0),s=n.map(e=>Math.abs(e)).sort((e,t)=>e-t),c=t.map(L).filter(e=>null!=e),d=c.filter(e=>e<0),u=c.filter(e=>e>0),m=d.map(e=>Math.abs(e)),h=Math.max(P(s,.95),...m,1),v=Math.max(P(i,.95),...u,1),f=a/v,g=Math.abs(l)/h,p=f>10?.75:.95,x=P(r,g>10?.25:.02),b=Math.max(P(r,p),P(i,p)),y=Math.max(0,f>10?Math.min(b,12*v):b,...u),C=Math.min(-Math.max(P(s,g>10?.98:1),...m,.08*y,1),x,...d),w=g>10||C<0&&Math.abs(l)>1.5*Math.abs(C);return(f>10||y>0&&a>1.5*y||w)&&C<y?k(C,y):k(l,a)}(a,e):k(r,n)}function R(e){let t=new Date(e.time).getTime();return Number.isFinite(t)?t:null}function U(e,t,l){let a=e.flatMap(e=>e.points.map(R)).filter(e=>null!=e);if(0===a.length)return null;let r=(0,o.G)(a),n=(0,o.u)(a);return n>
1r?{startTime:r+Math.max(0,Math.min(100,t))/100*(n-r),endTime:r+Math.max(0,Math.min(100,l))/100*(n-r)}:null}function W(e){var t,l,a,r,n,i,o,s,c,d,u,m,h;try{let s=null===(o=e.getModel)||void 0===o?void 0:null===(i=o.call(e))||void 0===i?void 0:null===(n=i.getComponent)||void 0===n?void 0:null===(r=n.call(i,"xAxis",0))||void 0===r?void 0:null===(a=r.axis)||void 0===a?void 0:null===(l=a.scale)||void 0===l?void 0:null===(t=l.getExtent)||void 0===t?void 0:t.call(l),c=Z(Array.isArray(s)?s[0]:null),d=Z(Array.isArray(s)?s[1]:null);if(null!=c&&null!=d&&d>c)return{startTime:c,endTime:d}}catch(e){}try{let t=null===(h=e.getModel)||void 0===h?void 0:null===(m=h.call(e))||void 0===m?void 0:null===(u=m.getComponent)||void 0===u?void 0:null===(d=u.call(m,"grid",0))||void 0===d?void 0:null===(c=d.coordinateSystem)||void 0===c?void 0:null===(s=c.getRect)||void 0===s?void 0:s.call(c),l=Number(null==t?void 0:t.x),a=Number(null==t?void 0:t.y),r=Number(null==t?void 0:t.width),n=Number(null==t?void 0:t.height);if(Number.isFinite(l)&&Number.isFinite(a)&&Number.isFinite(r)&&Number.isFinite(n)&&r>0&&n>0){let t=a+n/2,i=Z(e.convertFromPixel({xAxisIndex:0},[l,t])),o=Z(e.convertFromPixel({xAxisIndex:0},[l+r,t]));if(null!=i&&null!=o&&o>i)return{startTime:i,endTime:o}}}catch(e){}return{startTime:null,endTime:null}}function V(e){try{let t=e.getOption(),l=Array.isArray(t.dataZoom)?t.dataZoom[0]:t.dataZoom,a=W(e);return{start:"number"==typeof(null==l?void 0:l.start)?l.start:0,end:"number"==typeof(null==l?void 0:l.end)?l.end:100,startValue:null==l?void 0:l.startValue,endValue:null==l?void 0:l.endValue,startTime:a.startTime,endTime:a.endTime}}catch(e){return{start:0,end:100}}}function Z(e){if(Array.isArray(e))return Z(e[0]);if("number"==typeof e&&Number.isFinite(e))return e>1e11?e:e>1e9?1e3*e:null;if("string"!=typeof e||""===e.trim())return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function B(e){let t=Array.isArray(e)?e[1]:"object"==typeof e&&null!=e&&"value"in e?Array.isArray(e.value)?(e.value||[])[1]:e.value:e;if(null==t)return null;let l=Number(t);return Number.isFinite(l)?l:null}function Q(e){if(Array.isArray(e))return[e[0],null,...e.slice(2)];if("object"==typeof e&&null!=e&&"value"in e){let t=e.value;return Array.isArray(t)?{...e,value:[t[0],null,...t.slice(2)]}:{...e,value:null}}return null}function z(e){if(Array.isArray(e))return e[0];if("object"==typeof e&&null!=e){var t,l,a;return Array.isArray(e.value)?e.value[0]:null!==(a=null!==(l=null!==(t=e.time)&&void 0!==t?t:e.date)&&void 0!==l?l:e.name)&&void 0!==a?a:null}return null}function Y(e,t){if(Array.isArray(e))return[e[0],t,...e.slice(2)];if("object"==typeof e&&null!=e&&"value"in e){let l=e.value;return Array.isArray(l)?{...e,value:[l[0],t,...l.slice(2)]}:{...e,value:t}}return t}function K(e){if("number"==typeof e&&Number.isFinite(e))return e;if(null==e)return null;let t=new Date(String(e)).getTime();return Number.isFinite(t)?t:null}function q(e,t){let l=[],a=null,r=null;return e.forEach(e=>{let n=B(e);if(null==n){l.push(Q(e)),a=e,r=null;return}null!=r&&(r>=0?"positive":"negative")!=(n>=0?"positive":"negative")&&l.push(function(e,t,l,a){let r=K(z(e)),n=K(z(t)),i=a-l,o=0!==i&&Number.isFinite(i)?(0-l)/i:.5,s=Math.max(0,Math.min(1,Number.isFinite(o)?o:.5)),c=null!=r&&null!=n&&n!==r?r+(n-r)*s:z(0===a?t:e);return Y(Array.isArray(t)?[c,t[1],...t.slice(2)]:"object"==typeof t&&null!=t?Array.isArray(t.value)?{...t,value:[c,t.value[1],...t.value.slice(2)]}:{...t,time:c}:t,0)}(a,e,r,n));let i="positive"===t?n>=0:n<0;l.push(Y(e,i?n:null)),a=e,r=n}),l}function H(e,t){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=O(e),r=new Map(a.map((e,t)=>[e,t])),n=new Map;a.forEach(t=>{n.set(t,_(e.filter(e=>e.axisKey===t)))});let i=e.map(e=>{var l,a;let i=(0,N.Kz)(e.style),o=D(n.get(e.axisKey)),s=(0,S.nG)(e.style,e.color,{...e.source,lineStyle:e.lineStyle||e.source.lineStyle,lineWidth:null!==(l=e.lineWidth)&&void 0!==l?l:e.source.lineWidth}),c="bubble"===e.style?(0,N.E)(e.points,e.bubbleSizePoints,o):function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.map(e=>{let l=Number(e.value),a=null==e.value||!Number.isFinite(l)||t&&l<=0?null:l;return[e.time,a]})}(e.points,o),d=(0,N.WR)(e.style);return(0,x.nd)({id:"wb:".concat(e.source.id,":").concat(e.idKey||"main"),name:e.label,type:i,yAxisIndex:r.get(e.axisKey)||0,data:c,workbenchSeriesId:e.source.id,showSymbol:!!d,symbol:d?"circle":void 0,encode:{x:0,y:1,tooltip:"bubble"===e.style?[1,2]:[1]},symbolSize:"bubble"===e.style?(0,N.iy)(e.source,c):"scatter"===e.style?(0,N.bd)(e.source):void 0,connectNulls:!0,itemStyle:(0,N.oO)(e.source,s.itemStyle,c),lineStyle:s.lineStyle,areaStyle:s.areaStyle,barWidth:s.barWidth,barMaxWidth:null!==(a=s.barMaxWidth)&&void 0!==a?a:12,barGap:s.barGap,barCategoryGap:s.barCategoryGap,legendHoverLink:d,z:d?60:void 0,emphasis:d?{focus:"series",label:{show:"bubble"===e.style,formatter:t=>{var l;return M(null==t?void 0:null===(l=t.data)||void 0===l?void 0:l[1],e.valueFormat)},color:"#e2e8f0",fontSize:10}}:{disabled:!0},blur:{disabled:!0}},t,e.color)}).flatMap(e=>(function(e,t){var l,a,r,n;let i="string"==typeof e.workbenchSeriesId?e.workbenchSeriesId:"",o=i.split(":")[0]||i,s=t.series.find(e=>e.id===i||e.id===o),c=String(e.id||"").includes(":smoothing-"),d=(null==s?void 0:s.signColor)===!0&&!c;if(!s||!d||s.bubbleHeatmap||"line"!==e.type||!Array.isArray(e.data))return[e];let u=e.data,m=s.positiveColor||"#22c55e",h=s.negativeColor||"#ef4444",v=e.lineStyle||{},f=e.areaStyle||void 0,g=Number(null!==(a=null!==(l=v.width)&&void 0!==l?l:s.lineWidth)&&void 0!==a?a:2),p=Number.isFinite(g)?Math.max(.5,g):2,x=function(e){for(let t=e.length-1;t>=0;t-=1){let l=B(e[t]);if(null!=l)return l}return null}(u),b=null!=x&&x<0?h:m,y=String(e.id||s.id),C={...e,tooltip:{show:!0},silent:!1,latestValueDisabled:!0,workbenchExcludeFromExport:!0,connectNulls:!1,z:Math.max(Number(e.z||0),20)};return[{...e,data:u.map(Q),exportData:u,latestValueData:u,latestValueColor:b,lineStyle:{...v,color:b,opacity:1,width:Math.max(1.5,p)},itemStyle:{...e.itemStyle||{},color:b,opacity:1},areaStyle:f?{...f,color:"rgba(0,0,0,0)",opacity:0}
1:void 0,z:Math.min(Number(e.z||0),0)},{...C,id:"".concat(y,":positive"),data:q(u,"positive"),lineStyle:{...v,color:m,opacity:1,width:p},itemStyle:{...e.itemStyle||{},color:m,opacity:1},areaStyle:f?{...f,color:m,opacity:null!==(r=f.opacity)&&void 0!==r?r:.18}:void 0},{...C,id:"".concat(y,":negative"),data:q(u,"negative"),lineStyle:{...v,color:h,opacity:1,width:p},itemStyle:{...e.itemStyle||{},color:h,opacity:1},areaStyle:f?{...f,color:h,opacity:null!==(n=f.opacity)&&void 0!==n?n:.18}:void 0}]})(e,t)),o=new Set(e.filter(e=>!e.isSmoothing&&!1===l[e.label]).map(e=>e.source.id)),s=0===o.size?t:{...t,colorRanges:(t.colorRanges||[]).filter(e=>!o.has(e.seriesId)),drawings:(t.drawings||[]).filter(e=>!o.has(e.seriesId))};return(0,x.we)((0,x.Xk)(i,s),s)}function J(e){var t,l,o,S;let{chart:j,height:k=760,minHeight:P=720,onExportData:L,drawingsEditable:Q=!1}=e,{resolvedTheme:z,theme:Y}=(0,s.F)(),K=z||Y,[q,J]=(0,r.useState)({}),[X,G]=(0,r.useState)({}),[$,ee]=(0,r.useState)(!0),[et,el]=(0,r.useState)(null),[ea,er]=(0,r.useState)(0),en=(0,r.useRef)(null),ei=(0,r.useRef)(null),eo=(0,r.useRef)(null),es=(0,r.useRef)({}),ec=(0,r.useRef)({start:0,end:100,startTime:null,endTime:null}),ed=(0,r.useRef)(null),eu=(0,r.useCallback)(()=>{var e,t;return(null===(t=ei.current)||void 0===t?void 0:null===(e=t.getEchartsInstance)||void 0===e?void 0:e.call(t))||null},[]),em=(0,r.useCallback)(e=>{eo.current!==e&&(eo.current=e,er(e=>e+1))},[]);(0,C.O)({chartId:j.id,getChartInstance:eu,drawings:j.drawings||[],editable:Q}),(0,r.useEffect)(()=>{es.current={},ec.current={start:0,end:100,startTime:null,endTime:null},ed.current=null},[j.id]);let eh=(0,r.useMemo)(()=>{var e,t,l,a,r,n;return JSON.stringify({enabled:!!(null===(e=j.settings.timeWindow)||void 0===e?void 0:e.enabled),startDate:(null===(t=j.settings.timeWindow)||void 0===t?void 0:t.startDate)||null,trimStartDays:null!==(r=null===(l=j.settings.timeWindow)||void 0===l?void 0:l.trimStartDays)&&void 0!==r?r:0,trimEndDays:null!==(n=null===(a=j.settings.timeWindow)||void 0===a?void 0:a.trimEndDays)&&void 0!==n?n:0})},[null===(t=j.settings.timeWindow)||void 0===t?void 0:t.enabled,null===(l=j.settings.timeWindow)||void 0===l?void 0:l.startDate,null===(o=j.settings.timeWindow)||void 0===o?void 0:o.trimStartDays,null===(S=j.settings.timeWindow)||void 0===S?void 0:S.trimEndDays]),ev=(0,r.useMemo)(()=>JSON.stringify({baseAsset:j.baseAsset,metricSeries:j.series.filter(e=>"metric"===e.type).map(e=>({id:e.id,source:e.source,asset:e.asset,metric:e.metric})),formulaSeries:j.series.filter(e=>"formula"===e.type).map(e=>({id:e.id,source:e.source,expression:e.expression})),relativeScales:j.series.map(e=>e.scale).filter(e=>"btc_relative"===e||"asset_relative"===e)}),[j.baseAsset,j.series]),ef=(0,r.useMemo)(()=>({...j,settings:{...j.settings,timeframe:"all"}}),[ev]);(0,r.useEffect)(()=>{let e=!1;return(async()=>{ee(!0),el(null);try{var t;let l=await (0,c.sv)(ef),a=(0,h.Pe)(ef.series),r={...l};ef.series.forEach(e=>{let t=l[e.source];void 0!==t&&(0,h.q_)(r,a,e,t)});let n=(0,v.cY)(Object.values(r),{interval:ef.settings.interval,preferDenseDaily:!ef.settings.interval||"1d"===ef.settings.interval});r=(0,v.MS)(r,n);let i=n.length>0?n:null===(t=Object.values(r).find(T))||void 0===t?void 0:t.points;for(let e of ef.series)if("formula"===e.type&&e.expression)try{let t=(0,u.LY)(e.expression,r),l=(0,u.ct)(e.source,e.label,t.value,i);(0,h.q_)(r,a,e,l)}catch(t){console.warn('Workbench formula "'.concat(e.label,'" failed to evaluate:'),t),(0,h.q_)(r,a,e,{kind:"series",points:[]})}let o=[];ef.series.some(e=>"btc_relative"===e.scale)&&o.push((0,c.QI)(ef,"btc").then(e=>["btc_relative",e])),ef.series.some(e=>"asset_relative"===e.scale)&&o.push((0,c.QI)(ef,ef.baseAsset||"btc").then(e=>["asset_relative",e]));let s=await Promise.all(o);e||(J(r),G(Object.fromEntries(s)))}catch(t){e||(J({}),el((null==t?void 0:t.message)||"Failed to load workbench chart."))}finally{e||ee(!1)}})(),()=>{e=!0}},[ef]);let eg=(0,r.useMemo)(()=>{let e=[],t=(e,t,l,a,r)=>{let n=(0,m.pK)(e,l,a),i="bar"===r&&null!=l&&"none"!==l?(0,m.UN)(n):n,o=(0,m.hZ)(i,t,X[t||""]),s=(0,c.kt)(o,j.settings.timeframe);return!function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.some(e=>{let l=Number(e.value);return Number.isFinite(l)&&(!t||l>0)})}(s,D(t))?null:s};
1return j.series.forEach((l,a)=>{if(!1===l.visible)return;let r=q[l.source];if(!T(r))return;let n=E(l.axis,"new-".concat(l.id||a)),i=(0,N.EU)(l),o=(0,f.yl)(l).filter(e=>!1!==e.visible),s=o.find(e=>e.applyToSource),c=(null==s?void 0:s.source)?q[s.source]:null,d=s&&T(c)?c:r,u=t(s?(0,f.ob)(d.points,s.type,s.period):r.points,i,l.rateOfChange,l.rateOfChangeMode,l.style);null!=u&&(e.push({source:l,label:l.label,points:u,axisKey:n,color:(0,b.uj)(l,K,l.color),style:l.style,scale:i,bubbleSizePoints:"bubble"===l.style?(0,N.lF)(l,q,j.series):void 0,valueFormat:(0,y.fm)(l)}),o.filter(e=>!e.applyToSource).forEach((a,i)=>{let o=a.source?q[a.source]:null,s=T(o)?o:r,c=(0,f.ob)(s.points,a.type,a.period),d=(0,N.EU)(l),u=t(c,d,l.rateOfChange,l.rateOfChangeMode,a.style||l.style);null!=u&&e.push({source:l,label:"".concat(l.label," ").concat(a.type.toUpperCase()," ").concat(a.period),points:u,axisKey:a.axis?E(a.axis,"smooth-".concat(l.id,"-").concat(a.id||i)):n,color:a.color||(0,b.uj)(l,K,l.color),style:a.style||l.style,lineStyle:a.lineStyle||"solid",lineWidth:Math.max(1,Number(a.lineWidth)||2),bubbleSizePoints:"bubble"===(a.style||l.style)?(0,N.lF)(l,q,j.series):void 0,scale:d,isSmoothing:!0,idKey:"smoothing-".concat(a.id||i),valueFormat:(0,y.fm)(l)})}))}),(0,w.vH)(e,j.settings.timeWindow)},[K,j.series,j.settings.timeframe,j.settings.timeWindow,X,q]),ep=(0,r.useMemo)(()=>{let e=O(eg),t=e=>eg.some(t=>t.axisKey===e),l=e.filter(e=>"right"!==e&&t(e)).length,a=e.filter(e=>"right"===e&&t(e)).length,r=e.map((r,n)=>{var i;let o=eg.filter(e=>e.axisKey===r),s=_(o),c=D(s),u=o.map(e=>e.valueFormat),m=u.length>0&&u.every(e=>"percent"===e),h=u.length>0&&u.every(e=>"price"===e),v=0===o.length,f="right"===r?"right":"left",g=e.slice(0,n).filter(e=>("right"===e?"right":"left")===f&&t(e)).length,p=F(o,s),x=(null===(i=o[0])||void 0===i?void 0:i.color)||"#94a3b8",b=("right"===f?a:l)>1?44:0;return{show:!v,type:c?"log":"value",name:null,position:f,offset:g>0?g*b:0,scale:!0,min:p.min,max:p.max,nameLocation:"middle",nameRotate:90,nameGap:0,splitLine:{show:0===n,lineStyle:{color:"rgba(148,163,184,0.16)"}},axisLine:{show:!0,lineStyle:{color:x,width:2}},nameTextStyle:{color:x,fontWeight:600},axisLabel:{color:x,inside:!1,margin:4,formatter:h?e=>"$".concat((0,d.T4)(e)):m?e=>"".concat(e,"%"):e=>(0,d.uf)(e)},axisPointer:{label:{show:!0,backgroundColor:"rgba(17, 24, 39, 0.8)",formatter:e=>h?"$".concat((0,d.T4)(Number(e.value))):m?"".concat(Number(e.value).toFixed(2),"%"):(0,d.uf)(Number(e.value))}}}}),n=H(eg,j),i=(0,x.oQ)((0,N.M0)(j,n),n,j),o=(0,N.bY)(i),s=l>1||a>1,c=A("left",l,s&&l>0?44:6),u=A("right",a,a>0?44:6);return{backgroundColor:"transparent",animation:!1,color:eg.map(e=>e.color),grid:{top:o.has("top")?Math.max(36,N.Ih):36,right:o.has("right")?Math.max(u,N.Tg):u,bottom:o.has("bottom")?Math.max(54,N.Ih):54,left:o.has("left")?Math.max(c,N.Tg):c,containLabel:!s},tooltip:{trigger:"axis",backgroundColor:"rgba(15,23,42,0.94)",borderColor:"rgba(148,163,184,0.25)",textStyle:{color:"#e2e8f0"},formatter:e=>{let t=Array.isArray(e)?e:[e],l=t[0];return[Array.isArray(null==l?void 0:l.data)?l.data[0]:"",...t.filter(e=>null!=B(e.data)).map(e=>{let t=eg.find(t=>t.label===e.seriesName),l=B(e.data);return"".concat(e.marker," ").concat(e.seriesName,": ").concat(M(l,I(e.seriesName,t)))})].join("<br/>")}},legend:{top:0,type:"scroll",data:eg.map(e=>e.label),textStyle:{color:"#cbd5e1"}},xAxis:{type:"time",position:"bottom",boundaryGap:["0.2%","0.2%"],axisLabel:{color:"#94a3b8"},axisLine:{onZero:!1,onZeroAxisIndex:null,lineStyle:{color:"rgba(148,163,184,0.35)"}},splitLine:{show:!1}},yAxis:r,dataZoom:[{type:"slider",xAxisIndex:[0],start:0,end:100,zoomLock:!1,handleSize:"80%",filterMode:"empty",height:20,bottom:10,borderColor:"rgba(148,163,184,0.2)",textStyle:{color:"#94a3b8"}},{type:"inside",handleSize:"80%",xAxisIndex:[0],start:0,end:100,zoomLock:!1,zoomOnMouseWheel:!0,moveOnMouseMove:!0,moveOnMouseWheel:!1,preventDefaultMouseMove:!0,filterMode:"empty"},{type:"inside",yAxisIndex:(Array.isArray(r)?r:[r]).map((e,t)=>t),zoomLock:!1,zoomOnMouseWheel:"shift",moveOnMouseMove:!1,moveOnMouseWheel:!1,preventDefaultMouseMove:!1,filterMode:"none"}],series:n,visualMap:i}},[j,eg]);return((0,r.useEffect)(()=>{let e=Array.isArray(ep.series)?ep.series:ep.series?[ep.series]:[];null==L||L((0,g.AD)(e,j.name))},[j.name,L,ep]),(0,r.useEffect)(()=>{var e,t;let l=null===(t=ei.current)||void 0===t?void 0:null===(e=t.getEchartsInstance)||void 0===e?void 0:e.call(t);if(!l)return;let a=Array.isArray(ep.series)?ep.series:ep.series?[ep.series]:[],r=e=>{if((null==e?void 0:e.selected)&&"object"==typeof e.selected)return es.current=e.selected,es.current;if(Object.keys(es.current).length>0)return es.current;try{let e=l.getOption(),t=Array.isArray(e.legend)?e.legend[0]:e.legend,a=(null==t?void 0:t.selected)||{};if(Object.keys(a).length>0)return es.current=a,a;return es.current}catch(e){return es.current}},n=()=>{try{let e=l.getOption().series;if(Array.isArray(e))return e;if(e)return[e]}catch(e){}return a},i=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r();return n().filter(t=>!1!==e[String((null==t?void 0:t.name)||"")])},o=(0,N.bY)(ep.visualMap),s=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r(),a=O(eg),n=function(e,t,l){var a,r;let n=e.filter(e=>!1!==l[e.label]),i=U(e,t.start,t.end);if(!i)return n;let o=null!==(a=t.startTime)&&void 0!==a?a:Z(t.startValue),s=null!==(r=t.endTime)&&void 0!==r?r:Z(t.endValue),c=null!=o&&null!=s&&s>o,d=c?o:i.startTime,u=c?s:i.endTime;return n.map(e=>({...e,points:function(e,t,l){let a=null,r=null,n=[];
1return(e.points.forEach(e=>{let i=R(e);if(null!=i){if(i<t){(!a||i>a.time)&&(a={time:i,point:e});return}if(i>l){(!r||i<r.time)&&(r={time:i,point:e});return}n.push(e)}}),"line"===e.style||"area"===e.style)?[...a?[a.point]:[],...n,...r?[r.point]:[]]:n}(e,d,u)}))}(eg,e,t),i=a.filter(e=>n.some(t=>t.axisKey===e)),s=i.filter(e=>"right"!==e),c=i.filter(e=>"right"===e),d=e=>{let t="right"==("right"===e?"right":"left")?c:s,l=t.indexOf(e);return l<=0?0:l*(t.length>1?44:0)},u=(()=>{try{let e=l.getOption().yAxis||ep.yAxis;return Array.isArray(e)?e:e?[e]:[]}catch(t){let e=ep.yAxis;return Array.isArray(e)?e:e?[e]:[]}})(),m=a.map((e,t)=>{var l,a;let r=u[t]||{},i=eg.filter(t=>t.axisKey===e),o=n.filter(t=>t.axisKey===e);if(0===o.length)return{...r,show:!1,min:void 0,max:void 0,axisLine:{...r.axisLine,show:!1},axisLabel:{...r.axisLabel,show:!1},axisPointer:{...r.axisPointer,show:!1,triggerTooltip:!1,label:{...(null===(a=r.axisPointer)||void 0===a?void 0:a.label)||{},show:!1}}};let s=_(i),c=F(o,s);return{...r,show:!0,offset:d(e),type:D(s)?"log":"value",min:c.min,max:c.max,axisLine:{...r.axisLine,show:!0},axisLabel:{...r.axisLabel,show:!0},axisPointer:{...r.axisPointer,show:!0,label:{...(null===(l=r.axisPointer)||void 0===l?void 0:l.label)||{},show:!0}}}}),h=s.length,v=c.length,f=h>1||v>1,g=A("left",h,f&&h>0?44:6),p=A("right",v,v>0?44:6);return{xAxis:{position:"bottom",axisLine:{onZero:!1,onZeroAxisIndex:null}},yAxis:m,grid:{left:o.has("left")?Math.max(g,N.Tg):g,right:o.has("right")?Math.max(p,N.Tg):p,containLabel:!f}}},c=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r(),t=arguments.length>1?arguments[1]:void 0,a=arguments.length>2?arguments[2]:void 0,n=t;if(!n)try{n=l.getOption().yAxis}catch(e){}(0,p.S8)(l,n||ep.yAxis,a||i(e),{idPrefix:"workbench-".concat(j.id),formatValue:(e,t)=>{let l=eg.find(e=>e.label===t.name),a=t.workbenchFormatter;return M(e,I(t.name,l,a))}})},d=null,u=null,m=e=>{null!=d&&cancelAnimationFrame(d),null!=u&&clearTimeout(u),d=requestAnimationFrame(()=>{u=setTimeout(()=>{try{var t,n,i,o,d,u,m,h,v;if(null===(t=l.isDisposed)||void 0===t?void 0:t.call(l))return;let f=ec.current,g=e?f:V(l),p=(null==e?void 0:e.batch)?e.batch[0]:e;if((null==e?void 0:e.type)==="legendselectchanged"){let t=r(e),n=(0,x.oQ)((0,N.M0)(j,a).map(e=>{let l=a[Array.isArray(null==e?void 0:e.seriesIndex)?e.seriesIndex[0]:null==e?void 0:e.seriesIndex];return l&&!1===t[String(l.name||"")]?{...e,show:!1}:e}),a,j),i=s(ec.current,t);ed.current=i,l.setOption({yAxis:i.yAxis,grid:i.grid,legend:{data:eg.map(e=>e.label),selected:t},visualMap:n},{notMerge:!1,lazyUpdate:!1,silent:!0,replaceMerge:["yAxis","visualMap"]});let o=a.filter(e=>!1!==t[String((null==e?void 0:e.name)||"")]);requestAnimationFrame(()=>c(t,i.yAxis,o));return}let b=Z(null==p?void 0:p.startValue),y=Z(null==p?void 0:p.endValue),C="number"==typeof(null==p?void 0:p.start)?p.start:g.start,w="number"==typeof(null==p?void 0:p.end)?p.end:g.end,S=U(eg,C,w),A={start:C,end:w,startValue:null!==(i=null!==(n=null==p?void 0:p.startValue)&&void 0!==n?n:g.startValue)&&void 0!==i?i:f.startValue,endValue:null!==(d=null!==(o=null==p?void 0:p.endValue)&&void 0!==o?o:g.endValue)&&void 0!==d?d:f.endValue,startTime:null!==(m=null!==(u=null!=b?b:null==S?void 0:S.startTime)&&void 0!==u?u:g.startTime)&&void 0!==m?m:f.startTime,endTime:null!==(v=null!==(h=null!=y?y:null==S?void 0:S.endTime)&&void 0!==h?h:g.endTime)&&void 0!==v?v:f.endTime};ec.current=A;let T=r(e),E=s(A,T);ed.current=E;let M=(0,x.oQ)((0,N.M0)(j,a).map(e=>{let t=a[Array.isArray(null==e?void 0:e.seriesIndex)?e.seriesIndex[0]:null==e?void 0:e.seriesIndex];return t&&!1===T[String(t.name||"")]?{...e,show:!1}:e}),a,j);l.setOption({...E,legend:{data:eg.map(e=>e.label),selected:T},visualMap:M},{notMerge:!1,lazyUpdate:!1,silent:!0,replaceMerge:["yAxis","visualMap"]});let I=a.filter(e=>!1!==T[String((null==e?void 0:e.name)||"")]);requestAnimationFrame(()=>c(T,E.yAxis,I))}catch(e){}},0)})},h=e=>{var t,a,r,n,i,o,s,c;let d=ec.current,u=W(l),m=(null==e?void 0:e.batch)?e.batch[0]:e,h="number"==typeof(null==m?void 0:m.start)?m.start:d.start,v="number"==typeof(null==m?void 0:m.end)?m.end:d.end,f=U(eg,h,v);ec.current={start:h,end:v,startValue:null!==(t=null==m?void 0:m.startValue)&&void 0!==t?t:d.startValue,endValue:null!==(a=null==m?void 0:m.endValue)&&void 0!==a?a:d.endValue,
1startTime:null!==(i=null!==(n=null!==(r=Z(null==m?void 0:m.startValue))&&void 0!==r?r:null==f?void 0:f.startTime)&&void 0!==n?n:u.startTime)&&void 0!==i?i:d.startTime,endTime:null!==(c=null!==(s=null!==(o=Z(null==m?void 0:m.endValue))&&void 0!==o?o:null==f?void 0:f.endTime)&&void 0!==s?s:u.endTime)&&void 0!==c?c:d.endTime}},v=e=>{h(e),m(e)},f=e=>{m(e)};return m(),l.on("dataZoom",v),l.on("legendselectchanged",f),()=>{l.off("dataZoom",v),l.off("legendselectchanged",f),null!=d&&cancelAnimationFrame(d),null!=u&&clearTimeout(u)}},[j,j.id,ea,eg,ep]),(0,r.useEffect)(()=>{if($)return;let e=()=>{var e,t;return(null===(t=ei.current)||void 0===t?void 0:null===(e=t.getEchartsInstance)||void 0===e?void 0:e.call(t))||null},t=(e,t)=>{var l,a,r,n,i,o,s;try{let l=null===(s=e.getModel)||void 0===s?void 0:null===(o=s.call(e))||void 0===o?void 0:null===(i=o.getComponent)||void 0===i?void 0:null===(n=i.call(o,"grid",0))||void 0===n?void 0:null===(r=n.coordinateSystem)||void 0===r?void 0:null===(a=r.getRect)||void 0===a?void 0:a.call(r),c=Number(null==l?void 0:l.x),d=Number(null==l?void 0:l.width);if(Number.isFinite(c)&&Number.isFinite(d)&&d>0)return Math.min(.98,Math.max(.02,(t[0]-c)/d))}catch(e){}let c=Math.max(1,Number((null===(l=e.getWidth)||void 0===l?void 0:l.call(e))||1));return Math.min(.98,Math.max(.02,t[0]/c))},l=(e,t)=>{var l,a,r,n,i,o,s,c;try{let l=null===(c=e.getModel)||void 0===c?void 0:null===(s=c.call(e))||void 0===s?void 0:null===(o=s.getComponent)||void 0===o?void 0:null===(i=o.call(s,"grid",0))||void 0===i?void 0:null===(n=i.coordinateSystem)||void 0===n?void 0:null===(r=n.getRect)||void 0===r?void 0:r.call(n),a=Number(null==l?void 0:l.x),d=Number(null==l?void 0:l.y),u=Number(null==l?void 0:l.width),m=Number(null==l?void 0:l.height);if(Number.isFinite(a)&&Number.isFinite(d)&&Number.isFinite(u)&&Number.isFinite(m)&&u>0&&m>0)return t[0]>=a-8&&t[0]<=a+u+8&&t[1]>=d-8&&t[1]<=d+m+8}catch(e){}let d=Number((null===(l=e.getWidth)||void 0===l?void 0:l.call(e))||0),u=Number((null===(a=e.getHeight)||void 0===a?void 0:a.call(e))||0);return Number.isFinite(d)&&Number.isFinite(u)&&t[0]>=0&&t[0]<=d&&t[1]>=0&&t[1]<=u},a=(e,t,l)=>{try{let a=e.getOption(),r=(Array.isArray(a.dataZoom)?a.dataZoom:a.dataZoom?[a.dataZoom]:[]).map((e,a)=>0===a||1===a?{...e,start:t,end:l}:e);r.length>=2&&e.setOption({dataZoom:r},{notMerge:!1,lazyUpdate:!1,silent:!1})}catch(e){}},r=(e,r,n)=>{if(!l(e,r))return!1;let i=function(e,t,l){let a=Math.max(.05,e.end-e.start),r=t<0,n=Math.min(100,Math.max(.05,a*(r?.84:1.18)));if(!r&&a>=99.95)return null;let i=e.start+a*l,o=i-n*l,s=i+n*(1-l);return o<0&&(s-=o,o=0),s>100&&(o-=s-100,s=100),{start:o=Math.max(0,o),end:s=Math.min(100,s)}}(ec.current,n,t(e,r));if(!i)return;let{start:o,end:s}=i;return e.dispatchAction({type:"dataZoom",batch:[{dataZoomIndex:0,start:o,end:s},{dataZoomIndex:1,start:o,end:s}]}),requestAnimationFrame(()=>{let t=V(e);.01>Math.abs(t.start-o)&&.01>Math.abs(t.end-s)||a(e,o,s)}),!0},n=t=>{var l,a,n;if(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return;let i=e();if(!i||(null===(l=i.isDisposed)||void 0===l?void 0:l.call(i)))return;let o=null===(a=i.getDom)||void 0===a?void 0:a.call(i);if(!o)return;let s=o.getBoundingClientRect();r(i,[t.clientX-s.left,t.clientY-s.top],t.deltaY)&&(t.preventDefault(),t.stopPropagation(),null===(n=t.stopImmediatePropagation)||void 0===n||n.call(t))},i={capture:!0,passive:!1},o=new WeakSet,s=!1,c=null,d=null,u=null,m=e=>{o.has(e)||(o.add(e),n(e))},h=t=>{var l,a,n,i,s,c,d,u;let m=null==t?void 0:t.event;if(m){if(o.has(m))return;o.add(m)}if((null==m?void 0:m.shiftKey)||(null==m?void 0:m.ctrlKey)||(null==m?void 0:m.metaKey)||(null==m?void 0:m.altKey))return;let h=e();if(!h||(null===(l=h.isDisposed)||void 0===l?void 0:l.call(h)))return;let v="number"==typeof(null==m?void 0:m.deltaY)?m.deltaY:"number"==typeof(null==t?void 0:t.wheelDelta)?-t.wheelDelta:0;if(!Number.isFinite(v)||0===v)return;let f=[Number(null!==(c=null!==(s=null==t?void 0:t.zrX)&&void 0!==s?s:null==m?void 0:m.offsetX)&&void 0!==c?c:0),Number(null!==(u=null!==(d=null==t?void 0:t.zrY)&&void 0!==d?d:null==m?void 0:m.offsetY)&&void 0!==u?u:0)];Number.isFinite(f[0])&&Number.isFinite(f[1])&&r(h,f,v)&&(null==m||null===(a=m.preventDefault)||void 0===a||a.call(m),null==m||null===(n=m.stopPropagation)||void 0===n||n.call(m),null==m||null===(i=m.stopImmediatePropagation)||void 0===i||i.call(m),t.cancelBubble=!0)},v=function(){var t,l,a,r;let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,o=e(),f=null==o?void 0:null===(t=o.getDom)||void 0===t?void 0:t.call(o);if(!o||!f||(null===(l=o.isDisposed)||void 0===l?void 0:l.call(o))){n<12&&(c=setTimeout(()=>v(n+1),80));return}s||(s=!0,d=f,u=null===(a=o.getZr)||void 0===a?void 0:a.call(o),window.addEventListener("wheel",m,i),f.addEventListener("wheel",m,i),null==u||null===(r=u.on)||void 0===r||r.call(u,"mousewheel",h))};return v(),()=>{if(null!=c&&clearTimeout(c),s){var e;window.removeEventListener("wheel",m,i),null==d||d.removeEventListener("wheel",m,i),null==u||null===(e=u.off)||void 0===e||e.call(u,"mousewheel",h)}}},[j.id,ea,$,ep]),(0,r.useEffect)(()=>{let e=en.current;if(!e)return;let t=()=>{var e,t,l;let a=null===(t=ei.current)||void 0===t?void 0:null===(e=t.getEchartsInstance)||void 0===e?void 0:e.call(t);if(!(!a||(null===(l=a.isDisposed)||void 0===l?void 0:l.call(a)))){try{a.resize({silent:!0})}catch(e){return}requestAnimationFrame(()=>{var e;if(null===(e=a.isDisposed)||void 0===e?void 0:e.call(a))return;let t=a.getOption();if(!t)return;let l=Array.isArray(t.legend)?t.legend[0]:t.legend,r=(null==l?void 0:l.selected)||{},n=Object.keys(r).length>0?r:es.current;Object.keys(r).length>0&&(es.current=r);let i=H(eg,j,n).filter(e=>!1!==n[String((null==e?void 0:e.name)||"")]);(0,p.S8)(a,t.yAxis||ep.yAxis,i,{idPrefix:"workbench-".concat(j.id),formatValue:(e,t)=>
1{let l=eg.find(e=>e.label===t.name),a=t.workbenchFormatter;return M(e,I(t.name,l,a))}})})}},l=null,a=null,r=()=>{null!=l&&cancelAnimationFrame(l),null!=a&&clearTimeout(a),l=requestAnimationFrame(()=>{a=setTimeout(t,0)})},n=new ResizeObserver(r);return n.observe(e),window.addEventListener("resize",r),document.addEventListener("fullscreenchange",r),requestAnimationFrame(r),()=>{n.disconnect(),window.removeEventListener("resize",r),document.removeEventListener("fullscreenchange",r),null!=l&&cancelAnimationFrame(l),null!=a&&clearTimeout(a)}},[j,j.id,eg,ep]),$)?(0,a.jsx)("div",{className:"flex h-full items-center justify-center rounded-lg border border-border bg-card/40 text-sm text-muted-foreground",style:{minHeight:P},children:"Loading workbench chart..."}):et?(0,a.jsxs)("div",{className:"flex h-full items-center justify-center rounded-lg border border-red-500/30 bg-red-500/10 p-6 text-sm text-red-200",style:{minHeight:P},children:[(0,a.jsx)(i.Z,{className:"mr-2 h-4 w-4"}),et]}):(0,a.jsx)("div",{ref:en,id:"workbench-chart-container-".concat(j.id),className:"h-full w-full",style:{minHeight:P},children:(0,a.jsx)(n.Z,{ref:ei,option:ep,notMerge:!0,lazyUpdate:!0,opts:{renderer:"canvas"},onChartReady:em,style:{height:"number"==typeof k?"".concat(k,"px"):k,minHeight:P,width:"100%"}},"".concat(j.id,"-").concat(eh))})}},49871:function(e,t,l){l.d(t,{f:function(){return n},t:function(){return r}});var a=l(2265);let r=(0,a.createContext)(null),n=()=>(0,a.useContext)(r)},52178:function(e,t,l){l.d(t,{mC:function(){return r},pV:function(){return a}});let a=e=>{let t=e.match(/^(\d+)(min|hour|day|week)s?$/i);if(t){let e=parseInt(t[1],10),l=t[2].toLowerCase();if("min"===l)return e;if("hour"===l)return 60*e;if("day"===l)return 1440*e;if("week"===l)return 10080*e}let l=e.match(/^(\d+)([smhdwy])$/i);if(l){let e=parseInt(l[1],10),t=l[2].toLowerCase();if("s"===t)return e/60;if("m"===t)return e;if("h"===t)return 60*e;if("d"===t)return 1440*e;if("w"===t)return 10080*e;if("y"===t)return 525600*e}return/^ytd$/i.test(e)?525600:Number.MAX_SAFE_INTEGER},r=e=>[...e].sort((e,t)=>a(e.value)-a(t.value))},30326:function(e,t,l){l.d(t,{C:function(){return o},c:function(){return i}});var a=l(91854),r=l(35840);function n(e){var t;return(0,a.J)((null===(t=e[0])||void 0===t?void 0:t.scale)||"linear")}function i(e){let t=e.series.filter(e=>!1!==e.visible),l=[],i=new Set,o=Array.from(new Set(t.flatMap(e=>[(0,a.ye)(e.axis)?e.axis:null,...(0,r.yl)(e).map(e=>!1!==e.visible&&(0,a.ye)(e.axis)?e.axis:null)]).filter(e=>null!=e))).sort((e,t)=>Number(e.slice(1))-Number(t.slice(1))),s=t.some(e=>"new"===e.axis||(0,r.yl)(e).some(e=>!1!==e.visible&&"new"===e.axis)),c=o.reduce((e,t)=>Math.max(e,Number(t.slice(1))+1),3),d=o.length>0?c:s?3:1,u=t.filter(e=>"right"===e.axis),m=t.filter(e=>"new"!==e.axis&&!(0,a.ye)(e.axis)&&("price_usd"===e.source||e.source.startsWith("price_usd")||"price"===e.formatter||/price/i.test(e.label))),h=u.length>0?u:m;h.length>0&&(h.forEach(e=>i.add(e.id)),l.push({id:"price",label:"Price",value:n(h),seriesIds:h.map(e=>e.id)}));let v=t.filter(e=>!i.has(e.id)&&"new"!==e.axis&&!(0,a.ye)(e.axis));return v.length>0&&(v.forEach(e=>i.add(e.id)),l.push({id:"metric",label:"Metric",value:n(v),seriesIds:v.map(e=>e.id)})),o.forEach(e=>{let a=t.filter(t=>t.axis===e);0!==a.length&&(a.forEach(e=>i.add(e.id)),l.push({id:"axis:".concat(e),label:e.toUpperCase(),value:n(a),seriesIds:a.map(e=>e.id)}))}),t.forEach(e=>{i.has(e.id)||"new"!==e.axis||(i.add(e.id),l.push({id:"series:".concat(e.id),label:"Y".concat(d++),value:(0,a.J)(e.scale||"linear"),seriesIds:[e.id]}))}),t.forEach(e=>{(0,r.yl)(e).forEach((t,r)=>{!1!==t.visible&&"new"===t.axis&&l.push({id:"smoothing:".concat(e.id,":").concat(t.id||r),label:"Y".concat(d++),value:(0,a.J)(e.scale||"linear"),seriesIds:[e.id]})})}),l}function o(e,t,l){let r=(0,a.J)(l),n=i(e).find(e=>e.id===t);if(!n)return e;let o=new Set(n.seriesIds),s=e.series.map(e=>o.has(e.id)?{...e,scale:r}:e);return{...e,series:s,updatedAt:new Date().toISOString()}}}}]);
2//# sourceMappingURL=1082-25ba9e64802dac5f.js.map
3//# chunkId=01a109f9-0ecc-7601-84bc-9ca183ed550b

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.