1import{o as ge}from"./rolldown-runtime-ChpBd9eV.js";import{Cn as be,Ka as fe,P as ve,Pa as we,Tt as ye,Yt as q,_n as ee,ba as A,bt as Q,cn as je,ct as Ne,mt as ke,pn as re,rn as K,tt as Re,un as Ce,ut as Se,wa as le,wn as Me}from"./chat-page-C-flp553.js";import{Gn as Fe,fr as p}from"./community-page-dub7UFXa.js";import{It as te}from"./education-page-Buqr-MLV.js";import{Q as Le,U as se}from"./icons-vendor-DpKLKbbD.js";import{a as Ve,c as $e,f as Pe,g as De,i as Te,l as We,m as Ae,p as Ee,u as Be}from"./chartjs-vendor-CJ58C3gX.js";import{a as Ie,o as _e}from"./trading-charts-uBzRtfFs.js";var j=ge(fe(),1),e=we();Ve.register(Pe,Be,$e,Ee,De,Ae,Te,We);var T=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(s||0),W=(s,C=2)=>Number.isFinite(s)?s.toFixed(C):"0.00",H=s=>`${W(s,1)}%`,V=s=>s?s instanceof Date?s:typeof s?.toDate=="function"?s.toDate():new Date(s):new Date,ae=({title:s,icon:C,children:N,defaultExpanded:v=!0,badge:$,gradient:S="from-blue-600/20 to-indigo-600/20"})=>{const[d,P]=(0,j.useState)(v);return(0,e.jsxs)("div",{className:`bg-gradient-to-br ${S} rounded-2xl border border-slate-700/40 overflow-hidden`,children:[(0,e.jsxs)("button",{onClick:()=>P(!d),className:"w-full p-4 flex items-center justify-between hover:bg-white/5 transition",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[C&&(0,e.jsx)("div",{className:"p-1.5 bg-white/10 rounded-lg flex-shrink-0",children:(0,e.jsx)(C,{className:"w-4 h-4 text-white/80"})}),(0,e.jsx)("span",{className:"font-bold text-white",children:s}),$&&(0,e.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs bg-white/15 text-white/90 font-semibold",children:$})]}),(0,e.jsx)(je,{className:`w-4 h-4 text-white/50 transition-transform ${d?"rotate-180":""}`})]}),(0,e.jsx)(le,{initial:!1,children:d&&(0,e.jsx)(A.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:"easeInOut"},children:(0,e.jsx)("div",{className:"px-4 pb-4 pt-0 border-t border-white/10",children:N})})})]})},ze=({data:s,color:C="#3b82f6",width:N=80,height:v=28})=>{if(!s||s.length<2)return null;const $=Math.min(...s),S=Math.max(...s)-$||1;return(0,e.jsx)("svg",{width:N,height:v,className:"inline-block",children:(0,e.jsx)("polyline",{fill:"none",stroke:C,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",points:s.map((d,P)=>`${P/(s.length-1)*N},${v-(d-$)/S*(v-4)-2}`).join(" ")})})},He=({metric:s,onDelete:C,onViewHistory:N,onEdit:v,sparklineData:$})=>{const S=s.benchmark?s.currentValue>=s.benchmark:s.currentValue>0,d=s.benchmark?(s.currentValue/s.benchmark-1)*100:null,P={Performance:{bg:"bg-blue-500/15",text:"text-blue-400",border:"border-blue-500/30",spark:"#3b82f6"},Risk:{bg:"bg-amber-500/15",text:"text-amber-400",border:"border-amber-500/30",spark:"#f59e0b"},Discipline:{bg:"bg-purple-500/15",text:"text-purple-400",border:"border-purple-500/30",spark:"#a855f7"},Strategy:{bg:"bg-emerald-500/15",text:"text-emerald-400",border:"border-emerald-500/30",spark:"#10b981"},Custom:{bg:"bg-slate-600/30",text:"text-slate-300",border:"border-slate-600/30",spark:"#94a3b8"}},E=P[s.category]||P.Custom;return(0,e.jsxs)(A.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`relative bg-slate-900/60 rounded-2xl p-5 border transition-all hover:brightness-105 group ${s.error?"border-red-500/30 hover:border-red-500/50":"border-slate-700/40 hover:border-blue-500/40"}`,children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,e.jsx)("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-md uppercase tracking-wider ${E.bg} ${E.text}`,children:s.category}),$&&(0,e.jsx)(ze,{data:$,color:E.spark})]}),(0,e.jsxs)("div",{className:"mb-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[s.isBuiltIn&&(0,e.jsx)(Se,{className:"w-3.5 h-3.5 text-amber-400"}),(0,e.jsx)("h4",{className:"font-semibold text-white text-sm",children:s.name})]}),s.description&&(0,e.jsx)("p",{className:"text-[11px] text-slate-400 mt-0.5 line-clamp-1",children:s.description})]}),s.error?(0,e.jsxs)("div",{className:"flex items-center gap-2 text-red-400 mb-3",children:[(0,e.jsx)(q,{className:"w-5 h-5"}),(0,e.jsx)("span",{className:"text-sm",children:"Calculation Error"})]}):(0,e.jsxs)("div",{className:"mb-3",children:[(0,e.jsx)("div",{className:`text-2xl font-black ${S?"text-emerald-400":"text-red-400"}`,children:s.format==="currency"?T(s.currentValue):s.format==="percent"?H(s.currentValue):W(s.currentValue)}),d!==null&&(0,e.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[d>=0?(0,e.jsx)(be,{className:"w-3.5 h-3.5 text-emerald-400"}):(0,e.jsx)(Me,{className:"w-3.5 h-3.5 text-red-400"}),(0,e.jsxs)("span",{className:`text-xs font-medium ${d>=0?"text-emerald-400":"text-red-400"}`,children:[d>0?"+":"",d.toFixed(1),"% vs target"]})]})]}),s.benchmark&&!s.error&&(0,e.jsxs)("div",{className:"mb-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between text-[10px] text-slate-500 mb-1",children:[(0,e.jsx)("span",{children:"Progress to target"}),(0,e.jsx)("span",{className:"text-blue-400 font-medium",children:s.format==="currency"?T(s.benchmark):s.format==="percent"?H(s.benchmark):W(s.benchmark)})]}),(0,e.jsx)("div",{className:"h-1.5 bg-slate-700/50 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:`h-full rounded-full transition-all ${S?"bg-emerald-500":"bg-amber-500"}`,style:{width:`${Math.min(Math.max(s.currentValue/s.benchmark*100,0),100)}%`}})})]}),(0,e.jsxs)("div",{className:"flex gap-2 pt-3 border-t border-slate-700/30",children:[(0,e.jsxs)("button",{onClick:()=>N(s),className:"flex-1 flex items-center justify-center gap-1 px-3 py-1.5 bg-slate-700/40 hover:bg-slate-600/50 text-blue-400 rounded-lg text-xs font-medium transition",children:[(0,e.jsx)(re,{className:"w-3.5 h-3.5"}),"Trend"]}),!s.isBuiltIn&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{onClick:()=>v(s),className:"p-1.5 bg-slate-700/40 hover:bg-slate-600/50 text-slate-300 rounded-lg transition",children:(0,e.jsx)(ye,{className:"w-3.5 h-3.5"})}),(0,e.jsx)("button",{onClick:()=>C(s.id),className:"p-1.5 bg-slate-700/40 hover:bg-red-500/20 text-slate-300 hover:text-red-400 rounded-lg transition",children:(0,e.jsx)(Ne,{className:"w-3.5 h-3.5"})})]})]})]})},Oe=({template:s,onApply:C})=>(0,e.jsxs)(A.button,{onClick:()=>C(s),className:"group relative bg-slate-800/50 p-4 rounded-xl text-left border border-slate-700/50 hover:border-blue-500/50 transition-all",whileHover:{scale:1.02,y:-2},whileTap:{scale:.98},children:[(0,e.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,e.jsx)("h4",{className:"font-semibold text-white group-hover:text-blue-400 transition",children:s.name}),(0,e.jsx)("span",{className:`text-xs px-2 py-0.5 rounded ${s.category==="Performance"?"bg-blue-500/20 text-blue-400":s.category==="Risk"?"bg-amber-500/20 text-amber-400":s.category==="Discipline"?"bg-purple-500/20 text-purple-400":"bg-emerald-500/20 text-emerald-400"}`,children:s.category})]}),(0,e.jsx)("p",{className:"text-xs text-slate-400 mb-3",children:s.description}),(0,e.jsxs)("div",{className:"flex items-center gap-2 text-xs text-blue-400 opacity-0 group-hover:opacity-100 transition",children:[(0,e.jsx)(Q,{className:"w-4 h-4"}),"Use Template"]})]}),Ye=["All","Performance","Risk","Discipline","Strategy","Custom"],Ze=({trades:s=[],user:C=null})=>
1{const[N,v]=(0,j.useState)("dashboard"),[$,S]=(0,j.useState)(!1),[d,P]=(0,j.useState)(null),[E,ne]=(0,j.useState)(null),[B,ie]=(0,j.useState)("All"),[u,M]=(0,j.useState)({name:"",description:"",category:"Custom",type:"simple",field1:"pl",operation:"sum",condition:"all",conditionValue:"",field2:"",operation2:"count",condition2:"all",conditionValue2:"",benchmark:"",format:"number"}),[O,J]=(0,j.useState)([{id:"win-rate",name:"Win Rate",description:"Percentage of profitable trades",category:"Performance",formula:"wins / total * 100",benchmark:50,format:"percent",isBuiltIn:!0},{id:"profit-factor",name:"Profit Factor",description:"Gross profit divided by gross loss",category:"Risk",formula:"grossProfit / grossLoss",benchmark:1.5,format:"number",isBuiltIn:!0},{id:"avg-winner",name:"Average Winner",description:"Average profit on winning trades",category:"Performance",formula:"avgPL where pl > 0",benchmark:200,format:"currency",isBuiltIn:!0},{id:"avg-loser",name:"Average Loser",description:"Average loss on losing trades",category:"Performance",formula:"avgPL where pl < 0",benchmark:-100,format:"currency",isBuiltIn:!0},{id:"risk-reward",name:"Risk/Reward Ratio",description:"Average win size vs average loss size",category:"Risk",formula:"avgWin / avgLoss",benchmark:2,format:"number",isBuiltIn:!0},{id:"expectancy",name:"Expectancy",description:"Expected value per trade",category:"Performance",formula:"(winRate * avgWin) - (lossRate * avgLoss)",benchmark:50,format:"currency",isBuiltIn:!0},{id:"rule-following",name:"Rule Following",description:"Percentage of trades following rules",category:"Discipline",formula:"count where followedRules / total * 100",benchmark:90,format:"percent",isBuiltIn:!0},{id:"stop-loss-usage",name:"Stop Loss Usage",description:"Percentage of trades with stop-loss set",category:"Discipline",formula:"count where hasStopLoss / total * 100",benchmark:100,format:"percent",isBuiltIn:!0},{id:"max-drawdown",name:"Max Drawdown",description:"Largest peak-to-trough decline",category:"Risk",formula:"maxDrawdown",benchmark:-500,format:"currency",isBuiltIn:!0},{id:"avg-hold-time",name:"Avg Trades/Day",description:"Average number of trades per day",category:"Performance",formula:"trades / tradingDays",benchmark:3,format:"number",isBuiltIn:!0},{id:"consecutive-wins",name:"Win Streak",description:"Maximum consecutive winning trades",category:"Performance",formula:"maxWinStreak",benchmark:5,format:"number",isBuiltIn:!0},{id:"consecutive-losses",name:"Loss Streak",description:"Maximum consecutive losing trades",category:"Risk",formula:"maxLossStreak",benchmark:-3,format:"number",isBuiltIn:!0}]),oe=[{name:"Setup Win Rate",description:"Win rate for a specific setup type",category:"Strategy",config:{type:"conditional",field1:"pl",operation:"winRate",condition:"setup",format:"percent"}},{name:"Best Day of Week",description:"P/L by day of week analysis",category:"Performance",config:{type:"conditional",field1:"pl",operation:"sum",condition:"dayOfWeek",format:"currency"}},{name:"Largest Winner",description:"Your biggest winning trade",category:"Performance",config:{type:"simple",field1:"pl",operation:"max",format:"currency"}},{name:"Largest Loser",description:"Your biggest losing trade",category:"Risk",config:{type:"simple",field1:"pl",operation:"min",format:"currency"}},{name:"Recovery Factor",description:"Net profit divided by max drawdown",category:"Risk",config:{type:"ratio",field1:"netProfit",field2:"maxDrawdown",format:"number"}},{name:"Long vs Short P/L",description:"Performance difference by direction",category:"Strategy",config:{type:"comparison",field1:"pl",condition:"direction",format:"currency"}},{name:"Morning Win Rate",description:"Win rate for trades before noon",category:"Strategy",config:{type:"conditional",field1:"pl",operation:"winRate",condition:"morning",format:"percent"}},{name:"Average R-Multiple",description:"Average reward per unit of risk",category:"Risk",config:{type:"simple",field1:"rMultiple",operation:"avg",format:"number"}}],I=t=>Number.isFinite(t)?t:0,F=(0,j.useMemo)(()=>{if(s.length===0)return O.map(i=>({...i,currentValue:0,error:null}));const t=s.filter(i=>p(i)>0),a=s.filter(i=>p(i)<0),n=t.reduce((i,x)=>i+p(x),0),r=Math.abs(a.reduce((i,x)=>i+p(x),0)),o=t.length/s.length*100,l=a.length/s.length*100,m=t.length>0?n/t.length:0,c=a.length>0?r/a.length:0,b=s.filter(i=>i.stopLoss&&parseFloat(i.stopLoss)>0).length,R=s.filter(i=>i.followedRules===!0||i.followedRules==="true").length;let w=0,g=0,y=0,f=0;
1s.forEach(i=>{p(i)>0?(y++,w=Math.max(w,y),f=0):p(i)<0?(f++,g=Math.max(g,f),y=0):(y=0,f=0)});let L=0,z=0,G=0;[...s].sort((i,x)=>V(i.entryTime)-V(x.entryTime)).forEach(i=>{z+=p(i),z>L&&(L=z);const x=L-z;x>G&&(G=x)});const X=new Set;s.forEach(i=>X.add(V(i.entryTime).toDateString()));const Z=X.size||1,k={winRate:o,lossRate:l,grossProfit:n,grossLoss:r,netProfit:n-r,avgWin:m,avgLoss:c,profitFactor:r>0?n/r:n>0?999:0,riskReward:c>0?m/c:m>0?999:0,expectancy:o/100*m-l/100*c,stopLossUsage:b/s.length*100,ruleFollowing:R/s.length*100,maxWinStreak:w,maxLossStreak:g,maxDrawdown:G,totalTrades:s.length,winCount:t.length,lossCount:a.length,maxWin:Math.max(...s.map(i=>p(i)),0),maxLoss:Math.min(...s.map(i=>p(i)),0),tradesPerDay:s.length/Z,tradingDays:Z};return O.map(i=>{try{let x=0;switch(i.id){case"win-rate":x=k.winRate;break;case"profit-factor":x=k.profitFactor;break;case"avg-winner":x=k.avgWin;break;case"avg-loser":x=-k.avgLoss;break;case"risk-reward":x=k.riskReward;break;case"expectancy":x=k.expectancy;break;case"rule-following":x=k.ruleFollowing;break;case"stop-loss-usage":x=k.stopLossUsage;break;case"max-drawdown":x=-k.maxDrawdown;break;case"avg-hold-time":x=k.tradesPerDay;break;case"consecutive-wins":x=k.maxWinStreak;break;case"consecutive-losses":x=k.maxLossStreak;break;default:i.calculationFn&&(x=i.calculationFn(s,k))}return{...i,currentValue:x,error:null}}catch(x){return{...i,currentValue:0,error:x.message}}})},[O,s]),ce=(0,j.useMemo)(()=>{if(s.length<3)return{};const t=[...s].sort((c,b)=>V(c.entryTime)-V(b.entryTime)),a=10080*60*1e3,n=[];let r=V(t[0].entryTime),o=[];if(t.forEach(c=>{const b=V(c.entryTime);b-r>a?(o.length>0&&n.push([...o]),r=b,o=[c]):o.push(c)}),o.length>0&&n.push(o),n.length<2)return{};const l={},m=(c,b)=>{const R=c.filter(f=>p(f)>0),w=c.filter(f=>p(f)<0),g=R.reduce((f,L)=>f+p(L),0),y=Math.abs(w.reduce((f,L)=>f+p(L),0));switch(b){case"win-rate":return c.length>0?R.length/c.length*100:0;case"profit-factor":return y>0?g/y:g>0?5:0;case"avg-winner":return R.length>0?g/R.length:0;case"avg-loser":return w.length>0?-y/w.length:0;case"expectancy":return c.length>0?c.reduce((f,L)=>f+p(L),0)/c.length:0;default:return c.reduce((f,L)=>f+p(L),0)}};return["win-rate","profit-factor","avg-winner","avg-loser","expectancy"].forEach(c=>{l[c]=n.slice(-8).map(b=>m(b,c))}),l},[s]),D=(0,j.useMemo)(()=>{const t=[{label:"Win Rate",id:"win-rate",max:100},{label:"Profit Factor",id:"profit-factor",max:3},{label:"R:R Ratio",id:"risk-reward",max:4},{label:"Discipline",id:"rule-following",max:100},{label:"Stop Loss",id:"stop-loss-usage",max:100},{label:"Expectancy",id:"expectancy",max:200}],a=t.map(n=>{const r=F.find(o=>o.id===n.id);return r?Math.min(Math.max(r.currentValue/n.max*100,0),100):0});return{labels:t.map(n=>n.label),values:a}},[F]),h=(0,j.useMemo)(()=>{if(!d||s.length===0)return[];const t=[...s].sort((l,m)=>V(l.entryTime)-V(m.entryTime)),a=10080*60*1e3,n=[];let r=V(t[0].entryTime),o=[];return t.forEach(l=>{const m=V(l.entryTime);m-r>a?(o.length>0&&n.push({date:r.toLocaleDateString(),trades:[...o],count:o.length}),r=m,o=[l]):o.push(l)}),o.length>0&&n.push({date:r.toLocaleDateString(),trades:o,count:o.length}),n.map(l=>{const m=l.trades.filter(g=>p(g)>0),c=l.trades.filter(g=>p(g)<0),b=m.reduce((g,y)=>g+p(y),0),R=Math.abs(c.reduce((g,y)=>g+p(y),0));let w=0;switch(d.id){case"win-rate":w=l.count>0?m.length/l.count*100:0;break;case"profit-factor":w=R>0?b/R:b>0?5:0;break;case"avg-winner":w=m.length>0?b/m.length:0;break;case"avg-loser":w=c.length>0?-R/c.length:0;break;default:w=l.trades.reduce((g,y)=>g+p(y),0)}return{...l,value:w}})},[d,s]),_=(0,j.useMemo)(()=>{const t=[],a=b=>F.find(R=>R.id===b),n=a("win-rate"),r=a("profit-factor"),o=a("rule-following"),l=a("stop-loss-usage"),m=a("risk-reward"),c=a("expectancy");return n&&n.currentValue>=60?t.push({type:"success",title:"Strong Win Rate",message:`Your ${n.currentValue.toFixed(1)}% win rate is excellent. Focus on increasing position size on high-conviction setups.`}):n&&n.currentValue<40&&n.currentValue>0&&t.push({type:"warning",title:"Win Rate Needs Work",message:`At ${n.currentValue.toFixed(1)}%, focus on better entry timing and setup selection.`}),r&&r.currentValue<1&&r.currentValue>0?t.push({type:"danger",title:"Negative Expectancy",message:"Your profit factor is below 1.0, meaning you're losing money on average. Review your risk management."}):r&&r.currentValue>=2&&t.push({type:"success",title:"Excellent Profit Factor",message:`A ${r.currentValue.toFixed(1)} profit factor means your winners significantly outweigh your losers.`}),o&&o.currentValue<80&&o.currentValue>0&&t.push({type:"warning",title:"Discipline Issue",message:`Only ${o.currentValue.toFixed(0)}% of trades follow your rules. This is costing you money.`}),l&&l.currentValue<90&&l.currentValue>0&&t.push({type:"warning",title:"Stop Loss Gaps",message:`${(100-l.currentValue).toFixed(0)}% of trades lack stop losses. Always protect your capital.`}),m&&m.currentValue>=2&&t.push({type:"success",title:"Good Risk/Reward",message:`Your ${m.currentValue.toFixed(1)}:1 R:R means you can be profitable even with 40% win rate.`}),c&&c.currentValue>0?t.push({type:"success",title:"Positive Expectancy",message:`You expect to make ${T(c.currentValue)} per trade. Keep following your system.`}):c&&c.currentValue<0&&t.push({type:"danger",title:"Negative Expectancy",message:`You expect to lose ${T(Math.abs(c.currentValue))} per trade. Review your approach.`}),t},[F]),de=t=>J(a=>a.filter(n=>n.id!==t)),ue=t=>{P(t),v("history")},me=t=>{M({...u,name:t.name,description:t.description,category:t.category,...t.config}),S(!1),v("builder")},xe=()=>{if(!u.name)return;const t={id:`custom-${Date.now()}`,name:u.name,description:u.description,category:u.category,format:u.format,benchmark:parseFloat(u.benchmark)||null,isBuiltIn:!1,createdAt:new Date().toISOString(),calculationFn:pe(u)};J(a=>[...a,t]),M({name:"",description:"",category:"Custom",type:"simple",field1:"pl",operation:"sum",condition:"all",conditionValue:"",benchmark:"",format:"number"}),v("dashboard")},pe=t=>(a,n)=>{let r=a;switch(t.condition==="winners"?r=a.filter(o=>p(o)>0):t.condition==="losers"?r=a.filter(o=>p(o)<0):t.condition==="setup"&&t.conditionValue&&(r=a.filter(o=>o.setup===t.conditionValue)),t.operation){case"sum":return r.reduce((l,m)=>l+I(m[t.field1]||m.pl),0);case"avg":return r.length>0?r.reduce((l,m)=>l+I(m[t.field1]||m.pl),0)/r.length:0;case"count":return r.length;case"max":return Math.max(...r.map(l=>
1I(l[t.field1]||l.pl)),0);case"min":return Math.min(...r.map(l=>I(l[t.field1]||l.pl)),0);case"winRate":const o=r.filter(l=>p(l)>0).length;return r.length>0?o/r.length*100:0;default:return 0}},Y=({value:t,icon:a,children:n})=>(0,e.jsxs)("button",{onClick:()=>v(t),className:`flex items-center gap-2 px-3 py-2 rounded-xl text-sm font-semibold transition-all ${N===t?"bg-blue-600 text-white shadow-lg shadow-blue-500/25":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/80 border border-slate-700/50"}`,children:[a&&(0,e.jsx)("div",{className:`p-1 rounded-md ${N===t?"bg-white/20":"bg-slate-700/60"}`,children:(0,e.jsx)(a,{className:"w-3 h-3"})}),n]}),he=B==="All"?F:F.filter(t=>t.category===B),U=(0,j.useMemo)(()=>D.values.length===0?0:Math.round(D.values.reduce((t,a)=>t+a,0)/D.values.length),[D]);return s.length===0?(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[400px] text-center p-8",children:[(0,e.jsx)("div",{className:"w-20 h-20 rounded-2xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20 flex items-center justify-center mb-4",children:(0,e.jsx)(te,{className:"w-10 h-10 text-blue-400"})}),(0,e.jsx)("h3",{className:"text-xl font-bold text-white mb-2",children:"No Trade Data"}),(0,e.jsx)("p",{className:"text-slate-400",children:"Log some trades to start tracking custom metrics."})]}):(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsx)("div",{className:"bg-gradient-to-r from-blue-600/20 via-indigo-600/20 to-purple-600/20 rounded-2xl border border-slate-700/50 p-6",children:(0,e.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"p-3 bg-gradient-to-br from-blue-500 to-indigo-600 rounded-xl shadow-lg shadow-blue-500/25",children:(0,e.jsx)(te,{className:"w-6 h-6 text-white"})}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("h2",{className:"text-2xl font-black text-white tracking-tight",children:"Custom Metrics"}),(0,e.jsxs)("div",{className:"hidden sm:flex items-center gap-1 px-2 py-0.5 bg-blue-500/15 border border-blue-500/25 rounded-full",children:[(0,e.jsx)("div",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 animate-pulse"}),(0,e.jsx)("span",{className:"text-[10px] font-bold text-blue-400 uppercase tracking-wider",children:"Live"})]})]}),(0,e.jsxs)("p",{className:"text-sm text-slate-400",children:[F.length," KPIs tracking your performance"]})]})]}),(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsxs)("button",{onClick:()=>S(!0),className:"px-4 py-2 bg-slate-700/50 hover:bg-slate-600/50 text-white rounded-lg flex items-center gap-2 transition text-sm",children:[(0,e.jsx)(ee,{className:"w-4 h-4"}),"Templates"]}),(0,e.jsxs)("button",{onClick:()=>v("builder"),className:"px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg flex items-center gap-2 transition text-sm",children:[(0,e.jsx)(Q,{className:"w-4 h-4"}),"Create"]})]})]})}),(0,e.jsxs)("div",{className:"bg-slate-900/60 rounded-2xl p-3 border border-slate-700/40 flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsx)(Y,{value:"dashboard",icon:re,children:"Dashboard"}),(0,e.jsx)(Y,{value:"builder",icon:se,children:"Builder"}),(0,e.jsx)(Y,{value:"history",icon:K,children:"History"})]}),N==="dashboard"&&(0,e.jsxs)("div",{className:"flex items-center gap-1.5 bg-slate-900/60 border border-slate-700/40 px-3 py-1.5 rounded-xl",children:[(0,e.jsx)("span",{className:`text-sm font-black ${U>=70?"text-emerald-400":U>=40?"text-amber-400":"text-red-400"}`,children:U}),(0,e.jsx)("span",{className:"text-[10px] font-bold text-slate-500 uppercase tracking-widest",children:"Health"})]})]}),N==="dashboard"&&(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[(0,e.jsxs)("div",{className:"bg-slate-900/60 rounded-2xl p-5 border border-slate-700/40",children:[(0,e.jsxs)("h3",{className:"text-sm font-bold text-white mb-3 flex items-center gap-3",children:[(0,e.jsx)("div",{className:"p-1.5 bg-blue-500/20 rounded-lg",children:(0,e.jsx)(ke,{className:"w-3.5 h-3.5 text-blue-400"})}),"Performance Scorecard"]}),(0,e.jsx)("div",{className:"h-56",children:(0,e.jsx)(_e,{data:{labels:D.labels,datasets:[{label:"Your Score",data:D.values,backgroundColor:"rgba(59, 130, 246, 0.15)",borderColor:"rgb(59, 130, 246)",borderWidth:2,pointBackgroun
1dColor:"rgb(59, 130, 246)",pointBorderColor:"#fff",pointRadius:4,pointHoverRadius:6}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1}},scales:{r:{min:0,max:100,ticks:{display:!1,stepSize:25},grid:{color:"rgba(75, 85, 99, 0.3)"},pointLabels:{color:"#94a3b8",font:{size:11,weight:"500"}},angleLines:{color:"rgba(75, 85, 99, 0.2)"}}}}})})]}),(0,e.jsxs)("div",{className:"bg-slate-900/60 rounded-2xl p-5 border border-slate-700/40",children:[(0,e.jsxs)("h3",{className:"text-sm font-bold text-white mb-3 flex items-center gap-3",children:[(0,e.jsx)("div",{className:"p-1.5 bg-amber-500/20 rounded-lg",children:(0,e.jsx)(Fe,{className:"w-3.5 h-3.5 text-amber-400"})}),"Key Insights",_.length>0&&(0,e.jsx)("span",{className:"text-[10px] bg-white/10 px-1.5 py-0.5 rounded",children:_.length})]}),_.length>0?(0,e.jsx)("div",{className:"space-y-2.5 max-h-52 overflow-y-auto pr-1",children:_.map((t,a)=>(0,e.jsxs)("div",{className:`p-3 rounded-lg border ${t.type==="success"?"bg-emerald-500/10 border-emerald-500/20":t.type==="warning"?"bg-amber-500/10 border-amber-500/20":"bg-red-500/10 border-red-500/20"}`,children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[t.type==="success"&&(0,e.jsx)(Ce,{className:"w-4 h-4 text-emerald-400 flex-shrink-0"}),t.type==="warning"&&(0,e.jsx)(q,{className:"w-4 h-4 text-amber-400 flex-shrink-0"}),t.type==="danger"&&(0,e.jsx)(q,{className:"w-4 h-4 text-red-400 flex-shrink-0"}),(0,e.jsx)("h4",{className:"font-semibold text-white text-xs",children:t.title})]}),(0,e.jsx)("p",{className:"text-[11px] text-slate-300 pl-6 leading-relaxed",children:t.message})]},a))}):(0,e.jsx)("div",{className:"flex items-center justify-center h-40 text-slate-500 text-sm",children:"Log more trades to generate insights"})]})]}),(0,e.jsx)("div",{className:"flex gap-2 overflow-x-auto pb-1",children:Ye.map(t=>{const a=t==="All"?F.length:F.filter(n=>n.category===t).length;return t!=="All"&&a===0?null:(0,e.jsxs)("button",{onClick:()=>ie(t),className:`px-3 py-1.5 rounded-lg text-xs font-medium whitespace-nowrap transition flex items-center gap-1.5 ${B===t?"bg-blue-600 text-white shadow-md":"bg-slate-800/50 text-slate-400 hover:text-white hover:bg-slate-700/50 border border-slate-700/50"}`,children:[t,(0,e.jsxs)("span",{className:`text-[10px] ${B===t?"text-blue-200":"text-slate-500"}`,children:["(",a,")"]})]},t)})}),(0,e.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:he.map(t=>(0,e.jsx)(He,{metric:t,onDelete:de,onViewHistory:ue,onEdit:a=>{ne(a),v("builder")},sparklineData:ce[t.id]},t.id))})]}),N==="builder"&&(0,e.jsx)(ae,{title:"Create Custom Metric",icon:se,gradient:"from-purple-600/20 to-pink-600/20",defaultExpanded:!0,children:(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Metric Name *"}),(0,e.jsx)("input",{type:"text",value:u.name,onChange:t=>M({...u,name:t.target.value}),placeholder:"e.g., Morning Session Win Rate",className:"w-full bg-slate-900/50 border border-slate-700 rounded-lg px-4 py-2.5 text-white focus:border-blue-500 focus:outline-none transition"})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Category"}),(0,e.jsxs)("select",{value:u.category,onChange:t=>M({...u,category:t.target.value}),className:"w-full bg-slate-900/50 border border-slate-700 rounded-lg px-4 py-2.5 text-white focus:border-blue-500 focus:outline-none transition",children:[(0,e.jsx)("option",{value:"Custom",children:"Custom"}),(0,e.jsx)("option",{value:"Performance",children:"Performance"}),(0,e.jsx)("option",{value:"Risk",children:"Risk"}),(0,e.jsx)("option",{value:"Discipline",children:"Discipline"}),(0,e.jsx)("option",{value:"Strategy",children:"Strategy"})]})]})]}),(0,e.jsxs)("div",{className:"bg-slate-900/50 rounded-xl p-4 border border-slate-700",children:[(0,e.jsxs)("h4",{className:"font-semibold text-white mb-4 flex items-center gap-2",children:[(0,e.jsx)(Le,{className:"w-4 h-4 text-blue-400"}),"Calculation"]}),(0,e.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-xs text-slate-400 mb-2",children:"Operation"}),(0,e.jsxs)("select",{value:u.operation,onChange:t=>M({...u,operation:t.target.value}),className:"w-full bg-slate-800 border border-slate-600 rounded-lg px-3 py-2.5 text-white text-sm",children:[(0,e.jsx)("option",{value:"sum",children:"Sum (Total)"}),(0,e.jsx)("option",{value:"avg",children:"Average"}),(0,e.jsx)("option",{value:"count",children:"Count"}),(0,e.jsx)("option",{value:"max",children:"Maximum"}),(0,e.jsx)("option",{value:"min",children:"Minimum"}),(0,e.jsx)("option",{value:"winRate",children:"Win Rate"})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-xs text-slate-400 mb-2",children:"Field"}),(0,e.jsxs)("select",{value:u.field1,onChange:t=>M({...u,field1:t.target.value}),className:"w-full bg-slate-800 border border-slate-600 rounded-lg px-3 py-2.5 text-white text-sm",children:[(0,e.jsx)("option",{value:"pl",children:"P/L"}),(0,e.jsx)("option",{value:"rMultiple",children:"R-Multiple"}),(0,e.jsx)("option",{value:"positionSize",children:"Position Size"}),(0,e.jsx)("option",{value:"holdTime",children:"Hold Time"})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-xs text-slate-400 mb-2",children:"Filter"}),(0,e.jsxs)("select",{value:u.condition,onChange:t=>M({...u,condition:t.target.value}),className:"w-full bg-slate-800 border border-slate-600 rounded-lg px-3 py-2.5 text-white text-sm",children:[(0,e.jsx)("option",{value:"all",children:"All Trades"}),(0,e.jsx)("option",{value:"winners",children:"Winners Only"}),(0,e.jsx)("option",{value:"losers",children:"Losers Only"}),(0,e.jsx)("option",{value:"setup",children:"By Setup"})]})]})]}),u.condition==="setup"&&(0,e.jsxs)("div",{className:"mt-4",children:[(0,e.jsx)("label",{className:"block text-xs text-slate-400 mb-2",children:"Setup Name"}),(0,e.jsx)("input",{type:"text",value:u.conditionValue,onChange:t=>M({...u,conditionValue:t.target.value}),placeholder:"e.g., Breakout",className:"w-full bg-slate-800 border border-slate-600 rounded-lg px-3 py-2.5 text-white text-sm"})]})]}),(0,e.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Display Format"}),(0,e.jsxs)("select",{value:u.format,onChange:t=>M({...u,format:t.target.value}),className:"w-full bg-slate-900/50 border border-slate-700 rounded-lg px-4 py-2.5 text-white focus:border-blue-500 focus:outline-none",children:[(0,e.jsx)("option",{value:"number",children:"Number (e.g., 1.50)"}),(0,e.jsx)("option",{value:"currency",children:"Currency (e.g., $150.00)"}),(0,e.jsx)("option",{value:"percent",children:"Percent (e.g., 65.0%)"})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Benchmark Target (Optional)"}),(0,e.jsx)(ve,{value:u.benchmark,onChange:t=>M({...u,benchmark:t.target.value}),placeholder:"e.g., 50",className:"w-full bg-slate-900/50 border border-slate-700 rounded-lg px-4 py-2.5 text-white focus:border-blue-500 focus:outline-none"})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Description"}),(0,e.jsx)("input",{type:"text",value:u.description,onChange:t=>M({...u,description:t.target.value}),placeholder:"What does this metric measure?",className:"w-full bg-slate-900/50 border border-slate-700 rounded-lg px-4 py-2.5 text-white focus:border-blue-500 focus:outline-none"})]}),(0,e.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,e.jsx)("button",{onClick:()=>
1v("dashboard"),className:"px-4 py-2 bg-slate-700 hover:bg-slate-600 text-white rounded-lg transition text-sm",children:"Cancel"}),(0,e.jsxs)("button",{onClick:xe,disabled:!u.name,className:`px-6 py-2 rounded-lg font-semibold flex items-center gap-2 transition text-sm ${u.name?"bg-blue-600 hover:bg-blue-500 text-white":"bg-slate-700 text-slate-500 cursor-not-allowed"}`,children:[(0,e.jsx)(Q,{className:"w-4 h-4"}),"Create Metric"]})]})]})}),N==="history"&&(0,e.jsx)(ae,{title:"Historical Tracking",icon:K,gradient:"from-emerald-600/20 to-teal-600/20",defaultExpanded:!0,children:(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"block text-sm font-medium text-slate-300 mb-2",children:"Select Metric"}),(0,e.jsxs)("select",{value:d?.id||"",onChange:t=>{P(F.find(a=>a.id===t.target.value)||null)},className:"w-full bg-slate-900/50 border border-slate-700 rounded-lg px-4 py-2.5 text-white focus:border-blue-500 focus:outline-none",children:[(0,e.jsx)("option",{value:"",children:"Choose a metric..."}),F.map(t=>(0,e.jsx)("option",{value:t.id,children:t.name},t.id))]})]}),d&&h.length>0&&(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"bg-slate-900/50 rounded-xl p-4 flex items-center justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"text-xs text-slate-400",children:"Current Value"}),(0,e.jsx)("div",{className:"text-2xl font-bold text-white",children:d.format==="currency"?T(d.currentValue):d.format==="percent"?H(d.currentValue):W(d.currentValue)})]}),d.benchmark&&(0,e.jsxs)("div",{className:"text-right",children:[(0,e.jsx)("div",{className:"text-xs text-slate-400",children:"Target"}),(0,e.jsx)("div",{className:"text-xl font-semibold text-blue-400",children:d.format==="currency"?T(d.benchmark):d.format==="percent"?H(d.benchmark):W(d.benchmark)})]})]}),(0,e.jsx)("div",{className:"h-72",children:(0,e.jsx)(Ie,{data:{labels:h.map(t=>t.date),datasets:[{label:d.name,data:h.map(t=>t.value),borderColor:"rgb(59, 130, 246)",backgroundColor:"rgba(59, 130, 246, 0.1)",fill:!0,tension:.4,pointRadius:3,pointHoverRadius:6},...d.benchmark?[{label:"Target",data:h.map(()=>d.benchmark),borderColor:"rgb(16, 185, 129)",borderDash:[5,5],fill:!1,pointRadius:0}]:[]]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!0,position:"top",labels:{color:"#94a3b8",usePointStyle:!0}}},scales:{y:{grid:{color:"rgba(75, 85, 99, 0.2)"},ticks:{color:"#94a3b8"}},x:{grid:{color:"rgba(75, 85, 99, 0.1)"},ticks:{color:"#94a3b8"}}}}})}),(0,e.jsx)("div",{className:"grid grid-cols-3 gap-3",children:[{label:"First",value:h[0]?.value||0},{label:"Latest",value:h[h.length-1]?.value||0},{label:"Change",value:null,isChange:!0}].map((t,a)=>(0,e.jsxs)("div",{className:"bg-slate-900/50 rounded-lg p-3",children:[(0,e.jsx)("div",{className:"text-[10px] text-slate-500 uppercase tracking-wider",children:t.label}),t.isChange?(0,e.jsx)("div",{className:`text-lg font-bold ${(h[h.length-1]?.value||0)>(h[0]?.value||0)?"text-emerald-400":"text-red-400"}`,children:h.length>=2&&h[0]?.value!==0?`${((h[h.length-1]?.value-h[0]?.value)/Math.abs(h[0]?.value)*100).toFixed(1)}%`:"N/A"}):(0,e.jsx)("div",{className:"text-lg font-bold text-white",children:W(t.value)})]},a))})]}),d&&h.length===0&&(0,e.jsxs)("div",{className:"text-center py-12 text-slate-400",children:[(0,e.jsx)(K,{className:"w-12 h-12 mx-auto mb-3 text-slate-600"}),(0,e.jsx)("p",{children:"Not enough data for historical tracking"}),(0,e.jsx)("p",{className:"text-sm mt-1 text-slate-500",children:"Keep trading to build your history!"})]})]})}),(0,e.jsx)(le,{children:$&&(0,e.jsx)(A.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4",onClick:()=>S(!1),children:(0,e.jsxs)(A.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},onClick:t=>t.stopPropagation(),className:"bg-slate-800 rounded-xl p-6 max-w-3xl w-full max-h-[80vh] overflow-y-auto border border-slate-700",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,e.jsxs)("h3",{className:"text-xl font-bold text-white flex items-center gap-2",children:[(0,e.jsx)(ee,{className:"w-6 h-6 text-blue-400"}),"Metric Templates"]}),(0,e.jsx)("button",{onClick:()=>S(!1),className:"p-2 text-slate-400 hover:text-white transition",children:(0,e.jsx)(Re,{className:"w-5 h-5"})})]}),(0,e.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:oe.map((t,a)=>(0,e.jsx)(Oe,{template:t,onApply:me},a))})]})})})]})};export{Ze as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.