1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jspdf.es.min-Bh1qgChc.js","assets/index-g4WugBH4.js","assets/react-BpdGtorb.js","assets/charts-VqRjxJBw.js","assets/supabase-DRR_Es6B.js","assets/index-CEzzrbFB.css"])))=>i.map(i=>d[i]); 2import{d as _e,j as e,as as O,at as U,au as Y,av as K,a as Ee,T as fe,a5 as qe,B as R,X as ze,u as je,a9 as Be,V as We,a3 as He,e as Ie,I as B,a8 as ge,F as Oe,ak as ne,_ as Ue,Z as pe,s as se,$ as Ce,W as Ye,b as Ke,ae as Ge}from"./index-g4WugBH4.js";import{r as w}from"./react-BpdGtorb.js";import{P as Je}from"./PremiumPageHeader-DtoR-MWi.js";import{u as Xe}from"./usePortfolioAssets-1TAWI_Sl.js";import{f as ie,b as Qe,c as Ze,g as es,a as ss,h as ts,e as rs,i as is,j as as,d as ns,k as os}from"./riskCalculations-DlUAkL57.js";import{C as p,a as f,b,c as v,d as N}from"./card-rwt4A55r.js";import{B as V}from"./badge-DEgwKkG_.js";import{I as G}from"./info-CNue2mgk.js";import{C as ye}from"./circle-check-big-tnvYvNv2.js";import{T as Q}from"./triangle-alert-DnKzB0ks.js";import{A as ls}from"./activity-BGWZi07P.js";import{T as ue}from"./trending-down-BPYf34mQ.js";import{E as Pe}from"./earth-CtFIHWCH.js";import{E as W}from"./charts-VqRjxJBw.js";import{H as cs}from"./house-C3OSBbLq.js";import{C as ds}from"./circle-alert-DDNRfnll.js";import{L as C}from"./label-BhkyX0L4.js";import{T as ms,a as xs,b as ce,c as de}from"./tabs-D3rJiyQ0.js";import{T as me,a as xe,b as H,c as D,d as he,e as L}from"./table-ChZYyRts.js";import{a as I}from"./privacyFormat-CoirZvEa.js";import{C as hs}from"./chevron-down-fgIjtWz2.js";import{u as us}from"./usePortfolioRiskMetrics-C1Pouf73.js";import{RiskSkeleton as gs}from"./RiskSkeleton-cTJ-QM5i.js";import{D as be,a as ve,b as Ne,c as ke,d as we,e as Se}from"./dialog-CPfNxU02.js";import{C as ae}from"./checkbox-Bqgb2OQc.js";import{R as ps,a as Re}from"./radio-group-9ZkakjPl.js";import{E as fs}from"./ExportLoadingOverlay-BrNPx037.js";import{f as oe}from"./format-BpOyM-BW.js";import{F as js}from"./file-spreadsheet-BrSkWtd6.js";import{F as De}from"./file-down-D_w8u_1w.js";import{R as ys}from"./rotate-ccw-DV4MaVjY.js";import{S as bs}from"./scroll-area-C_O6PBee.js";import{F as vs}from"./folder-open-CjRPLT49.js";import{T as Ns}from"./trash-2-DBIc44cF.js";import{P as ks}from"./play-oiRNd7aX.js";import{S as ws}from"./save-D4VDB_Cx.js";import{u as Ss}from"./useEffectiveUserId-Cw4gMied.js";import"./supabase-DRR_Es6B.js";import"./index-CP_LwkyG.js";import"./loader-circle-D8jnIafj.js";import"./en-US-Bfz1jvxT.js";import"./differenceInCalendarDays-CZ0qhtMk.js";import"./getTimezoneOffsetInMilliseconds-B9UnuQsa.js";import"./index-BdQq_4o_.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const Cs=_e("Laptop",[["path",{d:"M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16",key:"tarvll"}]]),Rs=({riskScore:s,riskLevel:n,targetRange:i,isWithinTarget:t})=>{const a=()=>s<=3?"text-[hsl(var(--status-success-fg))]":s<=7?"text-[hsl(var(--status-warn-fg))]":"text-[hsl(var(--status-high-fg))]",d=()=>s<=3?"bg-[hsl(var(--status-success-fg))]":s<=7?"bg-[hsl(var(--status-warn-fg))]":"bg-[hsl(var(--status-high-fg))]";return e.jsx(p,{className:"border-border shadow-card",children:e.jsx(f,{className:"p-8",children:e.jsxs("div",{className:"text-center space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-2",children:[e.jsx("h2",{className:"text-lg font-semibold text-muted-foreground",children:"Portfolio Risk Score"}),e.jsx(O,{children:e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(G,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(K,{className:"max-w-xs",children:e.jsxs("p",{children:["Composite score (1-10) based on volatility (30%), concentration (25%), liquidity (20%), market exposure (15%), and leverage (10%). Your score of ",s.toFixed(1)," indicates ",n.toLowerCase()," risk aligned with your investment objectives."]})})]})})]}),e.jsx("div",{className:`text-7xl font-bold ${a()}`,children:s.toFixed(1)}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Scale: 1-10"})]}),e.jsx("div",{className:"space-y-2",children:e.jsxs(V,{variant:n==="Moderate"?"default":n==="Conservative"?"secondary":"destructive",className:"text-sm px-4 py-1",children:[n," Risk"]})}
7),e.jsxs("div",{className:"max-w-md mx-auto space-y-2",children:[e.jsx("div",{className:"w-full h-3 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full ${d()} transition-all duration-500`,style:{width:`${s/10*100}%`}})}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Conservative"}),e.jsx("span",{children:"Moderate"}),e.jsx("span",{children:"Aggressive"})]})]}),e.jsx("div",{className:"flex items-center justify-center gap-2 pt-4 border-t border-border",children:t?e.jsxs(e.Fragment,{children:[e.jsx(ye,{className:"h-5 w-5 text-[hsl(var(--status-success-fg))]"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Within Target Range"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"h-5 w-5 text-[hsl(var(--status-warn-fg))]"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Outside Target Range"})]})}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Target Range: ",i.min.toFixed(1)," - ",i.max.toFixed(1)]})]})})})},Fs=({volatility:s,maxDrawdown:n,sharpe:i,beta:t,currencyRisk:a})=>e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Key Risk Metrics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Primary risk indicators compared to market benchmarks"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-5 gap-6",children:[e.jsxs(p,{className:"border-border hover:border-primary/50 transition-all",children:[e.jsxs(b,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ls,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"text-xs text-[hsl(var(--status-success-fg))]",children:"â Lower than market"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-muted-foreground",children:"Portfolio Volatility"}),e.jsx(O,{children:e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(G,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx(K,{className:"max-w-xs",children:e.jsxs("p",{children:["Annualized standard deviation of returns. Lower is more stable. Your ",s.toFixed(1),"% is moderate for a balanced portfolio and below market average."]})})]})})]})]}),e.jsxs(f,{children:[e.jsxs("div",{className:"text-3xl font-bold text-primary",children:[s.toFixed(1),"%"]}),e.jsxs(N,{className:"mt-2",children:["vs Market: ",16.8,"%"]}),e.jsxs("div",{className:"mt-2 text-xs text-[hsl(var(--status-success-fg))]",children:[(16.8-s).toFixed(1),"% less volatile"]})]})]}),e.jsxs(p,{className:"border-border hover:border-primary/50 transition-all",children:[e.jsxs(b,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ue,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"text-xs text-[hsl(var(--status-success-fg))]",children:"â Better protection"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-muted-foreground",children:"Maximum Drawdown"}),e.jsx(O,{children:e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(G,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx(K,{className:"max-w-xs",children:e.jsxs("p",{children:["Largest peak-to-trough decline. Your ",n.percent.toFixed(1),"% is better than market's -12.3% during the same period, indicating strong downside protection."]})})]})})]})]}),e.jsxs(f,{children:[e.jsxs("div",{className:"text-3xl font-bold text-primary",children:[n.percent.toFixed(1),"%"]}),e.jsxs(N,{className:"mt-2",children:["vs Market: ",-12.3,"%"]}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:["Period: ",new Date(n.date).toLocaleDateString("en-US",{month:"short",year:"numeric"})]})]})]}),e.jsxs(p,{className:"border-border hover:border-primary/50 transition-all",children:[e.jsxs(b,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ee,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"text-xs text-[hsl(var(--status-success-fg))]",children:"â Strong performance"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-muted-foreground",children:"Sharpe Ratio"}),e.jsx(O,{children:e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(G,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx(K,{className:"max-w-xs",children:e.jsxs("p",{children:["Measures risk-adjusted returns. Higher is better. >1.0 is good, >2.0 is excellent. Your portfolio's ",i.toFixed(2)," indicates strong returns relative to risk taken."]})})]})})]})]}),e.jsxs(f,{children:[e.jsx("div",{className:"text-3xl font-bold text-primary",children:i.toFixed(2)}),e.jsx(N,{className:"mt-2",children:"Risk-adjusted return"}),e.jsx("div",{className:"mt-2 text-xs text-[hsl(var(--status-success-fg))]",children:i>2?"Excellent":i>1?"Good":"Fair"})]})]}),e.jsxs(p,{className:"border-border hover:border-primary/50 transition-all",children:[e.jsxs(b,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(fe,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Lower systematic risk"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-muted-foreground",children:"Portfolio Beta"}),e.jsx(O,{children:e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(G,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx(K,{className:"max-w-xs",children:e.jsxs("p",{children:["Measures volatility vs market. 1.0 = same as market. Your ",t.toFixed(2)," means ",((1-t)*100).toFixed(0),"% less volatile than S&P 500."]})})]})})]})]}),e.jsxs(f,{children:[e.jsx("div",{className:"text-3xl font-bold text-primary",children:t.toFixed(2)}),e.jsx(N,{className:"mt-2",children:"vs Market: 1.0 baseline"}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[((1-t)*100).toFixed(0),"% less volatile than market"]})]})]}),e.jsxs(p,{className:"border-border hover:border-primary/50 transition-all",children:[e.jsxs(b,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Pe,{className:"h-5 w-5 text-primary"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.concentration," concentration"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-muted-foreground",children:"Unhedged FX Exposure"}),e.jsx(O,{children:e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(G,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx(K,{className:"max-w-xs",children:e.jsx("p",{children:"Foreign-currency holdings remaining after recorded hedge coverage."})})]})})]})]}),e.jsxs(f,{children:[e.jsxs("div",{className:"text-3xl font-bold text-primary",children:[a.unhedgedForeignWeight.toFixed(1),"%"]}),e.jsx(N,{className:"mt-2",children:a.largestForeignCurrency?`Largest: ${a.largestForeignCurrency.currency} ${a.largestForeignCurrency.weight.toFixed(1)}%`:"No foreign-currency holdings"}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:["Base currency: ",a.baseCurrency]})]})]})]})]}),Ms=({concentrationMetrics:s})=>{const n=r=>({high:{variant:"destructive",label:"â ï¸ High"},medium:{variant:"default",label:"Medium"},low:{variant:"secondary",label:"Low"}})[r],i=r=>r==="high"?"#ef4444":r==="medium"?"#f59e0b":"#10b981",t=s.topHoldings.filter(r=>r.risk==="high").length,a=["#4F46E5","#EAB308","#3B82F6","#8B5CF6"],d=s.sectorConcentration.map(r=>({name:r.sector,value:r.percentage,risk:r.risk,itemStyle:{color:{type:"linear",x:0,y:0,x2:1,y2:0,colorStops:[{offset:0,color:i(r.risk)},{offset:1,color:i(r.risk)+"dd"}]}}})),x={animation:!0,animationDuration:1e3,grid:{left:"30%",right:"8%",top:"5%",bottom:"5%",containLabel:!0},tooltip:{trigger:"axis",axisPointer:{type:"shadow"},backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12,formatter:function(r){const o=r[0];return` 8 <div style="font-weight: 600; margin-bottom: 6px;">${o.name}</div> 9 <div style="color: #64748b;"> 10 Allocation: <span style="font-weight: 600; color: #1e293b;">${o.value.toFixed(1)}%</span> 11 </div> 12 `}},xAxis:{type:"value",axisLabel:{color:"#64748b",fontSize:11,formatter:"{value}%"}
12,axisLine:{show:!1},axisTick:{show:!1},splitLine:{lineStyle:{color:"#f1f5f9",type:"dashed"}}},yAxis:{type:"category",data:d.map(r=>r.name),axisLabel:{color:"#1e293b",fontSize:12,fontWeight:500},axisLine:{lineStyle:{color:"#e5e7eb"}},axisTick:{show:!1}},series:[{type:"bar",data:d,barWidth:"50%",itemStyle:{borderRadius:[0,8,8,0],shadowColor:"rgba(0, 0, 0, 0.15)",shadowBlur:6,shadowOffsetX:2},emphasis:{itemStyle:{shadowBlur:10,shadowOffsetX:3}}}]},g=s.geographicConcentration.map((r,o)=>({name:r.region,value:r.percentage,itemStyle:{color:a[o%a.length]}})),h={animation:!0,animationDuration:1e3,animationEasing:"elasticOut",tooltip:{trigger:"item",backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12,formatter:function(r){return` 13 <div style="font-weight: 600; margin-bottom: 6px;">${r.name}</div> 14 <div style="color: #64748b;"> 15 Allocation: <span style="font-weight: 600; color: #1e293b;">${r.value.toFixed(1)}%</span> 16 </div> 17 `}},series:[{type:"pie",radius:["45%","75%"],center:["50%","50%"],avoidLabelOverlap:!0,padAngle:3,itemStyle:{borderRadius:10,borderColor:"#fff",borderWidth:3,shadowBlur:15,shadowColor:"rgba(0, 0, 0, 0.15)"},label:{show:!0,position:"outside",fontSize:13,fontWeight:600,color:"#1e293b",formatter:`{b} 18{d}%`,lineHeight:18},labelLine:{show:!0,length:15,length2:10,smooth:.3,lineStyle:{width:2}},emphasis:{scale:!0,scaleSize:10,itemStyle:{shadowBlur:25,shadowColor:"rgba(0, 0, 0, 0.3)"},label:{fontSize:15,fontWeight:"bold"}},data:g}]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Concentration Risk"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Identify over-exposure to individual positions, sectors, or asset classes"})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Top Holdings Concentration"}),e.jsx(N,{children:"Individual positions over 15% of portfolio are considered high risk"}),t>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-2 p-3 bg-[hsl(var(--status-warn-bg))] rounded-lg",children:[e.jsx(Q,{className:"h-4 w-4 text-[hsl(var(--status-warn-fg))]"}),e.jsxs("span",{className:"text-sm text-[hsl(var(--status-warn-fg))]",children:[t," holdings exceed recommended concentration (>15%)"]})]})]}),e.jsx(f,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left",children:[e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground",children:"Asset"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Value"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"% of Portfolio"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Risk"})]})}),e.jsx("tbody",{children:s.topHoldings.map((r,o)=>{const m=n(r.risk);return e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"py-3 text-sm font-medium",children:r.name}),e.jsxs("td",{className:"py-3 text-sm text-right",children:["$",(r.value/1e6).toFixed(1),"M"]}),e.jsxs("td",{className:"py-3 text-sm text-right font-medium",children:[r.percentage.toFixed(1),"%"]}),e.jsx("td",{className:"py-3 text-right",children:e.jsx(V,{variant:m.variant,className:"text-xs",children:m.label})})]},o)})})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Sector Concentration"}),e.jsx(N,{children:"Exposure by sector/asset class"})]}),e.jsx(f,{children:e.jsx(W,{option:x,style:{height:"300px",width:"100%"},opts:{renderer:"svg"}})})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Geographic Concentration"}),e.jsx(N,{children:"Exposure by region"})]}),e.jsxs(f,{children:[e.jsx(W,{option:h,style:{height:"300px",width:"100%"},opts:{renderer:"svg"}}),e.jsx("div",{className:"mt-4 p-3 bg-[hsl(var(--status-warn-bg))] rounded-lg",children:e.jsx("p",{className:"text-sm text-[hsl(var(--status-warn-fg))]",children:"â ï¸ High geographic concentration - Consider increasing international exposure to 25-30%"})})]})]})]})]})},Ts=({liquidityMetrics:s,totalValue:n})=>{const i=[{name:`Immediate 19(0-1 day)`,value:s.immediate,pct:(s.immediate/n*100).toFixed(1),color:"#10b981"},{name:`Short-term 20(1-30 days)`,value:s.shortTerm,pct:(s.shortTerm/n*100).toFixed(1),color:"#3b82f6"},{name:`Medium-term 21(1-3 months)`,value:s.mediumTerm,pct:(s.mediumTerm/n*100).toFixed(1),color:"#f59e0b"},{name:`Illiquid 22(3+ months)`,value:s.illiquid,pct:(s.illiquid/n*100).toFixed(1),color:"#ef4444"}],a=(s.immediate+s.shortTerm)/n*100>10?"adequate":"warning",d=i.map(g=>({name:g.name,value:g.value,pct:g.pct,itemStyle:{color:{type:"linear",x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:g.color},{offset:1,color:g.color+"dd"}]},borderRadius:[8,8,0,0],shadowColor:g.color+"40",shadowBlur:10,shadowOffsetY:4}})),x={animation:!0,animationDuration:1e3,animationEasing:"cubicOut",grid:{left:"3%",right:"3%",bottom:"3%",top:"5%",containLabel:!0},tooltip:{trigger:"axis",axisPointer:{type:"shadow"},backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12,formatter:function(g){const h=g[0],r=i[h.dataIndex];return` 23 <div style="font-weight: 600; margin-bottom: 6px;">${h.name.replace(` 24`," ")}</div> 25 <div style="color: #64748b; margin-top: 4px;"> 26 Value: <span style="font-weight: 600; color: #1e293b;">$${(h.value/1e6).toFixed(1)}M</span> 27 </div> 28 <div style="color: #64748b; margin-top: 2px;"> 29 Allocation: <span style="font-weight: 600; color: #1e293b;">${r.pct}%</span> 30 </div> 31 `}},xAxis:{type:"category",data:d.map(g=>g.name),axisLabel:{color:"#64748b",fontSize:11,interval:0,rotate:0}
31,axisLine:{lineStyle:{color:"#e5e7eb"}},axisTick:{show:!1}},yAxis:{type:"value",axisLabel:{color:"#64748b",fontSize:11,formatter:function(g){return"$"+(g/1e6).toFixed(1)+"M"}},axisLine:{show:!1},axisTick:{show:!1},splitLine:{lineStyle:{color:"#f1f5f9",type:"dashed"}}},series:[{type:"bar",data:d,barWidth:"50%",emphasis:{itemStyle:{shadowBlur:15,shadowOffsetY:6}}}]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Liquidity Profile"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Assess ability to meet obligations and deploy capital quickly"})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Liquidity Breakdown"}),e.jsx(N,{children:"Time to convert holdings to cash"})]}),e.jsx(f,{children:e.jsx(W,{option:x,style:{height:"300px",width:"100%"},opts:{renderer:"svg"}})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Days to Liquidity"}),e.jsx(N,{children:"Weighted average time to convert to cash"})]}),e.jsxs(f,{children:[e.jsxs("div",{className:"text-4xl font-bold text-primary mb-2",children:[Math.round(s.daysToLiquidity)," days"]}),e.jsx(V,{variant:a==="adequate"?"secondary":"default",children:a==="adequate"?"â Adequate liquidity":"â ï¸ Moderate liquidity risk"})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Emergency Liquidity"}),e.jsx(N,{children:"Available immediately for emergencies"})]}),e.jsxs(f,{children:[e.jsxs("div",{className:"text-4xl font-bold text-primary mb-2",children:["$",(s.emergencyLiquidity/1e6).toFixed(1),"M"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Covers ~",(s.emergencyLiquidity/n*12).toFixed(1)," months of estimated expenses"]}),e.jsx(V,{variant:"secondary",className:"mt-2",children:"â Adequate for emergencies"})]})]})]})]})},Ps=({beta:s,totalValue:n})=>{const i=[{risk:"Equity",value:60},{risk:"Interest Rate",value:25},{risk:"Currency",value:15},{risk:"Commodity",value:10},{risk:"Real Estate",value:20}],t=n*.045,a=4.2,d={animation:!0,animationDuration:1e3,tooltip:{trigger:"item",backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12},radar:{indicator:i.map(x=>({name:x.risk,max:100})),shape:"polygon",splitNumber:4,axisName:{color:"#64748b",fontSize:12,fontWeight:500},splitLine:{lineStyle:{color:"#e5e7eb"}},splitArea:{show:!0,areaStyle:{color:["rgba(79, 70, 229, 0.05)","rgba(79, 70, 229, 0.03)"]}},axisLine:{lineStyle:{color:"#d1d5db"}}},series:[{type:"radar",data:[{value:i.map(x=>x.value),name:"Risk Exposure",areaStyle:{color:{type:"radial",x:.5,y:.5,r:.5,colorStops:[{offset:0,color:"rgba(79, 70, 229, 0.4)"},{offset:1,color:"rgba(79, 70, 229, 0.1)"}]}},lineStyle:{color:"#4F46E5",width:3,shadowColor:"rgba(79, 70, 229, 0.3)",shadowBlur:10},itemStyle:{color:"#4F46E5",borderColor:"#fff",borderWidth:2,shadowColor:"rgba(79, 70, 229, 0.4)",shadowBlur:8},symbol:"circle",symbolSize:8,emphasis:{lineStyle:{width:4},itemStyle:{shadowBlur:12,borderWidth:3}}}]}]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Market Exposure & Sensitivity"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"How portfolio responds to market movements"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Asset Class Risk Exposure"}),e.jsx(N,{children:"Risk factors across asset classes"})]}),e.jsx(f,{children:e.jsx(W,{option:d,style:{height:"300px",width:"100%"},opts:{renderer:"svg"}})})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Interest Rate Sensitivity"}),e.jsx(N,{children:"Impact of rate changes on portfolio value"})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Portfolio Duration"}),e.jsxs("p",{className:"text-2xl font-bold text-primary",children:[a.toFixed(1)," years"]})]}),e.jsxs("div",{className:"space-y-2 p-4 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"If rates â 1%:"}),e.jsxs("span",{className:"text-sm font-semibold text-[hsl(var(--status-high-fg))]",children:["-$",(t*a*.01/1e3).toFixed(0),"K"]})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"If rates â 1%:"}),e.jsxs("span",{className:"text-sm font-semibold text-[hsl(var(--status-success-fg))]",children:["+$",(t*a*.01/1e3).toFixed(0),"K"]})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Bond exposure: $",(t/1e6).toFixed(1),"M (",(t/n*100).toFixed(1),"% of portfolio)"]})]})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Currency Exposure"}),e.jsx(N,{children:"Foreign exchange risk across currencies"})]}),e.jsxs(f,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center p-3 bg-muted rounded-lg",children:[e.jsx("span",{className:"font-medium",children:"USD"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["82% ($",(n*.82/1e6).toFixed(1),"M)"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-3 bg-muted rounded-lg",children:[e.jsx("span",{className:"font-medium",children:"EUR"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["12% ($",(n*.12/1e6).toFixed(1),"M)"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-3 bg-muted rounded-lg",children:[e.jsx("span",{className:"font-medium",children:"Other"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["6% ($",(n*.06/1e6).toFixed(1),"M)"]})]})]}),e.jsx("div",{className:"mt-4 p-3 bg-[hsl(var(--status-warn-bg))] rounded-lg",children:e.jsx("p",{className:"text-sm text-[hsl(var(--status-warn-fg))]",children:"ð¡ FX Risk: Moderate - Consider hedging EUR exposure if expecting USD strength"})})]})]})]})},Ds=({totalValue:s,assets:n})=>{const i=n.filter(h=>{var r;return(r=h.category)==null?void 0:r.includes("Public")}).reduce((h,r)=>h+r.value,0)/s*100,t=n.filter(h=>{var r;return(r=h.category)==null?void 0:r.includes("Real Estate")}).reduce((h,r)=>h+r.value,0)/s*100,a=4.5,d=35.4,x=.84,g=[{title:"Market Crash Scenario",icon:ue,description:"S&P 500 drops 20%",impact:ie(s,i,0,0,0,{equity:-20},x),color:"hsl(var(--status-high-fg))",bgColor:"hsl(var(--status-high-bg))",comparison:"Better than market (-20%)",reason:"Lower equity beta (0.84)"},{title:"Interest Rate Spike",icon:fe,description:"Fed raises rates 2%",impact:ie(s,0,a,0,0,{bonds:-9},1),color:"hsl(var(--status-warn-fg))",bgColor:"hsl(var(--status-warn-bg))",comparison:"Low risk level",reason:"Minimal bond exposure"}
31,{title:"Real Estate Downturn",icon:cs,description:"Property values decline 15%",impact:ie(s,0,0,t,0,{realEstate:-15},1),color:"hsl(var(--status-warn-fg))",bgColor:"hsl(var(--status-warn-bg))",comparison:"Moderate risk",reason:"Monitor Lake House value"},{title:"Tech Sector Collapse",icon:Cs,description:"Tech stocks drop 30%",impact:ie(s,d,0,0,0,{equity:-30},x),color:"hsl(var(--status-high-fg))",bgColor:"hsl(var(--status-high-bg))",comparison:"High risk",reason:"35.4% tech concentration"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Stress Testing & Scenario Analysis"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model portfolio performance under adverse conditions"})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:g.map((h,r)=>{const o=h.icon;return e.jsxs(p,{className:"border-border",children:[e.jsxs(b,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(o,{className:"h-6 w-6",style:{color:h.color}}),e.jsx(V,{variant:h.comparison.includes("High")?"destructive":h.comparison.includes("Moderate")?"default":"secondary",children:h.comparison})]}),e.jsx(v,{children:h.title}),e.jsx(N,{children:h.description})]}),e.jsxs(f,{className:"space-y-3",children:[e.jsxs("div",{className:"p-4 rounded-lg",style:{backgroundColor:h.bgColor},children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Expected Portfolio Impact"}),e.jsxs("p",{className:"text-2xl font-bold",style:{color:h.color},children:["$",(h.impact.newValue/1e6).toFixed(1),"M"]}),e.jsxs("p",{className:"text-sm font-medium",style:{color:h.color},children:[h.impact.change>=0?"+":"","$",(h.impact.change/1e6).toFixed(1),"M (",h.impact.changePct>=0?"+":"",h.impact.changePct.toFixed(1),"%)"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Reason:"})," ",h.reason]})]})]},r)})}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Historical Stress Events"}),e.jsx(N,{children:"How your portfolio would have performed in past crises"})]}),e.jsx(f,{children:e.jsx("div",{className:"overflow-x-auto -mx-4 px-4 md:mx-0 md:px-0",children:e.jsxs("table",{className:"w-full min-w-[600px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left",children:[e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground",children:"Event"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground",children:"Date"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Market Impact"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Your Portfolio"})]})}),e.jsx("tbody",{children:[{event:"2008 Financial Crisis",date:"Sep 2008",market:-38,portfolio:-32},{event:"COVID-19 Crash",date:"Mar 2020",market:-34,portfolio:-28},{event:"2022 Bear Market",date:"Jan-Oct 2022",market:-25,portfolio:-19}].map((h,r)=>e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"py-3 text-sm font-medium",children:h.event}),e.jsx("td",{className:"py-3 text-sm text-muted-foreground",children:h.date}),e.jsxs("td",{className:"py-3 text-sm text-right text-[hsl(var(--status-high-fg))]",children:[h.market,"%"]}),e.jsxs("td",{className:"py-3 text-sm text-right",children:[e.jsxs("span",{className:"text-[hsl(var(--status-high-fg))]",children:[h.portfolio,"%"]}),e.jsx("span",{className:"text-xs text-[hsl(var(--status-success-fg))] ml-2",children:"(better)"})]})]},r))})]})})})]})]})},Ls=({var95:s,totalValue:n,assets:i})=>{var g;const t=((g=i.find(h=>{var r;return(r=h.category)==null?void 0:r.includes("Commodities")}))==null?void 0:g.value)||237e3,a=i.filter(h=>{var r;return(r=h.category)==null?void 0:r.includes("Cash")}).reduce((h,r)=>h+r.value,0),d=484e3,x=t+a+d;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Tail Risk Analysis"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Assess portfolio resilience to extreme market events"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{children:"Value at Risk (VaR)"}),e.jsx(O,{children:e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(G,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(K,{className:"max-w-xs",children:e.jsx("p",{children:"The maximum expected loss over a time period at 95% confidence. There's only a 5% chance losses exceed this amount."})})]})})]}),e.jsx(N,{children:"95% Confidence - Maximum expected loss"})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 bg-muted rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"1-Day VaR:"}),e.jsxs("span",{className:"text-sm font-semibold",children:["$",(s.oneDay/1e3).toFixed(0),"K"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["(",(s.oneDay/n*100).toFixed(1),"% of portfolio)"]})]}),e.jsxs("div",{className:"p-4 bg-muted rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"1-Month VaR:"}),e.jsxs("span",{className:"text-sm font-semibold",children:["$",(s.oneMonth/1e3).toFixed(0),"K"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["(",(s.oneMonth/n*100).toFixed(1),"% of portfolio)"]})]}),e.jsxs("div",{className:"p-4 bg-muted rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"1-Year VaR:"}),e.jsxs("span",{className:"text-sm font-semibold",children:["$",(s.oneYear/1e6).toFixed(1),"M"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["(",(s.oneYear/n*100).toFixed(1),"% of portfolio)"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-4",children:"95% confident losses won't exceed these amounts over given periods"})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Tail Risk Protection"}),e.jsx(N,{children:"Current defensive assets and hedges"})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center p-3 bg-muted rounded-lg",children:[e.jsx("span",{className:"text-sm",children:"Gold Holdings:"}),e.jsxs("span",{className:"text-sm font-medium",children:["$",(t/1e3).toFixed(0),"K (",(t/n*100).toFixed(1),"%)"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-3 bg-muted rounded-lg",children:[e.jsx("span",{className:"text-sm",children:"Cash Reserves:"}),e.jsxs("span",{className:"text-sm font-medium",children:["$",(a/1e3).toFixed(0),"K (",(a/n*100).toFixed(1),"%)"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-3 bg-muted rounded-lg",children:[e.jsx("span",{className:"text-sm",children:"Low Beta Stocks:"}),e.jsxs("span",{className:"text-sm font-medium",children:["$",(d/1e3).toFixed(0),"K (",(d/n*100).toFixed(1),"%)"]})]})]}),e.jsxs("div",{className:"p-4 bg-[hsl(var(--status-info-bg))] rounded-lg border-l-4 border-[hsl(var(--status-info-fg))]",children:[e.jsx("p",{className:"text-sm font-medium text-[hsl(var(--status-info-fg))] mb-1",children:"Total Protection"}),e.jsxs("p",{className:"text-2xl font-bold text-[hsl(var(--status-info-fg))]",children:["$",(x/1e6).toFixed(1),"M"]}),e.jsxs("p",{className:"text-xs text-[hsl(var(--status-info-fg))] mt-1",children:[(x/n*100).toFixed(1),"% of portfolio"]})]}),e.jsx(V,{variant:"default",className:"w-full justify-center",children:"ð¡ Moderate black swan protection"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Recommendation: Consider 15-20% in defensive assets"})]})]})]})]})},Vs=({concentrationMetrics:s,liquidityMetrics:n,totalValue:i})=>{var m;const t=((m=s.sectorConcentration.find(l=>l.sector.includes("Public")))==null?void 0:m.percentage)||35.4,a=s.topHoldings[0],d=(n.immediate+n.shortTerm)/i*100,x=s.topHoldings.find(l=>
31l.name.toLowerCase().includes("lake house")||l.name.toLowerCase().includes("lakehouse")),g=s.topHoldings.find(l=>l.name==="Microsoft"||l.name==="MSFT"||l.name.includes("Microsoft")),h=[];x&&x.percentage>15&&h.push({severity:"high",title:"Single Asset Concentration - Lake House",description:`Lake House represents ${x.percentage.toFixed(1)}% of portfolio (threshold: 15%)`,actions:["Consider diversifying into REITs","Or accept concentration with awareness"],dismissable:!0}),g&&g.percentage>15&&h.push({severity:"high",title:"Single Asset Concentration - Microsoft",description:`MSFT represents ${g.percentage.toFixed(1)}% of portfolio (threshold: 15%)`,actions:["Reduce position or add sector diversification","Set stop-loss at 10% below current price"],dismissable:!0}),t>30&&h.push({severity:"high",title:"Technology Sector Over-Concentration",description:`Tech exposure (${t.toFixed(1)}%) exceeds 30% threshold`,actions:["Rotate $640K into defensive sectors (Healthcare, Consumer Staples)","Review MSFT, NVDA, AAPL positions"],dismissable:!1}),h.length===0&&a&&a.percentage>15&&h.push({severity:"high",title:`Single Asset Concentration - ${a.name}`,description:`${a.name} represents ${a.percentage.toFixed(1)}% of your portfolio - above the 15% single asset limit.`,actions:["Consider diversifying","Or accept concentration with awareness"],dismissable:!0}),h.push({severity:"medium",title:"Market Volatility Spike Detected",description:"VIX increased 25% this week. Your portfolio may experience higher-than-normal volatility.",actions:["Review stop-loss orders","Consider temporary hedge"],dismissable:!0});const r=[{item:"Tech Concentration",current:`${t.toFixed(1)}%`,threshold:"<30%",status:"warning",action:"Reduce"},{item:"Single Asset (House)",current:`${a==null?void 0:a.percentage.toFixed(1)}%`,threshold:"<15%",status:"warning",action:"Monitor"},{item:"Liquid Cash",current:`${d.toFixed(1)}%`,threshold:">10%",status:d>=10?"ok":"warning",action:d>=10?"â OK":"Increase"},{item:"Portfolio Beta",current:"0.84",threshold:"0.7-0.9",status:"ok",action:"â OK"}],o=l=>{je.success(`Dismissed: ${l}`)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"AI Risk Monitoring"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Real-time alerts and proactive risk identification"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Active Risk Alerts"}),h.map((l,j)=>e.jsxs(p,{className:`border-2 ${l.severity==="high"?"border-[hsl(var(--status-high-fg))] bg-[hsl(var(--status-high-bg))]":"border-[hsl(var(--status-warn-fg))] bg-[hsl(var(--status-warn-bg))]"}`,children:[e.jsxs(b,{children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.severity==="high"?e.jsx(Q,{className:"h-5 w-5 text-[hsl(var(--status-high-fg))]"}):e.jsx(qe,{className:"h-5 w-5 text-[hsl(var(--status-warn-fg))]"}),e.jsx(v,{className:"text-base",children:l.title})]}),l.dismissable&&e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>o(l.title),children:e.jsx(ze,{className:"h-4 w-4"})})]}),e.jsx(N,{className:l.severity==="high"?"text-[hsl(var(--status-high-fg))]":"text-[hsl(var(--status-warn-fg))]",children:l.description})]}),e.jsxs(f,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm font-medium",children:"Suggested Actions:"}),e.jsx("ul",{className:"space-y-1",children:l.actions.map((k,F)=>e.jsxs("li",{className:"text-sm flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"â¢"}),e.jsx("span",{children:k})]},F))}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(R,{variant:"outline",size:"sm",children:"View Details"}),l.severity==="high"&&e.jsx(R,{size:"sm",children:"Rebalance"})]})]})]},j))]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Risk Watchlist"}),e.jsx(N,{children:"Items being monitored for risk thresholds"})]}),e.jsx(f,{children:e.jsx("div",{className:"overflow-x-auto -mx-4 px-4 md:mx-0 md:px-0",children:e.jsxs("table",{className:"w-full min-w-[600px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left",children:[e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground",children:"Item to Monitor"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Current Status"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Threshold"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Action"})]})}),e.jsx("tbody",{children:r.map((l,j)=>e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"py-3 text-sm font-medium",children:l.item}),e.jsx("td",{className:"py-3 text-sm text-right",children:l.current}),e.jsx("td",{className:"py-3 text-sm text-right text-muted-foreground",children:l.threshold}),e.jsx("td",{className:"py-3 text-right",children:l.status==="ok"?e.jsxs(V,{variant:"secondary",className:"text-xs",children:[e.jsx(ye,{className:"h-3 w-3 mr-1"}),l.action]}):e.jsx(V,{variant:"default",className:"text-xs",children:l.action})})]},j))})]})})})]})]})},$s=({volatility:s,returns:n,sharpe:i,maxDrawdown:t,beta:a})=>{const x={animation:!0,animationDuration:1200,animationEasing:"elasticOut",grid:{left:"12%",right:"8%",bottom:"15%",top:"8%",containLabel:!0},tooltip:{trigger:"item",backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12,formatter:function(o){const m=o.seriesName,l=o.value[0],j=o.value[1];return` 32 <div style="font-weight: 600; margin-bottom: 6px;">${m}</div> 33 <div style="color: #64748b; margin-top: 4px;"> 34 Risk: <span style="font-weight: 600; color: #1e293b;">${l.toFixed(1)}%</span> 35 </div> 36 <div style="color: #64748b; margin-top: 2px;"> 37 Return: <span style="font-weight: 600; color: #1e293b;">${j.toFixed(1)}%</span> 38 </div> 39 `}},xAxis:{type:"value",name:"Risk (Volatility %)",nameLocation:"middle",nameGap:30,nameTextStyle:{fontSize:12,color:"#64748b",fontWeight:500},min:6,max:22,axisLabel:{color:"#64748b",fontSize:11,formatter:"{value}%"}
39,axisLine:{lineStyle:{color:"#e5e7eb"}},splitLine:{lineStyle:{color:"#f1f5f9",type:"dashed"}}},yAxis:{type:"value",name:"Expected Return (%)",nameLocation:"middle",nameGap:40,nameTextStyle:{fontSize:12,color:"#64748b",fontWeight:500},min:4,max:12,axisLabel:{color:"#64748b",fontSize:11,formatter:"{value}%"},axisLine:{lineStyle:{color:"#e5e7eb"}},splitLine:{lineStyle:{color:"#f1f5f9",type:"dashed"}}},series:[{name:"Efficient Frontier",type:"line",data:[{risk:8,return:5},{risk:10,return:6.5},{risk:12,return:7.8},{risk:14,return:8.7},{risk:16,return:9.5},{risk:18,return:10},{risk:20,return:10.2}].map(o=>[o.risk,o.return]),smooth:!0,lineStyle:{color:"#10b981",width:3,shadowColor:"rgba(16, 185, 129, 0.3)",shadowBlur:10},itemStyle:{color:"#10b981",borderColor:"#fff",borderWidth:2},symbol:"circle",symbolSize:8,emphasis:{scale:!0,itemStyle:{shadowBlur:15,shadowColor:"rgba(16, 185, 129, 0.5)"}},markArea:{silent:!0,itemStyle:{color:"rgba(16, 185, 129, 0.08)"},data:[[{coord:[6,4]},{coord:[20,12]}]]}},{name:"Your Portfolio",type:"scatter",data:[[s,n]],symbolSize:20,itemStyle:{color:"#f59e0b",borderColor:"#fff",borderWidth:3,shadowColor:"rgba(245, 158, 11, 0.5)",shadowBlur:15},emphasis:{scale:!0,scaleSize:25,itemStyle:{shadowBlur:20,shadowColor:"rgba(245, 158, 11, 0.7)"}},z:10},{name:"Optimal Target",type:"scatter",data:[[s-2,n+.8]],symbolSize:18,symbol:"diamond",itemStyle:{color:"#3b82f6",borderColor:"#fff",borderWidth:3,shadowColor:"rgba(59, 130, 246, 0.5)",shadowBlur:15},emphasis:{scale:!0,scaleSize:22,itemStyle:{shadowBlur:20,shadowColor:"rgba(59, 130, 246, 0.7)"}},z:10}]},g=[{metric:"Return (YTD)",portfolio:n,target:8,sp500:10.2,maxValue:12},{metric:"Volatility (inverse)",portfolio:25-s,target:11,sp500:25-16.8,maxValue:25},{metric:"Sharpe Ratio",portfolio:i*5,target:5,sp500:5.9,maxValue:10},{metric:"Drawdown Resistance",portfolio:Math.abs(t.percent)<12?8:5,target:7,sp500:6,maxValue:10},{metric:"Beta (balanced)",portfolio:a<=.9?8:5,target:8,sp500:5,maxValue:10}],h={animation:!0,animationDuration:1e3,tooltip:{trigger:"item",backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12},legend:{bottom:0,data:["Your Portfolio","Target","S&P 500"],textStyle:{color:"#64748b",fontSize:12},itemGap:20},radar:{indicator:g.map(o=>({name:o.metric,max:o.maxValue})),shape:"polygon",splitNumber:4,center:["50%","45%"],radius:"60%",axisName:{color:"#64748b",fontSize:11,fontWeight:500},splitLine:{lineStyle:{color:"#e5e7eb"}},splitArea:{show:!0,areaStyle:{color:["rgba(79, 70, 229, 0.05)","rgba(79, 70, 229, 0.02)"]}},axisLine:{lineStyle:{color:"#d1d5db"}}},series:[{type:"radar",data:[{value:g.map(o=>o.portfolio),name:"Your Portfolio",areaStyle:{color:{type:"radial",x:.5,y:.5,r:.5,colorStops:[{offset:0,color:"rgba(245, 158, 11, 0.4)"},{offset:1,color:"rgba(245, 158, 11, 0.1)"}]}},lineStyle:{color:"#f59e0b",width:3,shadowColor:"rgba(245, 158, 11, 0.3)",shadowBlur:10},itemStyle:{color:"#f59e0b",borderColor:"#fff",borderWidth:2,shadowColor:"rgba(245, 158, 11, 0.4)",shadowBlur:8},symbol:"circle",symbolSize:8},{value:g.map(o=>o.target),name:"Target",areaStyle:{color:"rgba(16, 185, 129, 0.15)"},lineStyle:{color:"#10b981",width:2,type:"dashed"},itemStyle:{color:"#10b981",borderColor:"#fff",borderWidth:2},symbol:"circle",symbolSize:6},{value:g.map(o=>o.sp500),name:"S&P 500",areaStyle:{color:"rgba(100, 116, 139, 0.1)"},lineStyle:{color:"#64748b",width:2,type:"dotted"},itemStyle:{color:"#64748b",borderColor:"#fff",borderWidth:2},symbol:"circle",symbolSize:6}]}]},r=[{metric:"Return (YTD)",portfolio:`+${n.toFixed(1)}%`,target:"+8%",sp500:"+10.2%"},{metric:"Volatility",portfolio:`${s.toFixed(1)}%`,target:"12-16%",sp500:"16.8%"},{metric:"Sharpe Ratio",portfolio:i.toFixed(2),target:">1.0",sp500:"1.18"},{metric:"Max Drawdown",portfolio:`${t.percent.toFixed(1)}%`,target:"<-12%",sp500:"-12.3%"},{metric:"Beta",portfolio:a.toFixed(2),target:"0.7-0.9",sp500:"1.0"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Risk-Adjusted Returns"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Evaluate returns relative to risk taken"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Efficient Frontier Position"}),e.jsx(N,{children:"Your portfolio vs optimal risk-return tradeoff"})]}),e.jsxs(f,{children:[e.jsx(W,{option:x,style:{height:"350px",width:"100%"},opts:{renderer:"svg"}}),e.jsx("div",{className:"mt-4 p-3 bg-[hsl(var(--status-info-bg))] rounded-lg",children:e.jsx("p",{className:"text-sm text-[hsl(var(--status-info-fg))]",children:"Your portfolio is positioned well on the efficient frontier. To optimize, move toward â by reducing tech concentration for +0.8% expected return with same risk."})})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Performance Comparison Radar"}),e.jsx(N,{children:"Multi-dimensional risk-return analysis"})]}),e.jsx(f,{children:e.jsx(W,{option:h,style:{height:"350px",width:"100%"},opts:{renderer:"svg"}})})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Detailed Metrics Comparison"}),e.jsx(N,{children:"Performance vs benchmarks"})]}),e.jsxs(f,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left",children:[e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground",children:"Metric"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Your Portfolio"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"Target"}),e.jsx("th",{className:"pb-3 text-sm font-medium text-muted-foreground text-right",children:"S&P 500"})]})}),e.jsx("tbody",{children:r.map((o,m)=>e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"py-3 text-sm font-medium",children:o.metric}),e.jsx("td",{className:"py-3 text-sm text-right font-semibold text-primary",children:o.portfolio}),e.jsx("td",{className:"py-3 text-sm text-right text-muted-foreground",children:o.target}),e.jsx("td",{className:"py-3 text-sm text-right text-muted-foreground",children:o.sp500})]},m))})]})}),e.jsx("div",{className:"mt-4 p-3 bg-[hsl(var(--status-success-bg))] rounded-lg",children:e.jsx("p",{className:"text-sm text-[hsl(var(--status-success-fg))]",children:"â Strong risk-adjusted performance across all metrics"})})]})]})]})},As=({currentRiskScore:s,targetRange:n})=>{const i=s>=n.min&&s<=n.max,t=()=>{je.info("Risk tolerance assessment coming soon!")};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Risk Tolerance Assessment"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your investment risk profile and alignment"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Your Risk Profile"}),e.jsx(N,{children:"Investment profile assessment"})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Risk Tolerance Score"}),e.jsx("p",{className:"text-3xl font-bold text-primary",children:"6/10"}),e.jsx(V,{variant:"default",className:"mt-2",children:"Moderate"})]}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Investment Horizon:"}),e.jsx("span",{className:"font-medium",children:"15-20 years"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Loss Tolerance:"}),e.jsx("span",{className:"font-medium",children:"Up to -15%/year"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Last Updated: Aug 15, 2025"}),e.jsx(R,{variant:"outline",size:"sm",className:"w-full",onClick:t,children:"Retake Assessment"})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Portfolio Alignment"}),e.jsx(N,{children:"Risk tolerance match"})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Current Portfolio Risk"}),e.jsxs("p",{className:"text-3xl font-bold text-primary",children:[s.toFixed(1),"/10"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Target Risk Range"}),e.jsxs("p",{className:"text-lg font-semibold",children:[n.min.toFixed(1)," - ",n.max.toFixed(1)]})]}),i?e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-[hsl(var(--status-success-bg))] rounded-lg",children:[e.jsx(ye,{className:"h-5 w-5 text-[hsl(var(--status-success-fg))]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[hsl(var(--status-success-fg))]",children:"Within Target Range"}),e.jsx("p",{className:"text-xs text-[hsl(var(--status-success-fg))]",children:"Your portfolio aligns with your risk tolerance"})]})]}):e.jsxs("div",{className:"p-3 bg-[hsl(var(--status-warn-bg))] rounded-lg",children:[e.jsx("p",{className:"text-sm font-medium text-[hsl(var(--status-warn-fg))]",children:"Outside Target Range"}),e.jsx("p",{className:"text-xs text-[hsl(var(--status-warn-fg))]",children:"Consider rebalancing to align with risk tolerance"})]})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Risk Capacity"}),e.jsx(N,{children:"Your ability to take risk"})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Liquidity Needs:"}),e.jsx("span",{className:"font-medium",children:"Low"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Time Horizon:"}),e.jsx("span",{className:"font-medium",children:"Long (15-20 yrs)"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Income Stability:"}),e.jsx("span",{className:"font-medium",children:"High"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Financial Cushion:"}),e.jsx("span",{className:"font-medium",children:"Strong"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Risk Capacity Score"}),e.jsx("p",{className:"text-3xl font-bold text-primary",children:"7.5/10"})]}),e.jsxs("div",{className:"p-3 bg-[hsl(var(--status-info-bg))] rounded-lg",children:[e.jsx("p",{className:"text-xs text-[hsl(var(--status-info-fg))]",children:"â Risk capacity > Risk tolerance"}),e.jsx("p",{className:"text-xs text-[hsl(var(--status-info-fg))] mt-1",children:"You can afford more risk than you currently take"})]})]})]})]})]})},_s=({concentrationMetrics:s,liquidityMetrics:n,totalValue:i})=>{const t=s.sectorConcentration.find(m=>m.sector.includes("Public")),a=(t==null?void 0:t.percentage)||35.4,d=(n.immediate+n.shortTerm)/i*100,g=10/100*i-(n.immediate+n.shortTerm),h=[{priority:"high",icon:Q,title:"Reduce Technology Concentration",current:`${a.toFixed(1)}%`,target:"<30%",description:"Your tech exposure exceeds recommended levels",actions:["Trim $640K from tech holdings","Suggested: Reduce MSFT by 20% ($340K)","Suggested: Reduce NVDA by 15% ($195K)","Suggested: Reduce AAPL by 10% ($120K)"],impact:"Reduces sector risk, improves diversification",ctaLabel:"View Rebalancing Plan"},{priority:"medium",icon:ds,title:"Increase Liquid Reserves",current:`${d.toFixed(1)}%`,target:"10%",description:"Boost liquidity for opportunities and emergencie
39s",actions:[`Increase cash by $${(g/1e3).toFixed(0)}K`,"Suggested: Sell $470K of low-performing bonds","Or trim large positions gradually"],impact:"Better liquidity for opportunities and emergencies",ctaLabel:"Review Liquidity Options"},{priority:"low",icon:G,title:"Add International Diversification",current:"18%",target:"25-30%",description:"Reduce US geographic concentration",actions:["Deploy $840K-$1.2M internationally","Suggested: MSCI World ex-US ETF","Or European dividend stocks"],impact:"Reduces US geographic concentration",ctaLabel:"Explore International Options"}],r=["Set stop-loss orders on NVDA at -10% ($1.17M)","Add $50K to gold for tail risk protection","Review and update risk tolerance annually","Schedule quarterly risk review meeting"],o=m=>{je.info(`Opening: ${m}`)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Risk Mitigation Recommendations"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"AI-powered suggestions to optimize your risk profile"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"Priority Actions"}),h.map((m,l)=>{const j=m.icon,k=m.priority==="high"?"bg-[hsl(var(--status-high-bg))]":m.priority==="medium"?"bg-[hsl(var(--status-warn-bg))]":"bg-[hsl(var(--status-success-bg))]",F=m.priority==="high"?"text-[hsl(var(--status-high-fg))]":m.priority==="medium"?"text-[hsl(var(--status-warn-fg))]":"text-[hsl(var(--status-success-fg))]",M=m.priority==="high"?"destructive":m.priority==="medium"?"default":"secondary";return e.jsxs(p,{className:`border-2 ${k}`,children:[e.jsx(b,{children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(j,{className:`h-6 w-6 ${F}`}),e.jsxs("div",{children:[e.jsxs(V,{variant:M,className:"mb-2",children:[m.priority.toUpperCase()," PRIORITY"]}),e.jsxs(v,{children:[l+1,". ",m.title]}),e.jsxs(N,{className:"mt-1",children:["Current: ",m.current," â Target: ",m.target]})]})]})})}),e.jsxs(f,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:m.description}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Action Steps:"}),e.jsx("ul",{className:"space-y-1",children:m.actions.map((T,c)=>e.jsxs("li",{className:"text-sm flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"â¢"}),e.jsx("span",{children:T})]},c))})]}),e.jsx("div",{className:"p-3 bg-muted rounded-lg",children:e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Impact:"})," ",m.impact]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{size:"sm",onClick:()=>o(m.title),children:m.ctaLabel}),e.jsx(R,{variant:"outline",size:"sm",children:"Schedule Meeting"})]})]})]},l)})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Quick Win Opportunities"}),e.jsx(N,{children:"Easy actions you can take today"})]}),e.jsx(f,{children:e.jsx("ul",{className:"space-y-2",children:r.map((m,l)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx("span",{className:"text-primary",children:"â¢"}),e.jsx("span",{children:m})]},l))})})]})]})},Es=s=>s>=.8?"hsl(0, 72%, 51%)":s>=.5?"hsl(15, 80%, 58%)":s>=.2?"hsl(30, 90%, 65%)":s>=-.2?"hsl(0, 0%, 95%)":s>=-.5?"hsl(150, 50%, 75%)":"hsl(150, 60%, 55%)",qs=s=>Math.abs(s)>=.5?"hsl(0, 0%, 100%)":"hsl(0, 0%, 20%)",zs=["stocks","bonds","re","crypto","commod"],Fe=["Stocks","Bonds","RE","Crypto","Commod"],Bs=({correlationMatrix:s,factorExposures:n})=>{const i={animation:!0,animationDuration:1e3,tooltip:{trigger:"item",backgroundColor:"rgba(255,255,255,0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12},radar:{indicator:[{name:"Market",max:1,min:-1},{name:"Size",max:1,min:-1},{name:"Value",max:1,min:-1},{name:"Momentum",max:1,min:-1},{name:"Quality",max:1,min:-1},{name:"Low Vol",max:1,min:-1}],shape:"polygon",splitNumber:4,axisName:{color:"#64748b",fontSize:12,fontWeight:500},splitLine:{lineStyle:{color:"#e5e7eb"}},splitArea:{show:!0,areaStyle:{color:["rgba(34,197,94,0.05)","rgba(34,197,94,0.03)"]}}
39,axisLine:{lineStyle:{color:"#d1d5db"}}},series:[{type:"radar",data:[{value:[n.market,n.size,n.value,n.momentum,n.quality,n.lowVolatility],name:"Factor Exposure",areaStyle:{color:{type:"radial",x:.5,y:.5,r:.5,colorStops:[{offset:0,color:"rgba(34,197,94,0.4)"},{offset:1,color:"rgba(34,197,94,0.1)"}]}},lineStyle:{color:"#22c55e",width:3,shadowColor:"rgba(34,197,94,0.3)",shadowBlur:10},itemStyle:{color:"#22c55e",borderColor:"#fff",borderWidth:2,shadowColor:"rgba(34,197,94,0.4)",shadowBlur:8},symbol:"circle",symbolSize:8}]}]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Correlation & Factor Exposure"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Asset class correlations and portfolio factor sensitivities"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Asset Class Correlation Matrix"}),e.jsx(N,{children:"Pairwise correlation coefficients"})]}),e.jsxs(f,{children:[e.jsx(O,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-2 text-left font-medium text-muted-foreground"}),Fe.map(t=>e.jsx("th",{className:"p-2 text-center font-medium text-muted-foreground text-xs",children:t},t))]})}),e.jsx("tbody",{children:s.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"p-2 font-medium text-xs text-muted-foreground whitespace-nowrap",children:t.asset}),zs.map((a,d)=>{const x=t[a];return e.jsxs(U,{children:[e.jsx(Y,{asChild:!0,children:e.jsx("td",{className:"p-2 text-center text-xs font-semibold cursor-default transition-transform hover:scale-110 rounded",style:{backgroundColor:Es(x),color:qs(x),minWidth:48},children:x.toFixed(2)})}),e.jsx(K,{children:e.jsxs("p",{className:"text-xs",children:[t.asset," vs ",Fe[d],": ",e.jsx("strong",{children:x.toFixed(2)})]})})]},a)})]},t.asset))})]})})}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-4 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-3 h-3 rounded",style:{backgroundColor:"hsl(150, 60%, 55%)"}}),e.jsx("span",{children:"Negative"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-3 h-3 rounded",style:{backgroundColor:"hsl(0, 0%, 95%)"}}),e.jsx("span",{children:"Low"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-3 h-3 rounded",style:{backgroundColor:"hsl(0, 72%, 51%)"}}),e.jsx("span",{children:"High"})]})]})]})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Factor Exposure Analysis"}),e.jsx(N,{children:"Portfolio sensitivity to market factors (-1 to 1)"})]}),e.jsxs(f,{children:[e.jsx(W,{option:i,style:{height:"300px",width:"100%"},opts:{renderer:"svg"}}),e.jsx("div",{className:"grid grid-cols-3 gap-2 mt-4",children:[{label:"Market",value:n.market},{label:"Size",value:n.size},{label:"Value",value:n.value},{label:"Momentum",value:n.momentum},{label:"Quality",value:n.quality},{label:"Low Vol",value:n.lowVolatility}].map(t=>e.jsxs("div",{className:"text-center p-2 bg-muted rounded-lg",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t.label}),e.jsxs("p",{className:`text-sm font-bold ${t.value>=0?"text-[hsl(var(--status-success-fg))]":"text-[hsl(var(--status-high-fg))]"}`,children:[t.value>=0?"+":"",t.value.toFixed(2)]})]},t.label))})]})]})]})]})},re=[{asset:"Stocks",weight:60,riskContribution:72},{asset:"Bonds",weight:15,riskContribution:5},{asset:"Real Estate",weight:10,riskContribution:12},{asset:"Crypto",weight:8,riskContribution:8},{asset:"Commodities",weight:7,riskContribution:3}],Ws=()=>{const s=re.filter(i=>i.riskContribution-i.weight>5),n={animation:!0,animationDuration:800,tooltip:{trigger:"axis",axisPointer:{type:"shadow"},backgroundColor:"rgba(255,255,255,0.95)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:12},legend:{data:["Portfolio Weight %","Risk Contribution %"],bottom:0,textStyle:{color:"#64748b",fontSize:12}},grid:{left:"3%",right:"4%",bottom:"15%",top:"8%",containLabel:!0},xAxis:{type:"category",data:re.map(i=>i.asset),axisLabel:{color:"#64748b",fontSize:11}
39,axisLine:{lineStyle:{color:"#e5e7eb"}}},yAxis:{type:"value",axisLabel:{color:"#64748b",fontSize:11,formatter:"{value}%"},splitLine:{lineStyle:{color:"#f1f5f9"}}},series:[{name:"Portfolio Weight %",type:"bar",data:re.map(i=>i.weight),barGap:"10%",itemStyle:{color:"#4F46E5",borderRadius:[4,4,0,0]}},{name:"Risk Contribution %",type:"bar",data:re.map(i=>i.riskContribution),itemStyle:{color:"#F59E0B",borderRadius:[4,4,0,0]}}]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-primary",children:"Risk Budget & Parity Analysis"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Portfolio weight vs risk contribution by asset class"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs(p,{className:"lg:col-span-2",children:[e.jsxs(b,{children:[e.jsx(v,{children:"Weight vs Risk Contribution"}),e.jsx(N,{children:"Compare allocation weight to marginal risk contribution"})]}),e.jsx(f,{children:e.jsx(W,{option:n,style:{height:"320px",width:"100%"},opts:{renderer:"svg"}})})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Risk Efficiency"}),e.jsx(N,{children:"Risk Contribution / Weight ratio"})]}),e.jsx(f,{className:"space-y-3",children:re.map(i=>{const t=i.riskContribution/i.weight,a=i.riskContribution-i.weight>5;return e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:i.asset}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.weight,"% weight â ",i.riskContribution,"% risk"]})]}),e.jsxs(V,{variant:a?"warn":t<=1?"success":"outline",children:[t.toFixed(2),"x"]})]},i.asset)})})]})]}),s.length>0&&e.jsx(p,{className:"border-[hsl(var(--status-warn-bg))]",children:e.jsx(f,{className:"pt-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Q,{className:"h-5 w-5 text-[hsl(var(--status-warn-fg))] mt-0.5 shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Disproportionate Risk Alert"}),s.map(i=>e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{children:i.asset})," contributes ",i.riskContribution,"% of portfolio risk but only ",i.weight,"% of weight (",(i.riskContribution-i.weight).toFixed(0),"pp overweight in risk)."]},i.asset))]})]})})})]})},Hs=s=>(s==null?void 0:s.trim().toUpperCase())||"Unclassified";function Is(s,n="USD"){const i=s.reduce((l,j)=>l+Number(j.value||0),0),t=new Map,a=new Map;s.forEach(l=>{var S;const j=Number(l.value||0),k=Hs(l.currency),F=k===n?100:Math.min(100,Math.max(0,Number(l.fx_hedge_percentage??0))),M=j*F/100,T=t.get(k)??{currency:k,value:0,weight:0,hedgedValue:0,unhedgedValue:0,hedgePercentage:0,holdings:[]};T.value+=j,T.hedgedValue+=M,T.unhedgedValue+=j-M,T.holdings.push(l),t.set(k,T);const c=((S=l.jurisdiction)==null?void 0:S.trim())||"Unclassified",u=a.get(c)??{jurisdiction:c,value:0,weight:0,currencies:{}};u.value+=j,u.currencies[k]=(u.currencies[k]??0)+j,a.set(c,u)});const d=[...t.values()].map(l=>({...l,weight:i>0?l.value/i*100:0,hedgePercentage:l.value>0?l.hedgedValue/l.value*100:0,holdings:[...l.holdings].sort((j,k)=>k.value-j.value)})).sort((l,j)=>j.value-l.value),x=[...a.values()].map(l=>({...l,weight:i>0?l.value/i*100:0})).sort((l,j)=>j.value-l.value),g=d.filter(l=>l.currency!==n&&l.currency!=="Unclassified"),h=g.reduce((l,j)=>l+j.value,0),r=g.reduce((l,j)=>l+j.unhedgedValue,0),o=g[0]??null,m=(o==null?void 0:o.weight)??0;return{exposures:d,jurisdictions:x,summary:{baseCurrency:n,totalValue:i,foreignValue:h,foreignWeight:i>0?h/i*100:0,unhedgedForeignValue:r,unhedgedForeignWeight:i>0?r/i*100:0,largestForeignCurrency:o,concentration:m>=25?"High":m>=12.5?"Moderate":"Low",missingCurrencyCount:s.filter(l=>!l.currency).length,missingCountryCount:s.filter(l=>!l.country).length,missingJurisdictionCount:s.filter(l=>!l.jurisdiction).length,missingHedgeCount:s.filter(l=>l.currency!==n&&l.fx_hedge_percentage==null).length}}}function Os(s,n,i){return s.filter(t=>t.currency!==n&&t.currency!=="Unclassified").map(t=>({currency:t.currency,unhedgedValue:t.unhedgedValue,impact:t.unhedgedValue*i/100})).sort((t,a)=>Math.abs(a.impact)-Math.abs(t.impact))}function Us(s){const n=new Map;
39s.forEach(a=>{const d=`${a.base_currency}/${a.quote_currency}`;n.set(d,[...n.get(d)??[],a])}),n.forEach(a=>a.sort((d,x)=>d.recorded_at.localeCompare(x.recorded_at)));const i=a=>{var h,r;const d=n.get(a);if(!(d!=null&&d.length))return null;const x=Number((h=d[0])==null?void 0:h.rate),g=Number((r=d[d.length-1])==null?void 0:r.rate);return!x||!g?null:{first:x,last:g}},t=i("EUR/USD");return["EUR","GBP","CHF"].map(a=>{if(!t)return{currency:a,rate:null,change:null};if(a==="EUR")return{currency:a,rate:t.last,change:(t.last/t.first-1)*100};const d=i(`EUR/${a}`);if(!d)return{currency:a,rate:null,change:null};const x=t.first/d.first,g=t.last/d.last;return{currency:a,rate:g,change:(g/x-1)*100}})}const Me=["hsl(var(--primary))","hsl(var(--status-success-fg))","hsl(var(--status-warn-fg))","hsl(var(--status-high-fg))","hsl(var(--muted-foreground))","hsl(var(--secondary-foreground))"],Ys=[-5,-10,-20,10],Ks=({risk:s,rates:n,accounts:i})=>{var T;const{privacyMode:t}=Be(),[a,d]=w.useState(null),[x,g]=w.useState(-10),[h,r]=w.useState("exposure"),o=w.useMemo(()=>({animationDuration:600,tooltip:{trigger:"item",formatter:c=>`${c.name}: ${c.percent.toFixed(1)}%${t?"":` (${I(c.value,s.summary.totalValue,!1)})`}`},legend:{bottom:0,textStyle:{color:"hsl(var(--muted-foreground))",fontSize:11}},series:[{type:"pie",radius:["48%","72%"],center:["50%","43%"],label:{show:!1},data:s.exposures.map((c,u)=>({name:c.currency,value:c.value,itemStyle:{color:Me[u%Me.length]}}))}]}),[t,s]),m=w.useMemo(()=>Us(n),[n]),l=w.useMemo(()=>Os(s.exposures,s.summary.baseCurrency,x),[s,x]),j=l.reduce((c,u)=>c+u.impact,0),k=s.exposures.filter(c=>c.currency!=="Unclassified").slice(0,6).map(c=>c.currency),F=s.exposures.find(c=>c.currency===a)??null,M=s.summary.missingCurrencyCount+s.summary.missingCountryCount+s.summary.missingJurisdictionCount+s.summary.missingHedgeCount;return e.jsxs("section",{className:"space-y-5","aria-labelledby":"currency-risk-heading",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-end md:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"currency-risk-heading",className:"text-2xl font-bold text-primary",children:"Currency & Jurisdiction Risk"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Live holding exposure, hedge coverage, custody location, and FX stress impact"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(V,{variant:s.summary.concentration==="High"?"destructive":s.summary.concentration==="Moderate"?"warn":"success",children:[s.summary.concentration," FX concentration"]}),M>0&&e.jsxs(V,{variant:"outline",children:[e.jsx(Q,{className:"mr-1 h-3 w-3"}),"Data coverage gaps"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 lg:grid-cols-4",children:[e.jsx(X,{label:"Foreign currency",value:`${s.summary.foreignWeight.toFixed(1)}%`,detail:`Outside ${s.summary.baseCurrency}`}),e.jsx(X,{label:"Unhedged exposure",value:`${s.summary.unhedgedForeignWeight.toFixed(1)}%`,detail:I(s.summary.unhedgedForeignValue,s.summary.totalValue,t)}),e.jsx(X,{label:"Largest foreign currency",value:((T=s.summary.largestForeignCurrency)==null?void 0:T.currency)??"None",detail:s.summary.largestForeignCurrency?`${s.summary.largestForeignCurrency.weight.toFixed(1)}% of portfolio`:"No exposure"}),e.jsx(X,{label:"Currencies held",value:String(s.exposures.filter(c=>c.currency!=="Unclassified").length),detail:`${s.jurisdictions.filter(c=>c.jurisdiction!=="Unclassified").length} classified jurisdictions`})]}),e.jsxs(ms,{value:h,onValueChange:r,children:[e.jsxs(xs,{className:"grid h-auto w-full grid-cols-2 md:w-fit md:grid-cols-4",children:[e.jsx(ce,{value:"exposure",children:"Exposure"}),e.jsx(ce,{value:"jurisdiction",children:"Jurisdictions"}),e.jsx(ce,{value:"rates",children:"FX movements"}),e.jsx(ce,{value:"stress",children:"Stress test"})]}),e.jsxs(de,{value:"exposure",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-[0.8fr_1.2fr]",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Currency allocation"}),e.jsx(N,{children:"Holding values in reporting-currency terms"})]}),e.jsx(f,{children:e.jsx(W,{option:o,style:{height:300,width:"100%"},opts:{renderer:"svg"}})})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Exposure and hedge coverage"}),e.jsx(N,{children:"Select a currency to inspect its underlying holdings"})]}),e.jsx(f,{className:"px-0",children:e.jsxs(me,{children:[e.jsx(xe,{children:e.jsxs(H,{
39children:[e.jsx(D,{children:"Currency"}),e.jsx(D,{className:"text-right",children:"Exposure"}),e.jsx(D,{className:"text-right",children:"Weight"}),e.jsx(D,{className:"min-w-36",children:"Hedged"}),e.jsx(D,{className:"text-right",children:"Unhedged"})]})}),e.jsx(he,{children:s.exposures.map(c=>e.jsxs(H,{className:"cursor-pointer",onClick:()=>d(a===c.currency?null:c.currency),"data-state":a===c.currency?"selected":void 0,children:[e.jsx(L,{className:"font-semibold",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[a===c.currency?e.jsx(hs,{className:"h-4 w-4"}):e.jsx(We,{className:"h-4 w-4"}),c.currency]})}),e.jsx(L,{className:"text-right tabular-nums",children:I(c.value,s.summary.totalValue,t)}),e.jsxs(L,{className:"text-right tabular-nums",children:[c.weight.toFixed(1),"%"]}),e.jsx(L,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{value:c.hedgePercentage,className:"h-1.5 w-20"}),e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[c.hedgePercentage.toFixed(0),"%"]})]})}),e.jsx(L,{className:"text-right tabular-nums",children:I(c.unhedgedValue,s.summary.totalValue,t)})]},c.currency))})]})})]})]}),F&&e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsxs(v,{children:[F.currency," underlying holdings"]}),e.jsxs(N,{children:[F.holdings.length," positions reconcile to this exposure"]})]}),e.jsx(f,{className:"px-0",children:e.jsxs(me,{children:[e.jsx(xe,{children:e.jsxs(H,{children:[e.jsx(D,{children:"Holding"}),e.jsx(D,{children:"Country / region"}),e.jsx(D,{children:"Jurisdiction"}),e.jsx(D,{children:"Custodian"}),e.jsx(D,{className:"text-right",children:"Value"}),e.jsx(D,{className:"text-right",children:"Hedged"})]})}),e.jsx(he,{children:F.holdings.map(c=>e.jsxs(H,{children:[e.jsxs(L,{children:[e.jsx("div",{className:"font-medium",children:c.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c.asset_type.split("_").join(" ")})]}),e.jsx(L,{children:c.country||c.region||"Unclassified"}),e.jsx(L,{children:c.jurisdiction||"Unclassified"}),e.jsx(L,{children:c.custodian||"Unclassified"}),e.jsx(L,{className:"text-right tabular-nums",children:I(c.value,s.summary.totalValue,t)}),e.jsx(L,{className:"text-right tabular-nums",children:c.fx_hedge_percentage==null?"Not recorded":`${c.fx_hedge_percentage.toFixed(0)}%`})]},c.id))})]})})]})]}),e.jsxs(de,{value:"jurisdiction",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-[1.2fr_0.8fr]",children:[e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Currency à jurisdiction"}),e.jsx(N,{children:"Legal holding jurisdiction, not inferred from market currency"})]}),e.jsx(f,{className:"px-0",children:e.jsxs(me,{children:[e.jsx(xe,{children:e.jsxs(H,{children:[e.jsx(D,{children:"Jurisdiction"}),k.map(c=>e.jsx(D,{className:"text-right",children:c},c)),e.jsx(D,{className:"text-right",children:"Total"})]})}),e.jsx(he,{children:s.jurisdictions.map(c=>e.jsxs(H,{children:[e.jsx(L,{className:"font-medium",children:c.jurisdiction}),k.map(u=>e.jsx(L,{className:"text-right tabular-nums",children:c.currencies[u]?`${(c.currencies[u]/s.summary.totalValue*100).toFixed(1)}%`:"â"},u)),e.jsxs(L,{className:"text-right font-semibold tabular-nums",children:[c.weight.toFixed(1),"%"]})]},c.jurisdiction))})]})})]}),e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"Custody locations"}),e.jsx(N,{children:"Account balances are shown as a custody overlay and are not added to portfolio exposure"})]}),e.jsxs(f,{className:"space-y-3",children:[i.map(c=>e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b pb-3 last:border-0 last:pb-0",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Ie,{className:"h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:c.institution}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.country," · ",c.name]})]})]}),e.jsx(V,{variant:"outline",children:c.currency})]},c.id)),i.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No linked financial accounts."})]})]})]}),M>0&&e.jsxs("div",{className:"flex gap-3 rounded-md border border-[hsl(var(--status-warn-fg)/0.3)] bg-[hsl(var(--status-warn-bg))] p-4 text-sm",children:[e.jsx(Q,{className:"mt-0.5 h-4 w-4 shrink-0 text-[hsl(var(--status-warn-fg))]"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-[hsl(var(--status-warn-fg))]",children:"Classification coverage requires attention"}),e.jsxs("p",{className:"mt-1 text-muted-foreground",children:["Missing: ",s.summary.missingCurrencyCount," currencies, ",s.summary.missingCountryCount," countries, ",s.summary.missingJurisdictionCount," jurisdictions, and ",s.summary.missingHedgeCount," foreign-position hedge records."]})]})]})]}),e.jsx(de,{value:"rates",className:"mt-4",children:e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"FX movement against USD"}),e.jsx(N,{children:"Available 90-day market history; unavailable pairs are never estimated"})]}),e.jsx(f,{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:s.exposures.filter(c=>c.currency!==s.summary.baseCurrency&&c.currency!=="Unclassified").map(c=>{const u=m.find(S=>S.currency===c.currency);return e.jsxs("div",{className:"rounded-md border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"font-semibold",children:[c.currency,"/USD"]}),(u==null?void 0:u.change)!=null?e.jsxs(V,{variant:u.change>=0?"success":"destructive",children:[u.change>=0?e.jsx(fe,{className:"mr-1 h-3 w-3"}):e.jsx(ue,{className:"mr-1 h-3 w-3"}),u.change>=0?"+":"",u.change.toFixed(2),"%"]}):e.jsx(V,{variant:"outline",children:"History unavailable"})]}),e.jsxs("p",{className:"mt-3 text-sm text-muted-foreground",children:["Exposure ",c.weight.toFixed(1),"% · ",c.holdings.length," holdings"]}),(u==null?void 0:u.rate)!=null&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Latest: ",u.rate.toFixed(4)," USD"]})]},c.currency)})})]})}),e.jsx(de,{value:"stress",className:"mt-4",children:e.jsxs(p,{children:[e.jsxs(b,{children:[e.jsx(v,{children:"FX stress test"}),e.jsx(N,{children:"Applies the shock only to recorded unhedged foreign-currency exposure"})]}),e.jsxs(f,{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-end",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Preset shock"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Ys.map(c=>e.jsxs(R,{type:"button",size:"sm",variant:x===c?"default":"outline",onClick:()=>g(c),children:[c>0?"+":"",c,"%"]},c))})]}
39),e.jsxs("div",{className:"w-full space-y-2 md:ml-auto md:w-40",children:[e.jsx(C,{htmlFor:"custom-fx-shock",children:"Custom shock (%)"}),e.jsx(B,{id:"custom-fx-shock",type:"number",min:-50,max:50,value:x,onChange:c=>g(Math.min(50,Math.max(-50,Number(c.target.value)||0)))})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(X,{label:"Portfolio impact",value:`${j>=0?"+":""}${(j/Math.max(s.summary.totalValue,1)*100).toFixed(2)}%`,detail:I(Math.abs(j),s.summary.totalValue,t)}),e.jsx(X,{label:"Shock applied",value:`${x>0?"+":""}${x}%`,detail:"Across foreign currencies"}),e.jsx(X,{label:"Risk base",value:`${s.summary.unhedgedForeignWeight.toFixed(1)}%`,detail:"Unhedged portfolio weight"})]}),e.jsxs(me,{children:[e.jsx(xe,{children:e.jsxs(H,{children:[e.jsx(D,{children:"Currency"}),e.jsx(D,{className:"text-right",children:"Unhedged exposure"}),e.jsx(D,{className:"text-right",children:"Estimated impact"})]})}),e.jsx(he,{children:l.map(c=>e.jsxs(H,{children:[e.jsx(L,{className:"font-semibold",children:c.currency}),e.jsx(L,{className:"text-right",children:I(c.unhedgedValue,s.summary.totalValue,t)}),e.jsxs(L,{className:`text-right font-semibold ${c.impact<0?"text-destructive":"text-[hsl(var(--status-success-fg))]"}`,children:[c.impact>=0?"+":"",t?`${(c.impact/s.summary.totalValue*100).toFixed(2)}%`:I(c.impact,s.summary.totalValue,!1)]})]},c.currency))})]})]})]})})]})]})},X=({label:s,value:n,detail:i})=>e.jsx(p,{children:e.jsxs(f,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium uppercase text-muted-foreground",children:[e.jsx(Pe,{className:"h-3.5 w-3.5"}),s]}),e.jsx("p",{className:"mt-2 text-2xl font-bold text-foreground",children:n}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i})]})}),$=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(s),E=s=>`${s.toFixed(2)}%`,Gs=async s=>{const{jsPDF:n}=await ge(async()=>{const{jsPDF:m}=await import("./jspdf.es.min-Bh1qgChc.js");return{jsPDF:m}},__vite__mapDeps([0,1,2,3,4,5])),{default:i}=await ge(async()=>{const{default:m}=await import("./jspdf.plugin.autotable-CfO62xhj.js");return{default:m}},[]),{data:t,sections:a,includeBranding:d,includeDisclaimer:x,addWatermark:g,layout:h}=s,r=new n({orientation:h==="landscape"?"l":"p",unit:"mm",format:"a4"});let o=20;if(d&&(r.setFontSize(24),r.setTextColor(16,74,58),r.text("Finthos",20,o),o+=8,r.setFontSize(16),r.setTextColor(0,0,0),r.text("Risk Management Report",20,o),o+=15),r.setFontSize(10),r.setTextColor(100,100,100),r.text(`Generated: ${oe(new Date,"MMM dd, yyyy HH:mm")}`,20,o),o+=15,a.riskScoreSummary&&(r.setFontSize(12),r.setTextColor(0,0,0),r.text("Risk Score Summary",20,o),o+=5,i(r,{startY:o,head:[["Metric","Value"]],body:[["Portfolio Risk Score",`${t.riskScore.toFixed(1)} / 10`],["Risk Level",t.riskLevel],["Portfolio Value",$(t.totalValue)]],theme:"grid",headStyles:{fillColor:[16,74,58]}}),o=r.lastAutoTable.finalY+15),a.keyMetrics&&(o>220&&(r.addPage(),o=20),r.setFontSize(12),r.setTextColor(0,0,0),r.text("Key Risk Metrics",20,o),o+=5,i(r,{startY:o,head:[["Metric","Value"]],body:[["Annualized Volatility",E(t.volatility)],["Sharpe Ratio",t.sharpe.toFixed(2)],["Beta",t.beta.toFixed(2)],["Max Drawdown",E(t.maxDrawdown.percent)],["Max Drawdown Value",$(t.maxDrawdown.value)],["Max Drawdown Date",t.maxDrawdown.date]],theme:"grid",headStyles:{fillColor:[16,74,58]}}),o=r.lastAutoTable.finalY+15),a.concentrationAnalysis&&(o>200&&(r.addPage(),o=20),r.setFontSize(12),r.setTextColor(0,0,0),r.text("Concentration Analysis â Top Holdings",20,o),o+=5,i(r,{startY:o,head:[["Holding","Value","Weight","Risk"]],body:t.concentrationMetrics.topHoldings.map(m=>[m.name,$(m.value),E(m.percentage),m.risk.toUpperCase()]),theme:"grid",headStyles:{fillColor:[16,74,58]},styles:{fontSize:8}}),o=r.lastAutoTable.finalY+10,o>220&&(r.addPage(),o=20),r.text("Sector Concentration",20,o),o+=5,i(r,{startY:o,head:[["Sector","Value","Weight","Risk"]],body:t.concentrationMetrics.sectorConcentration.map(m=>[m.sector,$(m.value),E(m.percentage),m.risk.toUpperCase()]),theme:"grid",headStyles:{fillColor:[16,74,58]},styles:{fontSize:8}}),o=r.lastAutoTable.finalY+15),a.liquidityBreakdown&&(o>200&&(r.addPage(),o=20),r.setFontSize(12),r.setTextColor(0,0,0),r.text("Liquidity Breakdown",20,o),o+=5,i(r,{startY:o,head:[["Tier","Value","Weight"]],body:[["Immediate (T+0)",$(t.liquidityMetrics.immediate),E(t.liquidityMetrics.immediate/t.totalValue*100)],["Short-Term",$(t.liquidityMetrics.shortTerm),E(t.liquidityMetrics.shortTerm/t.totalValue*100)],["Medium-Term",$(t.liquidityMetrics.mediumTerm),E(t.liquidityMetrics.mediumTerm/t.totalValue*100)],["Illiquid",$(t.liquidityMetrics.illiquid),E(t.liquidityMetrics.illiquid/t.totalValue*100)]],theme:"grid",headStyles:{fillColor:[16,74,58]}}),o=r.lastAutoTable.finalY+15),a.varMetrics&&(o>230&&(r.addPage(),o=20),r.setFontSize(12),r.setTextColor(0,0,0),r.text("Value at Risk (95% Confidence)",20,o),o+=5,i(r,{startY:o,head:[["Horizon","VaR"]],body:[["1-Day",$(t.var95.oneDay)],["1-Month",$(t.var95.oneMonth)],["1-Year",$(t.var95.oneYear)]],theme:"grid",headStyles:{fillColor:[16,74,58]}}),o=r.lastAutoTable.finalY+15),a.currencyRisk&&(o>190&&(r.addPage(),o=20),r.setFontSize(12),r.setTextColor(0,0,0),r.text("Currency & Jurisdiction Risk",20,o),o+=5,i(r,{startY:o,head:[["Currency","Exposure","Weight","Hedged","Unhedged"]],body:t.currencyRisk.exposures.map(m=>[m.currency,$(m.value),E(m.weight),E(m.hedgePercentage),$(m.unhedgedValue)]),theme:"grid",headStyles:{fillColor:[16,74,58]},styles:{fontSize:8}}),o=r.lastAutoTable.finalY+10,i(r,{startY:o,head:[["Jurisdiction","Exposure","Weight"]],body:t.currencyRisk.jurisdictions.map(m=>[m.jurisdiction,$(m.value),E(m.weight)]),theme:"grid",headStyles:{fillColor:[16,74,58]},styles:{fontSize:8}}
39),o=r.lastAutoTable.finalY+15),g){const m=r.internal.getNumberOfPages();for(let l=1;l<=m;l++){r.setPage(l),r.setTextColor(220,220,220),r.setFontSize(60);const j=r.internal.pageSize.getWidth(),k=r.internal.pageSize.getHeight();r.text("CONFIDENTIAL",j/2,k/2,{angle:45,align:"center"})}}x&&(r.addPage(),r.setFontSize(10),r.setTextColor(100,100,100),r.text("Disclaimer: This report is for informational purposes only and should not be construed as investment advice. Past performance does not guarantee future results. Risk metrics are estimates based on historical data and assumptions.",20,20,{maxWidth:170})),r.save(`Finthos_Risk_Report_${oe(new Date,"yyyy-MM-dd")}.pdf`)},Js=async(s,n)=>{const i=await ge(()=>import("./xlsx-B6sNpj_1.js"),[]),t=i.utils.book_new();if(n.riskScoreSummary||n.keyMetrics){const a=i.utils.aoa_to_sheet([["Risk Management Report"],["Generated",oe(new Date,"MMM dd, yyyy HH:mm")],[],["Metric","Value"],["Risk Score",s.riskScore],["Risk Level",s.riskLevel],["Portfolio Value",s.totalValue],["Volatility %",s.volatility],["Sharpe Ratio",s.sharpe],["Beta",s.beta],["Max Drawdown %",s.maxDrawdown.percent],["Max Drawdown Value",s.maxDrawdown.value],["Max Drawdown Date",s.maxDrawdown.date]]);i.utils.book_append_sheet(t,a,"Summary")}if(n.concentrationAnalysis){const a=s.concentrationMetrics.topHoldings.map(x=>[x.name,x.value,x.percentage,x.risk]),d=i.utils.aoa_to_sheet([["Holding","Value","Weight %","Risk"],...a]);i.utils.book_append_sheet(t,d,"Concentration")}if(n.liquidityBreakdown){const a=i.utils.aoa_to_sheet([["Tier","Value","Weight %"],["Immediate",s.liquidityMetrics.immediate,s.liquidityMetrics.immediate/s.totalValue*100],["Short-Term",s.liquidityMetrics.shortTerm,s.liquidityMetrics.shortTerm/s.totalValue*100],["Medium-Term",s.liquidityMetrics.mediumTerm,s.liquidityMetrics.mediumTerm/s.totalValue*100],["Illiquid",s.liquidityMetrics.illiquid,s.liquidityMetrics.illiquid/s.totalValue*100]]);i.utils.book_append_sheet(t,a,"Liquidity")}if(n.varMetrics){const a=i.utils.aoa_to_sheet([["Horizon","VaR (95%)"],["1-Day",s.var95.oneDay],["1-Month",s.var95.oneMonth],["1-Year",s.var95.oneYear]]);i.utils.book_append_sheet(t,a,"VaR")}if(n.currencyRisk){const a=i.utils.aoa_to_sheet([["Currency","Exposure","Weight %","Hedged %","Unhedged Exposure","Holdings"],...s.currencyRisk.exposures.map(x=>[x.currency,x.value,x.weight,x.hedgePercentage,x.unhedgedValue,x.holdings.length])]);i.utils.book_append_sheet(t,a,"Currency Risk");const d=i.utils.aoa_to_sheet([["Jurisdiction","Exposure","Weight %"],...s.currencyRisk.jurisdictions.map(x=>[x.jurisdiction,x.value,x.weight])]);i.utils.book_append_sheet(t,d,"Jurisdictions")}i.writeFile(t,`Finthos_Risk_${oe(new Date,"yyyy-MM-dd")}.xlsx`)},Xs=s=>{let n=`Metric,Value 40`;n+=`Risk Score,${s.riskScore} 41`,n+=`Risk Level,${s.riskLevel} 42`,n+=`Portfolio Value,${s.totalValue} 43`,n+=`Volatility %,${s.volatility} 44`,n+=`Sharpe Ratio,${s.sharpe} 45`,n+=`Beta,${s.beta} 46`,n+=`Max Drawdown %,${s.maxDrawdown.percent} 47`,n+=`VaR 1-Day,${s.var95.oneDay} 48`,n+=`VaR 1-Month,${s.var95.oneMonth} 49`,n+=`VaR 1-Year,${s.var95.oneYear} 50`,n+=` 51Currency,Exposure,Weight %,Hedged %,Unhedged Exposure,Holdings 52`,s.currencyRisk.exposures.forEach(a=>{n+=`${a.currency},${a.value},${a.weight},${a.hedgePercentage},${a.unhedgedValue},${a.holdings.length} 53`}),n+=` 54Jurisdiction,Exposure,Weight % 55`,s.currencyRisk.jurisdictions.forEach(a=>{n+=`"${a.jurisdiction}",${a.value},${a.weight} 56`});const i=new Blob([n],{type:"text/csv;charset=utf-8;"}),t=document.createElement("a");t.href=URL.createObjectURL(i),t.download=`Finthos_Risk_${oe(new Date,"yyyy-MM-dd")}.csv`,document.body.appendChild(t),t.click(),document.body.removeChild(t)},Qs=({open:s,onOpenChange:n,exportData:i})=>{const[t,a]=w.useState("pdf"),[d,x]=w.useState({riskScoreSummary:!0,keyMetrics:!0,concentrationAnalysis:!0,liquidityBreakdown:!0,varMetrics:!0,recommendations:!0,currencyRisk:!0}),[g,h]=w.useState(!0),[r,o]=w.useState(!0),[m,l]=w.useState(!1),[j,k]=w.useState("portrait"),[F,M]=w.useState(!1),T=S=>{x(P=>({...P,[S]:!P[S]}))},c=async()=>{M(!0);try{t==="pdf"?await Gs({data:i,sections:d,includeBranding:g,includeDisclaimer:r,addWatermark:m,layout:j}):t==="xlsx"?await Js(i,d):Xs(i),ne({title:"Risk report exported successfully"}),n(!1)}catch(S){ne({title:"Export failed",description:S instanceof Error?S.message:"Unknown error",variant:"destructive"})}finally{M(!1)}},u=[{key:"riskScoreSummary",label:"Risk Score Summary"},{key:"keyMetrics",label:"Key Risk Metrics"},{key:"concentrationAnalysis",label:"Concentration Analysis"},{key:"liquidityBreakdown",label:"Liquidity Breakdown"},{key:"varMetrics",label:"Value at Risk"},{key:"recommendations",label:"Recommendations"},{key:"currencyRisk",label:"Currency & Jurisdiction Risk"}];return e.jsxs(e.Fragment,{children:[e.jsx(fs,{isLoading:F}),e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(ve,{className:"sm:max-w-lg",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:"Export Risk Report"}),e.jsx(we,{children:"Choose format, sections, and options for your risk report."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{children:[e.jsx(C,{className:"text-sm font-medium mb-3 block",children:"Format"}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{value:"pdf",label:"PDF",icon:Oe},{value:"xlsx",label:"Excel",icon:js},{value:"csv",label:"CSV",icon:De}].map(({value:S,label:P,icon:A})=>e.jsxs("button",{onClick:()=>a(S),className:`flex flex-col items-center gap-2 p-3 rounded-lg border-2 transition-colors ${t===S?"border-primary bg-primary/5":"border-border hover:border-muted-foreground
56/30"}`,children:[e.jsx(A,{className:"h-5 w-5"}),e.jsx("span",{className:"text-sm font-medium",children:P})]},S))})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-sm font-medium mb-3 block",children:"Include Sections"}),e.jsx("div",{className:"space-y-3",children:u.map(({key:S,label:P})=>e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(ae,{id:`risk-export-${S}`,checked:d[S],onCheckedChange:()=>T(S)}),e.jsx(C,{htmlFor:`risk-export-${S}`,className:"cursor-pointer",children:P})]},S))})]}),t==="pdf"&&e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsx(C,{className:"text-sm font-medium mb-2 block",children:"PDF Options"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(ae,{id:"risk-branding",checked:g,onCheckedChange:()=>h(!g)}),e.jsx(C,{htmlFor:"risk-branding",className:"cursor-pointer",children:"Include Branding"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(ae,{id:"risk-disclaimer",checked:r,onCheckedChange:()=>o(!r)}),e.jsx(C,{htmlFor:"risk-disclaimer",className:"cursor-pointer",children:"Include Disclaimer"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(ae,{id:"risk-watermark",checked:m,onCheckedChange:()=>l(!m)}),e.jsx(C,{htmlFor:"risk-watermark",className:"cursor-pointer",children:"Confidential Watermark"})]})]}),e.jsxs(ps,{value:j,onValueChange:S=>k(S),className:"flex gap-4 mt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Re,{value:"portrait",id:"risk-portrait"}),e.jsx(C,{htmlFor:"risk-portrait",children:"Portrait"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Re,{value:"landscape",id:"risk-landscape"}),e.jsx(C,{htmlFor:"risk-landscape",children:"Landscape"})]})]})]})]}),e.jsxs(Se,{children:[e.jsx(R,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsx(R,{onClick:c,disabled:F,children:"Export Report"})]})]})})]})},Le={riskScoreHero:!0,keyMetrics:!0,concentrationRisk:!0,liquidityRisk:!0,marketRisk:!0,scenarioAnalysis:!0,tailRisk:!0,aiAlerts:!0,riskAdjustedPerformance:!0,riskProfile:!0,recommendations:!0,correlationAndFactor:!0,riskBudget:!0,currencyGeopolitical:!0},Te={riskScoreHero:"Portfolio Risk Score",keyMetrics:"Key Risk Metrics",concentrationRisk:"Concentration Risk",liquidityRisk:"Liquidity Risk",marketRisk:"Market Risk & Sensitivity",scenarioAnalysis:"Scenario Analysis",tailRisk:"Tail Risk",aiAlerts:"AI Risk Alerts",riskAdjustedPerformance:"Risk-Adjusted Performance",riskProfile:"Risk Profile",recommendations:"Recommendations",correlationAndFactor:"Correlation & Factor Exposure",riskBudget:"Risk Budget & Parity",currencyGeopolitical:"Currency & Geopolitical Risk"},Zs=({open:s,onOpenChange:n,visibleSections:i,onVisibleSectionsChange:t,targetRange:a,onTargetRangeChange:d,riskFreeRate:x,onRiskFreeRateChange:g})=>{const h=o=>{t({...i,[o]:!i[o]})},r=()=>{t({...Le}),d({min:5,max:7}),g(4.5)};return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(ve,{className:"sm:max-w-md max-h-[85vh] overflow-y-auto",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:"Risk Settings"}),e.jsx(we,{children:"Configure risk parameters and dashboard visibility."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(C,{className:"text-sm font-medium",children:"Risk Parameters"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"target-min",className:"text-xs text-muted-foreground",children:"Target Min Score"}),e.jsx(B,{id:"target-min",type:"number",step:"0.1",min:"1",max:"10",value:a.min,onChange:o=>d({...a,min:parseFloat(o.target.value)||1})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"target-max",className:"text-xs text-muted-foreground",children:"Target Max Score"}),e.jsx(B,{id:"target-max",type:"number",step:"0.1",min:"1",max:"10",value:a.max,onChange:o=>d({...a,max:parseFloat(o.target.value)||10})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"risk-free",className:"text-xs text-muted-foreground",children:"Risk-Free Rate (%)"}),e.jsx(B,{id:"risk-free",type:"number",step:"0.1",min:"0",max:"20",value:x,onChange:o=>g(parseFloat(o.target.value)||0)})]})]}),e.jsxs("div",{className:"space-y-3 border-t pt-4",children:[e.jsx(C,{className:"text-sm font-medium",children:"Visible Sections"}),Object.keys(Te).map(o=>e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(ae,{id:`risk-vis-${o}`,checked:i[o],onCheckedChange:()=>h(o)}),e.jsx(C,{htmlFor:`risk-vis-${o}`,className:"cursor-pointer",children:Te[o]})]},o))]})]}),e.jsxs(Se,{className:"flex justify-between sm:justify-between",children:[e.jsxs(R,{variant:"ghost",size:"sm",onClick:r,children:[e.jsx(ys,{className:"h-4 w-4 mr-2"}),"Reset Defaults"]}),e.jsx(R,{onClick:()=>n(!1),children:"Done"})]})]})})};function et(){const s=Ue(),n=pe({queryKey:["saved-stress-scenarios"],queryFn:async()=>{const{data:a,error:d}=await se.from("saved_stress_scenarios").select("*").eq("user_id","621b6da6-e160-4ca6-8e3b-7bc18f51da57").order("updated_at",{ascending:!1});if(d)throw d;return a}}),i=Ce({mutationFn:async a=>{const{data:{user:d}}=await se.auth.getUser();if(!d)throw new Error("Not authenticated");const{error:x}=await se.from("saved_stress_scenarios").insert({user_id:d.id,name:a.name,equity_shock:a.equity_shock,bond_shock:a.bond_shock,real_estate_shock:a.real_estate_shock,commodity_shock:a.commodity_shock,notes:a.notes});if(x)throw x},onSuccess:()=>s.invalidateQueries({queryKey:["saved-stress-scenarios"]})}),t=Ce({mutationFn:async a=>{const{error:d}=await se.from("saved_stress_scenarios").delete().eq("id",a);if(d)throw d},onSuccess:()=>s.invalidateQueries({queryKey:["saved-stress-scenarios"]})});return{scenarios:n.data??[],isLoading:n.isLoading,save:i,remove:t}}const st=[{name:"2008 Financial Crisis",equity:-50,bonds:5,realEstate:-30,commodities:-20},{name:"COVID-19 Crash",equity:-34,bonds:8,realEstate:-15,commodities:-25},{name:"Rising Rates (+300bp)",equity:-15,bonds:-12,realEstate:-20,commodities:5},{name:"Stagflation",equity:-25,bonds:-10,realEstate:-5,commodities:30}],tt=({open:s,onOpenChange:n,totalValue:i,beta:t})=>{const[a,d]=w.useState("Custom Scenario"),[x,g]=w.useState(-20),[h,r]=w.useState(0),[o,m]=w.useState(-10),[l,j]=w.useState(-5),[k,F]=w.useState(null),[M,T]=w.useState(!1),{scenarios:c,save:u,remove:S}=et(),P=55,A=20,z=15,le=10,Z=()=>{const y=ie(i,P,A,z,le,{equity:x,bonds:h,realEstate:o,commodities:l},t);F({name:a,newValue:y.newValue,change:y.change,changePct:y.changePct})},_=y=>{d(y.name),g(y.equity),r(y.bonds),m(y.realEstate),j(y.commodities),F(null)},q=()=>{u.mutate({name:a,equity_shock:x,bond_shock:h,real_estate_shock:o,commodity_shock:l,notes:null},{onSuccess:()=>ne({title:"Scenario saved"}),onError:()=>ne({title:"Failed to save scenario",variant:"destructive"})})},ee=y=>{d(y.name),g(Number(y.equity_shock)),r(Number(y.bond_shock)),m(Number(y.real_estate_shock)),j(Number(y.commodity_shock)),F(null),T(!1)},te=y=>{S.mutate(y,{onSuccess:()=>ne({title:"Scenario deleted"})})},J=y=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(y);return e.jsx(be,{open:s,onOpenChange:n,children:e.jsxs(ve,{className:"sm:max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:"Stress Test Scenario Builder"}),e.jsx(we,{children:"Define market shocks, save scenarios, and calculate portfolio impact."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{variant:M?"outline":"default",size:"sm",onClick:()=>T(!1),children:"Presets"}),e.jsxs(R,{variant:M?"default":"outline",size:"sm",onClick:()=>T(!0),children:[e.jsx(vs,{className:"mr-1.5 h-3.5 w-3.5"}),"Saved (",c.length,")"]})]}),M?e.jsx(bs,{className:"h-[140px] rounded-md border p-2",children:c.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No saved scenarios yet"}):e.jsx("div",{className:"space-y-2",children:c.map(y=>e.jsxs("div",{className:"flex items-center justify-between gap-2 p-2 rounded-md hover:bg-muted/50",children:[e.jsx("button",{className:"flex-1 text-left text-sm font-medium truncate",onClick:()=>ee(y),children:y.name}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>te(y.id),children:e.jsx(Ns,{className:"h-3.5 w-3.5 text-destructive"})})]},y.id))})}):e.jsx("div",{className:"grid grid-cols-2 gap-2",children:st.map(y=>e.jsx(R,{variant:"outline",size:"sm",className:"text-xs justify-start",onClick:()=>_(y),children:y.name},y.name))}),e.jsx(Ye,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"scenario-name",className:"text-xs text-muted-foreground",children:"Scenario Name"}),e.jsx(B,{id:"scenario-name",value:a,onChange:y=>
56d(y.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"equity-shock",className:"text-xs text-muted-foreground",children:"Equity Shock (%)"}),e.jsx(B,{id:"equity-shock",type:"number",value:x,onChange:y=>g(parseFloat(y.target.value)||0)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"bond-shock",className:"text-xs text-muted-foreground",children:"Bond Shock (%)"}),e.jsx(B,{id:"bond-shock",type:"number",value:h,onChange:y=>r(parseFloat(y.target.value)||0)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"re-shock",className:"text-xs text-muted-foreground",children:"Real Estate Shock (%)"}),e.jsx(B,{id:"re-shock",type:"number",value:o,onChange:y=>m(parseFloat(y.target.value)||0)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"comm-shock",className:"text-xs text-muted-foreground",children:"Commodity Shock (%)"}),e.jsx(B,{id:"comm-shock",type:"number",value:l,onChange:y=>j(parseFloat(y.target.value)||0)})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(R,{onClick:Z,className:"flex-1",children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),"Run Stress Test"]}),e.jsxs(R,{variant:"outline",onClick:q,disabled:u.isPending,children:[e.jsx(ws,{className:"mr-2 h-4 w-4"}),"Save"]})]}),k&&e.jsx(p,{className:"border-destructive/30 bg-destructive/5",children:e.jsxs(f,{className:"pt-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-destructive",children:[e.jsx(ue,{className:"h-5 w-5"}),e.jsx("span",{className:"font-semibold",children:k.name})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Current Value"}),e.jsx("p",{className:"font-semibold",children:J(i)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Projected Value"}),e.jsx("p",{className:"font-semibold",children:J(k.newValue)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Impact"}),e.jsxs("p",{className:"font-semibold text-destructive",children:[J(k.change)," (",k.changePct.toFixed(1),"%)"]})]})]})]})})]}),e.jsx(Se,{children:e.jsx(R,{variant:"outline",onClick:()=>n(!1),children:"Close"})})]})})};function rt(){const s=Ss(),n=pe({queryKey:["currency-risk-accounts",s],queryFn:async()=>{const{data:t,error:a}=await se.from("financial_accounts").select("id, name, institution, balance, currency, country").eq("user_id",s).order("balance",{ascending:!1});if(a)throw a;return t??[]},enabled:!!s,staleTime:10*60*1e3}),i=pe({queryKey:["currency-risk-rates",s],queryFn:async()=>{const{data:t,error:a}=await se.from("fx_rates_history").select("base_currency, quote_currency, rate, recorded_at").eq("user_id",s).order("recorded_at",{ascending:!0});if(a)throw a;return t??[]},enabled:!!s,staleTime:15*60*1e3});return{accounts:n.data??[],rates:i.data??[],isLoading:n.isLoading||i.isLoading}}const Kt=()=>{const[s,n]=w.useState(!0),{data:i,isLoading:t}=Xe(),{data:a}=us(),d=rt(),[x,g]=w.useState(!1),[h,r]=w.useState(!1),[o,m]=w.useState(!1),[l,j]=w.useState({...Le}),[k,F]=w.useState({min:5,max:7}),[M,T]=w.useState(4.5),c=w.useMemo(()=>{if(!i)return[];const P=i.reduce((_,q)=>_+q.value,0),A=252,z=[],Z=.142/Math.sqrt(252);for(let _=A;_>=0;_--){const q=new Date;q.setDate(q.getDate()-_);const ee=Math.sin(_/A*Math.PI*4)*.05,te=Math.sin(_/A*Math.PI*8)*Z,J=1+ee+te;z.push({date:q.toISOString().split("T")[0],total_value:P*J})}return z.length>0&&(z[z.length-1].total_value=P),z},[i]),u=w.useMemo(()=>{if(!i||i.length===0)return null;const P=i.reduce(($e,Ae)=>$e+Ae.value,0),A=Qe(c||[]),z=Ze(i),le=es(i),Z=ss(i),_=ts(Z,P),q=.84,ee=is(A,le,_,q),te=as(ee),J=ns(8.9,A,M),y=rs(c||[]),Ve=os(P,A);return{riskScore:ee,riskLevel:te,volatility:A,sharpe:J,beta:q,maxDrawdown:y,var95:Ve,concentrationMetrics:z,liquidityMetrics:Z,totalValue:P}},[i,c,M]),S=w.useMemo(()=>Is((i??[]).map(P=>({...P,region:P.region??null})),"USD"),[i]);return w.useEffect(()=>{t||n(!1)},[t]),s||!u?e.jsx(gs,{}):e.jsxs("div",{className:"h-full flex flex-col overflow-hidden bg-background",children:[e.jsx(Je,{title:"Risk Management",tagline:"Monitor portfolio risk, stress test scenarios, and maintain optimal risk-adjusted returns",icon:Ke,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(R,{variant:"outline",size:"sm",onClick:()=>g(!0),children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"Export Risk Report"]}),e.jsxs(R,{variant:"outline",size:"sm",onClick:()=>r(!0),children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Risk Settings"]}),e.jsx(R,{size:"sm",onClick:()=>m(!0),children:"Run Stress Test"})]})}),e.jsx("div",{className:"flex-1 overflow-auto min-h-0",children:e.jsxs("div",{className:"container mx-auto p-6 space-y-8",children:[l.riskScoreHero&&e.jsx(Rs,{riskScore:u.riskScore,riskLevel:u.riskLevel,targetRange:k,isWithinTarget:u.riskScore>=k.min&&u.riskScore<=k.max}),l.keyMetrics&&e.jsx(Fs,{volatility:u.volatility,maxDrawdown:u.maxDrawdown,sharpe:u.sharpe,beta:u.beta,currencyRisk:S.summary}
56),l.currencyGeopolitical&&e.jsx(Ks,{risk:S,rates:d.rates,accounts:d.accounts}),l.concentrationRisk&&e.jsx(Ms,{concentrationMetrics:u.concentrationMetrics}),l.liquidityRisk&&e.jsx(Ts,{liquidityMetrics:u.liquidityMetrics,totalValue:u.totalValue}),l.marketRisk&&e.jsx(Ps,{beta:u.beta,totalValue:u.totalValue}),l.correlationAndFactor&&a&&e.jsx(Bs,{correlationMatrix:a.correlationMatrix,factorExposures:a.factorExposures}),l.riskBudget&&e.jsx(Ws,{}),l.scenarioAnalysis&&e.jsx(Ds,{totalValue:u.totalValue,assets:i||[]}),l.tailRisk&&e.jsx(Ls,{var95:u.var95,totalValue:u.totalValue,assets:i||[]}),l.aiAlerts&&e.jsx(Vs,{concentrationMetrics:u.concentrationMetrics,liquidityMetrics:u.liquidityMetrics,totalValue:u.totalValue}),l.riskAdjustedPerformance&&e.jsx($s,{volatility:u.volatility,returns:8.9,sharpe:u.sharpe,maxDrawdown:u.maxDrawdown,beta:u.beta}),l.riskProfile&&e.jsx(As,{currentRiskScore:u.riskScore,targetRange:k}),l.recommendations&&e.jsx(_s,{concentrationMetrics:u.concentrationMetrics,liquidityMetrics:u.liquidityMetrics,totalValue:u.totalValue})]})}),e.jsx(Qs,{open:x,onOpenChange:g,exportData:{...u,currencyRisk:S}}),e.jsx(Zs,{open:h,onOpenChange:r,visibleSections:l,onVisibleSectionsChange:j,targetRange:k,onTargetRangeChange:F,riskFreeRate:M,onRiskFreeRateChange:T}),e.jsx(tt,{open:o,onOpenChange:m,totalValue:u.totalValue,beta:u.beta})]})};export{Kt 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.