1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chat-page-evUfHQgD.js","assets/chartjs-vendor-CJ58C3gX.js","assets/rolldown-runtime-ChpBd9eV.js","assets/chat-page-BXqTKTIP.css"])))=>i.map(i=>d[i]); 2import{o as Yt}from"./rolldown-runtime-ChpBd9eV.js";import{Fa as Os,Ia as Fs,Ii as _t,In as _s,La as Bs,Ma as Jt,Ni as Ms,Pa as zs,Sr as Es,Ta as Us,Ti as Vs,_r as vt,da as M,ha as Pe}from"./chat-page-evUfHQgD.js";import{Au as Ws,Bt as Gs,Cc as Hs,Cu as qs,Eu as Bt,Ft as Qt,Gc as Ys,Hc as ct,Jc as Xt,Nc as Mt,Pc as Js,Qc as Kt,Rc as Le,Sc as xt,Su as Qs,Tc as Xs,Tu as Ks,Ut as Zs,Vc as ea,Vt as ta,Wt as sa,Xc as Ke,Yc as dt,_c as be,bu as aa,cl as De,cu as la,dc as Ze,el as Zt,fl as mt,hc as ce,hl as ra,hn as ia,jc as ht,kc as es,ku as zt,lc as pe,lu as gt,ml as ut,nl as re,ol as na,pl as q,tl as Et,ul as Ut,vc as Te,wc as pt,xu as Vt,yc as Se,zc as oa,zt as da}from"./market-core-DitXLvJ-.js";var ca=Yt(Fs(),1),i=Yt(Bs(),1),e=Us(),Wt={prop_firm:ce,trading_group:q,ria:re},Gt={prop_firm:"text-blue-400",trading_group:"text-green-400",ria:"text-purple-400"},xa=({className:l=""})=>{const $=Jt(),{user:L}=vt(),{currentOrg:h,allMemberships:u,fetchAllMemberships:E,switchOrganization:b}=gt(),[S,I]=(0,i.useState)(!1),[f,P]=(0,i.useState)(!1),[j,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{L?.uid&&u.length===0&&!j&&(p(!0),E(L.uid).catch(C=>{console.warn("[OrganizationSwitcher] Failed to fetch memberships:",C.message)}))},[L?.uid,u.length,j]);const k=async C=>{if(C===h?.id){I(!1);return}P(!0),await b(C,L.uid),P(!1),I(!1)},F=()=>{I(!1),$("/org/create")},o=()=>{I(!1),$("/org/browse")},w=h?Wt[h.type]||ce:ce;return(0,e.jsxs)("div",{className:`relative ${l}`,children:[(0,e.jsxs)("button",{onClick:()=>I(!S),disabled:f,className:"flex items-center gap-2 px-4 py-2.5 bg-slate-700/50 hover:bg-slate-700 rounded-lg border border-slate-600 transition-colors min-w-[200px]",children:[f?(0,e.jsx)("div",{className:"w-4 h-4 border-2 border-slate-400 border-t-white rounded-full animate-spin"}):(0,e.jsx)(w,{className:`w-4 h-4 ${h?Gt[h.type]:"text-slate-400"}`}),(0,e.jsx)("span",{className:"text-sm font-medium text-white truncate flex-1 text-left",children:h?.name||"Select Organization"}),(0,e.jsx)(Se,{className:`w-4 h-4 text-slate-400 transition-transform ${S?"rotate-180":""}`})]}),(0,e.jsx)(Pe,{children:S&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>I(!1)}),(0,e.jsxs)(M.div,{initial:{opacity:0,y:-10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-10,scale:.95},transition:{duration:.15},className:"absolute top-full left-0 mt-2 bg-slate-800 border border-slate-700 rounded-xl shadow-xl z-50 overflow-hidden min-w-[280px]",children:[(0,e.jsx)("div",{className:"px-4 py-2.5 border-b border-slate-700",children:(0,e.jsx)("p",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider",children:"Your Organizations"})}),(0,e.jsx)("div",{className:"max-h-64 overflow-y-auto",children:u.length===0?(0,e.jsx)("div",{className:"px-4 py-3 text-sm text-slate-400",children:"No organizations yet"}):u.map(({membership:C,org:_})=>{const a=Wt[_.type]||ce,N=h?.id===_.id;return(0,e.jsxs)("button",{onClick:()=>k(_.id),className:`w-full px-4 py-3 flex items-center gap-3 hover:bg-slate-700/50 transition-colors ${N?"bg-blue-500/10 border-l-2 border-blue-500":""}`,children:[(0,e.jsx)(a,{className:`w-5 h-5 ${Gt[_.type]||"text-slate-400"}`}),(0,e.jsxs)("div",{className:"flex-1 text-left min-w-0",children:[(0,e.jsx)("p",{className:"text-sm font-medium text-white truncate",children:_.name}),(0,e.jsxs)("p",{className:"text-xs text-slate-400 capitalize",children:[C.role," ⢠",_.type?.replace("_"," ")]})]}),N&&(0,e.jsx)(be,{className:"w-4 h-4 text-blue-400 flex-shrink-0"})]},_.id)})}),(0,e.jsx)("div",{className:"border-t border-slate-700"}),(0,e.jsxs)("button",{onClick:o,className:"w-full px-4 py-3 flex items-center gap-3 text-green-400 hover:bg-green-500/10 transition-colors",children:[(0,e.jsx)(Kt,{className:"w-5 h-5"}),(0,e.jsx)("span",{className:"text-sm font-medium",children:"Browse All Firms"})]}),(0,e.jsxs)("button",{onClick:F,className:"w-full px-4 py-3 flex items-center gap-3 text-blue-400 hover:bg-blue-500/10 transition-colors",children:[(0,e.jsx)(Xt,{className:"w-5 h-5"}),(0,e.jsx)("span",{className:"text-sm font-medium",children:"Create New Organization"})]})]})]})})]})},Xe={prop_firm:{icon:ce,label:"Prop Firm",color:"text-blue-400",bgColor:"bg-blue-500/20"},trading_group:{icon:q,label:"Trading Group",color:"text-green-400",bgColor:"bg-green-500/20"},ria:{icon:re,label:"RIA",color:"text-purple-400",bgColor:"bg-purple-500/20"},brokerage:{icon:Zt,label:"Brokerage",color:"text-orange-400",bgColor:"bg-orange-500/20"},educator:{icon:ht,label:"Educator",color:"text-pink-400",bgColor:"bg-pink-500/20"}},se=({label:l,value:$,icon:L,change:h,changeLabel:u="vs last period",color:E="blue",isLoading:b=!1,onClick:S=null,badge:I=null})=>{const f={blue:"bg-blue-500/20 text-blue-400",green:"bg-green-500/20 text-green-400",red:"bg-red-500/20 text-red-400",yellow:"bg-yellow-500/20 text-yellow-400",purple:"bg-purple-500/20 text-purple-400",teal:"bg-teal-500/20 text-teal-400",orange:"bg-orange-500/20 text-orange-400",gray:"bg-gray-500/20 text-gray-400 dark:text-gray-500 dark:text-gray-400 dark:text-gray-500 dark:text-gray-400"};return b?(0,e.jsx)("div",{className:"bg-white dark:bg-slate-800 rounded-xl p-3 sm:p-5 border border-slate-200 dark:border-slate-700 animate-pulse",children:(0,e.jsxs)("div",{className:"flex items-center gap-2 sm:gap-4",children:[(0,e.jsx)("div",{className:"w-9 h-9 sm:w-12 sm:h-12 bg-slate-200 dark:bg-slate-700 rounded-xl"}),(0,e.jsxs)("div",{className:"flex-1",children:[(0,e.jsx)("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-16 sm:w-20 mb-2"}),(0,e.jsx)("div",{className:"h-5 sm:h-6 bg-slate-200 dark:bg-slate-700 rounded w-16 sm:w-24"})]})]})}):(0,e.jsx)(M.div,{initial:{opacity:0,y:20}
2,animate:{opacity:1,y:0},onClick:S,className:`bg-white dark:bg-slate-800 rounded-xl p-3 sm:p-5 border border-slate-200 dark:border-slate-700 hover:border-slate-300 dark:hover:border-slate-600 transition-colors ${S?"cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-750":""}`,children:(0,e.jsxs)("div",{className:"flex items-center gap-2 sm:gap-4",children:[(0,e.jsx)("div",{className:`p-2 sm:p-3 rounded-xl ${f[E]||f.blue}`,children:(0,e.jsx)(L,{className:"w-4 h-4 sm:w-6 sm:h-6"})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1 sm:gap-2",children:[(0,e.jsx)("p",{className:"text-xs sm:text-sm text-slate-500 dark:text-slate-400 truncate",children:l}),I&&(0,e.jsx)("span",{className:"px-1.5 sm:px-2 py-0.5 text-[10px] sm:text-xs font-medium rounded-full bg-red-500/20 text-red-400 flex-shrink-0",children:I})]}),(0,e.jsx)("p",{className:"text-lg sm:text-2xl font-bold text-slate-900 dark:text-white truncate",children:$}),h!==void 0&&(0,e.jsxs)("p",{className:`text-[10px] sm:text-xs flex items-center gap-1 mt-0.5 sm:mt-1 ${h>=0?"text-green-400":"text-red-400"}`,children:[h>=0?"â":"â"," ",Math.abs(h),"% ",(0,e.jsx)("span",{className:"hidden sm:inline",children:u})]}),S&&(0,e.jsx)("p",{className:"text-[10px] sm:text-xs text-blue-400 mt-0.5 sm:mt-1 hidden sm:block",children:"Click to view details â"})]})]})})},Ht={challenge1:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",challenge2:"bg-orange-500/20 text-orange-400 border-orange-500/30",funded:"bg-green-500/20 text-green-400 border-green-500/30",suspended:"bg-red-500/20 text-red-400 border-red-500/30",terminated:"bg-gray-500/20 text-gray-400 dark:text-gray-500 dark:text-gray-400 dark:text-gray-500 dark:text-gray-400 border-gray-500/30"},ma={challenge1:"Challenge 1",challenge2:"Challenge 2",funded:"Funded",suspended:"Suspended",terminated:"Terminated"},bt=({phase:l})=>(0,e.jsx)("span",{className:`px-2 py-1 text-xs font-medium rounded-md border ${Ht[l]||Ht.terminated}`,children:ma[l]||l}),qt={owner:"bg-purple-500/20 text-purple-400 border-purple-500/30",admin:"bg-blue-500/20 text-blue-400 border-blue-500/30",manager:"bg-teal-500/20 text-teal-400 border-teal-500/30",trader:"bg-slate-500/20 text-slate-500 dark:text-slate-400 border-slate-500/30"},ft=({role:l})=>(0,e.jsx)("span",{className:`px-2 py-1 text-xs font-medium rounded-md border capitalize ${qt[l]||qt.trader}`,children:l}),ha=({isOpen:l,onClose:$,onInvite:L,isLoading:h,orgId:u,orgType:E,orgAccountTiers:b,orgName:S})=>{const{user:I}=vt(),[f,P]=(0,i.useState)(""),[j,p]=(0,i.useState)("trader"),[k,F]=(0,i.useState)(5e4),[o,w]=(0,i.useState)("evaluation_account"),[C,_]=(0,i.useState)("phase1"),[a,N]=(0,i.useState)("link"),[A,ie]=(0,i.useState)(!1),[Y,v]=(0,i.useState)(""),[O,T]=(0,i.useState)(!1),[U,J]=(0,i.useState)(1),[X,Q]=(0,i.useState)(30),[K,Ie]=(0,i.useState)(1),Re=[{id:"phase1",label:"Phase 1",description:"Initial Evaluation",color:"blue"},{id:"phase2",label:"Phase 2",description:"Verification Phase",color:"purple"},{id:"phase3",label:"Phase 3",description:"Final Assessment",color:"teal"}],$e={blue:{card:"bg-blue-500/15 border-blue-500/60",text:"text-blue-400",dot:"bg-blue-400"},purple:{card:"bg-purple-500/15 border-purple-500/60",text:"text-purple-400",dot:"bg-purple-400"},teal:{card:"bg-teal-500/15 border-teal-500/60",text:"text-teal-400",dot:"bg-teal-400"}},xe=b?.length>0?b:ia,D=j==="trader",ae=xe.find(r=>r.value===k)||xe[1]||xe[0],z=ae?.rules||{maxDailyLoss:5,maxTotalDrawdown:10,profitTarget:10,minTradingDays:5},fe=async()=>{if(!(!I?.uid||!u)){T(!0);try{const r=Ks(o),V=Re.find(Fe=>Fe.id===C),B=o==="evaluation_account",Oe=D?{dailyLossLimit:z.maxDailyLoss||5,maxDrawdown:z.maxTotalDrawdown||10,profitTarget:z.profitTarget||10,minTradingDays:z.minTradingDays||5,maxLeverage:z.maxLeverage,newsTrading:z.newsTrading,weekendHolding:z.weekendHolding}:{};v((await Qs({orgId:u,role:j,accountBalance:D?k:null,accountTier:ae?.description||"Standard",inviteType:o,orgName:S||"Organization",metadata:{inviteTypeLabel:r.label,description:r.description,...B&&D&&{phase:C,phaseLabel:V?.label||"Phase 1",ph
2aseDescription:V?.description||"Evaluation Phase"}},tierRules:Oe,singleUse:K===1,maxUses:K>1?K:null,expiresInDays:X,createdBy:I.uid})).inviteUrl),J(3)}catch(r){console.error("Error generating token:",r)}finally{T(!1)}}},et=async()=>{try{await navigator.clipboard.writeText(Y),ie(!0),setTimeout(()=>ie(!1),3e3)}catch{}},ne=()=>{P(""),p("trader"),F(5e4),w("evaluation_account"),_("phase1"),N("link"),v(""),J(1),Q(30),Ie(1),$()},tt=()=>{if(f.trim()){const r={email:f.trim(),role:j,...D&&{accountBalance:k,accountTier:ae?.description}};L(f.trim(),j,r),P("")}};return l?(0,e.jsx)(Pe,{children:(0,e.jsx)(M.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/70 backdrop-blur-sm z-50 flex items-center justify-center p-3 sm:p-4",onClick:ne,children:(0,e.jsxs)(M.div,{initial:{scale:.95,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.95,opacity:0,y:20},transition:{type:"spring",damping:25,stiffness:300},className:"bg-slate-50 dark:bg-slate-900 rounded-2xl border border-slate-200 dark:border-slate-700/50 w-full max-w-lg shadow-2xl max-h-[92vh] overflow-hidden flex flex-col",onClick:r=>r.stopPropagation(),children:[(0,e.jsxs)("div",{className:"relative overflow-hidden flex-shrink-0",children:[(0,e.jsx)("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-600 via-indigo-600 to-purple-700"}),(0,e.jsxs)("div",{className:"relative p-4 sm:p-5",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 bg-white/20 backdrop-blur-sm rounded-xl flex items-center justify-center border border-white/20",children:(0,e.jsx)(mt,{className:"w-5 h-5 text-slate-900 dark:text-white"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"text-base sm:text-lg font-bold text-slate-900 dark:text-white leading-tight",children:U===3?"Invite Link Ready":U===1?"Setup Invite":"Account Size & Rules"}),(0,e.jsx)("p",{className:"text-white/60 text-xs mt-0.5",children:S?`Inviting to ${S}`:"Generate a secure invite link"})]})]}),(0,e.jsx)("button",{onClick:ne,className:"w-8 h-8 bg-white/10 hover:bg-black/10 dark:hover:bg-white/25 rounded-lg flex items-center justify-center transition-colors border border-white/10",children:(0,e.jsx)(ut,{className:"w-4 h-4 text-slate-900 dark:text-white"})})]}),U<3&&(0,e.jsx)("div",{className:"mt-4 flex gap-1.5",children:(D&&a==="link"?[1,2]:[1]).map(r=>(0,e.jsx)("div",{className:`h-1 flex-1 rounded-full transition-all duration-300 ${U>=r?"bg-white":"bg-white/30"}`},r))})]})]}),(0,e.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,e.jsxs)(Pe,{mode:"wait",children:[U===3&&(0,e.jsxs)(M.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"p-4 sm:p-5 space-y-4",children:[(0,e.jsxs)("div",{className:"text-center py-3",children:[(0,e.jsx)(M.div,{initial:{scale:0,rotate:-15},animate:{scale:1,rotate:0},transition:{type:"spring",duration:.5,delay:.1},className:"w-16 h-16 bg-gradient-to-br from-green-400 to-emerald-500 rounded-2xl flex items-center justify-center mx-auto mb-3 shadow-lg shadow-green-500/30",children:(0,e.jsx)(be,{className:"w-8 h-8 text-slate-900 dark:text-white"})}),(0,e.jsx)("h3",{className:"text-lg font-bold text-slate-900 dark:text-white",children:"Link Generated!"}),(0,e.jsx)("p",{className:"text-slate-500 dark:text-slate-400 text-sm mt-1",children:D?`${ae?.label||"$"+k.toLocaleString()} · ${o==="evaluation_account"?`Phase ${C.replace("phase","")} Evaluation`:"Funded Account"}`:`${j.charAt(0).toUpperCase()+j.slice(1)} access`})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl border border-slate-200 dark:border-slate-700 p-3",children:[(0,e.jsx)("p",{className:"text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wide mb-2",children:"Invite Link"}),(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsx)("div",{className:"flex-1 bg-slate-50 dark:bg-slate-900 rounded-lg px-3 py-2.5 text-slate-500 dark:text-slate-400 text-sm truncate border border-slate-700/60 min-w-0",children:Y}),(0,e.jsxs)("button",{onClick:et,className:`px-4 py-2.5 rounded-lg font-semibold text-sm transition-all flex items-center gap-1.5 flex-shrink-0 ${A?"bg-green-500 text-white shadow-lg shadow-green-500/25":"bg-blue-600 hover:bg-blue-500 text-white"}`,children:[A?(0,e.jsx)(be,{className:"w-4 h-4"}):(0,e.jsx)(Hs,{className:"w-4 h-4"}),A?"Copied!":"Copy"]})]})]}),(0,e.jsxs)("div",{className:"grid grid-cols-3 gap-2",children:[D&&(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl p-3 border border-slate-200 dark:border-slate-700 text-center",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 mb-1",children:"Balance"}),(0,e.jsxs)("p",{className:"text-green-400 font-bold text-sm",children:["$",(k/1e3).toFixed(0),"K"]})]}),(0,e.jsxs)("div",{className:`bg-white dark:bg-slate-800 rounded-xl p-3 border border-slate-200 dark:border-slate-700 text-center ${D?"":"col-span-2"}`,children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 mb-1",children:"Expires"}),(0,e.jsxs)("p",{className:"text-slate-900 dark:text-white font-semibold text-sm",children:[X,"d"]})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl p-3 border border-slate-200 dark:border-slate-700 text-center",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 mb-1",children:"Uses"}),(0,e.jsx)("p",{className:"text-slate-900 dark:text-white font-semibold text-sm",children:K===1?"1Ã":K>=999?"â":`${K}Ã`})]})]}),(0,e.jsxs)("div",{className:"flex gap-3 bg-blue-500/10 border border-blue-500/25 rounded-xl p-3",children:[(0,e.jsx)(re,{className:"w-4 h-4 text-blue-400 mt-0.5 flex-shrink-0"}),(0,e.jsxs)("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:[(0,e.jsx)("span",{className:"text-blue-400 font-semibold",children:"Secure token link."})," ","New users signing up via this link are auto-enrolled. Existing users see a confirmation screen before joining."]})]}),(0,e.jsx)("button",{onClick:()=>{J(1),v("")},className:"w-full py-2.5 text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white text-sm border border-slate-200 dark:border-slate-700 rounded-xl hover:border-slate-300 dark:hover:border-slate-600 transition-all",children:"Generate Another Link"})]},"step3"),U===1&&(0,e.jsxs)(M.div,{initial:{opacity:0,x:20}
2,animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"p-4 sm:p-5 space-y-4",children:[(0,e.jsx)("div",{className:"flex gap-1 p-1 bg-white dark:bg-slate-800 rounded-xl border border-slate-200 dark:border-slate-700",children:[{id:"link",label:"Generate Link",Icon:Le},{id:"email",label:"Email Invite",Icon:ct}].map(r=>(0,e.jsxs)("button",{onClick:()=>N(r.id),style:{WebkitTapHighlightColor:"transparent"},className:`flex-1 flex items-center justify-center gap-2 py-2.5 px-3 min-h-[44px] rounded-lg text-sm font-medium transition-all touch-manipulation active:scale-[0.97] select-none ${a===r.id?"bg-blue-600 text-white shadow-md shadow-blue-500/30":"text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white active:bg-slate-100 dark:active:bg-slate-700/50"}`,children:[(0,e.jsx)(r.Icon,{className:"w-4 h-4"}),r.label]},r.id))}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200 mb-2.5 block",children:"Role"}),(0,e.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{id:"trader",label:"Trader",desc:"Log & view trades",activeClass:"bg-green-500/15 border-green-500/60 text-green-400"},{id:"manager",label:"Manager",desc:"View reports",activeClass:"bg-teal-500/15 border-teal-500/60 text-teal-400"},{id:"admin",label:"Admin",desc:"Full access",activeClass:"bg-blue-500/15 border-blue-500/60 text-blue-400"}].map(r=>(0,e.jsxs)("button",{onClick:()=>{p(r.id),r.id!=="trader"?w("trader_standard"):w("evaluation_account")},style:{WebkitTapHighlightColor:"transparent"},className:`p-3 min-h-[64px] rounded-xl border text-left transition-all touch-manipulation active:scale-[0.97] select-none ${j===r.id?`${r.activeClass} ring-2 ring-current/30 shadow-md`:"bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700 hover:border-slate-300 dark:hover:border-slate-600 active:bg-slate-50 dark:active:bg-slate-700/60"}`,children:[(0,e.jsx)("p",{className:`text-sm font-semibold ${j===r.id?"":"text-slate-900 dark:text-white"}`,children:r.label}),(0,e.jsx)("p",{className:"text-xs text-slate-500 mt-0.5",children:r.desc})]},r.id))})]}),D&&(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200 mb-2.5 block",children:"Account Type"}),(0,e.jsx)("div",{className:"grid grid-cols-2 gap-3",children:[{id:"evaluation_account",label:"Evaluation",sub:"Challenge / testing phase",Icon:De,cardActive:"bg-blue-500/15 border-blue-500/60",iconActive:"bg-blue-500/25 text-blue-400",textActive:"text-blue-400"},{id:"funded_account",label:"Funded",sub:"Live trading account",Icon:ce,cardActive:"bg-green-500/15 border-green-500/60",iconActive:"bg-green-500/25 text-green-400",textActive:"text-green-400"}].map(r=>{const V=o===r.id;return(0,e.jsxs)("button",{onClick:()=>w(r.id),style:{WebkitTapHighlightColor:"transparent"},className:`p-4 min-h-[100px] rounded-xl border text-left transition-all relative overflow-hidden touch-manipulation active:scale-[0.97] select-none ${V?`${r.cardActive} ring-2 ring-current/30 shadow-md`:"bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700 hover:border-slate-300 dark:hover:border-slate-600 active:bg-slate-50 dark:active:bg-slate-700/60"}`,children:[(0,e.jsx)("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center mb-2.5 ${V?r.iconActive:"bg-slate-200 dark:bg-slate-700 text-slate-500 dark:text-slate-400"}`,children:(0,e.jsx)(r.Icon,{className:"w-5 h-5"})}),(0,e.jsx)("p",{className:`font-semibold text-sm ${V?r.textActive:"text-slate-900 dark:text-white"}`,children:r.label}),(0,e.jsx)("p",{className:"text-xs text-slate-500 mt-0.5",children:r.sub}),V&&(0,e.jsx)("div",{className:`absolute top-2 right-2 w-5 h-5 rounded-full ${r.iconActive} flex items-center justify-center`,children:(0,e.jsx)(be,{className:"w-3 h-3"})})]},r.id)})})]}),D&&o==="evaluation_account"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 mb-2.5",children:[(0,e.jsx)("label",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:"Evaluation Phase"}),(0,e.jsx)("span",{className:"text-xs bg-blue-500/20 text-blue-400 px-2 py-0.5 rounded-full border border-blue-500/30",children:"Unique link per phase"})]}),(0,e.jsx)("div",{className:"grid grid-cols-3 gap-2",children:Re.map(r=>{const V=$e[r.color]||$e.blue,B=C===r.id;return(0,e.jsxs)("button",{onClick:()=>_(r.id),style:{WebkitTapHighlightColor:"transparent"},className:`p-3 min-h-[72px] rounded-xl border text-center transition-all touch-manipulation active:scale-[0.97] select-none ${B?`${V.card} ring-2 shadow-md`:"bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700 hover:border-slate-300 dark:hover:border-slate-600 active:bg-slate-50 dark:active:bg-slate-700/60"}`,children:[B&&(0,e.jsx)("div",{className:`w-2 h-2 rounded-full ${V.dot} mx-auto mb-1.5`}),(0,e.jsx)("p",{className:`text-sm font-bold ${B?V.text:"text-slate-900 dark:text-white"}`,children:r.label}),(0,e.jsx)("p",{className:"text-xs text-slate-500 mt-0.5 leading-tight",children:r.description})]},r.id)})})]}),a==="email"&&(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200 mb-2 block",children:"Email Address"}),(0,e.jsx)("input",{type:"email",placeholder:"[email protected]",value:f,onChange:r=>P(r.target.value),className:"w-full px-4 py-2.5 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white placeholder-slate-400 dark:placeholder-slate-500 focus:outline-none focus:border-blue-500 text-sm"})]})]},"step1"),U===2&&(0,e.jsxs)(M.div,{initial:{opacity:0,x:20}
2,animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"p-4 sm:p-5 space-y-4",children:[D?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-2.5",children:[(0,e.jsx)("label",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:"Account Balance"}),(0,e.jsxs)("span",{className:"text-sm font-bold text-green-400",children:["$",k.toLocaleString()]})]}),(0,e.jsx)("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-4",children:xe.map(r=>(0,e.jsx)("button",{onClick:()=>F(r.value),style:{WebkitTapHighlightColor:"transparent"},className:`py-3 min-h-[48px] rounded-xl border text-center text-sm font-semibold transition-all touch-manipulation active:scale-[0.97] select-none ${k===r.value?"bg-green-500/15 border-green-500/60 text-green-400 ring-2 ring-green-500/40 shadow-md shadow-green-500/20":"bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700 text-slate-600 dark:text-slate-300 hover:border-slate-300 dark:hover:border-slate-600 active:bg-slate-50 dark:active:bg-slate-700/60"}`,children:r.label},r.value))}),(0,e.jsx)("p",{className:"text-xs text-slate-500 mt-1.5",children:"Risk rules below update based on selected balance"})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200 mb-2.5 block",children:"Trading Rules Preview"}),(0,e.jsx)("div",{className:"grid grid-cols-2 gap-2",children:[{label:"Daily Loss Limit",value:`${z.maxDailyLoss??5}%`,colorClass:"text-red-400",Icon:pe},{label:"Max Drawdown",value:`${z.maxTotalDrawdown??10}%`,colorClass:"text-orange-400",Icon:re},{label:"Profit Target",value:`${z.profitTarget??10}%`,colorClass:"text-green-400",Icon:De},{label:"Min Trading Days",value:`${z.minTradingDays??5}`,colorClass:"text-blue-400",Icon:xt}].map((r,V)=>(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl p-3 border border-slate-200 dark:border-slate-700",children:[(0,e.jsxs)("div",{className:`flex items-center gap-1.5 text-xs ${r.colorClass} mb-1`,children:[(0,e.jsx)(r.Icon,{className:"w-3 h-3"}),r.label]}),(0,e.jsx)("div",{className:"text-slate-900 dark:text-white font-bold text-xl",children:r.value})]},V))})]})]}):(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800/60 rounded-xl p-4 border border-slate-200 dark:border-slate-700",children:[(0,e.jsxs)("p",{className:"text-slate-600 dark:text-slate-300 text-sm",children:["Generating a ",(0,e.jsx)("span",{className:"text-slate-900 dark:text-white font-semibold capitalize",children:j})," invite for"," ",(0,e.jsx)("span",{className:"text-slate-900 dark:text-white font-semibold",children:S||"your organization"}),"."]}),(0,e.jsx)("p",{className:"text-xs text-slate-500 mt-2",children:j==="manager"?"Can view all traders, reports, and performance data.":"Full access including settings and member management."})]}),(0,e.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-xs font-medium text-slate-500 dark:text-slate-400 mb-1.5 block",children:"Link Expires In"}),(0,e.jsx)("select",{value:X,onChange:r=>Q(Number(r.target.value)),className:"w-full px-3 py-2.5 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white text-sm focus:outline-none focus:border-blue-500",children:[7,14,30,60,90,365].map(r=>(0,e.jsxs)("option",{value:r,children:[r," days"]},r))})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-xs font-medium text-slate-500 dark:text-slate-400 mb-1.5 block",children:"Max Uses"}),(0,e.jsxs)("select",{value:K,onChange:r=>Ie(Number(r.target.value)),className:"w-full px-3 py-2.5 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-xl text-slate-900 dark:text-white text-sm focus:outline-none focus:border-blue-500",children:[(0,e.jsx)("option",{value:1,children:"Single use"}),(0,e.jsx)("option",{value:5,children:"5 uses"}),(0,e.jsx)("option",{value:10,children:"10 uses"}),(0,e.jsx)("option",{value:25,children:"25 uses"}),(0,e.jsx)("option",{value:50,children:"50 uses"}),(0,e.jsx)("option",{value:100,children:"100 uses"}),(0,e.jsx)("option",{value:999,children:"Unlimited"})]})]})]})]},"step2")]})}),(0,e.jsx)("div",{className:"flex-shrink-0 p-4 border-t border-slate-200 dark:border-slate-800 flex gap-3",children:U===3?
2(0,e.jsx)("button",{onClick:ne,className:"w-full py-3 bg-white dark:bg-slate-800 hover:bg-slate-700 text-slate-900 dark:text-white rounded-xl font-semibold transition-colors border border-slate-200 dark:border-slate-700",children:"Done"}):U===2?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{onClick:()=>J(1),className:"px-5 py-3 bg-white dark:bg-slate-800 hover:bg-slate-700 text-slate-600 dark:text-slate-300 rounded-xl font-medium transition-colors border border-slate-200 dark:border-slate-700",children:"Back"}),(0,e.jsx)("button",{onClick:fe,disabled:O,className:"flex-1 py-3 bg-gradient-to-r from-green-600 to-emerald-600 hover:from-green-500 hover:to-emerald-500 text-white rounded-xl font-semibold transition-all flex items-center justify-center gap-2 disabled:opacity-60 shadow-lg shadow-green-900/30",children:O?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Generating..."]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Le,{className:"w-4 h-4"}),"Generate Invite Link"]})})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{onClick:ne,className:"px-5 py-3 text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white transition-colors",children:"Cancel"}),a==="link"?D?(0,e.jsxs)("button",{onClick:()=>J(2),className:"flex-1 py-3 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white rounded-xl font-semibold transition-all flex items-center justify-center gap-2 shadow-lg shadow-blue-900/30",children:["Next: Account Size",(0,e.jsx)(Ze,{className:"w-4 h-4"})]}):(0,e.jsxs)("button",{onClick:()=>J(2),className:"flex-1 py-3 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white rounded-xl font-semibold transition-all flex items-center justify-center gap-2",children:["Next: Settings",(0,e.jsx)(Ze,{className:"w-4 h-4"})]}):(0,e.jsxs)("button",{onClick:tt,disabled:!f.trim()||h,className:"flex-1 py-3 bg-blue-600 hover:bg-blue-500 text-white rounded-xl font-semibold transition-all flex items-center justify-center gap-2 disabled:opacity-50",children:[h?(0,e.jsx)("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):(0,e.jsx)(ct,{className:"w-4 h-4"}),"Send Invitation"]})]})})]})})}):null},ga=({isOpen:l,onAccept:$,onDecline:L,isAccepting:h,inviteData:u})=>{if(!l||!u)return null;const E=u.organization,b=u.tierRules||{};return(0,e.jsx)(Pe,{children:(0,e.jsx)(M.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4",onClick:L,children:(0,e.jsxs)(M.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},onClick:S=>S.stopPropagation(),className:"bg-gradient-to-br from-slate-800 to-slate-900 rounded-2xl w-full max-w-lg shadow-2xl border border-slate-200 dark:border-slate-700/50 overflow-hidden",children:[(0,e.jsxs)("div",{className:"bg-gradient-to-r from-blue-600 to-indigo-600 p-6 text-center",children:[(0,e.jsx)("div",{className:"w-16 h-16 bg-white/20 rounded-2xl flex items-center justify-center mx-auto mb-4",children:(0,e.jsx)(ce,{className:"w-8 h-8 text-slate-900 dark:text-white"})}),(0,e.jsx)("h2",{className:"text-2xl font-bold text-slate-900 dark:text-white",children:"You're Invited!"}),(0,e.jsxs)("p",{className:"text-white/80 mt-2",children:["You've been invited to join ",(0,e.jsx)("span",{className:"font-semibold",children:E?.name||"an organization"})]})]}),(0,e.jsxs)("div",{className:"p-6 space-y-4",children:[(0,e.jsxs)("div",{className:"bg-slate-700/30 rounded-xl p-4",children:[(0,e.jsx)("h3",{className:"text-sm font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide mb-3",children:"Organization Details"}),(0,e.jsxs)("div",{className:"space-y-2",children:[E?.name&&(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)(q,{className:"w-5 h-5 text-slate-500 dark:text-slate-400"}),(0,e.jsx)("span",{className:"text-slate-900 dark:text-white",children:E.name})]}),u.accountBalance&&(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)(pt,{className:"w-5 h-5 text-green-400"}),(0,e.jsxs)("span",{className:"text-slate-900 dark:text-white",children:["Account Size: $",u.accountBalance?.toLocaleString()]})]}),u.inviteTypeLabel&&(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)(Te,{className:"w-5 h-5 text-blue-400"}),(0,e.jsx)("span",{className:"text-slate-900 dark:text-white",children:u.inviteTypeLabel})]})]})]}),(b.dailyLossLimit||b.maxDrawdown||b.profitTarget)&&(0,e.jsxs)("div",{className:"bg-slate-700/30 rounded-xl p-4",children:[(0,e.jsx)("h3",{className:"text-sm font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide mb-3",children:"Trading Rules"}),(0,e.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[b.dailyLossLimit&&(0,e.jsxs)("div",{className:"text-center p-2 bg-slate-600/30 rounded-lg",children:[(0,e.jsxs)("div",{className:"text-lg font-semibold text-red-400",children:[b.dailyLossLimit,"%"]}),(0,e.jsx)("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:"Max Daily Loss"})]}),b.maxDrawdown&&(0,e.jsxs)("div",{className:"text-center p-2 bg-slate-600/30 rounded-lg",children:[(0,e.jsxs)("div",{className:"text-lg font-semibold text-orange-400",children:[b.maxDrawdown,"%"]}),(0,e.jsx)("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:"Max Drawdown"})]}),b.profitTarget&&(0,e.jsxs)("div",{className:"text-center p-2 bg-slate-600/30 rounded-lg",children:[(0,e.jsxs)("div",{className:"text-lg font-semibold text-green-400",children:[b.profitTarget,"%"]}),(0,e.jsx)("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:"Profit Target"})]}),b.minTradingDays&&(0,e.jsxs)("div",{className:"text-center p-2 bg-slate-600/30 rounded-lg",children:[(0,e.jsx)("div",{className:"text-lg font-semibold text-blue-400",children:b.minTradingDays}),(0,e.jsx)("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:"Min Trading Days"})]})]})]}),(0,e.jsxs)("div",{className:"bg-gradient-to-r from-yellow-600/20 to-amber-600/20 border border-yellow-500/30 rounded-xl p-4 text-center",children:[(0,e.jsxs)("div",{className:"flex items-center justify-center gap-2 text-yellow-400",children:[(0,e.jsx)(re,{className:"w-5 h-5"}),(0,e.jsx)("span",{className:"font-medium",children:"Pro Features Included"})]}),(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"You'll get access to Pro tier features while in this organization"})]})]}),(0,e.jsxs)("div",{className:"p-6 pt-0 flex gap-3",children:[(0,e.jsx)("button",{onClick:L,disabled:h,className:"flex-1 px-4 py-3 bg-slate-200 dark:bg-slate-700 hover:bg-slate-600 text-slate-900 dark:text-white rounded-xl font-medium transition-colors disabled:opacity-50",children:"Decline"}),(0,e.jsx)("button",{onClick:$,disabled:h,className:"flex-1 px-4 py-3 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white rounded-xl font-medium transition-all flex items-center justify-center gap-2 disabled:opacity-50",children:h?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Ke,{className:"w-5 h-5 animate-spin"}),"Joining..."]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(be,{className:"w-5 h-5"}),"Accept Invite"]})})]})]})})})},ts=({trader:l,orgRiskRules:$})=>{const L=l.stats||{},h=$||{},u=l.startingBalance||l.accountBalance||h.accountBalance||5e4,E=l.currentBalance||L.currentBalance||u,b=h.maxDailyLoss||h.dailyLossLimit||1e3,S=h.maxTotalDrawdown||h.maxDrawdownPercent||10,I=h.profitTarget||1e4,f=l.dailyPnl||L.dailyPnl||0,P=l.totalPnl||L.totalPnl||E-u,j=(u-E)/u*100;S/100*u;let p="good",k="On Track",F="Following all rules",o=[];f<0&&Math.abs(f)>=b?(p="failed",k="Breached",F="Daily loss limit exceeded"):f<0&&Math.abs(f)>=b*.8&&(p="warning",k="At Risk",o.push(`Daily loss: $${Math.abs(f).toLocaleStr
2ing()} / $${b.toLocaleString()}`)),j>=S?(p="failed",k="Breached",F=`Max drawdown exceeded (${j.toFixed(1)}%)`):j>=S*.8&&p!=="failed"&&(p="warning",k="At Risk",o.push(`Drawdown: ${j.toFixed(1)}% / ${S}%`));const w=P/I*100;P>=I&&p==="good"?(k="Target Met",F="Profit target achieved! ð"):w>=80&&p==="good"?F=`${w.toFixed(0)}% to profit target`:p==="good"&&P>0?F=`+$${P.toLocaleString()} profit`:p==="good"&&(F="Within risk limits"),l.isActive||(p="suspended",k="Suspended",F="Account suspended");const C={good:{bg:"bg-green-500/20",border:"border-green-500/30",text:"text-green-400",dot:"bg-green-500",glow:"shadow-green-500/20"},warning:{bg:"bg-yellow-500/20",border:"border-yellow-500/30",text:"text-yellow-400",dot:"bg-yellow-500 animate-pulse",glow:"shadow-yellow-500/20"},failed:{bg:"bg-red-500/20",border:"border-red-500/30",text:"text-red-400",dot:"bg-red-500 animate-pulse",glow:"shadow-red-500/20"},suspended:{bg:"bg-slate-500/20",border:"border-slate-500/30",text:"text-slate-500 dark:text-slate-400",dot:"bg-slate-500",glow:""}}[p];return(0,e.jsxs)("div",{className:"group relative",children:[(0,e.jsxs)("div",{className:`flex items-center gap-2 px-2.5 py-1.5 rounded-lg ${C.bg} border ${C.border} ${C.glow}`,children:[(0,e.jsx)("span",{className:`w-2 h-2 rounded-full ${C.dot}`}),(0,e.jsx)("span",{className:`text-xs font-semibold ${C.text}`,children:k})]}),(0,e.jsxs)("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-3 py-2 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-xl opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all z-50 whitespace-nowrap",children:[(0,e.jsx)("p",{className:"text-xs text-slate-900 dark:text-white font-medium",children:F}),o.length>0&&(0,e.jsx)("div",{className:"mt-1 space-y-0.5",children:o.map((_,a)=>(0,e.jsxs)("p",{className:"text-xs text-yellow-400",children:["â ",_]},a))}),(0,e.jsx)("div",{className:"absolute top-full left-1/2 -translate-x-1/2 -mt-1 border-4 border-transparent border-t-slate-800"})]})]})},ua=({trader:l,onViewProfile:$,onViewTrades:L,onSuspend:h,onRemove:u,onSendMessage:E,onLinkAccount:b,onAdvancePhase:S,onResetPhase:I,canManage:f,orgRiskRules:P})=>{const[j,p]=(0,i.useState)(!1),[k,F]=(0,i.useState)({top:0,left:0}),o=i.useRef(null),w=l.stats||{},C=l.startingBalance||l.accountBalance||P?.accountBalance||5e4,_=l.currentBalance||w.currentBalance||C+(w.totalPnl||0),a=_-C,N=C>0?a/C*100:0,A=v=>v==null?"-":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0}).format(v),ie=v=>v==null?"-":`${v.toFixed(1)}%`,Y=v=>v?(v.toDate?v.toDate():new Date(v)).toLocaleDateString("en-US",{month:"short",day:"numeric"}):"-";return(0,e.jsxs)("tr",{className:`border-b border-slate-200 dark:border-slate-700/50 hover:bg-slate-800/50 transition-colors ${l.isActive?"":"opacity-60"}`,children:[(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center text-white font-semibold",children:l.displayName?.charAt(0)?.toUpperCase()||"?"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("button",{onClick:()=>L?.(l.id,l),className:"font-medium text-slate-900 dark:text-white hover:text-blue-400 transition-colors text-left",title:"Click to view member's org trades",children:l.displayName}),(0,e.jsx)("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:l.email})]})]})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)(ts,{trader:l,orgRiskRules:P})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-semibold text-slate-900 dark:text-white",children:A(_)}),(0,e.jsxs)("p",{className:`text-xs ${a>=0?"text-green-400":"text-red-400"}`,children:[a>=0?"+":"",A(a)," (",N>=0?"+":"",N.toFixed(1),"%)"]})]})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)(ft,{role:l.role})}),(0,e.jsx)("td",{className:"px-4 py-3",children:l.evaluationPhase&&(0,e.jsxs)("div",{className:"space-y-1 min-w-[120px]",children:[(0,e.jsx)(bt,{phase:l.evaluationPhase}),(()=>{const v=P?.evaluationPhases?.find?.(T=>T.id===l.evaluationPhase)||null,O=Qt(l.stats,v);return O?(0,e.jsxs)("div",{className:"space-y-0.5 mt-1",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1",children:[(0,e.jsx)("div",{className:"flex-1 h-1 bg-slate-700 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:`h-full ${O.status==="failed"?"bg-red-500":O.status==="complete"?"bg-green-500":O.status==="at_risk"?"bg-orange-500":"bg-blue-500"} transition-all`,style:{width:`${Math.max(2,O.profitPct)}%`}})}
2),(0,e.jsxs)("span",{className:"text-[10px] text-slate-500 w-7 text-right",children:[O.profitPct.toFixed(0),"%"]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1",children:[(0,e.jsx)("div",{className:"flex-1 h-1 bg-slate-700 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:`h-full ${O.drawdownPct>=90?"bg-red-500":O.drawdownPct>=75?"bg-orange-500":"bg-slate-500"} transition-all`,style:{width:`${Math.max(2,O.drawdownPct)}%`}})}),(0,e.jsxs)("span",{className:"text-[10px] text-slate-500 w-7 text-right",children:[O.drawdownPct.toFixed(0),"%DD"]})]})]}):null})()]})}),(0,e.jsx)("td",{className:"px-4 py-3 text-right",children:(0,e.jsx)("span",{className:`font-semibold ${(w.totalPnl||0)>=0?"text-green-400":"text-red-400"}`,children:A(w.totalPnl)})}),(0,e.jsx)("td",{className:"px-4 py-3 text-right text-slate-600 dark:text-slate-300",children:ie(w.winRate)}),(0,e.jsx)("td",{className:"px-4 py-3 text-right text-slate-600 dark:text-slate-300",children:w.totalTrades||0}),(0,e.jsx)("td",{className:"px-4 py-3 text-sm text-slate-500 dark:text-slate-400",children:Y(w.lastTradeDate||l.lastActiveAt)}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsxs)("div",{className:"relative",children:[(0,e.jsx)("button",{ref:o,onClick:()=>{if(!j&&o.current){const v=o.current.getBoundingClientRect(),O=192,T=200,U=window.innerWidth,J=window.innerHeight;let X=v.bottom+4,Q=v.right-O;X+T>J&&(X=v.top-T-4),Q<8&&(Q=v.left),Q+O>U-8&&(Q=U-O-8),F({top:X,left:Q})}p(!j)},className:"p-2 hover:bg-slate-700 rounded-lg transition-colors",children:(0,e.jsx)(Ys,{className:"w-4 h-4 text-slate-500 dark:text-slate-400"})}),j&&(0,ca.createPortal)((0,e.jsxs)("div",{className:"fixed inset-0",style:{zIndex:99999},children:[(0,e.jsx)("div",{className:"absolute inset-0",onClick:()=>p(!1)}),(0,e.jsxs)("div",{className:"absolute w-48 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-xl py-1",style:{to
2p:k.top,left:k.left},children:[(0,e.jsxs)("button",{onClick:()=>{L?.(l.id,l),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-blue-400 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[(0,e.jsx)(De,{className:"w-4 h-4"})," View Trades"]}),(0,e.jsxs)("button",{onClick:()=>{$(l.id),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-slate-600 dark:text-slate-300 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[(0,e.jsx)(es,{className:"w-4 h-4"})," View Profile"]}),f&&l.role!=="owner"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{onClick:()=>{h(l.id,l.isActive),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-slate-600 dark:text-slate-300 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[l.isActive?(0,e.jsx)(pe,{className:"w-4 h-4"}):(0,e.jsx)(Te,{className:"w-4 h-4"}),l.isActive?"Suspend":"Reactivate"]}),(0,e.jsxs)("button",{onClick:()=>{u(l.id),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-red-400 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[(0,e.jsx)(na,{className:"w-4 h-4"})," Remove"]}),l.evaluationPhase&&l.role==="trader"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"border-t border-slate-700 my-1"}),l.evaluationPhase!=="funded"&&(0,e.jsxs)("button",{onClick:()=>{S?.(l),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-green-400 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[(0,e.jsx)(Ze,{className:"w-4 h-4"})," Advance Phase"]}),(0,e.jsxs)("button",{onClick:()=>{I?.(l),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-orange-400 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[(0,e.jsx)(Ke,{className:"w-4 h-4"})," Reset to Challenge 1"]})]})]}),(0,e.jsxs)("button",{onClick:()=>{E?.(l.id,l),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-slate-600 dark:text-slate-300 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[(0,e.jsx)(ct,{className:"w-4 h-4"})," Send Message"]}),(0,e.jsxs)("button",{onClick:()=>{b?.(l.id,l),p(!1)},className:"w-full px-4 py-2 text-left text-sm text-blue-400 hover:bg-slate-700 flex items-center gap-2 cursor-pointer",children:[(0,e.jsx)(Le,{className:"w-4 h-4"}),l.tradeLockerAccountId?"Update Account":"Link Account"]})]})]}),document.body)]})})]})},ya=()=>{const l=Jt(),[$,L]=zs(),[h,u]=(0,i.useState)(!1),[E,b]=(0,i.useState)(!1),[S,I]=(0,i.useState)(!1),[f,P]=(0,i.useState)("traders"),[j,p]=(0,i.useState)({}),[k,F]=(0,i.useState)([]),{user:o}=vt(),{isAdmin:w,grantOrgProTier:C,subscribeToSubscription:_}=_s(),{currentOrg:a,currentMembership:N,allMemberships:A,members:ie,orgStats:Y,memberStats:v,pendingAccountRequests:O,isLoading:T,fetchMembers:U,fetchOrgStats:J,fetchAllMemberStats:X,fetchAccountRequests:Q,approveAccountRequest:K,rejectAccountRequest:Ie,inviteMember:Re,suspendMember:$e,removeMember:xe,hasPermission:D,fetchAllMemberships:ae,switchOrganization:z,fetchAllOrganizations:fe,adminJoinOrganization:et,ensureCurrentOrgHasGroupChat:ne,advanceTraderPhase:tt,resetTraderPhase:r,dismissRuleBreach:V}=gt(),B=la(),[Oe,Fe]=(0,i.useState)([]),[ss,jt]=(0,i.useState)(!1),[ve,as]=(0,i.useState)(!0),[ls,wt]=(0,i.useState)(null),[Nt,je]=(0,i.useState)(null),[rs,yt]=(0,i.useState)(!1),[is,we]=(0,i.useState)(!1),[Z,kt]=(0,i.useState)(null),[_e,st]=(0,i.useState)(""),[Ct,At]=(0,i.useState)("live.tradelocker.com"),[oe,St]=(0,i.useState)(!1);(0,i.useEffect)(()=>{(async()=>{if(!o?.uid||rs)return;const s=$.get("acceptInvite"),d=Bt();if(!d){je(null),s&&($.delete("acceptInvite"),L($,{replace:!0}));return}console.log("[OrgDashboard] Found stored invite token, validating..."),yt(!0);try{const c=await Ws(d);c.valid?(console.log("[OrgDashboard] Token valid, showing accept invite modal"),je(c),b(!0)):(console.log("[OrgDashboard] Token invalid:",c.error),je(null))}catch(c){console.error("[OrgDashboard] Error validating invite token:",c)}finally{yt(!1),s&&($.delete("acceptInvite"),L($,{replace:!0}))}})()},[o?.uid,$]),(0,i.useEffect)(()=>{console.log("[OrgDashboard] Checking pending org join...",{hasUser:!!o?.uid,hasCurrentOrg:!!a});const t=localStorage.getItem("tradeintelx_pending_org_join");if(console.log("[OrgDashboard] Pending join from localStorage:",t),!t){console.log("[OrgDashboard] No pending join foun
2d");return}if(a){console.log("[OrgDashboard] User has currentOrg, skipping redirect");return}if(!o?.uid){console.log("[OrgDashboard] No user yet, waiting...");return}try{const s=JSON.parse(t),d=Date.now()-s.timestamp<1440*60*1e3;if(console.log("[OrgDashboard] Pending join data:",s,"isRecent:",d),d&&s.orgId){console.log("[OrgDashboard] ð Redirecting to join page...");const c=new URLSearchParams;s.balance&&c.append("balance",s.balance),s.tier&&c.append("tier",s.tier);const g=c.toString(),G=`/org/join/${s.orgId}${g?"?"+g:""}`;console.log("[OrgDashboard] Redirect URL:",G),l(G,{replace:!0})}else console.log("[OrgDashboard] Pending join expired or missing orgId, clearing"),localStorage.removeItem("tradeintelx_pending_org_join")}catch(s){console.error("[OrgDashboard] Error processing pending join:",s),localStorage.removeItem("tradeintelx_pending_org_join")}},[o?.uid,a,l]),(0,i.useEffect)(()=>{o?.uid&&A.length===0&&ae(o.uid)},[o?.uid,A.length,ae]),(0,i.useEffect)(()=>{if(!(!a?.id||!B))return da(a.id,p,()=>{})},[a?.id,B]),(0,i.useEffect)(()=>{if(!(!a?.id||!B))return Gs(a.id,50,F,()=>{})},[a?.id,B]),(0,i.useEffect)(()=>{(async()=>ve&&!a&&(jt(!0),Fe(await fe()),jt(!1)))()},[ve,a,fe]);const Tt=async t=>{o?.uid&&await z(t,o.uid)},ns=t=>{l(`/org/join/${t}`)},os=async t=>{o?.uid&&w&&(wt(t),await et(t,o.uid,{displayName:o.displayName||"Admin",email:o.email}),wt(null),Fe(await fe()))},ds=async()=>{if(!(!o?.uid||!Nt)){I(!0),console.log("[OrgDashboard] Accepting invite...");try{const t=await aa(Bt());if(t.success)console.log("[OrgDashboard] Join successful:",t),C(t.orgId),o?.uid&&_(o.uid),Vt(),je(null),b(!1),t.orgId&&zt(t.orgId).catch(()=>{}),await ae(o.uid),await z(t.orgId,o.uid);else throw new Error("Failed to join organization")}catch(t){console.error("[OrgDashboard] Error accepting invite:",t)}finally{I(!1)}}},cs=()=>{Vt(),je(null),b(!1)},{members:Be,loading:pa}=Zs(a?.id),{violations:xs,loading:ms}=sa(a?.id,50),{requests:Me,loading:ba}=ta(a?.id),me=Be?.length>0?Be:ie,ze=xs||[],Ee=Me?.length>0?Me:O,[hs,gs]=(0,i.useState)(!1);(0,i.useEffect)(()=>{(Be?.length>0||Me?.length>=0)&&gs(!0)},[Be,Me]);const[Ue,us]=(0,i.useState)(""),[Ve,ps]=(0,i.useState)("all"),[We,bs]=(0,i.useState)("all"),[Ge,fa]=(0,i.useState)("displayName"),[at,va]=(0,i.useState)("asc"),[Pt,Lt]=(0,i.useState)(!1),[fs,Dt]=(0,i.useState)(!1),[lt,Ne]=(0,i.useState)(!1);(0,i.useEffect)(()=>{(async()=>{if(a?.id&&N?.organizationId===a.id&&!a.groupChatId){console.log("[OrgDashboard] Organization missing group chat, running lazy migration...");try{await ne()}catch(s){console.error("[OrgDashboard] Failed to ensure group chat:",s)}}})()},[a?.id,a?.groupChatId,N?.organizationId,ne]),(0,i.useEffect)(()=>{a?.id&&N?.organizationId===a.id&&rt()},[a?.id,N?.organizationId]);const rt=async()=>{if(!a?.id||!N||N.organizationId!==a.id){console.warn("[OrgDashboard] Skipping loadData - no valid membership for current org");return}await Promise.all([U(a.id),J(a.id),X(a.id),Q(a.id)])},vs=async()=>{Lt(!0),await rt(),Lt(!1)},js=async()=>{if(a?.id)try{(await zt(a.id)).success}catch(t){console.error("[OrgDashboard] Sync members error:",t)}},ws=async()=>{if(a?.id)try{(await qs(a.id)).success&&await rt()}catch(t){console.error("[OrgDashboard] Fix display names error:",t)}},He=(0,i.useMemo)(()=>me.map(t=>({...t,stats:v[t.id]})),[me,v]),ee=(0,i.useMemo)(()=>{const t={};return ze.forEach(s=>{t[s.memberId]||(t[s.memberId]=[]),t[s.memberId].push(s)}),me.filter(s=>t[s.id]?.length>0).map(s=>({...s,violations:t[s.id]||[],violationCount:t[s.id]?.length||0,latestViolation:t[s.id]?.[0]||null,stats:v[s.id]})).sort((s,d)=>d.violationCount-s.violationCount)},[me,ze,v]),he=(0,i.useMemo)(()=>He.filter(t=>{const s=t.stats;if(!s)return!1;const d=(s.dailyPnl?s.dailyPnl/(s.accountBalance||1e5)*100:0)<-3,c=(s.maxDrawdown||0)>6,g=t.violationCount>0;return d||c||g}),[He]),W=(0,i.useMemo)(()=>{let t=He;if(!B&&o?.uid&&(t=t.filter(s=>s.userId===o.uid||s.id===o.uid)),Ue){const s=Ue.toLowerCase();t=t.filter(d=>d.displayName?.toLowerCase().includes(s)||d.email?.toLowerCase().includes(s))}return Ve!=="all"&&(t=t.filter(s=>s.role===Ve)),We!=="all"&&(t=t.filter(s=>s.evaluationPhase===We)),t.sort((s,d)=>{let c,g;switch(Ge){case"pnl":c=s.stats?.totalPnl||0,g=d.stats?.totalPnl||0;break;case"winRate":c=s.stats?.winRate||0,g=d.stats?.winRate||0;break;case"trades":c=s.stats?.totalTrades||0,g=d.stats?.totalTrades||0;break;default:c=s[Ge]||"",g=d[Ge]||""}return typeof c=="string"?at==="asc"?c.localeCompare(g):g.localeCompare(c):at==="asc"?c-g:g-c}),t},[He,Ue,Ve,We,Ge,at]),Ns=async(t,s)=>{Dt(!0);const d=await Re(a.id,t,s,N?.userId);Dt(!1),d&&u(!1)},ys=async(t,s)=>{await $e(a.id,t,s,"Suspended by admin",N?.userId)},ks=async t=>{window.confirm("Are you sure you want to remove this member?")&&await xe(a.id,t,N?.userId)},Cs=async(t,s="trader")=>{await K(a.id,t,N?.userId,s)},As=async t=>{const s=window.prompt("Enter rejection reason (optional):")||"";await Ie(a.id,t,N?.userId,s)},Ss=t=>{l(`/org/traders/${t}`)},It=(t,s)=>{l(`/trade-logger?${new URLSearchParams({viewOrgMember:t,orgId:a?.id||"",memberName:s?.displayName||s?.email||""}).toString()}`)},Ts=async(t,s)=>{try{if(t===o?.uid)return;const{useChatStore:d}
2=await Os(async()=>{const{useChatStore:g}=await import("./chat-page-evUfHQgD.js").then(G=>G.m);return{useChatStore:g}},__vite__mapDeps([0,1,2,3])),c=await d.getState().createOrFindConversation([t],"direct",{});c&&l(`/chat?conversation=${c}`)}catch(d){console.error("Error opening chat:",d)}},Ps=(t,s)=>{kt({id:t,...s}),st(s?.tradeLockerAccountId||""),At(s?.tradeLockerServer||"live.tradelocker.com"),we(!0)},Ls=async t=>{if(!a?.id||!t)return;const s={challenge1:"challenge2",challenge2:"funded"}[t.evaluationPhase];if(!s||!window.confirm(`Advance ${t.displayName||t.email} to ${s==="funded"?"Funded":"Challenge 2"}?`))return;const d=t.userId||t.id;await tt(a.id,d,s)},Ds=async t=>{if(!a?.id||!t||!window.confirm(`Reset ${t.displayName||t.email} back to Challenge 1? This cannot be undone.`))return;const s=t.userId||t.id;await r(a.id,s)},Is=async()=>{if(_e.trim()&&!(!a?.id||!Z?.id)){St(!0);try{await Vs(Ms(Es,"organizations",a.id,"members",Z.id),{tradeLockerAccountId:_e.trim(),tradeLockerServer:Ct,tradeLockerLinkedAt:_t(),updatedAt:_t()}),we(!1),kt(null),st(""),a?.id&&U(a.id)}catch(t){console.error("[OrgDashboard] Link account error:",t)}finally{St(!1)}}},Rs=()=>{if(!W.length)return;const t=a?.riskRules||{},s=new Date().toISOString().split("T")[0],d=new Date().toLocaleTimeString(),c=W.map((x,n)=>{const m=x.stats||{},y=x.startingBalance||x.accountBalance||t?.accountBalance||5e4,R=x.currentBalance||m.currentBalance||y+(m.totalPnl||0),de=m.totalPnl||x.totalPnl||0,H=m.dailyPnl||x.dailyPnl||0,te=y-R,ue=y>0?te/y*100:0,Ce=t?.maxDailyLoss||y*.02,ot=t?.maxDrawdownPercent||6;let Je="Good";x.isActive?Math.abs(H)>=Ce||ue>=ot?Je="Breached":(Math.abs(H)>=Ce*.8||ue>=ot*.8)&&(Je="At Risk"):Je="Suspended";const Ae=Qe=>Qe?(Qe.toDate?Qe.toDate():new Date(Qe)).toISOString().split("T")[0]:"";
2return{"Trader #":n+1,"Trader ID":x.id||"","Display Name":x.displayName||"",Email:x.email||"",Role:x.role||"trader",Status:x.isActive?"Active":"Suspended","Joined Date":Ae(x.joinedAt||x.createdAt),"Account Tier":x.accountTier||"Standard","Starting Balance":y,"Current Balance":R,"Balance Change ($)":R-y,"Balance Change (%)":y>0?((R-y)/y*100).toFixed(2)+"%":"0%","Evaluation Phase":x.evaluationPhase||"N/A","Phase Start Date":Ae(x.phaseStartDate),"Days in Phase":x.daysInPhase||"","Total P&L":de,"Daily P&L":H,"Weekly P&L":m.weeklyPnl||0,"Monthly P&L":m.monthlyPnl||0,"Best Trade":m.bestTrade||0,"Worst Trade":m.worstTrade||0,"Average Trade":m.avgTrade||0,"Risk Status":Je,"Current Drawdown ($)":te>0?te:0,"Current Drawdown (%)":ue>0?ue.toFixed(2)+"%":"0%","Max Drawdown Allowed (%)":ot+"%","Daily Loss Limit":Ce,"Daily Loss Used":Math.abs(H),"Daily Loss (%)":Ce>0?(Math.abs(H)/Ce*100).toFixed(1)+"%":"0%","Total Trades":m.totalTrades||0,"Winning Trades":m.winningTrades||0,"Losing Trades":m.losingTrades||0,"Win Rate (%)":(m.winRate||0).toFixed(1)+"%","Profit Factor":(m.profitFactor||0).toFixed(2),"Avg Win":m.avgWin||0,"Avg Loss":m.avgLoss||0,"Largest Win":m.largestWin||0,"Largest Loss":m.largestLoss||0,"Trading Days":m.tradingDays||0,"Last Trade Date":Ae(m.lastTradeDate),"Last Active":Ae(x.lastActiveAt),"Total Trading Hours":m.totalTradingHours||"","Rule Breaches":x.ruleBreaches||0,Warnings:x.warnings||0,"Consistency Score":x.consistencyScore?x.consistencyScore+"%":"","Total Payouts":x.totalPayouts||0,"Pending Payout":x.pendingPayout||0,"Last Payout Date":Ae(x.lastPayoutDate),"Admin Notes":x.adminNotes||""}}),g=Object.keys(c[0]),G=[g.join(","),...c.map(x=>g.map(n=>{let m=x[n];return typeof m=="string"&&(m.includes(",")||m.includes('"')||m.includes(` 3`))&&(m='"'+m.replace(/"/g,'""')+'"'),m}).join(","))].join(` 4`),it=[`# ${a?.name||"Organization"} - Trader Export Report`,`# Generated: ${s} at ${d}`,`# Organization ID: ${a?.id||"N/A"}`,`# Organization Type: ${a?.type||"N/A"}`,`# Total Traders: ${c.length}`,`# Active Traders: ${c.filter(x=>x.Status==="Active").length}`,`# Total AUM: $${c.reduce((x,n)=>x+(n["Current Balance"]||0),0).toLocaleString()}`,`# Total P&L: $${c.reduce((x,n)=>x+(n["Total P&L"]||0),0).toLocaleString()}`,"#",""].join(` 5`)+G,nt=new Blob([it],{type:"text/csv;charset=utf-8;"}),Ye=URL.createObjectURL(nt),le=document.createElement("a");le.href=Ye,le.download=`${a?.name?.replace(/\s+/g,"_")||"traders"}_export_${s}.csv`,document.body.appendChild(le),le.click(),document.body.removeChild(le),URL.revokeObjectURL(Ye)},qe=t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0}).format(t||0),Rt=A.length>0,$s=t=>A.some(s=>s.org?.id===t);(0,i.useEffect)(()=>{if(!a&&A.length>0&&o?.uid){const t=A[0]?.org;t?.id&&(console.log("[OrgDashboard] Auto-selecting first org:",t.name),z(t.id,o.uid))}},[a,A,o?.uid,z]);const ge=N?.role,$t=ge==="owner"||ge==="admin",Ot=a&&N&&N.organizationId===a.id,ye=a&&A.some(t=>t.membership?.organizationId===a.id||t.org?.id===a.id),ke=w||ye;(0,i.useEffect)(()=>{console.log("[OrgDashboard] Access check:",{userId:o?.uid,orgId:a?.id,membershipOrgId:N?.organizationId,role:ge,isGlobalAdmin:w,isUserMemberOfCurrentOrg:ye,isOrgAdminOrOwner:$t,canAccess:ke,hasMembershipLoaded:Ot,allMembershipsCount:A.length})},[a,N,ge,ke,Ot,w,ye,$t,A.length,o?.uid]);const{clearOrg:Ft}=gt();return(0,i.useEffect)(()=>{const t=A.length>0||!T;a&&!w&&!ke&&!T&&t&&(console.log("[OrgDashboard] Unauthorized access detected, clearing org state and redirecting.",{role:ge,isGlobalAdmin:w,isUserMemberOfCurrentOrg:ye,allMembershipsCount:A.length}),Ft(),l("/org/browse",{replace:!0}))},[a,ke,T,l,ge,w,ye,A.length,Ft]),a&&!ke&&!T?(0,e.jsx)("div",{className:"min-h-screen overflow-y-auto theme-page bg-[var(--bg-primary)] flex items-center justify-center p-8",children:(0,e.jsxs)("div",{className:"text-center max-w-md",children:[(0,e.jsx)("div",{className:"w-12 h-12 border-3 border-red-500 border-t-transparent rounded-full animate-spin mx-auto mb-4"}),(0,e.jsx)("p",{className:"text-[var(--text-secondary)]",children:"Access denied. Redirecting..."})]})}):a?(0,e.jsxs)("div",{className:"min-h-screen overflow-y-auto theme-page bg-[var(--bg-primary)]",children:[(0,e.jsx)("div",{className:"bg-[var(--bg-secondary)] border-b border-[var(--border-primary)] px-3 sm:px-6 py-3 sm:py-4",children:(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2 sm:gap-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 sm:gap-4 min-w-0",children:[(0,e.jsx)(xa,{}),(0,e.jsx)("div",{className:"hidden sm:block h-8 w-px bg-slate-200 dark:bg-slate-700"}),(0,e.jsx)("div",{className:"hidden sm:block",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("span",{className:`px-2 py-1 text-xs font-medium rounded-md ${a.type==="prop_firm"?"bg-purple-500/20 text-purple-400":a.type==="trading_group"?"bg-green-500/20 text-green-400":"bg-blue-500/20 text-blue-400"}`,children:a.type==="prop_firm"?"Prop Firm":a.type==="trading_group"?"Trading Group":"RIA"}),(0,e.jsxs)("span",{className:"text-sm text-slate-500 dark:text-slate-400",children:[me.length," members"]})]})})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-3 flex-shrink-0",children:[hs&&(0,e.jsxs)("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-1.5 bg-green-500/20 text-green-400 rounded-lg text-xs font-medium",children:[(0,e.jsx)(dt,{className:"w-3.5 h-3.5 animate-pulse"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Live"})]}),(0,e.jsx)("button",{onClick:vs,disabled:Pt,className:"p-2 sm:p-2.5 hover:bg-slate-700 rounded-lg transition-colors text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white disabled:opacity-50",title:"Refresh data",children:(0,e.jsx)(Ke,{className:`w-4 h-4 sm:w-5 sm:h-5 ${Pt?"animate-spin":""}`})}),D("edit_org_settings")&&(0,e.jsxs)("div",{className:"relative",children:[(0,e.jsxs)("button",{onClick:()=>
5Ne(!lt),className:"p-2 sm:px-4 sm:py-2 text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white border border-slate-600 hover:border-slate-400 dark:hover:border-slate-500 rounded-lg text-sm font-medium flex items-center gap-2 transition-colors",children:[(0,e.jsx)(Et,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Admin"}),(0,e.jsx)(Se,{className:`w-3 h-3 transition-transform ${lt?"rotate-180":""}`})]}),lt&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>Ne(!1)}),(0,e.jsxs)("div",{className:"absolute right-0 top-full mt-1 w-56 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg shadow-xl z-50",onClick:t=>t.stopPropagation(),children:[(0,e.jsxs)("button",{type:"button",onClick:t=>{t.stopPropagation(),l("/org/settings"),Ne(!1)},className:"w-full px-4 py-2.5 text-left text-sm text-slate-600 dark:text-slate-300 hover:bg-slate-700 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white flex items-center gap-2 rounded-t-lg",children:[(0,e.jsx)(Et,{className:"w-4 h-4"}),"Organization Settings"]}),(0,e.jsxs)("button",{type:"button",onClick:t=>{t.stopPropagation(),js(),Ne(!1)},className:"w-full px-4 py-2.5 text-left text-sm text-slate-600 dark:text-slate-300 hover:bg-slate-700 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white flex items-center gap-2",children:[(0,e.jsx)(q,{className:"w-4 h-4"}),"Sync Members to Chat"]}),(0,e.jsxs)("button",{type:"button",onClick:t=>{t.stopPropagation(),ws(),Ne(!1)},className:"w-full px-4 py-2.5 text-left text-sm text-slate-600 dark:text-slate-300 hover:bg-slate-700 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white flex items-center gap-2 rounded-b-lg",children:[(0,e.jsx)(Ut,{className:"w-4 h-4"}),"Fix Member Names"]})]})]})]}),D("export_compliance")&&(0,e.jsxs)("button",{onClick:Rs,className:"p-2 sm:px-4 sm:py-2 text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white border border-slate-600 hover:border-slate-400 dark:hover:border-slate-500 rounded-lg text-sm font-medium flex items-center gap-2 transition-colors",children:[(0,e.jsx)(Xs,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Export"})]}),D("invite_members")&&(0,e.jsxs)("button",{onClick:()=>u(!0),className:"p-2 sm:px-4 sm:py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-sm font-medium flex items-center gap-2 transition-colors",children:[(0,e.jsx)(mt,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Invite"})]})]})]})}),a?.billingStatus==="pending_payment"&&(0,e.jsx)("div",{className:"px-3 sm:px-6 pt-3 sm:pt-4",children:(0,e.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-xl",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-medium text-yellow-400",children:"Payment required to activate this organization"}),(0,e.jsx)("p",{className:"text-sm text-slate-400",children:D("manage_billing")?"Complete checkout to unlock full access for your team.":"Ask your organization's owner to complete payment setup."})]}),D("manage_billing")&&(0,e.jsx)("button",{onClick:()=>l("/org/settings?tab=subscription"),className:"px-4 py-2 bg-yellow-500 hover:bg-yellow-400 text-slate-900 rounded-lg text-sm font-semibold transition-colors flex-shrink-0",children:"Complete Payment"})]})}),a?.billingStatus==="past_due"&&(0,e.jsx)("div",{className:"px-3 sm:px-6 pt-3 sm:pt-4",children:(0,e.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 p-4 bg-red-500/10 border border-red-500/30 rounded-xl",children:[(0,e.jsx)("p",{className:"font-medium text-red-400",children:"Your last payment failed â update billing to avoid losing access."}),D("manage_billing")&&(0,e.jsx)("button",{onClick:()=>l("/org/settings?tab=subscription"),className:"px-4 py-2 bg-red-500 hover:bg-red-400 text-white rounded-lg text-sm font-semibold transition-colors flex-shrink-0",children:"Update Billing"})]})}),(0,e.jsxs)("div",{className:"p-3 sm:p-6",children:[B?(0,e.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 ga
5p-3 sm:gap-4 mb-6 sm:mb-8",children:[(0,e.jsx)(se,{label:"Total Traders",value:Y?.totalMembers||me.length,icon:q,color:"blue",isLoading:T}),(0,e.jsx)(se,{label:"Total P&L",value:qe(Y?.totalPnl),icon:pt,change:Y?.pnlChange,color:(Y?.totalPnl||0)>=0?"green":"red",isLoading:T}),(0,e.jsx)(se,{label:"Avg Win Rate",value:`${(Y?.avgWinRate||0).toFixed(1)}%`,icon:De,color:"teal",isLoading:T}),(0,e.jsx)(se,{label:"Rule Breaches",value:ee.length,icon:pe,color:ee.length>0?"red":"gray",isLoading:T||ms,onClick:ee.length>0?()=>P("breaches"):null,badge:ee.length>0?`${ze.length} total`:null}),(0,e.jsx)(se,{label:"At Risk",value:he.length,icon:re,color:he.length>0?"orange":"gray",isLoading:T,onClick:he.length>0?()=>P("breaches"):null})]}):(0,e.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 sm:gap-4 mb-6 sm:mb-8",children:[(0,e.jsx)(se,{label:"Your Balance",value:qe(W[0]?.currentBalance||W[0]?.stats?.currentBalance||W[0]?.startingBalance||0),icon:pt,color:"blue",isLoading:T}),(0,e.jsx)(se,{label:"Your P&L",value:qe(W[0]?.stats?.totalPnl||0),icon:De,color:(W[0]?.stats?.totalPnl||0)>=0?"green":"red",isLoading:T}),(0,e.jsx)(se,{label:"Your Win Rate",value:`${(W[0]?.stats?.winRate||0).toFixed(1)}%`,icon:Te,color:"teal",isLoading:T}),(0,e.jsx)(se,{label:"Your Trades",value:W[0]?.stats?.totalTrades||0,icon:ht,color:"purple",isLoading:T})]}),B&&(0,e.jsxs)("div",{className:"flex items-center gap-1 mb-6 bg-white dark:bg-slate-800/50 p-1 rounded-lg w-full sm:w-fit overflow-x-auto",children:[(0,e.jsxs)("button",{onClick:()=>P("traders"),style:{WebkitTapHighlightColor:"transparent"},className:`px-4 py-2 min-h-[40px] rounded-md text-sm font-medium transition-colors flex items-center gap-2 touch-manipulation active:scale-95 ${f==="traders"?"bg-slate-200 dark:bg-slate-700 text-slate-900 dark:text-white shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white active:bg-slate-100 dark:active:bg-slate-700/50"}`,children:[(0,e.jsx)(q,{className:"w-4 h-4"}),"Traders"]}),D("approve_account_requests")&&(0,e.jsxs)("button",{onClick:()=>P("requests"),style:{WebkitTapHighlightColor:"transparent"},className:`px-4 py-2 min-h-[40px] rounded-md text-sm font-medium transition-colors flex items-center gap-2 touch-manipulation active:scale-95 ${f==="requests"?"bg-slate-200 dark:bg-slate-700 text-slate-900 dark:text-white shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white active:bg-slate-100 dark:active:bg-slate-700/50"}`,children:[(0,e.jsx)(xt,{className:"w-4 h-4"}),"Pending Requests",Ee.length>0&&(0,e.jsx)("span",{className:"px-2 py-0.5 bg-yellow-500 text-yellow-900 text-xs font-bold rounded-full",children:Ee.length})]}),(0,e.jsxs)("button",{onClick:()=>P("breaches"),style:{WebkitTapHighlightColor:"transparent"},className:`px-4 py-2 min-h-[40px] rounded-md text-sm font-medium transition-colors flex items-center gap-2 touch-manipulation active:scale-95 ${f==="breaches"?"bg-slate-200 dark:bg-slate-700 text-slate-900 dark:text-white shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white active:bg-slate-100 dark:active:bg-slate-700/50"}`,children:[(0,e.jsx)(pe,{className:"w-4 h-4"}),"Rule Breaches",ee.length>0&&(0,e.jsx)("span",{className:"px-2 py-0.5 bg-red-500 text-white text-xs font-bold rounded-full",children:ee.length})]}),(0,e.jsxs)("button",{onClick:()=>P("risk_monitor"),style:{WebkitTapHighlightColor:"transparent"},className:`px-4 py-2 min-h-[40px] rounded-md text-sm font-medium transition-colors flex items-center gap-2 touch-manipulation active:scale-95 ${f==="risk_monitor"?"bg-slate-200 dark:bg-slate-700 text-slate-900 dark:text-white shadow-sm":"text-slate-500 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900 dark:text-white active:bg-slate-100 dark:active:bg-slate-700/50"}`,children:[(0,e.jsx)(dt,{className:"w-4 h-4"}),"Risk Monitor",k.filter(t=>!t.dismissed).length>0&&(0,e.jsx)("span",{className:"px-2 py-0.5 bg-orange-500 text-white text-xs font-bold rounded-full",children:k.filter(t=>!t.dismissed).length})]})]}),f==="breaches"&&B&&(0,e.jsxs)("div",{className:"space-y-6 mb-6",children:[(0,e.jsxs)("div",{className:"grid grid-cols-3 gap-2 sm:gap-4",children:[(0,e.jsx)("div",{className:"bg-gradient-to-br from-red-500/10 to-red-600/10 border border-red-500/30 rounded-xl p-4",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 bg-red-500/20 rounded-lg flex items-center justify-center",children:(0,e.jsx)(pe,{className:"w-5 h-5 text-red-400"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Breached Accounts"}),(0,e.jsx)("p",{className:"text-2xl font-bold text-red-400",children:ee.length})]})]})}),(0,e.jsx)("div",{className:"bg-gradient-to-br from-orange-500/10 to-orange-600/10 border border-orange-500/30 rounded-xl p-4",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 bg-orange-500/20 rounded-lg flex items-center justify-center",children:(0,e.jsx)(re,{className:"w-5 h-5 text-orange-400"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"At Risk Accounts"}),(0,e.jsx)("p",{className:"text-2xl font-bold text-orange-400",children:he.length})]})]})}),(0,e.jsx)("div",{className:"bg-gradient-to-br from-slate-500/10 to-slate-600/10 border border-slate-500/30 rounded-xl p-4",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 bg-slate-500/20 rounded-lg flex items-center justify-center",children:(0,e.jsx)(ht,{className:"w-5 h-5 text-slate-500 dark:text-slate-400"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Total Violations"}),(0,e.jsx)("p",{className:"text-2xl font-bold text-slate-600 dar
5k:text-slate-300",children:ze.length})]})]})})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl border border-slate-200 dark:border-slate-700",children:[(0,e.jsxs)("div",{className:"p-4 border-b border-slate-200 dark:border-slate-700",children:[(0,e.jsxs)("h3",{className:"text-lg font-semibold text-slate-900 dark:text-white flex items-center gap-2",children:[(0,e.jsx)(pe,{className:"w-5 h-5 text-red-400"}),"Accounts with Rule Breaches"]}),(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"Traders who have violated one or more trading rules. Click to view details."})]}),(0,e.jsx)("div",{className:"divide-y divide-slate-200 dark:divide-slate-700",children:ee.length===0?(0,e.jsxs)("div",{className:"p-8 text-center",children:[(0,e.jsx)(Te,{className:"w-12 h-12 text-green-500/50 mx-auto mb-3"}),(0,e.jsx)("p",{className:"text-slate-500 dark:text-slate-400",children:"No rule breaches"}),(0,e.jsx)("p",{className:"text-sm text-slate-500 mt-1",children:"All traders are trading within their rules."})]}):ee.map(t=>(0,e.jsxs)("div",{className:"p-4 hover:bg-slate-800/80 transition-colors cursor-pointer",onClick:()=>l(`/org/trader/${t.userId||t.id}`),children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 sm:gap-4",children:[(0,e.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,e.jsx)("div",{className:"w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-gradient-to-br from-red-500 to-orange-500 flex items-center justify-center text-white font-semibold text-sm sm:text-lg",children:t.displayName?.charAt(0)?.toUpperCase()||t.email?.charAt(0)?.toUpperCase()||"?"}),(0,e.jsx)("div",{className:"absolute -bottom-1 -right-1 w-4 h-4 sm:w-5 sm:h-5 bg-red-500 rounded-full flex items-center justify-center text-white text-[10px] sm:text-xs font-bold",children:t.violationCount})]}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("p",{className:"font-medium text-slate-900 dark:text-white text-sm sm:text-base truncate",children:t.displayName}),(0,e.jsx)("p",{className:"text-xs sm:text-sm text-slate-500 dark:text-slate-400 truncate",children:t.email}),(0,e.jsxs)("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[(0,e.jsx)(bt,{phase:t.evaluationPhase||"challenge1"}),(0,e.jsx)(ft,{role:t.role||"trader"}),(0,e.jsx)("div",{className:`px-2 py-0.5 rounded text-xs font-medium ${t.latestViolation?.severity==="critical"?"bg-red-500/20 text-red-400":t.latestViolation?.severity==="warning"?"bg-yellow-500/20 text-yellow-400":"bg-slate-500/20 text-slate-500 dark:text-slate-400"}`,children:t.latestViolation?.severity||"Info"})]})]}),(0,e.jsxs)("div",{className:"hidden sm:flex items-center gap-4 flex-shrink-0",children:[(0,e.jsxs)("div",{className:"text-right",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500",children:"Latest Violation"}),(0,e.jsx)("p",{className:"text-sm text-red-400 font-medium",children:t.latestViolation?.type?.replace(/_/g," ")||"Unknown"}),(0,e.jsx)("p",{className:"text-xs text-slate-500",children:t.latestViolation?.timestamp?.toDate?t.latestViolation.timestamp.toDate().toLocaleDateString():t.latestViolation?.timestamp?new Date(t.latestViolation.timestamp).toLocaleDateString():"N/A"})]}),(0,e.jsxs)("button",{onClick:s=>{s.stopPropagation(),l(`/org/trader/${t.userId||t.id}`)},className:"px-3 py-2 bg-slate-200 dark:bg-slate-700 hover:bg-slate-600 text-slate-900 dark:text-white rounded-lg text-sm flex items-center gap-2 transition-colors",children:[(0,e.jsx)(es,{className:"w-4 h-4"}),"View"]})]}),(0,e.jsx)(Se,{className:"sm:hidden w-4 h-4 text-slate-500 -rotate-90 flex-shrink-0"})]}),t.violations.length>0&&(0,e.jsxs)("div",{className:"mt-3 pt-3 border-t border-slate-200 dark:border-slate-700/50",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 mb-2",children:"Recent violations:"}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[t.violations.slice(0,5).map((s,d)=>(0,e.jsx)("span",{className:`px-2 py-1 rounded text-xs ${s.severity==="critical"?"bg-red-500/10 text-red-400":s.severity==="warning"?"bg-yellow-500/10 text-yellow-400":"bg-slate-500/10 text-slate-500 dark:text-slate-400"}`,children:s.type?.replace(/_/g," ")||"Unknown"},d)),t.violations.length>5&&(0,e.jsxs)("span",{className:"px-2 py-1 rounded text-xs bg-slate-500/10 text-slate-500 dark:text-slate-400",children:["+",t.violations.length-5," more"]})]})]})]},t.id))})]}),he.length>0&&(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl border border-orange-500/30",children:[(0,e.jsxs)("div",{className:"p-4 border-b border-slate-200 dark:border-slate-700",children:[(0,e.jsxs)("h3",{className:"text-lg font-semibold text-slate-900 dark:text-white flex items-center gap-2",children:[(0,e.jsx)(re,{className:"w-5 h-5 text-orange-400"}),"At Risk Accounts"]}),(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"Traders approaching their limits. Consider reaching out proactively."})]}),(0,e.jsx)("div",{className:"divide-y divide-slate-200 dark:divide-slate-700",children:he.slice(0,10).map(t=>(0,e.jsx)("div",{className:"p-4 hover:bg-slate-800/80 transition-colors cursor-pointer",onClick:()=>l(`/org/trader/${t.userId||t.id}`),children:(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"flex items-center gap-4",children:[(0,e.jsx)("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-orange-500 to-yellow-500 flex items-center justify-center text-white font-semibold",children:t.displayName?.charAt(0)?.toUpperCase()||"?"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-medium text-slate-900 dark:text-white",children:t.displayName}),(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:t.email})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-4",children:[t.stats?.dailyPnl&&(0,e.jsxs)("div",{className:"text-right",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500",children:"Daily P&L"}),(0,e.jsx)("p",{className:`text-sm font-medium ${t.stats.dailyPnl>=0?"text-green-400":"text-red-400"}`,children:qe(t.stats.dailyPnl)})]}),t.stats?.maxDrawdown&&(0,e.jsxs)("div",{className:"text-right",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500",children:"Drawdown"}),(0,e.jsxs)("p",{className:"text-sm font-medium text-orange-400",children:[t.stats.maxDrawdown.toFixed(1),"%"]})]}),(0,e.jsx)("span",{className:"px-2 py-1 rounded text-xs bg-orange-500/20 text-orange-400",children:"At Risk"})]})]})},t.id))})]})]}),f==="risk_monitor"&&B&&(()=>{const t=a?.riskRules||a?.settings||{},s=t.warnAtPercent??75,d=t.criticalAtPercent??90,c=t.maxTotalDrawdown||t.maxDrawdownPercent||10,g=t.maxDailyLoss||t.dailyLossLimit||0;t.accountBalance;const G=n=>{const m=c>0?Math.abs(n?.maxDrawdown||0)/c*100:0,y=g>0?Math.abs(n?.todayPnl<0?n.todayPnl:0)/g*100:0,R=Math.max(m,y);return R>=d?"red":R>=s?"orange":R>=50?"yellow":"green"},it={green:"border-green-500/40",yellow:"border-yellow-500/50",orange:"border-orange-500/60",red:"border-red-500/70"},nt={green:"",yellow:"bg-yellow-500/5",orange:"bg-orange-500/10",red:"bg-red-500/10"},Ye={green:"text-green-400",yellow:"text-yellow-400",orange:"text-orange-400",red:"text-red-400"},le=[...ie.filter(n=>n.role==="trader"||n.role==="client")].sort((n,m)=>{const y={red:3,orange:2,yellow:1,green:0},R=j[n.userId||n.id]||n.stats||{};return(y[G(j[m.userId||m.id]||m.stats||{})]||0)-(y[G(R)]||0)}),x=k.filter(n=>!n.dismissed);return(0,e.jsxs)("div",{className:"space-y-6 mb-6",children:[x.length>0&&(0,e.jsxs)("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl overflow-hidden",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-red-500/20",children:[(0,e.jsxs)("h3",{className:"text-sm font-semibold text-red-400 flex items-center gap-2",children:[(0,e.jsx)(dt,{className:"w-4 h-4 animate-pulse"})," Live Breaches"]}),(0,e.jsxs)("span",{className:"text-xs text-slate-400",children:[x.length," unreviewed"]})]}),(0,e.jsx)("div",{className:"divide-y divide-red-500/10 max-h-64 overflow-y-auto",children:x.slice(0,20).map(n=>(0,e.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3",children:[(0,e.jsx)("div",{className:`w-2 h-2 rounded-full flex-shrink-0 ${n.severity==="critical"?"bg-red-500":n.severity==="warning"?"bg-yellow-500":"bg-slate-500"}`}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("p",{className:"text-sm text-white font-medium truncate",children:n.traderName||n.traderId}),(0,e.jsxs)("p",{className:"text-xs text-slate-400",children:[(n.ruleType||n.type||"").replace(/_/g," ")," â ",n.currentValue!=null?`${n.currentValue}`:"",n.limitValue!=null?` / ${n.limitValue}`:""]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,e.jsx)("span",{className:`px-2 py-0.5 rounded text-[10px] font-semibold uppercase ${n.severity==="critical"?"bg-red-500/20 text-red-400":n.severity==="warning"?"bg-yellow-500/20 text-yellow-400":"bg-slate-500/20 text-slate-400"}`,children:n.severity||"info"}),(0,e.jsx)("button",{onClick:()=>V(a.id,n.id),className:"p-1 hover:bg-slate-700 rounded text-slate-400 hover:text-white transition-colors",title:"Dismiss",children:(0,e.jsx)(ut,{className:"w-3.5 h-3.5"})}),(0,e.jsx)("button",{onClick:()=>l(`/org/trader/${n.traderId}`),className:"p-1 hover:bg-slate-700 rounded text-slate-400 hover:text-white transition-colors",title:"View trader",children:(0,e.jsx)(Ze,{className:"w-3.5 h-3.5"})})]})]},n.id))})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,e.jsxs)("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[(0,e.jsx)(Mt,{className:"w-4 h-4 text-blue-400"}),"Trader Risk Heatmap"]}),(0,e.jsxs)("div",{className:"flex items-center gap-3 text-xs text-slate-400",children:[(0,e.jsxs)("span",{className:"flex items-center gap-1",children:[(0,e.jsx)("span",{className:"w-2 h-2 rounded-full bg-green-500 inline-block"})," Safe"]}),(0,e.jsxs)("span",{className:"flex items-center gap-1",children:[(0,e.jsx)("span",{className:"w-2 h-2 rounded-full bg-yellow-500 inline-block"})," Warning"]}),(0,e.jsxs)("span",{className:"flex items-center gap-1",children:[(0,e.jsx)("span",{className:"w-2 h-2 rounded-full bg-orange-500 inline-block"})," At Risk"]}),(0,e.jsxs)("span",{className:"flex items-center gap-1",children:[(0,e.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500
5inline-block"})," Critical"]})]})]}),le.length===0?(0,e.jsxs)("div",{className:"p-12 text-center bg-slate-800 rounded-xl border border-slate-700",children:[(0,e.jsx)(q,{className:"w-10 h-10 text-slate-600 mx-auto mb-2"}),(0,e.jsx)("p",{className:"text-slate-400",children:"No traders to monitor"})]}):(0,e.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:le.map(n=>{const m=n.userId||n.id,y=j[m]||n.stats||{},R=G(y),de=c>0?Math.min(100,Math.abs(y.maxDrawdown||0)/c*100):0,H=g>0?Math.min(100,Math.abs(y.todayPnl<0?y.todayPnl:0)/g*100):0,te=Qt(y,t.evaluationPhases?.find?.(ue=>ue.id===n.evaluationPhase)||null);return(0,e.jsxs)("div",{onClick:()=>l(`/org/trader/${m}`),className:`cursor-pointer rounded-xl border-2 p-4 transition-all hover:scale-[1.02] hover:shadow-lg ${it[R]} ${nt[R]} bg-slate-800`,children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,e.jsx)("div",{className:`w-10 h-10 rounded-full flex items-center justify-center text-white font-semibold text-sm flex-shrink-0 ${R==="red"?"bg-red-500":R==="orange"?"bg-orange-500":R==="yellow"?"bg-yellow-500":"bg-slate-600"}`,children:n.displayName?.charAt(0)?.toUpperCase()||"?"}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("p",{className:"font-medium text-white text-sm truncate",children:n.displayName||n.email}),(0,e.jsx)("span",{className:`text-[10px] font-semibold uppercase ${Ye[R]}`,children:R==="green"?"Safe":R==="yellow"?"Warning":R==="orange"?"At Risk":"Critical"})]}),n.evaluationPhase&&(0,e.jsx)(bt,{phase:n.evaluationPhase})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex justify-between text-[10px] text-slate-400 mb-0.5",children:[(0,e.jsx)("span",{children:"Drawdown"}),(0,e.jsxs)("span",{children:[de.toFixed(0),"% of limit"]})]}),(0,e.jsx)("div",{className:"h-1.5 bg-slate-700 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:`h-full rounded-full transition-all ${de>=d?"bg-red-500":de>=s?"bg-orange-500":de>=50?"bg-yellow-500":"bg-green-500"}`,style:{width:`${Math.max(2,de)}%`}})})]}),g>0&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex justify-between text-[10px] text-slate-400 mb-0.5",children:[(0,e.jsx)("span",{children:"Daily Loss"}),(0,e.jsxs)("span",{children:[H.toFixed(0),"% of limit"]})]}),(0,e.jsx)("div",{className:"h-1.5 bg-slate-700 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:`h-full rounded-full transition-all ${H>=d?"bg-red-500":H>=s?"bg-orange-500":H>=50?"bg-yellow-500":"bg-blue-500"}`,style:{width:`${Math.max(2,H)}%`}})})]}),te&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex justify-between text-[10px] text-slate-400 mb-0.5",children:[(0,e.jsx)("span",{children:"Profit Target"}),(0,e.jsxs)("span",{children:[te.profitPct.toFixed(0),"%"]})]}),(0,e.jsx)("div",{className:"h-1.5 bg-slate-700 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:`h-full rounded-full transition-all ${te.status==="complete"?"bg-green-500":te.status==="failed"?"bg-red-500":"bg-blue-500"}`,style:{width:`${Math.max(2,te.profitPct)}%`}})})]})]}),(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-between text-[10px] text-slate-500",children:[(0,e.jsxs)("span",{children:["P&L: ",(0,e.jsxs)("span",{className:`font-medium ${(y.totalPnl||0)>=0?"text-green-400":"text-red-400"}`,children:[(y.totalPnl||0)>=0?"+":"","$",(y.totalPnl||0).toFixed(0)]})]}),(0,e.jsxs)("span",{children:["Trades: ",y.totalTrades||0]})]})]},n.id)})})]})]})})(),f==="requests"&&D("approve_account_requests")&&(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl border border-slate-200 dark:border-slate-700 mb-6",children:[(0,e.jsxs)("div",{className:"p-4 border-b border-slate-200 dark:border-slate-700",children:[(0,e.jsxs)("h3",{className:"text-lg font-semibold text-slate-900 dark:text-white flex items-center gap-2",children:[(0,e.jsx)(xt,{className:"w-5 h-5 text-yellow-400"}),"Pending Account Requests"]}),(0,e.jsx)("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"Review and approve trader account requests before they can join your organization."})]}),(0,e.jsx)("div",{className:"divide-y divide-slate-200 dark:divide-slate-700",children:Ee.length===0?(0,e.jsxs)("div",{className:"p-8 text-center",children:[(0,e.jsx)(Te,{className:"w-12 h-12 text-green-500/50 mx-auto mb-3"}),(0,e.jsx)("p",{className:"text-slate-500 dark:text-slate-400",children:"No pending requests"}),(0,e.jsx)("p",{className:"text-sm text-slate-500 mt-1",children:"All account requests have been processed."})]}):Ee.map(t=>(0,e.jsxs)("div",{className:"p-3 sm:p-4 hover:bg-slate-800/80 transition-colors",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 sm:gap-4 mb-3 sm:mb-0",children:[(0,e.jsx)("div",{className:"w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center text-white font-semibold text-sm sm:text-lg flex-shrink-0",children:t.displayName?.charAt(0)?.toUpperCase()||t.email?.charAt(0)?.toUpperCase()||"?"}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("p",{className:"font-medium text-slate-900 dark:text-white text-sm sm:text-base truncate",children:t.displayName}),(0,e.jsx)("p",{className:"text-xs sm:text-sm text-slate-500 dark:text-slate-400 truncate",children:t.email}),t.message&&(0,e.jsxs)("p",{className:"text-xs text-slate-500 mt-1 italic truncate",children:['"',t.message,'"']}),(0,e.jsx)("p",{className:"text-xs text-slate-500 mt-0.5 sm:hidden",children:t.createdAt?.toDate?t.createdAt.toDate().toLocaleDateString():new Date(t.createdAt).toLocaleDateString()})]}),(0,e.jsxs)("div",{className:"hidden sm:block text-right flex-shrink-0",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500",children:"Requested"}
5),(0,e.jsx)("p",{className:"text-sm text-slate-600 dark:text-slate-300",children:t.createdAt?.toDate?t.createdAt.toDate().toLocaleDateString():new Date(t.createdAt).toLocaleDateString()})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2 sm:ml-14",children:[(0,e.jsxs)("select",{id:`role-${t.id}`,defaultValue:"trader",className:"px-2 sm:px-3 py-1.5 sm:py-2 bg-slate-50 dark:bg-slate-900 border border-slate-600 rounded-lg text-xs sm:text-sm text-slate-600 dark:text-slate-300 focus:outline-none focus:border-blue-500",children:[(0,e.jsx)("option",{value:"trader",children:"Trader"}),(0,e.jsx)("option",{value:"manager",children:"Manager"}),(0,e.jsx)("option",{value:"admin",children:"Admin"})]}),(0,e.jsxs)("button",{onClick:()=>{const s=document.getElementById(`role-${t.id}`)?.value||"trader";Cs(t.id,s)},className:"flex-1 sm:flex-none px-3 sm:px-4 py-1.5 sm:py-2 bg-green-600 hover:bg-green-500 text-white rounded-lg text-xs sm:text-sm font-medium flex items-center justify-center gap-1.5 sm:gap-2 transition-colors",children:[(0,e.jsx)(Ut,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),"Approve"]}),(0,e.jsxs)("button",{onClick:()=>As(t.id),className:"flex-1 sm:flex-none px-3 sm:px-4 py-1.5 sm:py-2 bg-red-600/20 hover:bg-red-600/30 text-red-400 border border-red-500/30 rounded-lg text-xs sm:text-sm font-medium flex items-center justify-center gap-1.5 sm:gap-2 transition-colors",children:[(0,e.jsx)(ra,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),"Reject"]})]})]},t.id))})]}),f==="traders"&&B&&(0,e.jsxs)("div",{className:"bg-white dark:bg-slate-800 rounded-xl border border-slate-200 dark:border-slate-700",children:[(0,e.jsxs)("div",{className:"p-3 sm:p-4 border-b border-slate-200 dark:border-slate-700 flex flex-col sm:flex-row sm:flex-wrap sm:items-center gap-2 sm:gap-4",children:[(0,e.jsxs)("div",{className:"relative flex-1 sm:flex-none",children:[(0,e.jsx)(Kt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500 dark:text-slate-400"}),(0,e.jsx)("input",{type:"text",placeholder:"Search traders...",value:Ue,onChange:t=>us(t.target.value),className:"pl-10 pr-4 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-600 rounded-lg text-slate-900 dark:text-white placeholder-slate-400 dark:placeholder-slate-500 focus:outline-none focus:border-blue-500 w-full sm:w-64"})]}),(0,e.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,e.jsxs)("select",{value:Ve,onChange:t=>ps(t.target.value),className:"flex-1 sm:flex-none px-3 sm:px-4 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-600 rounded-lg text-slate-600 dark:text-slate-300 text-sm focus:outline-none focus:border-blue-500",children:[(0,e.jsx)("option",{value:"all",children:"All Roles"}),(0,e.jsx)("option",{value:"owner",children:"Owner"}),(0,e.jsx)("option",{value:"admin",children:"Admin"}),(0,e.jsx)("option",{value:"manager",children:"Manager"}),(0,e.jsx)("option",{value:"trader",children:"Trader"})]}),a.type==="prop_firm"&&(0,e.jsxs)("select",{value:We,onChange:t=>bs(t.target.value),className:"flex-1 sm:flex-none px-3 sm:px-4 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-600 rounded-lg text-slate-600 dark:text-slate-300 text-sm focus:outline-none focus:border-blue-500",children:[(0,e.jsx)("option",{value:"all",children:"All Phases"}),(0,e.jsx)("option",{value:"challenge1",children:"Challenge 1"}),(0,e.jsx)("option",{value:"challenge2",children:"Challenge 2"}),(0,e.jsx)("option",{value:"funded",children:"Funded"}),(0,e.jsx)("option",{value:"suspended",children:"Suspended"})]}),(0,e.jsxs)("div",{className:"sm:ml-auto text-sm text-slate-500 dark:text-slate-400 whitespace-nowrap",children:[W.length," traders"]})]})]}),(0,e.jsx)("div",{className:"block md:hidden divide-y divide-slate-700/50",children:T?[...Array(3)].map((t,s)=>(0,e.jsxs)("div",{className:"p-3 animate-pulse",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 bg-slate-200 dark:bg-slate-700 rounded-full"}),(0,e.jsxs)("div",{className:"flex-1",children:[(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-28 mb-1"}),(0,e.jsx)("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-36"})]})]}),(0,e.jsxs)("div",{className:"grid grid-cols-3 gap-2",children:[(0,e.jsx)("div",{className:"h-10 bg-slate-200 dark:bg-slate-700 rounded"}),(0,e.jsx)("div",{className:"h-10 bg-slate-200 dark:bg-slate-700 rounded"}),(0,e.jsx)("div",{className:"h-10 bg-slate-200 dark:bg-slate-700 rounded"})]})]},s)):W.length===0?(0,e.jsxs)("div",{className:"p-8 text-center",children:[(0,e.jsx)(q,{className:"w-10 h-10 text-slate-600 mx-auto mb-2"}),(0,e.jsx)("p",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"No traders found"})]}):W.map(t=>{const s=t.stats||{},d=t.startingBalance||t.accountBalance||5e4,c=t.currentBalance||s.currentBalance||d+(s.totalPnl||0),g=G=>G==null?"-":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0}).format(G);return(0,e.jsxs)("div",{className:`p-3 active:bg-slate-700/50 ${t.isActive?"":"opacity-60"}`,onClick:()=>It?.(t.id,t),children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 mb-2",children:[(0,e.jsx)("div",{className:"w-9 h-9 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center text-white font-semibold text-sm flex-shrink-0",children:t.displayName?.charAt(0)?.toUpperCase()||"?"}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("p",{className:"font-medium text-slate-900 dark:text-white text-sm truncate",children:t.displayName}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(ft,{role:t.role}),(0,e.jsx)(ts,{trader:t,orgRiskRules:a?.riskRules||a?.settings||{}})]})]}),(0,e.jsx)(Se,{className:"w-4 h-4 text-slate-500 -rotate-90 flex-shrink-0"})]}),(0,e.jsxs)("div",{className:"grid grid-cols-3 gap-2 text-center",children:[(0,e.jsxs)("div",{className:"bg-slate-50 dark:bg-slate-900/50 rounded-lg py-1.5 px-1",children:[(0,e.jsx)("p",{className:"text-[10px] text-slate-500 uppercase",children:"Balance"}),(0,e.jsx)("p",{className:"text-xs font-semibold text-slate-900 dark:text-white",children:g(c)})]}),(0,e.jsxs)("div",{className:"bg-slate-50 dark:bg-slate-900/50 rounded-lg py-1.5 px-1",children:[(0,e.jsx)("p",{className:"text-[10px] text-slate-500 uppercase",children:"P&L"}),(0,e.jsx)("p",{className:`text-xs font-semibold ${(s.totalPnl||0)>=0?"text-green-400":"text-red-400"}`,children:g(s.totalPnl)})]}),(0,e.jsxs)("div",{className:"bg-slate-50 dark:bg-slate-900/50 rounded-lg py-1.5 px-1",children:[(0,e.jsx)("p",{className:"text-[10px] text-slate-500 uppercase",children:"Win Rate"}),(0,e.jsx)("p",{className:"text-xs font-semibold text-slate-900 dark:text-white",children:s.winRate!=null?`${s.winRate.toFixed(0)}%`:"-"})]})]})]},t.id)})}),(0,e.jsx)("div",{className:"hidden md:block overflow-x-auto",children:(0,e.jsxs)("table",{className:"w-full",children:[(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{className:"border-b border-slate-200 dark:border-slate-700 text-left",children:[(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider",children:"Trader"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider",children:"Risk Status"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider",children:"Balance"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider",children:"Role"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider",children:"Phase"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider text-right",children:"P&L"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider text-right",children:"Win Rate"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider text-right",children:"Trades"}),(0,e.jsx)("th",{className:"px-4 py-3 text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider",children:"Last Active"}),(0,e.jsx)("th",{className:"px-4 py-3"})]})}),(0,e.jsx)("tbody",{children:T?[...Array(5)].map((t,s)=>(0,e.jsxs)("tr",{className:"border-b border-slate-200 dark:border-slate-700/50 animate-pulse",children:[(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 bg-slate-200 dark:bg-slate-700 rounded-full"}),(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-28"})]})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-20"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-24"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-16"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-20"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-16 ml-auto"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-12 ml-auto"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-10 ml-auto"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-16"})}),(0,e.jsx)("td",{className:"px-4 py-3",children:(0,e.jsx)("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-6"})})]},s)):W.length===0?(0,e.jsx)("tr",{children:(0,e.jsxs)("td",{colSpan:10,className:"px-4 py-12 text-center",children:[(0,e.jsx)(q,{className:"w-12 h-12 text-slate-600 mx-auto mb-3"}),(0,e.jsx)("p",{className:"text-slate-500 dark:text-slate-400",children:"No traders found"})]})}):W.map(t=>(0,e.jsx)(ua,{trader:t,onViewProfile:Ss,onViewTrades:It,onSuspend:ys,onRemove:ks,onSendMessage:Ts,onLinkAccount:Ps,onAdvancePhase:Ls,onResetPhase:Ds,canManage:B,orgRiskRules:a?.riskRules||a?.settings||{}},t.id))})]})})]})]}),(0,e.jsx)(ha,{isOpen:h,onClose:()=>u(!1),onInvite:Ns,isLoading:fs,orgId:a?.id,orgType:a?.type,orgName:a?.name,orgAccountTiers:a?.accountTiers}),(0,e.jsx)(ga,{isOpen:E,onAccept:ds,onDecline:cs,isAccepting:S,inviteData:Nt}),(0,e.jsx)(Pe,{children:is&&(0,e.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,e.jsx)(M.div,{initial:{opacity:0}
5,animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>{oe||we(!1)}}),(0,e.jsxs)(M.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-full max-w-md bg-slate-800 border border-slate-700 rounded-2xl shadow-2xl overflow-hidden",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-slate-700",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-10 h-10 bg-blue-500/20 rounded-xl flex items-center justify-center",children:(0,e.jsx)(Le,{className:"w-5 h-5 text-blue-400"})}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("h2",{className:"text-lg font-semibold text-white",children:[Z?.tradeLockerAccountId?"Update":"Link"," TradeLocker Account"]}),(0,e.jsx)("p",{className:"text-sm text-slate-400",children:Z?.displayName||Z?.email||"Trader"})]})]}),(0,e.jsx)("button",{onClick:()=>we(!1),disabled:oe,className:"p-2 hover:bg-slate-700 rounded-lg transition-colors text-slate-400 hover:text-white",children:(0,e.jsx)(ut,{className:"w-5 h-5"})})]}),(0,e.jsxs)("div",{className:"p-5 space-y-4",children:[(0,e.jsx)("p",{className:"text-slate-400 text-sm",children:"Link a TradeLocker account so trades are automatically logged to the org dashboard."}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("label",{className:"block text-sm font-medium text-slate-300 mb-1.5",children:[(0,e.jsx)(Js,{className:"inline w-3.5 h-3.5 mr-1 text-blue-400"}),"Account ID"]}),(0,e.jsx)("input",{type:"text",value:_e,onChange:t=>st(t.target.value),placeholder:"e.g. 12345678",className:"w-full px-4 py-3 bg-slate-900/50 border border-slate-600/50 rounded-xl text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500/50 transition-all",disabled:oe}),(0,e.jsx)("p",{className:"text-slate-500 text-xs mt-1",children:"The account ID from TradeLocker"})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("label",{className:"block text-sm font-medium text-slate-300 mb-1.5",children:[(0,e.jsx)(Zt,{className:"inline w-3.5 h-3.5 mr-1 text-purple-400"}),"Server"]}),(0,e.jsxs)("select",{value:Ct,onChange:t=>At(t.target.value),className:"w-full px-4 py-3 bg-slate-900/50 border border-slate-600/50 rounded-xl text-white focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500/50 transition-all appearance-none cursor-pointer",disabled:oe,children:[(0,e.jsx)("option",{value:"demo.tradelocker.com",children:"Demo Server (demo.tradelocker.com)"}),(0,e.jsx)("option",{value:"live.tradelocker.com",children:"Live Server (live.tradelocker.com)"})]})]}),Z?.tradeLockerAccountId&&(0,e.jsxs)("div",{className:"bg-slate-900/50 rounded-lg p-3 border border-slate-700/50",children:[(0,e.jsx)("p",{className:"text-xs text-slate-500 mb-1",children:"Currently linked:"}),(0,e.jsxs)("p",{className:"text-sm text-slate-300 font-mono",children:[Z.tradeLockerAccountId," â ",Z.tradeLockerServer||"N/A"]})]})]}),(0,e.jsxs)("div",{className:"flex gap-3 p-5 border-t border-slate-700",children:[(0,e.jsx)("button",{onClick:()=>we(!1),disabled:oe,className:"flex-1 px-4 py-3 bg-slate-700 hover:bg-slate-600 text-slate-300 rounded-xl font-medium transition-colors disabled:opacity-50",children:"Cancel"}),(0,e.jsx)("button",{onClick:Is,disabled:oe||!_e.trim(),className:"flex-1 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-500 hover:to-purple-500 text-white rounded-xl font-medium transition-all disabled:opacity-50 flex items-center justify-center gap-2",children:oe?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(oa,{className:"w-4 h-4 animate-spin"}),"Saving..."]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Le,{className:"w-4 h-4"}),Z?.tradeLockerAccountId?"Update":"Link"," Account"]})})]})]})]})})]}):A.length>0?(0,e.jsx)("div",{className:"min-h-screen overflow-y-auto theme-page bg-[var(--bg-primary)] flex items-center justify-center",children:(0,e.jsxs)("div",{className:"text-center",children:[(0,e.jsx)(Ke,{className:"w-8 h-8 text-blue-400 animate-spin mx-auto mb-4"}),(0,e.jsx)("p",{className:"text-[var(--text-secondary)]",children:"Loading your organization..."})]})}):(0,e.jsx)("div",{className:"min-h-screen overflow-y-auto theme-page bg-[var(--bg-primary)] p-8",children:(0,e.jsxs)("div",{className:"max-w-4xl mx-auto",children:[(0,e.jsxs)(M.div,{initial:{opacity:0,y:-20}
5,animate:{opacity:1,y:0},className:"text-center mb-8",children:[(0,e.jsx)("div",{className:"w-20 h-20 bg-blue-500/20 rounded-2xl flex items-center justify-center mx-auto mb-6",children:(0,e.jsx)(q,{className:"w-10 h-10 text-blue-400"})}),(0,e.jsx)("h1",{className:"text-2xl font-bold text-[var(--text-primary)] mb-3",children:"Organization Dashboard"}),(0,e.jsx)("p",{className:"text-[var(--text-secondary)]",children:Rt?"Select an organization to view its dashboard":"Create or join an organization to get started"})]}),Rt&&(0,e.jsxs)(M.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:"mb-8",children:[(0,e.jsxs)("h2",{className:"text-lg font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[(0,e.jsx)(Mt,{className:"w-5 h-5 text-blue-400"}),"Your Organizations (",A.length,")"]}),(0,e.jsx)("div",{className:"grid gap-4 sm:grid-cols-2",children:A.map(({membership:t,org:s})=>{if(!s)return null;const d=Xe[s.type]||Xe.trading_group,c=d.icon;return(0,e.jsx)(M.button,{onClick:()=>Tt(s.id),whileHover:{scale:1.02},whileTap:{scale:.98},className:"bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-xl p-5 text-left hover:border-blue-500/50 transition-all group",children:(0,e.jsxs)("div",{className:"flex items-start gap-4",children:[(0,e.jsx)("div",{className:`p-3 rounded-xl ${d.bgColor}`,children:(0,e.jsx)(c,{className:`w-6 h-6 ${d.color}`})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("h3",{className:"text-lg font-semibold text-[var(--text-primary)] truncate group-hover:text-blue-400 transition-colors",children:s.name}),(0,e.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,e.jsx)("span",{className:`px-2 py-0.5 text-xs font-medium rounded ${d.bgColor} ${d.color}`,children:d.label}),(0,e.jsxs)("span",{className:"text-xs text-slate-500 dark:text-slate-400 capitalize",children:["Your role: ",t.role]})]}),s.settings?.maxTraders&&(0,e.jsxs)("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-2",children:[s.memberCount||0," / ",s.settings.maxTraders," members"]})]}),(0,e.jsx)(Se,{className:"w-5 h-5 text-slate-500 dark:text-slate-400 -rotate-90 group-hover:text-blue-400 transition-colors"})]})},s.id)})})]}),(0,e.jsx)(M.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2},className:"mb-8",children:(0,e.jsxs)("button",{onClick:()=>l("/org/create"),className:"w-full bg-gradient-to-r from-blue-600 to-blue-500 hover:from-blue-500 hover:to-blue-400 text-white rounded-xl p-5 flex items-center gap-4 transition-all",children:[(0,e.jsx)("div",{className:"p-3 bg-white/20 rounded-xl",children:(0,e.jsx)(Xt,{className:"w-6 h-6"})}),(0,e.jsxs)("div",{className:"text-left",children:[(0,e.jsx)("h3",{className:"text-lg font-semibold",children:"Create New Organization"}),(0,e.jsx)("p",{className:"text-sm text-blue-100",children:"Start a new prop firm, trading group, or RIA"})]})]})}),(0,e.jsxs)(M.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.3},className:"border-t border-[var(--border-primary)] pt-8",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,e.jsxs)("h2",{className:"text-lg font-semibold text-[var(--text-primary)] flex items-center gap-2",children:[(0,e.jsx)(q,{className:"w-5 h-5 text-blue-400"}),"Browse Prop Firms & Trading Groups"]}),(0,e.jsx)("button",{onClick:()=>as(!ve),className:"px-4 py-2 bg-blue-600/20 hover:bg-blue-600/30 text-blue-400 rounded-lg text-sm font-medium transition-colors",children:ve?"Hide":"Browse Organizations"})]}),ve&&(0,e.jsx)("div",{className:"space-y-3",children:ss?(0,e.jsxs)("div",{className:"text-center py-8",children:[(0,e.jsx)("div",{className:"w-8 h-8 border-2 border-purple-400 border-t-transparent rounded-full animate-spin mx-auto mb-3"}),(0,e.jsx)("p",{className:"text-slate-500 dark:text-slate-400",children:"Loading all organizations..."})]}):Oe.length===0?(0,e.jsx)("div",{className:"text-center py-8 text-slate-500 dark:text-slate-400",children:"No organizations found on the platform"}):(0,e.jsx)("div",{className:"grid gap-3 sm:grid-cols-2",children:Oe.map(t=>{const s=Xe[t.type]||Xe.trading_group,d=s.icon,c=$s(t.id),g=ls===t.id;return(0,e.jsxs)("div",{className:"bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-xl p-4 flex items-center gap-4",children:[(0,e.jsx)("div",{className:`p-2.5 rounded-lg ${s.bgColor}`,children:(0,e.jsx)(d,{className:`w-5 h-5 ${s.color}`})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("h3",{className:"font-medium text-[var(--text-primary)] truncate",children:t.name}),(0,e.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[(0,e.jsx)("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s.label}),(0,e.jsx)("span",{className:"text-xs text-slate-500",children:"â¢"}),(0,e.jsxs)("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:[t.memberCount||0," members"]})]})]}),c?(0,e.jsxs)("button",{onClick:()=>Tt(t.id),className:"px-3 py-1.5 bg-green-500/20 text-green-400 rounded-lg text-sm font-medium hover:bg-green-500/30 transition-colors flex items-center gap-1.5",children:[(0,e.jsx)(be,{className:"w-4 h-4"}),"Enter"]}):w?(0,e.jsx)("button",{onClick:()=>os(t.id),disabled:g,className:"px-3 py-1.5 bg-purple-500/20 text-purple-400 rounded-lg text-sm font-medium hover:bg-purple-500/30 transition-colors flex items-center gap-1.5 disabled:opacity-50",children:g?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"w-4 h-4 border-2 border-purple-400 border-t-transparent roun
5ded-full animate-spin"}),"Joining..."]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(ea,{className:"w-4 h-4"}),"Admin Join"]})}):(0,e.jsxs)("button",{onClick:()=>ns(t.id),className:"px-3 py-1.5 bg-blue-500/20 text-blue-400 rounded-lg text-sm font-medium hover:bg-blue-500/30 transition-colors flex items-center gap-1.5",children:[(0,e.jsx)(mt,{className:"w-4 h-4"}),"Request"]})]},t.id)})})})]})]})})};export{ya 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.