PageSourceSearch

https://vaulticks.com/assets/EvaluationMode-DfCROq6D.js

js vaulticks.com collected 2026-09-24 14:55:52 UTC 133,035 bytes, 1 lines download raw bytes

1import{r as a,j as e}from"./ui-vendor-efoDfjla.js";import{u as bt,d as Le,D as tt}from"./DashboardLayout-DP1N6NDa.js";import{c as I,g as Pe,a as Pt,h as jt,e as Tt,b as Rt}from"./index-Dy-yis_s.js";import{C as me,a as st}from"./calculator-CO4C8QqQ.js";import{C as It}from"./ContractSelector-Dwpo4fLd.js";import{g as Xe}from"./dateUtils-DTOd2PGQ.js";import{m as wt,b as Nt}from"./subscription-b30AUCA_.js";import{f as vt,M as Ft,b as yt}from"./accountLimit-C_L7W8xu.js";import{Z as _e,V as zt,J as _t,r as ze,Q as Et,X as we,D as at,L as ue,o as Ot,O as Ce,E as nt,R as Ct,F as rt,e as De,w as lt,S as ot,Y as Oe,H as qe,U as it,y as Ut,P as Re,K as dt,_ as Ee,$ as Ie,m as Dt,q as Bt,a0 as Kt,l as Ve,a1 as Wt,b as Vt,a2 as Je,a3 as Qe,a4 as ct,d as xt,a5 as Gt,i as Ht}from"./utils-vendor-BXji2ymy.js";import{N as ve}from"./NumericInput-Cf40pzlq.js";import{TRADOVATE_RETURN_TO_KEY as Yt}from"./TradovateCallback-BLPtI8tL.js";import{s as qt,b as mt,E as Jt}from"./AutoJournal-BK-fF1hh.js";import"./router-vendor-CSWcbrtA.js";import"./query-vendor-BYBWvLyW.js";function Qt(t){if(!t)return 0;const r=t.trim().toUpperCase().replace(/[$,]/g,""),m=r.match(/^([\d.]+)\s*(K|M)?$/);if(!m){const h=parseFloat(r);return Number.isFinite(h)?h:0}const i=parseFloat(m[1]),p=m[2];return p==="K"?i*1e3:p==="M"?i*1e6:i}function Zt(t,r,m,i,p){const h=t+m.reduce((x,w)=>x+w.pnl,0);if(i!=null&&i>0){const x=h-i;return{trailingMaxDrawdown:i,trailLocked:!1,currentBalance:h,drawdownFloor:x,drawdownUsed:0,drawdownRemaining:Math.max(0,i)}}if(p!=null){const x=Math.max(0,h-p),w=Math.max(0,r-x);return{trailingMaxDrawdown:x,trailLocked:!1,currentBalance:h,drawdownFloor:p,drawdownUsed:w,drawdownRemaining:x}}let d=t,j=t-r;for(const x of m)if(d+=x.pnl,x.pnl>0){const w=d-r;w>j&&(j=w)}const g=Math.max(0,d-j);return{trailingMaxDrawdown:g,trailLocked:!1,currentBalance:d,drawdownFloor:j,drawdownUsed:Math.max(0,r-g),drawdownRemaining:g}}function Xt(t){const r=Math.max(0,t.profit_target-(t.current_profit||0)),m=Math.max(0,t.max_drawdown-(t.current_drawdown||0)),i=t.time_limit_days>0?Math.max(0,t.time_limit_days-(t.days_used||0)):1/0,p=Math.max(0,(t.min_trading_days||0)-(t.trading_days_completed||0));let h=.22,d=1;const j=t.profit_target>0?(t.current_profit||0)/t.profit_target*100:0;if(j>=75&&(h=.22,d=.95),i!==1/0&&t.time_limit_days>0){const x=i/t.time_limit_days*100;x<25&&j<50?(h=.25,d=1):x<25&&(h=.23)}if(p>5&&r>0){const x=r/p;(m>0?x/m:1)<.05&&(h=.22,d=.92)}const g=t.max_drawdown>0?(t.current_drawdown||0)/t.max_drawdown*100:0;return g>70?(h=.22,d=.88):g>50&&(d=Math.min(d,.93)),t.consistency_pct>0&&(t.consistency_score||0)<t.consistency_pct&&(d=Math.min(d,.9)),{pct:h,multiplier:d}}function es(t){const r=[],m=Math.max(0,t.profit_target-(t.current_profit||0)),i=Math.max(0,t.max_drawdown-(t.current_drawdown||0));t.daily_loss_limit>0&&t.daily_loss_limit;const p=t.time_limit_days>0?Math.max(0,t.time_limit_days-(t.days_used||0)):1/0;if(t.consistency_pct>0&&t.current_profit>0){const d=t.current_profit>0?i*.25/t.current_profit*100:0;d>30&&r.push({type:"consistency",severity:"warning",message:`Consistency risk: max trade could put ${Math.round(d)}% of profits in one day`,icon:"⚖️"})}if(t.daily_loss_limit>0){const d=i*.22,j=t.daily_loss_limit-d;j<t.daily_loss_limit*.3&&r.push({type:"daily_limit",severity:j<0?"danger":"warning",message:`Daily loss limit: $${Math.round(t.daily_loss_limit).toLocaleString()} available today`,icon:"🛡️"})}if(m>0&&m<t.profit_target*.15&&r.push({type:"profit_close",severity:"info",message:`Profit target close: only need $${Math.round(m).toLocaleString()} more`,icon:"🎯"}),p!==1/0&&p<=5&&p>0){const d=t.profit_target>0?(t.current_profit||0)/t.profit_target*100:0;d<80&&r.push({type:"time_pressure",severity:"danger",message:`Time pressure: ${p} day${p!==1?"s":""} remaining with ${Math.round(d)}% progress`,icon:"⏰"})}const h=t.max_drawdown>0?(t.current_drawdown||0)/t.max_drawdown*100:0;return h>70&&r.push({type:"drawdown_danger",severity:h>85?"danger":"warning",message:`Drawdown ${Math.round(h)}% used — only $${Math.round(i).toLocaleString()} remaining`,icon:"📉"}),r}function ts(t){const r=t.profit_target>0?(t.current_profit||0)/t.profit_target*100:0,m=t.max_drawdown>
10?(t.current_drawdown||0)/t.max_drawdown*100:0,i=t.time_limit_days>0?Math.max(0,t.time_limit_days-(t.days_used||0)):1/0,p=t.time_limit_days>0?(t.days_used||0)/t.time_limit_days*100:0;(t.trading_days_completed||0)>=(t.min_trading_days||0);const h=t.consistency_pct<=0||(t.consistency_score||0)>=t.consistency_pct;return m>80?{health:"red",label:"At Risk",reason:"Drawdown critically high"}:i!==1/0&&i<=3&&r<60?{health:"red",label:"At Risk",reason:"Running out of time"}:t.status==="failed"?{health:"red",label:"Failed",reason:"Evaluation failed"}:m>50?{health:"yellow",label:"Caution",reason:"Drawdown over 50%"}:i!==1/0&&i<=7&&r<50?{health:"yellow",label:"Caution",reason:"Time running low"}:h?p>60&&r<30?{health:"yellow",label:"Caution",reason:"Behind schedule"}:t.status==="passed"?{health:"green",label:"Passed",reason:"Evaluation passed"}:r>=80&&m<40?{health:"green",label:"On Track",reason:"Near target with low drawdown"}:{health:"green",label:"On Track",reason:"Within safe parameters"}:{health:"yellow",label:"Caution",reason:"Consistency below target"}}function ss(t,r,m,i,p,h){const d=me.find(v=>v.symbol===i);if(!d||p<=0||t<=0)return null;const j=Math.floor(t*r*m);if(j<=0)return null;const g=p*d.dollarPerPoint;let x=Math.floor(j/g),w=!1,k=d;if(x<1){const b={NQ:"MNQ",ES:"MES",GC:"MGC",CL:"MCL",SI:"SIL",YM:"MYM"}[d.symbol];if(b){const B=me.find(y=>y.symbol===b);if(B){k=B,w=!0;const y=p*B.dollarPerPoint;x=Math.max(1,Math.floor(j/y))}}x<1&&(x=1)}const A=typeof h=="number"&&Number.isFinite(h)?Math.floor(h):0,M=A>=1&&x>A;M&&(x=A);const N=k.dollarPerPoint>0?j/k.dollarPerPoint:0;return{riskPerTrade:j,riskPct:r*m*100,maxContracts:x,contract:k,autoMicro:w,firmCapped:M,requiredStop:Math.round(N*100)/100}}function We(t,r="NQ",m=0){const{pct:i,multiplier:p}=Xt(t),{health:h,label:d,reason:j}=ts(t),g=es(t),x=Math.max(0,t.profit_target-(t.current_profit||0)),w=Math.max(0,t.max_drawdown-(t.current_drawdown||0)),k=t.daily_loss_limit>0?t.daily_loss_limit:0,A=t.time_limit_days>0?Math.max(0,t.time_limit_days-(t.days_used||0)):-1,M=Math.max(0,(t.min_trading_days||0)-(t.trading_days_completed||0)),N=t.profit_target>0?(t.current_profit||0)/t.profit_target*100:0,v=t.max_drawdown>0?(t.current_drawdown||0)/t.max_drawdown*100:0,b=m>0?ss(w,i,p,r,m,t.max_contracts):null;return{health:h,healthLabel:d,healthReason:j,warnings:g,positionSizing:b,profitRemaining:x,drawdownRemaining:w,dailyLimitRemaining:k,daysRemaining:A,tradingDaysRemaining:M,progressPct:N,drawdownUsedPct:v,aggressivenessMultiplier:p}}function as(t,r,m,i,p,h,d="16:59"){const j=new Date(new Date().toLocaleString("en-US",{timeZone:"America/New_York"})),[g,x]=d.split(":").map(Number);let w;j.getHours()>g||j.getHours()===g&&j.getMinutes()>=x?w=new Date(j):(w=new Date(j),w.setDate(w.getDate()-1));const k=Ge(w);if(h&&h>=k)return null;let A;if(h)A=pt(h),A.setDate(A.getDate()+1);else{const B=p.reduce((y,T)=>{const P=T.trade_date||(T.trade_timestamp?T.trade_timestamp.split("T")[0]:"");return P&&(!y||P<y)?P:y},"");B?A=pt(B):A=w}let M=t,N=r,v=0;const b=new Date(A);for(;Ge(b)<=k;){const B=Ge(b),y=i+p.filter(P=>(P.trade_date||(P.trade_timestamp?P.trade_timestamp.split("T")[0]:""))<=B).reduce((P,ee)=>P+ee.pnl,0);N=Math.max(N,y);const T=N-m;M=Math.max(M,T),v++,b.setDate(b.getDate()+1)}return v===0?null:{newFloor:M,newHighestBalance:N,newProcessedDate:k,daysProcessed:v}}function Ge(t){return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}function pt(t){const[r,m,i]=t.split("-").map(Number);return new Date(r,m-1,i)}async function ns(){var t;try{return((t=(await I.entities.eval_trades.query({query:{},sort:"-created_at",limit:1e3})).data)==null?void 0:t.items)||[]}catch(r){return console.error("Failed to fetch all eval trades:",r),[]}}async function Ue(t){try{const r=new Date,m=Xe(),i=r.toISOString();return(await I.entities.eval_trades.create({data:{eval_account_id:t.eval_account_id,pnl:t.pnl,result:t.result,notes:t.notes||"",trade_date:m,trade_timestamp:i}})).data}catch(r){return console.error("Failed to create eval trade:",r),null}}async function St(t){try{return await I.entities.eval_trades.delete({id:String(t)}),!0}catch(r){return console.error("Failed to delete eval trade:",r),!1}}function Ke(t){const r=t.length,m=t.filter(d=>d.result==="win").length,i=t.filter(d=>d.result==="loss").length,p=t.reduce((d,j)=>d+j.pnl,0),h=r>0?m/r*100:0;return{totalTrades:r,wins:m,losses:i,netPnl:p,winRate:h}}const kt="eval-group-batches";function rs(){try{const t=localStorage.getItem(kt);return t?JSON.parse(t):[]}catch{return[]}}function He(t){localStorage.setItem(kt,JSON.stringify(t))}function ut(t){if(t.length===0)return!0;const r=Xe();return!t.some(m=>{var i;return(m.trade_date||((i=m.trade_timestamp)==null?void 0:i.split("T")[0]))===r})}const Mt="eval-group-filtered-contracts",$t="eval-group-active-contract";function ls(){try{const t=localStorage.getItem(Mt);if(t){const r=JSON.parse(t);if(Array.isArray(r)&&r.length>0)return r}}catch{}return me.map(t=>t.symbol)}function os(){try{const t=localStorage.getItem($t);if(t&&me.some(r=>r.symbol===t))return t}catch{}return"NQ"}function is({accounts:t,allTrades:r,onTradeLogged:m}){const{toast:i}
1=Pe(),[p,h]=a.useState(!1),[d,j]=a.useState(!1),[g,x]=a.useState({}),[w,k]=a.useState({}),[A,M]=a.useState(""),[N,v]=a.useState(""),[b,B]=a.useState(!1),[y,T]=a.useState(()=>rs()),[P,ee]=a.useState(""),[z,V]=a.useState(ls),[u,C]=a.useState(os);a.useEffect(()=>{localStorage.setItem(Mt,JSON.stringify(z))},[z]),a.useEffect(()=>{localStorage.setItem($t,u)},[u]);const F=a.useMemo(()=>{const s=Number(P);return Number.isFinite(s)&&s>0?s:0},[P]),o=a.useMemo(()=>me.find(s=>s.symbol===u)||me[0],[u]),$=a.useMemo(()=>t.filter(s=>s.status==="active"),[t]),_=a.useMemo(()=>$.map(s=>{const D=r.filter(W=>W.eval_account_id===s.id),S=Ke(D),l=S.netPnl,n=Math.max(0,-S.netPnl),f={...s,current_profit:Math.max(0,l),current_drawdown:Math.min(s.max_drawdown,n)},L=We(f,u,F);return{account:s,trades:D,stats:S,analysis:L,liveProfit:l,liveDrawdownUsed:n}}),[$,r,u,F]),U=$.length>0,Y=y.length>0,K=a.useMemo(()=>{let s=0,D=0,S=0,l=0;for(const f of _)s+=f.stats.totalTrades,D+=f.stats.wins,S+=f.stats.losses,l+=f.stats.netPnl;const n=s>0?D/s*100:0;return{totalTrades:s,wins:D,losses:S,netPnl:l,winRate:n}},[_]),ae=a.useMemo(()=>_.reduce((s,D)=>{const S=D.analysis.positionSizing;return s+(S?S.maxContracts:0)},0),[_]),ie=a.useMemo(()=>_.reduce((s,D)=>{const S=D.analysis.positionSizing;return s+(S?S.riskPerTrade:0)},0),[_]);a.useEffect(()=>{h(!1),j(!1),x({}),k({})},[$.length]);const te=a.useCallback(()=>{const s={};for(const D of _)s[String(D.account.id)]="";return s},[_]),ne=a.useCallback(()=>{U&&(x(te()),M(""),h(!0),j(!1))},[U,te]),Q=a.useCallback(async()=>{const s=[];for(const[n,f]of Object.entries(g)){const L=Number(f);L>0&&s.push({accountId:Number(n),amount:L})}if(s.length===0){i({title:"Invalid PnL",description:"Enter a positive dollar amount for at least one account.",variant:"destructive"});return}B(!0);const D=crypto.randomUUID(),S=[],l=A.trim().slice(0,2e3)||"";try{for(const n of s){const f=_.find(W=>W.account.id===n.accountId);if(!f)continue;const L=await Ue({eval_account_id:n.accountId,pnl:n.amount,result:"win",notes:l});if(L){S.push({evalAccountId:n.accountId,tradeId:L.id,pnl:n.amount});const W=Math.max(0,f.liveProfit+n.amount),O=(f.account.trading_days_completed||0)+(ut(f.trades)?1:0);if(W>=f.account.profit_target&&f.account.status!=="passed"){const oe=new Date().toISOString();await I.entities.eval_accounts.update({id:String(n.accountId),data:{current_profit:W,trading_days_completed:O,status:"passed",passed_at:oe}});let X=!1;try{await vt()&&(X=(await wt()).length>=Ft)}catch{X=!1}
1try{if(X)throw new Error("manual_limit");const ge=await Nt({account_name:`${f.account.firm_name} – ${f.account.account_size} (Passed Eval)`,broker_name:f.account.firm_name,account_number:`eval_passed_${n.accountId}_${Date.now()}`,remaining_drawdown:f.account.max_drawdown,current_balance:f.account.max_drawdown,starting_balance:0,peak_balance:0});ge!=null&&ge.id&&await I.entities.eval_accounts.update({id:String(n.accountId),data:{dashboard_account_id:ge.id}})}catch{}i({title:"🎉 EVALUATION PASSED!",description:X?`${f.account.firm_name} ${f.account.account_size} passed. ${yt}.`:`${f.account.firm_name} ${f.account.account_size} passed and was added to your Dashboard.`})}else await I.entities.eval_accounts.update({id:String(n.accountId),data:{current_profit:W,trading_days_completed:O}})}}if(S.length>0){const f=[{batchId:D,timestamp:new Date().toISOString(),entries:S},...y].slice(0,50);T(f),He(f)}i({title:"Group Win logged!",description:`+$${s.reduce((n,f)=>n+f.amount,0).toLocaleString()} across ${s.length} accounts`}),m()}catch(n){i({title:"Error",description:(n==null?void 0:n.message)||"Failed to log group trade",variant:"destructive"})}finally{B(!1),h(!1),x({}),M("")}},[g,A,_,y,m,i]),se=a.useCallback(()=>{U&&(k(te()),v(""),j(!0),h(!1))},[U,te]),de=a.useCallback(async()=>{const s=[];for(const[n,f]of Object.entries(w)){const L=Number(f);L>0&&s.push({accountId:Number(n),amount:L})}if(s.length===0){i({title:"Invalid PnL",description:"Enter a positive dollar amount for at least one account.",variant:"destructive"});return}B(!0);const D=crypto.randomUUID(),S=[],l=N.trim().slice(0,2e3)||"";try{for(const n of s){const f=_.find(W=>W.account.id===n.accountId);if(!f)continue;const L=await Ue({eval_account_id:n.accountId,pnl:-n.amount,result:"loss",notes:l});if(L){S.push({evalAccountId:n.accountId,tradeId:L.id,pnl:-n.amount});const W=Math.min(f.account.max_drawdown,f.liveDrawdownUsed+n.amount),O=(f.account.trading_days_completed||0)+(ut(f.trades)?1:0);await I.entities.eval_accounts.update({id:String(n.accountId),data:{current_drawdown:W,trading_days_completed:O}})}}if(S.length>0){const f=[{batchId:D,timestamp:new Date().toISOString(),entries:S},...y].slice(0,50);T(f),He(f)}i({title:"Group Loss logged",description:`-$${s.reduce((n,f)=>n+f.amount,0).toLocaleString()} across ${s.length} accounts`}),m()}catch(n){i({title:"Error",description:(n==null?void 0:n.message)||"Failed to log group trade",variant:"destructive"})}finally{B(!1),j(!1),k({}),v("")}},[w,N,_,y,m,i]),ce=a.useCallback(async()=>{if(y.length===0)return;B(!0);const s=y[0];try{for(const S of s.entries)await St(S.tradeId);const D=y.slice(1);T(D),He(D),i({title:"Group trade undone",description:`Removed ${s.entries.length} trades`}),m()}catch(D){i({title:"Error",description:(D==null?void 0:D.message)||"Failed to undo",variant:"destructive"})}finally{B(!1)}},[y,m,i]),q=p?g:d?w:null,re=d?-1:1,le=a.useMemo(()=>q?Object.values(q).reduce((s,D)=>{const S=Number(D);return S>0?s+re*S:s},0):0,[q,re]),Z=a.useMemo(()=>q?Object.values(q).some(s=>Number(s)>0):!1,[q]);return e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-[#21262D] flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-bold text-[#F0F6FC]",children:"Group Trade Result"}),e.jsxs("div",{className:"flex items-center gap-2",children:[F>0&&e.jsxs("span",{className:"text-[10px] text-[#F59E0B] font-semibold uppercase tracking-wider flex items-center gap-1",children:[e.jsx(_e,{className:"w-3 h-3"}),ae," total contracts"]}),e.jsxs("span",{className:"text-[10px] text-[#A855F7] font-semibold uppercase tracking-wider",children:[$.length," accounts"]})]})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx("div",{className:"bg-[#0D1117] rounded-lg p-3 border border-[#21262D] space-y-2",children:e.jsx(It,{filteredSymbols:z,onFilterChange:V,activeSymbol:u,onActiveChange:C})}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-3 border border-[#21262D] space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(zt,{className:"w-3.5 h-3.5 text-[#F59E0B]"}),e.jsx("span",{className:"text-[10px] text-[#F59E0B] uppercase tracking-wider font-semibold",children:"Position Sizing Calculator"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[9px] text-[#484F58] uppercase tracking-wider font-semibold block mb-1",children:"Stop Loss (points)"}),e.jsx("input",{type:"number",step:"any",min:"0",value:P,onChange:s=>ee(s.target.value),placeholder:"e.g. 10",className:"w-full bg-[#161B22] border border-[#30363D] text-[#F0F6FC] h-9 text-xs rounded-md px-3 focus:outline-none focus:ring-1 focus:ring-[#F59E0B] focus:border-[#F59E0B] placeholder:text-[#484F58] tabular-nums"})]}),F>0&&e.jsxs("div",{className:"flex items-center justify-between pt-1.5 border-t border-[#21262D] mt-1",children:[e.jsxs("span",{className:"text-[9px] text-[#484F58]",children:[o.symbol," · $",o.dollarPerPoint,"/pt ·"," ",F," pt stop"]}),e.jsxs("span",{className:"text-[10px] text-[#F59E0B] font-bold",children:["Total: ",ae," ",ae===1?"contract":"contracts"," · $",ie.toLocaleStr
1ing()," risk"]})]}),F===0&&e.jsx("p",{className:"text-[9px] text-[#484F58] italic",children:"Enter a stop loss to calculate position sizes per account"})]}),e.jsx("div",{className:"space-y-1.5",children:_.map(s=>{const D=s.analysis.positionSizing;return e.jsxs("div",{className:"flex items-center justify-between bg-[#0D1117] rounded-lg px-3 py-2 border border-[#21262D]",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsxs("span",{className:"text-[10px] font-bold text-[#F0F6FC] truncate",children:[s.account.firm_name," ",s.account.account_size]}),e.jsx("span",{className:"text-[9px] text-[#484F58]",children:s.account.plan_type})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[D?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-[10px] text-[#F59E0B] font-bold",children:[D.maxContracts," ",D.contract.symbol,D.autoMicro&&e.jsx("span",{className:"text-[8px] text-[#484F58] ml-0.5",children:"(auto)"})]}),e.jsxs("span",{className:"text-[9px] text-[#484F58]",children:["$",D.riskPerTrade.toLocaleString()," risk"]})]}):F>0?e.jsx("span",{className:"text-[9px] text-[#484F58]",children:"—"}):null,e.jsxs("span",{className:`text-[10px] font-bold ${s.stats.netPnl>=0?"text-[#22C55E]":"text-[#EF4444]"}`,children:[s.stats.netPnl>=0?"+":"","$",s.stats.netPnl.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})]}),e.jsxs("span",{className:"text-[9px] text-[#484F58]",children:["DD: $",Math.round(s.account.max_drawdown-s.liveDrawdownUsed).toLocaleString()]})]})]},s.account.id)})}),!p&&!d&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:se,disabled:!U||b,className:"flex-1 h-11 rounded-lg font-bold text-sm bg-[#EF4444]/15 border border-[#EF4444]/30 text-[#EF4444] hover:bg-[#EF4444]/25 transition-all flex items-center justify-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(_t,{className:"w-4 h-4"}),"Loss"]}),e.jsxs("button",{onClick:ne,disabled:!U||b,className:"flex-1 h-11 rounded-lg font-bold text-sm bg-[#22C55E]/15 border border-[#22C55E]/30 text-[#22C55E] hover:bg-[#22C55E]/25 transition-all flex items-center justify-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(ze,{className:"w-4 h-4"}),"Win"]}),e.jsxs("button",{onClick:ce,disabled:!Y||b,className:"h-11 px-3 rounded-lg font-bold text-xs bg-[#21262D] border border-[#30363D] text-[#8B949E] hover:text-[#F0F6FC] hover:bg-[#30363D] transition-all disabled:opacity-30 disabled:cursor-not-allowed flex items-center justify-center gap-1",title:"Undo last group trade",children:[e.jsx(Et,{className:"w-3.5 h-3.5"}),"Undo"]})]}),p&&e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-3 border border-[#22C55E]/20 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-[10px] text-[#22C55E] uppercase tracking-wider font-semibold",children:"Dollar amount gained (per account)"}),e.jsx("button",{onClick:()=>h(!1),className:"text-[#484F58] hover:text-[#8B949E] transition-colors",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]}),e.jsx("p",{className:"text-[9px] text-[#484F58]",children:"Enter the exact dollar amount won for each eval account. Leave blank or 0 to skip."}),e.jsx("div",{className:"space-y-1.5",children:_.map((s,D)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-[#8B949E] w-[42%] truncate",children:[s.account.firm_name," ",s.account.account_size,e.jsxs("span",{className:"text-[#484F58]",children:[" ","· ",s.account.plan_type]})]}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(at,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-[#484F58]"}),e.jsx("input",{type:"number",step:"any",value:g[String(s.account.id)]||"",onChange:S=>x(l=>({...l,[String(s.account.id)]:S.target.value})),onKeyDown:S=>{S.key==="Enter"&&Q(),S.key==="Escape"&&h(!1)},autoFocus:D===0,placeholder:"0.00",className:"w-full bg-[#161B22] border border-[#30363D] text-[#F0F6FC] h-8 text-xs rounded-md pl-6 pr-2 focus:outline-none focus:ring-1 focus:ring-[#22C55E] focu
1s:border-[#22C55E] placeholder:text-[#484F58]"})]})]},s.account.id))}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] text-[#22C55E] uppercase tracking-wider font-semibold block",children:"Shared note (saved on every account)"}),e.jsx("textarea",{value:A,onChange:s=>M(s.target.value),onKeyDown:s=>{(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&(s.preventDefault(),Q()),s.key==="Escape"&&h(!1)},maxLength:2e3,rows:2,placeholder:"Add a note...",className:"w-full bg-[#161B22] border border-[#30363D] text-[#F0F6FC] text-xs rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-[#22C55E] focus:border-[#22C55E] placeholder:text-[#484F58] resize-y min-h-[48px] max-h-[140px]"})]}),e.jsxs("button",{onClick:Q,disabled:!Z||b,className:"w-full h-9 rounded-lg font-bold text-xs bg-[#22C55E] hover:bg-[#16A34A] text-[#0D1117] transition-all disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[b?e.jsx(ue,{className:"w-3.5 h-3.5 animate-spin"}):null,"Confirm Group Win"]})]}),d&&e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-3 border border-[#EF4444]/20 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-[10px] text-[#EF4444] uppercase tracking-wider font-semibold",children:"Dollar amount lost (per account)"}),e.jsx("button",{onClick:()=>j(!1),className:"text-[#484F58] hover:text-[#8B949E] transition-colors",children:e.jsx(we,{className:"w-3.5 h-3.5"})})]}),e.jsx("p",{className:"text-[9px] text-[#484F58]",children:"Enter the exact dollar amount lost for each eval account (positive number). Leave blank or 0 to skip."}),e.jsx("div",{className:"space-y-1.5",children:_.map((s,D)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-[#8B949E] w-[42%] truncate",children:[s.account.firm_name," ",s.account.account_size,e.jsxs("span",{className:"text-[#484F58]",children:[" ","· ",s.account.plan_type]})]}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(at,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-[#484F58]"}),e.jsx("input",{type:"number",step:"any",value:w[String(s.account.id)]||"",onChange:S=>k(l=>({...l,[String(s.account.id)]:S.target.value})),onKeyDown:S=>{S.key==="Enter"&&de(),S.key==="Escape"&&j(!1)},autoFocus:D===0,placeholder:"0.00",className:"w-full bg-[#161B22] border border-[#30363D] text-[#F0F6FC] h-8 text-xs rounded-md pl-6 pr-2 focus:outline-none focus:ring-1 focus:ring-[#EF4444] focus:border-[#EF4444] placeholder:text-[#484F58]"})]})]},s.account.id))}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] text-[#EF4444] uppercase tracking-wider font-semibold block",children:"Shared note (saved on every account)"}),e.jsx("textarea",{value:N,onChange:s=>v(s.target.value),onKeyDown:s=>{(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&(s.preventDefault(),de()),s.key==="Escape"&&j(!1)},maxLength:2e3,rows:2,placeholder:"Add a note...",className:"w-full bg-[#161B22] border border-[#30363D] text-[#F0F6FC] text-xs rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-[#EF4444] focus:border-[#EF4444] placeholder:text-[#484F58] resize-y min-h-[48px] max-h-[140px]"})]}),e.jsxs("button",{onClick:de,disabled:!Z||b,className:"w-full h-9 rounded-lg font-bold text-xs bg-[#EF4444] hover:bg-[#DC2626] text-[#F0F6FC] transition-all disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[b?e.jsx(ue,{className:"w-3.5 h-3.5 animate-spin"}):null,"Confirm Group Loss"]})]}),Z&&q&&e.jsxs("div",{className:"bg-[#0D1117] rounded-lg px-3 py-2 border border-[#21262D] flex items-center justify-between",children:[e.jsx("p",{className:"text-[9px] text-[#484F58] uppercase tracking-wider font-semibold",children:"Group Total"}),e.jsxs("p",{className:`text-sm font-extrabold tabular-nums ${re>0?"text-[#22C55E]":"text-[#EF4444]"}`,children:[re>0?"+":"","$",le.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#21262D] space-y-2",children:[e.jsx("p",{className:"text-[9px] text-[#484F58] uppercase tracking-wider font-semibold",children:"Group Stats (All Eval Accounts)"}
1),e.jsxs("div",{className:"grid grid-cols-5 gap-2",children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-lg px-2.5 py-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-sm font-extrabold text-[#F0F6FC] tabular-nums",children:K.totalTrades}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Trades"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg px-2.5 py-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-sm font-extrabold text-[#22C55E] tabular-nums",children:K.wins}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Wins"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg px-2.5 py-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-sm font-extrabold text-[#EF4444] tabular-nums",children:K.losses}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Losses"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg px-2.5 py-2 border border-[#21262D] text-center",children:[e.jsxs("p",{className:`text-sm font-extrabold tabular-nums ${K.netPnl>0?"text-[#22C55E]":K.netPnl<0?"text-[#EF4444]":"text-[#8B949E]"}`,children:[K.netPnl>=0?"+":"","$",K.netPnl.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})]}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Net P&L"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg px-2.5 py-2 border border-[#21262D] text-center",children:[e.jsxs("p",{className:"text-sm font-extrabold text-[#F0F6FC] tabular-nums",children:[K.winRate.toFixed(0),"%"]}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Win Rate"})]})]})]})]})]})}const J=t=>t.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),At="vaulticks_fav_contracts",Ye=["MNQ","NQ","MES","ES"],ht="__all__",ft="__starred__";function ds(){try{const t=localStorage.getItem(At);if(!t)return Ye;const r=JSON.parse(t);return Array.isArray(r)?r.filter(m=>typeof m=="string"):Ye}catch{return Ye}}const cs=500;function xs(){const[t]=bt(),{accounts:r,loading:m,error:i,needsUpgrade:p,isFetching:h,refetch:d}=Pt(),{evalAccounts:j,flaggedIds:g,loading:x,error:w,needsUpgrade:k,isFetching:A,refetch:M}=jt({refetchInterval:3e4}),[N,v]=a.useState(""),b=m||x,B=h||A,y=p||k,T=N||i||w,[P,ee]=a.useState(!1),[z,V]=a.useState(null),[u,C]=a.useState(new Set),[F,o]=a.useState("MNQ"),[$,_]=a.useState(""),[U,Y]=a.useState(ds),[K,ae]=a.useState(!1),[ie,te]=a.useState(!1),ne=Number($)||0,Q=$!==""&&ne>0,se=me.find(l=>l.symbol===F)||me[1],de=l=>Y(n=>{const f=n.includes(l)?n.filter(L=>L!==l):[...n,l];try{localStorage.setItem(At,JSON.stringify(f))}catch{}return f}),ce=K?me:me.filter(l=>U.includes(l.symbol)||l.symbol===F),q=a.useCallback(async()=>{v(""),await Promise.all([d(),M()])},[d,M]),re=a.useCallback(async(l,n)=>{V(l),v("");try{await I.apiCall.invoke({url:"/api/v1/auto-eval/flag",method:"PUT",data:{tradovate_account_id:l,is_eval:n}}),await q()}catch(f){v((f==null?void 0:f.message)||"Failed to update eval flag")}finally{V(null)}},[q]),le=async()=>{var l;try{localStorage.setItem(Yt,"/evaluation");const n=await I.apiCall.invoke({url:"/api/v1/tradovate/auth/start",method:"GET"});(l=n==null?void 0:n.data)!=null&&l.authorize_url&&(window.location.href=n.data.authorize_url)}catch{}},Z=g.size>0,s=l=>C(n=>{const f=new Set(n);return f.has(l)?f.delete(l):f.add(l),f}),D=(()=>{const l=new Map;for(const f of j){const L=f.firm_name||"Unknown";l.has(L)||l.set(L,[]),l.get(L).push(f)}const n=[];for(const[f,L]of l.entries()){const W=[...L].sort((oe,X)=>oe.remaining_drawdown-X.remaining_drawdown);let O=0;for(;O<W.length;){let oe=O+1;for(;oe<W.length&&W[oe].remaining_drawdown-W[O].remaining_drawdown<=cs;)oe++;const X=W.slice(O,oe);X.length>=2?n.push({type:"group",key:`${f}:${X[0].tradovate_account_id}`,evs:X}):n.push({type:"single",ev:X[0]}),O=oe}}return n})(),S=[];for(const l of D)if(l.type==="single")S.push({kind:"card",ev:l.ev});else if(S.push({kind:"groupHeader",key:l.key,evs:l.evs}),u.has(l.key))for(const n of l.evs)S.push({kind:"card",ev:n});return y?e.jsx("div",{className:"p-6 lg:p-8 max-w-6xl mx-auto",children:e.jsxs("div",{className:"bg-[#161B22] rounded-xl p-10 border border-[#A855F7]/40 text-center space-y-4",children:[e.jsx(Ot,{className:"w-10 h-10 text-[#A855F7] mx-auto"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-[#F0F6FC]",children:"Auto Mode requires the Auto Mode plan"}),e.jsx("p",{className:"text-xs text-[#8B949E] mt-1 max-w-md mx-auto",children:"Self-tracking evaluations are part of the Auto Mode plan. Your current plan includes Manual Mode only."})]}),e.jsx("button",{onClick:()=>window.location.href="/pricing",className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-lg bg-[#22C55E] hover:bg-[#16A34A] text-black text-sm font-bold transition-colors",children:"Upgrade to Auto Mode"})]})}
1):e.jsxs("div",{className:"p-6 lg:p-8 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#8B5CF6]/15 flex items-center justify-center",children:e.jsx(Ce,{className:"w-5 h-5 text-[#8B5CF6]"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-extrabold text-[#F0F6FC] tracking-tight",children:"Evaluation Mode — Auto"}),e.jsx("p",{className:"text-sm text-[#8B949E]",children:"Your evals track themselves from live account data"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:le,title:"Connect or reconnect your brokerage",className:"flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-semibold text-[#8B949E] hover:text-[#F0F6FC] bg-[#161B22] border border-[#21262D] transition-colors",children:[e.jsx(nt,{className:"w-3.5 h-3.5"}),"Connect"]}),e.jsxs("button",{onClick:()=>q(),className:"flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-semibold text-[#8B949E] hover:text-[#F0F6FC] bg-[#161B22] border border-[#21262D] transition-colors",children:[e.jsx(Ct,{className:`w-3.5 h-3.5 ${B?"animate-spin":""}`}),"Refresh"]})]})]}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-3 flex flex-wrap items-center gap-2",children:[e.jsxs("select",{value:F,onChange:l=>{const n=l.target.value;if(n===ht){ae(!0);return}if(n===ft){ae(!1);return}o(n),ae(!1)},className:"px-2 py-1.5 rounded-lg text-xs font-bold bg-[#0D1117] border border-[#21262D] text-[#F0F6FC] focus:outline-none focus:border-[#22C55E]/50",children:[K&&e.jsx("option",{value:ft,children:"★ Starred only"}),ce.map(l=>e.jsxs("option",{value:l.symbol,children:[l.name," · $",l.dollarPerPoint,"/pt"]},l.symbol)),!K&&e.jsx("option",{value:ht,children:"All instruments…"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>te(l=>!l),title:"Choose favorite instruments","aria-label":"Choose favorite instruments",className:`p-1.5 rounded-lg border transition-colors ${ie?"text-[#F59E0B] border-[#F59E0B]/40 bg-[#F59E0B]/10":"text-[#8B949E] hover:text-[#F59E0B] bg-[#0D1117] border-[#21262D]"}`,children:e.jsx(rt,{className:`w-3.5 h-3.5 ${ie?"fill-current":""}`})}),ie&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>te(!1)}),e.jsxs("div",{className:"absolute left-0 top-full mt-2 z-50 w-60 bg-[#161B22] border border-[#21262D] rounded-xl shadow-2xl p-2 max-h-72 overflow-y-auto",children:[e.jsx("p",{className:"text-[10px] text-[#484F58] font-semibold uppercase tracking-wider px-2 py-1.5",children:"Favorite instruments"}),me.map(l=>{const n=U.includes(l.symbol);return e.jsxs("button",{onClick:()=>de(l.symbol),className:"w-full flex items-center justify-between gap-2 px-2 py-1.5 rounded-lg hover:bg-[#0D1117] transition-colors",children:[e.jsxs("span",{className:"text-xs font-semibold text-[#F0F6FC]",children:[l.name," ",e.jsxs("span",{className:"text-[#484F58] font-normal",children:["$",l.dollarPerPoint,"/pt"]})]}),e.jsx(rt,{className:`w-3.5 h-3.5 flex-shrink-0 ${n?"text-[#F59E0B] fill-current":"text-[#484F58]"}`})]},l.symbol)})]})]})]}),e.jsx("input",{type:"number",min:"0",step:"any",value:$,onChange:l=>_(l.target.value),placeholder:"Stop loss (points)",className:"w-40 px-3 py-1.5 rounded-lg text-xs font-bold bg-[#0D1117] border border-[#21262D] text-[#F0F6FC] placeholder:text-[#484F58] focus:outline-none focus:border-[#22C55E]/50"}),e.jsx("span",{className:"text-[10px] text-[#484F58] ml-auto hidden md:block",children:Q?"Position size shown on each eval card":"Enter a stop loss to size each eval"})]}),T&&e.jsx("div",{className:"bg-[#EF4444]/10 border border-[#EF4444]/30 rounded-lg px-4 py-3 text-sm text-[#EF4444]",children:T}),b&&r.length===0&&j.length===0?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(ue,{className:"w-6 h-6 text-[#8B5CF6] animate-spin"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] overflow-hidden",children:[e.jsx("button",{onClick:()=>ee(l=>!l),className:"w-full flex items-center justify-between px-5 py-3.5 text-left",children:e.jsxs("div",{className:"flex items-center gap-2",children:[Z?P?e.jsx(De,{className:"w-3.5 h-3.5 text-[#8B949E]"}):e.jsx(lt,{className:"w-3.5 h-3.5 text-[#8B949E]"}):null,e.jsx("span",{className:"text-sm font-bold text-[#F0F6FC]",children:Z?"Manage eval accounts":"Pick your eval accounts"}),e.jsxs("span",{className:"text-[10px] text-[#484F58] font-semibold",children:[g.size," flagged"]})]})}),(!Z||P)&&e.jsx("div",{className:"border-t border-[#21262D] divide-y divide-[#21262D]/60",children:r.length===0?e.jsxs("div",{className:"px-5 py-6 text-center space-y-3",children:[e.jsx("p",{className:"text-xs text-[#8B949E]",children:"No connected accounts yet — connect your brokerage to start tracking evals automatically."}),e.jsxs("button",{onClick:le,className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-lg bg-[#22C55E] hover:bg-[#16A34A] text-[#0D1117] text-sm font-bold transition-colors",children:[e.jsx(nt,{className:"w-4 h-4"}),"Connect Brokerage"]})]}):r.map(l=>{const n=g.has(l.tradovate_account_id),f=z===l.tradovate_account_id;return e.jsxs("div",{className:"flex items-center justify-between px-5 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold text-[#F0F6FC] truncate",children:Le(l.account_name,l.nickname,t)}),e.jsx("p",{className:"text-[10px] text-[#484F58]",children:l.organization_name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-[#484F58] font-semibold",children:"Eval account"}),e.jsx("button",{onClick:()=>re(l.tradovate_account_id,!n),disabled:f,className:`w-8 h-5 rounded-full transition-colors relative ${n?"bg-[#8B5CF6]/40":"bg-[#21262D]"} ${f?"opacity-60":""}`,"aria-label":"Toggle eval account",children:e.jsx("span",{className:`absolute top-0.5 w-4 h-4 rounded-full transition-all ${n?"left-3.5 bg-[#8B5CF6]":"left-0.5 bg-[#484F58]"}`})})]})]},l.tradovate_account_id)})})]}),j.length===0?e.jsxs("div",{className:"bg-[#161B22] rounded-xl p-10 border border-[#21262D] text-center space-y-3",children:[e.jsx(Ce,{className:"w-10 h-10 text-[#484F58] mx-auto"}),e.jsx("p",{className:"text-sm font-bold text-[#F0F6FC]",children:"No eval accounts yet — flag one above"}),e.jsx("p",{className:"text-xs text-[#8B949E] max-w-md mx-auto",children:"Flag the evaluation accounts you're trading and Vaulticks will track profit target progress, drawdown, trading days and consistency automatically."})]}):e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:S.map(l=>{if(l.kind==="groupHeader"){const O=l,oe=u.has(O.key),X=O.evs.map(G=>Math.max(0,G.remaining_drawdown)),ge=Math.min(...X),Be=Math.max(...X),Se=Math.min(...O.evs.map(G=>G.trading_days)),ke=O.evs.filter(G=>!!G.profit_target&&G.profit_target>0),je=ke.length>0?ke.reduce((G,$e)=>{const c=Math.max(0,G.profit_progress)/G.profit_target;return Math.max(0,$e.profit_progress)/$e.profit_target<c?$e:G}):null,Me=je?Math.min(100,Math.max(0,Math.max(0,je.profit_progress)/je.profit_target*100)):0,Ne=Math.min(...O.evs.map(G=>G.recommended_risk_per_trade)),Fe=O.evs.map(G=>G.max_contracts).filter(G=>typeof G=="number"&&G>=1),ye=Fe.length?Math.min(...Fe):null,xe=Q?st(Ne,ne,se,!1,void 0,ye,Math.min(...O.evs.map(G=>G.remaining_drawdown))):null;return e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-5 space-y-4",children:[e.jsxs("button",{onClick:()=>s(O.key),className:"w-full flex items-center justify-between text-left","aria-label":oe?"Collapse group":"Expand group",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[oe?e.jsx(De,{className:"w-3.5 h-3.5 text-[#8B949E] flex-shrink-0"}):e.jsx(lt,{className:"w-3.5 h-3.5 text-[#8B949E] flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-extrabold text-[#F0F6FC] truncate",children:[O.evs.length," accounts · similar drawdown"]}),e.jsx("p",{className:"text-[10px] text-[#484F58]",children:O.evs[0].firm_name})]})]}),e.jsxs("span",{className:"text-xs font-bold text-[#22C55E] font-mono whitespace-nowrap",children:["$",J(ge),"–$",J(Be)]})]}),je&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Profit target (lowe
1st of group)"}),e.jsxs("span",{className:"text-xs font-bold text-[#22C55E]",children:["$",J(Math.max(0,je.profit_progress))," of $",J(je.profit_target)," ·"," ",Math.round(Me),"%"]})]}),e.jsx("div",{className:"h-2 bg-[#21262D] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[#22C55E] transition-all duration-700 ease-out",style:{width:`${Me}%`}})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2.5 border border-[#21262D] text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx(ot,{className:"w-3 h-3 text-[#22C55E]"}),e.jsx("p",{className:"text-[9px] text-[#F0F6FC] uppercase tracking-wider font-semibold",children:"DD Range"})]}),e.jsxs("p",{className:"text-xs font-extrabold text-[#22C55E] font-mono mt-0.5",children:["$",J(ge),"–$",J(Be)]})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2.5 border border-[#21262D] text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx(Oe,{className:"w-3 h-3 text-[#3B82F6]"}),e.jsx("p",{className:"text-[9px] text-[#F0F6FC] uppercase tracking-wider font-semibold",children:"Days (min)"})]}),e.jsx("p",{className:"text-xs font-extrabold text-[#F0F6FC] font-mono mt-0.5",children:Se})]})]}),e.jsx("div",{className:"bg-[#0D1117] rounded-xl p-3 border border-[#F59E0B]/20",children:xe?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-[#F59E0B]"}),e.jsx("span",{className:"text-[11px] font-bold text-[#F0F6FC]",children:"Position size (group min)"})]}),e.jsxs("span",{className:`text-lg font-extrabold font-mono ${xe.safeToTrade?"text-[#22C55E]":xe.status==="tight"?"text-[#F59E0B]":"text-[#EF4444]"}`,children:["Take ",xe.maxContracts," ",xe.contractSymbol," each"]})]}),e.jsxs("p",{className:"text-[10px] text-[#484F58] mt-1",children:["risking $",J(Ne)]}),xe.firmCapped&&e.jsx("p",{className:"text-[10px] text-[#3B82F6] mt-0.5 font-semibold",children:"at the firm's max contract limit"}),xe.status==="tight"&&e.jsx("p",{className:"text-[10px] text-[#F59E0B] mt-0.5 font-semibold",children:"tight risk — exceeds the risk budget but fits the drawdown"}),!xe.safeToTrade&&xe.status!=="tight"&&e.jsx("p",{className:"text-[10px] text-[#EF4444] mt-0.5 font-semibold",children:"exceeds suggested risk — minimum size shown"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-[#F59E0B]"}),e.jsx("span",{className:"text-[11px] font-bold text-[#F0F6FC]",children:"Suggested risk per trade (group min)"})]}),e.jsxs("span",{className:"text-lg font-extrabold text-[#F59E0B] font-mono",children:["$",J(Ne)]})]}),e.jsx("p",{className:"text-[10px] text-[#484F58] mt-1",children:"Lowest suggested risk across the group. Enter a stop loss to size it."})]})})]},O.key)}const n=l.ev,f=!!n.profit_target&&n.profit_target>0,L=Q?st(n.recommended_risk_per_trade,ne,se,!1,void 0,n.max_contracts,n.remaining_drawdown):null,W=f?Math.min(100,Math.max(0,Math.max(0,n.profit_progress)/n.profit_target*100)):0;return e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-extrabold text-[#F0F6FC] truncate",children:Le(n.account_name,n.nickname,t)}),e.jsxs("p",{className:"text-[10px] text-[#484F58]",children:[n.firm_name," · starts at $",J(n.starting_balance)]})]}),e.jsxs("span",{className:"text-xs font-bold text-[#F0F6FC] font-mono",children:["$",J(n.equity)]})]}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Profit target"}),e.jsxs("span",{className:"text-xs font-bold text-[#22C55E]",children:["$",J(Math.max(0,n.profit_progress))," of $",J(n.profit_target)," ·"," ",Math.round(n.pct_to_target??W),"%"]})]}),e.jsx("div",{className:"h-2 bg-[#21262D] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[#22C55E] transition-all duration-700 ease-out",style:{width:`${W}%`}})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2.5 border border-[#21262D] text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx(ot,{className:"w-3 h-3 text-[#22C55E]"}),e.jsx("p",{className:"text-[9px] text-[#F0F6FC] uppercase tracking-wider font-semibold",children:"DD Left"})]}),e.jsxs("p",{className:"text-xs font-extrabold text-[#22C55E] font-mono mt-0.5",children:["$",J(n.remaining_drawdown)]})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2.5 border border-[#21262D] text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx(Oe,{className:"w-3 h-3 text-[#3B82F6]"}),e.jsx("p",{className:"text-[9px] text-[#F0F6FC] uppercase tracking-wider font-semibold",children:"Days"})]}),e.jsx("p",{className:"text-xs font-extrabold text-[#F0F6FC] font-mono mt-0.5",children:n.trading_days})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2.5 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-[9px] text-[#F0F6FC] uppercase tracking-wider font-semibold mt-0.5",children:"Consistency"}),n.consistency_rule_pct?n.best_day_share_pct!==null?e.jsxs("p",{className:`text-xs font-extrabold font-mono mt-0.5 ${n.consistency_violated?"text-[#EF4444]":"text-[#F0F6FC]"}`,title:`Best day $${J(n.best_day_pnl??0)} of $${J(n.total_profit)} total (max ${n.consistency_rule_pct}%)`,children:[n.best_day_share_pct,"% / ",n.consistency_rule_pct,"%"]}):e.jsx("p",{className:"text-xs font-extrabold text-[#484F58] font-mono mt-0.5",children:"—"}):e.jsx("p",{className:"text-xs font-extrabold text-[#484F58] font-mono mt-0.5",children:"none"})]})]}),n.consistency_violated&&e.jsxs("p",{className:"text-[10px] text-[#EF4444] font-semibold",children:["Consistency rule violated — your best day is"," ",n.best_day_share_pct,"% of total profit (max"," ",n.consistency_rule_pct,"%)."]}),e.jsx("div",{className:"bg-[#0D1117] rounded-xl p-3 border border-[#F59E0B]/20",children:L?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-[#F59E0B]"}),e.jsx("span",{className:"text-[11px] font-bold text-[#F0F6FC]",children:"Position size"})]}),e.jsxs("span",{className:`text-lg font-extrabold font-mono ${L.safeToTrade?"text-[#22C55E]":L.status==="tight"?"text-[#F59E0B]":"text-[#EF4444]"}`,children:["Take ",L.maxContracts," ",L.contractSymbol]})]}),e.jsxs("p",{className:"text-[10px] text-[#484F58] mt-1",children:["risking $",J(n.recommended_risk_per_trade)]}),L.firmCapped&&e.jsx("p",{className:"text-[10px] text-[#3B82F6] mt-0.5 font-semibold",children:"at the firm's max contract limit"}),L.status==="tight"&&e.jsx("p",{className:"text-[10px] text-[#F59E0B] mt-0.5 font-semibold",children:"tight risk — exceeds the risk budget but fits the drawdown"}),!L.safeToTrade&&L.status!=="tight"&&e.jsx("p",{className:"text-[10px] text-[#EF4444] mt-0.5 font-semibold",children:"exceeds suggested risk — minimum size shown"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-[#F59E0B]"}),e.jsx("span",{className:"text-[11px] font-bold text-[#F0F6FC]",children:"Suggested risk per trade"})]}),e.jsxs("span",{className:"text-lg font-extrabold text-[#F59E0B] font-mono",children:["$",J(n.recommended_risk_per_trade)]})]}),e.jsxs("p",{className:"text-[10px] text-[#484F58] mt-1",children:["Based on your $",J(n.remaining_drawdown)," ","remaining drawdown — same sizing model as Manual Evaluation Mode. Enter a stop loss to size it."]})]})})]}):e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-4 border border-[#F59E0B]/20 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"w-3.5 h-3.5 text-[#F59E0B]"}),e.jsx("p",{className:"text-xs font-bold text-[#F59E0B]",children:"No profit target on file — funded account?"})]}),e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"This firm rule has no evaluation profit target. Funded accounts belong on the Dashboard, not in Evaluation Mode."}),e.jsx("button",{onClick:()=>re(n.tradovate_account_id,!1),disabled:z===n.tradovate_account_id,className:"text-[10px] font-bold text-[#8B949E] hover:text-[#F0F6FC] border border-[#21262D] hover:border-[#30363D] rounded-md px-2 py-1 transition-colors disabled:opacity-60",children:"Unflag this account"})]})]},n.tradovate_account_id)})}),e.jsx("p",{className:"text-center text-[#30363D] text-[10px]",children:"Live data from your connected brokerage. For educational purposes only — always verify with your prop firm."})]})]})}const Ae=t=>
1t.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),ms=t=>new Date(`${t}T00:00:00`).toLocaleDateString(void 0,{month:"short",day:"numeric"});function ps(){const{days:t,loading:r}=Tt(),{evalAccounts:m,loading:i}=jt(),p=r||i,[h]=bt(),[d,j]=a.useState("all"),[g,x]=a.useState(()=>{const u=new Date;return{year:u.getFullYear(),month:u.getMonth()}}),w=qt(),k=a.useMemo(()=>t.map(u=>({...u,accounts:u.accounts.filter(C=>C.is_eval)})),[t]),A=a.useMemo(()=>k.some(u=>u.accounts.length>0),[k]),M=a.useMemo(()=>{const u=new Map;for(const C of k)for(const F of C.accounts)u.has(F.tradovate_account_id)||u.set(F.tradovate_account_id,{name:F.account_name,nickname:F.nickname??null});return Array.from(u.entries()).map(([C,F])=>({id:String(C),name:F.name,nickname:F.nickname})).sort((C,F)=>(C.nickname||C.name).localeCompare(F.nickname||F.name))},[k]),N=a.useMemo(()=>[...k].sort((u,C)=>u.date.localeCompare(C.date)),[k]),v=a.useMemo(()=>mt(N,d),[N,d]),b=`${g.year}-${String(g.month+1).padStart(2,"0")}`,B=a.useMemo(()=>mt(N.filter(u=>u.date.startsWith(b)),d),[N,d,b]),y=new Date(g.year,g.month,1).toLocaleDateString(void 0,{month:"long",year:"numeric"}),T=u=>{const C=v.accountMeta.get(u);return C?Le(C.name,C.nickname,h):`Account ${u}`},P=a.useMemo(()=>{const u=new Map;for(const C of k){const F=d==="all"?C.accounts:C.accounts.filter(_=>String(_.tradovate_account_id)===d);if(F.length===0)continue;let o=0,$=0;for(const _ of F)_.pnl!==null&&(o+=_.pnl,$+=1);u.set(C.date,{pnl:o,baselineOnly:$===0})}return u},[k,d]),ee=a.useMemo(()=>{const u=new Date(g.year,g.month,1),C=new Date(g.year,g.month+1,0).getDate(),F=Array(u.getDay()).fill(null);for(let o=1;o<=C;o++)F.push(`${g.year}-${String(g.month+1).padStart(2,"0")}-${String(o).padStart(2,"0")}`);return F},[g]),z=a.useMemo(()=>{let u=0;return P.forEach((C,F)=>{F.startsWith(b)&&(u+=C.pnl)}),u},[P,b]),V=u=>x(C=>{const F=new Date(C.year,C.month+u,1);return{year:F.getFullYear(),month:F.getMonth()}});return p?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(ue,{className:"w-5 h-5 text-[#22C55E] animate-spin"})}):m.length===0&&!A?null:e.jsxs("div",{className:"space-y-6",children:[m.length>0&&e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:m.map(u=>{const C=u.profit_target,F=!!C&&C>0,o=u.profit_progress,$=F?Math.max(0,C-o):0,_=F?Math.min(100,Math.max(0,o/C*100)):0;return e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-[#F0F6FC] truncate",children:Le(u.account_name,u.nickname??null,h)}),e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:u.firm_name})]}),e.jsx(Ce,{className:"w-4 h-4 text-[#22C55E] flex-shrink-0"})]}),F?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsxs("span",{className:"text-lg font-extrabold tabular-nums text-[#F0F6FC]",children:["$",Ae(o)]}),e.jsxs("span",{className:"text-[10px] text-[#8B949E]",children:["of $",Ae(C)]})]}),e.jsx("div",{className:"w-full h-1.5 rounded-full bg-[#0D1117] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[#22C55E]",style:{width:`${_}%`}})}),e.jsxs("div",{className:"flex justify-between text-[10px]",children:[e.jsxs("span",{className:"text-[#8B949E]",children:["$",Ae($)," to target"]}),e.jsxs("span",{className:"text-[#8B949E]",children:[_.toFixed(0),"%"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsxs("span",{className:"text-lg font-extrabold tabular-nums text-[#F0F6FC]",children:["$",Ae(o)]}),e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:"cumulative P&L"})]}),e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"No profit target — this program funds without one."})]})]},u.tradovate_account_id)})}),A&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-[#F0F6FC]",children:"Evaluation Journal"}),e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"Written automatically from your flagged eval accounts."})]}),M.length>0&&e.jsxs("select",{value:d,onChange:u=>j(u.target.value),className:"bg-[#161B22] border border-[#21262D] text-[#F0F6FC] text-sm rounded-lg px-3 py-2 focus:outline-none focus:ring-1 focus:ring-[#22C55E]",children:[e.jsx("option",{value:"all",children:"All Eval Accounts"}),M.map(u=>e.jsx("option",{value:u.id,children:Le(u.name,u.nickname,h)},u.id))]})]}),e.jsx(Jt,{points:v.points,accountIds:d==="all"?v.accountIds:[],accountLabel:T,liveDate:w,monthPoints:B.points,monthLabel:y,periodStorageKey:"vaulticks_equity_period_eval"}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-3 border-b border-[#21262D] flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>V(-1),className:"w-7 h-7 rounded-md text-[#8B949E] hover:text-[#F0F6FC] hover:bg-[#21262D] transition-colors",children:"‹"}),e.jsx("span",{className:"text-sm font-bold text-[#F0F6FC] min-w-[150px] text-center",children:y}),e.jsx("button",{onClick:()=>V(1),className:"w-7 h-7 rounded-md text-[#8B949E] hover:text-[#F0F6FC] hover:bg-[#21262D] transition-colors",children:"›"})]}),e.jsxs("span",{className:`text-sm font-bold tabular-nums ${z>0?"text-[#22C55E]":z<0?"text-[#EF4444]":"text-[#8B949E]"}`,children:[z>=0?"+":"","$",Ae(z)]})]}),e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"grid grid-cols-7 gap-1.5",children:[["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(u=>e.jsx("div",{className:"text-center text-[11px] font-bold text-[#F0F6FC] uppercase tracking-wider py-1",children:u},u)),ee.map((u,C)=>{if(!u)return e.jsx("div",{},`pad-${C}`);const F=P.get(u),$=u===w?"border-[#58A6FF] bg-[#58A6FF]/10 text-[#58A6FF]":!F||F.baselineOnly?"border-[#21262D] text-[#8B949E]":F.pnl>0?"border-[#22C55E]/25 bg-[#22C55E]/10 text-[#22C55E]":F.pnl<0?"border-[#
1EF4444]/25 bg-[#EF4444]/10 text-[#EF4444]":"border-[#21262D] text-[#8B949E]";return e.jsxs("div",{className:`aspect-square rounded-lg border p-1.5 flex flex-col justify-between ${$}`,title:ms(u),children:[e.jsx("span",{className:"text-[10px] font-semibold",children:Number(u.slice(-2))}),F&&!F.baselineOnly&&e.jsxs("span",{className:"text-[9px] font-bold tabular-nums truncate",children:[F.pnl>=0?"+":"",Math.round(F.pnl).toLocaleString()]})]},u)})]})})]})]})]})}const us=["Apex","Lucid","Tradeify","Alpha Futures","Take Profit Trader","MyFundedFutures","Topstep","E8"],hs=["25K","50K","100K","150K","250K","300K","Custom"],Is={"25K":1500,"50K":2e3,"100K":3e3,"150K":4e3,"250K":6500,"300K":7500},fs=["Phase 1","Phase 2","Evaluation","Custom"];function fe(t,r){return r===0?0:Math.min(100,Math.round(t/r*100))}function gs(t){return t>=85?"text-[#22C55E]":t>=60?"text-[#F59E0B]":"text-[#EF4444]"}function bs(t){if(!t)return"Never";const r=new Date(t),i=new Date().getTime()-r.getTime(),p=Math.floor(i/6e4);if(p<1)return"Just now";if(p<60)return`${p}m ago`;const h=Math.floor(p/60);if(h<24)return`${h}h ago`;const d=Math.floor(h/24);return d<30?`${d}d ago`:r.toLocaleDateString()}function gt(t){if(t.length===0)return!0;const r=Xe();return!t.some(m=>{var i;return(m.trade_date||((i=m.trade_timestamp)==null?void 0:i.split("T")[0]))===r})}const et={green:{border:"border-[#22C55E]/40",bg:"bg-[#22C55E]/10",text:"text-[#22C55E]",glow:"shadow-[#22C55E]/5"},yellow:{border:"border-[#F59E0B]/40",bg:"bg-[#F59E0B]/10",text:"text-[#F59E0B]",glow:"shadow-[#F59E0B]/5"}
1,red:{border:"border-[#EF4444]/40",bg:"bg-[#EF4444]/10",text:"text-[#EF4444]",glow:"shadow-[#EF4444]/5"}};function Lt({health:t,label:r,reason:m}){const i=et[t];return e.jsxs("div",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg border ${i.border} ${i.bg}`,title:m,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${t==="green"?"bg-[#22C55E]":t==="yellow"?"bg-[#F59E0B]":"bg-[#EF4444]"} animate-pulse`}),e.jsx("span",{className:`text-[10px] font-bold ${i.text}`,children:r})]})}function js({severity:t}){return t==="danger"?e.jsx("span",{className:"text-[#EF4444]",children:"●"}):t==="warning"?e.jsx("span",{className:"text-[#F59E0B]",children:"●"}):e.jsx("span",{className:"text-[#3B82F6]",children:"●"})}function ws({analysis:t,account:r}){const[m,i]=a.useState(["NQ","ES"]),[p,h]=a.useState("NQ"),[d,j]=a.useState(0),[g,x]=a.useState(!1),[w,k]=a.useState(!1),A=me.filter(b=>m.includes(b.symbol));function M(b){if(m.includes(b)){if(m.length<=1)return;const B=m.filter(y=>y!==b);i(B),b===p&&h(B[0])}else i([...m,b])}const N=a.useMemo(()=>We(r,p,d),[r,p,d]),v=N.positionSizing;return e.jsxs("div",{className:"border-t border-[#21262D] pt-3 space-y-3",children:[e.jsxs("button",{onClick:()=>x(!g),className:"flex items-center justify-between w-full text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-[#F59E0B]"}),e.jsx("span",{className:"text-[11px] font-bold text-[#F0F6FC]",children:"Eval Position Sizing"}),e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#F59E0B]/10 text-[#F59E0B] font-bold border border-[#F59E0B]/20",children:["$",Math.round(N.drawdownRemaining*N.aggressivenessMultiplier*.22).toLocaleString()]})]}),g?e.jsx(xt,{className:"w-3.5 h-3.5 text-[#484F58]"}):e.jsx(De,{className:"w-3.5 h-3.5 text-[#484F58]"})]}),g&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-[10px] text-[#484F58]",children:"Risk Budget"}),e.jsxs("p",{className:"text-sm font-extrabold text-[#F59E0B]",children:["$",Math.round(N.drawdownRemaining*N.aggressivenessMultiplier*.22).toLocaleString()]})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-[10px] text-[#484F58]",children:"Profit Left"}),e.jsxs("p",{className:"text-sm font-extrabold text-[#3B82F6]",children:["$",Math.round(N.profitRemaining).toLocaleString()]})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-[10px] text-[#484F58]",children:"DD Left"}),e.jsxs("p",{className:"text-sm font-extrabold text-[#22C55E]",children:["$",Math.round(N.drawdownRemaining).toLocaleString()]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-[9px] text-[#484F58] uppercase tracking-wider font-semibold",children:"Contracts"}),e.jsxs("button",{onClick:()=>k(!w),className:"inline-flex items-center gap-1 text-[10px] font-bold text-[#F59E0B] hover:text-[#FBBF24] transition-colors",children:[e.jsx(Gt,{className:"w-3 h-3"}),w?"Done":"Filter",w?e.jsx(xt,{className:"w-3 h-3"}):e.jsx(De,{className:"w-3 h-3"})]})]}),w&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[9px] text-[#484F58]",children:"Check the contracts you trade. Only checked ones appear below."}),e.jsx("div",{className:"grid grid-cols-2 gap-1",children:me.map(b=>{const B=m.includes(b.symbol);return e.jsxs("button",{onClick:()=>M(b.symbol),className:"flex items-center gap-1.5 px-2 py-1.5 rounded-lg border text-left transition-all "+(B?"bg-[#22C55E]/10 border-[#22C55E]/30 hover:bg-[#22C55E]/15":"bg-[#0D1117] border-[#30363D] hover:border-[#484F58] hover:bg-[#161B22]"),children:[e.jsx("div",{className:"w-3.5 h-3.5 rounded flex items-center justify-center flex-shrink-0 "+(B?"bg-[#22C55E] text-[#0D1117]":"border border-[#30363D]"),children:B&&e.jsx(Ht,{className:"w-2.5 h-2.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] font-bold truncate "+(B?"text-[#F0F6FC]":"text-[#8B949E]"),children:b.name}),e.jsxs("p",{className:"text-[8px] text-[#484F58]",children:["$",b.dollarPerPoint,"/pt"]})]})]},b.symbol)})})]}),!w&&e.jsx("div",{className:"space-y-1",children:A.map(b=>{const B=b.symbol===p;return e.jsxs("button",{onClick:()=>h(b.symbol),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-lg border text-left transition-all "+(B?"bg-[#F59E0B]/10 border-[#F59E0B]/30":"bg-[#0D1117] border-[#21262D] hover:border-[#30363D] hover:bg-[#0D1117]/80"),children:[e.jsx("div",{className:"w-3.5 h-3.5 rounded-full border-2 flex items-center justify-center flex-shrink-0 "+(B?"border-[#F59E0B]":"border-[#30363D]"),children:B&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#F59E0B]"})}),e.jsx("div",{className:"w-6 h-6 rounded flex items-center justify-center text-[8px] font-extrabold bg-[#F59E0B]/15 text-[#F59E0B] flex-shrink-0",children:b.symbol}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[10px] font-bold text-[#F0F6FC] truncate",children:b.name}),e.jsxs("p",{className:"text-[8px] text-[#484F58]",children:["$",b.dollarPerPoint.toLocaleStr
1ing(),"/pt"]})]})]},b.symbol)})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[9px] text-[#484F58] uppercase tracking-wider font-semibold mb-1 block",children:"Stop Loss (pts)"}),e.jsx(ve,{value:d,onValueChange:j,fallback:0,min:0,placeholder:"e.g. 10",className:"w-full px-2 py-1.5 rounded-lg bg-[#0D1117] border border-[#21262D] text-xs text-[#F0F6FC] placeholder-[#484F58] focus:border-[#F59E0B] focus:outline-none"})]})]}),v&&d>0?e.jsxs("div",{className:"bg-[#0D1117] rounded-xl p-3 border border-[#F59E0B]/20 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:"Max Contracts"}),e.jsxs("span",{className:"text-lg font-extrabold text-[#F59E0B]",children:[v.maxContracts,v.firmCapped&&e.jsx("span",{className:"ml-1 text-[9px] text-[#3B82F6] font-semibold",children:"(firm limit)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:"Contract"}),e.jsxs("span",{className:"text-xs font-bold text-[#F0F6FC]",children:[v.contract.name,v.autoMicro&&e.jsx("span",{className:"ml-1 text-[9px] text-[#F59E0B]",children:"(auto-micro)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:"Risk/Trade"}),e.jsxs("span",{className:"text-xs font-bold text-[#F0F6FC]",children:["$",v.riskPerTrade.toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:"Risk/DD"}),e.jsxs("span",{className:"text-xs font-bold text-[#F0F6FC]",children:["$",v.riskPerTrade.toLocaleString()," of $",Math.round(N.drawdownRemaining).toLocaleString()]})]}),v.requiredStop>0&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:"Max Stop for 1"}),e.jsxs("span",{className:"text-xs font-bold text-[#8B949E]",children:[v.requiredStop," pts"]})]})]}):d>0?e.jsx("div",{className:"bg-[#0D1117] rounded-xl p-3 border border-[#21262D] text-center",children:e.jsx("p",{className:"text-xs text-[#484F58]",children:"Insufficient drawdown for position sizing"})}):e.jsx("div",{className:"bg-[#0D1117] rounded-xl p-3 border border-[#21262D] text-center",children:e.jsx("p",{className:"text-xs text-[#484F58]",children:"Enter a stop loss to calculate position size"})})]})]})}function Ns(){return e.jsxs("div",{className:"absolute inset-0 z-20 backdrop-blur-sm bg-[#0D1117]/70 rounded-xl flex flex-col items-center justify-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[#F59E0B]/15 flex items-center justify-center",children:e.jsx(Kt,{className:"w-8 h-8 text-[#F59E0B]"})}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("h3",{className:"text-lg font-bold text-[#F0F6FC]",children:"Auto Mode Feature"}),e.jsx("p",{className:"text-sm text-[#8B949E] max-w-xs",children:"Evaluation Mode tracking is available on the Auto Mode plan ($69/mo)."})]}),e.jsxs("button",{className:"flex items-center gap-2 px-6 py-2.5 rounded-lg bg-gradient-to-r from-[#F59E0B] to-[#D97706] text-[#0D1117] font-bold text-sm hover:opacity-90 transition-opacity",children:[e.jsx(Bt,{className:"w-4 h-4"}),"Upgrade to Auto Mode"]})]})}function Ze({value:t,max:r,color:m="#22C55E",label:i,sublabel:p}){const h=fe(t,r);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:i}),e.jsxs("span",{className:"text-xs font-bold",style:{color:m},children:[h,"%",p?` · ${p}`:""]})]}),e.jsx("div",{className:"h-2 bg-[#21262D] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 ease-out",style:{width:`${h}%`,backgroundColor:m}})})]})}function vs({isOpen:t,onClose:r,firmName:m,accountSize:i,planType:p}){const[h,d]=a.useState([]),[j,g]=a.useState(!0);return a.useEffect(()=>{t&&(g(!0),I.apiCall.invoke({url:"/api/v1/eval-rules/versions",method:"GET",data:{firm_name:m,account_size:i,plan_type:p}}).then(x=>{var w;d(((w=x.data)==null?void 0:w.versions)||[])}).catch(()=>d([])).finally(()=>g(!1)))},[t,m,i,p]),t?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-[#161B22] rounded-2xl border border-[#21262D] w-full max-w-lg max-h-[80vh] overflow-hidden shadow-2xl flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b border-[#21262D]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-[#3B82F6]/15 flex items-center justify-center",children:e.jsx(Qe,{className:"w-4 h-4 text-[#3B82F6]"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-[#F0F6FC]",children:"Version History"}),e.jsxs("p",{className:"text-xs text-[#8B949E]",children:[m," · ",i," · ",p]})]})]}),e.jsx("button",{onClick:r,className:"p-2 rounded-lg hover:bg-[#21262D] text-[#8B949E] hover:text-[#F0F6FC] transition-colors",children:e.jsx(we,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-5 space-y-3",children:j?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(ue,{className:"w-5 h-5 animate-spin text-[#3B82F6]"}),e.jsx("span",{className:"ml-2 text-sm text-[#8B949E]",children:"Loading versions..."})]}):h.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(Qe,{className:"w-8 h-8 text-[#30363D] mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-[#8B949E]",children:"No version history yet."}),e.jsx("p",{className:"text-xs text-[#484F58] mt-1",children:"Versions are created when rules are refreshed."})]}):h.map((x,w)=>{var k,A,M;return e.jsxs("div",{className:`bg-[#0D1117] rounded-xl p-4 border ${w===0?"border-[#3B82F6]/30":"border-[#21262D]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[w===0&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#3B82F6]/15 text-[#3B82F6] font-bold border border-[#3B82F6]/30",children:"LATEST"}),e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:x.verified_at?new Date(x.verified_at).toLocaleStr
1ing():"N/A"})]}),x.ai_confidence&&e.jsx("span",{className:`text-[10px] font-bold ${x.ai_confidence==="high"?"text-[#22C55E]":x.ai_confidence==="medium"?"text-[#F59E0B]":"text-[#EF4444]"}`,children:x.ai_confidence.toUpperCase()})]}),x.version_note&&e.jsx("p",{className:"text-xs text-[#F0F6FC] mb-2 font-medium",children:x.version_note}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[#484F58]",children:"Target:"})," ",e.jsxs("span",{className:"text-[#8B949E]",children:["$",((k=x.profit_target)==null?void 0:k.toLocaleString())||0]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#484F58]",children:"Drawdown:"})," ",e.jsxs("span",{className:"text-[#8B949E]",children:["$",((A=x.max_drawdown)==null?void 0:A.toLocaleString())||0]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#484F58]",children:"Daily:"})," ",e.jsxs("span",{className:"text-[#8B949E]",children:["$",((M=x.daily_loss_limit)==null?void 0:M.toLocaleString())||0]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#484F58]",children:"Min Days:"})," ",e.jsx("span",{className:"text-[#8B949E]",children:x.min_trading_days||0})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#484F58]",children:"Limit:"})," ",e.jsxs("span",{className:"text-[#8B949E]",children:[x.time_limit_days||"∞"," days"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[#484F58]",children:"Consistency:"})," ",e.jsxs("span",{className:"text-[#8B949E]",children:[x.consistency_pct||0,"%"]})]})]})]},x.id)})})]})}):null}function Fs({isOpen:t,onClose:r,firmName:m,accountSize:i,planType:p,onFlagged:h}){const{toast:d}=Pe(),[j,g]=a.useState(""),[x,w]=a.useState(!1),k=async()=>{var A,M,N;w(!0);try{const b=(await I.apiCall.invoke({url:"/api/v1/eval-rules/flag",method:"POST",data:{firm_name:m,account_size:i,plan_type:p,reason:j.trim()}})).data;d({title:"Flagged",description:b.message}),h(),g(""),r()}catch(v){const b=((A=v==null?void 0:v.data)==null?void 0:A.detail)||((N=(M=v==null?void 0:v.response)==null?void 0:M.data)==null?void 0:N.detail)||(v==null?void 0:v.message)||"Failed to flag";d({title:"Error",description:b,variant:"destructive"})}finally{w(!1)}};return t?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-[#161B22] rounded-2xl border border-[#21262D] w-full max-w-md 
1shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b border-[#21262D]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-[#F59E0B]/15 flex items-center justify-center",children:e.jsx(Je,{className:"w-4 h-4 text-[#F59E0B]"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-[#F0F6FC]",children:"Report Outdated Rules"}),e.jsxs("p",{className:"text-xs text-[#8B949E]",children:[m," · ",i," · ",p]})]})]}),e.jsx("button",{onClick:r,className:"p-2 rounded-lg hover:bg-[#21262D] text-[#8B949E] hover:text-[#F0F6FC] transition-colors",children:e.jsx(we,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-[#8B949E]",children:"If you believe the rules for this evaluation are outdated or incorrect, flag them for review. When 3 or more users flag the same rule set, it will be added to the admin review queue."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-semibold text-[#F0F6FC]",children:["Reason ",e.jsx("span",{className:"text-[#484F58]",children:"(optional)"})]}),e.jsx("textarea",{value:j,onChange:A=>g(A.target.value),placeholder:"e.g. Profit target was recently changed to $4,000...",rows:3,className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] placeholder-[#484F58] focus:border-[#F59E0B] focus:outline-none resize-none"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:r,className:"flex-1 px-4 py-2.5 rounded-xl border border-[#21262D] text-sm font-medium text-[#8B949E] hover:bg-[#21262D] transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:k,disabled:x,className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-[#F59E0B]/15 border border-[#F59E0B]/30 text-[#F59E0B] font-bold text-sm hover:bg-[#F59E0B]/25 transition-colors",children:[x?e.jsx(ue,{className:"w-4 h-4 animate-spin"}):e.jsx(Je,{className:"w-4 h-4"}),x?"Submitting...":"Flag as Outdated"]})]})]})]})}):null}function Te({account:t,trades:r,onDelete:m,onTradeLogged:i}){const{toast:p}=Pe(),h=t.status==="passed",d=a.useMemo(()=>Ke(r),[r]),j=d.netPnl,g=a.useMemo(()=>Qt(t.account_size),[t.account_size]),x=a.useMemo(()=>{const c=[...r].sort((H,R)=>{const pe=H.trade_timestamp||H.created_at||"",be=R.trade_timestamp||R.created_at||"";return pe.localeCompare(be)}),E=t.eod_current_floor??g-t.max_drawdown;return Zt(g,t.max_drawdown,c.map(H=>({pnl:H.pnl})),t.trailing_drawdown_override??null,E)},[g,t.max_drawdown,r,t.trailing_drawdown_override,t.eod_current_floor]),w=Math.max(0,t.max_drawdown-x.drawdownRemaining),k=fe(Math.max(0,j),t.profit_target),A=(t.time_limit_days||0)-(t.days_used||0),[M,N]=a.useState(!1),[v,b]=a.useState(""),B=async c=>{const H=(t.eod_highest_balance??g)-c,R=g-c,pe=Math.max(R,H);await I.entities.eval_accounts.update({id:String(t.id),data:{max_drawdown:c,eod_max_drawdown_amount:c,eod_current_floor:pe,trailing_drawdown_override:null}}),p({title:"Max Drawdown updated",description:`Set to $${c.toLocaleString()} — all displays synced.`}),i()},y=t.eod_max_drawdown_amount??t.max_drawdown,T=t.eod_highest_balance??g,P=t.eod_current_floor??g-y,ee=t.eod_cutoff_time??"16:59",z=g+d.netPnl,V=Math.max(0,z-P),u=async()=>{t.eod_max_drawdown_amount||await I.entities.eval_accounts.update({id:String(t.id),data:{eod_highest_balance:g,eod_current_floor:g-y,eod_max_drawdown_amount:y,last_eod_processed_date:null}})},C=a.useRef(!1);a.useEffect(()=>{if((t.drawdown_type||"eod_trailing")==="eod_trailing"&&!C.current&&t.eod_max_drawdown_amount!=null&&t.eod_max_drawdown_amount!==t.max_drawdown){const E=(t.eod_highest_balance??g)-t.max_drawdown,H=g-t.max_drawdown,R=Math.max(H,E);C.current=!0,I.entities.eval_accounts.update({id:String(t.id),data:{eod_max_drawdown_amount:t.max_drawdown,eod_current_floor:R,trailing_drawdown_override:null}}).then(()=>{p({title:"Drawdown Auto-Repaired",description:`Synced EOD max DD to $${t.max_drawdown.toLocaleString()}
1, floor to $${Math.round(R).toLocaleString()}`}),i()}).finally(()=>{setTimeout(()=>{C.current=!1},5e3)})}},[t.id,t.max_drawdown,t.eod_max_drawdown_amount]);const F=a.useRef(!1),o=a.useRef(null);a.useEffect(()=>{if((t.drawdown_type||"eod_trailing")!=="eod_trailing"||F.current)return;const c=[...r].sort((H,R)=>{const pe=H.trade_timestamp||H.created_at||"",be=R.trade_timestamp||R.created_at||"";return pe.localeCompare(be)}),E=as(P,T,y,g,c,t.last_eod_processed_date??null,ee);if(E&&E.daysProcessed>0){if(o.current===E.newProcessedDate)return;o.current=E.newProcessedDate,F.current=!0,I.entities.eval_accounts.update({id:String(t.id),data:{eod_current_floor:E.newFloor,eod_highest_balance:E.newHighestBalance,last_eod_processed_date:E.newProcessedDate}}).then(()=>{p({title:"EOD Auto-Processed",description:`Caught up ${E.daysProcessed} day${E.daysProcessed>1?"s":""}. Floor: $${Math.round(E.newFloor).toLocaleString()}`}),i()}).finally(()=>{setTimeout(()=>{F.current=!1},5e3)})}},[t.id,t.last_eod_processed_date,r.length]);const $=a.useMemo(()=>({...t,current_profit:Math.max(0,j),current_drawdown:Math.min(t.max_drawdown,w)}),[t,j,w]),_=a.useMemo(()=>We($),[$]),U=et[_.health],[Y,K]=a.useState(!1),[ae,ie]=a.useState(!1),[te,ne]=a.useState(""),[Q,se]=a.useState(""),[de,ce]=a.useState(""),[q,re]=a.useState(""),[le,Z]=a.useState(!1),s=r.length>0,D=r.length>0?r[0]:null,[S,l]=a.useState(!1),[n,f]=a.useState(null),L=async()=>{const c=parseFloat(te);if(!c||c<=0){p({title:"Invalid PnL",description:"Enter a positive dollar amount to log a win.",variant:"destructive"});return}Z(!0);try{if(await Ue({eval_account_id:t.id,pnl:c,result:"win",notes:de.trim()||""})){const H=Math.max(0,j+c),R=(t.trading_days_completed||0)+(gt(r)?1:0);if(H>=t.profit_target&&t.status!=="passed"){const pe=new Date().toISOString();await I.entities.eval_accounts.update({id:String(t.id),data:{current_profit:H,trading_days_completed:R,status:"passed",passed_at:pe}});let be=!1;try{await vt()&&(be=(await wt()).length>=Ft)}catch{be=!1}try{if(be)throw new Error("manual_limit");const he=await Nt({account_name:`${t.firm_name} – ${t.account_size} (Passed Eval)`,broker_name:t.firm_name,account_number:`eval_passed_${t.id}_${Date.now()}`,remaining_drawdown:t.max_drawdown,current_balance:t.max_drawdown,starting_balance:0,peak_balance:0});he!=null&&he.id&&(await I.entities.eval_accounts.update({id:String(t.id),data:{dashboard_account_id:he.id}}),f(he.id))}catch(he){(he==null?void 0:he.message)!=="manual_limit"&&console.error("Failed to create dashboard account:",he)}l(!0),be&&p({title:"Account limit reached",description:yt}),p({title:"🎉 EVALUATION PASSED!",description:be?`Congratulations! ${t.firm_name} ${t.account_size} passed.`:`Congratulations! ${t.firm_name} ${t.account_size} has been added to your Dashboard.`})}else await I.entities.eval_accounts.update({id:String(t.id),data:{current_profit:H,trading_days_completed:R}}),p({title:"Win logged!",description:`+$${c.toLocaleString()}`});await u(),i()}}catch(E){p({title:"Error",description:(E==null?void 0:E.message)||"Failed to log trade",variant:"destructive"})}finally{Z(!1),K(!1),ne(""),ce("")}},W=async()=>{const c=parseFloat(Q);if(!c||c<=0){p({title:"Invalid PnL",description:"Enter a positive dollar amount to log a loss.",variant:"destructive"});return}Z(!0);try{if(await Ue({eval_account_id:t.id,pnl:-c,result:"loss",notes:q.trim()||""})){const H=w+c;await I.entities.eval_accounts.update({id:String(t.id),data:{current_drawdown:Math.min(t.max_drawdown,H),trading_days_completed:(t.trading_days_completed||0)+(gt(r)?1:0)}}),p({title:"Loss logged",description:`-$${c.toLocaleString()}`}),await u(),i()}}catch(E){p({title:"Error",description:(E==null?void 0:E.message)||"Failed to log trade",variant:"destructive"})}finally{Z(!1),ie(!1),se(""),re("")}},O=async()=>{if(D){Z(!0);try{await St(D.id)&&(p({title:"Trade undone",description:`Removed ${D.result} ($${Math.abs(D.pnl).toLocaleString()})`}),i())}catch(c){p({title:"Error",description:(c==null?void 0:c.message)||"Failed to undo",variant:"destructive"})}finally{Z(!1)}}},[oe,X]=a.useState(!1),[ge,Be]=a.useState(!1),[Se,ke]=a.useState(!1),[je,Me]=a.useState(null),[Ne,Fe]=a.useState(0),[ye,xe]=a.useState(!1),G=a.useCallback(async()=>{try{const[c,E]=await Promise.all([I.apiCall.invoke({url:"/api/v1/eval-rules/last-verified",method:"GET",data:{firm_name:t.firm_name,account_size:t.account_size,plan_type:t.plan_type}}),I.apiCall.invoke({url:"/api/v1/eval-rules/flag-count",method:"GET",data:{firm_name:t.firm_name,account_size:t.account_size,plan_type:t.plan_type}})]),H=c.data,R=E.data;Me(H.verified_at||null),Fe(R.flag_count),xe(R.user_has_flagged)}catch{}},[t.firm_name,t.account_size,t.plan_type]);a.useEffect(()=>{G()},[G]);const $e=async()=>{var c,E,H;ke(!0);try{const pe=(await I.apiCall.invoke({url:"/api/v1/eval-rules/refresh",method:"POST",data:{firm_name:t.firm_name,account_size:t.account_size,plan_type:t.plan_type}})).data;
1Me(pe.verified_at),Fe(0),xe(!1),p({title:"Rules Refreshed",description:pe.version_note||"Rules have been re-verified with AI."})}catch(R){const pe=((c=R==null?void 0:R.data)==null?void 0:c.detail)||((H=(E=R==null?void 0:R.response)==null?void 0:E.data)==null?void 0:H.detail)||(R==null?void 0:R.message)||"Refresh failed";p({title:"Error",description:pe,variant:"destructive"})}finally{ke(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`bg-[#161B22] rounded-xl border p-5 space-y-4 transition-all shadow-lg ${U.border} ${U.glow}`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("h3",{className:"text-sm font-bold text-[#F0F6FC]",children:[t.firm_name," ",t.account_size]}),e.jsx(Lt,{health:_.health,label:_.healthLabel,reason:_.healthReason}),h&&e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-[#22C55E]/15 text-[#22C55E] font-bold border border-[#22C55E]/30",children:"PASSED ✓"})]}),e.jsx("span",{className:"text-xs text-[#8B949E]",children:t.plan_type})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("button",{onClick:()=>m(t.id),className:"p-1.5 rounded-lg hover:bg-[#21262D] text-[#8B949E] hover:text-[#EF4444] transition-colors",title:"Delete evaluation",children:e.jsx(Dt,{className:"w-3.5 h-3.5"})})})]}),e.jsx(Ze,{value:Math.max(0,j),max:t.profit_target,color:k>=100?"#22C55E":"#3B82F6",label:"Profit Target",sublabel:`$${Math.max(0,j).toLocaleString()} / $${t.profit_target.toLocaleString()}`}),(t.drawdown_type||"eod_trailing")==="eod_trailing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Remaining Drawdown"}),e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#F59E0B]/10 text-[#F59E0B] font-bold border border-[#F59E0B]/20",children:"EOD TRAILING"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs font-bold",style:{color:x.drawdownRemaining<t.max_drawdown*.3?"#EF4444":x.drawdownRemaining<t.max_drawdown*.6?"#F59E0B":"#22C55E"},children:["$",Math.round(x.drawdownRemaining).toLocaleString()," / $",t.max_drawdown.toLocaleString()]}),!M&&e.jsx("button",{onClick:()=>{b(String(Math.round(t.max_drawdown))),N(!0)},className:"p-1 rounded hover:bg-[#21262D] text-[#484F58] hover:text-[#F59E0B] transition-colors",title:"Edit max drawdown",children:e.jsx(Ve,{className:"w-3 h-3"})})]})]}),M?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:v,onChange:c=>b(c.target.value),className:"flex-1 px-2 py-1.5 rounded-lg bg-[#0D1117] border border-[#F59E0B]/50 text-xs text-[#F0F6FC] focus:outline-none focus:ring-1 focus:ring-[#F59E0B]",autoFocus:!0,onKeyDown:async c=>{if(c.key==="Enter"){const E=parseFloat(v);E>0&&await B(E),N(!1)}c.key==="Escape"&&N(!1)}}),e.jsx("button",{onClick:async()=>{const c=parseFloat(v);c>0&&await B(c),N(!1)},className:"px-2 py-1.5 rounded-lg text-[10px] font-bold bg-[#F59E0B]/15 border border-[#F59E0B]/30 text-[#F59E0B] hover:bg-[#F59E0B]/25 transition-colors",children:"Save"}),t.trailing_drawdown_override&&e.jsx("button",{onClick:async()=>{await B(t.max_drawdown),N(!1)},className:"px-2 py-1.5 rounded-lg text-[10px] font-bold bg-[#21262D] border border-[#30363D] text-[#8B949E] hover:text-[#F0F6FC] transition-colors",children:"Reset"}),e.jsx("button",{onClick:()=>N(!1),className:"p-1.5 rounded-lg hover:bg-[#21262D] text-[#484F58] hover:text-[#F0F6FC] transition-colors",children:e.jsx(we,{className:"w-3 h-3"})})]}):e.jsx("div",{className:"h-2 bg-[#21262D] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 ease-out",style:{width:`${fe(t.max_drawdown-x.drawdownRemaining,t.max_drawdown)}%`,backgroundColor:x.drawdownRemaining<t.max_drawdown*.3?"#EF4444":x.drawdownRemaining<t.max_drawdown*.6?"#F59E0B":"#22C55E"}})}),t.trailing_drawdown_override&&!M&&e.jsx("p",{className:"text-[9px] text-[#F59E0B]/70 italic",children:"Manual override active"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"EOD Trailing Drawdown"}),e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#58A6FF]/10 text-[#58A6FF] font-bold border border-[#58A6FF]/20",children:["FLOOR: $",Math.round(P).toLocaleStr
1ing()]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"text-xs font-bold",style:{color:V<y*.3?"#EF4444":V<y*.6?"#F59E0B":"#22C55E"},children:["$",Math.round(V).toLocaleString()," remaining"]})})]}),e.jsx("div",{className:"h-2 bg-[#21262D] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 ease-out",style:{width:`${Math.min(100,fe(y-V,y))}%`,backgroundColor:V<y*.3?"#EF4444":V<y*.6?"#F59E0B":"#22C55E"}})}),e.jsxs("div",{className:"flex items-center justify-between text-[9px] text-[#484F58]",children:[e.jsxs("span",{children:["Highest: $",Math.round(T).toLocaleString()]}),e.jsxs("span",{children:["Balance: $",Math.round(z).toLocaleString()]}),e.jsxs("span",{children:["Max DD: $",y.toLocaleString()]}),t.last_eod_processed_date&&e.jsxs("span",{children:["Last EOD: ",t.last_eod_processed_date]})]})]})]}),t.drawdown_type==="static"&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Remaining Drawdown"}),e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#8B5CF6]/10 text-[#8B5CF6] font-bold border border-[#8B5CF6]/20",children:"STATIC"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs font-bold",style:{color:(()=>{const c=g-t.max_drawdown,E=Math.max(0,x.currentBalance-c);return E<t.max_drawdown*.3?"#EF4444":E<t.max_drawdown*.6?"#F59E0B":"#22C55E"})()},children:["$",(()=>{const c=g-t.max_drawdown,E=Math.max(0,x.currentBalance-c);return Math.round(E).toLocaleString()})()," / $",t.max_drawdown.toLocaleString()]}),!M&&e.jsx("button",{onClick:()=>{b(String(Math.round(t.max_drawdown))),N(!0)},className:"p-1 rounded hover:bg-[#21262D] text-[#484F58] hover:text-[#8B5CF6] transition-colors",title:"Edit max drawdown",children:e.jsx(Ve,{className:"w-3 h-3"})})]})]}),M?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:v,onChange:c=>b(c.target.value),className:"flex-1 px-2 py-1.5 rounded-lg bg-[#0D1117] border border-[#8B5CF6]/50 text-xs text-[#F0F6FC] focus:outline-none focus:ring-1 focus:ring-[#8B5CF6]",autoFocus:!0,onKeyDown:async c=>{if(c.key==="Enter"){const E=parseFloat(v);E>0&&await B(E),N(!1)}c.key==="Escape"&&N(!1)}}),e.jsx("button",{onClick:async()=>{const c=parseFloat(v);c>0&&await B(c),N(!1)},className:"px-2 py-1.5 rounded-lg text-[10px] font-bold bg-[#8B5CF6]/15 border border-[#8B5CF6]/30 text-[#8B5CF6] hover:bg-[#8B5CF6]/25 transition-colors",children:"Save"}),t.trailing_drawdown_override&&e.jsx("button",{onClick:async()=>{await B(t.max_drawdown),N(!1)},className:"px-2 py-1.5 rounded-lg text-[10px] font-bold bg-[#21262D] border border-[#30363D] text-[#8B949E] hover:text-[#F0F6FC] transition-colors",children:"Reset"}),e.jsx("button",{onClick:()=>N(!1),className:"p-1.5 rounded-lg hover:bg-[#21262D] text-[#484F58] hover:text-[#F0F6FC] transition-colors",children:e.jsx(we,{className:"w-3 h-3"})})]}):e.jsx("div",{className:"h-2 bg-[#21262D] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 ease-out",style:{width:`${(()=>{const c=g-t.max_drawdown,E=Math.max(0,x.currentBalance-c);return fe(t.max_drawdown-E,t.max_drawdown)})()}%`,backgroundColor:(()=>{const c=g-t.max_drawdown,E=Math.max(0,x.currentBalance-c);return E<t.max_drawdown*.3?"#EF4444":E<t.max_drawdown*.6?"#F59E0B":"#22C55E"})()}})}),t.trailing_drawdown_override&&!M&&e.jsx("p",{className:"text-[9px] text-[#8B5CF6]/70 italic",children:"Manual override active"}),e.jsxs("div",{className:"flex items-center justify-between text-[9px] text-[#484F58]",children:[e.jsxs("span",{children:["Floor: $",Math.round(g-t.max_drawdown).toLocaleString()," (fixed)"]}),e.jsxs("span",{children:["Balance: $",Math.round(x.currentBalance).toLocaleString()]}),e.jsxs("span",{children:["Max DD: $",t.max_drawdown.toLocaleStr
1ing()]})]})]})}),t.drawdown_type==="intraday"&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Remaining Drawdown"}),e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#22C55E]/10 text-[#22C55E] font-bold border border-[#22C55E]/20",children:"INTRADAY"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs font-bold",style:{color:x.drawdownRemaining<t.max_drawdown*.3?"#EF4444":x.drawdownRemaining<t.max_drawdown*.6?"#F59E0B":"#22C55E"},children:["$",Math.round(x.drawdownRemaining).toLocaleString()," / $",t.max_drawdown.toLocaleString()]}),!M&&e.jsx("button",{onClick:()=>{b(String(Math.round(t.max_drawdown))),N(!0)},className:"p-1 rounded hover:bg-[#21262D] text-[#484F58] hover:text-[#22C55E] transition-colors",title:"Edit max drawdown",children:e.jsx(Ve,{className:"w-3 h-3"})})]})]}),M?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:v,onChange:c=>b(c.target.value),className:"flex-1 px-2 py-1.5 rounded-lg bg-[#0D1117] border border-[#22C55E]/50 text-xs text-[#F0F6FC] focus:outline-none focus:ring-1 focus:ring-[#22C55E]",autoFocus:!0,onKeyDown:async c=>{if(c.key==="Enter"){const E=parseFloat(v);E>0&&await B(E),N(!1)}c.key==="Escape"&&N(!1)}}),e.jsx("button",{onClick:async()=>{const c=parseFloat(v);c>0&&await B(c),N(!1)},className:"px-2 py-1.5 rounded-lg text-[10px] font-bold bg-[#22C55E]/15 border border-[#22C55E]/30 text-[#22C55E] hover:bg-[#22C55E]/25 transition-colors",children:"Save"}),t.trailing_drawdown_override&&e.jsx("button",{onClick:async()=>{await B(t.max_drawdown),N(!1)},className:"px-2 py-1.5 rounded-lg text-[10px] font-bold bg-[#21262D] border border-[#30363D] text-[#8B949E] hover:text-[#F0F6FC] transition-colors",children:"Reset"}),e.jsx("button",{onClick:()=>N(!1),className:"p-1.5 rounded-lg hover:bg-[#21262D] text-[#484F58] hover:text-[#F0F6FC] transition-colors",children:e.jsx(we,{className:"w-3 h-3"})})]}):e.jsx("div",{className:"h-2 bg-[#21262D] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 ease-out",style:{width:`${fe(t.max_drawdown-x.drawdownRemaining,t.max_drawdown)}%`,backgroundColor:x.drawdownRemaining<t.max_drawdown*.3?"#EF4444":x.drawdownRemaining<t.max_drawdown*.6?"#F59E0B":"#22C55E"}})}),t.trailing_drawdown_override&&!M&&e.jsx("p",{className:"text-[9px] text-[#22C55E]/70 italic",children:"Manual override active"}),e.jsxs("div",{className:"flex items-center justify-between text-[9px] text-[#484F58]",children:[e.jsxs("span",{children:["Balance: $",Math.round(x.currentBalance).toLocaleString()]}),e.jsxs("span",{children:["Max DD: $",t.max_drawdown.toLocaleString()]}),e.jsx("span",{className:"text-[#22C55E]",children:"Trails in real-time with your firm"})]})]})}),e.jsxs("div",{className:`grid ${(t.consistency_pct||0)>0?"grid-cols-3":"grid-cols-2"} gap-3`,children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-3 border border-[#21262D] text-center",children:[e.jsx("div",{className:"flex items-center justify-center gap-1 mb-1",children:e.jsx(Oe,{className:"w-3 h-3 text-[#8B949E]"})}),e.jsx("p",{className:"text-lg font-extrabold text-[#F0F6FC]",children:t.time_limit_days?A:"∞"}),e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"Days Left"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-3 border border-[#21262D] text-center",children:[e.jsx("div",{className:"flex items-center justify-center gap-1 mb-1",children:e.jsx(Wt,{className:"w-3 h-3 text-[#8B949E]"})}),e.jsxs("p",{className:"text-lg font-extrabold text-[#F0F6FC]",children:[t.trading_days_completed||0,e.jsxs("span",{className:"text-xs text-[#8B949E]",children:["/",t.min_trading_days||0]})]}),e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"Trading Days"})]}),(t.consistency_pct||0)>0&&e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-3 border border-[#21262D] text-center",children:[e.jsx("div",{className:"flex items-center justify-center gap-1 mb-1",children:(t.consistency_score||0)>=85?e.jsx(Ee,{className:"w-3 h-3 text-[#22C55E]"}):e.jsx(qe,{className:"w-3 h-3 text-[#F59E0B]"})}),e.jsxs("p",{className:`text-lg font-extrabold ${gs(t.consistency_score||0)}`,children:[t.consistency_score||0,"%"]}),e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"Consistency"})]})]}),((t.daily_loss_limit||0)>0||(t.consistency_pct||0)>0)&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[(t.daily_loss_limit||0)>0&&e.jsxs("span",{className:"text-[10px] px-2 py-1 rounded-md bg-[#21262D] text-[#8B949E] border border-[#30363D]",children:["Daily Limit: $",t.daily_loss_limit.toLocaleStr
1ing()]}),(t.consistency_pct||0)>0&&e.jsxs("span",{className:"text-[10px] px-2 py-1 rounded-md bg-[#21262D] text-[#8B949E] border border-[#30363D]",children:["Consistency Req: ",t.consistency_pct,"%"]})]}),_.warnings.length>0&&e.jsx("div",{className:"space-y-1.5",children:_.warnings.map((c,E)=>e.jsxs("div",{className:`flex items-start gap-2 px-3 py-2 rounded-lg border text-[11px] ${c.severity==="danger"?"bg-[#EF4444]/5 border-[#EF4444]/20 text-[#EF4444]":c.severity==="warning"?"bg-[#F59E0B]/5 border-[#F59E0B]/20 text-[#F59E0B]":"bg-[#3B82F6]/5 border-[#3B82F6]/20 text-[#3B82F6]"}`,children:[e.jsx(js,{severity:c.severity}),e.jsx("span",{className:"font-medium leading-tight",children:c.message})]},E))}),e.jsxs("div",{className:"border-t border-[#21262D] pt-3 space-y-3",children:[d.totalTrades>0&&e.jsxs("div",{className:"grid grid-cols-5 gap-2",children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-sm font-extrabold text-[#F0F6FC]",children:d.totalTrades}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Trades"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-sm font-extrabold text-[#22C55E]",children:d.wins}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Wins"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsx("p",{className:"text-sm font-extrabold text-[#EF4444]",children:d.losses}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Losses"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsxs("p",{className:`text-sm font-extrabold ${d.netPnl>=0?"text-[#22C55E]":"text-[#EF4444]"}`,children:[d.netPnl>=0?"+":"","$",d.netPnl.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})]}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Net P&L"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2 border border-[#21262D] text-center",children:[e.jsxs("p",{className:"text-sm font-extrabold text-[#F0F6FC]",children:[d.winRate.toFixed(0),"%"]}),e.jsx("p",{className:"text-[9px] text-[#8B949E]",children:"Win Rate"})]})]}),!Y&&!ae&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>K(!0),disabled:le||h,className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-2.5 rounded-lg text-xs font-bold transition-all border bg-[#22C55E]/10 border-[#22C55E]/30 text-[#22C55E] hover:bg-[#22C55E]/20 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(ze,{className:"w-3.5 h-3.5"}),"Win"]}),e.jsxs("button",{onClick:()=>ie(!0),disabled:le||h,className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-2.5 rounded-lg text-xs font-bold transition-all border bg-[#EF4444]/10 border-[#EF4444]/30 text-[#EF4444] hover:bg-[#EF4444]/20 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(_t,{className:"w-3.5 h-3.5"}),"Loss"]}),e.jsxs("button",{onClick:O,disabled:le||!s,className:"flex items-center justify-center gap-1.5 px-3 py-2.5 rounded-lg text-xs font-bold transition-all border bg-[#8B949E]/10 border-[#8B949E]/30 text-[#8B949E] hover:bg-[#8B949E]/20 disabled:opacity-40 disabled:cursor-not-allowed",title:s&&D?`Undo: ${D.result} $${Math.abs(D.pnl)}`:"No trades to undo",children:[e.jsx(Et,{className:"w-3.5 h-3.5"}),"Undo"]})]}),Y&&e.jsxs("div",{className:"bg-[#22C55E]/5 border border-[#22C55E]/20 rounded-lg p-3 space-y-2",children:[e.jsx("p",{className:"text-xs font-bold text-[#22C55E]",children:"Log a Win"}),e.jsx("input",{type:"number",placeholder:"Dollar amount (e.g. 500)",value:te,onChange:c=>ne(c.target.value),className:"w-full text-xs bg-[#0D1117] border border-[#30363D] focus:border-[#22C55E] focus:outline-none focus:ring-1 focus:ring-[#22C55E] rounded-md px-3 py-2 text-[#F0F6FC] placeholder-[#484F58]",autoFocus:!0,onKeyDown:c=>{c.key==="Enter"&&L(),c.key==="Escape"&&(K(!1),ne(""),ce(""))}}),e.jsx("textarea",{placeholder:"Notes (optional)",value:de,onChange:c=>ce(c.target.value),rows:2,className:"w-full text-xs bg-[#0D1117] border border-[#30363D] focus:border-[#22C55E] focu
1s:outline-none focus:ring-1 focus:ring-[#22C55E] rounded-md px-3 py-2 text-[#F0F6FC] placeholder-[#484F58] resize-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:L,disabled:le||!te,className:"flex-1 flex items-center justify-center gap-1 px-3 py-2 rounded-md text-xs font-bold bg-[#22C55E] text-[#0D1117] hover:bg-[#16A34A] disabled:opacity-50 transition-colors",children:[le?e.jsx(ue,{className:"w-3 h-3 animate-spin"}):e.jsx(Ee,{className:"w-3 h-3"}),"Confirm Win"]}),e.jsx("button",{onClick:()=>{K(!1),ne(""),ce("")},className:"px-3 py-2 rounded-md text-xs font-bold text-[#8B949E] border border-[#21262D] hover:border-[#30363D] transition-colors",children:"Cancel"})]})]}),ae&&e.jsxs("div",{className:"bg-[#EF4444]/5 border border-[#EF4444]/20 rounded-lg p-3 space-y-2",children:[e.jsx("p",{className:"text-xs font-bold text-[#EF4444]",children:"Log a Loss"}),e.jsx("input",{type:"number",placeholder:"Dollar amount (e.g. 200)",value:Q,onChange:c=>se(c.target.value),className:"w-full text-xs bg-[#0D1117] border border-[#30363D] focus:border-[#EF4444] focus:outline-none focus:ring-1 focus:ring-[#EF4444] rounded-md px-3 py-2 text-[#F0F6FC] placeholder-[#484F58]",autoFocus:!0,onKeyDown:c=>{c.key==="Enter"&&W(),c.key==="Escape"&&(ie(!1),se(""),re(""))}}),e.jsx("textarea",{placeholder:"Notes (optional)",value:q,onChange:c=>re(c.target.value),rows:2,className:"w-full text-xs bg-[#0D1117] border border-[#30363D] focus:border-[#EF4444] focus:outline-none focus:ring-1 focus:ring-[#EF4444] rounded-md px-3 py-2 text-[#F0F6FC] placeholder-[#484F58] resize-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:W,disabled:le||!Q,className:"flex-1 flex items-center justify-center gap-1 px-3 py-2 rounded-md text-xs font-bold bg-[#EF4444] text-white hover:bg-[#DC2626] disabled:opacity-50 transition-colors",children:[le?e.jsx(ue,{className:"w-3 h-3 animate-spin"}):e.jsx(qe,{className:"w-3 h-3"}),"Confirm Loss"]}),e.jsx("button",{onClick:()=>{ie(!1),se(""),re("")},className:"px-3 py-2 rounded-md text-xs font-bold text-[#8B949E] border border-[#21262D] hover:border-[#30363D] transition-colors",children:"Cancel"})]})]})]}),e.jsx(ws,{analysis:_,account:t}),e.jsxs("div",{className:"border-t border-[#21262D] pt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Vt,{className:"w-3 h-3 text-[#8B949E]"}),e.jsxs("span",{className:"text-[10px] text-[#8B949E]",children:["Last verified: ",e.jsx("span",{className:"text-[#F0F6FC] font-medium",children:bs(je)})]})]}),Ne>0&&e.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-[#F59E0B]/10 text-[#F59E0B] font-bold border border-[#F59E0B]/20",children:[Ne," flag",Ne!==1?"s":""]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>X(!0),disabled:ye,className:`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-[11px] font-medium transition-all border ${ye?"bg-[#21262D] border-[#21262D] text-[#484F58] cursor-not-allowed":"bg-[#F59E0B]/5 border-[#F59E0B]/20 text-[#F59E0B] hover:bg-[#F59E0B]/10"}`,title:ye?"You already flagged this":"Report outdated rules",children:[e.jsx(Je,{className:"w-3 h-3"}),ye?"Flagged":"Report Outdated"]}),e.jsxs("button",{onClick:$e,disabled:Se,className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-[11px] font-medium transition-all border bg-[#3B82F6]/5 border-[#3B82F6]/20 text-[#3B82F6] hover:bg-[#3B82F6]/10",title:"Refresh rules via AI",children:[Se?e.jsx(ue,{className:"w-3 h-3 animate-spin"}):e.jsx(Ct,{className:"w-3 h-3"}),Se?"Refreshing...":"Refresh"]}),e.jsxs("button",{onClick:()=>Be(!0),className:"flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-[11px] font-medium transition-all border bg-[#8B5CF6]/5 border-[#8B5CF6]/20 text-[#8B5CF6] hover:bg-[#8B5CF6]/10",title:"View version history",children:[e.jsx(Qe,{className:"w-3 h-3"}),"History"]})]})]})]}),e.jsx(Fs,{isOpen:oe,onClose:()=>X(!1),firmName:t.firm_name,accountSize:t.account_size,planType:t.plan_type,onFlagged:()=>{xe(!0),Fe(c=>c+1)}}),e.jsx(vs,{isOpen:ge,onClose:()=>Be(!1),firmName:t.firm_name,accountSize:t.account_size,planType:t.plan_type}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-[#161B22] rounded-2xl border border-[#22C55E]/40 w-full max-w-md 
1shadow-2xl shadow-[#22C55E]/10 overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-[#22C55E]/20 via-[#10B981]/20 to-[#059669]/20 p-6 text-center border-b border-[#22C55E]/20",children:[e.jsx("div",{className:"text-5xl mb-3",children:"🎉🏆🎉"}),e.jsx("h2",{className:"text-2xl font-extrabold text-[#22C55E] tracking-tight",children:"EVALUATION PASSED!"}),e.jsx("p",{className:"text-sm text-[#8B949E] mt-1",children:"Congratulations on passing your evaluation!"})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-xl border border-[#21262D] p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E]",children:"Firm"}),e.jsx("span",{className:"text-sm font-bold text-[#F0F6FC]",children:t.firm_name})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E]",children:"Account Size"}),e.jsx("span",{className:"text-sm font-bold text-[#F0F6FC]",children:t.account_size})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E]",children:"Plan"}),e.jsx("span",{className:"text-sm font-bold text-[#F0F6FC]",children:t.plan_type})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E]",children:"Profit Target"}),e.jsxs("span",{className:"text-sm font-bold text-[#22C55E]",children:["$",t.profit_target.toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-[#8B949E]",children:"Final Profit"}),e.jsxs("span",{className:"text-sm font-bold text-[#22C55E]",children:["$",Math.max(0,j).toLocaleString()]})]})]}),e.jsx("div",{className:"bg-[#22C55E]/5 border border-[#22C55E]/20 rounded-xl p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ee,{className:"w-4 h-4 text-[#22C55E] mt-0.5 flex-shrink-0"}),e.jsxs("p",{className:"text-xs text-[#8B949E]",children:["A new account has been automatically created on your ",e.jsx("span",{className:"text-[#22C55E] font-bold",children:"Dashboard"})," with your max drawdown of ",e.jsxs("span",{className:"text-[#F0F6FC] font-bold",children:["$",t.max_drawdown.toLocaleString()]})," so you can continue tracking your funded account."]})]})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>l(!1),className:"flex-1 px-4 py-2.5 rounded-xl text-sm font-bold text-[#8B949E] border border-[#21262D] hover:border-[#30363D] transition-colors",children:"Stay Here"}),e.jsxs("button",{onClick:()=>{l(!1),window.location.href="/"},className:"flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl bg-gradient-to-r from-[#22C55E] to-[#16A34A] text-[#0D1117] font-bold text-sm hover:opacity-90 transition-opacity shadow-lg shadow-[#22C55E]/20",children:[e.jsx(Ie,{className:"w-4 h-4"}),"Go to Dashboard"]})]})]})]})})]})}function ys({isOpen:t,onClose:r,onCreated:m}){const{toast:i}=Pe(),[p,h]=a.useState("form"),[d,j]=a.useState(""),[g,x]=a.useState(""),[w,k]=a.useState(""),[A,M]=a.useState(""),[N,v]=a.useState(""),[b,B]=a.useState(""),[y,T]=a.useState(!1),[P,ee]=a.useState(!1),[z,V]=a.useState(null),[u,C]=a.useState(0),[F,o]=a.useState(0),[$,_]=a.useState(0),[U,Y]=a.useState(0),[K,ae]=a.useState(0),[ie,te]=a.useState(0),[ne,Q]=a.useState("eod_trailing"),se=d==="__custom__"?g:d,de=w==="__custom__"?A:w,ce=N==="__custom__"?b:N,q=se.trim()&&de.trim()&&ce.trim(),re=async()=>{var s,D,S;if(q){T(!0);try{const n=(await I.apiCall.invoke({url:"/api/v1/eval-ai/fetch-rules",method:"POST",data:{firm_name:se.trim(),account_size:de.trim(),plan_type:ce.trim()}})).data;V(n),C(n.profit_target),o(n.max_drawdown),_(n.daily_loss_limit),Y(n.consistency_pct),ae(n.min_trading_days),te(n.time_limit_days);const f=se.trim().toLowerCase();f.includes("topstep")||f.includes("apex")||f.includes("tradeify")||f.includes("myfunded")||f.includes("take profit"),Q("eod_trailing"),h("review")}catch(l){const n=((s=l==null?void 0:l.data)==null?void 0:s.detail)||((S=(D=l==null?void 0:l.response)==null?void 0:D.data)==null?void 0:S.detail)||(l==null?void 0:l.message)||"Failed to fetch rules";i({title:"Error",description:n,variant:"destructive"})}finally{T(!1)}}},le=async()=>{var s,D,S;ee(!0);try{await I.entities.eval_accounts.create({data:{firm_name:se.trim(),account_size:de.trim(),plan_type:ce.trim(),profit_target:u,current_profit:0,max_drawdown:F,current_drawdown:0,daily_loss_limit:$,consistency_pct:U,min_trading_days:K,trading_days_completed:0,time_limit_days:ie,days_used:0,consistency_score:0,status:"active",drawdown_type:ne}}),i({title:"Success",description:"Eval account created!"}),m(),Z()}catch(l){const n=((s=l==null?void 0:l.data)==null?void 0:s.detail)||((S=(D=l==null?void 0:l.response)==null?void 0:D.data)==null?void 0:S.detail)||(l==null?void 0:l.message)||"Failed to save";i({title:"Error",description:n,variant:"destructive"})}finally{ee(!1)}},Z=()=>{h("form"),j(""),x(""),k(""),M(""),v(""),B(""),V(null),C(0),o(0),_(0),Y(0),ae(0),te(0),Q("eod_trailing"),r()};return t?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-[#161B22] rounded-2xl border border-[#21262D] w-full max-w-lg max-h-[90vh] overflow-y-auto shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b border-[#21262D]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-[#8B5CF6]/15 flex items-center justify-center",children:e.jsx(Re,{className:"w-4 h-4 text-[#8B5CF6]"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-[#F0F6FC]",children:"Add Eval Account"}),e.jsx("p",{className:"text-xs text-[#8B949E]",children:p==="form"?"Enter prop firm details":"Review & adju
1st rules"})]})]}),e.jsx("button",{onClick:Z,className:"p-2 rounded-lg hover:bg-[#21262D] text-[#8B949E] hover:text-[#F0F6FC] transition-colors",children:e.jsx(we,{className:"w-4 h-4"})})]}),p==="form"?e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold text-[#F0F6FC]",children:"Prop Firm"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[us.map(s=>e.jsx("button",{onClick:()=>j(s),className:`px-3 py-2 rounded-lg text-xs font-medium transition-all border ${d===s?"bg-[#8B5CF6]/15 border-[#8B5CF6]/50 text-[#8B5CF6]":"bg-[#0D1117] border-[#21262D] text-[#8B949E] hover:border-[#30363D]"}`,children:s},s)),e.jsx("button",{onClick:()=>j("__custom__"),className:`px-3 py-2 rounded-lg text-xs font-medium transition-all border col-span-2 ${d==="__custom__"?"bg-[#8B5CF6]/15 border-[#8B5CF6]/50 text-[#8B5CF6]":"bg-[#0D1117] border-[#21262D] text-[#8B949E] hover:border-[#30363D]"}`,children:"Other (Custom)"})]}),d==="__custom__"&&e.jsx("input",{type:"text",value:g,onChange:s=>x(s.target.value),placeholder:"Enter firm name...",className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] placeholder-[#484F58] focus:border-[#8B5CF6] focus:outline-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold text-[#F0F6FC]",children:"Account Size"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:hs.map(s=>e.jsx("button",{onClick:()=>k(s==="Custom"?"__custom__":s),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all border ${(s==="Custom"?w==="__custom__":w===s)?"bg-[#3B82F6]/15 border-[#3B82F6]/50 text-[#3B82F6]":"bg-[#0D1117] border-[#21262D] text-[#8B949E] hover:border-[#30363D]"}`,children:s},s))}),w==="__custom__"&&e.jsx("input",{type:"text",value:A,onChange:s=>M(s.target.value),placeholder:"e.g. 500K",className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] placeholder-[#484F58] focus:border-[#3B82F6] focus:outline-none"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold text-[#F0F6FC]",children:"Plan / Phase"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:fs.map(s=>e.jsx("button",{onClick:()=>v(s==="Custom"?"__custom__":s),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all border ${(s==="Custom"?N==="__custom__":N===s)?"bg-[#22C55E]/15 border-[#22C55E]/50 text-[#22C55E]":"bg-[#0D1117] border-[#21262D] text-[#8B949E] hover:border-[#30363D]"}`,children:s},s))}),N==="__custom__"&&e.jsx("input",{type:"text",value:b,onChange:s=>B(s.target.value),placeholder:"e.g. Combined Phase",className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] placeholder-[#484F58] focus:border-[#22C55E] focus:outline-none"})]}),e.jsx("button",{onClick:re,disabled:!q||y,className:`w-full flex items-center justify-center gap-2 px-4 py-3 rounded-xl font-bold text-sm transition-all ${q&&!y?"bg-gradient-to-r from-[#8B5CF6] to-[#6D28D9] text-white hover:opacity-90":"bg-[#21262D] text-[#484F58] cursor-not-allowed"}`,children:y?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-4 h-4 animate-spin"}),"Fetching rules with AI..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ct,{className:"w-4 h-4"}),"Fetch Rules with AI"]})}),e.jsx("p",{className:"text-[10px] text-[#484F58] text-center",children:"AI will look up the evaluation rules for your selected firm. You can edit them before saving."})]}):e.jsxs("div",{className:"p-5 space-y-5",children:[z&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ct,{className:"w-3.5 h-3.5 text-[#8B5CF6]"}),e.jsxs("span",{className:"text-xs text-[#8B949E]",children:["AI Confidence:"," ",e.jsx("span",{className:`font-bold ${z.ai_confidence==="high"?"text-[#22C55E]":z.ai_confidence==="medium"?"text-[#F59E0B]":"text-[#EF4444]"}`,children:z.ai_confidence.toUpperCase()})]}),z.from_cache&&e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-[#21262D] text-[#8B949E]",children:"cached"})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-xl p-4 border border-[#21262D]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ce,{className:"w-4 h-4 text-[#8B5CF6]"}),e.jsxs("span",{className:"text-sm font-bold text-[#F0F6FC]",children:[se," — ",de," — ",ce]})]}),e.jsx("p",{className:"text-xs text-[#8B949E]",children:"Review the rules below. You can adjust any values before saving."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-[#F0F6FC]",children:["Drawdown Type",e.jsx("span",{className:"ml-2 text-[10px] font-normal text-[#F59E0B]",children:"⚠️ This determines how y
1our drawdown is calculated — critical for account safety"})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"eod_trailing",label:"EOD Trailing",desc:"Floor ratchets up at end of day"},{value:"static",label:"Static",desc:"Fixed floor, never trails"},{value:"intraday",label:"Intraday",desc:"Real-time (manual entry)"}].map(s=>e.jsxs("button",{onClick:()=>Q(s.value),className:`px-3 py-2.5 rounded-lg text-left transition-all border ${ne===s.value?"bg-[#F59E0B]/15 border-[#F59E0B]/50 text-[#F59E0B]":"bg-[#0D1117] border-[#21262D] text-[#8B949E] hover:border-[#30363D]"}`,children:[e.jsx("p",{className:`text-xs font-bold ${ne===s.value?"text-[#F59E0B]":"text-[#F0F6FC]"}`,children:s.label}),e.jsx("p",{className:"text-[9px] text-[#484F58] mt-0.5",children:s.desc})]},s.value))}),e.jsx("p",{className:"text-[10px] text-[#484F58]",children:"AI pre-selected its best guess. Override if your firm uses a different model."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-semibold text-[#8B949E] uppercase tracking-wider",children:"Profit Target ($)"}),e.jsx(ve,{value:u,onValueChange:C,fallback:0,min:0,className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] focus:border-[#8B5CF6] focus:outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-semibold text-[#8B949E] uppercase tracking-wider",children:"Max Drawdown ($)"}),e.jsx(ve,{value:F,onValueChange:o,fallback:0,min:0,className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] focus:border-[#8B5CF6] focus:outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-semibold text-[#8B949E] uppercase tracking-wider",children:"Daily Loss Limit ($)"}),e.jsx(ve,{value:$,onValueChange:_,fallback:0,min:0,className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] focus:border-[#8B5CF6] focus:outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-semibold text-[#8B949E] uppercase tracking-wider",children:"Consistency Req (%)"}),e.jsx(ve,{value:U,onValueChange:Y,fallback:0,min:0,className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] focus:border-[#8B5CF6] focus:outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-semibold text-[#8B949E] uppercase tracking-wider",children:"Min Trading Days"}),e.jsx(ve,{value:K,onValueChange:ae,fallback:0,min:0,className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] focus:border-[#8B5CF6] focus:outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-semibold text-[#8B949E] uppercase tracking-wider",children:"Time Limit (Days)"}),e.jsx(ve,{value:ie,onValueChange:te,fallback:0,min:0,className:"w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#21262D] text-sm text-[#F0F6FC] focus:border-[#8B5CF6] focus:outline-none"})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>h("form"),className:"flex-1 px-4 py-2.5 rounded-xl border border-[#21262D] text-sm font-medium text-[#8B949E] hover:bg-[#21262D] transition-colors",children:"Back"}),e.jsx("button",{onClick:le,disabled:P||u<=0||F<=0,className:`flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl font-bold text-sm transition-all ${!P&&u>0&&F>0?"bg-gradient-to-r from-[#22C55E] to-[#16A34A] text-white hover:opacity-90":"bg-[#21262D] text-[#484F58] cursor-not-allowed"}`,children:P?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-4 h-4 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{className:"w-4 h-4"}),"Save Account"]})})]})]})]})}):null}function zs(){const{toast:t}=Pe(),{mode:r}=Rt(),[m]=a.useState(!0),[i,p]=a.useState([]),[h,d]=a.useState([]),[j,g]=a.useState(!0),[x,w]=a.useState(!1),[k,A]=a.useState(!1),M=a.useCallback(async()=>{var o;try{const $=await I.entities.eval_accounts.query({query:{},sort:"-created_at",limit:50});p(((o=$.data)==null?void 0:o.items)||[])}catch($){console.error("Failed to load eval accounts:",$)}finally{g(!1)}},[]),N=a.useCallback(async()=>{try{const o=await ns();d(o)}catch(o){console.error("Failed to load eval trades:",o)}},[]),v=a.useCallback(()=>{M(),N()},[M,N]);a.useEffect(()=>{M(),N()},[M,N]);const b=a.useCallback(o=>h.filter($=>$.eval_account_id===o),[h]);if(r==="auto")return e.jsxs(tt,{children:[e.jsx(xs,{}),e.jsx("div",{className:"max-w-6xl mx-auto px-4 pb-10",children:e.jsx(ps,{})})]});const B=async o=>{var $;try{await I.entities.eval_accounts.delete({id:String(o)}),p(_=>_.filter(U=>U.id!==o)),t({title:"Deleted",description:"Eval account removed."})}catch(_){const U=(($=_==null?void 0:_.data)==null?void 0:$.detail)||(_==null?void 0:_.message)||"Failed to delete";t({title:"Error",description:U,variant:"destructive"})}},y=i.filter(o=>o.status==="active"),T=i.filter(o=>o.status==="passed"),P=i.filter(o=>o.status==="failed"),ee=y.length>=2,z=k&&ee,V=y.reduce((o,$)=>o+($.current_profit||0),0),u=y.reduce((o,$)=>o+($.profit_target||0),0),C=y.filter(o=>(o.consistency_pct||0)>0),F=C.length>0?Math.round(C.reduce((o,$)=>o+($.consistency_score||0),0)/C.length):0;return e.jsxs(tt,{children:[e.jsxs("div",{className:"p-6 lg:p-8 max-w-6xl mx-auto 
1space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#8B5CF6]/15 flex items-center justify-center",children:e.jsx(Ce,{className:"w-5 h-5 text-[#8B5CF6]"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-extrabold text-[#F0F6FC] tracking-tight",children:"Evaluation Mode"}),e.jsx("p",{className:"text-sm text-[#8B949E]",children:"Track your prop firm evaluation progress"})]})]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-xs text-[#8B949E] bg-[#161B22] px-3 py-1.5 rounded-lg border border-[#21262D]",children:[i.length," Evaluations"]}),m&&ee&&e.jsxs("button",{onClick:()=>A(!k),className:`inline-flex items-center gap-1.5 text-xs font-bold transition-all px-3 py-2 rounded-lg ${k?"bg-[#A855F7]/15 text-[#A855F7] border border-[#A855F7]/30":"text-[#484F58] hover:text-[#8B949E] border border-[#21262D] hover:border-[#30363D]"}`,children:[k?e.jsx(it,{className:"w-3.5 h-3.5"}):e.jsx(Ut,{className:"w-3.5 h-3.5"}),k?"Grouped":"Single"]}),m&&e.jsxs("button",{onClick:()=>w(!0),className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-r from-[#8B5CF6] to-[#6D28D9] text-white font-bold text-sm hover:opacity-90 transition-opacity shadow-lg shadow-[#8B5CF6]/20",children:[e.jsx(Re,{className:"w-4 h-4"}),"Add Eval Account"]})]})]}),e.jsxs("div",{className:"relative",children:[!m&&e.jsx(Ns,{}),e.jsxs("div",{className:`space-y-6 ${m?"":"pointer-events-none select-none"}`,children:[!z&&e.jsxs("div",{className:`grid grid-cols-1 sm:grid-cols-2 ${C.length>0?"lg:grid-cols-4":"lg:grid-cols-3"} gap-4`,children:[e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ze,{className:"w-4 h-4 text-[#3B82F6]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Overall Progress"})]}),e.jsxs("p",{className:"text-2xl font-extrabold text-[#F0F6FC]",children:[u>0?fe(V,u):0,"%"]}),e.jsxs("p",{className:"text-xs text-[#8B949E] mt-1",children:["$",V.toLocaleString()," / $",u.toLocaleString()]})]}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(dt,{className:"w-4 h-4 text-[#22C55E]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Active Evals"})]}),e.jsx("p",{className:"text-2xl font-extrabold text-[#F0F6FC]",children:y.length}),e.jsx("p",{className:"text-xs text-[#8B949E] mt-1",children:"In progress"})]}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ee,{className:"w-4 h-4 text-[#22C55E]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Passed"})]}),e.jsx("p",{className:"text-2xl font-extrabold text-[#22C55E]",children:T.length}),e.jsx("p",{className:"text-xs text-[#8B949E] mt-1",children:"Evaluations passed"})]}),C.length>0&&e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ie,{className:"w-4 h-4 text-[#F59E0B]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Avg Consistency"})]}),e.jsxs("p",{className:"text-2xl font-extrabold text-[#F0F6FC]",children:[F,"%"]}),e.jsx("p",{className:"text-xs text-[#8B949E] mt-1",children:"Across active evals"})]})]}),j&&e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(ue,{className:"w-6 h-6 animate-spin text-[#8B5CF6]"}),e.jsx("span",{className:"ml-2 text-sm text-[#8B949E]",children:"Loading evaluations..."})]}),!j&&i.length===0&&e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-12 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[#8B5CF6]/10 flex items-center justify-center mx-auto mb-4",children:e.jsx(Ce,{className:"w-8 h-8 text-[#8B5CF6]"})}),e.jsx("h3",{className:"text-lg font-bold text-[#F0F6FC] mb-2",children:"No Evaluations Yet"}),e.jsx("p",{className:"text-sm text-[#8B949E] max-w-sm mx-auto mb-6",children:"Add your first prop firm evaluation to start tracking your progress. AI will automatically fetch the rules for you."}),e.jsxs("button",{onClick:()=>w(!0),className:"inline-flex items-center gap-2 px-6 py-2.5 rounded-xl bg-gradient-to-r from-[#8B5CF6] to-[#6D28D9] text-white font-bold text-sm hover:opacity-90 transition-opacity",children:[e.jsx(Re,{className:"w-4 h-4"}),"Add Eval Account"]})]}),y.length>0&&e.jsxs("div",{className:"space-y-3",children:[!z&&e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h2",{className:"text-sm font-bold text-[#F0F6FC] uppercase tracking-wider",children:"Active Evaluations"})}),z?e.jsxs("div",{className:"grid lg:grid-cols-12 gap-8",children:[e.jsxs("div",{className:"lg:col-span-5 xl:col-span-4 space-y-6",children:[e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-[#21262D] flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-bold text-[#F0F6FC]",children:["Eval Accounts (",y.length,")"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>A(!k),className:"inline-flex items-center gap-1 text-[10px] font-bold transition-colors px-2.5 py-1.5 rounded-md bg-[#A855F7]/15 text-[#A855F7] border border-[#A855F7]/30",children:[e.jsx(it,{className:"w-3 h-3"}),"Grouped"]}),e.jsxs("button",{onClick:()=>w(!0),className:"inline-flex items-center gap-1 text-xs font-bold text-[#8B5CF6] hover:text-[#A855F7] transition-colors px-2 py-1",children:[e.jsx(Re,{className:"w-3.5 h-3.5"}),"Add"]})]})]}),e.jsxs("div",{className:"p-4 space-y-2",children:[y.map(o=>{const $=We(o),_=et[$.health],U=b(o.id),Y=Ke(U);return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-all cursor-default ${_.border} bg-[#0D1117] hover:bg-[#161B22]`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("p",{className:"text-xs font-bold text-[#F0F6FC] truncate",children:[o.firm_name," ",o.account_size]}),e.jsx(Lt,{health:$.health,label:$.healthLabel,reason:$.healthReason})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[e.jsx("span",{className:"text-[10px] text-[#8B949E]",children:o.plan_type}),e.jsxs("span",{className:`text-[10px] font-bold ${Y.netPnl>=0?"text-[#22C55E]":"text-[#EF4444]"}`,children:[Y.netPnl>
1=0?"+":"","$",Y.netPnl.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})]}),e.jsxs("span",{className:"text-[10px] text-[#484F58]",children:[fe(Math.max(0,Y.netPnl),o.profit_target),"% to target"]})]})]}),e.jsx("button",{onClick:()=>B(o.id),className:"p-1 rounded hover:bg-[#21262D] text-[#484F58] hover:text-[#EF4444] transition-colors flex-shrink-0",title:"Remove",children:e.jsx(Dt,{className:"w-3 h-3"})})]},o.id)}),e.jsx("p",{className:"text-[10px] text-[#A855F7] text-center mt-3",children:"Group mode: trades logged across all accounts simultaneously"})]})]}),e.jsx(is,{accounts:y,allTrades:h,onTradeLogged:v})]}),e.jsxs("div",{className:"lg:col-span-7 xl:col-span-8 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ze,{className:"w-4 h-4 text-[#3B82F6]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Overall Progress"})]}),e.jsxs("p",{className:"text-2xl font-extrabold text-[#F0F6FC]",children:[u>0?fe(V,u):0,"%"]}),e.jsxs("p",{className:"text-xs text-[#8B949E] mt-1",children:["$",V.toLocaleString()," / $",u.toLocaleString()]})]}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(dt,{className:"w-4 h-4 text-[#22C55E]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Active Evals"})]}),e.jsx("p",{className:"text-2xl font-extrabold text-[#F0F6FC]",children:y.length}),e.jsx("p",{className:"text-xs text-[#8B949E] mt-1",children:"In progress"})]}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ee,{className:"w-4 h-4 text-[#22C55E]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Passed"})]}),e.jsx("p",{className:"text-2xl font-extrabold text-[#22C55E]",children:T.length}),e.jsx("p",{className:"text-xs text-[#8B949E] mt-1",children:"Evaluations passed"})]}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ie,{className:"w-4 h-4 text-[#F59E0B]"}),e.jsx("span",{className:"text-xs text-[#8B949E] font-medium",children:"Avg Consistency"})]}),e.jsxs("p",{className:"text-2xl font-extrabold text-[#F0F6FC]",children:[F,"%"]}),e.jsx("p",{className:"text-xs text-[#8B949E] mt-1",children:"Across active evals"})]})]}),e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#21262D] overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-[#21262D]",children:e.jsx("span",{className:"text-sm font-bold text-[#F0F6FC]",children:"Account Progress"})}),e.jsx("div",{className:"p-4 space-y-4",children:y.map(o=>{const $=b(o.id),_=Ke($),U=fe(Math.max(0,_.netPnl),o.profit_target),Y=Math.max(0,-_.netPnl),K=fe(Y,o.max_drawdown);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-bold text-[#F0F6FC]",children:[o.firm_name," ",o.account_size]}),e.jsxs("span",{className:`text-xs font-bold ${_.netPnl>=0?"text-[#22C55E]":"text-[#EF4444]"}`,children:[_.netPnl>=0?"+":"","$",_.netPnl.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})]})]}),e.jsx(Ze,{value:Math.max(0,_.netPnl),max:o.profit_target,color:U>=100?"#22C55E":"#3B82F6",label:"Profit",sublabel:`$${Math.max(0,_.netPnl).toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})} / $${o.profit_target.toLocaleString()}`}),e.jsx(Ze,{value:Y,max:o.max_drawdown,color:K>70?"#EF4444":K>40?"#F59E0B":"#22C55E",label:"Drawdown",sublabel:`$${Y.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})} / $${o.max_drawdown.toLocaleString()}`})]},o.id)})})]}),e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer text-xs text-[#8B949E] hover:text-[#F0F6FC] transition-colors py-1",children:[e.jsx(De,{className:"w-3 h-3 group-open:rotate-180 transition-transform"}),"Show individual account details"]}
1),e.jsx("div",{className:"grid grid-cols-1 gap-4 mt-3",children:y.map(o=>e.jsx(Te,{account:o,trades:b(o.id),onDelete:B,onTradeLogged:v},o.id))})]}),e.jsx("p",{className:"text-center text-[#30363D] text-xs pt-2",children:"For educational purposes only. Always verify with your prop firm."})]})]}):e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:y.map(o=>e.jsx(Te,{account:o,trades:b(o.id),onDelete:B,onTradeLogged:v},o.id))})]}),T.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-sm font-bold text-[#22C55E] uppercase tracking-wider",children:"🏆 Passed Evaluations"}),e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-[#22C55E]/10 text-[#22C55E] font-bold border border-[#22C55E]/20",children:T.length})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:T.map(o=>e.jsxs("div",{className:"bg-[#161B22] rounded-xl border border-[#22C55E]/20 p-4 space-y-3 hover:border-[#22C55E]/40 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#22C55E]/10 flex items-center justify-center",children:e.jsx(Bt,{className:"w-4 h-4 text-[#22C55E]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-[#F0F6FC]",children:o.firm_name}),e.jsxs("p",{className:"text-[10px] text-[#8B949E]",children:[o.account_size," · ",o.plan_type]})]})]}),e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-[#22C55E]/15 text-[#22C55E] font-bold border border-[#22C55E]/30",children:"PASSED ✓"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2",children:[e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"Profit Target"}),e.jsxs("p",{className:"text-xs font-bold text-[#22C55E]",children:["$",o.profit_target.toLocaleString()]})]}),e.jsxs("div",{className:"bg-[#0D1117] rounded-lg p-2",children:[e.jsx("p",{className:"text-[10px] text-[#8B949E]",children:"Max Drawdown"}),e.jsxs("p",{className:"text-xs font-bold text-[#F0F6FC]",children:["$",o.max_drawdown.toLocaleString()]})]})]}),o.passed_at&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-[#8B949E]",children:[e.jsx(Oe,{className:"w-3 h-3"}),"Passed on ",new Date(o.passed_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]}),o.dashboard_account_id&&e.jsxs("a",{href:"/",className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 rounded-lg text-[11px] font-bold bg-[#22C55E]/10 border border-[#22C55E]/20 text-[#22C55E] hover:bg-[#22C55E]/20 transition-colors",children:[e.jsx(Ie,{className:"w-3 h-3"}),"View on Dashboard"]})]},`passed-summary-${o.id}`))}),e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer text-xs text-[#8B949E] hover:text-[#F0F6FC] transition-colors py-1",children:[e.jsx(De,{className:"w-3 h-3 group-open:rotate-180 transition-transform"}),"Show full details for passed accounts"]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 mt-3",children:T.map(o=>e.jsx(Te,{account:o,trades:b(o.id),onDelete:B,onTradeLogged:v},o.id))})]})]}),P.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-sm font-bold text-[#F0F6FC] uppercase tracking-wider",children:"Failed Evaluations"}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:P.map(o=>e.jsx(Te,{account:o,trades:b(o.id),onDelete:B,onTradeLogged:v},o.id))})]})]})]})]}),e.jsx(ys,{isOpen:x,onClose:()=>w(!1),onCreated:()=>{w(!1),M()}})]})}export{Is as APEX_DRAWDOWN_PRESETS,zs 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.