1import{d as _s,Z as re,s as w,j as e,B as v,T as L,a2 as ts,a3 as Ms,C as Ts,R as I,F as As,a4 as Es,a5 as Ps,u as k,_ as ne,I as V,c as Fs,X as ke,Y as Is,$ as Ls,S as $s,a1 as Os,a6 as Rs,h as qs,a7 as Bs}from"./index-g4WugBH4.js";import{e as ge,r as g}from"./react-BpdGtorb.js";import{C as P,a as as}from"./card-rwt4A55r.js";import{P as He}from"./PremiumPageHeader-DtoR-MWi.js";import{M as zs}from"./markdown-content-2xHJ6WRf.js";import{u as U}from"./useCurrency-wPDAOoOM.js";import{L as Vs,a as Us}from"./LazyChart-oBrKRoT4.js";import{u as rs,a as Hs}from"./useEffectiveUserId-Cw4gMied.js";import{H as Ws,D as Gs}from"./DashboardSkeleton-C9D9InVx.js";import{E as Ys,R as ns,A as Xs,C as Ks,X as Qs,Y as Js,T as Zs,d as et,e as st,P as tt,f as at,g as rt}from"./charts-VqRjxJBw.js";import{g as ae,a as nt}from"./categoryColors-1iGE5PPb.js";import{g as De}from"./categoryIcons-BmmySs-e.js";import{C as is,a as ls,b as os}from"./collapsible-B5jSS86d.js";import{B as ie}from"./badge-DEgwKkG_.js";import{T as z}from"./trending-down-BPYf34mQ.js";import{C as be}from"./chevron-down-fgIjtWz2.js";import{E as cs}from"./external-link-BQ2If9NO.js";import{D as _e,a as Me,b as Te,c as Ae,e as it,d as lt}from"./dialog-CPfNxU02.js";import{T as Ee,a as Pe,b as R,c as q}from"./tabs-D3rJiyQ0.js";import{W as xe}from"./wallet-HpDRxlz2.js";import{C as te}from"./chart-pie-BOvzj0BE.js";import{B as ot}from"./building-DDiMhIK4.js";import{D as ds}from"./droplets-D8I8JcG6.js";import{s as ce}from"./subMonths-grsZku1C.js";import{s as We}from"./subYears-DxS7iwP6.js";import{f as J,s as ct}from"./format-BpOyM-BW.js";import{s as dt}from"./subDays-wSpt_wn_.js";import{p as we}from"./parseISO-DeETzOIE.js";import{A as ms}from"./activity-BGWZi07P.js";import{S as us}from"./scroll-area-C_O6PBee.js";import{P as Fe}from"./plus-CCLN8KKX.js";import{C as xs}from"./calendar-D_26tjgl.js";import{M as Ie}from"./minus-D9bkl0eL.js";import{A as mt,a as ut,b as xt,c as ht,d as pt,e as ft,f as gt,g as jt}from"./alert-dialog-BJ0jpsBY.js";import{S as vt}from"./square-pen-qvvbu_Db.js";import{G as yt}from"./git-compare-_zpLocPJ.js";import{T as Nt}from"./trash-2-DBIc44cF.js";import{T as bt}from"./triangle-alert-DnKzB0ks.js";import{U as wt}from"./UpgradeModal-CmKXTbRv.js";import{L as A}from"./label-BhkyX0L4.js";import{T as hs}from"./textarea-DQF7pbvW.js";import{S as Y,a as X,b as K,c as Q,d as b}from"./select-C-mPsjVI.js";import{P as Ct,a as St,b as kt}from"./popover-BJ1S_E6P.js";import{C as Dt}from"./calendar-ZtJ2CiKq.js";import{u as _t}from"./useDeals-8jiFNcvG.js";import{u as Mt}from"./useCashflows-C8lx-phR.js";import{read as Tt,utils as At}from"./xlsx-B6sNpj_1.js";import{U as he}from"./upload-D90uK3WW.js";import{B as ps}from"./briefcase-CcrvOfEr.js";import{D as Et}from"./dollar-sign-DlmilPn4.js";import{L as B}from"./loader-circle-D8jnIafj.js";import{I as Pt}from"./info-CNue2mgk.js";import{L as Ft}from"./lock-Cnc8d74-.js";import{D as ve}from"./database-BSqXkgPZ.js";import{E as Ce}from"./eye-BSB_4g8e.js";import{E as It}from"./eye-off-DwR79A47.js";import{u as Ge,a as Lt,b as $t}from"./useAlphaVantage-SsGcIwCs.js";import{R as Se}from"./refresh-cw-BiIPmSZZ.js";import{u as Ot}from"./usePortfolioMetrics-Dq8ckhqV.js";import{L as Rt}from"./layers-3drO3ebm.js";import{A as qt}from"./arrow-up-D-8Osp6o.js";import{A as Bt}from"./arrow-down-DcgTZkLx.js";import{S as zt}from"./star-BdiW8UKl.js";import{u as Vt}from"./useConsolidatedPortfolio-Db_5BKas.js";import{C as Ut}from"./calendar-clock-cua5E5ni.js";import{H as Ht}from"./HoldingDetailDrawer-D2BZz-9P.js";import{S as Wt}from"./switch-CBLSXIri.js";import{R as Gt}from"./rotate-ccw-DV4MaVjY.js";import{S as Yt}from"./settings-2-DJ9ywY9c.js";import{L as Xt}from"./layout-grid-kgCi-CAs.js";import{f as Kt}from"./formatDistanceToNow-CKuQd25-.js";import{C as Qt}from"./copy-mOIC0n3U.js";import{C as Ye}from"./circle-alert-DDNRfnll.js";import"./supabase-DRR_Es6B.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"./index-Bs2sydDB.js";import"./startOfMonth-DrI67C0Y.js";import"./getTimezoneOffsetInMilliseconds-B9UnuQsa.js";import"./en-US-Bfz1jvxT.js";import"./addYears-NX0UtgMg.js";import"./differenceInCalendarDays-CZ0qhtMk.js";import"./index-BdQq_4o_.js";import"./index-CP_LwkyG.js";import"./isSameDay-C48lonqK.js";import"./endOfMonth-TCNI7KCh.js";import"./differenceInCalendarMonths-CDiZ4PwV.js";import"./chevron-left-CNuhV7no.js";import"./riskCalculations-DlUAkL57.js";import"./constructNow-BR0oC-tW.js";import"./differenceInMonths-Bvhe9Knj.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Xe=_s("FileUp",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"m15 15-3-3-3 3",key:"15xj92"}]]);function fs(s,t=!0){var l,a;const r=rs(),n=re({queryKey:["dashboard-data",r],queryFn:async()=>{const{data:i,error:c}=await w.rpc("get_dashboard_data",{p_user_id:r});if(c)throw console.error("Dashboard RPC error:",c),c;const d=i;return{assets:d.assets||[],categoryData:d.categories||[]}},enabled:t&&!!r,staleTime:10*60*1e3,gcTime:30*60*1e3,refetchOnWindowFocus:!1});return{assets:((l=n.data)==null?void 0:l.assets)||[],categoryData:((a=n.data)==null?void 0:a.categoryData)||[],isLoading:n.isLoading,isError:n.isError,refetch:n.refetch}}const Jt=({data:s})=>{const{formatCurrency:t,formatCurrencyCompact:r}=U();if(s.length===0)return null;const n=s.map(a=>({name:a.category,value:Number(a.total_value),percentage:Number(a.allocation_pct),asset_count:a.asset_count,itemStyle:{color:ae(a.category)}})),l={animation:!0,animationDuration:1e3,animationEasing:"elasticOut",tooltip:{trigger:"item",backgroundColor:"rgba(255, 255, 255, 0.98)",borderColor:"#e5e7eb",borderWidth:1,textStyle:{color:"#1e293b",fontSize:13},padding:16,formatter:function(a){return` 7 <div style="font-weight: 700; margin-bottom: 10px; font-size: 14px; color: ${a.color};">${a.name}</div> 8 <div style="display: flex; flex-direction: column; gap: 6px;"> 9 <div style="display: flex; justify-content: space-between; gap: 24px;">
10 <span style="color: #64748b;">Total Value:</span> 11 <span style="font-weight: 600; color: #1e293b;">${t(a.value)}</span> 12 </div> 13 <div style="display: flex; justify-content: space-between; gap: 24px;"> 14 <span style="color: #64748b;">Allocation:</span> 15 <span style="font-weight: 600; color: #1e293b;">${a.data.percentage.toFixed(1)}%</span> 16 </div> 17 <div style="display: flex; justify-content: space-between; gap: 24px;"> 18 <span style="color: #64748b;">Assets:</span> 19 <span style="font-weight: 600; color: #1e293b;">${a.data.asset_count} position${a.data.asset_count!==1?"s":""}</span> 20 </div> 21 </div> 22 `}},series:[{type:"pie",radius:["40%","70%"],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:function(a){return`{name|${a.name}} 23{value|${r(a.value)}} 24{percent|${a.percent.toFixed(1)}%}`},rich:{name:{fontSize:13,fontWeight:600,color:"#1e293b",lineHeight:18},value:{fontSize:12,fontWeight:500,color:"#64748b",lineHeight:16},percent:{fontSize:12,fontWeight:700,lineHeight:16}}},labelLine:{show:!0,length:20,length2:15,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:n}]};return e.jsx(Ys,{option:l,style:{height:"450px",width:"100%"},opts:{renderer:"svg"},className:"animate-fade-in"})},Zt=({data:s})=>{const{formatCurrency:t,formatCurrencyCompact:r}=U(),n=ge(),l=a=>{n(`/app/portfolio?category=${encodeURIComponent(a)}`)};return e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:s.map(a=>e.jsx(P,{className:"hover:shadow-lg hover:scale-[1.02] transition-all duration-200 cursor-pointer",onClick:()=>l(a.category),children:e.jsxs(as,{className:"p-6",children:[e.jsx("div",{className:"h-1 w-full rounded-full mb-4",style:{backgroundColor:ae(a.category)}}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{backgroundColor:nt(a.category,.15)},children:De(a.category)}),e.jsx("h3",{className:"font-semibold text-charcoal text-sm",children:a.category})]}),e.jsxs("div",{className:"mb-2",children:[e.jsx("p",{className:"text-2xl font-bold text-charcoal",children:r(a.total_value)}),e.jsxs("p",{className:"text-sm text-muted-grey",children:[a.asset_count," ",a.asset_count===1?"asset":"assets"]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-grey",children:"Portfolio %"}),e.jsxs("span",{className:"text-sm font-semibold text-charcoal",children:[a.allocation_pct.toFixed(1),"%"]})]}),e.jsx("div",{className:"w-full bg-soft-border rounded-full h-2",children:e.jsx("div",{className:"h-2 rounded-full transition-all",style:{width:`${a.allocation_pct}%`,backgroundColor:ae(a.category)}})})]}),e.jsx(v,{variant:"ghost",size:"sm",className:"w-full mt-4 text-xs",children:"View Details â"})]})},a.category))})};function ea(s){return{equity:"Equity",etf:"ETF",bond:"Bond",fund:"Fund",mutual_fund:"Mutual Fund",reit:"REIT",private_equity:"Private Equity",hedge_fund:"Hedge Fund",real_estate:"Real Estate",luxury_real_estate:"Luxury Real Estate",sports_franchise:"Sports Franchise",energy_infrastructure:"Energy Infrastructure",data_center:"Data Center",mining_project:"Mining Project",hotel:"Hotel",resort:"Resort",commodity:"Commodity",commodity_gold:"Gold",commodity_silver:"Silver",commodity_oil:"Oil",commodity_other:"Commodity",cryptocurrency:"Cryptocurrency",crypto:"Cryptocurrency",art:"Art",wine:"Wine",classic_car:"Classic Car",jewelry:"Jewelry",collectible:"Collectible",cash:"Cash",fx:"Foreign Exchange",other:"Other"}[s.toLowerCase()]||s}function sa(s){if(!s||s.length===0)return{categories:[],totals:{value:0,positionCount:0,largestHolding:null,bestPerformer:null}};const t=s.reduce((i,c)=>i+c.value,0),r=new Map;
24s.forEach(i=>{const c=i.category||"Other";r.has(c)||r.set(c,[]),r.get(c).push(i)});const n=[];r.forEach((i,c)=>{const d=i.reduce((o,x)=>o+x.value,0),u=d/t*100,p=i.reduce((o,x)=>{const f=x.performance_percentage||0,j=x.value/d;return o+f*j},0),m=new Map;i.forEach(o=>{const x=o.asset_type||"other";m.has(x)||m.set(x,[]),m.get(x).push(o)});const h=[];m.forEach((o,x)=>{const f=o.reduce((N,y)=>N+y.value,0),j=f/d*100,_=[...o].sort((N,y)=>y.value-N.value);h.push({name:x,displayName:ea(x),value:f,percentage:j,count:o.length,holdings:_})}),h.sort((o,x)=>x.value-o.value),n.push({name:c,icon:De(c),color:ae(c),value:d,percentage:u,positionCount:i.length,ytdReturn:p,assetClasses:h})}),n.sort((i,c)=>c.value-i.value);const l=s.length>0?s.reduce((i,c)=>c.value>i.value?c:i):null,a=s.length>0?s.reduce((i,c)=>{const d=c.performance_percentage||0,u=i.performance_percentage||0;return d>u?c:i}):null;return{categories:n,totals:{value:t,positionCount:s.length,largestHolding:l?{name:l.name,value:l.value,percentage:l.value/t*100}:null,bestPerformer:a?{name:a.name,return:a.performance_percentage||0}:null}}}function ta({data:s,color:t,width:r=60,height:n=20}){if(!s||s.length===0)return null;const l=Math.max(...s),a=Math.min(...s),i=l-a;if(i===0){const d=n/2,u=s.map((p,m)=>`${m/(s.length-1)*r},${d}`).join(" ");return e.jsx("svg",{width:r,height:n,className:"opacity-70",children:e.jsx("polyline",{fill:"none",stroke:t,strokeWidth:"2",points:u})})}const c=s.map((d,u)=>{const p=u/(s.length-1)*r,m=n-(d-a)/i*n;return`${p},${m}`}).join(" ");return e.jsx("svg",{width:r,height:n,className:"opacity-70",children:e.jsx("polyline",{fill:"none",stroke:t,strokeWidth:"2",points:c})})}function pe(s){return s>=1e6?`${(s/1e6).toFixed(2)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toFixed(0)}function gs(s){return s.charAt(0).toUpperCase()}function js(s,t){return t===0?s:s/(1+t/100)}function aa(s,t=12){const n=100+s,l=[100];for(let a=1;a<t;a++){const i=a/(t-1),c=100+(n-100)*i,d=(Math.random()-.5)*2;l.push(c+d)}return l}const Ke="pk_WGmnWqgzQoW3ae1QJK0LLg",Qe={AAPL:"apple.com",MSFT:"microsoft.com",GOOGL:"google.com",GOOG:"google.com",AMZN:"amazon.com",META:"meta.com",FB:"meta.com",TSLA:"tesla.com",NVDA:"nvidia.com",NFLX:"netflix.com",ADBE:"adobe.com",CRM:"salesforce.com",ORCL:"oracle.com",INTC:"intel.com",AMD:"amd.com",QCOM:"qualcomm.com",AVGO:"broadcom.com",TXN:"ti.com",CSCO:"cisco.com",IBM:"ibm.com",JPM:"jpmorganchase.com",BAC:"bankofamerica.com",WFC:"wellsfargo.com",GS:"goldmansachs.com",MS:"morganstanley.com",C:"citigroup.com",BLK:"blackrock.com",SCHW:"schwab.com",V:"visa.com",MA:"mastercard.com",PYPL:"paypal.com",AXP:"americanexpress.com",KO:"coca-cola.com",PEP:"pepsico.com",WMT:"walmart.com",COST:"costco.com",TGT:"target.com",HD:"homedepot.com",LOW:"lowes.com",MCD:"mcdonalds.com",SBUX:"starbucks.com",NKE:"nike.com",DIS:"disney.com",CMCSA:"comcast.com",JNJ:"jnj.com",UNH:"unitedhealthgroup.com",PFE:"pfizer.com",ABBV:"abbvie.com",TMO:"thermofisher.com",ABT:"abbott.com",MRK:"merck.com",LLY:"lilly.com",BMY:"bms.com",BA:"boeing.com",CAT:"caterpillar.com",GE:"ge.com",HON:"honeywell.com",MMM:"3m.com",DE:"deere.com",XOM:"exxonmobil.com",CVX:"chevron.com",COP:"conocophillips.com",T:"att.com",VZ:"verizon.com",TMUS:"t-mobile.com",F:"ford.com",GM:"gm.com",LMT:"lockheedmartin.com",RTX:"rtx.com",NOC:"northropgrumman.com",ASML:"asml.com",TSM:"tsmc.com",MU:"micron.com"};function vs(s,t,r=128){if(s&&Qe[s.toUpperCase()])return`https://img.logo.dev/${Qe[s.toUpperCase()]}?token=${Ke}&size=${r}`;if(t){const n=ra(t);if(n)return`https://img.logo.dev/${n}?token=${Ke}&size=${r}`}return null}function ra(s){const t=s.toLowerCase().replace(/\s+(inc\.?|incorporated|corp\.?|corporation|ltd\.?|limited|llc|l\.l\.c\.|company|co\.?|group|holdings?|partners?|plc)$/i,"").trim(),r={apple:"apple.com",microsoft:"microsoft.com",alphabet:"google.com",google:"google.com",amazon:"amazon.com",facebook:"meta.com",meta:"meta.com","meta platforms":"meta.com",tesla:"tesla.com",nvidia:"nvidia.com",jpmorgan:"jpmorganchase.com","jpmorgan chase":"jpmorganchase.com","bank of america":"bankofamerica.com","wells fargo":"wellsfargo.com","goldman sachs":"goldmansachs.com","morgan stanley":"morganstanley.com"};if(r[t])return r[t];const n=t.replace(/[^a-z0-9\s]/g,"").replace(/\s+/g,"")+".com";return n.length>5&&n.length<40?n:null}function ys(s){let t=0;for(let d=0;d<s.length;d++)t=s.charCodeAt(d)+((t<<5)-t);const r=Math.abs(t)%360,n=60+Math.abs(t)%20,l=50+Math.abs(t)%15,a=l-15,i=`hsl(${r}, ${n}%, ${l}%)`,c=`hsl(${(r+30)%360}, ${n}%, ${a}%)`;return[i,c]}function Ns(s){if(!s)return"ð";const t=s.toLowerCase();return t.includes("real estate")||t.includes("property")?t.includes("commercial")?"ð¢":t.includes("residential")?"ð¡":"ð ":t.includes("private equity")||t.includes("pe fund")?"ð¼":t.includes("hedge fund")?"ð":t.includes("venture")||t.includes("vc")?"ð":t.includes("mutual fund")?"ð":t.includes("bitcoin")||t.includes("btc")?"â¿":t.includes("ethereum")||t.includes("eth")?"Î":t.includes("crypto")?"ð°":t.includes("gold")?"ð¥":t.includes("silver")?"ð¥":t.includes("oil")||t.includes("petroleum")?"ð¢ï¸":t.includes("commodity")?"ðª":t.includes("art")?"ð¨":t.includes("collectible")?"ð¼ï¸":t.includes("bond")||t.includes("treasury")?"ð":t.includes("etf")?"ð":"ð"}const na=({holding:s,onClick:t,index:r=0})=>{var f;const[n,l]=g.useState(!1),a=s.performance_percentage||0,i=a>=0,c=js(s.value,a),d=s.value-c,u=aa(a),p=s.category?ae(s.category):"hsl(var(--deep-emerald))",m=s.logo_url||vs(s.ticker,s.name,128),[h,o]=ys(s.name),x=m&&!n;return e.jsxs(P,{className:"p-4 hover:shadow-lg transition-all duration-200 cursor-pointer hover:scale-[1.02] animate-fade-in",onClick:t,style:{animationDelay:`${r*50}ms`},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[x?e.jsx("img",{src:m,alt:`${s.name} logo`,className:"w-12 h-12 rounded-lg object-cover bg-white p-1",onError:j=>{console.error("â Logo failed to load:",{holding:s.name,ticker:s.ticker,url:m,error:j}),l(!0)},onLoad:()=>{console.log("â
Logo loaded successfully:",{holding:s.name,ticker:s.ticker,url:m})},loading:"lazy"}):e.jsx("div",{className:"w-12 h-12 rounded-lg flex items-center justify-center text-white font-bold text-xl",style:{background:`linear-gradient(135deg, ${h}, ${o})`},children:s.ticker?gs(s.name):Ns(s.asset_type)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"font-semibold text-foreground truncate",children:s.name}),s.ticker&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.ticker})]}),e.jsx(ie,{variant:"outline",className:"text-xs",style:{borderColor:p,color:p},children:s.asset_type||"Equity"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-1",children:[e.jsxs("span",{className:"text-2xl font-bold text-foreground",children:["$",pe(s.value)]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(f=s.allocation_percentage)==null?void 0:f.toFixed(1),"% of portfolio"]})]}),e.jsx("div",{className:"w-full h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${Math.min((s.allocation_percentage||0)*2,100)}%`,backgroundColor:p}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:`flex items-center gap-1 ${i?"text-green-600":"text-red-600"}`,children:[i?e.jsx(L,{className:"h-4 w-4"}):e.jsx(z,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-semibold",children:[i?"+":"",a.toFixed(1),"%"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"YTD"})]}),e.jsx(ta,{data:u,color:i?"#10B981":"#EF4444",width:60,height:20})]}),e.jsxs("div",{className:"mt-3 pt-3 border-t border-soft-border grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Cost Basis:"}),e.jsxs("span",{className:"ml-1 font-medium text-foreground",children:["$",pe(c)]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"text-muted-foreground",children:"Gain:"}),e.jsxs("span",{className:`ml-1 font-medium ${d>=0?"text-green-600":"text-red-600"}`,children:["$",pe(Math.abs(d))]})]})]})]})},ia=g.memo(na),la=({category:s,isExpanded:t,onToggle:r,maxHoldingsToShow:n=3,onHoldingClick:l,isLoading:a=!1})=>{const{formatCurrency:i}=U(),c=ge(),[d,u]=g.useState(!1),p=g.useMemo(()=>s.assetClasses.flatMap(x=>x.holdings),[s.assetClasses]),m=d?p:p.slice(0,n),h=De(s.name),o=s.ytdReturn>=0;return e.jsx(P,{className:"overflow-hidden min-h-[100px]",children:e.jsxs(is,{open:t,onOpenChange:r,children:[e.jsx(ls,{asChild:!0,children:e.jsxs("div",{className:"p-4 md:p-5 cursor-pointer hover:bg-muted/30 transition-colors duration-150 min-h-[80px]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"text-2xl flex-shrink-0",children:h}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground truncate",children:s.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.positionCount," position",s.positionCount!==1?"s":""," â¢",e.jsxs("span",{className:o?"text-green-600":"text-red-600",children:[" ",o?"+":"",s.ytdReturn.toFixed(1),"% YTD"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 flex-shrink-0",children:[e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-foreground",children:i(s.value)}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.percentage.toFixed(1),"% of portfolio"]})]}),e.jsx(be,{className:`h-5 w-5 text-muted-foreground transition-transform duration-200 ${t?"rotate-180":""}`})]})]}),e.jsx("div",{className:"mt-3 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${Math.min(s.percentage,100)}%`,backgroundColor:"hsl(var(--deep-emerald))"}})})]})}),e.jsx(os,{children:e.jsxs(as,{className:"px-4 py-4 bg-muted/20 border-t",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4",children:a?e.jsx(Ws,{count:n}):m.map((x,f)=>e.jsx(ia,{holding:x,onClick:()=>l==null?void 0:l(x),index:f},x.id))}),p.length>n&&e.jsx("div",{className:"text-center mb-4",children:e.jsx(v,{variant:"outline",size:"lg",className:"w-full md:w-auto",onClick:x=>{x.stopPropagation(),u(!d)},children:d?e.jsxs(e.Fragment,{children:[e.jsx(ts,{className:"h-4 w-4 mr-2"}),"Collapse"]}):e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-4 w-4 mr-2"}),"View All ",p.length," Position",p.length!==1?"s":""]})})}),e.jsx("div",{className:"pt-4 border-t border-soft-border",children:e.jsxs(v,{variant:"outline",size:"sm",onClick:x=>{x.stopPropagation(),c(`/app/portfolio?category=${encodeURIComponent(s.name)}`)},className:"w-full md:w-auto",children:[e.jsx(cs,{className:"h-4 w-4 mr-2"}),"View in Portfolio Page"]})})]})})]})})},oa=g.memo(la);function ca({holding:s}){const{formatCurrency:t}=U(),r=s.performance_percentage||0,n=r>=0,l=js(s.value,r),a=s.value-l,i=s.allocation_percentage||0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(de,{label:"Current Value",value:t(s.value),icon:e.jsx(xe,{className:"h-4 w-4"})}),e.jsx(de,{label:"Cost Basis",value:`$${pe(l)}`,icon:e.jsx(te,{className:"h-4 w-4"})}),e.jsx(de,{label:"Unrealized Gain",value:`${a>=0?"+":""}${t(a)}`,valueClassName:a>=0?"text-green-600":"text-red-600",icon:a>=0?e.jsx(L,{className:"h-4 w-4"}):e.jsx(z,{className:"h-4 w-4"})}),e.jsx(de,{label:"YTD Return",value:`${n?"+":""}${r.toFixed(1)}%`,valueClassName:n?"text-green-600":"text-red-600",icon:n?e.jsx(L,{className:"h-4 w-4"}):e.jsx(z,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-muted/30 space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Portfolio Allocation"}),e.jsxs("span",{className:"text-sm font-semibold",children:[i.toFixed(2),"%"]})]}),e.jsx(Ms,{value:i,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This holding represents ",i.toFixed(2),"% of your total portfolio value"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(W,{icon:e.jsx(te,{className:"h-4 w-4"}),label:"Asset Type",value:s.asset_type}),s.category&&e.jsx(W,{icon:e.jsx(te,{className:"h-4 w-4"}),label:"Category",value:s.category}),s.custodian&&e.jsx(W,{icon:e.jsx(ot,{className:"h-4 w-4"}),label:"Custodian",value:s.custodian}),s.liquidity&&e.jsx(W,{icon:e.jsx(ds,{className:"h-4 w-4"}),label:"Liquidity",value:s.liquidity}),s.units!==null&&s.units!==void 0&&e.jsx(W,{icon:e.jsx(xe,{className:"h-4 w-4"}
24),label:"Units Held",value:s.units.toLocaleString()}),s.current_price!==null&&s.current_price!==void 0&&e.jsx(W,{icon:e.jsx(L,{className:"h-4 w-4"}),label:"Current Price",value:t(s.current_price)}),s.currency&&e.jsx(W,{icon:e.jsx(xe,{className:"h-4 w-4"}),label:"Currency",value:s.currency})]})]})}function de({label:s,value:t,icon:r,valueClassName:n="text-foreground"}){return e.jsxs("div",{className:"p-4 rounded-lg bg-muted/50 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[r,e.jsx("p",{className:"text-xs",children:s})]}),e.jsx("p",{className:`text-xl font-bold ${n}`,children:t})]})}function W({icon:s,label:t,value:r}){return e.jsxs("div",{className:"flex justify-between items-center p-3 bg-muted/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s,e.jsx("span",{className:"text-sm",children:t})]}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:r})]})}function bs(s){const t=new Date;switch(s){case"1W":return dt(t,7);case"1M":return ce(t,1);case"3M":return ce(t,3);case"6M":return ce(t,6);case"1Y":return We(t,1);case"YTD":return ct(t);case"MAX":return We(t,10);default:return ce(t,1)}}function da(s,t,r="1M"){return re({queryKey:["holding-performance",s,r],queryFn:async()=>{if(!s)return{data:[],metrics:ws()};const n=bs(r),l=J(n,"yyyy-MM-dd"),{data:a,error:i}=await w.from("positions").select("date, value").eq("asset_id",s).gte("date",l).order("date",{ascending:!0});i&&console.error("Error fetching positions:",i);let c;if(a&&a.length>0){const u=a[0].value;c=a.map(p=>({date:p.date,value:p.value,change:(p.value-u)/u*100}))}else c=ma(t,r);const d=ua(c);return{data:c,metrics:d}},enabled:!!s,staleTime:1e3*60*10})}function ws(){return{periodReturn:0,highValue:0,lowValue:0,volatility:0,maxDrawdown:0}}function ma(s,t){const r=bs(t),l=Math.ceil((new Date().getTime()-r.getTime())/(1e3*60*60*24)),a=Math.min(l,365),i=[],c=.02,d=3e-4;let u=s;const p=[u];for(let h=1;h<a;h++){const o=(Math.random()-.5)*2*c+d;u=u/(1+o),p.unshift(u)}const m=p[0];for(let h=0;h<a;h++){const o=new Date(r);o.setDate(o.getDate()+h),i.push({date:J(o,"yyyy-MM-dd"),value:p[h],change:(p[h]-m)/m*100})}return i}function ua(s){if(s.length===0)return ws();const t=s.map(o=>o.value),r=t[0],l=(t[t.length-1]-r)/r*100,a=Math.max(...t),i=Math.min(...t),c=[];for(let o=1;o<t.length;o++)c.push((t[o]-t[o-1])/t[o-1]);const d=c.reduce((o,x)=>o+x,0)/c.length,u=c.reduce((o,x)=>o+Math.pow(x-d,2),0)/c.length,p=Math.sqrt(u)*Math.sqrt(252)*100;let m=0,h=t[0];for(const o of t){o>h&&(h=o);const x=(h-o)/h*100;x>m&&(m=x)}return{periodReturn:l,highValue:a,lowValue:i,volatility:p,maxDrawdown:m}}const xa=["1W","1M","3M","6M","1Y","YTD","MAX"];function ha({assetId:s,assetName:t,currentValue:r}){const[n,l]=g.useState("1M"),{data:a,isLoading:i}=da(s,r,n),{formatCurrency:c}=U();if(i)return e.jsx(pa,{});const d=(a==null?void 0:a.data)||[],u=a==null?void 0:a.metrics,p=((u==null?void 0:u.periodReturn)||0)>=0;return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:xa.map(m=>e.jsx(v,{variant:n===m?"default":"outline",size:"sm",onClick:()=>l(m),className:n===m?"bg-deep-emerald hover:bg-deep-emerald/90":"",children:m},m))}),e.jsx("div",{className:"h-64 w-full",children:e.jsx(ns,{width:"100%",height:"100%",children:e.jsxs(Xs,{data:d,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"colorValue",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:p?"hsl(var(--chart-1))":"hsl(var(--destructive))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:p?"hsl(var(--chart-1))":"hsl(var(--destructive))",stopOpacity:0})]})}),e.jsx(Ks,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Qs,{dataKey:"date",tickFormatter:m=>{try{return J(we(m),"MMM d")}catch{return m}},className:"text-xs text-muted-foreground",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Js,{tickFormatter:m=>`$${(m/1e3).toFixed(0)}k`,className:"text-xs text-muted-foreground",tick:{fill:"hsl(var(--muted-foreground))"},width:60}),e.jsx(Zs,{content:({active:m,payload:h})=>{if(m&&h&&h.length){const o=h[0].payload;return e.jsxs("div",{className:"bg-popover border border-border rounded-lg p-3 shadow-lg",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:J(we(o.date),"MMM d, yyyy")}),e.jsx("p",{className:"text-lg font-semibold",children:c(o.value)}),e.jsxs("p",{className:`text-sm ${o.change>=0?"text-green-600":"text-red-600"}`,children:[o.change>=0?"+":"",o.change.toFixed(2),"%"]})]})}return null}}),e.jsx(et,{type:"monotone",dataKey:"value",stroke:p?"hsl(var(--chart-1))":"hsl(var(--destructive))",strokeWidth:2,fill:"url(#colorValue)"})]})})}),u&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(se,{icon:p?e.jsx(L,{className:"h-4 w-4"}):e.jsx(z,{className:"h-4 w-4"}),label:`${n} Return`,value:`${u.periodReturn>=0?"+":""}${u.periodReturn.toFixed(2)}%`,valueClassName:p?"text-green-600":"text-red-600"}),e.jsx(se,{icon:e.jsx(L,{className:"h-4 w-4"}),label:"Period High",value:c(u.highValue)}),e.jsx(se,{icon:e.jsx(z,{className:"h-4 w-4"}),label:"Period Low",value:c(u.lowValue)}),e.jsx(se,{icon:e.jsx(ms,{className:"h-4 w-4"}),label:"Volatility (Ann.)",value:`${u.volatility.toFixed(1)}%`}),e.jsx(se,{icon:e.jsx(Ts,{className:"h-4 w-4"}),label:"Max Drawdown",value:`-${u.maxDrawdown.toFixed(1)}%`,valueClassName:"text-red-600"})]})]})}function se({icon:s,label:t,value:r,valueClassName:n="text-foreground"}){return e.jsxs("div",{className:"p-3 rounded-lg bg-muted/30 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s,e.jsx("p",{className:"text-xs",children:t})]}),e.jsx("p",{className:`text-lg font-semibold ${n}`,children:r})]})}function pa(){return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex gap-1",children:[...Array(7)].map((s,t)=>e.jsx(I,{className:"h-8 w-12"},t))}),e.jsx(I,{className:"h-64 w-full"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[...Array(5)].map((s,t)=>e.jsx(I,{className:"h-20 w-full"},t))})]})}function fa(s){return re({queryKey:["holding-transactions",s],queryFn:async()=>
24{if(!s)return[];const{data:t,error:r}=await w.from("transactions").select("*").eq("asset_id",s).order("transaction_date",{ascending:!1}).limit(50);if(r)throw console.error("Error fetching transactions:",r),r;return t||[]},enabled:!!s,staleTime:1e3*60*5})}function ga(s){const t={buy:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",sell:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",dividend:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",interest:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",fee:"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400",transfer:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400",rebalance:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400"};return t[s.toLowerCase()]||t.transfer}function ja(s){return{buy:"â",sell:"â",dividend:"ð°",interest:"ð",fee:"ð³",transfer:"â",rebalance:"âï¸"}[s.toLowerCase()]||"â¢"}function va({assetId:s,assetName:t}){const{data:r,isLoading:n,error:l}=fa(s),{formatCurrency:a}=U();return n?e.jsx(ba,{}):l?e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:e.jsx("p",{children:"Error loading transactions. Please try again."})}):!r||r.length===0?e.jsx(Na,{assetName:t}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[r.length," transaction",r.length!==1?"s":""]}),e.jsxs(v,{size:"sm",variant:"outline",children:[e.jsx(Fe,{className:"h-4 w-4 mr-1"}),"Add Transaction"]})]}),e.jsx(us,{className:"h-[400px] pr-4",children:e.jsx("div",{className:"space-y-3",children:r.map(i=>e.jsx(ya,{type:i.transaction_type,amount:i.amount,date:i.transaction_date,description:i.description,units:i.units,pricePerUnit:i.price_per_unit,currency:i.currency,formatCurrency:a},i.id))})})]})}function ya({type:s,amount:t,date:r,description:n,units:l,pricePerUnit:a,currency:i,formatCurrency:c}){const d=ja(s),u=ga(s),p=["buy","fee"].includes(s.toLowerCase());return e.jsx("div",{className:"p-4 rounded-lg border bg-card hover:bg-muted/30 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs(ie,{className:`${u} font-medium`,children:[e.jsx("span",{className:"mr-1",children:d}),s]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:[p?"-":"+",c(Math.abs(t))]}),n&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:n}),l&&a&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[l.toLocaleString()," units @ ",c(a)]})]})]}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[e.jsx(xs,{className:"h-3 w-3"}),J(we(r),"MMM d, yyyy")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:i})]})]})})}function Na({assetName:s}){return e.jsxs("div",{className:"p-8 text-center space-y-4",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-full bg-muted/50 flex items-center justify-center",children:e.jsx(As,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-foreground",children:"No transactions recorded"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["No transaction history found for ",s]})]}),e.jsxs(v,{size:"sm",className:"bg-deep-emerald hover:bg-deep-emerald/90",children:[e.jsx(Fe,{className:"h-4 w-4 mr-1"}),"Add First Transaction"]})]})}function ba(){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(I,{className:"h-5 w-24"}),e.jsx(I,{className:"h-9 w-32"})]}),e.jsx("div",{className:"space-y-3",children:[...Array(5)].map((s,t)=>e.jsx(I,{className:"h-24 w-full"},t))})]})}const Je={equity:[{headline:"{company} Reports Strong Q4 Earnings, Beats Analyst Expectations",sentiment:"positive"},{headline:"{company}
24 Announces Strategic Partnership with Tech Giant",sentiment:"positive"},{headline:"Analysts Upgrade {company} Stock Following Product Launch",sentiment:"positive"},{headline:"{company} Faces Headwinds Amid Market Uncertainty",sentiment:"negative"},{headline:"{company} CEO Outlines Growth Strategy at Investor Day",sentiment:"neutral"},{headline:"Market Watch: {company} Trading at Key Technical Levels",sentiment:"neutral"}],bond:[{headline:"Fixed Income Markets Steady as {company} Bond Yields Hold",sentiment:"neutral"},{headline:"{company} Credit Rating Affirmed by Major Agency",sentiment:"positive"},{headline:"Bond Investors Eye {company} Amid Rate Environment",sentiment:"neutral"}],"private-equity":[{headline:"{company} Portfolio Company Achieves Key Milestone",sentiment:"positive"},{headline:"Private Markets: {company} Fund Performance Update",sentiment:"neutral"},{headline:"{company} Announces New Investment in Growth Sector",sentiment:"positive"}],"real-estate":[{headline:"{company} Property Values Rise in Strong Market",sentiment:"positive"},{headline:"Real Estate Update: {company} Occupancy Rates Stable",sentiment:"neutral"},{headline:"{company} Announces New Development Project",sentiment:"positive"}],crypto:[{headline:"{company} Sees Increased Institutional Adoption",sentiment:"positive"},{headline:"Crypto Markets: {company} Volatility Persists",sentiment:"neutral"},{headline:"{company} Network Upgrade Completed Successfully",sentiment:"positive"}],commodity:[{headline:"Commodities Update: {company} Prices Fluctuate on Supply Data",sentiment:"neutral"},{headline:"{company} Demand Rises in Emerging Markets",sentiment:"positive"}],default:[{headline:"{company} Investment Performance Review",sentiment:"neutral"},{headline:"Market Update: {company} Sector Analysis",sentiment:"neutral"},{headline:"{company} Quarterly Portfolio Summary",sentiment:"neutral"}]},wa=["Bloomberg","Reuters","Financial Times","Wall Street Journal","CNBC","MarketWatch","Barron's","The Economist"];function Ca(s){return s[Math.floor(Math.random()*s.length)]}function Sa(s){return{"Public Equity":"equity","Fixed Income":"bond","Private Equity":"private-equity","Real Estate":"real-estate",Cryptocurrency:"crypto",Commodities:"commodity"}[s]||"default"}function ka(s,t,r){const n=Sa(t),l=Je[n]||Je.default,a=Math.floor(Math.random()*3)+3,i=[],c=new Set;for(let d=0;d<a;d++){let u;do u=Math.floor(Math.random()*l.length);while(c.has(u)&&c.size<l.length);c.add(u);const p=l[u],m=Math.floor(Math.random()*7),h=Math.floor(Math.random()*24),o=new Date;o.setDate(o.getDate()-m),o.setHours(o.getHours()-h);let x=p.sentiment;r!=null&&(r>5&&Math.random()>.5&&(x="positive"),r<-5&&Math.random()>.5&&(x="negative")),i.push({id:`news-${d}-${Date.now()}`,headline:p.headline.replace("{company}",s),source:Ca(wa),timestamp:o,sentiment:x,summary:`Latest market update regarding ${s} and its position in the ${t} sector.`,url:"#"})}return i.sort((d,u)=>u.timestamp.getTime()-d.timestamp.getTime())}function Da(s){const r=new Date().getTime()-s.getTime(),n=Math.floor(r/(1e3*60*60)),l=Math.floor(n/24);return n<1?"Just now":n<24?`${n}h ago`:l===1?"Yesterday":l<7?`${l} days ago`:s.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function _a({assetName:s,assetType:t,ticker:r,performance:n}){const l=g.useMemo(()=>ka(r||s,t,n),[s,t,r,n]);return l.length===0?e.jsxs("div",{className:"p-8 text-center space-y-4",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-full bg-muted/50 flex items-center justify-center",children:e.jsx(Es,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-foreground",children:"No news available"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"We couldn't find any recent news for this holding"})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Latest news for ",r||s]}),e.jsx(ie,{variant:"outline",className:"text-xs",children:"Mock Data"})]}),e.jsx(us,{className:"h-[400px] pr-4",children:e.jsx("div",{className:"space-y-3",children:l.map(a=>e.jsx(Ma,{article:a},a.id))})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"ð¡ Connect a news API like Finnhub or NewsAPI for live news"})]})}function Ma({article:s}){const r={positive:{icon:e.jsx(L,{className:"h-3 w-3"}),className:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400"},negative:{icon:e.jsx(z,{className:"h-3 w-3"}),className:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"},neutral:{icon:e.jsx(Ie,{className:"h-3 w-3"}),className:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400"}}[s.sentiment];return e.jsx("article",{className:"p-4 rounded-lg border bg-card hover:bg-muted/30 transition-colors group cursor-pointer",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:s.source}),e.jsxs(ie,{className:`${r.className} text-xs`,children:[r.icon,e.jsx("span",{className:"ml-1 capitalize",children:s.sentiment})]})]}),e.jsx("span",{className:"text-muted-foreground",children:Da(s.timestamp)})]}),e.jsx("h4",{className:"font-medium text-foreground leading-snug group-hover:text-deep-emerald transition-colors",children:s.headline}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:s.summary}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-deep-emerald opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("span",{children:"Read more"}),e.jsx(cs,{className:"h-3 w-3"})]})]})})}function Ta({holdingId:s,holdingName:t,onEdit:r,onAddTransaction:n,onSetAlert:l,onCompare:a,onDelete:i,onClose:c}){const[d,u]=g.useState(!1),p=()=>{r?r():k.info("Edit functionality coming soon")},m=()=>{n?n():k.info("Add transaction functionality coming soon")},h=()=>{l?l():k.info("Alert functionality coming soon")},o=()=>{a?a():k.info("Compare functionality coming soon")},x=()=>
24{i&&(i(s),c(),k.success(`${t} has been deleted`)),u(!1)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(v,{variant:"outline",size:"sm",onClick:p,children:[e.jsx(vt,{className:"h-4 w-4 mr-1.5"}),"Edit"]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:m,children:[e.jsx(Fe,{className:"h-4 w-4 mr-1.5"}),"Add Transaction"]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:h,children:[e.jsx(Ps,{className:"h-4 w-4 mr-1.5"}),"Set Alert"]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:o,children:[e.jsx(yt,{className:"h-4 w-4 mr-1.5"}),"Compare"]}),i&&e.jsxs(v,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>u(!0),children:[e.jsx(Nt,{className:"h-4 w-4 mr-1.5"}),"Delete"]})]}),e.jsx(mt,{open:d,onOpenChange:u,children:e.jsxs(ut,{children:[e.jsxs(xt,{children:[e.jsxs(ht,{className:"flex items-center gap-2",children:[e.jsx(bt,{className:"h-5 w-5 text-destructive"}),"Delete ",t,"?"]}),e.jsx(pt,{children:"This will permanently delete this holding and all associated transactions. This action cannot be undone."})]}),e.jsxs(ft,{children:[e.jsx(gt,{children:"Cancel"}),e.jsx(jt,{onClick:x,className:"bg-destructive hover:bg-destructive/90",children:"Delete"})]})]})})]})}function Aa({holding:s,isOpen:t,onClose:r,onEdit:n,onDelete:l}){const[a,i]=g.useState(!1),[c,d]=g.useState("overview"),u=x=>{x||(r(),d("overview"),i(!1))};if(!s)return null;const p=s.logo_url||vs(s.ticker,s.name,256),[m,h]=ys(s.name),o=p&&!a;return e.jsx(_e,{open:t,onOpenChange:u,children:e.jsxs(Me,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[o?e.jsx("img",{src:p,alt:`${s.name} logo`,className:"w-16 h-16 rounded-lg object-cover bg-white p-1",onError:()=>i(!0)}):e.jsx("div",{className:"w-16 h-16 rounded-lg flex items-center justify-center text-white font-bold text-2xl",style:{background:`linear-gradient(135deg, ${m}, ${h})`},children:s.ticker?gs(s.name):Ns(s.asset_type)}),e.jsxs("div",{children:[e.jsx(Ae,{className:"text-2xl",children:s.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s.ticker||s.asset_type})]})]})}),e.jsxs(Ee,{value:c,onValueChange:d,className:"mt-4",children:[e.jsxs(Pe,{className:"grid w-full grid-cols-4",children:[e.jsx(R,{value:"overview",children:"Overview"}),e.jsx(R,{value:"performance",children:"Performance"}),e.jsx(R,{value:"transactions",children:"Transactions"}),e.jsx(R,{value:"news",children:"News"})]}),e.jsx(q,{value:"overview",className:"mt-4",children:e.jsx(ca,{holding:s})}),e.jsx(q,{value:"performance",className:"mt-4",children:e.jsx(ha,{assetId:s.id,assetName:s.name,currentValue:s.value})}),e.jsx(q,{value:"transactions",className:"mt-4",children:e.jsx(va,{assetId:s.id,assetName:s.name})}),e.jsx(q,{value:"news",className:"mt-4",children:e.jsx(_a,{assetName:s.name,assetType:s.asset_type,ticker:s.ticker,performance:s.performance_percentage})})]}),e.jsxs(it,{className:"mt-6 flex flex-col sm:flex-row gap-4",children:[e.jsx(Ta,{holdingId:s.id,holdingName:s.name,onEdit:n?()=>n(s):void 0,onDelete:l,onClose:r}),e.jsx("div",{className:"flex-1"}),e.jsx(v,{variant:"outline",onClick:r,children:"Close"})]})]})})}function Ea({assets:s}){const t=ge(),r=g.useMemo(()=>s.map(o=>({...o,custodian:o.custodian??null,liquidity:o.liquidity??null,currency:o.currency??"USD",ticker:o.ticker??null,units:o.units??null,current_price:o.current_price??null,allocation_percentage:o.allocation_percentage??null})),[s]),n=g.useMemo(()=>sa(r),[r]),[l,a]=g.useState(new Set),[i,c]=g.useState(null),[d,u]=g.useState(!1),p=o=>{a(x=>{const f=new Set(x);return f.has(o)?f.delete(o):f.add(o),f})},m=o=>{c(o),u(!0)},h=()=>{u(!1),c(null)};return n.categories.length===0?e.jsxs(P,{className:"p-12 text-center space-y-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"No assets to display"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'Click "Load Demo Portfolio" in the header to seed your $1.2B portfolio.'})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[n.categories.map(o=>e.jsx(oa,{category:o,isExpanded:l.has(o.name),onToggle:()=>p(o.name),maxHoldingsToShow:3,onHoldingClick:m},o.name)),e.jsx(P,{className:"p-6 text-center bg-gradient-to-r from-deep-emerald/5 to-gold-accent/5 border-gold-accent/20",children:e.jsxs(v,{onClick:()=>t("/app/portfolio"),size:"lg",className:"w-full md:w-auto bg-deep-emerald hover:bg-deep-emerald/90",children:["View All ",n.totals.positionCount," Holdings in Portfolio â"]})})]}),e.jsx(Aa,{holding:i,isOpen:d,onClose:h})]})}const Pa={name:["name","asset name","asset_name","company","holding","security","instrument","fund name"],value:["value","amount","market value","market_value","total","price","worth","nav","current value","market_val"],type:["type","asset type","asset_type","category","class","asset class","asset_class","instrument type"],ticker:["ticker","symbol","code","isin","cusip"],currency:["currency","ccy","cur"],custodian:["custodian","broker","bank","institution","platform","provider"],category:["category","sector","
24industry","sub_type","sub type"]};function Fa(s){const t={},r=s.map(n=>n.toLowerCase().trim());for(const[n,l]of Object.entries(Pa))for(const a of l){const i=r.indexOf(a);if(i!==-1){t[n]=s[i];break}}return t}function G(s,t,r){const n=t[r];if(!n)return;const l=s[n];return l!=null?l.toString().trim():void 0}const Ia=["equity","etf","bond","fund","private_equity","hedge_fund","real_estate","crypto","commodity_gold","commodity_silver","cash","fx","art","wine","venture_capital","infrastructure"],La={stock:"equity",stocks:"equity",equities:"equity",share:"equity",shares:"equity","mutual fund":"fund",mf:"fund",funds:"fund","mutual funds":"fund","fixed income":"bond",fi:"bond",bonds:"bond","fixed deposit":"bond",fd:"bond",property:"real_estate","real estate":"real_estate",realestate:"real_estate",reit:"real_estate",gold:"commodity_gold",silver:"commodity_silver",pe:"private_equity","private equity":"private_equity",vc:"venture_capital","venture capital":"venture_capital",cryptocurrency:"crypto",bitcoin:"crypto",btc:"crypto",etfs:"etf","exchange traded fund":"etf","hedge funds":"hedge_fund","hedge fund":"hedge_fund",cash:"cash",fx:"fx",forex:"fx",art:"art",wine:"wine"};function $a(s){const t=s.toLowerCase().trim().replace(/[_-]/g," ");return Ia.includes(t.replace(/\s+/g,"_"))?t.replace(/\s+/g,"_"):La[t]||"equity"}function Oa({onSuccess:s}){const[t,r]=g.useState("single"),[n,l]=g.useState(!1),[a,i]=g.useState({name:"",asset_type:"equity",value:"",ticker:"",custodian:"",liquidity:"daily",currency:"USD"}),[c,d]=g.useState([]),[u,p]=g.useState(""),[m,h]=g.useState({}),o=async j=>{j.preventDefault(),l(!0);try{const{data:{user:_}}=await w.auth.getUser();if(!_)throw new Error("Not authenticated");const{error:N}=await w.from("assets").insert([{user_id:_.id,name:a.name,asset_type:a.asset_type,value:parseFloat(a.value),ticker:a.ticker||null,custodian:a.custodian||null,liquidity:a.liquidity,currency:a.currency}]);if(N)throw N;k.success("Asset added successfully"),i({name:"",asset_type:"equity",value:"",ticker:"",custodian:"",liquidity:"daily",currency:"USD"}),s()}catch(_){k.error(_.message||"Failed to add asset")}finally{l(!1)}},x=async j=>{var N;const _=(N=j.target.files)==null?void 0:N[0];if(_){p(_.name);try{const y=await _.arrayBuffer(),C=Tt(y),S=C.Sheets[C.SheetNames[0]],E=At.sheet_to_json(S);if(E.length>0){const H=Fa(Object.keys(E[0]));h(H),H.name||k.warning(`Could not auto-detect a "Name" column. Found headers: ${Object.keys(E[0]).join(", ")}`),H.value||k.warning(`Could not auto-detect a "Value" column. Found headers: ${Object.keys(E[0]).join(", ")}`)}d(E)}catch{k.error("Failed to parse file")}}},f=async()=>{if(c.length!==0){l(!0);try{const{data:{user:j}}=await w.auth.getUser();if(!j)throw new Error("Not authenticated");const _=c.map(S=>{const E=G(S,m,"type")||"equity";return{user_id:j.id,name:(G(S,m,"name")||"").trim(),asset_type:$a(E),value:parseFloat(G(S,m,"value")||"0"),ticker:G(S,m,"ticker")||null,custodian:G(S,m,"custodian")||null,currency:G(S,m,"currency")||"EUR",category:G(S,m,"category")||void 0}}),N=_.filter(S=>S.name&&S.name!==""&&!isNaN(S.value)&&S.value>0),y=_.length-N.length;if(N.length===0){k.error("No valid rows found. Ensure each row has a Name and a Value greater than 0."),l(!1);return}y>0&&k.warning(`${y} row(s) skipped (missing name or zero/invalid value)`);const{error:C}=await w.from("assets").insert(N);if(C)throw C;k.success(`${N.length} assets imported`),d([]),p(""),s()}catch(j){k.error(j.message||"Bulk import failed")}finally{l(!1)}}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{size:"sm",variant:t==="single"?"default":"outline",onClick:()=>r("single"),children:"Single Asset"}),e.jsxs(v,{size:"sm",variant:t==="bulk"?"default":"outline",onClick:()=>r("bulk"),children:[e.jsx(Xe,{className:"h-3.5 w-3.5 mr-1"})," Bulk Import"]})]}),t==="single"?e.jsxs("form",{onSubmit:o,className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Name *"}),e.jsx(V,{value:a.name,onChange:j=>i({...a,name:j.target.value}),required:!0,className:"h-9"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Type *"}),e.jsxs(Y,{value:a.asset_type,onValueChange:j=>i({...a,asset_type:j}),children:[e.jsx(X,{className:"h-9",children:e.jsx(K,{})}),e.jsxs(Q,{children:[e.jsx(b,{value:"equity",children:"Equity"}),e.jsx(b,{value:"etf",children:"ETF"}),e.jsx(b,{value:"bond",children:"Bond"}),e.jsx(b,{value:"fund",children:"Fund"}),e.jsx(b,{value:"private_equity",children:"Private Equity"}),e.jsx(b,{value:"hedge_fund",children:"Hedge Fund"}),e.jsx(b,{value:"real_estate",children:"Real Estate"}),e.jsx(b,{value:"crypto",children:"Crypto"}),e.jsx(b,{value:"commodity_gold",children:"Gold"}),e.jsx(b,{value:"cash",children:"Cash"}),e.jsx(b,{value:"art",children:"Art"}),e.jsx(b,{value:"wine",children:"Wine"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Value *"}),e.jsx(V,{type:"number",step:"0.01",value:a.value,onChange:j=>i({...a,value:j.target.value}),required:!0,className:"h-9"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Ticker"}),e.jsx(V,{value:a.ticker,onChange:j=>i({...a,ticker:j.target.value}),className:"h-9"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Currency"}),e.jsxs(Y,{value:a.currency,onValueChange:j=>i({...a,currency:j}),children:[e.jsx(X,{className:"h-9",children:e.jsx(K,{})}),e.jsxs(Q,{children:[e.jsx(b,{value:"EUR",children:"EUR"}),e.jsx(b,{value:"USD",children:"USD"}),e.jsx(b,{value:"GBP",children:"GBP"}),e.jsx(b,{value:"CHF",children:"CHF"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Custodian"}),e.jsx(V,{value:a.custodian,onChange:j=>i({...a,custodian:j.target.value}),className:"h-9"})]}),e.jsxs(v,{type:"submit",disabled:n,className:"w-full",children:[n?e.jsx(B,{className:"h-4 w-4 animate-spin mr-2"}):null,"Add Asset"]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"border-2 border-dashed border-border rounded-lg p-6 text-center",children:[e.jsx(Xe,{className:"h-8 w-8 mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Upload Excel or CSV"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3",children:"Columns: Name, Type, Value, Ticker, Custodian, Currency"}),e.jsx(V,{type:"file",accept:".xlsx,.xls,.csv",onChange:x,className:"max-w-xs mx-auto"})]}),c.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u,": ",c.length," rows parsed"]}),e.jsx("div",{className:"max-h-32 overflow-auto border rounded text-xs",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:Object.keys(c[0]).slice(0,5).map(j=>e.jsx("th",{className:"px-2 py-1 text-left",children:j},j))})}),e.jsx("tbody",{children:c.slice(0,5).map((j,_)=>e.jsx("tr",{className:"border-t",children:Object.values(j).slice(0,5).map((N,y)=>e.jsx("td",{className:"px-2 py-1",children:String(N)},y))},_))})]})}),e.jsxs(v,{onClick:f,disabled:n,className:"w-full",children:[n?e.jsx(B,{className:"h-4 w-4 animate-spin mr-2"}):null,"Import ",c.length," Assets"]})]})]})]})}const Ra=["FinTech","AI/ML","B2B SaaS","HealthTech","Consumer","Other"],qa=["Email - Cold","Email - Warm","Warm Intro","Referral","Platform","Conference"];function Ba({onSuccess:s}){const[t,r]=g.useState(""),[n,l]=g.useState("FinTech"),[a,i]=g.useState("Referral"),[c,d]=g.useState(""),[u,p]=g.useState(""),[m,h]=g.useState(!1),o=_t(),x=async()=>
24{if(!t.trim()){k.error("Company name is required");return}h(!0);try{await new Promise((f,j)=>{o.mutate({companyName:t,sector:n,source:a,tagline:u.substring(0,100),description:u,askAmount:c?parseFloat(c):0,valuation:0,aiScore:0,recommendation:"Consider",stage:"sourcing",receivedDate:new Date,isStarred:!1,isArchived:!1,aiReasoning:[],teamAnalysis:"",marketAnalysis:"",tractionMetrics:"",financialAnalysis:"",investmentFit:{matches:[],doesntMatch:[]},documents:[],scoreBreakdown:{teamQuality:0,marketOpportunity:0,traction:0,businessModel:0,competitivePosition:0,financialHealth:0},traction:"",logoColor:"#667EEA"},{onSuccess:f,onError:j})}),k.success("Deal created"),r(""),p(""),d(""),s()}catch(f){k.error(f.message||"Failed to create deal")}finally{h(!1)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Company Name *"}),e.jsx(V,{value:t,onChange:f=>r(f.target.value),className:"h-9",placeholder:"Acme Inc."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Deal Size ($)"}),e.jsx(V,{type:"number",value:c,onChange:f=>d(f.target.value),className:"h-9"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Sector"}),e.jsxs(Y,{value:n,onValueChange:f=>l(f),children:[e.jsx(X,{className:"h-9",children:e.jsx(K,{})}),e.jsx(Q,{children:Ra.map(f=>e.jsx(b,{value:f,children:f},f))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Source"}),e.jsxs(Y,{value:a,onValueChange:f=>i(f),children:[e.jsx(X,{className:"h-9",children:e.jsx(K,{})}),e.jsx(Q,{children:qa.map(f=>e.jsx(b,{value:f,children:f},f))})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Description"}),e.jsx(hs,{value:u,onChange:f=>p(f.target.value),rows:3,placeholder:"Brief description..."})]}),e.jsxs(v,{onClick:x,disabled:m||!t.trim(),className:"w-full",children:[m?e.jsx(B,{className:"h-4 w-4 animate-spin mr-2"}):null,"Create Deal"]})]})}function za({onSuccess:s}){const[t,r]=g.useState(new Date),[n,l]=g.useState("capital_call"),[a,i]=g.useState(""),[c,d]=g.useState("EUR"),[u,p]=g.useState(""),[m,h]=g.useState("pending"),o=Mt(),x=()=>{if(!a||parseFloat(a)<=0){k.error("Amount must be positive");return}const j=["distribution","dividend","interest","rental_income"].includes(n)?parseFloat(a):-parseFloat(a);o.mutate({due_date:J(t,"yyyy-MM-dd"),cashflow_type:n,amount:j,currency:c,description:u,status:m},{onSuccess:()=>{k.success("Cash flow added"),i(""),p(""),s()},onError:()=>k.error("Failed to add cash flow")})};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Date"}),e.jsxs(Ct,{children:[e.jsx(St,{asChild:!0,children:e.jsxs(v,{variant:"secondary",className:Fs("w-full justify-start text-left font-normal h-9 text-xs",!t&&"text-muted-foreground"),children:[e.jsx(xs,{className:"mr-2 h-3.5 w-3.5"}),t?J(t,"PPP"):"Pick a date"]})}),e.jsx(kt,{className:"w-auto p-0",align:"start",children:e.jsx(Dt,{mode:"single",selected:t,onSelect:f=>f&&r(f),initialFocus:!0,className:"pointer-events-auto"})})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Type"}),e.jsxs(Y,{value:n,onValueChange:l,children:[e.jsx(X,{className:"h-9",children:e.jsx(K,{})}),e.jsxs(Q,{children:[e.jsx(b,{value:"capital_call",children:"Capital Call"}),e.jsx(b,{value:"distribution",children:"Distribution"}),e.jsx(b,{value:"dividend",children:"Dividend"}),e.jsx(b,{value:"interest",children:"Interest"}),e.jsx(b,{value:"tax",children:"Tax Payment"}),e.jsx(b,{value:"expense",children:"Expense/Fee"}),e.jsx(b,{value:"rental_income",children:"Rental Income"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Amount *"}),e.jsx(V,{type:"number",step:"0.01",value:a,onChange:f=>i(f.target.value),className:"h-9"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Currency"}),e.jsxs(Y,{value:c,onValueChange:d,children:[e.jsx(X,{className:"h-9",children:e.jsx(K,{})}),e.jsxs(Q,{children:[e.jsx(b,{value:"EUR",children:"EUR"}),e.jsx(b,{value:"USD",children:"USD"}),e.jsx(b,{value:"GBP",children:"GBP"}),e.jsx(b,{value:"CHF",children:"CHF"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Status"}),e.jsxs(Y,{value:m,onValueChange:h,children:[e.jsx(X,{className:"h-9",children:e.jsx(K,{})}),e.jsxs(Q,{children:[e.jsx(b,{value:"pending",children:"Pending"}),e.jsx(b,{value:"paid",children:"Paid"}),e.jsx(b,{value:"received",children:"Received"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs",children:"Description"}),e.jsx(hs,{value:u,onChange:f=>p(f.target.value),rows:2})]}),e.jsxs(v,{onClick:x,disabled:o.isPending,className:"w-full",children:[o.isPending?e.jsx(B,{className:"h-4 w-4 animate-spin mr-2"}):null,"Add Cash Flow"]})]})}function ye({open:s,onOpenChange:t}){const r=ne(),n=async()=>{try{const{data:l}=await w.rpc("claim_full_access");l===!0&&k.success("Your data has been imported! Switched to your personal portfolio.")}catch{}await r.invalidateQueries()};return e.jsx(_e,{open:s,onOpenChange:t,children:e.jsxs(Me,{className:"sm:max-w-[600px] max-h-[85vh] overflow-y-auto",children:[e.jsxs(Te,{children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(he,{className:"h-5 w-5 text-primary"}),"Add Your Data"]}
24),e.jsx(lt,{children:"Import your portfolio data. All entries are saved to your personal account and reflected across the platform including AI insights."})]}),e.jsxs(Ee,{defaultValue:"assets",className:"mt-2",children:[e.jsxs(Pe,{className:"w-full grid grid-cols-3",children:[e.jsxs(R,{value:"assets",className:"text-xs gap-1.5",children:[e.jsx(ps,{className:"h-3.5 w-3.5"})," Assets"]}),e.jsxs(R,{value:"deals",className:"text-xs gap-1.5",children:[e.jsx(L,{className:"h-3.5 w-3.5"})," Deals"]}),e.jsxs(R,{value:"cashflows",className:"text-xs gap-1.5",children:[e.jsx(Et,{className:"h-3.5 w-3.5"})," Cash Flows"]})]}),e.jsx(q,{value:"assets",children:e.jsx(Oa,{onSuccess:n})}),e.jsx(q,{value:"deals",children:e.jsx(Ba,{onSuccess:n})}),e.jsx(q,{value:"cashflows",children:e.jsx(za,{onSuccess:n})})]})]})})}function Va(){const{isDemo:s,isLoading:t,demoDataLoaded:r}=Hs(),[n,l]=g.useState(!1),[a,i]=g.useState(!1),[c,d]=g.useState(!1),[u,p]=g.useState(!1),[m,h]=g.useState(!1),[o,x]=g.useState(!1),f=ne();if(t||n)return null;const j=!s,_=r,N=j&&!r,y=async H=>{d(!0);try{const{data:{user:le}}=await w.auth.getUser();if(!le)throw new Error("Not authenticated");const{error:Z}=await w.from("profiles").update({demo_data_loaded:H,updated_at:new Date().toISOString()}).eq("id",le.id);if(Z)throw Z;k.success(H?"Switched to demo portfolio.":"Switched to your own data."),await f.invalidateQueries()}catch{k.error("Failed to switch data view.")}finally{d(!1)}},C=async()=>{h(!0);try{await w.functions.invoke("enhanced-seed-portfolio"),k.success("Demo portfolio loaded."),await f.invalidateQueries()}catch{k.error("Failed to load demo portfolio.")}finally{h(!1)}},S=async()=>{p(!0),k.info("Migrating all demo data...");try{await w.functions.invoke("enhanced-seed-portfolio"),await w.functions.invoke("migrate-demo-data"),await w.functions.invoke("seed-deals-data"),await w.functions.invoke("seed-cashflow-data"),await w.functions.invoke("seed-investments-data"),k.success("All demo data loaded successfully."),await f.invalidateQueries()}catch{k.error("Migration failed.")}finally{p(!1)}},E=e.jsx("button",{onClick:()=>l(!0),className:"p-0.5 rounded hover:bg-muted transition-colors",children:e.jsx(ke,{className:"h-3 w-3 text-muted-foreground"})});return s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mx-4 md:mx-6 mt-3 rounded-lg border border-gold-accent/30 bg-gradient-to-r from-gold-accent/5 via-background to-gold-accent/5 px-3 py-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"flex-shrink-0 h-6 w-6 rounded-md bg-gold-accent/15 flex items-center justify-center",children:e.jsx(Pt,{className:"h-3.5 w-3.5 text-gold-accent"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground",children:"Demo Mode"}),e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-bold uppercase tracking-wider px-1 py-0.5 rounded bg-gold-accent/15 text-gold-accent",children:[e.jsx(Ft,{className:"h-2 w-2"}),"Read-Only"]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground truncate",children:"Viewing sample $7B portfolio"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsxs(v,{size:"sm",variant:"default",className:"text-[11px] h-7 px-2.5",onClick:()=>x(!0),children:[e.jsx(he,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:"Upload Data"})]}),e.jsxs(v,{size:"sm",variant:"outline",className:"text-[11px] h-7 px-2.5",onClick:()=>S(),disabled:u,children:[u?e.jsx(B,{className:"h-3 w-3 animate-spin"}):e.jsx(ve,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:u?"Loading...":"Migrate Data"})]}),E]})]}),e.jsx(ye,{open:o,onOpenChange:x}),e.jsx(wt,{open:a,onOpenChange:i})]}):j&&_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mx-4 md:mx-6 mt-3 rounded-lg border border-gold-accent/30 bg-gradient-to-r from-gold-accent/5 via-background to-gold-accent/5 px-3 py-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"flex-shrink-0 h-6 w-6 rounded-md bg-gold-accent/15 flex items-center justify-center",children:e.jsx(Ce,{className:"h-3.5 w-3.5 text-gold-accent"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground",children:"Demo Portfolio Active"}),e.jsx("p",{className:"text-[11px] text-muted-foreground truncate",children:"Viewing sample $7B portfolio"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsxs(v,{size:"sm",variant:"default",className:"text-[11px] h-7 px-2.5",onClick:()=>x(!0),children:[e.jsx(he,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:"Upload Data"})]}),e.jsxs(v,{size:"sm",variant:"outline",className:"text-[11px] h-7 px-2.5",onClick:()=>S(),disabled:u,children:[u?e.jsx(B,{className:"h-3 w-3 animate-spin"}):e.jsx(ve,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:u?"Migrating...":"Migrate Data"})]}),e.jsxs(v,{size:"sm",variant:"outline",className:"text-[11px] h-7 px-2.5",onClick:()=>
24y(!1),disabled:c,children:[c?e.jsx(B,{className:"h-3 w-3 animate-spin"}):e.jsx(It,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:c?"Switching...":"My Data"})]}),E]})]}),e.jsx(ye,{open:o,onOpenChange:x})]}):N?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mx-4 md:mx-6 mt-3 rounded-lg border border-border/50 bg-gradient-to-r from-background via-muted/30 to-background px-3 py-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"flex-shrink-0 h-6 w-6 rounded-md bg-primary/10 flex items-center justify-center",children:e.jsx(ps,{className:"h-3.5 w-3.5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground",children:"Your Portfolio"}),e.jsx("p",{className:"text-[11px] text-muted-foreground truncate",children:"Viewing your personal data"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsxs(v,{size:"sm",variant:"default",className:"text-[11px] h-7 px-2.5",onClick:()=>x(!0),children:[e.jsx(he,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:"Upload Data"})]}),e.jsxs(v,{size:"sm",variant:"outline",className:"text-[11px] h-7 px-2.5",onClick:C,disabled:m,children:[m?e.jsx(B,{className:"h-3 w-3 animate-spin"}):e.jsx(ve,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:m?"Loading...":"Load Demo"})]}),e.jsxs(v,{size:"sm",variant:"outline",className:"text-[11px] h-7 px-2.5",onClick:()=>y(!0),disabled:c,children:[c?e.jsx(B,{className:"h-3 w-3 animate-spin"}):e.jsx(Ce,{className:"h-3 w-3"}),e.jsx("span",{className:"ml-1",children:c?"Switching...":"Demo Portfolio"})]}),E]})]}),e.jsx(ye,{open:o,onOpenChange:x})]}):null}const Ze=[{symbol:"SPY",name:"S&P 500"},{symbol:"QQQ",name:"NASDAQ 100"},{symbol:"DIA",name:"Dow Jones"},{symbol:"VIXY",name:"VIX (VIXY)"}],es=[{symbol:"XLK",name:"Technology"},{symbol:"XLV",name:"Healthcare"},{symbol:"XLF",name:"Financials"},{symbol:"XLE",name:"Energy"},{symbol:"XLY",name:"Consumer"},{symbol:"XLI",name:"Industrials"},{symbol:"XLRE",name:"Real Estate"},{symbol:"XLB",name:"Materials"}];function Ua(){const[s,t]=g.useState(!1),r=g.useMemo(()=>Ze.map(o=>o.symbol),[]),n=g.useMemo(()=>es.map(o=>o.symbol),[]),{data:l,isFetching:a,dataUpdatedAt:i}=Ge(r),{data:c}=Ge(s?n:[]),d=ne(),u=Ze.map(o=>{const x=l==null?void 0:l.find(f=>(f==null?void 0:f.symbol)===o.symbol);return{symbol:o.symbol,name:o.name,price:Number((x==null?void 0:x.price)??0),changePct:Number((x==null?void 0:x.change_pct)??0)}}),p=es.map(o=>{const x=c==null?void 0:c.find(f=>(f==null?void 0:f.symbol)===o.symbol);return{name:o.name,change:Number((x==null?void 0:x.change_pct)??0)}}),m=()=>{d.invalidateQueries({queryKey:["av","batchQuotes"]})},h=new Date(i||Date.now());return e.jsx(is,{open:s,onOpenChange:t,children:e.jsxs(P,{className:"p-3 md:p-4 mb-4 border-soft-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-fresh-green animate-pulse"}),e.jsx("h4",{className:"text-sm font-semibold text-charcoal",children:"Market Pulse"}),e.jsx("span",{className:"text-[10px] text-muted-grey",children:h.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(v,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:m,disabled:a,children:e.jsx(Se,{className:`h-3 w-3 ${a?"animate-spin":""}`})}),e.jsx(ls,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:s?e.jsx(ts,{className:"h-3 w-3"}):e.jsx(be,{className:"h-3 w-3"})})})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:u.map(o=>{const x=o.changePct>=0,f=o.changePct>.1?L:o.changePct<-.1?z:Ie;return e.jsx("div",{className:"flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] text-muted-grey truncate",children:o.name}),e.jsx("p",{className:"text-sm font-semibold text-charcoal",children:o.price?o.price.toLocaleStr
24ing(void 0,{maximumFractionDigits:2}):"â"}),e.jsxs("div",{className:`flex items-center gap-1 text-[11px] font-medium ${x?"text-fresh-green":"text-destructive"}`,children:[e.jsx(f,{className:"h-3 w-3"}),e.jsxs("span",{children:[x?"+":"",o.changePct.toFixed(2),"%"]})]})]})},o.symbol)})}),e.jsx(os,{children:e.jsxs("div",{className:"mt-4 pt-3 border-t border-soft-border",children:[e.jsx("h5",{className:"text-xs font-semibold text-muted-grey mb-2",children:"Sector Performance (SPDR ETFs)"}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:p.map(o=>e.jsxs("div",{className:`rounded-md p-2 text-center text-[11px] font-medium ${o.change>0?"bg-fresh-green/10 text-fresh-green":o.change<0?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:[e.jsx("p",{className:"truncate",children:o.name}),e.jsxs("p",{className:"font-bold",children:[o.change>0?"+":"",o.change.toFixed(2),"%"]})]},o.name))})]})})]})})}function Ha(s,t){if(s.length===0)return{score:0,dimensions:[],grade:"N/A",color:"text-muted-grey"};const r={};s.forEach(y=>{const C=y.category||"Other";r[C]=(r[C]||0)+y.value});const l=Object.values(r).map(y=>y/t).reduce((y,C)=>y+C*C,0),a=Math.min(100,Math.round((1-l)*125)),c=[...s].sort((y,C)=>C.value-y.value).slice(0,5).reduce((y,C)=>y+C.value,0)/t,d=Math.min(100,Math.round((1-c)*150)),u=["daily","high","instant"],p=s.filter(y=>y.liquidity&&u.some(C=>y.liquidity.toLowerCase().includes(C))).reduce((y,C)=>y+C.value,0),m=Math.min(100,Math.round(p/t*130)),h=s.filter(y=>y.performance_percentage!=null).map(y=>y.performance_percentage);let o=70;if(h.length>2){const y=h.reduce((S,E)=>S+E,0)/h.length,C=Math.sqrt(h.reduce((S,E)=>S+(E-y)**2,0)/h.length);o=Math.min(100,Math.max(20,Math.round(100-C*3)))}const x=Math.min(100,Math.round(Math.min(s.length,30)/30*100)),f=[{metric:"Diversification",value:a,fullMark:100},{metric:"Concentration",value:d,fullMark:100},{metric:"Liquidity",value:m,fullMark:100},{metric:"Stability",value:o,fullMark:100},{metric:"Breadth",value:x,fullMark:100}],j=Math.round(f.reduce((y,C)=>y+C.value,0)/f.length),_=j>=80?"Excellent":j>=60?"Good":"Needs Attention",N=j>=80?"text-fresh-green":j>=60?"text-gold-accent":"text-destructive";return{score:j,dimensions:f,grade:_,color:N}}function Wa({assets:s,totalValue:t}){const{score:r,dimensions:n,grade:l,color:a}=g.useMemo(()=>Ha(s,t),[s,t]);return s.length===0?null:e.jsxs(P,{className:"p-6 mb-8",children:[e.jsx("h3",{className:"text-lg font-semibold text-deep-emerald mb-4",children:"Portfolio Health Score"}),e.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-6",children:[e.jsxs("div",{className:"relative w-32 h-32 flex-shrink-0",children:[e.jsxs("svg",{viewBox:"0 0 100 100",className:"w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"50",cy:"50",r:"42",fill:"none",stroke:"hsl(var(--soft-border))",strokeWidth:"8"}),e.jsx("circle",{cx:"50",cy:"50",r:"42",fill:"none",stroke:"hsl(var(--deep-emerald))",strokeWidth:"8",strokeLinecap:"round",strokeDasharray:`${r/100*264} 264`})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:"text-3xl font-bold text-charcoal",children:r}),e.jsx("span",{className:`text-xs font-semibold ${a}`,children:l})]})]}),e.jsx("div",{className:"flex-1 w-full h-48",children:e.jsx(ns,{width:"100%",height:"100%",children:e.jsxs(st,{data:n,outerRadius:"75%",children:[e.jsx(tt,{stroke:"hsl(var(--soft-border))"}),e.jsx(at,{dataKey:"metric",tick:{fontSize:11,fill:"hsl(var(--muted-grey))"}}),e.jsx(rt,{dataKey:"value",stroke:"hsl(var(--deep-emerald))",fill:"hsl(var(--deep-emerald))",fillOpacity:.2,strokeWidth:2})]})})}),e.jsx("div",{className:"flex flex-col gap-2 min-w-[140px]",children:n.map(i=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-xs text-muted-grey",children:i.metric}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-16 h-1.5 bg-soft-border rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-deep-emerald",style:{width:`${i.value}%`}})}),e.jsx("span",{className:"text-xs font-semibold text-charcoal w-6 text-right",children:i.value})]})]},i.metric))})]})]})}const Ga=new Set(["Cash & FX","Public Markets","Digital Assets","Commodities"]);function me(s,t,r=!1){const n=r?s<=t.good:s>=t.good,l=r?s<=t.warn:s>=t.warn;return n?"text-fresh-green":l?"text-gold-accent":"text-rose-500"}function Ya({assets:s,totalValue:t}){const{data:r}=Ot(),n=s.filter(m=>m.category==="Cash & FX").reduce((m,h)=>m+Number(h.value),0),l=t>0?n/t*100:0,a=s.filter(m=>Ga.has(m.category||"")).reduce((m,h)=>m+Number(h.value),0),i=t>0?a/t*100:0,c=[...s].sort((m,h)=>Number(h.value)-Number(m.value)).slice(0,5).reduce((m,h)=>m+Number(h.value),0),d=t>0?c/t*100:0,u=(r==null?void 0:r.maxDrawdown)??0,p=[{label:"Cash Position",value:`${l.toFixed(1)}%`,sub:"of portfolio",icon:xe,tone:me(l,{good:5,warn:2})},{label:"Liquid ⤠7 Days",value:`${i.toFixed(1)}
24%`,sub:"marketable assets",icon:ds,tone:me(i,{good:40,warn:20})},{label:"Top-5 Concentration",value:`${d.toFixed(1)}%`,sub:"of total value",icon:Rt,tone:me(d,{good:40,warn:60},!0)},{label:"Max Drawdown",value:`${u.toFixed(1)}%`,sub:"trailing 30d",icon:z,tone:me(Math.abs(u),{good:5,warn:10},!0)}];return e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-charcoal uppercase tracking-wide",children:"Risk & Exposure"}),e.jsx("p",{className:"text-xs text-muted-grey",children:"Decision metrics at a glance"})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 md:gap-4",children:p.map(m=>{const h=m.icon;return e.jsxs(P,{className:"p-4 border-soft-border",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("p",{className:"text-xs text-muted-grey font-medium",children:m.label}),e.jsx(h,{className:"h-4 w-4 text-muted-grey"})]}),e.jsx("p",{className:`text-2xl font-semibold ${m.tone}`,children:m.value}),e.jsx("p",{className:"text-xs text-muted-grey mt-1",children:m.sub})]},m.label)})})]})}function ue({label:s,value:t}){const r=t??0,n=r>.05?qt:r<-.05?Bt:Ie,l=r>.05?"text-fresh-green":r<-.05?"text-rose-500":"text-muted-grey";return e.jsxs("div",{className:"flex flex-col items-start min-w-[68px]",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-grey font-medium",children:s}),e.jsxs("span",{className:`text-base md:text-lg font-semibold flex items-center gap-0.5 ${l}`,children:[e.jsx(n,{className:"h-3.5 w-3.5"}),Math.abs(r).toFixed(2),"%"]})]})}function Xa(){const s=rs(),{data:t=[]}=re({queryKey:["hero-delta-history",s],enabled:!!s,staleTime:10*60*1e3,queryFn:async()=>{const{data:d,error:u}=await w.from("allocations_daily").select("date, total_value, perf_1d, perf_mtd, perf_ytd").eq("user_id",s).order("date",{ascending:!0}).limit(1e3);if(u)throw u;return d||[]}}),r=t.at(-1),n=t[0],l=(r==null?void 0:r.perf_1d)!=null?Number(r.perf_1d):null,a=(r==null?void 0:r.perf_mtd)!=null?Number(r.perf_mtd):null,i=(r==null?void 0:r.perf_ytd)!=null?Number(r.perf_ytd):null,c=n&&r&&Number(n.total_value)>0?(Number(r.total_value)/Number(n.total_value)-1)*100:null;return e.jsxs("div",{className:"flex flex-wrap items-center gap-4 md:gap-6 pt-3 border-t border-soft-border/60",children:[e.jsx(ue,{label:"DoD",value:l}),e.jsx(ue,{label:"MTD",value:a}),e.jsx(ue,{label:"YTD",value:i}),e.jsx(ue,{label:"ITD",value:c}),e.jsxs("div",{className:"flex flex-col items-start min-w-[68px]",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-grey font-medium",children:"vs Benchmark"}),e.jsx("span",{className:"text-base md:text-lg font-semibold text-charcoal",children:"SPX"})]})]})}function Ka(){const{data:s}=Is(),{formatCurrencyCompact:t}=U(),r=ne(),{data:n,isLoading:l}=re({queryKey:["dashboard-watchlist",s==null?void 0:s.id],queryFn:async()=>{const{data:i,error:c}=await w.from("dashboard_watchlist").select("id, asset_id, alert_threshold_pct, assets(name, value, performance_percentage, category)").eq("user_id",s.id).order("created_at",{ascending:!1}).limit(5);if(c)throw c;return i||[]},enabled:!!(s!=null&&s.id),staleTime:5*60*1e3}),a=Ls({mutationFn:async i=>{const{error:c}=await w.from("dashboard_watchlist").delete().eq("id",i);if(c)throw c},onSuccess:()=>r.invalidateQueries({queryKey:["dashboard-watchlist"]})});return e.jsxs(P,{className:"p-5 mb-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zt,{className:"h-4 w-4 text-gold-accent"}),e.jsx("h3",{className:"text-lg font-semibold text-charcoal",children:"Watchlist"})]}),e.jsx(Ce,{className:"h-4 w-4 text-muted-grey"})]}),l?e.jsx("div",{className:"space-y-3",children:Array.from({length:3}).map((i,c)=>e.jsx(I,{className:"h-10 w-full"},c))}):!n||n.length===0?e.jsx("p",{className:"text-sm text-muted-grey text-center py-6",children:"No watchlist items. Pin assets from the Portfolio page."}):e.jsx("div",{className:"space-y-2",children:n.map(i=>{var u,p,m,h;const c=(u=i.assets)==null?void 0:u.performance_percentage,d=(c||0)>=0;return e.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-lg bg-off-white/50 hover:bg-off-white transition-colors",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-charcoal truncate",children:(p=i.assets)==null?void 0:p.name}),e.jsx("p",{className:"text-[11px] text-muted-grey",children:((m=i.assets)==null?void 0:m.category)||"â"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sm font-semibold text-charcoal",children:t(((h=i.assets)==null?void 0:h.value)||0)}),e.jsxs("p",{className:`text-[11px] font-medium ${d?"text-fresh-green":"text-destructive"}`,children:[d?"+":"",(c||0).toFixed(1),"%"]})]}),e.jsx(v,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-grey hover:text-destructive",onClick:()=>a.mutate(i.id),children:e.jsx(ke,{className:"h-3 w-3"})})]})]},i.id)})})]})}function Qa(s){const t=new Date(s+"T00:00:00Z").getTime(),r=Date.now();return Math.ceil((t-r)/(1e3*60*60*24))}function Ja(){const{data:s=[],isLoading:t}=Lt("3month"),{accounts:r=[]}=Vt(),n=g.useMemo(()=>{const a=new Set;for(const i of r)for(const c of i.holdings??[])c.ticker&&a.add(String(c.ticker).toUpperCase());return a},[r]),l=g.useMemo(()=>{const a=s.map(d=>({...d,daysOut:Qa(d.report_date)})).filter(d=>d.daysOut>=0&&d.daysOut<=14).sort((d,u)=>d.daysOut-u.daysOut),i=a.filter(d=>n.has(String(d.symbol).toUpperCase())),c=a.filter(d=>!n.has(String(d.symbol).toUpperCase()));return[...i,...c].slice(0,8)},[s,n]);return e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ut,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-xs font-bold uppercase tracking-wider",children:"Earnings â Next 14 Days"})]}),t?e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading c
24alendarâ¦"}):l.length===0?e.jsx("div",{className:"text-xs text-muted-foreground",children:"No upcoming earnings."}):e.jsx("div",{className:"space-y-1.5",children:l.map(a=>{const i=n.has(String(a.symbol).toUpperCase());return e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1 border-b border-border/40 last:border-0",children:[e.jsx("span",{className:"font-mono font-semibold w-16",children:a.symbol}),e.jsx("span",{className:"flex-1 truncate text-muted-foreground",children:a.name??""}),i&&e.jsx(ie,{variant:"secondary",className:"text-[9px] h-4 px-1.5",children:"Held"}),e.jsx("span",{className:"tabular-nums text-muted-foreground w-20 text-right",children:a.report_date}),e.jsx("span",{className:`tabular-nums w-10 text-right font-semibold ${a.daysOut<=2?"text-amber-600":"text-foreground"}`,children:a.daysOut===0?"Today":`${a.daysOut}d`})]},`${a.symbol}-${a.report_date}`)})})]})}function Ne({rows:s,portfolioSymbols:t,onPick:r,direction:n}){return s!=null&&s.length?e.jsx("div",{className:"divide-y divide-border/40",children:s.slice(0,5).map(l=>{const a=parseFloat((l.change_percentage||"0").replace("%","")),i=a>=0,c=t.has(l.ticker.toUpperCase());return e.jsxs("button",{type:"button",onClick:()=>r(l.ticker.toUpperCase()),className:"w-full grid grid-cols-[1fr_auto_auto] items-center gap-3 px-1 py-2 text-xs hover:bg-muted/40 transition text-left",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary flex-shrink-0",title:"In your portfolio"}),e.jsx("span",{className:"font-mono font-semibold truncate",children:l.ticker})]}),e.jsxs("span",{className:"tabular-nums text-muted-foreground",children:["$",parseFloat(l.price).toFixed(2)]}),e.jsxs("span",{className:`tabular-nums font-semibold ${n==="flat"?"text-muted-foreground":i?"text-emerald-600":"text-rose-600"}`,children:[i?"+":"",a.toFixed(2),"%"]})]},l.ticker)})}):e.jsx("div",{className:"text-xs text-muted-foreground py-6 text-center",children:"No data available."})}function Za(){const{data:s,isLoading:t}=$t(),{assets:r}=fs(),[n,l]=g.useState(null),a=new Set((r??[]).map(i=>(i.symbol??i.ticker??"").toString().toUpperCase()).filter(Boolean));return e.jsxs(P,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-deep-emerald",children:"Top Movers"}),(s==null?void 0:s.last_updated)&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(s.last_updated).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}),t?e.jsx("div",{className:"space-y-2",children:[0,1,2,3,4].map(i=>e.jsx(I,{className:"h-7 w-full"},i))}):e.jsxs(Ee,{defaultValue:"gainers",children:[e.jsxs(Pe,{className:"grid grid-cols-3 w-full h-8",children:[e.jsxs(R,{value:"gainers",className:"text-[11px] gap-1",children:[e.jsx(L,{className:"h-3 w-3"})," Gainers"]}),e.jsxs(R,{value:"losers",className:"text-[11px] gap-1",children:[e.jsx(z,{className:"h-3 w-3"})," Losers"]}),e.jsxs(R,{value:"active",className:"text-[11px] gap-1",children:[e.jsx(ms,{className:"h-3 w-3"})," Active"]})]}),e.jsx(q,{value:"gainers",className:"mt-2",children:e.jsx(Ne,{rows:(s==null?void 0:s.gainers)??[],portfolioSymbols:a,onPick:l,direction:"up"})}),e.jsx(q,{value:"losers",className:"mt-2",children:e.jsx(Ne,{rows:(s==null?void 0:s.losers)??[],portfolioSymbols:a,onPick:l,direction:"down"})}),e.jsx(q,{value:"active",className:"mt-2",children:e.jsx(Ne,{rows:(s==null?void 0:s.most_active)??[],portfolioSymbols:a,onPick:l,direction:"flat"})})]}),e.jsx(Ht,{symbol:n,onOpenChange:i=>!i&&l(null)})]})}function er(){const[s,t]=g.useState(null),[r,n]=g.useState(!0),[l,a]=g.useState(!1);g.useEffect(()=>{const d=localStorage.getItem("dashboard_briefing_dismissed");if(d&&new Date(d).toDateString()===new Date().toDateString()){a(!0),n(!1);return}i()},[]);const i=async()=>{n(!0);try{const{data:d,error:u}=await w.functions.invoke("dashboard-insights",{body:{action:"dailyBriefing"}});if(u)throw u;d!=null&&d.bullets&&t({bullets:d.bullets,timestamp:d.timestamp||new Date().toISOString()})}catch(d){console.warn("Daily briefing failed:",d),t({bullets:["Markets are showing mixed signals â review your portfolio allocations for any drift from targets.","No critical alerts in the last 24 hours. Your portfolio health remains stable.","Consider reviewing upcoming cashflow obligations this week for liquidity planning."],timestamp:new Date().toISOString()})}finally{n(!1)}},c=()=>{a(!0),localStorage.setItem("dashboard_briefing_dismissed",new Date().toISOString())};return l?null:e.jsx(P,{className:"p-4 mb-4 bg-gradient-to-r from-deep-emerald/5 via-fresh-green/5 to-gold-accent/5 border-deep-emerald/20",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-deep-emerald/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx($s,{className:"h-4 w-4 text-deep-emerald"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:"text-sm font-semibold text-deep-emerald",children:"Daily Briefing"}),s&&e.jsx("span",{className:"text-[10px] text-muted-grey",children:new Date(s.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}),r?e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{className:"h-3 w-full"}),e.jsx(I,{className:"h-3 w-5/6"})]}
24):s?e.jsx("div",{className:"space-y-1.5",children:s.bullets.slice(0,3).map((d,u)=>e.jsxs("p",{className:"text-sm text-charcoal leading-relaxed",children:["⢠",d]},u))}):null]})]}),e.jsx(v,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 flex-shrink-0",onClick:c,children:e.jsx(ke,{className:"h-3 w-3 text-muted-grey"})})]})})}const fe={marketPulse:!0,aiBriefing:!0,totalValue:!0,riskExposure:!0,healthScore:!0,categoryAllocation:!0,watchlist:!0,holdings:!0,aiInsights:!0},ss={marketPulse:"Market Pulse",aiBriefing:"AI Daily Briefing",totalValue:"Hero â Total Value & Deltas",riskExposure:"Risk & Exposure Strip",healthScore:"Portfolio Health Score",categoryAllocation:"Allocation â Actual vs Policy",watchlist:"Market Context (Watchlist, Earnings, Movers)",holdings:"Holdings Snapshot",aiInsights:"Strategic Insights"};function sr({open:s,onOpenChange:t,visibleSections:r,onVisibleSectionsChange:n}){const l=i=>{n({...r,[i]:!r[i]})},a=()=>{n({...fe})};return e.jsx(_e,{open:s,onOpenChange:t,children:e.jsxs(Me,{className:"sm:max-w-md",children:[e.jsx(Te,{children:e.jsx(Ae,{children:"Customize Dashboard"})}),e.jsx("div",{className:"space-y-4 py-2",children:Object.keys(ss).map(i=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(A,{htmlFor:`dash-section-${i}`,className:"cursor-pointer",children:ss[i]}),e.jsx(Wt,{id:`dash-section-${i}`,checked:r[i],onCheckedChange:()=>l(i)})]},i))}),e.jsxs(v,{variant:"outline",size:"sm",onClick:a,className:"w-full gap-2",children:[e.jsx(Gt,{className:"h-4 w-4"}),"Reset to Default"]})]})})}const Un=()=>{const[s,t]=g.useState(null),[r,n]=g.useState(null),{assets:l,categoryData:a,isLoading:i,refetch:c}=fs(s==null?void 0:s.id),[d,u]=g.useState(null),[p,m]=g.useState(!0),[h,o]=g.useState(null),[x,f]=g.useState(()=>localStorage.getItem("dashboard_category_view")||"donut"),[j,_]=g.useState(!1),[N,y]=g.useState(()=>{try{const D=localStorage.getItem("dashboard_visible_sections");return D?{...fe,...JSON.parse(D)}:fe}catch{return fe}}),C=ge(),{toast:S}=Os();Rs(s);const{currency:E,formatCurrency:H,formatCurrencyCompact:le}=U(),Z=ne();g.useEffect(()=>{localStorage.setItem("dashboard_visible_sections",JSON.stringify(N))},[N]),g.useEffect(()=>{localStorage.setItem("dashboard_category_view",x)},[x]),g.useEffect(()=>{const{data:{subscription:D}}=w.auth.onAuthStateChange((T,$)=>{n($),t(($==null?void 0:$.user)??null)});return w.auth.getSession().then(({data:{session:T}})=>{n(T),t((T==null?void 0:T.user)??null)}),()=>D.unsubscribe()},[]),g.useEffect(()=>{if(s&&l.length>0){const D=()=>oe();if("requestIdleCallback"in window){const T=requestIdleCallback(D,{timeout:3e3});return()=>cancelIdleCallback(T)}else{const T=setTimeout(D,1e3);return()=>clearTimeout(T)}}else l.length===0&&!i&&m(!1)},[s,l.length,i]),g.useEffect(()=>{if(l.length>0&&s&&!p){const D=setTimeout(()=>{Z.prefetchQuery({queryKey:["portfolio-assets"],queryFn:async()=>{const{data:T}=await w.from("assets").select("id, name, asset_type, category, value, allocation_percentage, performance_percentage, custodian, liquidity, currency, ticker, units, current_price").eq("user_id","621b6da6-e160-4ca6-8e3b-7bc18f51da57");return T},staleTime:3e5})},2e3);return()=>clearTimeout(D)}},[l.length,s,p,Z]);const oe=async(D=!1)=>{var Le,$e,Oe,Re,qe,Be,ze,Ve;if(!r){m(!1);return}if(!D&&r.expires_at&&Date.now()/1e3-(r.expires_at-3600)>50*60){const{data:M,error:O}=await w.auth.refreshSession();!O&&M.session&&n(M.session)}m(!0),o(null);const T=new AbortController,$=setTimeout(()=>T.abort(),15e3);try{const{data:F,error:M}=await w.functions.invoke("dashboard-insights",{body:{action:"getOrCreate"}});if((($e=(Le=M==null?void 0:M.context)==null?void 0:Le.body)==null?void 0:$e.code)==="SESSION_EXPIRED"||M&&((Oe=M.message)!=null&&Oe.includes("Session expired")||(Re=M.message)!=null&&Re.includes("session_not_found"))){if(!D){const{data:O,error:ee}=await w.auth.refreshSession();if(!ee&&O.session)return n(O.session),oe(!0)}o("SESSION_EXPIRED"),m(!1);return}if(M&&((qe=M.message)!=null&&qe.includes("Unauthorized")||(Be=M.message)!=null&&Be.includes("401"))){if(!D){const{data:O,error:ee}=await w.auth.refreshSession();if(!ee&&O.session)return n(O.session),oe(!0)}o("SESSION_EXPIRED"),m(!1);return}if(M)throw M;
24u({content:F.insight.content,timestamp:F.insight.created_at,status:F.status,isFresh:F.status==="generated"})}catch(F){if(clearTimeout($),F.name==="AbortError"){o("Insights loading timed out. Please try again."),m(!1);return}if((ze=F==null?void 0:F.message)!=null&&ze.includes("Failed to fetch")||(F==null?void 0:F.name)==="FunctionsFetchError")try{const{data:M,error:O}=await w.functions.invoke("generate-portfolio-insights");if(O)throw O;const ee=((Ve=M.insights)==null?void 0:Ve.map(Ue=>`- **${Ue.title}**: ${Ue.description}`).join(` 25 26`))||"";u({content:ee,timestamp:new Date().toISOString(),status:"error",isFresh:!0}),o("Temporary insights shown (service fallback)")}catch{o("Edge function not available. Please refresh the page.")}else try{const{data:M}=await w.functions.invoke("dashboard-insights",{body:{action:"getLatest"}});if(M!=null&&M.insight)u({content:M.insight.content,timestamp:M.insight.created_at,status:"error",isFresh:!1}),o("Showing last saved insights (generation failed)");else throw F}catch{o("Failed to load insights. Please try again.")}}finally{clearTimeout($),m(!1)}},Cs=async()=>{if(r){m(!0);try{const{data:D,error:T}=await w.functions.invoke("dashboard-insights",{body:{action:"regenerate"}});if(T)throw T;u({content:D.insight.content,timestamp:D.insight.created_at,status:"generated",isFresh:!0}),o(null),S({title:"Insights Refreshed",description:"AI analysis updated with latest data"})}catch{S({title:"Regeneration Failed",description:"Could not generate fresh insights",variant:"destructive"})}finally{m(!1)}}},Ss=()=>{d&&(navigator.clipboard.writeText(d.content),S({title:"Copied",description:"Insights copied to clipboard"}))},ks=async()=>{if(!d||!s)return;const{error:D}=await w.from("saved_messages").insert({user_id:s.id,message_id:crypto.randomUUID(),title:`AI Insights â ${new Date().toLocaleDateString()}`,notes:d.content,tags:["insights","dashboard"]});S(D?{title:"Error",description:"Failed to save to notebook",variant:"destructive"}:{title:"Saved",description:"Insights added to Notebook"})},Ds=async()=>{await w.auth.signOut(),S({title:"Signed out",description:"You have been signed out successfully"}),C("/")},je=l.reduce((D,T)=>D+Number(T.value),0);return l.reduce((D,T)=>{const $=T.category||"Other";return D[$]||(D[$]=[]),D[$].push(T),D},{}),i?e.jsxs("div",{className:"h-full flex flex-col bg-light-grey-bg",children:[e.jsx(He,{title:"Wealth Overview",tagline:"Your unified snapshot of portfolio performance, allocations, and growth metrics.",icon:L}),e.jsx("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:e.jsx(Gs,{})})]}):e.jsxs("div",{className:"h-full flex flex-col bg-light-grey-bg",children:[e.jsx(He,{title:"Wealth Overview",tagline:"Your unified snapshot of portfolio performance, allocations, and growth metrics.",icon:L,actions:e.jsxs(v,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>_(!0),children:[e.jsx(Yt,{className:"h-4 w-4"}),"Customize"]})}),e.jsx(Va,{}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[N.marketPulse&&e.jsx(Ua,{}),N.totalValue&&e.jsx(P,{className:"p-4 md:p-8 mb-8 bg-gradient-to-br from-white via-off-white to-gold-accent/3 border-gold-accent/10",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-start md:justify-between gap-6 md:gap-8",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-muted-grey text-sm mb-2",children:"Total Portfolio Value"}),e.jsx("h3",{className:"text-3xl md:text-5xl font-semibold text-deep-emerald",children:le(je)}),e.jsxs("p",{className:"text-sm text-gold-accent mt-1 mb-4",children:["Currency: ",E]}),e.jsx(Xa,{})]}),e.jsx("div",{className:"flex-1 w-full md:w-auto h-48 md:h-56",children:e.jsx(Vs,{children:e.jsx(Us,{})})})]})}),N.aiBriefing&&e.jsx(er,{}),N.riskExposure&&l.length>0&&e.jsx(Ya,{assets:l,totalValue:je}),N.categoryAllocation&&a.length>0&&e.jsxs(P,{className:"p-6 mb-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-semibold text-deep-emerald mb-2",children:"Allocation â Actual vs Policy Drift"}),e.jsx("p",{className:"text-sm text-muted-grey",children:"Set policy targets in Governance to surface rebalance signals"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(v,{variant:x==="donut"?"default":"outline",size:"sm",onClick:()=>f("donut"),className:x==="donut"?"bg-deep-emerald hover:bg-deep-emerald/90":"",children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),"Chart"]}),e.jsxs(v,{variant:x==="cards"?"default":"outline",size:"sm",onClick:()=>f("cards"),className:x==="cards"?"bg-deep-emerald hover:bg-deep-emerald/90":"",children:[e.jsx(Xt,{className:"h-4 w-4 mr-2"}),"Cards"]})]})]}),e.jsx("div",{className:"transition-all duration-300",children:x==="cards"?e.jsx("div",{className:"animate-in fade-in-50 duration-300",children:e.jsx(Zt,{data:a})}):e.jsx("div",{className:"animate-in fade-in-50 duration-300",children:e.jsx(Jt,{data:a})})})]}),N.healthScore&&e.jsx(Wa,{assets:l,totalValue:je}),N.holdings&&e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold text-deep-emerald",children:"Holdings Snapshot"}),e.jsx("p",{className:"text-sm text-muted-grey",children:"Top positions grouped by category â drill into Portfolio Intelligence for full analytics"})]}),e.jsx(v,{variant:"outline",size:"sm",onClick:()=>C("/app/portfolio"),className:"gap-2",children:"Open Portfolio Intelligence"})]}),e.jsx(Ea,{assets:l})]}),N.watchlist&&e.jsxs("section",{className:"mb-8",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-charcoal uppercase tracking-wide",children:"Market Context"}),e.jsx("p",{className:"text-xs text-muted-grey",children:"Exter
26nal signals â your watchlist, this week's earnings, and top movers"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsx(Ka,{}),e.jsx(Ja,{}),e.jsx(Za,{})]})]}),N.aiInsights&&e.jsxs(P,{className:"p-4 md:p-8 border-2 border-gold-accent/20 shadow-elevation-2",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-4 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3 md:gap-4",children:[e.jsx("div",{className:"w-12 h-12 md:w-14 md:h-14 rounded-2xl bg-gradient-to-br from-gold-accent/20 to-gold-accent/5 flex items-center justify-center flex-shrink-0",children:e.jsx(te,{className:"text-gold-accent",size:24})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl md:text-2xl font-semibold text-charcoal",children:"Strategic Insights"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-grey",children:"Recommended actions with rationale â save to Notebook to revisit"})]})]}),d&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-grey",children:["Updated ",Kt(new Date(d.timestamp),{addSuffix:!0})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(v,{variant:"ghost",size:"sm",onClick:Cs,disabled:p,children:e.jsx(Se,{className:`h-4 w-4 ${p?"animate-spin":""}`})}),e.jsx(v,{variant:"ghost",size:"sm",onClick:Ss,children:e.jsx(Qt,{className:"h-4 w-4"})}),e.jsxs(v,{variant:"outline",size:"sm",onClick:ks,className:"gap-2",children:[e.jsx(qs,{className:"h-4 w-4"}),"Save to Notebook"]})]})]})]}),h&&h!=="SESSION_EXPIRED"&&e.jsxs("div",{className:"mb-4 p-3 rounded-md bg-gold-accent/10 border border-gold-accent/30 flex items-center space-x-2",children:[e.jsx(Ye,{className:"h-4 w-4 text-gold-accent"}),e.jsx("span",{className:"text-xs text-gold-accent",children:h})]}),e.jsx("div",{className:"bg-off-white rounded-lg p-6 border border-soft-border",children:p?e.jsxs("div",{className:"space-y-3",children:[e.jsx(I,{className:"h-4 w-full"}),e.jsx(I,{className:"h-4 w-5/6"}),e.jsx(I,{className:"h-4 w-4/6"})]}):h==="SESSION_EXPIRED"?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(Ye,{className:"h-12 w-12 text-gold-accent mx-auto mb-4"}),e.jsx("p",{className:"text-muted-grey mb-2 font-medium",children:"Your session has expired"}),e.jsx("p",{className:"text-sm text-muted-grey mb-4",children:"Please sign in again to view insights"}),e.jsxs(v,{variant:"default",size:"sm",onClick:Ds,className:"bg-deep-emerald hover:bg-deep-emerald/90",children:[e.jsx(Bs,{className:"h-4 w-4 mr-2"}),"Sign In Again"]})]}):h&&!d?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted-grey mb-4",children:h}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>oe(!1),className:"border-gold-accent text-gold-accent hover:bg-gold-accent/10",children:[e.jsx(Se,{className:"h-4 w-4 mr-2"}),"Retry"]})]}):d?e.jsx(zs,{content:d.content,className:"prose prose-sm max-w-none text-charcoal [&>ul]:list-disc [&>ul]:pl-4 [&>ul>li]:mb-2 [&>p]:mb-4 [&>p]:leading-relaxed [&_strong]:text-deep-emerald [&_strong]:font-semibold"}):e.jsx("p",{className:"text-muted-grey text-center",children:"Add assets to your portfolio to receive AI insights"})})]})]}),e.jsx(sr,{open:j,onOpenChange:_,visibleSections:N,onVisibleSectionsChange:y})]})};export{Un 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.