PageSourceSearch

https://techmalak.com/assets/js/index-BVp-uYeM.js

js techmalak.com collected 2026-09-24 23:51:53 UTC 30,510 bytes, 1 lines download raw bytes

1import{C as se,j as e,l as M,q as re}from"./main-BGrMPGSc.js";import{N as ae,a as w,c as te,R as le}from"./router-vendor-CnMLpzFH.js";import{c as oe}from"./ui-vendor-mBAqIvvt.js";import{F as ne,e as ie,C as I}from"./Upload-BC1kKeon.js";import"./index-D2iwaVtp.js";import{B as A}from"./index-BbUja-Fu.js";import{P as de}from"./index-1odnOtpu.js";import{a as q}from"./Skeleton-CCAYUC7L.js";import{u as ce}from"./useAuth-B04jjPKI.js";import{c as v}from"./utils-CQQBCEZ3.js";import{c as U,M as D}from"./behavioral-modules-CE3101VR.js";import{T as F}from"./trophy-DNEt57Hm.js";import{T as Z}from"./target-b6kSakLD.js";import{S as J}from"./shield-C0XiNOpC.js";import{Z as R}from"./zap-Dt9xnmHC.js";import{A as X}from"./arrow-left-DCwSloWj.js";import{C as B,B as T,L as me,a as $}from"./lock-CsKy3bRd.js";import{C as ge}from"./circle-x-ElqcBz_5.js";import{S as xe}from"./sparkles-naCGM1e9.js";import{C as ue,a as K}from"./chevron-right-CHzOXTEV.js";import{C as z}from"./chart-column-zuPlvq0W.js";import{T as Q}from"./trending-up-DyxEII2u.js";import{T as pe}from"./triangle-alert-DM87r9Zj.js";import{s as E}from"./supabase-Bp7AwA7Z.js";import{a as he}from"./xpAward-Ci8jbt00.js";import{t as O}from"./index-ICG4qlAO.js";import{F as H,S as fe}from"./shield-alert-D9SoEejE.js";import{T as be}from"./trending-down-CcCmdbvT.js";import{L as je,C as ye}from"./layers-CkCRE_Xr.js";import{c as ve}from"./createLucideIcon-KzH94YZI.js";import{E as Ne}from"./eye-Cla8Zm8d.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};l.SENTRY_RELEASE={id:"c2fa0ad612596b597e7066496a65ae647c4e0b42"};var o=new l.Error().stack;o&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[o]="f0089e52-297e-42c5-8c63-a1342d8e1ea5",l._sentryDebugIdIdentifier="sentry-dbid-f0089e52-297e-42c5-8c63-a1342d8e1ea5")}catch{}})();const we=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]],_e=ve("scan",we);function Ce({items:l=[],className:o,...a}){const{isRtl:r}=se(),f=r?ne:ie;return e.jsx("ul",{className:oe("flex flex-wrap items-center gap-1.5",o),...a,children:l.map((_,t)=>e.jsx("li",{className:"flex items-center gap-1.5",children:_.path?e.jsxs(e.Fragment,{children:[e.jsx(ae,{to:_.path,className:"tracking-wide text-primary-600 transition-colors hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500",children:_.title}),t<l.length-1&&e.jsx(f,{className:"size-5"})]}):e.jsxs("span",{className:"tracking-wide",children:[" ",_.title]})},t))})}const Se=({module:l,levelTitle:o,levelColor:a,onComplete:r,onExit:f,existingResponses:_={}})=>{const[t,b]=w.useState(0),[h,S]=w.useState(_),[i,j]=w.useState(null),[C,k]=w.useState(!1),[d,m]=w.useState(!1),s=l.scenarios[t],n=l.scenarios.length,c=w.useMemo(()=>U(l.id,h),[l.id,h]),g=w.useCallback(p=>{C||(j(p),S(u=>({...u,[s.id]:p})),setTimeout(()=>k(!0),300))},[s?.id,C]),x=w.useCallback(()=>{if(t<n-1)b(p=>p+1),j(null),k(!1);else{const p=U(l.id,h);m(!0),r(h,p.percentage,p.disciplinedCount)}},[t,n,l.id,h,r]),P=w.useCallback(()=>{if(t>0){b(N=>N-1);const p=l.scenarios[t-1],u=h[p.id];j(u||null),k(!!u)}},[t,l.scenarios,h]);if(d){const p=c.percentage>=80?"text-game-green":c.percentage>=60?"text-game-amber":"text-game-magenta",u=c.percentage>=80?"Elite Discipline":c.percentage>=60?"Developing Discipline":"Needs Work",y=c.percentage>=80?F:c.percentage>=60?Z:J;return e.jsx("div",{className:"max-w-2xl mx-auto space-y-6",children:e.jsxs(I,{className:"bg-gradient-to-br from-gray-800/80 via-gray-900 to-gray-800/80 border border-gray-700/50 p-8 text-center",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("div",{className:v("w-20 h-20 rounded-full flex items-center justify-center",c.percentage>=80?"bg-game-green/20 border-2 border-game-green":c.percentage>=60?"bg-game-amber/20 border-2 border-game-amber":"bg-game-magenta/20 border-2 border-game-magenta"),children:e.jsx(y,{className:v("w-10 h-10",p)})})}),e.jsx("h2",{className:"text-2xl font-bold text-white font-['Poppins',sans-serif] mb-2",children:"Module Complete"}),e.jsx("p",{className:"text-gray-400 font-['Inter',sans-serif] mb-6",children:l.title}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-8",children:[e.jsxs("div",{className:"bg-gray-800/50 rounded-lg p-4 border border-gray-700/30",children:[e.jsxs("div",{className:v("text-3xl font-bold font-mono",p),children:[c.percentage,"%"]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"Overall Score"})]}),e.jsxs("div",{className:"bg-gray-800/50 rounded-lg p-4 border border-gray-700/30",children:[e.jsxs("div",{className:"text-3xl font-bold text-game-green font-mono",children:[c.disciplinedCount,"/",c.total]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"Disciplined"})]}),e.jsxs("div",{className:"bg-gray-800/50 rounded-lg p-4 border border-gray-700/30",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[e.jsx(R,{className:"w-5 h-5 text-game-amber"}),e.jsxs("span",{className:"text-3xl font-bold text-game-amber font-mono",children:["+",l.xpReward]})]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"XP Earned"})]})]}),e.jsxs("div",{className:v("inline-flex items-center gap-2 px-4 py-2 rounded-full text-sm font-bold uppercase tracking-wider mb-6",c.percentage>=80?"bg-game-green/10 border border-game-green/30 text-game-green":c.percentage>=60?"bg-game-amber/10 border border-game-amber/30 text-game-amber":"bg-game-magenta/10 border border-game-magenta/30 text-game-magenta"),children:[e.jsx(y,{className:"w-4 h-4"}),u]}),e.jsx("div",{className:"pt-4",children:e.jsxs(A,{onClick:f,className:"bg-brand-primary hover:bg-brand-hover px-8",children:[e.jsx(X,{className:"w-4 h-4 mr-2"}),"Back to Modules"]})})]})})}
1return s?e.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{onClick:f,className:"flex items-center gap-2 text-gray-400 hover:text-white transition-colors text-sm",children:[e.jsx(X,{className:"w-4 h-4"}),"Exit Module"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-500 uppercase tracking-wider",children:o}),e.jsx("span",{className:"px-2.5 py-1 rounded-full text-xs font-bold",style:{backgroundColor:`${a}20`,color:a,borderColor:`${a}40`,borderWidth:1},children:l.title})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-xs text-gray-400",children:[e.jsxs("span",{children:["Scenario ",t+1," of ",n]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(B,{className:"w-3 h-3 text-game-green"}),c.disciplinedCount," disciplined"]})]}),e.jsx("div",{className:"w-full h-2 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500 ease-out",style:{width:`${(t+(C?1:0))/n*100}%`,background:`linear-gradient(90deg, ${a}, ${a}cc)`}})})]}),e.jsxs(I,{className:"bg-gray-800/60 border border-gray-700/50 p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 w-10 h-10 rounded-full bg-brand-primary/10 border border-brand-primary/30 flex items-center justify-center",children:e.jsx(T,{className:"w-5 h-5 text-brand-primary"})}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-white font-['Inter',sans-serif] leading-relaxed text-sm-plus",children:s.narrative})})]}),s.context&&e.jsx("div",{className:"ml-[52px] px-4 py-3 bg-gray-900/60 rounded-lg border border-gray-700/30",children:e.jsx("p",{className:"text-sm font-mono text-gray-300 tracking-wide",children:s.context})})]}),e.jsx("div",{className:"space-y-3",children:s.choices.map(p=>{const u=i===p.id,N=C,y=p.type==="disciplined";return e.jsx("button",{onClick:()=>g(p.id),disabled:C,className:v("w-full text-left p-4 rounded-lg border-2 transition-all duration-300",!u&&!N&&"bg-gray-800/30 border-gray-700/50 hover:border-gray-600 hover:bg-gray-800/50 cursor-pointer",u&&!N&&"bg-brand-primary/10 border-brand-primary ring-2 ring-brand-primary/20",N&&y&&"bg-game-green/10 border-game-green/50",N&&!y&&u&&"bg-game-magenta/10 border-game-magenta/50",N&&!y&&!u&&"bg-gray-900/30 border-gray-700/30 opacity-50",N&&"cursor-default"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:N?y?e.jsx(B,{className:"w-5 h-5 text-game-green"}):e.jsx(ge,{className:"w-5 h-5 text-game-magenta/60"}):e.jsx("div",{className:v("w-5 h-5 rounded-full border-2",u?"border-brand-primary bg-brand-primary":"border-gray-500"),children:u&&e.jsx("div",{className:"w-full h-full rounded-full flex items-center justify-center",children:e.jsx("div",{className:"w-2 h-2 rounded-full bg-white"})})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:v("text-sm-plus font-['Inter',sans-serif] leading-relaxed",N&&y&&"text-game-green",N&&!y&&u&&"text-game-magenta",N&&!y&&!u&&"text-gray-500",!N&&u&&"text-white font-medium",!N&&!u&&"text-gray-300"),children:p.text}),N&&u&&e.jsx("div",{className:v('mt-3 p-3 rounded-md text-sm font-["Inter",sans-serif] leading-relaxed',y?"bg-game-green/10 text-game-green border border-game-green/30":"bg-game-magenta/10 text-game-magenta border border-game-magenta/30"),children:p.feedback}),N&&y&&!u&&e.jsx("span",{className:"inline-block mt-2 text-xs font-bold text-game-green uppercase tracking-wider",children:"Disciplined Choice"})]}),N&&(u||y)&&e.jsxs("div",{className:v("flex-shrink-0 px-2 py-1 rounded-full text-xs font-bold",y?"bg-game-green/10 text-game-green border border-game-green/20":"bg-game-magenta/10 text-game-magenta border border-game-magenta/20"),children:["+",p.points," pts"]})]})},p.id)})}),C&&e.jsxs("div",{className:"mt-4 p-4 bg-gray-900/60 rounded-lg border border-gray-700/30 space-y-3 animate-in fade-in duration-500",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-bold text-gray-300 uppercase tracking-wider",children:[e.jsx(xe,{className:"w-4 h-4 text-brand-primary"}),"Clinical Debrief"]}),e.jsx("p",{className:"text-sm text-gray-300 font-['Inter',sans-serif] leading-relaxed",children:s.debrief})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(A,{onClick:P,disabled:t===0,variant:"outlined",className:"border-gray-600 hover:border-gray-500 text-gray-300 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(ue,{className:"w-4 h-4 mr-1"}),"Previous"]}),e.jsxs("div",{className:"text-sm text-gray-400 font-mono",children:[c.score," / ",c.maxScore," pts"]}),C&&e.jsx(A,{onClick:x,className:"bg-brand-primary hover:bg-brand-hover",children:t<n-1?e.jsxs(e.Fragment,{children:["Next Scenario",e.jsx(K,{className:"w-4 h-4 ml-1"})]}):e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"w-4 h-4 mr-1"}),"Complete Module"]})}),!C&&e.jsx("div",{className:"w-[140px]"})]})]}):null},V={mod_l1_triggers:"Trigger ID",mod_l1_biases:"Bias Recognition",mod_l1_awareness:"Self-Awareness",mod_l2_flow:"Flow State",mod_l2_tilt:"Tilt Recovery",mod_l2_volatility:"Volatility Nav",mod_l3_sizing:"Position Sizing",mod_l3_pyramid:"Pyramiding",mod_l3_equity:"Equity Curve"},ke=({allProgress:l,className:o})=>{const a=w.useMemo(()=>l.filter(t=>t.completed),[l]),r=w.useMemo(()=>
1{if(a.length===0)return null;const t=a.reduce((d,m)=>d+m.disciplined_count,0),b=a.reduce((d,m)=>d+m.total_scenarios,0),h=a.reduce((d,m)=>d+m.score,0)/a.length,S=a.reduce((d,m)=>d+m.xp_awarded,0),i=b>0?t/b*100:0,j=D.map(d=>{const m=a.filter(g=>g.level_id===d.id),s=m.reduce((g,x)=>g+x.disciplined_count,0),n=m.reduce((g,x)=>g+x.total_scenarios,0),c=m.length>0?m.reduce((g,x)=>g+x.score,0)/m.length:0;return{levelId:d.id,title:d.title.split(":")[0],color:d.color,completedCount:m.length,totalCount:d.modules.length,avgScore:c,disciplineRate:n>0?s/n*100:0}}),C=a.filter(d=>d.score<70).sort((d,m)=>d.score-m.score).slice(0,3),k=a.filter(d=>d.score>=80).sort((d,m)=>m.score-d.score).slice(0,3);return{totalCompleted:a.length,totalAvailable:D.reduce((d,m)=>d+m.modules.length,0),avgScore:h,disciplineRate:i,totalDisciplined:t,totalScenarios:b,totalXp:S,levelBreakdown:j,weakModules:C,strongModules:k}},[a]);if(!r||r.totalCompleted===0)return e.jsxs(I,{className:v("bg-gray-900/50 border border-gray-800 p-6",o),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(z,{className:"w-5 h-5 text-brand-primary"}),e.jsx("h3",{className:"text-lg font-bold text-white font-['Poppins',sans-serif]",children:"Behavioral Analytics"})]}),e.jsxs("div",{className:"text-center py-8",children:[e.jsx(T,{className:"w-10 h-10 text-gray-600 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-500 text-sm font-['Inter',sans-serif]",children:"Complete your first module to see analytics"})]})]});const f=r.avgScore>=85?"Elite":r.avgScore>=70?"Strong":r.avgScore>=55?"Developing":"Needs Work",_=r.avgScore>=85?"text-game-green":r.avgScore>=70?"text-game-cyan":r.avgScore>=55?"text-game-amber":"text-game-magenta";return e.jsxs(I,{className:v("bg-gray-900/50 border border-gray-800 overflow-hidden",o),children:[e.jsx("div",{className:"p-6 border-b border-gray-800/50",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(z,{className:"w-5 h-5 text-brand-primary"}),e.jsx("h3",{className:"text-lg font-bold text-white font-['Poppins',sans-serif]",children:"Behavioral Analytics"})]}),e.jsx("div",{className:v("text-sm font-bold uppercase tracking-wider",_),children:f})]})}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-gray-800/40 rounded-lg p-3 border border-gray-700/30",children:[e.jsxs("div",{className:"text-2xl font-bold text-white font-mono",children:[r.avgScore.toFixed(0),"%"]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"Avg Score"})]}),e.jsxs("div",{className:"bg-gray-800/40 rounded-lg p-3 border border-gray-700/30",children:[e.jsxs("div",{className:"text-2xl font-bold text-game-green font-mono",children:[r.disciplineRate.toFixed(0),"%"]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"Discipline Rate"})]}),e.jsxs("div",{className:"bg-gray-800/40 rounded-lg p-3 border border-gray-700/30",children:[e.jsxs("div",{className:"text-2xl font-bold text-white font-mono",children:[r.totalCompleted,"/",r.totalAvailable]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"Modules Done"})]}),e.jsxs("div",{className:"bg-gray-800/40 rounded-lg p-3 border border-gray-700/30",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(R,{className:"w-4 h-4 text-game-amber"}),e.jsx("span",{className:"text-2xl font-bold text-game-amber font-mono",children:r.totalXp})]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"XP Earned"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-2",children:[e.jsxs("span",{className:"text-game-green font-semibold flex items-center gap-1",children:[e.jsx(B,{className:"w-3 h-3"}),"Disciplined: ",r.totalDisciplined]}),e.jsxs("span",{className:"text-game-magenta font-semibold",children:["Impulsive: ",r.totalScenarios-r.totalDisciplined]})]}),e.jsxs("div",{className:"w-full h-3 bg-gray-800 rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full bg-game-green rounded-l-full transition-all duration-500",style:{width:`${r.disciplineRate}%`}}),e.jsx("div",{className:"h-full bg-game-magenta/60 rounded-r-full transition-all duration-500",style:{width:`${100-r.disciplineRate}%`}})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-gray-300 uppercase tracking-wider mb-3",children:"Level Breakdown"}),e.jsx("div",{className:"space-y-3",children:r.levelBreakdown.map(t=>t.completedCount===0?null:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2 h-8 rounded-full",style:{backgroundColor:t.color}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium text-white truncate",children:t.title}),e.jsxs("span",{className:"text-xs text-gray-400",children:[t.completedCount,"/",t.totalCount," modules"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 h-1.5 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${t.avgScore}%`,backgroundColor:t.color}})}),e.jsxs("span",{className:"text-xs font-mono text-gray-400 w-10 text-right",children:[t.avgScore.toFixed(0),"%"]})]})]})]},t.levelId))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[r.strongModules.length>0&&e.jsxs("div",{className:"bg-game-green/10 rounded-lg p-4 border border-game-green/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Q,{className:"w-4 h-4 text-game-green"}),e.jsx("span",{className:"text-sm font-bold text-game-green",children:"Strengths"})]}),e.jsx("div",{className:"space-y-2",children:r.strongModules.map(t=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-300",children:V[t.module_id]||t.module_id}),e.jsxs("span",{className:"font-mono text-game-green",children:[t.score,"%"]})]},t.module_id))})]}),r.weakModules.length>0&&e.jsxs("div",{className:"bg-game-magenta/10 rounded-lg p-4 border border-game-magenta/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(pe,{className:"w-4 h-4 text-game-magenta"}),e.jsx("span",{className:"text-sm font-bold text-game-magenta",children:"Needs Improvement"})]}),e.jsx("div",{className:"space-y-2",children:r.weakModules.map(t=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-300",children:V[t.module_id]||t.module_id}),e.jsxs("span",{className:"font-mono text-game-magenta",children:[t.score,"%"]})]},t.module_id))})]})]})]})]})};async function W(l){const{data:o,error:a}=await E.from("user_module_progress").select("*").eq("user_id",l).order("created_at",{ascending:!0});return a?(M.error("[BehavioralModules] Error fetching progress:",a),[]):o??[]}async function Me(l,o){const{data:a,error:r}=await E.from("user_module_progress").select("*").eq("user_id",l).eq("module_id",o).maybeSingle();return r?(M.error("[BehavioralModules] Error fetching module progress:",r),null):a}function G(l){const o=new Map;for(const a of l){const r=o.get(a.level_id)??[];r.push(a),o.set(a.level_id,r)}return D.map(a=>{const r=o.get(a.id)??[],f=r.filter(i=>i.completed),_=a.modules.length,t=f.length>=_;let b=!0;if(a.unlockCriteria.requiredLevel){const i=a.unlockCriteria.requiredLevel,j=o.get(i)??[],k=D.find(m=>m.id===i)?.modules.length??0,d=j.filter(m=>m.completed);d.length<k&&(b=!1),b&&a.unlockCriteria.minimumScore!==void 0&&(d.length>0?d.reduce((s,n)=>s+n.score,0)/d.length:0)<a.unlockCriteria.minimumScore&&(b=!1)}const h=r.reduce((i,j)=>i+j.xp_awarded,0),S=f.length>0?Math.round(f.reduce((i,j)=>i+j.score,0)/f.length):0;return{levelId:a.id,modules:r,isUnlocked:b,isComplete:t,overallScore:S,totalXpEarned:h}})}async function Pe(l,o,a,r,f=!1){const{score:_,maxScore:t,percentage:b,disciplinedCount:h,total:S}=U(o,r);let i=0;if(f&&!(await Me(l,o))?.completed){i=D.flatMap(c=>c.modules).find(c=>c.id===o)?.xpReward??0;const n=Math.max(.5,b/100);i=Math.round(i*n)}const j=await he({moduleId:o,levelId:a,responses:r,score:b,disciplinedCount:h,totalScenarios:S,completed:f});if(!j.missing)return j.error?(M.error("[BehavioralModules] Error saving progress:",j.error),null):j.row;const C={user_id:l,module_id:o,level_id:a,responses:r,score:b,disciplined_count:h,total_scenarios:S,completed:f,completed_at:f?new Date().toISOString():null,xp_awarded:i,updated_at:new Date().toISOString()},{data:k,error:d}=await E.from("user_module_progress").upsert(C,{onConflict:"user_id,module_id"}).select().single();if(d)return M.error("[BehavioralModules] Error saving progress:",d),null;if(i>0)try{await E.rpc("increment_trader_xp",{p_user_id:l,p_xp_amount:i}),M.debug(`[BehavioralModules] Awarded ${i} XP for completing ${o}`),await E.from("xp_events").insert({user_id:l,event_type:"behavioral_assessment",xp_earned:i,reference_id:k?.id??null,reference_type:"behavioral_module",description:`Completed behavioral module: ${o} (Score: ${b}%)`})}catch(m){M.error("[BehavioralModules] Error awarding XP:",m)}return k}async function De(l,o,a,r,f){try{const _=D.flatMap(i=>i.modules).find(i=>i.id===o);if(!_)return;const b=`[Behavioral Module Completed] ${D.find(i=>i.modules.some(j=>j.id===o))?.title} — ${_.title}: Score ${a}%, Disciplined choices: ${r}/${f}`,{data:h}=await E.from("chat_sessions").select("id").eq("user_id",l).order("created_at",{ascending:!1}).limit(1).maybeSingle();if(!h?.id){M.debug("[BehavioralModules] No chat session yet — skipping User Log note");return}const{error:S}=await E.from("chat_messages").insert({chat_session_id:h.id,user_id:l,question:"[system] behavioral module completed",answer:b,status:"completed",origin:"system_note",completed_at:new Date().toISOString()});if(S){M.error("[BehavioralModules] User log note insert failed:",S);return}M.debug("[BehavioralModules] User log update triggered:",b)}catch(_){M.error("[BehavioralModules] User log trigger error:",_)}}const Ee={Brain:T,Shield:J,Flame:H,Target:Z,Eye:Ne,Scan:_e,ShieldAlert:fe,TrendingUp:Q,
1Calculator:ye,Layers:je,TrendingDown:be,Zap:R,HeartPulse:H};function Y(l){return Ee[l]||T}const Le=({className:l})=>{const{user:o}=ce(),[a,r]=te(),[f,_]=w.useState(!0),[t,b]=w.useState([]),[h,S]=w.useState([]),[i,j]=w.useState(null),C=w.useRef(!1);w.useEffect(()=>{async function s(){if(!o?.id){_(!1);return}try{const n=await W(o.id);S(n),b(G(n))}catch(n){M.error("[ModulesHub] Error loading progress:",n)}finally{_(!1)}}s()},[o?.id]),w.useEffect(()=>{if(f||C.current)return;const s=a.get("launch");if(s)for(const n of D){const c=n.modules.find(g=>g.id===s);if(c){j({module:c,levelTitle:n.title,levelColor:n.color}),C.current=!0,r({},{replace:!0});return}}},[f,a,r]);const k=w.useCallback(async(s,n,c)=>{if(!o?.id||!i)return;const{module:g}=i,x=D.find(P=>P.modules.some(p=>p.id===g.id));if(x)try{await Pe(o.id,g.id,x.id,s,!0),De(o.id,g.id,n,c,g.scenarios.length);const P=await W(o.id);S(P),b(G(P)),O.success(`Module complete: ${g.title}`,{description:`Score: ${n}% · +${g.xpReward} XP`,className:"tm-toast--celebrate"})}catch(P){M.error("[ModulesHub] Error saving completion:",P),O.error("Failed to save progress. Please try again.")}},[o?.id,i]),d=w.useCallback((s,n,c)=>{j({module:s,levelTitle:n,levelColor:c})},[]),m=w.useCallback(()=>{j(null)},[]);if(i){const s=h.find(n=>n.module_id===i.module.id);return e.jsx("div",{className:l,children:e.jsx(Se,{module:i.module,levelTitle:i.levelTitle,levelColor:i.levelColor,onComplete:k,onExit:m,existingResponses:s?.responses})})}return f?e.jsxs("div",{className:v("space-y-6",l),children:[e.jsx(q,{className:"h-32 w-full"}),e.jsx(q,{className:"h-64 w-full"}),e.jsx(q,{className:"h-64 w-full"})]}):e.jsxs("div",{className:v("space-y-8",l),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight text-white font-['Poppins',sans-serif]",children:"Behavioral Progression"}),e.jsx("p",{className:"text-gray-400 max-w-2xl font-['Inter',sans-serif]",children:"Master the psychology of high-performance trading through scenario-based training. Complete each level to unlock the next. Your choices feed the AI coach's understanding of your behavioral patterns."})]}),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:t.map(s=>{const n=D.find(x=>x.id===s.levelId),c=s.modules.filter(x=>x.completed).length,g=n.modules.length;return e.jsxs(I,{className:v("p-4 border transition-all",s.isUnlocked?"bg-gray-800/50 border-gray-700/50":"bg-gray-900/30 border-gray-800/30 opacity-60"),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center",style:{backgroundColor:`${n.color}20`},children:s.isComplete?e.jsx(B,{className:"w-4 h-4",style:{color:n.color}}):s.isUnlocked?e.jsx(me,{className:"w-4 h-4",style:{color:n.color}}):e.jsx($,{className:"w-4 h-4 text-gray-500"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-white",children:n.title.split(":")[0]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[c,"/",g," modules"]})]})]}),e.jsx("div",{className:"w-full h-1.5 bg-gray-700 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${g>0?c/g*100:0}%`,backgroundColor:n.color}})})]},s.levelId)})}),h.some(s=>s.completed)&&e.jsx(ke,{allProgress:h}),D.map((s,n)=>{const c=t[n],g=c?.isUnlocked??s.unlockCriteria.requiredLevel===null;return e.jsxs(I,{className:v("border overflow-hidden relative",g?"bg-gray-900 border-gray-800":"bg-gray-900/40 border-gray-800/40"),children:[e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 rounded-full blur-[80px] -mr-32 -mt-32 pointer-events-none",style:{backgroundColor:`${s.color}08`}}),e.jsx("div",{className:"p-6 border-b border-gray-800/50 relative z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center",style:{backgroundColor:`${s.color}15`,border:`1px solid ${s.color}30`},children:le.createElement(Y(s.icon),{className:"w-6 h-6",style:{color:g?s.color:re[3]}})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold text-white font-['Poppins',sans-serif] flex items-center gap-2",children:[s.title,!g&&e.jsx($,{className:"w-4 h-4 text-gray-500"}),c?.isComplete&&e.jsx(B,{className:"w-4 h-4 text-game-green"})]}),e.jsx("p",{className:"text-gray-400 text-sm font-['Inter',sans-serif]",children:s.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-game-amber/10 border border-game-amber/20",children:[e.jsx(R,{className:"w-4 h-4 text-game-amber"}),e.jsxs("span",{className:"text-sm font-bold text-game-amber",children:["+",s.xpReward," XP"]})]})]})}),e.jsxs("div",{className:"p-6 relative z-10",children:[!g&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx($,{className:"w-10 h-10 text-gray-600 mx-auto mb-3"}),e.jsxs("p",{className:"text-gray-500 text-sm font-['Inter',sans-serif]",children:["Complete ",s.unlockCriteria.requiredLevel?.replace("_"," ").replace(/\b\w/g,x=>x.toUpperCase())," with ",s.unlockCriteria.minimumScore,"%+ score to unlock"]})]}),g&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:s.modules.map(x=>{const P=h.find(L=>L.module_id===x.id),p=P?.completed??!1,u=P?.score??0,N=s.modules.indexOf(x),y=N===0||h.some(L=>L.module_id===s.modules[N-1].id&&L.completed),ee=Y(x.icon);return e.jsxs("div",{className:v("relative rounded-xl border p-5 transition-all duration-300",y?"bg-gray-800/80 border-gray-700/50 hover:border-brand-primary/50 hover:shadow-[0_0_15px_color-mix(in_srgb,var(--color-brand-primary)_10%,transparent)] group cursor-pointer":"bg-gray-900/40 border-gray-800 cursor-not-allowed overflow-hidden"),onClick:y?()=>d(x,s.title,s.color):void 0,children:[!y&&e.jsxs("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[1px] flex flex-col items-center justify-center z-10",children:[e.jsx($,{className:"w-6 h-6 text-gray-500 mb-1"}),e.jsx("span",{className:"text-xs text-gray-500",children:"Complete previous module"})]}),p&&e.jsx("div",{className:"absolute top-3 right-3",children:e.jsx(B,{className:"w-5 h-5 text-game-green"})}),e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsx("div",{className:v("p-2 rounded-lg",y?"bg-brand-primary/15 text-brand-primary":"bg-gray-800 text-gray-500"),children:e.jsx(ee,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex items-center gap-1 px-2 py-0.5 rounded-full bg-game-amber/10 border border-game-amber/20",children:[e.jsx(R,{className:"w-3 h-3 text-game-amber"}),e.jsxs("span",{className:"text-xs font-bold text-game-amber",children:["+",x.xpReward]})]})]}),e.jsx("h3",{className:v("text-base font-bold font-['Poppins',sans-serif] mb-1.5",y?"text-white":"text-gray-500"),children:x.title}),e.jsx("p",{className:v("text-sm font-['Inter',sans-serif] mb-4 line-clamp-2",y?"text-gray-400":"text-gray-600"),children:x.description}),e.jsxs("div",{className:"text-xs text-gray-500 mb-3",children:[x.scenarios.length," scenarios"]}),y&&e.jsx("div",{className:"mt-auto",children:p?e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-gray-400",children:"Score"}),e.jsxs("span",{className:v("font-bold",u>=80?"text-game-green":u>=60?"text-game-amber":"text-game-magenta"),children:[u,"%"]})]}),e.jsx("div",{className:"w-full h-1.5 bg-gray-700 rounded-full overflow-hidden",children:e.jsx("div",{className:v("h-full rounded-full transition-all",u>=80?"bg-game-green":u>=60?"bg-game-amber":"bg-game-magenta"),style:{width:`${u}%`}})}),e.jsx("button",{className:"mt-2 text-xs text-gray-500 hover:text-brand-primary transition-colors",onClick:L=>{L.stopPropagation(),d(x,s.title,s.color)},children:"Retake module"})]}):e.jsxs("div",{className:"flex items-center justify-between text-sm font-semibold text-brand-primary group-hover:text-coral-2 transition-colors",children:[e.jsx("span",{children:"Start Module"}),e.jsx(K,{className:"w-4 h-4 transform group-hover:translate-x-1 transition-transform"})]})})]},x.id)})})]})]},s.id)})]})};function cs(){return e.jsxs("div",{className:"min-h-screen bg-bg-page relative overflow-hidden",children:[e.jsx(de,{}),e.jsx("div",{className:"flex flex-col min-h-screen relative z-10",children:e.jsxs("div",{className:"flex-1 space-y-4 p-4 md:p-8 pt-6",children:[e.jsx(Ce,{items:[{title:"Dashboard",path:"/dashboard"},{title:"Trader Psychology",path:"/behavioral-assessment"},{title:"Behavioral Modules"}]}),e.jsx(Le,{className:"mt-4"})]})})]})}export{cs 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.