PageSourceSearch

https://finthos.ai/assets/Portfolio-7NihxiDG.js

js finthos.ai collected 2026-10-05 11:59:23 UTC 52,156 bytes, 7 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PerformanceTab-BA2HB5Qa.js","assets/index-g4WugBH4.js","assets/react-BpdGtorb.js","assets/charts-VqRjxJBw.js","assets/supabase-DRR_Es6B.js","assets/index-CEzzrbFB.css","assets/card-rwt4A55r.js","assets/mockBenchmarkData-kH15l0il.js","assets/useEffectiveUserId-Cw4gMied.js","assets/format-BpOyM-BW.js","assets/en-US-Bfz1jvxT.js","assets/differenceInCalendarDays-CZ0qhtMk.js","assets/getTimezoneOffsetInMilliseconds-B9UnuQsa.js","assets/AllocationTab-BPdXoNpU.js","assets/usePortfolioAssets-1TAWI_Sl.js","assets/triangle-alert-DnKzB0ks.js","assets/RiskAnalysisTab-CrjOeAs1.js","assets/badge-DEgwKkG_.js","assets/usePortfolioRiskMetrics-C1Pouf73.js","assets/riskCalculations-DlUAkL57.js","assets/useCurrency-wPDAOoOM.js","assets/currency-C7WYauQv.js","assets/BenchmarkTab-9gnSSNsT.js"])))=>i.map(i=>d[i]);
2import{d as Ce,a1 as $,j as e,I as R,B as b,s as L,R as v,T as Y,b as Se,a8 as H,a3 as Te,_ as ce,Z as Pe,a9 as Ae,S as de,a as _e,V as ee,aa as De,ab as Le,ac as B}from"./index-g4WugBH4.js";import{r as x,e as me}from"./react-BpdGtorb.js";import{P as V}from"./PremiumPageHeader-DtoR-MWi.js";import{D as xe,a as he,b as ue,c as pe,d as Fe,e as Ie}from"./dialog-CPfNxU02.js";import{L as T}from"./label-BhkyX0L4.js";import{S as te,a as se,b as ae,c as re,d as h}from"./select-C-mPsjVI.js";import{C as g,b as k,c as C,d as P,a as w}from"./card-rwt4A55r.js";import{T as Re,a as Ee,b as ie,c as E,d as Me,e as M}from"./table-ChZYyRts.js";import{B as y}from"./badge-DEgwKkG_.js";import{u as ge}from"./useEffectiveUserId-Cw4gMied.js";import{u as ze}from"./usePortfolioAssets-1TAWI_Sl.js";import{u as Oe}from"./useConsolidatedPortfolio-Db_5BKas.js";import{PortfolioSkeleton as Ue}from"./PortfolioSkeleton-CzhXKpV0.js";import{u as $e}from"./usePortfolioMetrics-Dq8ckhqV.js";import{u as q}from"./useCurrency-wPDAOoOM.js";import{T as G}from"./trending-down-BPYf34mQ.js";import{B as He}from"./briefcase-CcrvOfEr.js";import{R as qe,L as Be,h as Ve,E as J}from"./charts-VqRjxJBw.js";import{A as je}from"./activity-BGWZi07P.js";import{D as We}from"./dollar-sign-DlmilPn4.js";import{T as fe,a as ye,b as _,c as D}from"./tabs-D3rJiyQ0.js";import{A as Ye}from"./arrow-right-HbiHr6XF.js";import{g as Ge}from"./categoryColors-1iGE5PPb.js";import{g as Je}from"./categoryIcons-BmmySs-e.js";import{B as ne}from"./brain-C7FrD4rT.js";import{R as K}from"./refresh-cw-BiIPmSZZ.js";import{T as Q}from"./triangle-alert-DnKzB0ks.js";import{M as Ke}from"./minus-D9bkl0eL.js";import{a as Qe}from"./useAlphaVantage-SsGcIwCs.js";import{C as Ze}from"./calendar-clock-cua5E5ni.js";import{F as Xe}from"./FactorAttributionPanel-DVyuKmU0.js";import{A as be,a as et,b as ve}from"./alert-weJO6L7T.js";import{S as tt}from"./switch-CBLSXIri.js";import{R as st}from"./rotate-ccw-DV4MaVjY.js";import{C as at,a as rt,b as it}from"./collapsible-B5jSS86d.js";import{S as nt}from"./settings-2-DJ9ywY9c.js";import{P as lt}from"./plus-CCLN8KKX.js";import{C as ot}from"./chevron-down-fgIjtWz2.js";import"./supabase-DRR_Es6B.js";import"./index-BdQq_4o_.js";import"./index-CP_LwkyG.js";import"./riskCalculations-DlUAkL57.js";import"./currency-C7WYauQv.js";import"./house-C3OSBbLq.js";import"./server-3-AKBBHj.js";import"./trophy-J2diXcnm.js";import"./heart-CFutvkV3.js";import"./cpu-BdFIzyJC.js";import"./git-branch-Bjq8NZT8.js";import"./index-Bs2sydDB.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 ct=Ce("Layers3",[["path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z",key:"8b97xw"}],["path",{d:"m6.08 9.5-3.5 1.6a1 1 0 0 0 0 1.81l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9a1 1 0 0 0 0-1.83l-3.5-1.59",key:"1e5n1m"}],["path",{d:"m6.08 14.5-3.5 1.6a1 1 0 0 0 0 1.81l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9a1 1 0 0 0 0-1.83l-3.5-1.59",key:"1iwflc"}]]),dt=({open:t,onOpenChange:a,onSuccess:n})=>{const[i,r]=x.useState(!1),{toast:l}=$(),[s,o]=x.useState({name:"",asset_type:"equity",value:"",ticker:"",custodian:"",liquidity:"daily",currency:"USD"}),d=async c=>{c.preventDefault();try{r(!0);const{data:{user:m}}=await L.auth.getUser();if(!m){l({title:"Error",description:"You must be logged in",variant:"destructive"});return}const{error:u}=await L.from("assets").insert([{user_id:m.id,name:s.name,asset_type:s.asset_type,value:parseFloat(s.value),ticker:s.ticker||null,custodian:s.custodian||null,liquidity:s.liquidity,currency:s.currency}]);if(u)throw u;l({title:"Success",description:"Asset added successfully"}),o({name:"",asset_type:"equity",value:"",ticker:"",custodian:"",liquidity:"daily",currency:"USD"}),a(!1),n()}catch(m){console.error("Error adding asset:",m),l({title:"Error",description:"Failed to add asset",variant:"destructive"})}finally{r(!1)}};return e.jsx(xe,{open:t,onOpenChange:a,children:e.jsx(he,{className:"sm:max-w-[500px]",children:e.jsxs("form",{onSubmit:d,children:[e.jsxs(ue,{children:[e.jsx(pe,{children:"Add New Asset"}),e.jsx(Fe,{children:"Add a new asset to your portfolio"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"name",children:"Asset Name *"}),e.jsx(R,{id:"name",value:s.name,onChange:c=>o({...s,name:c.target.value}),required:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"asset_type",children:"Asset Type *"}),e.jsxs(te,{value:s.asset_type,onValueChange:c=>o({...s,asset_type:c}),children:[e.jsx(se,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground",children:"Public Markets"}),e.jsx(h,{value:"equity",children:"Equity"}),e.jsx(h,{value:"etf",children:"ETF"}),e.jsx(h,{value:"bond",children:"Bond"}),e.jsx(h,{value:"fund",children:"Fund"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Commodities"}),e.jsx(h,{value:"commodity_gold",children:"Gold"}),e.jsx(h,{value:"commodity_silver",children:"Silver"}),e.jsx(h,{value:"commodity_oil",children:"Oil"}),e.jsx(h,{value:"commodity_other",children:"Other Commodity"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Alternatives"}),e.jsx(h,{value:"private_equity",children:"Private Equity"}),e.jsx(h,{value:"hedge_fund",children:"Hedge Fund"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Real Estate"}),e.jsx(h,{value:"real_estate",children:"Real Estate"}),e.jsx(h,{value:"luxury_real_estate",children:"Luxury Real Estate"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Infrastru
7cture"}),e.jsx(h,{value:"energy_infrastructure",children:"Energy Infrastructure"}),e.jsx(h,{value:"data_center",children:"Data Center"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Hospitality"}),e.jsx(h,{value:"hotel",children:"Hotel"}),e.jsx(h,{value:"resort",children:"Resort"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Sports & Trophy Assets"}),e.jsx(h,{value:"sports_franchise",children:"Sports Franchise"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Natural Resources"}),e.jsx(h,{value:"mining_project",children:"Mining Project"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Lifestyle & Legacy"}),e.jsx(h,{value:"art",children:"Art"}),e.jsx(h,{value:"wine",children:"Wine"}),e.jsx(h,{value:"jewelry",children:"Jewelry"}),e.jsx(h,{value:"classic_car",children:"Classic Car"}),e.jsx(h,{value:"collectible",children:"Other Collectible"}),e.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground mt-2",children:"Other"}),e.jsx(h,{value:"crypto",children:"Cryptocurrency"}),e.jsx(h,{value:"cash",children:"Cash"}),e.jsx(h,{value:"fx",children:"Foreign Exchange"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"value",children:"Value *"}),e.jsx(R,{id:"value",type:"number",step:"0.01",value:s.value,onChange:c=>o({...s,value:c.target.value}),required:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"ticker",children:"Ticker Symbol"}),e.jsx(R,{id:"ticker",value:s.ticker,onChange:c=>o({...s,ticker:c.target.value})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"custodian",children:"Custodian"}),e.jsx(R,{id:"custodian",value:s.custodian,onChange:c=>o({...s,custodian:c.target.value})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"liquidity",children:"Liquidity"}),e.jsxs(te,{value:s.liquidity,onValueChange:c=>o({...s,liquidity:c}),children:[e.jsx(se,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(h,{value:"daily",children:"Daily"}),e.jsx(h,{value:"periodic",children:"Periodic"}),e.jsx(h,{value:"illiquid",children:"Illiquid"})]})]})]})]}),e.jsxs(Ie,{children:[e.jsx(b,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(b,{type:"submit",disabled:i,children:i?"Adding...":"Add Asset"})]})]})})})},mt=()=>{const[t,a]=x.useState([]),[n,i]=x.useState(!0),[r,l]=x.useState(!1),[s,o]=x.useState(1),d=20,{toast:c}=$(),m=ge();x.useEffect(()=>{m&&u(1)},[m]);const u=async(f,I=!1)=>{try{i(!0);const N=(f-1)*d,Ne=N+d,{data:we,error:Z,count:ke}=await L.from("transactions").select("id, transaction_type, amount, transaction_date, description, currency",{count:"exact"}).eq("user_id",m).order("transaction_date",{ascending:!1}).range(N,Ne-1);if(Z)throw Z;const X=we||[];a(I?[...t,...X]:X),l((ke||0)>f*d),o(f)}catch(N){console.error("Error fetching transactions:",N),c({title:"Error",description:"Failed to load transactions",variant:"destructive"})}finally{i(!1)}},A=()=>{u(s+1,!0)},p=f=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(f),j=f=>new Date(f).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),S=f=>({dividend:"default",fee:"destructive",buy:"secondary",sell:"outline",rebalancing:"secondary"})[f]||"outline";return n?e.jsxs(g,{children:[e.jsxs(k,{children:[e.jsx(C,{children:"Recent Transactions"}),e.jsx(P,{children:"Your latest portfolio transactions"})]}),e.jsx(w,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"h-12 w-full"}),e.jsx(v,{className:"h-12 w-full"}),e.jsx(v,{className:"h-12 w-full"})]})})]}):t.length===0?e.jsxs(g,{children:[e.jsxs(k,{children:[e.jsx(C,{children:"Recent Transactions"}),e.jsx(P,{children:"Your latest portfolio transactions"})]}),e.jsx(w,{children:e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No transactions yet"})})]}):e.jsxs(g,{children:[e.jsxs(k,{children:[e.jsx(C,{children:"Recent Transactions"}),e.jsx(P,{children:"Your latest portfolio transactions"})]}),e.jsxs(w,{children:[e.jsxs(Re,{children:[e.jsx(Ee,{children:e.jsxs(ie,{children:[e.jsx(E,{children:"Date"}),e.jsx(E,{children:"Type"}),e.jsx(E,{children:"Description"}),e.jsx(E,{className:"text-right",children:"Amount"})]})}),e.jsx(Me,{children:t.map(f=>e.jsxs(ie,{children:[e.jsx(M,{children:j(f.transaction_date)}),e.jsx(M,{children:e.jsx(y,{variant:S(f.transaction_type),children:f.transaction_type})}),e.jsx(M,{children:f.description||"-"}),e.jsx(M,{className:"text-right font-mono",children:p(f.amount)})]},f.id))})]}),r&&e.jsx("div",{className:"mt-4 text-center",children:e.jsx(b,{variant:"outline",onClick:A,disabled:n,children:n?"Loading...":"Load More"})})]})]})};
7function xt(){const{data:t,isLoading:a}=$e(),{formatCurrency:n}=q();if(a)return e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-6 mb-8",children:[...Array(6)].map((l,s)=>e.jsx(g,{className:"p-6",children:e.jsx(v,{className:"h-24 w-full"})},s))});if(!t)return null;const r=(l=>l>1.5?{label:"Excellent",variant:"default"}:l>1?{label:"Good",variant:"default"}:{label:"Fair",variant:"secondary"})(t.sharpeRatio);return e.jsx("div",{className:"space-y-6 mb-8",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-6",children:[e.jsxs(g,{className:"p-6 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-grey",children:"Total Portfolio Value"}),e.jsx("p",{className:"text-3xl font-bold text-charcoal mt-1",children:n(t.totalValue)}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs("span",{className:`flex items-center text-sm font-medium ${t.changePercentage30d>=0?"text-[hsl(var(--chart-success))]":"text-[hsl(var(--chart-danger))]"}`,children:[t.changePercentage30d>=0?e.jsx(Y,{className:"w-4 h-4 mr-1"}):e.jsx(G,{className:"w-4 h-4 mr-1"}),t.changePercentage30d>=0?"+":"",t.changePercentage30d.toFixed(1),"%"]}),e.jsx("span",{className:"text-xs text-muted-grey",children:"(30 days)"})]})]}),e.jsx(He,{className:"w-10 h-10 text-deep-emerald opacity-20"})]}),t.last30DaysData.length>0&&e.jsx("div",{className:"h-12 -mx-2",children:e.jsx(qe,{width:"100%",height:"100%",children:e.jsx(Be,{data:t.last30DaysData,children:e.jsx(Ve,{type:"monotone",dataKey:"value",stroke:"hsl(var(--deep-emerald))",strokeWidth:2,dot:!1})})})})]}),e.jsxs(g,{className:"p-6 hover:shadow-lg transition-shadow",children:[e.jsx("p",{className:"text-sm text-muted-grey",children:"YTD Return"}),e.jsxs("p",{className:`text-3xl font-bold mt-1 ${t.ytdReturn>=0?"text-[hsl(var(--chart-success))]":"text-[hsl(var(--chart-danger))]"}`,children:[t.ytdReturn>=0?"+":"",t.ytdReturn.toFixed(1),"%"]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"text-xs text-muted-grey",children:"vs S&P 500: +9.3%"}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-[hsl(var(--chart-success))] text-sm font-medium",children:[t.ytdReturn-9.3>=0?"+":"",(t.ytdReturn-9.3).toFixed(1),"%"]}),e.jsx("span",{className:"text-xs text-muted-grey",children:"outperformance"})]})]}),e.jsx(y,{className:"mt-2 bg-[hsl(var(--chart-success))] text-white",children:"Top 15% Performer"})]}),e.jsxs(g,{className:"p-6 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Se,{className:"w-4 h-4 text-deep-emerald"}),e.jsx("p",{className:"text-sm text-muted-grey",children:"Sharpe Ratio"})]}),e.jsx("p",{className:"text-3xl font-bold text-charcoal mt-1",children:t.sharpeRatio.toFixed(2)}),e.jsx("p",{className:"text-xs text-muted-grey mt-2",children:"Risk-Adjusted Return"}),e.jsx(y,{variant:r.variant,className:"mt-2",children:r.label}),e.jsx("p",{className:"text-xs text-muted-grey mt-1",children:"Industry Avg: 1.24"})]}),e.jsxs(g,{className:"p-6 hover:shadow-lg transition-shadow",children:[e.jsx("p",{className:"text-sm text-muted-grey",children:"Maximum Drawdown"}),e.jsxs("p",{className:"text-3xl font-bold text-charcoal mt-1",children:[t.maxDrawdown.toFixed(1),"%"]}),e.jsx("p",{className:"text-xs text-muted-grey mt-2",children:"12-Month Period"}),e.jsx(y,{className:"mt-2 bg-[hsl(var(--chart-success))] text-white",children:"Low Risk"}),e.jsx("p",{className:"text-xs text-muted-grey mt-1",children:"vs S&P 500: -14.5%"})]}),e.jsxs(g,{className:"p-6 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(je,{className:"w-4 h-4 text-deep-emerald"}),e.jsx("p",{className:"text-sm text-muted-grey",children:"Portfolio Beta"})]}),e.jsx("p",{className:"text-3xl font-bold text-charcoal mt-1",children:t.beta.toFixed(2)}),e.jsx("p",{className:"text-xs text-muted-grey mt-2",children:"Market Sensitivity"}),e.jsx("div",{className:"mt-2 flex items-center",children:e.jsx("div",{className:"flex-1 bg-soft-border rounded-full h-2",children:e.jsx("div",{className:"bg-deep-emerald h-2 rounded-full",style:{width:`${Math.min(t.beta*100,100)}%`}})})}),e.jsx("p",{className:"text-xs text-muted-grey mt-1",children:t.beta<1?"Lower volatility than market":"Higher volatility than market"})]}),e.jsxs(g,{className:"p-6 hover:shadow-lg transition-shadow",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(We,{className:"w-4 h-4 text-deep-emerald"}),e.jsx("p",{className:"text-sm text-muted-grey",children:"Dividend Yield"})]}),e.jsxs("p",{className:"text-3xl font-bold text-charcoal mt-1",children:[t.dividendYield.toFixed(1),"%"]}),e.jsx("p",{className:"text-xs text-muted-grey mt-2",children:"Annual Income"}),e.jsx("p",{className:"text-sm font-semibold text-charcoal mt-2",children:n(t.estimatedAnnualDivi
7dends)}),e.jsx("p",{className:"text-xs text-muted-grey mt-1",children:"Est. annual dividends"})]})]})})}const ht=x.lazy(()=>H(()=>import("./PerformanceTab-BA2HB5Qa.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(t=>({default:t.PerformanceTab}))),ut=x.lazy(()=>H(()=>import("./AllocationTab-BPdXoNpU.js"),__vite__mapDeps([13,1,2,3,4,5,6,14,8,15])).then(t=>({default:t.AllocationTab}))),pt=x.lazy(()=>H(()=>import("./RiskAnalysisTab-CrjOeAs1.js"),__vite__mapDeps([16,1,2,3,4,5,6,17,18,19,8,20,21,15])).then(t=>({default:t.RiskAnalysisTab}))),gt=x.lazy(()=>H(()=>import("./BenchmarkTab-9gnSSNsT.js"),__vite__mapDeps([22,1,2,3,4,5,6])).then(t=>({default:t.BenchmarkTab})));function jt(){const{formatCurrency:t}=q(),a=[{source:"Asset Allocation",percentage:6.2,contribution:50},{source:"Security Selection",percentage:4.8,contribution:38.7},{source:"Timing Effect",percentage:1.7,contribution:13.7},{source:"Currency Effect",percentage:-.3,contribution:-2.4}],n=a.reduce((r,l)=>r+l.percentage,0);return e.jsxs(g,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold text-charcoal",children:"Performance Attribution (YTD)"}),e.jsxs(b,{variant:"ghost",size:"sm",children:["View Details ",e.jsx(Ye,{className:"w-4 h-4 ml-2"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 gap-6",children:[a.map(r=>e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-grey mb-1",children:r.source}),e.jsxs("p",{className:`text-2xl font-bold ${r.percentage>=0?"text-[hsl(var(--chart-success))]":"text-[hsl(var(--chart-danger))]"}`,children:[r.percentage>=0?"+":"",r.percentage.toFixed(1),"%"]}),e.jsx(Te,{value:Math.abs(r.contribution),className:`mt-2 h-2 ${r.percentage<0?"[&>div]:bg-[hsl(var(--chart-danger))]":""}`})]},r.source)),e.jsxs("div",{className:"border-l pl-6",children:[e.jsx("p",{className:"text-xs text-muted-grey mb-1",children:"Total Return"}),e.jsxs("p",{className:"text-3xl font-bold text-[hsl(var(--chart-success))]",children:["+",n.toFixed(1),"%"]}),e.jsxs("p",{className:"text-xs text-muted-grey mt-1",children:[t(1455120)," gain"]})]})]})]})}const z=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(v,{className:"h-24"}),e.jsx(v,{className:"h-24"}),e.jsx(v,{className:"h-24"})]}),e.jsx(v,{className:"h-64"})]});function ft(){const[t,a]=x.useState("performance");return e.jsx("div",{className:"mb-8",children:e.jsxs(fe,{value:t,onValueChange:a,className:"w-full",children:[e.jsxs(ye,{className:"grid w-full grid-cols-5 mb-6",children:[e.jsx(_,{value:"performance",children:"Performance"}),e.jsx(_,{value:"attribution",children:"Attribution"}),e.jsx(_,{value:"risk",children:"Risk Analysis"}),e.jsx(_,{value:"allocation",children:"Allocation"}),e.jsx(_,{value:"comparison",children:"Benchmarks"})]}),e.jsx(D,{value:"performance",children:e.jsx(x.Suspense,{fallback:e.jsx(z,{}),children:e.jsx(ht,{})})}),e.jsx(D,{value:"attribution",children:e.jsx(jt,{})}),e.jsx(D,{value:"risk",children:e.jsx(x.Suspense,{fallback:e.jsx(z,{}),children:e.jsx(pt,{})})}),e.jsx(D,{value:"allocation",children:e.jsx(x.Suspense,{fallback:e.jsx(z,{}),children:e.jsx(ut,{})})}),e.jsx(D,{value:"comparison",children:e.jsx(x.Suspense,{fallback:e.jsx(z,{}),children:e.jsx(gt,{})})})]})})}function yt({assets:t}){const{formatCurrency:a}=q(),n=t.reduce((m,u)=>m+Number(u.value),0),i=t.length,r=new Set(t.map(m=>m.category).filter(Boolean)).size,l=t.reduce((m,u)=>Number(u.value)>Number(m.value)?u:m,t[0]||{name:"N/A",value:0,allocation_percentage:0}),s=t.reduce((m,u)=>(u.performance_percentage||0)>(m.performance_percentage||0)?u:m,t[0]||{name:"N/A",performance_percentage:0}),o=t.reduce((m,u)=>m+Number(u.value||0)/(1+(u.performance_percentage||0)/100),0),d=n-o,c=o>0?d/o*100:0;return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs(g,{className:"p-4",children:[e.jsx("p",{className:"text-sm text-muted-grey mb-1",children:"Total Value"}),e.jsx("p",{className:"text-2xl lg:text-3xl font-bold text-charcoal",children:a(n)}),e.jsxs("div",{className:`text-sm mt-1 flex items-center gap-1 ${d>=0?"text-success-green":"text-error-red"}`,children:[d>=0?e.jsx(Y,{className:"h-3 w-3"}):e.jsx(G,{className:"h-3 w-3"}),e.jsxs("span",{children:[d>=0?"+":"",a(d)," (",c>=0?"+":"",c.toFixed(1),"%) YTD"]})]})]}),e.jsxs(g,{className:"p-4",children:[e.jsx("p",{className:"text-sm text-muted-grey mb-1",children:"Total Positions"}),e.jsx("p",{className:"text-2xl lg:text-3xl font-bold text-charcoal",children:i}),e.jsxs("p",{className:"text-sm text-muted-grey mt-1",children:["Across ",r," ",r===1?"category":"categories"]})]}),e.jsxs(g,{className:"p-4",children:[e.jsx("p",{className:"text-sm text-muted-grey mb-1",children:"Largest Holding"}),e.jsx("p",{className:"text-lg lg:text-xl font-bold text-charcoal truncate",title:l.name,children:l.name}),e.jsxs("p",{className:"text-sm text-muted-grey mt-1",children:[a(Number(l.value))," (",(l.allocation_percentage||0).toFixed(1),"%)"]})]}),e.jsxs(g,{className:"p-4",children:[e.jsx("p",{className:"text-sm text-muted-grey mb-1",children:"Best Performer"}),e.jsx("p",{className:"text-lg lg:text-xl font-bold text-charcoal truncate",title:s.name,children:s.name}),e.jsxs("p",{className:"text-sm text-success-green mt-1",children:["+",(s.performance_percentage||0).toFixed(1),"% YTD"]})]})]})}function bt(){const t=ge(),a=ce();
7return{...Pe({queryKey:["category-insights",t],queryFn:async()=>{const{data:r,error:l}=await L.functions.invoke("generate-category-insights",{body:{}});if(l)throw l;return(r==null?void 0:r.insights)||[]},enabled:!!t,staleTime:10*60*1e3,gcTime:30*60*1e3,refetchOnWindowFocus:!1}),refresh:async()=>{const{data:r,error:l}=await L.functions.invoke("generate-category-insights",{body:{refresh:!0}});if(l)throw l;return a.setQueryData(["category-insights",t],(r==null?void 0:r.insights)||[]),(r==null?void 0:r.insights)||[]}}}const vt=t=>t==="overweight"?"bg-emerald-50 text-emerald-700 border-emerald-200":t==="underweight"?"bg-rose-50 text-rose-700 border-rose-200":"bg-muted text-foreground border-border",Nt=t=>t==="critical"?"bg-red-50 text-red-700 border-red-200":t==="high"?"bg-amber-50 text-amber-700 border-amber-200":t==="medium"?"bg-yellow-50 text-yellow-700 border-yellow-200":"bg-muted text-muted-foreground border-border",wt=t=>t==="positive"?e.jsx(Y,{className:"h-3 w-3 text-emerald-600"}):t==="negative"?e.jsx(G,{className:"h-3 w-3 text-rose-600"}):e.jsx(Ke,{className:"h-3 w-3 text-muted-foreground"});function kt({item:t}){const a=me(),{formatCurrency:n}=q(),{privacyMode:i}=Ae(),r=Ge(t.category),l=Je(t.category,"h-4 w-4"),s=t.insight;return t.error||!s?e.jsxs("div",{className:"rounded-lg border border-border p-4 text-sm text-muted-foreground",children:["Unable to generate intelligence for ",t.category,". ",t.error?`(${t.error})`:""]}):e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center gap-3",style:{borderLeftWidth:3,borderLeftColor:r},children:[e.jsx("div",{className:"h-8 w-8 rounded-md grid place-items-center shrink-0",style:{backgroundColor:`${r}1a`,color:r},children:l}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h4",{className:"font-semibold text-sm",children:t.category}),e.jsxs(y,{variant:"outline",className:"text-[10px] h-5",children:[t.summary.holdings_count," holdings"]}),e.jsxs(y,{variant:"outline",className:"text-[10px] h-5",children:[t.summary.portfolio_weight_pct.toFixed(1),"% of NAV"]}),e.jsxs(y,{variant:"outline",className:`text-[10px] h-5 ${t.summary.weighted_performance_pct>=0?"text-emerald-700 border-emerald-200":"text-rose-700 border-rose-200"}`,children:[t.summary.weighted_performance_pct>=0?"+":"",t.summary.weighted_performance_pct.toFixed(2),"% wtd"]}),!i&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:n(t.summary.category_nav)})]}),e.jsx("p",{className:"text-xs text-foreground mt-1 leading-snug",children:s.headline})]})]}),e.jsxs("div",{className:"p-4 grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(de,{className:"h-3.5 w-3.5 text-deep-emerald"}),e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Performance Drivers"})]}),e.jsx("ul",{className:"space-y-2",children:s.performance_drivers.map((o,d)=>e.jsxs("li",{className:"text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-medium",children:[wt(o.direction),e.jsx("span",{children:o.driver}),e.jsx(y,{variant:"outline",className:"text-[9px] h-4 ml-auto",children:o.magnitude})]}),e.jsx("p",{className:"text-muted-foreground mt-0.5 leading-relaxed",children:o.evidence})]},d))})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Q,{className:"h-3.5 w-3.5 text-amber-600"}),e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Key Risks"})]}),e.jsx("ul",{className:"space-y-2",children:s.key_risks.map((o,d)=>e.jsxs("li",{className:"text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-medium",children:[e.jsx("span",{children:o.risk}),e.jsx(y,{variant:"outline",className:`text-[9px] h-4 ml-auto ${Nt(o.severity)}`,children:o.severity})]}),e.jsxs("p",{className:"text-muted-foreground mt-0.5 leading-relaxed",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Mitigant:"})," ",o.mitigant]})]},d))})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(_e,{className:"h-3.5 w-3.5 text-primary"}),e.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Outlook (",s.outlook.horizon,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(y,{className:`text-[10px] h-5 capitalize border ${vt(s.outlook.stance)}`,variant:"outline",children:s.outlook.stance}),e.jsxs(y,{variant:"outline",className:"text-[10px] h-5 capitalize",children:[s.outlook.conviction," conviction"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:s.outlook.rationale}
7),e.jsx("p",{className:"text-[11px] text-muted-foreground/80 mt-2 italic leading-relaxed",children:s.benchmark_context})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ee,{className:"h-3.5 w-3.5 text-deep-emerald"}),e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Recommended Actions"})]}),e.jsx("ul",{className:"space-y-1.5",children:s.recommended_actions.map((o,d)=>e.jsxs("li",{className:"text-xs flex items-start gap-2",children:[e.jsx(y,{variant:"outline",className:"text-[9px] h-4 capitalize shrink-0",children:o.priority}),e.jsx("span",{className:"text-foreground leading-relaxed",children:o.action})]},d))}),e.jsxs(b,{variant:"link",size:"sm",className:"h-auto p-0 mt-2 text-[11px]",onClick:()=>a(`/app/advisor?context=${encodeURIComponent(t.category)}`),children:["Deep dive in AI Advisor ",e.jsx(ee,{className:"h-3 w-3 ml-0.5"})]})]})]})]})}function Ct(){const{data:t,isLoading:a,error:n,refresh:i,refetch:r}=bt(),{toast:l}=$(),[s,o]=x.useState(!1),[d,c]=x.useState(""),m=t||[],u=m.map(j=>j.category),A=d&&u.includes(d)?d:u[0]||"",p=async()=>{o(!0);try{await i(),l({title:"Intelligence refreshed",description:"Latest AI commentary generated."})}catch(j){const S=(j==null?void 0:j.message)||"Failed to refresh";l({title:S.includes("429")?"Rate limited":S.includes("402")?"Credits required":"Refresh failed",description:S,variant:"destructive"})}finally{o(!1)}};return a?e.jsxs(g,{children:[e.jsx(k,{className:"pb-3",children:e.jsxs(C,{className:"text-base flex items-center gap-2",children:[e.jsx(ne,{className:"h-5 w-5 text-primary"})," Category Intelligence"]})}),e.jsx(w,{className:"space-y-3",children:[0,1,2].map(j=>e.jsx(v,{className:"h-32 w-full"},j))})]}):n?e.jsx(g,{children:e.jsxs(w,{className:"p-6 text-sm text-muted-foreground",children:["Unable to load category intelligence. ",e.jsx(b,{variant:"link",size:"sm",onClick:()=>r(),children:"Retry"})]})}):m.length===0?null:e.jsxs(g,{className:"border-primary/20",children:[e.jsxs(k,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{className:"text-base flex items-center gap-2",children:[e.jsx(ne,{className:"h-5 w-5 text-primary"}),"Category Intelligence",e.jsx(y,{variant:"outline",className:"text-[10px] h-5 ml-1",children:"AI"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:p,disabled:s,className:"text-xs",children:[e.jsx(K,{className:`h-3 w-3 mr-1 ${s?"animate-spin":""}`}),"Refresh"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Performance drivers, risks, and outlook by alternative asset category."})]}),e.jsx(w,{children:e.jsxs(fe,{value:A,onValueChange:c,children:[e.jsx(ye,{className:"flex flex-wrap h-auto justify-start gap-1 bg-muted/40 p-1",children:m.map(j=>e.jsx(_,{value:j.category,className:"text-xs data-[state=active]:bg-background",children:j.category},j.category))}),m.map(j=>e.jsx(D,{value:j.category,className:"mt-4",children:e.jsx(kt,{item:j})},j.category))]})})]})}const St={USD:1,EUR:1.08,GBP:1.27,CHF:1.12,SGD:.745,AED:.272,INR:.012,CNY:.138,JPY:.0066,HKD:.128,CAD:.73,AUD:.66},le={"Information Technology":29.8,Financials:13.5,"Health Care":11.6,"Consumer Discretionary":10.4,"Communication Services":9.2,Industrials:8.4,"Consumer Staples":5.9,Energy:3.4,Utilities:2.4,"Real Estate":2.2,Materials:2,Other:1.2};function F(t,a){const n=St[a]??1;return(t.quantity||0)*(t.current_price||0)*n}function Tt(t){const a={};let n=0;for(const r of t)for(const l of r.holdings){const s=F(l,r.currency),o=l.sector||"Other";a[o]=(a[o]||0)+s,n+=s}if(n<=0)return[];const i=new Set([...Object.keys(a),...Object.keys(le)]);return Array.from(i).map(r=>{const l=a[r]||0,s=l/n*100,o=le[r]??0;return{sector:r,portfolioPct:s,benchmarkPct:o,tilt:s-o,valueUsd:l}}).sort((r,l)=>Math.abs(l.tilt)-Math.abs(r.tilt))}function Pt(t){const a=[];let n=0;for(const r of t)for(const l of r.holdings){const s=F(l,r.currency);s<=0||(n+=s,a.push({ticker:l.ticker,name:l.name,sector:l.sector,weight:0,beta:l.beta??1,contribution:0,valueUsd:s}))}let i=0;for(const r of a)r.weight=n>0?r.valueUsd/n*100:0,r.contribution=r.weight/100*r.beta,i+=r.contribution;return a.sort((r,l)=>Math.abs(l.contribution)-Math.abs(r.contribution)),{rows:a,portfolioBeta:i,totalUsd:n}}const At=[.05,.05,.14,.07,.07,.14,.07,.07,.14,.06,.06,.18];function _t(t){let a=0,n=0,i=0;for(const o of t)for(const d of o.holdings){const c=F(d,o.currency);if(c<=0)continue;i+=c;const m=d.dividend_yield??0;a+=c*(m/100),n+=c*m}const r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];let l=0;return{months:r.map((o,d)=>{const c=a*At[d];return l+=c,{month:o,income:c,cumulative:l}}),annualIncome:a,averageYield:i>
70?n/i:0}}function Dt(t,a=8){const n=[];for(const i of t)for(const r of i.holdings){const l=F(r,i.currency),s=r.dividend_yield??0;l<=0||s<=0||n.push({ticker:r.ticker,name:r.name,yield:s,annualIncome:l*(s/100)})}return n.sort((i,r)=>r.annualIncome-i.annualIncome).slice(0,a)}function oe(t){const a=new Date(t),n=(a.getUTCDay()+6)%7;return a.setUTCDate(a.getUTCDate()-n),a.setUTCHours(0,0,0,0),a}function Lt(t,a,n=8){let i=0;const r={};for(const d of a)for(const c of d.holdings){const m=F(c,d.currency);i+=m;const u=(c.ticker||"").toUpperCase();r[u]=(r[u]||0)+m}const l=d=>{const c=d.toUpperCase();return i>0?(r[c]||0)/i*100:0},s=oe(new Date),o={};for(let d=0;d<n;d++){const c=new Date(s);c.setUTCDate(c.getUTCDate()+d*7);const m=c.toISOString().slice(0,10);o[m]={weekStart:m,weekLabel:c.toLocaleDateString("en-US",{month:"short",day:"numeric"}),rows:[]}}for(const d of t){const c=new Date(d.report_date);if(isNaN(c.getTime()))continue;const m=oe(c).toISOString().slice(0,10);if(!o[m])continue;const u=l(d.symbol);o[m].rows.push({symbol:d.symbol,name:d.name??null,reportDate:d.report_date,inPortfolio:u>0,weight:u,estimate:d.estimate})}for(const d of Object.values(o))d.rows.sort((c,m)=>c.inPortfolio!==m.inPortfolio?c.inPortfolio?-1:1:(m.weight||0)-(c.weight||0));return Object.values(o).sort((d,c)=>d.weekStart.localeCompare(c.weekStart))}const Ft=({accounts:t})=>{const a=x.useMemo(()=>Tt(t).slice(0,12),[t]),n=x.useMemo(()=>({tooltip:{trigger:"axis",axisPointer:{type:"shadow"},valueFormatter:i=>`${i>=0?"+":""}${i.toFixed(2)} pp`},grid:{left:140,right:30,top:10,bottom:30},xAxis:{type:"value",axisLabel:{formatter:i=>`${i>=0?"+":""}${i}`,fontSize:10},splitLine:{lineStyle:{type:"dashed",opacity:.3}}},yAxis:{type:"category",data:a.map(i=>i.sector),axisLabel:{fontSize:11},inverse:!0},series:[{type:"bar",data:a.map(i=>({value:Number(i.tilt.toFixed(2)),itemStyle:{color:i.tilt>=0?"hsl(var(--primary))":"hsl(0 72% 51%)"}})),barWidth:14,label:{show:!0,position:"right",formatter:i=>`${i.value>=0?"+":""}${i.value}pp`,fontSize:10}}]}),[a]);return e.jsxs(g,{children:[e.jsxs(k,{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(ct,{className:"h-5 w-5 text-primary"}),"Sector Tilts vs S&P 500"]}),e.jsx(P,{children:"Over- and under-weights relative to S&P 500 GICS sector weights."})]}),e.jsx(w,{children:a.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-10 text-center",children:"No sector data available."}):e.jsxs(e.Fragment,{children:[e.jsx(J,{option:n,style:{height:360}}),e.jsx("div",{className:"overflow-x-auto mt-2",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left py-2",children:"Sector"}),e.jsx("th",{className:"text-right py-2",children:"Portfolio"}),e.jsx("th",{className:"text-right py-2",children:"Benchmark"}),e.jsx("th",{className:"text-right py-2",children:"Tilt"})]})}),e.jsx("tbody",{children:a.map(i=>e.jsxs("tr",{className:"border-b border-border/40",children:[e.jsx("td",{className:"py-1.5 font-medium",children:i.sector}),e.jsxs("td",{className:"py-1.5 text-right tabular-nums",children:[i.portfolioPct.toFixed(1),"%"]}),e.jsxs("td",{className:"py-1.5 text-right tabular-nums text-muted-foreground",children:[i.benchmarkPct.toFixed(1),"%"]}),e.jsxs("td",{className:`py-1.5 text-right tabular-nums font-medium ${i.tilt>=0?"text-emerald-600":"text-rose-600"}`,children:[i.tilt>=0?"+":"",i.tilt.toFixed(2)," pp"]})]},i.sector))})]})})]})})]})},It=({accounts:t})=>{const{rows:a,portfolioBeta:n}=x.useMemo(()=>Pt(t),[t]),i=a.slice(0,10),r=x.useMemo(()=>({tooltip:{trigger:"axis",axisPointer:{type:"shadow"},valueFormatter:s=>s.toFixed(3)},grid:{left:80,right:30,top:10,bottom:30},xAxis:{type:"value",axisLabel:{fontSize:10}},yAxis:{type:"category",data:i.map(s=>s.ticker),axisLabel:{fontSize:11},inverse:!0},series:[{type:"bar",data:i.map(s=>({value:Number(s.contribution.toFixed(3)),itemStyle:{color:s.contribution>=0?"hsl(var(--primary))":"hsl(0 72% 51%)"}})),barWidth:14,label:{show:!0,position:"right",fontSize:10,formatter:s=>s.value.toFixed(3)}}]}),[i]),l=n>1.1?{label:"Aggressive",cls:"bg-rose-500/10 text-rose-600 border-rose-500/30"}:n<.9?{label:"Defensive",cls:"bg-emerald-500/10 text-emerald-600 border-emerald-500/30"}:{label:"Market-neutral",cls:"bg-amber-500/10 text-amber-700 border-amber-500/30"};return e.jsxs(g,{children:[e.jsx(k,{children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(je,{className:"h-5 w-5 text-primary"}),"Beta Contribution"]}),e.jsx(P,{children:"Top contributors to portfolio market beta."})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Portfolio β"}),e.jsx("div",{className:"text-2xl font-semibold tabular-nums",children:n.toFixed(2)}),e.jsx(y,{variant:"outline",className:`text-[10px] ${l.cls}`,children:l.label})]})]})}),e.jsx(w,{children:i.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-10 text-center",children:"No listed-equity holdings."}):e.jsxs(e.Fragment,{children:[e.jsx(J,{option:r,style:{height:320}}),e.jsx("div",{className:"overflow-x-auto mt-2",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left py-2",children:"Ticker"}),e.jsx("th",{className:"text-left py-2",children:"Name"}),e.jsx("th",{className:"text-right py-2",children:"Weight"}),e.jsx("th",{className:"text-right py-2",children:"β"}),e.jsx("th",{className:"text-right py-2",children:"Contribution"})]})}),e.jsx("tbody",{children:i.map(s=>e.jsxs("tr",{className:"border-b border-border/40",children:[e.jsx("td",{className:"py-1.5 font-mono text-xs",children:s.ticker}),e.jsx("td",{className:"py-1.5 truncate max-w-[180px]",children:s.name}),e.jsxs("td",{className:"py-1.5 text-right tabular-nums",children:[s.weight.toFixed(2),"%"]}),e.jsx("td",{className:"py-1.5 text-right tabular-nums",children:s.beta.toFixed(2)}),e.jsx("td",{className:"py-1.5 text-right tabular-nums font-medium",children:s.contribution.toFixed(3)})]},s.ticker))})]})})]})})]})},W=t=>
7t.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}),Rt=({accounts:t})=>{const{months:a,annualIncome:n,averageYield:i}=x.useMemo(()=>_t(t),[t]),r=x.useMemo(()=>Dt(t),[t]),l=x.useMemo(()=>({tooltip:{trigger:"axis",axisPointer:{type:"shadow"},valueFormatter:s=>W(s)},legend:{data:["Monthly","Cumulative"],textStyle:{fontSize:10},bottom:0},grid:{left:60,right:60,top:10,bottom:40},xAxis:{type:"category",data:a.map(s=>s.month),axisLabel:{fontSize:10}},yAxis:[{type:"value",name:"Monthly",axisLabel:{fontSize:10,formatter:s=>`$${Math.round(s/1e3)}k`},splitLine:{lineStyle:{type:"dashed",opacity:.3}}},{type:"value",name:"Cumulative",axisLabel:{fontSize:10,formatter:s=>`$${Math.round(s/1e3)}k`},splitLine:{show:!1}}],series:[{name:"Monthly",type:"bar",data:a.map(s=>Math.round(s.income)),itemStyle:{color:"hsl(var(--primary))"},barWidth:18},{name:"Cumulative",type:"line",yAxisIndex:1,smooth:!0,symbol:"circle",data:a.map(s=>Math.round(s.cumulative)),lineStyle:{color:"hsl(var(--accent-foreground))",width:2},itemStyle:{color:"hsl(var(--accent-foreground))"}}]}),[a]);return e.jsxs(g,{children:[e.jsx(k,{children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(De,{className:"h-5 w-5 text-primary"}),"Forward Dividend Projection"]}),e.jsx(P,{children:"Estimated next-12-month income, based on current yields and seasonality."})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Annual income"}),e.jsx("div",{className:"text-2xl font-semibold tabular-nums",children:W(n)}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["avg yield ",i.toFixed(2),"%"]})]})]})}),e.jsx(w,{children:n<=0?e.jsx("p",{className:"text-sm text-muted-foreground py-10 text-center",children:"No dividend-paying holdings detected."}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsx(J,{option:l,style:{height:320}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2",children:"Top payers"}),e.jsxs("div",{className:"space-y-2",children:[r.map(s=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-xs",children:s.ticker}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:s.name})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"tabular-nums font-medium",children:W(s.annualIncome)}),e.jsxs("div",{className:"text-[11px] text-muted-foreground tabular-nums",children:[s.yield.toFixed(2),"%"]})]})]},s.ticker)),r.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No payers identified."})]})]})]})})]})},Et=({accounts:t})=>{const{data:a,isLoading:n}=Qe("3month"),i=x.useMemo(()=>a?Lt(a,t,8):[],[a,t]),r=x.useMemo(()=>Math.max(1,...i.map(s=>s.rows.length)),[i]),l=x.useMemo(()=>i.flatMap(s=>s.rows.filter(o=>o.inPortfolio).map(o=>({...o,weekLabel:s.weekLabel}))),[i]);return e.jsxs(g,{children:[e.jsx(k,{children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(Ze,{className:"h-5 w-5 text-primary"}),"Earnings Heatmap — Next 8 Weeks"]}),e.jsx(P,{children:"Reporting density by week, with your holdings highlighted."})]}),e.jsxs(y,{variant:"outline",className:"text-[10px]",children:[l.length," portfolio events"]})]})}),e.jsx(w,{children:n?e.jsx(v,{className:"h-40"}):i.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-10 text-center",children:"No earnings data available."}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-4 md:grid-cols-8 gap-2",children:i.map(s=>{const o=s.rows.length/r,d=s.rows.some(c=>c.inPortfolio);return e.jsxs("div",{className:`rounded-md p-3 border ${d?"border-primary/60 ring-1 ring-primary/30":"border-border"}`,style:{backgroundColor:`hsl(var(--primary) / ${.05+o*.35})`},title:`${s.rows.length} reports — week of ${s.weekLabel}`,children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:s.weekLabel}),e.jsx("div",{className:"text-xl font-semibold tabular-nums",children:s.rows.length}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[s.rows.filter(c=>c.inPortfolio).length," held"]})]},s.weekStart)})}),l.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground mb-2",children:"Your upcoming reports"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left py-2",children:"Symbol"}),e.jsx("th",{className:"text-left py-2",children:"Name"}),e.jsx("th",{className:"text-left py-2",children:"Week"}),e.jsx("th",{className:"text-left py-2",children:"Date"}),e.jsx("th",{className:"text-right py-2",children:"Weight"}),e.jsx("th",{className:"text-right py-2",children:"EPS Est."})]})}),e.jsx("tbody",{children:l.slice(0,12).map(s=>e.jsxs("tr",{className:"border-b border-border/40",children:[e.jsx("td",{className:"py-1.5 font-mono text-xs",children:s.symbol}),e.jsx("td",{className:"py-1.5 truncate max-w-[200px]",children:s.name??"—"}),e.jsx("td",{className:"py-1.5",children:s.weekLabel}),e.jsx("td",{className:"py-1.5 tabular-nums",children:s.reportDate}),e.jsxs("td",{className:"py-1.5 text-right tabular-nums",children:[s.weight.toFixed(2),"%"]}),e.jsx("td",{className:"py-1.5 text-right tabular-nums text-muted-foreground",children:s.estimate!=null?`$${s.estimate.toFixed(2)}`:"—"})]},`${s.symbol}-${s.reportDate}`))})]})})]})]})})]})};function Mt({error:t,onRetry:a}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-4",children:[e.jsxs(be,{variant:"destructive",className:"max-w-lg",children:[e.jsx(Q,{className:"h-5 w-5"}),e.jsx(et,{children:"Failed to Load Portfolio Data"}),e.jsxs(ve,{className:"mt-2 space-y-3",children:[e.jsx("p",{className:"text-sm",children:(t==null?void 0:t.message)||"An unexpected error occurred while fetching your portfolio."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{onClick:a,size:"sm",children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Retry"]}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>window.location.reload(),children:"Refresh Page"})]})]})]}),e.jsxs("div",{className:"mt-6 text-center text-sm text-muted-foreground max-w-md",children:[e.jsx("p",{children:"If the problem persists, try:"}),e.jsxs("ul",{className:"mt-2 space-y-1 text-left",children:[e.jsx("li",{children:"• Checking your internet connection"}),e.jsx("li",{children:"• Clearing your browser cache"}),e.jsx("li",{children:"• Logging out and back in"})]})]})]})}const U={summary:!0,metrics:!0,analyticsTabs:!0,factorAttribution:!0,sectorTilt:!0,betaContribution:!0,categoryIntelligence:!0,dividendProjection:!0,earningsHeatmap:!0,transactions:!0},zt=[{label:"Overview",items:[{key:"summary",label:"Summary banner"},{key:"metrics",label:"Metrics header"}]},{label:"Performance",items:[{key:"analyticsTabs",label:"Analytics Tabs (incl. Attribution)"},{key:"factorAttribution",label:"Factor Attribution"}]},{label:"Risk & Exposure",items:[{key:"sectorTilt",label:"Sector Tilt"},{key:"betaContribution",label:"Beta Contribution"},{key:"categoryIntelligence",label:"Category Intelligence"}]},{label:"Forward-Looking",items:[{key:"dividendProjection",label:"Dividend Projection"},{key:"earningsHeatmap",label:"Earnings Heatmap"}]},{label:"Ledger",items:[{key:"transactions",label:"Transactions"}]}];function Ot({open:t,onOpenChange:a,visibleSections:n,onVisibleSectionsChange:i}){const r=s=>{i({...n,[s]:!n[s]})},l=()=>{i({...U})};return e.jsx(xe,{open:t,onOpenChange:a,children:e.jsxs(he,{className:"sm:max-w-md max-h-[85vh] overflow-y-auto",children:[e.jsx(ue,{children:e.jsx(pe,{children:"Customize Portfolio View"})}),e.jsx("div",{className:"space-y-5 py-2",children:zt.map(s=>e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:s.label}),e.jsx("div",{className:"space-y-3",children:s.items.map(o=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:`section-${o.key}`,className:"cursor-pointer text-sm",children:o.label}),e.jsx(tt,{id:`section-${o.key}`,checked:n[o.key],onCheckedChange:()=>r(o.key)})]},o.key))})]},s.label))}),e.jsxs(b,{variant:"outline",size:"sm",onClick:l,className:"w-full gap-2",children:[e.jsx(st,{className:"h-4 w-4"}),"Reset to Default"]})]})})}function Ut(t){if(!t||typeof t!="object")return U;const a=t,n=(l,s)=>typeof l=="boolean"?l:s,i=n(a.intelligence,!0),r=n(a.performanceAttribution,!0);return{summary:n(a.summary,!0),metrics:n(a.metrics,!0),analyticsTabs:n(a.analyticsTabs,!0)&&n(a.analyticsTabs,r),factorAttribution:n(a.factorAttribution,i),sectorTilt:n(a.sectorTilt,i),betaContribution:n(a.betaContribution,i),categoryIntelligence:n(a.categoryIntelligence,!0),dividendProjection:n(a.dividendProjection,i),earningsHeatmap:n(a.earningsHeatmap,i),transactions:n(a.transactions,!0)}}function $t(){const[t,a]=x.useState(navigator.onLine);return x.useEffect(()=>{const n=()=>a(!0),i=()=>a(!1);return window.addEventListener("online",n),window.addEventListener("offline",i),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",i)}},[]),t}const O=({label:t})=>e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.2em] text-muted-foreground",children:t}),e.jsx("div",{className:"flex-1 h-px bg-border"})]}),zs=()=>{Le(),ce();const{data:t=[],isLoading:a,error:n,refetch:i}=ze(),{accounts:r,isLoading:l}=Oe(),s=(t??[]).map(N=>({asset_type:N.asset_type,value:N.value,performance_percentage:N.performance_percentage})),[o,d]=x.useState(!1);x.useState(!1);const[c,m]=x.useState(!1),[u,A]=x.useState(!1),[p,j]=x.useState(()=>{try{const N=localStorage.getItem("portfolio_visible_sections");return N?Ut(JSON.parse(N)):U}catch{return U}}),{toast:S}=$(),f=me(),I=$t();return n?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(V,{title:"Portfolio Intelligence",tagline:"AI-powered insights, multi-factor attribution, and sector-level analytics across your complete portfolio.",icon:B}),e.jsx("div",{className:"flex-1 p-4 md:p-6 overflow-auto",children:e.jsx(Mt,{error:n,onRetry:()=>i()})})]}):a?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(V,{title:"Portfolio Intelligence",tagline:"AI-powered insights, multi-factor attribution, and sector-level analytics across your complete portfolio.",icon:B}),e.jsx("div",{className:"flex-1 p-4 md:p-6 overflow-auto",children:e.jsx(Ue,{})})]}):e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(V,{title:"Portfolio Intelligence",tagline:"AI-powered insights, multi-factor attribution, and sector-level analytics across your complete portfolio.",icon:B,actions:e.jsxs(e.Fragment,{children:[e.jsxs(b,{variant:"outline",size:"sm",className:"min-h-[44px] md:min-
7h-auto",onClick:()=>A(!0),children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),"Customize"]}),e.jsx(b,{variant:"outline",size:"sm",disabled:c,onClick:async()=>{m(!0),await i(),m(!1),S({title:"Portfolio refreshed",description:`${t.length} assets updated`})},children:e.jsx(K,{className:`h-4 w-4 ${c?"animate-spin":""}`})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>f("/app/advisor"),children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Ask AI"]}),e.jsxs(b,{size:"sm",onClick:()=>d(!0),children:[e.jsx(lt,{className:"h-4 w-4 mr-2"}),"Add Asset"]})]})}),e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[!I&&e.jsxs(be,{variant:"destructive",children:[e.jsx(Q,{className:"h-4 w-4"}),e.jsx(ve,{children:"You are currently offline. Some features may not work properly."})]}),p.summary&&e.jsx(yt,{assets:t}),p.metrics&&e.jsx(xt,{}),(p.analyticsTabs||p.factorAttribution)&&e.jsx(O,{label:"Performance"}),p.analyticsTabs&&e.jsx(ft,{}),p.factorAttribution&&(l?e.jsx(v,{className:"h-96"}):e.jsx(Xe,{assets:s})),(p.sectorTilt||p.betaContribution||p.categoryIntelligence)&&e.jsx(O,{label:"Risk & Exposure"}),(p.sectorTilt||p.betaContribution)&&(l?e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(v,{className:"h-96"}),e.jsx(v,{className:"h-96"})]}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[p.sectorTilt&&e.jsx(Ft,{accounts:r}),p.betaContribution&&e.jsx(It,{accounts:r})]})),p.categoryIntelligence&&e.jsx(Ct,{}),(p.dividendProjection||p.earningsHeatmap)&&e.jsx(O,{label:"Forward-Looking"}),(p.dividendProjection||p.earningsHeatmap)&&(l?e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(v,{className:"h-96"}),e.jsx(v,{className:"h-96"})]}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[p.dividendProjection&&e.jsx(Rt,{accounts:r}),p.earningsHeatmap&&e.jsx(Et,{accounts:r})]})),p.transactions&&e.jsxs(e.Fragment,{children:[e.jsx(O,{label:"Ledger"}),e.jsxs(at,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",className:"w-full justify-between",children:[e.jsx("span",{children:"Transactions"}),e.jsx(ot,{className:"h-4 w-4"})]})}),e.jsx(it,{className:"pt-4",children:e.jsx(mt,{})})]})]})]}),e.jsx(dt,{open:o,onOpenChange:d,onSuccess:()=>i()}),e.jsx(Ot,{open:u,onOpenChange:A,visibleSections:p,onVisibleSectionsChange:N=>{j(N),localStorage.setItem("portfolio_visible_sections",JSON.stringify(N))}})]})};export{zs as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.