1import{z as mt,r as t,j as e,g as ft,B as Ae,a as Mt,u as pt,K as z,M as Ee,L as _e,a9 as ve,v as xt,b2 as ht,b3 as gt,b4 as bt,b5 as yt,I as vt,b8 as Bt,a7 as $t,av as Ve,J as Ut,b9 as De,c as st}from"./main-rwWalgtK.js";import{a as Vt}from"./ranking-stage-D1bSgnLs.js";import{s as Ht,a as zt}from"./user-error-DNN5kwTx.js";import{D as jt,a as Yt,e as wt,c as Kt,b as Gt,L as Qt,d as Wt,f as Xt,T as qe,R as Jt,r as Zt}from"./included-domains.functions-CvoGwLAC.js";import{n as Te,P as Nt}from"./plan-tag-summary-CyeSFPm5.js";import{R as St}from"./raise-summary-C6LabxQa.js";import{g as Fe,c as kt,s as _t,u as er,a as tr,b as rr,d as sr,e as nt,f as nr,r as ar,h as at,i as or,j as ir}from"./run.functions-BSkwrG43.js";import{g as tt,c as Ct,l as lr,d as dr,e as cr,f as Rt,r as ur}from"./deals.functions-BPUbNQnF.js";import{D as Tt}from"./deal-name-collision-dialog-BhDokVWi.js";import{g as Dt}from"./account.functions-Do3eONae.js";import{f as me}from"./anthropic-error-Za9zyxbx.js";import{T as mr}from"./textarea-BeBclvOl.js";import{P as fr,c as pr,b as xr}from"./popover-BumxmGZF.js";import{X as hr}from"./x-CT6MgQxM.js";import{u as gr}from"./onboarding-B_kUsLql.js";import{C as br}from"./checkbox-BBjueFva.js";import{I as yr,H as vr,a as jr,c as wr,b as Nr}from"./deal-hq-location-section-CfqCI0cr.js";import{A as ze,a as Ye,b as Ke,c as Ge,d as Qe,e as We,f as Xe,g as Je}from"./alert-dialog-iEruvJXw.js";import{S as Et,a as Ft,b as It,c as Pt,d as Ze}from"./select-C_mtS8d0.js";import{F as He,M as ot}from"./file-field-BtfqR_oF.js";import{g as Sr,c as kr}from"./onboarding-handoff.functions-BX-76aru.js";import{h as _r}from"./finder-handoff-NwnHqj48.js";import{C as At}from"./check-ERfHPR0W.js";import{C as Cr}from"./chevron-down-Yir-hmoX.js";import{C as Rr}from"./chevron-right-B7sl-bEG.js";import"./property-types-Bhbnh0_e.js";import"./plus-2BlkptdJ.js";import"./Combination-B0LoZHdt.js";import"./index-CLVOXAhG.js";import"./dialog-C3bfrFNX.js";import"./index-CB0UFMcB.js";import"./search-Dwr3M_pv.js";import"./index-BdQq_4o_.js";import"./index-Dx4MIMDP.js";import"./index-DG2ieJUr.js";import"./upload-BDjq57xT.js";const Tr=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],Dr=mt("download",Tr);const Er=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],Lt=mt("info",Er);function it(){let r=!1;return{isLocked:()=>r,async run(n){if(!r){r=!0;try{return await n()}finally{r=!1}}}}}const et=t.forwardRef(({num:r,eyebrow:n,title:i,description:c,actions:s,className:a,...b},v)=>e.jsxs("header",{ref:v,className:ft("flex items-start justify-between gap-4 pb-4",a),...b,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[(r!==void 0||n)&&e.jsxs("div",{className:"mb-1 flex items-center gap-2 text-sm font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{"aria-hidden":!0,className:"h-px w-6 bg-brand-accent"}),r!==void 0&&e.jsx("span",{className:"font-serif text-sm italic text-brand-accent normal-case tracking-normal",children:r}),n&&e.jsx("span",{children:n})]}),e.jsx("h2",{className:"font-serif text-2xl font-normal leading-tight tracking-tight text-foreground",children:i}),c&&e.jsx("p",{className:"mt-1.5 text-sm text-muted-foreground",children:c})]}),s&&e.jsx("div",{className:"shrink-0",children:s})]}));et.displayName="SectionHead";let lt=0;function Me({children:r,open:n,title:i,body:c,step:s,primaryLabel:a="Got it",onPrimary:b,onDismiss:v}){const u=t.useRef(0);t.useEffect(()=>{n&&(u.current=Date.now()+350)},[n]);const d=t.useCallback(()=>{lt=Date.now()+500,setTimeout(()=>b(),0)},[b]),h=t.useCallback(()=>{v&&(Date.now()<u.current||Date.now()<lt||setTimeout(()=>v(),0))},[v]);return e.jsxs(fr,{open:n,children:[e.jsx(pr,{asChild:!0,children:r}),e.jsxs(xr,{sideOffset:8,className:ft("w-80 border-brand-line bg-brand-paper p-0 text-brand-ink shadow-lg"),onInteractOutside:f=>{v&&(f.preventDefault(),h())},onEscapeKeyDown:f=>{v&&(f.preventDefault(),h())},children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 px-4 pt-4",children:[e.jsx("h3",{className:"font-serif text-base font-semibold leading-snug text-brand-ink",children:i}),v&&e.jsx("button",{type:"button",onClick:h,"aria-label":"Dismiss",className:"mt-0.5 inline-flex size-6 shrink-0 items-center justify-center rounded-sm text-brand-muted transition-colors hover:text-brand-ink focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brand-ink/30",children:e.jsx(hr,{className:"size-4"})})]}),e.jsx("div",{className:"px-4 pb-4 pt-2",children:e.jsx("p",{className:"text-sm leading-relaxed text-brand-ink/90",children:c})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-brand-line px-4 py-3",children:[s?e.jsxs("span",{className:"text-xs font-medium tabular-nums text-brand-accent",children:[s.current," of ",s.total]}):e.jsx("span",{"aria-hidden":!0}),e.jsx(Ae,{size:"sm",onClick:d,children:a})]})]})]})}const dt=["equity investors in your company","debt investors/lenders for your company","asset-based lenders or structured credit investors in your assets","equity investors in your real estate","debt investors/lenders in your real estate","limited partners for your fund","seed or GP stake investors for your fund"];function Fr({plan:r,onReupload:n}){return e.jsxs("section",{className:"rounded-md border border-border bg-muted/20 p-4",children:[e.jsxs("div",{className:"mb-2 flex items-baseline justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Parsed from your materials"}),e.jsx("button",{type:"button",onClick:n,className:"text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground",children:"Not right? Re-upload"})]}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"This is what the parser extracted. The plan and outreach are based on these tags â re-upload if anything looks wrong, otherwise continue."}),e.jsx(Nt,{plan:r})]})}function ct(){const r=new Date,n=i=>String(i).padStart(2,"0");return`Deal ${r.getFullYear()}-${n(r.getMonth()+1)}-${n(r.getDate())} ${n(r.getHours())}:${n(r.getMinutes())}`}function Ir(r){return r&&r.replace(/[\\/:*?"<>|]+/g,"").replace(/['`]+/g,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,60).replace(/_+$/g,"")||"deal"}function Es(){const[r,n]=t.useState("entry"),[i,c]=t.useState(null),[s,a]=t.useState(null),[b,v]=t.useState(null),[u,d]=t.useState(""),[h,f]=t.useState(!1),[g,k]=t.useState(!1),[p,w]=t.useState(null),[E,D]=t.useState("entry"),[W,Y]=t.useState(!1),[q,l]=t.useState("credits"),N=Mt
1(),{user:R}=pt(),j=z(Dt),P=Ee({queryKey:["my-credits",R?.id],queryFn:()=>j(),enabled:!!R?.id,staleTime:3e4});function M(){const _=P.data;if(!_)return!0;const K=(_.credits_remaining??0)<=0,$=_.trial_available??!1;return!K||$?!0:(l("credits"),Y(!0),!1)}t.useEffect(()=>{if(typeof window>"u")return;const _=new URLSearchParams(window.location.search),K=_.get("runId"),$=_.get("dealId"),U=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;let J=!1;async function Z(){let ae=!1;if(K&&U.test(K))try{const V=await Fe({data:{runId:K}});if(J)return;c(K),a(V?.deal_id??null),d(V?.deal_name??""),n("running"),ae=!0}catch{if(J)return;c(null),n("entry")}else if($&&U.test($))try{const V=await tt({data:{dealId:$}});if(J)return;v($),d(V.deal?.name??""),n("continue"),ae=!0}catch{if(J)return;v(null),n("entry")}J||!ae&&typeof window<"u"&&window.location.search&&window.history.replaceState(null,"",window.location.pathname)}return Z(),()=>{J=!0}},[]);function F(){c(null),a(null),d(""),v(null),n("entry"),typeof window<"u"&&window.location.search&&window.history.replaceState(null,"",window.location.pathname)}const se=r==="plan"||r==="running"||r==="refine";function B(_){i&&se?(D(_),w(null),f(!0)):_==="dashboard"?N({to:"/dashboard"}):F()}async function xe(){if(!i){f(!1),E==="dashboard"?N({to:"/dashboard"}):F();return}k(!0),w(null);try{await kt({data:{runId:i}}),k(!1),f(!1),E==="dashboard"?N({to:"/dashboard"}):F()}catch(_){w(_ instanceof Error?_.message:"Cancel failed"),k(!1)}}return e.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[e.jsx("header",{className:"border-b border-border",children:e.jsxs("div",{className:"mx-auto flex max-w-3xl items-center justify-between gap-4 px-6 py-5",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s&&e.jsx(_e,{to:"/deals/$dealId",params:{dealId:s},className:"text-[12px] text-muted-foreground no-underline hover:text-foreground",children:"â Back to deal"}),e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Deal Builder"}),u&&e.jsx("p",{className:"text-sm text-muted-foreground truncate",title:u,children:u})]}),se&&e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>
1B("dashboard"),className:"rounded-md border border-input bg-background px-3 py-2 text-[13.5px] font-medium hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>B("entry"),className:"rounded-md border border-input bg-background px-3 py-2 text-[13.5px] font-medium hover:bg-accent",children:"Start over"})]})]})}),e.jsx(ze,{open:h,onOpenChange:_=>{g||f(_)},children:e.jsxs(Ye,{children:[e.jsxs(Ke,{children:[e.jsx(Ge,{children:"Cancel this deal?"}),e.jsx(Qe,{children:"Any credits already consumed will not be refunded."})]}),p&&e.jsx("p",{className:"text-sm text-destructive",children:p}),e.jsxs(We,{children:[e.jsx(Xe,{disabled:g,children:"Keep running"}),e.jsx(Je,{disabled:g,onClick:_=>{_.preventDefault(),xe()},children:g?"Cancelingâ¦":E==="dashboard"?"Cancel":"Cancel and start over"})]})]})}),e.jsx(ze,{open:W,onOpenChange:Y,children:e.jsxs(Ye,{children:[e.jsxs(Ke,{children:[e.jsx(Ge,{children:"You're out of credits"}),e.jsx(Qe,{children:"You don't have enough credits to start a new deal. Top up to continue."})]}),e.jsxs(We,{children:[e.jsx(Xe,{children:"Not now"}),e.jsx(Je,{onClick:_=>{_.preventDefault(),Y(!1),N({to:"/buy-credits"})},children:"Buy credits"})]})]})}),e.jsxs("main",{className:"mx-auto max-w-3xl px-6 py-10",children:[r==="entry"&&e.jsx(Pr,{onNewDeal:()=>{M()&&n("upload")},onContinueDeal:()=>n("continue")}),r==="continue"&&e.jsx(Ar,{initialDealId:b,onStarted:({runId:_,dealId:K,dealName:$})=>{c(_),a(K),d($),n("running")},onCancel:F,onNewDeal:()=>{M()&&n("upload")}}),r==="upload"&&e.jsx(qr,{onSubmitted:({runId:_,dealId:K,dealName:$})=>{c(_),a(K),d($),n("plan")}}),r==="plan"&&i&&e.jsx(Mr,{runId:i,onRun:()=>n("running"),onCancel:F,onDealName:d,gateStartRun:M}),r==="running"&&i&&e.jsx(Vr,{runId:i,onComplete:()=>n("download"),onNeedsRefinement:()=>n("refine"),onStartOver:F}),r==="download"&&i&&e.jsx(Hr,{runId:i,onAnother:F}),r==="refine"&&i&&e.jsx(Gr,{runId:i,onContinue:()=>n("running"),onCancel:F})]})]})}function Pr({onNewDeal:r,onContinueDeal:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"font-serif text-3xl tracking-tight text-foreground",children:"What are we doing today?"}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("button",{onClick:r,className:"rounded-lg border border-brand-line bg-brand-paper-2/40 p-6 text-left transition hover:border-brand-accent hover:bg-brand-paper-2",children:[e.jsx("div",{className:"text-base font-medium text-foreground",children:"Start a new deal"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Upload materials, generate a plan, and build fresh outreach."})]}),e.jsxs("button",{onClick:n,className:"rounded-lg border border-brand-line bg-brand-paper-2/40 p-6 text-left transition hover:border-brand-accent hover:bg-brand-paper-2",children:[e.jsx("div",{className:"text-base font-medium text-foreground",children:"Find more contacts"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Pick a previous deal and pull more contacts (deduped against earlier outreach for this deal)."})]})]})]})}function Ot({id:r,checked:n,onChange:i,disabled:c}){return e.jsxs("div",{className:"flex items-start gap-2.5 border-t border-brand-line pt-4",children:[e.jsx(br,{id:r,checked:n,disabled:c,onCheckedChange:s=>i(s===!0),className:"mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(xt,{htmlFor:r,className:"text-sm font-medium text-foreground",children:"Draft personalized outreach for each contact"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave this on to get an email and a LinkedIn message drafted for every contact. Turn it off to receive contacts and ratings only. The price is the same either way, and this applies to this delivery only."})]})]})}function Ar({initialDealId:r,onStarted:n,onCancel:i,onNewDeal:c}){const[s,a]=t.useState(null),[b,v]=t.useState(""),[u,d]=t.useState("100"),[h,f]=t.useState(!1),[g,k]=t.useState(!0),[p,w]=t.useState(null),E=t.useRef(null),D=z(Ct),W=z(_t),Y=z(tt),q=Ee({queryKey:["deal-detail",b],queryFn:()=>Y({data:{dealId:b}}),enabled:b!==""});t.useEffect(()=>{lr({data:{}}).then(j=>{const P=j.filter(F=>F.is_demo!==!0);a(P.map(F=>({id:F.id,name:F.name})));const M=P.find(F=>F.id===r);M?v(M.id):P.length>0?v(P[0].id):v("")}
1).catch(j=>w(j instanceof Error?j.message:"Failed to load deals"))},[r]);const l=Number(u),N=Number.isInteger(l)&&l>=10&&l<=1e3&&b!=="";async function R(){f(!0),w(null);try{await E.current?.flushPending();const j=await D({data:{dealId:b,deliveryTarget:l,skipOutreach:!g}}),P=j?.runId??j?.run_id;if(!P)throw new Error("Run creation did not return a run id");await W({data:{runId:P}});const M=s?.find(F=>F.id===b)?.name??"";n({runId:P,dealId:b,dealName:M})}catch(j){console.error("[delivery:start] failed",j),w(Ht(j,zt)),f(!1)}}return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"font-serif text-3xl tracking-tight",children:"Find more contacts"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Uses this dealâs plan and materials. Firms and contacts from prior contacts already reached for this deal are excluded automatically."}),s===null?e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx(ve,{className:"inline mr-2 h-4 w-4 animate-spin"}),"Loading dealsâ¦"]}):s.length===0?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set up your deal first. Find more investors works on a deal with your materials and plan."}),e.jsx(Ae,{onClick:c,children:"Set up your deal"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Deal"}),e.jsxs(Et,{value:b,onValueChange:v,children:[e.jsx(Ft,{children:e.jsx(It,{placeholder:"Choose a dealâ¦"})}),e.jsx(Pt,{children:s.map(j=>e.jsx(Ze,{value:j.id,children:j.name},j.id))})]})]}),b!==""&&e.jsx(Or,{dealId:b,query:q}),e.jsxs("div",{className:"flex flex-col gap-1.5 border-b border-brand-line py-3 last:border-b-0",children:[e.jsxs(xt,{htmlFor:"number-of-investors",className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:["Number of investors",e.jsx(ht,{delayDuration:200,children:e.jsxs(gt,{children:[e.jsx(bt,{asChild:!0,children:e.jsx(Lt,{size:14,className:"ml-1.5 inline-flex align-middle text-brand-muted cursor-help"})}),e.jsx(yt,{side:"top",className:"z-50",children:"Each investor costs one credit. One credit delivers one matched investor with the outreach drafted in your voice."})]})})]}),e.jsx(vt,{id:"number-of-investors",type:"number",min:10,max:1e3,value:u,onChange:j=>d(j.target.value),"aria-describedby":"number-of-investors-hint",className:"border-0 bg-transparent px-0 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 text-foreground max-w-[200px] text-[15px]! md:text-[15px]!"}),e.jsx("p",{id:"number-of-investors-hint",className:"text-xs text-muted-foreground",children:"10â1000. Default min(100, available credits)."})]}),e.jsx(Ot,{id:"continue-draft-outreach",checked:g,onChange:k}),b!==""&&e.jsx(jt,{ref:E,dealId:b,collapsible:!0,title:"Excluded firms (optional)"})]}),p&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:me(p)}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(Ae,{onClick:R,disabled:!N||h,children:h?"Startingâ¦":"Build outreach"}),e.jsx("button",{onClick:i,className:"text-sm text-muted-foreground underline hover:text-foreground",children:"Cancel"})]})]})}const Lr={presentation:"Investor presentation",memo:"Memo or supporting materials",template:"Template email"};function Or({dealId:r,query:n}){if(n.isLoading)return e.jsxs("div",{className:"rounded-md border border-brand-line bg-brand-paper p-3 text-xs text-muted-foreground",children:[e.jsx(ve,{className:"mr-2 inline h-3.5 w-3.5 animate-spin"}),"Loading this dealâs planâ¦"]});if(n.error||!n.data)return e.jsx("div",{className:"rounded-md border border-brand-line bg-brand-paper p-3 text-xs text-muted-foreground",children:"Could not load this dealâs plan."});const{deal:i}=n.data,c=i.plan_json,s=(Array.isArray(i.parse_report)?i.parse_report:[]).filter(d=>d&&(d.category==="presentation"||d.category==="memo"||d.category==="template")),a=d=>s.find(h=>h.category===d)??null;if(!(!!c&&(!!c.dealSummary||!!c.branch||Object.keys(c).length>0)))return e.jsxs("div",{className:"rounded-md border border-brand-line bg-brand-paper p-3 text-xs text-muted-foreground",children:["This deal does not have a saved plan yet."," ",e.jsx(_e,{to:"/deals/$dealId/refine",params:{dealId:r},className:"underline hover:text-foreground",children:"Refine plan"})]});const u=Te(typeof c?.branch=="string"?c.branch:void 0)==="RealEstate";return e.jsxs("section",{className:"space-y-3 rounded-md border border-brand-line bg-brand-paper p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"This outreach will use:"}),e.jsx(_e,{to:"/deals/$dealId/refine",params:{dealId:r},className:"text-xs text-muted-foreground underline hover:text-foreground",children:"Refine plan"})]}),e.jsx(St,{plan:c}),e.jsx(Nt,{plan:c}),u&&e.jsx("p",{className:"text-[12px] italic text-muted-foreground",children:"Property and capital types are listed in priority order; the first item is primary."}),e.jsxs("div",{className:"space-y-1.5 rounded-md border border-brand-line/60 bg-brand-paper-2/40 px-3 py-2.5",children:[e.jsx("div",{className:"text-[12px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Current materials"}),e.jsx("ul",{className:"space-y-1",children:["presentation","memo","template"].map(d=>{const h=a(d);return e.jsx("li",{className:"flex items-center justify-between gap-3 text-[14px]",children:e.jsxs("span",{className:"min-w-0 truncate text-foreground",children:[e.jsxs("span",{className:"text-muted-foreground",children:[Lr[d],":"]})," ",h?e.jsx("span",{children:h.filename}):e.jsx("span",{className:"italic text-muted-foreground",children:"none"})]})},d)})})]})]})}function qr({onSubmitted:r}){const[n,i]=t.useState(null),[c,s]=t.useState(null),[a,b]=t.useState(null),v=Bt.useSearch(),[u,d]=t.useState(()=>{const m=v.ranking_category,T=v.ranking_stage;return!m&&!T?"":[m?`Sector: ${m}.`:null,T?`Stage: ${Vt(T)}
1.`:null].filter(Boolean).join(" ")}),[h,f]=t.useState(""),[g,k]=t.useState(""),[p,w]=t.useState([]),[E,D]=t.useState(""),[W,Y]=t.useState(!1),q=t.useRef(null),[l,N]=t.useState(""),[R,j]=t.useState(""),[P,M]=t.useState(""),[F,se]=t.useState(""),{user:B}=pt(),xe=z(Sr),_=z(kr),K=z(Yt),$=Ee({queryKey:["pending-onboarding",B?.id],queryFn:()=>xe(),enabled:!!B,staleTime:6e4}),U=$.data&&!$.data.consumed?$.data.handoff:null,J=U?_r(U):"";t.useEffect(()=>{J&&d(m=>m===""?J:m)},[J]);const Z=z(dr);t.useEffect(()=>{const m=B?.email;m&&N(T=>T===""?m:T)},[B?.email]),t.useEffect(()=>{if(!B?.id)return;let m=!1;return Z().then(T=>{m||!T||(T.firstName&&j(H=>H===""?T.firstName:H),T.role&&M(H=>H===""?T.role:H),T.firm&&se(H=>H===""?T.firm:H))}).catch(()=>{}),()=>{m=!0}},[B?.id,Z]);const ae=z(Dt),V=Ee({queryKey:["my-credits",B?.id],queryFn:()=>ae(),enabled:!!B?.id,staleTime:3e4}),G=V.data?.credits_remaining??null,oe=V.data?.trial_available??!1,[le,he]=t.useState(""),[Ce,ge]=t.useState(!1),[be,Ie]=t.useState(!0);t.useEffect(()=>{if(Ce||G===null)return;const m=Math.max(0,Math.min(100,G));he(String(m))},[G,Ce]);const[ie,ee]=t.useState(!1),[ce,ne]=t.useState(null),je=z(cr),y=z(Rt),[x,C]=t.useState(null),Q=z(Ct),L=t.useRef(null);t.useEffect(()=>{ce&&L.current&&L.current.scrollIntoView({behavior:"smooth",block:"center"})},[ce]);const ue=n!==null||c!==null||u.trim().length>0,fe=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l.trim()),ye=Number(le),we=oe?!0:le.trim()!==""&&Number.isInteger(ye)&&ye>=10&&ye<=1e3,Le=oe?!1:we&&G!==null&&ye>G,de=G===0,Be=oe?!ie&&fe&&R.trim()&&P.trim()&&ue:!ie&&fe&&R.trim()&&P.trim()&&ue&&we&&!Le;async function Oe(m=!1){ne(null);let T=p;if(E.trim()){const O=wr(E.trim(),p);if(!O){ne(Nr);return}T=O,w(O),D("")}if(!oe&&!we){ne("Number of investors must be an integer between 10 and 1000.");return}const H=h.trim().slice(0,80);if(!m&&H)try{const O=await y({data:{name:H}});if(O.collision){C(O);return}}catch{}ee(!0);try{const O=[n,c,a].filter(X=>X!==null),te=h.trim().slice(0,80);console.log("prepipeline_client","submit",{t_ms:performance.now(),ts_iso:new Date().toISOString(),file_count:O.length,total_b64_chars:O.reduce((X,Se)=>X+Se.base64.length,0)});const A=await je({data:{files:O.map(X=>({name:X.name,category:X.category,base64:X.base64})),description:u,investorTypesRequest:g.trim()||void 0,investorHqLocation:T.length>0?T:void 0,firstName:R,role:P,firm:F,userEmail:l,name:te||ct(),...U?{finderAnswers:U}:{}}}),re=A?.dealId??A?.deal_id;if(!re)throw new Error("Deal creation did not return a deal id");if(U?.firms&&U.firms.length>0)try{await K({data:{dealId:re,domains:U.firms.map(X=>X.domain).filter(X=>X.length>0),firms:U.firms}})}catch{}if(U)try{await _()}catch{}const Pe=await Q({data:{dealId:re,deliveryTarget:oe?void 0:ye,skipOutreach:!be}}),Ne=Pe?.runId??Pe?.run_id;if(!Ne)throw new Error("Run creation did not return a run id");r({runId:Ne,dealId:re,dealName:te||ct()})}catch(O){const te=O instanceof Error?O.message:"Submission failed",A=te.includes("REGION_UNSUPPORTED")?"Outreach generation isn't available from your current location yet. Our AI provider doesn't support requests from this region. If you're using a VPN, connect to a United States location and try again. Your Investor Readiness Report is unaffected and works from any location.":te;ne(A),ee(!1)}}return e.jsxs("div",{className:"space-y-10",children:[ie?e.jsxs("div",{className:"rounded-lg border border-border bg-card p-8 text-center",children:[e.jsx(ve,{className:"mx-auto mb-3 h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Reading your materials and generating a planâ¦"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"This usually takes 10â20 seconds."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"font-serif text-4xl leading-tight tracking-tight text-foreground sm:text-5xl",children:"Take a deal to market in minutes."}),e.jsx("p",{className:"max-w-2xl text-base text-muted-foreground",children:"Drop your materials and weâll deliver a vetted investor list with a personalised draft for every recipient."})]}),e.jsxs("section",{className:"space-y-5",children:[e.jsx(et,{num:"01",eyebrow:"The deal",title:"Your materials",description:"Share whatever you have. Any single file or a written description is enough to start."}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("label",{htmlFor:"deal-name-input",className:"block text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Deal name"}),h.length>60?e.jsxs("span",{className:`text-xs ${h.length>=80?"text-destructive":"text-muted-foreground"}`,children:[h.length," / 80"]}):null]}),e.jsx("input",{id:"deal-name-input",type:"text",value:h,maxLength:80,onChange:m=>f(m.target.value),placeholder:"Acme Series B, Northwind Credit Fund, Globex SFR
1- anything that helps you find this later.",className:"block w-full rounded-md border border-brand-line bg-brand-paper-2/40 px-3 py-2.5 text-[15px] text-foreground placeholder:text-muted-foreground/70 shadow-sm transition-colors hover:border-dashed hover:border-brand-accent focus:outline-none focus:border-brand-accent focus:border-solid focus:ring-2 focus:ring-brand-accent/20 focus:bg-brand-paper"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional - if blank, weâll use a timestamp."})]}),e.jsxs("div",{className:"space-y-4 border-t border-brand-line pt-5",children:[!ue&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Provide at least one file or a description of the deal."}),e.jsx(He,{label:"Investor presentation or supporting materials",hint:"PDF or DOCX · optional",accept:".pdf,.docx",value:n,onChange:m=>i(m?{...m,category:"presentation"}:null)}),e.jsx(He,{label:"Supporting materials",hint:"PDF or DOCX · optional",accept:".pdf,.docx",value:c,onChange:m=>s(m?{...m,category:"memo"}:null)}),e.jsx(He,{label:"Template email sent to investors",hint:"PDF or DOCX · optional",accept:".pdf,.docx",value:a,onChange:m=>b(m?{...m,category:"template"}:null)})]}),e.jsxs("div",{className:"space-y-2 border-t border-brand-line pt-5",children:[e.jsx("label",{htmlFor:"deal-description",className:"block text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Or describe the deal"}),e.jsx(mr,{id:"deal-description",value:u,onChange:m=>d(m.target.value),rows:5,maxLength:ot,placeholder:"Sector, stage, structure, size, key terms, anything investors should know.",className:"resize-none rounded-md border border-brand-line bg-brand-paper-2/40 shadow-sm transition-colors hover:border-dashed hover:border-brand-accent focus-visible:border-brand-accent focus-visible:border-solid focus-visible:ring-2 focus-visible:ring-brand-accent/20 focus-visible:bg-brand-paper text-[15px]! leading-[1.6] md:text-[15px]!"}),e.jsxs("div",{className:"text-right text-xs text-muted-foreground",children:[u.length.toLocaleString("en-US")," / ",ot.toLocaleString("en-US")]})]}),e.jsxs("div",{className:"space-y-2 border-t border-brand-line pt-5",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsxs("label",{htmlFor:"deal-investor-types",className:"block text-xs font-medium uppercase tracking-wider text-muted-foreground",children:["What types of investors are you targeting?"," ",e.jsx("span",{className:"ml-1 normal-case tracking-normal text-muted-foreground/70",children:"(optional)"})]}),e.jsx("button",{type:"button",onClick:()=>Y(!0),className:"text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",children:"Browse types"})]}),e.jsx(vt,{id:"deal-investor-types",ref:q,value:g,onChange:m=>k(m.target.value.slice(0,500)),maxLength:500,placeholder:'e.g., growth equity, single family offices, angels, specialty lenders. Or "all except SPACs". Or "All".',className:"rounded-md border-brand-line bg-brand-paper-2/40 shadow-sm transition-colors hover:border-dashed hover:border-brand-accent focus-visible:border-brand-accent focus-visible:border-solid focus-visible:ring-2 focus-visible:ring-brand-accent/20 focus-visible:bg-brand-paper text-[15px]! md:text-[15px]!"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Plain English. Include what you want, or exclude what you donât. Optional. Blank means âAllâ."})]}),e.jsxs("div",{className:"space-y-2 border-t border-brand-line pt-5",children:[e.jsxs("label",{htmlFor:"deal-investor-hq-location",className:"block text-xs font-medium uppercase tracking-wider text-muted-foreground",children:["Investor HQ location"," ",e.jsx("span",{className:"ml-1 normal-case tracking-normal text-muted-foreground/70",children:"(optional)"})]}),e.jsx(yr,{inputId:"deal-investor-hq-location",value:p,onChange:w,onPendingTextChange:D}),e.jsx("p",{className:"text-xs text-muted-foreground",children:vr})]}),e.jsx(jr,{open:W,onOpenChange:Y,onAdd:m=>{if(m.length===0)return;const T=g.trim(),H=new Set(T.split(",").map(A=>
1A.trim().toLowerCase()).filter(Boolean)),O=m.filter(A=>!H.has(A.toLowerCase()));if(O.length===0){q.current?.focus();return}const te=T?`${T}, ${O.join(", ")}`:O.join(", ");k(te.slice(0,500)),setTimeout(()=>q.current?.focus(),0)}}),oe?e.jsxs("div",{className:"border-t border-brand-line pt-5",children:[e.jsxs("p",{className:"text-sm text-brand-ink",children:["Your first sample is free:"," ",e.jsxs("span",{className:"font-medium",children:[$t," free contacts"]}),", on us."]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Top up credits to run a full deal of 10 to 1000 investors on your next one."})]}):G!==null&&G<10?e.jsxs("div",{className:"space-y-2 border-t border-brand-line pt-5",children:[e.jsx("h3",{className:"font-serif text-lg text-brand-ink",children:"You need at least 10 credits to start a deal."}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["You have ",G,". Add credits to continue."]}),e.jsx(Ae,{asChild:!0,className:"mt-1",children:e.jsx(_e,{to:"/buy-credits",children:"Buy credits"})})]}):e.jsxs("div",{className:"space-y-2 border-t border-brand-line pt-5",children:[e.jsxs("label",{htmlFor:"delivery-target-input",className:"block text-xs font-medium uppercase tracking-wider text-muted-foreground",children:["Number of investors",e.jsx(ht,{delayDuration:200,children:e.jsxs(gt,{children:[e.jsx(bt,{asChild:!0,children:e.jsx(Lt,{size:14,className:"ml-1.5 inline-flex align-middle text-brand-muted cursor-help"})}),e.jsx(yt,{side:"top",className:"z-50",children:"Each investor costs one credit. One credit delivers one matched investor with the outreach drafted in your voice."})]})})]}),e.jsx("input",{id:"delivery-target-input",type:"number",min:10,max:1e3,step:1,value:le,onChange:m=>{ge(!0),he(m.target.value)},disabled:de,title:de?"You're out of credits. Top up to start a new deal.":void 0,"aria-invalid":de||Le||le.trim()!==""&&!we?!0:void 0,className:"block w-full max-w-[200px] rounded-md border border-brand-line bg-brand-paper-2/40 px-3 py-2.5 text-base font-medium tabular-nums text-foreground shadow-sm transition-colors hover:border-dashed hover:border-brand-accent focus:outline-none focus:border-brand-accent focus:border-solid focus:ring-2 focus:ring-brand-accent/20 focus:bg-brand-paper disabled:cursor-not-allowed disabled:opacity-60 aria-invalid:border-destructive aria-invalid:ring-destructive/20"}),de?e.jsx("p",{className:"text-xs text-destructive",children:"Youâre out of credits. Top up to start a new deal."}):Le&&G!==null?e.jsxs("p",{className:"text-xs text-destructive",children:["You only have ",G," credits available. Reduce to ",G," or top up."]}):le.trim()!==""&&!we?e.jsx("p",{className:"text-xs text-destructive",children:"Must be an integer between 10 and 1000."}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"How many outreach rows to deliver (10 to 1000). Defaults to your available credits, up to 100."})]}),e.jsx(Ot,{id:"new-deal-draft-outreach",checked:be,onChange:Ie,disabled:de})]}),e.jsxs("section",{className:"space-y-5",children:[e.jsx(et,{num:"02",eyebrow:"You",title:"About you",description:"We use this to personalise every outbound draft."}),e.jsx("div",{className:"rounded-lg border border-brand-line bg-brand-paper-2/60 shadow-sm",children:e.jsxs("div",{className:"px-4",children:[e.jsx(Ve,{label:"First name *",value:R,onChange:m=>j(m.target.value),placeholder:"Jane"}),e.jsxs("div",{className:"flex flex-col gap-1.5 border-b border-brand-line py-3 last:border-b-0",children:[e.jsx("label",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Role *"}),e.jsxs(Et,{value:P,onValueChange:M,children:[e.jsx(Ft,{className:"h-auto border-0 bg-transparent px-0 py-0 text-foreground shadow-none focus:ring-0 focus-visible:ring-0 data-[placeholder]:text-muted-foreground/70",children:e.jsx(It,{placeholder:"Select your roleâ¦"})}),e.jsxs(Pt,{children:[e.jsx(Ze,{value:"Banker representing the issuer",children:"Banker representing the issuer"}),e.jsx(Ze,{value:"Founder/CEO/GP raising directly",children:"Founder / CEO / GP raising directly"})]})]})]}),e.jsx(Ve,{label:"Firm name",value:F,onChange:m=>se(m.target.value),placeholder:"Optional"}
1),e.jsx(Ve,{label:"Email *",type:"email",value:l,onChange:m=>N(m.target.value),placeholder:"[email protected]",error:l.trim().length>0&&!fe?"Please enter a valid email address.":void 0})]})})]}),ce&&e.jsx("div",{ref:L,role:"alert","aria-live":"polite",className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:me(ce)}),e.jsxs("div",{className:"flex items-center justify-between gap-4 border-t border-brand-line pt-6",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"By submitting you agree your materials will be processed to draft outreach."}),e.jsx(Ae,{size:"lg",disabled:!Be,onClick:()=>{Oe()},className:"min-w-[180px] hover:outline-dashed hover:outline-2 hover:outline-offset-2 hover:outline-brand-accent",children:"Build my outreach"})]})]}),e.jsx(Tt,{collision:x,onOpenChange:m=>{m||C(null)},onContinue:()=>{C(null),Oe(!0)}})]})}function Mr({runId:r,onRun:n,onCancel:i,onDealName:c,gateStartRun:s}){return e.jsx(Br,{runId:r,onRun:n,onCancel:i,onDealName:c,gateStartRun:s})}function Br({runId:r,onRun:n,onCancel:i,onDealName:c,gateStartRun:s}){const[a,b]=t.useState(null),[v,u]=t.useState(!1),[d,h]=t.useState(""),[f,g]=t.useState(!1),[k,p]=t.useState(null),[w,E]=t.useState(""),[D,W]=t.useState(""),[Y,q]=t.useState(!1),[l,N]=t.useState(null),R=t.useRef(!1),j=t.useRef(null),P=z(_t),M=z(er),F=z(tr),se=z(rr),[B,xe]=t.useState(null),_=t.useRef(!1),[K,$]=t.useState(null),[U,J]=t.useState(null),[Z,ae]=t.useState([]),[V,G]=t.useState([]),oe=t.useRef(!1),[le,he]=t.useState([]),[Ce,ge]=t.useState([]),[be,Ie]=t.useState([]),[ie,ee]=t.useState([]),ce=t.useRef(!1),[ne,je]=t.useState([]),[y,x]=t.useState([]),[C,Q]=t.useState([]),[L,ue]=t.useState([]),fe=t.useRef(!1),ye=t.useRef(!1);t.useEffect(()=>{ye.current||!a||!a.plan_json||(ye.current=!0,console.log("prepipeline_client","plan_review_mount",{t_ms:performance.now(),ts_iso:new Date().toISOString(),runId:r,status:a.status}))},[a,r]);const we=z(sr),de=Ee({queryKey:["planVocabulary"],queryFn:()=>we(),staleTime:1e3*60*60}).data?.vocab,{tour_choice:Be,plan_tour_dismissed_at:Oe,markSeen:m}=gr(),T=Be==="yes"&&Oe===null,[H,O]=t.useState(1),te=()=>{O(0),m("plan_tour_dismissed_at")};if(t.useEffect(()=>{let o=!1;async function S(){try{const I=await Fe({data:{runId:r}});if(o||b(I),!o&&I&&!R.current&&I.deal_id){R.current=!0;try{const pe=(await tt({data:{dealId:I.deal_id}})).deal?.name??"";o||(E(pe),W(pe),c?.(pe))}catch{}}!o&&I&&I.status==="planning"&&setTimeout(S,1500)}catch(I){o||p(I instanceof Error?I.message:"Failed to load plan")}}return S(),()=>{o=!0}},[r]),t.useEffect(()=>{if(!a||!a.plan_json||_.current)return;const o=a.plan_json;if(Te(o.branch)!=="Fund")return;_.current=!0;const S=Array.isArray(o.lpTargets)?o.lpTargets:null;xe(S&&S.length>0?S:Kt(o))},[a]),t.useEffect(()=>{if(!a||!a.plan_json||oe.current)return;const o=a.plan_json;if(Te(typeof o.branch=="string"?o.branch:void 0)!=="Loans/Debt")return;oe.current=!0;const S=o.loanTypePickKind==="category"?"category":"type",I=typeof o.loanTypePrimary=="string"?o.loanTypePrimary:null,Re=Array.isArray(o.loanTargets)?o.loanTargets.map(String):[];if(I){$(S),J(I);const pe=Zt(S,I);G(pe),ae(Re.length>0?Re:pe)}},[a]),t.useEffect(()=>{if(!a||!a.plan_json||ce.current)return;const o=a.plan_json;if(Te(typeof o.branch=="string"?o.branch:void 0)!=="DirectEquityMezz")return;ce.current=!0;const S=I=>Array.isArray(I)?I.map(String):[];he(S(o.industryTypes)),ge(S(o.companyTypes)),Ie(S(o.verticalTypes)),ee(S(o.stageTypes))},[a]),t.useEffect(()=>{if(!a||!a.plan_json||fe.current)return;const o=a.plan_json;if(Te(typeof o.branch=="string"?o.branch:void 0)!=="RealEstate")return;fe.current=!0;const S=pe=>Array.isArray(pe)?pe.map(String):[],I=S(o.realEstatePropertyTypes),Re=S(o.realEstateEquityOrDebt);je(I),x(Re),Q(I),ue(Re)},[a]),k)return e.jsx(ut,{message:me(k)??k,onCancel:i});if(!a||!a.plan_json)return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-8 text-center",children:[e.jsx(ve,{className:"mx-auto mb-3 h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Generating planâ¦"})]});if(a.status==="error")return e.jsx(ut,{message:me(a.error_message)??"Plan failed",onCancel:i});const A=a.plan_json,re=Te(A.branch),Pe=re==="DirectEquityMezz"?Gt(A,{industryTypes:le,companyTypes:Ce,verticalTypes:be,stageTypes:ie}):{},Ne=Object.keys(Pe).length>0,X=re==="RealEstate",Se=(()=>
1{if(!X)return!1;if(ne.length!==C.length)return!0;for(let o=0;o<ne.length;o++)if(ne[o]!==C[o])return!0;if(y.length!==L.length)return!0;for(let o=0;o<y.length;o++)if(y[o]!==L[o])return!0;return!1})();async function $e(o=!1){if(!s())return;const S=w.trim();if(!o&&S&&S!==D.trim())try{const I=await Rt({data:{name:S,excludeDealId:a?.deal_id??null}});if(I.collision){N(I);return}}catch{}if(A?.materialsSufficient===!1){q(!0);return}await rt()}async function rt(){console.log("prepipeline_client","click_run",{t_ms:performance.now(),ts_iso:new Date().toISOString(),runId:r});const o=w.trim();if(o.length<1||o.length>100){p("Deal name is required (1â100 characters)");return}g(!0),p(null);try{if(await j.current?.flushPending(),a?.deal_id&&o!==D.trim()&&(await ur({data:{dealId:a.deal_id,name:o}}),c?.(o)),re==="Fund"&&B&&B.length>0&&await M({data:{runId:r,lpTargets:B}}),re==="Loans/Debt"&&K&&U&&await F({data:{runId:r,loanTypePickKind:K,loanTypePrimary:U,loanTargets:Z}}),X&&Se&&await se({data:{runId:r,realEstatePropertyTypes:ne,realEstateEquityOrDebt:y}}),re==="Loans/Debt"&&(!U||!Z||Z.length===0)){p("Select a loan type before starting this run. The loan-type targeting picker above must have at least one entry checked."),g(!1);return}await P({data:{runId:r}}),n()}catch(S){p(S instanceof Error?S.message:"Failed to start"),g(!1)}}async function Ue(){const o=d.trim().length>0;if(!(!o&&!Ne&&!Se)){g(!0),p(null);try{o&&await or({data:{runId:r,feedback:d}}),Ne&&await ir({data:{runId:r,...Pe}}),X&&Se&&await se({data:{runId:r,realEstatePropertyTypes:ne,realEstateEquityOrDebt:y}});const S=await Fe({data:{runId:r}});b(S),h(""),u(!1),ce.current=!1,fe.current=!1}catch(S){p(S instanceof Error?S.message:"Adjust failed")}finally{g(!1)}}}return e.jsxs("div",{className:"space-y-6",children:[A.investorTypeFallback&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900",children:[e.jsx(De,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:"Investor type was unclear from the materials - please use Adjust to clarify."})]}),e.jsxs("section",{children:[e.jsx("label",{htmlFor:"deal-name",className:"mb-1.5 block text-sm font-medium",children:"Deal name"}),e.jsx("input",{id:"deal-name",type:"text",value:w,maxLength:100,onChange:o=>E(o.target.value),placeholder:"e.g., ARS Aviation Q3",className:"w-full rounded-md border border-input bg-background px-3 py-2 text-[15px] leading-[1.6]"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"1â100 characters. You can rename later from the deal page."})]}),e.jsx(St,{plan:A,headingNode:e.jsx(Me,{open:T&&H===1,title:"This is what we read from your materials.",body:"Check it. If anything is off, Adjust sends you back to fix it before we spend a credit.",step:{current:1,total:3},primaryLabel:"Next",onPrimary:()=>O(2),onDismiss:te,children:e.jsx("h2",{className:"mb-2 text-base font-semibold",children:"Here's what we understood about your raise:"})})}),Array.isArray(A.investor_hq_location)&&(A.investor_hq_location??[]).length>0&&e.jsxs("p",{className:"text-sm text-foreground",children:["Investor HQ locations:"," ",(A.investor_hq_location??[]).join(", ")]}),Number(a?.delivery_target)>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(ke,{label:"Requested investors",value:String(a.delivery_target)})}),e.jsxs("section",{children:[e.jsx(Me,{open:T&&H===2,title:"This is the plan.",body:"We match investors against your deal, then draft outreach in your voice for each one.",step:{current:2,total:3},primaryLabel:"Next",onPrimary:()=>O(3),onDismiss:te,children:e.jsx("h2",{className:"mb-2 text-base font-semibold",children:"Here's what we'll do:"})}),e.jsxs("ul",{className:"space-y-1.5 text-sm",children:[e.jsxs("li",{children:["⢠We will find ",e.jsx("strong",{children:A.investorTypePhrase}),A.typeFilterSummary&&e.jsxs(e.Fragment,{children:[", restricted to ",e.jsx("strong",{children:A.typeFilterSummary})]})]}),e.jsx("li",{children:"⢠We will identify the best contact at each investor"}),e.jsxs("li",{children:["⢠We will draft a personalized email and LinkedIn message for each contact in"," ",e.jsx("strong",{children:A.voiceDescriptor})]}),e.jsxs("li",{children:["⢠You will receive a spreadsheet with all of this in about"," ",e.jsx("strong",{children:(()=>{const o=a?.delivery_target??100,{lo:S,hi:I}=wt(o);return`~${S}â${I} minutes`})()})]})]})]}),e.jsx(Fr,{plan:A,onReupload:i}),re==="Fund"&&B&&e.jsx(Qt,{value:B,onChange:xe}),re==="Loans/Debt"&&e.jsxs(e.Fragment,{children:[e.jsx(Wt,{checked:Z,onChange:ae,onReset:()=>{V.length>0&&ae(V)},canReset:V.length>0&&(V.length!==Z.length||V.some((o,S)=>o!==Z[S]))}),k&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:me(k)}),v?e.jsxs("div",{className:"space-y-3 rounded-md border border-border p-4",children:[e.jsx("label",{className:"block text-sm font-medium",children:"What should we change?"}),e.jsx("textarea",{value:d,onChange:o=>h(o.target.value),rows:4,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-[15px] leading-[1.6]",placeholder:"e.g., Focus on growth equity, not venture. We're a Series C, not seed."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:f||!d.trim(),onClick:Ue,className:"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:f?"Updatingâ¦":"Update Plan"}),e.jsx("button",{onClick:()=>{u(!1),h("")},className:"rounded-md border border-input px-4 py-2 text-sm",children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx(Me,{open:T&&H===3,title:"Running spends credits.",body:"One
1credit per matched investor. Your first run is free.",step:{current:3,total:3},primaryLabel:"Got it",onPrimary:te,onDismiss:te,children:e.jsx("button",{disabled:f,onClick:()=>{$e()},className:"rounded-md bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground disabled:opacity-50",children:"Run It"})}),e.jsx("button",{disabled:f,onClick:()=>u(!0),className:"rounded-md border border-input bg-background px-5 py-2.5 text-sm font-medium hover:bg-accent disabled:opacity-50",children:"Adjust"}),e.jsx("button",{disabled:f,onClick:i,className:"text-sm text-muted-foreground underline hover:text-foreground",children:"Cancel"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This is the targeting we will run. Click chips below to add or remove loan types â the ladder is your curated list."}),e.jsx(Xt,{checked:Z,onChange:ae})]}),re!=="Loans/Debt"&&e.jsxs(e.Fragment,{children:[k&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:me(k)}),v?e.jsxs("div",{className:"space-y-3 rounded-md border border-border p-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{disabled:f||!d.trim()&&!Ne&&!Se,onClick:Ue,className:"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:f?"Updatingâ¦":"Update Plan"})}),re==="DirectEquityMezz"&&e.jsxs(e.Fragment,{children:[e.jsx(qe,{label:"Industry Types",value:le,options:de?.industryTypes??[],onChange:he}),e.jsx(qe,{label:"Company Types",value:Ce,options:de?.companyTypes??[],onChange:ge}),e.jsx(qe,{label:"Vertical Types",value:be,options:de?.verticalTypes??[],onChange:Ie}),e.jsx(qe,{label:"Stage Types",value:ie,options:de?.stageTypes??[],onChange:ee})]}),X&&e.jsx(Jt,{propertyTypes:ne,onPropertyTypesChange:je,propertyVocab:de?.realEstatePropertyTypes??[],capitalTypes:y,onCapitalTypesChange:x}),e.jsx("label",{className:"block text-sm font-medium",children:"What should we change?"}),e.jsx("textarea",{value:d,onChange:o=>h(o.target.value),rows:4,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-[15px] leading-[1.6]",placeholder:"e.g., Focus on growth equity, not venture. We're a Series C, not seed."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:f||!d.trim()&&!Ne&&!Se,onClick:Ue,className:"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:f?"Updatingâ¦":"Update Plan"}),e.jsx("button",{onClick:()=>{u(!1),h("")},className:"rounded-md border border-input px-4 py-2 text-sm",children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx(Me,{open:T&&H===3,title:"Running spends credits.",body:"One credit per matched investor. Your first run is free.",step:{current:3,total:3},primaryLabel:"Got it",onPrimary:te,onDismiss:te,children:e.jsx("button",{disabled:f,onClick:()=>{$e()},className:"rounded-md bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground disabled:opacity-50",children:"Run It"})}),e.jsx("button",{disabled:f,onClick:()=>u(!0),className:"rounded-md border border-input bg-background px-5 py-2.5 text-sm font-medium hover:bg-accent disabled:opacity-50",children:"Adjust"}),e.jsx("button",{disabled:f,onClick:i,className:"text-sm text-muted-foreground underline hover:text-foreground",children:"Cancel"})]})]}),a?.deal_id&&e.jsx(jt,{ref:j,dealId:a.deal_id,collapsible:!0,title:"Excluded firms (optional)"}),e.jsx(ze,{open:Y,onOpenChange:q,children:e.jsxs(Ye,{children:[e.jsxs(Ke,{children:[e.jsx(Ge,{children:"Run anyway?"}),e.jsxs(Qe,{children:[A.insufficientReason??"This deal doesn't have enough detail to produce useful matches."," ","Running now will use approximately ",Number(a?.delivery_target)||0," credit",Number(a?.delivery_target)===1?"":"s","."]})]}),e.jsxs(We,{children:[e.jsx(Xe,{disabled:f,children:"Cancel"}),e.jsx(Je,{disabled:f,onClick:o=>{o.preventDefault(),q(!1),rt()},children:"Run"})]})]})}),e.jsx(Tt,{collision:l,onOpenChange:o=>{o||N(null)},onContinue:()=>{N(null),$e(!0)}})]})}const $r=[{id:"setup",backendStage:1},{id:"match",backendStage:1},{id:"identify",backendStage:2},{id:"draft",backendStage:3},{id:"build",backendStage:4}];function Ur({target:r,snap:n}){const[i,c]=t.useState(0),s=t.useRef(0),a=t.useRef(0),b=t.useRef(0),v=t.useRef(2e3),u=t.useRef(null);return t.useEffect(()=>{const d=Math.max(a.current,r);
1if(n){u.current!=null&&cancelAnimationFrame(u.current),u.current=null,a.current=d,s.current=d,c(d);return}if(d===a.current&&i===d)return;s.current=i,a.current=d,b.current=performance.now();const h=Math.max(0,a.current-s.current);v.current=Math.min(12e3,Math.max(1800,h*120));const f=g=>{const k=Math.min(1,(g-b.current)/v.current),p=1-Math.pow(1-k,3),w=Math.round(s.current+(a.current-s.current)*p);c(w),k<1?u.current=requestAnimationFrame(f):u.current=null};return u.current!=null&&cancelAnimationFrame(u.current),u.current=requestAnimationFrame(f),()=>{u.current!=null&&cancelAnimationFrame(u.current),u.current=null}},[r,n]),e.jsx("span",{className:"tabular-nums",children:i})}function Vr({runId:r,onComplete:n,onNeedsRefinement:i,onStartOver:c}){const[s,a]=t.useState(null),[b,v]=t.useState(!1),[u,d]=t.useState(!1),h=t.useRef(Date.now()),[,f]=t.useState(0);t.useEffect(()=>{const y=setInterval(()=>f(x=>x+1),1e3);return()=>clearInterval(y)},[]);const g=t.useRef(null),[k,p]=t.useState(!1),w=15e3,E=t.useRef(it()),D=t.useRef(it()),W=t.useRef(0),Y=t.useRef(Date.now()),q=t.useRef(0),l="cd:match-latch:",N=`${l}${r}`,R=()=>{if(typeof window>"u")return{done:!1,matchedFinal:null};try{for(let C=window.sessionStorage.length-1;C>=0;C--){const Q=window.sessionStorage.key(C);Q&&Q.startsWith(l)&&Q!==N&&window.sessionStorage.removeItem(Q)}const y=window.sessionStorage.getItem(N);if(!y)return{done:!1,matchedFinal:null};const x=JSON.parse(y);return{done:x.done===!0,matchedFinal:typeof x.matchedFinal=="number"?x.matchedFinal:null}}catch{return{done:!1,matchedFinal:null}}},j=t.useRef(R()),P=t.useRef(j.current.done),M=t.useRef(j.current.matchedFinal),F=y=>{if(!(typeof window>"u"))try{window.sessionStorage.setItem(N,JSON.stringify({done:!0,matchedFinal:y}))}catch{}};t.useEffect(()=>{if(!(typeof window>"u"))return console.log("[RunningView] mount",{runId:r,rehydratedLatch:j.current,t:new Date().toISOString()}),()=>{console.log("[RunningView] unmount",{runId:r,matchDoneAtUnmount:P.current,matchedFinalAtUnmount:M.current,t:new Date().toISOString()})}},[r]);const se=Ut();t.useEffect(()=>{if(!(typeof window>"u")&&s&&(s.status==="complete"||s.status==="error"||s.status==="canceled"||s.status==="needs_refinement")){try{window.sessionStorage.removeItem(N)}catch{}se.invalidateQueries({queryKey:["my-recent-deals"]}),s.deal_id&&se.invalidateQueries({queryKey:["deal-detail",s.deal_id]})}},[s?.status,r]),t.useEffect(()=>{if(typeof window>"u")return;const y=new URLSearchParams(window.location.search);if(y.get("runId")===r)return;y.set("runId",r),y.delete("dealId");const x=y.toString();window.history.replaceState(null,"",x?`${window.location.pathname}?${x}`:window.location.pathname)},[r]),t.useEffect(()=>{let y=!1,x=null;async function C(){try{const Q=await Fe({data:{runId:r}});if(y)return;if(a(Q),Q.status==="complete"){if(g.current=null,p(!1),se.invalidateQueries({queryKey:["my-credits"]}),typeof window<"u"){const L=new URLSearchParams(window.location.search);if(L.has("runId")){L.delete("runId");const ue=L.toString();window.history.replaceState(null,"",ue?`${window.location.pathname}?${ue}`:window.location.pathname)}}n();return}if(Q.status==="needs_refinement"){g.current=null,p(!1),se.invalidateQueries({queryKey:["my-credits"]}),i();return}if(Q.status==="canceled"){g.current=null,p(!1);return}if(Q.status==="error"){g.current===null&&(g.current=Date.now()),Date.now()-g.current>=w&&p(!0),x=setTimeout(C,2e3);return}g.current!==null&&(g.current=null,p(!1)),x=setTimeout(C,2e3)}catch{y||(x=setTimeout(C,3e3))}}return C(),()=>{y=!0,x&&clearTimeout(x)}},[r,n,i]);async function B(){await E.current.run(async()=>{v(!0);try{await nt({data:{runId:r,fromStage:s?.error_stage??void 0}})}finally{v(!1)}})}async function xe(){await D.current.run(async()=>{const y=s?.investor_results?.length??0;if(window.confirm(`Restart pipeline from Stage 2 (Identifying contacts), preserving ${y} Stage 1 investors?`)){d(!0);try{await nt({data:{runId:r,fromStage:2}})}finally{d(!1)}}})}if(!s)return e.jsx("div",{className:"rounded-lg border border-border bg-card p-8 text-center",children:e.jsx(ve,{className:"mx-auto h-6 w-6 animate-spin text-muted-foreground"})});const _=Math.floor((Date.now()-h.current)/1e3),{lo:K,hi:$,total:U}=wt(s.delivery_target??100),J=Math.max(1,Math.round(U)),Z=Math.floor(_/60),ae=_%60,V=s.investor_results?.length??0;V>W.current&&(W.current=V,Y.current=Date.now()),W.current>q.current&&(q.current=W.current);const G=P.current&&M.current!=null?M.current:q.current,oe=s.contact_results?.length??0,le=typeof s.delivery_target=="number"&&Number.isFinite(s.delivery_target)&&s.delivery_target>=1?Math.floor(s.delivery_target):null,he=oe>0?oe:le??(q.current||0),ge=s.status==="complete"||s.current_stage>=3||s.current_stage>=2&&Date.now()-Y.current>=15e3,be=(s.investor_results?.length??0)>0||s.current_stage>1||s.status==="complete",ie=new Set(["planning","plan_ready","running"]).has(s.status),ee=s.status==="error"&&k,ce=s.status==="canceled",ne=V>0&&(ee||s.status==="running")&&s.current_stage>=1&&s.current_stage<=2,je=s.total_contacts_loaded??null;return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg border border-border bg-card p-6",children:e.jsx("ul",{className:"space-y-3",children:$r.map(y=>{let x=!1,C=!1;y.id==="setup"?(x=be,C=!ee&&ie&&!x):y.id==="match"?(P.current||ge&&(s.current_stage>1||s.status==="complete")&&(P.current=!0,M.current=q.current,F(M.current)),x=P.current,C=!ee&&ie&&be&&!x):y.id==="identify"?(x=s.current_stage>2||s.status==="complete",C=!ee&&ie&&ge&&s.current_stage===2&&!x):y.id==="draft"?(x=s.current_stage>3||s.status==="complete",C=!ee&&ie&&s.current_stage===3&&!x):(x=s.status==="complete",C=!ee&&ie&&s.current_stage===4&&!x);const Q=ee&&s.error_stage===y.backendStage;let L;Q?L={setup:"Setting up: failed",match:"Matching investors: failed",identify:"Identifying contacts: failed",draft:"Drafting outreach: failed",build:"Building spreadsheet: failed"}
1[y.id]:y.id==="setup"?L=x?"Analyzing your deal":"Setting upâ¦":y.id==="match"?x?L=`Matched ${G} investors`:C?L=e.jsxs(e.Fragment,{children:["Matching investorsâ¦"," ",e.jsx(Ur,{target:G,snap:ge})]}):L="Matching investors":y.id==="identify"?x?L=`Selected your top ${he} contacts by rating`:L="Identifying contactsâ¦":y.id==="draft"?L=x?"Drafted outreach":"Drafting outreachâ¦":L=x?"Done":"Building spreadsheetâ¦";const ue=y.id==="identify"&&C&&je!=null;return e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex h-6 w-6 items-center justify-center",children:x?e.jsx(At,{className:"h-5 w-5 text-emerald-600"}):C?e.jsx(ve,{className:"h-5 w-5 animate-spin text-foreground"}):Q?e.jsx(De,{className:"h-5 w-5 text-destructive"}):e.jsx("div",{className:"mt-2 h-2 w-2 rounded-full bg-muted-foreground/30"})}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm "+(x?"text-foreground":C?"font-medium text-foreground":"text-muted-foreground"),children:L}),ue&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Searching ",je.toLocaleString()," investor contacts to find your top ",le??he]})]})]},y.id)})})}),ee?e.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 p-4",children:[e.jsxs("div",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(De,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:me(s.error_message)})]}),(()=>{const x=s.retry_count??0,C=x>=3;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:C?`Retry limit reached (${x}/3). Start a new run.`:`Retries used: ${x}/3`}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[C?null:e.jsx("button",{disabled:b,onClick:B,className:"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:b?"Retryingâ¦":`Retry from step ${s.error_stage}`}),!C&&ne&&s.error_stage!==2?e.jsx("button",{disabled:u,onClick:xe,className:"rounded-md border border-input bg-background px-4 py-2 text-sm font-medium hover:bg-accent disabled:opacity-50",children:u?"Restartingâ¦":`Retry from Stage 2 (keep ${V} investors)`}):null,e.jsx("button",{type:"button",onClick:c,className:"rounded-md border border-input bg-background px-4 py-2 text-sm font-medium hover:bg-accent",children:"Start a new run"})]})]})})()]}):ce?e.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 p-4",children:[e.jsxs("div",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(De,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:me(s.error_message)??"This run was canceled."})]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:e.jsx("button",{type:"button",onClick:c,className:"rounded-md border border-input bg-background px-4 py-2 text-sm font-medium hover:bg-accent",children:"Start a new run"})})]}):e.jsx("div",{className:"space-y-3",children:e.jsxs("p",{className:"text-center text-xs text-muted-foreground",children:["Elapsed ",Z,":",ae.toString().padStart(2,"0")," / ~",J," min"," ","(typical run: ~",K,"â",$," minutes) · Keep this tab open."]})})]})}function Hr({runId:r,onAnother:n}){const[i,c]=t.useState(null),[s,a]=t.useState(!1),[b,v]=t.useState(!1),[u,d]=t.useState(!1);t.useEffect(()=>{Fe({data:{runId:r}}).then(g=>c(g))},[r]);async function h(){a(!0);try{const{url:g}=await ar({data:{runId:r}});g&&i&&c({...i,final_xlsx_url:g})}finally{a(!1)}}async function f(){if(!i?.final_xlsx_url)return;const g=new Date().toISOString().slice(0,10),k=`${Ir(i.deal_name)}_${g}.xlsx`;d(!0);try{const w=await(await fetch(i.final_xlsx_url)).blob(),E=URL.createObjectURL(w),D=document.createElement("a");D.href=E,D.download=k,document.body.appendChild(D),D.click(),D.remove(),setTimeout(()=>URL.revokeObjectURL(E),1e3)}catch{window.open(i.final_xlsx_url,"_blank","noopener")}finally{d(!1)}}return e.jsx(zr,{run:i,runId:r,downloading:u,refreshing:s,showBreakdown:b,onToggleBreakdown:()=>v(g=>!g),onDownload:f,onRefresh:h,onAnother:n})}function zr({run:r,runId:n,downloading:i,refreshing:c,showBreakdown:s,onToggleBreakdown:a,onDownload:b,onRefresh:v,onAnother:u}){const d=z(nr),[h]=t.useState(()=>Date.now()),f=Ee({queryKey:["run-completion-summary",n],queryFn:()=>d({data:{runId:n}}),staleTime:6e4,refetchInterval:l=>{const N=l.state.data;return N?(N.stats?.contacts_total??0)===0&&Date.now()-h<9e4?3e3:!1:2e3}}),g=f.data?.stats.contacts_total??0,k=!!f.data&&g===0&&Date.now()-h<9e4;if(!r||f.isLoading||!f.data||!f.data.deal_id||k)return e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(ve,{className:"h-5 w-5 animate-spin text-muted-foreground"})});const{stats:p,readiness:w,is_first_run:E,deal_id:D}=f.data,W=l=>
1(l.split(/\\N/)[0]??l).replace(/\s*\(PRIMARY TYPE\)\s*/i,"").trim()||"Unspecified",Y=Object.entries(p.type_breakdown).filter(([,l])=>l>0).map(([l,N])=>[W(l),N]).sort((l,N)=>{const R=/family\s*office/i.test(l[0])?1:0,j=/family\s*office/i.test(N[0])?1:0;return R!==j?j-R:N[1]-l[1]}).slice(0,4),q=!!r.final_xlsx_url;return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-emerald-700",children:[e.jsx(At,{className:"h-5 w-5"}),e.jsx("span",{className:"text-sm font-medium uppercase tracking-wide",children:"Your outreach is ready"})]}),e.jsxs("h2",{className:"font-serif text-3xl tracking-tight text-foreground",children:["Your matches for ",r.deal_name??"this deal"," are ready to review and contact."]}),(()=>{const l=r.plan_json?.typeFilterShortfall;return!l||l.delivered>=l.requested?null:e.jsxs("div",{className:"rounded-md border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:["We found ",e.jsx("strong",{children:l.delivered})," of your requested"," ",e.jsx("strong",{children:l.requested})," investors matching your investor-type restriction. To get more, broaden the investor types or remove the restriction."]})})(),e.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:(()=>{const l=p.branch==="Fund",N=Y.filter(([R])=>!/family\s*office/i.test(R)).slice(0,3).map(([R,j])=>[R==="Other"?"Unverified":R,j]);return e.jsxs(e.Fragment,{children:[p.investors_total>0&&e.jsx(ke,{label:"Investors matched",value:String(p.investors_total)}),p.contacts_total>0&&e.jsx(ke,{label:"Contacts",value:String(p.contacts_total)}),Number(r.delivery_target)>0&&e.jsx(ke,{label:"Requested",value:String(r.delivery_target)}),p.rated_80_plus>0&&!l&&e.jsx(ke,{label:"Rated 80+",value:String(p.rated_80_plus)}),p.family_office_count>0&&e.jsx(ke,{label:"Family offices",value:String(p.family_office_count),emphasis:!0}),N.map(([R,j])=>e.jsx(ke,{label:R,value:String(j)},R))]})})()})]}),w&&(w.strengths.length>0||w.lead_profile)&&e.jsxs("section",{className:"space-y-4 rounded-xl border border-border bg-muted/20 p-5",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-serif text-xl text-foreground",children:"Investor Readiness Report"}),w.score!=null&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Readiness score ",w.score,"/100"]})]}),e.jsx(_e,{to:"/deals/$dealId/deck-studio",params:{dealId:D},className:"text-sm font-medium text-primary no-underline hover:underline",children:"View full report â"})]}),w.strengths.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Key strengths"}),e.jsx("div",{className:"space-y-2.5",children:w.strengths.map((l,N)=>e.jsxs("div",{className:"rounded-md border border-border bg-background p-3",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:l.strength}),l.how_to_leverage&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l.how_to_leverage})]},N))})]}),w.lead_profile?.required_profile&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Lead investor profile"}),e.jsx("p",{className:"text-sm text-foreground",children:w.lead_profile.required_profile}),w.lead_profile.why&&e.jsx("p",{className:"text-xs text-muted-foreground",children:w.lead_profile.why})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx(_e,{to:"/deals/$dealId/contacts",params:{dealId:D},onClick:()=>st("completion_cta_clicked",{target:"work_list",is_first_run:E},{deal_id:D,report_id:n}),className:"inline-flex w-full items-center justify-center gap-2 rounded-lg bg-primary px-6 py-4 text-base font-semibold text-primary-foreground no-underline shadow hover:bg-primary/90 sm:w-auto",children:"Go to your investor contact list â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Opens your Investors & Contacts, where you can contact them with bespoke messages, take notes, and track their status."})]}),e.jsxs("section",{className:"flex flex-wrap items-center gap-3 border-t border-border pt-5 text-sm",children:[q?e.jsxs("button",{type:"button",onClick:()=>{st("completion_cta_clicked",{target:"export",is_first_run:E},{deal_id:D,report_id:n}),b()},disabled:i,className:"inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-60",children:[e.jsx(Dr,{className:"h-3.5 w-3.5"}),i?"Preparingâ¦":"Export to spreadsheet"]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"Preparing exportâ¦"}),e.jsx("button",{onClick:v,className:"text-xs text-muted-foreground underline hover:text-foreground",children:c?"Refreshingâ¦":"Get a new download link"}),e.jsx(_e,{to:"/dashboard",className:"text-xs text-muted-foreground no-underline hover:text-foreground",children:"Back to dashboard"}),e.jsx("button",{type:"button",onClick:u,className:"text-xs text-muted-foreground hover:text-foreground",children:"Start another deal"}),e.jsx("div",{className:"ml-auto flex items-center gap-2",children:e.jsx(Yr,{run:r,expanded:s,onToggle:a})})]}),s&&e.jsx(Kr,{run:r})]})}function ke({label:r,value:n,emphasis:i=!1}){return e.jsxs("div",{className:i?"rounded-lg border border-primary/30 bg-primary/5 px-3 py-2":"rounded-lg border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"text-xl font-semibold leading-tight text-foreground",children:n}),e.jsx("div",{className:"text-[12px] uppercase tracking-wider text-muted-foreground",children:r})]})}function qt(r,n=2){return`$${r.toFixed(n)}`}function Yr({run:r,expanded:n,onToggle:i}){const c=Number(r.cost_usd??0);return e.jsxs("button",{type:"button",onClick:i,className:"inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-3 py-2 text-[13.5px] text-muted-foreground hover:bg-accent",title:"Click for per-stage breakdown",children:[n?e.jsx(Cr,{className:"h-3.5 w-3.5"}):e.jsx(Rr,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:["Cost: ",e.jsx("span",{className:"font-medium text-foreground",children:qt(c)})]})]})}function Kr({run:r}){const n=r.stage_costs??{},i=(...u)=>u.reduce((d,h)=>d+(n[h]?.cost??0),0),c=i("stage_0_plan"),s=i("stage_1"),a=i("stage_2"),b=i("stage_3"),v=[["Plan",c],["Investors",s],["Contacts",a],["Outreach",b]];return e.jsx("div",{className:"rounded-md border border-border bg-muted/30 px-4 py-2 text-xs text-muted-foreground",children:v.map(([u,d],h)=>e.jsxs("span",{children:[h>0&&e.jsx("span",{className:"mx-1.5",children:"·"}),u,": ",e.jsx("span",{className:"font-medium text-foreground",children:qt(d,2)})]},u))})}function ut({message:r,onCancel:n}){return e.jsxs("div",{className:"space-y-4 rounded-md border border-destructive/40 bg-destructive/5 p-6",children:[e.jsxs("div",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(De,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:r})]}),e.jsx("button",{onClick:n,className:"rounded-md border border-input bg-background px-4 py-2 text-sm",children:"Start over"})]})}function Gr({runId:r,onContinue:n,onCancel:i}){const[c,s]=t.useState(null),[a,b]=t.useState("__ai__"),[v,u]=t.useState(""),[d,h]=t.useState(!1),[f,g]=t.useState(""),[k,p]=t.useState(!1),[w,E]=t.useState(null);if(t.useEffect(()=>{Fe({data:{runId:r}}).then(l=>{s(l);const N=l.plan_json?.investorTypePhrase??"";dt.includes(N)&&b(N);const j=(l.deal_context??"").match(/--- investor types requested ---\n([\s\S]*?)(?=\n\n---|\n*$)/);u(j?j[1].trim():"")})},[r]),!c||!c.plan_json)return e.jsx("div",{className:"rounded-lg border border-border bg-card p-8 text-center",children:e.jsx(ve,{className:"mx-auto h-6 w-6 animate-spin text-muted-foreground"})});const D=c.plan_json;async function W(){p(!0),E(null);try{await at({data:{runId:r,investorTypePhraseOverride:a==="__ai__"?null:a,investorTypesRequestOverride:d?v:void 0,additionalContext:f}}),n()}catch(l){E(l instanceof Error?l.message:"Refine failed"),p(!1)}}async function Y(){p(!0),E(null);try{await at({data:{runId:r,proceedAnyway:!0}}),n()}catch(l){E(l instanceof Error?l.message:"Failed to continue"),p(!1)}}async function q(){p(!0);try{await kt({data:{runId:r}})}finally{i()}}return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-md border border-amber-300 bg-amber-50 p-4 text-sm text-amber-900",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(De,{className:"mt-0.5 h-4 w-4 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"We need to refine the deal before continuing"}),e.jsx("p",{className:"mt-1",children:me(c.error_message)})]})]})}),e.jsxs("section",{children:[e.jsx("h2",{className:"mb-2 text-base font-semibold",children:"What we understood:"}),e.jsx("p",{className:"text-sm leading-relaxed",children:D.dealSummary}),e.jsxs("p",{className:"mt-2 text-sm",children:["Currently targeting: ",e.jsx("strong",{children:D.investorTypePhrase})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-sm font-medium",children:"Override investor type"}),e.jsxs("select",{value:a,onChange:l=>b(l.target.value),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-[15px] leading-[1.6]",children:[e.jsxs("option",{value:"__ai__",children:["Use AI's recommendation (",D.investorTypePhrase,")"]}),dt.map(l=>e.jsx("option",{value:l,children:l},l))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-sm font-medium",children:"Investor types requested"}
1),e.jsx("textarea",{value:v,onChange:l=>{u(l.target.value.slice(0,500)),h(!0)},rows:2,maxLength:500,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-[15px] leading-[1.6]",placeholder:'e.g., growth equity, single family offices. Or "all except SPACs". Blank means "All".'}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Loosen or rewrite this if the filter excluded too many candidates. Blank = no type filter."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-sm font-medium",children:"Additional context"}),e.jsx("textarea",{value:f,onChange:l=>g(l.target.value),rows:5,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-[15px] leading-[1.6]",placeholder:"Anything about sector, structure, or specific investor types we should focus on."})]}),w&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:me(w)}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{disabled:k,onClick:W,className:"rounded-md bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground disabled:opacity-50",children:k?"Refiningâ¦":"Refine and continue"}),e.jsx("button",{disabled:k,onClick:Y,className:"rounded-md border border-input bg-background px-5 py-2.5 text-sm font-medium hover:bg-accent disabled:opacity-50",children:"Continue with what we found"}),e.jsx("button",{disabled:k,onClick:q,className:"rounded-md border border-input bg-background px-5 py-2.5 text-sm font-medium hover:bg-accent disabled:opacity-50",children:"Cancel"})]})]})}export{Es as component}; 2//# sourceMappingURL=app-5tnogiBG.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.