PageSourceSearch

https://cosmowarp.vercel.app/_next/static/chunks/3958.b2788242da044157.js

js cosmowarp.vercel.app collected 2026-10-03 06:36:44 UTC 491,655 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3958],{73958:function(e,t,r){r.r(t),r.d(t,{default:function(){return LimitOrderBookV2}});var i=r(52676),n=r(75271),o=r(6752),l=r.n(o),a=r(50397);function ensureDefined(e){if(void 0===e)throw Error("Value is undefined");return e}let PluginBase=class PluginBase{requestUpdate(){this._requestUpdate&&this._requestUpdate()}attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._series.subscribeDataChanged(this._fireDataUpdated),this._requestUpdate=i,this.requestUpdate()}detached(){var e;null===(e=this._series)||void 0===e||e.unsubscribeDataChanged(this._fireDataUpdated),this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return ensureDefined(this._chart)}get series(){return ensureDefined(this._series)}constructor(){this._chart=void 0,this._series=void 0,this._fireDataUpdated=e=>{this.dataUpdated&&this.dataUpdated(e)}}};let DomOverlayPaneRenderer=class DomOverlayPaneRenderer{draw(e){0!==this._data.bars.length&&e.useMediaCoordinateSpace(e=>{let t=e.context;
1for(let e of this._data.bars)t.fillStyle=e.color+"80",t.fillRect(e.x,e.y-1,e.width,2)})}constructor(e){this._data=e}};let DomOverlayPaneView=class DomOverlayPaneView{update(){let e=this._source.series,t=this._source.chart.timeScale(),r=t.width(),i=this._source._levels;if(!i.length){this._data.bars=[];return}let n=Math.max(...i.map(e=>Math.max(e.bidSize,e.askSize)),1),o=[];for(let t of i){let i=e.priceToCoordinate(t.price);if(null!==i){if(t.bidSize>0){let e=Math.max(2,t.bidSize/n*120);o.push({y:i,x:r-e,width:e,color:"#22c55e"})}if(t.askSize>0){let e=Math.max(2,t.askSize/n*120);o.push({y:i,x:r-e,width:e,color:"#ef4444"})}}}this._data.bars=o}renderer(){return new DomOverlayPaneRenderer(this._data)}constructor(e){this._source=e,this._data={bars:[]}}};let DomOverlayIndicator=class DomOverlayIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this.updateAllViews()}setLevels(e){this._levels=e,this.updateAllViews(),this.requestUpdate()}autoscaleInfo(){return null}constructor(){super(),this._levels=[],this._paneViews=[new DomOverlayPaneView(this)]}};let PositionZonesPaneRenderer=class PositionZonesPaneRenderer{draw(e){let t=this._viewData.zones;0!==t.length&&e.useMediaCoordinateSpace(e=>{let r=e.context;
1for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let n=i.entryPoint;if(!n)continue;let o=this._viewData.dim&&e===this._viewData.hoverIndex;r.globalAlpha=o?1:this._viewData.dim?.25:1;let l=n.x,a=n.y,s="LONG"===n.side,d=s?"#22c55e":"#ef4444";if(r.beginPath(),r.arc(l,a,4,0,2*Math.PI),r.fillStyle=d,r.fill(),r.strokeStyle="rgba(7, 11, 24, 0.8)",r.lineWidth=1,r.stroke(),n.label){r.font="10px Nasalization, sans-serif";let e=n.label,t=r.measureText(e).width,i=l+8,o=a+14,s=o-9;r.fillStyle="rgba(7, 11, 24, 0.75)",r.strokeStyle=d,r.lineWidth=1,r.fillRect(i,s,t+12,18),r.strokeRect(i,s,t+12,18),r.textBaseline="middle",r.textAlign="left",r.fillStyle="#ffffff",r.fillText(e,i+6,o)}r.globalAlpha=1}})}drawBackground(e){let t=this._viewData.zones;0!==t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context;r.scale(e.horizontalPixelRatio,e.verticalPixelRatio);let draw=function(e,t,i){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:.35,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4],l=arguments.length>5&&void 0!==arguments[5]&&arguments[5];if(!e)return;let{x1:a,x2:s,upper:d,lower:c,entryY:u}=e,p=Math.min(a,s),h=Math.abs(s-a),g=Math.min(d,c),x=Math.abs(c-d),b=Math.abs(d-u)>Math.abs(c-u)?d:c,f=o?s:p,m=r.createLinearGradient(p,u,f,b);l?(m.addColorStop(0,t.replace(/[\d.]+\)/,"0)")),m.addColorStop(1,t.replace(/[\d.]+\)/,n+")"))):(m.addColorStop(0,t.replace(/[\d.]+\)/,n+")")),m.addColorStop(1,t.replace(/[\d.]+\)/,"0)"))),r.fillStyle=m,r.strokeStyle=i,r.lineWidth=1,r.fillRect(p,g,h,x),r.strokeRect(p,g,h,x)};for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let n=this._viewData.dim&&e===this._viewData.hoverIndex;if(r.globalAlpha=n?1:this._viewData.dim?.18:1,draw(i.liquidationZone,"rgba(239, 68, 68, 0.15)","rgba(239, 68, 68, 0.5)",.35,!1,!0),draw(i.profitZone,"rgba(34, 197, 94, 0.08)","rgba(34, 197, 94, 0.25)",.15,!0),draw(i.takeProfitZone,"rgba(34, 197, 94, 0.15)","rgba(34, 197, 94, 0.5)"),draw(i.trailingStopZone,"rgba(251, 191, 36, 0.15)","rgba(251, 191, 36, 0.5)"),i.animated){let e=i.profitZone||i.takeProfitZone;e&&function(e,t,r,i){let n=Math.min(t.x1,t.x2),o=Math.max(t.x1,t.x2),l=Math.min(t.upper,t.lower),a=Math.max(t.upper,t.lower),s=o-n,d=a-l;if(s<40||d<36)return;let c="LONG"===r,u=n+s/2,p=Math.min(26,.12*s),h=Math.min(8,.08*d),g=("undefined"!=typeof performance?performance.now():Date.now())/1e3,x=c?"34, 197, 94":"239, 68, 68";e.save(),e.strokeStyle="#ffffff",e.lineWidth=4,e.lineCap="round",e.lineJoin="round";for(let t=0;t<3;t++){let r=(t+1)/4,n=c?a-r*d:l+r*d,o=Math.max(0,Math.sin(4*g-1.1*t)),s=(.12+.6*o*o)*i;e.globalAlpha=s,e.strokeStyle="rgba(".concat(x,", 1)"),e.beginPath(),c?(e.moveTo(u-p,n+h),e.lineTo(u,n-h),e.lineTo(u+p,n+h)):(e.moveTo(u-p,n-h),e.lineTo(u,n+h),e.lineTo(u+p,n-h)),e.stroke()}e.restore()}(r,e,i.side,this._viewData.dim?.35:1)}r.globalAlpha=1}})}constructor(e){this._viewData=e}};let PositionZonesPaneView=class PositionZonesPaneView{formatLabel(e,t){return t||("LONG"===e?"L":"S")}update(){var e;let t=this._source.series,r=this._source.chart.timeScale(),i=t.data();this._data.dim=this._source._dim,this._data.hoverIndex=null!==(e=this._source._hoveredIndex)&&void 0!==e?e:-1,this._data.zones=this._source._positions.map(e=>{let n="number"==typeof e.openedAt?e.openedAt:Number(e.openedAt),o=i.filter(e=>{let t="number"==typeof e.time?e.time:Number(e.time);return t>=n}),l=o[0],a=l?r.timeToCoordinate(l.time):r.timeToCoordinate(e.openedAt),s=r.width(),d=null,c=Number.isFinite(e.entryPrice)&&null!==a?t.priceToCoordinate(e.entryPrice):null;null!==a&&null!==c&&(d={x:a,y:c,side:e.side,label:this.formatLabel(e.side,e.label)});let u=null;if(e.liquidationPrice&&Number.isFinite(e.liquidationPrice)&&null!==a){let r="LONG"===e.side?e.entryPrice:e.liquidationPrice,i="LONG"===e.side?e.liquidationPrice:e.entryPrice,n=t.priceToCoordinate(r),o=t.priceToCoordinate(i);null!==n&&null!==o&&null!==c&&(u={x1:a,x2:s,upper:n,lower:o,entryY:c})}let p=null;if(e.takeProfit&&Number.isFinite(e.takeProfit)&&null!==a){let r="LONG"===e.side?e.takeProfit:e.entryPrice,i="LONG"===e.side?e.entryPrice:e.takeProfit,n=t.priceToCoordinate(r),o=t.priceToCoordinate(i);null!==n&&null!==o&&null!==c&&(p={x1:a,x2:s,upper:n,lower:o,entryY:c})}let h=null;if((!e.takeProfit||!Number.isFinite(e.takeProfit))&&Number.isFinite(e.entryPrice)&&null!==a){let r=e.liquidationPrice||0,i=Number.isFinite(r)&&r>0?Math.abs(e.entryPrice-r):.2*e.entryPrice,n="LONG"===e.side?e.entryPrice+i:e.entryPrice-i,o="LONG"===e.side?n:e.entryPrice,l="LONG"===e.side?e.entryPrice:n,d=t.priceToCoordinate(o),u=t.priceToCoordinate(l);null!==d&&null!==u&&null!==c&&(h={x1:a,x2:s,upper:d,lower:u,entryY:c})}let g=null;if(e.trailingStop&&Number.isFinite(e.trailingStop)&&null!==a){let r="LONG"===e.side?e.entryPrice:e.trailingStop,i="LONG"===e.side?e.trailingStop:e.entryPrice,n=t.priceToCoordinate(r),o=t.priceToCoordinate(i);null!==n&&null!==o&&null!==c&&(g={x1:a,x2:s,upper:n,lower:o,entryY:c})}return{liquidationZone:u,takeProfitZone:p,profitZone:h,trailingStopZone:g,entryPoint:d,side:e.side,animated:!!e.animated}})}renderer(){return new PositionZonesPaneRenderer(this._data)}constructor(e){this._source=e,this._data={zones:[],hoverIndex:-1,dim:!1}}};let PositionZonesIndicator=class PositionZonesIndicator extends PluginBase{_syncAnimationLoop(){let e=this._positions.some(e=>e.animated);if(e&&null===this._animRaf&&"undefined"!=typeof requestAnimationFrame){let tick=()=>{this.requestUpdate(),this._animRaf=requestAnimationFrame(tick)};this._animRaf=requestAnimationFrame(tick)}else e||null===this._animRaf||(cancelAnimationFrame(this._animRaf),this._animRaf=null)}detached(){null!==this._animRaf&&(cancelAnimationFrame(this._animRaf),this._animRaf=null),super.detached()}
1updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this.updateAllViews()}setPositionZones(e){this._positions=e,this.updateAllViews(),this._syncAnimationLoop()}setHighlight(e,t){this._dim=e,this._hoveredIndex=t,this.updateAllViews()}autoscaleInfo(){return null}constructor(){super(),this._positions=[],this._dim=!1,this._hoveredIndex=null,this._animRaf=null,this._paneViews=[new PositionZonesPaneView(this)]}};let s="#22c55e",d="#ef4444";function abbrev(e){let t=Math.abs(e);return t>=1e9?"".concat((e/1e9).toFixed(1),"B"):t>=1e6?"".concat((e/1e6).toFixed(1),"M"):t>=1e3?"".concat((e/1e3).toFixed(1),"K"):e.toFixed(0)}let GexLevelsPaneRenderer=class GexLevelsPaneRenderer{draw(e){(0!==this._data.bars.length||0!==this._data.lines.length)&&e.useMediaCoordinateSpace(e=>{let t=e.context,r=this._data.rightEdge;if(this._data.curve&&this._data.curve.points.length>1){let e=this._data.curve.points,i=e[0],n=e[e.length-1];t.beginPath(),t.moveTo(i.x,i.y);for(let r=1;r<e.length;r++){let i=e[r];t.lineTo(i.x,i.y)}t.lineTo(r,n.y),t.lineTo(r,i.y),t.closePath();let o=t.createLinearGradient(r,0,r-140,0);o.addColorStop(0,this._data.curve.positive?s:d),o.addColorStop(1,this._data.curve.positive?"rgba(34,197,94,0.0)":"rgba(239,68,68,0.0)"),t.fillStyle=this._data.curve.positive?s+"18":d+"18",t.fill(),t.strokeStyle=this._data.curve.positive?s+"80":d+"80",t.lineWidth=1,t.stroke()}for(let e of this._data.bars){let i=e.y,n=Math.max(e.length,2);t.fillStyle=e.positive?s+"cc":d+"cc",t.fillRect(r-n,i-1,n,2)}for(let e of this._data.lines){let i=e.y;t.strokeStyle=e.color,t.lineWidth=1.5,t.setLineDash(e.dashed?[6,4]:[]),t.beginPath(),t.moveTo(0,i),t.lineTo(r,i),t.stroke(),t.setLineDash([]),t.font="10px sans-serif";let n=t.measureText(e.label).width;t.fillStyle=e.color,t.fillRect(4,i-8,n+8,16),t.fillStyle="#0b0e11",t.textBaseline="middle",t.fillText(e.label,8,i)}})}constructor(e){this._data=e}};let GexLevelsPaneView=class GexLevelsPaneView{update(){var e,t,r;let i=this._source.series,n=this._source.chart.timeScale(),o=this._source._profile;if(this._data.rightEdge=n.width(),!o){this._data.bars=[],this._data.lines=[];return}let l=o.maxAbsGex||1,a=this._data.rightEdge,c=[],u=[];for(let e of o.strikes){let t=i.priceToCoordinate(e.strike);if(null===t)continue;let r=Math.abs(e.gex)/l*140;c.push({y:t,length:r,positive:e.gex>=0})}this._data.bars=c;let p=[...o.strikes].sort((e,t)=>e.strike-t.strike);if(p.length>=2){for(let e=0;e<p.length-1;e++){let t=p[e],r=p[e+1];for(let e=0;e<16;e++){let n=e/16,l=t.strike+n*(r.strike-t.strike),s=t.gex+n*(r.gex-t.gex),d=i.priceToCoordinate(l);if(null===d)continue;let c=Math.abs(s)/(o.maxAbsGex||1)*140;u.push({y:d,x:a-Math.max(c,2)})}}let e=p[p.length-1],t=i.priceToCoordinate(e.strike);if(null!==t){let r=Math.abs(e.gex)/(o.maxAbsGex||1)*140;u.push({y:t,x:a-Math.max(r,2)})}}this._data.curve=u.length>1?{points:u,positive:(null!==(e=o.totalGex)&&void 0!==e?e:0)>=0}:null;let h=[],pushLine=(e,t,r,n)=>{if(null===e||!Number.isFinite(e))return;let o=i.priceToCoordinate(e);null!==o&&h.push({y:o,color:t,label:r,dashed:n})};pushLine(o.callWall,s,"Call Wall ".concat(abbrev(null!==(t=o.callWall)&&void 0!==t?t:0)),!1),pushLine(o.putWall,d,"Put Wall ".concat(abbrev(null!==(r=o.putWall)&&void 0!==r?r:0)),!1),pushLine(o.zeroGamma,"#f0b90b","Gamma Flip",!0),this._data.lines=h}renderer(){return new GexLevelsPaneRenderer(this._data)}constructor(e){this._source=e,this._data={bars:[],curve:null,lines:[],rightEdge:0}}};let GexLevelsIndicator=class GexLevelsIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this.updateAllViews()}setProfile(e){this._profile=e,this.updateAllViews(),this.requestUpdate()}autoscaleInfo(){return null}constructor(){super(),this._profile=null,this._paneViews=[new GexLevelsPaneView(this)]}};function bandColor(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return"hsla(".concat("long"===t?360-60*e:"short"===t?160-60*e:240-240*e,", 85%, 50%, ").
1concat(((.05+.45*e)*r).toFixed(3),")")}function toTime(e){return e>1e12?e/1e3:e}let LiqHeatmapPaneRenderer=class LiqHeatmapPaneRenderer{draw(e){(0!==this._data.bands.length||0!==this._data.dots.length)&&e.useMediaCoordinateSpace(e=>{let t=e.context,{width:r}=e.mediaSize;for(let e of this._data.bands){let i=Math.max(1,e.yBottom-e.yTop),n=e.xEnd-e.xStart,o=Math.min(48,.4*n),l=t.createLinearGradient(e.xStart,0,e.xStart+o,0);if(l.addColorStop(0,bandColor(e.intensity,e.side,0)),l.addColorStop(1,bandColor(e.intensity,e.side,1)),t.fillStyle=l,t.fillRect(e.xStart,e.yTop,n,i),null!=e.openX&&e.openX>0&&e.openX<r){let r=(e.yTop+e.yBottom)/2;t.strokeStyle="rgba(255,255,255,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(e.openX-3,r),t.lineTo(e.openX+3,r),t.moveTo(e.openX,r-3),t.lineTo(e.openX,r+3),t.stroke()}}for(let e of this._data.dots)t.beginPath(),t.arc(e.x,e.y,e.r,0,2*Math.PI),t.fillStyle=e.color,t.fill(),t.strokeStyle="rgba(255,255,255,0.35)",t.lineWidth=.5,t.stroke();if(null!==this._data.maxClusterPrice&&this._data.bands.length>0){let e=this._data.bands.reduce((e,t)=>t.intensity>e.intensity?t:e),r=(e.yTop+e.yBottom)/2;t.font="10px sans-serif";let i="Max Liq $".concat(function(e){let t=Math.abs(e);return t>=1e9?"".concat((e/1e9).toFixed(1),"B"):t>=1e6?"".concat((e/1e6).toFixed(1),"M"):t>=1e3?"".concat((e/1e3).toFixed(1),"K"):e.toFixed(0)}(this._data.maxClusterTotal)," @ ").concat(this._data.maxClusterPrice.toFixed(1)),n=t.measureText(i).width+8;t.fillStyle="#f0b90b",t.fillRect(4,r-16,n,14),t.fillStyle="#0b0e11",t.textBaseline="middle",t.fillText(i,8,r-9)}})}constructor(e){this._data=e}};let LiqHeatmapPaneView=class LiqHeatmapPaneView{update(){let e=this._source.series,t=this._source.chart.timeScale(),r=this._source._heatmap,i=this._source._realized,n=t.width(),o=[];if(r&&r.buckets.length){let i=t.options().barSpacing,l=r.bucketSize/2,a=0,s=0;for(let d of r.buckets){let c;let u=e.priceToCoordinate(d.price+l),p=e.priceToCoordinate(d.price-l);if(null===u||null===p){s++;continue}let h=0,g=n;if(null!=d.firstTouch&&null!=d.lastTouch){let e=t.timeToCoordinate(toTime(d.firstTouch)),r=t.timeToCoordinate(toTime(d.lastTouch));if(null!==e&&null!==r)g=Math.max((h=Math.max(0,Math.min(e-i/2,n-1)))+1,Math.min(r+i/2,n)),c=e;else if(n>0)h=Math.max(0,n-40),g=n;else{s++;continue}}else if(null!==d.lastTouch){let e=t.timeToCoordinate(toTime(d.lastTouch));if(null!==e)h=Math.max(0,Math.min(e-i/2,n-1));else if(n>0)h=Math.max(0,n-40);else{s++;continue}}else{s++;continue}if(h>=n||g<=0||g<=h){s++;continue}let x=Math.sqrt(d.total/(r.maxTotal||1)),b="both";d.longLiq>1.2*d.shortLiq?b="long":d.shortLiq>1.2*d.longLiq&&(b="short"),o.push({xStart:h,xEnd:g,yTop:Math.min(u,p),yBottom:Math.max(u,p),intensity:x,side:b,openX:c}),a++}o.sort((e,t)=>e.intensity-t.intensity),this._data.bands=o;let d=r.buckets.reduce((e,t)=>t.total>e.total?t:e,r.buckets[0]);this._data.maxClusterPrice=d.price,this._data.maxClusterTotal=d.total,console.log("[liq-heatmap] bands=".concat(a," skipped=").concat(s," maxTotal=").concat((r.maxTotal/1e6).toFixed(2),"M"))}else this._data.bands=[],this._data.maxClusterPrice=null;let l=[],a=Math.max(1,...i.map(e=>e.usd));for(let r of i){let i=t.timeToCoordinate(toTime(r.time)),n=e.priceToCoordinate(r.price);if(null===i||null===n)continue;let o=2+6*Math.sqrt(r.usd/a);l.push({x:i,y:n,r:o,color:"long"===r.side?"rgba(242,54,69,0.85)":"rgba(8,153,129,0.85)"})}this._data.dots=l}renderer(){return new LiqHeatmapPaneRenderer(this._data)}constructor(e){this._source=e,this._data={bands:[],dots:[],maxClusterPrice:null,maxClusterTotal:0}}};let LiqHeatmapIndicator=class LiqHeatmapIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this.updateAllViews()}setHeatmap(e){this._heatmap=e,this.updateAllViews(),this.requestUpdate()}setRealized(e){this._realized=e,this.updateAllViews(),this.requestUpdate()}autoscaleInfo(){return null}constructor(){super(),this._heatmap=null,this._realized=[],this._paneViews=[new LiqHeatmapPaneView(this)]}};
1function metallicFill(e,t,r,i){let n=function(e){let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/);return t?{r:+t[1],g:+t[2],b:+t[3],a:void 0!==t[4]?+t[4]:1}:null}(i);if(!n||r-t<1)return i;let o=e.createLinearGradient(0,t,0,r),sheen=e=>Math.min(255,Math.round(255-(255-e)*.55)),clamp=e=>Math.min(1,Math.max(0,e));return o.addColorStop(0,"rgba(".concat(n.r,",").concat(n.g,",").concat(n.b,",").concat(clamp(.55*n.a),")")),o.addColorStop(.22,"rgba(".concat(sheen(n.r),",").concat(sheen(n.g),",").concat(sheen(n.b),",").concat(clamp(1.15*n.a),")")),o.addColorStop(.45,"rgba(".concat(n.r,",").concat(n.g,",").concat(n.b,",").concat(clamp(.8*n.a),")")),o.addColorStop(1,"rgba(".concat(Math.round(.55*n.r),",").concat(Math.round(.55*n.g),",").concat(Math.round(.55*n.b),",").concat(clamp(.5*n.a),")")),o}let EmaChannelPaneRenderer=class EmaChannelPaneRenderer{draw(){}drawBackground(e){let t=this._viewData.data;t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context;r.scale(e.horizontalPixelRatio,e.verticalPixelRatio);let i=this._viewData.options,n=new Path2D,o=new Path2D;for(let e of(n.moveTo(t[0].x,t[0].fast),o.moveTo(t[0].x,t[0].slow),t))n.lineTo(e.x,e.fast),o.lineTo(e.x,e.slow);let l=1/0,a=-1/0;for(let e of t)e.fast<l&&(l=e.fast),e.slow<l&&(l=e.slow),e.fast>a&&(a=e.fast),e.slow>a&&(a=e.slow);let s=metallicFill(r,l,a,i.bullFillColor),d=metallicFill(r,l,a,i.bearFillColor);for(let e=0;e<t.length-1;e++){let i=t[e],n=t[e+1],o=i.fast>=i.slow,l=new Path2D;l.moveTo(i.x,i.fast),l.lineTo(n.x,n.fast),l.lineTo(n.x,n.slow),l.lineTo(i.x,i.slow),l.closePath(),r.fillStyle=o?s:d,r.fill(l)}r.strokeStyle=i.lineColor,r.lineWidth=i.lineWidth,r.stroke(n),r.stroke(o)})}constructor(e){this._viewData=e}};let EmaChannelPaneView=class EmaChannelPaneView{update(){let e=this._source.series,t=this._source.chart.timeScale();this._data.data=this._source._bandData.map(r=>{var i,n,o;return{x:null!==(i=t.timeToCoordinate(r.time))&&void 0!==i?i:-100,fast:null!==(n=e.priceToCoordinate(r.fast))&&void 0!==n?n:-100,slow:null!==(o=e.priceToCoordinate(r.slow))&&void 0!==o?o:-100}})}renderer(){return new EmaChannelPaneRenderer(this._data)}constructor(e){this._source=e,this._data={data:[],options:this._source._options}}};function calculateEMA(e,t){let r=[],i=2/(t+1),n=null;for(let o=0;o<e.length;o++)if(o<t-1)r.push({time:e[o].time,value:null});else if(o===t-1){let i=e.slice(0,t).reduce((e,t)=>e+t.close,0);n=i/t,r.push({time:e[o].time,value:n})}else n=e[o].close*i+(n||0)*(1-i),r.push({time:e[o].time,value:n});return r}let c={fast:7,slow:34,lineColor:"rgba(34, 197, 94, 0.25)",bullFillColor:"rgba(34, 197, 94, 0.4)",bearFillColor:"rgba(239, 68, 68, 0.4)",lineWidth:.5};let EmaChannelIndicator=class EmaChannelIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this._seriesData=this.series.data(),this.calculateBands(),"full"===e&&this.updateAllViews(),this.requestUpdate()}calculateBands(){let e=calculateEMA(this._seriesData,this._options.fast),t=calculateEMA(this._seriesData,this._options.slow);this._bandData=[];for(let r=0;r<e.length;r++)null!==e[r].value&&null!==t[r].value&&this._bandData.push({time:e[r].time,fast:e[r].value,slow:t[r].value})}constructor(e={}){super(),this._seriesData=[],this._options={...c,...e},this._paneViews=[new EmaChannelPaneView(this)],this._bandData=[]}};function cloneReadonly(e){return JSON.parse(JSON.stringify(e))}let ClosestTimeIndexFinder=class ClosestTimeIndexFinder{findClosestIndex(e,t){let r="".concat(e,":").concat(t);if(this.cache.has(r))return this.cache.get(r);let i=this._performSearch(e,t);return this.cache.set(r,i),i}_performSearch(e,t){let r=0,i=this.numbers.length-1;if(e<=this.numbers[0].time)return 0;if(e>=this.numbers[i].time)return i;for(;r<=i;){let t=Math.floor((r+i)/2),n=this.numbers[t].time;if(n===e)return t;n>e?i=t-1:r=t+1}return"left"===t?i:r}constructor(e){this.numbers=e,this.cache=new Map}};let UpperLowerInRange=class UpperLowerInRange{getMinMax(e,t){let r="".concat(e,":").concat(t);if(this._cache.has(r))return this._cache.get(r);let i={lower:1/0,upper:-1/0},n=Math.floor(e/this._chunkSize),o=Math.floor(t/this._chunkSize);for(let e=n;e<=o;e++){let t=e*this._chunkSize,r=Math.min((e+1)*this._chunkSize-1,this._arr.length-1),n="".concat(t,":").concat(r);if(this._cache.has(n)){let e=this._cache.get(n);this._check(e,i)}else{let e={lower:1/0,upper:-1/0};for(let i=t;i<=r;i++)this._check(this._arr[i],e);this._cache.set(n,e),this._check(e,i)}}return this._cache.set(r,i),i}_check(e,t){e.lower<t.lower&&(t.lower=e.lower),e.upper>t.upper&&(t.upper=e.upper)}constructor(e,t=10){this._arr=e,this._chunkSize=t,this._cache=new Map}};let u={emerald:{upper:"34, 197, 94",lower:"14, 116, 144",basis:"134, 239, 172"},ocean:{upper:"56, 189, 248",lower:"37, 99, 235",basis:"125, 211, 252"},sunset:{upper:"251, 146, 60",lower:"219, 39, 119",basis:"253, 186, 116"},violet:{upper:"167, 139, 250",lower:"109, 40, 217",basis:"196, 181, 253"}};let BollingerBandsPaneRenderer=class BollingerBandsPaneRenderer{draw(){}
1drawBackground(e){let t=this._viewData.data;if(t.length<2)return;let{options:r}=this._viewData,i=u[r.colorScheme]||u.emerald;e.useBitmapCoordinateSpace(e=>{let n=e.context;n.scale(e.horizontalPixelRatio,e.verticalPixelRatio);let o=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let e of t)e.upper<o&&(o=e.upper),e.lower>l&&(l=e.lower);if(!Number.isFinite(o)||!Number.isFinite(l)||l-o<1)return;let a=new Path2D;for(let e of(a.moveTo(t[0].x,t[0].upper),t))a.lineTo(e.x,e.upper);let s=t.length-1;a.lineTo(t[s].x,t[s].lower);for(let e=t.length-2;e>=0;e--)a.lineTo(t[e].x,t[e].lower);a.closePath();let d=n.createLinearGradient(0,o,0,l),clampA=e=>Math.min(1,Math.max(0,e));d.addColorStop(0,"rgba(".concat(i.upper,", ").concat(clampA(.7*r.fillOpacity),")")),d.addColorStop(.18,"rgba(".concat(i.upper.split(",").map(e=>Math.min(255,Math.round(255-(255-+e)*.55))).join(","),", ").concat(clampA(1.2*r.fillOpacity),")")),d.addColorStop(.5,"rgba(".concat(i.basis,", ").concat(.35*r.fillOpacity,")")),d.addColorStop(.85,"rgba(".concat(i.lower,", ").concat(r.fillOpacity,")")),d.addColorStop(1,"rgba(".concat(i.lower,", ").concat(clampA(.55*r.fillOpacity),")")),n.fillStyle=d,n.fill(a);let strokeLine=function(e,r,i){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],l=new Path2D;for(let r of(l.moveTo(t[0].x,t[0][e]),t))l.lineTo(r.x,r[e]);n.strokeStyle=r,n.lineWidth=i,n.setLineDash(o),n.stroke(l),n.setLineDash([])};strokeLine("upper","rgba(".concat(i.upper,", 0.9)"),r.lineWidth),strokeLine("lower","rgba(".concat(i.lower,", 0.9)"),r.lineWidth),strokeLine("basis","rgba(".concat(i.basis,", 0.7)"),Math.max(.5,.75*r.lineWidth),[4,3])})}constructor(e){this._viewData=e}};let BollingerBandsPaneView=class BollingerBandsPaneView{update(){let e=this._source.series,t=this._source.chart.timeScale();this._data.options=this._source._options,this._data.data=this._source._bandsData.map(r=>{var i,n,o,l;return{x:null!==(i=t.timeToCoordinate(r.time))&&void 0!==i?i:-100,upper:null!==(n=e.priceToCoordinate(r.upper))&&void 0!==n?n:-100,basis:null!==(o=e.priceToCoordinate(r.basis))&&void 0!==o?o:-100,lower:null!==(l=e.priceToCoordinate(r.lower))&&void 0!==l?l:-100}})}renderer(){return new BollingerBandsPaneRenderer(this._data)}constructor(e){this._source=e,this._data={data:[],options:this._source._options}}};let p={period:20,multiplier:2,fillOpacity:.25,colorScheme:"emerald",lineWidth:1};let BollingerBandsIndicator=class BollingerBandsIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this._seriesData=cloneReadonly(this.series.data()),this.calculateBands(),"full"===e&&(this._timeIndices=new ClosestTimeIndexFinder(this._seriesData))}applyOptions(e){this._options={...this._options,...e},this.calculateBands(),this.updateAllViews(),this.requestUpdate()}calculateBands(){let{period:e,multiplier:t}=this._options,r=[];this._minValue=Number.POSITIVE_INFINITY,this._maxValue=Number.NEGATIVE_INFINITY;let i=[];for(let e of this._seriesData){let t=void 0!==e.close?e.close:void 0!==e.value?e.value:void 0;void 0!==t&&i.push({time:e.time,price:t})}let n=0,o=0;for(let l=0;l<i.length;l++){let a=i[l].price;if(n+=a,o+=a*a,l>=e){let t=i[l-e].price;n-=t,o-=t*t}if(l<e-1)continue;let s=n/e,d=Math.max(0,o/e-s*s),c=Math.sqrt(d),u=s+t*c,p=s-t*c;u>this._maxValue&&(this._maxValue=u),p<this._minValue&&(this._minValue=p),r.push({time:i[l].time,upper:u,basis:s,lower:p})}this._bandsData=r,this._upperLower=new UpperLowerInRange(this._bandsData,4)}autoscaleInfo(e,t){var r,i,n,o;let l=this.chart.timeScale(),a=null!==(i=l.coordinateToTime(null!==(r=l.logicalToCoordinate(e))&&void 0!==r?r:0))&&void 0!==i?i:0,s=null!==(o=l.coordinateToTime(null!==(n=l.logicalToCoordinate(t))&&void 0!==n?n:5e9))&&void 0!==o?o:5e9,d=this._timeIndices.findClosestIndex(a,"left"),c=this._timeIndices.findClosestIndex(s,"right"),u=this._upperLower.getMinMax(d,c);return{priceRange:{minValue:u.lower,maxValue:u.upper}}}constructor(e={}){super(),this._seriesData=[],this._bandsData=[],this._minValue=Number.POSITIVE_INFINITY,this._maxValue=Number.NEGATIVE_INFINITY,this._options={...p,...e},this._paneViews=[new BollingerBandsPaneView(this)],this._timeIndices=new ClosestTimeIndexFinder([]),this._upperLower=new UpperLowerInRange([])}};let h={emerald:{bull:"34, 197, 94",bear:"239, 68, 68",a:"74, 222, 128",b:"239, 68, 68"},ocean:{bull:"56, 189, 248",bear:"239, 68, 68",a:"125, 211, 252",b:"37, 99, 235"},sunset:{bull:"251, 146, 60",bear:"219, 39, 119",a:"253, 186, 116",b:"219, 39, 119"},violet:{bull:"167, 139, 250",bear:"250, 112, 255",a:"196, 181, 253",b:"250, 112, 255"}};let IchimokuCloudPaneRenderer=class IchimokuCloudPaneRenderer{draw(){}
1drawBackground(e){let t=this._viewData.data;if(t.length<2)return;let{options:r}=this._viewData,i=h[r.colorScheme]||h.emerald;e.useBitmapCoordinateSpace(e=>{let n=e.context;n.scale(e.horizontalPixelRatio,e.verticalPixelRatio),n.lineWidth=r.lineWidth,n.setLineDash([]);let o=1/0,l=-1/0;for(let e of t)e.a<o&&(o=e.a),e.b<o&&(o=e.b),e.a>l&&(l=e.a),e.b>l&&(l=e.b);let sheen=e=>Math.min(255,Math.round(255-(255-e)*.55)),clampA=e=>Math.min(1,Math.max(0,e)),makeFill=e=>{if(l-o<1)return"rgba(".concat(e,", ").concat(r.fillOpacity,")");let[t,i,a]=e.split(",").map(e=>+e),s=n.createLinearGradient(0,o,0,l);return s.addColorStop(0,"rgba(".concat(t,",").concat(i,",").concat(a,",").concat(clampA(.55*r.fillOpacity),")")),s.addColorStop(.22,"rgba(".concat(sheen(t),",").concat(sheen(i),",").concat(sheen(a),",").concat(clampA(1.15*r.fillOpacity),")")),s.addColorStop(.45,"rgba(".concat(t,",").concat(i,",").concat(a,",").concat(clampA(.8*r.fillOpacity),")")),s.addColorStop(1,"rgba(".concat(Math.round(.55*t),",").concat(Math.round(.55*i),",").concat(Math.round(.55*a),",").concat(clampA(.5*r.fillOpacity),")")),s},a=makeFill(i.bull),s=makeFill(i.bear);for(let e=1;e<t.length;e++){let r=t[e-1],i=t[e],o=!!r.bull&&!!i.bull||(!!r.bull||!!i.bull)&&i.bull,l=new Path2D;l.moveTo(r.x,r.a),l.lineTo(i.x,i.a),l.lineTo(i.x,i.b),l.lineTo(r.x,r.b),l.closePath(),n.fillStyle=o?a:s,n.fill(l)}let d=new Path2D;for(let e of(d.moveTo(t[0].x,t[0].a),t))d.lineTo(e.x,e.a);n.strokeStyle="rgba(".concat(i.a,", 0.9)"),n.stroke(d);let c=new Path2D;for(let e of(c.moveTo(t[0].x,t[0].b),t))c.lineTo(e.x,e.b);n.strokeStyle="rgba(".concat(i.b,", 0.9)"),n.stroke(c)})}constructor(e){this._viewData=e}};let IchimokuCloudPaneView=class IchimokuCloudPaneView{update(){let e=this._source.series,t=this._source.chart.timeScale();this._data.options=this._source._options,this._data.data=this._source._cloudData.reduce((r,i)=>{let n=t.logicalToCoordinate(i.logical),o=e.priceToCoordinate(i.a),l=e.priceToCoordinate(i.b);return null!==n&&null!==o&&null!==l&&r.push({x:n,a:o,b:l,bull:i.a>=i.b}),r},[])}renderer(){return new IchimokuCloudPaneRenderer(this._data)}constructor(e){this._source=e,this._data={data:[],options:this._source._options}}};let g={conversionPeriod:9,basePeriod:26,spanBPeriod:52,displacement:26,fillOpacity:.25,colorScheme:"emerald",lineWidth:1};let IchimokuCloudIndicator=class IchimokuCloudIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this._seriesData=cloneReadonly(this.series.data()),this.calculateCloud(),"full"===e&&(this._timeIndices=new ClosestTimeIndexFinder(this._seriesData))}applyOptions(e){this._options={...this._options,...e},this.calculateCloud(),this.updateAllViews(),this.requestUpdate()}calculateCloud(){let{conversionPeriod:e,basePeriod:t,spanBPeriod:r,displacement:i}=this._options,n=this._seriesData,o=[];this._minValue=Number.POSITIVE_INFINITY,this._maxValue=Number.NEGATIVE_INFINITY;let l=[];n.forEach((e,t)=>{let r=function(e){if(void 0!==e.high&&void 0!==e.low)return{high:e.high,low:e.low}}(e);r&&l.push({time:e.time,logical:t,high:r.high,low:r.low})});let a=l.length;if(0===a){this._cloudData=o,this._upperLower=new UpperLowerInRange(o,4);return}for(let n=Math.max(e,t,r)-1;n<a;n++){let a=-1/0,s=1/0;for(let t=n-e+1;t<=n;t++)l[t].high>a&&(a=l[t].high),l[t].low<s&&(s=l[t].low);let d=(a+s)/2,c=-1/0,u=1/0;for(let e=n-t+1;e<=n;e++)l[e].high>c&&(c=l[e].high),l[e].low<u&&(u=l[e].low);let p=(c+u)/2,h=-1/0,g=1/0;for(let e=n-r+1;e<=n;e++)l[e].high>h&&(h=l[e].high),l[e].low<g&&(g=l[e].low);let x=(h+g)/2,b=(d+p)/2,f=l[n].logical+i,m=l[n].time,y=Math.max(b,x),v=Math.min(b,x);o.push({time:m,logical:f,a:b,b:x,upper:y,lower:v})}this._cloudData=o,this._upperLower=new UpperLowerInRange(this._cloudData,4)}autoscaleInfo(e,t){var r,i,n,o;let l=this.chart.timeScale(),a=null!==(i=l.coordinateToTime(null!==(r=l.logicalToCoordinate(e))&&void 0!==r?r:0))&&void 0!==i?i:0,s=null!==(o=l.coordinateToTime(null!==(n=l.logicalToCoordinate(t))&&void 0!==n?n:5e9))&&void 0!==o?o:5e9,d=this._timeIndices.findClosestIndex(a,"left"),c=this._timeIndices.findClosestIndex(s,"right"),u=this._upperLower.getMinMax(d,c);return{priceRange:{minValue:u.lower,maxValue:u.upper}}}constructor(e={}){super(),this._seriesData=[],this._cloudData=[],this._minValue=Number.POSITIVE_INFINITY,this._maxValue=Number.NEGATIVE_INFINITY,this._options={...g,...e},this._paneViews=[new IchimokuCloudPaneView(this)],this._timeIndices=new ClosestTimeIndexFinder([]),this._upperLower=new UpperLowerInRange([])}};
1function candle_channel_metallicFill(e,t,r,i){let n=function(e){let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/);return t?{r:+t[1],g:+t[2],b:+t[3],a:void 0!==t[4]?+t[4]:1}:null}(i);if(!n||r-t<1)return i;let o=e.createLinearGradient(0,t,0,r),sheen=e=>Math.min(255,Math.round(255-(255-e)*.55)),clamp=e=>Math.min(1,Math.max(0,e));return o.addColorStop(0,"rgba(".concat(n.r,",").concat(n.g,",").concat(n.b,",").concat(clamp(.55*n.a),")")),o.addColorStop(.22,"rgba(".concat(sheen(n.r),",").concat(sheen(n.g),",").concat(sheen(n.b),",").concat(clamp(1.15*n.a),")")),o.addColorStop(.45,"rgba(".concat(n.r,",").concat(n.g,",").concat(n.b,",").concat(clamp(.8*n.a),")")),o.addColorStop(1,"rgba(".concat(Math.round(.55*n.r),",").concat(Math.round(.55*n.g),",").concat(Math.round(.55*n.b),",").concat(clamp(.5*n.a),")")),o}function makeBodyFillColor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.35,r=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/);if(!r)return e;let i=void 0!==r[4]?parseFloat(r[4]):1;return"rgba(".concat(r[1],", ").concat(r[2],", ").concat(r[3],", ").concat(Math.min(1,i+t).toFixed(2),")")}let CandleChannelPaneRenderer=class CandleChannelPaneRenderer{draw(){}drawBackground(e){let t=this._viewData.data;t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context;r.scale(e.horizontalPixelRatio,e.verticalPixelRatio);let i=this._viewData.options,n=new Path2D,o=new Path2D,l=t[0];if(!l)return;for(let e of(n.moveTo(l.x,l.high),o.moveTo(l.x,l.low),t))n.lineTo(e.x,e.high),o.lineTo(e.x,e.low);let a=1/0,s=-1/0;for(let e of t)e.high<a&&(a=e.high),e.low>s&&(s=e.low);let d=candle_channel_metallicFill(r,a,s,i.upFillColor),c=candle_channel_metallicFill(r,a,s,i.downFillColor);for(let e=0;e<t.length-1;e++){let i=t[e],n=t[e+1];if(!i||!n)continue;let o=new Path2D;o.moveTo(i.x,i.high),o.lineTo(n.x,n.high),o.lineTo(n.x,n.low),o.lineTo(i.x,i.low),o.closePath(),r.fillStyle=i.isUp?d:c,r.fill(o)}let u=new Path2D,p=new Path2D;for(let e of(u.moveTo(l.x,l.bodyHigh),p.moveTo(l.x,l.bodyLow),t))u.lineTo(e.x,e.bodyHigh),p.lineTo(e.x,e.bodyLow);let h=1/0,g=-1/0;for(let e of t)e.bodyHigh<h&&(h=e.bodyHigh),e.bodyLow>g&&(g=e.bodyLow);let x=candle_channel_metallicFill(r,h,g,i.upBodyFillColor),b=candle_channel_metallicFill(r,h,g,i.downBodyFillColor);for(let e=0;e<t.length-1;e++){let i=t[e],n=t[e+1];if(!i||!n)continue;let o=new Path2D;o.moveTo(i.x,i.bodyHigh),o.lineTo(n.x,n.bodyHigh),o.lineTo(n.x,n.bodyLow),o.lineTo(i.x,i.bodyLow),o.closePath(),r.fillStyle=i.isUp?x:b,r.fill(o)}r.strokeStyle=i.lineColor,r.lineWidth=i.lineWidth,r.stroke(n),r.stroke(o),r.stroke(u),r.stroke(p)})}constructor(e){this._viewData=e}};let CandleChannelPaneView=class CandleChannelPaneView{update(){let e=this._source.series,t=this._source.chart.timeScale();this._data.data=this._source._bandData.map(r=>{var i,n,o,l,a;return{x:null!==(i=t.timeToCoordinate(r.time))&&void 0!==i?i:-100,high:null!==(n=e.priceToCoordinate(r.high))&&void 0!==n?n:-100,low:null!==(o=e.priceToCoordinate(r.low))&&void 0!==o?o:-100,bodyHigh:null!==(l=e.priceToCoordinate(r.bodyHigh))&&void 0!==l?l:-100,bodyLow:null!==(a=e.priceToCoordinate(r.bodyLow))&&void 0!==a?a:-100,isUp:r.isUp}})}renderer(){return new CandleChannelPaneRenderer(this._data)}constructor(e){this._source=e,this._data={data:[],options:this._source._options}}};let x={upFillColor:"rgba(34, 197, 94, 0.25)",downFillColor:"rgba(239, 68, 68, 0.25)",upBodyFillColor:"",downBodyFillColor:"",lineColor:"rgba(255, 255, 255, 0.1)",lineWidth:.5};let CandleChannelIndicator=class CandleChannelIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this._seriesData=this.series.data(),this.calculateBands(),this.updateAllViews(),this.requestUpdate()}calculateBands(){this._bandData=this._seriesData.map(e=>{let t=Number(e.high),r=Number(e.low),i=Number(e.open),n=Number(e.close);return Number.isFinite(t)&&Number.isFinite(r)&&Number.isFinite(i)&&Number.isFinite(n)?{time:e.time,high:t,low:r,bodyHigh:Math.max(i,n),bodyLow:Math.min(i,n),isUp:n>=i}:null}
1).filter(Boolean)}constructor(e={}){super(),this._bandData=[],this._seriesData=[],this._options={...x,...e},this._options.upBodyFillColor=e.upBodyFillColor||makeBodyFillColor(this._options.upFillColor),this._options.downBodyFillColor=e.downBodyFillColor||makeBodyFillColor(this._options.downFillColor),this._paneViews=[new CandleChannelPaneView(this)]}};function wrapAngle(e){return Math.atan2(Math.sin(e),Math.cos(e))}function calculateFourierOscillator(e,t){let r=e.map(e=>Number(e.close)),i=function(e,t){let r=[],i=Math.max(8,Math.floor(t)),n=null,o=null;for(let t=0;t<e.length;t++){let l=Math.max(0,t-i+1),a=e.slice(l,t+1),s=a.length;if(s<8){r.push(null);continue}let d=function(e){let t=e.length;if(t<8)return null;let r=function(e){let t=e.length,r=0,i=0,n=0,o=0;for(let l=0;l<t;l++)r+=l,i+=e[l],n+=l*e[l],o+=l*l;let l=t*o-r*r;if(0===l)return e;let a=(t*n-r*i)/l,s=(i-a*r)/t;return e.map((e,t)=>e-(a*t+s))}(e),i=function(e){let t=e.length;return t<2?e:e.map((e,r)=>e*(.5-.5*Math.cos(2*Math.PI*r/(t-1))))}(r),n=Math.max(4,Math.round(t/10)),o=Math.max(1,Math.ceil(t/t)),l=Math.min(Math.floor(t/2)-1,Math.floor(t/n));o>l&&(o=1,l=Math.max(1,Math.floor(t/2)-1));let a=o,s=-1,d=new Float64Array(l+1),c=new Float64Array(l+1);for(let e=o;e<=l;e++){let r=0,n=0;for(let o=0;o<t;o++){let l=2*Math.PI*e*o/t;r+=i[o]*Math.cos(l),n+=i[o]*Math.sin(l)}d[e]=r,c[e]=n;let o=r*r+n*n;o>s&&(s=o,a=e)}if(s<=0)return null;let u=Math.atan2(c[a],d[a]),p=wrapAngle(2*Math.PI*a*(t-1)/t+u);return{k:a,period:t/a,instPhase:p,mag:s}}(a);if(!d){r.push(null);continue}let c=d.instPhase,u=d.period;if(null===n||null===o)n=c,o=u;else{n+=2*Math.PI/(o=.6*o+.4*u);let e=wrapAngle(c-n);n+=.25*e}r.push(Math.cos(n))}return r}(r,t);return e.map((e,t)=>({time:e.time,value:i[t]}))}let FourierOscillatorPaneRenderer=class FourierOscillatorPaneRenderer{draw(){}drawBackground(e){let t=this._viewData.data;if(!t||t.length<2)return;let r=this._viewData.options;e.useBitmapCoordinateSpace(e=>{let i=e.context,n=e.bitmapSize.height,o=e.bitmapSize.width,l=e.horizontalPixelRatio,a=.78*n,s=.92*n,d=(a+s)/2,c=(s-a)/2,u=t.filter(e=>null!=e.x&&null!=e.value&&!Number.isNaN(e.value)).map(e=>({x:Math.round(e.x*l),value:e.value}));if(u.length<2)return;let p=new Path2D;p.moveTo(u[0].x,d-u[0].value*c);for(let e=1;e<u.length;e++)p.lineTo(u[e].x,d-u[e].value*c);let h=new Path2D(p);h.lineTo(u[u.length-1].x,d),h.lineTo(u[0].x,d),h.closePath(),i.fillStyle=r.fillColor,i.fill(h),i.strokeStyle=r.lineColor,i.lineWidth=r.lineWidth,i.stroke(p),i.beginPath(),i.moveTo(0,d),i.lineTo(o,d),i.strokeStyle="rgba(255,255,255,0.15)",i.lineWidth=1,i.stroke()})}constructor(e){this._viewData=e}};let FourierOscillatorPaneView=class FourierOscillatorPaneView{update(){let e=this._source.chart.timeScale();this._data.data=this._source._oscData.map(t=>({x:e.timeToCoordinate(t.time),value:t.value}))}renderer(){return new FourierOscillatorPaneRenderer(this._data)}zOrder(){return"top"}constructor(e){this._source=e,this._data={data:[],options:this._source._options}}};let b={windowSize:64,lineColor:"rgba(6, 182, 212, 0.9)",fillColor:"rgba(6, 182, 212, 0.15)",lineWidth:1.5};let FourierOscillatorIndicator=class FourierOscillatorIndicator extends PluginBase{updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}attached(e){super.attached(e),this.dataUpdated("full")}dataUpdated(e){this._seriesData=this.series.data(),this.calculateOscillator(),"full"===e&&this.updateAllViews(),this.requestUpdate()}calculateOscillator(){let e=Math.max(4*this._options.windowSize,500),t=this._seriesData.slice(-e);this._oscData=calculateFourierOscillator(t,this._options.windowSize)}constructor(e={}){super(),this._oscData=[],this._seriesData=[],this._options={...b,...e},this._paneViews=[new FourierOscillatorPaneView(this)]}};function symbolToGexCurrency(e){let t=e.toUpperCase();return t.startsWith("BTC")||t.startsWith("XBT")?"BTC":t.startsWith("ETH")?"ETH":t.startsWith("SOL")?"SOL":null}let f={JAN:0,FEB:1,MAR:2,APR:3,MAY:4,JUN:5,JUL:6,AUG:7,SEP:8,OCT:9,NOV:10,DEC:11};async function fetchGexProfile(e,t){var r,i,n,o,l;let a="".concat("https://www.deribit.com/api/v2","/public/get_book_summary_by_currency?currency=").concat(e,"&kind=option"),s=await fetch(a,{signal:t});if(!s.ok)throw Error("Deribit GEX request failed (".concat(s.status,")"));let d=await s.json(),c=null!==(i=d.result)&&void 0!==i?i:[],u=c.map(e=>e.underlying_price).filter(e=>"number"==typeof e&&e>0).sort((e,t)=>
1e-t),p=u.length?u[Math.floor(u.length/2)]:0;if(p<=0)throw Error("Deribit GEX: no underlying price available");let h=Date.now(),g=new Map;for(let e of c){if(!e.open_interest||!e.mark_iv)continue;let t=function(e){let t=e.split("-");if(4!==t.length)return null;let r=t[1],i=t[2],n=t[3],o=/^(\d{1,2})([A-Z]{3})(\d{2})$/.exec(r);if(!o)return null;let l=Number(o[1]),a=f[o[2]],s=2e3+Number(o[3]);if(void 0===a)return null;let d=Date.UTC(s,a,l,8,0,0),c=Number(i);return!Number.isFinite(c)||c<=0?null:{strike:c,isCall:"C"===n,expiryMs:d}}(e.instrument_name);if(!t)continue;let r=(t.expiryMs-h)/31536e6;if(r<=0||r>2.5)continue;let i=(null!==(n=e.mark_iv)&&void 0!==n?n:0)/100,l=function(e,t,r,i){var n;if(e<=0||t<=0||r<=0||i<=0)return 0;let o=Math.sqrt(i);return Math.exp(-.5*(n=(Math.log(e/t)+.5*r*r*i)/(r*o))*n)/Math.sqrt(2*Math.PI)/(e*r*o)}(p,t.strike,i,r);if(l<=0)continue;let a=t.isCall?1:-1,s=a*l*e.open_interest*p*p*.01;g.set(t.strike,(null!==(o=g.get(t.strike))&&void 0!==o?o:0)+s)}let x=[...g.entries()].map(e=>{let[t,r]=e;return{strike:t,gex:r}}).sort((e,t)=>e.strike-t.strike),b=null,m=null,y=0,v=0,w=0,S=0;for(let e of x)S+=e.gex,w=Math.max(w,Math.abs(e.gex)),e.gex>y&&(y=e.gex,b=e.strike),e.gex<v&&(v=e.gex,m=e.strike);let k=null,j=0,C=0,_=null!==(l=null===(r=x[0])||void 0===r?void 0:r.strike)&&void 0!==l?l:null;for(let e of x){if(j+=e.gex,null!==_&&(C<0&&j>=0||C>0&&j<=0)){let t=j-C,r=0!==t?-C/t:0;k=_+r*(e.strike-_);break}C=j,_=e.strike}return{currency:e,spot:p,updatedAt:h,strikes:x,callWall:b,putWall:m,zeroGamma:k,maxAbsGex:w,totalGex:S}}function hexToRgba(e,t){let r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return r?"rgba(".concat(parseInt(r[1],16),", ").concat(parseInt(r[2],16),", ").concat(parseInt(r[3],16),", ").concat(t,")"):e}function toBitmap(e,t,r){return{x:Math.round(t*e.horizontalPixelRatio),y:Math.round(r*e.verticalPixelRatio)}}function showHandles(e){return"hovered"===e.state||"selected"===e.state}function dashFor(e){return"dashed"===e?[6,6]:"dotted"===e?[2,3]:void 0}function applyDash(e,t){t&&e.context.setLineDash(t.map(t=>t*e.horizontalPixelRatio))}function strokeLine(e,t,r,i,n,o){let l=e.context;l.save(),l.strokeStyle=i,l.lineWidth=n*e.verticalPixelRatio,applyDash(e,o),l.beginPath(),l.moveTo(t.x,t.y),l.lineTo(r.x,r.y),l.stroke(),l.restore()}function drawHandle(e,t,r){let i=e.context;i.save(),i.beginPath(),i.arc(t.x,t.y,5*e.horizontalPixelRatio,0,2*Math.PI),i.fillStyle="#ffffff",i.fill(),i.lineWidth=1.5*e.horizontalPixelRatio,i.strokeStyle=r,i.stroke(),i.restore()}function drawArrowhead(e,t,r,i){let n=e.context,o=Math.atan2(r.y-t.y,r.x-t.x),l=12*e.horizontalPixelRatio,a=Math.PI/7;n.save(),n.fillStyle=i,n.beginPath(),n.moveTo(r.x,r.y),n.lineTo(r.x-l*Math.cos(o-a),r.y-l*Math.sin(o-a)),n.lineTo(r.x-l*Math.cos(o+a),r.y-l*Math.sin(o+a)),n.closePath(),n.fill(),n.restore()}function posZone(e,t,r,i,n,o){let l=e.context,a=toBitmap(e,t,Math.min(i,n)),s=toBitmap(e,r,Math.max(i,n));l.save(),l.fillStyle=hexToRgba(o,.12),l.fillRect(a.x,a.y,s.x-a.x,s.y-a.y),l.strokeStyle=hexToRgba(o,.6),l.lineWidth=e.verticalPixelRatio,l.strokeRect(a.x,a.y,s.x-a.x,s.y-a.y),l.restore()}function signPct(e,t){if(0===t)return"0%";let r=(e-t)/t*100;return"".concat(r>=0?"+":"").concat(r.toFixed(2),"%")}function drawAlertBadge(e,t,r){let i=e.context,n=4*e.horizontalPixelRatio;i.save(),i.fillStyle="#f0b90b",i.strokeStyle="#1b1f2a",i.lineWidth=e.horizontalPixelRatio,i.beginPath(),i.arc(t,r,n,0,2*Math.PI),i.fill(),i.stroke(),i.restore()}function drawRectHandles(e,t,r,i){drawHandle(e,t,i),drawHandle(e,r,i),drawHandle(e,{x:t.x,y:r.y},i),drawHandle(e,{x:r.x,y:t.y},i)}let m=[0,.236,.382,.5,.618,.786,1],y=[0,.618,1,1.618,2.618],v=["#e91e63","#ff5722","#ff9800","#ffc107","#4caf50","#2196F3","#9c27b0"];function makeResolveCtx(e,t,r){return{chart:e,series:t,intervalSec:r,data:t.data()}}function timeToX(e,t){let r=e.chart.timeScale(),i=r.timeToCoordinate(t);if(null!==i)return i;let n=function(e,t){let{data:r,intervalSec:i}=e;if(0===r.length||i<=0)return null;let n=r[0].time,o=r[r.length-1].time;if(t<=n)return(t-n)/i;if(t>=o)return r.length-1+(t-o)/i;let l=function(e,t){let r=0,i=e.length;for(;r<i;){let n=r+i>>1;e[n].time<t?r=n+1:i=n}return r}(r,t),a=r[l-1].time,s=r[l].time;return l-1+(t-a)/Math.max(s-a,1)}(e,t);return null===n?null:function(e,t){let r=Math.floor(t),i=e.logicalToCoordinate(r);if(null===i)return null;let n=t-r;if(0===n)return i;let o=e.logicalToCoordinate(r+1);return null===o?null:i+n*(o-i)}(r,n)}function resolveEntry(e,t,r){let i={d:e,x1:null!=e.time?timeToX(t,e.time):null,y1:Number.isFinite(e.price)?t.series.priceToCoordinate(e.price):null,x2:null!=e.time2?timeToX(t,e.time2):null,y2:null!=e.price2?t.series.priceToCoordinate(e.price2):null,state:r};return("fibonacci"===e.type||"fibextension"===e.type)&&(i.fibLevels=function(e,t){if(null==e.price2)return[];let r=t.priceFormatter();return(e.fibLevels&&e.fibLevels.length>0?e.fibLevels:"fibextension"===e.type?y:m).map((i,n)=>{var o;let l=e.price2+(e.price-e.price2)*i;
1return{level:i,price:l,y:t.priceToCoordinate(l),color:null!==(o=v[n])&&void 0!==o?o:"#2196F3",label:"".concat(i," (").concat(r.format(l),")")}})}(e,t.series)),"trendline"===e.type&&(i.seg=function(e,t){if(null===e.x1||null===e.y1||null===e.x2||null===e.y2)return;let r=e.x1<=e.x2?{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2}:{x1:e.x2,y1:e.y2,x2:e.x1,y2:e.y1};return function(e,t,r){if(!t.extendLeft&&!t.extendRight||e.x2-e.x1<.5)return e;let i=(e.y2-e.y1)/(e.x2-e.x1),n={...e};return t.extendLeft&&(n.y1-=i*n.x1,n.x1=0),t.extendRight&&r>n.x2&&(n.y2+=i*(r-n.x2),n.x2=r),n}(r,e.d,t)}(i,t.chart.timeScale().width()),("selected"===r||"preview"===r)&&(i.stats=function(e,t){if(null==e.price2||null==e.time||null==e.time2)return[];let r=e.price2-e.price,i=0!==e.price?r/e.price*100:0,n=t.intervalSec>0?Math.round(Math.abs(e.time2-e.time)/t.intervalSec):0,o=t.series.priceFormatter().format(Math.abs(r));return["".concat(r>=0?"+":"−").concat(o," (").concat(i.toFixed(2),"%)"),"".concat(n," bars")]}(e,t))),"position"===e.type&&(i.yStop=null!=e.stopPrice?t.series.priceToCoordinate(e.stopPrice):null,i.yTarget=null!=e.targetPrice?t.series.priceToCoordinate(e.targetPrice):null),"channel"===e.type&&(i.x3=null!=e.time3?timeToX(t,e.time3):null,i.y3=null!=e.price3?t.series.priceToCoordinate(e.price3):null),i}let DrawingsPaneRenderer=class DrawingsPaneRenderer{draw(e){e.useBitmapCoordinateSpace(e=>{for(let t of this._entries)!function(e,t,r){switch(t.d.type){case"trendline":!function(e,t){var r,i;if(null===t.x1||null===t.y1||null===t.x2||null===t.y2)return;let n=toBitmap(e,t.x1,t.y1),o=toBitmap(e,t.x2,t.y2),l=null!==(r=t.seg)&&void 0!==r?r:{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2},a=toBitmap(e,l.x1,l.y1),s=toBitmap(e,l.x2,l.y2);if(strokeLine(e,a,s,t.d.color,null!==(i=t.d.width)&&void 0!==i?i:2,dashFor(t.d.lineStyle)),t.d.arrowEnd&&drawArrowhead(e,a,s,t.d.color),t.d.arrowStart&&drawArrowhead(e,s,a,t.d.color),showHandles(t)&&(drawHandle(e,n,t.d.color),drawHandle(e,o,t.d.color),function(e,t,r,i){let n=e.context,o=3*e.horizontalPixelRatio,l=(t.x+r.x)/2,a=(t.y+r.y)/2;n.save(),n.fillStyle="#ffffff",n.strokeStyle=i,n.lineWidth=1.5*e.horizontalPixelRatio,n.beginPath(),n.rect(l-o,a-o,2*o,2*o),n.fill(),n.stroke(),n.restore()}
1(e,n,o,t.d.color)),t.d.alertEnabled){let t=n.x>=o.x?n:o;drawAlertBadge(e,t.x,t.y)}t.stats&&t.stats.length>0&&function(e,t,r,i,n){let o=e.context,l=e.horizontalPixelRatio,a=e.verticalPixelRatio,s=Math.round(180*Math.atan2(n.y-t.y,t.x-n.x)/Math.PI),d=[...r,"".concat(s,"\xb0")];o.save(),o.font="".concat(Math.round(10*a),"px monospace");let c=13*a,u=6*l,p=Math.max(...d.map(e=>o.measureText(e).width))+2*u,h=d.length*c+u,g=Math.min(t.x+10*l,e.bitmapSize.width-p),x=Math.min(t.y+10*a,e.bitmapSize.height-h);o.fillStyle="rgba(20, 24, 35, 0.92)",o.beginPath(),o.roundRect(g,x,p,h,4*l),o.fill(),o.strokeStyle=i.color,o.lineWidth=1,o.stroke(),o.fillStyle="#e0e3ea",o.textBaseline="top",d.forEach((e,t)=>{o.fillText(e,g+u,x+u/2+t*c)}),o.restore()}(e,o,t.stats,t.d,n)}(e,t);break;case"horizontal":!function(e,t){var r;if(null===t.y1)return;let i=Math.round(t.y1*e.verticalPixelRatio);strokeLine(e,{x:0,y:i},{x:e.bitmapSize.width,y:i},t.d.color,null!==(r=t.d.width)&&void 0!==r?r:1.5,dashFor(t.d.lineStyle)),showHandles(t)&&drawHandle(e,{x:Math.round(e.bitmapSize.width/2),y:i},t.d.color),t.d.alertEnabled&&drawAlertBadge(e,e.bitmapSize.width-14*e.horizontalPixelRatio,i)}(e,t);break;case"rectangle":!function(e,t){var r,i,n;if(null===t.x1||null===t.y1||null===t.x2||null===t.y2)return;let o=toBitmap(e,t.x1,t.y1),l=toBitmap(e,t.x2,t.y2),a=e.context;a.save(),a.fillStyle=hexToRgba(null!==(r=t.d.fillColor)&&void 0!==r?r:t.d.color,null!==(i=t.d.fillOpacity)&&void 0!==i?i:.14),a.fillRect(Math.min(o.x,l.x),Math.min(o.y,l.y),Math.abs(l.x-o.x),Math.abs(l.y-o.y)),a.strokeStyle=t.d.color,a.lineWidth=(null!==(n=t.d.width)&&void 0!==n?n:1.5)*e.verticalPixelRatio,applyDash(e,dashFor(t.d.lineStyle)),a.strokeRect(Math.min(o.x,l.x),Math.min(o.y,l.y),Math.abs(l.x-o.x),Math.abs(l.y-o.y)),a.restore(),showHandles(t)&&drawRectHandles(e,o,l,t.d.color)}(e,t);break;case"fibonacci":case"fibextension":!function(e,t){if(null===t.x1||null===t.x2||!t.fibLevels||0===t.fibLevels.length)return;let r=Math.round(Math.min(t.x1,t.x2)*e.horizontalPixelRatio),i=Math.round(Math.max(t.x1,t.x2)*e.horizontalPixelRatio);for(let n of(function(e,t,r,i){let n=e.context;
1for(let o=0;o<t.length-1;o++){let l=t[o],a=t[o+1];if(null===l.y||null===a.y)continue;let s=Math.round(l.y*e.verticalPixelRatio),d=Math.round(a.y*e.verticalPixelRatio);n.fillStyle=hexToRgba(a.color,.08),n.fillRect(r,Math.min(s,d),i-r,Math.abs(d-s))}}(e,t.fibLevels,r,i),t.fibLevels))!function(e,t,r,i){if(null===t.y)return;let n=Math.round(t.y*e.verticalPixelRatio);strokeLine(e,{x:r,y:n},{x:i,y:n},t.color,1);let o=e.context;o.save(),o.font="".concat(Math.round(10*e.verticalPixelRatio),"px monospace"),o.textAlign="right",o.textBaseline="middle",o.fillStyle=t.color,o.fillText(t.label,r-6*e.horizontalPixelRatio,n),o.restore()}(e,n,r,i);!function(e,t){if(null===t.x1||null===t.y1||null===t.x2||null===t.y2)return;let r=toBitmap(e,t.x1,t.y1),i=toBitmap(e,t.x2,t.y2);strokeLine(e,r,i,t.d.color,1,[4,4]),showHandles(t)&&(drawHandle(e,r,t.d.color),drawHandle(e,i,t.d.color))}(e,t)}(e,t);break;case"position":!function(e,t,r){let{x1:i,x2:n,y1:o,yStop:l,yTarget:a}=t;if(null===i||null===n||null===o||null==l||null==a)return;let s=Math.min(i,n),d=Math.max(i,n);posZone(e,s,d,o,a,"#089981"),posZone(e,s,d,o,l,"#f23645"),strokeLine(e,toBitmap(e,s,o),toBitmap(e,d,o),"#d1d4dc",1.5,[5,3]),showHandles(t)&&function(e,t,r,i,n){let o=(r+i)/2;drawHandle(e,toBitmap(e,o,n),t.d.color),null!=t.yTarget&&drawHandle(e,toBitmap(e,o,t.yTarget),t.d.color),null!=t.yStop&&drawHandle(e,toBitmap(e,o,t.yStop),t.d.color),drawHandle(e,toBitmap(e,i,n),t.d.color)}(e,t,s,d,o);let c=function(e,t){if(null==e.stopPrice||null==e.targetPrice)return[];let r=Math.abs(e.targetPrice-e.price),i=Math.abs(e.price-e.stopPrice),n="short"===e.side?"Short":"Long",o=["".concat(n,"  RR ").concat((i>0?r/i:0).toFixed(2)),"T ".concat(t.priceFormat(e.targetPrice),"  ").concat(signPct(e.targetPrice,e.price)),"S ".concat(t.priceFormat(e.stopPrice),"  ").concat(signPct(e.stopPrice,e.price))];if(t.accountEquity>0&&i>0){var l;let r=t.accountEquity*(null!==(l=e.riskPct)&&void 0!==l?l:1)/100,n=r/i;o.push("Risk $".concat(r.toFixed(0)," \xb7 Qty ").concat(n>=100?n.toFixed(0):n.toFixed(2)))}return o}(t.d,r);if(c.length>0){let r=toBitmap(e,d+8,o);!function(e,t,r,i,n){let o=e.context,l=e.horizontalPixelRatio,a=e.verticalPixelRatio;o.save(),o.font="".concat(Math.round(10*a),"px monospace");let s=13*a,d=6*l,c=Math.max(...i.map(e=>o.measureText(e).width))+2*d,u=i.length*s+d,p=Math.min(t,e.bitmapSize.width-c),h=Math.min(Math.max(r,0),e.bitmapSize.height-u);o.fillStyle="rgba(20, 24, 35, 0.92)",o.beginPath(),o.roundRect(p,h,c,u,4*l),o.fill(),o.strokeStyle=n,o.lineWidth=1,o.stroke(),o.fillStyle="#e0e3ea",o.textBaseline="top",i.forEach((e,t)=>o.fillText(e,p+d,h+d/2+t*s)),o.restore()}(e,r.x,r.y,c,t.d.color)}}(e,t,r);break;case"vertical":!function(e,t){var r;if(null===t.x1)return;let i=Math.round(t.x1*e.horizontalPixelRatio);strokeLine(e,{x:i,y:0},{x:i,y:e.bitmapSize.height},t.d.color,null!==(r=t.d.width)&&void 0!==r?r:1.5,dashFor(t.d.lineStyle)),showHandles(t)&&drawHandle(e,{x:i,y:Math.round(e.bitmapSize.height/2)},t.d.color)}(e,t);break;case"channel":!function(e,t){var r,i,n,o;if(null===t.x1||null===t.y1||null===t.x2||null===t.y2||null==t.y3)return;let l=t.y3-t.y1,a=toBitmap(e,t.x1,t.y1),s=toBitmap(e,t.x2,t.y2),d=toBitmap(e,t.x1,t.y3),c=toBitmap(e,t.x2,t.y2+l),u=e.context;u.save(),u.fillStyle=hexToRgba(null!==(r=t.d.fillColor)&&void 0!==r?r:t.d.color,null!==(i=t.d.fillOpacity)&&void 0!==i?i:.1),u.beginPath(),u.moveTo(a.x,a.y),u.lineTo(s.x,s.y),u.lineTo(c.x,c.y),u.lineTo(d.x,d.y),u.closePath(),u.fill(),u.restore();let p=dashFor(t.d.lineStyle);strokeLine(e,a,s,t.d.color,null!==(n=t.d.width)&&void 0!==n?n:2,p),strokeLine(e,d,c,t.d.color,null!==(o=t.d.width)&&void 0!==o?o:2,p),showHandles(t)&&(drawHandle(e,a,t.d.color),drawHandle(e,s,t.d.color),drawHandle(e,d,t.d.color))}(e,t);break;case"ellipse":!function(e,t){var r,i,n;if(null===t.x1||null===t.y1||null===t.x2||null===t.y2)return;let o=toBitmap(e,t.x1,t.y1),l=toBitmap(e,t.x2,t.y2),a=e.context,s=(o.x+l.x)/2,d=(o.y+l.y)/2;a.save(),a.beginPath(),a.ellipse(s,d,Math.abs(l.x-o.x)/2,Math.abs(l.y-o.y)/2,0,0,2*Math.PI),a.fillStyle=hexToRgba(null!==(r=t.d.fillColor)&&void 0!==r?r:t.d.color,null!==(i=t.d.fillOpacity)&&void 0!==i?i:.14),a.fill(),a.strokeStyle=t.d.color,a.lineWidth=(null!==(n=t.d.width)&&void 0!==n?n:1.5)*e.verticalPixelRatio,applyDash(e,dashFor(t.d.lineStyle)),a.stroke(),a.restore(
1),showHandles(t)&&drawRectHandles(e,o,l,t.d.color)}(e,t);break;case"arrow":!function(e,t){var r;if(null===t.x1||null===t.y1||null===t.x2||null===t.y2)return;let i=toBitmap(e,t.x1,t.y1),n=toBitmap(e,t.x2,t.y2);strokeLine(e,i,n,t.d.color,null!==(r=t.d.width)&&void 0!==r?r:2,dashFor(t.d.lineStyle)),drawArrowhead(e,i,n,t.d.color),showHandles(t)&&(drawHandle(e,i,t.d.color),drawHandle(e,n,t.d.color))}(e,t);break;case"triangle":!function(e,t){var r,i,n;if(null===t.x1||null===t.y1||null===t.x2||null===t.y2)return;let o=toBitmap(e,t.x1,t.y1),l=toBitmap(e,t.x2,t.y2),a=e.context;a.save(),a.beginPath(),a.moveTo((o.x+l.x)/2,o.y),a.lineTo(l.x,l.y),a.lineTo(o.x,l.y),a.closePath(),a.fillStyle=hexToRgba(null!==(r=t.d.fillColor)&&void 0!==r?r:t.d.color,null!==(i=t.d.fillOpacity)&&void 0!==i?i:.14),a.fill(),a.strokeStyle=t.d.color,a.lineWidth=(null!==(n=t.d.width)&&void 0!==n?n:1.5)*e.verticalPixelRatio,applyDash(e,dashFor(t.d.lineStyle)),a.stroke(),a.restore(),showHandles(t)&&(drawHandle(e,o,t.d.color),drawHandle(e,l,t.d.color))}(e,t);break;case"text":!function(e,t){var r,i,n,o;if(null===t.x1||null===t.y1)return;let l=e.context,a=e.horizontalPixelRatio,s=(null!==(r=t.d.fontSize)&&void 0!==r?r:14)*e.verticalPixelRatio,d=(null!==(i=t.d.text)&&void 0!==i?i:"Text").split("\n"),c=toBitmap(e,t.x1,t.y1),u=1.3*s,p=4*a;l.save(),l.font=function(e,t){let r=e.italic?"italic ":"",i=e.bold?"bold ":"";return"".concat(r).concat(i).concat(Math.round(t),"px sans-serif")}(t.d,s),l.textBaseline="top";let h=Math.max(...d.map(e=>l.measureText(e).width)),g=h+2*p,x=d.length*u+2*p,b=c.x-p,f=c.y-p;t.d.textBg&&(l.fillStyle=null!==(n=t.d.textBgColor)&&void 0!==n?n:"#1e222d",l.fillRect(b,f,g,x)),t.d.textBorder&&(l.strokeStyle=null!==(o=t.d.textBorderColor)&&void 0!==o?o:t.d.color,l.lineWidth=a,l.strokeRect(b,f,g,x)),l.fillStyle=t.d.color,d.forEach((e,t)=>l.fillText(e,c.x,c.y+t*u)),showHandles(t)&&(l.strokeStyle=t.d.color,l.lineWidth=a,l.setLineDash([3*a,3*a]),l.strokeRect(b,f,g,x)),l.restore()}(e,t)}}(e,t,this._info)})}constructor(e,t){this._entries=e,this._info=t}};let DrawingsPaneView=class DrawingsPaneView{update(){this._entries=this._source.resolveEntries()}renderer(){return new DrawingsPaneRenderer(this._entries,this._source.drawInfo())}constructor(e){this._entries=[],this._source=e}};let PriceAxisLabelView=class PriceAxisLabelView{update(){this._y=this._source.series.priceToCoordinate(this._price)}coordinate(){var e;return null!==(e=this._y)&&void 0!==e?e:-1}visible(){return null!==this._y}tickVisible(){return!0}text(){return this._source.series.priceFormatter().format(this._price)}textColor(){return"#ffffff"}backColor(){return this._color}constructor(e,t,r){this._y=null,this._source=e,this._price=t,this._color=r}};let DrawingsPrimitive=class DrawingsPrimitive extends PluginBase{setDrawings(e){this._drawings=e,this._rebuildAxisViews(),this.requestUpdate()}setPreview(e){this._preview=e,this.requestUpdate()}setSelected(e){this._selectedIds=new Set(e),this._rebuildAxisViews(),this.requestUpdate()}setHovered(e){this._hoveredId!==e&&(this._hoveredId=e,this.requestUpdate())}setAccountEquity(e){this._accountEquity!==e&&(this._accountEquity=e,this.requestUpdate())}drawInfo(){return{accountEquity:this._accountEquity,priceFormat:e=>this.series.priceFormatter().format(e)}}setIntervalSec(e){this._intervalSec!==e&&(this._intervalSec=e,this.requestUpdate())}updateAllViews(){for(let e of this._paneViews)e.update();for(let e of this._axisViews)e.update()}paneViews(){return this._paneViews}priceAxisViews(){return this._axisViews}resolveEntries(){let e=makeResolveCtx(this.chart,this.series,this._intervalSec),t=this._drawings.map(t=>resolveEntry(t,e,this._stateFor(t.id)));return this._preview&&t.push(resolveEntry(this._preview,e,"preview")),t}_stateFor(e){return this._selectedIds.has(e)?"selected":e===this._hoveredId?"hovered":"normal"}_rebuildAxisViews(){let e=[];for(let t of this._drawings)!function(e,t,r,i){if("horizontal"===t.type){e.push(new PriceAxisLabelView(i,t.price,t.color));return}r.has(t.id)&&(Number.isFinite(t.price)&&e.push(new PriceAxisLabelView(i,t.price,t.color)),null!=t.price2&&e.push(new PriceAxisLabelView(i,t.price2,t.color)))}(e,t,this._selectedIds,this);this._axisViews=e}constructor(...e){super(...e),this._drawings=[],this._preview=null,this._selectedIds=new Set,this._hoveredId=null,this._intervalSec=60,this._accountEquity=0,this._paneViews=[new DrawingsPaneView(this)],this._axisViews=[]}};function dist(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function distToSegment(e,t,r){let i=r.x-t.x,n=r.y-t.y,o=i*i+n*n;if(0===o)return dist(e,t);let l=Math.max(0,Math.min(1,((e.x-t.x)*i+(e.y-t.y)*n)/o));return dist(e,{x:t.x+l*i,y:t.y+l*n})}function pointInBox(e,t,r,i,n,o){return e.x>=Math.min(t,i)-o&&e.x<=Math.max(t,i)+o&&e.y>=Math.min(r,n)-o&&e.y<=Math.max(r,n)+o}function hitTest(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i={handle:8*r,line:6*r};for(let r=e.length-1;r>=0;r--){let n=function(e,t,r){switch(e.d.type){case"trendline":case"arrow":return function(e,t,r){var i;let n=anchorHit(e,t,r);if(n)return n;
1let o=null!==(i=e.seg)&&void 0!==i?i:null!==e.x1&&null!==e.y1&&null!==e.x2&&null!==e.y2?{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2}:null;if(!o)return null;let l=distToSegment(t,{x:o.x1,y:o.y1},{x:o.x2,y:o.y2})<=r.line;return l?bodyHit(e):null}(e,t,r);case"horizontal":return null===e.y1||Math.abs(t.y-e.y1)>r.line?null:{id:e.d.id,region:{kind:"point",timeKey:null,priceKey:"price"}};case"rectangle":return function(e,t,r){if(null===e.x1||null===e.y1||null===e.x2||null===e.y2)return null;let i=rectCornerHit(e,t,r);return i||(pointInBox(t,e.x1,e.y1,e.x2,e.y2,r.line)?bodyHit(e):null)}(e,t,r);case"fibonacci":case"fibextension":return function(e,t,r){let i=anchorHit(e,t,r);if(i)return i;if(null===e.x1||null===e.x2||!e.fibLevels||t.x<Math.min(e.x1,e.x2)-r.line||t.x>Math.max(e.x1,e.x2)+r.line)return null;let n=e.fibLevels.some(e=>null!==e.y&&Math.abs(t.y-e.y)<=r.line);return n?bodyHit(e):null}(e,t,r);case"position":return function(e,t,r){let{x1:i,x2:n,y1:o,yStop:l,yTarget:a}=e;if(null===i||null===n||null===o)return null;let s=Math.min(i,n),d=Math.max(i,n),c=(s+d)/2;if(null!=a&&dist(t,{x:c,y:a})<=r.handle)return pointHit(e,null,"targetPrice");if(null!=l&&dist(t,{x:c,y:l})<=r.handle)return pointHit(e,null,"stopPrice");if(dist(t,{x:c,y:o})<=r.handle)return pointHit(e,null,"price");if(dist(t,{x:d,y:o})<=r.handle)return pointHit(e,"time2",null);let u=[o,null!=l?l:o,null!=a?a:o],p=t.x>=s-r.line&&t.x<=d+r.line&&t.y>=Math.min(...u)-r.line&&t.y<=Math.max(...u)+r.line;return p?bodyHit(e):null}(e,t,r);case"vertical":return null===e.x1||Math.abs(t.x-e.x1)>r.line?null:{id:e.d.id,region:{kind:"point",timeKey:"time",priceKey:null}};case"channel":return function(e,t,r){let i=anchorHit(e,t,r);if(i)return i;if(null!==e.x1&&null!=e.y3&&dist(t,{x:e.x1,y:e.y3})<=r.handle)return{id:e.d.id,region:{kind:"point",timeKey:"time3",priceKey:"price3"}};if(null===e.x1||null===e.y1||null===e.x2||null===e.y2||null==e.y3)return null;let n=e.y3-e.y1,o=distToSegment(t,{x:e.x1,y:e.y1},{x:e.x2,y:e.y2})<=r.line,l=distToSegment(t,{x:e.x1,y:e.y3},{x:e.x2,y:e.y2+n})<=r.line;return o||l?bodyHit(e):null}(e,t,r);case"ellipse":case"triangle":return function(e,t,r){if(null===e.x1||null===e.y1||null===e.x2||null===e.y2)return null;let i=rectCornerHit(e,t,r);return i||(pointInBox(t,e.x1,e.y1,e.x2,e.y2,r.line)?bodyHit(e):null)}(e,t,r);case"text":return function(e,t,r){var i,n;if(null===e.x1||null===e.y1)return null;let o=null!==(i=e.d.fontSize)&&void 0!==i?i:14,l=(null!==(n=e.d.text)&&void 0!==n?n:"Text").split("\n"),a=l.reduce((e,t)=>Math.max(e,t.length),4),s=l.length*o*1.3,d=t.x>=e.x1-r.line&&t.x<=e.x1+a*o*.6+r.line&&t.y>=e.y1-r.line&&t.y<=e.y1+s+r.line;return d?{id:e.d.id,region:{kind:"point",timeKey:"time",priceKey:"price"}}:null}(e,t,r);default:return null}}(e[r],t,i);if(n)return n}return null}function pointHit(e,t,r){return{id:e.d.id,region:{kind:"point",timeKey:t,priceKey:r}}}function bodyHit(e){return{id:e.d.id,region:{kind:"body"}}}function anchorHit(e,t,r){return null!==e.x1&&null!==e.y1&&dist(t,{x:e.x1,y:e.y1})<=r.handle?{id:e.d.id,region:{kind:"point",timeKey:"time",priceKey:"price"}}:null!==e.x2&&null!==e.y2&&dist(t,{x:e.x2,y:e.y2})<=r.handle?{id:e.d.id,region:{kind:"point",timeKey:"time2",priceKey:"price2"}}:null}function rectCornerHit(e,t,r){let i=[{x:e.x1,y:e.y1,timeKey:"time",priceKey:"price"},{x:e.x2,y:e.y2,timeKey:"time2",priceKey:"price2"},{x:e.x1,y:e.y2,timeKey:"time",priceKey:"price2"},{x:e.x2,y:e.y1,timeKey:"time2",priceKey:"price"}];for(let n of i)if(dist(t,n)<=r.handle)return{id:e.d.id,region:{kind:"point",timeKey:n.timeKey,priceKey:n.priceKey}};return null}let w={KeyT:"trendline",KeyH:"horizontal",KeyF:"fibonacci",KeyR:"rectangle",KeyM:"measure"};function evtFromTouch(e){return{shiftKey:!1,preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()}}let DrawingToolsManager=class DrawingToolsManager{destroy(){this.clearLongPress(),this.container.removeEventListener("mousedown",this.handleMouseDown,!0),this.container.removeEventListener("dblclick",this.handleDblClick),this.container.removeEventListener("contextmenu",this.handleContextMenu),this.container.removeEventListener("touchstart",this.handleTouchStart,!0),window.removeEventListener("mousemove",this.handleMouseMove),window.removeEventListener("mouseup",this.handleMouseUp),window.removeEventListener("touchmove",this.handleTouchMove),window.removeEventListener("touchend",this.handleTouchEnd),window.removeEventListener("touchcancel",this.handleTouchEnd),window.removeEventListener("keydown",this.handleKeyDown);try{this.series.detachPrimitive(this.primitive)}catch(e){}this.container.style.cursor=""}setTool(e){this.tool!==e&&(this.tool=e,this.cancelPlacement(),this.applyCursor(null))}setMagnetMode(e){this.magnetMode=e}setStyleDefaults(e){this.styleDefaults=e}setStayInDrawingMode(e){this.stayInMode=e}setAccountEquity(e){this.primitive.setAccountEquity(e)}updateTimeframe(e,t){this.timeframe=e,this.intervalSec=t,this.primitive.setIntervalSec(t)}setSelection(e){this.select(e.filter(e=>this.drawings.some(t=>t.id===e)))}setDrawings(e){if(this.drag)return;this.drawings=e.map(e=>({...e}));let t=this.selectedIds.filter(e=>this.drawings.some(t=>t.id===e));t.length!==this.selectedIds.length&&this.select(t),this.primitive.setDrawings(this.drawings)}ctx(){return makeResolveCtx(this.chart,this.series,this.intervalSec)}posFromClient(e,t){let r=this.container.getBoundingClientRect(),i=e-r.left,n=t-r.top,o=this.chart.timeScale(),l=o.width(),a=r.height-o.height();return l<=0||i<0||n<0||i>l||n>a?null:{x:i,y:n}}eventPos(e){return this.posFromClient(e.clientX,e.clientY)}toPoint(e){let t=function(e,t){let r=e.chart.timeScale().coordinateToTime(t);if(null!==r)return r;let{data:i,intervalSec:n}=e;if(0===i.length||n<=0)return null;let o=e.chart.timeScale().coordinateToLogical(t);if(null===o)return null;let l=i.length-1,a=i[l].time,s=i[0].time;return o>l?a+Math.round(o-l)*n:o<0?s+Math.round(o)*n:null}(this.ctx(),e.x),r=this.series.coordinateToPrice(e.y);return null===t||null===r?null:{time:t,price:r}}resolveAll(){let e=this.ctx();return this.drawings.map(t=>resolveEntry(t,e,"normal"))}makeNew(e,t,r){let i=this.buildNew(e,t,r);if("measure"===e)return i;let n=this.styleDefaults[i.type];return n?{...i,...function(e){let t={};for(let r of Object.keys(e))void 0!==e[r]&&(t[r]=e[r]);return t}(n)}:i}buildNew(e,t,r){if("long-position"===e||"short-position"===e)return this.makePosition("long-position"===e?"long":"short",t,r);let i={id:crypto.randomUUID(),color:"trendline"===e?"#2196F3":"#f0b90b",createdTf:this.timeframe};if("horizontal"===e)return{...i,type:"horizontal",price:t.price};if("vertical"===e)return{...i,type:"vertical",price:t.price,time:t.time};let n={...i,price:t.price,time:t.time,price2:r.price,time2:r.time};return"ray"===e?{...n,type:"trendline",extendRight:!0}:"extended"===e?{...n,type:"trendline",extendLeft:!0,extendRight:!0}:"measure"===e?{...n,type:"trendline",color:"#b2b5be",lineStyle:"dashed"}:"channel"===e?{...n,type:"channel",time3:t.time,price3:2*t.price-r.price}:"text"===e?{...n,type:"text",text:"Text"}:{...n,type:e}}makePosition(e,t,r){let i=t.price,n=r.price;return{id:crypto.randomUUID(),type:"position",side:e,color:"long"===e?"#089981":"#f23645",createdTf:this.timeframe,price:i,time:Math.min(t.time,r.time),time2:Math.max(t.time,r.time),targetPrice
1:n,stopPrice:i-(n-i),riskPct:1}}startLongPress(e,t){this.clearLongPress();let r=window.setTimeout(()=>{var t,r;this.longPress=null,this.drag=null,this.applyCursor(null),null===(t=(r=this.cb).onRequestSettings)||void 0===t||t.call(r,e)},500);this.longPress={timer:r,id:e,startPos:t}}cancelLongPressIfMoved(e){this.longPress&&(!e||dist(e,this.longPress.startPos)>10)&&this.clearLongPress()}clearLongPress(){this.longPress&&(window.clearTimeout(this.longPress.timer),this.longPress=null)}handleHistoryShortcut(e){var t,r,i,n,o,l;return(!!e.ctrlKey||!!e.metaKey)&&("KeyZ"===e.code?(e.preventDefault(),e.shiftKey?null===(t=(r=this.cb).onRedo)||void 0===t||t.call(r):null===(i=(n=this.cb).onUndo)||void 0===i||i.call(n),!0):"KeyY"===e.code&&(e.preventDefault(),null===(o=(l=this.cb).onRedo)||void 0===o||o.call(l),!0))}handleToolShortcut(e){var t,r;if(!e.altKey||e.ctrlKey||e.metaKey)return!1;let i=w[e.code];return!!i&&(e.preventDefault(),null===(t=(r=this.cb).onSelectTool)||void 0===t||t.call(r,i),!0)}handleClipboardShortcut(e){return(!!e.ctrlKey||!!e.metaKey)&&("KeyC"===e.code?(this.copySelected(),!0):"KeyV"===e.code?(e.preventDefault(),this.pasteClipboard(),!0):"KeyD"===e.code&&(e.preventDefault(),this.copySelected(),this.pasteClipboard(),!0))}handleArrowNudge(e){let t={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[e.key];if(!t||0===this.selectedIds.length)return!1;e.preventDefault();let r=e.shiftKey?10:1;return this.nudgeSelected(t[0]*r,t[1]*r),!0}copySelected(){this.clipboard=this.drawings.filter(e=>this.selectedIds.includes(e.id)).map(e=>({...e}))}pasteClipboard(){if(0===this.clipboard.length)return;let e=3*this.intervalSec,t=this.clipboard.map(t=>this.offsetCopy(t,e));for(let e of(this.drawings=[...this.drawings,...t],this.primitive.setDrawings(this.drawings),t))this.cb.onAdd({...e});this.select(t.map(e=>e.id))}offsetCopy(e,t){return{...e,id:crypto.randomUUID(),time:null!=e.time?e.time+t:void 0,time2:null!=e.time2?e.time2+t:void 0,time3:null!=e.time3?e.time3+t:void 0}}nudgeSelected(e,t){let r=this.resolveAll(),i=[];for(let n of this.selectedIds){let o=this.drawings.find(e=>e.id===n),l=r.find(e=>e.d.id===n);if(!o||!l||o.locked)continue;let a=this.shiftDrawing(o,l,e,t);a&&i.push(a)}if(0===i.length)return;let n=new Map(i.map(e=>[e.id,e]));for(let e of(this.drawings=this.drawings.map(e=>{var t;return null!==(t=n.get(e.id))&&void 0!==t?t:e}),this.primitive.setDrawings(this.drawings),i))this.cb.onUpdate({...e})}handleEscape(){if(this.clearMeasure(),"none"!==this.tool){this.tool="none",this.cancelPlacement(),this.applyCursor(null),this.cb.onToolFinished();return}this.select([])}placementStart(e,t){let r=this.pointFor(e,t.shiftKey,this.placementAnchorPx());if(r){if(t.preventDefault(),t.stopPropagation(),"horizontal"===this.tool||"vertical"===this.tool||"text"===this.tool){this.commitDrawing(this.makeNew(this.tool,r,r));return}if(this.placing){this.commitPlacement(this.placing.p1,r);return}this.placing={p1:r,startX:e.x,startY:e.y},this.primitive.setPreview(this.makeNew(this.tool,r,r))}}commitPlacement(e,t){if("measure"===this.tool){this.finishMeasure(e,t);return}this.commitDrawing(this.makeNew(this.tool,e,t))}finishMeasure(e,t){this.placing=null,this.measureResult={id:"measure",type:"trendline",color:"#b2b5be",lineStyle:"dashed",price:e.price,time:e.time,price2:t.price,time2:t.time},this.primitive.setPreview(this.measureResult),this.tool="none",this.applyCursor(null),this.cb.onToolFinished()}clearMeasure(){this.measureResult&&(this.measureResult=null,this.primitive.setPreview(null))}placingMove(e,t){let r=this.pointFor(e,t,this.placementAnchorPx());r&&this.placing&&this.primitive.setPreview(this.makeNew(this.tool,this.placing.p1,r))}maybeCommitPlacement(e,t){let r=this.placing;if(!e||10>dist(e,{x:r.startX,y:r.startY}))return;let i=this.pointFor(e,t,this.placementAnchorPx());i&&this.commitPlacement(r.p1,i)}commitDrawing(e){this.placing=null,this.primitive.setPreview(null),this.drawings=[...this.drawings,e],this.primitive.setDrawings(this.drawings),this.cb.onAdd({...e}),this.stayInMode&&"none"!==this.tool||(this.select([e.id]),this.tool="none",this.applyCursor(null),this.cb.onToolFinis
1hed())}cancelPlacement(){this.placing=null,this.primitive.setPreview(null)}selectionStart(e,t,r){let i=this.resolveAll(),n=hitTest(i,e,r?2:1);return n?((t.preventDefault(),t.stopPropagation(),t.shiftKey)?this.toggleSelection(n.id):(this.selectedIds.includes(n.id)||this.select([n.id]),this.beginDrag(n,e,i,r)),n):(t.shiftKey||this.select([]),null)}toggleSelection(e){let t=this.selectedIds.includes(e)?this.selectedIds.filter(t=>t!==e):[...this.selectedIds,e];this.select(t)}beginDrag(e,t,r,i){let n=this.drawings.find(t=>t.id===e.id),o=r.find(t=>t.d.id===e.id);if(!n||!o||n.locked)return;let l="body"===e.region.kind?this.groupFor(e.id,r):[];this.drag={hit:e,startX:t.x,startY:t.y,origin:{...n},originEntry:o,group:l,moved:!1,isTouch:i},this.applyCursor("grabbing")}groupFor(e,t){if(this.selectedIds.length<2||!this.selectedIds.includes(e))return[];let r=[];for(let i of this.selectedIds){if(i===e)continue;let n=this.drawings.find(e=>e.id===i),o=t.find(e=>e.d.id===i);n&&o&&!n.locked&&r.push({origin:{...n},entry:o})}return r}dragMove(e,t){let r=this.drag,i=this.computeDragUpdates(r,e,t);if(0===i.length)return;r.moved=!0;let n=new Map(i.map(e=>[e.id,e]));this.drawings=this.drawings.map(e=>{var t;return null!==(t=n.get(e.id))&&void 0!==t?t:e}),this.primitive.setDrawings(this.drawings)}computeDragUpdates(e,t,r){if("body"!==e.hit.region.kind){let i=this.dragPoint(e,t,r);return i?[i]:[]}let i=t.x-e.startX,n=t.y-e.startY,o=[],l=this.shiftDrawing(e.origin,e.originEntry,i,n);if(!l)return[];for(let t of(o.push(l),e.group)){let e=this.shiftDrawing(t.origin,t.entry,i,n);e&&o.push(e)}return o}dragPoint(e,t,r){if("point"!==e.hit.region.kind)return null;let i=this.pointFor(t,r,this.dragAnchorPx(e));if(!i)return null;let n={...e.origin},{timeKey:o,priceKey:l}=e.hit.region;return o&&(n[o]=i.time),l&&(n[l]=i.price),n}shiftDrawing(e,t,r,i){if("horizontal"===e.type){if(null===t.y1)return null;let r=this.series.coordinateToPrice(t.y1+i);return null===r?null:{...e,price:r}}if("vertical"===e.type){let i=this.shiftPoint(t.x1,t.y1,r,0);return i?{...e,time:i.time}:null}if("position"===e.type)return this.shiftPosition(e,t,r,i);if("channel"===e.type)return this.shiftChannel(e,t,r,i);let n=this.shiftPoint(t.x1,t.y1,r,i),o=this.shiftPoint(t.x2,t.y2,r,i);return n&&o?{...e,time:n.time,price:n.price,time2:o.time,price2:o.price}:null}shiftChannel(e,t,r,i){var n;let o=this.shiftPoint(t.x1,t.y1,r,i),l=this.shiftPoint(t.x2,t.y2,r,i),a=this.shiftPoint(t.x1,null!==(n=t.y3)&&void 0!==n?n:t.y1,r,i);return o&&l&&a?{...e,time:o.time,price:o.price,time2:l.time,price2:l.price,time3:a.time,price3:a.price}:null}shiftPosition(e,t,r,i){var n,o,l;let a=this.shiftPoint(t.x1,t.y1,r,i);if(!a)return null;let s=a.price-e.price,d=a.time-(null!==(n=e.time)&&void 0!==n?n:a.time);return{...e,time:(null!==(o=e.time)&&void 0!==o?o:0)+d,time2:(null!==(l=e.time2)&&void 0!==l?l:0)+d,price:a.price,stopPrice:null!=e.stopPrice?e.stopPrice+s:void 0,targetPrice:null!=e.targetPrice?e.targetPrice+s:void 0}}shiftPoint(e,t,r,i){return null===e||null===t?null:this.toPoint({x:e+r,y:t+i})}endDrag(){let e=this.drag;if(this.drag=null,this.applyCursor(null),!e.moved)return;let t=[e.hit.id,...e.group.map(e=>e.origin.id)];for(let e of t){let t=this.drawings.find(t=>t.id===e);t&&this.cb.onUpdate({...t})}}pointFor(e,t,r){let i=this.snapToNearbyAnchor(e);if(i)return i;if(t&&r)return this.toPoint(function(e,t){let r=t.x-e.x,i=t.y-e.y,n=Math.hypot(r,i);if(n<1)return t;let o=Math.PI/4,l=Math.round(Math.atan2(i,r)/o)*o;return{x:e.x+n*Math.cos(l),y:e.y+n*Math.sin(l)}}(r,e));let n=this.toPoint(e);return n&&"none"!==this.magnetMode?this.magnetSnap(n,e.y):n}snapToNearbyAnchor(e){for(let t of this.resolveAll())if(!this.selectedIds.includes(t.d.id)){for(let r of this.anchorPoints(t))if(8>=dist(e,{x:r.x,y:r.y}))return{time:r.time,price:r.price}}return null}anchorPoints(e){let t=e.d,r=[];return null!=e.x1&&null!=e.y1&&null!=t.time&&r.push({x:e.x1,y:e.y1,time:t.time,price:t.price}),null!=e.x2&&null!=e.y2&&null!=t.time2&&null!=t.price2&&r.push({x:e.x2,y:e.y2,time:t.time2,price:t.price2}),null!=e.x3&&null!=e.y3&&null!=t.time3&&null!=t.price3&&r.push({x:e.x3,y:e.y3,time:t.time3,price:t.price3}),r}placementAnchorPx(){if(!this.placing||"trendline"!==this.tool)return null;let e=timeToX(this.ctx(),this.placing.p1.time),t=this.series.priceToCoordinate(this.placing.p1.price);return null!==e&&null!==t?{x:e,y:t}:null}dragAnchorPx(e){if("trendline"!==e.origin.type||"point"!==e.hit.region.kind)return null;let t=e.originEntry,r="time"===e.hit.region.timeKey,i=r?t.x2:t.x1,n=r?t.y2:t.y1;return null!==i&&null!==n?{x:i,y:n}:null}magnetSnap(e,t){let r=this.candleAt(e.time);if(!r)return e;let i=e.price,n="strong"===this.magnetMode?Number.POSITIVE_INFINITY:14;for(let e of[r.open,r.high,r.low,r.close]){let r=this.series.priceToCoordinate(e);if(null===r)continue;let o=Math.abs(r-t);o<n&&(n=o,i=e)}return{time:e.time,price:i}}candleAt(e){let t=this.series.data(),r=0,i=t.length-1;for(;r<=i;){let n=r+i>>1,o=t[n].time;
1if(o===e)return function(e){let t="number"==typeof e.open&&"number"==typeof e.high&&"number"==typeof e.low&&"number"==typeof e.close;return t?e:null}(t[n]);o<e?r=n+1:i=n-1}return null}removeSelected(){let e=this.selectedIds;for(let t of(this.select([]),this.drawings=this.drawings.filter(t=>!e.includes(t.id)),this.primitive.setDrawings(this.drawings),e))this.cb.onRemove(t)}select(e){var t,r;let i=e.length===this.selectedIds.length&&e.every((e,t)=>e===this.selectedIds[t]);i||(this.selectedIds=e,this.primitive.setSelected(e),null===(t=(r=this.cb).onSelectionChange)||void 0===t||t.call(r,[...e]))}hoverHit(e){var t;let r=null!==(t=null==e?void 0:e.id)&&void 0!==t?t:null;r!==this.hoveredId&&(this.hoveredId=r,this.primitive.setHovered(r)),this.applyCursor(e?"pointer":null)}applyCursor(e){if(e){this.container.style.cursor=e;return}this.container.style.cursor="none"!==this.tool?"crosshair":""}constructor(e){var t;this.tool="none",this.drawings=[],this.placing=null,this.drag=null,this.selectedIds=[],this.hoveredId=null,this.magnetMode="none",this.stayInMode=!1,this.longPress=null,this.measureResult=null,this.clipboard=[],this.styleDefaults={},this.handleMouseDown=e=>{if(0!==e.button)return;let t=this.eventPos(e);if(t){if(this.clearMeasure(),"none"!==this.tool){this.placementStart(t,e);return}this.selectionStart(t,e,!1)}},this.handleMouseMove=e=>{let t=this.eventPos(e);if(this.drag){t&&this.dragMove(t,e.shiftKey);return}if(!t){this.hoverHit(null);return}if(this.placing){this.placingMove(t,e.shiftKey);return}"none"===this.tool&&this.hoverHit(hitTest(this.resolveAll(),t))},this.handleMouseUp=e=>{if(this.drag){this.endDrag();return}this.placing&&this.maybeCommitPlacement(this.eventPos(e),e.shiftKey)},this.handleDblClick=e=>{var t,r;if("none"!==this.tool)return;let i=this.eventPos(e);if(!i)return;let n=hitTest(this.resolveAll(),i);n&&(e.preventDefault(),e.stopPropagation(),this.select([n.id]),null===(t=(r=this.cb).onRequestSettings)||void 0===t||t.call(r,n.id))},this.handleContextMenu=e=>{var t,r;let i=this.eventPos(e);if(!i)return;let n=hitTest(this.resolveAll(),i);n&&(e.preventDefault(),e.stopPropagation(),this.selectedIds.includes(n.id)||this.select([n.id]),null===(t=(r=this.cb).onContextMenu)||void 0===t||t.call(r,n.id,e.clientX,e.clientY))},this.handleTouchStart=e=>{if(1!==e.touches.length)return;let t=e.touches[0],r=this.posFromClient(t.clientX,t.clientY);if(!r)return;if("none"!==this.tool){this.placementStart(r,evtFromTouch(e));return}let i=this.selectionStart(r,evtFromTouch(e),!0);i&&this.startLongPress(i.id,r)},this.handleTouchMove=e=>{if(1!==e.touches.length)return;let t=e.touches[0],r=this.posFromClient(t.clientX,t.clientY);if(this.cancelLongPressIfMoved(r),this.drag){e.preventDefault(),r&&this.dragMove(r,!1);return}this.placing&&r&&this.placingMove(r,!1)},this.handleTouchEnd=e=>{if(this.clearLongPress(),this.drag){this.endDrag();return}if(!this.placing)return;let t=e.changedTouches[0];this.maybeCommitPlacement(t?this.posFromClient(t.clientX,t.clientY):null,!1)},this.handleKeyDown=e=>{var t;if(!((t=e.target)instanceof HTMLElement&&(t.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(t.tagName))||this.handleHistoryShortcut(e)||this.handleToolShortcut(e))&&!(this.handleClipboardShortcut(e)||this.handleArrowNudge(e))){if("Escape"===e.key){this.handleEscape();return}("Delete"===e.key||"Backspace"===e.key)&&this.selectedIds.length>0&&!this.drag&&(e.preventDefault(),this.removeSelected())}},this.chart=e.chart,this.series=e.series,this.container=e.container,this.cb=e.callbacks,this.intervalSec=e.intervalSec,this.timeframe=e.timeframe,this.primitive=new DrawingsPrimitive,this.primitive.setIntervalSec(e.intervalSec),this.primitive.setAccountEquity(null!==(t=e.accountEquity)&&void 0!==t?t:0),this.series.attachPrimitive(this.primitive),this.container.addEventListener("mousedown",this.handleMouseDown,!0),this.container.addEventListener("dblclick",this.handleDblClick),this.container.addEventListener("contextmenu",this.handleContextMenu),this.container.addEventListener("touchstart",this.handleTouchStart,{capture:!0,passive:!1}),window.addEventListener("mousemove",this.handleMouseMove),window.addEventListener("mouseup",this.handleMouseUp),window.addEventListener("touchmove",this.handleTouchMove,{passive:!1}),window.addEventListener("touchend",this.handleTouchEnd),window.addEventListener("touchcancel",this.handleTouchEnd),window.addEventListener("keydown",this.handleKeyDown)}};let S=[{id:"lines",label:"Lines",tools:[{tool:"trendline",label:"Trend Line"},{tool:"ray",label:"Ray"},{tool:"extended",label:"Extended"},{tool:"horizontal",label:"Horizontal"},{tool:"vertical",label:"Vertical"},{tool:"channel",label:"Channel"}]},{id:"fib",label:"Fib",tools:[{tool:"fibonacci",label:"Fib Retracement"},{tool:"fibextension",label:"Fib Extension"}]},{id:"shapes",label:"Shapes",tools:[{tool:"rectangle",label:"Rectangle"},{tool:"ellipse",label:"Ellipse"},{tool:"triangle",label:"Triangle"},{tool:"arrow",label:"Arrow"}
1]},{id:"trade",label:"Trade",tools:[{tool:"long-position",label:"Long"},{tool:"short-position",label:"Short"},{tool:"measure",label:"Measure"}]},{id:"text",label:"Text",tools:[{tool:"text",label:"Text"}]},{id:"ai",label:"AI",tools:[{tool:"ai-analyse",label:"AI Analyse"}]}],k={width:"100%",height:"34px",borderRadius:"6px",border:"none",background:"transparent",color:"rgba(255,255,255,0.6)",fontSize:"10px",fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",whiteSpace:"nowrap",padding:"0 4px",boxSizing:"border-box"};function DrawingToolRail(e){let{drawingTool:t,onDrawingTool:r}=e,[o,l]=(0,n.useState)(null),[a,s]=(0,n.useState)(!1),[d,c]=(0,n.useState)({x:12,y:128}),[u,p]=(0,n.useState)(null),h=(0,n.useRef)(null);(0,n.useEffect)(()=>{c(e=>({...e,y:window.innerWidth<768?208:128}))},[]),(0,n.useEffect)(()=>{if(!o)return;let close=e=>{h.current&&!h.current.contains(e.target)&&l(null)};return document.addEventListener("mousedown",close),()=>document.removeEventListener("mousedown",close)},[o]),(0,n.useEffect)(()=>{if(!u)return;let onMove=e=>{c({x:e.clientX-u.offsetX,y:e.clientY-u.offsetY})},onUp=()=>p(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[u]);let select=e=>{r(t===e?"none":e),l(null)};return a?(0,i.jsx)("button",{type:"button",title:"Show drawing tools",onClick:()=>s(!1),style:{position:"absolute",left:d.x,top:d.y,zIndex:20,width:"28px",height:"28px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(7, 11, 24, 0.9)",color:"rgba(255,255,255,0.7)",fontSize:"13px",cursor:"pointer",touchAction:"none"},children:"✎"}):(0,i.jsxs)("div",{ref:h,style:{position:"absolute",left:d.x,top:d.y,zIndex:20,display:"flex",flexDirection:"column",alignItems:"center",gap:"3px",minWidth:"70px",touchAction:"none",padding:"4px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxSizing:"border-box"},children:[(0,i.jsx)("div",{title:"Drag to move",onPointerDown:e=>{p({offsetX:e.clientX-d.x,offsetY:e.clientY-d.y})},style:{...k,cursor:"move",color:"rgba(255,255,255,0.35)",fontSize:"14px"},children:"☰"}),(0,i.jsx)("button",{type:"button",title:"Cursor",onClick:()=>{r("none"),l(null)},style:{...k,background:"none"===t?"rgba(59,130,246,0.25)":"transparent",color:"none"===t?"#93c5fd":"rgba(255,255,255,0.6)"},children:"⌖"}),(0,i.jsx)("button",{type:"button",title:"Measure (drag: bars + Δprice + %)",onClick:()=>{r("measure"===t?"none":"measure"),l(null)},style:{...k,background:"measure"===t?"rgba(59,130,246,0.25)":"transparent",color:"measure"===t?"#93c5fd":"rgba(255,255,255,0.6)"},children:"⇄"}),S.map(e=>{let r=e.tools.find(e=>e.tool===t),n=o===e.id;return(0,i.jsxs)("div",{style:{position:"relative"},children:[(0,i.jsx)("button",{type:"button",title:e.label,onClick:()=>l(t=>t===e.id?null:e.id),style:{...k,background:r?"rgba(59,130,246,0.25)":"transparent",color:r?"#93c5fd":"rgba(255,255,255,0.6)"},children:e.label}),n&&(0,i.jsx)("div",{style:{position:"absolute",left:"100%",top:0,marginLeft:"6px",minWidth:"140px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.96)",border:"1px solid rgba(255,255,255,0.12)",boxShadow:"0 10px 30px rgba(0,0,0,0.5)",overflow:"hidden"},children:e.tools.map(e=>(0,i.jsx)("button",{type:"button",onClick:()=>select(e.tool),style:{width:"100%",border:"none",background:t===e.tool?"rgba(59,130,246,0.2)":"transparent",color:t===e.tool?"#93c5fd":"rgba(255,255,255,0.85)",padding:"8px 12px",textAlign:"left",fontSize:"12px",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(255,255,255,0.08)"},onMouseLeave:r=>{r.currentTarget.style.background=t===e.tool?"rgba(59,130,246,0.2)":"transparent"},children:e.label},e.tool))})]},e.id)}),(0,i.jsx)("div",{style:{width:"100%",height:"1px",background:"rgba(255,255,255,0.08)",margin:"2px 0"}}),(0,i.jsx)("button",{type:"button",title:"Hide toolbar",onClick:()=>{l(null),s(!0)},style:{...k,fontSize:"10px"},children:"✕"})]})}var j=r(67027),C=r(49063),_=r(75782);let M={amplitude:["#22d3ee","#34445f","#fbbf24"],phase:["#fbbf24","#34d399","#22d3ee","#c084fc","#fbbf24"],rainbow:["#6d28d9","#2563eb","#22d3ee","#22c55e","#facc15","#f97316","#ef4444"],infrared:["#08051b","#40106b","#a51c70","#ed4b35","#ffad32","#fff4bd"],"red-venus":["#210612","#60102a","#ae2440","#e65249","#ff9973","#ffe0b5"]};function fourierPhase(e,t,r){let i=Math.acos(Math.min(1,Math.max(-1,e)));return(null!=r?r:e)>(null!=t?t:e)?2*Math.PI-i:i}let P=[16,32,64];let ReplayTrackCurve=class ReplayTrackCurve extends j.Hyl{getPoint(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new j.Pa4,r=j.M8C.clamp(e,0,1),i=r*(this.prices.length-1),n=Math.floor(i),o=i-n,l=j.M8C.lerp(this.prices[n],this.prices[Math.min(n+1,this.prices.length-1)],o*o*(3-2*o)),a=r*this.width;return t.set(a,(l-this.mid)*this.scale,5*Math.sin(.028*a)+1.5*Math.sin(.061*a)+this.offset)}getPointAt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new j.Pa4;return this.getPoint(e,t)}getTangentAt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new j.Pa4;return this.getTangent(e,t)}constructor(e,t,r,i,n=0){super(),this.prices=e,this.mid=t,this.scale=r,this.width=i,this.offset=n}};function alignAnchoredVwap(e,t){let align=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=new Map(t.map(e=>[e.time,e.value]));return e.map(e=>{let t=r.get(Math.floor(e[0]/1e3));return void 0!==t&&Number.isFinite(t)?t:null})};return{mean:align(null==t?void 0:t.vwapData),upper:align(null==t?void 0:t.upperData),lower:
1align(null==t?void 0:t.lowerData)}}function buildAnchoredVwapChannel(e,t,r,i,n){let o=[],quad=(e,t,r,i)=>o.push(...e,...t,...r,...e,...r,...i);for(let o=0;o<e.length-1;o++){let l=e[o],a=e[o+1],s=t[o],d=t[o+1];if([l,a,s,d].some(e=>null==e||!Number.isFinite(e)))continue;let c=o*n,u=(o+1)*n,p=(l-r)*i,h=(a-r)*i,g=(s-r)*i,x=(d-r)*i;quad([c,p,-.7],[u,h,-.7],[u,h,.7],[c,p,.7]),quad([c,g,-.7],[u,x,-.7],[u,x,.7],[c,g,.7]),quad([c,p,-.7],[u,h,-.7],[u,x,-.7],[c,g,-.7])}return o}function isAnchorClick(e,t,r){return!!e&&!e.moved&&4>=Math.hypot(t-e.x,r-e.y)}function CandleReplay3D(e){var t;let{ohlc:r,anchoredVwapData:o,anchoredVwapPicking:l=!1,getAnchoredVwapPreview:a,onAnchoredVwapCommit:s,onAnchoredVwapCancel:d,anchoredVwapColor:c="#f59e0b",anchoredVwapBandOpacity:u=.45,cameraMode:p="orbit",progress:h,isPlaying:g=!1,isExporting:x=!1,cinematicEnd:b=null,closeTime:f,side:m="long",onUnavailable:y,entry:v,playbackPrice:w,currentIndex:S=0,height:k="100%",canvasRef:T,showEmaChannel:R=!0,emaFast:z=7,emaSlow:I=34,emaChannelOpacity:E=.4,showBollinger:D=!1,bollingerPeriod:L=20,bollingerMult:A=2,bollingerOpacity:F=.25,bollingerScheme:N="emerald",showSmaCrowd:B=!0,smaCount:W=9,smaMode:O="sma",rainbowDensity:V=50,showFourierOscillator:U=!1,fourierWindowSize:H=64,fourierTimeframes:q=P,fourierHistory:Y,fourierColorMode:K="amplitude",fourierMeshOpacity:X=.85,fourierWireframe:G=!0,fourierFocusRequest:J=0}=e,Q=(0,n.useRef)(null),[$,Z]=(0,n.useState)(!1),ee="orbit"!==p,[et,er]=(0,n.useState)(null),ei=(0,n.useRef)({active:!1,getAnchoredVwapPreview:a,onAnchoredVwapCommit:s,onAnchoredVwapCancel:d});ei.current={active:l&&!ee,getAnchoredVwapPreview:a,onAnchoredVwapCommit:s,onAnchoredVwapCancel:d};let en=(0,n.useRef)(()=>{});(0,n.useEffect)(()=>{var e;en.current();let t=null===(e=Q.current)||void 0===e?void 0:e.querySelector("canvas");t&&(t.style.cursor=l&&!ee?"crosshair":ee?"default":"grab")},[l,ee,r]);
1let[eo,el]=(0,n.useState)(!0),[ea,es]=(0,n.useState)(null),ed=(0,n.useRef)(eo);ed.current=eo;let ec=(0,n.useRef)({progress:0,previous:0,updatedAt:0,isPlaying:g,isExporting:x,cinematicEnd:b,cameraMode:p}),eu=(0,n.useRef)(y);eu.current=y,(0,n.useEffect)(()=>{let e=j.M8C.clamp(null!=h?h:S/Math.max(1,r.length-1),0,1),t=ec.current.progress;ec.current={progress:e,previous:e<t||!g?e:t,updatedAt:performance.now(),isPlaying:g,isExporting:x,cinematicEnd:b,cameraMode:p}},[h,S,r.length,g,x,b,p]);let ep=(0,n.useMemo)(()=>r.map(e=>({time:e[0],open:e[1],high:e[2],low:e[3],close:e[4]})),[r]),eh=(0,n.useMemo)(()=>alignAnchoredVwap(r,o),[r,o]),eg=(0,n.useMemo)(()=>{if(!U)return[];let e=Y?Y.map(e=>({time:e[0],close:e[4]})):ep;return function(e,t,r){let i=Math.min(e.length,Math.max(0,r)),n=e.length-i;return Array.from(new Set(t.filter(Number.isFinite).map(e=>Math.min(256,Math.max(8,Math.round(e)))))).sort((e,t)=>e-t).map(t=>{let r=calculateFourierOscillator(e,t);return{window:t,values:r.slice(n).map((e,r)=>r+n>=t-1&&Number.isFinite(e.value)?e.value:null)}})}(e,q,ep.length)},[ep,Y,q,U]),ex=eg.some(e=>e.values.some(e=>null!==e)),{minP:eb,maxP:ef,midP:em,rangeP:ey,yScale:ev,xStep:ew,totalWidth:eS}=(0,n.useMemo)(()=>{let e=[...eh.mean,...eh.upper,...eh.lower].filter(e=>null!==e),t=ep.length?Math.min(...ep.map(e=>e.low),...e):0,r=ep.length?Math.max(...ep.map(e=>e.high),...e):1,i=Math.max(r-t,1e-4*Math.abs(r),Number.EPSILON),n=ee?Math.max(1,240/Math.max(1,ep.length-1)):1,o=Math.max(1,ep.length-1)*n;return{minP:t,maxP:r,midP:(t+r)/2,rangeP:i,yScale:18/i,xStep:n,totalWidth:o}},[ep,ee,eh]),ek=(0,n.useRef)(0),ej=(0,n.useRef)(0),eC=(0,n.useRef)({offset:new j.Pa4,pan:new j.Pa4,initialized:!1,isDragging:!1,fourier:!1}),e_=(0,n.useRef)(()=>{}
1),eM=(0,n.useRef)(null),[eP,eT]=(0,n.useState)(1),eR=(0,n.useRef)(1),ez=(0,n.useRef)(null),applyYZoom=e=>{let t=Math.min(4,Math.max(.25,e));eR.current=t,eT(t)};return(0,n.useEffect)(()=>{J&&(ed.current=!0,el(!0),e_.current())},[J]),(0,n.useEffect)(()=>{let e=Math.min(Math.max(0,S),ep.length-1),t=ep[e],r=w||(null==t?void 0:t.close)||0,i=e*ew,n=(r-em)*ev;ek.current=i,ej.current=n},[S,w,ep,em,ev,ew]),(0,n.useEffect)(()=>{var e,t,i,n,l;let a,s;if(!Q.current||ep.length<2)return;let d=Q.current,p=Math.min(window.devicePixelRatio||1,1.75);Z(!1);let h=new j.xsS;h.background=new j.Ilk(461592),ee&&(h.fog=new j.yo9(461592,.009));let g=new j.cPb(ee?68:45,1,.08,Math.max(1e3,eS+400));try{a=new C.CP7({antialias:!0,alpha:!1,preserveDrawingBuffer:!0})}catch(e){Z(!0),null===(i=eu.current)||void 0===i||i.call(eu);return}a.setPixelRatio(p),a.toneMapping=j.LY2,a.toneMappingExposure=1.25;let x=d.querySelector("canvas");x&&x.remove(),d.appendChild(a.domElement),T&&(T.current=a.domElement);let b=a.domElement;b.style.cursor=ee?"default":ei.current.active?"crosshair":"grab",b.style.userSelect="none",b.style.touchAction=ee?"auto":"none",b.setAttribute("role","img"),b.setAttribute("aria-label",ee?"Cinematic rollercoaster following the position price history":"3D candlestick chart");let y=ee?null:new _.z(g,b);y&&(y.enableDamping=!0,y.dampingFactor=.12,y.rotateSpeed=.65,y.zoomSpeed=.8,y.screenSpacePanning=!0,y.minDistance=5,y.maxDistance=Math.max(160,2*eS),y.minPolarAngle=.1,y.maxPolarAngle=Math.PI-.1);let onOrbitStart=()=>{eC.current.isDragging=!0,es(null),b.style.cursor="grabbing"},onOrbitEnd=()=>{eC.current.isDragging=!1,b.style.cursor=ei.current.active?"crosshair":"grab"};null==y||y.addEventListener("start",onOrbitStart),null==y||y.addEventListener("end",onOrbitEnd);let resize=()=>{let e=Math.max(1,d.clientWidth),t=Math.max(1,"number"==typeof k?k:d.clientHeight);a.setSize(e,t),g.aspect=e/t,g.updateProjectionMatrix()};resize();let P=new j.vmT(16777215,461592,.6);h.add(P);let U=new j.Ox3(16777215,.7);U.position.set(20,40,30),h.add(U);let q=new j.Ox3(5972406,.4);q.position.set(-20,10,-20),h.add(q);let Y=new Float32Array(9e3),J=new Float32Array(9e3),$=new j.Ilk,et=new j.Pa4(eS/2,0,0);for(let e=0;e<3e3;e++){let t=60+180*Math.random(),r=Math.random()*Math.PI*2,i=Math.acos(2*Math.random()-1),n=et.x+t*Math.sin(i)*Math.cos(r),o=et.y+t*Math.sin(i)*Math.sin(r),l=et.z+t*Math.cos(i);Y[3*e]=n,Y[3*e+1]=o,Y[3*e+2]=l;let a=Math.random(),s=.2+.4*Math.random();$.setHSL(a,s,.7+.3*Math.random()),J[3*e]=$.r,J[3*e+1]=$.g,J[3*e+2]=$.b}let eo=new j.u9r;eo.setAttribute("position",new j.TlE(Y,3)),eo.setAttribute("color",new j.TlE(J,3));let el=new j.UY4({size:.15,vertexColors:!0,transparent:!0,opacity:.9,sizeAttenuation:!0}),ea=new j.woe(eo,el);h.add(ea);let ey=new j.ZAu;h.add(ey);let eP={},eT=[],ez=[],computeSMA=e=>{let t=[];for(let r=0;r<ep.length;r++){if(r<e-1){t.push(null);continue}let i=ep.slice(r-e+1,r+1).reduce((e,t)=>e+t.close,0);t.push(i/e)}return t},computeEMA=e=>{let t=[],r=2/(e+1),i=null;for(let n=0;n<ep.length;n++){if(n<e-1){t.push(null);continue}if(null===i){let t=ep.slice(n-e+1,n+1).reduce((e,t)=>e+t.close,0);i=t/e}else i=(ep[n].close-i)*r+i;t.push(i)}return t},addLine=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=[];for(let t=0;t<e.length;t++){let r=e[t];null!=r&&n.push(new j.Pa4(t*ew,(r-em)*ev,.15))}if(n.length<2)return;let o=new j.u9r().setFromPoints(n),l={color:t,transparent:r<1,opacity:r},a=i?new j.FT0({...l,dashSize:.5,gapSize:.3}):new j.nls(l),s=new j.x12(o,a);i&&s.computeLineDistances(),ey.add(s),ez.push(s)};if(o){let e=new j.Ilk(c).getHex(),t=j.M8C.clamp(u,0,1),r=buildAnchoredVwapChannel(eh.upper,eh.lower,em,ev,ew);if(r.length){let i=new j.u9r;i.setAttribute("position",new j.a$l(r,3));let n=new j.vBJ({color:e,side:j.ehD,transparent:!0,opacity:.6*t,depthWrite:!1}),o=new j.Kj0(i,n);ey.add(o),ez.push(o)}addLine(eh.mean,e),addLine(eh.upper,e,t,!0),addLine(eh.lower,e,t,!0)}let eI=new j.Ilk;if(R){let e=computeEMA(z),t=computeEMA(I),r=[],i=[];for(let n=0;n<ep.length-1;n++){let o=e[n],l=t[n],a=e[n+1],s=t[n+1];if(null==o||null==l||null==a||null==s)continue;let d=o>=l;eI.setHex(d?2278750:15680580);let c=n*ew,u=(n+1)*ew,p=(o-em)*ev,h=(l-em)*ev,g=(a-em)*ev,x=(s-em)*ev;r.push(c,p,.12,u,g,.12,u,x,.12),i.push(eI.r,eI.g,eI.b,eI.r,eI.g,eI.b,eI.r,eI.g,eI.b),r.push(c,p,.12,u,x,.12,c,h,.12),i.push(eI.r,eI.g,eI.b,eI.r,eI.g,eI.b,eI.r,eI.g,eI.b)}if(r.length>=9){let e=new j.u9r;e.setAttribute("position",new j.TlE(new Float32Array(r),3)),e.setAttribute("color",new j.TlE(new Float32Array(i),3));let t=new j.vBJ({vertexColors:!0,side:j.ehD,transparent:!0,opacity:.6*E,depthWrite:!1}),n=new j.Kj0(e,t);ey.add(n),ez.push(n)}addLine(e,16436245,E),addLine(t,3900150,E)}if(D&&ep.length>L){let e={emerald:{upper:2278750,lower:947344,basis:8843180},ocean:{upper:3718648,lower:2450411,basis:8246268},sunset:{upper:16486972,lower:14362487,basis:16628340},violet:{upper:10980346,lower:7153881,basis:12891645}},t=e[N]||e.emerald,r=new j.Ilk(t.upper),i=new j.Ilk(t.lower),n=Array(ep.length).fill(null),o=Array(ep.length).fill(null),l=Array(ep.length).fill(null),a=0,s=0;for(let e=0;e<ep.length;e++){let t=ep[e].close;if(a+=t,s+=t*t,e>=L){let t=ep[e-L].close;a-=t,s-=t*t}if(e<L-1)continue;let r=a/L,i=Math.max(0,s/L-r*r),d=Math.sqrt(i);o[e]=r,n[e]=r+A*d,l[e]=r-A*d}let d=[],c=[];for(let e=0;e<ep.length-1;e++){let t=n[e],o=l[e],a=n[e+1],s=l[e+1];if(null==t||null==o||null==a||null==s)continue;let u=e*ew,p=(e+1)*ew,h=(t-em)*ev,g=(o-em)*ev,x=(a-em)*ev,b=(s-em)*ev;d.push(u,h,.11,p,x,.11,p,b,.11),c.push(r.r,r.g,r.b,r.r,r.g,r.b,i.r,i.g,i.b),d.push(u,h,.11,p,b,.11,u,g,.11),c.push(r.r,r.g,r.b,i.r,i.g,i.b,i.r,i.g,i.b)}if(d.length>=9){let e=new j.u9r;e.setAttribute("position",new j.TlE(new Float32Array(d),3)),e.setAttribute("color",new j.TlE(new Float32Array(c),3));let t=new j.vBJ({vertexColors:!0,side:j.ehD,transparent:!0,opacity:F,depthWrite:!1}),r=new j.Kj0(e,t);
1ey.add(r),ez.push(r)}addLine(n,t.upper,Math.min(1,F+.4)),addLine(l,t.lower,Math.min(1,F+.4)),addLine(o,t.basis,Math.min(1,F+.3),!0)}if(B&&W>0){let e=[3,5,8,13,21,34,55,89,144],t=[16711680,16744192,16776960,65280,255,4915330,9699539,16716947,65535],r=Math.min(W,e.length),i=V/100,n=.15+.25*i,o=[];for(let i=0;i<r;i++){let r="ema"===O?computeEMA(e[i]):computeSMA(e[i]);o.push(r),addLine(r,t[i%t.length],n)}let l=[],a=[];for(let e=0;e<r-1;e++){let r=o[e],i=o[e+1];eI.setHex(t[e%t.length]);for(let e=0;e<ep.length-1;e++){let t=r[e],n=i[e],o=r[e+1],s=i[e+1];if(null==t||null==n||null==o||null==s)continue;let d=e*ew,c=(e+1)*ew,u=(t-em)*ev,p=(n-em)*ev,h=(o-em)*ev,g=(s-em)*ev;l.push(d,u,.12,c,h,.12,c,g,.12),a.push(eI.r,eI.g,eI.b,eI.r,eI.g,eI.b,eI.r,eI.g,eI.b),l.push(d,u,.12,c,g,.12,d,p,.12),a.push(eI.r,eI.g,eI.b,eI.r,eI.g,eI.b,eI.r,eI.g,eI.b)}}if(l.length>=9){let e=new j.u9r;e.setAttribute("position",new j.TlE(new Float32Array(l),3)),e.setAttribute("color",new j.TlE(new Float32Array(a),3));let t=new j.vBJ({vertexColors:!0,side:j.ehD,transparent:!0,opacity:.05+.25*i,depthWrite:!1}),r=new j.Kj0(e,t);ey.add(r),ez.push(r)}}let eE=null!==(n=null===(e=eg[0])||void 0===e?void 0:e.window)&&void 0!==n?n:8,eD=null!==(l=null===(t=eg[eg.length-1])||void 0===t?void 0:t.window)&&void 0!==l?l:H,windowZ=e=>-3-(e-eE)/Math.max(1,eD-eE)*22,eL=[],eA=null,eF=new j.ZAu;ey.add(eF);let addLabel=function(e,t,r,i){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"#cbd5e1",o=document.createElement("canvas");o.width=384,o.height=64;let l=o.getContext("2d");if(!l)return;l.fillStyle="rgba(7,11,24,0.85)",l.fillRect(0,0,o.width,o.height),l.font="500 28px system-ui",l.textAlign="center",l.textBaseline="middle",l.fillStyle=n,l.fillText(e,o.width/2,o.height/2);let a=new j.ROQ(o);a.colorSpace=j.KI_,eL.push(a);let s=new j.jyi(new j.xeV({map:a,depthTest:!1,transparent:!0}));s.position.set(t,r,i),s.scale.set(9,1.5,1),eF.add(s),ez.push(s)};if(ex){let e=[],t=[],r=[],i=[],n=[],o=new j.Ilk("#22d3ee"),l=new j.Ilk("#34445f"),a=new j.Ilk("#fbbf24"),s=[a,new j.Ilk("#34d399"),o,new j.Ilk("#c084fc"),a],d=M[K].map(e=>new j.Ilk(e)),c=new j.Ilk,u=ep.length;eg.forEach(r=>{r.values.forEach((i,n)=>{if(e.push(n*ew,-15+(null!=i?i:0)*4.5,windowZ(r.window)),"phase"===K&&null!==i){var u,p;let e=fourierPhase(i,null!==(u=r.values[n-1])&&void 0!==u?u:null,null!==(p=r.values[n+1])&&void 0!==p?p:null),t=e/(Math.PI/2),o=Math.min(3,Math.floor(t));c.copy(s[o]).lerp(s[o+1],t-o)}else if("amplitude"===K||"phase"===K)c.copy(l).lerp((null!=i?i:0)>=0?a:o,Math.pow(Math.abs(null!=i?i:0),.65));else{let e=j.M8C.clamp(((null!=i?i:0)+1)/2,0,1)*(d.length-1),t=Math.min(d.length-2,Math.floor(e));c.copy(d[t]).lerp(d[t+1],e-t)}t.push(c.r,c.g,c.b)})});let vertex=t=>new j.Pa4().fromArray(e,3*t),segment=(t,r)=>i.push(...e.slice(3*t,3*t+3),...e.slice(3*r,3*r+3)),triangle=(t,i,o)=>{r.push(t,i,o);let l=[];for(let[r,n]of[[t,i],[i,o],[o,t]]){let t=e[3*r+1]- -15,i=e[3*n+1]- -15;(t<=0&&i>0||t>0&&i<=0)&&l.push(vertex(r).lerp(vertex(n),-t/(i-t)))}2===l.length&&n.push(...l[0].toArray(),...l[1].toArray())};for(let e=0;e<eg.length;e++)for(let t=0;t<u;t++){let r=e*u+t;null!==eg[e].values[t]&&(t+1<u&&null!==eg[e].values[t+1]&&segment(r,r+1),!(e+1>=eg.length)&&null!==eg[e+1].values[t]&&((t%4==0||t===u-1)&&segment(r,r+u),t+1<u&&null!==eg[e].values[t+1]&&null!==eg[e+1].values[t+1]&&(triangle(r,r+u,r+1),triangle(r+1,r+u,r+u+1))))}let p=new j.u9r;p.setAttribute("position",new j.a$l(e,3)),p.setAttribute("color",new j.a$l(t,3)),p.setIndex(r),p.computeVertexNormals();let h=new j.Wid({vertexColors:!0,side:j.ehD,transparent:X<1,opacity:X,roughness:.8,metalness:0,emissive:16777215,emissiveIntensity:.12,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});(eA=new j.Kj0(p,h)).name="fourier-window-surface",ey.add(eA),ez.push(eA);let addSegments=(e,t,r)=>{let i=new j.ejS(new j.u9r().setAttribute("position",new j.a$l(e,3)),new j.nls({color:t,transparent:!0,opacity:r}));ey.add(i),ez.push(i)};(G||1===eg.length)&&addSegments(i,12179942,1===eg.length?.85:.16),addSegments(n,16777215,.85);let g=[0,-15,-3,eS,-15,-3,eS,-15,-3,eS,-15,windowZ(eD),eS,-19.5,-3,eS,-10.5,-3];addSegments(g,6583435,.75);let x=Math.max(1,Math.ceil(eg.length/5));for(let e of(eg.forEach((e,t)=>{(t%x==0||t===eg.length-1)&&addLabel("".concat(e.window," bars"),eS+5,-15.4,windowZ(e.window))}),addLabel("Z \xb7 Window length",eS+5,-17,windowZ(eD)-2,"#a5b4fc"),addLabel("Y \xb7 Oscillator",eS+3,-8,-3),[-1,0,1]))addLabel(e>0?"+1 crest":e<0?"-1 trough":"0 crossing",eS+5,-15+4.5*e,0,e>0?"#fbbf24":e<0?"#22d3ee":"#cbd5e1");for(let e of[0,Math.floor((u-1)/2),u-1])addLabel(new Date(ep[e].time).toLocaleStr
1ing(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),e*ew,-22,-1);addLabel("X \xb7 Chart time",eS/2,-24,-1)}let eN=new j.iMs,eB=new j.FM8,eW=0,onFourierHover=e=>{var t,r;if(ei.current.active||!eA||eC.current.isDragging||performance.now()-eW<70)return;eW=performance.now();let i=b.getBoundingClientRect();eB.set((e.clientX-i.left)/i.width*2-1,-(e.clientY-i.top)/i.height*2+1),eN.setFromCamera(eB,g);let n=eN.intersectObject(eA)[0];if(!n){es(null);return}let o=ey.worldToLocal(n.point.clone()),l=Math.min(ep.length-1,Math.max(0,Math.round(o.x/ew))),a=eg.reduce((e,t)=>Math.abs(windowZ(t.window)-o.z)<Math.abs(windowZ(e.window)-o.z)?t:e),s=a.values[l];es(null===s?null:{window:a.window,value:s,time:ep[l].time,phase:fourierPhase(s,null!==(t=a.values[l-1])&&void 0!==t?t:null,null!==(r=a.values[l+1])&&void 0!==r?r:null)})},clearFourierHover=()=>es(null);b.addEventListener("pointermove",onFourierHover),b.addEventListener("pointerleave",clearFourierHover),es(null);let eO=[];ep.forEach((e,t)=>{let r=t*ew,i=e.close>=e.open,n=i?2278750:16281969;eP[n]||(eP[n]=new j.Wid({color:n,roughness:.35,metalness:.1,emissive:n,emissiveIntensity:.15}));let o=Math.max(.02,Math.abs(e.close-e.open)*ev),l=((e.open+e.close)/2-em)*ev,a=new j.Kj0(new j.DvJ(.55,o,.55),eP[n]);a.position.set(r,l,0),ey.add(a),eT.push(a);let s=Math.max(.02,(e.high-e.low)*ev),d=((e.high+e.low)/2-em)*ev,c=new j.Kj0(new j.DvJ(.05,s,.05),eP[n]);c.position.set(r,d,0),ey.add(c),eT.push(c),a.userData.anchorIndex=c.userData.anchorIndex=t,eO.push(a,c)});let eV=new j.ZAu;ey.add(eV);let eU=null,eH=null,clearPreview=()=>{eV.children.slice().forEach(e=>{e.geometry.dispose(),e.material.dispose(),eV.remove(e)}),eU=null,er(null)},cancelPointer=()=>{eH=null,clearPreview()};en.current=cancelPointer;let pickAnchor=e=>{let t=b.getBoundingClientRect();if(!t.width||!t.height||e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)return null;g.updateMatrixWorld(),ey.updateMatrixWorld(!0),eB.set((e.clientX-t.left)/t.width*2-1,-(e.clientY-t.top)/t.height*2+1),eN.setFromCamera(eB,g);let r=eN.intersectObjects(eO,!1)[0];if(r)return r.object.userData.anchorIndex;let i=eN.ray.clone().applyMatrix4(new j.yGw().copy(ey.matrixWorld).invert());return function(e,t,r,i,n){if(t<1||.05>Math.abs(e.direction.z))return null;let o=e.intersectPlane(new j.JOQ(new j.Pa4(0,0,1),0),new j.Pa4);return!o||o.x<-r/2||o.x>(t-.5)*r||o.y<i||o.y>n?null:Math.max(0,Math.min(t-1,Math.round(o.x/r)))}(i,ep.length,ew,(eb-em)*ev-2,(ef-em)*ev+2)},showPreview=e=>{let t=null===e?null:Math.floor(ep[e].time/1e3);if(t===eU||(clearPreview(),null===e||null===t||!ei.current.getAnchoredVwapPreview))return;let i=alignAnchoredVwap(r,ei.current.getAnchoredVwapPreview(t));eU=t,er(t);let n=new j.Ilk(c),o=buildAnchoredVwapChannel(i.upper,i.lower,em,ev,ew);o.length&&eV.add(new j.Kj0(new j.u9r().setAttribute("position",new j.a$l(o,3)),new j.vBJ({color:n,side:j.ehD,transparent:!0,opacity:.15,depthWrite:!1}))),[i.mean,i.upper,i.lower].forEach((e,t)=>{let r=e.flatMap((e,t)=>null===e?[]:[new j.Pa4(t*ew,(e-em)*ev,.3)]);if(r.length<2)return;let i=new j.x12(new j.u9r().setFromPoints(r),new j.FT0({color:n,transparent:!0,opacity:t?.25:.9,dashSize:.5,gapSize:.3,depthTest:!1}));i.computeLineDistances(),eV.add(i)});let l=ep[e],a=new j.x12(new j.u9r().setFromPoints([new j.Pa4(e*ew,(l.low-em)*ev-1,0),new j.Pa4(e*ew,(l.high-em)*ev+1,0)]),new j.nls({color:n,depthTest:!1}));a.renderOrder=10,eV.add(a)},onAnchorDown=e=>{if(ei.current.active){if(eH||!e.isPrimary||0!==e.button||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey){cancelPointer();return}eH={id:e.pointerId,x:e.clientX,y:e.clientY,moved:!1}}},onAnchorMove=e=>{if(ei.current.active){if(eH&&!isAnchorClick(eH,e.clientX,e.clientY)&&(eH.moved=!0),e.buttons||eC.current.isDragging){clearPreview();return}es(null),showPreview(pickAnchor(e))}},onAnchorUp=e=>{var t,r;let i=ei.current.active&&(null==eH?void 0:eH.id)===e.pointerId&&0===e.button&&isAnchorClick(eH,e.clientX,e.clientY);if(eH=null,!i)return;let n=pickAnchor(e);if(null===n){clearPreview();return}let o=Math.floor(ep[n].time/1e3);clearPreview(),null===(t=(r=ei.current).onAnchoredVwapCommit)||void 0===t||t.call(r,o)},onAnchorKey=e=>{var t,r;"Escape"===e.key&&ei.current.active&&(cancelPointer(),null===(t=(r=ei.current).onAnchoredVwapCancel)||void 0===t||t.call(r))};b.addEventListener("pointerdown",onAnchorDown),b.addEventListener("pointermove",onAnchorMove),b.addEventListener("pointerup",onAnchorUp),b.addEventListener("pointerleave",cancelPointer),b.addEventListener("pointercancel",cancelPointer),b.addEventListener("wheel",cancelPointer),window.addEventListener("keydown",onAnchorKey);let eq=null;if("number"==typeof v){let e=(v-em)*ev;(eq=new j.Kj0(new j.DvJ(eS+2,.03,.08),new j.Wid({color:16777215,emissive:16777215,emissiveIntensity:.3}))).position.set(eS/2,e,.1),ey.add(eq),eT.push(eq)}let eY=new j.Kj0(new j.xo$(.28,12,12),new j.Wid({color:16777215,emissive:16777215,emissiveIntensity:.4}));ey.add(eY),eT.push(eY);let eK=new j.ZAu,eX=new j.ZAu,eG=new ReplayTrackCurve(ep.map(e=>e.close),em,ev,eS),eJ=new j.Pa4(0,1,0),eQ=new j.Pa4(1,0,0),e$=new j.Pa4,eZ=new j.Pa4,e0=new j.Pa4,e5=new j.Pa4,e1=new j.Pa4,e2=new j.Pa4,e4=new j.Ilk,e6=f?1e3*f:ep[ep.length-1].time,e8=1,e3=ep.findIndex(e=>e.time>=e6);if(0===e3)e8=0;else if(e3>0){let e=ep[e3-1],t=(e6-e.time)/Math.max(1,ep[e3].time-e.time);e8=(e3-1+t)/(ep.length-1)}let pnlColor=e=>(e-(null!=v?v:ep[0].close))*("short"===m?-1:1)>=0?3534269:16733820,e9=new j.Wid({color:1584195,metalness:.7,roughness:.25}),e7=new j.vBJ({color:6809849}),te=null,tt=null;if(ee){h.add(eK),ey.position.z=-9,eY.visible=!1,eq&&(eq.visible=!1);let e=Math.min(1800,Math.max(360,6*ep.length));for(let t of[-.85,.85]){let r=new ReplayTrackCurve(ep.map(e=>e.close),em,ev,eS,t),i=new j.WXh(r,e,.09,6,!1),n=new Float32Array(3*i.attributes.position.count);for(let t=0;t<=e;t++){let i=r.getPoint(t/e);e4.setHex(pnlColor(i.y/ev+em));for(let e=0;e<=6;e++)e4.toArray(n,(7*t+e)*3)}i.setAttribute("color",new j.TlE(n,3)),eK.add(new j.Kj0(i,new j.vBJ({vertexColors:!0})));let o=new j.Kj0(new j.WXh(r,e,.23,5,!1),new j.vBJ({color:3725805,transparent:!0,opacity:.08,blending:j.WMw,depthWrite:!1}));eK.add(o)}let t=Math.min(600,Math.ceil(eS/1.25)),r=new j.SPe(new j.DvJ(.13,.12,2.15),new j.Wid({color:5079968,metalness:.65,roughness:.4,emissive:1458788,emissiveIntensity:.4}),t+1),i=new j.Tme;
1for(let e=0;e<=t;e++){let n=e/t;eG.getPoint(n,i.position),i.position.y-=.12,i.quaternion.setFromUnitVectors(eQ,eG.getTangent(n,eZ)),i.updateMatrix(),r.setMatrixAt(e,i.matrix)}eK.add(r);let n=Math.min(100,Math.ceil(eS/8)),o=new j.SPe(new j.fHI(.09,.18,1,5),new j.Wid({color:1521744,metalness:.6,roughness:.7}),n+1);i.quaternion.identity();for(let e=0;e<=n;e++){eG.getPoint(e/n,e$);let t=e$.y+19;i.position.set(e$.x,-19+t/2,e$.z),i.scale.set(1,t,1),i.updateMatrix(),o.setMatrixAt(e,i.matrix)}eK.add(o);let l=new j.VLJ(eS+240,Math.min(160,Math.ceil(eS/4)),1458522,1058101);l.position.set(eS/2,-19,0),eK.add(l);let a=new j.Kj0(new j.xo$(17,32,24),new j.vBJ({color:3283813,fog:!1}));a.position.set(eS+100,40,-60),eK.add(a);let s=new j.Kj0(new j.XvJ(24,.16,6,100),new j.vBJ({color:10321151,transparent:!0,opacity:.65,fog:!1}));s.position.copy(a.position),s.rotation.set(1.1,.6,.2),eK.add(s);let addGate=(e,t)=>{let r=new j.ZAu,i=new j.Kj0(new j.XvJ(3.1,.07,6,64),new j.vBJ({color:t}));i.rotation.y=Math.PI/2,i.position.y=2.5,r.add(i);let n=new j.Kj0(new j.XvJ(3.3,.2,6,64),new j.vBJ({color:t,transparent:!0,opacity:.12,blending:j.WMw,depthWrite:!1}));return n.rotation.copy(i.rotation),n.position.copy(i.position),r.add(n),eG.getPoint(e,r.position),r.quaternion.setFromUnitVectors(eQ,eG.getTangent(e,eZ)),eK.add(r),r};addGate(0,6809849),e8<1&&(tt=addGate(e8,12886527));let d=function(e){let t=new j.ZAu;t.name="replay-finish-tunnel",e.getPoint(1,t.position),t.quaternion.setFromUnitVectors(new j.Pa4(1,0,0),e.getTangent(1));let r=new j.vBJ({color:16317180}),i=new j.vBJ({color:1054759}),n=new j.vBJ({color:6809849}),o=new j.DvJ(.65,1,1),l=new j.DvJ(.5,8,.5),a=new j.DvJ(.5,.5,13);for(let e of[0,3,6,9]){for(let r of[-6.5,6.5]){let i=new j.Kj0(l,n);i.position.set(e,3,r),t.add(i)}let r=new j.Kj0(a,n);r.position.set(e,7,0),t.add(r)}for(let e=0;e<2;e++)for(let n=0;n<14;n++){let l=new j.Kj0(o,(e+n)%2?i:r);l.position.set(0,7.5+e,n-6.5),t.add(l)}for(let e of[-6.5,6.5]){for(let n=0;n<8;n++){let l=new j.Kj0(o,n%2?i:r);l.position.set(0,n-.5,e),t.add(l)}let l=new j.Kj0(new j.DvJ(9,.25,.25),n);l.position.set(4.5,7,e),t.add(l)}return t}(eG);eK.add(d);let c=document.createElement("canvas");c.width=512,c.height=96;let u=c.getContext("2d");if(u){u.fillStyle="#101827",u.fillRect(0,0,512,96),u.fillStyle="#f8fafc",u.font="900 64px system-ui",u.textAlign="center",u.textBaseline="middle",u.fillText("FINISH",256,48);let e=new j.ROQ(c);e.colorSpace=j.KI_,eL.push(e);let t=new j.Kj0(new j._12(10,1.9),new j.vBJ({map:e,side:j.ehD}));t.rotation.y=-Math.PI/2,t.position.set(-.4,9.7,0),d.add(t)}let p=new j.Kj0(new j.DvJ(2.8,.45,1.55),e9);for(let e of(p.position.y=.45,eX.add(p),[-.77,.77])){let t=new j.Kj0(new j.DvJ(2.85,.08,.08),e7);t.position.set(0,.65,e),eX.add(t)}let g=new j.Kj0(new j.DvJ(.35,.9,1.15),e9);g.position.set(-.8,1.1,0),eX.add(g);let x=new j.Kj0(new j.DvJ(.12,.3,1.6),e7);x.position.set(1.35,.7,0),eX.add(x),eK.add(eX);let b=new j.cek(6809849,18,14,2);b.position.set(1.5,2,0),eX.add(b);let f=[];for(let e=0;e<80;e++){let t=2.399963*e,r=5+e%7*1.4,i=7.13*e%60-20,n=Math.cos(t)*r+4,o=Math.sin(t)*r;f.push(i,n,o,i+.6+e%4*.5,n,o)}te=new j.ejS(new j.u9r().setAttribute("position",new j.a$l(f,3)),new j.nls({color:9235199,transparent:!0,opacity:.22,blending:j.WMw,depthWrite:!1})),eK.add(te)}else e9.dispose(),e7.dispose();let tr=new ResizeObserver(resize);tr.observe(d);let ti=new j.Pa4,tn=new j.Pa4,to=new j.Pa4,tl=new j.Pa4,ta=new j.Pa4,getBaseTarget=()=>{let e=ex&&ed.current;return ti.set(e?Math.max(eS/2,ek.current-24):ek.current,(e?-15:ej.current)*eR.current,e?-14:0)},resetView=()=>{if(!y)return;let e=ex&&ed.current;y.enableDamping=!1,y.update(),g.up.set(0,1,0),y.target.copy(getBaseTarget()),g.position.setFromSphericalCoords(e?58:33,e?1:1.15,.65).add(y.target),y.update(),y.enableDamping=!0,tn.copy(ti),y.saveState()};e_.current=resetView;let ts=ex&&ed.current,animate=()=>{let e=ec.current,t=eR.current;if(ey.scale.y=t,eK.scale.y=t,ee){var r;let i=e.isPlaying&&!e.isExporting?Math.min(1,(performance.now()-e.updatedAt)/80):1,n=j.M8C.lerp(e.previous,e.progress,i);eG.getPoint(n,e$);let o=Math.min(1,n+5/eS);eG.getPoint(o,e0),tl.copy(e$),tl.y*=t,ta.copy(e0),ta.y*=t,eZ.copy(ta).sub(tl),.001>eZ.lengthSq()&&eG.getTangent(1,eZ),eZ.normalize();
1let l=.09*Math.sin(.028*e$.x)+.04*Math.sin(.061*e$.x);e2.copy(eJ).applyAxisAngle(eZ,-l),eX.position.copy(e$),eX.quaternion.setFromUnitVectors(eQ,eZ),eX.rotateX(-l),e7.color.setHex(pnlColor(e$.y/ev+em));let a=null!==(r=e.cinematicEnd)&&void 0!==r?r:0,s="chase"===e.cameraMode;(function(e,t,r){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:new j.Pa4,n=j.M8C.clamp(e,0,1),o=.15+n*n*(3-2*n)*(Math.PI-.3),l=(t?12:8)+15*r;return i.set(Math.cos(o)*l,(t?5:3.5)+9*r,Math.sin(o)*l+8*r)})(n,s,a,e1).applyQuaternion(eX.quaternion).add(tl),e5.copy(tl),e5.y+=1,g.position.copy(e1),g.up.copy(e2).lerp(eJ,a),g.lookAt(e5);let d=(s?58:68+8*Math.max(0,-eZ.y))-12*a;Math.abs(g.fov-d)>.01&&(g.fov=d,g.updateProjectionMatrix()),te&&(te.visible=(e.isPlaying||e.isExporting)&&n<1&&0===a,te.material.opacity=.22*Math.min(1,(1-n)/.2),te.position.set(e$.x-n*eS*2%8,e$.y,e$.z)),tt&&tt.scale.setScalar(1+.08*Math.max(0,1-30*Math.abs(n-e8)))}else if(y){let t=ex&&ed.current;ts!==t&&(resetView(),ts=t),to.copy(getBaseTarget()).sub(tn),y.target.add(to),g.position.add(to),tn.copy(ti),y.enabled=!e.isExporting,y.enableDamping=!e.isExporting,y.update(),eY.position.set(ek.current,ej.current,.4)}a.render(h,g),s=requestAnimationFrame(animate)},td=Math.min(Math.max(0,S),ep.length-1),tc=ep[td],tu=w||(null==tc?void 0:tc.close)||0;ek.current=td*ew,ej.current=(tu-em)*ev;let tp=eM.current;!ee&&y&&tp?(y.target.copy(tp.target),g.position.copy(tp.position),tn.copy(getBaseTarget()),y.update()):resetView();let onContextLost=e=>{var t;e.preventDefault(),cancelAnimationFrame(s),Z(!0),null===(t=eu.current)||void 0===t||t.call(eu)};return b.addEventListener("webglcontextlost",onContextLost),animate(),(
1)=>{cancelAnimationFrame(s),y&&(eM.current={position:g.position.clone(),target:y.target.clone()}),b.removeEventListener("webglcontextlost",onContextLost),null==y||y.removeEventListener("start",onOrbitStart),null==y||y.removeEventListener("end",onOrbitEnd),null==y||y.dispose(),e_.current=()=>{},cancelPointer(),en.current=()=>{},b.removeEventListener("pointerdown",onAnchorDown),b.removeEventListener("pointermove",onAnchorMove),b.removeEventListener("pointerup",onAnchorUp),b.removeEventListener("pointerleave",cancelPointer),b.removeEventListener("pointercancel",cancelPointer),b.removeEventListener("wheel",cancelPointer),window.removeEventListener("keydown",onAnchorKey),b.removeEventListener("pointermove",onFourierHover),b.removeEventListener("pointerleave",clearFourierHover),eL.forEach(e=>e.dispose()),tr.disconnect();let e=new Set,t=new Set;eK.traverse(r=>{if(r.geometry&&t.add(r.geometry),r.material){let t=Array.isArray(r.material)?r.material:[r.material];t.forEach(t=>e.add(t))}r instanceof j.SPe&&r.dispose()}),e.forEach(e=>e.dispose()),t.forEach(e=>e.dispose()),eT.forEach(e=>{var t;null===(t=e.geometry)||void 0===t||t.dispose()}),eo.dispose(),el.dispose(),Object.values(eP).forEach(e=>e.dispose()),ez.forEach(e=>{var t;e instanceof j.jyi||null===(t=e.geometry)||void 0===t||t.dispose(),e.material.dispose()}),eq&&eq.material.dispose(),eY.material.dispose(),a.domElement.remove(),a.dispose(),T&&(T.current=null)}},[ep,k,v,em,ev,ew,eS,T,R,z,I,E,D,L,A,F,N,B,W,O,V,U,H,q,ee,f,m,eg,ex,K,X,G,eh,o,c,u]),(0,i.jsxs)("div",{ref:Q,style:{width:"100%",height:k,position:"relative",borderRadius:"12px",overflow:"hidden"},children:[$&&(0,i.jsx)("div",{role:"status",style:{position:"absolute",inset:0,zIndex:60,display:"grid",placeItems:"center",padding:24,background:"#070b18",color:"#cbd5e1",textAlign:"center"},children:"3D rendering is unavailable. Switch to the 2D chart to continue the replay."}),U&&!ee&&!$&&(0,i.jsxs)("div",{style:{position:"absolute",left:12,bottom:12,zIndex:50,width:"min(350px, calc(100% - 24px))",boxSizing:"border-box",padding:"10px 12px",borderRadius:10,background:"rgba(7,11,24,0.9)",border:"1px solid #334155",backdropFilter:"blur(6px)",color:"#cbd5e1",fontSize:10},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:10,marginBottom:7},children:[(0,i.jsx)("strong",{style:{letterSpacing:"0.1em",color:"#a5b4fc"},children:"FOURIER SURFACE"}),(0,i.jsx)("button",{type:"button","aria-pressed":eo,onClick:()=>{ed.current=!eo,el(e=>!e),e_.current()},style:{color:"#e2e8f0",border:"1px solid #475569",background:"#1e293b",borderRadius:5,fontSize:10,padding:"3px 7px",cursor:"pointer"},children:eo?"Follow price":"Focus mesh"})]}),(0,i.jsx)("div",{style:{height:6,borderRadius:3,background:"linear-gradient(90deg, ".concat(M[K].join(", "),")")}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",marginTop:4},children:"phase"===K?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{children:"Crest"}),(0,i.jsx)("span",{children:"Falling"}),(0,i.jsx)("span",{children:"Trough"}),(0,i.jsx)("span",{children:"Rising"}),(0,i.jsx)("span",{children:"Crest"})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{children:"-1 \xb7 Trough"}),(0,i.jsx)("span",{children:"0 \xb7 Crossing"}),(0,i.jsx)("span",{children:"+1 \xb7 Crest"})]})}),(0,i.jsxs)("div",{style:{marginTop:7,color:"#94a3b8",lineHeight:1.5},children:["X \xb7 Time \xa0 Y \xb7 Oscillator \xa0 Z \xb7 Window bars",(0,i.jsx)("br",{}),"White = zero crossing \xb7 Hover to inspect samples"]}),ex?eg.length<2?(0,i.jsx)("div",{style:{marginTop:6,color:"#fbbf24"},children:"One window: showing a slice. Increase Window Size for a surface."}):null:(0,i.jsx)("div",{style:{marginTop:6,color:"#fbbf24"},children:"No full-window oscillations yet. Load more candles or use a shorter window."}),ea&&(0,i.jsxs)("div",{style:{marginTop:7,borderTop:"1px solid #334155",paddingTop:7,fontVariantNumeric:"tabular-nums",color:"#f1f5f9"},children:[ea.window," bars \xb7 ",ea.value>=0?"+":"",ea.value.toFixed(3)," \xb7 phase ",(180*ea.phase/Math.PI).toFixed(0),"\xb0",(0,i.jsx)("br",{}),(0,i.jsx)("span",{style:{color:"#94a3b8"}
1,children:new Date(ea.time).toLocaleString()})]})]}),ee&&!$&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{style:{position:"absolute",inset:0,pointerEvents:"none",background:"radial-gradient(ellipse at 50% 45%, transparent 35%, rgba(3,7,18,0.6) 100%)",zIndex:2}}),(0,i.jsx)("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:48,zIndex:3,background:"linear-gradient(transparent, rgba(3,7,18,0.9))",pointerEvents:"none"}}),(0,i.jsxs)("div",{style:{position:"absolute",bottom:16,left:18,right:18,zIndex:4,display:"flex",justifyContent:"space-between",gap:12,color:"#94a3b8",fontSize:10,letterSpacing:"0.12em",pointerEvents:"none"},children:[(0,i.jsx)("span",{children:"ALTITUDE = PRICE \xb7 GREEN / RED = PNL"}),(0,i.jsxs)("span",{children:[f&&(null===(t=ep[Math.min(S,ep.length-1)])||void 0===t?void 0:t.time)>1e3*f?"POST-CLOSE":"ON TRACK"," \xb7 ",Math.round((null!=h?h:0)*100),"%"]})]})]}),(0,i.jsx)("div",{style:{position:"absolute",top:"10px",left:"10px",zIndex:50,padding:"5px 10px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.75)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.8)",fontSize:"11px",fontWeight:500,pointerEvents:"none",userSelect:"none",backdropFilter:"blur(4px)"},children:ee?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{style:{color:"#67e8f9",fontWeight:700,letterSpacing:"0.16em",fontSize:10},children:"POSITION ODYSSEY"}),(0,i.jsxs)("div",{style:{marginTop:5},children:["ride"===p?"Front seat":"Chase camera"," \xb7 ",g?"Riding":x?"Recording":"Ready to ride"]}),(0,i.jsx)("div",{style:{marginTop:4,color:"#94a3b8",fontSize:10},children:"Interpolated candles, not execution ticks"})]}):l?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{style:{color:"#fbbf24"},children:["Anchor VWAP \xb7 ",null===et?"Point at a candle to preview":new Date(1e3*et).toLocaleString()]}),(0,i.jsx)("div",{style:{marginTop:4},children:"Click to anchor \xb7 Drag to orbit \xb7 Wheel to zoom \xb7 Esc to cancel"})]}):"Drag to rotate \xb7 Right-click / Shift + drag to pan \xb7 Wheel to zoom"}),!$&&(0,i.jsxs)("div",{title:"Y scale — drag up/down or scroll \xb7 double-click to reset",onPointerDown:e=>{var t,r;e.stopPropagation(),null===(t=(r=e.target).setPointerCapture)||void 0===t||t.call(r,e.pointerId),ez.current={startY:e.clientY,startZoom:eR.current}},onPointerMove:e=>{let t=ez.current;t&&applyYZoom(t.startZoom*Math.exp((t.startY-e.clientY)*.006))},onPointerUp:()=>{ez.current=null},onPointerCancel:()=>{ez.current=null},onWheel:e=>{e.stopPropagation(),applyYZoom(eR.current*Math.exp(-(.0012*e.deltaY)))},onDoubleClick:()=>applyYZoom(1),style:{position:"absolute",right:12,top:64,zIndex:50,width:44,height:180,borderRadius:22,background:"rgba(7, 11, 24, 0.45)",border:"1px solid rgba(255,255,255,0.14)",backdropFilter:"blur(4px)",cursor:"ns-resize",touchAction:"none",userSelect:"none",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"space-between",padding:"10px 0",opacity:.55,transition:"opacity 0.15s"},onPointerEnter:e=>{e.currentTarget.style.opacity="0.9"},onPointerLeave:e=>{e.currentTarget.style.opacity="0.55"},children:[(0,i.jsx)("span",{style:{fontSize:12,color:"#93c5fd",pointerEvents:"none"},children:"+"}),(0,i.jsx)("div",{style:{position:"relative",flex:1,width:4,margin:"6px 0",borderRadius:2,background:"rgba(255,255,255,0.12)",pointerEvents:"none"},children:(0,i.jsx)("div",{style:{position:"absolute",left:"50%",transform:"translate(-50%, 50%)",bottom:"".concat((Math.log(eP)-Math.log(.25))/(Math.log(4)-Math.log(.25))*100,"%"),width:18,height:18,borderRadius:"50%",background:"rgba(96,165,250,0.85)",border:"2px solid rgba(255,255,255,0.7)",boxShadow:"0 0 8px rgba(96,165,250,0.6)"}})}),(0,i.jsx)("span",{style:{fontSize:12,color:"#93c5fd",pointerEvents:"none"},children:"−"}),(0,i.jsxs)("span",{style:{fontSize:9,color:"rgba(255,255,255,0.7)",fontVariantNumeric:"tabular-nums",pointerEvents:"none"},children:["\xd7",eP.toFixed(2)]})]})]})}async function fetchJson(e){let t=new AbortController,r=setTimeout(()=>t.abort(),8e3);try{let r=await fetch(e,{signal:t.signal});if(!r.ok)throw Error("HTTP ".concat(r.status));return await r.json()}finally{clearTimeout(r)}}let T=[{name:"CRYPTOCV",url:"https://cryptocurrency.cv/api/news?limit=30",parse:e=>((null==e?void 0:e.articles)||[]).map(e=>({title:String((null==e?void 0:e.title)||"").trim(),source:String((null==e?void 0:e.source)||"CRYPTOCV").toUpperCase().slice(0,24),url:String((null==e?void 0:e.link)||""),ts:Math.floor(new Date((null==e?void 0:e.pubDate)||0).getTime()/1e3)||0,summary:String((null==e?void 0:e.description)||"").replace(/\s+/g," ").trim().slice(0,500)||void 0})).filter(e=>e.title)},{name:"REDDIT",url:"https://www.reddit.com/r/CryptoCurrency+Forex+stocks/hot.json?limit=30&raw_json=1",parse:e=>{var t;return((null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.children)||[]).map(e=>{var t,r,i,n,o;return{title:String((null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.t
1itle)||"").trim(),source:"R/".concat(String((null==e?void 0:null===(r=e.data)||void 0===r?void 0:r.subreddit)||"").toUpperCase()),url:(null==e?void 0:null===(i=e.data)||void 0===i?void 0:i.url)||((null==e?void 0:null===(n=e.data)||void 0===n?void 0:n.permalink)?"https://www.reddit.com".concat(e.data.permalink):""),ts:Number((null==e?void 0:null===(o=e.data)||void 0===o?void 0:o.created_utc)||0)}}).filter(e=>e.title)}},{name:"HN",url:"https://hn.algolia.com/api/v1/search?query=crypto%20OR%20bitcoin%20OR%20forex&tags=story&hitsPerPage=30",parse:e=>((null==e?void 0:e.hits)||[]).map(e=>({title:String((null==e?void 0:e.title)||"").trim(),source:"HN",url:(null==e?void 0:e.url)||"https://news.ycombinator.com/item?id=".concat(null==e?void 0:e.objectID),ts:Math.floor(new Date((null==e?void 0:e.created_at)||0).getTime()/1e3)||0})).filter(e=>e.title)},{name:"COINTELEGRAPH",url:"https://api.rss2json.com/v1/api.json?rss_url=".concat(encodeURIComponent("https://cointelegraph.com/rss")),parse:e=>((null==e?void 0:e.items)||[]).slice(0,20).map(e=>({title:String((null==e?void 0:e.title)||"").trim(),source:"COINTELEGRAPH",url:String((null==e?void 0:e.link)||""),ts:Math.floor(new Date((null==e?void 0:e.pubDate)||0).getTime()/1e3)||0})).filter(e=>e.title)},{name:"FOREXLIVE",url:"https://api.rss2json.com/v1/api.json?rss_url=".concat(encodeURIComponent("https://www.forexlive.com/feed/news")),parse:e=>((null==e?void 0:e.items)||[]).slice(0,20).map(e=>({title:String((null==e?void 0:e.title)||"").trim(),source:"FOREXLIVE",url:String((null==e?void 0:e.link)||""),ts:Math.floor(new Date((null==e?void 0:e.pubDate)||0).getTime()/1e3)||0})).filter(e=>e.title)},{name:"FLASH",url:"/api/flash-news",parse:e=>((null==e?void 0:e.items)||[]).slice(0,30).map(e=>({title:String((null==e?void 0:e.title)||"").trim(),source:String((null==e?void 0:e.source)||"FLASH").toUpperCase().slice(0,24),url:String((null==e?void 0:e.url)||""),ts:Number((null==e?void 0:e.ts)||0),summary:(null==e?void 0:e.summary)?String(e.summary):void 0,impact:"number"==typeof(null==e?void 0:e.impact)?e.impact:void 0,whyItMatters:(null==e?void 0:e.whyItMatters)?String(e.whyItMatters):void 0,eventType:(null==e?void 0:e.eventType)?String(e.eventType):void 0,image:(null==e?void 0:e.image)?String(e.image):void 0})).filter(e=>e.title)}];async function fetchNewsHeadlines(e){let t=await Promise.allSettled(T.map(t=>{let r="FLASH"===t.name&&e?"".concat(t.url,"?q=").concat(encodeURIComponent(e)):t.url;return fetchJson(r).then(t.parse)})),r=[];return t.forEach((e,t)=>{"fulfilled"===e.status?(console.debug("[NewsFeed] ".concat(T[t].name,": ").concat(e.value.length," items")),r=r.concat(e.value)):console.warn("[NewsFeed] ".concat(T[t].name," failed:"),e.reason)}),r.sort((e,t)=>t.ts-e.ts),r}let R={BUY:"#4ade80",SELL:"#f87171",HOLD:"#94a3b8"},z={BTC:["bitcoin"],ETH:["ethereum","ether"],SOL:["solana"],INJ:["injective"],ATOM:["cosmos"],DOGE:["dogecoin"],XRP:["ripple"],ADA:["cardano"],AVAX:["avalanche"],MATIC:["polygon"],LINK:["chainlink"],DOT:["polkadot"],LTC:["litecoin"],BNB:["binance"],TRX:["tron"],NEAR:["near protocol"],ARB:["arbitrum"],OP:["optimism"],SUI:["sui network"],APT:["aptos"]};function timeAgo(e){if(!e)return"";let t=Math.max(0,Date.now()/1e3-e);return t<60?"".concat(Math.floor(t),"s"):t<3600?"".concat(Math.floor(t/60),"m"):t<86400?"".concat(Math.floor(t/3600),"h"):"".concat(Math.floor(t/86400),"d")}function NewsTicker(e){let{visible:t=!0,speed:r=60,symbol:o,pairOnly:a=!1,alarmEnabled:s=!1,alarmSensitivity:d="high",refreshMin:c=5}=e,[u,p]=(0,n.useState)([]),[h,g]=(0,n.useState)("idle"),[x,b]=(0,n.useState)(null),[f,m]=(0,n.useState)(null),[y,v]=(0,n.use
1State)(!1),[w,S]=(0,n.useState)(!1),[k,j]=(0,n.useState)({}),[C,_]=(0,n.useState)(null),[M,P]=(0,n.useState)({}),[T,I]=(0,n.useState)(null),[E,D]=(0,n.useState)(null),L=(0,n.useRef)(null),A=(0,n.useRef)(0),F=(0,n.useRef)(!1),N=(0,n.useRef)(null),B=(0,n.useRef)([]),W=(0,n.useRef)(!0),O=(0,n.useRef)(null),cancelHide=()=>{N.current&&(clearTimeout(N.current),N.current=null)},scheduleHide=()=>{cancelHide(),N.current=setTimeout(()=>{F.current=!1,b(null)},350)};(0,n.useEffect)(()=>{if(!t)return;let e=!1,r=a&&o?o:void 0,i=(null!=c?c:5)*6e4,load=async()=>{g("loading");let t=await fetchNewsHeadlines(r);e||(t.length?(p(t),g("ok:".concat(t.length))):g("empty"))};load();let n=setInterval(load,i);return()=>{e=!0,clearInterval(n)}},[t,a,o,c]),(0,n.useEffect)(()=>{if(!t)return;let e=0,i=performance.now(),step=t=>{let n=Math.min(100,t-i);i=t;let o=L.current;if(o&&!F.current){let e=o.scrollWidth/2;e>0&&(A.current=(A.current+r*n/1e3)%e,o.style.transform="translateX(".concat(-A.current,"px)"))}e=requestAnimationFrame(step)};return e=requestAnimationFrame(step),()=>cancelAnimationFrame(e)},[t,r,u.length]);let itemKey=e=>e.url||e.title,analyzeSentiment=async()=>{if(u.length&&!y){v(!0);try{let e=await fetch("/api/ollama-sentiment",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({symbol:o||"CRYPTO",headlines:u.slice(0,40).map(e=>({title:e.title,source:e.source,url:e.url,summary:e.summary}))})}),t=await e.json();e.ok&&t.signal?m({signal:t.signal,confidence:t.confidence,reasoning:t.reasoning}):console.warn("[NewsTicker] sentiment failed:",t)}catch(e){console.warn("[NewsTicker] sentiment error:",e)}finally{v(!1)}}},summarizeItem=async e=>{let t=itemKey(e);if(!M[t]&&T!==t){I(t);try{let r=await fetch("/api/ollama-summary",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:e.title,url:e.url,summary:e.summary})}),i=await r.json();r.ok&&i.summary?P(e=>({...e,[t]:i.summary})):console.warn("[NewsTicker] summary failed:",i)}catch(e){console.warn("[NewsTicker] summary error:",e)}finally{I(null)}}},analyzeItem=async e=>{let t=itemKey(e);if(!k[t]&&C!==t){_(t);try{let r=await fetch("/api/ollama-sentiment",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({symbol:o||"CRYPTO",headlines:[{title:e.title,source:e.source,url:e.url,summary:e.summary}]})}),i=await r.json();r.ok&&i.signal?j(e=>({...e,[t]:{signal:i.signal,confidence:i.confidence,reasoning:i.reasoning}})):console.warn("[NewsTicker] item sentiment failed:",i)}catch(e){console.warn("[NewsTicker] item sentiment error:",e)}finally{_(null)}}};(0,n.useEffect)(()=>{if(!s||!u.length){B.current=u;return}let e=new Set(B.current.map(e=>itemKey(e))),t=u.filter(t=>!e.has(itemKey(t)));if(B.current=u,W.current){W.current=!1;return}let r=t.find(e=>{var t;let r=null!==(t=e.impact)&&void 0!==t?t:0;return"high"===d?r>=1&&r<=2||r>=4&&r<=5:1===r||5===r});r&&(D(r),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>D(null),8e3))},[u,s,d]);let V=(0,n.useMemo)(()=>a&&o?u.filter(e=>(function(e,t){let r=(t||"").split(/[\/\-]/)[0].trim().toUpperCase();if(!r)return!0;let i="".concat(e.title," ").concat(e.summary||"").toLowerCase(),n=new RegExp("\\b".concat(r.toLowerCase(),"\\b"));return!!n.test(i)||(z[r]||[]).some(e=>i.includes(e))})(e,o)):u,[u,a,o]),U=(0,n.useMemo)(()=>[...V,...V],[V]);return t?u.length?(0,i.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:28,zIndex:40,pointerEvents:"auto"},onMouseEnter:()=>{cancelHide(),F.current=!0},onMouseLeave:scheduleHide,children:[(0,i.jsx)("style",{children:"@keyframes newsTickerFade { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }"}),(0,i.jsxs)("div",{style:{position:"relative",height:26,overflow:"hidden",background:"rgba(7, 11, 24, 0.88)",borderTop:"1px solid rgba(255,255,255,0.1)",fontFamily:'"Courier New", Courier, monospace',fontSize:12,lineHeight:"26px",color:"#a7f3d0",textShadow:"0 0 6px rgba(52, 211, 153, 0.35)"},children:[(0,i.jsxs)("div",{style:{position:"absolute",right:0,top:0,bottom:0,zIndex:45,display:"flex",alignItems:"center",gap:6,padding:"0 8px",background:"rgba(7, 11, 24, 0.95)",borderLeft:"1px solid rgba(255,255,255,0.1)"},children:[f&&(0,i.jsxs)("button",{onClick:()=>S(e=>!e),title:f.reasoning,style:{padding:"1px 8px",borderRadius:4,border:"1px solid ".concat(R[f.signal],"55"),background:"".concat(R[f.signal],"22"),color:R[f.signal],fontFamily:"inherit",fontSize:11,fontWeight:700,cursor:"pointer"},children:[f.signal," ",f.confidence,"%"]}),(0,i.jsx)("button",{onClick:analyzeSentiment,disabled:y,style:{padding:"1px 8px",borderRadius:4,border:"1px solid rgba(103, 232, 249, 0.4)",background:"rgba(103, 232, 249, 0.12)",color:"#67e8f9",fontFamily:"inherit",fontSize:11,fontWeight:700,cursor:y?"wait":"pointer"},children:y?"AI…":"AI"}),(0,i.jsxs)("a",{href:"https://x.com/flash_terminal",target:"_blank",rel:"noopener noreferrer",title:"powered by flash ai",style:{padding:"1px 7px",borderRadius:999,border:"1px solid rgba(251, 191, 36, 0.35)",background:"rgba(251, 191, 36, 0.08)",color:"#fbbf24",fontFamily:"inherit",fontSize:9,fontWeight:700,letterSpacing:.5,textDecoration:"none",whiteSpace:"nowrap",o
1pacity:.85,display:"inline-flex",alignItems:"center",gap:4},children:[(0,i.jsx)(l(),{src:"/flash_ai.svg",alt:"flash ai",width:12,height:12,unoptimized:!0,style:{display:"block"}}),"flash ai"]})]}),(0,i.jsxs)("div",{ref:L,style:{display:"inline-flex",whiteSpace:"nowrap",willChange:"transform"},children:[0===U.length&&(0,i.jsxs)("span",{style:{padding:"0 18px",color:"rgba(255,255,255,0.4)"},children:["no ",null==o?void 0:o.toUpperCase()," headlines right now — switch back to ALL"]}),U.map((e,t)=>(0,i.jsxs)("span",{onMouseEnter:()=>{cancelHide(),F.current=!0,b(t)},onClick:()=>e.url&&window.open(e.url,"_blank","noopener"),style:{padding:"0 18px",cursor:e.url?"pointer":"default",color:x===t?"#fef08a":void 0,borderRight:"1px solid rgba(255,255,255,0.08)"},children:[(0,i.jsxs)("span",{style:{color:"#67e8f9"},children:["[",e.source,"]"]})," ",e.impact?(0,i.jsx)("span",{style:{letterSpacing:1,fontSize:9},title:"impact ".concat(e.impact,"/5"),children:Array.from({length:5},(t,r)=>(0,i.jsx)("span",{style:{color:r<(e.impact||0)?"#fbbf24":"rgba(255,255,255,0.2)"},children:"●"},r))}):null," ",(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.45)"},children:timeAgo(e.ts)})," ",e.title.length>90?e.title.slice(0,90)+"…":e.title]},t))]})]}),w&&f&&(0,i.jsxs)("div",{style:{position:"absolute",bottom:28,right:8,maxWidth:"min(480px, 90%)",padding:"10px 14px",borderRadius:8,background:"rgba(7, 11, 24, 0.97)",border:"1px solid ".concat(R[f.signal],"55"),boxShadow:"0 8px 24px rgba(0,0,0,0.6)",color:"#e2e8f0",fontSize:12,lineHeight:1.5,whiteSpace:"normal",zIndex:50},children:[(0,i.jsxs)("div",{style:{color:R[f.signal],fontWeight:700,marginBottom:4},children:["AI SENTIMENT: ",f.signal," (",f.confidence,"%)"]}),(0,i.jsx)("div",{children:f.reasoning})]}),null!=x&&U[x]&&(0,i.jsxs)("div",{onMouseEnter:cancelHide,onMouseLeave:scheduleHide,style:{position:"absolute",bottom:30,left:"50%",transform:"translateX(-50%)",maxWidth:"min(560px, 90%)",padding:"10px 14px",borderRadius:8,background:"rgba(7, 11, 24, 0.97)",border:"1px solid rgba(103, 232, 249, 0.35)",boxShadow:"0 8px 24px rgba(0,0,0,0.6)",color:"#e2e8f0",fontSize:12,lineHeight:1.5,whiteSpace:"normal",zIndex:50,animation:"newsTickerFade 0.18s ease-out"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:10,marginBottom:4},children:[(0,i.jsxs)("span",{style:{color:"#67e8f9"},children:[U[x].source," \xb7 ",timeAgo(U[x].ts)," ago",U[x].impact?(0,i.jsx)("span",{style:{marginLeft:8,letterSpacing:2},title:"impact ".concat(U[x].impact,"/5"),children:Array.from({length:5},(e,t)=>(0,i.jsx)("span",{style:{color:t<(U[x].impact||0)?"#fbbf24":"rgba(255,255,255,0.2)"},children:"●"},t))}):null]}),(()=>{let e=U[x],t=itemKey(e),r=k[t],n=C===t;return(0,i.jsx)("button",{onClick:()=>analyzeItem(e),disabled:n||!!r,style:{padding:"2px 10px",borderRadius:4,border:"1px solid ".concat(r?R[r.signal]+"66":"rgba(103, 232, 249, 0.4)"),background:r?"".concat(R[r.signal],"22"):"rgba(103, 232, 249, 0.12)",color:r?R[r.signal]:"#67e8f9",fontFamily:"inherit",fontSize:11,fontWeight:700,cursor:n?"wait":r?"default":"pointer",whiteSpace:"nowrap"},children:n?"Analyzing…":r?"".concat(r.signal," ").concat(r.confidence,"%"):"AI Sentiment"})})()]}),(0,i.jsx)("div",{children:U[x].title}),(()=>{let e=U[x],t=itemKey(e),r=M[t],n=T===t,o=r||e.summary;return(0,i.jsxs)("div",{style:{marginTop:6},children:[o?(0,i.jsxs)("div",{style:{color:"rgba(255,255,255,0.6)",fontSize:11,lineHeight:1.55},children:[r?"":"(source excerpt) ",o]}):null,e.whyItMatters&&(0,i.jsxs)("div",{style:{marginTop:4,color:"#fbbf24",fontSize:11,lineHeight:1.5,opacity:.85},children:["Why it matters: ",e.whyItMatters]}),!r&&(0,i.jsx)("button",{onClick:()=>summarizeItem(e),disabled:n,style:{marginTop:4,padding:"2px 10px",borderRadius:4,border:"1px solid rgba(167, 139, 250, 0.4)",background:"rgba(167, 139, 250, 0.12)",color:"#c4b5fd",fontFamily:"inherit",fontSize:11,fontWeight:700,cursor:n?"wait":"pointer"},children:n?"Summarizing…":"Summarize Article"})]})})(),(()=>{let e=k[itemKey(U[x])];return e?(0,i.jsxs)("div",{style:{marginTop:6,color:R[e.signal],fontWeight:700},children:[e.signal," ",e.confidence,"% — ",(0,i.jsx)("span",{style:{color:"#e2e8f0",fontWeight:400},children:e.reasoning})]}):null})(),U[x].url&&(0,i.jsx)("div",{style:{marginTop:6,color:"rgba(255,255,255,0.4)",fontSize:10},children:"click headline to open source"})]}),E&&(0,i.jsxs)("div",{style:{position:"absolute",right:8,bottom:"100%",marginBottom:6,width:260,padding:10,borderRadius:8,background:"rgba(7, 11, 24, 0.96)",border:"1px solid rgba(239, 68, 68, 0.5)",boxShadow:"0 0 16px rgba(239, 68, 68, 0.3)",zIndex:50,fontFamily:"system-ui, sans-serif",fontSize:12},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[(0,i.jsxs)("span",{style:{color:"#f87171",fontWeight:700},children:["high"===d?"High":"Low"," Impact Alert"]}),(0,i.jsx)("button",{onClick:()=>D(null),style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:12},children:"✕"})]}),(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.9)",lineHeight:1.4},children:E.title}),E.url&&(0,i.jsx)("a",{href:E.url,target:"_blank",rel:"noopener noreferrer",style:{display:"block",marginTop:6,color:"#67e8f9",textDecoration:"none",fontSize:11},children:"Read source ↗"})]})]}):(0,i.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:28,zIndex:40,height:26,overflow:"hidden",background:"rgba(7, 11, 24, 0.88)",borderTop:"1px solid rgba(255,255,255,0.1)",fontFamily:'"Courier New", Courier, monospace',fontSize:12,lineHeight:"26px",color:"#fbbf24",padding:"0 12px"},children:["NEWS WIRE: ","loading"===h?"fetching headlines…":"empty"===h?"no headlines (all sources failed — see console)":h]}):null}function synthLevels(e){let t=Math.max(1e-4*e,1e-4),r=[];for(let i=20;i>=1;i--)r.push({price:e+t*i,bidSize:0,askSize:depthSize(i),type:"ask"});r.push({price:e+.5*t,bidSize:0,askSize:depthSize(0),type:"ask"}),r.push({price:e-.5*t,bidSize:depthSize(0),askSize:0,type:"bid"});for(let i=1;i<=20;i++)r.push({price:e-t*i,bidSize:depthSize(i),askSize:0,type:"bid"});return r}function depthSize(e){return Math.max(1,Math.round(120*Math.exp(-e/8)))}function DOMBox(e){let{symbol:t,price:r,onClose:o,onMapToChart:l}
1=e,[a,s]=(0,n.useState)({x:120,y:150}),[d,c]=(0,n.useState)(null),[u,p]=(0,n.useState)([]),[h,g]=(0,n.useState)(!1),x=(0,n.useRef)(null),b=(0,n.useRef)(null),f=(0,n.useRef)(0),m=(t||"").toUpperCase().replace(/[-/]?(USD|USDC|USDT|PERP)$/i,"").replace(/[^A-Z0-9]/g,"");(0,n.useEffect)(()=>{if(!m)return;let e=null,t=!1,r=0,i=null,n=null,levelsFrom=(e,t)=>{let r=[],i=[];for(let t of e||[]){let e=Number(t.px),i=Number(t.sz);e>0&&i>0&&r.push([e,i])}for(let e of t||[]){let t=Number(e.px),r=Number(e.sz);t>0&&r>0&&i.push([t,r])}r.sort((e,t)=>t[0]-e[0]),i.sort((e,t)=>e[0]-t[0]),b.current={bids:r,asks:i},f.current=Date.now(),g(!0);let n=[];for(let[e,t]of i.slice(0,20).reverse())n.push({price:e,bidSize:0,askSize:t,type:"ask"});for(let[e,t]of r.slice(0,20))n.push({price:e,bidSize:t,askSize:0,type:"bid"});p(n)},connect=()=>{t||((e=new WebSocket("wss://api.hyperliquid.xyz/ws")).onopen=()=>{r=0,null==e||e.send(JSON.stringify({method:"subscribe",subscription:{type:"l2Book",coin:m}})),n=setInterval(()=>{(null==e?void 0:e.readyState)===WebSocket.OPEN&&e.send(JSON.stringify({method:"ping"}))},2e4)},e.onmessage=e=>{try{var t,r,i;let n=JSON.parse(String(e.data));"l2Book"===n.channel&&(null===(t=n.data)||void 0===t?void 0:t.levels)&&levelsFrom(null!==(r=n.data.levels[0])&&void 0!==r?r:[],null!==(i=n.data.levels[1])&&void 0!==i?i:[])}catch(e){}},e.onclose=()=>{n&&clearInterval(n),n=null,t||(i=setTimeout(connect,r=Math.min(r+500,8e3)))},e.onerror=()=>null==e?void 0:e.close())};return connect(),()=>{t=!0,i&&clearTimeout(i),n&&clearInterval(n);try{null==e||e.close()}catch(e){}b.current=null,g(!1)}},[m]),(0,n.useEffect)(()=>{let e=setInterval(()=>{b.current&&Date.now()-f.current>5e3&&(b.current=null,g(!1)),!b.current&&r>0&&p(synthLevels(r))},1e3);return()=>clearInterval(e)},[r]);let y=h&&u.length?u:synthLevels(r),v=(0,n.useMemo)(()=>{let e=y.filter(e=>"ask"===e.type).sort((e,t)=>e.price-t.price),t=y.filter(e=>"bid"===e.type).sort((e,t)=>t.price-e.price),r=new Map,i=new Map,n=0,o=0;for(let t of e)n+=t.askSize,r.set(t.price,n);for(let e of t)o+=e.bidSize,i.set(e.price,o);return y.map(e=>({price:e.price,bidSize:"bid"===e.type&&i.get(e.price)||0,askSize:"ask"===e.type&&r.get(e.price)||0,type:e.type}))},[y]);(0,n.useEffect)(()=>{null==l||l(v)},[v,l]);let w=Math.max(...y.map(e=>
1Math.max(e.bidSize,e.askSize)),1);(0,n.useEffect)(()=>{window.innerWidth<560&&s({x:8,y:96})},[]),(0,n.useEffect)(()=>{if(!d)return;let onMove=e=>s({x:e.clientX-d.offsetX,y:e.clientY-d.offsetY}),onUp=()=>c(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[d]);let S=r>=100?2:5,formatPrice=e=>e.toLocaleString("en-US",{minimumFractionDigits:S,maximumFractionDigits:S}),formatSize=e=>e>=100?Math.round(e).toLocaleString("en-US"):e.toLocaleString("en-US",{maximumFractionDigits:4});return(0,i.jsxs)("div",{ref:x,style:{position:"absolute",left:a.x,top:a.y,zIndex:20,width:"min(240px, calc(100vw - 16px))",borderRadius:"10px",background:"rgba(7, 11, 24, 0.96)",border:"1px solid rgba(255,255,255,0.12)",boxShadow:"0 10px 30px rgba(0,0,0,0.5)",overflow:"hidden",fontSize:"12px",color:"rgba(255,255,255,0.85)",boxSizing:"border-box"},children:[(0,i.jsxs)("div",{onPointerDown:e=>c({offsetX:e.clientX-a.x,offsetY:e.clientY-a.y}),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 10px",borderBottom:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.04)",cursor:"move",touchAction:"none"},children:[(0,i.jsxs)("span",{style:{fontWeight:600},children:["Depth of Market — ",t,(0,i.jsx)("span",{style:{marginLeft:6,fontSize:9,fontWeight:500,color:h?"#4ade80":"rgba(255,255,255,0.4)"},children:h?"LIVE":"EST"})]}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[l&&(0,i.jsx)("button",{type:"button",onClick:()=>l(v),title:"Map orderbook into the chart",style:{padding:"3px 8px",borderRadius:"4px",border:"1px solid rgba(59, 130, 246, 0.4)",background:"rgba(59, 130, 246, 0.12)",color:"#93c5fd",fontSize:"10px",fontWeight:600,cursor:"pointer"},children:"Map to Chart"}),(0,i.jsx)("button",{type:"button",onClick:o,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:"14px",lineHeight:1},children:"✕"})]})]}),(0,i.jsx)("div",{style:{maxHeight:"min(520px, 62vh)",overflowY:"auto"},children:(0,i.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse"},children:[(0,i.jsx)("thead",{style:{position:"sticky",top:0,background:"rgba(7, 11, 24, 0.98)",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("tr",{children:[(0,i.jsx)("th",{style:{textAlign:"right",width:"32%",padding:"4px 6px"},children:"Bid Size"}),(0,i.jsx)("th",{style:{textAlign:"center",width:"36%",padding:"4px 6px"},children:"Price"}),(0,i.jsx)("th",{style:{textAlign:"left",width:"32%",padding:"4px 6px"},children:"Ask Size"})]})}),(0,i.jsx)("tbody",{children:y.map((e,t)=>(0,i.jsxs)("tr",{style:{position:"relative"},children:[(0,i.jsx)("td",{style:{textAlign:"right",padding:"3px 6px",position:"relative"},children:e.bidSize>0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{style:{position:"absolute",top:0,bottom:0,right:0,background:"rgba(34,197,94,0.18)",width:"".concat(e.bidSize/w*100,"%")}}),(0,i.jsx)("span",{style:{position:"relative",color:"#4ade80"},children:formatSize(e.bidSize)})]})}),(0,i.jsx)("td",{style:{textAlign:"center",padding:"3px 6px",fontFamily:"monospace",color:"ask"===e.type?"#f87171":"#4ade80"},children:formatPrice(e.price)}),(0,i.jsx)("td",{style:{textAlign:"left",padding:"3px 6px",position:"relative"},children:e.askSize>0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{style:{position:"absolute",top:0,bottom:0,left:0,background:"rgba(239,68,68,0.18)",width:"".concat(e.askSize/w*100,"%")}}),(0,i.jsx)("span",{style:{position:"relative",color:"#f87171"},children:formatSize(e.askSize)})]})})]},t))})]})})]})}function FluctuatingDigits(e){let{count:t=4,interval:r=80}
1=e,[o,l]=(0,n.useState)("");return(0,n.useEffect)(()=>{let tick=()=>{let e="";for(let r=0;r<t;r++)e+=Math.floor(10*Math.random());l(e)};tick();let e=window.setInterval(tick,r);return()=>window.clearInterval(e)},[t,r]),(0,i.jsx)("span",{style:{display:"inline-block",minWidth:"".concat(t,"ch")},children:o})}function RollingNumber(e){let{value:t,decimals:r=2,prefix:o="",suffix:l="",duration:a=400,fluctuate:s=!1,fluctuateCount:d=4,fluctuateInterval:c=80,style:u,className:p}=e,h=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,[r,i]=(0,n.useState)(()=>Number.isFinite(e)?e:0),o=(0,n.useRef)(null),l=(0,n.useRef)(r),a=(0,n.useRef)(r),s=(0,n.useRef)(r),d=(0,n.useRef)(0);return(0,n.useEffect)(()=>{l.current=r},[r]),(0,n.useEffect)(()=>{let r=Number.isFinite(e)?e:0;if(r===s.current)return;a.current=l.current,s.current=r,d.current=Date.now(),o.current&&cancelAnimationFrame(o.current);let tick=()=>{let e=Date.now()-d.current,r=Math.min(e/t,1),n=a.current+(s.current-a.current)*r;i(n),r<1&&(o.current=requestAnimationFrame(tick))};return o.current=requestAnimationFrame(tick),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(t,a),g=Number.isFinite(h)?h.toLocaleString("en-US",{minimumFractionDigits:r,maximumFractionDigits:r}):"—";return(0,i.jsxs)("span",{className:p,style:u,children:[o,g,s&&(0,i.jsx)(FluctuatingDigits,{count:d,interval:c}),l]})}var I=r(37843),E=r(14691),D=r(19539);function pineColorToRgba(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgba(0,0,0,0)";if(null==e||"na"===e||""===e)return t;if("string"!=typeof e)return String(e);let r=e.trim();if("#"===r[0]){if(7===r.length){let e=parseInt(r.slice(1,3),16),t=parseInt(r.slice(3,5),16),i=parseInt(r.slice(5,7),16);return"rgba(".concat(e,",").concat(t,",").concat(i,",1)")}if(9===r.length){let e=parseInt(r.slice(1,3),16),t=parseInt(r.slice(3,5),16),i=parseInt(r.slice(5,7),16),n=parseInt(r.slice(7,9),16)/255;return"rgba(".concat(e,",").concat(t,",").concat(i,",").concat(n.toFixed(3),")")}return r}return r.match(/rgba?\(([^)]+)\)/),r}function timeForIndex(e,t,r){if(!e||0===e.length)return null;let i=e.length-1;return r>=0&&r<=i?e[r].time:r<0?e[0].time+r*t:e[i].time+(r-i)*t}let PineLinePaneRenderer=class PineLinePaneRenderer{draw(){}drawBackground(e){let{lines:t}=this._data;t&&t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context,i=e.horizontalPixelRatio,n=e.verticalPixelRatio;for(let e of t)e&&null!=e.x1&&null!=e.y1&&null!=e.x2&&null!=e.y2&&(r.beginPath(),r.moveTo(e.x1*i,e.y1*n),r.lineTo(e.x2*i,e.y2*n),r.strokeStyle=pineColorToRgba(e.color,"#fff"),r.lineWidth=Math.max(1,(e.width||1)*i),"style_dashed"===e.style?r.setLineDash([6*i,4*i]):"style_dotted"===e.style?r.setLineDash([2*i,2*i]):r.setLineDash([]),r.stroke())})}constructor(e){this._data=e}};let PineLinePaneView=class PineLinePaneView{update(){let e=this._source.series,t=this._source.chart.timeScale(),r=this._source.candles,i=this._source.barSeconds;this._data.lines=(this._source._items||[]).map(n=>{let o=timeForIndex(r,i,n.x1),l=timeForIndex(r,i,n.x2),a=e.priceToCoordinate(n.y1),s=e.priceToCoordinate(n.y2),d=null==o?null:t.timeToCoordinate(o),c=null==l?null:t.timeToCoordinate(l);return null==d||null==a||null==c||null==s?null:{x1:d,y1:a,x2:c,y2:s,color:n.color,style:n.style,width:n.width}}).filter(Boolean)}renderer(){return new PineLinePaneRenderer(this._data)}constructor(e){this._source=e,this._data={lines:[]}}};let PineLinePrimitive=class PineLinePrimitive{attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._requestUpdate=i,this.updateAllViews(),this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return this._chart}get series(){return this._series}get candles(){return this._candles}get barSeconds(){return this._barSeconds}requestUpdate(){this._requestUpdate&&this._requestUpdate()}updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}constructor(e,t,r){this._items=e,this._candles=t,this._barSeconds=r,this._paneViews=[new PineLinePaneView(this)]}};let PinePolylinePaneRenderer=class PinePolylinePaneRenderer{draw(e){let{polys:t}=this._data;t&&t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context,i=e.horizontalPixelRatio,n=e.verticalPixelRatio;for(let e of t)if(e&&e.points&&!(e.points.length<2)&&e.line_color){r.beginPath(),r.moveTo(e.points[0].x*i,e.points[0].y*n);for(let t=1;t<e.points.length;t++){let o=e.points[t];r.lineTo(o.x*i,o.y*n)}e.closed&&r.closePath(),r.strokeStyle=e.line_color,r.lineWidth=Math.max(1,(e.line_width||1)*i),"style_dashed"===e.line_style?r.setLineDash([6*i,4*i]):"style_dotted"===e.line_style?r.setLineDash([2*i,2*i]):r.setLineDash([]),r.stroke()}r.setLineDash([])})}
1drawBackground(e){let{polys:t}=this._data;t&&t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context,i=e.horizontalPixelRatio,n=e.verticalPixelRatio;for(let e of t)if(e&&e.points&&!(e.points.length<2)&&e.fill_color){r.beginPath(),r.moveTo(e.points[0].x*i,e.points[0].y*n);for(let t=1;t<e.points.length;t++){let o=e.points[t];r.lineTo(o.x*i,o.y*n)}e.closed&&r.closePath(),r.fillStyle=e.fill_color,r.fill()}})}constructor(e){this._data=e}};let PinePolylinePaneView=class PinePolylinePaneView{update(){let e=this._source.series,t=this._source.chart.timeScale(),r=this._source.candles,i=this._source.barSeconds,n=r.length-1,o=n>=0?t.timeToCoordinate(r[n].time):null,l=1;if(n>=1){let e=t.timeToCoordinate(r[n-1].time),i=t.timeToCoordinate(r[n].time);null!=e&&null!=i&&(l=i-e)}this._data.polys=(this._source._items||[]).map(a=>{let s=(a.points||[]).map(a=>{if(null==a||null==a.price||null==a.index)return null;let s=timeForIndex(r,i,a.index),d=null==s?null:t.timeToCoordinate(s);null==d&&null!=o&&n>=0&&"number"==typeof a.index&&(d=o+(a.index-n)*l);let c=e.priceToCoordinate(a.price);return null==d||null==c?null:{x:d,y:c}}).filter(Boolean);return s.length<2?null:{points:s,closed:!!a.closed,fill_color:pineColorToRgba(a.fill_color,null),line_color:pineColorToRgba(a.line_color,null),line_width:a.line_width,line_style:a.line_style}}).filter(Boolean)}renderer(){return new PinePolylinePaneRenderer(this._data)}constructor(e){this._source=e,this._data={polys:[]}}};let PinePolylinePrimitive=class PinePolylinePrimitive{attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._requestUpdate=i,this.updateAllViews(),this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return this._chart}get series(){return this._series}get candles(){return this._candles}get barSeconds(){return this._barSeconds}requestUpdate(){this._requestUpdate&&this._requestUpdate()}updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}constructor(e,t,r){this._items=e,this._candles=t,this._barSeconds=r,this._paneViews=[new PinePolylinePaneView(this)]}};let L={tiny:8,small:10,normal:12,large:14,huge:18};let PineLabelPaneRenderer=class PineLabelPaneRenderer{draw(){}drawBackground(e){let{labels:t}=this._data;t&&t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context,i=e.horizontalPixelRatio,n=e.verticalPixelRatio;for(let e of t){if(!e||null==e.x||null==e.y||!e.text)continue;let t=Math.round((e.size||12)*n);r.font="".concat(t,"px monospace");let o=6*i,l=3*n,a=String(e.text).split("\n"),s=1.2*t,d=Math.max(...a.map(e=>r.measureText(e).width)),c=d+2*o,u=s*a.length+2*l,p=e.x*i-c/2,h=e.y*n-u/2;"style_none"!==e.style&&(r.fillStyle=pineColorToRgba(e.color,"#000"),r.beginPath(),r.roundRect?r.roundRect(p,h,c,u,4*i):r.rect(p,h,c,u),r.fill()),r.fillStyle=pineColorToRgba(e.textcolor,"#fff"),r.textBaseline="middle";let g=h+l+s/2;a.forEach((e,t)=>{r.fillText(e,p+o,g+t*s)})}})}constructor(e){this._data=e}};let PineLabelPaneView=class PineLabelPaneView{update(){let e=this._source.series,t=this._source.chart.timeScale(),r=this._source.candles,i=this._source.barSeconds,n=r.length-1,o=n>=0?t.timeToCoordinate(r[n].time):null,l=0;if(n>=1){let e=t.timeToCoordinate(r[n-1].time),i=t.timeToCoordinate(r[n].time);null!=e&&null!=i&&(l=i-e)}this._data.labels=(this._source._items||[]).map(a=>{let s=timeForIndex(r,i,a.x);if(null==s)return null;let d=t.timeToCoordinate(s);null==d&&null!=o&&n>=0&&"number"==typeof a.x&&(d=o+(a.x-n)*l);let c=e.priceToCoordinate(a.y);return null==d||null==c?null:(("be"===a.yloc||"belowbar"===a.yloc)&&(c+=14),("ab"===a.yloc||"abovebar"===a.yloc)&&(c-=14),{x:d,y:c,text:String(a.text||""),color:a.color,textcolor:a.textcolor,size:L[a.size]||L.normal,style:a.style})}).filter(Boolean)}renderer(){return new PineLabelPaneRenderer(this._data)}constructor(e){this._source=e,this._data={labels:[]}}};let PineLabelPrimitive=class PineLabelPrimitive{attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._requestUpdate=i,this.updateAllViews(),this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return this._chart}get series(){return this._series}get candles(){return this._candles}get barSeconds(){return this._barSeconds}requestUpdate(){this._requestUpdate&&this._requestUpdate()}
1updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}constructor(e,t,r){this._items=e,this._candles=t,this._barSeconds=r,this._paneViews=[new PineLabelPaneView(this)]}};let PineBackgroundPaneRenderer=class PineBackgroundPaneRenderer{draw(){}drawBackground(e){let{rects:t}=this._data;t&&t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context,i=e.horizontalPixelRatio,n=e.bitmapSize.height;for(let e of t)e&&null!=e.x1&&null!=e.x2&&e.color&&(r.fillStyle=e.color,r.fillRect(e.x1*i,0,(e.x2-e.x1)*i,n))})}constructor(e){this._data=e}};let PineBackgroundPaneView=class PineBackgroundPaneView{update(){let e=this._source.chart.timeScale(),t=this._source.candles,r=this._source.barSeconds;this._data.rects=(this._source._items||[]).map(i=>{let n=timeForIndex(t,r,i.index),o=timeForIndex(t,r,i.index+1);if(null==n||null==o)return null;let l=e.timeToCoordinate(n),a=e.timeToCoordinate(o);if(null==l||null==a)return null;let s=pineColorToRgba(i.color,null);return s?{x1:l,x2:a,color:s}:null}).filter(Boolean)}renderer(){return new PineBackgroundPaneRenderer(this._data)}constructor(e){this._source=e,this._data={rects:[]}}};let PineBackgroundPrimitive=class PineBackgroundPrimitive{attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._requestUpdate=i,this.updateAllViews(),this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return this._chart}get series(){return this._series}get candles(){return this._candles}get barSeconds(){return this._barSeconds}requestUpdate(){this._requestUpdate&&this._requestUpdate()}updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}constructor(e,t,r){this._items=e,this._candles=t,this._barSeconds=r,this._paneViews=[new PineBackgroundPaneView(this)]}};let A={tiny:"9px",small:"11px",normal:"13px",large:"15px",huge:"18px"},F={left:"left",center:"center",right:"right"},N={top:"top",center:"middle",bottom:"bottom"};function positionStyle(e){switch(e){case"top_left":return{top:10,left:10,transform:"translate(0,0)"};case"top_center":return{top:10,left:"50%",transform:"translateX(-50%)"};case"top_right":default:return{top:10,right:10,transform:"translate(0,0)"};case"middle_left":return{top:"50%",left:10,transform:"translateY(-50%)"};case"middle_center":return{top:"50%",left:"50%",transform:"translate(-50%, -50%)"};case"middle_right":return{top:"50%",right:10,transform:"translateY(-50%)"};case"bottom_left":return{bottom:10,left:10,transform:"translate(0,0)"};case"bottom_center":return{bottom:10,left:"50%",transform:"translateX(-50%)"};case"bottom_right":return{bottom:10,right:10,transform:"translate(0,0)"}}}function DraggableTable(e){let{table:t,idx:r}
1=e,[o,l]=(0,n.useState)(!1),[a,s]=(0,n.useState)(positionStyle(t.position));(0,n.useEffect)(()=>{o||s(positionStyle(t.position))},[t.position,o]);let[d,c]=(0,n.useState)({x:0,y:0});(0,n.useEffect)(()=>{(0!==d.x||0!==d.y)&&l(!0)},[d]);let[u,p]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!u)return;let onMove=e=>{c({x:u.ox+(e.clientX-u.startX),y:u.oy+(e.clientY-u.startY)})},onUp=()=>p(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[u]);let h=t.rows||0,g=t.columns||0;return 0===h||0===g?null:(0,i.jsx)("div",{style:{position:"absolute",zIndex:15,pointerEvents:"auto",...a,transform:"".concat(a.transform||""," translate(").concat(d.x,"px, ").concat(d.y,"px)")},children:(0,i.jsxs)("div",{style:{background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",borderRadius:"8px",backdropFilter:"blur(6px)",boxShadow:"0 10px 30px rgba(0,0,0,0.5)",padding:"4px",display:"flex",flexDirection:"column"},children:[(0,i.jsx)("div",{title:"Drag to move",onPointerDown:e=>{p({startX:e.clientX,startY:e.clientY,ox:d.x,oy:d.y})},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",cursor:"move",color:"rgba(255,255,255,0.35)",fontSize:"12px",padding:"2px 0",userSelect:"none"},children:"☰"}),(0,i.jsx)("table",{style:{borderCollapse:"collapse",backgroundColor:t.bgcolor||"transparent",color:"#fff",fontFamily:"monospace",fontSize:"11px"},children:(0,i.jsx)("tbody",{children:Array.from({length:h},(e,r)=>(0,i.jsx)("tr",{children:Array.from({length:g},(e,n)=>{var o,l;let a=null===(l=t.cells)||void 0===l?void 0:null===(o=l[r])||void 0===o?void 0:o[n];if(!a)return(0,i.jsx)("td",{style:{padding:"3px 8px"},children:"\xa0"},n);let s={padding:"3px 8px",textAlign:F[a.text_halign]||"left",verticalAlign:N[a.text_valign]||"middle",color:a.text_color||"rgba(255,255,255,0.85)",backgroundColor:a.bgcolor||"transparent",border:"".concat(t.border_width||0,"px solid ").concat(t.border_color||"transparent"),fontSize:A[a.text_size]||"11px",whiteSpace:"nowrap"};return(0,i.jsx)("td",{style:s,title:a.tooltip||"",children:a.text||""},n)})},r))})})]})})}function PineTableOverlay(e){let{tables:t}=e;return t&&t.length?(0,i.jsx)(i.Fragment,{children:t.map((e,t)=>{var r;return!e||e._deleted?null:(0,i.jsx)(DraggableTable,{table:e,idx:t},"pine-table-".concat(null!==(r=e.id)&&void 0!==r?r:t))})}):null}try{I.kL.register(I.uw,I.f$,I.ZL,I.vn,I.od,I.jn,I.Dx,I.u,I.De,I.Gu)}catch(e){}let toPrice=e=>{let t="number"==typeof e?e:Number(e);return Number.isFinite(t)?Math.abs(t)>1e9?t/1e12:t:0},getPnlColor=e=>{if(e>=0){let t=Math.min(Math.max(e/5,0),1);return"rgb(".concat(Math.round(255+-181*t),", ").concat(Math.round(255+-33*t),", ").concat(Math.round(255+-127*t),")")}if(e>-20)return"#ffffff";if(e<=-60)return"#ff0000";let t=Math.min(Math.max((e+20)/40,0),1);return"rgb(".concat(Math.round(250+-11*t),", ").concat(Math.round(204+-136*t),", ").concat(Math.round(21+47*t),")")};function OpenChartsPro_hexToRgba(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgba(255,255,255,1)";if("string"!=typeof e)return t;if(/^rgba?\(/i.test(e.trim()))return e;if(9===e.length){let t=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16),n=parseInt(e.slice(7,9),16)/255;return"rgba(".concat(t,",").concat(r,",").concat(i,",").concat(n,")")}return 7===e.length?e:t}function withAlpha(e,t){let r=Math.min(Math.max(t,0),1);if("string"!=typeof e)return"rgba(255,255,255,".concat(r,")");if("#"===e[0]&&(7===e.length||9===e.length)){let t=parseInt(e.slice(1,3),16),i=parseInt(e.slice(3,5),16),n=parseInt(e.slice(5,7),16),o=9===e.length?parseInt(e.slice(7,9),16)/255:1;return"rgba(".concat(t,",").concat(i,",").concat(n,",").concat(o*r,")")}let i=e.match(/rgba?\(([^)]+)\)/);if(i){let e=i[1].split(",").map(e=>parseFloat(e)),t=e.length>3?e[3]:1;return"rgba(".concat(e[0],",").concat(e[1],",").concat(e[2],",").concat(t*r,")")}return e}function getPriceScaleMargins(e,t,r){let i=r&&e>0?Math.min(.5,58/e):0;
1if(!t)return{rightPriceScale:{top:0,bottom:i,borderColor:"rgba(255,255,255,0.1)"},leftPriceScale:{visible:!1}};let n=Math.min(.95,.2+i);return{rightPriceScale:{top:0,bottom:n,borderColor:"rgba(255,255,255,0.1)"},leftPriceScale:{visible:!0,borderColor:"rgba(255,255,255,0.1)",scaleMargins:{top:Math.max(0,1-n),bottom:i}}}}function timeAtIndex(e,t,r){if(!e||0===e.length||!Number.isFinite(r))return null;let i=e.length-1;return r>=0&&r<=i?e[Math.round(r)].time:r<0?e[0].time+r*t:e[i].time+(r-i)*t}let PineZonePaneRenderer=class PineZonePaneRenderer{draw(){}drawBackground(e){let t=this._data.points;t&&!(t.length<2)&&e.useBitmapCoordinateSpace(e=>{let r=e.context;r.scale(e.horizontalPixelRatio,e.verticalPixelRatio);let i=new Path2D;for(let e of(i.moveTo(t[0].x,t[0].y1),t))i.lineTo(e.x,e.y1);for(let e=t.length-1;e>=0;e--)i.lineTo(t[e].x,t[e].y2);i.closePath(),r.fillStyle=this._data.color,r.fill(i)})}constructor(e){this._data=e}};let PineZonePaneView=class PineZonePaneView{update(){let e=this._source.series,t=this._source.chart.timeScale();this._data.color=this._source._color,this._data.points=this._source._points.map(r=>{var i,n,o;return{x:null!==(i=t.timeToCoordinate(r.time))&&void 0!==i?i:-100,y1:null!==(n=e.priceToCoordinate(r.v1))&&void 0!==n?n:-100,y2:null!==(o=e.priceToCoordinate(r.v2))&&void 0!==o?o:-100}}).filter(e=>e.x>-50)}renderer(){return new PineZonePaneRenderer(this._data)}constructor(e){this._source=e,this._data={points:[],color:e._color}}};let PineZonePrimitive=class PineZonePrimitive{attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._requestUpdate=i,this.updateAllViews(),this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return this._chart}get series(){return this._series}requestUpdate(){this._requestUpdate&&this._requestUpdate()}updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}constructor(e,t){this._points=e,this._color=t,this._paneViews=[new PineZonePaneView(this)]}};let LookbackHighlightPaneRenderer=class LookbackHighlightPaneRenderer{draw(){}drawBackground(e){let t=this._data.x;null!=t&&e.useBitmapCoordinateSpace(e=>{let r=e.context,i=e.horizontalPixelRatio,n=e.bitmapSize.width,o=e.bitmapSize.height,l=Math.min(n,Math.max(0,Math.round(t*i)));r.fillStyle="rgba(96, 165, 250, 0.10)",r.fillRect(l,0,n-l,o),r.fillStyle="rgba(96, 165, 250, 0.55)",r.fillRect(l,0,Math.max(1,Math.round(i)),o)})}constructor(e){this._data=e}};let LookbackHighlightPaneView=class LookbackHighlightPaneView{update(){var e;let t=null===(e=this._source.chart)||void 0===e?void 0:e.timeScale(),r=this._source._startTime;this._data.x=t&&null!=r?t.timeToCoordinate(r):null}renderer(){return new LookbackHighlightPaneRenderer(this._data)}constructor(e){this._source=e,this._data={x:null}}};let LookbackHighlightPrimitive=class LookbackHighlightPrimitive{attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._requestUpdate=i,this.updateAllViews(),this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return this._chart}get series(){return this._series}setStartTime(e){this._startTime=e,this.updateAllViews(),this.requestUpdate()}requestUpdate(){this._requestUpdate&&this._requestUpdate()}updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}constructor(){this._startTime=null,this._paneViews=[new LookbackHighlightPaneView(this)]}};let PriceLineLabelPaneRenderer=class PriceLineLabelPaneRenderer{draw(){}drawBackground(e){let t=this._data.labels;t&&t.length&&e.useBitmapCoordinateSpace(e=>{let r=e.context,i=e.horizontalPixelRatio,n=e.verticalPixelRatio;r.font="".concat(Math.round(10*n),"px monospace");let o=7*i,l=14*n,a=10*i;t.forEach(t=>{if(null===t.y||void 0===t.y)return;let s=t.y*n,d=r.measureText(t.text).width+2*o,c=e.bitmapSize.width-d-a,u=s-l/2;r.fillStyle="rgba(7, 11, 24, 0.85)",r.strokeStyle=t.color,r.lineWidth=1,r.beginPath(),r.roundRect(c,u,d,l,4*i),r.fill(),r.stroke(),r.fillStyle=t.color,r.textBaseline="middle",r.fillText(t.text,c+o,s)})})}constructor(e){this._data=e}};
1let PriceLineLabelPaneView=class PriceLineLabelPaneView{update(){let e=this._source.series;this._data.labels=(this._source._labels||[]).map(t=>({text:t.text,color:t.color,y:e?e.priceToCoordinate(t.price):null}))}renderer(){return new PriceLineLabelPaneRenderer(this._data)}constructor(e){this._source=e,this._data={labels:[]}}};let PriceLineLabelsPrimitive=class PriceLineLabelsPrimitive{attached(e){let{chart:t,series:r,requestUpdate:i}=e;this._chart=t,this._series=r,this._requestUpdate=i,this.updateAllViews(),this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return this._chart}get series(){return this._series}requestUpdate(){this._requestUpdate&&this._requestUpdate()}setLabels(e){this._labels=e,this.updateAllViews(),this.requestUpdate()}updateAllViews(){this._paneViews.forEach(e=>e.update())}paneViews(){return this._paneViews}constructor(){this._labels=[],this._paneViews=[new PriceLineLabelPaneView(this)]}};function parseRgb(e){if("string"!=typeof e)return[255,255,255];if("#"===e[0]&&(7===e.length||9===e.length))return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)];let t=e.match(/rgba?\(([^)]+)\)/);if(t){let e=t[1].split(",").map(e=>parseFloat(e));return[e[0]||0,e[1]||0,e[2]||0]}return[255,255,255]}function calculateSMA(e,t){let r=[];for(let i=0;i<e.length;i++)if(i<t-1)r.push({time:e[i].time,value:null});else{let n=e.slice(i-t+1,i+1).reduce((e,t)=>e+t.close,0);r.push({time:e[i].time,value:n/t})}return r}let B=[3,5,8,13,21,34,55,89,144],W=["rgba(255, 99, 132, 0.8)","rgba(255, 159, 64, 0.8)","rgba(255, 205, 86, 0.8)","rgba(75, 192, 192, 0.8)","rgba(54, 162, 235, 0.8)","rgba(153, 102, 255, 0.8)","rgba(255, 99, 255, 0.8)","rgba(199, 199, 199, 0.8)","rgba(83, 102, 255, 0.8)","rgba(255, 159, 127, 0.8)","rgba(127, 255, 212, 0.8)","rgba(240, 230, 140, 0.8)","rgba(255, 105, 180, 0.8)","rgba(100, 149, 237, 0.8)","rgba(255, 215, 0, 0.8)","rgba(220, 20, 60, 0.8)","rgba(0, 128, 128, 0.8)","rgba(255, 140, 0, 0.8)","rgba(128, 0, 128, 0.8)","rgba(0, 128, 0, 0.8)","rgba(255, 192, 203, 0.8)","rgba(176, 224, 230, 0.8)","rgba(255, 228, 225, 0.8)","rgba(144, 238, 144, 0.8)","rgba(255, 182, 193, 0.8)"],O={rainbow:W,darkBlue:["rgba(15, 23, 42, 0.8)","rgba(30, 41, 59, 
10.8)","rgba(30, 58, 138, 0.8)","rgba(29, 78, 216, 0.8)","rgba(37, 99, 235, 0.8)","rgba(59, 130, 246, 0.8)","rgba(96, 165, 250, 0.8)","rgba(125, 211, 252, 0.8)","rgba(56, 189, 248, 0.8)"],venusRed:["rgba(69, 10, 10, 0.8)","rgba(127, 29, 29, 0.8)","rgba(153, 27, 27, 0.8)","rgba(185, 28, 28, 0.8)","rgba(220, 38, 38, 0.8)","rgba(239, 68, 68, 0.8)","rgba(248, 113, 113, 0.8)","rgba(252, 165, 165, 0.8)","rgba(254, 202, 202, 0.8)"]},V={"5s":5,"1m":60,"5m":300,"15m":900,"30m":1800,"1h":3600,"6h":21600,"1d":86400},U={default:{upMain:"#22c55e",downMain:"#ef4444",upBase:[74,222,128],upHigh:[255,235,60],downBase:[248,113,113],downHigh:[170,90,245],upWickBase:[134,239,172],upWickHigh:[255,255,150],downWickBase:[252,165,165],downWickHigh:[200,140,255]},colorblind:{upMain:"#3b82f6",downMain:"#30fa15",upBase:[59,130,246],upHigh:[147,197,253],downBase:[202,138,4],downHigh:[250,204,21],upWickBase:[96,165,250],upWickHigh:[191,219,254],downWickBase:[234,179,8],downWickHigh:[254,240,138]}};function apply5sGlow(e){let t=e.close>=e.open,r=t?"rgba(0, 255, 255, 1)":"rgba(255, 0, 255, 1)";e.color=r,e.wickColor=r,e.borderColor=r}function OpenChartsPro_calculateEMA(e,t){let r=[],i=2/(t+1),n=null;for(let o=0;o<e.length;o++)if(o<t-1)r.push({time:e[o].time,value:null});else if(o===t-1){let i=e.slice(0,t).reduce((e,t)=>e+t.close,0);n=i/t,r.push({time:e[o].time,value:n})}else n=e[o].close*i+(n||0)*(1-i),r.push({time:e[o].time,value:n});return r}function calculateRSI(e,t){let r=[],i=0,n=0;for(let o=1;o<e.length;o++){let l=e[o]-e[o-1],a=l>0?l:0,s=l<0?-l:0;if(o<t)i+=a/t,n+=s/t,r.push(null);else if(o===t){i+=a/t,n+=s/t;let e=0===n?100:i/n;r.push(0===n?100:100-100/(1+e))}else{i=(i*(t-1)+a)/t,n=(n*(t-1)+s)/t;let e=0===n?100:i/n;r.push(0===n?100:100-100/(1+e))}}return r.unshift(null),r}function calculateEMAPrices(e,t){let r=[],i=2/(t+1),n=null;for(let o=0;o<e.length;o++)if(o<t-1)r.push(null);else if(o===t-1){let i=e.slice(0,t).reduce((e,t)=>e+t,0);n=i/t,r.push(n)}else n=(e[o]-(n||0))*i+(n||0),r.push(n);return r}function calculateMACD(e,t,r,i){let n=calculateEMAPrices(e,t).map(e=>null!=e?e:0),o=calculateEMAPrices(e,r).map(e=>null!=e?e:0),l=n.map((e,t)=>0===o[t]?null:e-o[t]),a=l.filter(e=>null!==e),s=calculateEMAPrices(a,i).map(e=>null!=e?e:0),d=l.length-a.length,c=Array(d).fill(null).concat(s),u=l.map((e,t)=>{let r=c[t];return null===e||null===r||0===r?null:e-r});return{macdLine:l,signal:c,histogram:u}}let H={color:"#f59e0b",bandOpacity:.45,bandWidth:1};function calculateAnchoredVwap(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:H.bandWidth,i=[],n=[],o=[],l=0,a=0,s=0,d=!1;for(let c of e){if(!d){if(c.time<t)continue;d=!0,l=(c.high+c.low+c.close)/3}let e=(c.high+c.low+c.close)/3,u=c.volume||0;a+=u;let p=e-l,h=a>0?u/a:0;l+=h*p;let g=e-l;s+=u*p*g;let x=a>0?Math.sqrt(Math.max(0,s/a)):0,b=x*r;i.push({time:c.time,value:l}),n.push({time:c.time,value:l+b}),o.push({time:c.time,value:l-b})}return{vwapData:i,upperData:n,lowerData:o}}function OpenChartsPro_FluctuatingDigits(e){let{count:t=4,interval:r=80}
1=e,[o,l]=(0,n.useState)("");return(0,n.useEffect)(()=>{let e=0,tick=()=>{e+=1;let r="";for(let i=0;i<t;i++){let n=t-1-i,l=Math.max(1,Math.pow(2,n)),a=e%l==0;a||!o[i]?r+=Math.floor(10*Math.random()):r+=o[i]}l(r)};tick();let i=window.setInterval(tick,r);return()=>window.clearInterval(i)},[t,o,r]),(0,i.jsx)("span",{children:o})}let q=[7e-4,.04,.125,1,7,30,90,365];function LayersRail(e){let{layers:t,onToggle:r,opacity:o=1,onOpacityChange:l,zones:a,onZonesToggle:s}=e,[d,c]=(0,n.useState)(!1),[u,p]=(0,n.useState)({x:90,y:128}),[h,g]=(0,n.useState)(null),x=(0,n.useRef)(null),b=(0,n.useRef)(!1),f=(0,n.useRef)(null);return((0,n.useEffect)(()=>{window.innerWidth<768&&p(e=>({...e,y:208}))},[]),(0,n.useEffect)(()=>{if(!h)return;let onMove=e=>{f.current&&!b.current&&(Math.abs(e.clientX-f.current.x)>4||Math.abs(e.clientY-f.current.y)>4)&&(b.current=!0),p({x:e.clientX-h.offsetX,y:e.clientY-h.offsetY})},onUp=()=>{f.current=null,g(null)};return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[h]),d)?(0,i.jsx)("button",{type:"button",title:"Show / drag layers",onClick:()=>{b.current||c(!1),b.current=!1},onPointerDown:e=>{f.current={x:e.clientX,y:e.clientY},b.current=!1,g({offsetX:e.clientX-u.x,offsetY:e.clientY-u.y})},style:{position:"absolute",left:u.x,top:u.y,zIndex:30,width:"32px",height:"32px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.25)",background:"rgba(7, 11, 24, 0.95)",color:"#fff",fontSize:"14px",cursor:"move",boxShadow:"0 2px 6px rgba(0,0,0,0.3)",touchAction:"none"},children:"☰"}):(0,i.jsxs)("div",{ref:x,style:{position:"absolute",left:u.x,top:u.y,zIndex:20,display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"2px",minWidth:"120px",maxWidth:"180px",padding:"4px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxSizing:"border-box"},children:[(0,i.jsxs)("div",{title:"Drag to move",onPointerDown:e=>{g({offsetX:e.clientX-u.x,offsetY:e.clientY-u.y})},style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"4px 6px",borderRadius:"6px",cursor:"move",transition:"background 0.15s ease"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(255,255,255,0.08)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.35)",fontSize:"14px"},children:"☰"}),(0,i.jsx)("div",{style:{fontSize:"11px",fontWeight:700,color:"#fff"},children:"Layers"})]}),t.map((e,t)=>(0,i.jsxs)("label",{style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"4px 6px",borderRadius:"4px",cursor:"pointer",transition:"background 0.15s ease"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(255,255,255,0.08)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,i.jsx)("input",{type:"checkbox",checked:!1!==e.visible,onChange:()=>r(t),style:{accentColor:"#60a5fa",cursor:"pointer"}}),(0,i.jsx)("span",{style:{fontSize:"11px",color:"rgba(255,255,255,0.85)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.title||"Layer ".concat(t+1)})]},t)),s&&(0,i.jsxs)("label",{style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"4px 6px",borderRadius:"4px",cursor:"pointer"},title:"Fill zones between overlay plots (e.g. EMA ribbons)",children:[(0,i.jsx)("input",{type:"checkbox",checked:!1!==a,onChange:()=>s(),style:{accentColor:"#60a5fa",cursor:"pointer"}}),(0,i.jsx)("span",{style:{fontSize:"11px",color:"rgba(255,255,255,0.85)"},children:"Zones"})]}),l&&(0,i.jsxs)("div",{style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"4px 6px"},title:"Overlay opacity",children:[(0,i.jsx)("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.6)",whiteSpace:"nowrap"},children:"Opacity"}),(0,i.jsx)("input",{type:"range",min:0,max:100,value:Math.round(100*o),onChange:e=>l(Number(e.target.value)/100),style:{flex:1,minWidth:0,accentColor:"#60a5fa",cursor:"pointer",height:"12px"}}),(0,i.jsxs)("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.6)",width:"28px",textAlign:"right"},children:[Math.round(100*o),"%"]})]}),(0,i.jsx)("div",{style:{width:"100%",height:"1px",background:"rgba(255,255,255,0.08)",margin:"2px 0"}}),(0,i.jsx)("button",{type:"button",title:"Hide layers",onClick:()=>c(!0),style:{width:"100%",height:"26px",borderRadius:"6px",border:"none",background:"transparent",color:"rgba(255,255,255,0.6)",fontSize:"10px",fontWeight:600,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:"✕"})]})}function MovableIndicatorToolbox(e){let{title:t,open:r,setOpen:o,pos:l,setPos:a,signal:s,children:d}
1=e,[c,u]=(0,n.useState)(null),p=(0,n.useRef)(!1),h=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(!c)return;let onMove=e=>{h.current&&!p.current&&(Math.abs(e.clientX-h.current.x)>4||Math.abs(e.clientY-h.current.y)>4)&&(p.current=!0),a({x:e.clientX-c.offsetX,y:e.clientY-c.offsetY})},onUp=()=>{h.current=null,u(null)};return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[c,a]),(0,i.jsxs)("div",{style:{position:"absolute",left:l.x,top:l.y,zIndex:25,minWidth:"min(260px, calc(100vw - 16px))",maxWidth:"min(340px, calc(100vw - 16px))",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",borderRadius:"10px",padding:"8px",boxSizing:"border-box",backdropFilter:"blur(6px)",boxShadow:"0 4px 12px rgba(0,0,0,0.4)"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"move"},onPointerDown:e=>{h.current={x:e.clientX,y:e.clientY},p.current=!1,u({offsetX:e.clientX-l.x,offsetY:e.clientY-l.y})},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},onClick:e=>{if(e.stopPropagation(),p.current){p.current=!1;return}o(!r)},children:[(0,i.jsx)("span",{style:{fontSize:"14px",color:"#fbbf24",userSelect:"none"},children:r?"▾":"▸"}),(0,i.jsx)("span",{style:{fontSize:"12px",fontWeight:600,color:"#fbbf24"},children:t})]}),s]}),r&&(0,i.jsx)("div",{style:{marginTop:"8px"},children:d})]})}let clampToViewportX=(e,t)=>Math.max(4,Math.min(e,window.innerWidth-t-8));function OpenChartsPro(e){var t,r,o,l,s,d,c,u,p,h;let{ohlc:g,livePrice:x,interval:b,symbol:f,pairName:m,height:y=600,positions:v=[],limitOrders:w=[],showPositions:S=!1,selectedPositionId:k=null,onSelectPosition:j,externalInputs:C={},liqHeatmap:_=null,liqEvents:M=null,onLiqRequest:P,onPineUpdate:T,pineStrategy:R,pineAutoRun:z,initialDomActive:I=!1,indicatorScale:L=1,onIndicatorScaleChange:A=()=>{},onManagePosition:F,onUpdatePosition:N,onPositionRiskChange:Y,onClosePosition:K,onTwapClosePosition:X,onOpenPosition:G,onOpenSignalPosition:J,quoteBalance:Q=0,smaCount:$,smaPeriods:Z,rainbowColors:ee,smaColorScheme:et,onSmaColorSchemeChange:er,onSmaCountChange:ei,maxLeverage:en=100,chartTimeframe:eo,onTimeframeChange:el,proMode:ea,candleTheme:es,onCandleThemeChange:ed,lookbackHighlight:ec=null}=e,eu=(0,n.useRef)(null),ep=(0,n.useRef)(null),eh=(0,n.useRef)(null),eg=(0,n.useRef)(null),ex=(0,n.useRef)(null),eb=(0,n.useRef)(null),ef=(0,n.useRef)(null),em=(0,n.useRef)(null),ey=(0,n.useRef)(null),ev=(0,n.useRef)(null),ew=(0,n.useRef)(null),eS=(0,n.useRef)(null),ek=(0,n.useRef)([]),ej=(0,n.useRef)(null),eC=(0,n.useRef)([]),e_=(0,n.useRef)([]),eM=(0,n.useRef)([]),eP=(0,n.useRef)(null),eT=(0,n.useRef)(null),eR=(0,n.useRef)(null),ez=(0,n.useRef)([]),eI=(0,n.useRef)(null),[eE,eD]=(0,n.useState)(null),[eL,eA]=(0,n.use
1State)(null),eF=(0,n.useRef)(null),eN=(0,n.useRef)(null),eB=(0,n.useRef)(null),eW=(0,n.useMemo)(()=>{let e=(f||(m?m.split("/")[0]:"")||"").toLowerCase();return v.filter(t=>{var r,i,n,o,l;let a=null!==(l=null!==(o=null!==(n=null!==(i=null!==(r=t.symbol)&&void 0!==r?r:t.market)&&void 0!==i?i:t.coin)&&void 0!==n?n:t.pairName)&&void 0!==o?o:t.market_base)&&void 0!==l?l:"",s=String(a).toLowerCase();return!!(!s||!e||s===e||s.includes("/")&&s.split("/")[0]===e||e.includes("/")&&e.split("/")[0]===s)||s.includes(e)||e.includes(s)})},[v,f,m]),[eO,eV]=(0,n.useState)(()=>{if(null!=k&&eW.length){let e=eW.findIndex(e=>e.id===k);return e>=0?e:null}return null});(0,n.useEffect)(()=>{if(null!=k&&eW.length){let e=eW.findIndex(e=>e.id===k);eV(e>=0?e:null)}},[k,eW]);let scaleFromSlider=e=>{let t=Math.min(100,Math.max(0,e))/100;return t<=.5?(Math.pow(10,2*t)-1)/9:Math.pow(10,2*(t-.5))},[eU,eH]=(0,n.useState)(!1),[eq,eY]=(0,n.useState)(!0),[eK,eX]=(0,n.useState)(!1),[eG,eJ]=(0,n.useState)(100),[eQ,e$]=(0,n.useState)(4),[eZ,e0]=(0,n.useState)(5),e5=S&&eq,e1=(0,n.useMemo)(()=>{var e;if(!e5||!eW.length)return[];if(eU)return eW;let t=null!=k?k:null!=eO?null===(e=eW[eO])||void 0===e?void 0:e.id:null;return null==t?eW:eW.filter(e=>String(e.id)===String(t))}
1,[e5,eW,k,eO,eU]),[e2,e4]=(0,n.useState)(!1),[e6,e8]=(0,n.useState)(null),[e3,e9]=(0,n.useState)(null),[e7,te]=(0,n.useState)(null),[tt,tr]=(0,n.useState)(null),[ti,tn]=(0,n.useState)(null),[to,tl]=(0,n.useState)(null),ta=(0,n.useRef)(null),ts=(0,n.useRef)(x),td=(0,n.useRef)(null);(0,n.useEffect)(()=>{ts.current=x},[x]);let tc=(0,n.useCallback)(()=>{let e=eg.current,t=eh.current,r=ta.current;if(!e||!t||!r||!Number.isFinite(r._entry)){tn(null),tl(null),tr(null);return}let i=e.priceToCoordinate(r._entry);tn("number"==typeof i?i:null);let n=td.current;if("number"==typeof n){let e=t.timeScale().timeToCoordinate(n);tl("number"==typeof e?e:null)}else tl(null);let o=ts.current;if("number"==typeof o&&o>0){var l;let t=e.priceToCoordinate(o),r=(null===(l=eu.current)||void 0===l?void 0:l.clientHeight)||0;tr("number"==typeof t&&t>=0&&t<=r?t:null)}else tr(null)},[]),[tu,tp]=(0,n.useState)(!1),[th,tg]=(0,n.useState)(null),[tx,tb]=(0,n.useState)([]),[tf,tm]=(0,n.useState)(!1),[ty,tv]=(0,n.useState)(!1),[tw,tS]=(0,n.useState)([]),[tk,tj]=(0,n.useState)(null),[tC,t_]=(0,n.useState)(null),[tM,tP]=(0,n.useState)(1),[tT,tR]=(0,n.useState)(!0),[tz,tI]=(0,n.useState)(!1),[tE,tD]=(0,n.useState)(1),tL=(0,n.useRef)(1),tA=(0,n.useRef)(null),tF=(0,n.useRef)(null),tN=(0,n.useRef)(null),tB=(0,n.useRef)(null),tW=(0,n.useRef)([]),applyYZoom=e=>{let t=Math.min(4,Math.max(.25,e));tL.current=t,tD(t)},[tO,tV]=(0,n.useState)(null),[tU,tH]=(0,n.useState)(null),[tq,tY]=(0,n.use
1State)(null),[tK,tX]=(0,n.useState)(""),tG=(0,n.useRef)(null),[tJ,tQ]=(0,n.useState)(!1),[t$,tZ]=(0,n.useState)(!1),[t0,t5]=(0,n.useState)(!0),[t1,t2]=(0,n.useState)(null),[t4,t6]=(0,n.useState)(!1),[t8,t3]=(0,n.useState)(!1),t9=(0,n.useRef)(null),controlCardHover=e=>({onMouseEnter:()=>{t4||t2(e)},onMouseLeave:()=>{t4||t2(t=>t===e?null:t)}}),controlCardBodyStyle=e=>{let t=t4||t1===e;return{overflow:"hidden",maxHeight:t?"800px":"0px",opacity:t?1:0,transition:"max-height 4.6s cubic-bezier(0.22, 1, 0.36, 1), opacity 1.45s ease",pointerEvents:t?"auto":"none"}};(0,n.useEffect)(()=>{let e=t9.current;if(!e||"undefined"==typeof ResizeObserver)return;let check=()=>t3(e.offsetHeight>56);check();let t=new ResizeObserver(check);return t.observe(e),()=>t.disconnect()},[]);let[t7,re]=(0,n.useState)(!1),rt=(0,n.useRef)(null),[rr,ri]=(0,n.useState)(!1),[rn,ro]=(0,n.useState)({}),[rl,ra]=(0,n.useState)(C||{}),rs=(0,n.useRef)(C||{}),rd=(0,n.useRef)(new Set),updateExternalInput=(e,t)=>{rd.current.add(e),ra(r=>{let i={...r,[e]:t};return rs.current=i,i})},[rc,ru]=(0,n.useState)(""),[rp,rh]=(0,n.useState)(!1),[rg,rx]=(0,n.useState)(!1),[rb,rf]=(0,n.useState)(!1),[rm,ry]=(0,n.useState)([]),[rv,rw]=(0,n.useState)("sma"),[rS,rk]=(0,n.useState)(50),[rj,rC]=(0,n.useState)(null!=$?$:4),r_=(0,n.useRef)(rj),[rM,rP]=(0,n.useState)(null!=et?et:"rainbow");(0,n.useEffect)(()=>{"number"==typeof $&&$!==rj&&(rC($),$>0&&(r_.current=$))},[$]),(0,n.useEffect)(()=>{et&&et!==rM&&rP(et)},[et,rM]);let rT=(0,n.useMemo)(()=>{var e;return null!==(e=null!=ee?ee:O[rM])&&void 0!==e?e:W},[ee,rM]),rR=(0,n.useCallback)(()=>{if(rj>0)r_.current=rj,rC(0),null==ei||ei(0);else{let e=Math.max(1,r_.current);rC(e),null==ei||ei(e)}},[rj,ei]),rz=(0,n.useCallback)(e=>{e>0&&(r_.current=e),rC(e),null==ei||ei(e)},[ei]),rI=(0,n.useCallback)(e=>{rP(e),null==er||er(e)},[er]),[rE,rD]=(0,n.useState)(null!=es?es:"default");(0,n.useEffect)(()=>{void 0!==es&&es!==rE&&rD(es)},[es,rE]);let[rL,rA]=(0,n.useState)(!0),[rF,rN]=(0,n.useState)(7),[rB,rW]=(0,n.useState)(34),[rO,rV]=(0,n.useState)(.7),[rU,rH]=(0,n.useState)("colorblind"),[rq,rY]=(0,n.use
1State)(!1),[rK,rX]=(0,n.useState)(!0),[rG,rJ]=(0,n.useState)(20),[rQ,r$]=(0,n.useState)(2),[rZ,r0]=(0,n.useState)(.25),[r5,r1]=(0,n.useState)("emerald"),[r2,r4]=(0,n.useState)("bollinger"),[r6,r8]=(0,n.useState)(!0),[r3,r9]=(0,n.useState)(60),[r7,ie]=(0,n.useState)(!0),[it,ir]=(0,n.useState)(!1),[ii,io]=(0,n.useState)("high"),[il,ia]=(0,n.useState)(5);(0,n.useEffect)(()=>{try{let e=localStorage.getItem("opencharts-news-alarm");if(!e)return;let t=JSON.parse(e);"boolean"==typeof t.enabled&&ir(t.enabled),("high"===t.sensitivity||"low"===t.sensitivity)&&io(t.sensitivity),"number"==typeof t.refreshMin&&ia(t.refreshMin)}catch(e){}},[]),(0,n.useEffect)(()=>{try{localStorage.setItem("opencharts-news-alarm",JSON.stringify({enabled:it,sensitivity:ii,refreshMin:il}))}catch(e){}},[it,ii,il]);let[is,id]=(0,n.useState)(!1),[ic,iu]=(0,n.useState)(.3),[ip,ih]=(0,n.useState)("default"),[ig,ix]=(0,n.useState)(!1),[ib,im]=(0,n.useState)(64),[iy,iv]=(0,n.useState)(12),[iw,iS]=(0,n.useState)("amplitude"),[ik,ij]=(0,n.useState)(.85),[iC,i_]=(0,n.useState)(0),[iM,iP]=(0,n.useState)(!0),iT=(0,n.useMemo)(()=>(function(e,t){let r=Math.min(256,Math.max(8,Math.round(Number.isFinite(e)?e:64))),i=Math.min(24,Math.max(2,Math.round(Number.isFinite(t)?t:12)));return Array.from(new Set(Array.from({length:i},(e,t)=>Math.round(8+(r-8)*t/(i-1)))))})(ib,iy),[ib,iy]),[iR,iz]=(0,n.useState)(!1),[iI,iE]=(0,n.useState)(!1),[iD,iL]=(0,n.useState)({x:20,y:650}),[iA,iF]=(0,n.useState)({x:320,y:650}
1),[iN,iB]=(0,n.useState)(12),[iW,iO]=(0,n.useState)(26),[iV,iU]=(0,n.useState)(9),[iH,iq]=(0,n.useState)(14),[iY,iK]=(0,n.useState)(14),[iX,iG]=(0,n.useState)(3),[iJ,iQ]=(0,n.useState)(3),[i$,iZ]=(0,n.useState)(!1),[i0,i5]=(0,n.useState)(.5),[i1,i2]=(0,n.useState)("default"),[i4,i6]=(0,n.useState)(!0),i8="opencharts_indicator_settings",i3={candleTheme:null!=es?es:"default",showEmaChannel:!0,emaFast:7,emaSlow:45,emaChannelOpacity:.4,emaChannelColorMode:"colorblind",emaChannelAlarm:!1,showBollinger:!0,bollingerPeriod:20,bollingerMult:2,bollingerOpacity:.25,bollingerScheme:"emerald",bandMode:"bollinger",showNews:!0,newsSpeed:60,newsPairOnly:!1,showCandleChannel:!1,candleChannelOpacity:.3,candleChannelColorMode:"default",showFourierOscillator:!1,fourierWindowSize:64,fourierWindowCount:12,fourierColorMode:"amplitude",fourierMeshOpacity:.85,fourierWireframe:!0,smaMode:"sma",rainbowDensity:50,smaCrowdsCount:null!=$?$:4,smaColorScheme:null!=et?et:"rainbow",showVolume:!1,volumeOpacity:.5,volumeColorMode:"default",showVolProfile:!0,macdFast:12,macdSlow:26,macdSignal:9,rsiPeriod:14,stochPeriod:14,stochKSmooth:3,stochDSmooth:3,indicators:[]},i9={candleTheme:rD,showEmaChannel:rA,emaFast:rN,emaSlow:rW,emaChannelOpacity:rV,emaChannelColorMode:rH,emaChannelAlarm:rY,showBollinger:rX,bollingerPeriod:rJ,bollingerMult:r$,bollingerOpacity:r0,bollingerScheme:r1,bandMode:r4,showNews:r8,newsSpeed:r9,newsPairOnly:ie,showCandleChannel:id,candleChannelOpacity:iu,candleChannelColorMode:ih,showFourierOscillator:ix,fourierWindowSize:im,fourierWindowCount:iv,fourierColorMode:iS,fourierMeshOpacity:ij,fourierWireframe:iP,smaMode:rw,rainbowDensity:rk,smaCrowdsCount:rC,smaColorScheme:rP,showVolume:iZ,volumeOpacity:i5,volumeColorMode:i2,showVolProfile:i6,macdFast:iB,macdSlow:iO,macdSignal:iU,rsiPeriod:iq,stochPeriod:iK,stochKSmooth:iG,stochDSmooth:iQ,indicators:ry},getCurrentIndicatorSettings=()=>({candleTheme:rE,showEmaChannel:rL,emaFast:rF,emaSlow:rB,emaChannelOpacity:rO,emaChannelColorMode:rU,emaChannelAlarm:rq,showBollinger:rK,bollingerPeriod:rG,bollingerMult:rQ,bollingerOpacity:rZ,bollingerScheme:r5,bandMode:r2,showNews:r6,newsSpeed:r3,newsPairOnly:r7,showCandleChannel:is,candleChannelOpacity:ic,candleChannelColorMode:ip,showFourierOscillator:ig,fourierWindowSize:ib,fourierWindowCount:iy,fourierColorMode:iw,fourierMeshOpacity:ik,fourierWireframe:iM,smaMode:rv,rainbowDensity:rS,smaCrowdsCount:rj,smaColorScheme:rM,showVolume:i$,volumeOpacity:i0,volumeColorMode:i1,showVolProfile:i4,macdFast:iN,macdSlow:iW,macdSignal:iV,rsiPeriod:iH,stochPeriod:iY,stochKSmooth:iX,stochDSmooth:iJ,indicators:rm}),applyIndicatorSettings=e=>{e&&Object.entries(e).forEach(e=>{let[t,r]=e,i=i9[t];i&&void 0!==r&&i(r)})},[i7,ne]=(0,n.useState)(null),triggerGlow=e=>{ne(e),setTimeout(()=>ne(t=>t===e?null:t),450)},nt=(0,n.useCallback)((e,t)=>{if("default"===i1)return e.isUp?"rgba(34, 197, 94, ".concat(i0,")"):"rgba(239, 68, 68, ".concat(i0,")");let r=t?e.volume/t:0;return"rgba(".concat(Math.round(59+191*r),", ").concat(Math.round(130+74*r),", ").concat(Math.round(246+-225*r),", ").concat(i0,")")},[i1,i0]),SliderPill=e=>{let{name:t,value:r}=e;return(0,i.jsx)("div",{draggable:!0,onDragStart:e=>{e.dataTransfer.setData("text/plain","".concat(t," = ").concat(r)),e.dataTransfer.effectAllowed="copy"},title:"Drag ".concat(t," = ").concat(r," into the PineScript editor"),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"2px 8px",borderRadius:"999px",background:"rgba(59, 130, 246, 0.15)",border:"1px solid rgba(59, 130, 246, 0.25)",color:"#93c5fd",fontSize:"10px",cursor:"grab",textAlign:"center",userSelect:"none"},children:r})},[nr,ni]=(0,n.useState)(0),[nn,no]=(0,n.useState)(85),nl=(0,n.useRef)(null),[na,ns]=(0,n.useState)([]),[nd,nc]=(0,n.useState)("rsi_divergence"),nu=(0,n.useMemo)(()=>na.find(e=>e.name===nd)||null,[na,nd]),np=(0,n.useRef)(null),[nh,ng]=(0,n.useState)("none"),[nx,nb]=(0,n.useState)(null),[nf,nm]=(0,n.useState)(null),[ny,nv]=(0,n.useState)(!1),[nw,nS]=(0,n.useState)(""),[nk,nj]=(0,n.useState)(""),[nC,n_]=(0,n.useState)({x:0,y:0}
1),[nM,nP]=(0,n.useState)(!1),[nT,nR]=(0,n.useState)({w:300,h:null}),nz=(0,n.useRef)(null),nI=(0,n.useRef)(null),[nE,nD]=(0,n.useState)({}),[nL,nA]=(0,n.useState)(""),[nF,nN]=(0,n.useState)([]),[nB,nW]=(0,n.useState)(!1),[nO,nV]=(0,n.useState)(""),[nU,nH]=(0,n.useState)(0),nq=(0,n.useRef)(null),nY=(0,n.useRef)([]),nK=(0,n.useRef)(0),nX=(0,n.useRef)([]),nG=(0,n.useRef)(null),[nJ,nQ]=(0,n.useState)(!1),[n$,nZ]=(0,n.useState)(!!I),[n0,n5]=(0,n.useState)(null),n1=(0,n.useRef)(null),n2=null!==symbolToGexCurrency(f),[n4,n6]=(0,n.useState)(!1),n8=(0,n.useRef)(null),n3=!!(null==_?void 0:null===(t=_.buckets)||void 0===t?void 0:t.length)||!!(M&&M.length),n9=x||(g.length?Number(g[g.length-1][4]):0),n7=(0,n.useCallback)(e=>{tW.current=e,tB.current&&tB.current.setLevels(e)},[]),[oe,ot]=(0,n.useState)(!0),[or,oi]=(0,n.useState)(!0),[on,oo]=(0,n.useState)(!1),[ol,oa]=(0,n.useState)(0),[os,od]=(0,n.useState)(!1),oc=(0,n.useRef)([]),ou=(0,n.useRef)(null),op=(0,n.useRef)([]),oh=(0,n.useRef)([]),og=(0,n.useRef)(null),ox=(0,n.useRef)(null),ob=(0,n.useRef)([]),of=(0,n.useRef)(!1),om=(0,n.useRef)(null),oy=(0,n.useRef)(null),ov=(0,n.useRef)(60),ow=(0,n.useRef)(null),oS=(0,n.useRef)([]),ok=(0,n.useRef)([]),[oj,oC]=(0,n.useState)(!1),[o_,oM]=(0,n.useState)([]),[oP,oT]=(0,n.useState)(()=>Date.now()),oR=(0,n.useRef)(!1),oz=(0,n.useRef)(new Set),oI=(0,n.useRef)(!1),oE=(0,n.useRef)(!1),oD=(0,n.useRef)(!1),oL=(0,n.useRef)(!1),[oA,oF]=(0,n.useState)(0),oN=(0,n.useRef)(null),[oB,oW]=(0,n.use
1State)(""),[oO,oV]=(0,n.useState)(10),[oU,oH]=(0,n.useState)(!1),[oq,oY]=(0,n.useState)(50),[oK,oX]=(0,n.useState)(!1),[oG,oJ]=(0,n.useState)(10),[oQ,o$]=(0,n.useState)(!1),[oZ,o0]=(0,n.useState)(2),[o5,o1]=(0,n.useState)(!1),[o2,o4]=(0,n.useState)(null),[o6,o8]=(0,n.useState)({x:360,y:16}),o3=(0,n.useRef)(null),o9=(0,n.useRef)(null),o7=(0,n.useRef)(0),[le,lt]=(0,n.useState)(null),[lr,li]=(0,n.useState)(""),[ln,lo]=(0,n.useState)(10),[ll,la]=(0,n.useState)(null),[ls,ld]=(0,n.useState)(!1),[lc,lu]=(0,n.useState)(!0),[lp,lh]=(0,n.useState)(25),lg=(0,n.useRef)(!1),lx=(0,n.useRef)(!1),[lb,lf]=(0,n.useState)(!1),[lm,ly]=(0,n.useState)(10),[lv,lw]=(0,n.useState)(!1),[lS,lk]=(0,n.useState)(2),[lj,lC]=(0,n.useState)("market"),[l_,lM]=(0,n.useState)("single"),[lP,lT]=(0,n.useState)(""),[lR,lz]=(0,n.useState)(""),[lI,lE]=(0,n.useState)(""),[lD,lL]=(0,n.useState)(5),[lA,lF]=(0,n.useState)("off");(0,n.useEffect)(()=>{let e=!!(null==le?void 0:le.open);if(e&&!lx.current&&(lg.current=!1),lx.current=e,!e||lg.current)return;let t=Math.max(1/ln-D.Rt,1e-12),r=Math.min(300,Math.max(1,Math.round(2*t*ln*100)));lh(r)},[null==le?void 0:le.open,ln]);let[lN,lB]=(0,n.useState)(null),[lW,lO]=(0,n.useState)(""),[lV,lU]=(0,n.useState)(!1),[lH,lq]=(0,n.useState)(null),[lY,lK]=(0,n.useState)({x:360,y:72}),[lX,lG]=(0,n.useState)(null),lJ=(0,n.useRef)(null),[lQ,l$]=(0,n.useState)(null),[lZ,l0]=(0,n.useState)(null),[l5,l1]=(0,n.useState)(!1),[l2,l4]=(0,n.useState)(!1),[l6,l8]=(0,n.use
1State)(null),[l3,l9]=(0,n.useState)(!1),[l7,ae]=(0,n.useState)("moderate"),[at,ar]=(0,n.useState)(!1),[ai,an]=(0,n.useState)(""),[ao,al]=(0,n.useState)(null),[aa,as]=(0,n.useState)(""),[ad,ac]=(0,n.useState)({x:360,y:16}),[au,ap]=(0,n.useState)(null),[ah,ag]=(0,n.useState)(!1),[ax,ab]=(0,n.useState)({x:140,y:60}),[af,am]=(0,n.useState)(null),ay=(0,n.useRef)(null),[av,aw]=(0,n.useState)({x:null,y:54}),aS=(0,n.useRef)(null),[ak,aj]=(0,n.useState)(!0),aC=(0,n.useRef)(!0);(0,n.useEffect)(()=>{var e,t,r;if(aC.current=ak,null===(e=ox.current)||void 0===e||e.applyOptions({handleScroll:!ak,handleScale:!ak}),ak){let e=null===(t=eh.current)||void 0===t?void 0:t.timeScale().getVisibleLogicalRange();e&&(null===(r=ox.current)||void 0===r||r.timeScale().setVisibleLogicalRange(e))}},[ak]);let snapPineSettings=e=>{var t,r,i,n,o,l,a,s,d;let c=null!==(n=null===(t=ay.current)||void 0===t?void 0:t.offsetWidth)&&void 0!==n?n:360,u=null!==(o=null===(r=ay.current)||void 0===r?void 0:r.offsetHeight)&&void 0!==o?o:400,p=null===(i=eu.current)||void 0===i?void 0:i.getBoundingClientRect(),h=window.innerWidth,g=window.innerHeight,x=(null!==(l=null==p?void 0:p.left)&&void 0!==l?l:0)+8,b=(null!==(a=null==p?void 0:p.right)&&void 0!==a?a:h)-8,f=(null!==(s=null==p?void 0:p.top)&&void 0!==s?s:0)+8+80,m=(null!==(d=null==p?void 0:p.bottom)&&void 0!==d?d:g)-8;ab({x:"tl"===e||"bl"===e?x:Math.max(x,b-c),y:"tl"===e||"tr"===e?f:Math.max(f,m-u)})},[a_,aM]=(0,n.useState)({x:480,y:84}
1),[aP,aT]=(0,n.useState)(null),[aR,az]=(0,n.useState)(!1),aI=(0,n.useRef)(null),[aE,aD]=(0,n.useState)(!1),aL=(0,n.useRef)(null),[aA,aF]=(0,n.useState)(null),aN=(0,n.useRef)(!1),aB=(0,n.useRef)(null),[aW,aO]=(0,n.useState)({x:215,y:88}),[aV,aU]=(0,n.useState)(null),[aH,aq]=(0,n.useState)({x:0,y:0}),[aY,aK]=(0,n.useState)(null),[aX,aG]=(0,n.useState)(!1),[aJ,aQ]=(0,n.useState)(!1),a$=(0,n.useRef)([]);(0,n.useEffect)(()=>{var e,t;let r=null!==(t=null===(e=eu.current)||void 0===e?void 0:e.clientWidth)&&void 0!==t?t:window.innerWidth;if(r>=700)return;let clampX=(e,t)=>Math.max(4,Math.min(e,r-t-8));o8(e=>({...e,x:clampX(e.x,340)})),ac(e=>({...e,x:clampToViewportX(e.x,380)})),lK(e=>({...e,x:clampToViewportX(e.x,320)})),ab(e=>({...e,x:clampToViewportX(e.x,360)})),aM(e=>({...e,x:clampX(e.x,140)})),aO(e=>({...e,x:clampX(e.x,288)})),iL(e=>({x:clampX(e.x,260),y:Math.min(e.y,140)})),iF(e=>({x:clampX(e.x,260),y:Math.min(e.y,140)})),nR(e=>({...e,w:Math.min(e.w,Math.max(220,window.innerWidth-24))})),t5(!1)},[]),(0,n.useEffect)(()=>{let e=localStorage.getItem("opencharts_pinescript_code");e&&(of.current=!0,tX(e),rf(!1))},[]);let removeIndicator=e=>{ry(rm.filter(t=>t!==e))},aZ=(0,n.useMemo)(()=>{let e=g.map(e=>Number(e[5])||0),t=Math.max(1,...e),lerp=(e,t,r)=>Math.round(e+(t-e)*r);return g.map((r,i)=>{let n=Number(r[1]),o=Number(r[2]),l=Number(r[3]),a=Number(r[4]),s=e[i],d=a>=n,c=s/t,u=.55+.45*c,p=.7+.3*c,h=.6+.4*c,g=U[rE],x=g.upBase,b=g.upHigh,f=g.downBase,m=g.downHigh,y=g.upWickBase,v=g.upWickHigh,w=g.downWickBase,S=g.downWickHigh,k=d?x:f,j=d?b:m,C=d?y:w,_=d?v:S,M=lerp(k[0],j[0],c),P=lerp(k[1],j[1],c),T=lerp(k[2],j[2],c),R=lerp(C[0],_[0],c),z=lerp(C[1],_[1],c),I=lerp(C[2],_[2],c),E="rgba(".concat(M,",").concat(P,",").concat(T,",").concat(u,")"),D="rgba(".concat(R,",").concat(z,",").concat(I,",").concat(p,")"),L="rgba(".concat(M,",").concat(P,",").concat(T,",").concat(h,")");return{time:Math.floor(r[0]/1e3),open:n,high:o,low:l,close:a,volume:s,isUp:d,color:E,wickColor:D,borderColor:L}})},[g,rE]),a0=(0,n.useMemo)(()=>l5&&null!==l6?calculateAnchoredVwap(aZ,l6):null,[l5,l6,aZ]),a5=(0,n.useMemo)(()=>g.slice(-120).map(e=>[Number(e[0]),Number(e[1]),Number(e[2]),Number(e[3]),Number(e[4])]),[g]),a1=(0,n.useMemo)(()=>g.slice(-(120+ib)).map(e=>[Number(e[0]),Number(e[1]),Number(e[2]),Number(e[3]),Number(e[4])]),[g,ib]),a2=(0,n.useMemo)(()=>aZ.map(e=>e.close),[aZ]),a4=(0,n.useMemo)(()=>aZ.map(e=>e.time),[aZ]),a6=(0,n.useCallback)(e=>{let t=new Date(1e3*e);return null!=eo&&eo<1?t.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1}):null!=eo&&1===eo?t.toLocaleTimeString("en-US",{hour:"2-digit",hour12:!1}):t.toLocaleDateString("en-US",{month:"short",day:"numeric"})},[eo]),a8=(0,n.useMemo)(()=>{if(!ea||a2.length<35)return{active:!1,value:null};let e=calculateRSI(a2,iH),t=e.filter(e=>null!==e);if(t.length<2){var r;return{active:!1,value:null!==(r=t[t.length-1])&&void 0!==r?r:null}}let i=t[t.length-2],n=t[t.length-1];return{active:n<30||i<30&&n>i,value:n}},[ea,a2,iH]),a3=(0,n.useMemo)(()=>{if(!ea||a2.length<35)return{active:!1};let e=calculateMACD(a2,iN,iW,iV),t=e.macdLine.filter(e=>null!==e),r=e.signal.filter(e=>null!==e);if(t.length<2||r.length<2)return{active:!1};let i=t[t.length-2],n=t[t.length-1],o=r[r.length-2],l=r[r.length-1];return{active:i<=o&&n>l||n>l}},[ea,a2,iN,iW,iV]),a9=(0,n.useMemo)(()=>{if(!ea||a2.length<2)return null;let e=a4.map(a6),t=calculateRSI(a2,iH),r=function(e,t,r,i,n){let o=calculateRSI(e,t).map(e=>null!=e?e:0),l=[];for(let e=0;e<o.length;e++){if(e<r-1){l.push(null);continue}let t=o.slice(e-r+1,e+1),i=Math.min(...t),n=Math.max(...t),a=n-i;l.push(0===a?50:(o[e]-i)/a*100)}let smooth=(e,t)=>{let r=[],i=0,n=0;for(let o=0;o<e.length;o++){let l=e[o];if(null!==l&&(i+=l,n++),o>=t){let r=e[o-t];null!==r&&(i-=r,n--)}r.push(o>=t-1&&n>0?i/n:null)}return r},a=smooth(l,i),s=smooth(a,n);return{k:a,d:s}}(a2,iH,iY,iX,iJ);return{labels:e,datasets:[{label:"RSI (".concat(iH,")"),data:t,borderColor:"rgba(255, 205, 86, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"y"},{label:"Stoch %K (".concat(iY,",").concat(iX,")"),data:r.k,borderColor:"rgba(56, 189, 248, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"y"},{label:"Stoch %D (".concat(iJ,")"),data:r.d,borderColor:"rgba(244, 114, 182, 0.9)",backgroundColor:"transparent",borderWidth:1.5,borderDash:[4,4],pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"y"}]}}
1,[ea,a2,a4,iH,iY,iX,iJ,a6]),a7=(0,n.useMemo)(()=>{if(!ea||a2.length<2)return null;let e=a4.map(a6),t=calculateMACD(a2,iN,iW,iV);return{labels:e,datasets:[{label:"MACD (".concat(iN,",").concat(iW,")"),data:t.macdLine,borderColor:"rgba(54, 162, 235, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"yMacd"},{label:"Signal (".concat(iV,")"),data:t.signal,borderColor:"rgba(255, 99, 132, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"yMacd"},{label:"MACD Histogram",type:"bar",data:t.histogram,borderWidth:1,pointRadius:0,barPercentage:.95,categoryPercentage:.9,yAxisID:"yMacd",backgroundColor:e=>{let r,i;let n=e.dataIndex,o=e.raw;if(null==o)return"rgba(255,255,255,0.5)";let l=n>0?t.histogram[n-1]:o,a=e.chart,{ctx:s,chartArea:d,scales:c}=a;if(!d||!(null==c?void 0:c.yMacd))return"rgba(255,255,255,0.5)";let u=c.yMacd,p=o>0,h=o>l;p?(r=h?"rgba(255, 255, 255, 0.9)":"rgba(239, 68, 68, 0.9)",i=h?"rgba(255, 255, 255, 0.2)":"rgba(239, 68, 68, 0.2)"):(r=h?"rgba(34, 197, 94, 0.9)":"rgba(30, 58, 138, 0.9)",i=h?"rgba(34, 197, 94, 0.2)":"rgba(30, 58, 138, 0.2)");let g=u.getPixelForValue(p?Math.max(o,0):0),x=u.getPixelForValue(p?0:Math.min(o,0)),b=s.createLinearGradient(0,g,0,x);return b.addColorStop(0,r),b.addColorStop(1,i),b},borderColor:e=>{let r=e.dataIndex,i=e.raw;if(null==i)return"rgba(255,255,255,0.5)";let n=r>0?t.histogram[r-1]:i;return i>0?i>n?"rgba(255, 255, 255, 0.6)":"rgba(239, 68, 68, 0.6)":i<n?"rgba(30, 58, 138, 0.6)":"rgba(34, 197, 94, 0.6)"},hoverBackgroundColor:e=>{let r=e.dataIndex,i=e.raw;if(null==i)return"rgba(255,255,255,0.5)";let n=r>0?t.histogram[r-1]:i;return i>0?i>n?"rgba(255, 255, 255, 0.95)":"rgba(239, 68, 68, 0.95)":i<n?"rgba(30, 58, 138, 0.8)":"rgba(34, 197, 94, 0.95)"},hoverBorderColor:e=>{let r=e.dataIndex,i=e.raw;if(null==i)return"rgba(255,255,255,0.5)";let n=r>0?t.histogram[r-1]:i;return i>0?i>n?"rgba(255, 255, 255, 1)":"rgba(239, 68, 68, 1)":i<n?"rgba(30, 58, 138, 1)":"rgba(34, 197, 94, 1)"}}]}},[ea,a2,a4,iN,iW,iV,a6]),se=(0,n.useMemo)(()=>({responsive:!0,maintainAspectRatio:!1,animation:{duration:0},interaction:{mode:"index",intersect:!1},plugins:{legend:{display:!0,labels:{color:"rgba(255,255,255,0.6)",font:{size:10},boxWidth:10}},tooltip:{mode:"index",intersect:!1,backgroundColor:"rgba(7, 11, 24, 0.9)",titleColor:"#fff",bodyColor:"#e5e7eb",borderColor:"rgba(124, 58, 237, 0.3)",borderWidth:1}},scales:{x:{grid:{display:!1},ticks:{color:"rgba(255, 255, 255, 0.5)",font:{size:11},autoSkip:!1,callback:(e,t)=>t%10==0?e:null}},y:{type:"linear",position:"left",min:0,max:100,grid:{color:"rgba(255, 255, 255, 0.08)"},ticks:{color:"rgba(255, 255, 255, 0.6)",font:{size:10}}}}}),[]),st=(0,n.useMemo)(()=>({responsive:!0,maintainAspectRatio:!1,animation:{duration:0},interaction:{mode:"index",intersect:!1},plugins:{legend:{display:!0,labels:{color:"rgba(255,255,255,0.6)",font:{size:10},boxWidth:10}},tooltip:{mode:"index",intersect:!1,backgroundColor:"rgba(7, 11, 24, 0.9)",titleColor:"#fff",bodyColor:"#e5e7eb",borderColor:"rgba(124, 58, 237, 0.3)",borderWidth:1}},scales:{x:{grid:{display:!1},ticks:{color:"rgba(255, 255, 255, 0.5)",font:{size:11},autoSkip:!1,callback:(e,t)=>t%10==0?e:null}},yMacd:{type:"linear",position:"left",grid:{color:"rgba(255, 255, 255, 0.08)"},ticks:{color:"rgba(54, 162, 235, 0.8)",font:{size:10}}}}}),[]),sr=(0,n.useCallback)(e=>{var t,r,i,n,o;let l=eg.current,a=eh.current,s=oy.current;if(!l||!a||!s||!aZ.length)return;let d=aZ.length>1?aZ[aZ.length-1].time-aZ[aZ.length-2].time:60,c=ov.current||60,u=Math.floor(Date.now()/1e3),p=Math.floor(u/c)*c,h=Math.floor(u/d)*d,g=!1,x=!1;if(p>s.time){x=!0,oS.current.push(s);let e=s.time+c;for(;e<=p;){let t=oy.current?oy.current.close:s.close,r={time:e,open:t,high:t,low:t,close:t,volume:0};e===p?oy.current=r:oS.current.push(r),c===V["5s"]&&apply5sGlow(r);try{l.update(r)}catch(e){}e+=c}}let b=oy.current;if(h>(ow.current||0)){let e=null===(t=oS.current[0])||void 0===t?void 0:t.time,r=e===ow.current&&oS.current.length>=Math.max(1,Math.floor(d/c));if(r){let e=function(e,t){if(!e.length)return null;let r=e[0].open,i=Math.max(...e.map(e=>e.high)),n=Math.min(...e.map(e=>e.low)),o=e[e.length-1].close,l=e.reduce((e,t)=>
1e+(t.volume||0),0);return{time:t,open:r,high:i,low:n,close:o,volume:l}}(oS.current,ow.current||h);e&&ok.current.push(e)}ow.current=h,oS.current=[],g=!0}if("number"==typeof e&&e>0){b.high=Math.max(b.high,e),b.low=Math.min(b.low,e),b.close=e,c===V["5s"]&&apply5sGlow(b);try{l.update(b)}catch(e){}}if(g){let e=oy.current,t=null!==(n=null===(r=(i=a.timeScale()).getVisibleLogicalRange)||void 0===r?void 0:r.call(i))&&void 0!==n?n:null,o=new Map;aZ.forEach(e=>{o.set(e.time,e)}),ok.current.forEach(e=>{o.set(e.time,e)}),e&&o.set(e.time,e);let s=Array.from(o.values()).sort((e,t)=>e.time-t.time);try{l.setData(s)}catch(e){}if(t&&s.length>1)try{a.timeScale().setVisibleLogicalRange(t)}catch(e){}if(e)try{l.update(e)}catch(e){}}x&&(null===(o=oN.current)||void 0===o||o.call(oN))},[aZ]),loadStrategyCode=e=>{e&&fetch("/api/pinescript?name=".concat(encodeURIComponent(e))).then(e=>e.json()).then(e=>{"string"==typeof e.code&&(of.current=!0,tK&&(tG.current=tK),tX(e.code),rf(!1))}).catch(()=>{})};(0,n.useEffect)(()=>{let e=!0;return fetch("/api/pinescripts").then(e=>e.json()).then(async t=>{if(!e||!Array.isArray(t.strategies))return;let r=t.strategies.map(e=>{if("string"==typeof e)return{name:e,title:e,description:"Custom Pine strategy"};let t="string"==typeof(null==e?void 0:e.name)?e.name:"";return t?{name:t,title:"string"==typeof(null==e?void 0:e.title)&&e.title.trim()?e.title.trim():t,description:"string"==typeof(null==e?void 0:e.description)&&e.description.trim()?e.description.trim():"Custom Pine strategy"}:null}).filter(Boolean);if(!r.length)return;ns(r);let i=R&&r.some(e=>e.name===R)?R:r[0].name;if(nc(i),i&&!of.current){let t=await fetch("/api/pinescript?name=".concat(encodeURIComponent(i))),r=await t.json();e&&!of.current&&"string"==typeof r.code&&(of.current=!0,tX(r.code),rf(!1))}}).catch(()=>{}),()=>{e=!1}},[]),(0,n.useEffect)(()=>{if(!eu.current)return;if(eh.current){try{eh.current.remove()}catch(e){}eh.current=null,eg.current=null}let autoscaleInfoProvider=e=>{let t=tL.current,zoomRange=(e,r)=>{let i=(e+r)/2,n=(r-e)/2/t;return{minValue:i-n,maxValue:i+n}};if(eb.current){let e=zoomRange(eb.current.from,eb.current.to);return{priceRange:e,margins:{above:0,below:0}}}let r=e();return(null==r?void 0:r.priceRange)&&1!==t&&(r.priceRange=zoomRange(r.priceRange.minValue,r.priceRange.maxValue)),r};tF.current=autoscaleInfoProvider;let e=(0,a.C2)(eu.current,{layout:{background:{color:"#070b18"},textColor:"rgba(255,255,255,0.7)",fontFamily:"Nasalization"},grid:{vertLines:{color:"rgba(255,255,255,0.05)"},horzLines:{color:"rgba(255,255,255,0.05)"}},crosshair:{mode:a.rM.Normal},...getPriceScaleMargins(eu.current.clientHeight,i$,r6),timeScale:{borderColor:"rgba(255,255,255,0.1)",timeVisible:["5s","1m","5m","15m","30m","1h"].includes(b),shiftVisibleRangeOnNewBar:!1},width:eu.current.clientWidth,height:eu.current.clientHeight}),t=U[rE],r=e.addCandlestickSeries({upColor:t.upMain,downColor:t.downMain,borderUpColor:t.upMain,borderDownColor:t.downMain,wickUpColor:t.upMain,wickDownColor:t.downMain,autoscaleInfoProvider});if(r.setData(aZ),i$){let t=aZ.reduce((e,t)=>Math.max(e,t.volume||0),1),r=e.addHistogramSeries({priceScaleId:"left",priceFormat:{type:"volume"}});r.setData(aZ.map(e=>({time:e.time,value:e.volume,color:nt(e,t)}))),ew.current=r}if(ex.current){try{e.timeScale().setVisibleLogicalRange(ex.current)}catch(t){e.timeScale().fitContent()}ex.current=null}else e.timeScale().fitContent();if(eb.current)try{r.priceScale().applyOptions({autoScale:!1})}catch(e){}if(rm.forEach(t=>{if("Volume"===t){let t=e.addHistogramSeries({priceScaleId:"left",priceFormat:{type:"volume"},color:"rgba(99,102,241,0.5)"});t.setData(aZ.map(e=>({time:e.time,value:e.volume})))}else if("SMA 20"===t){let t=e.addLineSeries({color:"#f59e0b",lineWidth:1,title:"SMA 20",priceLineVisible:!1});t.setData(calculateSMA(aZ,20).filter(e=>null!==e.value))}else if("SMA 50"===t){let t=e.addLineSeries({color:"#ec4899",lineWidth:1,title:"SMA 50",priceLineVisible:!1});t.setData(calculateSMA(aZ,50).filter(e=>null!==e.value))}else if("EMA 20"===t){let t=e.addLineSeries({color:"#22d3ee",lineWidth:1,title:"EMA 20",priceLineVisible:!1});t.setData(OpenChartsPro_calculateEMA(aZ,20).filter(e=>null!==e.value))}}
1),rL&&aZ.length){let e="colorblind"===rU,t=e?"59, 130, 246":"239, 68, 68",i=new EmaChannelIndicator({fast:rF,slow:rB,bullFillColor:"rgba(".concat(t,", ").concat(rO,")"),bearFillColor:"rgba(".concat(e?"250, 204, 21":"34, 197, 94",", ").concat(rO,")"),lineColor:"rgba(".concat(t,", 0.25)"),lineWidth:.5});r.attachPrimitive(i),ef.current=i}if(is&&aZ.length){let e="colorblind"===ip,t=new CandleChannelIndicator({upFillColor:"rgba(".concat(e?"59, 130, 246":"34, 197, 94",", ").concat(ic,")"),downFillColor:"rgba(".concat(e?"250, 204, 21":"239, 68, 68",", ").concat(ic,")"),lineColor:"rgba(255, 255, 255, 0.1)",lineWidth:.5});r.attachPrimitive(t),ey.current=t}eh.current=e,eg.current=r;let i=new PriceLineLabelsPrimitive;try{r.attachPrimitive(i)}catch(e){}tN.current=i;let n=new DomOverlayIndicator;try{r.attachPrimitive(n)}catch(e){}tB.current=n,tW.current.length&&n.setLevels(tW.current),oa(e=>e+1);let o=new DrawingToolsManager({chart:e,series:r,container:eu.current,intervalSec:V[b]||60,timeframe:b,accountEquity:0,callbacks:{onAdd:e=>{oc.current=[...oc.current,e]},onUpdate:e=>{oc.current=oc.current.map(t=>t.id===e.id?e:t)},onRemove:e=>{oc.current=oc.current.filter(t=>t.id!==e)},onToolFinished:()=>{ng("none")}}});o.setDrawings(oc.current),o.setTool(nh),o.setStayInDrawingMode("none"!==nh),ou.current=o;let updateCoords=()=>{tc()};e.timeScale().subscribeVisibleTimeRangeChange(updateCoords);let updatePriceRange=()=>{if(eu.current){let i=eu.current.clientHeight;if(i>0){var e,t;let n=r.priceScale().options().scaleMargins,o=null!==(e=null==n?void 0:n.top)&&void 0!==e?e:0,l=null!==(t=null==n?void 0:n.bottom)&&void 0!==t?t:0,a=r.coordinateToPrice(Math.round(i*o)),s=r.coordinateToPrice(Math.round(i*(1-l)-1));"number"==typeof a&&"number"==typeof s&&(eb.current={from:Math.min(a,s),to:Math.max(a,s)})}}tc()},l=r.priceScale();"function"==typeof l.subscribeVisibleRangeChanged&&l.subscribeVisibleRangeChanged(updatePriceRange);let s=new ResizeObserver(()=>{eu.current&&eh.current&&(eh.current.applyOptions({width:eu.current.clientWidth,height:eu.current.clientHeight}),tc())});return eu.current&&s.observe(eu.current),()=>{var t,i,n,a,d,c,u,p;e.timeScale().unsubscribeVisibleTimeRangeChange(updateCoords),"function"==typeof l.subscribeVisibleRangeChanged&&(null===(a=l.unsubscribeVisibleRangeChanged)||void 0===a||a.call(l,updatePriceRange)),s.disconnect();try{o.destroy()}catch(e){}ou.current=null,op.current.forEach(t=>{let{series:r}=t;try{e.removeSeries(r)}catch(e){}}),op.current=[];let h=null!==(d=null===(t=eu.current)||void 0===t?void 0:t.clientHeight)&&void 0!==d?d:0;if(r&&h>0){let e=r.priceScale().options().scaleMargins,t=null!==(c=null==e?void 0:e.top)&&void 0!==c?c:0,i=null!==(u=null==e?void 0:e.bottom)&&void 0!==u?u:0,n=r.coordinateToPrice(Math.round(h*t)),o=r.coordinateToPrice(Math.round(h*(1-i)-1));"number"==typeof n&&"number"==typeof o&&(eb.current={from:Math.min(n,o),to:Math.max(n,o)})}ex.current=null!==(p=null==e?void 0:null===(n=e.timeScale())||void 0===n?void 0:null===(i=n.getVisibleLogicalRange)||void 0===i?void 0:i.call(n))&&void 0!==p?p:null;try{e.remove()}catch(e){}}},[aZ,b,y,rm,rE]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(e&&t){try{e.applyOptions(getPriceScaleMargins(e.options().height,i$,r6))}catch(e){}if(ew.current){try{e.removeSeries(ew.current)}catch(e){}ew.current=null}if(i$&&aZ.length){let t=aZ.reduce((e,t)=>Math.max(e,t.volume||0),1),r=e.addHistogramSeries({priceScaleId:"left",priceFormat:{type:"volume"}});r.setData(aZ.map(e=>({time:e.time,value:e.volume,color:nt(e,t)}))),ew.current=r}}},[i$,r6,i0,i1,aZ,nt]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(e&&t&&(e_.current.forEach(t=>{try{e.removeSeries(t)}catch(e){}}),e_.current=[],(null!=rj?rj:0)>0&&aZ.length)){let t=(null!=Z?Z:B).slice(0,rj),r=[];t.forEach((t,i)=>{let n=rT[i%rT.length],o=(null!=rS?rS:50)/100,l=(.15+.25*o).toFixed(2),a=(.3*o).toFixed(2),s=(.05*o).toFixed(2),d=n.replace(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/,(e,t,r,i)=>"rgba(".concat(Math.min(255,Math.round(255-(255-+t)*.55)),", ").concat(Math.min(255,Math.round(255-(255-+r)*.55)),", ").concat(Math.min(255,Math.round(255-(255-+i)*.55)))),c=e.addAreaSeries({lineColor:n.replace("0.8",l),lineWidth:.5,topColor:d.replace("0.8",a),bottomColor:n.replace("0.8",s),priceLineVisible:!1,autoscaleInfoProvider:()=>null});c.setData(("ema"===rv?OpenChartsPro_calculateEMA:calculateSMA)(aZ,t).filter(e=>null!==e.value)),r.push(c)}),e_.current=r}},[rj,Z,rT,rv,rS,aZ]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(e&&t){if(ef.current){try{t.detachPrimitive(ef.current)}catch(e){}ef.current=null}if(rL&&aZ.length){let e="colorblind"===rU,r=e?"59, 130, 246":"239, 68, 68",i=new EmaChannelIndicator({fast:rF,slow:rB,bullFillColor:"rgba(".concat(r,", ").concat(rO,")"),bearFillColor:"rgba(".concat(e?"250, 204, 21":"34, 197, 94",", ").concat(rO,")"),lineColor:"rgba(".concat(r,", 0.25)"),lineWidth:.5});t.attachPrimitive(i),ef.current=i}}},[rL,rF,rB,rO,rU,aZ]),(0,n.useEffect)(()=>{let e=eg.current;if(e){if(em.current){try{e.detachPrimitive(em.current)}catch(e){}em.current=null}if(rK&&aZ.length){let t;if("ichimoku"===r2){let e=Math.max(1,rG),r=Math.max(1,Math.round(.35*rG)),i=Math.max(e+1,Math.round(rG*rQ));t=new IchimokuCloudIndicator({conversionPeriod:r,basePeriod:e,spanBPeriod:i,displacement:0,fillOpacity:rZ,colorScheme:r5,lineWidth:1})}else t=new BollingerBandsIndicator({period:rG,multiplier:rQ,fillOpacity:rZ,colorScheme:r5,lineWidth:1});e.attachPrimitive(t),em.current=t}}},[rK,r2,rG,rQ,rZ,r5,aZ,ol]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(e&&t){if(ey.current){try{t.detachPrimitive(ey.current)}catch(e){}ey.current=null}if(is&&aZ.length){let e="colorblind"===ip,r=new CandleChannelIndicator({upFillColor:"rgba(".concat(e?"59, 130, 246":"34, 197, 94",", ").concat(ic,")"),downFillColor:"rgba(".concat(e?"250, 204, 21":"239, 68, 68",", ").concat(ic,")"),lineColor:"rgba(255, 255, 255, 0.1)",lineWidth:.5});t.attachPrimitive(r),ey.current=r}}},[is,ic,ip,aZ]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(e&&t){if(ev.current){try{t.detachPrimitive(ev.current)}catch(e){}ev.current=null}if(ig&&aZ.length){let e=new FourierOscillatorIndicator({windowSize:ib});t.attachPrimitive(e),ev.current=e}}},[ig,ib,aZ]),(0,n.useEffect)(()=>{let e=eh.current;if(!e)return;let t=[];
1if(eS.current&&t.push(eS.current),ek.current.forEach(e=>{e&&t.push(e)}),ek.current=[],t.forEach(t=>{try{e.removeSeries(t)}catch(e){}}),eS.current=null,!a0)return;let{vwapData:r,upperData:i,lowerData:n}=a0;if(!r.length)return;let o=e.addLineSeries({color:H.color,lineWidth:1.5,title:"Anchored VWAP",priceLineVisible:!1});o.setData(r),eS.current=o;let l={color:"rgba(245,158,11,".concat(H.bandOpacity,")"),lineWidth:1,lineStyle:2,priceLineVisible:!1,lastValueVisible:!1},a=e.addLineSeries({...l,title:"VWAP Upper"}),s=e.addLineSeries({...l,title:"VWAP Lower"});return a.setData(i),s.setData(n),ek.current=[a,s],()=>{let t=[];eS.current&&t.push(eS.current),ek.current.forEach(e=>{e&&t.push(e)}),t.forEach(t=>{try{e.removeSeries(t)}catch(e){}}),eS.current=null,ek.current=[]}},[a0]),(0,n.useEffect)(()=>{let e=eg.current,t=tF.current;if(e&&t)try{e.applyOptions({autoscaleInfoProvider:t})}catch(e){}},[tE]),(0,n.useEffect)(()=>{let resize=()=>{eh.current&&eu.current&&eh.current.applyOptions({width:eu.current.clientWidth,height:eu.current.clientHeight})};resize();let e=requestAnimationFrame(resize);return()=>cancelAnimationFrame(e)},[tJ,t$,tx,th,rm,tf]),(0,n.useEffect)(()=>{let handle=()=>{tv(!!document.fullscreenElement),window.setTimeout(()=>{eh.current&&eu.current&&eh.current.applyOptions({width:eu.current.clientWidth,height:eu.current.clientHeight})},0)};return document.addEventListener("fullscreenchange",handle),()=>document.removeEventListener("fullscreenchange",handle)},[]);let si=(0,n.useMemo)(()=>{if(!i4||aZ.length<2)return[];let e=Math.min(...aZ.map(e=>e.low)),t=Math.max(...aZ.map(e=>e.high)),r=Math.max(1e-9,Math.max(t-e,1e-9)/240),i={};aZ.forEach(e=>{let t=Math.floor(e.low/r),n=Math.floor(e.high/r),o=Math.max(1,n-t+1);for(let l=t;l<=n;l++)i[l]||(i[l]={price:l*r,volume:0}),i[l].volume+=(e.volume||0)/o});let n=Object.values(i).filter(e=>Number.isFinite(e.price)&&e.price>0),o=Math.max(...n.map(e=>e.volume),1e-9);return n.map(e=>({...e,percent:e.volume/o}))},[aZ,i4]);(0,n.useEffect)(()=>{let e=eh.current,t=eg.current,r=(null==t?void 0:t.priceScale)?t.priceScale():e?e.priceScale("right"):null;if(!e||!r||!i4)return;let handle=()=>{ni(e=>e+1),no(r.width())};return no(r.width()),"function"==typeof e.timeScale().subscribeVisibleTimeRangeChange&&e.timeScale().subscribeVisibleTimeRangeChange(handle),"function"==typeof r.subscribeSizeChange&&r.subscribeSizeChange(handle),()=>{try{"function"==typeof e.timeScale().unsubscribeVisibleTimeRangeChange&&e.timeScale().unsubscribeVisibleTimeRangeChange(handle)}catch(e){}try{"function"==typeof r.unsubscribeSizeChange&&r.unsubscribeSizeChange(handle)}catch(e){}}},[aZ,i4]),(0,n.useEffect)(()=>{let e=nl.current,t=eg.current;if(!e||!t||!i4||!si.length)return;let r=e.parentElement,i=(null==r?void 0:r.clientHeight)||y;e.width=80,e.height=i;let n=e.getContext("2d");n&&(n.clearRect(0,0,80,i),n.fillStyle="rgba(99,102,241,0.55)",si.forEach(e=>{let r=t.priceToCoordinate(e.price);if("number"!=typeof r)return;let i=80*e.percent;n.fillRect(80-i,r-1,i,2)}))},[si,i4,nr,y]),(0,n.useEffect)(()=>{let e=eg.current;if(!e||!g.length)return;let t=g[g.length-1];t[0];let r=g.length>1?Math.max(1,Math.floor((Number(t[0])-Number(g[g.length-2][0]))/1e3)):60,i="1m"===b?V["5s"]:V[b]||r;ov.current=i,ok.current=[],oS.current=[];let n=Number(t[4]),o=Math.floor(Date.now()/1e3);ow.current=Math.floor(o/r)*r,oy.current={time:Math.floor(o/i)*i,open:n,high:n,low:n,close:n},i===V["5s"]&&apply5sGlow(oy.current);try{e.update(oy.current)}catch(e){}},[g,b]),(0,n.useEffect)(()=>{"number"==typeof x&&x>0&&sr(x),ts.current=x,tc()},[x,sr]),(0,n.useEffect)(()=>{let e=window.setInterval(()=>{sr()},1e3);return()=>window.clearInterval(e)},[sr]);let sn=(0,n.useMemo)(()=>{var e,t;if(!eW.length)return 0;let r=V[b]||60,i=(null==eE?void 0:eE.time)?Number(eE.time):Number.POSITIVE_INFINITY,n=eW.map((e,t)=>{var i,n,o;let l=Number(null!==(o=null!==(n=null!==(i=e.opened_at)&&void 0!==i?i:e.openedAt)&&void 0!==n?n:e.created_at)&&void 0!==o?o:e.createdAt);return Number.isFinite(l)?{position:e,index:t,openedAt:Math.floor((l>1e10?Math.floor(l/1e3):l)/r)*r}:{position:e,index:t,openedAt:-1}}).filter(e=>e.openedAt>=0&&e.openedAt<=i).sort((e,t)=>
1t.openedAt-e.openedAt);return null!==(t=null===(e=n[0])||void 0===e?void 0:e.index)&&void 0!==t?t:0},[eW,eE,b]),so=(0,n.useMemo)(()=>{var e,t,r,i;if(!e5||!eW.length)return null;let n=null!=eO?eO:sn,o=eW[n];if(!o)return null;let l=Number(null!==(i=null!==(r=null!==(t=o.opened_at)&&void 0!==t?t:o.openedAt)&&void 0!==r?r:o.created_at)&&void 0!==i?i:o.createdAt),a=Number.isFinite(l)&&l>1e10?Math.floor(l/1e3):l,s="long"===o.side||(null===(e=o.side)||void 0===e?void 0:e.long)?"long":"short",d="number"==typeof o.entryUsd&&Number.isFinite(o.entryUsd)?o.entryUsd:toPrice(o.entry_price),c=toPrice(o.liquidation_price),u=o.stop_loss?toPrice(o.stop_loss):0,p=o.take_profit?toPrice(o.take_profit):0,h="number"==typeof o.notionalUsd?o.notionalUsd:Number(o.notional||0)/1e6,g="number"==typeof o.collateralUsd?o.collateralUsd:Number(o.collateral||0)/1e6,x="number"==typeof o.pnlUsd?o.pnlUsd:"number"==typeof o.marketPnlUsd?o.marketPnlUsd:0,b="number"==typeof o.effectiveLeverageUsd&&Number.isFinite(o.effectiveLeverageUsd)?o.effectiveLeverageUsd:"number"==typeof o.effective_leverage&&Number.isFinite(o.effective_leverage)?Number(o.effective_leverage):"number"==typeof o.leverage&&Number.isFinite(o.leverage)?Number(o.leverage):g>0?h/g:0;return{...o,_index:n,_openedAt:a,_side:s,_entry:d,_liq:c,_sl:u,_tp:p,_notional:h,_collateral:g,_pnl:x,_pnlPct:g>0?x/g*100:0,_effectiveLeverage:b}},[e5,eW,eO,sn]);(0,n.useEffect)(()=>{if(ta.current=so,so&&Number.isFinite(so._openedAt)&&aZ.length){let e=V[b]||60,t=Math.floor(so._openedAt/e)*e,r=[...aZ].reverse().find(e=>e.time<=t);td.current=r?r.time:t}else td.current=null;tc()},[so,aZ,b]);let getRiskLevelsForPosition=e=>{var t,r,i,n,o;if(!e)return{stopLoss:0,takeProfit:0};let l=e._side||("long"===e.side||(null===(t=e.side)||void 0===t?void 0:t.long)?"long":"short"),a=null!==(r=e._entry)&&void 0!==r?r:"number"==typeof e.entryUsd&&Number.isFinite(e.entryUsd)?e.entryUsd:toPrice(e.entry_price),s=null!==(i=e._liq)&&void 0!==i?i:toPrice(e.liquidation_price),d=null!==(n=e._sl)&&void 0!==n?n:e.stop_loss?toPrice(e.stop_loss):0,c=null!==(o=e._tp)&&void 0!==o?o:e.take_profit?toPrice(e.take_profit):0,u=Math.max(Math.abs(a-s),.01*a);return{stopLoss:d>0?d:"long"===l?a-.5*u:a+.5*u,takeProfit:c>0?c:"long"===l?a+u:a-u}},findRiskLevelAtPoint=e=>{let t=eg.current,r=eu.current;if(!t||!r||!so)return null;let i=r.getBoundingClientRect(),n=e-i.top,{stopLoss:o,takeProfit:l}=getRiskLevelsForPosition(so),a=[{positionId:String(so.id),level:"stop_loss",price:o},{positionId:String(so.id),level:"take_profit",price:l}],s=null,d=1/0;for(let e of a){let r=t.priceToCoordinate(e.price);if(null===r)continue;let i=Math.abs(r-n);i<d&&(s=e,d=i)}return s&&d<=12?s:null},findPositionAtPoint=e=>{let t=eg.current,r=eu.current;if(!t||!r||!e1.length)return null;let i=r.getBoundingClientRect(),n=e-i.top,o=null,l=1/0;for(let e of e1){e._side;let r=e._entry,i=e._liq,a=e._sl,s=e._tp,d=getRiskLevelsForPosition(e),c=a>0?a:e2?d.stopLoss:0,u=s>0?s:e2?d.takeProfit:0,p=[r,i,c,u].filter(e=>Number.isFinite(e)&&e>0);for(let r of p){let i=t.priceToCoordinate(r);if(null===i)continue;let a=Math.abs(i-n);a<l&&(o={positionId:String(e.id),price:r},l=a)}}return o&&l<=12?o.positionId:null},updateDraggedRiskLevel=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e6,r=eg.current,i=eu.current;if(!r||!i||!t||!Y)return;let n=i.getBoundingClientRect(),o=r.coordinateToPrice(e-n.top);"number"==typeof o&&Number.isFinite(o)&&o>0&&Y(t.positionId,t.level,o)};(0,n.useEffect)(()=>{var e,t,r;if(!eg.current)return;if(eM.current.forEach(e=>{try{eg.current.removePriceLine(e)}catch(e){}}),eM.current=[],eT.current){try{eg.current.detachPrimitive(eT.current)}catch(e){}eT.current=null}let i=[];if((!e5||!e1.length)&&(!on||!w.length)){null===(t=tN.current)||void 0===t||t.setLabels([]);return}let n=V[b]||60,o=e1.length>10,l=[],a=null;if(eP.current=null,e1.forEach((e,t)=>{var r,a,s,d;let c="long"===e.side||(null===(r=e.side)||void 0===r?void 0:r.long)?"long":"short",u=String(e.id)===k,p="long"===c?u?"rgba(34,197,94,0.95)":o?"rgba(34,197,94,0.15)":"rgba(34,197,94,0.35)":u?"rgba(239,68,68,0.95)":o?"rgba(239,68,68,0.15)":"rgba(239,68,68,0.35)",h="number"==typeof e.entryUsd&&Number.isFinite(e.entryUsd)?e.entryUsd:toPrice(e.entry_price),g=toPrice(e.liquidation_price),x=e.stop_loss?toPrice(e.stop_loss):0,b=e.take_profit?toPrice(e.take_profit):0,m=Number(null!==(d=null!==(s=null!==(a=e.opened_at)&&void 0!==a?a:e.openedAt)&&void 0!==s?s:e.created_at)&&void 0!==d?d:e.createdAt),y=Number.isFinite(m)&&m>1e10?Math.floor(m/1e3):m,v=eW.findIndex(t=>t===e),w=v>=0?v+1:t+1;if(h>
10){let e=eg.current.createPriceLine({price:h,color:p,lineWidth:1,lineStyle:0,axisLabelVisible:!0});eM.current.push(e),i.push({price:h,text:"".concat(c.toUpperCase()," ").concat(w),color:"long"===c?"#4ade80":"#f87171"}),u&&(eP.current=e)}g>0&&(eM.current.push(eg.current.createPriceLine({price:g,color:u?"rgba(245,158,11,0.45)":o?"rgba(245,158,11,0.08)":"rgba(245,158,11,0.2)",lineWidth:1,lineStyle:0,axisLabelVisible:!0})),i.push({price:g,text:"Liq ".concat(w),color:"#f59e0b"}));let S=getRiskLevelsForPosition({...e,_side:c,_entry:h,_liq:g,_sl:x,_tp:b}),j=x>0?x:e2?S.stopLoss:0,C=b>0?b:e2?S.takeProfit:0;if(j>0&&((null==e3?void 0:e3.positionId)===String(e.id)&&(null==e3||e3.level),(null==e6?void 0:e6.positionId)===String(e.id)&&(null==e6||e6.level),eM.current.push(eg.current.createPriceLine({price:j,color:u?"rgba(239,68,68,0.95)":o?"rgba(239,68,68,0.15)":"rgba(239,68,68,0.35)",lineWidth:1,lineStyle:0,axisLabelVisible:!0})),i.push({price:j,text:"".concat(e2&&x<=0?"Set ":"","SL ").concat(w),color:"#f87171"})),C>0&&((null==e3?void 0:e3.positionId)===String(e.id)&&(null==e3||e3.level),(null==e6?void 0:e6.positionId)===String(e.id)&&(null==e6||e6.level),eM.current.push(eg.current.createPrice
1Line({price:C,color:u?"rgba(34,197,94,0.45)":o?"rgba(34,197,94,0.08)":"rgba(34,197,94,0.2)",lineWidth:1,lineStyle:0,axisLabelVisible:!0})),i.push({price:C,text:"".concat(e2&&b<=0?"Set ":"","TP ").concat(w),color:"#4ade80"})),Number.isFinite(y)&&y>0&&h>0){let e="".concat(f," Position #").concat(w," ").concat("long"===c?"Long":"Short");l.push({openedAt:Math.floor(y/n)*n,entryPrice:h,liquidationPrice:g>0?g:void 0,takeProfit:b>0?b:void 0,side:"long"===c?"LONG":"SHORT",label:e})}}),on&&w.length&&w.forEach((e,t)=>{var r,o;let a="long"===e.side||(null===(r=e.side)||void 0===r?void 0:r.long)?"long":"short",s=toPrice(e.limit_price),d=Number(e.leverage),c=s>0&&d>0?(0,D.jO)(s,d,a):0,u=e.stop_loss_pct?Number(e.stop_loss_pct):0,p=e.take_profit_pct?Number(e.take_profit_pct):0,h=s>0&&u>0?"long"===a?s*(1-u):s*(1+u):0,g=s>0&&p>0?"long"===a?s*(1+p):s*(1-p):0,x="long"===a?"rgba(34,197,94,0.5)":"rgba(239,68,68,0.5)",b=t+1;s>0&&(eM.current.push(eg.current.createPriceLine({price:s,color:x,lineWidth:1,lineStyle:1,axisLabelVisible:!0})),i.push({price:s,text:"LIMIT ".concat(a.toUpperCase()," ").concat(b),color:"long"===a?"#4ade80":"#f87171"})),c>
10&&(eM.current.push(eg.current.createPriceLine({price:c,color:"rgba(245,158,11,0.45)",lineWidth:1,lineStyle:1,axisLabelVisible:!0})),i.push({price:c,text:"LIMIT Liq ".concat(b),color:"#f59e0b"})),h>0&&(eM.current.push(eg.current.createPriceLine({price:h,color:"rgba(239,68,68,0.45)",lineWidth:1,lineStyle:1,axisLabelVisible:!0})),i.push({price:h,text:"LIMIT SL ".concat(b),color:"#f87171"})),g>0&&(eM.current.push(eg.current.createPriceLine({price:g,color:"rgba(34,197,94,0.45)",lineWidth:1,lineStyle:1,axisLabelVisible:!0})),i.push({price:g,text:"LIMIT TP ".concat(b),color:"#4ade80"}));let m=Number(null!==(o=e.created_at)&&void 0!==o?o:e.createdAt),y=Number.isFinite(m)&&m>1e10?Math.floor(m/1e3):m;if(Number.isFinite(y)&&y>0&&s>0){let t=Number(e.collateral)/1e6*d,r="".concat(f," Limit #").concat(b," ").concat("long"===a?"Long":"Short").concat(t>0?" $".concat(t.toFixed(2)):"").concat(d>0?", ".concat(d.toString(),"x"):""),i=e.trailing_stop_pct?Number(e.trailing_stop_pct):0,o=i>0&&s>0?"long"===a?s*(1-i):s*(1+i):void 0;l.push({openedAt:Math.floor(y/n)*n,entryPrice:s,liquidationPrice:c>0?c:void 0,takeProfit:g>0?g:void 0,trailingStop:o,side:"long"===a?"LONG":"SHORT",label:r})}}),l.length){let e=new PositionZonesIndicator;eg.current.attachPrimitive(e),e.setPositionZones(l);let t=e1.findIndex(e=>String(e.id)===k);e.setHighlight(o,t>=0?t:null),eT.current=e}if(null===(e=tN.current)||void 0===e||e.setLabels(i),k&&eP.current){let e=e1.find(e=>String(e.id)===k),t=e&&("long"===e.side||(null===(r=e.side)||void 0===r?void 0:r.long))?"long":"short",i="long"===t?"34,197,94":"239,68,68",pulse=()=>{if(!eP.current)return;let e=Date.now()/300;eP.current.applyOptions({color:"rgba(".concat(i,", ").concat(.55+.4*(.5+.5*Math.sin(e)),")"),lineWidth:1}),a=requestAnimationFrame(pulse)};a=requestAnimationFrame(pulse)}return()=>{a&&cancelAnimationFrame(a),eP.current=null}},[e5,e1,eW,e2,e3,e6,k,f,on,w,b,ol]),(0,n.useEffect)(()=>{var e,t,r;let i=eg.current;if(!i)return;if(null==ec||!aZ.length){if(eR.current){try{i.detachPrimitive(eR.current)}catch(e){}eR.current=null}return}let n=Math.max(1,Math.min(Math.round(ec),aZ.length)),o=null===(e=aZ[aZ.length-n])||void 0===e?void 0:e.time;if(null!=o){if(!eR.current||eR.current.series!==i){if(eR.current)try{null===(r=eR.current.series)||void 0===r||null===(t=r.detachPrimitive)||void 0===t||t.call(r,eR.current)}catch(e){}eR.current=new LookbackHighlightPrimitive;try{i.attachPrimitive(eR.current)}catch(e){}}eR.current.setStartTime(o)}},[ec,aZ,ol]),(0,n.useEffect)(()=>{if(!eg.current)return;if(ez.current.forEach(e=>{try{eg.current.removePriceLine(e)}catch(e){}}),ez.current=[],eI.current){try{eg.current.detachPrimitive(eI.current)}catch(e){}eI.current=null}if(!(null==le?void 0:le.open))return;let e=le.side,t=le.price;if("limit"===lj){if("single"===l_){let e=Number(lP);Number.isFinite(e)&&e>0&&(t=e)}else if(lR&&lI){let e=Number(lR),r=Number(lI);Number.isFinite(e)&&Number.isFinite(r)&&e>0&&r>e&&(t=(e+r)/2)}}if(!Number.isFinite(t)||t<=0)return;let r=(0,D.jO)(t,ln,e),i=lc?"long"===e?t*(1+lp/100/ln):t*(1-lp/100/ln):void 0,n=lb?"long"===e?t-(t-r)*(lm/100):t+(r-t)*(lm/100):void 0,o=x&&Number.isFinite(x)?x:t,l="long"===e?Math.max(t,o):Math.min(t,o),a=lv?"long"===e?l*(1-lS/100/ln):l*(1+lS/100/ln):void 0,s="long"===e?"#22c55e":"#f87171";t>
10&&ez.current.push(eg.current.createPriceLine({price:t,color:s,lineWidth:1,title:"Entry Preview",axisLabelVisible:!0})),r&&Number.isFinite(r)&&r>0&&ez.current.push(eg.current.createPriceLine({price:r,color:"#ef4444",lineWidth:1,title:"Liq Preview",axisLabelVisible:!0})),i&&Number.isFinite(i)&&i>0&&ez.current.push(eg.current.createPriceLine({price:i,color:"#22c55e",lineWidth:1,title:"TP Preview",axisLabelVisible:!0})),n&&Number.isFinite(n)&&n>0&&ez.current.push(eg.current.createPriceLine({price:n,color:"#f87171",lineWidth:1,title:"SL Preview",axisLabelVisible:!0}));let d=aZ.length?aZ[aZ.length-1].time:Math.floor(Date.now()/1e3),c=[{openedAt:d,entryPrice:t,liquidationPrice:Number.isFinite(r)&&r>0?r:void 0,takeProfit:i&&Number.isFinite(i)&&i>0?i:void 0,trailingStop:a&&Number.isFinite(a)&&a>0?a:void 0,side:"long"===e?"LONG":"SHORT",label:"Preview",animated:!0}],u=new PositionZonesIndicator;eg.current.attachPrimitive(u),u.setPositionZones(c),eI.current=u},[le,lj,l_,lP,lR,lI,lD,ln,lc,lp,lb,lm,lv,lS,aZ,x]),(0,n.useEffect)(()=>{let e=eg.current;if(!e||(a$.current.forEach(t=>{try{e.removePriceLine(t)}catch(e){}}),a$.current=[],!(null==le?void 0:le.open)||"limit"!==lj||"off"===lA))return;if("single"===lA){let t=Number(lP);Number.isFinite(t)&&t>
10&&a$.current.push(e.createPriceLine({price:t,color:"#a78bfa",lineWidth:1,lineStyle:2,title:"Pick Limit",axisLabelVisible:!0}));return}let t=Number(lR),r=Number(lI);Number.isFinite(t)&&t>0&&a$.current.push(e.createPriceLine({price:t,color:"#34d399",lineWidth:1,lineStyle:2,title:"Grid Low",axisLabelVisible:!0})),Number.isFinite(r)&&r>0&&a$.current.push(e.createPriceLine({price:r,color:"#34d399",lineWidth:1,lineStyle:2,title:"Grid High",axisLabelVisible:!0}))},[le,lj,lA,lP,lR,lI]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(!e||!t)return;let handler=e=>{if(!(null==le?void 0:le.open)||"limit"!==lj||"off"===lA)return;let r=e.point;if(!r||null==r.x||null==r.y)return;let i=t.coordinateToPrice(r.y);if(null==i||!Number.isFinite(i)||i<=0)return;let n=i>=100?i.toFixed(2):i.toFixed(4);if("single"===lA){lT(n),lF("off");return}};return e.subscribeClick(handler),()=>{e.unsubscribeClick(handler)}},[le,lj,lA]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(!e||!t||!(null==lN?void 0:lN.open)||!lV)return;let handler=e=>{if(!(null==lN?void 0:lN.open)||!lV)return;let r=e.point;if(!r||null==r.x||null==r.y)return;let i=t.coordinateToPrice(r.y);if(null==i||!Number.isFinite(i)||i<=0)return;let n=i>=100?i.toFixed(2):i.toFixed(4);lO(n),lU(!1)};return e.subscribeClick(handler),()=>{e.unsubscribeClick(handler)}},[null==lN?void 0:lN.open,lV]),(0,n.useEffect)(()=>{let e=eh.current;if(!e||!l2||os)return;let removePreview=()=>{if(ej.current){try{e.removeSeries(ej.current)}catch(e){}ej.current=null}eC.current.forEach(t=>{if(t)try{e.removeSeries(t)}catch(e){}}),eC.current=[]},getTime=e=>null==e?null:"number"==typeof e?e:Math.floor(new Date(e).getTime()/1e3),t=!1,r=null,moveHandler=i=>{var n,o,l,a,s;if(t)return;let d=null!==(l=i.time)&&void 0!==l?l:e.timeScale().coordinateToTime(null!==(o=null===(n=i.point)||void 0===n?void 0:n.x)&&void 0!==o?o:0),c=getTime(d);if(null==c||!aZ.length||c===r)return;let{vwapData:u,upperData:p,lowerData:h}=calculateAnchoredVwap(aZ,c);if(!ej.current){let t=e.addLineSeries({color:"#f59e0b",lineWidth:1.5,lineStyle:2,title:"Anchored VWAP Preview",priceLineVisible:!1,lastValueVisible:!1,autoscaleInfoProvider:()=>null});ej.current=t;let r={color:"rgba(245,158,11,0.25)",lineWidth:1,lineStyle:2,priceLineVisible:!1,lastValueVisible:!1,autoscaleInfoProvider:()=>null},i=e.addLineSeries({...r,title:"VWAP Upper Preview"}),n=e.addLineSeries({...r,title:"VWAP Lower Preview"});eC.current=[i,n]}r=c,t=!0;try{ej.current.setData(u),null===(a=eC.current[0])||void 0===a||a.setData(p),null===(s=eC.current[1])||void 0===s||s.setData(h)}finally{t=!1}},clickHandler=t=>{var r,i,n;if(!l2)return;let o=null!==(n=t.time)&&void 0!==n?n:e.timeScale().coordinateToTime(null!==(i=null===(r=t.point)||void 0===r?void 0:r.x)&&void 0!==i?i:0),l=getTime(o);null!=l&&(l8(l),l4(!1),l1(!0))};return e.subscribeCrosshairMove(moveHandler),e.subscribeClick(clickHandler),()=>{e.unsubscribeCrosshairMove(moveHandler),e.unsubscribeClick(clickHandler),removePreview()}},[l2,aZ,os]),(0,n.useEffect)(()=>{if(!eg.current)return;if(lJ.current){try{eg.current.removePriceLine(lJ.current)}catch(e){}lJ.current=null}if(!(null==lN?void 0:lN.open))return;let e=Number(lW);if(!Number.isFinite(e)||e<=0)return;let t="stop_loss"===lN.level;
1return lJ.current=eg.current.createPriceLine({price:e,color:t?"#f87171":"#4ade80",lineWidth:1,lineStyle:2,title:t?"Stop Loss":"Take Profit",axisLabelVisible:!0}),()=>{if(lJ.current&&eg.current){try{eg.current.removePriceLine(lJ.current)}catch(e){}lJ.current=null}}},[null==lN?void 0:lN.open,null==lN?void 0:lN.level,lW]),(0,n.useEffect)(()=>{if(!lX)return;let onMove=e=>lK({x:e.clientX-lX.offsetX,y:e.clientY-lX.offsetY}),onUp=()=>lG(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[lX]),(0,n.useEffect)(()=>{"limit"!==lj&&lF("off")},[lj]),(0,n.useEffect)(()=>{"grid"!==l_?(l$(null),l0(null),"grid"===lA&&lF("off")):"single"===lA&&lF("off")},[l_,lA]),(0,n.useEffect)(()=>{let e=ou.current;if(e){if("ai-analyse"===nh){e.setTool("none"),e.setStayInDrawingMode(!1);return}e.setTool(nh),e.setStayInDrawingMode("none"!==nh)}},[nh]),(0,n.useEffect)(()=>{"ai-analyse"===nh&&(nb(null),nm(null),nS(""),nj(""),nN([]),nA(""),nV(""),nq.current=null,eB.current=null)},[nh]);let sl=(0,n.useCallback)(()=>{var e;null===(e=ou.current)||void 0===e||e.setDrawings([...oc.current,...nX.current,...nY.current])},[]);(0,n.useEffect)(()=>{if(!nJ||!n2){n5(null);return}let e=symbolToGexCurrency(f);if(!e)return;let t=!1,r=new AbortController,load=()=>{fetchGexProfile(e,r.signal).then(e=>{t||n5(e)}).catch(()=>{t||n5(null)})};load();let i=window.setInterval(load,6e4);return()=>{t=!0,r.abort(),window.clearInterval(i)}},[nJ,n2,f]),(0,n.useEffect)(()=>{if(!eg.current)return;if(n1.current){try{eg.current.detachPrimitive(n1.current)}catch(e){}n1.current=null}if(!nJ||!n0)return;let e=new GexLevelsIndicator;eg.current.attachPrimitive(e),e.setProfile(n0),n1.current=e},[nJ,n0,aZ]),(0,n.useEffect)(()=>{if(!eg.current)return;if(n8.current){try{eg.current.detachPrimitive(n8.current)}catch(e){}n8.current=null}if(!n4||!_&&!(M&&M.length))return;let e=new LiqHeatmapIndicator;eg.current.attachPrimitive(e),e.setHeatmap(_),e.setRealized(M||[]),n8.current=e},[n4,_,aZ]),(0,n.useEffect)(()=>{var e;null===(e=n8.current)||void 0===e||e.setRealized(M||[])},[M]),(0,n.useEffect)(()=>{if(eh.current&&(op.current.forEach(e=>{let{series:t}=e;try{eh.current.removeSeries(t)}catch(e){}}),op.current=[],(null==tC?void 0:tC.overlay)!==!1&&(tw.forEach(e=>{var t,r,i;if(!1===e.visible||!e.data||!e.data.length)return;let n=null===(t=e.options)||void 0===t?void 0:t.style;if("shape"===n||"fill"===n||"hline"===n||"char"===n||"candle"===n||(null===(r=e.options)||void 0===r?void 0:r.display)==="none"||(null===(i=e.options)||void 0===i?void 0:i.display)==="pane")return;let o=e.data.filter(e=>null!==e.value&&void 0!==e.value&&Number.isFinite(Number(e.value))).map(e=>{var t;return{time:Math.floor(e.time/1e3),value:Number(e.value),color:null===(t=e.options)||void 0===t?void 0:t.color}});if(!o.length)return;let l=e.options||{},a=l.color||"#fff",s="style_stepline"===l.linestyle?1:0,d=Number(l.linewidth)||1,c=[];for(let e of o){let t=e.color||a,r=c[c.length-1];if(r&&r.color===t)r.data.push(e);else{let i={color:t,data:[e]};r&&r.data.length&&i.data.unshift(r.data[r.data.length-1]),c.push(i)}}c.forEach((t,r)=>{let i=withAlpha(OpenChartsPro_hexToRgba(t.color),tM),n=eh.current.addLineSeries({color:i,lineWidth:d,title:0===r?e.title||e._plotKey||"Pine":"",priceScaleId:ak?"right":"pine-overlay",lineType:s,priceLineVisible:!1,lastValueVisible:r===c.length-1,autoscaleInfoProvider:()=>null});n.setData(t.data.map(e=>{let{time:t,value:r}=e;return{time:t,value:r}})),op.current.push({series:n,title:e.title||e._plotKey,plot:e,color:i})})}),tT&&op.current.length>=2&&aZ.length))){let e=new Map;tw.forEach(t=>{let r=(null==t?void 0:t.title)||(null==t?void 0:t._plotKey);r&&!e.has(r)&&e.set(r,{plot:t,series:null})}),op.current.forEach(t=>{var r,i;let n=(null===(r=t.plot)||void 0===r?void 0:r.title)||(null===(i=t.plot)||void 0===i?void 0:i._plotKey);n&&e.set(n,{plot:t.plot,series:t.series,color:t.color})});let t=tw.filter(e=>{var t,r,i;return(null==e?void 0:null===(t=e.options)||void 0===t?void 0:t.style)==="fill"&&(null===(r=e.options)||void 0===r?void 0:r.plot1)&&(null===(i=e.options)||void 0===i?void 0:i.plot2)&&!1!==e.visible}),r=[];if(t.length)t.forEach(t=>{var i;let n=e.get(t.options.plot1),o=e.get(t.options.plot2);
1if(!n||!o)return;let l=n.series?n:o,a=n.series?o:n;if(!l.series)return;let s=Array.isArray(t.data)?t.data:[],d=[...s].reverse().find(e=>{var t;return null==e?void 0:null===(t=e.options)||void 0===t?void 0:t.color});r.push({a:l,b:a,fillColor:(null==d?void 0:null===(i=d.options)||void 0===i?void 0:i.color)||t.options.color})});else{let e=new Map,t=[];aZ.forEach(r=>{e.set(Math.floor(r.time),Number(r.close)),t.push(Number(r.close))});let i=t.slice().sort((e,t)=>e-t),n=i[Math.floor(i.length/2)]||0,o=op.current.filter(t=>{let{plot:r}=t;return function(e,t,r){var i;if(!e||!Array.isArray(e.data)||(null===(i=e.options)||void 0===i?void 0:i.style)==="shape")return!1;let n=[];for(let r of e.data){let e=Number(r.value);if(!Number.isFinite(e))continue;let i=t.get(Math.floor(r.time/1e3));if(void 0!==i&&(n.push({t:r.time,v:e,c:i}),n.length>=500))break}if(n.length<10)return!1;let o=n.map(e=>e.v).sort((e,t)=>e-t),l=o[Math.floor(o.length/2)];if(!(r>0)||l/r<.05||l/r>20)return!1;let a=n.length,s=0,d=0;for(let e of n)s+=e.v,d+=e.c;let c=s/a,u=d/a,p=0,h=0,g=0;for(let e of n){let t=e.v-c,r=e.c-u;p+=t*r,h+=t*t,g+=r*r}if(h<=0||g<=0)return!1;let x=p/Math.sqrt(h*g);return x>.5}(r,e,n)});for(let e=0;e+1<o.length;e++)r.push({a:o[e],b:o[e+1]})}for(let{a:e,b:t,fillColor:i}of r){let r;let n=new Map;(t.plot.data||[]).forEach(e=>{let t=Number(e.value);Number.isFinite(t)&&n.set(Math.floor(e.time/1e3),t)});let o=[];if((e.plot.data||[]).forEach(e=>{let t=Number(e.value);if(!Number.isFinite(t))return;let r=n.get(Math.floor(e.time/1e3));void 0!==r&&o.push({time:Math.floor(e.time/1e3),v1:t,v2:r})}),!(o.length<2)){if(i){let[e,t,n]=parseRgb(i),o=i.match(/rgba?\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\s*\)/),l=o?parseFloat(o[1]):.18;r="rgba(".concat(e,",").concat(t,",").concat(n,",").concat(l*tM,")")}else{let[i,n,o]=parseRgb(e.color),[l,a,s]=parseRgb(t.color);r="rgba(".concat(Math.round((i+l)/2),",").concat(Math.round((n+a)/2),",").concat(Math.round((o+s)/2),",").concat(.18*tM,")")}try{e.series.attachPrimitive(new PineZonePrimitive(o,r))}catch(e){}}}}},[tw,tM,tT,aZ,tC,ak]);let sa=(null==tC?void 0:tC.overlay)===!1;function unquotePineString(e){let t=e.trim(),r=t.match(/^"([^"]*)"$/)||t.match(/^'([^']*)'$/);return r?r[1]:null}function updateInputInCode(e,t,r,i){let n=e.split("\n"),o=RegExp("^\\s*(?:\\w+\\s+)?"+t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\s*=\\s*input\\."+i+"\\s*\\(");for(let e=0;e<n.length;e++){let t=n[e];if(!o.test(t))continue;let l=t.indexOf("(");if(-1===l)continue;let a=l+1;for(;a<t.length&&(" "===t[a]||"	"===t[a]);)a++;let s=a,d=null,c=-1;for(;s<t.length;){let e=t[s];if(d)e===d&&(d=null);else if('"'===e||"'"===e)d=e;else if(","===e||")"===e){c=s;break}s++}if(-1===c)continue;let u=String(r);"string"===i&&(u=JSON.stringify(r)),n[e]=t.slice(0,a)+u+t.slice(c)}return n.join("\n")}(0,n.useEffect)(()=>{if(!sa&&ox.current){ox.current.__unsubscribeSync&&ox.current.__unsubscribeSync(),ox.current.__resizeObserver&&ox.current.__resizeObserver.disconnect();try{ox.current.remove()}catch(e){}ox.current=null,ob.current=[]}},[sa]),(0,n.useEffect)(()=>{let e=og.current;if(!sa||!e||0===tw.length)return;let t=!ox.current||!e.contains(ox.current.chartElement());if(t){var r;if(ox.current){try{ox.current.remove()}catch(e){}ox.current=null,ob.current=[]}ox.current=(0,a.C2)(e,{layout:{background:{type:"solid",color:"transparent"},textColor:"#d1d4dc"},grid:{vertLines:{color:"rgba(255,255,255,0.05)"},horzLines:{color:"rgba(255,255,255,0.05)"}},crosshair:{mode:a.rM.Normal},rightPriceScale:{borderColor:"rgba(255,255,255,0.1)"},leftPriceScale:{visible:!1},timeScale:{visible:!1,borderVisible:!1,rightOffset:0},handleScroll:!ak,handleScale:!ak}),ox.current.applyOptions({width:e.clientWidth,height:e.clientHeight});let syncToSub=()=>{var e;if(!aC.current)return;let t=null===(e=eh.current)||void 0===e?void 0:e.timeScale().getVisibleLogicalRange();t&&ox.current&&ox.current.timeScale().setVisibleLogicalRange(t)},syncToMain=()=>{var e;if(!aC.current)return;let t=null===(e=ox.current)||void 0===e?void 0:e.timeScale().getVisibleLogicalRange();t&&eh.current&&eh.current.timeScale().setVisibleLogicalRange(t)};null===(r=eh.current)||void 0===r||r.timeScale().subscribeVisibleTimeRangeChange(syncToSub),ox.current.timeScale().subscribeVisibleTimeRangeChange(syncToMain),ox.current.__unsubscribeSync=()=>{var e,t;null===(e=eh.current)||void 0===e||e.timeScale().unsubscribeVisibleTimeRangeChange(syncToSub),null===(t=ox.current)||void 0===t||t.timeScale().unsubscribeVisibleTimeRangeChange(syncToMain)},syncToSub();let t=new ResizeObserver(()=>{ox.current&&og.current&&ox.current.applyOptions({width:og.current.clientWidth,height:og.current.clientHeight})});t.observe(e),ox.current.__resizeObserver=t}
1ob.current.forEach(e=>{let{series:t}=e;try{var r;null===(r=ox.current)||void 0===r||r.removeSeries(t)}catch(e){}}),ob.current=[],tw.forEach(e=>{var t;if(!1===e.visible||!e.data||!e.data.length||(null===(t=e.options)||void 0===t?void 0:t.style)==="shape")return;let r=e.data.filter(e=>null!==e.value&&void 0!==e.value&&Number.isFinite(Number(e.value))).map(e=>({time:Math.floor(e.time/1e3),value:Number(e.value)}));if(!r.length)return;let i=e.options||{},n=withAlpha(OpenChartsPro_hexToRgba(i.color||"#fff"),tM),o="style_stepline"===i.linestyle?1:0,l=ox.current.addLineSeries({color:n,lineWidth:1,title:e.title||e._plotKey||"Pine",lineType:o});l.setData(r),ob.current.push({series:l,title:e.title||e._plotKey})})},[sa,tw,tM]),(0,n.useEffect)(()=>{if(!eg.current||(oh.current.forEach(e=>{try{eg.current.detachPrimitive(e)}catch(e){}}),oh.current=[],!tk||!aZ.length))return;let e=aZ.length>1?aZ[1].time-aZ[0].time:60,attach=(t,r)=>{if(!r||!r.length)return;let i=new t(r,aZ,e);try{eg.current.attachPrimitive(i),oh.current.push(i)}catch(e){}};attach(PineLinePrimitive,tk.lines),attach(PinePolylinePrimitive,tk.polylines),attach(PineLabelPrimitive,tk.labels),attach(PineBackgroundPrimitive,tk.backgrounds),(tk.linefills||[]).forEach(t=>{if(!t||!t.line1||!t.line2||!t.color)return;let r=t.line1,i=t.line2,n=Math.min(r.x1,r.x2,i.x1,i.x2),o=Math.max(r.x1,r.x2,i.x1,i.x2),l=timeAtIndex(aZ,e,n),a=timeAtIndex(aZ,e,o);if(null==l||null==a)return;let lineY=(e,t)=>e.x2===e.x1?e.y1:e.y1+(t-e.x1)*(e.y2-e.y1)/(e.x2-e.x1),s=lineY(r,n),d=lineY(i,n),c=lineY(r,o),u=lineY(i,o);if(![s,d,c,u].every(e=>Number.isFinite(e)))return;let p=OpenChartsPro_hexToRgba(t.color,"rgba(59,130,246,0.25)"),h=new PineZonePrimitive([{time:l,v1:s,v2:d},{time:a,v1:c,v2:u}],p);try{eg.current.attachPrimitive(h),oh.current.push(h)}catch(e){}}),nX.current=(tk.boxes||[]).map(t=>(function(e,t,r){if(!e||e._deleted)return null;let i=timeAtIndex(t,r,e.left),n=timeAtIndex(t,r,e.right);if(null==i||null==n)return null;let o=e.border_color?OpenChartsPro_hexToRgba(e.border_color,"#fff"):"#fff",l=e.bgcolor?OpenChartsPro_hexToRgba(e.bgcolor,"rgba(0,0,0,0)"):"rgba(0,0,0,0)";return{id:"pine-box-".concat(e.id),type:"rectangle",time:i,time2:n,price:e.top,price2:e.bottom,color:o,fillColor:l,fillOpacity:1,width:e.border_width||1,lineStyle:({style_solid:"solid",style_dashed:"dashed",style_dotted:"dotted"})[e.border_style]||"solid",text:e.text||"",fontSize:({tiny:10,small:12,normal:14,large:16,huge:20})[e.text_size]||14,locked:!1,zIndex:1}})(t,aZ,e)).filter(Boolean),sl()},[tk,aZ,tT]);let setPineInputValue=(e,t,r)=>{ro(r=>({...r,[e]:t})),tX(i=>updateInputInCode(i,e,t,r))},renderPineInput=e=>{var t,r,n,o,l;return(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},title:e.name,children:e.title}),"bool"===e.type?(0,i.jsx)("input",{type:"checkbox",checked:!!rn[e.name],onChange:t=>setPineInputValue(e.name,t.target.checked,e.type)}):"string"===e.type&&(null===(t=e.options)||void 0===t?void 0:t.length)?(0,i.jsx)("select",{value:String(null!==(r=rn[e.name])&&void 0!==r?r:""),onChange:t=>setPineInputValue(e.name,t.target.value,e.type),style:{width:"100%",padding:"4px 6px",borderRadius:"4px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(0,0,0,0.4)",color:"#fff"},children:e.options.map(e=>(0,i.jsx)("option",{value:e,children:e},e))}):"string"===e.type?(0,i.jsx)("input",{type:"text",value:String(null!==(n=rn[e.name])&&void 0!==n?n:""),onChange:t=>setPineInputValue(e.name,t.target.value,e.type),style:{width:"100%",padding:"4px 6px",borderRadius:"4px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(0,0,0,0.2)",color:"#fff"}}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("input",{type:"range",min:e.min,max:e.max,step:e.step,value:Number(null!==(o=rn[e.name])&&void 0!==o?o:0),onChange:t=>setPineInputValue(e.name,Number(t.target.value),e.type),style:{width:"100%"}}),(0,i.jsx)("div",{style:{fontSize:"10px",color:"rgba(255,255,255,0.5)",textAlign:"center"},children:null!==(l=rn[e.name])&&void 0!==l?l:0})]})]},e.name)},runSimulation=async()=>
1{if(tK&&0!==aZ.length){if(oL.current=!0,oE.current){oD.current=!0;return}oE.current=!0,tp(!0),tY(null);try{let e;let t=aZ.map(e=>({time:1e3*e.time,timestamp:1e3*e.time,open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume})),r=await fetch("/api/simulate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({symbol:f,timeframe:b,marketData:t,code:tK,inputs:{...rn,...rs.current}})}),i=await r.text();try{e=JSON.parse(i)}catch(e){throw Error(i.slice(0,300)||"Simulation failed")}if(!r.ok)throw Error((null==e?void 0:e.error)||i.slice(0,300)||"Simulation failed");tg(e.summary),tb(e.trades||[]),tS(t=>{let r=0===t.length||t.some(e=>!1!==e.visible);return(e.plots||[]).map((e,i)=>{let n=e.title||e._plotKey,o=n?t.find(e=>(e.title||e._plotKey)===n):t[i];return{...e,visible:!!r&&(!o||o.visible)}})}),tj(e.drawings||null),t_(e.indicator||null),null==T||T(e)}catch(e){tY((null==e?void 0:e.message)||"Simulation failed")}finally{oE.current=!1,tp(!1),oD.current&&(oD.current=!1,oF(e=>e+1))}}},ss=(0,n.useCallback)(async()=>{if((oj||rr)&&tK&&!oI.current&&aZ.length){oI.current=!0;try{var e;let t=oy.current,r=new Map;aZ.forEach(e=>{r.set(e.time,e)}),ok.current.forEach(e=>{r.set(e.time,e)}),t&&r.set(t.time,t);let i=Array.from(r.values()).sort((e,t)=>e.time-t.time),n=i.map(e=>({time:1e3*e.time,timestamp:1e3*e.time,open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume||0})),o=await fetch("/api/simulate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({symbol:f,timeframe:b,marketData:n,code:tK,inputs:{...rn,...rs.current}})});if(!o.ok)return;let l=await o.json();if(tS(e=>{let t=0===e.length||e.some(e=>!1!==e.visible);return(l.plots||[]).map((r,i)=>{let n=r.title||r._plotKey,o=n?e.find(e=>(e.title||e._plotKey)===n):e[i];return{...r,visible:!!t&&(!o||o.visible)}})}),tj(l.drawings||null),t_(l.indicator||null),null==T||T(l),!oj)return;let a=l.trades||[],s=l.openTrades||[],d=(null===(e=i[i.length-1])||void 0===e?void 0:e.time)||0,c=ov.current||60,toTs=e=>Math.floor(new Date(e).getTime()/1e3),u=[];for(let e of a){let t=toTs(e.time);Number.isNaN(t)||u.push({type:e.type,signal:e.signal,price:Number(e.price)||0,ts:t})}for(let e of s){let t=toTs(e.time);Number.isNaN(t)||u.push({type:e.type,signal:e.signal,price:Number(e.price)||0,ts:t})}if(!u.length)return;if(!oR.current){u.forEach(e=>oz.current.add("".concat(e.type,"-").concat(e.ts))),oR.current=!0;return}let p=u.filter(e=>{if(e.ts<d-2*c)return!1;let t="".concat(e.type,"-").concat(e.ts);return!oz.current.has(t)&&(oz.current.add(t),!0)});if(!p.length)return;let h=p.map(e=>{let t="".concat(e.type||""," ").concat(e.signal||"").toLowerCase(),r=t.includes("entry"),i=t.includes("long");return{isEntry:r,isLong:i,e}}).filter(e=>{let{isLong:t}=e;return!(t&&!oe||!t&&!or)}).map(e=>{let{isEntry:t,isLong:r,e:i}=e;return{id:"".concat(i.type,"-").concat(i.ts),action:t?"open":"close",side:r?"long":"short",price:i.price,time:i.ts,expiresAt:Date.now()+3e4}});if(!h.length)return;oM(e=>{let t=new Map;return[...e,...h].forEach(e=>t.set(e.action,e)),Array.from(t.values())})}catch(e){}finally{oI.current=!1}}},[oj,rr,tK,aZ,f,b,rn,rs,oe,or]);(0,n.useEffect)(()=>{oN.current=ss},[ss]),(0,n.useEffect)(()=>{R&&!tK&&loadStrategyCode(R)},[R,tK]),(0,n.useEffect)(()=>{z&&tK&&!rr&&ri(!0)},[z,tK,rr]),(0,n.useEffect)(()=>{oR.current=!1,oz.current=new Set,oj||oM([])},[oj,tK]),(0,n.useEffect)(()=>{if(!o_.length)return;let e=window.setInterval(()=>{let e=Date.now();oT(e),o5||oM(t=>t.filter(t=>t.expiresAt>e))},500);return()=>window.clearInterval(e)},[o_.length,o5]),(0,n.useEffect)(()=>{let onMove=e=>{let t=o3.current;t&&o8({x:Math.max(0,t.origX+(e.clientX-t.startX)),y:Math.max(0,t.origY+(e.clientY-t.startY))})},onUp=()=>{o3.current=null};return window.addEventListener("mousemove",onMove),window.addEventListener("mouseup",onUp),()=>{window.removeEventListener("mousemove",onMove),window.removeEventListener("mouseup",onUp)}},[]),(0,n.useEffect)(()=>{o9.current=null,o7.current=0},[rq]),(0,n.useEffect)(()=>{if(!rq||aZ.length<Math.max(rF,rB)+2)return;let e=OpenChartsPro_calculateEMA(aZ,rF).filter(e=>null!==e.value),t=OpenChartsPro_calculateEMA(aZ,rB).filter(e=>null!==e.value);if(e.length<2||t.length<2)return;let r=e[e.length-1],i=e[e.length-2],n=t[t.length-1],o=t[t.length-2];if(!r||!i||!n||!o||r.time!==n.time||i.time!==o.time)return;let l=r.value>n.value?"bullish":"bearish",a=i.value>o.value?"bullish":"bearish";if(null===o9.current){o9.current=l,o7.current=r.time;return}if(r.time!==o7.current&&(l!==a||l!==o9.current)){var s,d;let e="bullish"===l?"long":"short",t=null!==(d=null===(s=aZ[aZ.length-1])||void 0===s?void 0:s.close)&&void 0!==d?d:r.value,i="ema-alarm-".concat(r.time,"-").concat(l),n={id:i,side:e,action:"open",price:t,time:r.t
1ime,expiresAt:Date.now()+3e4};oM(e=>e.some(e=>e.id===i)?e:[...e,n]),o9.current=l,o7.current=r.time}},[rq,aZ,rF,rB]);let sd=(0,n.useMemo)(()=>oe&&or?tx:tx.filter(e=>{let t="".concat(e.type||""," ").concat(e.signal||"").toLowerCase(),r=t.includes("long"),i=t.includes("short");return oe&&r||or&&i}),[tx,oe,or]),sc=(0,n.useMemo)(()=>0===tw.length||tw.some(e=>!1!==e.visible),[tw]),su=(0,n.useMemo)(()=>sc?sd.map((e,t)=>{var r,i;let n=Math.floor(new Date(e.time).getTime()/1e3);if(Number.isNaN(n)||n<=0)return null;let o=tO===t;if(null===(r=e.type)||void 0===r?void 0:r.includes("Entry")){let t=e.type.includes("Long");return{time:n,position:t?"belowBar":"aboveBar",color:t?o?"#93c5fd":"#2196F3":o?"#fdba74":"#FF9800",shape:t?"arrowUp":"arrowDown",text:t?"Entry Long":"Entry Short",size:o?2:1}}if(null===(i=e.type)||void 0===i?void 0:i.includes("Exit")){let t="number"==typeof e.profit?e.profit:0;return{time:n,position:t>=0?"aboveBar":"belowBar",color:t>=0?o?"#86efac":"#0ecb81":o?"#fca5a5":"#f6465d",shape:"circle",text:t>0?"+$".concat(t.toFixed(0)):t<0?"-$".concat(Math.abs(t).toFixed(0)):"Exit",size:o?2:1}}return null}).filter(Boolean):[],[sd,tO,sc]),sp=(0,n.useMemo)(()=>{let e=[],t=0;for(let e=1;e<aZ.length;e++){let r=aZ[e].time-aZ[e-1].time;if(r>0){t=r;break}}return tw.forEach(r=>{if(!1===r.visible)return;let i=r.options||{};if("shape"!==i.style||!Array.isArray(r.data))return;let n=String(i.location||"").toLowerCase(),o=String(i.shape||"").toLowerCase(),l="abovebar"===n||"top"===n||"absolute"===n&&o.includes("down")?"aboveBar":"belowBar",a=o.includes("up")?"arrowUp":o.includes("down")?"arrowDown":o.includes("diamond")||o.includes("square")?"square":"circle",s=withAlpha(i.color?OpenChartsPro_hexToRgba(i.color):"belowBar"===l?"#0ecb81":"#f6465d",tM),d=Number.isFinite(Number(i.offset))?Number(i.offset):0;r.data.forEach(n=>{let o=n.value,c=!0===o||"number"==typeof o&&Number.isFinite(o);if(!c)return;let u=Math.floor(n.time/1e3)+d*t;Number.isFinite(u)&&!(u<=0)&&e.push({time:u,position:l,color:s,shape:a,text:i.text||r.title||"",size:1})})}),e},[tw,aZ,tM]);(0,n.useEffect)(()=>{if(eg.current){let e=[...su,...sp].sort((e,t)=>e.time-t.time);eg.current.setMarkers(e)}},[su,sp]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(!e||!t||0===sd.length)return;let handler=e=>{if(!e.time){tV(null);return}let t="number"==typeof e.time?e.time:Math.floor(new Date(e.time).getTime()/1e3),r=-1,i=1/0;sd.forEach((e,n)=>{let o=Math.floor(new Date(e.time).getTime()/1e3);if(Number.isNaN(o))return;let l=Math.abs(o-t);l<i&&l<=300&&(i=l,r=n)}),tV(r>=0?r:null)};return e.subscribeCrosshairMove(handler),()=>{e.unsubscribeCrosshairMove(handler)}},[sd]),(0,n.useEffect)(()=>{let e=eh.current,t=eg.current;if(!e||!t)return;let handler=e=>{var r,i;let n=null==e?void 0:null===(r=e.seriesData)||void 0===r?void 0:r.get(t);if(!(null==e?void 0:e.time)||!(null==e?void 0:e.point)||!n){eD(null),eA(null),eF.current&&(clearTimeout(eF.current),eF.current=null),eN.current=null;return}let o="number"==typeof e.time?e.time:Math.floor(new Date(e.time).getTime()/1e3),l=aZ.find(e=>e.time===o),a={...n,time:o,x:e.point.x,y:e.point.y,volume:null==l?void 0:l.volume};eD(a),eB.current=a,(null===(i=eN.current)||void 0===i?void 0:i.time)!==o&&(eF.current&&(clearTimeout(eF.current),eF.current=null),eA(null),eN.current=a,eF.current=setTimeout(()=>{eA(eN.current)},3e3))};return e.subscribeCrosshairMove(handler),()=>{e.unsubscribeCrosshairMove(handler),eF.current&&(clearTimeout(eF.current),eF.current=null)}},[aZ]),(0,n.useEffect)(()=>{if(!au)return;let onMove=e=>ac({x:e.clientX-au.offsetX,y:e.clientY-au.offsetY}),onUp=()=>ap(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[au]),(0,n.useEffect)(()=>{if(!af)return;let onMove=e=>ab({x:e.clientX-af.offsetX,y:e.clientY-af.offsetY}),onUp=()=>am(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[af]),(0,n.useEffect)(()=>
1{if(!aV)return;let onMove=e=>aO({x:e.clientX-aV.offsetX,y:e.clientY-aV.offsetY}),onUp=()=>aU(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[aV]),(0,n.useEffect)(()=>{if(!aY)return;let onMove=e=>{let t=aY.startOffsetX-(e.clientX-aY.startX),r=aY.startOffsetY+(e.clientY-aY.startY);aq({x:t,y:r})},onUp=()=>aK(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[aY]),(0,n.useEffect)(()=>{if(!aP)return;let onMove=e=>{let t=e.clientX-aP.offsetX,r=e.clientY-aP.offsetY;aB.current&&(Math.abs(t-aB.current.x)>2||Math.abs(r-aB.current.y)>2)&&(aN.current=!0),aM({x:t,y:r})},onUp=()=>aT(null);return window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp),()=>{window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)}},[aP]);let modifyStrategy=async()=>{if(rc.trim()){rh(!0),tY(null);try{let e;let t=await fetch("/api/modify-pinescript",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:tK,prompt:rc})}),r=await t.text();try{e=JSON.parse(r)}catch(e){throw Error(r.slice(0,300)||"Modify failed")}if(!t.ok)throw Error((null==e?void 0:e.error)||r.slice(0,300)||"Modify failed");if("string"!=typeof e.code)throw Error("Response did not include modified code");of.current=!0,tK&&(tG.current=tK),tX(e.code),rf(!0),ru("")}catch(e){tY((null==e?void 0:e.message)||"Modify failed")}finally{rh(!1)}}},startAiResize=e=>t=>{var r,i,n;t.preventDefault(),t.stopPropagation();let o=null!==(n=null!==(i=nT.h)&&void 0!==i?i:null===(r=nz.current)||void 0===r?void 0:r.offsetHeight)&&void 0!==n?n:0;nI.current={startX:t.clientX,startY:t.clientY,w:nT.w,h:o,posX:nC.x,corner:e};let onMove=e=>{let t=nI.current;if(!t)return;let r=e.clientX-t.startX,i=e.clientY-t.startY,n=Math.max(240,Math.min(720,"bl"===t.corner?t.w-r:t.w+r)),o=Math.max(180,Math.min(900,t.h+i));nR({w:n,h:o}),"br"===t.corner&&n_(e=>({x:t.posX+(n-t.w),y:e.y}))},onUp=()=>{nI.current=null,window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)};window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp)},sh=(0,n.useMemo)(()=>{let e=[];th&&e.push({key:"summary",label:"Strategy summary (P&L / win rate)",kind:"summary"}),(tw||[]).forEach((t,r)=>{var i,n;if(!1===t.visible||!(null===(i=t.data)||void 0===i?void 0:i.length))return;let o=null===(n=t.options)||void 0===n?void 0:n.style;"barcolor"!==o&&"background"!==o&&e.push({key:"plot:".concat(t._plotKey||t.title||r),label:t.title||t._plotKey||"plot ".concat(r),kind:o||"line"})});let t=((null==tk?void 0:tk.labels)||[]).filter(e=>e&&!e._deleted).length,r=((null==tk?void 0:tk.lines)||[]).filter(e=>e&&!e._deleted).length,i=((null==tk?void 0:tk.boxes)||[]).filter(e=>e&&!e._deleted).length;return t&&e.push({key:"drawings:labels",label:"Labels (".concat(t,")"),kind:"labels"}),r&&e.push({key:"drawings:lines",label:"Line levels (".concat(r,")"),kind:"lines"}),i&&e.push({key:"drawings:boxes",label:"Box zones (".concat(i,")"),kind:"boxes"}),e},[tw,tk,th]),handleAiAnalyse=async e=>{var t,r,i,n,o,l,a,s;let d=null!==(t=null==e?void 0:e.start)&&void 0!==t?t:nx,c=null!==(r=null==e?void 0:e.end)&&void 0!==r?r:nf;if(null==d||null==c){nj("Hover and set both a start and an end candle.");return}let u=Math.min(d,c),p=Math.max(d,c),h=aZ.filter(e=>e.time>=u&&e.time<=p);if(!h.length){nj("No candles in the selected range.");return}nv(!0),nj(""),nS("");try{let e;let t=h.map(e=>"Time: ".concat(new Date(1e3*e.time).toISOString(),", O: ").concat(Number(e.open).toFixed(2),", H: ").concat(Number(e.high).toFixed(2),", L: ").concat(Number(e.low).toFixed(2),", C: ").concat(Number(e.close).toFixed(2),", V: ").concat(Number(e.volume||0).toLocaleString())).join("\n"),r=[],streamOn=e=>!1!==nE[e],d=sh.some(e=>streamOn(e.key)),c=(null==nu?void 0:nu.title)||nd;if(((null==tw?void 0:tw.length)||th||tk)&&(c||d)){r.push("--- ACTIVE PINE STRATEGY OUTPUT ---"),c&&r.push("Strategy: ".concat(c)),th&&streamOn("summary")&&r.push("Net profit: $".concat(null!==(l=null===(n=th.net_profit)||void 0===n?void 0:n.toFixed(2))&&void 0!==l?l:"0.00"," | Win rate: ").concat(null!==(a=null===(o=th.win_rate)||void 0===o?void 0:o.toFixed(1))&&void 0!==a?a:0,"% | Closed trades: ").concat(null!==(s=th.total_closed_trades)&&void 0!==s?s:0));let e=1e3*u,t=1e3*p;if(null==tw?void 0:tw.length){let i=tw.map((e,t)=>({p:e,key:"plot:".concat(e._plotKey||e.title||t)}
1)).filter(e=>{var t;let{p:r,key:i}=e;return!1!==r.visible&&(null===(t=r.data)||void 0===t?void 0:t.length)&&streamOn(i)}).map(r=>{var i;let{p:n}=r,o=n.title||n._plotKey||"plot",l=null===(i=n.options)||void 0===i?void 0:i.style;if("barcolor"===l||"background"===l)return null;let a=n.data.filter(r=>r.time>=e&&r.time<=t),s=n.data.slice().reverse().find(e=>e.time<=t),d=null==s?void 0:s.value;if("shape"===l){let e=a.filter(e=>e.value).length;return"".concat(o,": ").concat(e," signal(s) in range")}if(Array.isArray(d)){let e=a.filter(e=>Array.isArray(e.value)&&e.value.some(e=>null!=e&&Number.isFinite(Number(e))));if(!e.length)return"".concat(o,": inactive in range");let t=e[e.length-1];return"".concat(o,": active on ").concat(e.length," bar(s), last ").concat(new Date(t.time).toISOString())}let c=null!=d&&Number.isFinite(Number(d))?Number(d).toFixed(4):"N/A",u=a.map(e=>Number(e.value)).filter(e=>Number.isFinite(e)),p=u.length>1?" (range ".concat(Math.min(...u).toFixed(4),"-").concat(Math.max(...u).toFixed(4),")"):"";return"".concat(o,": ").concat(c).concat(p)}).filter(Boolean).join(" | ");i&&r.push("Indicators (latest at selection end, with in-range min-max): ".concat(i))}if(tk){let e=aZ.indexOf(h[0]),t=aZ.indexOf(h[h.length-1]),overlaps=(r,i)=>r<=t&&i>=e;if(streamOn("drawings:labels")){let i=(tk.labels||[]).filter(r=>r&&!r._deleted&&r.text&&r.x>=e&&r.x<=t).map(e=>String(e.text)),n=[...new Set(i)].slice(0,40);n.length&&r.push("Labels in range: ".concat(n.join(" | ")))}if(streamOn("drawings:lines")){let e=(tk.lines||[]).filter(e=>e&&!e._deleted&&Number.isFinite(e.y1)&&overlaps(e.x1,e.x2)).map(e=>Number(e.y1).toFixed(2)),t=[...new Set(e)].slice(0,25);t.length&&r.push("Line levels in range: ".concat(t.join(", ")))}if(streamOn("drawings:boxes")){let e=(tk.boxes||[]).filter(e=>e&&!e._deleted&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&overlaps(e.left,e.right)).map(e=>"".concat(Number(e.bottom).toFixed(2),"-").concat(Number(e.top).toFixed(2))),t=[...new Set(e)].slice(0,25);t.length&&r.push("Box zones in range (bottom-top): ".concat(t.join(", ")))}}}let g=r.length?"".concat(t,"\n\n").concat(r.join("\n")):t;nq.current=g;let x=await fetch("/api/ollama-market",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({context:g,pair:f,mode:"analyse",risk:"moderate"})}),b=await x.text();try{e=JSON.parse(b)}catch(e){throw Error(b.slice(0,300)||"Ollama returned invalid JSON")}if(!x.ok)throw Error((null==e?void 0:e.error)||b.slice(0,300)||"Ollama error ".concat(x.status));nS(e.analysis||e.description||e.response||(null===(i=e.message)||void 0===i?void 0:i.content)||"No analysis received"),ng("none"),nP(!0)}catch(e){nj((null==e?void 0:e.message)||"Ollama request failed.")}finally{nv(!1)}},normalizeAiDrawing=e=>{var t,r,i;if(!e||"object"!=typeof e)return null;let toTime=e=>{if("number"==typeof e&&Number.isFinite(e))return e>1e12?Math.floor(e/1e3):e;if("string"==typeof e){let t=new Date(e).getTime();return Number.isFinite(t)?Math.floor(t/1e3):null}return null},num=e=>Number.isFinite(Number(e))?Number(e):null,n={color:"string"==typeof e.color?e.color:"#f0b90b",fillColor:"string"==typeof e.fillColor?e.fillColor:void 0,lineStyle:["solid","dashed","dotted"].includes(e.lineStyle)?e.lineStyle:void 0,text:"string"==typeof e.text?e.text:void 0,fontSize:null!==(t=num(e.fontSize))&&void 0!==t?t:void 0},o=toTime(e.time),l=toTime(e.time2),a=toTime(e.time3),s=num(e.price),d=num(e.price2),c=num(e.price3),u={id:"ai-".concat(++nK.current),createdTf:b,zIndex:2,...n},p=aZ.length>1?aZ[1].time-aZ[0].time:V[b]||60;switch(String(e.type)){case"horizontal":if(null==s)return null;return{...u,type:"horizontal",price:s};case"vertical":if(null==o)return null;return{...u,type:"vertical",time:o,price:null!=s?s:0};case"trendline":case"arrow":if(null==o||null==l||null==s||null==d)return null;return{...u,type:e.type,time:o,time2:l,price:s,price2:d,extendRight:!!e.extendRight,extendLeft:!!e.extendLeft};case"channel":if(null==o||null==l||null==s||null==d)return null;return{...u,type:"channel",time:o,time2:l,price:s,price2:d,time3:null!=a?a:o,price3:null!=c?c:s};case"fibonacci":case"fibextension":if(null==o||null==l||null==s||null==d)return null;return{...u,type:e.type,time:o,time2:l,price:s,price2:d};
1case"rectangle":case"zone":case"box":case"ellipse":if(null==o||null==l||null==s||null==d)return null;return{...u,type:"ellipse"===e.type?"ellipse":"rectangle",time:o,time2:l,price:s,price2:d};case"triangle":if(null==o||null==l||null==a||null==s||null==d||null==c)return null;return{...u,type:"triangle",time:o,time2:l,time3:a,price:s,price2:d,price3:c};case"text":case"label":if(null==o||null==s)return null;return{...u,type:"text",time:o,price:s,text:n.text||"Note"};case"highlight":{if(null==o)return null;let e=aZ.find(e=>e.time===o)||aZ.reduce((e,t)=>null==e||Math.abs(t.time-o)<Math.abs(e.time-o)?t:e,null);if(!e)return null;return{...u,type:"rectangle",time:e.time,time2:e.time+p,price:Number(e.high),price2:Number(e.low),color:"#f0b90b"===n.color?"rgba(240,185,11,0.6)":n.color,fillColor:n.fillColor||"rgba(240,185,11,0.18)"}}case"long-position":case"short-position":case"position":{if(null==o||null==s)return null;let t="short-position"===e.type||"short"===e.side?"short":"long";return{...u,type:"position",side:t,time:o,time2:null!=l?l:o,price:s,targetPrice:null!==(r=num(e.targetPrice))&&void 0!==r?r:void 0,stopPrice:null!==(i=num(e.stopPrice))&&void 0!==i?i:void 0}}default:return null}},sg=(0,n.useCallback)(()=>{nY.current=[],nH(0),sl()},[sl]),handleAiChatSend=async()=>{let e=nL.trim();if(e&&!nB){if(!nq.current){nV("Run the analysis first so the chat has chart context.");return}nA(""),nV(""),nW(!0),nN(t=>[...t,{role:"user",content:e}]);try{let t;let r=await fetch("/api/ollama-chart-chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:e,context:nq.current,history:nF})}),i=await r.text();try{t=JSON.parse(i)}catch(e){throw Error(i.slice(0,300)||"Chat returned invalid JSON")}if(!r.ok)throw Error((null==t?void 0:t.error)||i.slice(0,300)||"Chat error ".concat(r.status));let n="string"==typeof t.reply&&t.reply.trim()?t.reply:"Done.";nN(e=>[...e,{role:"assistant",content:n}]);let o=(Array.isArray(t.drawings)?t.drawings:[]).map(normalizeAiDrawing).filter(Boolean).slice(0,15);o.length&&(nY.current=[...nY.current,...o],nH(nY.current.length),sl())}catch(e){nV((null==e?void 0:e.message)||"Chat request failed.")}finally{nW(!1)}}},sx=(0,n.useCallback)(async()=>{if(!aZ.length){an("No chart data available.");return}ar(!0),an(""),al(null),as("");try{let e=aZ.map(e=>e.close),t=e[e.length-1],r=e[0],i=(t-r)/r*100,n=Math.max(...aZ.map(e=>e.high)),o=Math.min(...aZ.map(e=>e.low)),l=[];if(l.push("Pair: ".concat(f)),l.push("Timeframe: ".concat(eo,"d")),l.push("Data points: ".concat(e.length)),l.push("Current Price: $".concat(t.toFixed(2))),l.push("Period High: $".concat(n.toFixed(2))),l.push("Period Low: $".concat(o.toFixed(2))),l.push("Price Change: ".concat(i>=0?"+":"").concat(i.toFixed(2),"%")),Z&&rj&&rj>0){let e="ema"===rv?OpenChartsPro_calculateEMA:calculateSMA,t="ema"===rv?"EMA":"SMA",r=Z.slice(0,rj).map(t=>{var r;let i=e(aZ,t),n=null!==(r=i.filter(e=>null!==e.value).pop())&&void 0!==r?r:null;return{period:t,value:n?n.value:null}});l.push("".concat(t,"s: ").concat(r.map(e=>"".concat(t).concat(e.period,"=$").concat(null!==e.value?e.value.toFixed(2):"N/A")).join(", ")))}let a=symbolToGexCurrency(f);if(a)try{let e=await fetchGexProfile(a),t=e.callWall?"$".concat(e.callWall.toFixed(2)):"N/A",r=e.putWall?"$".concat(e.putWall.toFixed(2)):"N/A",i=e.zeroGamma?"$".concat(e.zeroGamma.toFixed(2)):"N/A",n="".concat(e.totalGex>=0?"+":"").concat(e.totalGex.toFixed(0)," USD per 1% move");l.push("GEX (Deribit options): Call Wall ".concat(t,", Put Wall ").concat(r,", Gamma Flip ").concat(i,", Net GEX ").concat(n))}catch(e){l.push("GEX (Deribit options): unavailable")}else l.push("GEX (Deribit options): not available for ".concat(f));let s=await fetch("/api/ollama-market",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({context:l.join("\n"),mode:"suggest",pair:f,risk:l7})});if(!s.ok)throw Error("AI suggestion request failed");let d=await s.json();if(d.error)throw Error(d.error);if(!Array.isArray(d.suggestions))throw Error("No suggestions returned");al(d.suggestions),d.description&&as(String(d.description))}catch(e){an((null==e?void 0:e.message)||"Failed to get AI position suggestions")}finally{ar(!1)}},[aZ,f,eo,Z,rj,l7,rv]),sb=(0,n.useCallback)(e=>{let t=e.open_position||e,r="long"===t.side?"long":"short",i=Math.max(1,Math.min(Number(t.leverage)||D.n3,Math.max(1,Math.floor(en||100)))),n=t.limit_price?"limit":"market",o=t.limit_price?String(t.limit_price):"";if(lt(e=>e?{...e,side:r}:e),lo(i),lC(n),lM("single"),lT(o),t.take_profit_pct){let e=Number(t.take_profit_pct);Number.isFinite(e)&&e>0?(lu(!0),lg.current=!0,lh(Math.max(1,100*e*i))):lu(!1)}if(t.stop_loss_pct){let e=Number(t.stop_loss_pct),r=Math.max(1/i-D.Rt,1e-12);Number.isFinite(e)&&e>0&&r>0?(lf(!0),ly(Math.min(100,e/r*100))):lf(!1)}else lf(!1);if(t.trailing_stop_pct){let e=Number(t.trailing_stop_pct);Number.isFinite(e)&&e>0?(lw(!0),lk(Math.max(.5,100*e*i))):lw(!1)}},[en]),insertLiveIndicators=async()=>
1{if(0!==Object.keys(C).length){rx(!0),tY(null);try{let e;let t=Object.entries(C).map(e=>{let[t,r]=e;return"- ".concat(t," = ").concat(r)}).join("\n"),r=await fetch("/api/modify-pinescript",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:tK,prompt:"Insert/update the following live indicator values into the Pine Script v5 code at the correct places:\n\n".concat(t,"\n\nUse these live inputs wherever they are applicable in the strategy logic, not just as standalone values. Prefer replacing duplicate strategy-specific input lengths/periods with the matching live variable names. Mapping rules: MACD fast/slow/signal inputs and ta.macd arguments should use macdFast, macdSlow, and macdSignal; RSI lengths and ta.rsi periods should use rsiPeriod; Stochastic/Stoch RSI periods and smoothing should use stochPeriod, stochKSmooth, and stochDSmooth; generic lookback/length/period inputs for SMA, EMA, Bollinger Bands, Donchian, Fibonacci, SuperTrend ATR, volume averages, or similar calculations may use rsiPeriod when no more specific live input exists; EMA trend lengths may use macdSlow when appropriate. If the code already defines variables or inputs with the live names, update their default/assigned value to the number above while preserving the rest of the line. If a live variable is missing, add it near the top of the script after the strategy/indicator declaration. Remove duplicate strategy-specific input declarations when their uses have been replaced by live variables. Preserve Pine Script v5 syntax and return the full code with all values applied. Do not add extra commentary.")})}),i=await r.text();try{e=JSON.parse(i)}catch(e){throw Error(i.slice(0,300)||"Insert live indicators failed")}if(!r.ok)throw Error((null==e?void 0:e.error)||i.slice(0,300)||"Insert live indicators failed");if("string"!=typeof e.code)throw Error("Response did not include updated code");of.current=!0,tK&&(tG.current=tK),tX(e.code),rf(!0)}catch(e){tY((null==e?void 0:e.message)||"Insert live indicators failed")}finally{rx(!1)}}},sf=(0,n.useMemo)(()=>(function(e){var t,r,i,n,o,l,a,s,d,c,u,p,h,g,x,b,f,m,y,v,w,S,k;let j,C;let _={},M=/^\s*(?:(?:string|int|float|bool)\s+)?(\w+)\s*=\s*("([^"]*)"|'([^']*)')\s*$/gm;for(;j=M.exec(e);)_[j[1]]=null!==(r=null!==(t=j[3])&&void 0!==t?t:j[4])&&void 0!==r?r:"";let P=[],T={},R=/(\w+)\s*=\s*input\.(int|float|bool|string)\s*\(/g;for(;C=R.exec(e);){let t;let r=C[1],j=C[2],M=C.index+C[0].length,R=M,z=1,I=null;for(;M<e.length&&z>0;){let t=e[M];I?"\\"===t?M++:t===I&&(I=null):'"'===t||"'"===t?I=t:"("===t?z++:")"===t&&z--,M++}let E=e.slice(R,M-1),D=function(e){let t=[],r=0,i=null,n="";for(let l=0;l<e.length;l++){let a=e[l];if(i){if(n+=a,"\\"===a){var o;n+=null!==(o=e[l+1])&&void 0!==o?o:"",l++}else a===i&&(i=null);continue}if('"'===a||"'"===a){i=a,n+=a;continue}if(("("===a||"["===a)&&r++,(")"===a||"]"===a)&&r--,","===a&&0===r){t.push(n),n="";continue}n+=a}return n.trim()&&t.push(n),t}(E),L=E.match(/defval\s*=\s*([^,]+)/i),A=(L?L[1]:null!==(u=D[0])&&void 0!==u?u:"").trim();t="bool"===j?"true"===A:"string"===j?null!==(h=null!==(p=unquotePineString(A))&&void 0!==p?p:_[A])&&void 0!==h?h:A:Number(A)||0;let F=null===(i=E.match(/title\s*=\s*("[^"]*"|'[^']*')/i))||void 0===i?void 0:i[1],N=null!==(b=null!==(x=unquotePineString(null!=F?F:""))&&void 0!==x?x:unquotePineString(null!==(g=D[1])&&void 0!==g?g:""))&&void 0!==b?b:r,B=null!==(f=null===(o=E.match(/group\s*=\s*(\w+|"[^"]*"|'[^']*')/i))||void 0===o?void 0:null===(n=o[1])||void 0===n?void 0:n.trim())&&void 0!==f?f:"",W=null!==(y=null!==(m=unquotePineString(B))&&void 0!==m?m:_[B])&&void 0!==y?y:"Inputs",O=null!==(v=null===(l=E.match(/options\s*=\s*\[([^\]]*)\]/i))||void 0===l?void 0:l[1])&&void 0!==v?v:null===(a=D.find(e=>e.trim().startsWith("[")&&e.trim().endsWith("]")))||void 0===a?void 0:a.trim(),V=O?(O.match(/"([^"]*)"|'([^']*)'/g)||[]).map(e=>e.slice(1,-1)):[],U=O?V.length?V:O.replace(/^\s*\[|\]\s*$/g,"").split(",").map(e=>{var t,r;return null!==(r=null!==(t=unquotePineString(e))&&void 0!==t?t:_[e.trim()])&&void 0!==r?r:e.trim()}).filter(Boolean):null,H=null===(s=E.match(/minval\s*=\s*([^,\n]+)/i))||void 0===s?void 0:s[1].trim(),q=null===(d=E.match(/maxval\s*=\s*([^,\n]+)/i))||void 0===d?void 0:d[1].trim(),Y=null===(c=E.match(/step\s*=\s*([^,\n]+)/i))||void 0===c?void 0:c[1].trim(),K="int"===j?1:0,X="float"===j?.1:1;H&&(K=null!==(w=Number(H))&&void 0!==w?w:K);let G=K+("int"===j?100:10);q&&(G=null!==(S=Number(q))&&void 0!==S?S:G),Y&&(X=null!==(k=Number(Y))&&void 0!==k?k:X),P.push({name:r,type:j,title:N,group:W,min:K,max:G,step:X,options:U}),T[r]=t}return{values:T,defs:P}})(tK),[tK]),sm=sf.defs,sy=(0,n.useMemo)(()=>{let e=[],t=new Map;for(let r of sm)t.has(r.group)||(t.set(r.group,[]),e.push(r.group)),t.get(r.group).push(r);return e.map(e=>
1({group:e,defs:t.get(e)}))},[sm]);(0,n.useEffect)(()=>{ro(sf.values)},[sf]),(0,n.useEffect)(()=>{C&&ra(e=>{let t={...C||{}};return rd.current.forEach(r=>{void 0!==e[r]&&(t[r]=e[r])}),rs.current=t,t})},[C]),(0,n.useEffect)(()=>{0!==Object.keys(rl).length&&(tK&&(tG.current=tK),tX(e=>(function(e,t){let r=e;for(let[e,i]of Object.entries(t)){let t=r.match(RegExp("^\\s*(?:\\w+\\s+)?"+e+"\\s*=\\s*input\\.(int|float|bool|string)\\s*\\(","m"));if(t)r=updateInputInCode(r,e,i,t[1]);else{let t=RegExp("\\b"+e+"\\s*=\\s*[^;\\n]+","g");r=r.replace(t,"".concat(e," = ").concat(i))}}return r})(e,rl)))},[rl]),(0,n.useEffect)(()=>{(rr||oL.current)&&aZ.length>0&&tK&&runSimulation()},[rr,rn,rl]),(0,n.useEffect)(()=>{rr&&aZ.length>0&&tK&&runSimulation()},[rr,aZ]),(0,n.useEffect)(()=>{oA>0&&runSimulation()},[oA]),(0,n.useEffect)(()=>{ea&&aZ.length>0&&runSimulation()},[ea]);let sv=(0,n.useRef)(null),sw=(0,n.useRef)(!1);return(0,n.useEffect)(()=>{null!==sv.current&&sv.current!==nd&&(sw.current=!0),sv.current=nd},[nd]),(0,n.useEffect)(()=>{sw.current&&aZ.length>0&&(sw.current=!1,runSimulation())},[tK,aZ]),(0,n.useEffect)(()=>{localStorage.setItem("opencharts_pinescript_code",tK)},[tK]),(0,i.jsxs)("div",{ref:ep,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"},children:[(0,i.jsx)("style",{children:"\n        @media (max-width: 768px) {\n          .ocp-side-controls {\n            flex-direction: column !important;\n            min-width: 0 !important;\n            width: 100% !important;\n            align-items: stretch !important;\n          }\n          .ocp-panel-col {\n            width: 100% !important;\n            min-width: 0 !important;\n          }\n          .ocp-wide-panel {\n            width: 100% !important;\n            max-width: 100% !important;\n          }\n          .ocp-btn-col {\n            flex-direction: row !important;\n            flex-wrap: wrap !important;\n            width: 100% !important;\n          }\n          .ocp-timeframe-bar {\n            right: 116px !important;\n          }\n          .ocp-timeframe-bar button {\n            padding: 3px 7px !important;\n            font-size: 10px !important;\n          }\n        }\n      "}),(0,i.jsx)("div",{style:{overflow:"hidden",maxHeight:t0?"2400px":"0px",opacity:t0?1:0,transform:t0?"translateY(0)":"translateY(-16px)",transition:"max-height 0.35s ease, opacity 0.3s ease, transform 0.35s ease"},children:(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:(0,i.jsxs)("div",{className:"ocp-side-controls",style:{display:"flex",gap:"8px",alignItems:"flex-start",flexWrap:"wrap",flex:"1 1 auto",width:"100%"},children:[(0,i.jsxs)("div",{className:"ocp-panel-col",style:{display:"flex",flexDirection:"column",gap:"8px",minWidth:0,alignItems:"stretch",flex:"2 1 0"},children:[(0,i.jsxs)("div",{className:"ocp-wide-panel",style:{width:"100%",minWidth:"280px",borderRadius:"10px",border:"1px solid rgba(255,255,255,0.12)",background:"linear-gradient(180deg, rgba(15,23,42,0.75), rgba(2,6,23,0.8))",padding:"8px"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:"8px",marginBottom:"6px"},children:[(0,i.jsx)("div",{style:{fontSize:"10px",letterSpacing:"0.08em",textTransform:"uppercase",color:"rgba(255,255,255,0.58)"},children:"Pine Strategies"}),(0,i.jsx)("a",{href:"https://github.com/rattadan/TactiX_Trading_Panel",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"9px",color:"rgba(96,165,250,0.85)",textDecoration:"none",whiteSpace:"nowrap"},children:"Want your indicator or strategy listed and earn from usage? visit github.com/rattadan/TactiX_Trading_Panel"})]}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=np.current)||void 0===e?void 0:e.scrollBy({left:-240,behavior:"smooth"})},style:{width:"24px",height:"24px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.16)",background:"rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.85)",fontSize:"14px",fontWeight:700,cursor:"pointer",flex:"0 0 auto"},"aria-label":"Previous strategies",children:"←"}),(0,i.jsx)("div",{ref:np,style:{display:"flex",gap:"8px",flex:"1 1 0",minWidth:0,overflowX:"auto",overflowY:"hidden",paddingBottom:"4px",scrollSnapType:"x mandatory",maxHeight:"112px",scrollbarWidth:"none",msOverflowStyle:"none"},children:na.map(e=>{let t=nd===e.name;return(0,i.jsxs)("button",{onClick:()=>{nc(e.name),ri(!0),sw.current=!0,loadStrategyCode(e.name)}
1,style:{textAlign:"left",minWidth:"220px",maxWidth:"220px",flex:"0 0 auto",scrollSnapAlign:"start",padding:"8px 10px",borderRadius:"8px",border:t?"1px solid rgba(96,165,250,0.8)":"1px solid rgba(255,255,255,0.12)",background:t?"rgba(59,130,246,0.2)":"rgba(15,23,42,0.45)",color:"#fff",cursor:"pointer"},title:e.description,children:[(0,i.jsx)("div",{style:{fontSize:"12px",fontWeight:700,lineHeight:1.2},children:e.title}),(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.68)",marginTop:"3px",lineHeight:1.25},children:e.description})]},e.name)})}),(0,i.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=np.current)||void 0===e?void 0:e.scrollBy({left:240,behavior:"smooth"})},style:{width:"24px",height:"24px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.16)",background:"rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.85)",fontSize:"14px",fontWeight:700,cursor:"pointer",flex:"0 0 auto"},"aria-label":"Next strategies",children:"→"})]}),nu&&(0,i.jsxs)("div",{style:{marginTop:"7px",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:["Selected: ",nu.title]})]}),(0,i.jsxs)("div",{className:"ocp-wide-panel",style:{width:"100%",borderRadius:"10px",border:"1px solid rgba(255,255,255,0.12)",background:"linear-gradient(180deg, rgba(15,23,42,0.75), rgba(2,6,23,0.8))",padding:"8px"},children:[(0,i.jsx)("div",{style:{fontSize:"10px",letterSpacing:"0.08em",textTransform:"uppercase",color:"rgba(255,255,255,0.58)",marginBottom:"6px"},children:"Indicator Scale"}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[(0,i.jsx)("input",{type:"range",min:0,max:100,step:1,value:L<=0?0:L>=1?Math.min(100,(.5+Math.log10(L)/2)*100):Math.log10(9*L+1)/2*100,onChange:e=>{ri(!0),A(scaleFromSlider(Number(e.target.value)))},style:{flex:1,accentColor:"#60a5fa"}}),(0,i.jsxs)("span",{style:{fontSize:"11px",color:"#fff",minWidth:"40px",fontVariantNumeric:"tabular-nums"},children:[L.toFixed(2),"x"]})]})]}),tq&&(0,i.jsx)("div",{className:"ocp-wide-panel",style:{width:"100%",marginTop:"8px",padding:"10px",borderRadius:"10px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px",maxHeight:"140px",overflowY:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:tq})]}),(0,i.jsxs)("div",{className:"ocp-btn-col",style:{display:"flex",flexDirection:"column",order:1,flex:"1 1 0",minWidth:"150px",gap:"8px",padding:"10px 12px",borderRadius:"12px",border:"1px solid rgba(255,255,255,0.12)",background:"linear-gradient(180deg, rgba(15,23,42,0.75), rgba(2,6,23,0.8))",boxShadow:"0 0 24px rgba(0,0,0,0.35)"},children:[(0,i.jsx)("button",{onClick:()=>{ep.current&&(document.fullscreenElement?document.exitFullscreen().catch(()=>{}):ep.current.requestFullscreen().catch(()=>{}))},style:{padding:"8px 16px",borderRadius:"8px",border:ty?"1px solid rgba(245,158,11,0.5)":"1px solid rgba(245,158,11,0.3)",background:ty?"rgba(245,158,11,0.2)":"rgba(245,158,11,0.08)",color:"#fbbf24",boxShadow:ty?"0 0 8px 1px rgba(245,158,11,0.6), inset 0 0 6px 1px rgba(245,158,11,0.15)":"none",textShadow:ty?"0 0 4px rgba(245,158,11,0.8)":"none",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:ty?"Exit Fullscreen":"Fullscreen"}),(0,i.jsx)("button",{onClick:()=>{tS(e=>{let t=e.some(e=>!1!==e.visible);return e.map(e=>({...e,visible:!t}))})},style:{padding:"8px 16px",borderRadius:"8px",border:tw.some(e=>!1!==e.visible)?"1px solid rgba(245,158,11,0.5)":"1px solid rgba(245,158,11,0.3)",background:tw.some(e=>!1!==e.visible)?"rgba(245,158,11,0.2)":"rgba(245,158,11,0.08)",color:"#fbbf24",boxShadow:tw.some(e=>!1!==e.visible)?"0 0 8px 1px rgba(245,158,11,0.6), inset 0 0 6px 1px rgba(245,158,11,0.15)":"none",textShadow:tw.some(e=>!1!==e.visible)?"0 0 4px rgba(245,158,11,0.8)":"none",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:tw.some(e=>!1!==e.visible)?"Hide Indicator":"Show Indicator"}),(0,i.jsx)("button",{onClick:()=>tI(e=>!e),title:"Show raw indicator plot values (debug log)",style:{padding:"8px 16px",borderRadius:"8px",border:tz?"1px solid rgba(96,165,250,0.5)":"1px solid rgba(96,165,250,0.3)",background:tz?"rgba(96,165,250,0.2)":"rgba(96,165,250,0.08)",color:"#93c5fd",boxShadow:tz?"0 0 8px 1px rgba(96,165,250,0.6), inset 0 0 6px 1px rgba(96,165,250,0.15)":"none",textShadow:tz?"0 0 4px rgba(96,165,250,0.8)":"none",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:tz?"Hide Log":"Indicator Log"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-start"},children:[(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:[(0,i.jsx)("button",{onClick:()=>nQ(e=>!e),disabled:!n2,title:n2?"Gamma exposure levels (Deribit options data)":"GEX available for BTC / ETH / SOL only",style:{padding:"8px 16px",borderRadius:"8px",border:nJ?"1px solid rgba(34,197,94,0.5)":"1px solid rgba(34,197,94,0.3)",background:nJ?"rgba(34,197,94,0.2)":"rgba(34,197,94,0.08)",color:"#86efac",boxShadow:nJ?"0 0 8px 1px rgba(34,197,94,0.6), inset 0 0 6px 1px rgba(34,197,94,0.15)":"none",textShadow:nJ?"0 0 4px rgba(34,197,94,0.8)":"none",fontSize:"13px",fontWeight:600,cursor:n2?"pointer":"not-allowed",opacity:n2?1:.4},children:nJ?"Hide GEX":"GEX"}),(0,i.jsx)("button",{onClick:()=>n6(e=>!e),disabled:!n3,title:n3?"Estimated liquidation heatmap (Hyperliquid)":"Liquidation heatmap data not available for this symbol",style:{padding:"8px 16px",borderRadius:"8px",border:n4?"1px solid rgba(242,54,69,0.5)":"1px solid rgba(242,54,69,0.3)",background:n4?"rgba(242,54,69,0.2)":"rgba(242,54,69,0.08)",color:"#fca5a5",boxShadow:n4?"0 0 8px 1px rgba(242,54,69,0.6), inset 0 0 6px 1px rgba(242,54,69,0.15)":"none",textShadow:n4?"0 0 4px rgba(242,54,69,0.8)":"none",fontSize:"13px",fontWeight:600,cursor:n3||P?"pointer":"not-allowed",opacity:n3||P?1:.4}
1,children:n4&&n3?"Hide Liq":"Liq"}),(0,i.jsx)("button",{onClick:()=>nZ(e=>!e),style:{padding:"8px 16px",borderRadius:"8px",border:n$?"1px solid rgba(59,130,246,0.5)":"1px solid rgba(59,130,246,0.3)",background:n$?"rgba(59,130,246,0.2)":"rgba(59,130,246,0.08)",color:"#93c5fd",boxShadow:n$?"0 0 8px 1px rgba(59,130,246,0.6), inset 0 0 6px 1px rgba(59,130,246,0.15)":"none",textShadow:n$?"0 0 4px rgba(59,130,246,0.8)":"none",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:n$?"Hide DOM":"DOM"})]}),(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",borderRadius:"8px",border:"1px solid rgba(245,158,11,0.4)",background:"rgba(245,158,11,0.08)",overflow:"hidden",transition:"all 0.25s ease"},children:[(0,i.jsxs)("button",{onClick:()=>tQ(e=>!e),style:{padding:"8px 12px 8px 16px",border:"none",background:tJ?"rgba(245,158,11,0.2)":"transparent",color:"#fbbf24",boxShadow:tJ?"0 0 8px 1px rgba(245,158,11,0.6), inset 0 0 6px 1px rgba(245,158,11,0.15)":"none",textShadow:tJ?"0 0 4px rgba(245,158,11,0.8)":"none",fontSize:"13px",fontWeight:600,cursor:"pointer",whiteSpace:"nowrap",borderRadius:"8px",transition:"background 0.2s ease",display:"flex",alignItems:"center",gap:"4px"},children:["PineScript",(0,i.jsx)("span",{style:{display:"inline-block",transform:tJ?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.25s ease",fontSize:"10px",opacity:.75},children:"▼"})]}),(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"4px",padding:tJ?"4px 0 0 0":"0",maxHeight:tJ?"200px":"0px",opacity:tJ?1:0,overflow:"hidden",transition:"max-height 0.3s ease, opacity 0.25s ease, padding 0.25s ease"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>{try{localStorage.setItem(i8,JSON.stringify(getCurrentIndicatorSettings())),triggerGlow("save")}catch(e){}},style:{padding:"4px 10px",borderRadius:"6px",border:"1px solid rgba(34, 197, 94, 0.4)",background:"rgba(34, 197, 94, 0.12)",color:"#4ade80",fontSize:"11px",fontWeight:600,cursor:"pointer",boxShadow:"save"===i7?"0 0 12px 2px rgba(34, 197, 94, 0.6)":"none",transition:"box-shadow 0.35s ease"},children:"Save Setting"}),(0,i.jsx)("button",{type:"button",onClick:()=>{try{let e=localStorage.getItem(i8);e&&applyIndicatorSettings(JSON.parse(e)),triggerGlow("load")}catch(e){}},style:{padding:"4px 10px",borderRadius:"6px",border:"1px solid rgba(59, 130, 246, 0.4)",background:"rgba(59, 130, 246, 0.12)",color:"#93c5fd",fontSize:"11px",fontWeight:600,cursor:"pointer",boxShadow:"load"===i7?"0 0 12px 2px rgba(59, 130, 246, 0.6)":"none",transition:"box-shadow 0.35s ease"},children:"Load saved values"}),(0,i.jsx)("button",{type:"button",onClick:()=>{applyIndicatorSettings(i3),triggerGlow("restore")},style:{padding:"4px 10px",borderRadius:"6px",border:"1px solid rgba(239, 68, 68, 0.4)",background:"rgba(239, 68, 68, 0.12)",color:"#f87171",fontSize:"11px",fontWeight:600,cursor:"pointer",boxShadow:"restore"===i7?"0 0 12px 2px rgba(239, 68, 68, 0.6)":"none",transition:"box-shadow 0.35s ease"},children:"Restore default values"})]}),(0,i.jsx)("button",{onClick:runSimulation,disabled:tu||0===aZ.length,style:{padding:"6px 12px",borderRadius:"6px",border:"1px solid rgba(59,130,246,0.4)",background:"rgba(59,130,246,0.15)",color:"#93c5fd",fontSize:"12px",fontWeight:600,cursor:tu?"not-allowed":"pointer",opacity:tu?.6:1,whiteSpace:"nowrap"},children:tu?"Running…":"Run Pine Strategy"}),(0,i.jsx)("button",{onClick:()=>oC(e=>!e),title:"Re-run the strategy on every 5s candle and alert on new entry/exit signals",style:{padding:"6px 12px",borderRadius:"6px",border:oj?"1px solid rgba(96,165,250,0.6)":"1px solid rgba(96,165,250,0.3)",background:oj?"rgba(96,165,250,0.2)":"rgba(96,165,250,0.08)",color:oj?"#93c5fd":"#bfdbfe",fontSize:"12px",fontWeight:600,cursor:"pointer",whiteSpace:"nowrap"},children:oj?"Alarms On":"Alarms Off"}),(0,i.jsx)("button",{onClick:()=>ri(e=>!e),style:{padding:"6px 12px",borderRadius:"6px",border:rr?"1px solid rgba(34,197,94,0.5)":"1px solid rgba(34,197,94,0.3)",background:rr?"rgba(34,197,94,0.2)":"rgba(34,197,94,0.08)",color:rr?"#4ade80":"#86efac",fontSize:"12px",fontWeight:600,cursor:"pointer",whiteSpace:"nowrap"},children:rr?"Live On":"Live Off"}),(0,i.jsx)("button",{onClick:()=>{var e;localStorage.removeItem("opencharts_pinescript_code"),of.current=!1;let t=(null===(e=na[0])||void 0===e?void 0:e.name)||nd;nc(t),loadStrategyCode(t)},style:{padding:"6px 12px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.06)",color:"rgba(255,255,255,0.85)",fontSize:"12px",fontWeight:600,cursor:"pointer",whiteSpace:"nowrap"},children:"Clear Cache"}),(th||sd.length>0)&&(0,i.jsx)("button",{onClick:()=>tm(e=>!e),style:{padding:"6px 12px",borderRadius:"6px",border:tf?"1px solid rgba(251,191,36,0.5)":"1px solid rgba(251,191,36,0.3)",background:tf?"rgba(251,191,36,0.2)":"rgba(251,191,36,0.08)",color:tf?"#fbbf24":"#fde68a",fontSize:"12px",fontWeight:600,cursor:"pointer",whiteSpace:"nowrap"},children:tf?"Hide Trades":"Show Trades"})]})]}),(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[(0,i.jsx)("button",{onClick:()=>ot(e=>!e),style:{padding:"6px 14px",borderRadius:"8px",border:oe?"1px solid rgba(34,197,94,0.5)":"1px solid rgba(34,197,94,0.3)",background:oe?"rgba(34,197,94,0.2)":"rgba(34,197,94,0.08)",color:oe?"#4ade80":"#86efac",boxShadow:oe?"0 0 8px 1px rgba(34,197,94,0.6), inset 0 0 6px 1px rgba(34,197,94,0.15)":"none",textShadow:oe?"0 0 4px rgba(34,197,94,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:"Longs"}),(0,i.jsx)("button",{onClick:()=>oi(e=>!e),style:{padding:"6px 14px",borderRadius:"8px",border:or?"1px solid rgba(239,68,68,0.5)":"1px solid rgba(239,68,68,0.3)",background:or?"rgba(239,68,68,0.2)":"rgba(239,68,68,0.08)",color:or?"#f87171":"#fca5a5",boxShadow:or?"0 0 8px 1px rgba(239,68,68,0.6), inset 0 0 6px 1px rgba(239,68,68,0.15)":"none",textShadow:or?"0 0 4px rgba(239,68,68,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:"Shorts"}),(0,i.jsx)("style",{children:"\n                    @keyframes limitOrdersBtnPulse {\n                      0%, 100% { box-shadow: 0 0 4px 1px rgba(250,204,21,0.2); background: rgba(250,204,21,0.12); }\n                      50% { box-shadow: 0 0 10px 2px rgba(250,204,21,0.45); background: rgba(250,204,21,0.22); }\n                    }\n                  "}),(0,i.jsx)("button",{onClick:()=>oo(e=>!e),disabled:!w.length,style:{padding:"6px 14px",borderRadius:"8px",border:w.length?on?"1px solid rgba(250,204,21,0.6)":"1px solid rgba(250,204,21,0.4)":"1px solid rgba(107,114,128,0.3)",background:w.length?on?"rgba(250,204,21,0.25)":"rgba(250,204,21,0.12)":"rgba(75,85,99,0.08)",color:w.length?"#facc15":"#9ca3af",boxShadow:w.length&&on?"0 0 8px 1px rgba(250,204,21,0.6), inset 0 0 6px 1px rgba(250,204,21,0.15)":"none",textShadow:on?"0 0 4px rgba(250,204,21,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:w.length?"pointer":"not-allowed",opacity:w.length?1:.6,animation:w.length&&!on?"limitOrdersBtnPulse 2s ease-in-out infinite":"none"},children:"Limitorders"}),(0,i.jsx)("button",{onClick:()=>eY(e=>!e),style:{padding:"6px 14px",borderRadius:"8px",border:eq?"1px solid rgba(168,85,247,0.5)":"1px solid rgba(168,85,247,0.3)",background:eq?"rgba(168,85,247,0.2)":"rgba(168,85,247,0.08)",color:eq?"#c084fc":"#d8b4fe",boxShadow:eq?"0 0 8px 1px rgba(168,85,247,0.6), inset 0 0 6px 1px rgba(168,85,247,0.15)":"none",textShadow:eq?"0 0 4px rgba(168,85,247,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:eq?"Hide Positions":"Show Positions"})]})]})]})]})})}),(0,i.jsxs)("div",{title:t0?"Drag up or click to hide controls":"Drag down or click to show controls",onPointerDown:e=>{var t,r;e.preventDefault(),rt.current={startY:e.clientY,moved:!1}
1,re(!0),null===(t=(r=e.currentTarget).setPointerCapture)||void 0===t||t.call(r,e.pointerId)},onPointerMove:e=>{let t=rt.current;if(!t)return;let r=e.clientY-t.startY;Math.abs(r)>8&&(t.moved=!0),r>48?t5(!0):r<-48&&t5(!1)},onPointerUp:()=>{let e=rt.current;rt.current=null,re(!1),e&&!e.moved&&t5(e=>!e)},onPointerCancel:()=>{rt.current=null,re(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center",height:"16px",marginTop:"-6px",marginBottom:"6px",cursor:t7?"grabbing":"grab",touchAction:"none",userSelect:"none",background:"linear-gradient(180deg, rgba(15,23,42,0.85) 0%, rgba(2,6,23,0.95) 100%)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:"8px",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.06), 0 4px 12px rgba(0,0,0,0.35)"},children:[(0,i.jsx)("style",{children:"\n          @keyframes ocpHandlePulse {\n            0%, 78%, 100% { background: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0.12)); box-shadow: none; }\n            88% { background: linear-gradient(180deg, rgba(250,204,21,0.95), rgba(250,204,21,0.5)); box-shadow: 0 0 12px 2px rgba(250,204,21,0.6); }\n          }\n        "}),(0,i.jsx)("div",{style:{width:"72px",height:"5px",borderRadius:"999px",background:t7?"linear-gradient(180deg, rgba(147,197,253,0.9), rgba(59,130,246,0.7))":"linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0.12))",boxShadow:t7?"0 0 8px rgba(147,197,253,0.5)":"none",animation:t7?"none":"ocpHandlePulse 4s ease-in-out infinite"}})]}),(0,i.jsx)("div",{className:"ocp-card-strip",style:{position:"relative",zIndex:40,height:0,marginBottom:0,overflow:"visible",pointerEvents:"none"},children:(0,i.jsxs)("div",{ref:t9,className:"ocp-card-strip-inner",style:{position:"absolute",top:0,left:0,right:0,display:"flex",flexDirection:"row",gap:"8px",flexWrap:"wrap",minWidth:0,pointerEvents:"none"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>t6(e=>!e),title:t4?"Release: cards collapse again on mouse leave":"Keep controls open: disable hover expand/collapse",style:{alignSelf:"flex-start",pointerEvents:"auto",padding:"4px 8px",borderRadius:"6px",border:t4?"1px solid rgba(103, 232, 249, 0.5)":"1px solid rgba(255,255,255,0.1)",background:t4?"rgba(103, 232, 249, 0.2)":"rgba(255,255,255,0.05)",color:t4?"#67e8f9":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",whiteSpace:"nowrap"},children:t4?"\uD83D\uDCCC pinned":"\uD83D\uDCCC keep open"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-start",flexWrap:"wrap",minWidth:0,flex:"1 1 220px"},children:[(0,i.jsxs)("div",{...controlCardHover("volume"),style:{flex:"1 1 140px",minWidth:0,padding:"12px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t4||"volume"===t1?"8px":"0"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Volume Bars"}),(0,i.jsx)("button",{onClick:()=>iZ(!i$),style:{padding:"4px 10px",borderRadius:"6px",border:i$?"1px solid rgba(99,102,241,0.5)":"1px solid rgba(255,255,255,0.1)",background:i$?"rgba(99,102,241,0.2)":"rgba(255,255,255,0.05)",color:i$?"#93c5fd":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:i$?"On":"Off"})]}),(0,i.jsx)("div",{style:controlCardBodyStyle("volume"),children:(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(100px, 1fr))",gap:"12px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Fill Opacity"}),(0,i.jsx)("input",{type:"range",min:.05,max:1,step:.05,value:i0,onChange:e=>i5(parseFloat(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[Math.round(100*i0),"% fill"]})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Color Mode"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"6px"},children:[(0,i.jsx)("button",{onClick:()=>i2("default"),style:{padding:"4px 8px",borderRadius:"6px",border:"default"===i1?"1px solid rgba(34,197,94,0.5)":"1px solid rgba(255,255,255,0.1)",background:"default"===i1?"rgba(34,197,94,0.15)":"rgba(255,255,255,0.05)",color:"default"===i1?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"Red/Green"}),(0,i.jsx)("button",{onClick:()=>i2("colorblind"),style:{padding:"4px 8px",borderRadius:"6px",border:"colorblind"===i1?"1px solid rgba(250,204,21,0.5)":"1px solid rgba(255,255,255,0.1)",background:"colorblind"===i1?"rgba(250,204,21,0.15)":"rgba(255,255,255,0.05)",color:"colorblind"===i1?"#facc15":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"Yellow/Blue"})]})]})]})})]}),(0,i.jsxs)("div",{...controlCardHover("ema"),style:{flex:"1 0 0",padding:"6px",borderRadius:"5px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t4||"ema"===t1?"8px":"0"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"EMA Channel"}),(0,i.jsx)("button",{onClick:()=>rA(!rL),style:{padding:"4px 10px",borderRadius:"6px",border:rL?"1px solid rgba(34, 197, 94, 0.5)":"1px solid rgba(255,255,255,0.1)",background:rL?"rgba(34, 197, 94, 0.2)":"rgba(255,255,255,0.05)",color:rL?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:rL?"On":"Off"})]}),(0,i.jsx)("div",{style:controlCardBodyStyle("ema"),children:(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:"12px"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",whiteSpace:"nowrap"},children:"Fast EMA"}),(0,i.jsx)("input",{type:"range",min:3,max:72,step:1,value:rF,onChange:e=>rN(parseInt(e.target.value)),style:{flex:"1 1 auto",minWidth:0}}),(0,i.jsx)(SliderPill,{name:"emaFast",value:rF})]}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",whiteSpace:"nowrap"},children:"Slow EMA"}),(0,i.jsx)("input",{type:"range",min:3,max:72,step:1,value:rB,onChange:e=>rW(parseInt(e.target.value)),style:{flex:"1 1 auto",minWidth:0}}),(0,i.jsx)(SliderPill,{name:"emaSlow",value:rB})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Fill Opacity"}
1),(0,i.jsx)("input",{type:"range",min:.05,max:1,step:.05,value:rO,onChange:e=>rV(parseFloat(e.target.value)),style:{width:"100%"}}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:[(0,i.jsxs)("span",{children:[Math.round(100*rO),"% fill"]}),(0,i.jsx)("span",{children:"colorblind"===rU?"blue = fast leading":"green = fast leading"})]})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Color Mode"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"6px"},children:[(0,i.jsx)("button",{onClick:()=>rH("default"),style:{padding:"4px 8px",borderRadius:"6px",border:"default"===rU?"1px solid rgba(34,197,94,0.5)":"1px solid rgba(255,255,255,0.1)",background:"default"===rU?"rgba(34,197,94,0.15)":"rgba(255,255,255,0.05)",color:"default"===rU?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"Red/Green"}),(0,i.jsx)("button",{onClick:()=>rH("colorblind"),style:{padding:"4px 8px",borderRadius:"6px",border:"colorblind"===rU?"1px solid rgba(250,204,21,0.5)":"1px solid rgba(255,255,255,0.1)",background:"colorblind"===rU?"rgba(250,204,21,0.15)":"rgba(255,255,255,0.05)",color:"colorblind"===rU?"#facc15":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"Yellow/Blue"})]})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"EMA Alarm"}),(0,i.jsx)("button",{onClick:()=>rY(e=>!e),style:{padding:"4px 10px",borderRadius:"6px",border:rq?"1px solid rgba(250, 204, 21, 0.5)":"1px solid rgba(255,255,255,0.1)",background:rq?"rgba(250, 204, 21, 0.15)":"rgba(255,255,255,0.05)",color:rq?"#facc15":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",width:"100%"},children:rq?"Alarm On":"Alarm Off"})]})]})})]}),(0,i.jsxs)("div",{...controlCardHover("candle"),style:{flex:"1 1 0",padding:"12px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t4||"candle"===t1?"8px":"0"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Candle Channel"}),(0,i.jsx)("button",{onClick:()=>id(!is),style:{padding:"4px 10px",borderRadius:"6px",border:is?"1px solid rgba(168, 85, 247, 0.5)":"1px solid rgba(255,255,255,0.1)",background:is?"rgba(168, 85, 247, 0.2)":"rgba(255,255,255,0.05)",color:is?"#c084fc":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:is?"On":"Off"})]}),(0,i.jsx)("div",{style:controlCardBodyStyle("candle"),children:(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(100px, 1fr))",gap:"12px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Fill Opacity"}),(0,i.jsx)("input",{type:"range",min:.05,max:1,step:.05,value:ic,onChange:e=>iu(parseFloat(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[Math.round(100*ic),"% fill"]})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Color Mode"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"6px"},children:[(0,i.jsx)("button",{onClick:()=>ih("default"),style:{padding:"4px 8px",borderRadius:"6px",border:"default"===ip?"1px solid rgba(34,197,94,0.5)":"1px solid rgba(255,255,255,0.1)",background:"default"===ip?"rgba(34,197,94,0.15)":"rgba(255,255,255,0.05)",color:"default"===ip?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"Red/Green"}),(0,i.jsx)("button",{onClick:()=>ih("colorblind"),style:{padding:"4px 8px",borderRadius:"6px",border:"colorblind"===ip?"1p
1x solid rgba(250,204,21,0.5)":"1px solid rgba(255,255,255,0.1)",background:"colorblind"===ip?"rgba(250,204,21,0.15)":"rgba(255,255,255,0.05)",color:"colorblind"===ip?"#facc15":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"Yellow/Blue"})]})]})]})})]}),(0,i.jsxs)("div",{...controlCardHover("fourier"),style:{flex:"1 1 140px",minWidth:0,padding:"12px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t4||"fourier"===t1?"8px":"0"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Fourier Oscillator"}),(0,i.jsx)("button",{type:"button",onClick:()=>{ix(!0),od(!0),i_(e=>e+1)},style:{padding:"4px 10px",borderRadius:"6px",border:"1px solid rgba(6, 182, 212, 0.5)",background:"rgba(6, 182, 212, 0.2)",color:"#22d3ee",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"Focus mesh"}),(0,i.jsx)("button",{onClick:()=>ix(!ig),style:{padding:"4px 10px",borderRadius:"6px",border:ig?"1px solid rgba(6, 182, 212, 0.5)":"1px solid rgba(255,255,255,0.1)",background:ig?"rgba(6, 182, 212, 0.2)":"rgba(255,255,255,0.05)",color:ig?"#22d3ee":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:ig?"On":"Off"})]}),(0,i.jsxs)("div",{style:controlCardBodyStyle("fourier"),children:[(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(100px, 1fr))",gap:"12px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Window Size"}),(0,i.jsx)("input",{type:"range",min:8,max:256,step:8,value:ib,onChange:e=>im(parseInt(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsx)("span",{children:ib})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"3D Window Samples"}),(0,i.jsx)("input",{"aria-label":"Fourier window samples",type:"range",min:2,max:24,step:1,value:iy,onChange:e=>iv(parseInt(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[iT.length," windows \xb7 8–",ib," bars"]})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"3D Color Map"}),(0,i.jsxs)("select",{"aria-label":"Fourier mesh color map",value:iw,onChange:e=>iS(e.target.value),style:{width:"100%",padding:"5px",color:"#cbd5e1",background:"#111827",border:"1px solid #334155",borderRadius:"6px"},children:[(0,i.jsx)("option",{value:"amplitude",children:"Trough / crest"}),(0,i.jsx)("option",{value:"phase",children:"Cycle phase"}),(0,i.jsx)("option",{value:"rainbow",children:"Rainbow"}),(0,i.jsx)("option",{value:"infrared",children:"Infrared"}),(0,i.jsx)("option",{value:"red-venus",children:"Red Venus"})]})]}),(0,i.jsxs)("div",{children:[(0,i.jsxs)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:["3D Opacity \xb7 ",Math.round(100*ik),"%"]}),(0,i.jsx)("input",{"aria-label":"Fourier mesh opacity",type:"range",min:.2,max:1,step:.05,value:ik,onChange:e=>ij(Number(e.target.value)),style:{width:"100%"}}),(0,i.jsxs)("label",{style:{display:"flex",gap:"5px",fontSize:"10px",color:"#94a3b8"},children:[(0,i.jsx)("input",{type:"checkbox",checked:iM,onChange:e=>iP(e.target.checked)}),"Mesh grid"]})]})]}),(0,i.jsx)("div",{style:{marginTop:"8px",fontSize:"10px",lineHeight:1.5,color:"#94a3b8"},children:"3D: X = chart time \xb7 Y = oscillator \xb7 Z = window length in bars. White contours show zero crossings. Colors show normalized oscillation, not spectral power."})]})]}),(0,i.jsxs)("div",{...controlCardHover("sma"),style:{flex:"1 1 0",padding:"12px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t4||"sma"===t1?"8px":"0"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"SMA Levels"}),(0,i.jsx)("button",{onClick:rR,style:{padding:"4px 10px",borderRadius:"6px",border:rj>0?"1px solid rgba(34, 197, 94, 0.5)":"1px solid rgba(255,255,255,0.1)",background:rj>0?"rgba(34, 197, 94, 0.2)":"rgba(255,255,255,0.05)",color:rj>0?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:rj>0?"On":"Off"})]}),(0,i.jsx)("div",{style:controlCardBodyStyle("sma"),children:(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(90px, 1fr))",gap:"12px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Count"}),(0,i.jsx)("input",{type:"range",min:1,max:9,step:1,value:rj,onChange:e=>rz(parseInt(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[rj," lines"]})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Mode"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"6px"},children:[(0,i.jsx)("button",{onClick:()=>rw("sma"),style:{padding:"4px 8px",borderRadius:"6px",border:"sma"===rv?"1px solid rgba(59,130,246,0.5)":"1px solid rgba(255,255,255,0.1)",background:"sma"===rv?"rgba(59,130,246,0.15)":"rgba(255,255,255,0.05)",color:"sma"===rv?"#60a5fa":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"SMA"}),(0,i.jsx)("button",{onClick:()=>rw("ema"),style:{padding:"4px 8px",borderRadius:"6px",border:"ema"===rv?"1px solid rgba(59,130,246,0.5)":"1px solid rgba(255,255,255,0.1)",background:"ema"===rv?"rgba(59,130,246,0.15)":"rgba(255,255,255,0.05)",color:"ema"===rv?"#60a5fa":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:"EMA"})]})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Density"}),(0,i.jsx)("input",{type:"range",min:0,max:100,step:1,value:rS,onChange:e=>
1rk(parseInt(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[rS,"%"]})})]}),(0,i.jsx)("div",{children:(0,i.jsxs)("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:[(0,i.jsx)("button",{onClick:()=>rI("rainbow"),style:{padding:"4px 8px",borderRadius:"6px",border:"rainbow"===rM?"1px solid rgba(250,204,21,0.5)":"1px solid rgba(255,255,255,0.1)",background:"rainbow"===rM?"rgba(250,204,21,0.15)":"rgba(255,255,255,0.05)",color:"rainbow"===rM?"#facc15":"rgba(255,255,255,0.6)",fontSize:"10px",fontWeight:600,cursor:"pointer"},children:"Rainbow"}),(0,i.jsx)("button",{onClick:()=>rI("darkBlue"),style:{padding:"4px 8px",borderRadius:"6px",border:"darkBlue"===rM?"1px solid rgba(59,130,246,0.5)":"1px solid rgba(255,255,255,0.1)",background:"darkBlue"===rM?"rgba(59,130,246,0.15)":"rgba(255,255,255,0.05)",color:"darkBlue"===rM?"#60a5fa":"rgba(255,255,255,0.6)",fontSize:"10px",fontWeight:600,cursor:"pointer"},children:"Dark Blue"}),(0,i.jsx)("button",{onClick:()=>rI("venusRed"),style:{padding:"4px 8px",borderRadius:"6px",border:"venusRed"===rM?"1px solid rgba(239,68,68,0.5)":"1px solid rgba(255,255,255,0.1)",background:"venusRed"===rM?"rgba(239,68,68,0.15)":"rgba(255,255,255,0.05)",color:"venusRed"===rM?"#f87171":"rgba(255,255,255,0.6)",fontSize:"10px",fontWeight:600,cursor:"pointer"},children:"Venus Red"})]})})]})})]}),(0,i.jsxs)("div",{...controlCardHover("bollinger"),style:{flex:"1 1 0",padding:"12px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t4||"bollinger"===t1?"8px":"0"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Band Indicator"}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,i.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"6px",padding:"2px",width:"128px"},children:[(0,i.jsx)("div",{style:{position:"absolute",top:"2px",left:"bollinger"===r2?"2px":"50%",width:"calc(50% - 2px)",height:"calc(100% - 4px)",background:"rgba(255,255,255,0.12)",borderRadius:"4px",transition:"left 0.2s ease"}}),(0,i.jsx)("button",{onClick:()=>r4("bollinger"),style:{flex:1,padding:"3px 0",border:"none",background:"transparent",color:"bollinger"===r2?"#fff":"rgba(255,255,255,0.5)",fontSize:"10px",fontWeight:600,cursor:"pointer",zIndex:1},children:"Bollinger"}),(0,i.jsx)("button",{onClick:()=>r4("ichimoku"),style:{flex:1,padding:"3px 0",border:"none",background:"transparent",color:"ichimoku"===r2?"#fff":"rgba(255,255,255,0.5)",fontSize:"10px",fontWeight:600,cursor:"pointer",zIndex:1},children:"Ichimoku"})]}),(0,i.jsx)("button",{onClick:()=>rX(!rK),style:{padding:"4px 10px",borderRadius:"6px",border:rK?"1px solid rgba(167, 139, 250, 0.5)":"1px solid rgba(255,255,255,0.1)",background:rK?"rgba(167, 139, 250, 0.2)":"rgba(255,255,255,0.05)",color:rK?"#a78bfa":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:rK?"On":"Off"})]})]}),(0,i.jsx)("div",{style:controlCardBodyStyle("bollinger"),children:(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(100px, 1fr))",gap:"12px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Period"}),(0,i.jsx)("input",{type:"range",min:5,max:60,step:1,value:rG,onChange:e=>rJ(parseInt(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[rG," bars"]})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Scaling"}),(0,i.jsx)("input",{type:"range",min:.5,max:4,step:.1,value:rQ,onChange:e=>r$(parseFloat(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[rQ.toFixed(1),"σ width"]})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Fill Opacity"}),(0,i.jsx)("input",{type:"range",min:.05,max:.8,step:.05,value:rZ,onChange:e=>r0(parseFloat(e.target.value)),style:{width:"100%"}}),(0,i.jsx)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:(0,i.jsxs)("span",{children:[Math.round(100*rZ),"% fill"]})})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Color Scheme"}),(0,i.jsx)("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:[{key:"emerald",label:"Emerald",rgb:"34,197,94"},{key:"ocean",label:"Ocean",rgb:"56,189,248"},{key:"sunset",label:"Sunset",rgb:"251,146,60"},{key:"violet",label:"Violet",rgb:"167,139,250"}].map(e=>(0,i.jsx)("button",{onClick:()=>r1(e.key),style:{padding:"4px 8px",borderRadius:"6px",border:r5===e.ke
1y?"1px solid rgba(".concat(e.rgb,",0.5)"):"1px solid rgba(255,255,255,0.1)",background:r5===e.key?"rgba(".concat(e.rgb,",0.15)"):"rgba(255,255,255,0.05)",color:r5===e.key?"rgb(".concat(e.rgb,")"):"rgba(255,255,255,0.6)",fontSize:"10px",fontWeight:600,cursor:"pointer"},children:e.label},e.key))})]})]})})]}),(0,i.jsxs)("div",{...controlCardHover("news"),style:{flex:"1 1 0",padding:"12px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t4||"news"===t1?"8px":"0"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"News Wire"}),(0,i.jsx)("button",{onClick:()=>r8(!r6),style:{padding:"4px 10px",borderRadius:"6px",border:r6?"1px solid rgba(103, 232, 249, 0.5)":"1px solid rgba(255,255,255,0.1)",background:r6?"rgba(103, 232, 249, 0.2)":"rgba(255,255,255,0.05)",color:r6?"#67e8f9":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:r6?"On":"Off"})]}),(0,i.jsxs)("div",{style:controlCardBodyStyle("news"),children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Scroll Speed"}),(0,i.jsx)("input",{type:"range",min:20,max:160,step:5,value:r3,onChange:e=>r9(parseInt(e.target.value)),style:{width:"100%"}})]}),(0,i.jsxs)("div",{style:{marginTop:"8px"},children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Headlines"}),(0,i.jsx)("button",{onClick:()=>ie(!r7),title:r7?"Showing only ".concat(f," headlines"):"Showing all headlines",style:{padding:"4px 10px",borderRadius:"6px",border:r7?"1px solid rgba(251, 191, 36, 0.5)":"1px solid rgba(255,255,255,0.1)",background:r7?"rgba(251, 191, 36, 0.15)":"rgba(255,255,255,0.05)",color:r7?"#fbbf24":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:r7?"".concat((f||"").toUpperCase()," only"):"All news"})]}),(0,i.jsxs)("div",{style:{marginTop:"8px"},children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Alarm"}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexWrap:"wrap"},children:[(0,i.jsx)("button",{onClick:()=>ir(!it),style:{padding:"4px 10px",borderRadius:"6px",border:it?"1px solid rgba(239, 68, 68, 0.5)":"1px solid rgba(255,255,255,0.1)",background:it?"rgba(239, 68, 68, 0.15)":"rgba(255,255,255,0.05)",color:it?"#f87171":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:it?"On":"Off"}),(0,i.jsx)("button",{onClick:()=>io(e=>"high"===e?"low":"high"),disabled:!it,style:{padding:"4px 10px",borderRadius:"6px",border:"1px solid rgba(251, 191, 36, 0.4)",background:it&&"high"===ii?"rgba(251, 191, 36, 0.15)":"rgba(255,255,255,0.05)",color:it?"high"===ii?"#fbbf24":"rgba(255,255,255,0.5)":"rgba(255,255,255,0.3)",fontSize:"11px",fontWeight:600,cursor:it?"pointer":"not-allowed",transition:"all 0.2s ease"},children:"high"===ii?"High":"Low"})]}),(0,i.jsx)("div",{style:{marginTop:"4px",fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:it?"high"===ii?"High: 1-2 stars and 4-5 stars events":"Low: 1 and 5 stars events":"Alarm off"}),(0,i.jsxs)("div",{style:{marginTop:"6px"},children:[(0,i.jsxs)("label",{style:{display:"block",fontSize:"10px",color:"rgba(255,255,255,0.5)",marginBottom:"2px"},children:["Check every ",il,"m"]}),(0,i.jsx)("input",{type:"range",min:1,max:5,step:2,value:il,onChange:e=>ia(parseInt(e.target.value)),style:{width:"100%"}})]})]}),(0,i.jsx)("a",{href:"/sentiment",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",marginTop:"8px",fontSize:"11px",color:"#67e8f9",textDecoration:"none"},onMouseEnter:e=>e.currentTarget.style.textDecoration="underline",onMouseLeave:e=>e.currentTarget.style.textDecoration="none",children:"Sentiment Dashboard ↗"})]})]})]})]})}),rm.length>0&&(0,i.jsx)("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginBottom:"8px"},children:rm.map(e=>(0,i.jsxs)("span",{style:{padding:"4px 8px",borderRadius:"6px",background:"rgba(255,255,255,0.06)",color:"#fff",fontSize:"11px",display:"flex",alignItems:"center",gap:"4px"},children:[e,(0,i.jsx)("button",{onClick:()=>removeIndicator(e),style:{background:"none",border:"none",color:"#f87171",cursor:"pointer",fontSize:"11px",padding:0},children:"x"})]},e))}),tJ&&(0,i.jsxs)("div",{style:{marginBottom:"12px",padding:"12px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[(0,i.jsx)("div",{style:{fontSize:"12px",fontWeight:600,color:"#fbbf24"},children:"PineScript Editor"}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,i.jsxs)("label",{style:{fontSize:"12px",color:"#93c5fd",cursor:"pointer"},children:["Import .pine",(0,i.jsx)("input",{type:"file",accept:".pine,.txt,.js",onChange:e=>{var t;let r=null===(t=e.target.files)||void 0===t?void 0:t[0];if(!r)return;let i=new FileReader;i.onload=e=>{var t,r;of.current=!0,tK&&(tG.current=tK),tX(String(null!==(r=null===(t=e.target)||void 0===t?void 0:t.result)&&void 0!==r?r:"")),rf(!1)},i.readAsText(r)},style:{display:"none"}})]}),(0,i.jsx)("button",{onClick:()=>{localStorage.setItem("opencharts_pinescript_code",tK),rf(!1)},style:{padding:"2px 8px",borderRadius:"4px",border:"1px solid rgba(34, 197, 94, 0.4)",background:"rgba(34, 197, 94, 0.12)",color:"#4ade80",fontSize:"11px",cursor:"pointer"},children:"Save"}),(0,i.jsx)("span",{style:{fontSize:"11px",color:"rgba(255,255,255,0.45)"},children:"Pine Script v5+"}),(0,i.jsx)("a",{href:"https://github.com/topics/pinescript-strategies",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"#93c5fd"},children:"Examples"}),(0,i.jsx)("button",{onClick:()=>tZ(!t$),style:{padding:"2px 6px",borderRadius:"4px",border:"1px solid rgba(255,255,255,0.15)",background:"rgba(255,255,255,0.06)",color:"rgba(255,255,255,0.7)",fontSize:"11px",cursor:"pointer"},children:t$?"Collapse":"Expand"})]})]}),(0,i.jsxs)("div",{style:{position:"relative",width:"100%"},children:[Object.keys(C).length>0&&(0,i.jsx)("div",{style:{position:"absolute",top:0,left:0,right:0,display:"flex",gap:"6px",flexWrap:"wrap",padding:"6px 10px",background:"rgba(7, 11, 24, 0.85)",borderBottom:"1px solid rgba(255,255,255,0.08)",zIndex:2,borderTopLeftRadius:"8px",borderTopRightRadius:"8px"},children:Object.entries(C).map(e=>{let[t,r]=e;return(0,i.jsxs)("div",{draggable:!0,onDragStart:e=>{e.dataTransfer.setData("text/plain","".concat(t," = ").concat(r)),e.dataTransfer.effectAllowed="copy"},title:"Drag to insert ".concat(t," = ").concat(r),style:{display:"inline-flex",alignItems:"center",padding:"2px 8px",borderRadius:"999px",background:"rgba(59, 130, 246, 0.15)",border:"1px solid rgba(59, 130, 246, 0.25)",color:"#93c5fd",fontSize:"11px",cursor:"grab",userSelect:"none"},children:[t,": ",r]},t)}
1)}),(0,i.jsx)("textarea",{ref:om,value:tK,onChange:e=>{tX(e.target.value),rf(!1)},onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="copy"},onDrop:e=>{e.preventDefault();let t=e.dataTransfer.getData("text/plain"),r=e.currentTarget;if(!t||!r)return;let i=function(e,t,r){let i=e.getBoundingClientRect();if(t<i.left||t>i.right||r<i.top||r>i.bottom)return e.selectionStart;let n=window.getComputedStyle(e),o=document.createElement("div");o.contentEditable="true",o.textContent=e.value,Object.assign(o.style,{position:"fixed",left:"".concat(i.left,"px"),top:"".concat(i.top,"px"),width:"".concat(i.width,"px"),height:"".concat(i.height,"px"),padding:n.padding||"".concat(n.paddingTop," ").concat(n.paddingRight," ").concat(n.paddingBottom," ").concat(n.paddingLeft),border:n.border,boxSizing:n.boxSizing,font:n.font||"".concat(n.fontStyle," ").concat(n.fontVariant," ").concat(n.fontWeight," ").concat(n.fontSize,"/").concat(n.lineHeight," ").concat(n.fontFamily),lineHeight:n.lineHeight,letterSpacing:n.letterSpacing,whiteSpace:"pre-wrap",wordWrap:"break-word",overflowWrap:"break-word",overflow:"auto",resize:"none",outline:"none",color:"transparent",background:"rgba(0,0,0,0.001)",zIndex:"10000"}),document.body.appendChild(o),o.getBoundingClientRect();let l=e.selectionStart;try{var a,s,d,c,u,p,h;let i=null!==(u=null===(a=(s=document).caretPositionFromPoint)||void 0===a?void 0:a.call(s,t,r))&&void 0!==u?u:null===(d=(c=document).caretRangeFromPoint)||void 0===d?void 0:d.call(c,t,r);if(i){let t=null,r=0;if(void 0!==i.offsetNode&&void 0!==i.offset){if(i.offsetNode.nodeType===Node.TEXT_NODE)t=i.offsetNode,r=i.offset;else{let e=null===(p=i.offsetNode.childNodes)||void 0===p?void 0:p[i.offset];(null==e?void 0:e.nodeType)===Node.TEXT_NODE&&(t=e)}}else if(void 0!==i.startContainer&&void 0!==i.startOffset){if(i.startContainer.nodeType===Node.TEXT_NODE)t=i.startContainer,r=i.startOffset;else{let e=null===(h=i.startContainer.childNodes)||void 0===h?void 0:h[i.startOffset];(null==e?void 0:e.nodeType)===Node.TEXT_NODE&&(t=e)}}if(t){let i=0,n=document.createTreeWalker(o,NodeFilter.SHOW_TEXT),a=n.nextNode();for(;a;){if(a===t){i+=r;break}i+=a.length,a=n.nextNode()}l=Math.min(i,e.value.length)}}}catch(e){}return o.parentNode&&o.parentNode.removeChild(o),l}(r,e.clientX,e.clientY),n=tK.slice(0,i)+t+tK.slice(i);tX(n),rf(!1),setTimeout(()=>{r.focus();let e=i+t.length;r.setSelectionRange(e,e)},0)},rows:t$?24:8,style:{width:"100%",resize:"vertical",minHeight:t$?"480px":"160px",padding:"40px 10px 10px",borderRadius:"8px",background:"rgba(0,0,0,0.2)",color:rb?"#86efac":"#fff",border:rb?"1px solid rgba(34,197,94,0.4)":"1px solid rgba(255,255,255,0.1)",fontFamily:"monospace",fontSize:"12px",boxSizing:"border-box"}})]}),sm.length>0&&(0,i.jsxs)("details",{style:{marginTop:"12px"},children:[(0,i.jsxs)("summary",{style:{cursor:"pointer",fontSize:"11px",fontWeight:600,color:"rgba(255,255,255,0.6)",letterSpacing:"0.06em",textTransform:"uppercase",userSelect:"none"},children:["Indicator Settings (",sm.length,")"]}),(0,i.jsx)("div",{style:{marginTop:"10px",display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:"12px"},children:sm.map(e=>renderPineInput(e))})]}),(0,i.jsxs)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsx)("div",{style:{fontSize:"12px",fontWeight:600,color:"#fbbf24",marginBottom:"8px"},children:"Modify Strategy with AI"}),(0,i.jsx)("textarea",{value:rc,onChange:e=>ru(e.target.value),placeholder:"Explain your strategy modification",rows:3,style:{width:"100%",padding:"8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(0,0,0,0.2)",color:"#fff",fontSize:"12px",marginBottom:"8px",resize:"vertical"}}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px"},children:[(0,i.jsx)("button",{onClick:modifyStrategy,disabled:rp||!rc.trim(),style:{padding:"6px 12px",borderRadius:"6px",border:"1px solid rgba(168,85,247,0.4)",background:rp?"rgba(168,85,247,0.1)":"rgba(168,85,247,0.2)",color:"#c4b5fd",fontSize:"12px",fontWeight:600,cursor:rp?"not-allowed":"pointer"},children:rp?"Thinking... ":"Finetune your Strategy"}),(0,i.jsx)("button",{onClick:insertLiveIndicators,disabled:rg||0===Object.keys(C).length,style:{padding:"6px 12px",borderRadius:"6px",border:"1px solid rgba(59,130,246,0.4)",background:rg?"rgba(59,130,246,0.1)":"rgba(59,130,246,0.2)",color:"#93c5fd",fontSize:"12px",fontWeight:600,cursor:rg?"not-allowed":"pointer"},children:rg?"Inserting... ":"Insert Live Indicators"}),(0,i.jsx)("button",{onClick:()=>
1{tG.current&&(tX(tG.current),rf(!1))},disabled:!tG.current,style:{padding:"6px 12px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.06)",color:"rgba(255,255,255,0.85)",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:"↺ Undo Last Change"})]})]})]}),tf&&th&&(0,i.jsxs)("div",{style:{display:"flex",gap:"12px",marginBottom:"12px",fontSize:"12px",color:"rgba(255,255,255,0.7)"},children:[(0,i.jsxs)("span",{children:["Trades: ",th.total_closed_trades]}),(0,i.jsxs)("span",{children:["Net: $",null!==(u=null===(r=th.net_profit)||void 0===r?void 0:r.toFixed(2))&&void 0!==u?u:"0.00"]}),(0,i.jsxs)("span",{children:["Win: ",null!==(p=null===(o=th.win_rate)||void 0===o?void 0:o.toFixed(1))&&void 0!==p?p:0,"%"]})]}),tf&&sd.length>0&&(0,i.jsxs)("div",{style:{maxHeight:"140px",overflowY:"auto",marginBottom:"12px",padding:"10px",borderRadius:"10px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto"},children:[(0,i.jsx)("div",{style:{fontSize:"12px",fontWeight:600,color:"#fbbf24",marginBottom:"8px"},children:"Trades"}),sd.map((e,t)=>{var r,n,o;let l=e.time&&new Date(e.time).toLocaleString()||"N/A",a="number"==typeof e.profit?e.profit:0,s="number"==typeof e.price?e.price.toFixed(2):"—",d="number"==typeof e.entry?e.entry.toFixed(2):(null===(r=e.type)||void 0===r?void 0:r.includes("Entry"))?s:"—",c="number"==typeof e.exit?e.exit.toFixed(2):(null===(n=e.type)||void 0===n?void 0:n.includes("Exit"))?s:"—";return(0,i.jsxs)("div",{onMouseEnter:e=>{tV(t),tH({x:e.clientX,y:e.clientY})},onMouseMove:e=>tH({x:e.clientX,y:e.clientY}),onMouseLeave:()=>{tV(null),tH(null)},style:{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:"11px",color:"rgba(255,255,255,0.8)",padding:"4px 8px",borderRadius:"4px",background:tO===t?"rgba(255,255,255,0.08)":"transparent",borderBottom:t<sd.length-1?"1px solid rgba(255,255,255,0.05)":"none",cursor:"pointer"},children:[(0,i.jsx)("span",{style:{minWidth:"120px"},children:l}),(0,i.jsx)("span",{style:{minWidth:"80px",color:(null===(o=e.type)||void 0===o?void 0:o.includes("Long"))?"#60a5fa":"#f87171"},children:e.type||e.signal}),(0,i.jsxs)("span",{style:{minWidth:"60px",color:"rgba(255,255,255,0.6)"},children:["$",d]}),(0,i.jsxs)("span",{style:{minWidth:"60px",color:"rgba(255,255,255,0.6)"},children:["$",c]}),(0,i.jsxs)("span",{style:{minWidth:"80px",color:a>=0?"#0ecb81":"#f6465d"},children:[a>=0?"+":"",a.toFixed(2)]})]},t)})]}),null!=tO&&tU&&(0,i.jsx)("div",{style:{position:"fixed",left:tU.x+12,top:tU.y+12,zIndex:100,pointerEvents:"none",minWidth:"180px",padding:"10px",borderRadius:"8px",background:"rgba(7,11,24,0.95)",border:"1px solid rgba(255,255,255,0.12)",boxShadow:"0 8px 24px rgba(0,0,0,0.4)",backdropFilter:"blur(6px)",color:"#fff",fontSize:"11px"},children:(()=>{var e,t,r;let n=sd[tO];if(!n)return null;let o="number"==typeof n.entry?n.entry.toFixed(2):"number"==typeof n.price?n.price.toFixed(2):"—",l="number"==typeof n.exit?n.exit.toFixed(2):"—",a=null!==(r=null!==(t=n.size)&&void 0!==t?t:n.qty)&&void 0!==r?r:"—",s="number"==typeof n.profit?n.profit:0;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{style:{fontWeight:700,marginBottom:"6px",color:(null===(e=n.type)||void 0===e?void 0:e.includes("Long"))?"#60a5fa":"#f87171"},children:n.type||n.signal}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"4px 12px"},children:[(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Entry"}),(0,i.jsxs)("span",{children:["$",o]}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Exit"}),(0,i.jsxs)("span",{children:["$",l]}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Size"}),(0,i.jsx)("span",{children:a}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:"P&L"}),(0,i.jsxs)("span",{style:{color:s>=0?"#0ecb81":"#f6465d"},children:[s>=0?"+":"",s.toFixed(2)]}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Win"}),(0,i.jsx)("span",{style:{color:s>=0?"#0ecb81":"#f6465d"},children:s>=0?"Yes":"No"})]})]})})()}),(0,i.jsxs)("div",{style:{position:"relative",width:"100%",flex:"1 1 0",minHeight:"180px",display:"flex",flexDirection:"column",cursor:e6?"grabbing":e3?"grab":"default"},onMouseMove:e=>{var t;if(null===(t=og.current)||void 0===t||!t.contains(e.target)){if(e2){if(e6){e.preventDefault(),updateDraggedRiskLevel(e.clientY);return}e9(findRiskLevelAtPoint(e.clientY))}e1.length>10?te(findPositionAtPoint(e.clientY)):te(null)}},onMouseDown:e=>{var t,r;if((null===(t=og.current)||void 0===t?void 0:t.contains(e.target))||!e2)return;let i=findRiskLevelAtPoint(e.clientY);i&&(e.preventDefault(),null===(r=eh.current)||void 0===r||r.applyOptions({handleScroll:!1,handleScale:!1}),e8(i))},onMouseUp:e=>{var t,r;if(e2&&(null===(t=og.current)||void 0===t||!t.contains(e.target))){if(e6&&N){let{positionId:e,level:t,price:r}=e6,i=e1.find(t=>String(t.id)===e);if(!i)return;N(e,t,r)}e8(null),e9(null),te(null),null===(r=eh.current)||void 0===r||r.applyOptions({handleScroll:!0,handleScale:!0})}},onMouseLeave:()=>{var e;e8(null),e9(null),te(null),null===(e=eh.current)||void 0===e||e.applyOptions({handleScroll:!0,handleScale:!0})},children:[(0,i.jsxs)("div",{ref:eu,style:{position:"relative",width:"100%",flex:"1 1 0",minHeight:0},children:[(0,i.jsx)(PineTableOverlay,{tables:(null==tk?void 0:tk.tables)||[]}),(0,i.jsx)(NewsTicker,{visible:r6,speed:r3,symbol:f,pairOnly:r7,alarmEnabled:it,alarmSensitivity:ii,refreshMin:il}),ea&&a7&&(0,i.jsxs)(MovableIndicatorToolbox,{title:"MACD Moving Average Convergence Divergence",open:iR,setOpen:iz,pos:iD,setPos:iL,signal:(0,i.jsx)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",borderRadius:"999px",fontSize:"11px",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",background:a3.active?"rgba(34, 197, 94, 0.2)":"rgba(255,255,255,0.08)",border:a3.active?"1px solid rgba(34, 197, 94, 0.5)":"1px solid rgba(255,255,255,0.15)",color:a3.active?"#4ade80":"rgba(255,255,255,0.4)",transition:"all 0.3s ease"},title:a3.active?"MACD line crossed above signal (bullish)":"MACD line below or crossing signal",children:(0,i.jsx)("span",{style:{display:"inline-block",width:"12px",height:"12px",borderRadius:"50%",background:a3.active?"#4ade80":"rgba(255,255,255,0.3)",boxShadow:a3.active?"0 0 6px #4ade80":"none",transition:"all 0.3s ease"}})}),children:[(0,i.jsx)("div",{style:{height:"160px"},children:(0,i.jsx)(E.kL,{type:"line",data:a7,options:st})}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(80px, 1fr))",gap:"12px",marginTop:"8px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("input",{type:"range",min:5,max:20,step:1,value:iN,onChange:e=>{let t=parseInt(e.target.value);
1iB(t),updateExternalInput("macdFast",t),runSimulation()},style:{width:"100%"}}),(0,i.jsx)(SliderPill,{name:"macdFast",value:iN})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("input",{type:"range",min:15,max:50,step:1,value:iW,onChange:e=>{let t=parseInt(e.target.value);iO(t),updateExternalInput("macdSlow",t),runSimulation()},style:{width:"100%"}}),(0,i.jsx)(SliderPill,{name:"macdSlow",value:iW})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("input",{type:"range",min:5,max:20,step:1,value:iV,onChange:e=>{let t=parseInt(e.target.value);iU(t),updateExternalInput("macdSignal",t),runSimulation()},style:{width:"100%"}}),(0,i.jsx)(SliderPill,{name:"macdSignal",value:iV})]})]})]}),ea&&a9&&(0,i.jsxs)(MovableIndicatorToolbox,{title:"Stochastic RSI",open:iI,setOpen:iE,pos:iA,setPos:iF,signal:(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",borderRadius:"999px",fontSize:"11px",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",background:a8.active?"rgba(34, 197, 94, 0.2)":"rgba(255,255,255,0.08)",border:a8.active?"1px solid rgba(34, 197, 94, 0.5)":"1px solid rgba(255,255,255,0.15)",color:a8.active?"#4ade80":"rgba(255,255,255,0.4)",transition:"all 0.3s ease"},title:a8.active?"RSI: ".concat(null===(l=a8.value)||void 0===l?void 0:l.toFixed(2)," (oversold / bounce)"):"RSI: ".concat(null!==(h=null===(s=a8.value)||void 0===s?void 0:s.toFixed(2))&&void 0!==h?h:"N/A"),children:[(0,i.jsx)("span",{style:{display:"inline-block",width:"12px",height:"12px",borderRadius:"50%",background:a8.active?"#4ade80":"rgba(255,255,255,0.3)",boxShadow:a8.active?"0 0 6px #4ade80":"none",transition:"all 0.3s ease"}}),a8.active?"Bullish":"No Signal"]}),children:[(0,i.jsx)("div",{style:{height:"160px"},children:(0,i.jsx)(E.kL,{type:"line",data:a9,options:se})}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(70px, 1fr))",gap:"12px",marginTop:"8px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"RSI Period"}),(0,i.jsx)("input",{type:"range",min:7,max:30,step:1,value:iH,onChange:e=>{let t=parseInt(e.target.value);iq(t),updateExternalInput("rsiPeriod",t),runSimulation()},style:{width:"100%"}}),(0,i.jsx)(SliderPill,{name:"rsiPeriod",value:iH})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Stoch Period"}),(0,i.jsx)("input",{type:"range",min:5,max:30,step:1,value:iY,onChange:e=>{let t=parseInt(e.target.value);iK(t),updateExternalInput("stochPeriod",t),runSimulation()},style:{width:"100%"}}),(0,i.jsx)(SliderPill,{name:"stochPeriod",value:iY})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"K Smooth"}),(0,i.jsx)("input",{type:"range",min:2,max:10,step:1,value:iX,onChange:e=>{let t=parseInt(e.target.value);iG(t),updateExternalInput("stochKSmooth",t),runSimulation()},style:{width:"100%"}}),(0,i.jsx)(SliderPill,{name:"stochKSmooth",value:iX})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"D Smooth"}),(0,i.jsx)("input",{type:"range",min:2,max:10,step:1,value:iJ,onChange:e=>{let t=parseInt(e.target.value);iQ(t),updateExternalInput("stochDSmooth",t),runSimulation()},style:{width:"100%"}}),(0,i.jsx)(SliderPill,{name:"stochDSmooth",value:iJ})]})]})]}),i4&&(0,i.jsx)("canvas",{ref:nl,style:{position:"absolute",top:0,right:nn,width:"80px",height:"100%",pointerEvents:"none",zIndex:2}}),null!=eo&&null!=el&&(0,i.jsxs)("div",{className:"ocp-timeframe-bar",style:{position:"absolute",top:54,left:12,display:"flex",flexWrap:"wrap",gap:"4px",zIndex:30,background:"rgba(7, 11, 24, 0.72)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"8px",padding:"4px",backdropFilter:"blur(6px)",pointerEvents:"auto"},children:[q.map(e=>{let t=eo===e,r=e<=.125?"#22c55e":e<=30?"#facc15":"#fb923c";return(0,i.jsx)("button",{onClick:()=>el(e),style:{padding:"4px 10px",borderRadius:"6px",border:t?"1px solid ".concat(r):"1px solid rgba(255,255,255,0.12)",background:t?"".concat(r,"22"):"rgba(255,255,255,0.06)",color:t?r:"rgba(255,255,255,0.55)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease",opacity:t?1:.85,boxShadow:t?"0 0 8px 1px ".concat(r,"66, inset 0 0 6px 1px ").concat(r,"1a"):"none",textShadow:t?"0 0 4px ".concat(r,"aa"):"none"},children:e<=7e-4?"1M":.04===e?"1H":.125===e?"3H":1===e?"1D":7===e?"7D":30===e?"30D":90===e?"90D":"1Y"},e)}),(0,i.jsx)("button",{onClick:()=>{var e;return null===(e=eh.current)||void 0===e?void 0:e.timeScale().fitContent()},style:{padding:"4px 10px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(255,255,255,0.05)",color:"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:"Reset Zoom"})]}),"ai-analyse"===nh&&(0,i.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:20,cursor:"crosshair"},onPointerDown:e=>{var t;let r=null===(t=eu.current)||void 0===t?void 0:t.getBoundingClientRect();if(!r||!eh.current)return;let i=e.clientX-r.left,n=eh.current.timeScale().coordinateToTime(i);if(null==n)return;e.target.setPointerCapture(e.pointerId);let o="number"==typeof n?n:Math.floor(new Date(n).getTime()/1e3);nb(o),nm(o),nj(""),nS("")},onPointerMove:e=>{if(1!==e.buttons||!eh.current||!eu.current)return;let t=eu.current.getBoundingClientRect(),r=e.clientX-t.left,i=eh.current.timeScale().coordinateToTime(r),n=null!=i?"number"==typeof i?i:Math.floor(new Date(i).getTime()/1e3):null;null!=n&&nm(n)},onPointerUp:e=>{if(!eh.current||!eu.current)return;let t=eu.current.getBoundingClientRect(),r=e.clientX-t.left,i=eh.current.timeScale().coordinateToTime(r),n=null!=i?"number"==typeof i?i:Math.floor(new Date(i).getTime()/1e3):null;null!=n&&nm(n)},children:null!=nx&&null!=nf&&eh.current&&(()=>{let e=eh.current.timeScale().timeToCoordinate(nx),t=eh.current.timeScale().timeToCoordinate(nf);return null==e||null==t?null:(0,i.jsx)("div",{style:{position:"absolute",top:0,left:Math.min(e,t),width:Math.abs(t-e),height:"100%",background:"rgba(59,130,246,0.18)",border:"1px solid rgba(59,130,246,0.5)",pointerEvents:"none",zIndex:21}})})()}),"grid"===lA&&"limit"===lj&&"grid"===l_&&(0,i.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:20,cursor:"ns-resize"},onPointerDown:e=>{var t,r;let i=null===(t=eu.current)||void 0===t?void 0:t.getBoundingClientRect();if(!i||!eg.current)return;let n=e.clientY-i.top,o=eg.current.coordinateToPrice(n);null!=o&&Number.isFinite(o)&&!(o<=0)&&(null===(r=eh.current)||void 0===r||r.applyOptions({handleScroll:!1,handleScale:!1}),e.target.setPointerCapture(e.pointerId),l$(n),l0(n))},onPointerMove:e=>{if(1!==e.buttons||!eu.current||!eg.current||null==lQ)return;let t=eu.current.getBoundingClientRect(),r=e.clientY-t.top,i=eg.current.coordinateToPrice(lQ),n=eg.current.coordinateToPrice(r);if(null==i||null==n||!Number.isFinite(i)||!Number.isFinite(n))return;l0(r);let o=Math.min(i,n),l=Math.max(i,n);lz(o>=100?o.toFixed(2):o.toFixed(4)),lE(l>=100?l.toFixed(2):l.toFixed(4))},onPointerUp:e=>{var t;if(!eu.current||!eg.current||null==lQ)return;let r=eu.current.getBoundingClientRect(),i=e.clientY-r.top,n=eg.current.coordinateToPrice(lQ),o=eg.current.coordinateToPrice(i);if(null!=n&&null!=o&&Number.isFinite(n)&&Number.isFinite(o)){let e=Math.min(n,o),t=Math.max(n,o);lz(e>=100?e.toFixed(2):e.toFixed(4)),lE(t>=100?t.toFixed(2):t.toFixed(4)),l0(i)}lF("off"),null===(t=eh.current)||void 0===t||t.applyOptions({handleScroll:!0,handleScale:!0})},onPointerCancel:()=>{var e;l$(null),l0(null),lF("off"),null===(e=eh.current)||void 0===e||e.applyOptions({handleScroll:!0,handleScale:!0})},children:null!=lQ&&null!=lZ&&(0,i.jsx)("div",{style:{position:"absolute",left:0,top:Math.min(lQ,lZ),width:"100%",height:Math.max(2,Math.abs(lZ-lQ)),background:"rgba(52,211,153,0.16)",border:"1px solid rgba(52,211,153,0.45)",pointerEvents:"none",zIndex:21}})}),os&&(0,i.jsx)("div",{style:{position:"absolute",inset:0,zIndex:12,pointerEvents:"auto"},children:(0,i.jsx)(CandleReplay3D,{ohlc:a5,anchoredVwapData:a0,anchoredVwapPicking:l2,getAnchoredVwapPreview:e=>calculateAnchoredVwap(aZ,e),onAnchoredVwapCommit:e=>{l8(e),l4(!1),l1(!0)},onAnchoredVwapCancel:()=>l4(!1),anchoredVwapColor:H.color,anchoredVwapBandOpacity:H.bandOpacity,currentIndex:Math.max(0,a5.length-1),playbackPrice:x||(g.length?Number(g[g.length-1][4]):0),showEmaChannel:rL,emaFast:rF,emaSlow:rB,emaChannelOpacity:rO,showBollinger:rK,bollingerPeriod:rG,bollingerMult:rQ,bollingerOpacity:rZ,bollingerScheme:r5,showSmaCrowd:rj>0,smaCount:rj,smaMode:rv,rainbowDensity:rS,showFourierOscillator:ig,fourierWindowSize:ib,fourierTimeframes:iT,fourierHistory:a1,fourierColorMode:iw,fourierMeshOpacity:ik,fourierWireframe:iM,fourierFocusRequest:iC})}),(0,i.jsx)("button",{type:"button",onClick:()=>od(e=>!e),style:{position:"absolute",top:"84px",right:"10px",zIndex:50,padding:"5px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.15)",background:"rgba(7, 11, 24, 0.7)",color:"#fff",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:os?"2D":"3D"}),sm.length>0&&(0,i.jsx)("button",{type:"button",title:"".concat((null==nu?void 0:nu.title)||"Indicator"," settings — drag to move, click to open"),onPointerDown:e=>{var t,r,i,n;e.stopPropagation(),null===(t=(r=e.currentTarget).setPointerCapture)||void 0===t||t.call(r,e.pointerId);let o=e.currentTarget.getBoundingClientRect(),l=null===(i=eu.current)||void 0===i?void 0:i.getBoundingClientRect(),a=null!==(n=av.x)&&void 0!==n?n:l?o.left-l.left:0;aS.current={startX:e.clientX,startY:e.clientY,origX:a,origY:av.y,moved:!1}},onPointerMove:e=>{let t=aS.current;if(!t)return;let r=e.clientX-t.startX,i=e.clientY-t.startY;!t.moved&&Math.hypot(r,i)>4&&(t.moved=!0),t.moved&&aw({x:t.origX+r,y:t.origY+i})},onPointerUp:()=>{let e=aS.current;aS.current=null,e&&!e.moved&&ag(e=>!e)},onPointerCancel:()=>{aS.current=null},style:{position:"absolute",top:"".concat(av.y,"px"),...null!=av.x?{left:"".concat(av.x,"px")}
1:{right:"92px"},zIndex:50,width:"44px",height:"44px",borderRadius:"8px",border:ah?"1px solid rgba(96,165,250,0.6)":"1px solid rgba(255,255,255,0.15)",background:ah?"rgba(59,130,246,0.25)":"rgba(7, 11, 24, 0.7)",color:ah?"#93c5fd":"#fff",fontSize:"30px",lineHeight:1,cursor:"grab",touchAction:"none",display:"flex",alignItems:"center",justifyContent:"center",animation:ah?"none":"menu-handle-pulse 3.5s ease-in-out infinite"},children:"⚙"}),sm.length>0&&tw.length>0&&(0,i.jsx)("button",{type:"button",title:ak?"Unlock indicator — scale/move it independently":"Lock indicator — scale/move together with the chart",onClick:()=>aj(e=>!e),style:{position:"absolute",top:"".concat(av.y+52,"px"),...null!=av.x?{left:"".concat(av.x,"px")}:{right:"92px"},zIndex:50,width:"44px",height:"44px",borderRadius:"8px",border:ak?"1px solid rgba(96,165,250,0.6)":"1px solid rgba(255,255,255,0.15)",background:ak?"rgba(59,130,246,0.25)":"rgba(7, 11, 24, 0.7)",color:ak?"#93c5fd":"#fff",fontSize:"20px",lineHeight:1,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:ak?"\uD83D\uDD12":"\uD83D\uDD13"}),os&&(0,i.jsx)("div",{style:{position:"absolute",top:"10px",right:"80px",zIndex:100,padding:"5px 10px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.75)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.8)",fontSize:"11px",fontWeight:500,pointerEvents:"none",userSelect:"none",backdropFilter:"blur(4px)"},children:"Drag to rotate \xb7 Right-click / Shift + drag to pan \xb7 Wheel to zoom"}),os&&(0,i.jsxs)("div",{title:"Y scale — drag up/down or scroll \xb7 double-click to reset",onPointerDown:e=>{var t,r;e.stopPropagation(),null===(t=(r=e.target).setPointerCapture)||void 0===t||t.call(r,e.pointerId),tA.current={startY:e.clientY,startZoom:tL.current}},onPointerMove:e=>{let t=tA.current;t&&applyYZoom(t.startZoom*Math.exp((t.startY-e.clientY)*.006))},onPointerUp:()=>{tA.current=null},onPointerCancel:()=>{tA.current=null},onWheel:e=>{e.stopPropagation(),applyYZoom(tL.current*Math.exp(-(.0012*e.deltaY)))},onDoubleClick:()=>applyYZoom(1),style:{position:"absolute",right:12,top:64,zIndex:50,width:44,height:180,borderRadius:22,background:"rgba(7, 11, 24, 0.45)",border:"1px solid rgba(255,255,255,0.14)",backdropFilter:"blur(4px)",cursor:"ns-resize",touchAction:"none",userSelect:"none",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"space-between",padding:"10px 0",opacity:.55,transition:"opacity 0.15s"},onPointerEnter:e=>{e.currentTarget.style.opacity="0.9"},onPointerLeave:e=>{e.currentTarget.style.opacity="0.55"},children:[(0,i.jsx)("span",{style:{fontSize:12,color:"#93c5fd",pointerEvents:"none"},children:"+"}),(0,i.jsx)("div",{style:{position:"relative",flex:1,width:4,margin:"6px 0",borderRadius:2,background:"rgba(255,255,255,0.12)",pointerEvents:"none"},children:(0,i.jsx)("div",{style:{position:"absolute",left:"50%",transform:"translate(-50%, 50%)",bottom:"".concat((Math.log(tE)-Math.log(.25))/(Math.log(4)-Math.log(.25))*100,"%"),width:18,height:18,borderRadius:"50%",background:"rgba(96,165,250,0.85)",border:"2px solid rgba(255,255,255,0.7)",boxShadow:"0 0 8px rgba(96,165,250,0.6)"}})}),(0,i.jsx)("span",{style:{fontSize:12,color:"#93c5fd",pointerEvents:"none"},children:"−"}),(0,i.jsxs)("span",{style:{fontSize:9,color:"rgba(255,255,255,0.7)",fontVariantNumeric:"tabular-nums",pointerEvents:"none"},children:["\xd7",tE.toFixed(2)]})]})]}),(null==tC?void 0:tC.overlay)===!1&&tw.length>0&&(0,i.jsx)("div",{ref:og,style:{position:"relative",width:"100%",height:"160px",flexShrink:0,borderTop:"1px solid rgba(255,255,255,0.08)"}}),tz&&tw.length>0&&(0,i.jsxs)("div",{style:{width:"100%",maxHeight:"180px",overflowY:"auto",flexShrink:0,borderTop:"1px solid rgba(255,255,255,0.08)",background:"rgba(0,0,0,0.45)",fontFamily:"monospace",fontSize:"11px",padding:"6px 10px"},children:[(0,i.jsxs)("div",{style:{color:"#93c5fd",marginBottom:4},children:["indicator: ",(null==tC?void 0:tC.title)||"n/a"," | overlay: ",String(null==tC?void 0:tC.overlay)," | plots: ",tw.length]}),tw.map((e,t)=>{var r,n;let o=Array.isArray(null==e?void 0:e.data)?e.data:[],l=o.filter(e=>Number.isFinite(Number(null==e?void 0:e.value))),a=l[l.length-1],s=(null==e?void 0:null===(r=e.options)||void 0===r?void 0:r.style)||"line",d=null==e?void 0:null===(n=e.options)||void 0===n?void 0:n.display;return(0,i.jsxs)("div",{style:{color:!1===e.visible?"#6b7280":"#d1d4dc",whiteSpace:"nowrap"},children:["[",t,"] ",e.title||e._plotKey||"plot"," | style=",s,d?" | display=".concat(d):"",!1===e.visible?" | HIDDEN":""," ","| pts=",l.length,"/",o.length,a?" | last=".concat(Number(a.value).toPrecision(6)," @ ").concat(new Date(a.time).toISOString()):" | last=na"]},e._plotKey||e.title||t)}
1)]}),(0,i.jsx)(DrawingToolRail,{drawingTool:nh,onDrawingTool:e=>ng(e)}),(0,i.jsx)(LayersRail,{layers:tw,onToggle:e=>{tS(t=>{var r;let i=[...t];return i[e]={...i[e],visible:!(null===(r=i[e])||void 0===r?void 0:r.visible)},i})},opacity:tM,onOpacityChange:tP,zones:tT,onZonesToggle:()=>tR(e=>!e)}),("ai-analyse"===nh||nM)&&(0,i.jsxs)("div",{ref:nz,style:{position:"absolute",right:12,top:64,zIndex:21,transform:"translate(".concat(nC.x,"px, ").concat(nC.y,"px)"),width:"".concat(nT.w,"px"),maxWidth:"calc(100vw - 24px)",height:null!=nT.h?"".concat(nT.h,"px"):void 0,display:"flex",flexDirection:"column",overflowY:null!=nT.h?"auto":void 0,padding:"14px",borderRadius:"12px",background:"rgba(7, 11, 24, 0.95)",border:"1px solid rgba(59,130,246,0.4)",color:"#fff",boxShadow:"0 18px 45px rgba(0,0,0,0.35)",backdropFilter:"blur(10px)"},children:[(0,i.jsx)("div",{onPointerDown:e=>{e.preventDefault(),e.stopPropagation(),nG.current={startX:e.clientX,startY:e.clientY,panelX:nC.x,panelY:nC.y};let onMove=e=>{let t=nG.current;t&&n_({x:t.panelX+(e.clientX-t.startX),y:t.panelY+(e.clientY-t.startY)})},onUp=()=>{nG.current=null,window.removeEventListener("pointermove",onMove),window.removeEventListener("pointerup",onUp)};window.addEventListener("pointermove",onMove),window.addEventListener("pointerup",onUp)},style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 0",marginBottom:"8px",cursor:"move",color:"rgba(255,255,255,0.35)",fontSize:"13px"},children:"☰"}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:700,color:"#93c5fd"},children:"AI Analyse"}),(0,i.jsx)("button",{type:"button",onClick:()=>{nP(!1),ng("none")},style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",fontSize:"18px",cursor:"pointer",lineHeight:1,animation:nw?"ai-close-pulse 2s ease-in-out infinite":"none"},children:"\xd7"})]}),(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"8px"},children:"Click and drag on the chart to select a candle range."}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>{let e=eE||eB.current;if(!e){nj("Hover a candle on the chart first.");return}nb(e.time),nj("")},style:{padding:"6px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(34,197,94,0.2)",color:"#4ade80",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:nx?"Start: ".concat(new Date(1e3*nx).toLocaleTimeString()):"Set Start"}),(0,i.jsx)("button",{type:"button",onClick:()=>{let e=eE||eB.current;if(!e){nj("Hover a candle on the chart first.");return}nm(e.time),nj("")},style:{padding:"6px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(239,68,68,0.2)",color:"#f87171",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:nf?"End: ".concat(new Date(1e3*nf).toLocaleTimeString()):"Set End"})]}),sh.length>0&&(0,i.jsxs)("div",{style:{marginBottom:"10px"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("div",{style:{fontSize:"10px",fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:"0.5px"},children:"Include in prompt"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>nD({}),style:{background:"none",border:"none",color:"#60a5fa",fontSize:"10px",cursor:"pointer",padding:0},children:"All"}),(0,i.jsx)("button",{type:"button",onClick:()=>nD(Object.fromEntries(sh.map(e=>[e.key,!1]))),style:{background:"none",border:"none",color:"#60a5fa",fontSize:"10px",cursor:"pointer",padding:0},children:"None"})]})]}),(0,i.jsx)("div",{style:{maxHeight:"110px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"3px",paddingRight:"4px"},children:sh.map(e=>{let t=!1!==nE[e.key];return(0,i.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"11px",color:t?"#e2e8f0":"rgba(255,255,255,0.4)",cursor:"pointer"},children:[(0,i.jsx)("input",{type:"checkbox",checked:t,onChange:()=>nD(r=>({...r,[e.key]:!t})),style:{accentColor:"#3b82f6",width:"12px",height:"12px",margin:0,flexShrink:0}}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.label}),(0,i.jsx)("span",{style:{fontSize:"9px",color:"rgba(255,255,255,0.35)",flexShrink:0},children:e.kind})]},e.key)})})]}),nk&&(0,i.jsx)("div",{style:{color:"#f87171",fontSize:"11px",marginBottom:"8px"},children:nk}),(0,i.jsx)("button",{type:"button",onClick:()=>handleAiAnalyse(),disabled:null==nx||null==nf||ny,style:{width:"100%",padding:"10px",borderRadius:"8px",border:"none",background:null!=nx&&null!=nf?"rgba(59,130,246,0.25)":"rgba(255,255,255,0.05)",color:null!=nx&&null!=nf?"#93c5fd":"rgba(255,255,255,0.4)",fontSize:"13px",fontWeight:700,cursor:null!=nx&&null!=nf?"pointer":"not-allowed"},children:ny?"Analysing...":"Analyse"}),(0,i.jsx)("button",{type:"button",onClick:()=>
1{if(!aZ.length||ny)return;let e={start:aZ[0].time,end:aZ[aZ.length-1].time};nb(e.start),nm(e.end),nN([]),nV(""),handleAiAnalyse(e)},disabled:!aZ.length||ny,style:{width:"100%",marginTop:"6px",padding:"8px",borderRadius:"8px",border:"1px solid rgba(59,130,246,0.35)",background:"rgba(59,130,246,0.1)",color:"#93c5fd",fontSize:"12px",fontWeight:600,cursor:aZ.length&&!ny?"pointer":"not-allowed"},children:"Full Chart"}),nw&&(0,i.jsx)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",pointerEvents:"auto",fontSize:"12px",lineHeight:1.45,whiteSpace:"pre-wrap",maxHeight:null!=nT.h?void 0:"200px",flex:null!=nT.h?"1 1 auto":void 0,minHeight:0,overflowY:"auto"},children:nw}),nw&&(0,i.jsxs)("div",{style:{marginTop:"12px",borderTop:"1px solid rgba(59,130,246,0.25)",paddingTop:"10px"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"6px"},children:[(0,i.jsx)("div",{style:{fontSize:"12px",fontWeight:700,color:"#93c5fd"},children:"Chart Chat"}),nU>0&&(0,i.jsx)("button",{type:"button",onClick:sg,style:{padding:"3px 8px",borderRadius:"6px",border:"1px solid rgba(239,68,68,0.4)",background:"rgba(239,68,68,0.12)",color:"#f87171",fontSize:"10px",fontWeight:600,cursor:"pointer"},children:"Remove AI Overlay"})]}),nF.length>0&&(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"6px",maxHeight:"160px",overflowY:"auto",marginBottom:"8px",paddingRight:"2px"},children:[nF.map((e,t)=>(0,i.jsx)("div",{style:{alignSelf:"user"===e.role?"flex-end":"flex-start",maxWidth:"90%",padding:"6px 9px",borderRadius:"8px",fontSize:"11px",lineHeight:1.4,whiteSpace:"pre-wrap",background:"user"===e.role?"rgba(59,130,246,0.2)":"rgba(255,255,255,0.05)",border:"user"===e.role?"1px solid rgba(59,130,246,0.35)":"1px solid rgba(255,255,255,0.08)",color:"user"===e.role?"#bfdbfe":"#e2e8f0"},children:e.content},t)),nB&&(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.4)"},children:"Thinking..."})]}),nO&&(0,i.jsx)("div",{style:{color:"#f87171",fontSize:"11px",marginBottom:"6px"},children:nO}),(0,i.jsxs)("div",{style:{display:"flex",gap:"6px"},children:[(0,i.jsx)("input",{type:"text",value:nL,onChange:e=>nA(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),handleAiChatSend())},placeholder:"Ask about the chart...",disabled:nB,style:{flex:1,minWidth:0,padding:"7px 9px",borderRadius:"7px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"11px",outline:"none"}}),(0,i.jsx)("button",{type:"button",onClick:handleAiChatSend,disabled:nB||!nL.trim(),style:{padding:"7px 12px",borderRadius:"7px",border:"none",background:nL.trim()?"rgba(59,130,246,0.3)":"rgba(255,255,255,0.05)",color:nL.trim()?"#93c5fd":"rgba(255,255,255,0.35)",fontSize:"11px",fontWeight:700,cursor:nL.trim()?"pointer":"not-allowed",flexShrink:0},children:"Send"})]})]}),(0,i.jsx)("div",{onPointerDown:startAiResize("bl"),style:{position:"absolute",left:3,bottom:3,width:14,height:14,cursor:"nesw-resize",borderLeft:"2px solid rgba(147,197,253,0.5)",borderBottom:"2px solid rgba(147,197,253,0.5)",borderBottomLeftRadius:"4px",touchAction:"none"}}),(0,i.jsx)("div",{onPointerDown:startAiResize("br"),style:{position:"absolute",right:3,bottom:3,width:14,height:14,cursor:"nwse-resize",borderRight:"2px solid rgba(147,197,253,0.5)",borderBottom:"2px solid rgba(147,197,253,0.5)",borderBottomRightRadius:"4px",touchAction:"none"}})]}),n$&&n9>0&&(0,i.jsx)(DOMBox,{symbol:f,price:n9,onClose:()=>nZ(!1),onMapToChart:n7}),o_.length>0&&(0,i.jsxs)("div",{style:{position:"absolute",top:0,left:0,zIndex:40,transform:"translate(".concat(o6.x,"px, ").concat(o6.y,"px)"),display:"flex",flexDirection:"column",gap:"12px",maxHeight:"calc(100% - 32px)",overflowY:"auto"},children:[(0,i.jsx)("div",{onMouseDown:e=>{e.preventDefault(),o3.current={startX:e.clientX,startY:e.clientY,origX:o6.x,origY:o6.y}},style:{width:"min(340px, calc(100vw - 16px))",height:"18px",borderRadius:"6px",background:"rgba(255,255,255,0.08)",cursor:"move",display:"flex",alignItems:"center",justifyContent:"center",gap:"3px",marginBottom:"4px"},children:[0,1,2].map(e=>(0,i.jsx)("div",{style:{width:"18px",height:"2px",borderRadius:"1px",background:"rgba(255,255,255,0.25)"}},e))}),o_.map(e=>{let t=Math.max(0,Math.ceil((e.expiresAt-oP)/1e3));return(0,i.jsxs)("div",{style:{width:"min(340px, calc(100vw - 16px))",padding:"16px",borderRadius:"14px",border:"1px solid ".concat("long"===e.side?"rgba(34,197,94,0.6)":"rgba(239,68,68,0.6)"),background:"rgba(7, 11, 24, 0.98)",color:"#fff",boxShadow:"0 20px 60px rgba(0,0,0,0.5)",backdropFilter:"blur(10px)"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"6px"},children:[(0,i.jsxs)("div",{style:{fontSize:"13px",fontWeight:800,color:"long"===e.side?"#4ade80":"#f87171"},children:["open"===e.action?"Entry Signal":"Exit Signal",": ",e.side.toUpperCase()]}),(0,i.jsx)("button",{onClick:()=>{oM(t=>t.filter(t=>t.id!==e.id)),o4(null)},style:{border:"none",background:"transparent",color:"rgba(255,255,255,0.5)",fontSize:"16px",cursor:"pointer",lineHeight:1},children:"\xd7"})]}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[(0,i.jsx)("div",{style:{flex:1,height:"4px",borderRadius:"2px",background:"rgba(255,255,255,0.08)",overflow:"hidden"},children:(0,i.jsx)("div",{style:{width:"".concat(t/30*100,"%"),height:"100%",borderRadius:"2px",background:"long"===e.side?"#22c55e":"#ef4444",transition:"width 1s linear"}})}),(0,i.jsxs)("div",{style:{fontSize:"10px",color:"rgba(255,255,255,0.5)",whiteSpace:"nowrap"},children:[t,"s"]})]}),(0,i.jsxs)("div",{style:{fontSize:"22px",fontWeight:700,fontFamily:"monospace",marginBottom:"2px"},children:["$",(x||e.price).toFixed((x||e.price)>=100?2:4)]}),(0,i.jsxs)("div",{style:{fontSize:"10px",color:"rgba(255,255,255,0.4)",marginBottom:"12px"},children:["Triggered ",new Date(1e3*e.time).toLocaleTimeString()]}),"close"===e.action?(0,i.jsx)("button",{onClick:()=>{oM(t=>t.filter(t=>t.id!==e.id)),o4(null)},style:{width:"100%",padding:"10px 16px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.06)",color:"rgba(255,255,255,0.8)",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:"Dismiss"}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Position Size in USDC"}),(0,i.jsxs)("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.4)"},children:["Balance: ",Q.toFixed(6)]})]}),(0,i.jsx)("input",{type:"number",value:oB,onChange:e=>oW(e.target.value),placeholder:"0.00",style:{width:"100%",padding:"8px 10px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"13px",boxSizing:"border-box",marginBottom:"6px"}}),(0,i.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:"6px",marginBottom:"12px"},children:[2.5,5,7.5,10].map(e=>(0,i.jsxs)("button",{onClick:()=>oW((Q*e/100).toFixed(2)),style:{padding:"6px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(255,255,255,0.05)",color:"rgba(255,255,255,0.7)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:[e,"%"]},e))}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Leverage"}),(0,i.jsxs)("span",{style:{fontSize:"12px",fontWeight:700,color:"#60a5fa"},children:[oO,"x"]})]}),(0,i.jsx)("input",{type:"range",min:1,max:Math.max(1,Math.floor(en||1)),step:1,value:oO,onChange:e=>oV(Number(e.target.value)),style:{width:"100%",accentColor:"#60a5fa",marginBottom:"12px"}}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Take Profit"}),(0,i.jsx)("button",{onClick:()=>oH(e=>!e),style:{padding:"2px 8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:oU?"rgba(34,197,94,0.2)":"rgba(255,255,255,0.05)",color:oU?"#4ade80":"rgba(255,255,255,0.5)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:oU?"".concat(oq,"%"):"Off"})]}),(0,i.jsx)("input",{type:"range",min:1,max:300,step:1,value:oq,disabled:!oU,onChange:e=>{oH(!0),oY(Number(e.target.value))},style:{width:"100%",accentColor:"#22c55e",marginBottom:"12px",opacity:oU?1:.4}}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Stop Loss"}),(0,i.jsx)("button",{onClick:()=>oX(e=>!e),style:{padding:"2px 8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:oK?"rgba(239,68,68,0.2)":"rgba(255,255,255,0.05)",color:oK?"#f87171":"rgba(255,255,255,0.5)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:oK?"".concat(oG,"%"):"Off"})]}),(0,i.jsx)("input",{type:"range",min:1,max:100,step:1,value:oG,disabled:!oK,onChange:e=>{oX(!0),oJ(Number(e.target.value))},style:{width:"100%",accentColor:"#ef4444",marginBottom:"12px",opacity:oK?1:.4}}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Trailing Stop (%)"}),(0,i.jsx)("button",{onClick:()=>o$(e=>!e),style:{padding:"2px 8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:oQ?"rgba(96,165,250,0.2)":"rgba(255,255,255,0.05)",color:oQ?"#93c5fd":"rgba(255,255,255,0.5)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:oQ?"".concat(oZ,"%"):"Off"})]}),(0,i.jsx)("input",{type:"range",min:.5,max:50,step:.5,value:oZ,disabled:!oQ,onChange:e=>{o$(!0),o0(Number(e.target.value))},style:{width:"100%",accentColor:"#60a5fa",marginBottom:"12px",opacity:oQ?1:.4}}),o2&&(0,i.jsx)("div",{style:{fontSize:"11px",color:"#f87171",marginBottom:"10px"},children:o2}),(0,i.jsx)("button",{disabled:o5||!Number(oB),onClick:async()=>{o4(null);let t=Number(oB);if(!t||t<=0){o4("Enter a position size.");return}o1(!0);try{await (null==J?void 0:J({side:e.side,collateral:t,leverage:oO,takeProfitPct:oU?oq/100:null,stopLossPct:oK?oG/100:null,trailingStopPct:oQ?oZ/100:null})),oM(t=>t.filter(t=>t.id!==e.id)),oW("")}catch(e){o4((null==e?void 0:e.message)||"Failed to open position.")}finally{o1(!1)}},onMouseEnter:()=>!o5&&aG(!0),onMouseLeave:()=>aG(!1),style:{width:"100%",padding:"12px",borderRadius:"8px",border:"none",background:"long"===e.side?"rgba(34,197,94,0.25)":"rgba(239,68,68,0.25)",color:"long"===e.side?"#4ade80":"#f87171",fontSize:"14px",fontWeight:800,cursor:o5||
1!Number(oB)?"not-allowed":"pointer",opacity:o5||!Number(oB)?.5:1,transition:"all 0.15s ease",transform:aX?"scale(1.03)":"scale(1)",textShadow:aX?"0 0 10px ".concat("long"===e.side?"rgba(34,197,94,0.8)":"rgba(239,68,68,0.8)"):"none"},children:o5?"Opening...":"Open ".concat("long"===e.side?"Long":"Short")})]})]},e.id)})]}),(null==le?void 0:le.open)&&(0,i.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,pointerEvents:"none"},children:(0,i.jsxs)("div",{onClick:e=>e.stopPropagation(),style:{position:"absolute",left:ad.x,top:ad.y,width:"calc(100vw - 32px)",maxWidth:"380px",boxSizing:"border-box",pointerEvents:"auto",borderRadius:"18px",background:"rgba(7, 11, 24, 0.98)",border:"1px solid rgba(255,255,255,0.1)",boxShadow:"0 24px 80px rgba(0,0,0,0.45)",padding:"22px",color:"#fff"},children:[(0,i.jsx)("div",{onPointerDown:e=>ap({offsetX:e.clientX-ad.x,offsetY:e.clientY-ad.y}),style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 0",marginBottom:"12px",cursor:"move",color:"rgba(255,255,255,0.35)",fontSize:"13px"},children:"☰"}),(0,i.jsxs)("div",{onPointerDown:e=>{"BUTTON"!==e.target.tagName&&ap({offsetX:e.clientX-ad.x,offsetY:e.clientY-ad.y})},style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px",cursor:"move"},children:[(0,i.jsx)("div",{style:{fontSize:"16px",fontWeight:700},children:"Open Position"}),(0,i.jsx)("button",{onClick:()=>lt(null),style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",fontSize:"22px",cursor:"pointer",lineHeight:1},children:"\xd7"})]}),(0,i.jsxs)("div",{style:{fontSize:"26px",fontWeight:700,fontFamily:"monospace",marginBottom:"16px"},children:["$",le.price.toFixed(le.price>=100?2:4)]}),(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"6px"},children:"Direction"}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",marginBottom:"14px"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>lt(e=>e?{...e,side:"long"}:e),style:{padding:"10px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"long"===le.side?"rgba(34,197,94,0.25)":"rgba(255,255,255,0.05)",color:"long"===le.side?"#4ade80":"rgba(255,255,255,0.7)",fontSize:"14px",fontWeight:700,cursor:"pointer"},children:"Long"}),(0,i.jsx)("button",{type:"button",onClick:()=>lt(e=>e?{...e,side:"short"}:e),style:{padding:"10px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"short"===le.side?"rgba(239,68,68,0.25)":"rgba(255,255,255,0.05)",color:"short"===le.side?"#f87171":"rgba(255,255,255,0.7)",fontSize:"14px",fontWeight:700,cursor:"pointer"},children:"Short"})]}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Position Size in USDC"}),(0,i.jsxs)("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.4)"},children:["Balance: ",Q.toFixed(6)]})]}),(0,i.jsx)("input",{type:"number",value:lr,onChange:e=>li(e.target.value),placeholder:"0.00",style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",boxSizing:"border-box",marginBottom:"6px"}}),(0,i.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:"6px",marginBottom:"14px"},children:[2.5,5,7.5,10].map(e=>(0,i.jsxs)("button",{type:"button",onClick:()=>li((Q*e/100).toFixed(2)),style:{padding:"6px",borderRadius:"6px",border:Number(lr)?"1px solid rgba(255,255,255,0.1)":"1px solid rgba(59, 130, 246, 0.5)",background:Number(lr)?"rgba(255,255,255,0.05)":"rgba(59, 130, 246, 0.12)",color:Number(lr)?"rgba(255,255,255,0.7)":"#93c5fd",fontSize:"11px",fontWeight:600,cursor:"pointer",animation:Number(lr)?void 0:"perp-pulse-blue 1.4s infinite"},children:[e,"%"]},e))}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"6px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Leverage"}),(0,i.jsxs)("span",{style:{fontSize:"13px",fontWeight:700,color:(0,D.gr)(ln)},children:[Math.round(ln),"x"]})]}),(0,i.jsxs)("div",{style:{position:"relative",height:"36px",display:"flex",alignItems:"center",marginBottom:"16
1px"},children:[(0,i.jsx)("div",{style:{position:"absolute",left:0,right:0,height:"12px",borderRadius:"999px",background:"linear-gradient(to right, rgb(34, 197, 94), rgb(239, 68, 68))",boxShadow:"0 0 0 1px rgba(255,255,255,0.08) inset"}}),(0,i.jsx)("input",{className:"perp-open-slider",type:"range",min:0,max:1,step:.001,value:(0,D.LV)(ln,1,Math.max(1,Math.floor(en||1))),onChange:e=>lo((0,D.ph)(parseFloat(e.target.value),1,Math.max(1,Math.floor(en||1)))),style:{position:"relative",width:"100%",height:"30px",zIndex:2,"--slider-thumb-color":(0,D.gr)(ln),"--slider-thumb-fill":(0,D.gr)(ln),accentColor:(0,D.gr)(ln),cursor:"pointer"}})]}),(0,i.jsx)("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:["market","limit"].map(e=>(0,i.jsx)("button",{type:"button",onClick:()=>lC(e),style:{flex:1,padding:"8px",borderRadius:"6px",border:lj===e?"1px solid rgba(124, 58, 237, 0.5)":"1px solid rgba(255,255,255,0.1)",background:lj===e?"rgba(124, 58, 237, 0.2)":"rgba(255,255,255,0.05)",color:lj===e?"#a78bfa":"rgba(255,255,255,0.6)",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:e},e))}),"limit"===lj&&(0,i.jsx)("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:["single","grid"].map(e=>(0,i.jsx)("button",{type:"button",onClick:()=>lM(e),style:{flex:1,padding:"8px",borderRadius:"6px",border:l_===e?"1px solid rgba(16, 185, 129, 0.5)":"1px solid rgba(255,255,255,0.1)",background:l_===e?"rgba(16, 185, 129, 0.2)":"rgba(255,255,255,0.05)",color:l_===e?"#34d399":"rgba(255,255,255,0.6)",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:e},e))}),"limit"===lj&&"single"===l_&&(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"6px",display:"block"},children:"Limit Price (USD)"}),(0,i.jsx)("input",{type:"number",value:lP,onChange:e=>lT(e.target.value),placeholder:le.price.toFixed(le.price>=100?2:4),min:"0",step:"0.01",style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",boxSizing:"border-box"}}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",marginTop:"8px",alignItems:"center"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>{lF(e=>"single"===e?"off":"single")},style:{padding:"6px 10px",borderRadius:"8px",border:"single"===lA?"1px solid rgba(167,139,250,0.55)":"1px solid rgba(255,255,255,0.12)",background:"single"===lA?"rgba(167,139,250,0.2)":"rgba(255,255,255,0.05)",color:"single"===lA?"#c4b5fd":"rgba(255,255,255,0.78)",fontSize:"11px",fontWeight:700,cursor:"pointer"},children:"single"===lA?"Cancel Chart Pick":"Pick On Chart"}),(0,i.jsx)("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:"single"===lA?"Click a chart price to set the limit.":"Use the chart instead of typing manually."})]})]}),"limit"===lj&&"grid"===l_&&(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"6px",display:"block"},children:"Grid Range (USD)"}),(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"8px",marginBottom:"8px"},children:[(0,i.jsx)("input",{type:"number",value:lR,onChange:e=>lz(e.target.value),placeholder:"Lower",min:"0",step:"0.01",style:{flex:1,padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",boxSizing:"border-box"}}),(0,i.jsx)("input",{type:"number",value:lI,onChange:e=>lE(e.target.value),placeholder:"Upper",min:"0",step:"0.01",style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",boxSizing:"border-box"}})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",marginBottom:"8px",alignItems:"center"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>{l$(null),l0(null),lF(e=>"grid"===e?"off":"grid")},style:{padding:"6px 10px",borderRadius:"8px",border:"grid"===lA?"1px solid rgba(52,211,153,0.55)":"1px solid rgba(255,255,255,0.12)",background:"grid"===lA?"rgba(52,211,153,0.2)":"rgba(255,255,255,0.05)",color:"grid"===lA?"#6ee7b7":"rgba(255,255,255,0.78)",fontSize:"11px",fontWeight:700,cursor:"pointer"},children:"grid"===lA?"Cancel Range Pick":"Drag Range On Chart"}),(0,i.jsx)("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:"grid"===lA?"Click and hold on the chart, then drag vertically to define the grid range.":"Use click-and-drag on the chart to set lower and upper prices."})]}),(0,i.jsxs)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.5)",marginBottom:"4px",display:"block"},children:["Orders: ",lD]}),(0,i.jsx)("input",{type:"range",min:2,max:20,step:1,value:lD,onChange:e=>lL(Number(e.target.value)),style:{width:"100%",accentColor:"#34d399",marginBottom:"4px"}})]}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Take Profit"}),(0,i.jsx)("button",{type:"button",onClick:()=>lu(e=>!e),style:{padding:"2px 8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:lc?"rgba(34,197,94,0.2)":"rgba(255,255,255,0.05)",color:lc?"#4ade80":"rgba(255,255,255,0.5)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:lc?"".concat((lp/ln).toFixed(2),"%"):"Off"})]}),(0,i.jsx)("input",{type:"range",min:1,max:300,step:1,value:lp,disabled:!lc,onChange:e=>{lu(!0),lg.current=!0,lh(Number(e.target.value))},style:{width:"100%",accentColor:"#22c55e",marginBottom:"12px",opacity:lc?1:.4}}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Stop Loss"}),(0,i.jsx)("button",{type:"button",onClick:()=>lf(e=>!e),style:{padding:"2px 8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:lb?"rgba(239,68,68,0.2)":"rgba(255,255,255,0.05)",color:lb?"#f87171":"rgba(255,255,255,0.5)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:lb?"".concat(lm,"%"):"Off"})]}),(0,i.jsx)("input",{type:"range",min:1,max:100,step:1,value:lm,disabled:!lb,onChange:e=>{lf(!0),ly(Number(e.target.value))},style:{width:"100%",accentColor:"#ef4444",marginBottom:"12px",opacity:lb?1:.4}}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)"},children:"Trailing Stop (%)"}),(0,i.jsx)("button",{type:"button",onClick:()=>lw(e=>!e),style:{padding:"2px 8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:lv?"rgba(96,165,250,0.2)":"rgba(255,255,255,0.05)",color:lv?"#93c5fd":"rgba(255,255,255,0.5)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:lv?"".concat((lS/ln).toFixed(2),"%"):"Off"})]}),(0,i.jsx)("input",{type:"range",min:.5,max:50,step:.5,value:lS,disabled:!lv,onChange:e=>{lw(!0),lk(Number(e.target.value))},style:{width:"100%",accentColor:"#60a5fa",marginBottom:"12px",opacity:lv?1:.4}}),(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsxs)("button",{type:"button",onClick:()=>l9(e=>!e),style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"12px",fontWeight:600,display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer"},children:[(0,i.jsx)("span",{children:"AI Suggestion"}),(0,i.jsx)("span",{style:{transform:l3?"rotate(90deg)":"none",transition:"transform 0.2s ease"},children:"▶"})]}),l3&&(0,i.jsxs)("div",{style:{position:"absolute",left:"100%",top:0,bottom:0,width:"300px",zIndex:10,borderLeft:"1px solid rgba(255,255,255,0.1)",borderRadius:"18px",background:"rgba(7, 11, 24, 0.98)",boxShadow:"4px 0 30px rgba(0,0,0,0.4)",overflowY:"auto",padding:"12px"},children:[(0,i.jsx)("div",{style:{display:"flex",gap:"6px",marginBottom:"10px"},children:["low","moderate","aggressive"].map(e=>(0,i.jsx)("button",{type:"button",onClick:()=>ae(e),disabled:at,style:{flex:1,padding:"6px 8px",borderRadius:"6px",border:l7===e?"1px solid rgba(59, 130, 246, 0.5)":"1px solid rgba(255,255,255,0.1)",background:l7===e?"rgba(59, 130, 246, 0.2)":"rgba(255,255,255,0.05)",color:l7===e?"#93c5fd":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,textTransform:"capitalize",cursor:"pointer"},children:e},e))}),(0,i.jsx)("button",{type:"button",onClick:sx,disabled:at,style:{width:"100%",padding:"10px 16px",borderRadius:"8px",border:"1px solid rgba(59, 130, 246, 0.5)",background:"linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(37, 99, 235, 0.35))",color:"#93c5fd",fontSize:"12px",fontWeight:700,cursor:at?"not-allowed":"pointer",opacity:at?.6:1,boxShadow:"0 0 16px rgba(59, 130, 246, 0.35), inset 0 0 10px rgba(59, 130, 246, 0.08)",textShadow:"0 0 8px rgba(147, 197, 253, 0.55)",transition:"all 0.2s ease",marginBottom:"12px"},children:at?"Suggesting...":"Position Suggest"}),ai&&(0,i.jsx)("div",{style:{color:"#f87171",fontSize:"11px",marginBottom:"8px"},children:ai}),aa&&(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.7)",marginBottom:"8px",lineHeight:"1.4"},children:aa}),ao&&ao.map((e,t)=>{let r=e.open_position||e,n=r.side||"long";return(0,i.jsxs)("div",{onClick:()=>sb(e),style:{padding:"10px",borderRadius:"6px",background:"rgba(59, 130, 246, 0.08)",border:"1px solid rgba(59, 130, 246, 0.25)",cursor:"pointer",marginBottom:"8px"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"6px"},children:[(0,i.jsx)("span",{style:{fontSize:"12px",fontWeight:700,color:"long"===n?"#4ade80":"#f87171",textTransform:"uppercase"},children:n}),(0,i.jsxs)("span",{style:{fontSize:"11px",color:"#93c5fd",fontWeight:600}
1,children:[Math.round(Number(r.leverage)||10),"x"]})]}),(0,i.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:[r.limit_price&&(0,i.jsxs)("span",{style:{padding:"3px 8px",borderRadius:"999px",background:"rgba(168, 85, 247, 0.12)",border:"1px solid rgba(168, 85, 247, 0.35)",color:"#c4b5fd",fontSize:"10px",fontWeight:600},children:["Limit $",Number(r.limit_price).toFixed(2)]}),!r.limit_price&&(0,i.jsx)("span",{style:{padding:"3px 8px",borderRadius:"999px",background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.2)",color:"rgba(255,255,255,0.6)",fontSize:"10px",fontWeight:600},children:"Market"}),r.take_profit_pct&&(0,i.jsxs)("span",{style:{padding:"3px 8px",borderRadius:"999px",background:"rgba(34, 197, 94, 0.12)",border:"1px solid rgba(34, 197, 94, 0.35)",color:"#86efac",fontSize:"10px",fontWeight:600},children:["TP ",(100*Number(r.take_profit_pct)).toFixed(1),"%"]}),r.stop_loss_pct&&(0,i.jsxs)("span",{style:{padding:"3px 8px",borderRadius:"999px",background:"rgba(239, 68, 68, 0.12)",border:"1px solid rgba(239, 68, 68, 0.35)",color:"#fca5a5",fontSize:"10px",fontWeight:600},children:["SL ",(100*Number(r.stop_loss_pct)).toFixed(1),"%"]}),r.trailing_stop_pct&&(0,i.jsxs)("span",{style:{padding:"3px 8px",borderRadius:"999px",background:"rgba(251, 191, 36, 0.12)",border:"1px solid rgba(251, 191, 36, 0.35)",color:"#fbbf24",fontSize:"10px",fontWeight:600},children:["TS ",(100*Number(r.trailing_stop_pct)).toFixed(1),"%"]})]})]},t)})]})]}),ll&&(0,i.jsx)("div",{style:{fontSize:"12px",color:"#f87171",marginBottom:"10px"},children:ll}),(0,i.jsx)("button",{type:"button",disabled:ls||!Number(lr)||!J,onClick:async()=>{la(null);let e=Number(lr);if(!e||e<=0){la("Enter a position size.");return}let t=le.side,r=le.price,i=null,n=null;if("limit"===lj){if("single"===l_){let e=Number(lP);if(!lP||!Number.isFinite(e)||e<=0){la("Enter a valid limit price.");return}i=e,r=e}else{let e=Number(lR),t=Number(lI);if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0||t<=e){la("Enter a valid grid price range.");return}n={lower:e,upper:t,count:Math.max(2,Math.min(20,lD))},r=(e+t)/2}}let o=(0,D.jO)(r,ln,t),l=lb?"long"===t?r-(r-o)*(lm/100):r+(o-r)*(lm/100):void 0,a=lb&&l?Math.abs((l-r)/r):null;ld(!0);try{await (null==J?void 0:J({side:t,collateral:e,leverage:ln,takeProfitPct:lc?lp/100/ln:null,
1stopLossPct:a,trailingStopPct:lv?lS/100/ln:null,limitPrice:i,grid:n})),lt(null),li(""),lT(""),lz(""),lE(""),l$(null),l0(null),lF("off"),lC("market"),lM("single")}catch(e){la((null==e?void 0:e.message)||"Failed to open position.")}finally{ld(!1)}},onMouseEnter:()=>!ls&&aQ(!0),onMouseLeave:()=>aQ(!1),style:{width:"100%",padding:"14px",borderRadius:"10px",border:"none",background:"long"===le.side?"rgba(34,197,94,0.25)":"rgba(239,68,68,0.25)",color:"long"===le.side?"#4ade80":"#f87171",fontSize:"15px",fontWeight:800,cursor:!ls&&Number(lr)&&J?"pointer":"not-allowed",opacity:!ls&&Number(lr)&&J?1:.5,transition:"all 0.15s ease",transform:aJ?"scale(1.03)":"scale(1)",textShadow:aJ?"0 0 10px ".concat("long"===le.side?"rgba(34,197,94,0.8)":"rgba(239,68,68,0.8)"):"none"},children:ls?"Opening...":"limit"===lj?"grid"===l_?"Open Grid ".concat("long"===le.side?"Long":"Short"):"Open Limit ".concat("long"===le.side?"Long":"Short"):"Open ".concat("long"===le.side?"Long":"Short")})]})}),(null==lN?void 0:lN.open)&&(0,i.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,pointerEvents:"none"},children:(0,i.jsxs)("div",{onClick:e=>e.stopPropagation(),style:{position:"absolute",left:lY.x,top:lY.y,width:"calc(100vw - 32px)",maxWidth:"320px",boxSizing:"border-box",pointerEvents:"auto",borderRadius:"18px",background:"rgba(7, 11, 24, 0.98)",border:"1px solid rgba(255,255,255,0.1)",boxShadow:"0 24px 80px rgba(0,0,0,0.45)",padding:"22px",color:"#fff"},children:[(0,i.jsx)("div",{onPointerDown:e=>lG({offsetX:e.clientX-lY.x,offsetY:e.clientY-lY.y}),style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 0",marginBottom:"12px",cursor:"move",color:"rgba(255,255,255,0.35)",fontSize:"13px"},children:"☰"}),(0,i.jsxs)("div",{onPointerDown:e=>{"BUTTON"!==e.target.tagName&&lG({offsetX:e.clientX-lY.x,offsetY:e.clientY-lY.y})},style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px",cursor:"move"},children:[(0,i.jsx)("div",{style:{fontSize:"16px",fontWeight:700},children:"stop_loss"===lN.level?"Set Stop Loss":"Set Take Profit"}),(0,i.jsx)("button",{onClick:()=>{lB(null),lU(!1),lO(""),lq(null)},style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",fontSize:"22px",cursor:"pointer",lineHeight:1},children:"\xd7"})]}),(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsxs)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"6px",display:"block"},children:["stop_loss"===lN.level?"Stop Loss":"Take Profit"," Price (USD)"]}),(0,i.jsx)("input",{type:"number",value:lW,onChange:e=>{lq(null),lO(e.target.value)},placeholder:"0.00",min:"0",step:"0.01",style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",boxSizing:"border-box"}})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",marginBottom:"12px",alignItems:"center"},children:[(0,i.jsx)("button",{type:"button",onClick:()=>lU(e=>!e),style:{padding:"6px 10px",borderRadius:"8px",border:lV?"1px solid rgba(167,139,250,0.55)":"1px solid rgba(255,255,255,0.12)",background:lV?"rgba(167,139,250,0.2)":"rgba(255,255,255,0.05)",color:lV?"#c4b5fd":"rgba(255,255,255,0.78)",fontSize:"11px",fontWeight:700,cursor:"pointer"},children:lV?"Cancel Chart Pick":"Pick On Chart"}),(0,i.jsx)("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.5)"},children:lV?"Click a chart price to set ".concat("stop_loss"===lN.level?"SL":"TP","."):"Use the chart instead of typing manually."})]}),lH&&(0,i.jsx)("div",{style:{fontSize:"12px",color:"#f87171",marginBottom:"10px"},children:lH}),(0,i.jsx)("button",{type:"button",disabled:!Number(lW)||!Y,onClick:()=>{let e=Number(lW);if(!Number.isFinite(e)||e<=0){lq("Enter a valid ".concat("stop_loss"===lN.level?"SL":"TP"," price"));return}null==Y||Y(lN.positionId,lN.level,e),lB(null),lU(!1),lO(""),lq(null)},style:{width:"100%",padding:"12px",borderRadius:"8px",border:"none",background:"stop_loss"===lN.level?"rgba(239,68,68,0.25)":"rgba(34,197,94,0.25)",color:"stop_loss"===lN.level?"#f87171":"#4ade80",fontSize:"14px",fontWeight:700,cursor:"pointer",opacity:Number(lW)&&Y?1:.5},children:"stop_loss"===lN.level?"Set Stop Loss":"Set Take Profit"})]})}),ah&&sm.length>0&&(0,i.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,pointerEvents:"none"},children:(0,i.jsxs)("div",{ref:ay,onClick:e=>e.stopPropagation(),style:{position:"absolute",left:ax.x,top:ax.y,width:"calc(100vw - 32px)",maxWidth:"300px",boxSizing:"border-box",maxHeight:"70vh",overflowY:"auto",pointerEvents:"auto",borderRadius:"18px",background:"rgba(7, 11, 24, 0.98)",border:"1px solid rgba(255,255,255,0.1)",boxShadow:"0 24px 80px rgba(0,0,0,0.45)",padding:"22px",color:"#fff"},children:[(0,i.jsxs)("div",{onPointerDown:e=>am({offsetX:e.clientX-ax.x,offsetY:e.clientY-ax.y}),style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16
1px",cursor:"move"},children:[(0,i.jsxs)("div",{style:{fontSize:"15px",fontWeight:700},children:[(null==nu?void 0:nu.title)||"Indicator"," Settings"]}),(0,i.jsx)("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:["tl","tr","bl","br"].map(e=>(0,i.jsx)("button",{type:"button",title:"Dock ".concat("tl"===e?"top left":"tr"===e?"top right":"bl"===e?"bottom left":"bottom right"),onPointerDown:e=>e.stopPropagation(),onClick:()=>snapPineSettings(e),style:{width:"22px",height:"22px",borderRadius:"5px",border:"1px solid rgba(255,255,255,0.15)",background:"rgba(255,255,255,0.06)",color:"rgba(255,255,255,0.7)",fontSize:"11px",cursor:"pointer",lineHeight:1,padding:0},children:"tl"===e?"↖":"tr"===e?"↗":"bl"===e?"↙":"↘"},e))}),(0,i.jsx)("button",{onClick:()=>ag(!1),style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",fontSize:"22px",cursor:"pointer",lineHeight:1},children:"\xd7"})]}),(0,i.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:sy.map(e=>{let{group:t,defs:r}=e;return(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{style:{fontSize:"10px",letterSpacing:"0.08em",textTransform:"uppercase",color:"rgba(255,255,255,0.5)",marginBottom:"8px"},children:t}),(0,i.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"10px"},children:r.map(e=>renderPineInput(e))})]},t)})})]})}),!(null==le?void 0:le.open)&&(0,i.jsxs)("div",{onMouseEnter:()=>{aI.current&&clearTimeout(aI.current),az(!1)},onMouseLeave:()=>{aI.current&&clearTimeout(aI.current),aI.current=setTimeout(()=>az(!0),500)},style:{position:"absolute",left:a_.x,top:a_.y,zIndex:30,pointerEvents:"auto",display:"flex",flexDirection:"column",alignItems:"center",gap:"6px",minWidth:"132px",padding:"6px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.92)",border:"1px solid rgba(255,255,255,0.12)",backdropFilter:"blur(6px)",boxShadow:"0 8px 24px rgba(0,0,0,0.35)",boxSizing:"border-box"},children:[(0,i.jsx)("div",{onPointerDown:e=>{e.preventDefault(),e.stopPropagation(),aT({offsetX:e.clientX-a_.x,offsetY:e.clientY-a_.y})},style:{width:"100%",height:"28px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"6px",cursor:"move",color:"rgba(255,255,255,0.35)",fontSize:"14px",animation:aR?"menu-handle-pulse 3.5s ease-in-out infinite":"none"},children:"☰"}),(0,i.jsxs)("div",{style:{width:"100%",overflow:"hidden",maxHeight:aR?0:"300px",opacity:aR?0:1,transition:"max-height 0.35s ease, opacity 0.25s ease",display:"flex",flexDirection:"column",gap:"6px",pointerEvents:aR?"none":"auto"},children:[(0,i.jsx)("div",{onClick:()=>{la(null),n9&&(lt({open:!0,price:n9,side:"long"}),ac({x:clampToViewportX(a_.x+60,380),y:a_.y+60}))},onMouseEnter:()=>aF("open"),onMouseLeave:()=>aF(null),style:{width:"100%",padding:"6px 14px",borderRadius:"8px",border:"open"===aA?"1px solid rgba(59,130,246,0.5)":"1px solid rgba(59,130,246,0.3)",background:"open"===aA?"rgba(59,130,246,0.2)":"rgba(59,130,246,0.08)",color:"open"===aA?"#60a5fa":"#93c5fd",boxShadow:"open"===aA?"0 0 8px 1px rgba(59,130,246,0.6), inset 0 0 6px 1px rgba(59,130,246,0.15)":"none",textShadow:"open"===aA?"0 0 4px rgba(59,130,246,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:"pointer",textAlign:"center",whiteSpace:"nowrap"},children:"Open New Position"}),(0,i.jsx)("div",{onClick:()=>{let e="ai-analyse"===nh?"none":"ai-analyse";ng(e),nP("ai-analyse"===e)},onMouseEnter:()=>aF("analyse"),onMouseLeave:()=>aF(null),style:{width:"100%",padding:"6px 14px",borderRadius:"8px",border:"analyse"===aA||"ai-analyse"===nh?"1px solid rgba(59,130,246,0.5)":"1px solid rgba(59,130,246,0.3)",background:"analyse"===aA||"ai-analyse"===nh?"rgba(59,130,246,0.2)":"rgba(59,130,246,0.08)",color:"analyse"===aA||"ai-analyse"===nh?"#60a5fa":"#93c5fd",boxShadow:"analyse"===aA||"ai-analyse"===nh?"0 0 8px 1px rgba(59,130,246,0.6), inset 0 0 6px 1px rgba(59,130,246,0.15)":"none",textShadow:"analyse"===aA||"ai-analyse"===nh?"0 0 4px rgba(59,130,246,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:"pointer",textAlign:"center",whiteSpace:"nowrap"},children:"AI Support"}),(0,i.jsx)("div",{onClick:()=>eY(e=>!e),onMouseEnter:()=>aF("positions"),onMouseLeave:()=>aF(null),style:{width:"100%",padding:"6px 14px",borderRadius:"8px",border:"positions"===aA||eq?"1px solid rgba(168,85,247,0.5)":"1px solid rgba(168,85,247,0.3)",background:"positions"===aA||eq?"rgba(168,85,247,0.2)":"rgba(168,85,247,0.08)",color:"positions"===aA||eq?"#c084fc":"#d8b4fe",boxShadow:"positions"===aA||eq?"0 0 8px 1px rgba(168,85,247,0.6), inset 0 0 6px 1px rgba(168,85,247,0.15)":"none",textShadow:"positions"===aA||eq?"0 0 4px rgba(168,85,247,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:"pointer",textAlign:"center",whiteSpace:"nowrap"},children:eq?"Hide Positions":"Show Positions"}),(0,i.jsx)("div",{onClick:()=>{l2?l4(!1):l5?(l1(!1),l4(!1)):l4(!0)},onMouseEnter:()=>aF("vwap"),onMouseLeave:()=>aF(null),style:{width:"100%",padding:"6px 14px",borderRadius:"8px",border:"vwap"===aA||l2||l5?"1px solid rgba(245,158,11,0.5)":"1px solid rgba(245,158,11,0.3)",background:"vwap"===aA||l2||l5?"rgba(245,158,11,0.2)":"rgba(245,158,11,0.08)",color:"vwap"===aA||l2||l5?"#fbbf24":"#fcd34d",boxShadow:"vwap"===aA||l2||l5?"0 0 8px 1px rgba(245,158,11,0.6), inset 0 0 6px 1px rgba(245,158,11,0.15)":"none",textShadow:"vwap"===aA||l2||l5?"0 0 4px rgba(245,158,11,0.8)":"none",fontSize:"12px",fontWeight:600,cursor:"pointer",textAlign:"center",whiteSpace:"nowrap"},children:l2?"Cancel VWAP":l5?"Hide VWAP":"Anchor VWAP"})]})]}),so&&eq&&(0,i.jsxs)("div",{onMouseEnter:()=>{aL.current&&clearTimeout(aL.current),aD(!1)},onMouseLeave:()=>{aL.current&&clearTimeout(aL.current),aL.current=setTimeout(()=>aD(!0),500)},style:{position:"absolute",left:aW.x,top:aW.y,zIndex:21,width:"min(288px, calc(100vw - 16px))",padding:"14px",borderRadius:"12px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(7, 11, 24, 0.94)",color:"#fff",boxShadow:"0 18px 45px rgba(0,0,0,0.35)",backdropFilter:"blur(10px)",fontSize:"12px"},children:[(0,i.jsx)("div",{onPointerDown:e=>aU({offsetX:e.clientX-aW.x,offsetY:e.clientY-aW.y}),style:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 0",marginBottom:"8px",cursor:"move",color:"rgba(255,255,255,0.35)",fontSize:"13px"},children:"☰"}),eW.length>1&&!aE&&(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),eH(!eU)},style:{width:"100%",padding:"6px 8px",marginBottom:"8px",borderRadius:"6px",border:eU?"1p
1x solid #facc15":"1px solid rgba(255,255,255,0.12)",background:eU?"#facc1522":"rgba(255,255,255,0.04)",color:eU?"#facc15":"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease",opacity:eU?1:.85,boxShadow:eU?"0 0 8px 1px #facc1566, inset 0 0 6px 1px #facc151a":"none",textShadow:eU?"0 0 4px #facc15aa":"none"},children:"All Positions"}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[eW.length>1&&(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{var t;e.stopPropagation(),eH(!1);let r=null!==(t=null==so?void 0:so._index)&&void 0!==t?t:0,i=r>0?r-1:eW.length-1;eW[i]&&j&&j(eW[i].id),eV(i)},style:{background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.12)",borderRadius:"6px",color:"rgba(255,255,255,0.75)",fontSize:"12px",fontWeight:800,cursor:"pointer",padding:"2px 7px",lineHeight:1},title:"Previous position",children:"←"}),(0,i.jsx)("div",{style:{fontSize:"13px",fontWeight:800},children:eU?"".concat(f," All Positions (").concat(eW.length,")"):"".concat(f," Position #").concat(so._index+1)}),eW.length>1&&(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{var t;e.stopPropagation(),eH(!1);let r=null!==(t=null==so?void 0:so._index)&&void 0!==t?t:0,i=r<eW.length-1?r+1:0;eW[i]&&j&&j(eW[i].id),eV(i)},style:{background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.12)",borderRadius:"6px",color:"rgba(255,255,255,0.75)",fontSize:"12px",fontWeight:800,cursor:"pointer",padding:"2px 7px",lineHeight:1},title:"Next position",children:"→"})]}),(0,i.jsx)("div",{style:{marginTop:"2px",color:"rgba(255,255,255,0.5)",fontSize:"11px"},children:eU?"Viewing all positions":"Opened ".concat(Number.isFinite(so._openedAt)?new Date(1e3*so._openedAt).toLocaleString("en-US",{hour12:!1}):"—")})]}),(0,i.jsxs)("div",{onMouseDown:e=>e.stopPropagation(),style:{display:"flex",alignItems:"center",gap:"4px",padding:"3px 6px",borderRadius:"999px",background:"long"===so._side?"rgba(34,197,94,0.16)":"rgba(239,68,68,0.16)"},children:[(0,i.jsx)("span",{style:{color:"long"===so._side?"#22c55e":"#ef4444",fontWeight:800,fontSize:"11px"},children:so._side.toUpperCase()}),(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),eY(!1)},style:{background:"transparent",border:"none",color:"rgba(255,255,255,0.5)",fontSize:"14px",fontWeight:700,cursor:"pointer",padding:"0 2px",lineHeight:1,marginLeft:"4px"},title:"Hide positions",children:"\xd7"})]})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",marginBottom:aE?0:"12px"},children:[(0,i.jsxs)("div",{style:{padding:"8px",borderRadius:"8px",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.06)"},children:[(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"10px"},children:"Entry"}),(0,i.jsxs)("div",{style:{fontWeight:800},children:["$",Number(so._entry||0).toFixed(2)]})]}),(0,i.jsxs)("div",{style:{padding:"8px",borderRadius:"8px",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.06)"},children:[(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"10px"},children:"P&L"}),(0,i.jsxs)("div",{style:{fontWeight:800,color:so._pnl>=0?"#22c55e":"#ef4444"},children:[so._pnl>=0?"+":"","$",Number(so._pnl||0).toFixed(2)]}),(0,i.jsxs)("div",{style:{fontSize:"10px",color:so._pnlPct>=0?"#22c55e":"#ef4444",marginTop:"2px"},children:[so._pnlPct>=0?"+":"",Number(so._pnlPct||0).toFixed(2),"%"]})]}),(0,i.jsxs)("div",{style:{padding:"8px",borderRadius:"8px",background:"rgba(245,158,11,0.08)",border:"1px solid rgba(245,158,11,0.16)"},children:[(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"10px"},children:"Liq"}),(0,i.jsx)("div",{style:{fontWeight:800,color:"#f59e0b"},children:so._liq>0?"$".concat(Number(so._liq).toFixed(2)):"—"})]}),(0,i.jsxs)("div",{style:{padding:"8px",borderRadius:"8px",background:"rgba(34,197,94,0.08)",border:"1px solid rgba(34,197,94,0.16)"},children:[(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"10px"},children:"TP / SL"}),(0,i.jsxs)("div",{style:{fontWeight:800},children:[so._tp>0?"$".concat(Number(so._tp).toFixed(2)):"—"," / ",so._sl>0?"$".concat(Number(so._sl).toFixed(2)):"—"]})]})]}),(0,i.jsxs)("div",{style:{overflow:"hidden",maxHeight:aE?0:"800px",o
1pacity:aE?0:1,transition:"max-height 0.35s ease, opacity 0.25s ease",pointerEvents:aE?"none":"auto"},children:[so._tp<=0&&Y&&(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),lB({open:!0,positionId:String(so.id),side:so._side,level:"take_profit"}),lO(""),lU(!0),lt(null),lF("off"),lq(null)},style:{width:"100%",marginTop:"4px",padding:"6px 10px",borderRadius:"6px",border:"1px solid rgba(34,197,94,0.4)",background:"rgba(34,197,94,0.12)",color:"#4ade80",fontSize:"11px",fontWeight:600,cursor:"pointer",textAlign:"center"},children:"+ Take Profit"}),so._sl<=0&&Y&&(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),lB({open:!0,positionId:String(so.id),side:so._side,level:"stop_loss"}),lO(""),lU(!0),lt(null),lF("off"),lq(null)},style:{width:"100%",marginTop:"4px",padding:"6px 10px",borderRadius:"6px",border:"1px solid rgba(239,68,68,0.4)",background:"rgba(239,68,68,0.12)",color:"#f87171",fontSize:"11px",fontWeight:600,cursor:"pointer",textAlign:"center"},children:"+ Stop Loss"}),so._tp>0&&Y&&(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),e4(!0),e8(null),e9(null),lB({open:!0,positionId:String(so.id),side:so._side,level:"take_profit"}),lO(so._tp>0?String(Number(so._tp.toFixed(2))):""),lU(!0),lt(null),lF("off"),lq(null)},style:{width:"100%",marginTop:"4px",padding:"6px 10px",borderRadius:"6px",border:"1px solid rgba(34,197,94,0.4)",background:e2?"rgba(34,197,94,0.3)":"rgba(34,197,94,0.12)",color:"#4ade80",fontSize:"11px",fontWeight:600,cursor:"pointer",textAlign:"center"},title:"Drag the TP line on the chart or click a price to set it exactly",children:e2?"Drag or click the TP line…":"Change TP"}),so._sl>0&&Y&&(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),e4(!0),e8(null),e9(null),lB({open:!0,positionId:String(so.id),side:so._side,level:"stop_loss"}),lO(so._sl>0?String(Number(so._sl.toFixed(2))):""),lU(!0),lt(null),lF("off"),lq(null)},style:{width:"100%",marginTop:"4px",padding:"6px 10px",borderRadius:"6px",border:"1px solid rgba(239,68,68,0.4)",background:e2?"rgba(239,68,68,0.3)":"rgba(239,68,68,0.12)",color:"#f87171",fontSize:"11px",fontWeight:600,cursor:"pointer",textAlign:"center"},title:"Drag the SL line on the chart or click a price to set it exactly",children:e2?"Drag or click the SL line…":"Change SL"}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",marginBottom:"10px",color:"rgba(255,255,255,0.65)"},children:[(0,i.jsxs)("div",{children:["Notional ",(0,i.jsxs)("strong",{style:{color:"#fff"},children:["$",Number(so._notional||0).toFixed(2)]})]}),(0,i.jsxs)("div",{children:["Margin ",(0,i.jsxs)("strong",{style:{color:"#fff"},children:["$",Number(so._collateral||0).toFixed(2)]})]})]}),(0,i.jsxs)("div",{style:{marginBottom:"12px",color:"rgba(255,255,255,0.65)",fontSize:"12px"},children:["Effective Leverage ",(0,i.jsxs)("strong",{style:{color:so._effectiveLeverage>=0?"#22c55e":"#ef4444"},children:[Number(so._effectiveLeverage||0).toFixed(2),"x"]})]}),(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"6px",marginBottom:"12px",padding:"8px",borderRadius:"10px",border:"1px solid rgba(255,255,255,0.12)"},children:[(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"6px"},children:[(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),so.id&&(null==K||K(String(so.id),.25))},disabled:!so.id||!K,style:{padding:"8px 4px",borderRadius:"6px",border:"1px solid rgba(34,197,94,0.4)",background:"rgba(34,197,94,0.15)",color:"#4ade80",fontSize:"12px",fontWeight:600,cursor:K?"pointer":"not-allowed"},children:"25%"}),(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),so.id&&(null==K||K(String(so.id),.5))},disabled:!so.id||!K,style:{padding:"8px 4px",borderRadius:"6px",border:"1px solid rgba(34,197,94,0.4)",background:"rgba(34,197,94,0.15)",color:"#4ade80",fontSize:"12px",fontWeight:600,cursor:K?"pointer":"not-allowed"},children:"50%"}),(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),so.id&&(null==K||K(String(so.id),.75))},disabled:!so.id||!K,style:{padding:"8px 4px",borderRadius:"6px",border:"1px solid rgba(34,197,94,0.4)",background:"rgba(34,197,94,0.15)",color:"#4ade80",fontSize:"12px",fontWeight:600,cursor:K?"pointer":"not-allowed"},children:"75%"})]}),(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),so.id&&(null==K||K(String(so.id)))},disabled:!so.id||!K,style:{width:"100%",padding:"9px 12px",borderRadius:"8px",border:"1px solid rgba(239,68,68,0.4)",background:"rgba(239,68,68,0.15)",color:"#fca5a5",fontSize:"13px",fontWeight:700,cursor:K?"pointer":"not-allowed"},children:"Close"})]}),X&&(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"6px",marginBottom:"12px"},children:[(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),eX(e=>!e)},disabled:!so.id||!X,style:{width:"100%",padding:"9px 12px",borderRadius:"8px",border:"1px solid rgba(168,85,247,0.4)",background:eK?"rgba(168,85,247,0.25)":"rgba(168,85,247,0.15)",color:"#c084fc",fontSize:"13px",fontWeight:700,cursor:X?"pointer":"not-allowed"},children:eK?"Hide TWAP":"TWAP Close"}),eK&&(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"6px",padding:"8px",borderRadius:"8px",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.08)"},children:[(0,i.jsx)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:"4px"},children:[25,50,75,100].map(e=>(0,i.jsxs)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),eJ(e)},style:{padding:"4px 2px",borderRadius:"4px",border:eG===e?"1px solid rgba(34,197,94,0.5)":"1px solid rgba(255,255,255,0.12)",background:eG===e?"rgba(34,197,94,0.2)":"rgba(255,255,255,0.04)",color:eG===e?"#4ade80":"rgba(255,255,255,0.7)",fontSize:"11px",fontWeight:600,cursor:"pointer"},children:[e,"%"]},e))}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",whiteSpace:"nowrap"}
1,children:"Slices"}),(0,i.jsx)("input",{type:"number",min:1,max:20,value:eQ,onChange:e=>e$(Math.max(1,Math.min(20,Math.floor(Number(e.target.value)||1)))),onMouseDown:e=>e.stopPropagation(),style:{flex:1,background:"rgba(0,0,0,0.2)",border:"1px solid rgba(255,255,255,0.12)",borderRadius:"4px",color:"#fff",padding:"4px 6px",fontSize:"12px"}}),(0,i.jsx)("label",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",whiteSpace:"nowrap"},children:"Interval (s)"}),(0,i.jsx)("input",{type:"number",min:1,max:300,value:eZ,onChange:e=>e0(Math.max(1,Math.min(300,Math.floor(Number(e.target.value)||1)))),onMouseDown:e=>e.stopPropagation(),style:{width:"50px",background:"rgba(0,0,0,0.2)",border:"1px solid rgba(255,255,255,0.12)",borderRadius:"4px",color:"#fff",padding:"4px 6px",fontSize:"12px"}})]}),(0,i.jsxs)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),so.id&&(null==X||X(String(so.id),eG/100,eQ,eZ))},disabled:!so.id||!X||eQ<1||eZ<1,style:{width:"100%",padding:"8px 12px",borderRadius:"6px",border:"1px solid rgba(239,68,68,0.4)",background:"rgba(239,68,68,0.15)",color:"#fca5a5",fontSize:"12px",fontWeight:700,cursor:X&&eQ>=1&&eZ>=1?"pointer":"not-allowed"},children:["Start TWAP Close (",eG,"% in ",eQ,"x",eZ,"s)"]})]})]}),(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),so.id&&(null==F||F(String(so.id)))},disabled:!so.id||!F,style:{width:"100%",padding:"9px 12px",borderRadius:"9px",border:"1px solid rgba(96,165,250,0.35)",background:F?"rgba(59,130,246,0.18)":"rgba(255,255,255,0.06)",color:F?"#93c5fd":"rgba(255,255,255,0.35)",fontSize:"12px",fontWeight:800,cursor:F?"pointer":"not-allowed"},children:"Manage Position"}),(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),e4(e=>!e),e8(null),e9(null)},disabled:!so.id||!Y,style:{width:"100%",marginTop:"8px",padding:"9px 12px",borderRadius:"9px",border:e2?"1px solid rgba(34,197,94,0.45)":"1px solid rgba(255,255,255,0.12)",background:e2?"rgba(34,197,94,0.16)":"rgba(255,255,255,0.06)",color:e2?"#86efac":"rgba(255,255,255,0.72)",fontSize:"12px",fontWeight:800,cursor:Y?"pointer":"not-allowed"},children:e2?"Drag & Drop Active":"Drag & Drop Position"}),e2&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("button",{type:"button",onMouseDown:e=>e.stopPropagation(),onClick:e=>{var t;e.stopPropagation(),so.id&&(null===(t=N||F)||void 0===t||t(String(so.id)))},disabled:!so.id||!N&&!F,style:{width:"100%",marginTop:"8px",padding:"9px 12px",borderRadius:"9px",border:"1px solid rgba(34,197,94,0.45)",background:"rgba(34,197,94,0.18)",color:"#86efac",fontSize:"12px",fontWeight:800,cursor:N||F?"pointer":"not-allowed"},children:"Update Position"}),(0,i.jsx)("div",{style:{marginTop:"8px",color:"rgba(255,255,255,0.45)",fontSize:"10px",lineHeight:1.4},children:"Grab the SL or TP line, drag it to a new price, then update to review and sign."})]})]})]}),so&&null!=tt&&x&&(0,i.jsxs)("div",{style:{position:"absolute",right:nn+20+aH.x,top:tt+190+aH.y,transform:"translateY(-50%)",zIndex:22,minWidth:"140px",padding:"8px 12px",borderRadius:"8px",background:"rgba(7, 11, 24, 0.94)",border:"1px solid rgba(255,255,255,0.12)",color:"#fff",boxShadow:"0 12px 30px rgba(0,0,0,0.35)",backdropFilter:"blur(8px)",fontSize:"12px",pointerEvents:"none"},children:[(0,i.jsx)("div",{onPointerDown:e=>aK({startX:e.clientX,startY:e.clientY,startOffsetX:aH.x,startOffsetY:aH.y}),style:{pointerEvents:"auto",cursor:"move",display:"flex",justifyContent:"center",alignItems:"center",padding:"2px 0",marginBottom:"4px",color:"rgba(255,255,255,0.35)",fontSize:"13px"},children:"☰"}),(0,i.jsxs)("div",{style:{fontSize:"10px",color:"rgba(255,255,255,0.6)",marginBottom:"2px"},children:["Mark ",(0,i.jsx)(RollingNumber,{value:x,decimals:2,prefix:"$",style:{fontWeight:600,color:"#fff",fontFamily:'monospace, ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace',fontVariantNumeric:"tabular-nums"},fluctuate:!0,fluctuateCount:2,fluctuateInterval:40})]}),(0,i.jsx)("div",{style:{fontSize:"10px",color:"rgba(255,255,255,0.6)",marginBottom:"2px"},children:"Live PnL"}),(0,i.jsxs)("div",{style:{fontWeight:800,color:so._pnl>=0?"#22c55e":"#ef4444"},children:[so._pnl>=0?"+":"","$",Number(so._pnl||0).toFixed(5),(0,i.jsx)(OpenChartsPro_FluctuatingDigits,{count:4})," USDC"]}),(()=>{let e="number"==typeof so.pnlPercent?so.pnlPercent:so._pnlPct;return"number"==typeof e&&Number.isFinite(e)?(0,i.jsxs)("div",{style:{fontSize:"12px",fontWeight:800,color:getPnlColor(e),marginTop:"2px"},children:["(",e>=0?"+":"",e.toFixed(2),"%)"]}):null})()]}),so&&null!=ti&&null!=to&&null!=tt&&x&&(0,i.jsx)("div",{style:{position:"absolute",left:to,right:0,top:Math.min(ti,tt),height:Math.abs(ti-tt),background:("long"===so._side?x>=so._entry:x<=so._entry)?"rgba(34, 197, 94, 0.25)":"rgba(239, 68, 68, 0.25)",zIndex:6,pointerEvents:"none"}}),eL&&(0,i.jsxs)("div",{style:{position:"absolute",left:Math.min(Math.max(eL.x+16,12),Math.max(12,((null===(d=eu.current)||void 0===d?void 0:d.clientWidth)||280)-180)),top:Math.min(Math.max(eL.y+16,12),Math.max(12,((null===(c=eu.current)||void 0===c?void 0:c.clientHeight)||220)-150)),zIndex:20,minWidth:"168px",padding:"12px 14px",borderRadius:"10px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(7, 11, 24, 0.94)",color:"#fff",boxShadow:"0 18px 45px rgba(0,0,0,0.35)",backdropFilter:"blur(10px)",pointerEvents:"none",fontSize:"12px"},children:[(0,i.jsxs)("div",{style:{fontSize:"13px",fontWeight:700,marginBottom:"8px"},children:[f," Candle"]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"auto auto",gap:"4px 12px",color:"rgba(255,255,255,0.72)"},children:[(0,i.jsx)("span",{children:"Open"}),(0,i.jsxs)("strong",{style:{color:"#fff",textAlign:"right"},children:["$",Number(eL.open).toFixed(2)]}),(0,i.jsx)("span",{children:"High"}),(0,i.jsxs)("strong",{style:{color:"#22c55e",textAlign:"right"},children:["$",Number(eL.high).toFixed(2)]}),(0,i.jsx)("span",{children:"Low"}),(0,i.jsxs)("strong",{style:{color:"#ef4444",textAlign:"right"},children:["$",Number(eL.low).toFixed(2)]}),(0,i.jsx)("span",{children:"Close"}),(0,i.jsxs)("strong",{style:{color:Number(eL.close)>=Number(eL.open)?"#22c55e":"#ef4444",textAlign:"right"},children:["$",Number(eL.close).toFixed(2)]}),(0,i.jsx)("span",{children:"Volume"}),(0,i.jsx)("strong",{style:{color:"#93c5fd",textAlign:"right"}
1,children:Number(eL.volume||0).toLocaleString()})]}),(0,i.jsx)("div",{style:{marginTop:"8px",paddingTop:"8px",borderTop:"1px solid rgba(255,255,255,0.08)",color:"rgba(255,255,255,0.5)",fontSize:"11px"},children:new Date(1e3*eL.time).toLocaleString("en-US",{hour12:!1})})]})]})]})}var Y=r(59958),K=r(70153),X=r(20095),G=r(49189),J=r(36039),Q=r(8772),$=r(51471),Z=r(14224),ee=r(55872).Buffer;I.kL.register(I.uw,I.f$,I.ZL,I.vn,I.od,I.jn,I.Dx,I.u,I.De,I.Gu);let et="cosmos17k0jlcp9teljwqk5d2m95afddxvudykqyxxr8gremrzuq93a3h9spnkp2h",er=Z.env.NEXT_PUBLIC_COSMOS_REST_ENDPOINT||"https://cosmos-rest.publicnode.com",toBase64Json=e=>{let t=JSON.stringify(e);return"function"==typeof window.btoa?window.btoa(t):void 0!==ee?ee.from(t,"utf-8").toString("base64"):""},querySmart=async(e,t)=>{let r="".concat(er,"/cosmwasm/wasm/v1/contract/").concat(e,"/smart/").concat(toBase64Json(t)),i=await fetch(r);if(!i.ok)throw Error("Smart query failed (".concat(i.status,")"));let n=await i.json();return null==n?void 0:n.data},getEventAttributeValue=(e,t)=>{var r;let i=null==e?void 0:null===(r=e.attributes)||void 0===r?void 0:r.find(e=>e.key===t);return null==i?void 0:i.value},LimitOrderBookV2_calculateSMA=(e,t)=>{let r=[];for(let i=0;i<e.length;i++)if(i<t-1)r.push(null);else{let n=e.slice(i-t+1,i+1).reduce((e,t)=>e+t,0);r.push(n/t)}return r},LimitOrderBookV2_calculateEMA=(e,t)=>{let r=[],i=null,n=t>0?2/(t+1):1;for(let o=0;o<e.length;o++)if(o<t-1)r.push(null);else if(o===t-1){let n=0;for(let r=0;r<t;r++)n+=e[o-r];i=n/t,r.push(i)}else i=e[o]*n+(null!=i?i:0)*(1-n),r.push(i);return r},LimitOrderBookV2_calculateRSI=(e,t)=>{let r=[],i=0,n=0;for(let o=1;o<e.length;o++){let l=e[o]-e[o-1],a=l>0?l:0,s=l<0?-l:0;if(o<t)i+=a/t,n+=s/t,r.push(null);else if(o===t){i+=a/t,n+=s/t;let e=0===n?100:i/n;r.push(0===n?100:100-100/(1+e))}else{i=(i*(t-1)+a)/t,n=(n*(t-1)+s)/t;let e=0===n?100:i/n;r.push(0===n?100:100-100/(1+e))}}return r.unshift(null),r},LimitOrderBookV2_calculateStochasticRSI=(e,t,r,i,n)=>{let o=LimitOrderBookV2_calculateRSI(e,t).map(e=>null!=e?e:0),l=[];for(let e=0;e<o.length;e++){if(e<r-1){l.push(null);continue}let t=o.slice(e-r+1,e+1),i=Math.min(...t),n=Math.max(...t),a=n-i;l.push(0===a?50:(o[e]-i)/a*100)}let smooth=(e,t)=>{let r=[],i=0,n=0;for(let o=0;o<e.length;o++){let l=e[o];if(null!==l&&(i+=l,n++),o>=t){let r=e[o-t];null!==r&&(i-=r,n--)}r.push(o>=t-1&&n>0?i/n:null)}return r},a=smooth(l,i),s=smooth(a,n);return{k:a,d:s}},LimitOrderBookV2_calculateMACD=(e,t,r,i)=>{let n=LimitOrderBookV2_calculateEMA(e,t).map(e=>null!=e?e:0),o=LimitOrderBookV2_calculateEMA(e,r).map(e=>null!=e?e:0),l=n.map((e,t)=>0===o[t]?null:e-o[t]),a=l.filter(e=>null!==e),s=LimitOrderBookV2_calculateEMA(a,i).map(e=>null!=e?e:0),d=l.length-a.length,c=Array(d).fill(null).concat(s),u=l.map((e,t)=>{let r=c[t];return null===e||null===r||0===r?null:e-r});return{macdLine:l,signal:c,histogram:u}},ei=[{id:"BTC-USD",base_currency:"BTC",quote_currency:"USD"},{id:"ETH-USD",base_currency:"ETH",quote_currency:"USD"},{id:"SOL-USD",base_currency:"SOL",quote_currency:"USD"},{id:"XRP-USD",base_currency:"XRP",quote_currency:"USD"},{id:"DOGE-USD",base_currency:"DOGE",quote_currency:"USD"},{id:"ADA-USD",base_currency:"ADA",quote_currency:"USD"},{id:"AVAX-USD",base_currency:"AVAX",quote_currency:"USD"},{id:"LINK-USD",base_currency:"LINK",quote_currency:"USD"},{id:"DOT-USD",base_currency:"DOT",quote_currency:"USD"},{id:"LTC-USD",base_currency:"LTC",quote_currency:"USD"}];async function fetchProducts(){try{let[e,t]=await Promise.all([fetch("https://api.exchange.coinbase.com/products"),fetch("https://api.exchange.coinbase.com/products/stats")]);if(!e.ok)throw Error("products fetch failed");let r=await e.json(),i=t.ok?await t.json():{};return r.filter(e=>"online"===e.status&&"USD"===e.quote_currency).map(e=>{var t;let r=null===(t=i[e.id])||void 0===t?void 0:t.stats_24hour,n=r?Number(r.open):null,o=r?Number(r.last):null,l=r?Number(r.volume):null,a=null;return n&&n>0&&null!=o&&(a=(o-n)/n*100),{...e,change24h:a,volume24h:l,lastPrice:o}}).sort((e,t)=>e.base_currency.localeCompare(t.base_currency))}catch(e){return ei}}let getCoinbaseCandlesParams=e=>e<=7e-4||e<=.04||e<=.125?{interval:"1m",granularity:60}:e<=1?{interval:"5m",granularity:300}:e<=7?{interval:"1h",granularity:3600}:e<=30?{interval:"6h",granularity:21600}
1:{interval:"1d",granularity:86400},getGranularityForRange=e=>{for(let t of[60,300,900,3600,21600,86400])if(e/t<=300)return t;return 86400},fetchOhlcRange=async(e,t,r,i)=>{if(!e||t>=r)return[];let n=null!=i?i:getGranularityForRange(r-t),o=new Date(1e3*t).toISOString(),l=new Date(1e3*r).toISOString(),a="https://api.exchange.coinbase.com/products/".concat(e,"/candles?granularity=").concat(n,"&start=").concat(encodeURIComponent(o),"&end=").concat(encodeURIComponent(l)),s=await fetch(a);if(!s.ok)throw Error("Failed to fetch OHLC range from Coinbase");let d=await s.json();return d.map(e=>[1e3*e[0],Number(e[3]),Number(e[2]),Number(e[1]),Number(e[4]),Number(e[5]||0)]).sort((e,t)=>Number(e[0])-Number(t[0]))},fetchOhlc=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:7,{granularity:r}=getCoinbaseCandlesParams(t);try{if(60===r){let t=Math.floor(Date.now()/1e3),i=t-86400,n=[];for(let o=i;o<t;o+=18e3){let i=Math.min(o+18e3,t),l=await fetchOhlcRange(e,o,i,r);n.push(...l)}let o=new Set;return n.filter(e=>!o.has(e[0])&&(o.add(e[0]),!0)).sort((e,t)=>Number(e[0])-Number(t[0]))}let t="https://api.exchange.coinbase.com/products/".concat(e,"/candles?granularity=").concat(r),i=await fetch(t);if(!i.ok)throw Error("Failed to fetch OHLC data from Coinbase");let n=await i.json();return n.map(e=>[1e3*e[0],Number(e[3]),Number(e[2]),Number(e[1]),Number(e[4]),Number(e[5]||0)]).sort((e,t)=>Number(e[0])-Number(t[0]))}catch(e){return[]}},fetchPairInfo=async e=>{try{let t=D.gi[e.toLowerCase()],r=t;if(!r){let t=await fetch("https://api.coingecko.com/api/v3/search?query=".concat(encodeURIComponent(e)));if(t.ok){let i=await t.json(),n=i.coins||[],o=n.find(t=>{var r;return(null===(r=t.symbol)||void 0===r?void 0:r.toUpperCase())===e.toUpperCase()})||n[0];o&&(r=o.id)}}if(!r)return null;let i="https://api.coingecko.com/api/v3/coins/".concat(r,"?localization=false&tickers=false&market_data=false&community_data=false&developer_data=false&sparkline=false"),n=await fetch(i);if(!n.ok)return null;return await n.json()}catch(e){return console.error("fetchPairInfo failed",e),null}};function LimitOrderBookV2(e){var t,r,o,a,s,d,c,u,p,h,g,x,b,f,m,y,v,w,S,k,j,C,_,M,P,T,R,z,I,D,L,A,F,N,B,W,O,V,U,H,q,Z,ei,en;let{getSigningClient:eo,chainName:el,denomLogos:ea}=e,{address:es}
1=(0,Y.Ab)(el),ed=(0,K.NL)(),[ec,eu]=(0,n.useState)([]),[ep,eh]=(0,n.useState)(null),[eg,ex]=(0,n.useState)([]),[eb,ef]=(0,n.useState)(!0),[em,ey]=(0,n.useState)(7),[ev,ew]=(0,n.useState)(!0),[eS,ek]=(0,n.useState)(null),[ej,eC]=(0,n.useState)(""),[e_,eM]=(0,n.useState)("change_desc"),eP=(0,n.useRef)(null),[eT,eR]=(0,n.useState)(1),[ez,eI]=(0,n.useState)(14),[eE,eD]=(0,n.useState)(14),[eL,eA]=(0,n.useState)(3),[eF,eN]=(0,n.useState)(3),[eB,eW]=(0,n.useState)(12),[eO,eV]=(0,n.useState)(26),[eU,eH]=(0,n.useState)(9),[eq,eY]=(0,n.useState)(0),[eK]=(0,n.useState)([3,5,8,10,12,15,20,25,30,35,40,45,50,55,60,70,80,89,100,120,150,200,250,300]),[eX,eG]=(0,n.useState)("buy"),[eJ,eQ]=(0,n.useState)(""),[e$,eZ]=(0,n.useState)(""),[e0,e5]=(0,n.useState)(!1),[e1,e2]=(0,n.useState)(""),[e4,e6]=(0,n.useState)(""),[e8,e3]=(0,n.useState)(null),[e9,e7]=(0,n.useState)("buy"),[te,tt]=(0,n.useState)(""),[tr,ti]=(0,n.useState)(!1),[tn,to]=(0,n.useState)(""),[tl,ta]=(0,n.useState)(""),[ts,td]=(0,n.useState)(null),[tc,tu]=(0,n.useState)(null),[tp,th]=(0,n.useState)(""),[tg,tx]=(0,n.useState)(!1),[tb,tf]=(0,n.useState)(""),[tm,ty]=(0,n.useState)(""),[tv,tw]=(0,n.useState)("buy"),[tS,tk]=(0,n.useState)(""),[tj,tC]=(0,n.useState)(""),[t_,tM]=(0,n.useState)(5),[tP,tT]=(0,n.useState)(""),[tR,tz]=(0,n.useState)(!1),[tI,tE]=(0,n.useState)(""),[tD,tL]=(0,n.useState)(""),[tA,tF]=(0,n.useState)(""),[tN,tB]=(0,n.useState)(null),[tW,tO]=(0,n.useState)(!1),[tV,tU]=(0,n.useState)(""),[tH,tq]=(0,n.use
1State)(!1),[tY,tK]=(0,n.useState)(""),[tX,tG]=(0,n.useState)(!1),[tJ,tQ]=(0,n.useState)(""),[t$,tZ]=(0,n.useState)("noble"),[t0,t5]=(0,n.useState)(""),[t1,t2]=(0,n.useState)(!1),[t4,t6]=(0,n.useState)(""),[t8,t3]=(0,n.useState)(""),t9=(0,X.a)({queryKey:["clob-config",et],staleTime:3e5,queryFn:async()=>{let e=await querySmart(et,{config:{}});return e}}),t7=(0,X.a)({queryKey:["clob-bids",et],staleTime:5e3,refetchInterval:5e3,queryFn:async()=>{let e=await querySmart(et,{book:{side:"buy"}});return(null==e?void 0:e.orders)||[]}}),re=(0,X.a)({queryKey:["clob-asks",et],staleTime:5e3,refetchInterval:5e3,queryFn:async()=>{let e=await querySmart(et,{book:{side:"sell"}});return(null==e?void 0:e.orders)||[]}}),rt=(0,X.a)({queryKey:["clob-user-orders",et,es],enabled:!!es,staleTime:5e3,refetchInterval:5e3,queryFn:async()=>{if(!es)return[];let e=await querySmart(et,{user_orders:{owner:es}});return(null==e?void 0:e.orders)||[]}}),rr=(0,X.a)({queryKey:["clob-stats",et],staleTime:3e4,refetchInterval:3e4,queryFn:async()=>{let e=await querySmart(et,{stats:{}});return e}}),ri=(0,X.a)({queryKey:["clob-base-balance",es,null===(t=t9.data)||void 0===t?void 0:t.base_denom],enabled:!!es&&!!(null===(r=t9.data)||void 0===r?void 0:r.base_denom),staleTime:1e4,refetchInterval:15e3,queryFn:async()=>{var e,t;if(!es||!(null===(e=t9.data)||void 0===e?void 0:e.base_denom))return"0";let r="".concat(er,"/cosmos/bank/v1beta1/balances/").concat(es,"/by_denom?denom=").concat(encodeURIComponent(t9.data.base_denom)),i=await fetch(r);if(!i.ok)throw Error("Failed to fetch balance");let n=await i.json();return String((null==n?void 0:null===(t=n.balance)||void 0===t?void 0:t.amount)||"0")}}),rn=(0,X.a)({queryKey:["clob-quote-balance",es,null===(o=t9.data)||void 0===o?void 0:o.quote_denom],enabled:!!es&&!!(null===(a=t9.data)||void 0===a?void 0:a.quote_denom),staleTime:1e4,refetchInterval:15e3,queryFn:async()=>{var e,t;if(!es||!(null===(e=t9.data)||void 0===e?void 0:e.quote_denom))return"0";let r="".concat(er,"/cosmos/bank/v1beta1/balances/").concat(es,"/by_denom?denom=").concat(encodeURIComponent(t9.data.quote_denom)),i=await fetch(r);if(!i.ok)throw Error("Failed to fetch balance");let n=await i.json();return String((null==n?void 0:null===(t=n.balance)||void 0===t?void 0:t.amount)||"0")}}),ro=(0,n.useCallback)(async(e,t)=>{tB({hash:e,label:t,status:"pending"});for(let n=0;n<10;n++)try{var r,i;let o=await (0,J.KI)(er,e);if(!o){if(n<9){await new Promise(e=>setTimeout(e,2e3));continue}tB({hash:e,label:t,status:"error",message:"Transaction not found after multiple attempts"});return}let l=null===(r=o.tx_response)||void 0===r?void 0:r.code;if(void 0!==l&&0!==Number(l)){let r=(null===(i=o.tx_response)||void 0===i?void 0:i.raw_log)||"Transaction failed";tB({hash:e,label:t,status:"error",message:r});return}tB({hash:e,label:t,status:"success"});return}catch(r){if(n<9){await new Promise(e=>setTimeout(e,2e3));continue}tB({hash:e,label:t,status:"error",message:(null==r?void 0:r.message)||"Failed to fetch transaction details"});return}},[]),rl=(0,n.useCallback)(async e=>{for(let r=0;r<10;r++)try{var t;let i=await (0,J.KI)(er,e);if(!i){if(r<9){await new Promise(e=>setTimeout(e,2e3));continue}return null}let n=(null===(t=i.tx_response)||void 0===t?void 0:t.events)||[];for(let e of n){if("wasm"!==e.type)continue;let t=getEventAttributeValue(e,"action"),r=getEventAttributeValue(e,"order_id");if("place_limit"!==t||!r)continue;let i=getEventAttributeValue(e,"side"),n=getEventAttributeValue(e,"price"),o=getEventAttributeValue(e,"qty"),l=getEventAttributeValue(e,"fills")||"0",a=getEventAttributeValue(e,"matched_base")||"0",s=getEventAttributeValue(e,"matched_quote")||"0";if(!i||!n||!o)return null;return{orderId:r,side:i,price:n,qty:o,fills:l,matchedBase:a,matchedQuote:s}}if(r<9){await new Promise(e=>setTimeout(e,2e3));continue}break}catch(e){if(r<9){await new Promise(e=>setTimeout(e,2e3));continue}break}return null},[]),ra=(0,n.useMemo)(()=>eg.length?Number(eg[eg.length-1][4]):0,[eg]),rs=(0,n.useMemo)(()=>{var e,t;return(null==ep?void 0:ep.id)==="ATOM-USD"&&ra>0?ra:(null===(e=t7.data)||void 0===e?void 0:e.length)&&(null===(t=re.data)||void 0===t?void 0:t.length)?(Number(t7.data[0].price)+Number(re.data[0].price))/2/1e12:ra>0?ra:0},[ep,ra,t7.data,re.data]),rd=(0,n.useCallback)(async()=>
1{if(es&&eJ&&e$&&t9.data){e5(!0),e2(""),e6(""),e3(null);try{let e=t9.data.base_decimals||6;t9.data.quote_decimals;let t=t9.data.taker_fee_bps||25,r=t9.data.base_denom,i=t9.data.quote_denom,n=parseFloat(eJ),o=parseFloat(e$);if(!isFinite(n)||n<=0||!isFinite(o)||o<=0)throw Error("Invalid price or quantity");let l=String(Math.floor(1e12*n)),a=String(Math.floor(o*Math.pow(10,e))),s=[];if("buy"===eX){let e=BigInt(l)*BigInt(a)/BigInt(1e12),r=e*BigInt(t)/BigInt(1e4);s.push({denom:i,amount:(e+r).toString()})}else s.push({denom:r,amount:a});s.sort((e,t)=>e.denom.localeCompare(t.denom));let d=await eo(),c=await d.execute(es,et,{place_limit:{price:l,qty:a,side:eX}},{amount:[{denom:"uatom",amount:"25000"}],gas:"350000"},"Place limit order",s);e6(c.transactionHash),eQ(""),eZ(""),ro(c.transactionHash,"Place limit order");let u=await rl(c.transactionHash);e3(u),ed.invalidateQueries({queryKey:["clob-bids"]}),ed.invalidateQueries({queryKey:["clob-asks"]}),ed.invalidateQueries({queryKey:["clob-user-orders"]}),ed.invalidateQueries({queryKey:["clob-stats"]})}catch(e){e2((null==e?void 0:e.message)||"Failed to place order")}finally{e5(!1)}}},[es,eX,eJ,e$,t9.data,eo,ed,ro,rl]),rc=(0,n.useCallback)(async e=>{if(es&&te&&t9.data&&rs&&!(rs<=0)){ti(!0),to(""),ta(""),td(null);try{let t=t9.data.base_decimals||6;t9.data.quote_decimals;let r=t9.data.taker_fee_bps||25,i=t9.data.base_denom,n=t9.data.quote_denom,o=parseFloat(te);if(!isFinite(o)||o<=0)throw Error("Invalid quantity");let l=String(Math.floor(1e12*rs)),a=String(Math.floor(o*Math.pow(10,t))),s=[];if("buy"===e){let e=BigInt(l)*BigInt(a)/BigInt(1e12),t=e*BigInt(r)/BigInt(1e4);s.push({denom:n,amount:(e+t).toString()})}else s.push({denom:i,amount:a});s.sort((e,t)=>e.denom.localeCompare(t.denom));let d=await eo(),c=await d.execute(es,et,{place_limit:{price:l,qty:a,side:e}},{amount:[{denom:"uatom",amount:"25000"}],gas:"350000"},"Place market order",s);ta(c.transactionHash),tt(""),ro(c.transactionHash,"Place market order");let u=await rl(c.transactionHash);td(u),ed.invalidateQueries({queryKey:["clob-bids"]}),ed.invalidateQueries({queryKey:["clob-asks"]}),ed.invalidateQueries({queryKey:["clob-user-orders"]}),ed.invalidateQueries({queryKey:["clob-stats"]})}catch(e){to((null==e?void 0:e.message)||"Failed to place market order")}finally{ti(!1)}}},[es,te,t9.data,rs,eo,ed,ro,rl]),ru=(0,n.useCallback)(async e=>{if(es){tu(e),th("");try{let t=await eo(),r=await t.execute(es,et,{cancel:{order_id:e}},{amount:[{denom:"uatom",amount:"25000"}],gas:"250000"},"Cancel limit order");tF(r.transactionHash),ro(r.transactionHash,"Cancel limit order"),ed.invalidateQueries({queryKey:["clob-bids"]}),ed.invalidateQueries({queryKey:["clob-asks"]}),ed.invalidateQueries({queryKey:["clob-user-orders"]}),ed.invalidateQueries({queryKey:["clob-stats"]})}catch(e){th((null==e?void 0:e.message)||"Failed to cancel order")}finally{tu(null)}}},[es,eo,ed,ro]),rp=(0,n.useCallback)(async()=>{var e;if(!es)return;let t=(null===(e=rt.data)||void 0===e?void 0:e.filter(e=>"open"===e.status||"partially_filled"===e.status))||[];if(0!==t.length){tx(!0),tf(""),ty("");try{let e=[];for(let r of t){let t={cancel:{order_id:r.id}};e.push({typeUrl:"/cosmwasm.wasm.v1.MsgExecuteContract",value:{sender:es,contract:et,msg:new TextEncoder().encode(JSON.stringify(t)),funds:[]}})}let r=await eo(),i={amount:[{denom:"uatom",amount:String(25e3*e.length)}],gas:String(25e4*e.length)},n=await r.signAndBroadcast(es,e,i,"Cancel all ".concat(e.length," orders"));ty(n.transactionHash),ro(n.transactionHash,"Cancel all ".concat(e.length," orders")),ed.invalidateQueries({queryKey:["clob-bids"]}),ed.invalidateQueries({queryKey:["clob-asks"]}),ed.invalidateQueries({queryKey:["clob-user-orders"]}),ed.invalidateQueries({queryKey:["clob-stats"]})}catch(e){tf((null==e?void 0:e.message)||"Failed to cancel all orders")}finally{tx(!1)}}},[es,rt.data,eo,ed,ro]),rh=(0,n.useCallback)(async()=>{if(es&&tS&&tj&&tP&&t9.data){tz(!0),tE(""),tL("");try{let e=t9.data.base_decimals||6,t=t9.data.taker_fee_bps||25,r=t9.data.base_denom,i=t9.data.quote_denom,n=parseFloat(tS),o=parseFloat(tj),l=parseFloat(tP),a=Math.max(2,Math.min(20,t_));if(!isFinite(n)||!isFinite(o)||!isFinite(l)||n<=0||o<=0||l<=0)throw Error("Invalid channel, total amount, or step count");if(o<=n)throw Error("Upper price must be greater than lower price");let s=(o-n)/(a-1),d=[];for(let o=0;o<a;o++){let c;let u=n+o*s,p=String(Math.floor(1e12*u)),h=[];if("sell"===tv){let t=l/a;c=String(Math.floor(t*Math.pow(10,e))),h.push({denom:r,amount:c})}else{let r=l/a,n=r/u;c=String(Math.floor(n*Math.pow(10,e)));let o=BigInt(p)*BigInt(c)/BigInt(1e12),s=o*BigInt(t)/BigInt(1e4),d=o+s;h.push({denom:i,amount:d.toString()})}h.sort((e,t)=>
1e.denom.localeCompare(t.denom));let g={place_limit:{price:p,qty:c,side:tv}};d.push({typeUrl:"/cosmwasm.wasm.v1.MsgExecuteContract",value:{sender:es,contract:et,msg:new TextEncoder().encode(JSON.stringify(g)),funds:h}})}let c=await eo(),u={amount:[{denom:"uatom",amount:String(25e3*d.length)}],gas:String(35e4*d.length)},p=await c.signAndBroadcast(es,d,u,"Place ".concat(tv," grid orders"));tL(p.transactionHash),ro(p.transactionHash,"Place ".concat(tv," grid orders")),ed.invalidateQueries({queryKey:["clob-bids"]}),ed.invalidateQueries({queryKey:["clob-asks"]}),ed.invalidateQueries({queryKey:["clob-user-orders"]}),ed.invalidateQueries({queryKey:["clob-stats"]})}catch(e){tE((null==e?void 0:e.message)||"Failed to place grid orders")}finally{tz(!1)}}},[es,tS,tj,tP,t_,tv,t9.data,eo,ed,ro]),deriveAddress=(e,t)=>{try{let{data:r}=(0,G.fromBech32)(e);return(0,G.toBech32)(t,r)}catch(e){return""}},evmToInjectiveBech32=e=>{try{if(!e.startsWith("0x"))return e;let t=e.slice(2).padStart(40,"0"),r=ee.from(t,"hex");return(0,G.toBech32)("inj",r)}catch(e){return console.error("Failed to convert EVM address:",e),""}},rg=(0,n.useMemo)(()=>[{key:"osmosis",chainId:"osmosis-1",prefix:"osmo",restFallback:"https://osmosis-rest.publicnode.com"},{key:"noble",chainId:"noble-1",prefix:"noble",restFallback:"https://noble-rest.publicnode.com"},{key:"injective",chainId:"injective-1",prefix:"inj",restFallback:"https://injective-rest.publicnode.com"}],[]),rx=(0,X.a)({queryKey:["skip-chains-info"],staleTime:3e5,enabled:tX,queryFn:async()=>{let e=await fetch("/api/skip/v2/info/chains");if(!e.ok)throw Error("Failed to fetch Skip chains");let t=await e.json(),r=Array.isArray(null==t?void 0:t.chains)?t.chains:[],i={};return r.forEach(e=>{e.chain_id&&(i[e.chain_id]=e)}),i}}),rb=(0,X.a)({queryKey:["skip-assets-deposit",rg.map(e=>e.chainId).join(",")],staleTime:3e5,enabled:tX,queryFn:async()=>{let e=new URLSearchParams;e.set("chain_ids",rg.map(e=>e.chainId).join(",")),e.set("include_no_metadata_assets","false");let t=await fetch("/api/skip/v2/fungible/assets?".concat(e.toString()));if(!t.ok)throw Error("Failed to fetch Skip assets");let r=await t.json(),i={};return rg.forEach(e=>{var t,n;let{chainId:o,key:l}=e,a=(null==r?void 0:null===(n=r.chain_to_assets_map)||void 0===n?void 0:null===(t=n[o])||void 0===t?void 0:t.assets)||[],s=a.find(e=>{var t,r;return"uusdc"===e.denom||(null===(t=e.symbol)||void 0===t?void 0:t.toUpperCase())==="USDC"||(null===(r=e.name)||void 0===r?void 0:r.toUpperCase().includes("USDC"))});s&&(i[l]={denom:s.denom,symbol:s.symbol,name:s.name,decimals:s.decimals||6})}),i}}),rf=(0,n.useMemo)(()=>{if(!es)return{};let e={};return rg.forEach(t=>{let{key:r,prefix:i}=t;"injective"===r?e[r]=t0:e[r]=deriveAddress(es,i)}),e},[es,t0,rg]),rm=(0,X.a)({queryKey:["deposit-balance","osmosis",rf.osmosis,null===(d=rb.data)||void 0===d?void 0:null===(s=d.osmosis)||void 0===s?void 0:s.denom],enabled:!!tX&&!!rf.osmosis&&!!(null===(u=rb.data)||void 0===u?void 0:null===(c=u.osmosis)||void 0===c?void 0:c.denom),staleTime:1e4,refetchInterval:15e3,queryFn:async()=>{var e,t,r;let i=null===(e=rx.data)||void 0===e?void 0:e["osmosis-1"],n=null!==(r=null==i?void 0:i.rest)&&void 0!==r?r:rg[0].restFallback,o=rb.data.osmosis.denom,l="".concat(n,"/cosmos/bank/v1beta1/balances/").concat(rf.osmosis,"/by_denom?denom=").concat(encodeURIComponent(o)),a=await fetch(l);if(!a.ok)throw Error("Failed to fetch Osmosis balance: ".concat(a.status));let s=await a.json();return String((null==s?void 0:null===(t=s.balance)||void 0===t?void 0:t.amount)||"0")}}),ry=(0,X.a)({queryKey:["deposit-balance","noble",rf.noble,null===(h=rb.data)||void 0===h?void 0:null===(p=h.noble)||void 0===p?void 0:p.denom],enabled:!!tX&&!!rf.noble&&!!(null===(x=rb.data)||void 0===x?void 0:null===(g=x.noble)||void 0===g?void 0:g.denom),staleTime:1e4,refetchInterval:15e3,queryFn:async()=>{var e,t,r;let i=null===(e=rx.data)||void 0===e?void 0:e["noble-1"],n=null!==(r=null==i?void 0:i.rest)&&void 0!==r?r:rg[1].restFallback,o=rb.data.noble.denom,l="".concat(n,"/cosmos/bank/v1beta1/balances/").concat(rf.noble,"/by_denom?denom=").concat(encodeURIComponent(o)),a=await fetch(l);if(!a.ok)throw Error("Failed to fetch Noble balance: ".concat(a.status));let s=await a.json();return String((null==s?void 0:null===(t=s.balance)||void 0===t?void 0:t.amount)||"0")}}),rv=(0,X.a)({queryKey:["deposit-balance","injective",rf.injective,null===(f=rb.data)||void 0===f?void 0:null===(b=f.injective)||void 0===b?void 0:b.de
1nom],enabled:!!tX&&!!rf.injective&&!!(null===(y=rb.data)||void 0===y?void 0:null===(m=y.injective)||void 0===m?void 0:m.denom),staleTime:1e4,refetchInterval:15e3,queryFn:async()=>{var e,t,r;let i=null===(e=rx.data)||void 0===e?void 0:e["injective-1"],n=null!==(r=null==i?void 0:i.rest)&&void 0!==r?r:rg[2].restFallback,o=rb.data.injective.denom,l=rf.injective;if(l.startsWith("0x")&&!(l=evmToInjectiveBech32(l)))throw Error("Invalid Injective EVM address");let a="".concat(n,"/cosmos/bank/v1beta1/balances/").concat(l,"/by_denom?denom=").concat(encodeURIComponent(o)),s=await fetch(a);if(!s.ok)throw Error("Failed to fetch Injective balance: ".concat(s.status));let d=await s.json();return String((null==d?void 0:null===(t=d.balance)||void 0===t?void 0:t.amount)||"0")}}),rw=(0,n.useCallback)(async()=>{if(es&&tJ){t2(!0),t6(""),t3("");try{var e,t;let r=parseFloat(tJ);if(!isFinite(r)||r<=0)throw Error("Invalid amount");let i=rg.find(e=>e.key===t$);if(!i)throw Error("Invalid chain");let n=null===(e=rb.data)||void 0===e?void 0:e[t$];if(!n)throw Error("USDC asset not found on source chain");let o=null===(t=t9.data)||void 0===t?void 0:t.quote_denom;
1if(!o)throw Error("Destination denom not available");let l=rf[t$];if(!l)throw Error("Source address not available");let a=n.decimals||6,s=String(Math.floor(r*Math.pow(10,a))),d=await fetch("/api/skip/v2/fungible/route",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({source_asset_denom:n.denom,source_asset_chain_id:i.chainId,dest_asset_denom:o,dest_asset_chain_id:"cosmoshub-4",amount_in:s,smart_relay:!0})}),c=await d.json();if(!d.ok||c.code)throw Error(c.message||"Skip route failed");let u=c.chain_ids||[],p=u.map(e=>{var t;if("cosmoshub-4"===e)return es;if(e===i.chainId)return l;let r=null===(t=rx.data)||void 0===t?void 0:t[e];if(null==r?void 0:r.bech32_prefix){let e=deriveAddress(es,r.bech32_prefix);if(e)return e}return l}),h=await fetch("/api/skip/v2/fungible/msg",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({source_asset_denom:n.denom,source_asset_chain_id:i.chainId,dest_asset_denom:o,dest_asset_chain_id:"cosmoshub-4",amount_in:s,address_list:p,operations:c.operations,chain_ids:u})}),g=await h.json();if(!h.ok||g.code)throw Error(g.message||"Skip msg build failed");let x=g.msgs||[];if(!x.length)throw Error("No messages returned from Skip");throw Error("Multi-chain deposit requires a source-chain signer. Please use the Skip widget or deposit manually via your wallet.")}catch(e){t6((null==e?void 0:e.message)||"Deposit failed")}finally{t2(!1)}}},[es,tJ,t$,rf,rb.data,t9.data,rx.data,rg]),rS=(0,Q.Gl)({limit:50},$.l9),{fundVault:rk}=(0,Q.YF)(el),[rj,rC]=(0,n.useState)(null),[r_,rM]=(0,n.useState)(null),rP=(0,n.useMemo)(()=>{let e=rS.data||[],t=Math.floor(Date.now()/1e3);return e.filter(e=>{let r=e.offer_denom===$.KB.ATOM&&e.ask_denom===$.KB.USDC||e.offer_denom===$.KB.USDC&&e.ask_denom===$.KB.ATOM,i="open"===e.status&&(e.expires_at<=0||e.expires_at>t);return r&&i})},[rS.data]),rT=(0,n.useCallback)(async e=>{if(es){rC(e.vault_id),rM(null);try{await rk.mutateAsync({vaultId:e.vault_id,amount:e.ask_amount,denom:e.ask_denom})}catch(e){rM((null==e?void 0:e.message)||"Failed to take offer")}finally{rC(null)}}},[es,rk]),formatPrice=e=>{let t=Number(e);return(t/1e12).toFixed(2)},formatQty=e=>{var t;let r=Number(e),i=(null===(t=t9.data)||void 0===t?void 0:t.base_decimals)||6;return(r/Math.pow(10,i)).toFixed(i)},formatQuoteQty=e=>{var t;let r=Number(e),i=(null===(t=t9.data)||void 0===t?void 0:t.quote_decimals)||6;return(r/Math.pow(10,i)).toFixed(i)},rR=(0,n.useMemo)(()=>{var e,t,r;if(!(null===(e=t7.data)||void 0===e?void 0:e.length)||!(null===(t=re.data)||void 0===t?void 0:t.length))return null;let i=Number(t7.data[0].price),n=Number(re.data[0].price),o=(null===(r=t9.data)||void 0===r?void 0:r.quote_decimals)||6,l=(n-i)/Math.pow(10,o);return{value:l.toFixed(o),percent:((n-i)/i*100).toFixed(2)}},[t7.data,re.data,t9.data]);(0,n.useEffect)(()=>{let e=!1;return fetchProducts().then(t=>{if(e)return;eu(t);let r=t.find(e=>"ATOM-USD"===e.id);eh(r||t.find(e=>"BTC-USD"===e.id)||t[0])}),()=>{e=!0}},[]),(0,n.useEffect)(()=>{if(!ep)return;let e=!1;return ef(!0),fetchOhlc(ep.id,em).then(t=>{e||(ex(t),ef(!1))}),()=>{e=!0}},[ep,em]),(0,n.useEffect)(()=>{if(!ep){ek(null);return}let e=!1;return ek(null),fetchPairInfo(ep.base_currency).then(t=>{e||ek(t)}),()=>{e=!0}},[ep]);let rz=(0,n.useMemo)(()=>{let e=ej.trim().toLowerCase(),t=e?ec.filter(t=>"".concat(t.base_currency," ").concat(t.id).toLowerCase().includes(e)):[...ec];switch(e_){case"az":t.sort((e,t)=>e.base_currency.localeCompare(t.base_currency));break;case"change_desc":t.sort((e,t)=>{var r,i;return(null!==(r=t.change24h)&&void 0!==r?r:-1/0)-(null!==(i=e.change24h)&&void 0!==i?i:-1/0)});break;case"change_asc":t.sort((e,t)=>{var r,i;return(null!==(r=e.change24h)&&void 0!==r?r:1/0)-(null!==(i=t.change24h)&&void 0!==i?i:1/0)});break;case"volume_desc":t.sort((e,t)=>{var r,i;return(null!==(r=t.volume24h)&&void 0!==r?r:-1/0)-(null!==(i=e.volume24h)&&void 0!==i?i:-1/0)})}return t},[ec,ej,e_]),{interval:rI}=(0,n.useMemo)(()=>getCoinbaseCandlesParams(em),[em]),rE=(null==ep?void 0:ep.base_currency)||"",rD=ep?"".concat(ep.base_currency,"/USD"):"",rL=(0,n.useCallback)(async()=>
1{if(!eg||eg.length<2){tK("Not enough chart data for analysis");return}tq(!0),tK(""),tU("");try{var e,t,r,i,n,o,l;let a=eg.map(e=>Number(e[4])),s=a[a.length-1],d=a[0],c=(s-d)/d*100,u=Math.max(...a),p=Math.min(...a),h=LimitOrderBookV2_calculateRSI(a,ez),g=null!==(i=h.filter(e=>null!==e).pop())&&void 0!==i?i:null,x=LimitOrderBookV2_calculateMACD(a,eB,eO,eU),b=null!==(n=x.macdLine.filter(e=>null!==e).pop())&&void 0!==n?n:null,f=null!==(o=x.signal.filter(e=>null!==e).pop())&&void 0!==o?o:null,m=null!==(l=x.histogram.filter(e=>null!==e).pop())&&void 0!==l?l:null,y=eK.slice(0,eq).map(e=>{var t;let r=LimitOrderBookV2_calculateSMA(a,e),i=null!==(t=r.filter(e=>null!==e).pop())&&void 0!==t?t:null;return{period:e,value:i}}),v=null===(e=t7.data)||void 0===e?void 0:e[0],w=null===(t=re.data)||void 0===t?void 0:t[0],S=(t7.data||[]).reduce((e,t)=>e+Number(t.qty),0),k=(re.data||[]).reduce((e,t)=>e+Number(t.qty),0),j=[];j.push("Pair: ATOM/USDC"),j.push("Timeframe: ".concat(em,"d")),j.push("Data points: ".concat(a.length)),j.push("Current Price: $".concat(s.toFixed(2))),j.push("Period High: $".concat(u.toFixed(2))),j.push("Period Low: $".concat(p.toFixed(2))),j.push("Price Change: ".concat(c>=0?"+":"").concat(c.toFixed(2),"%")),j.push("RSI (".concat(ez,"): ").concat(null!==g?g.toFixed(2):"N/A")),j.push("MACD Line: ".concat(null!==b?b.toFixed(4):"N/A")),j.push("MACD Signal: ".concat(null!==f?f.toFixed(4):"N/A")),j.push("MACD Histogram: ".concat(null!==m?m.toFixed(4):"N/A")),eq>0&&j.push("SMAs: ".concat(y.map(e=>"SMA".concat(e.period,"=$").concat(null!==e.value?e.value.toFixed(2):"N/A")).join(", ")));let C=(null===(r=t9.data)||void 0===r?void 0:r.base_decimals)||6,fmtQty=e=>(Number(e)/Math.pow(10,C)).toFixed(C);if(v&&w){let e=Number(v.price)/1e12,t=Number(w.price)/1e12;j.push("Best Bid: $".concat(e.toFixed(2)," (qty: ").concat(fmtQty(v.qty),")")),j.push("Best Ask: $".concat(t.toFixed(2)," (qty: ").concat(fmtQty(w.qty),")")),j.push("Spread: $".concat((t-e).toFixed(2)," (").concat(((t-e)/e*100).toFixed(2),"%)"))}j.push("Total Bid Volume: ".concat(fmtQty(String(S))," ATOM")),j.push("Total Ask Volume: ".concat(fmtQty(String(k))," ATOM"));let _=await fetch("/api/ollama-market",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({context:j.join("\n")})});if(!_.ok)throw Error("AI analysis request failed");let M=await _.json();tU(M.analysis||"No analysis returned")}catch(e){tK((null==e?void 0:e.message)||"Failed to get AI analysis")}finally{tq(!1)}},[eg,ez,eB,eO,eU,eK,eq,t7.data,re.data,em,t9.data]),rA=(0,n.useMemo)(()=>{let scalePeriod=e=>Math.max(1,Math.round(e*eT));return{rsiPeriod:scalePeriod(ez),macdFast:scalePeriod(eB),macdSlow:scalePeriod(eO),macdSignal:scalePeriod(eU),stochPeriod:scalePeriod(eE),stochKSmooth:scalePeriod(eL),stochDSmooth:scalePeriod(eF),indicatorScale:Number(eT.toFixed(2))}},[ez,eB,eO,eU,eE,eL,eF,eT]),rF=(0,n.useMemo)(()=>eg.map(e=>{let t=Number(e[0]),r=new Date(t);return em<1?r.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):1===em?r.toLocaleTimeString("en-US",{hour:"numeric",hour12:!0}):r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}),[eg,em]),rN=(0,n.useMemo)(()=>{if(eg.length<2)return null;let e=eg.map(e=>Number(e[4])),t=LimitOrderBookV2_calculateRSI(e,rA.rsiPeriod),r=LimitOrderBookV2_calculateStochasticRSI(e,rA.rsiPeriod,rA.stochPeriod,rA.stochKSmooth,rA.stochDSmooth);return{labels:rF,datasets:[{label:"RSI (".concat(rA.rsiPeriod,")"),data:t,borderColor:"rgba(255, 205, 86, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"y"},{label:"Stoch %K (".concat(rA.stochPeriod,",").concat(rA.stochKSmooth,")"),data:r.k,borderColor:"rgba(56, 189, 248, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"y"},{label:"Stoch %D (".concat(rA.stochDSmooth,")"),data:r.d,borderColor:"rgba(244, 114, 182, 0.9)",backgroundColor:"transparent",borderWidth:1.5,borderDash:[4,4],pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"y"}]}},[eg,rF,rA]),rB=(0,n.useMemo)(()=>{if(eg.length<2)return null;let e=eg.map(e=>Number(e[4])),t=LimitOrderBookV2_calculateMACD(e,rA.macdFast,rA.macdSlow,rA.macdSignal);return{labels:rF,datasets:[{label:"MACD (".concat(rA.macdFast,",").concat(rA.macdSlow,")"),data:t.macdLine,borderColor:"rgba(54, 162, 235, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"yMacd"},{label:"Signal (".concat(rA.macdSignal,")"),data:t.signal,borderColor:"rgba(255, 99, 132, 0.9)",backgroundColor:"transparent",borderWidth:1.5,pointRadius:0,pointHoverRadius:4,tension:.4,yAxisID:"yMacd"},{label:"MACD Histogram",type:"bar",data:t.histogram,borderWidth:1,pointRadius:0,barPercentage:.95,categoryPercentage:.9,yAxisID:"yMacd",backgroundColor:e=>{let r=e.dataIndex,i=e.raw,n=r>0?t.histogram[r-1]:i,o=i>n;return i>0?o?"rgba(255, 255, 255, 0.3)":"rgba(239, 68, 68, 0.3)":o?"rgba(34, 197, 94, 0.3)":"rgba(30, 58, 138, 0.3)"},borderColor:e=>{let r=e.dataIndex,i=e.raw,n=r>0?t.histogram[r-1]:i;return i>0?i>n?"rgba(255, 255, 255, 0.6)":"rgba(239, 68, 68, 0.6)":i<n?"rgba(30, 58, 138, 0.6)":"rgba(34, 197, 94, 0.6)"}}]}},[eg,rF,rA]),rW=(0,n.useMemo)(()=>({responsive:!0,maintainAspectRatio:!1,animation:{duration:0},interaction:{mode:"index",intersect:!1}
1,plugins:{legend:{display:!0,labels:{color:"rgba(255,255,255,0.6)",font:{size:10},boxWidth:10}},tooltip:{mode:"index",intersect:!1,backgroundColor:"rgba(7, 11, 24, 0.9)",titleColor:"#fff",bodyColor:"#e5e7eb",borderColor:"rgba(124, 58, 237, 0.3)",borderWidth:1}},scales:{x:{grid:{display:!1},ticks:{color:"rgba(255, 255, 255, 0.5)",font:{size:11}}},y:{type:"linear",position:"left",min:0,max:100,grid:{color:"rgba(255, 255, 255, 0.08)"},ticks:{color:"rgba(255, 255, 255, 0.6)",font:{size:10}}}}}),[]),rO=(0,n.useMemo)(()=>({responsive:!0,maintainAspectRatio:!1,animation:{duration:0},interaction:{mode:"index",intersect:!1},plugins:{legend:{display:!0,labels:{color:"rgba(255,255,255,0.6)",font:{size:10},boxWidth:10}},tooltip:{mode:"index",intersect:!1,backgroundColor:"rgba(7, 11, 24, 0.9)",titleColor:"#fff",bodyColor:"#e5e7eb",borderColor:"rgba(124, 58, 237, 0.3)",borderWidth:1}},scales:{x:{grid:{display:!1},ticks:{color:"rgba(255, 255, 255, 0.5)",font:{size:11}}},yMacd:{type:"linear",position:"left",grid:{color:"rgba(255, 255, 255, 0.08)"},ticks:{color:"rgba(54, 162, 235, 0.8)",font:{size:10}}}}}),[]),scroll=e=>{if(!eP.current)return;let t=Math.max(160,.4*eP.current.clientWidth);eP.current.scrollBy({left:e*t,behavior:"smooth"})};return(0,i.jsxs)("div",{style:{width:"100%",margin:"0 auto",padding:"1.25rem",boxSizing:"border-box",borderRadius:"1rem",background:"linear-gradient(135deg, rgba(232, 238, 245, 0.16) 0%, rgba(255, 255, 255, 0.08) 30%, rgba(176, 190, 208, 0.13) 55%, rgba(255, 255, 255, 0.06) 75%, rgba(148, 163, 184, 0.15) 100%)",border:"1px solid rgba(255,255,255,0.18)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)"},children:[(0,i.jsxs)("div",{style:{marginBottom:"1.5rem",padding:"1rem 1.25rem",borderRadius:"0.75rem",background:"linear-gradient(135deg, rgba(232, 238, 245, 0.22) 0%, rgba(255, 255, 255, 0.12) 30%, rgba(176, 190, 208, 0.18) 55%, rgba(255, 255, 255, 0.09) 75%, rgba(148, 163, 184, 0.2) 100%)",border:"1px solid rgba(255,255,255,0.22)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)"},children:[(0,i.jsx)("h1",{style:{fontSize:"1.875rem",fontWeight:700,color:"#f3f4f6",margin:"0 0 0.5rem"},children:"Limit Order Book v2 — ATOM/USDC"}),(0,i.jsx)("p",{style:{fontSize:"0.875rem",color:"#6b7280",margin:0},children:"Analyse various Trading Pairs"})]}),es&&(0,i.jsxs)("div",{style:{display:"flex",gap:"12px",marginBottom:"20px"},children:[(0,i.jsxs)("div",{style:{flex:1,display:"flex",alignItems:"center",gap:"10px",padding:"12px",borderRadius:"10px",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.08)"},children:[(null==ea?void 0:ea[(null===(v=t9.data)||void 0===v?void 0:v.base_denom)||""])?(0,i.jsx)("img",{src:ea[(null===(w=t9.data)||void 0===w?void 0:w.base_denom)||""],alt:"ATOM",style:{width:28,height:28,borderRadius:"50%",objectFit:"cover"},onError:e=>{e.currentTarget.style.display="none"}}):(0,i.jsx)("div",{style:{width:28,height:28,borderRadius:"50%",background:"linear-gradient(135deg, #6b7280, #9ca3af)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:700,color:"#fff"},children:"A"}),(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.5)"},children:"ATOM"}),(0,i.jsx)("div",{style:{fontSize:"16px",fontWeight:700,color:"#fff"},children:ri.isLoading?"...":formatQty(ri.data||"0")})]})]}),(0,i.jsxs)("div",{style:{flex:1,display:"flex",alignItems:"center",gap:"10px",padding:"12px",borderRadius:"10px",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.08)"},children:[(null==ea?void 0:ea[(null===(S=t9.data)||void 0===S?void 0:S.quote_denom)||""])?(0,i.jsx)("img",{src:ea[(null===(k=t9.data)||void 0===k?void 0:k.quote_denom)||""],alt:"USDC",style:{width:28,height:28,borderRadius:"50%",objectFit:"cover"},onError:e=>{e.currentTarget.style.display="none"}}):(0,i.jsx)("div",{style:{width:28,height:28,borderRadius:"50%",background:"linear-gradient(135deg, #22c55e, #16a34a)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:700,color:"#fff"},children:"U"}),(0,i.jsxs)("div",{style:{flex:1},children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.5)"},children:"USDC"}),(0,i.jsx)("div",{style:{fontSize:"16px",fontWeight:700,color:"#fff"},children:rn.isLoading?"...":formatQuoteQty(rn.data||"0")})]}),(0,i.jsx)("button",{onClick:()=>{tG(!0),t6(""),t3("")},style:{padding:"6px 12px",borderRadius:"6px",border:"1px solid rgba(34, 197, 94, 0.4)",background:"rgba(34, 197, 94, 0.15)",color:"#4ade80",fontSize:"12px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(34, 197, 94, 0.25)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(34, 197, 94, 0.15)"},children:"Deposit"})]})]}),tN&&(0,i.jsxs)("div",{style:{marginBottom:"20px",padding:"12px",borderRadius:"10px",background:"error"===tN.status?"rgba(239, 68, 68, 0.1)":"success"===tN.status?"rgba(34, 197, 94, 0.1)":"rgba(59, 130, 246, 0.1)",border:"1px solid ".concat("error"===tN.status?"rgba(239, 68, 68, 0.3)":"success"===tN.status?"rgba(34, 197, 94, 0.3)":"rgba(59, 130, 246, 0.3)"),color:"error"===tN.status?"#fca5a5":"success"===tN.status?"#86efac":"#93c5fd",fontSize:"13px"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,i.jsxs)("span",{style:{fontWeight:600},children:["pending"===tN.status?"⏳ Confirming":"success"===tN.status?"✓ Confirmed":"✗ Failed",":"]}
1),(0,i.jsx)("span",{children:tN.label})]}),(0,i.jsx)("div",{style:{fontFamily:"monospace",wordBreak:"break-all",fontSize:"12px"},children:tN.hash}),"error"===tN.status&&tN.message&&(0,i.jsx)("div",{style:{marginTop:"6px",fontSize:"12px",color:"#fca5a5"},children:tN.message})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:"12px",marginBottom:"24px"},children:[(0,i.jsxs)("div",{style:{padding:"12px",borderRadius:"10px",background:"rgba(59, 130, 246, 0.1)",border:"1px solid rgba(59, 130, 246, 0.2)"},children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Open Orders"}),(0,i.jsx)("div",{style:{fontSize:"18px",fontWeight:700,color:"#60a5fa"},children:(null===(j=rr.data)||void 0===j?void 0:j.open_orders)||0})]}),(0,i.jsxs)("div",{style:{padding:"12px",borderRadius:"10px",background:"rgba(34, 197, 94, 0.1)",border:"1px solid rgba(34, 197, 94, 0.2)"},children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Filled Orders"}),(0,i.jsx)("div",{style:{fontSize:"18px",fontWeight:700,color:"#4ade80"},children:(null===(C=rr.data)||void 0===C?void 0:C.filled_orders)||0})]}),(0,i.jsxs)("div",{style:{padding:"12px",borderRadius:"10px",background:"rgba(168, 85, 247, 0.1)",border:"1px solid rgba(168, 85, 247, 0.2)"},children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Total Volume"}),(0,i.jsxs)("div",{style:{fontSize:"18px",fontWeight:700,color:"#c4b5fd"},children:[formatQty((null===(_=rr.data)||void 0===_?void 0:_.total_base_volume)||"0")," ATOM"]})]}),(0,i.jsxs)("div",{style:{padding:"12px",borderRadius:"10px",background:"rgba(234, 179, 8, 0.1)",border:"1px solid rgba(234, 179, 8, 0.2)"},children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"4px"},children:"Taker Fee"}),(0,i.jsxs)("div",{style:{fontSize:"18px",fontWeight:700,color:"#fbbf24"},children:[(null===(M=t9.data)||void 0===M?void 0:M.taker_fee_bps)||25," bps"]})]})]}),(0,i.jsxs)("div",{style:{marginBottom:"1.5rem"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"0.75rem"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",flex:"1 1 auto",flexWrap:"wrap"},children:[(0,i.jsx)("input",{type:"text",value:ej,onChange:e=>eC(e.target.value),placeholder:"Search pair...",style:{minWidth:"140px",flex:"1 1 140px",maxWidth:"220px",padding:"0.45rem 0.7rem",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"0.875rem",outline:"none"}}),(0,i.jsxs)("select",{value:e_,onChange:e=>eM(e.target.value),style:{padding:"0.45rem 0.7rem",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"0.875rem",cursor:"pointer"},children:[(0,i.jsx)("option",{value:"change_desc",style:{background:"#1f2937",color:"#fff"},children:"24h % ▼"}),(0,i.jsx)("option",{value:"change_asc",style:{background:"#1f2937",color:"#fff"},children:"24h % ▲"}),(0,i.jsx)("option",{value:"volume_desc",style:{background:"#1f2937",color:"#fff"},children:"24h vol ▼"}),(0,i.jsx)("option",{value:"az",style:{background:"#1f2937",color:"#fff"},children:"A-Z"})]}),(0,i.jsx)("span",{style:{fontSize:"0.875rem",fontWeight:600,color:"#fff"},children:ec.length?"".concat(rz.length," / ").concat(ec.length," USD pairs"):"Loading pairs..."})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:"0.5rem"},children:[(0,i.jsx)("button",{onClick:()=>scroll(-1),"aria-label":"Previous pairs",style:{width:"32px",height:"32px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.06)",color:"#fff",cursor:"pointer",fontSize:"1.1rem"},children:"‹"}),(0,i.jsx)("button",{onClick:()=>scroll(1),"aria-label":"Next pairs",style:{width:"32px",height:"32px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.06)",color:"#fff",cursor:"pointer",fontSize:"1.1rem"},children:"›"})]})]}),(0,i.jsx)("div",{ref:eP,style:{display:"flex",gap:"0.75rem",overflowX:"auto",paddingBottom:"0.5rem",scrollbarWidth:"none",msOverflowStyle:"none"},children:rz.map(e=>{let t=(null==ep?void 0:ep.id)===e.id,r=e.change24h,n=null==r?"--":"".concat(r>=0?"+":"").concat(r.toFixed(2),"%");return(0,i.jsxs)("button",{onClick:()=>eh(e),style:{flex:"0 0 auto",minWidth:"120px",padding:"0.75rem 1rem",borderRadius:"12px",border:"1px solid ".concat(t?"#a855f7":"rgba(255,255,255,0.08)"),background:t?"rgba(168,85,247,0.16)":"rgba(255,255,255,0.04)",color:"#fff",cursor:"pointer",textAlign:"left",transition:"all 0.2s ease"},children:[(0,i.jsx)("div",{style:{fontWeight:700,fontSize:"1rem"},children:e.base_currency}),(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:"0.5rem"},children:[(0,i.jsx)("div",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.55)"},children:e.id}),(0,i.jsx)("div",{style:{fontSize:"0.7rem",color:null==r?"rgba(255,255,255,0.55)":r>=0?"#4ade80":"#f87171",fontWeight:600},children:n})]})]},e.id)})})]}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"0.75rem"},children:[(0,i.jsx)("div",{style:{fontSize:"1.125rem",fontWeight:700,color:"#fff"},children:rD}),(0,i.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",color:"rgba(255,255,255,0.7)",fontSize:"0.875rem",cursor:"pointer"},children:[(0,i.jsx)("input",{type:"checkbox",checked:ev,onChange:e=>ew(e.target.checked),style:{cursor:"pointer"}}),"Pro mode"]})]}),eS&&(0,i.jsxs)("div",{style:{marginBottom:"1.5rem",padding:"1.25rem",border:"1px solid rgba(75, 85, 99, 0.4)",borderRadius:"0.75rem",background:"rgba(31, 41, 55, 0.6)"},children:[(0,i.jsx)("h3",{style:{fontSize:"1.125rem",fontWeight:600,color:"#f3f4f6",marginBottom:"1rem"},children:"Pair Info"}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"1rem",marginBottom:"1rem"},children:[(null===(P=eS.image)||void 0===P?void 0:P.small)&&(0,i.jsx)(l(),{src:eS.image.small,alt:eS.name,width:48,height:48,unoptimized:!0,style:{borderRadius:"50%",objectFit:"cover"}}),(0,i.jsxs)("div",{children:[(0,i.jsxs)("div",{style:{fontSize:"1rem",fontWeight:700,color:"#fff"},children:[eS.name," ",(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.5)"},children:["(",null===(T=eS.symbol)||void 0===T?void 0:T.toUpperCase(),")"]})]}
1),(null===(z=eS.links)||void 0===z?void 0:null===(R=z.homepage)||void 0===R?void 0:R[0])&&(0,i.jsx)("a",{href:eS.links.homepage[0],target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"#60a5fa",textDecoration:"none"},children:"Website"})]})]}),(null===(I=eS.description)||void 0===I?void 0:I.en)&&(0,i.jsx)("div",{style:{fontSize:"0.8rem",color:"rgba(255,255,255,0.7)",marginBottom:"1rem",maxHeight:"8rem",overflow:"auto"},children:eS.description.en}),(0,i.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.5rem"},children:[(null===(L=eS.links)||void 0===L?void 0:null===(D=L.homepage)||void 0===D?void 0:D[0])&&(0,i.jsx)("a",{href:eS.links.homepage[0],target:"_blank",rel:"noopener noreferrer",style:{padding:"0.375rem 0.75rem",borderRadius:"0.375rem",background:"rgba(59, 130, 246, 0.15)",color:"#93c5fd",fontSize:"0.75rem",textDecoration:"none"},children:"Website"}),(null===(A=eS.links)||void 0===A?void 0:A.twitter_screen_name)&&(0,i.jsx)("a",{href:"https://x.com/".concat(eS.links.twitter_screen_name),target:"_blank",rel:"noopener noreferrer",style:{padding:"0.375rem 0.75rem",borderRadius:"0.375rem",background:"rgba(59, 130, 246, 0.15)",color:"#93c5fd",fontSize:"0.75rem",textDecoration:"none"},children:"X / Twitter"}),(null===(F=eS.links)||void 0===F?void 0:F.telegram_channel_identifier)&&(0,i.jsx)("a",{href:"https://t.me/".concat(eS.links.telegram_channel_identifier),target:"_blank",rel:"noopener noreferrer",style:{padding:"0.375rem 0.75rem",borderRadius:"0.375rem",background:"rgba(59, 130, 246, 0.15)",color:"#93c5fd",fontSize:"0.75rem",textDecoration:"none"},children:"Telegram"}),(null===(N=eS.links)||void 0===N?void 0:N.subreddit_url)&&(0,i.jsx)("a",{href:eS.links.subreddit_url,target:"_blank",rel:"noopener noreferrer",style:{padding:"0.375rem 0.75rem",borderRadius:"0.375rem",background:"rgba(59, 130, 246, 0.15)",color:"#93c5fd",fontSize:"0.75rem",textDecoration:"none"},children:"Reddit"}),(null===(B=eS.links)||void 0===B?void 0:B.facebook_username)&&(0,i.jsx)("a",{href:"https://facebook.com/".concat(eS.links.facebook_username),target:"_blank",rel:"noopener noreferrer",style:{padding:"0.375rem 0.75rem",borderRadius:"0.375rem",background:"rgba(59, 130, 246, 0.15)",color:"#93c5fd",fontSize:"0.75rem",textDecoration:"none"},children:"Facebook"})]})]}),(0,i.jsx)("div",{style:{height:"calc(100vh - 60px)",minHeight:"1300px",borderRadius:"12px",background:"rgba(255,255,255,0.02)",border:"1px solid rgba(255,255,255,0.08)",overflow:"hidden"},children:eb?(0,i.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",color:"rgba(255,255,255,0.5)"},children:"Loading candles..."}):eg.length>=2?(0,i.jsx)(OpenChartsPro,{ohlc:eg,livePrice:ra,interval:rI,symbol:rE,pairName:rD,height:1300,chartTimeframe:em,onTimeframeChange:ey,proMode:ev,maxLeverage:50,showPositions:!1,positions:[],limitOrders:[],externalInputs:rA,indicatorScale:eT,onIndicatorScaleChange:eR,smaCount:eq,onSmaCountChange:eY,liqHeatmap:null,liqEvents:[],onOpenPosition:()=>{},onOpenSignalPosition:()=>{}}):(0,i.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",color:"rgba(255,255,255,0.5)"},children:"Failed to load candles"})}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 350px",gap:"24px",marginTop:"24px"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:600,color:"#fff",marginBottom:"12px"},children:"Order Book — ATOM/USDC"}),rR&&(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderRadius:"8px",background:"rgba(255,255,255,0.05)",marginBottom:"8px",fontSize:"12px"},children:[(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.6)"},children:"Spread"}),(0,i.jsxs)("span",{style:{color:"#fbbf24",fontWeight:600},children:[rR.value," (",rR.percent,"%)"]})]}),(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"#f87171",fontWeight:600,marginBottom:"6px",textTransform:"uppercase"},children:"Asks (Sell)"}),(0,i.jsx)("div",{style:{display:"grid",gap:"4px"},children:re.isLoading?(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"12px"},children:"Loading..."}):(null===(W=re.data)||void 0===W?void 0:W.length)?re.data.slice(0,10).reverse().map(e=>(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"8px",padding:"6px 10px",borderRadius:"6px",background:"rgba(248, 113, 113, 0.1)",fontSize:"12px"},children:[(0,i.jsx)("span",{style:{color:"#f87171",fontWeight:600},children:formatPrice(e.price)}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.8)"},children:formatQty(e.qty)}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:formatQty(e.qty_filled)})]},e.id)):(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"12px"},children:"No asks"})})]}),(0,i.jsxs)("div",{children:[(null===(O=t7.data)||void 0===O?void 0:O[0])&&(null===(V=re.data)||void 0===V?void 0:V[0])&&(0,i.jsxs)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.7)",marginBottom:"8px",textAlign:"center",padding:"4px",borderRadius:"4px",background:"rgba(255,255,255,0.05)"},children:["Mark Price: ",(0,i.jsx)("span",{style:{color:"#fff",fontWeight:600},children:formatPrice(String((Number(t7.data[0].price)+Number(re.data[0].price))/2))})]}),(0,i.jsx)("div",{style:{fontSize:"11px",color:"#4ade80",fontWeight:600,marginBottom:"6px",textTransform:"uppercase"},children:"Bids (Buy)"}),(0,i.jsx)("div",{style:{display:"grid",gap:"4px"},children:t7.isLoading?(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"12px"},children:"Loading..."}):(null===(U=t7.data)||void 0===U?void 0:U.length)?t7.data.slice(0,10).map(e=>(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"8px",padding:"6px 10px",borderRadius:"6px",background:"rgba(74, 222, 128, 0.1)",fontSize:"12px"},children:[(0,i.jsx)("span",{style:{color:"#4ade80",fontWeight:600},children:formatPrice(e.price)}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.8)"},children:formatQty(e.qty)}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:formatQty(e.qty_filled)})]},e.id)):(0,i.jsx)("div",{style:{color:"rgba(255,255,255,0.5)",fontSize:"12px"},children:"No bids"})})]})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:600,color:"#fff",marginBottom:"12px"},children:"Market Order"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",marginBottom:"16
1px"},children:[(0,i.jsx)("button",{onClick:()=>{e7("buy"),tt("")},style:{flex:1,padding:"10px",borderRadius:"8px",border:"buy"===e9?"1px solid rgba(74, 222, 128, 0.5)":"1px solid rgba(255,255,255,0.1)",background:"buy"===e9?"rgba(74, 222, 128, 0.2)":"rgba(255,255,255,0.05)",color:"buy"===e9?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"13px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:"Buy"}),(0,i.jsx)("button",{onClick:()=>{e7("sell"),tt("")},style:{flex:1,padding:"10px",borderRadius:"8px",border:"sell"===e9?"1px solid rgba(248, 113, 113, 0.5)":"1px solid rgba(255,255,255,0.1)",background:"sell"===e9?"rgba(248, 113, 113, 0.2)":"rgba(255,255,255,0.05)",color:"sell"===e9?"#f87171":"rgba(255,255,255,0.6)",fontSize:"13px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:"Sell"})]}),(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsxs)("label",{style:{display:"flex",justifyContent:"space-between",fontSize:"12px",color:"rgba(255,255,255,0.6)",marginBottom:"6px"},children:[(0,i.jsxs)("span",{children:["Amount (","buy"===e9?"USDC":"ATOM",")"]}),(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.4)",display:"flex",alignItems:"center",gap:"4px"}
1,children:["Price: ",rs>0?"$".concat(rs.toFixed(2)):"..."," | ",ri.isLoading||rn.isLoading?"...":(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{style:{color:"#fff",fontWeight:600},children:formatQty(ri.data||"0")}),(0,i.jsx)("span",{children:"ATOM"}),(0,i.jsx)("span",{children:" / "}),(0,i.jsx)("span",{style:{color:"#fff",fontWeight:600},children:(Number(rn.data||"0")/Math.pow(10,(null===(H=t9.data)||void 0===H?void 0:H.quote_decimals)||6)).toFixed(2)}),(0,i.jsx)("span",{children:"USDC"})]})]})]}),(0,i.jsx)("input",{type:"number",value:te,onChange:e=>tt(e.target.value),placeholder:"0.00",style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",outline:"none"}}),(0,i.jsx)("div",{style:{display:"flex",gap:"4px",marginTop:"6px"},children:[25,50,75,100].map(e=>(0,i.jsxs)("button",{onClick:()=>{var t,r;let i=(null===(t=t9.data)||void 0===t?void 0:t.base_decimals)||6,n=(null===(r=t9.data)||void 0===r?void 0:r.quote_decimals)||6,o=Number(ri.data||"0")/Math.pow(10,i),l=Number(rn.data||"0")/Math.pow(10,n),a=e/100;"buy"===e9?tt((l*a).toFixed(6)):tt((o*a).toFixed(6))},style:{flex:1,padding:"4px 0",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.04)",color:"rgba(255,255,255,0.5)",fontSize:"10px",fontWeight:600,cursor:"pointer",transition:"all 0.15s ease"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(255,255,255,0.1)",e.currentTarget.style.color="rgba(255,255,255,0.8)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(255,255,255,0.04)",e.currentTarget.style.color="rgba(255,255,255,0.5)"},children:[e,"%"]},e))})]}),(0,i.jsx)("button",{onClick:()=>rc(e9),disabled:tr||!te,style:{width:"100%",padding:"12px",borderRadius:"8px",border:"buy"===e9?"1px solid rgba(74, 222, 128, 0.5)":"1px solid rgba(248, 113, 113, 0.5)",background:"buy"===e9?"rgba(74, 222, 128, 0.2)":"rgba(248, 113, 113, 0.2)",color:"buy"===e9?"#4ade80":"#f87171",fontSize:"14px",fontWeight:700,cursor:tr||!te?"not-allowed":"pointer",opacity:tr||!te?.6:1,transition:"all 0.2s ease",marginBottom:"20px"},children:tr?"buy"===e9?"Buying...":"Selling...":"buy"===e9?"Buy":"Sell"}),tn&&(0,i.jsx)("div",{style:{marginBottom:"12px",padding:"8px 12px",borderRadius:"6px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"11px"},children:tn}),tl&&(0,i.jsxs)("div",{style:{marginBottom:"12px",padding:"8px 12px",borderRadius:"6px",background:"rgba(34, 197, 94, 0.1)",border:"1px solid rgba(34, 197, 94, 0.3)",color:"#86efac",fontSize:"11px"},children:["Market order placed: ",(0,i.jsxs)("a",{href:"https://www.mintscan.io/cosmos/txs/".concat(tl),target:"_blank",rel:"noopener noreferrer",style:{color:"#86efac",textDecoration:"underline"},children:[tl.slice(0,12),"..."]}),ts&&(0,i.jsxs)("div",{style:{marginTop:"8px",fontSize:"10px",color:"rgba(255,255,255,0.8)",lineHeight:1.5},children:[(0,i.jsxs)("div",{children:["Order ID: ",(0,i.jsx)("span",{style:{fontFamily:"monospace"},children:ts.orderId})]}),(0,i.jsxs)("div",{children:["Side: ",ts.side.toUpperCase()," | Price: $",formatPrice(ts.price)," | Qty: ",formatQty(ts.qty)," ATOM"]}),(0,i.jsxs)("div",{children:["Matched: ",formatQty(ts.matchedBase)," ATOM / $",formatQuoteQty(ts.matchedQuote)]})]})]}),(0,i.jsx)("div",{style:{marginBottom:"16px",borderBottom:"1px solid rgba(255,255,255,0.1)"}}),(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:600,color:"#fff",marginBottom:"12px"},children:"Place a single Limit Order"}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:[(0,i.jsx)("button",{onClick:()=>eG("buy"),style:{flex:1,padding:"10px",borderRadius:"8px",border:"buy"===eX?"1px solid rgba(74, 222, 128, 0.5)":"1px solid rgba(255,255,255,0.1)",background:"buy"===eX?"rgba(74, 222, 128, 0.2)":"rgba(255,255,255,0.05)",color:"buy"===eX?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"13px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:"Buy"}),(0,i.jsx)("button",{onClick:()=>eG("sell"),style:{flex:1,padding:"10px",borderRadius:"8px",border:"sell"===eX?"1px solid rgba(248, 113, 113, 0.5)":"1px solid rgba(255,255,255,0.1)",background:"sell"===eX?"rgba(248, 113, 113, 0.2)":"rgba(255,255,255,0.05)",color:"sell"===eX?"#f87171":"rgba(255,255,255,0.6)",fontSize:"13px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:"Sell"})]}),(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"12px",color:"rgba(255,255,255,0.6)",marginBottom:"6px"},children:"Price (USDC)"}),(0,i.jsx)("input",{type:"number",value:eJ,onChange:e=>eQ(e.target.value),placeholder:"0.00",style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",outline:"none"}})]}
1),(0,i.jsxs)("div",{style:{marginBottom:"16px"},children:[(0,i.jsxs)("label",{style:{display:"flex",justifyContent:"space-between",fontSize:"12px",color:"rgba(255,255,255,0.6)",marginBottom:"6px"},children:[(0,i.jsx)("span",{children:"Quantity (ATOM)"}),(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.4)"},children:["Balance: ",ri.isLoading?"...":formatQty(ri.data||"0")," ATOM"]})]}),(0,i.jsx)("input",{type:"number",value:e$,onChange:e=>eZ(e.target.value),placeholder:"0.00",style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"14px",outline:"none"}})]}),(0,i.jsx)("button",{onClick:rd,disabled:e0||!eJ||!e$||!es,style:{width:"100%",padding:"12px",borderRadius:"8px",border:"buy"===eX?"1px solid rgba(74, 222, 128, 0.4)":"1px solid rgba(248, 113, 113, 0.4)",background:"buy"===eX?"rgba(74, 222, 128, 0.2)":"rgba(248, 113, 113, 0.2)",color:"buy"===eX?"#4ade80":"#f87171",fontSize:"14px",fontWeight:600,cursor:!e0&&eJ&&e$&&es?"pointer":"not-allowed",opacity:!e0&&eJ&&e$&&es?1:.5,transition:"all 0.2s ease"},children:e0?"Placing...":"Place ".concat("buy"===eX?"Buy":"Sell"," Order")}),e1&&(0,i.jsx)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px"},children:e1}),e4&&(0,i.jsxs)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(34, 197, 94, 0.1)",border:"1px solid rgba(34, 197, 94, 0.3)",color:"#86efac",fontSize:"12px"},children:["✓ Order placed: ",e4,e8&&(0,i.jsxs)("div",{style:{marginTop:"8px",fontSize:"11px",color:"rgba(255,255,255,0.85)",lineHeight:1.5},children:[(0,i.jsxs)("div",{children:["Order ID: ",(0,i.jsx)("span",{style:{fontFamily:"monospace"},children:e8.orderId})]}),(0,i.jsxs)("div",{children:["Side: ",e8.side.toUpperCase()," | Price: $",formatPrice(e8.price)," | Qty: ",formatQty(e8.qty)," ATOM"]}),(0,i.jsxs)("div",{children:["Matched: ",formatQty(e8.matchedBase)," ATOM / $",formatQuoteQty(e8.matchedQuote)]})]})]}),(0,i.jsxs)("div",{style:{marginTop:"24px",paddingTop:"20px",borderTop:"1px solid rgba(255,255,255,0.1)"},children:[(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:600,color:"#fff",marginBottom:"12px"},children:"Grid Bot"}),(0,i.jsx)("div",{style:{marginBottom:"12px",fontSize:"11px",color:"rgba(255,255,255,0.5)",lineHeight:1.5},children:"Sells go above the current price; buys go below. Use the auto-fill buttons or enter bounds manually."}),(0,i.jsxs)("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:[(0,i.jsx)("button",{onClick:()=>tw("buy"),style:{flex:1,padding:"8px",borderRadius:"6px",border:"buy"===tv?"1px solid rgba(74, 222, 128, 0.5)":"1px solid rgba(255,255,255,0.1)",background:"buy"===tv?"rgba(74, 222, 128, 0.2)":"rgba(255,255,255,0.05)",color:"buy"===tv?"#4ade80":"rgba(255,255,255,0.6)",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:"Buy Grid"}),(0,i.jsx)("button",{onClick:()=>tw("sell"),style:{flex:1,padding:"8px",borderRadius:"6px",border:"sell"===tv?"1px solid rgba(248, 113, 113, 0.5)":"1px solid rgba(255,255,255,0.1)",background:"sell"===tv?"rgba(248, 113, 113, 0.2)":"rgba(255,255,255,0.05)",color:"sell"===tv?"#f87171":"rgba(255,255,255,0.6)",fontSize:"12px",fontWeight:600,cursor:"pointer"},children:"Sell Grid"})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",marginBottom:"8px"},children:[(0,i.jsx)("button",{onClick:()=>{rs>0&&tk((.95*rs).toFixed(6))},style:{padding:"8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(255,255,255,0.05)",color:"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",textAlign:"center"},children:"Lower = price −5%"}),(0,i.jsx)("button",{onClick:()=>{rs>0&&tC((1.05*rs).toFixed(6))},style:{padding:"8px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.1)",background:"rgba(255,255,255,0.05)",color:"rgba(255,255,255,0.6)",fontSize:"11px",fontWeight:600,cursor:"pointer",textAlign:"center"},children:"Upper = price +5%"})]}),(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",marginBottom:"12px"},children:[(0,i.jsx)("input",{type:"number",value:tS,onChange:e=>tk(e.target.value),placeholder:"Lower price",style:{width:"100%",padding:"8px 10px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"13px",outline:"none"}}),(0,i.jsx)("input",{type:"number",value:tj,onChange:e=>tC(e.target.value),placeholder:"Upper price",style:{width:"100%",padding:"8px 10px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"13px",outline:"none"}})]}),(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"4px"},children:[(0,i.jsx)("label",{style:{fontSize:"12px",color:"rgba(255,255,255,0.6)"},children:"Orders"}),(0,i.jsx)("span",{style:{fontSize:"12px",color:"#fff",fontWeight:600},children:t_})]}),(0,i.jsx)("input",{type:"range",min:2,max:20,step:1,value:t_,onChange:e=>tM(Number(e.target.value)),style:{width:"100%"}})]}),(0,i.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,i.jsxs)("label",{style:{display:"block",fontSize:"12px",color:"rgba(255,255,255,0.6)",marginBottom:"6px"},children:["Total ","sell"===tv?"ATOM":"USDC"]}
1),(0,i.jsx)("input",{type:"number",value:tP,onChange:e=>tT(e.target.value),placeholder:"0.00",style:{width:"100%",padding:"8px 10px",borderRadius:"6px",border:"1px solid rgba(255,255,255,0.2)",background:"rgba(255,255,255,0.05)",color:"#fff",fontSize:"13px",outline:"none"}})]}),tS&&tj&&tP&&(0,i.jsxs)("div",{style:{marginBottom:"12px",padding:"12px",borderRadius:"8px",background:"rgba(255,255,255,0.03)",border:"1px solid rgba(255,255,255,0.08)"},children:[(0,i.jsxs)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.6)",marginBottom:"8px",fontWeight:600},children:["Grid Preview (",t_," Orders)"]}),(0,i.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"4px",maxHeight:"200px",overflowY:"auto"},children:Array.from({length:t_}).map((e,t)=>{let r=Number(tS),n=Number(tj),o=(n-r)/(t_-1),l=r+o*t,a=Number(tP),s=a/t_;return(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",fontSize:"11px",padding:"6px",borderRadius:"4px",background:"rgba(255,255,255,0.02)"},children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Price:"}),(0,i.jsxs)("span",{style:{color:"#fff",marginLeft:"4px",fontWeight:600},children:["$",l.toFixed(6)]})]}),(0,i.jsxs)("div",{children:[(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Qty:"}),(0,i.jsxs)("span",{style:{color:"#fff",marginLeft:"4px",fontWeight:600},children:["sell"===tv?(s/l).toFixed(6):s.toFixed(6)," ","sell"===tv?"ATOM":"USDC"]})]})]},t)})})]}),(0,i.jsx)("button",{onClick:rh,disabled:tR||!tS||!tj||!tP||!es,style:{width:"100%",padding:"10px",borderRadius:"8px",border:"buy"===tv?"1px solid rgba(74, 222, 128, 0.4)":"1px solid rgba(248, 113, 113, 0.4)",background:"buy"===tv?"rgba(74, 222, 128, 0.2)":"rgba(248, 113, 113, 0.2)",color:"buy"===tv?"#4ade80":"#f87171",fontSize:"13px",fontWeight:600,cursor:!tR&&tS&&tj&&tP&&es?"pointer":"not-allowed",opacity:!tR&&tS&&tj&&tP&&es?1:.5,transition:"all 0.2s ease"},children:tR?"Placing Grid...":"Place ".concat(t_," ").concat("buy"===tv?"Buy":"Sell"," Orders")}),tI&&(0,i.jsx)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px"},children:tI}),tD&&(0,i.jsxs)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(34, 197, 94, 0.1)",border:"1px solid rgba(34, 197, 94, 0.3)",color:"#86efac",fontSize:"12px"},children:["✓ Grid placed in a single transaction:",(0,i.jsx)("div",{style:{marginTop:"4px",fontFamily:"monospace",wordBreak:"break-all"},children:tD})]})]})]})]}),eg.length>=2&&(0,i.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1.5rem"},children:[(0,i.jsxs)("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",alignItems:"center",background:"rgba(7, 11, 24, 0.72)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"8px",padding:"0.5rem 0.75rem",backdropFilter:"blur(6px)"},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[(0,i.jsx)("label",{style:{fontSize:"0.75rem",color:"rgba(255,255,255,0.6)",whiteSpace:"nowrap"},children:"Indicator Scale:"}),(0,i.jsx)("input",{type:"range",min:"0.5",max:"2",step:"0.1",value:eT,onChange:e=>eR(Number(e.target.value)),style:{width:"100px",cursor:"pointer"}}),(0,i.jsxs)("span",{style:{fontSize:"0.75rem",color:"#a78bfa",minWidth:"35px"},children:[eT.toFixed(1),"x"]})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:"0.25rem",alignItems:"center"},children:[(0,i.jsx)("label",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.5)"},children:"RSI:"}),(0,i.jsx)("input",{type:"number",min:"1",max:"50",value:ez,onChange:e=>eI(Number(e.target.value)),style:{width:"42px",padding:"0.25rem",fontSize:"0.7rem",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",color:"#fff"}})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:"0.25rem",alignItems:"center"},children:[(0,i.jsx)("label",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.5)"},children:"Stoch:"}),(0,i.jsx)("input",{type:"number",min:"1",max:"50",value:eE,onChange:e=>eD(Number(e.target.value)),style:{width:"38px",padding:"0.25rem",fontSize:"0.7rem",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",color:"#fff"},title:"Period"}),(0,i.jsx)("input",{type:"number",min:"1",max:"20",value:eL,onChange:e=>eA(Number(e.target.value)),style:{width:"38px",padding:"0.25rem",fontSize:"0.7rem",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",color:"#fff"},title:"K Smooth"}),(0,i.jsx)("input",{type:"number",min:"1",max:"20",value:eF,onChange:e=>eN(Number(e.target.value)),style:{width:"38px",padding:"0.25rem",fontSize:"0.7rem",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",color:"#fff"},title:"D Smooth"})]}),(0,i.jsxs)("div",{style:{display:"flex",gap:"0.25rem",alignItems:"center"},children:[(0,i.jsx)("label",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.5)"},children:"MACD:"}),(0,i.jsx)("input",{type:"number",min:"1",max:"30",value:eB,onChange:e=>eW(Number(e.target.value)),style:{width:"38px",padding:"0.25rem",fontSize:"0.7rem",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",color:"#fff"},title:"Fast"}),(0,i.jsx)("span",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.4)"},children:"/"}),(0,i.jsx)("input",{type:"number",min:"1",max:"50",value:eO,onCh
1ange:e=>eV(Number(e.target.value)),style:{width:"38px",padding:"0.25rem",fontSize:"0.7rem",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",color:"#fff"},title:"Slow"}),(0,i.jsx)("span",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.4)"},children:"/"}),(0,i.jsx)("input",{type:"number",min:"1",max:"20",value:eU,onChange:e=>eH(Number(e.target.value)),style:{width:"38px",padding:"0.25rem",fontSize:"0.7rem",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",color:"#fff"},title:"Signal"})]}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[(0,i.jsx)("label",{style:{fontSize:"0.7rem",color:"rgba(255,255,255,0.5)"},children:"Rainbow SMA:"}),(0,i.jsx)("input",{type:"range",min:"0",max:"9",step:"1",value:eq,onChange:e=>eY(Number(e.target.value)),style:{width:"80px",cursor:"pointer"}}),(0,i.jsx)("span",{style:{fontSize:"0.7rem",color:"#a78bfa",minWidth:"20px"},children:eq})]})]}),rN&&(0,i.jsxs)("div",{style:{borderRadius:"0.75rem",overflow:"hidden",border:"1px solid rgba(75, 85, 99, 0.4)",padding:"1rem",background:"rgba(31, 41, 55, 0.6)"},children:[(0,i.jsx)("div",{style:{fontSize:"0.875rem",fontWeight:600,color:"#fbbf24",marginBottom:"0.75rem"},children:"RSI / Stochastic RSI"}),(0,i.jsx)("div",{style:{height:"220px"},children:(0,i.jsx)(E.kL,{type:"line",data:rN,options:rW})})]}),rB&&(0,i.jsxs)("div",{style:{borderRadius:"0.75rem",overflow:"hidden",border:"1px solid rgba(75, 85, 99, 0.4)",padding:"1rem",background:"rgba(31, 41, 55, 0.6)"},children:[(0,i.jsx)("div",{style:{fontSize:"0.875rem",fontWeight:600,color:"#60a5fa",marginBottom:"0.75rem"},children:"MACD"}),(0,i.jsx)("div",{style:{height:"220px"},children:(0,i.jsx)(E.kL,{type:"line",data:rB,options:rO})})]})]}),(0,i.jsxs)("div",{style:{marginTop:"24px",paddingTop:"20px",borderTop:"1px solid rgba(255,255,255,0.1)"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:600,color:"#fff"},children:"AI Market Analysis"}),(0,i.jsx)("button",{onClick:rL,disabled:tH||eg.length<2,style:{padding:"8px 16px",borderRadius:"8px",border:"1px solid rgba(168, 85, 247, 0.4)",background:tH?"rgba(168, 85, 247, 0.1)":"rgba(168, 85, 247, 0.2)",color:"#c4b5fd",fontSize:"12px",fontWeight:600,cursor:tH||eg.length<2?"not-allowed":"pointer",opacity:tH||eg.length<2?.6:1,transition:"all 0.2s ease"},children:tH?"Analyzing...":"Analyze with AI"})]}),tY&&(0,i.jsx)("div",{style:{padding:"10px",borderRadius:"8px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px"},children:tY}),tV&&(0,i.jsx)("div",{style:{padding:"14px",borderRadius:"10px",background:"rgba(168, 85, 247, 0.08)",border:"1px solid rgba(168, 85, 247, 0.25)",color:"rgba(255,255,255,0.85)",fontSize:"13px",lineHeight:1.7,whiteSpace:"pre-wrap"},children:tV})]}),es&&rt.data&&rt.data.length>0&&(0,i.jsxs)("div",{style:{marginTop:"24px",paddingTop:"20px",borderTop:"1px solid rgba(255,255,255,0.1)"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:600,color:"#fff"},children:"Your Open Orders"}),(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[(0,i.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",color:"rgba(255,255,255,0.6)",cursor:"pointer"},children:[(0,i.jsx)("input",{type:"checkbox",checked:tW,onChange:e=>tO(e.target.checked),style:{cursor:"pointer"}}),"Hide filled"]}),(0,i.jsx)("button",{onClick:rp,disabled:tg||!(null===(q=rt.data)||void 0===q?void 0:q.some(e=>"open"===e.status||"partially_filled"===e.status)),style:{padding:"6px 12px",borderRadius:"6px",border:"1px solid rgba(239, 68, 68, 0.4)",background:"rgba(239, 68, 68, 0.15)",color:"#fca5a5",fontSize:"12px",fontWeight:600,cursor:tg?"not-allowed":"pointer",opacity:tg?.6:1,transition:"all 0.2s ease"},children:tg?"Cancelling...":"Cancel All"})]})]}),(0,i.jsx)("div",{style:{display:"grid",gap:"8px"},children:rt.data.filter(e=>!tW||"filled"!==e.status).map(e=>(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"auto auto 1fr 1fr 1fr auto auto",gap:"12px",alignItems:"center",padding:"12px",borderRadius:"10px",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.08)"},children:[(0,i.jsx)("span",{style:{padding:"4px 8px",borderRadius:"999px",fontSize:"11px",fontWeight:600,background:"buy"===e.side?"rgba(34, 197, 94, 0.2)":"rgba(239, 68, 68, 0.2)",color:"buy"===e.side?"#4ade80":"#f87171"},children:e.side.toUpperCase()}),(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.6)",fontSize:"12px"},children:["#",e.id]}),(0,i.jsx)("span",{style:{color:"#fff",fontSize:"13px",fontWeight:600},children:formatPrice(e.price)}),(0,i.jsx)("span",{style:{color:"rgba(255,255,255,0.8)",fontSize:"13px"},children:formatQty(e.qty)}),(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.5)",fontSize:"12px"},children:[formatQty(e.qty_filled)," filled"]}),(0,i.jsx)("span",{style:{padding:"4px 8px",borderRadius:"999px",fontSize:"11px",fontWeight:600,background:"open"===e.status?"rgba(34, 197, 94, 0.2)":"rgba(234, 179, 8, 0.2)",color:"open"===e.status?"#4ade80":"#fbbf24"},children:e.status}),"open"===e.status||"partially_filled"===e.status?(0,i.jsx)("button",{onClick:()=>ru(e.id),disabled:tc===e.id,style:{padding:"6px 12px",borderRadius:"8px",border:"1px solid rgba(239, 68, 68, 0.4)",background:"rgba(239, 68, 68, 0.15)",color:"#fca5a5",fontSize:"11px",fontWeight:600,cursor:tc===e.id?"not-allowed":"pointer",opacity:tc===e.id?.6:1,transition:"all 0.2s ease",whiteSpace:"nowrap"},children:tc===e.id?"Cancelling...":"Cancel"}):(0,i.jsx)("span",{})]},e.id))}),tp&&(0,i.jsx)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px"},children:tp}),tb&&(0,i.jsx)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px"},children:tb})]}),es&&(0,i.jsxs)("div",{style:{marginTop:"24px",paddingTop:"20px",borderTop:"1px solid rgba(255,255,255,0.1)"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[(0,i.jsx)("div",{style:{fontSize:"14px",fontWeight:600,color:"#fff"},children:"OTC Offers — ATOM / USDC"}),(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.4)"},children:"Powered by Escrow"})]}),rS.isLoading?(0,i.jsx)("div",{style:{padding:"16px",textAlign:"center",color:"rgba(255,255,255,0.5)",fontSize:"13px"},children:"Loading offers..."}):0===rP.length?(0,i.jsx)("div",{style:{padding:"16px",textAlign:"center",color:"rgba(255,255,255,0.4)",fontSize:"13px"},children:"No active OTC offers for ATOM/USDC"}):(0,i.jsx)("div",{style:{display:"grid",gap:"8px"},children:rP.map(e=>{let t=(e.offer_denom,$.KB.ATOM,6),r=(e.ask_denom,$.KB.ATOM,6),n=Number(e.offer_amount)/Math.pow(10,t),o=Number(e.ask_amount)/Math.pow(10,r),l=n>0?o/n:0,a=e.offer_denom===$.KB.ATOM,s=(0,$.yf)(e.offer_denom),d=(0,$.yf)(e.ask_denom),c=rs>0?rs:null,u=a?c:1,p=a?1:c,h=u&&p&&p>0?u/p:null,g=h&&l>0?(l-h)/h*100:null,x=null!==g?"".concat(g>0?"+":"").concat(g.toFixed(2),"% ").concat(0===g?"at market":g>0?"above market":"below market"):null,b=null!==g?g>0?"#f97316":"#22c55e":"rgba(255,255,255,0.5)";return(0,i.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr 1fr 1fr 1fr auto",gap:"12px",alignItems:"center",padding:"12px",borderRadius:"10px",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.08)"},children:[(0,i.jsx)("span",{style:{padding:"4px 8px",borderRadius:"999px",fontSize:"11px",fontWeight:600,background:a?"rgba(168, 85, 247, 0.2)":"rgba(34, 197, 94, 0.2)",color:a?"#c084fc":"#4ade80"},children:a?"ATOM → USDC":"USDC → ATOM"}),(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.6)",fontSize:"12px",fontFamily:"monospace"},children:["#",e.vault_id.slice(0,8)]}),(0,i.jsxs)("span",{style:{color:"#fff",fontSize:"13px",fontWeight:600},children:["Receive ",(0,$.dN)(e.offer_amount,e.offer_denom)," ",s]}),(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.8)",fontSize:"13px"}
1,children:["for ",(0,$.dN)(e.ask_amount,e.ask_denom)," ",d]}),(0,i.jsxs)("span",{style:{color:"rgba(255,255,255,0.5)",fontSize:"12px",display:"flex",flexDirection:"column",gap:"2px"},children:[(0,i.jsxs)("span",{children:["rate ",(o>0?n/o:0).toFixed(6)]}),x&&(0,i.jsx)("span",{style:{color:b,fontWeight:600},children:x})]}),(0,i.jsx)("button",{onClick:()=>rT(e),disabled:rj===e.vault_id,style:{padding:"6px 12px",borderRadius:"8px",border:"1px solid rgba(59, 130, 246, 0.4)",background:"rgba(59, 130, 246, 0.15)",color:"#93c5fd",fontSize:"11px",fontWeight:600,cursor:rj===e.vault_id?"not-allowed":"pointer",opacity:rj===e.vault_id?.6:1,transition:"all 0.2s ease",whiteSpace:"nowrap"},children:rj===e.vault_id?"Taking...":"Take"})]},e.vault_id)})}),r_&&(0,i.jsx)("div",{style:{marginTop:"12px",padding:"10px",borderRadius:"8px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px"},children:r_})]}),tX&&(0,i.jsx)("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0, 0, 0, 0.7)",backdropFilter:"blur(4px)",zIndex:100,display:"flex",alignItems:"center",justifyContent:"center",padding:"24px"},onClick:e=>{e.target===e.currentTarget&&tG(!1)},children:(0,i.jsxs)("div",{style:{width:"100%",maxWidth:"460px",padding:"24px",borderRadius:"16px",background:"rgba(13, 17, 35, 0.95)",border:"1px solid rgba(255,255,255,0.1)"},children:[(0,i.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[(0,i.jsx)("div",{style:{fontSize:"18px",fontWeight:700,color:"#fff"},children:"Deposit USDC"}),(0,i.jsx)("button",{onClick:()=>tG(!1),style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",fontSize:"20px",cursor:"pointer"},children:"\xd7"})]}),(0,i.jsx)("div",{style:{fontSize:"13px",color:"rgba(255,255,255,0.6)",marginBottom:"16px"},children:"Bridge USDC from another chain to Cosmos Hub for trading."}),(0,i.jsx)("div",{style:{display:"flex",gap:"8px",marginBottom:"20px"},children:[{key:"noble",label:"Noble",color:"#60a5fa"},{key:"osmosis",label:"Osmosis",color:"#c084fc"},{key:"injective",label:"Injective",color:"#f87171"}].map(e=>(0,i.jsx)("button",{onClick:()=>tZ(e.key),style:{flex:1,padding:"10px",borderRadius:"10px",border:t$===e.key?"1p
1x solid ".concat(e.color):"1px solid rgba(255,255,255,0.1)",background:t$===e.key?"".concat(e.color,"20"):"rgba(255,255,255,0.03)",color:t$===e.key?e.color:"rgba(255,255,255,0.6)",fontSize:"13px",fontWeight:600,cursor:"pointer",transition:"all 0.2s ease"},children:e.label},e.key))}),(0,i.jsxs)("div",{style:{marginBottom:"16px",padding:"12px",borderRadius:"10px",background:"rgba(255,255,255,0.03)",border:"1px solid rgba(255,255,255,0.08)"},children:[(0,i.jsx)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.5)",marginBottom:"4px"},children:"injective"===t$?"Your Injective Address":"Derived ".concat(t$.charAt(0).toUpperCase()+t$.slice(1)," Address")}),"injective"===t$?(0,i.jsx)("input",{type:"text",value:t0,onChange:e=>t5(e.target.value),placeholder:"0x... or inj1...",style:{width:"100%",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"8px",padding:"8px 12px",color:"#fff",fontSize:"13px",fontFamily:"monospace",outline:"none"}}):(0,i.jsx)("div",{style:{fontSize:"13px",color:"#fff",fontFamily:"monospace",wordBreak:"break-all"},children:rf[t$]||"—"})]}),(0,i.jsxs)("div",{style:{marginBottom:"20px",padding:"12px",borderRadius:"10px",background:"rgba(255,255,255,0.03)",border:"1px solid rgba(255,255,255,0.08)"},children:[(0,i.jsxs)("div",{style:{fontSize:"11px",color:"rgba(255,255,255,0.5)",marginBottom:"4px"},children:["USDC Balance on ",t$.charAt(0).toUpperCase()+t$.slice(1)]}),(0,i.jsxs)("div",{style:{fontSize:"20px",fontWeight:700,color:"#fff"},children:["osmosis"===t$&&(rm.isLoading?"...":rm.data?formatQuoteQty(rm.data):"0"),"noble"===t$&&(ry.isLoading?"...":ry.data?formatQuoteQty(ry.data):"0"),"injective"===t$&&(rv.isLoading?"...":rv.data?formatQuoteQty(rv.data):"0")]}),(0,i.jsxs)("div",{style:{fontSize:"9px",color:"rgba(255,255,255,0.3)",marginTop:"8px",fontFamily:"monospace"},children:["osmosis"===t$&&rm.isError&&(0,i.jsxs)("div",{children:["Error: ",null===(Z=rm.error)||void 0===Z?void 0:Z.message]}),"noble"===t$&&ry.isError&&(0,i.jsxs)("div",{children:["Error: ",null===(ei=ry.error)||void 0===ei?void 0:ei.message]}),"injective"===t$&&rv.isError&&(0,i.jsxs)("div",{children:["Error: ",null===(en=rv.error)||void 0===en?void 0:en.message]})]})]}),(0,i.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,i.jsx)("label",{style:{display:"block",fontSize:"11px",color:"rgba(255,255,255,0.5)",marginBottom:"6px"},children:"Amount to Deposit (USDC)"}),(0,i.jsx)("input",{type:"number",value:tJ,onChange:e=>tQ(e.target.value),placeholder:"0.00",min:"0",step:"0.01",style:{width:"100%",padding:"12px",borderRadius:"10px",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",color:"#fff",fontSize:"15px",outline:"none"}})]}),t4&&(0,i.jsx)("div",{style:{marginBottom:"16px",padding:"10px",borderRadius:"8px",background:"rgba(239, 68, 68, 0.1)",border:"1px solid rgba(239, 68, 68, 0.3)",color:"#fca5a5",fontSize:"12px"},children:t4}),(0,i.jsx)("button",{onClick:rw,disabled:t1||!tJ,style:{width:"100%",padding:"14px",borderRadius:"10px",border:"none",background:t1||!tJ?"rgba(255,255,255,0.1)":"linear-gradient(135deg, #22c55e, #16a34a)",color:"#fff",fontSize:"15px",fontWeight:700,cursor:t1||!tJ?"not-allowed":"pointer",opacity:t1||!tJ?.6:1,transition:"all 0.2s ease"},children:t1?"Building Route...":"Deposit"}),(0,i.jsx)("div",{style:{marginTop:"12px",fontSize:"11px",color:"rgba(255,255,255,0.4)",textAlign:"center"},children:"Powered by Skip API"})]})})]})}},19539:function(e,t,r){r.d(t,{D1:function(){return b},KL:function(){return x},Kc:function(){return calculatePositionSize},LV:function(){return leverageToSlider},Ln:function(){return m},Ly:function(){return g},Q0:function(){return s},Rt:function(){return u},Sd:function(){return formatPerpQuote},Ug:function(){return h},a1:function(){return d},ah:function(){return leverageColorRgba},cM:function(){return p},f:function(){return n},gi:function(){return f},gr:function(){return leverageColor},jO:function(){return calculateLiquidationPrice},n3:function(){return c},ph:function(){return sliderToLeverage},ql:function(){return calculateNotional},r2:function(){return a},uU:function(){return l},xR:function(){return o}});var i=r(14224);let n=i.env.NEXT_PUBLIC_PERP_MARKET_CONTRACT||"";i.env.NEXT_PUBLIC_PERP_FACTORY_CONTRACT,i.env.NEXT_PUBLIC_PERP_POSITION_TOKEN_CONTRACT;let o="erc20:0x0C382e685bbeeFE5d3d9C29e29E341fEE8E84C5d",l="BTC",a=6,s=1,d=200,c=10,u=.005,p="BTC",h="USDC",g="".concat(p,"/").concat(h),x="bitcoin",b="BTCUSDT",f={bitcoin:"bitcoin",ethereum:"ethereum",cosmos:"cosmos",atom:"cosmos",btc:"bitcoin",eth:"ethereum"},m={"0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b":{pair:"BTC/USD",coingeckoId:"bitcoin",symbol:"BTC"},"0x61226d39beea19d334f17c2febce27e12646d84675924ebb02b9cdaea68727e3":{pair:"ATOM/USD",coingeckoId:"cosmos",symbol:"ATOM"}},formatPerpQuote=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a,r=Number(e);return(r/Math.pow(10,t)).toFixed(t)},calculateLiquidationPrice=function(e,t,r){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:u;return"long"===r?e*(1-1/t+i):e*(1+1/t-i)},calculateNotional=(e,t)=>e*t,calculatePositionSize=(e,t)=>
1!t||t<=0?0:e/t,leverageColor=e=>{let t=Math.min(1,Math.max(0,(e-s)/(d-s)));return"rgb(".concat(Math.round(34+205*t),", ").concat(Math.round(197+-129*t),", ").concat(Math.round(94+-26*t),")")},leverageColorRgba=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=Math.min(1,Math.max(0,(e-s)/(d-s)));return"rgba(".concat(Math.round(34+205*r),", ").concat(Math.round(197+-129*r),", ").concat(Math.round(94+-26*r),", ").concat(t,")")},sliderToLeverage=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:d,i=Math.min(1,Math.max(0,e));return r<=10*t?Math.round(t+(r-t)*i):Math.round(t+(r-t)*Math.pow(i,Math.log((r/10-t)/(r-t))/Math.log(.5)))},leverageToSlider=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:d,i=Math.min(r,Math.max(t,e));return r<=10*t?(i-t)/(r-t):Math.pow((i-t)/(r-t),1/(Math.log((r/10-t)/(r-t))/Math.log(.5)))}}}]);

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.