const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/awm-trading-blotter-xQFjGZ8m.js","assets/index-B_1BLMrZ.js","assets/index-ByKBvrJT.css"])))=>i.map(i=>d[i]);
import{u as ye,r as g,j as e,B as N,Z as Fe,aJ as Ye,G as Je,ag as De,F as X,x as k,I as S,h as ot,N as it,k as Ze,aO as dt,L as P,aG as xt,n as U,cl as Xe,al as ge,aR as ae,aS as le,aT as re,aU as ne,aV as R,a3 as _,bg as me,ae as Le,o as ve,aa as Ee,V as be,a0 as Se,at as ze,ad as Ie,bv as pt,H as mt,b6 as te,aF as ut,P as Ae,T as ht,aD as Ue,a1 as _e,ab as Ke,W as We,cd as Ge,a as W,q as A,b as G,R as Oe,ah as ft,aL as bt,ak as Qe,aW as gt,be as yt}from"./index-B_1BLMrZ.js";import{F as Ne}from"./file-spreadsheet-DOOKiYyy.js";import{a8 as jt}from"./ai-advisor-toolkit-DagTvBTn.js";import{A as He}from"./arrow-left-right-CVXJTtsW.js";import"./bcp-disclosure-Bs9uMRlI.js";const we="#C9A84C",Me="#132a4a";function $(s,t=2){if(s==null||s==="")return"—";const a=typeof s=="string"?parseFloat(s):s;return isNaN(a)?"—":a.toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t})}function ee(s){return s==null?"—":`${s>=0?"+":""}${$(s)}%`}function J(s){return s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"—"}function K(s){if(s==null)return"";let t=String(s);return/^[=+\-@\t\r]/.test(t)&&(t="'"+t),t.includes(",")||t.includes('"')||t.includes(`
`)?`"${t.replace(/"/g,'""')}"`:t}function Y(s){return s==null?"":String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function F(s){if(s==null||s==="")return"";const t=typeof s=="string"?parseFloat(s):s;return isNaN(t)?"":String(t)}function et(s){const t=[["Symbol","Name","Asset Class","Quantity","Cost Basis","Market Value","Unrealized P&L","P&L %","Weight %"]];for(const a of s.holdings||[])t.push([K(a.ticker),K(a.name),K(a.assetClass),F(a.quantity),F(a.costBasis),F(a.marketValue),F(a.unrealizedPnl),F(a.unrealizedPnlPct),F(a.weight)]);return t.map(a=>a.join(",")).join(`
`)}function tt(s){const t=[["Period","TWRR","MWRR","Annualized","Days"]];for(const a of s.performance?.periods||[])t.push([K(a.label),F(a.twrr),F(a.mwrr),String(!!a.annualized),F(a.days)]);t.push([]),t.push(["Monthly Returns"]),t.push(["Month","Return"]);for(const a of s.performance?.monthlyReturns||[])t.push([K(a.month),String(a.return)]);return t.map(a=>a.join(",")).join(`
`)}function st(s){const t=[["Date","Type","Reference","Description","Amount","Status"]];for(const a of s.transactionSummary?.recentTransactions||[])t.push([K(a.date),K(a.type),K(a.ref),K(a.description),String(a.amount),K(a.status)]);return t.map(a=>a.join(",")).join(`
`)}function at(s){const t=[{title:"Asset Class Allocation",data:s.allocation?.assetClass},{title:"Sector Allocation",data:s.allocation?.sector},{title:"Country/Region Allocation",data:s.allocation?.country},{title:"Style Allocation",data:s.allocation?.style}],a=[];for(const c of t){a.push(c.title),a.push("Name,Value,Weight %");for(const n of c.data||[])a.push(`${K(n.name)},${n.value},${n.pct}`);a.push("")}return a.join(`
`)}function lt(s){const t=s.risk||{};return[["Metric","Value"],["Standard Deviation (Ann.)",String(t.standardDeviation??"")],["Max Drawdown",String(t.maxDrawdown??"")],["Sharpe Ratio",String(t.sharpeRatio??"")],["Sortino Ratio",String(t.sortinoRatio??"")],["Alpha",String(t.alpha??"")],["Beta",String(t.beta??"")],["R-Squared",String(t.rSquared??"")],["Tracking Error",String(t.trackingError??"")],["Information Ratio",String(t.informationRatio??"")],["Treynor Ratio",String(t.treynorRatio??"")],["Calmar Ratio",String(t.calmarRatio??"")],["VaR (95%)",String(t.var95??"")],["CVaR (95%)",String(t.cvar95??"")],["Up Capture Ratio",String(t.upCaptureRatio??"")],["Down Capture Ratio",String(t.downCaptureRatio??"")]].map(c=>c.join(",")).join(`
`)}function Nt(s){const t=[];return t.push("AWM GLOBAL ADVISORS — CLIENT INVESTMENT STATEMENT"),t.push(`Account: ${s.account?.name} (${s.account?.code})`),t.push(`Period: ${J(s.reportPeriod?.startDate)} to ${J(s.reportPeriod?.endDate)}`),t.push(`Generated: ${J(s.generatedAt)}`),t.push(""),t.push("SUMMARY"),t.push(`Total Market Value,${F(s.summary?.totalMarketValue)}`),t.push(`Total Cost Basis,${F(s.summary?.totalCostBasis)}`),t.push(`Unrealized P&L,${F(s.summary?.totalUnrealizedPnl)}`),t.push(`Total Return %,${F(s.summary?.totalReturnPct)}`),t.push(`IRR,${F(s.summary?.irr)}`),t.push(`TWRR,${F(s.summary?.twrr)}`),t.push(`MWRR,${F(s.summary?.mwrr)}`),t.push(""),t.push("HOLDINGS"),t.push(et(s)),t.push(""),t.push("PERFORMANCE"),t.push(tt(s)),t.push(""),t.push("ALLOCATION"),t.push(at(s)),t.push(""),t.push("RISK ANALYTICS"),t.push(lt(s)),t.push(""),t.push("TRANSACTIONS"),t.push(st(s)),t.join(`
`)}function Z(s,t,a){const c=new Blob([s],{type:a}),n=URL.createObjectURL(c),r=document.createElement("a");r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function Be(s){const t=(s.holdings||[]).map(m=>`<tr>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;font-family:monospace;font-weight:bold;color:${we}">${Y(m.ticker)||"—"}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0">${Y(m.name)||"—"}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0">${Y(m.assetClass)||"—"}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace">${$(m.quantity,4)}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace">$${$(m.costBasis)}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace">$${$(m.marketValue)}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace;color:${(m.unrealizedPnl||0)>=0?"#16a34a":"#dc2626"}">${ee(m.unrealizedPnlPct)}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace">${$(m.weight,1)}%</td>
    </tr>`).join(""),a=(s.performance?.periods||[]).map(m=>`<tr>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;font-weight:bold">${Y(m.label)}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace;color:${(m.twrr||0)>=0?"#16a34a":"#dc2626"}">${ee(m.twrr)}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace;color:${(m.mwrr||0)>=0?"#16a34a":"#dc2626"}">${ee(m.mwrr)}</td>
      <td style="padding:4px 8px;border-bottom:1px solid #e2e8f0;text-align:right;font-family:monospace">${m.days}d</td>
    </tr>`).join(""),c=(m,x)=>{if(!x||x.length===0)return"";const f=x.map(d=>`<tr>
        <td style="padding:3px 8px;border-bottom:1px solid #f1f5f9">${Y(d.name)}</td>
        <td style="padding:3px 8px;border-bottom:1px solid #f1f5f9;text-align:right;font-family:monospace">$${$(d.value)}</td>
        <td style="padding:3px 8px;border-bottom:1px solid #f1f5f9;text-align:right;font-family:monospace">${$(d.pct,1)}%</td>
      </tr>`).join("");return`<h3 style="font-size:13px;color:#334155;margin:16px 0 6px;border-bottom:1px solid #e2e8f0;padding-bottom:4px">${m}</h3>
    <table style="width:100%;border-collapse:collapse;font-size:11px">
      <thead><tr style="background:#f8fafc"><th style="padding:4px 8px;text-align:left">Category</th><th style="padding:4px 8px;text-align:right">Value</th><th style="padding:4px 8px;text-align:right">Weight</th></tr></thead>
      <tbody>${f}</tbody>
    </table>`},n=s.risk||{},o=[["Standard Deviation (Ann.)",n.standardDeviation!=null?`${$(n.standardDeviation)}%`:"—"],["Max Drawdown",n.maxDrawdown!=null?`${$(n.maxDrawdown)}%`:"—"],["Sharpe Ratio",$(n.sharpeRatio)],["Sortino Ratio",$(n.sortinoRatio)],["Alpha",n.alpha!=null?`${ee(n.alpha)}`:"—"],["Beta",$(n.beta)],["R²",$(n.rSquared)],["VaR (95%)",n.var95!=null?`${$(n.var95)}%`:"—"],["CVaR (95%)",n.cvar95!=null?`${$(n.cvar95)}%`:"—"],["Up Capture",n.upCaptureRatio!=null?`${$(n.upCaptureRatio)}%`:"—"],["Down Capture",n.downCaptureRatio!=null?`${$(n.downCaptureRatio)}%`:"—"]].map(([m,x])=>`<tr><td style="padding:3px 8px;border-bottom:1px solid #f1f5f9">${m}</td><td style="padding:3px 8px;border-bottom:1px solid #f1f5f9;text-align:right;font-family:monospace">${x}</td></tr>`).join(""),u=(s.transactionSummary?.recentTransactions||[]).slice(0,25).map(m=>`<tr>
      <td style="padding:3px 8px;border-bottom:1px solid #f1f5f9;font-family:monospace;font-size:10px">${J(m.date)}</td>
      <td style="padding:3px 8px;border-bottom:1px solid #f1f5f9">${Y(m.type)||"—"}</td>
      <td style="padding:3px 8px;border-bottom:1px solid #f1f5f9">${Y(m.description)||"—"}</td>
      <td style="padding:3px 8px;border-bottom:1px solid #f1f5f9;text-align:right;font-family:monospace">$${$(m.amount)}</td>
    </tr>`).join("");return`<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Client Statement — ${s.account?.name||"Account"}</title>
  <style>
    @page { margin: 0.6in; size: A4; }
    body { font-family: 'Segoe UI', Tahoma, Geneva, sans-serif; font-size: 11px; color: #1e293b; line-height: 1.4; margin: 0; padding: 20px; }
    .header { border-bottom: 3px solid ${we}; padding-bottom: 12px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: flex-end; }
    .bank-name { font-size: 18px; font-weight: bold; color: ${Me}; letter-spacing: 0.5px; }
    .subtitle { font-size: 10px; color: #64748b; margin-top: 2px; }
    .acct-info { text-align: right; }
    .acct-name { font-size: 14px; font-weight: bold; color: #1e293b; }
    .summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
    .summary-box { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 10px; }
    .summary-label { font-size: 9px; text-transform: uppercase; color: #94a3b8; font-weight: bold; letter-spacing: 0.5px; }
    .summary-value { font-size: 16px; font-weight: bold; margin-top: 2px; font-family: monospace; }
    h2 { font-size: 14px; color: ${Me}; margin: 24px 0 8px; border-bottom: 2px solid ${we}; padding-bottom: 4px; page-break-after: avoid; }
    table { width: 100%; border-collapse: collapse; font-size: 10px; }
    thead tr { background: #f8fafc; }
    th { padding: 5px 8px; text-align: left; font-size: 9px; text-transform: uppercase; color: #64748b; font-weight: bold; }
    .footer { margin-top: 30px; padding-top: 10px; border-top: 2px solid ${we}; font-size: 9px; color: #94a3b8; text-align: center; }
    .page-break { page-break-before: always; }
    @media print { body { padding: 0; } }
  </style>
</head>
<body>
  <div class="header">
    <div>
      <div class="bank-name">AWM GLOBAL ADVISORS</div>
      <div class="subtitle">Investment Advisory Services</div>
      <div class="subtitle" style="margin-top:8px;font-weight:bold;color:#1e293b">CLIENT INVESTMENT STATEMENT</div>
    </div>
    <div class="acct-info">
      <div class="acct-name">${Y(s.account?.name)||"—"}</div>
      <div class="subtitle">${Y(s.account?.code)||"—"} · ${Y(s.account?.currency)||"USD"}</div>
      <div class="subtitle">${J(s.reportPeriod?.startDate)} — ${J(s.reportPeriod?.endDate)} (${s.reportPeriod?.days||0} days)</div>
      <div class="subtitle">Generated ${J(s.generatedAt)}</div>
    </div>
  </div>

  <div class="summary-grid">
    <div class="summary-box">
      <div class="summary-label">Total Market Value</div>
      <div class="summary-value" style="color:${Me}">$${$(s.summary?.totalMarketValue)}</div>
    </div>
    <div class="summary-box">
      <div class="summary-label">Total Cost Basis</div>
      <div class="summary-value">$${$(s.summary?.totalCostBasis)}</div>
    </div>
    <div class="summary-box">
      <div class="summary-label">Unrealized P&amp;L</div>
      <div class="summary-value" style="color:${(s.summary?.totalUnrealizedPnl||0)>=0?"#16a34a":"#dc2626"}">$${$(s.summary?.totalUnrealizedPnl)}</div>
    </div>
    <div class="summary-box">
      <div class="summary-label">Total Return</div>
      <div class="summary-value" style="color:${(s.summary?.totalReturnPct||0)>=0?"#16a34a":"#dc2626"}">${ee(s.summary?.totalReturnPct)}</div>
    </div>
  </div>

  <div class="summary-grid" style="grid-template-columns: repeat(3, 1fr)">
    <div class="summary-box">
      <div class="summary-label">IRR</div>
      <div class="summary-value">${ee(s.summary?.irr)}</div>
    </div>
    <div class="summary-box">
      <div class="summary-label">TWRR</div>
      <div class="summary-value">${ee(s.summary?.twrr)}</div>
    </div>
    <div class="summary-box">
      <div class="summary-label">MWRR</div>
      <div class="summary-value">${ee(s.summary?.mwrr)}</div>
    </div>
  </div>

  <h2>Performance</h2>
  <table>
    <thead><tr><th>Period</th><th style="text-align:right">TWRR</th><th style="text-align:right">MWRR</th><th style="text-align:right">Duration</th></tr></thead>
    <tbody>${a}</tbody>
  </table>

  <h2>Holdings (${(s.holdings||[]).length} positions)</h2>
  <table>
    <thead><tr><th>Symbol</th><th>Name</th><th>Class</th><th style="text-align:right">Qty</th><th style="text-align:right">Cost</th><th style="text-align:right">Market</th><th style="text-align:right">P&amp;L</th><th style="text-align:right">Wt%</th></tr></thead>
    <tbody>${t}</tbody>
  </table>

  <div class="page-break"></div>

  <h2>Asset Allocation</h2>
  ${c("By Asset Class",s.allocation?.assetClass)}
  ${c("By Sector",s.allocation?.sector)}
  ${c("By Country/Region",s.allocation?.country)}

  <h2>Risk Analytics</h2>
  <table style="width:50%">
    <thead><tr><th>Metric</th><th style="text-align:right">Value</th></tr></thead>
    <tbody>${o}</tbody>
  </table>

  ${(s.transactionSummary?.recentTransactions||[]).length>0?`
  <h2>Recent Activity</h2>
  <div style="margin-bottom:8px;font-size:10px;color:#64748b">
    Transactions: ${s.transactionSummary?.totalTransactions||0} total · Buys: ${s.transactionSummary?.buys||0} · Sells: ${s.transactionSummary?.sells||0} · Dividends: ${s.transactionSummary?.dividends||0} · Fees: ${s.transactionSummary?.fees||0}
  </div>
  <table>
    <thead><tr><th>Date</th><th>Type</th><th>Description</th><th style="text-align:right">Amount</th></tr></thead>
    <tbody>${u}</tbody>
  </table>`:""}

  <div class="footer">
    <p><strong>AWM Global Advisors LLC</strong></p>
    <p>This report is generated for informational purposes only and does not constitute investment advice. Past performance is not indicative of future results.</p>
    <p>Confidential</p>
  </div>
</body>
</html>`}function vt({statement:s,printRef:t}){const{toast:a}=ye(),[c,n]=g.useState(!1),[r,o]=g.useState(!1),[u,m]=g.useState(!1),[x,f]=g.useState(""),[d,i]=g.useState(""),[L,q]=g.useState(!1),[C,v]=g.useState(!1),E=g.useRef(null),y=s;if(!y)return null;const V=`AWM_Statement_${y.account?.code||"account"}_${y.reportPeriod?.endDate||"report"}`;function ce(){window.print(),n(!1)}function z(){m(!0),n(!1),setTimeout(()=>{if(E.current){const j=E.current.contentDocument||E.current.contentWindow?.document;j&&(j.open(),j.write(Be(y)),j.close())}},100)}function H(){v(!0),n(!1);try{const j=Be(y),je=window.open("","_blank");je?(je.document.write(j),je.document.close(),setTimeout(()=>{je.print(),v(!1)},500)):(Z(j,`${V}.html`,"text/html"),a({title:"PDF preview opened — use browser print to save as PDF"}),v(!1))}catch{a({title:"Failed to generate PDF",variant:"destructive"}),v(!1)}}function ue(){n(!1);const j=Be(y);Z(j,`${V}.html`,"text/html"),a({title:`Downloaded ${V}.html`})}function l(){n(!1);const j=Nt(y);Z(j,`${V}_Full.csv`,"text/csv"),a({title:"Downloaded full statement CSV"})}function p(){n(!1);const j=et(y);Z(j,`${V}_Holdings.csv`,"text/csv"),a({title:"Downloaded holdings CSV"})}function b(){n(!1);const j=tt(y);Z(j,`${V}_Performance.csv`,"text/csv"),a({title:"Downloaded performance CSV"})}function I(){n(!1);const j=st(y);Z(j,`${V}_Transactions.csv`,"text/csv"),a({title:"Downloaded transactions CSV"})}function he(){n(!1);const j=at(y);Z(j,`${V}_Allocation.csv`,"text/csv"),a({title:"Downloaded allocation CSV"})}function Pe(){n(!1);const j=lt(y);Z(j,`${V}_Risk.csv`,"text/csv"),a({title:"Downloaded risk analytics CSV"})}function rt(){n(!1);const j=JSON.stringify(y,null,2);Z(j,`${V}.json`,"application/json"),a({title:"Downloaded statement JSON"})}function nt(){const j=window.location.href;navigator.clipboard.writeText(j).then(()=>{q(!0),setTimeout(()=>q(!1),2e3),a({title:"Link copied to clipboard"})})}function ct(){if(!x){a({title:"Enter an email address",variant:"destructive"});return}const j=encodeURIComponent(`Client Statement — ${y.account?.name} (${y.account?.code})`),je=encodeURIComponent(`Please find the client statement for ${y.account?.name} (${y.account?.code}).

Period: ${J(y.reportPeriod?.startDate)} — ${J(y.reportPeriod?.endDate)}
Total Portfolio Value: $${$(y.summary?.totalMarketValue)}
Total Return: ${ee(y.summary?.totalReturnPct)}

`+(d?`Note: ${d}

`:"")+`Generated by AWM Global Advisors · ${J(y.generatedAt)}`);window.open(`mailto:${x}?subject=${j}&body=${je}`),o(!1),a({title:`Opening email client for ${x}`})}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 relative","data-testid":"export-toolbar",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:z,className:"gap-1 text-xs h-8","data-testid":"button-preview-statement",children:[e.jsx(Fe,{className:"h-3.5 w-3.5"})," Preview"]}),e.jsxs(N,{variant:"outline",size:"sm",onClick:ce,className:"gap-1 text-xs h-8","data-testid":"button-print-statement",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," Print"]}),e.jsxs("div",{className:"relative",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:()=>{n(!c),o(!1)},className:"gap-1 text-xs h-8","data-testid":"button-download-menu",children:[e.jsx(Je,{className:"h-3.5 w-3.5"})," Download ",e.jsx(De,{className:"h-3 w-3"})]}),c&&e.jsxs("div",{className:"absolute right-0 top-9 z-50 bg-white rounded-lg border border-border shadow-xl py-1 w-56","data-testid":"download-dropdown",children:[e.jsx("p",{className:"px-3 py-1.5 text-[9px] text-slate-400 uppercase font-bold tracking-wider",children:"PDF / Print"}),e.jsxs("button",{type:"button",onClick:H,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-pdf",children:[e.jsx(X,{className:"h-3.5 w-3.5 text-red-500"})," Save as PDF (Print Dialog)"]}),e.jsxs("button",{type:"button",onClick:ue,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-html",children:[e.jsx(X,{className:"h-3.5 w-3.5 text-blue-500"})," Download HTML Report"]}),e.jsx("div",{className:"border-t border-border my-1"}),e.jsx("p",{className:"px-3 py-1.5 text-[9px] text-slate-400 uppercase font-bold tracking-wider",children:"CSV Exports"}),e.jsxs("button",{type:"button",onClick:l,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-csv-full",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-emerald-500"})," Full Statement CSV"]}),e.jsxs("button",{type:"button",onClick:p,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-csv-holdings",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-emerald-500"})," Holdings Only"]}),e.jsxs("button",{type:"button",onClick:b,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-csv-performance",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-emerald-500"})," Performance Only"]}),e.jsxs("button",{type:"button",onClick:he,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-csv-allocation",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-emerald-500"})," Allocation Only"]}),e.jsxs("button",{type:"button",onClick:Pe,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-csv-risk",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-emerald-500"})," Risk Analytics Only"]}),e.jsxs("button",{type:"button",onClick:I,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-csv-transactions",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-emerald-500"})," Transactions Only"]}),e.jsx("div",{className:"border-t border-border my-1"}),e.jsx("p",{className:"px-3 py-1.5 text-[9px] text-slate-400 uppercase font-bold tracking-wider",children:"Data"}),e.jsxs("button",{type:"button",onClick:rt,className:"w-full px-3 py-1.5 text-left text-xs hover:bg-slate-50 flex items-center gap-2","data-testid":"download-json",children:[e.jsx(X,{className:"h-3.5 w-3.5 text-amber-500"})," Raw JSON Data"]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:()=>{o(!r),n(!1)},className:"gap-1 text-xs h-8","data-testid":"button-share-menu",children:[e.jsx(jt,{className:"h-3.5 w-3.5"})," Share"]}),r&&e.jsxs("div",{className:"absolute right-0 top-9 z-50 bg-white rounded-lg border border-border shadow-xl p-3 w-72 space-y-3","data-testid":"share-dropdown",children:[e.jsx("p",{className:"text-xs font-bold text-slate-800",children:"Share Statement"}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-500 uppercase font-bold",children:"Email To"}),e.jsx(S,{maxLength:254,value:x,onChange:j=>f(j.target.value),placeholder:"colleague@awmga.com",className:"h-8 text-xs mt-1",type:"email","data-testid":"input-share-email"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-500 uppercase font-bold",children:"Note (optional)"}),e.jsx(ot,{maxLength:5e3,value:d,onChange:j=>i(j.target.value),placeholder:"Optional message...",className:"text-xs mt-1 h-14","data-testid":"input-share-note"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(N,{size:"sm",onClick:ct,className:"flex-1 gap-1 text-xs",style:{backgroundColor:we},"data-testid":"button-send-email",children:[e.jsx(it,{className:"h-3.5 w-3.5"})," Send via Email"]}),e.jsxs(N,{variant:"outline",size:"sm",onClick:nt,className:"gap-1 text-xs","data-testid":"button-copy-link",children:[L?e.jsx(Ze,{className:"h-3.5 w-3.5 text-emerald-500"}):e.jsx(dt,{className:"h-3.5 w-3.5"}),L?"Copied!":"Copy Link"]})]})]})]})]}),u&&e.jsx("div",{className:"fixed inset-0 z-[100] bg-black/50 flex items-center justify-center p-4",onClick:()=>m(!1),"data-testid":"preview-modal",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-2xl w-full max-w-5xl h-[90vh] flex flex-col",onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4",style:{color:we}}),e.jsx("span",{className:"text-sm font-bold text-slate-800",children:"Statement Preview"}),e.jsxs("span",{className:"text-xs text-slate-400",children:[y.account?.name," (",y.account?.code,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(N,{variant:"outline",size:"sm",onClick:H,className:"gap-1 text-xs","data-testid":"preview-download-pdf",children:[C?e.jsx(P,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Je,{className:"h-3.5 w-3.5"})," Save as PDF"]}),e.jsxs(N,{variant:"outline",size:"sm",onClick:()=>{E.current?.contentWindow&&E.current.contentWindow.print()},className:"gap-1 text-xs","data-testid":"preview-print",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," Print"]}),e.jsx("button",{type:"button",onClick:()=>m(!1),className:"text-slate-400 hover:text-slate-600","data-testid":"preview-close",children:e.jsx(xt,{className:"h-5 w-5"})})]})]}),e.jsx("iframe",{ref:E,className:"flex-1 w-full border-0",title:"Statement Preview","data-testid":"preview-iframe"})]})}),c&&e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>n(!1)}),r&&e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>o(!1)})]})}const Ce="#C9A84C",wt="#132a4a";function h(s,t=2){if(s==null||s==="")return"—";const a=typeof s=="string"?parseFloat(s):s;return isNaN(a)?"—":a.toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t})}function M(s,t=2){return s==null?"—":`${s>=0?"+":""}${h(s,t)}%`}function qe(s){return s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"—"}const Ct=[{value:"1M",label:"1 Month"},{value:"3M",label:"3 Months"},{value:"QTD",label:"Quarter to Date"},{value:"YTD",label:"Year to Date"},{value:"1Y",label:"1 Year"},{value:"2Y",label:"2 Years"},{value:"3Y",label:"3 Years"},{value:"5Y",label:"5 Years"},{value:"R12M",label:"Rolling 12 Months"},{value:"SI",label:"Since Inception"},{value:"custom",label:"Custom Date Range"}],de=["#C9A84C","#132a4a","#2563eb","#16a34a","#9333ea","#ea580c","#0891b2","#be185d","#65a30d","#6366f1","#d97706","#475569","#dc2626","#0d9488","#7c3aed"];function $e({slices:s,title:t}){return s.length?e.jsxs("div",{className:"space-y-2","data-testid":`allocation-${t.toLowerCase().replace(/\s/g,"-")}`,children:[e.jsx("h4",{className:"text-xs font-bold text-slate-500 uppercase tracking-wider",children:t}),e.jsx("div",{className:"flex h-6 rounded-md overflow-hidden border border-border",children:s.map((a,c)=>e.jsx("div",{style:{width:`${Math.max(a.pct,1)}%`,backgroundColor:de[c%de.length]},className:"relative group",title:`${a.name}: ${h(a.pct)}%`,children:a.pct>8&&e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[9px] font-bold text-white truncate px-1",children:[h(a.pct,1),"%"]})},a.name))}),e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:s.map((a,c)=>e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{backgroundColor:de[c%de.length]}}),e.jsx("span",{className:"text-slate-700 font-medium",children:a.name}),e.jsxs("span",{className:"text-slate-400",children:[h(a.pct,1),"%"]}),e.jsxs("span",{className:"text-slate-400",children:["($",h(a.value),")"]})]},a.name))})]}):null}function xe({slices:s,size:t=160}){const a=t/2-8,c=t/2,n=t/2;let r=-90;const o=s.map((u,m)=>{const x=u.pct/100*360,f=r*Math.PI/180,d=(r+x)*Math.PI/180;r+=x;const i=c+a*Math.cos(f),L=n+a*Math.sin(f),q=c+a*Math.cos(d),C=n+a*Math.sin(d),v=x>180?1:0,E=a*.55,y=c+E*Math.cos(d),V=n+E*Math.sin(d),ce=c+E*Math.cos(f),z=n+E*Math.sin(f),H=`M ${i} ${L} A ${a} ${a} 0 ${v} 1 ${q} ${C} L ${y} ${V} A ${E} ${E} 0 ${v} 0 ${ce} ${z} Z`;return e.jsx("path",{d:H,fill:de[m%de.length],stroke:"white",strokeWidth:"1",children:e.jsxs("title",{children:[u.name,": ",h(u.pct,1),"%"]})},m)});return e.jsx("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,children:s.length>0?o:e.jsx("circle",{cx:c,cy:n,r:a,fill:"#e2e8f0"})})}function T({children:s,className:t=""}){return e.jsx("div",{className:`rounded-lg border border-slate-200 shadow-sm overflow-hidden ${t}`,style:{background:"linear-gradient(180deg, #ffffff 0%, #f8fafc 100%)"},children:s})}function D({icon:s,title:t,sub:a}){return e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b",style:{borderColor:"#e2e8f0",background:"linear-gradient(90deg, #f1f5f9 0%, #f8fafc 100%)"},children:[e.jsx("div",{className:"flex items-center justify-center h-7 w-7 rounded-md",style:{backgroundColor:"rgba(197, 160, 89, 0.12)"},children:e.jsx(s,{className:"h-4 w-4",style:{color:Ce}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-extrabold tracking-tight",style:{color:"#2d1a0e"},children:t}),a&&e.jsx("p",{className:"text-[10px] text-slate-400 -mt-0.5",children:a})]})]})}function w({label:s,value:t,sub:a,icon:c,color:n,trend:r}){return e.jsxs("div",{className:"rounded-lg border border-slate-200 p-3 space-y-1 shadow-sm",style:{background:"linear-gradient(135deg, #ffffff 0%, #f9f6f1 100%)"},"data-testid":`metric-${s.toLowerCase().replace(/\s/g,"-")}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:s}),c&&e.jsx(c,{className:"h-3.5 w-3.5",style:{color:"rgba(197, 160, 89, 0.4)"}})]}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-lg font-extrabold tracking-tight",style:{color:n||"#1e293b"},children:t}),r&&(r==="up"?e.jsx(Ue,{className:"h-3.5 w-3.5 text-emerald-500"}):r==="down"?e.jsx(De,{className:"h-3.5 w-3.5 text-red-500"}):null)]}),a&&e.jsx("p",{className:"text-[10px] font-medium",style:{color:"#9c8e78"},children:a})]})}function kt({monthlyReturns:s}){if(!s.length)return null;const t=[...new Set(s.map(c=>c.month.split("-")[0]))],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return e.jsx("div",{className:"overflow-x-auto","data-testid":"return-heatmap",children:e.jsxs("table",{className:"text-[10px]",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-2 py-1 text-left text-slate-500 font-bold",children:"Year"}),a.map(c=>e.jsx("th",{className:"px-2 py-1 text-center text-slate-500 font-bold",children:c},c)),e.jsx("th",{className:"px-2 py-1 text-center text-slate-500 font-bold",children:"Annual"})]})}),e.jsx("tbody",{children:t.map(c=>{let n=1;return e.jsxs("tr",{children:[e.jsx("td",{className:"px-2 py-1 font-bold text-slate-700",children:c}),a.map((r,o)=>{const u=`${c}-${String(o+1).padStart(2,"0")}`,m=s.find(d=>d.month===u),x=m?.return||0;m&&(n*=1+x);const f=m?x>.02?"bg-emerald-200 text-emerald-900":x>0?"bg-emerald-100 text-emerald-800":x<-.02?"bg-red-200 text-red-900":x<0?"bg-red-100 text-red-800":"bg-slate-100 text-slate-600":"bg-slate-50";return e.jsx("td",{className:`px-2 py-1 text-center font-mono ${f} border border-white`,children:m?M(x*100,1):""},o)}),e.jsx("td",{className:`px-2 py-1 text-center font-mono font-bold border border-white ${n-1>=0?"bg-emerald-100 text-emerald-900":"bg-red-100 text-red-900"}`,children:M((n-1)*100,1)})]},c)})})]})})}const St=[{id:"summary",label:"Summary",icon:X},{id:"performance",label:"Performance",icon:_},{id:"holdings",label:"Holdings",icon:me},{id:"allocation",label:"Allocation",icon:Le},{id:"benchmark",label:"Benchmark",icon:ve},{id:"risk",label:"Risk Analytics",icon:Ee},{id:"transactions",label:"Activity",icon:be}];function At({accountId:s,onBack:t}){const[a,c]=g.useState("1Y"),[n,r]=g.useState(""),[o,u]=g.useState(""),[m,x]=g.useState("summary"),f=g.useRef(null),d=a==="custom"?`?startDate=${n}&endDate=${o}`:`?period=${a}`,{data:i,isLoading:L,error:q}=U({queryKey:["/api/staff/subledger/statement",s,a,n,o],queryFn:async()=>{const v=await fetch(`/api/staff/subledger/statement/${s}${d}`,{credentials:"include"});if(!v.ok)throw new Error(await v.text());return v.json()},enabled:a!=="custom"||!!n&&!!o});if(L)return e.jsxs("div",{className:"flex items-center justify-center py-24 text-slate-400",children:[e.jsx(P,{className:"h-6 w-6 animate-spin mr-3"}),e.jsx("span",{children:"Generating statement..."})]});if(q)return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(N,{variant:"ghost",onClick:t,className:"gap-2","data-testid":"button-back-statement",children:[e.jsx(Xe,{className:"h-4 w-4"})," Back"]}),e.jsxs("div",{className:"text-center py-12 text-red-500",children:[e.jsx(ge,{className:"h-8 w-8 mx-auto mb-2"}),e.jsx("p",{children:"Failed to generate statement"}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:q.message})]})]});const C=i;return C?e.jsxs("div",{className:"space-y-4",ref:f,"data-testid":"statement-panel",children:[e.jsx("div",{className:"rounded-2xl p-5 relative overflow-hidden",style:{background:"linear-gradient(135deg, #fdf8ee, #fef9f0)",border:"1px solid #e8d5a3",boxShadow:"0 4px 16px rgba(201,168,76,0.08)"},children:e.jsxs("div",{className:"relative flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(N,{variant:"ghost",size:"sm",onClick:t,className:"gap-1 border border-slate-200 text-slate-700 hover:bg-slate-100","data-testid":"button-back-statement",children:[e.jsx(Xe,{className:"h-4 w-4"})," Back"]}),e.jsx("div",{className:"rounded-2xl flex items-center justify-center shrink-0",style:{width:52,height:52,background:"rgba(201,168,76,0.15)",border:"1px solid rgba(201,168,76,0.3)"},children:e.jsx(X,{className:"h-6 w-6",style:{color:"#C9A84C"}})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black text-slate-800 tracking-tight",children:"Client Statement"}),e.jsxs("p",{className:"text-sm text-slate-500",children:[C.account?.name," (",C.account?.code,") · ",C.account?.currency]})]})]}),e.jsxs("div",{className:"relative flex items-center gap-2 flex-wrap",children:[e.jsxs(ae,{value:a,onValueChange:c,children:[e.jsx(le,{className:"w-[180px] text-xs h-8 border-slate-200 bg-white text-slate-700","data-testid":"select-period",children:e.jsx(re,{placeholder:"Select period"})}),e.jsx(ne,{children:Ct.map(v=>e.jsx(R,{value:v.value,children:v.label},v.value))})]}),a==="custom"&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(S,{type:"date",value:n,onChange:v=>r(v.target.value),className:"h-8 text-xs w-32 border-slate-200 bg-white text-slate-700","data-testid":"input-custom-start"}),e.jsx("span",{className:"text-xs text-slate-500",children:"to"}),e.jsx(S,{type:"date",value:o,onChange:v=>u(v.target.value),className:"h-8 text-xs w-32 border-slate-200 bg-white text-slate-700","data-testid":"input-custom-end"})]}),e.jsx(vt,{statement:C,printRef:f})]})]})}),e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{border:"1px solid #e8d5a3",background:"linear-gradient(135deg, #fdf8ee, #fef9f0)",boxShadow:"0 2px 8px rgba(201,168,76,0.08)"},children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4 px-5 py-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest font-bold",style:{color:"#C9A84C"},children:"Report Period"}),e.jsxs("p",{className:"text-base font-extrabold text-slate-800 tracking-tight mt-0.5",children:[qe(C.reportPeriod?.startDate)," — ",qe(C.reportPeriod?.endDate)]}),e.jsxs("p",{className:"text-[10px] font-medium text-slate-400",children:[C.reportPeriod?.days," calendar days · Generated ",new Date(C.generatedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest font-bold",style:{color:"#C9A84C"},children:"Total Portfolio Value"}),e.jsxs("p",{className:"text-3xl font-black tracking-tight text-slate-800 mt-0.5",children:["$",h(C.summary?.totalMarketValue)]}),e.jsxs("p",{className:`text-sm font-bold mt-0.5 ${(C.summary?.totalReturnPct||0)>=0?"text-emerald-600":"text-red-600"}`,children:[M(C.summary?.totalReturnPct)," total return"]})]})]}),e.jsx("div",{className:"h-1",style:{background:`linear-gradient(90deg, ${Ce}, ${wt}, ${Ce})`}})]}),e.jsx("div",{className:"flex gap-0.5 flex-wrap pb-0",style:{borderBottom:"2px solid #e2e8f0"},children:St.map(v=>{const E=v.icon,y=m===v.id;return e.jsxs("button",{type:"button",onClick:()=>x(v.id),className:`flex items-center gap-1.5 px-3.5 py-2 text-xs font-bold transition-all relative ${y?"text-[#2d1a0e]":"text-slate-400 hover:text-slate-600"}`,style:y?{borderBottom:`2px solid ${Ce}`,marginBottom:"-2px"}:{marginBottom:"-2px"},"data-testid":`tab-stmt-${v.id}`,children:[e.jsx(E,{className:"h-3.5 w-3.5",style:y?{color:Ce}:void 0}),v.label]},v.id)})}),m==="summary"&&e.jsx(Rt,{s:C}),m==="performance"&&e.jsx($t,{s:C}),m==="holdings"&&e.jsx(Tt,{s:C}),m==="allocation"&&e.jsx(Dt,{s:C}),m==="benchmark"&&e.jsx(Pt,{s:C}),m==="risk"&&e.jsx(Et,{s:C}),m==="transactions"&&e.jsx(Lt,{s:C}),e.jsxs("div",{className:"text-center pt-4 border-t border-border",children:[e.jsxs("p",{className:"text-[9px] text-slate-400",children:["Statement generated ",new Date(C.generatedAt).toLocaleString()," · AWM Global Advisors LLC · Confidential"]}),e.jsx("p",{className:"text-[9px] text-slate-400",children:"Past performance does not guarantee future results. Values are based on available subledger data."})]})]}):null}function Rt({s}){const t=s.summary||{};return e.jsxs("div",{className:"space-y-5","data-testid":"tab-content-summary",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(w,{label:"Market Value",value:`$${h(t.totalMarketValue)}`,icon:me}),e.jsx(w,{label:"Cost Basis",value:`$${h(t.totalCostBasis)}`,icon:me,color:"#6366f1"}),e.jsx(w,{label:"Unrealized P&L",value:`$${h(t.totalUnrealizedPnl)}`,icon:_,color:(t.totalUnrealizedPnl||0)>=0?"#16a34a":"#dc2626",trend:(t.totalUnrealizedPnl||0)>=0?"up":"down"}),e.jsx(w,{label:"Total Return",value:M(t.totalReturnPct),icon:ve,color:(t.totalReturnPct||0)>=0?"#16a34a":"#dc2626",trend:(t.totalReturnPct||0)>=0?"up":"down"}),e.jsx(w,{label:"IRR",value:M(t.irr),icon:be,sub:"Internal Rate of Return"}),e.jsx(w,{label:"TWRR",value:M(t.twrr),icon:Se,sub:"Time-Weighted Return"}),e.jsx(w,{label:"MWRR",value:M(t.mwrr),icon:ze,sub:"Dollar-Weighted Return"}),e.jsx(w,{label:"Holdings",value:`${t.holdingsCount||0}`,icon:Ie,sub:"Active positions"})]}),s.performance?.periods?.length>0&&e.jsxs(T,{children:[e.jsx(D,{icon:_,title:"Performance by Period"}),e.jsx("div",{className:"overflow-x-auto p-4",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f1f5f9"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Period"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"TWRR"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"MWRR"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Annualized"})]})}),e.jsx("tbody",{children:s.performance.periods.map((a,c)=>e.jsxs("tr",{className:"border-b",style:{borderColor:"#e2e8f0"},"data-testid":`row-period-${a.label}`,children:[e.jsx("td",{className:"px-3 py-2 font-bold",style:{color:"#2d1a0e"},children:a.label}),e.jsx("td",{className:`px-3 py-2 text-right font-mono font-bold ${(a.twrr||0)>=0?"text-emerald-600":"text-red-600"}`,children:M(a.twrr*100)}),e.jsx("td",{className:`px-3 py-2 text-right font-mono ${(a.mwrr||0)>=0?"text-emerald-600":"text-red-600"}`,children:M(a.mwrr*100)}),e.jsx("td",{className:"px-3 py-2 text-right font-mono text-slate-500",children:a.annualized?M(a.annualizedReturn*100):"N/A"})]},c))})]})})]}),s.allocation?.assetClass?.length>0&&e.jsxs(T,{children:[e.jsx(D,{icon:Le,title:"Asset Class Overview"}),e.jsxs("div",{className:"flex items-center gap-6 flex-wrap p-4",children:[e.jsx(xe,{slices:s.allocation.assetClass}),e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsx($e,{slices:s.allocation.assetClass,title:"Asset Class Breakdown"})})]})]}),s.risk&&e.jsxs(T,{children:[e.jsx(D,{icon:Ee,title:"Key Risk Metrics"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(w,{label:"Std Deviation",value:h(s.risk.standardDeviation)+"%",sub:"Annualized"}),e.jsx(w,{label:"Max Drawdown",value:h(s.risk.maxDrawdown)+"%",color:"#dc2626"}),e.jsx(w,{label:"Sharpe Ratio",value:h(s.risk.sharpeRatio)}),e.jsx(w,{label:"Beta",value:h(s.risk.beta)})]})]})]})}function $t({s}){const t=s.performance||{};return e.jsxs("div",{className:"space-y-5","data-testid":"tab-content-performance",children:[e.jsxs(T,{children:[e.jsx(D,{icon:Se,title:"Return Summary by Period"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50 border-b border-border",children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold text-slate-500 uppercase tracking-wider",children:"Period"}),e.jsx("th",{className:"px-3 py-2 text-center font-bold text-slate-500 uppercase tracking-wider",children:"Days"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold text-slate-500 uppercase tracking-wider",children:"Time-Weighted (TWRR)"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold text-slate-500 uppercase tracking-wider",children:"Dollar-Weighted (MWRR)"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold text-slate-500 uppercase tracking-wider",children:"Annualized"})]})}),e.jsx("tbody",{children:(t.periods||[]).map((a,c)=>e.jsxs("tr",{className:"border-b border-border bg-white hover:bg-slate-50",children:[e.jsx("td",{className:"px-3 py-2 font-bold text-slate-700",children:a.label}),e.jsx("td",{className:"px-3 py-2 text-center text-slate-500",children:a.days}),e.jsx("td",{className:`px-3 py-2 text-right font-mono font-bold ${(a.twrr||0)>=0?"text-emerald-600":"text-red-600"}`,children:M(a.twrr*100)}),e.jsx("td",{className:`px-3 py-2 text-right font-mono ${(a.mwrr||0)>=0?"text-emerald-600":"text-red-600"}`,children:M(a.mwrr*100)}),e.jsx("td",{className:"px-3 py-2 text-right font-mono text-slate-500",children:a.annualized?M(a.annualizedReturn*100):"—"})]},c))})]})})]}),t.monthlyReturns?.length>0&&e.jsxs(T,{children:[e.jsx(D,{icon:pt,title:"Monthly Return Heatmap"}),e.jsx("div",{className:"p-4",children:e.jsx(kt,{monthlyReturns:t.monthlyReturns})})]}),t.quarterlyReturns?.length>0&&e.jsxs(T,{children:[e.jsx(D,{icon:ze,title:"Quarterly Returns"}),e.jsx("div",{className:"flex items-end gap-2 h-32 px-4 py-4",children:(t.quarterlyReturns||[]).map((a,c)=>{const n=Math.max(...t.quarterlyReturns.map(u=>Math.abs(u.return)),.01),r=Math.abs(a.return)/n*100,o=a.return>=0;return e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end gap-0.5","data-testid":`bar-quarter-${a.quarter}`,children:[e.jsx("span",{className:`text-[9px] font-mono font-bold ${o?"text-emerald-600":"text-red-600"}`,children:M(a.return*100,1)}),e.jsx("div",{className:`w-full rounded-t ${o?"bg-emerald-400":"bg-red-400"}`,style:{height:`${Math.max(r,4)}%`}}),e.jsx("span",{className:"text-[8px] font-bold",style:{color:"#8c7a5e"},children:a.quarter})]},c)})})]}),t.yearlyReturns?.length>0&&e.jsxs(T,{children:[e.jsx(D,{icon:Se,title:"Annual Returns"}),e.jsx("div",{className:"overflow-x-auto p-4",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f1f5f9"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Year"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase",style:{color:"#8c7a5e"},children:"Return"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Visual"})]})}),e.jsx("tbody",{children:t.yearlyReturns.map((a,c)=>{const n=Math.max(...t.yearlyReturns.map(o=>Math.abs(o.return)),.01),r=Math.abs(a.return)/n*100;return e.jsxs("tr",{className:"border-b",style:{borderColor:"#e2e8f0"},children:[e.jsx("td",{className:"px-3 py-2 font-bold",style:{color:"#2d1a0e"},children:a.year}),e.jsx("td",{className:`px-3 py-2 text-right font-mono font-bold ${a.return>=0?"text-emerald-600":"text-red-600"}`,children:M(a.return*100)}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("div",{className:"h-3 rounded",style:{width:`${Math.max(r,4)}%`,backgroundColor:a.return>=0?"#10b981":"#ef4444"}})})]},c)})})]})})]})]})}function Tt({s}){const t=s.holdings||[],[a,c]=g.useState("marketValue"),[n,r]=g.useState("desc"),o=g.useMemo(()=>[...t].sort((m,x)=>{const f=m[a]||0,d=x[a]||0;return n==="desc"?d-f:f-d}),[t,a,n]),u=m=>{a===m?r(x=>x==="desc"?"asc":"desc"):(c(m),r("desc"))};return e.jsxs("div",{className:"space-y-4","data-testid":"tab-content-holdings",children:[e.jsxs(T,{children:[e.jsx(D,{icon:Ie,title:"Holdings Detail"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f1f5f9"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Ticker"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Name"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Asset Class"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider cursor-pointer",style:{color:"#8c7a5e"},onClick:()=>u("quantity"),children:"Quantity"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider cursor-pointer",style:{color:"#8c7a5e"},onClick:()=>u("closingPrice"),children:"Price"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider cursor-pointer",style:{color:"#8c7a5e"},onClick:()=>u("costBasis"),children:"Cost Basis"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider cursor-pointer",style:{color:"#8c7a5e"},onClick:()=>u("marketValue"),children:"Mkt Value"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider cursor-pointer",style:{color:"#8c7a5e"},onClick:()=>u("unrealizedPnl"),children:"Unreal. P&L"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider cursor-pointer",style:{color:"#8c7a5e"},onClick:()=>u("unrealizedPnlPct"),children:"Return %"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider cursor-pointer",style:{color:"#8c7a5e"},onClick:()=>u("weight"),children:"Weight"})]})}),e.jsx("tbody",{children:o.map((m,x)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-holding-${m.ticker}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono font-bold",style:{color:Ce},children:m.ticker}),e.jsx("td",{className:"px-3 py-2 font-medium",style:{color:"#2d1a0e"},children:m.name}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-bold",style:{background:"#f1f5f9",color:"#8c7a5e"},children:m.assetClass})}),e.jsx("td",{className:"px-3 py-2 text-right font-mono",style:{color:"#2d1a0e"},children:h(m.quantity,4)}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono",style:{color:"#2d1a0e"},children:["$",h(m.closingPrice)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-600",children:["$",h(m.costBasis)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono font-bold",style:{color:"#2d1a0e"},children:["$",h(m.marketValue)]}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono font-bold ${(m.unrealizedPnl||0)>=0?"text-emerald-600":"text-red-600"}`,children:["$",h(m.unrealizedPnl)]}),e.jsx("td",{className:`px-3 py-2 text-right font-mono font-bold ${(m.unrealizedPnlPct||0)>=0?"text-emerald-600":"text-red-600"}`,children:M(m.unrealizedPnlPct)}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-500",children:[h(m.weight,1),"%"]})]},m.instrumentId||x))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"font-bold text-xs",style:{background:"#f1f5f9",borderTop:"2px solid #C9A84C"},children:[e.jsx("td",{className:"px-3 py-2",style:{color:"#2d1a0e"},colSpan:5,children:"PORTFOLIO TOTAL"}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono",style:{color:"#2d1a0e"},children:["$",h(s.summary?.totalCostBasis)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono",style:{color:"#2d1a0e"},children:["$",h(s.summary?.totalMarketValue)]}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono ${(s.summary?.totalUnrealizedPnl||0)>=0?"text-emerald-600":"text-red-600"}`,children:["$",h(s.summary?.totalUnrealizedPnl)]}),e.jsx("td",{className:`px-3 py-2 text-right font-mono ${(s.summary?.totalReturnPct||0)>=0?"text-emerald-600":"text-red-600"}`,children:M(s.summary?.totalReturnPct)}),e.jsx("td",{className:"px-3 py-2 text-right font-mono",style:{color:"#2d1a0e"},children:"100.0%"})]})})]})})]}),!t.length&&e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(me,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No holdings found for this period"})]})]})}function Dt({s}){const t=s.allocation||{};return e.jsxs("div",{className:"space-y-5","data-testid":"tab-content-allocation",children:[e.jsxs(T,{children:[e.jsx(D,{icon:Le,title:"Asset Class Allocation"}),e.jsxs("div",{className:"flex items-center gap-6 flex-wrap p-4",children:[e.jsx(xe,{slices:t.assetClass||[],size:180}),e.jsxs("div",{className:"flex-1 min-w-[250px]",children:[e.jsx($e,{slices:t.assetClass||[],title:"By Asset Class"}),e.jsx("div",{className:"mt-3",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid #e2e8f0"},children:[e.jsx("th",{className:"px-2 py-1 text-left font-bold",style:{color:"#8c7a5e"},children:"Class"}),e.jsx("th",{className:"px-2 py-1 text-right font-bold",style:{color:"#8c7a5e"},children:"Value"}),e.jsx("th",{className:"px-2 py-1 text-right font-bold",style:{color:"#8c7a5e"},children:"Weight"})]})}),e.jsx("tbody",{children:(t.assetClass||[]).map((a,c)=>e.jsxs("tr",{className:"border-b",style:{borderColor:"#e2e8f0"},children:[e.jsxs("td",{className:"px-2 py-1 flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2 h-2 rounded-sm",style:{backgroundColor:de[c%de.length]}}),e.jsx("span",{className:"font-medium",style:{color:"#2d1a0e"},children:a.name})]}),e.jsxs("td",{className:"px-2 py-1 text-right font-mono text-slate-600",children:["$",h(a.value)]}),e.jsxs("td",{className:"px-2 py-1 text-right font-mono font-bold",style:{color:"#2d1a0e"},children:[h(a.pct,1),"%"]})]},a.name))})]})})]})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:Ie,title:"Investment Style Allocation"}),e.jsxs("div",{className:"flex items-center gap-6 flex-wrap p-4",children:[e.jsx(xe,{slices:t.style||[],size:180}),e.jsxs("div",{className:"flex-1 min-w-[250px]",children:[e.jsx($e,{slices:t.style||[],title:"By Style"}),e.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-2 text-[10px]",children:[e.jsxs("div",{className:"rounded p-2 text-center",style:{background:"#f1f5f9"},children:[e.jsx("p",{className:"font-bold",style:{color:"#8c7a5e"},children:"Value"}),e.jsxs("p",{className:"font-bold",style:{color:"#2d1a0e"},children:[h((t.style||[]).filter(a=>a.name.includes("Value")).reduce((a,c)=>a+c.pct,0),1),"%"]})]}),e.jsxs("div",{className:"rounded p-2 text-center",style:{background:"#f1f5f9"},children:[e.jsx("p",{className:"font-bold",style:{color:"#8c7a5e"},children:"Blend"}),e.jsxs("p",{className:"font-bold",style:{color:"#2d1a0e"},children:[h((t.style||[]).filter(a=>a.name.includes("Blend")||!a.name.includes("Value")&&!a.name.includes("Growth")).reduce((a,c)=>a+c.pct,0),1),"%"]})]}),e.jsxs("div",{className:"rounded p-2 text-center",style:{background:"#f1f5f9"},children:[e.jsx("p",{className:"font-bold",style:{color:"#8c7a5e"},children:"Growth"}),e.jsxs("p",{className:"font-bold",style:{color:"#2d1a0e"},children:[h((t.style||[]).filter(a=>a.name.includes("Growth")).reduce((a,c)=>a+c.pct,0),1),"%"]})]})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(T,{children:[e.jsx(D,{icon:mt,title:"Country / Region Allocation"}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(xe,{slices:t.country||[],size:150}),e.jsx($e,{slices:t.country||[],title:"By Country"})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:te,title:"Sector Allocation"}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(xe,{slices:t.sector||[],size:150}),e.jsx($e,{slices:t.sector||[],title:"By Sector"})]})]})]})]})}const Ve=[{name:"Global 60/40",slices:[{name:"US Large Cap Equity",pct:36},{name:"International Developed Equity",pct:15.5},{name:"Emerging Markets Equity",pct:5},{name:"US Small/Mid Cap Equity",pct:3.5},{name:"US Aggregate Bond",pct:24},{name:"International Bond",pct:10},{name:"High Yield Bond",pct:4},{name:"Cash & Equivalents",pct:2}]},{name:"Conservative 30/70",slices:[{name:"US Large Cap Equity",pct:18},{name:"International Equity",pct:8},{name:"Small Cap Equity",pct:4},{name:"US Aggregate Bond",pct:35},{name:"Global Bond",pct:20},{name:"TIPS / Inflation-Protected",pct:10},{name:"Cash & Equivalents",pct:5}]},{name:"Aggressive Growth",slices:[{name:"US Large Cap Growth",pct:30},{name:"US Large Cap Value",pct:15},{name:"US Small Cap",pct:12},{name:"International Developed",pct:18},{name:"Emerging Markets",pct:12},{name:"Real Assets / Commodities",pct:5},{name:"High Yield Bond",pct:5},{name:"Cash",pct:3}]},{name:"Global Bond",slices:[{name:"US Treasury",pct:25},{name:"US Investment Grade Corporate",pct:20},{name:"US Mortgage-Backed (MBS)",pct:15},{name:"International Government Bond",pct:15},{name:"Emerging Markets Bond",pct:8},{name:"High Yield Corporate",pct:7},{name:"TIPS / Inflation-Linked",pct:5},{name:"Cash & Money Market",pct:5}]},{name:"Endowment Model",slices:[{name:"US Equity",pct:20},{name:"International Equity",pct:15},{name:"Private Equity / Alternatives",pct:20},{name:"Real Assets",pct:10},{name:"Hedge Funds",pct:10},{name:"Fixed Income",pct:15},{name:"Natural Resources",pct:5},{name:"Cash",pct:5}]},{name:"Income Focused",slices:[{name:"Dividend Equity",pct:20},{name:"REITs",pct:10},{name:"Preferred Stock",pct:8},{name:"Investment Grade Bond",pct:25},{name:"High Yield Bond",pct:12},{name:"Emerging Market Debt",pct:8},{name:"MLPs / Infrastructure",pct:7},{name:"TIPS",pct:5},{name:"Cash",pct:5}]},{name:"US Equity Only",slices:[{name:"S&P 500 / Large Cap",pct:50},{name:"Mid Cap",pct:20},{name:"Small Cap Value",pct:10},{name:"Small Cap Growth",pct:10},{name:"REITs",pct:5},{name:"Cash",pct:5}]},{name:"Risk Parity",slices:[{name:"US Equity",pct:15},{name:"International Equity",pct:10},{name:"Long-Term Treasuries",pct:30},{name:"TIPS",pct:15},{name:"Commodities",pct:15},{name:"Gold",pct:10},{name:"Cash",pct:5}]}],oe=["#2563eb","#16a34a","#C9A84C","#9333ea","#ea580c","#0891b2","#be185d","#65a30d","#6366f1","#d97706","#475569","#dc2626","#0d9488","#7c3aed","#132a4a"];function Pt({s}){const[t,a]=g.useState(""),[c,n]=g.useState([{name:"US Large Cap Equity",pct:36},{name:"International Developed Equity",pct:15.5},{name:"Emerging Markets Equity",pct:5},{name:"US Small/Mid Cap Equity",pct:3.5},{name:"US Aggregate Bond",pct:24},{name:"International Bond",pct:10},{name:"High Yield Bond",pct:4},{name:"Cash & Equivalents",pct:2}]),r=c.reduce((l,p)=>l+p.pct,0),o=Math.abs(r-100)<.1,u=s.allocation?.assetClass||[],m=l=>{const p=Ve.find(b=>b.name===l);p&&(n(p.slices.map(b=>({...b}))),a(l))},x=(l,p)=>{n(b=>b.map((I,he)=>he===l?{...I,pct:Math.max(0,Math.min(100,p))}:I))},f=(l,p)=>{n(b=>b.map((I,he)=>he===l?{...I,name:p}:I))},d=()=>{const l=Math.max(0,100-r);n(p=>[...p,{name:"New Allocation",pct:l>0?Math.min(l,10):0}])},i=l=>{n(p=>p.filter((b,I)=>I!==l))},L=()=>{r<=0||n(l=>l.map(p=>({...p,pct:Math.round(p.pct/r*1e3)/10})))},q=c.filter(l=>/equity|cap|stock|growth|value|small|mid|large|emerging|international.*eq|reit/i.test(l.name)).reduce((l,p)=>l+p.pct,0),C=c.filter(l=>/bond|fixed|treasury|corporate|mbs|mortgage|tips|inflation|debt|income|yield/i.test(l.name)).reduce((l,p)=>l+p.pct,0),v=c.filter(l=>/alternative|hedge|private|commodity|gold|natural|real.*asset|infrastructure|mlp|preferred/i.test(l.name)).reduce((l,p)=>l+p.pct,0),E=c.filter(l=>/cash|money.*market/i.test(l.name)).reduce((l,p)=>l+p.pct,0),y=100-q-C-v-E,V=u.filter(l=>/equity|etf/i.test(l.name)).reduce((l,p)=>l+p.pct,0),ce=u.filter(l=>/fixed|bond/i.test(l.name)).reduce((l,p)=>l+p.pct,0),z=u.filter(l=>/cash/i.test(l.name)).reduce((l,p)=>l+p.pct,0),H=100-V-ce-z,ue=[{label:"Equity",portfolio:V,benchmark:q},{label:"Fixed Income",portfolio:ce,benchmark:C},{label:"Alternatives",portfolio:0,benchmark:v},{label:"Cash",portfolio:z,benchmark:E},{label:"Other",portfolio:H,benchmark:y>0?y:0}].filter(l=>l.portfolio>.1||l.benchmark>.1);return e.jsxs("div",{className:"space-y-5","data-testid":"tab-content-benchmark",children:[e.jsxs(T,{children:[e.jsx(D,{icon:ut,title:"Benchmark Designer"}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsxs(ae,{value:t,onValueChange:m,children:[e.jsx(le,{className:"w-[200px] text-xs h-8","data-testid":"select-benchmark-preset",children:e.jsx(re,{placeholder:"Load Preset Benchmark..."})}),e.jsx(ne,{children:Ve.map(l=>e.jsx(R,{value:l.name,children:l.name},l.name))})]})}),e.jsx("div",{className:"grid grid-cols-4 gap-2 text-[10px]",children:Ve.map(l=>e.jsxs("button",{type:"button",onClick:()=>m(l.name),className:`p-2 rounded border text-left transition-all ${t===l.name?"border-[#C9A84C] bg-[#fdf8ef] shadow-sm":"border-slate-200 hover:border-slate-300"}`,style:t!==l.name?{background:"linear-gradient(180deg, #ffffff 0%, #f8fafc 100%)"}:{},"data-testid":`button-preset-${l.name.replace(/\s+/g,"-").toLowerCase()}`,children:[e.jsx("p",{className:"font-bold truncate",style:{color:"#2d1a0e"},children:l.name}),e.jsxs("p",{className:"mt-0.5",style:{color:"#8c7a5e"},children:[l.slices.length," components"]})]},l.name))})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:Le,title:"Custom Benchmark Allocation"}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between flex-wrap gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:`text-xs font-bold px-2 py-0.5 rounded ${o?"bg-emerald-100 text-emerald-800":"bg-amber-100 text-amber-800"}`,"data-testid":"text-benchmark-total",children:[h(r,1),"% ",o?"✓ Balanced":`(${r>100?"Over":"Under"} ${h(Math.abs(100-r),1)}%)`]}),!o&&e.jsxs(N,{variant:"outline",size:"sm",onClick:L,className:"text-[10px] h-7 gap-1","data-testid":"button-normalize",children:[e.jsx(Ze,{className:"h-3 w-3"})," Normalize to 100%"]}),e.jsxs(N,{variant:"outline",size:"sm",onClick:d,className:"text-[10px] h-7 gap-1","data-testid":"button-add-slice",children:[e.jsx(Ae,{className:"h-3 w-3"})," Add"]})]})}),e.jsxs("div",{className:"flex gap-6 flex-wrap",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(xe,{slices:c.filter(l=>l.pct>0),size:200})}),e.jsx("div",{className:"flex-1 min-w-[300px] space-y-1.5",children:c.map((l,p)=>e.jsxs("div",{className:"flex items-center gap-2 group","data-testid":`benchmark-slice-${p}`,children:[e.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:oe[p%oe.length]}}),e.jsx(S,{maxLength:255,value:l.name,onChange:b=>f(p,b.target.value),className:"h-7 text-xs flex-1 min-w-[150px]","data-testid":`input-slice-name-${p}`}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(S,{type:"number",value:l.pct,onChange:b=>x(p,parseFloat(b.target.value)||0),className:"h-7 text-xs w-16 text-right font-mono",step:"0.5",min:"0",max:"100","data-testid":`input-slice-pct-${p}`}),e.jsx("span",{className:"text-[10px] text-slate-400 w-3",children:"%"})]}),e.jsx("input",{type:"range",value:l.pct,onChange:b=>x(p,parseFloat(b.target.value)),min:"0",max:"100",step:"0.5",className:"w-24 h-1.5 accent-[#C9A84C] flex-shrink-0","data-testid":`slider-slice-${p}`}),e.jsx(N,{variant:"ghost",size:"sm",onClick:()=>i(p),className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity text-red-400 hover:text-red-600","data-testid":`button-remove-slice-${p}`,children:e.jsx(ht,{className:"h-3 w-3"})})]},p))})]}),e.jsx("div",{className:"flex h-7 rounded-md overflow-hidden border border-border","data-testid":"benchmark-allocation-bar",children:c.filter(l=>l.pct>0).map((l,p)=>e.jsx("div",{style:{width:`${Math.max(l.pct,.5)}%`,backgroundColor:oe[p%oe.length]},className:"relative group transition-all",title:`${l.name}: ${h(l.pct,1)}%`,children:l.pct>6&&e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold text-white truncate px-0.5",children:[h(l.pct,0),"%"]})},p))}),e.jsxs("div",{className:"grid grid-cols-4 gap-2 text-[10px] mt-2",children:[e.jsxs("div",{className:"bg-blue-50 rounded p-2 text-center",children:[e.jsx("p",{className:"font-bold text-blue-600",children:"Equity"}),e.jsxs("p",{className:"font-bold text-blue-800",children:[h(q,1),"%"]})]}),e.jsxs("div",{className:"bg-emerald-50 rounded p-2 text-center",children:[e.jsx("p",{className:"font-bold text-emerald-600",children:"Fixed Income"}),e.jsxs("p",{className:"font-bold text-emerald-800",children:[h(C,1),"%"]})]}),e.jsxs("div",{className:"bg-purple-50 rounded p-2 text-center",children:[e.jsx("p",{className:"font-bold text-purple-600",children:"Alternatives"}),e.jsxs("p",{className:"font-bold text-purple-800",children:[h(v,1),"%"]})]}),e.jsxs("div",{className:"bg-slate-50 rounded p-2 text-center",children:[e.jsx("p",{className:"font-bold text-slate-600",children:"Cash"}),e.jsxs("p",{className:"font-bold text-slate-800",children:[h(E,1),"%"]})]})]})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:Se,title:"Portfolio vs. Benchmark Comparison"}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-8 flex-wrap justify-center",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-wider mb-2",style:{color:"#8c7a5e"},children:"Portfolio"}),e.jsx(xe,{slices:u.length>0?u:[{name:"No Data",pct:100}],size:160}),e.jsxs("p",{className:"text-[10px] mt-1",style:{color:"#8c7a5e"},children:[u.length," classes"]})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-wider mb-2",style:{color:"#8c7a5e"},children:"Benchmark"}),e.jsx(xe,{slices:c.filter(l=>l.pct>0),size:160}),e.jsxs("p",{className:"text-[10px] mt-1",style:{color:"#8c7a5e"},children:[c.filter(l=>l.pct>0).length," components"]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f1f5f9"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Category"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase",style:{color:"#8c7a5e"},children:"Portfolio %"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase",style:{color:"#8c7a5e"},children:"Benchmark %"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase",style:{color:"#8c7a5e"},children:"Deviation"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Visual"})]})}),e.jsx("tbody",{children:ue.map((l,p)=>{const b=l.portfolio-l.benchmark;return e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-comparison-${l.label.toLowerCase().replace(/\s/g,"-")}`,children:[e.jsx("td",{className:"px-3 py-2 font-bold",style:{color:"#2d1a0e"},children:l.label}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono",style:{color:"#2d1a0e"},children:[h(l.portfolio,1),"%"]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono",style:{color:"#2d1a0e"},children:[h(l.benchmark,1),"%"]}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono font-bold ${Math.abs(b)<1?"text-slate-400":b>0?"text-blue-600":"text-amber-600"}`,children:[b>=0?"+":"",h(b,1),"%"]}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-1 h-4",children:[e.jsx("div",{className:"h-3 rounded bg-blue-400",style:{width:`${Math.max(l.portfolio*.8,2)}px`},title:"Portfolio"}),e.jsx("div",{className:"h-3 rounded bg-slate-300 border border-slate-400 border-dashed",style:{width:`${Math.max(l.benchmark*.8,2)}px`},title:"Benchmark"})]})})]},p)})})]})}),e.jsx("div",{className:"flex items-end gap-3 h-40 px-4 pb-2 rounded-lg pt-4",style:{background:"#f1f5f9",border:"1px solid #e2e8f0"},"data-testid":"benchmark-column-chart",children:ue.map((l,p)=>{const b=Math.max(...ue.map(Pe=>Math.max(Pe.portfolio,Pe.benchmark)),1),I=l.portfolio/b*100,he=l.benchmark/b*100;return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-0.5",children:[e.jsxs("div",{className:"flex items-end gap-0.5 w-full justify-center",style:{height:"100px"},children:[e.jsx("div",{className:"w-[35%] rounded-t bg-blue-500 transition-all relative group",style:{height:`${Math.max(I,3)}%`},children:e.jsxs("span",{className:"absolute -top-4 left-1/2 -translate-x-1/2 text-[8px] font-mono font-bold text-blue-600 whitespace-nowrap",children:[h(l.portfolio,0),"%"]})}),e.jsx("div",{className:"w-[35%] rounded-t bg-slate-300 border border-dashed border-slate-400 transition-all relative group",style:{height:`${Math.max(he,3)}%`},children:e.jsxs("span",{className:"absolute -top-4 left-1/2 -translate-x-1/2 text-[8px] font-mono font-bold text-slate-500 whitespace-nowrap",children:[h(l.benchmark,0),"%"]})})]}),e.jsx("span",{className:"text-[9px] font-bold text-slate-500 text-center leading-tight mt-1",children:l.label})]},p)})}),e.jsxs("div",{className:"flex items-center justify-center gap-4 text-[10px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-blue-500"}),e.jsx("span",{className:"font-medium",style:{color:"#8c7a5e"},children:"Portfolio"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-slate-300 border border-dashed border-slate-400"}),e.jsx("span",{className:"font-medium",style:{color:"#8c7a5e"},children:"Benchmark"})]})]})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:X,title:"Benchmark Detail"}),e.jsx("div",{className:"overflow-x-auto p-4",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f1f5f9"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"#"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Component"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase",style:{color:"#8c7a5e"},children:"Weight"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Bar"})]})}),e.jsx("tbody",{children:c.filter(l=>l.pct>0).sort((l,p)=>p.pct-l.pct).map((l,p)=>e.jsxs("tr",{className:"border-b",style:{borderColor:"#e2e8f0"},"data-testid":`row-bm-detail-${p}`,children:[e.jsx("td",{className:"px-3 py-2",style:{color:"#8c7a5e"},children:p+1}),e.jsxs("td",{className:"px-3 py-2 flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{backgroundColor:oe[p%oe.length]}}),e.jsx("span",{className:"font-medium",style:{color:"#2d1a0e"},children:l.name})]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono font-bold",style:{color:"#2d1a0e"},children:[h(l.pct,1),"%"]}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("div",{className:"h-3 rounded",style:{width:`${Math.max(l.pct,2)}%`,backgroundColor:oe[p%oe.length]}})})]},p))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"font-bold",style:{background:"#f1f5f9",borderTop:"2px solid #C9A84C"},children:[e.jsx("td",{className:"px-3 py-2",style:{color:"#2d1a0e"},colSpan:2,children:"TOTAL"}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono ${o?"text-emerald-600":"text-amber-600"}`,children:[h(r,1),"%"]}),e.jsx("td",{className:"px-3 py-2"})]})})]})})]})]})}function Et({s}){const t=s.risk||{};return e.jsxs("div",{className:"space-y-5","data-testid":"tab-content-risk",children:[e.jsxs(T,{children:[e.jsx(D,{icon:Ee,title:"Volatility & Risk Measures"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 p-4",children:[e.jsx(w,{label:"Std Deviation",value:h(t.standardDeviation)+"%",sub:"Annualized volatility",icon:be}),e.jsx(w,{label:"Max Drawdown",value:h(t.maxDrawdown)+"%",sub:"Peak-to-trough",icon:ge,color:"#dc2626"}),e.jsx(w,{label:"Tracking Error",value:h(t.trackingError)+"%",sub:"vs. benchmark",icon:ve}),e.jsx(w,{label:"VaR (95%)",value:h(t.var95)+"%",sub:"Annual Value at Risk",icon:Ee,color:"#9333ea"})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:Se,title:"Risk-Adjusted Return Ratios"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 p-4",children:[e.jsx(w,{label:"Sharpe Ratio",value:h(t.sharpeRatio),sub:"Excess return / volatility",icon:_}),e.jsx(w,{label:"Sortino Ratio",value:h(t.sortinoRatio),sub:"Return / downside deviation",icon:_}),e.jsx(w,{label:"Treynor Ratio",value:h(t.treynorRatio)+"%",sub:"Return / beta",icon:_}),e.jsx(w,{label:"Calmar Ratio",value:h(t.calmarRatio),sub:"Return / max drawdown",icon:_}),e.jsx(w,{label:"Information Ratio",value:h(t.informationRatio),sub:"Active return / tracking error",icon:ve})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:ve,title:"Market Sensitivity (CAPM)"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 p-4",children:[e.jsx(w,{label:"Alpha",value:M(t.alpha),sub:"Excess return vs. CAPM",icon:_,color:(t.alpha||0)>=0?"#16a34a":"#dc2626",trend:(t.alpha||0)>=0?"up":"down"}),e.jsx(w,{label:"Beta",value:h(t.beta),sub:"Market sensitivity",icon:be,color:Math.abs(t.beta-1)<.1?"#6366f1":t.beta>1?"#dc2626":"#16a34a"}),e.jsx(w,{label:"R-Squared",value:h(t.rSquared*100)+"%",sub:"Variance explained by market",icon:ve}),e.jsx(w,{label:"CVaR (95%)",value:h(t.cvar95)+"%",sub:"Expected shortfall",icon:ge,color:"#dc2626"})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:ze,title:"Capture Ratios"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 p-4",children:[e.jsx(w,{label:"Up Capture",value:h(t.upCaptureRatio)+"%",sub:"Participation in up markets",icon:Ue,color:"#16a34a",trend:"up"}),e.jsx(w,{label:"Down Capture",value:h(t.downCaptureRatio)+"%",sub:"Exposure in down markets",icon:De,color:"#dc2626",trend:"down"})]})]}),e.jsxs(T,{children:[e.jsx(D,{icon:X,title:"Complete Risk Dashboard"}),e.jsx("div",{className:"overflow-x-auto p-4",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f1f5f9"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Metric"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase",style:{color:"#8c7a5e"},children:"Value"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Description"})]})}),e.jsx("tbody",{children:[{metric:"Standard Deviation",value:h(t.standardDeviation)+"%",desc:"Annualized portfolio volatility measuring total risk"},{metric:"Maximum Drawdown",value:h(t.maxDrawdown)+"%",desc:"Largest peak-to-trough decline"},{metric:"Sharpe Ratio",value:h(t.sharpeRatio),desc:"Risk-adjusted return per unit of total risk (vs. risk-free rate)"},{metric:"Sortino Ratio",value:h(t.sortinoRatio),desc:"Return per unit of downside risk only"},{metric:"Alpha (Jensen's)",value:M(t.alpha),desc:"Excess return vs. CAPM expected return"},{metric:"Beta",value:h(t.beta),desc:"Systematic risk / market sensitivity (1.0 = market)"},{metric:"R-Squared",value:h(t.rSquared*100)+"%",desc:"Proportion of variance explained by benchmark"},{metric:"Treynor Ratio",value:h(t.treynorRatio)+"%",desc:"Risk-adjusted return per unit of systematic risk"},{metric:"Information Ratio",value:h(t.informationRatio),desc:"Active return per unit of tracking error"},{metric:"Tracking Error",value:h(t.trackingError)+"%",desc:"Standard deviation of active returns vs. benchmark"},{metric:"Calmar Ratio",value:h(t.calmarRatio),desc:"Annualized return divided by maximum drawdown"},{metric:"Value at Risk (95%)",value:h(t.var95)+"%",desc:"Max expected annual loss at 95% confidence"},{metric:"CVaR / Expected Shortfall (95%)",value:h(t.cvar95)+"%",desc:"Average loss beyond VaR threshold"},{metric:"Up Capture Ratio",value:h(t.upCaptureRatio)+"%",desc:"Portfolio participation in up-market periods"},{metric:"Down Capture Ratio",value:h(t.downCaptureRatio)+"%",desc:"Portfolio exposure in down-market periods"}].map((a,c)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},children:[e.jsx("td",{className:"px-3 py-2 font-bold",style:{color:"#2d1a0e"},children:a.metric}),e.jsx("td",{className:"px-3 py-2 text-right font-mono font-bold",style:{color:"#2d1a0e"},children:a.value}),e.jsx("td",{className:"px-3 py-2 max-w-xs",style:{color:"#8c7a5e"},children:a.desc})]},c))})]})})]})]})}function Lt({s}){const t=s.transactionSummary||{};return e.jsxs("div",{className:"space-y-4","data-testid":"tab-content-transactions",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsx(w,{label:"Total Transactions",value:`${t.totalTransactions||0}`,icon:be}),e.jsx(w,{label:"Buys / Deposits",value:`${t.buys||0}`,icon:Ue,color:"#16a34a"}),e.jsx(w,{label:"Sells / Withdrawals",value:`${t.sells||0}`,icon:De,color:"#dc2626"}),e.jsx(w,{label:"Dividends",value:`${t.dividends||0}`,icon:me,color:"#C9A84C"}),e.jsx(w,{label:"Fees",value:`${t.fees||0}`,icon:ge,color:"#6366f1"})]}),(t.recentTransactions||[]).length>0&&e.jsxs(T,{children:[e.jsx(D,{icon:be,title:"Recent Activity"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"#f1f5f9"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Date"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Reference"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Description"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase",style:{color:"#8c7a5e"},children:"Amount"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase",style:{color:"#8c7a5e"},children:"Status"})]})}),e.jsx("tbody",{children:(t.recentTransactions||[]).map((a,c)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-stmt-txn-${c}`,children:[e.jsx("td",{className:"px-3 py-2",style:{color:"#8c7a5e"},children:qe(a.date)}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-bold",style:{background:"#f1f5f9",color:"#8c7a5e"},children:a.type})}),e.jsx("td",{className:"px-3 py-2 font-mono",style:{color:"#8c7a5e"},children:a.ref||"—"}),e.jsx("td",{className:"px-3 py-2 max-w-[200px] truncate",style:{color:"#2d1a0e"},children:a.description||"—"}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono font-bold ${a.amount>=0?"text-slate-800":"text-red-600"}`,children:["$",h(Math.abs(a.amount))]}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold ${a.status==="SETTLED"?"bg-emerald-100 text-emerald-800":a.status==="REVERSED"?"bg-red-100 text-red-800":"bg-amber-100 text-amber-800"}`,children:a.status})})]},c))})]})})]}),!(t.recentTransactions||[]).length&&e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(be,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No transactions in this period"})]})]})}const It=g.lazy(()=>gt(()=>import("./awm-trading-blotter-xQFjGZ8m.js"),__vite__mapDeps([0,1,2]))),O="#C9A84C",Q="#132a4a";function B(s,t=2){if(s==null||s==="")return"—";const a=typeof s=="string"?parseFloat(s):s;return isNaN(a)?"—":a.toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t})}function fe(s){if(s==null||s==="")return"—";const t=typeof s=="string"?parseInt(s,10):s;return isNaN(t)?"—":t.toLocaleString("en-US")}function se(s){return s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"—"}function ke(s){if(!s)return"—";const t=new Date(s);return t.toLocaleDateString("en-US",{month:"short",day:"numeric"})+" "+t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Re({active:s,onClick:t,children:a,testId:c,activeStyle:n,inactiveClass:r}){return e.jsx("button",{type:"button",onClick:t,"data-testid":c,className:`px-3 py-1.5 text-xs font-bold uppercase rounded-md transition-colors ${s?"":r||"text-slate-500 bg-slate-100 border border-slate-200"}`,style:s?n||{background:Q,color:"#fff"}:void 0,children:a})}function Te({open:s,onClose:t,title:a,children:c}){return s?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:e.jsxs("div",{className:"bg-white rounded-md border border-border shadow-lg w-full max-w-lg max-h-[90vh] overflow-y-auto mx-4",onClick:n=>n.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[e.jsx("h3",{className:"text-base font-bold text-slate-800",children:a}),e.jsx("button",{type:"button",onClick:t,className:"text-slate-400 text-lg","data-testid":"button-modal-close",children:"×"})]}),e.jsx("div",{className:"px-5 py-4 space-y-4",children:c})]})}):null}function ie({label:s,value:t,icon:a,color:c}){return e.jsxs("div",{className:"rounded-md border border-border p-4 bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsx(a,{className:"h-4 w-4",style:{color:c||O}}),e.jsx("span",{className:"text-2xl font-bold text-slate-800",children:t})]}),e.jsx("p",{className:"text-xs text-slate-500",children:s})]})}function pe({status:s}){const a={ACTIVE:{bg:"bg-emerald-100 text-emerald-800",text:"Active"},INACTIVE:{bg:"bg-slate-100 text-slate-600",text:"Inactive"},PENDING:{bg:"bg-amber-100 text-amber-800",text:"Pending"},SETTLED:{bg:"bg-emerald-100 text-emerald-800",text:"Settled"},REVERSED:{bg:"bg-red-100 text-red-800",text:"Reversed"},MANUAL_REVIEW:{bg:"bg-blue-100 text-blue-800",text:"Manual Review"},CLEAN:{bg:"bg-emerald-100 text-emerald-800",text:"Clean"},BREAKS_FOUND:{bg:"bg-red-100 text-red-800",text:"Breaks Found"},RUNNING:{bg:"bg-blue-100 text-blue-800",text:"Running"},INVESTIGATING:{bg:"bg-amber-100 text-amber-800",text:"Investigating"},RESOLVED:{bg:"bg-emerald-100 text-emerald-800",text:"Resolved"},ESCALATED:{bg:"bg-red-100 text-red-800",text:"Escalated"},OPEN:{bg:"bg-amber-100 text-amber-800",text:"Open"},SNAPSHOT_LOCKED:{bg:"bg-blue-100 text-blue-800",text:"Snapshot Locked"},ALLOCATED:{bg:"bg-emerald-100 text-emerald-800",text:"Allocated"},FAILED:{bg:"bg-red-100 text-red-800",text:"Failed"}}[s]||{bg:"bg-slate-100 text-slate-600",text:s};return e.jsx("span",{className:`inline-block px-2 py-0.5 rounded text-[10px] font-bold uppercase ${a.bg}`,children:a.text})}const Mt=[{id:"dashboard",label:"Dashboard",icon:Se},{id:"accounts",label:"Accounts",icon:te},{id:"instruments",label:"Instruments",icon:Ke},{id:"transactions",label:"Transactions",icon:He},{id:"trading-blotter",label:"Trading Blotter",icon:Ie},{id:"positions",label:"Positions",icon:_},{id:"reconciliation",label:"Reconciliation",icon:We},{id:"corporate-actions",label:"Corp Actions",icon:me},{id:"statements",label:"Statements",icon:X},{id:"trial-balance",label:"Trial Balance",icon:_e},{id:"audit-log",label:"Audit Log",icon:Ge}];function Bt(){const{toast:s}=ye(),{data:t,isLoading:a}=U({queryKey:["/api/staff/subledger/dashboard"]}),c=U({queryKey:["/api/staff/ibkr/health"]}),[n,r]=g.useState(null),o=W({mutationFn:async()=>(await G("POST","/api/staff/ibkr/sync/full")).json(),onSuccess:d=>{r(d),A.invalidateQueries({queryKey:["/api/staff/subledger"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/accounts"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/positions"]});const i=d.accounts?.accountsSynced||0,L=d.positions?.positionsSynced||0;s({title:`Synced ${i} accounts, ${L} positions from IBKR`})},onError:()=>s({title:"IBKR sync failed",variant:"destructive"})}),u=W({mutationFn:async()=>(await G("POST","/api/staff/ibkr/sync/accounts")).json(),onSuccess:d=>{r(d),A.invalidateQueries({queryKey:["/api/staff/subledger"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/accounts"]}),s({title:`Synced ${d.accountsSynced||0} accounts from IBKR`})},onError:()=>s({title:"Account sync failed",variant:"destructive"})}),m=W({mutationFn:async()=>(await G("POST","/api/staff/ibkr/sync/positions")).json(),onSuccess:d=>{r(d),A.invalidateQueries({queryKey:["/api/staff/subledger"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/positions"]}),s({title:`Synced ${d.positionsSynced||0} positions from IBKR`})},onError:()=>s({title:"Position sync failed",variant:"destructive"})});if(a)return e.jsxs("div",{className:"flex items-center justify-center py-16 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading dashboard..."]});const x=t||{},f=!!c.data?.ibkr_tws_connected||!!c.data?.ibkr_portal_active;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border p-4",style:{background:"linear-gradient(135deg, rgba(19,42,74,0.04) 0%, rgba(197,160,89,0.06) 100%)",borderColor:"#d1c9b8"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center",style:{background:"rgba(197,160,89,0.15)"},children:e.jsx(Oe,{size:16,style:{color:O}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-extrabold",style:{color:"#0f172a"},children:"Interactive Brokers → Subledger Feed"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-0.5",children:"Sync client accounts, positions, and balances from IBKR into the subledger"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("div",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[11px] font-bold ${f?"bg-green-50 text-green-700":"bg-red-50 text-red-600"}`,children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${f?"bg-green-500":"bg-red-500"}`}),"IBKR ",f?"Connected":"Not Connected"]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(N,{size:"sm",className:"h-8 text-xs font-bold text-white",style:{background:O},onClick:()=>u.mutate(),disabled:u.isPending,"data-testid":"btn-sl-sync-accounts",children:[u.isPending?e.jsx(P,{size:12,className:"animate-spin mr-1"}):e.jsx(te,{size:12,className:"mr-1"}),"Sync Accounts"]}),e.jsxs(N,{size:"sm",className:"h-8 text-xs font-bold text-white",style:{background:O},onClick:()=>m.mutate(),disabled:m.isPending,"data-testid":"btn-sl-sync-positions",children:[m.isPending?e.jsx(P,{size:12,className:"animate-spin mr-1"}):e.jsx(_,{size:12,className:"mr-1"}),"Sync Positions"]}),e.jsxs(N,{size:"sm",className:"h-8 text-xs font-bold text-white",style:{background:Q},onClick:()=>o.mutate(),disabled:o.isPending,"data-testid":"btn-sl-full-sync",children:[o.isPending?e.jsx(P,{size:12,className:"animate-spin mr-1"}):e.jsx(Oe,{size:12,className:"mr-1"}),"Full Sync (Accounts + Positions + Balances)"]})]}),n&&e.jsxs("div",{className:"mt-3 p-3 rounded border text-xs",style:{background:"#ffffff",borderColor:"#e2e8f0"},children:[e.jsx("span",{className:"font-bold",style:{color:"#2d1a0e"},children:"Last Sync Result:"}),e.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-x-6 gap-y-1 text-slate-700",children:[n.accountsSynced!==void 0&&e.jsxs("div",{children:["Accounts synced: ",e.jsx("strong",{children:n.accountsSynced})]}),n.accountsCreated!==void 0&&e.jsxs("div",{children:["Accounts created: ",e.jsx("strong",{children:n.accountsCreated})]}),n.positionsSynced!==void 0&&e.jsxs("div",{children:["Positions synced: ",e.jsx("strong",{children:n.positionsSynced})]}),n.instrumentsCreated!==void 0&&e.jsxs("div",{children:["Instruments created: ",e.jsx("strong",{children:n.instrumentsCreated})]}),n.accounts&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Accounts: ",e.jsx("strong",{children:n.accounts.accountsSynced})," synced, ",e.jsx("strong",{children:n.accounts.accountsCreated})," created"]}),e.jsxs("div",{children:["Positions: ",e.jsx("strong",{children:n.positions?.positionsSynced||0})," synced"]}),e.jsxs("div",{children:["Balances: ",e.jsx("strong",{children:n.balances?.accountsUpdated||0})," updated"]})]}),Array.isArray(n.errors)&&n.errors.length>0&&e.jsx("div",{className:"col-span-2 text-red-600 mt-1",children:n.errors.map((d,i)=>e.jsxs("div",{children:["⚠ ",d]},i))}),n.accounts?.errors?.length>0&&e.jsx("div",{className:"col-span-2 text-red-600 mt-1",children:n.accounts.errors.map((d,i)=>e.jsxs("div",{children:["⚠ ",d]},i))})]})]}),!f&&e.jsx("p",{className:"mt-2 text-[11px] text-amber-700 bg-amber-50 rounded px-2 py-1 border border-amber-200",children:"IBKR Gateway is not connected. Go to IBKR Dashboard → Overview → Connect TWS first, then return here to sync."})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(ie,{label:"Total Accounts",value:fe(x.totalAccounts||0),icon:te}),e.jsx(ie,{label:"Client Accounts",value:fe(x.clientAccounts||0),icon:te,color:"#3b82f6"}),e.jsx(ie,{label:"System Accounts",value:fe(x.systemAccounts||0),icon:te,color:"#8b5cf6"}),e.jsx(ie,{label:"Total Transactions",value:fe(x.totalTransactions||0),icon:He}),e.jsx(ie,{label:"Pending Transactions",value:fe(x.pendingTransactions||0),icon:ft,color:"#f59e0b"}),e.jsx(ie,{label:"Instruments",value:fe(x.totalInstruments||0),icon:Ke}),e.jsx(ie,{label:"Open Breaks",value:fe(x.openBreaks||0),icon:ge,color:"#ef4444"}),e.jsx(ie,{label:"Total Position Value",value:`$${B(x.totalPositionValue||0)}`,icon:me,color:"#10b981"})]}),x.lastReconciliation&&e.jsxs("div",{className:"rounded-md border border-border p-4 bg-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(We,{className:"h-4 w-4",style:{color:O}}),e.jsx("span",{className:"text-sm font-bold text-slate-800",children:"Last Reconciliation"})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap text-xs text-slate-600",children:[e.jsx(pe,{status:x.lastReconciliation.runStatus||"CLEAN"}),e.jsx("span",{children:ke(x.lastReconciliation.runCompletedAt||x.lastReconciliation.runStartedAt)}),x.lastReconciliation.totalBreaks!=null&&e.jsxs("span",{children:[x.lastReconciliation.totalBreaks," breaks found"]})]})]})]})}function Vt(){const{toast:s}=ye(),[t,a]=g.useState("ALL"),[c,n]=g.useState(!1),[r,o]=g.useState({accountCode:"",accountName:"",accountType:"CLIENT",currency:"USD",clientId:""}),{data:u=[],isLoading:m}=U({queryKey:["/api/staff/subledger/accounts"]}),x=W({mutationFn:async d=>{await G("POST","/api/staff/subledger/accounts",d)},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/accounts"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Account created"}),n(!1),o({accountCode:"",accountName:"",accountType:"CLIENT",currency:"USD",clientId:""})},onError:()=>s({title:"Failed to create account",variant:"destructive"})}),f=t==="ALL"?u:u.filter(d=>d.accountType===t||d.type===t);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:["ALL","CLIENT","SYSTEM","MASTER"].map(d=>e.jsx(Re,{active:t===d,onClick:()=>a(d),testId:`filter-accounts-${d.toLowerCase()}`,children:d},d))}),e.jsxs(N,{onClick:()=>n(!0),className:"gap-1.5 font-bold",style:{background:Q,color:"#fff"},"data-testid":"button-new-account",children:[e.jsx(Ae,{className:"h-4 w-4"})," New Account"]})]}),m?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):f.length===0?e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(te,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No accounts found"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Code"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Name"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Subtype"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Currency"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Status"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Opened"})]})}),e.jsx("tbody",{children:f.map((d,i)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-account-${d.id||i}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono font-bold",style:{color:O},children:d.accountCode||d.code||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-800 font-medium",children:d.accountName||d.name||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:d.accountType||d.type||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:d.accountSubtype||d.subtype||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:d.currency||"USD"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(pe,{status:d.isActive?"ACTIVE":"INACTIVE"})}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:se(d.openedDate)})]},d.id||i))})]})}),e.jsxs(Te,{open:c,onClose:()=>n(!1),title:"New Account",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Account Code"}),e.jsx(S,{maxLength:100,value:r.accountCode,onChange:d=>o({...r,accountCode:d.target.value}),placeholder:"e.g. CLI-001","data-testid":"input-account-code"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Account Name"}),e.jsx(S,{maxLength:100,value:r.accountName,onChange:d=>o({...r,accountName:d.target.value}),placeholder:"e.g. John Smith Trading","data-testid":"input-account-name"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Account Type"}),e.jsxs(ae,{value:r.accountType,onValueChange:d=>o({...r,accountType:d}),children:[e.jsx(le,{"data-testid":"select-account-type",children:e.jsx(re,{})}),e.jsxs(ne,{children:[e.jsx(R,{value:"CLIENT",children:"Client"}),e.jsx(R,{value:"SYSTEM",children:"System"}),e.jsx(R,{value:"MASTER",children:"Master"})]})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Currency"}),e.jsxs(ae,{value:r.currency,onValueChange:d=>o({...r,currency:d}),children:[e.jsx(le,{"data-testid":"select-account-currency",children:e.jsx(re,{})}),e.jsxs(ne,{children:[e.jsx(R,{value:"USD",children:"USD"}),e.jsx(R,{value:"EUR",children:"EUR"}),e.jsx(R,{value:"GBP",children:"GBP"}),e.jsx(R,{value:"KYD",children:"KYD"})]})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Client ID (optional)"}),e.jsx(S,{maxLength:100,value:r.clientId,onChange:d=>o({...r,clientId:d.target.value}),placeholder:"Optional","data-testid":"input-account-client-id"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(N,{variant:"outline",onClick:()=>n(!1),"data-testid":"button-cancel-account",children:"Cancel"}),e.jsx(N,{onClick:()=>x.mutate(r),disabled:x.isPending||!r.accountCode||!r.accountName,style:{background:Q,color:"#fff"},"data-testid":"button-submit-account",children:x.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):"Create Account"})]})]})]})}function Ft(){const{toast:s}=ye(),[t,a]=g.useState("ALL"),[c,n]=g.useState(!1),[r,o]=g.useState({ticker:"",instrumentName:"",assetClass:"EQUITY",cusip:"",isin:"",exchange:"",ibkrConId:""}),{data:u=[],isLoading:m}=U({queryKey:["/api/staff/subledger/instruments"]}),x=W({mutationFn:async i=>{await G("POST","/api/staff/subledger/instruments",i)},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/instruments"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Instrument created"}),n(!1),o({ticker:"",instrumentName:"",assetClass:"EQUITY",cusip:"",isin:"",exchange:"",ibkrConId:""})},onError:()=>s({title:"Failed to create instrument",variant:"destructive"})}),f=["ALL","EQUITY","FIXED_INCOME","ETF","FUND","CASH","MONEY_MARKET"],d=t==="ALL"?u:u.filter(i=>i.assetClass===t);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:f.map(i=>e.jsx(Re,{active:t===i,onClick:()=>a(i),testId:`filter-instruments-${i.toLowerCase()}`,children:i.replace("_"," ")},i))}),e.jsxs(N,{onClick:()=>n(!0),className:"gap-1.5 font-bold",style:{background:Q,color:"#fff"},"data-testid":"button-new-instrument",children:[e.jsx(Ae,{className:"h-4 w-4"})," New Instrument"]})]}),m?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):d.length===0?e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(Ke,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No instruments found"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Ticker"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Name"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Asset Class"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"CUSIP"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"ISIN"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Exchange"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"IBKR ConID"})]})}),e.jsx("tbody",{children:d.map((i,L)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-instrument-${i.id||L}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono font-bold",style:{color:O},children:i.ticker||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-800 font-medium",children:i.instrumentName||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:i.assetClass||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-500 font-mono",children:i.cusip||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-500 font-mono",children:i.isin||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:i.exchange||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-500 font-mono",children:i.ibkrConId||"—"})]},i.id||L))})]})}),e.jsxs(Te,{open:c,onClose:()=>n(!1),title:"New Instrument",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Ticker"}),e.jsx(S,{maxLength:100,value:r.ticker,onChange:i=>o({...r,ticker:i.target.value}),placeholder:"e.g. AAPL","data-testid":"input-instrument-ticker"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Name"}),e.jsx(S,{maxLength:100,value:r.instrumentName,onChange:i=>o({...r,instrumentName:i.target.value}),placeholder:"e.g. Apple Inc.","data-testid":"input-instrument-name"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Asset Class"}),e.jsxs(ae,{value:r.assetClass,onValueChange:i=>o({...r,assetClass:i}),children:[e.jsx(le,{"data-testid":"select-instrument-asset-class",children:e.jsx(re,{})}),e.jsx(ne,{children:["EQUITY","FIXED_INCOME","ETF","FUND","CASH","MONEY_MARKET"].map(i=>e.jsx(R,{value:i,children:i.replace("_"," ")},i))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"CUSIP"}),e.jsx(S,{maxLength:100,value:r.cusip,onChange:i=>o({...r,cusip:i.target.value}),placeholder:"Optional","data-testid":"input-instrument-cusip"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"ISIN"}),e.jsx(S,{maxLength:100,value:r.isin,onChange:i=>o({...r,isin:i.target.value}),placeholder:"Optional","data-testid":"input-instrument-isin"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Exchange"}),e.jsx(S,{maxLength:100,value:r.exchange,onChange:i=>o({...r,exchange:i.target.value}),placeholder:"e.g. NASDAQ","data-testid":"input-instrument-exchange"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"IBKR ConID"}),e.jsx(S,{maxLength:255,value:r.ibkrConId,onChange:i=>o({...r,ibkrConId:i.target.value}),placeholder:"Optional","data-testid":"input-instrument-conid"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(N,{variant:"outline",onClick:()=>n(!1),"data-testid":"button-cancel-instrument",children:"Cancel"}),e.jsx(N,{onClick:()=>x.mutate(r),disabled:x.isPending||!r.ticker||!r.instrumentName,style:{background:Q,color:"#fff"},"data-testid":"button-submit-instrument",children:x.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):"Create Instrument"})]})]})]})}function Ot(){const{toast:s}=ye(),[t,a]=g.useState("ALL"),[c,n]=g.useState("ALL"),[r,o]=g.useState(!1),[u,m]=g.useState(null),[x,f]=g.useState({transactionType:"DEPOSIT",tradeDate:"",effectiveDate:"",legs:[{accountId:"",legType:"DR",amount:"",instrumentId:"",quantity:"",unitPrice:""}]}),{data:d=[],isLoading:i}=U({queryKey:["/api/staff/subledger/transactions"]}),L=W({mutationFn:async l=>{await G("POST","/api/staff/subledger/transactions",l)},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/transactions"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Transaction posted"}),o(!1),f({transactionType:"DEPOSIT",tradeDate:"",effectiveDate:"",legs:[{accountId:"",legType:"DR",amount:"",instrumentId:"",quantity:"",unitPrice:""}]})},onError:()=>s({title:"Failed to post transaction",variant:"destructive"})}),q=W({mutationFn:async l=>{await G("POST",`/api/staff/subledger/transactions/${l}/reverse`,{})},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/transactions"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Transaction reversed"})},onError:()=>s({title:"Failed to reverse transaction",variant:"destructive"})}),C=W({mutationFn:async l=>{await G("POST",`/api/staff/subledger/transactions/${l}/approve`,{})},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/transactions"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Transaction approved"})},onError:()=>s({title:"Failed to approve transaction",variant:"destructive"})}),v=["ALL","DEPOSIT","WITHDRAWAL","TRADE_BUY","TRADE_SELL","DIVIDEND","INTEREST","FEE","ADJUSTMENT","REVERSAL"],E=["ALL","PENDING","SETTLED","REVERSED","MANUAL_REVIEW"];let y=d;t!=="ALL"&&(y=y.filter(l=>l.transactionType===t||l.type===t)),c!=="ALL"&&(y=y.filter(l=>l.status===c));function V(){f({...x,legs:[...x.legs,{accountId:"",legType:"CR",amount:"",instrumentId:"",quantity:"",unitPrice:""}]})}function ce(l){f({...x,legs:x.legs.filter((p,b)=>b!==l)})}function z(l,p,b){const I=[...x.legs];I[l][p]=b,f({...x,legs:I})}function H(){let l=0,p=0;for(const b of x.legs){const I=parseFloat(b.amount);if(isNaN(I)||I<=0)return!1;b.legType==="DR"?l+=I:p+=I}return Math.abs(l-p)<.01}function ue(){if(!H()){s({title:"DR and CR legs must sum to zero",variant:"destructive"});return}L.mutate(x)}return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:v.map(l=>e.jsx(Re,{active:t===l,onClick:()=>a(l),testId:`filter-txn-type-${l.toLowerCase()}`,children:l.replace("_"," ")},l))}),e.jsx("div",{className:"flex gap-1 flex-wrap",children:E.map(l=>e.jsx(Re,{active:c===l,onClick:()=>n(l),testId:`filter-txn-status-${l.toLowerCase()}`,inactiveClass:l==="PENDING"?"text-amber-700 bg-amber-50 border border-amber-200":l==="SETTLED"?"text-emerald-700 bg-emerald-50 border border-emerald-200":l==="REVERSED"?"text-red-700 bg-red-50 border border-red-200":l==="MANUAL_REVIEW"?"text-blue-700 bg-blue-50 border border-blue-200":"text-slate-500 bg-slate-100 border border-slate-200",children:l.replace("_"," ")},l))})]}),e.jsxs(N,{onClick:()=>o(!0),className:"gap-1.5 font-bold",style:{background:Q,color:"#fff"},"data-testid":"button-post-transaction",children:[e.jsx(Ae,{className:"h-4 w-4"})," Post Transaction"]})]}),i?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):y.length===0?e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(He,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No transactions found"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Ref"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Trade Date"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Effective Date"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Status"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Source"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Created By"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Actions"})]})}),e.jsx("tbody",{children:y.map((l,p)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-txn-${l.id||p}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono font-bold",style:{color:O},children:l.transactionRef||`TXN-${l.id}`}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:(l.transactionType||l.type||"—").replace("_"," ")}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:se(l.tradeDate)}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:se(l.effectiveDate)}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(pe,{status:l.status||"PENDING"})}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:l.sourceSystem||"MANUAL"}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:l.createdBy||"—"}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex gap-1 flex-wrap",children:[e.jsxs(N,{size:"sm",variant:"outline",className:"gap-1 text-[10px]",onClick:()=>m(l),"data-testid":`button-view-txn-${l.id||p}`,children:[e.jsx(Fe,{className:"h-3 w-3"})," View"]}),l.status==="SETTLED"&&e.jsxs(N,{size:"sm",variant:"outline",className:"gap-1 text-[10px] text-red-600",onClick:()=>q.mutate(l.id),disabled:q.isPending,"data-testid":`button-reverse-txn-${l.id||p}`,children:[e.jsx(bt,{className:"h-3 w-3"})," Reverse"]}),l.status==="MANUAL_REVIEW"&&e.jsxs(N,{size:"sm",variant:"outline",className:"gap-1 text-[10px] text-emerald-600",onClick:()=>C.mutate(l.id),disabled:C.isPending,"data-testid":`button-approve-txn-${l.id||p}`,children:[e.jsx(Qe,{className:"h-3 w-3"})," Approve"]})]})})]},l.id||p))})]})}),e.jsx(Te,{open:!!u,onClose:()=>m(null),title:`Transaction ${u?.transactionRef||""}`,children:u&&e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 font-bold uppercase text-[10px]",children:"Type"}),e.jsx("p",{className:"text-slate-800",children:u.transactionType||u.type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 font-bold uppercase text-[10px]",children:"Status"}),e.jsx("p",{children:e.jsx(pe,{status:u.status})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 font-bold uppercase text-[10px]",children:"Trade Date"}),e.jsx("p",{className:"text-slate-800",children:se(u.tradeDate)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 font-bold uppercase text-[10px]",children:"Effective Date"}),e.jsx("p",{className:"text-slate-800",children:se(u.effectiveDate)})]})]}),u.legs&&u.legs.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 font-bold uppercase text-[10px]",children:"Legs"}),e.jsx("div",{className:"mt-1 rounded-md border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50",children:[e.jsx("th",{className:"px-2 py-1 text-left",children:"Account"}),e.jsx("th",{className:"px-2 py-1 text-left",children:"Type"}),e.jsx("th",{className:"px-2 py-1 text-right",children:"Amount"}),e.jsx("th",{className:"px-2 py-1 text-left",children:"Instrument"}),e.jsx("th",{className:"px-2 py-1 text-right",children:"Qty"})]})}),e.jsx("tbody",{children:u.legs.map((l,p)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-2 py-1 font-mono",children:l.accountId||l.accountCode||"—"}),e.jsx("td",{className:"px-2 py-1",children:e.jsx("span",{className:l.legType==="DR"?"text-red-600 font-bold":"text-emerald-600 font-bold",children:l.legType})}),e.jsx("td",{className:"px-2 py-1 text-right font-mono",children:B(l.amount)}),e.jsx("td",{className:"px-2 py-1",children:l.instrumentId||"—"}),e.jsx("td",{className:"px-2 py-1 text-right",children:l.quantity||"—"})]},p))})]})})]})]})}),e.jsxs(Te,{open:r,onClose:()=>o(!1),title:"Post Transaction",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Transaction Type"}),e.jsxs(ae,{value:x.transactionType,onValueChange:l=>f({...x,transactionType:l}),children:[e.jsx(le,{"data-testid":"select-txn-type",children:e.jsx(re,{})}),e.jsx(ne,{children:["DEPOSIT","WITHDRAWAL","TRADE_BUY","TRADE_SELL","DIVIDEND","INTEREST","FEE","ADJUSTMENT"].map(l=>e.jsx(R,{value:l,children:l.replace("_"," ")},l))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Trade Date"}),e.jsx(S,{type:"date",value:x.tradeDate,onChange:l=>f({...x,tradeDate:l.target.value}),"data-testid":"input-txn-trade-date"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Effective Date"}),e.jsx(S,{type:"date",value:x.effectiveDate,onChange:l=>f({...x,effectiveDate:l.target.value}),"data-testid":"input-txn-effective-date"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Transaction Legs"}),e.jsxs(N,{size:"sm",variant:"outline",onClick:V,className:"gap-1 text-[10px]","data-testid":"button-add-leg",children:[e.jsx(Ae,{className:"h-3 w-3"})," Add Leg"]})]}),x.legs.map((l,p)=>e.jsxs("div",{className:"rounded-md border border-border p-3 mb-2 bg-slate-50 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] font-bold text-slate-500",children:["Leg ",p+1]}),x.legs.length>1&&e.jsx("button",{type:"button",onClick:()=>ce(p),className:"text-red-500 text-[10px] font-bold","data-testid":`button-remove-leg-${p}`,children:"Remove"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-400",children:"Account ID"}),e.jsx(S,{maxLength:100,value:l.accountId,onChange:b=>z(p,"accountId",b.target.value),placeholder:"Account","data-testid":`input-leg-account-${p}`})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-400",children:"DR/CR"}),e.jsxs(ae,{value:l.legType,onValueChange:b=>z(p,"legType",b),children:[e.jsx(le,{"data-testid":`select-leg-type-${p}`,children:e.jsx(re,{})}),e.jsxs(ne,{children:[e.jsx(R,{value:"DR",children:"DR (Debit)"}),e.jsx(R,{value:"CR",children:"CR (Credit)"})]})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-400",children:"Amount"}),e.jsx(S,{type:"number",step:"0.01",value:l.amount,onChange:b=>z(p,"amount",b.target.value),placeholder:"0.00","data-testid":`input-leg-amount-${p}`})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-400",children:"Instrument (opt)"}),e.jsx(S,{value:l.instrumentId,onChange:b=>z(p,"instrumentId",b.target.value),placeholder:"Optional","data-testid":`input-leg-instrument-${p}`})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-400",children:"Quantity (opt)"}),e.jsx(S,{type:"number",value:l.quantity,onChange:b=>z(p,"quantity",b.target.value),placeholder:"Optional","data-testid":`input-leg-quantity-${p}`})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] text-slate-400",children:"Unit Price (opt)"}),e.jsx(S,{type:"number",step:"0.01",value:l.unitPrice,onChange:b=>z(p,"unitPrice",b.target.value),placeholder:"Optional","data-testid":`input-leg-unit-price-${p}`})]})]})]},p)),!H()&&x.legs.some(l=>l.amount)&&e.jsxs("p",{className:"text-red-600 text-[10px] font-bold flex items-center gap-1",children:[e.jsx(ge,{className:"h-3 w-3"})," DR and CR totals must balance to zero"]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(N,{variant:"outline",onClick:()=>o(!1),"data-testid":"button-cancel-transaction",children:"Cancel"}),e.jsx(N,{onClick:ue,disabled:L.isPending||!x.tradeDate||!x.effectiveDate||!H(),style:{background:Q,color:"#fff"},"data-testid":"button-submit-transaction",children:L.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):"Post Transaction"})]})]})]})}function qt(){const[s,t]=g.useState(""),{data:a=[],isLoading:c}=U({queryKey:["/api/staff/subledger/positions"]}),n=s?a.filter(r=>(r.accountCode||r.accountId||"").toLowerCase().includes(s.toLowerCase())):a;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:e.jsx(S,{maxLength:100,value:s,onChange:r=>t(r.target.value),placeholder:"Filter by account...",className:"max-w-xs","data-testid":"input-positions-filter"})}),c?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):n.length===0?e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(_,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No positions found"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Account"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Instrument"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"As-of Date"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Quantity"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Cost Basis"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Market Value"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Closing Price"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Unrealized P&L"})]})}),e.jsx("tbody",{children:n.map((r,o)=>{const u=parseFloat(r.unrealizedPnl||r.unrealizedPL||"0");return e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-position-${r.id||o}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono font-bold",style:{color:O},children:r.accountCode||r.accountId||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-800 font-medium",children:r.instrumentTicker||r.instrumentId||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:se(r.asOfDate)}),e.jsx("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:B(r.quantity,4)}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:["$",B(r.costBasis)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:["$",B(r.marketValue)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:["$",B(r.closingPrice)]}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono font-bold ${u>=0?"text-emerald-600":"text-red-600"}`,children:["$",B(u)]})]},r.id||o)})})]})})]})}function zt(){const{toast:s}=ye(),[t,a]=g.useState({}),{data:c=[],isLoading:n}=U({queryKey:["/api/staff/subledger/reconciliation/runs"]}),{data:r=[],isLoading:o}=U({queryKey:["/api/staff/subledger/breaks"]}),u=W({mutationFn:async()=>{await G("POST","/api/staff/subledger/reconciliation/run",{})},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/reconciliation/runs"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/breaks"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Reconciliation started"})},onError:()=>s({title:"Failed to start reconciliation",variant:"destructive"})}),m=W({mutationFn:async({id:f,status:d,resolutionNotes:i})=>{await G("PATCH",`/api/staff/subledger/breaks/${f}`,{status:d,resolutionNotes:i})},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/breaks"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Break status updated"})},onError:()=>s({title:"Failed to update break",variant:"destructive"})}),x=c.length>0?c[0]:null;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[x&&e.jsxs("div",{className:"rounded-md border border-border p-4 bg-white flex-1 min-w-[250px]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(We,{className:"h-4 w-4",style:{color:O}}),e.jsx("span",{className:"text-sm font-bold text-slate-800",children:"Latest Run"}),e.jsx(pe,{status:x.runStatus||"CLEAN"})]}),e.jsxs("div",{className:"flex gap-4 text-xs text-slate-500 flex-wrap",children:[e.jsxs("span",{children:["Started: ",ke(x.runStartedAt)]}),x.runCompletedAt&&e.jsxs("span",{children:["Completed: ",ke(x.runCompletedAt)]}),x.totalBreaks!=null&&e.jsxs("span",{children:["Breaks: ",x.totalBreaks]})]})]}),e.jsxs(N,{onClick:()=>u.mutate(),disabled:u.isPending,className:"gap-1.5 font-bold",style:{background:Q,color:"#fff"},"data-testid":"button-run-reconciliation",children:[u.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(Oe,{className:"h-4 w-4"})," Run Reconciliation"]})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(ge,{className:"h-4 w-4 text-amber-500"})," Breaks"]}),o?e.jsxs("div",{className:"flex items-center justify-center py-8 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):r.length===0?e.jsxs("div",{className:"text-center py-8 text-slate-400 rounded-md border border-border bg-white",children:[e.jsx(Qe,{className:"h-8 w-8 mx-auto mb-2 text-emerald-400"}),e.jsx("p",{className:"text-sm",children:"No breaks found"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Type"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Amount"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Custodian"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Subledger"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Age"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Status"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Actions"})]})}),e.jsx("tbody",{children:r.map((f,d)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-break-${f.id||d}`,children:[e.jsx("td",{className:"px-3 py-2 text-slate-800 font-medium",children:f.breakType||f.type||"—"}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-red-600 font-bold",children:["$",B(f.breakAmount)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-600",children:["$",B(f.custodianValue)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-600",children:["$",B(f.subledgerValue)]}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:f.breakAgeDays!=null?`${f.breakAgeDays}d`:"—"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(pe,{status:f.status||"OPEN"})}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex gap-1 flex-wrap items-center",children:[e.jsxs(ae,{value:"",onValueChange:i=>m.mutate({id:f.id,status:i,resolutionNotes:t[f.id]}),children:[e.jsx(le,{className:"h-7 w-28 text-[10px]","data-testid":`select-break-status-${f.id||d}`,children:e.jsx(re,{placeholder:"Update..."})}),e.jsxs(ne,{children:[e.jsx(R,{value:"INVESTIGATING",children:"Investigating"}),e.jsx(R,{value:"RESOLVED",children:"Resolved"}),e.jsx(R,{value:"ESCALATED",children:"Escalated"})]})]}),e.jsx(S,{maxLength:100,value:t[f.id]||"",onChange:i=>a({...t,[f.id]:i.target.value}),placeholder:"Notes...",className:"h-7 text-[10px] w-32","data-testid":`input-break-notes-${f.id||d}`})]})})]},f.id||d))})]})})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(Ge,{className:"h-4 w-4",style:{color:O}})," Run History"]}),n?e.jsxs("div",{className:"flex items-center justify-center py-8 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):c.length===0?e.jsx("div",{className:"text-center py-8 text-slate-400 rounded-md border border-border bg-white",children:e.jsx("p",{className:"text-sm",children:"No reconciliation runs yet"})}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Run ID"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Started"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Completed"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Status"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Breaks"})]})}),e.jsx("tbody",{children:c.map((f,d)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-run-${f.id||d}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono",style:{color:O},children:f.id}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:ke(f.runStartedAt)}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:ke(f.runCompletedAt)}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(pe,{status:f.runStatus||"CLEAN"})}),e.jsx("td",{className:"px-3 py-2 text-right font-mono",children:f.totalBreaks??"—"})]},f.id||d))})]})})]})]})}function Ut(){const{toast:s}=ye(),[t,a]=g.useState("ALL"),[c,n]=g.useState(!1),[r,o]=g.useState({caType:"DIVIDEND_CASH",instrumentId:"",recordDate:"",payDate:"",grossAmount:"",perShareAmount:""}),{data:u=[],isLoading:m}=U({queryKey:["/api/staff/subledger/corporate-actions"]}),x=W({mutationFn:async i=>{await G("POST","/api/staff/subledger/corporate-actions",i)},onSuccess:()=>{A.invalidateQueries({queryKey:["/api/staff/subledger/corporate-actions"]}),A.invalidateQueries({queryKey:["/api/staff/subledger/dashboard"]}),s({title:"Corporate action created"}),n(!1),o({caType:"DIVIDEND_CASH",instrumentId:"",recordDate:"",payDate:"",grossAmount:"",perShareAmount:""})},onError:()=>s({title:"Failed to create corporate action",variant:"destructive"})}),f=["ALL","PENDING","SNAPSHOT_LOCKED","ALLOCATED","FAILED"],d=t==="ALL"?u:u.filter(i=>i.status===t);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:f.map(i=>e.jsx(Re,{active:t===i,onClick:()=>a(i),testId:`filter-corp-action-${i.toLowerCase()}`,children:i.replace("_"," ")},i))}),e.jsxs(N,{onClick:()=>n(!0),className:"gap-1.5 font-bold",style:{background:Q,color:"#fff"},"data-testid":"button-new-corp-action",children:[e.jsx(Ae,{className:"h-4 w-4"})," New Corporate Action"]})]}),m?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):d.length===0?e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(me,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No corporate actions found"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Instrument"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Record Date"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Pay Date"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Gross Amount"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Per Share"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Status"})]})}),e.jsx("tbody",{children:d.map((i,L)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-corp-action-${i.id||L}`,children:[e.jsx("td",{className:"px-3 py-2 text-slate-800 font-medium",children:i.caType||"—"}),e.jsx("td",{className:"px-3 py-2 font-mono",style:{color:O},children:i.instrumentTicker||i.instrumentId||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:se(i.recordDate)}),e.jsx("td",{className:"px-3 py-2 text-slate-500",children:se(i.payDate)}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:["$",B(i.grossAmount)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:["$",B(i.perShareAmount,4)]}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(pe,{status:i.status||"PENDING"})})]},i.id||L))})]})}),e.jsxs(Te,{open:c,onClose:()=>n(!1),title:"New Corporate Action",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Action Type"}),e.jsxs(ae,{value:r.caType,onValueChange:i=>o({...r,caType:i}),children:[e.jsx(le,{"data-testid":"select-corp-action-type",children:e.jsx(re,{})}),e.jsxs(ne,{children:[e.jsx(R,{value:"DIVIDEND_CASH",children:"Cash Dividend"}),e.jsx(R,{value:"DIVIDEND_STOCK",children:"Stock Dividend"}),e.jsx(R,{value:"INTEREST",children:"Interest"}),e.jsx(R,{value:"STOCK_SPLIT",children:"Stock Split"}),e.jsx(R,{value:"RETURN_OF_CAPITAL",children:"Return of Capital"}),e.jsx(R,{value:"MERGER",children:"Merger"}),e.jsx(R,{value:"SPIN_OFF",children:"Spin Off"})]})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Instrument ID"}),e.jsx(S,{maxLength:100,value:r.instrumentId,onChange:i=>o({...r,instrumentId:i.target.value}),placeholder:"Instrument ID or ticker","data-testid":"input-corp-action-instrument"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Record Date"}),e.jsx(S,{type:"date",value:r.recordDate,onChange:i=>o({...r,recordDate:i.target.value}),"data-testid":"input-corp-action-record-date"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Pay Date"}),e.jsx(S,{type:"date",value:r.payDate,onChange:i=>o({...r,payDate:i.target.value}),"data-testid":"input-corp-action-pay-date"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Gross Amount"}),e.jsx(S,{type:"number",step:"0.01",value:r.grossAmount,onChange:i=>o({...r,grossAmount:i.target.value}),placeholder:"0.00","data-testid":"input-corp-action-gross"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-[10px] font-bold uppercase tracking-wider text-slate-500",children:"Per Share Amount"}),e.jsx(S,{type:"number",step:"0.0001",value:r.perShareAmount,onChange:i=>o({...r,perShareAmount:i.target.value}),placeholder:"0.0000","data-testid":"input-corp-action-per-share"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(N,{variant:"outline",onClick:()=>n(!1),"data-testid":"button-cancel-corp-action",children:"Cancel"}),e.jsx(N,{onClick:()=>x.mutate(r),disabled:x.isPending||!r.instrumentId||!r.recordDate,style:{background:Q,color:"#fff"},"data-testid":"button-submit-corp-action",children:x.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):"Create"})]})]})]})}function _t(){const[s,t]=g.useState(null),{data:a=[],isLoading:c}=U({queryKey:["/api/staff/subledger/accounts"]}),n=a.filter(r=>r.accountType==="CLIENT");return s?e.jsx(At,{accountId:s,onBack:()=>t(null)}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-5 w-5",style:{color:O}}),e.jsx("h3",{className:"text-sm font-bold text-slate-800",children:"Client Account Statements"})]}),e.jsx("p",{className:"text-xs text-slate-500",children:"Select a client account to generate a comprehensive performance statement with returns analysis, allocation breakdown, and risk metrics."}),c?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading accounts..."]}):n.length===0?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-center py-8 text-slate-400 border border-dashed border-border rounded-lg",children:[e.jsx(te,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm font-medium",children:"No client accounts found"}),e.jsx("p",{className:"text-xs mt-1",children:"Create a client account in the Accounts tab first, then generate statements here."})]}),e.jsxs("div",{className:"bg-slate-50 rounded-lg border border-border p-4",children:[e.jsx("h4",{className:"text-xs font-bold text-slate-500 uppercase mb-2",children:"Or generate statement for any account"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:a.map(r=>e.jsxs("button",{type:"button",onClick:()=>t(r.id),className:"flex items-center gap-3 p-3 bg-white rounded-md border border-border hover:border-[#C9A84C] hover:shadow-sm transition-all text-left","data-testid":`button-stmt-account-${r.accountCode}`,children:[e.jsx(te,{className:"h-4 w-4 text-slate-400 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-slate-800 truncate",children:r.accountName}),e.jsxs("p",{className:"text-[10px] text-slate-400 font-mono",children:[r.accountCode," · ",r.accountType]})]})]},r.id))})]})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:n.map(r=>e.jsxs("button",{type:"button",onClick:()=>t(r.id),className:"flex items-center gap-3 p-4 rounded-lg border hover:border-[#C9A84C] hover:shadow-md transition-all text-left group",style:{background:"linear-gradient(180deg, #ffffff 0%, #f8fafc 100%)",borderColor:"#e2e8f0"},"data-testid":`button-stmt-account-${r.accountCode}`,children:[e.jsx("div",{className:"p-2 rounded-md bg-slate-50 group-hover:bg-[#fdf8ef] transition-colors",children:e.jsx(X,{className:"h-5 w-5 text-slate-400 group-hover:text-[#C9A84C] transition-colors"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-bold truncate",style:{color:"#2d1a0e"},children:r.accountName}),e.jsxs("p",{className:"text-[10px] text-slate-400 font-mono",children:[r.accountCode," · ",r.currency||"USD"]}),e.jsxs("p",{className:"text-[10px] text-slate-400",children:["Opened ",se(r.openedDate)]})]}),e.jsx(De,{className:"h-4 w-4 text-slate-400 -rotate-90 group-hover:text-[#C9A84C] transition-colors"})]},r.id))})]})}function Kt(){const{data:s,isLoading:t}=U({queryKey:["/api/staff/subledger/trial-balance"]}),a=s?.accounts||[],c=a.reduce((o,u)=>o+parseFloat(u.drTotal||"0"),0),n=a.reduce((o,u)=>o+parseFloat(u.crTotal||"0"),0),r=Math.abs(c-n)<.01;return e.jsx("div",{className:"space-y-4",children:t?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):a.length===0?e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(_e,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No trial balance data"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Account Code"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Account Name"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"DR Total"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"CR Total"}),e.jsx("th",{className:"px-3 py-2 text-right font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Balance"})]})}),e.jsx("tbody",{children:a.map((o,u)=>{const m=parseFloat(o.drTotal||"0"),x=parseFloat(o.crTotal||"0"),f=parseFloat(o.balance||"0");return e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-trial-balance-${u}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono font-bold",style:{color:O},children:o.account?.accountCode||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-800 font-medium",children:o.account?.accountName||"—"}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:["$",B(m)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-700",children:["$",B(x)]}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono font-bold ${f>=0?"text-slate-800":"text-red-600"}`,children:["$",B(f)]})]},o.account?.id||u)})}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"bg-slate-100 border-t-2 border-border font-bold",children:[e.jsx("td",{className:"px-3 py-2 text-slate-800",colSpan:2,children:"TOTALS"}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-800",children:["$",B(c)]}),e.jsxs("td",{className:"px-3 py-2 text-right font-mono text-slate-800",children:["$",B(n)]}),e.jsxs("td",{className:`px-3 py-2 text-right font-mono ${r?"text-emerald-600":"text-red-600"}`,children:["$",B(c-n),r&&e.jsx(Qe,{className:"h-3 w-3 inline ml-1"}),!r&&e.jsx(yt,{className:"h-3 w-3 inline ml-1"})]})]})})]})})})}function Wt(){const[s,t]=g.useState("ALL"),{data:a=[],isLoading:c}=U({queryKey:["/api/staff/subledger/audit-log"]}),n=["ALL","ACCOUNT","TRANSACTION","INSTRUMENT","CORP_ACTION","RECONCILIATION","BREAK"],r=s==="ALL"?a:a.filter(o=>o.entityType===s);return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:n.map(o=>e.jsx(Re,{active:s===o,onClick:()=>t(o),testId:`filter-audit-${o.toLowerCase()}`,children:o.replace("_"," ")},o))}),c?e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading..."]}):r.length===0?e.jsxs("div",{className:"text-center py-12 text-slate-400",children:[e.jsx(Ge,{className:"h-8 w-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No audit entries found"})]}):e.jsx("div",{className:"overflow-x-auto rounded-md border",style:{borderColor:"#e2e8f0"},children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",style:{background:"#f1f5f9",borderColor:"#e2e8f0"},children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Event Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Entity Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Entity ID"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"User"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Description"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold uppercase tracking-wider",style:{color:"#8c7a5e"},children:"Timestamp"})]})}),e.jsx("tbody",{children:r.map((o,u)=>e.jsxs("tr",{className:"border-b hover:bg-[#f8fafc]",style:{borderColor:"#e2e8f0"},"data-testid":`row-audit-${o.id||u}`,children:[e.jsx("td",{className:"px-3 py-2 text-slate-800 font-medium",children:o.eventType||o.action||"—"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-slate-100 text-slate-600",children:o.entityType||"—"})}),e.jsx("td",{className:"px-3 py-2 font-mono text-slate-500",children:o.entityId||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:o.userId||o.userName||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-500 max-w-xs truncate",children:o.description||o.details||"—"}),e.jsx("td",{className:"px-3 py-2 text-slate-400",children:ke(o.createdAt||o.timestamp)})]},o.id||u))})]})})]})}function Xt(){const[s,t]=g.useState(null),a={Dashboard:"Details about Dashboard functionality and capabilities.",Journal:"Details about Journal functionality and capabilities.",Accounts:"Details about Accounts functionality and capabilities.",Positions:"Details about Positions functionality and capabilities.",Reconciliation:"Daily reconciliation of bank, custodian, and client account positions.","Audit Trail":"Immutable audit trail of all transactions with timestamps and user attribution."},[c,n]=g.useState("dashboard");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-2xl p-5 relative overflow-hidden",style:{background:"linear-gradient(135deg, #fdf8ee, #fef9f0)",border:"1px solid #e8d5a3",boxShadow:"0 4px 16px rgba(201,168,76,0.08)"},children:[e.jsxs("div",{className:"relative flex items-center gap-3.5",children:[e.jsx("div",{className:"rounded-2xl flex items-center justify-center shrink-0",style:{width:52,height:52,background:"rgba(201,168,76,0.15)",border:"1px solid rgba(201,168,76,0.3)"},children:e.jsx(_e,{className:"h-6 w-6",style:{color:"#C9A84C"}})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black text-slate-800 tracking-tight",children:"Subledger Management"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Double-entry accounting engine, reconciliation, positions, and audit trail"})]})]}),e.jsx("div",{className:"relative flex flex-wrap gap-1.5 mt-3.5",children:["Dashboard","Journal","Accounts","Positions","Reconciliation","Audit Trail"].map(r=>{const o=s===r;return e.jsx("button",{type:"button","data-testid":`badge-${r.toLowerCase().replace(/[\s/]+/g,"-")}`,onClick:()=>t(o?null:r),className:"text-[10px] font-bold px-2.5 py-1 rounded-full cursor-pointer transition-all hover:scale-105",style:o?{background:"#C9A84C",color:"#fff",border:"1px solid #A88B35",boxShadow:"0 2px 8px rgba(201,168,76,0.3)"}:{background:"rgba(201,168,76,0.12)",color:"#A88B35",border:"1px solid rgba(201,168,76,0.3)"},children:r},r)})})]}),s&&a[s]&&e.jsx("div",{className:"rounded-xl border-l-4 p-4 animate-in fade-in slide-in-from-top-2 duration-200",style:{borderLeftColor:"#C9A84C",background:"#f0f4f8",border:"1px solid #cbd5e1"},children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-900 text-sm",children:s}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:a[s]})]}),e.jsx("button",{"data-testid":"btn-awm_subledger_panel-view-1284",type:"button",onClick:()=>t(null),className:"text-slate-400 hover:text-slate-600 p-1",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]})}),e.jsx("div",{className:"flex gap-1 flex-wrap border-b border-border pb-2",children:Mt.map(r=>{const o=r.icon,u=c===r.id;return e.jsxs("button",{type:"button",onClick:()=>n(r.id),"data-testid":`tab-subledger-${r.id}`,className:`flex items-center gap-1.5 px-3 py-2 text-xs font-bold rounded-md transition-colors ${u?"text-white":"text-slate-500"}`,style:u?{background:"#C9A84C"}:void 0,children:[e.jsx(o,{className:"h-3.5 w-3.5"}),r.label]},r.id)})}),c==="dashboard"&&e.jsx(Bt,{}),c==="accounts"&&e.jsx(Vt,{}),c==="instruments"&&e.jsx(Ft,{}),c==="transactions"&&e.jsx(Ot,{}),c==="trading-blotter"&&e.jsx(g.Suspense,{fallback:e.jsxs("div",{className:"flex items-center justify-center py-12 text-slate-400",children:[e.jsx(P,{className:"h-5 w-5 animate-spin mr-2"})," Loading Trading Blotter..."]}),children:e.jsx(It,{})}),c==="positions"&&e.jsx(qt,{}),c==="reconciliation"&&e.jsx(zt,{}),c==="corporate-actions"&&e.jsx(Ut,{}),c==="statements"&&e.jsx(_t,{}),c==="trial-balance"&&e.jsx(Kt,{}),c==="audit-log"&&e.jsx(Wt,{})]})}export{Xt as default};
