1import{j as t}from"./index-CiCw9Duq.js";import{r as m}from"./vendor-i18n-BBu7i065.js";import"./vendor-solana-BIelvPCZ.js";import"./vendor-react-BL5zx_iT.js";import"./vendor-ui-Ct1FBp4w.js";import"./vendor-supabase-DbyvBBOg.js";const Pe=[{key:"1h",label:"1H"},{key:"1d",label:"1D"},{key:"5d",label:"5D"},{key:"1m",label:"1M"},{key:"all",label:"ALL"}];function g(e){return e===0?"$0":e<1e-6?`$${e.toFixed(12).replace(/0+$/,"").replace(/\.$/,"")}`:e<1e-4?`$${e.toFixed(10).replace(/0+$/,"").replace(/\.$/,"")}`:e<.01?`$${e.toFixed(8).replace(/0+$/,"").replace(/\.$/,"")}`:e<1?`$${e.toFixed(6).replace(/0+$/,"").replace(/\.$/,"")}`:e<1e3?`$${e.toFixed(2)}`:`$${(e/1e3).toFixed(1)}K`}function ne(e){return!e||e<=0?"---":e>=1e9?`$${(e/1e9).toFixed(2)}B`:e>=1e6?`$${(e/1e6).toFixed(2)}M`:e>=1e3?`$${(e/1e3).toFixed(2)}K`:`$${e.toFixed(0)}`}function _e(e){return e===0?"$0":e<1e-6?`$${e.toFixed(10).replace(/0+$/,"").replace(/\.$/,"")}`:e<1e-4?`$${e.toFixed(8).replace(/0+$/,"").replace(/\.$/,"")}`:e<.01?`$${e.toFixed(6).replace(/0+$/,"").replace(/\.$/,"")}`:e<1?`$${e.toFixed(4).replace(/0+$/,"").replace(/\.$/,"")}`:e<1e3?`$${e.toFixed(2)}`:`$${(e/1e3).toFixed(1)}K`}function le(e){return e>=1e6?`$${(e/1e6).toFixed(1)}M`:e>=1e3?`$${(e/1e3).toFixed(1)}K`:`$${e.toFixed(0)}`}function re(e,a){const r=new Date(e);if(a==="1h"||a==="1d"){const y=r.getHours(),k=r.getMinutes().toString().padStart(2,"0");return`${y%12||12}:${k}${y>=12?"p":"a"}`}const $=(r.getMonth()+1).toString().padStart(2,"0"),o=r.getDate().toString().padStart(2,"0");if(a==="5d"){const y=r.getHours();return`${$}/${o} ${y%12||12}${y>=12?"p":"a"}`}return`${$}/${o}`}async function se(e){const a=[`/api/token/chart?interval=${e}`,`/.netlify/functions/token-chart?interval=${e}`];for(const r of a)try{const $=await fetch(r,{headers:{Accept:"application/json"}});if(!$.ok)continue;const o=await $.json();if(o?.candles?.length)return o.candles}catch{}return[]}const N=900,B=300,w=90,E=12,p=8,Se=22,R=N-w-E,v=B-p-Se,M=40;function Ye({isLight:e=!1,marketCap:a}){const[r,$]=m.useState("5d"),[o,y]=m.useState([]),[k,A]=m.useState(!0),[Y,G]=m.useState(null),[c,I]=m.useState(null),D=m.useRef(null);m.useEffect(()=>{let n=!1;return A(!0),G(null),se(r).then(s=>{n||(s.length===0&&G("No data available"),y(s),A(!1))}).catch(()=>{n||A(!1)}),()=>{n=!0}},[r]),m.useEffect(()=>{const n=r==="1h"?3e4:r==="1d"?6e4:12e4,s=window.setInterval(()=>{se(r).then(f=>{f.length&&y(f)}).catch(()=>{})},n);return()=>window.clearInterval(s)},[r]);const ae=e?"#f9fafb":"#0a0a0a",ce=e?"#e5e7eb":"rgba(255,255,255,0.06)",ie=e?"rgba(0,0,0,0.05)":"rgba(255,255,255,0.04)",O=e?"rgba(0,0,0,0.35)":"rgba(255,255,255,0.3)",X="#10b981",K="#ef4444",S="#06b6d4",xe=e?"rgba(6,182,212,0.18)":"rgba(6,182,212,0.2)",de=e?"rgba(6,182,212,0.01)":"rgba(6,182,212,0.02)",fe=e?"rgba(6,182,212,0.15)":"rgba(6,182,212,0.12)",U=e?"rgba(0,0,0,0.12)":"rgba(255,255,255,0.12)",Z=e?"#fff":"#1c1c1c",ue=e?"#e5e7eb":"rgba(255,255,255,0.1)",he=e?"#111":"#fff",W=e?"#6b7280":"rgba(255,255,255,0.5)",me="#0ea5e9",pe=e?"#f3f4f6":"rgba(255,255,255,0.05)",$e="#fff",ge=e?"#6b7280":"rgba(255,255,255,0.4)",{minP:Te,maxP:Ve,rangeP:Be,maxVol:Ae,toX:u,toY:F,volY:ye,linePath:q,areaPath:J,yTicks:Q,xTicks:be,highVal:je,lowVal:ve,totalVol:we}=m.useMemo(()=>{const n=o.map(l=>l.high),s=o.map(l=>l.low),f=o.map(l=>l.volume);let x=s.length?Math.min(...s):0,d=n.length?Math.max(...n):0;if(d===x){const l=x*.02||1e-6;x-=l,d+=l}else{const l=(d-x)*.08;x-=l,d+=l}const h=d-x||1,P=f.length?Math.max(...f):1,V=l=>w+l/Math.max(1,o.length-1)*R,z=l=>p+(v-M)-(l-x)/h*(v-M),Fe=l=>p+v-l/(P||1)*M,H=o.map((l,j)=>`${j===0?"M":"L"} ${V(j).toFixed(1)} ${z(l.close).toFixed(1)}`).join(" "),Me=H?`${H} L ${V(o.length-1).toFixed(1)} ${(p+v-M).toFixed(1)} L ${w} ${(p+v-M).toFixed(1)} Z`:"",te=5,Ce=Array.from({length:te},(l,j)=>{const _=x+h*j/(te-1);return{val:_,y:z(_)}}),oe=Math.min(7,o.length),Ne=o.length>=2?Array.from({length:oe},(l,j)=>{const _=Math.round(j/(oe-1)*(o.length-1));return{ts:o[_].ts,x:V(_)}}):[];return{minP:x,maxP:d,rangeP:h,maxVol:P,toX:V,toY:z,volY:Fe,linePath:H,areaPath:Me,yTicks:Ce,xTicks:Ne,highVal:n.length?Math.max(...n):0,lowVal:s.length?Math.min(...s):0,totalVol:f.reduce((l,j)=>l+j,0)}},[o,w,p,R,v,M]),b=o.length?o[o.length-1]:null,T=o.length?o[0]:null,L=T&&b?(b.close-T.open)/(T.open||1)*100:0,ee=L>=0,ke=m.useCallback(n=>{if(!D.current||o.length<2)return;const s=D.current.getBoundingClientRect(),f=(n.clientX-s.left)/s.width*N;let x=0,d=1/0;for(let h=0;h<o.length;h++){const P=Math.abs(u(h)-f);P<d&&(d=P,x=h)}I(x)},[o.length]),i=c!==null?o[c]:null;return t.jsxs("div",{className:"w-full h-full flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 overflow-hidden flex-shrink-0",children:[t.jsx("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:Pe.map(n=>t.jsx("button",{onClick:()=>$(n.key),className:"px-2 py-1 rounded-md text-[11px] font-semibold transition-all flex-shrink-0",style:{background:r===n.key?me:pe,color:r===n.key?$e:ge},children:n.label},n.key))}),b&&!k&&t.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[t.jsx("span",{className:`text-sm font-bold whitespace-nowrap ${e?"text-gray-900":"text-white"}`,children:g(b.close)}),t.jsxs("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded-full whitespace-nowrap ${ee?"text-emerald-500 bg-emerald-500/10":"text-red-500 bg-red-500/10"}`,children:[ee?"+":"",L.toFixed(2),"%"]}),a!=null&&a>0&&t.jsxs("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded-full whitespace-nowrap ${e?"bg-gray-100 text-gray-600":"bg-white/[0.06] text-white/50"}`,children:["MCap ",ne(a)]})]})]}),t.jsxs("div",{className:"flex-1 min-h-0 relative rounded-xl overflow-hidden border",style:{background:ae,borderColor:ce}
1,children:[k&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:t.jsxs("div",{className:"flex flex-col items-center gap-2",children:[t.jsx("div",{className:"w-6 h-6 border-2 border-cyan-500/30 border-t-cyan-500 rounded-full animate-spin"}),t.jsx("span",{className:`text-xs ${e?"text-gray-400":"text-white/40"}`,children:"Loading chart..."})]})}),Y&&!k&&o.length===0&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:t.jsx("span",{className:`text-sm ${e?"text-gray-400":"text-white/40"}`,children:Y})}),o.length>0&&t.jsxs("svg",{ref:D,viewBox:`0 0 ${N} ${B}`,preserveAspectRatio:"none",className:"w-full h-full cursor-crosshair",onMouseMove:ke,onMouseLeave:()=>I(null),children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:"areaGradChart",x1:"0",x2:"0",y1:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:xe}),t.jsx("stop",{offset:"100%",stopColor:de})]})}),Q.map((n,s)=>t.jsx("line",{x1:w,x2:N-E,y1:n.y,y2:n.y,stroke:ie,strokeWidth:1},`g${s}`)),Q.map((n,s)=>t.jsx("text",{x:w-6,y:n.y+4,textAnchor:"end",fill:O,fontSize:9,fontFamily:"ui-monospace, monospace",children:_e(n.val)},`yl${s}`)),be.map((n,s)=>t.jsx("text",{x:n.x,y:B-4,textAnchor:"middle",fill:O,fontSize:9,fontFamily:"ui-monospace, monospace",children:re(n.ts,r)},`xl${s}`)),o.map((n,s)=>{const f=Math.max(1,R/o.length*.6),x=u(s)-f/2,d=ye(n.volume),h=p+v-d;return t.jsx("rect",{x,y:d,width:f,height:Math.max(0,h),fill:fe,rx:1},`v${s}`)}),J&&t.jsx("path",{d:J,fill:"url(#areaGradChart)"}),q&&t.jsx("path",{d:q,fill:"none",stroke:S,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round"}),b&&t.jsxs("g",{children:[t.jsxs("circle",{cx:u(o.length-1),cy:F(b.close),r:5,fill:S,opacity:.3,children:[t.jsx("animate",{attributeName:"r",values:"5;8;5",dur:"2s",repeatCount:"indefinite"}),t.jsx("animate",{attributeName:"opacity",values:"0.3;0.1;0.3",dur:"2s",repeatCount:"indefinite"})]}),t.jsx("circle",{cx:u(o.length-1),cy:F(b.close),r:3,fill:S})]}),c!==null&&i&&t.jsxs("g",{children:[t.jsx("line",{x1:u(c),x2:u(c),y1:p,y2:p+v,stroke:U,strokeWidth:1,strokeDasharray:"3 2"}),t.jsx("line",{x1:w,x2:N-E,y1:F(i.close),y2:F(i.close),stroke:U,strokeWidth:1,strokeDasharray:"3 2"}),t.jsx("circle",{cx:u(c),cy:F(i.close),r:4,fill:S,stroke:Z,strokeWidth:2}),t.jsxs("g",{transform:`translate(${u(c)<N/2?u(c)+14:u(c)-164}, ${Math.max(p,Math.min(F(i.close)-50,B-110))})`,children:[t.jsx("rect",{width:150,height:90,rx:8,fill:Z,stroke:ue,strokeWidth:1,filter:"drop-shadow(0 2px 8px rgba(0,0,0,0.15))"}),t.jsx("text",{x:10,y:18,fill:he,fontSize:13,fontWeight:"bold",fontFamily:"ui-monospace, monospace",children:g(i.close)}),t.jsxs("text",{x:10,y:34,fill:W,fontSize:9,fontFamily:"ui-monospace, monospace",children:["O: ",g(i.open)," H: ",g(i.high)]}),t.jsxs("text",{x:10,y:48,fill:W,fontSize:9,fontFamily:"ui-monospace, monospace",children:["L: ",g(i.low)," Vol: ",le(i.volume)]}),t.jsx("text",{x:10,y:66,fill:W,fontSize:9,fontFamily:"ui-monospace, monospace",children:re(i.ts,r)}),c>0&&t.jsxs("text",{x:10,y:82,fontSize:10,fontWeight:"bold",fill:i.close>=o[c-1].close?X:K,fontFamily:"ui-monospace, monospace",children:[i.close>=o[c-1].close?"â²":"â¼"," ",((i.close-o[c-1].close)/(o[c-1].close||1)*100).toFixed(3),"%"]})]})]})]})]}),o.length>0&&!k&&t.jsxs("div",{className:"flex items-center justify-between gap-2 px-1 overflow-hidden flex-shrink-0",children:[t.jsx(C,{label:"Open",value:g(T?.open??0),isLight:e}),t.jsx(C,{label:"High",value:g(je),isLight:e,color:X}),t.jsx(C,{label:"Low",value:g(ve),isLight:e,color:K}),t.jsx(C,{label:"Close",value:g(b?.close??0),isLight:e}),t.jsx(C,{label:"Vol",value:le(we),isLight:e}),a!=null&&a>0&&t.jsx(C,{label:"MCap",value:ne(a),isLight:e})]})]})}function C({label:e,value:a,isLight:r,color:$}){return t.jsxs("div",{className:"text-center flex-shrink-0 min-w-0",children:[t.jsx("div",{className:`text-[9px] uppercase tracking-wider whitespace-nowrap ${r?"text-gray-400":"text-white/30"}`,children:e}),t.jsx("div",{className:"text-[11px] font-semibold whitespace-nowrap",style:{color:$||(r?"#111":"#fff")},children:a})]})}export{Ye as default};
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.