1import{l as fe,r as l,j as e,U as ge,M as ve,m as y,n as N,o as _,B as o,aI as ye,p as S,I as R,q as b,E as z,X as Ne}from"./index-BghHNOje.js";import{B as C}from"./badge-BCCCWQE0.js";import{D as H,a as U,b as q,c as V,f as W}from"./dialog-Clo9IObs.js";import{S as se,a as ae,b as te,c as ne,d as w}from"./select-BuQ2jC-b.js";import{T as _e,a as Se,b as A,c as be,d as Ce,e as m}from"./table-C5ZVYO-V.js";import{u as we,S as p}from"./useTableSort-B-A7qTri.js";import{T as ke}from"./textarea-CDQn81xI.js";import{P as Fe}from"./PipelineKpiRow-fjMkywHn.js";import{u as De,a as Te,s as Re,b as Ae,S as P,c as le,r as Pe}from"./useStartupOutreach-DCOvgUJt.js";import{C as Be}from"./checkbox-CIRobcpM.js";import{L as Le}from"./LastRunNote-CEh43I8s.js";import{B as $e}from"./building-2-DbXAZakx.js";import{S as Me}from"./shield-check-BRJsKqt_.js";import{L as G}from"./loader-circle-B8iw8PN7.js";import{C as re}from"./check-Cs64SJZX.js";import{B as Oe}from"./bot-CRVg89mO.js";import"./index-B6H0OFpw.js";import"./index-YvgZ23nC.js";import"./chevron-up-D-aySBK5.js";import"./useAdminActionRuns-G3KbyO0S.js";import"./triangle-alert-nzYwmCkk.js";import"./clock-CsNJYkxI.js";const K=i=>{var u;return((u=P.find(r=>r.value===i))==null?void 0:u.label)??i},Ee=i=>{var u;return((u=le.find(r=>r.value===i))==null?void 0:u.label)??i},Ie=(i,u)=>i==null?"Amount undisclosed":`${u||""} ${i.toLocaleString("de-CH",{maximumFractionDigits:0})}`.trim(),ds=()=>{const{toast:i}=fe(),u=De(),r=Te(),j=u.data??[],k=l.useMemo(()=>Re(j),[j]),B=Ae(),ie=l.useMemo(()=>{var n;const s=(n=B.data)==null?void 0:n[0];return s?{started_at:s.started_at,finished_at:s.finished_at,status:s.status==="error"||s.status==="failed"?"error":s.status==="running"?"running":"success",summary:`${s.created_count} companies added, ${s.discovered_count} reviewed`,error_message:s.error_count?`${s.error_count} problems during research`:null}:null},[B.data]),[L,ce]=l.useState(""),[F,de]=l.useState("all"),[f,oe]=l.useState("ready"),[a,X]=l.useState(null),[ue,D]=l.useState(!1),[$,me]=l.useState(P.map(s=>s.value)),[J,xe]=l.useState("Switzerland and Europe"),[Q,he]=l.useState("100"),[T,Y]=l.useState(null),[g,v]=l.useState(null),[M,Z]=l.useState(""),[O,ee]=l.useState(""),c=we(null),E=l.useMemo(()=>{const s=L.trim().toLowerCase(),n=["review_needed","qualified","draft_ready"],d=j.filter(t=>F!=="all"&&t.primary_field!==F||(f==="ready"?!n.includes(t.status):f!=="all"&&t.status!==f)?!1:!s||[t.legal_name,t.trading_name,t.city,t.country_code,t.canonical_domain].filter(Boolean).some(x=>String(x).toLowerCase().includes(s)));return c.sort(d,{company:t=>t.trading_name||t.legal_name||"",field:t=>t.primary_field??"",funding:t=>{const x=(t.funding??[]).map(I=>I.announced_at).filter(I=>!!I).sort();return x.length?new Date(x[x.length-1]):null},contacts:t=>{var x;return((x=t.contacts)==null?void 0:x.length)??0},fit:t=>t.fit_score??null,stage:t=>t.status??""})},[j,L,F,f,c]),h=async(s,n)=>{try{await s(),i({title:n})}catch(d){i({title:"Action failed",description:d.message,variant:"destructive"})}},pe=async s=>{try{const n=await Pe(r,async()=>(await u.refetch()).data??void 0,s,Y);i({title:`${n.created} companies added, ${n.researched} researched`,description:n.failures.length?`Did not work: ${n.failures.map(d=>`${K(d.field)} (${d.message})`).join("; ")}`:n.failed?`${n.failed} could not be completed and are filed under "Contacts missing".`:"Only companies with a named contact and a company inbox count as found."})}catch(n){i({title:"Search failed",description:n.message,variant:"destructive"})}finally{Y(null)}},je=s=>{v(s),Z(s.subject),ee(s.body)};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Fe,{kpis:[{label:"Ready to contact",value:String(k.twoContacts),icon:$e},{label:"Funding accepted",value:String(k.qualified),icon:Me},{label:"Contacts missing",value:String(k.contactsMissing),icon:ge},{label:"Drafts to review",value:String(k.drafts),icon:ve}]}),e.jsxs(y,{children:[e.jsxs(N,{className:"flex flex-row flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-base",children:"Funded deep-tech startups"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Research and drafting only. Nothing can be sent from this workspace."})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs(o,{size:"sm",onClick:()=>D(!0),disabled:!!T,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"})," Find companies"]})}),T?e.jsx("p",{className:"text-xs text-muted-foreground",children:T}):e.jsx(Le,{run:ie,loading:B.isLoading})]})]}),e.jsxs(S,{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(R,{className:"w-full sm:w-64",placeholder:"Search company, city or domainâ¦",value:L,onChange:s=>ce(s.target.value)}),e.jsxs(se,{value:F,onValueChange:de,children:[e.jsx(ae,{className:"w-full sm:w-48",children:e.jsx(te,{})}),e.jsxs(ne,{children:[e.jsx(w,{value:"all",children:"All fields"}),P.map(s=>e.jsx(w,{value:s.value,children:s.label},s.value))]})]}),e.jsxs(se,{value:f,onValueChange:oe,children:[e.jsx(ae,{className:"w-full sm:w-48",children:e.jsx(te,{})}),e.jsxs(ne,{children:[e.jsx(w,{value:"ready",children:"Ready to work on"}),e.jsx(w,{value:"all",children:"All stages"}),le.map(s=>e.jsx(w,{value:s.value,children:s.label},s.value))]})]}),e.jsxs("span",{className:"self-center text-sm text-muted-foreground",children:[E.length," of ",j.length]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(_e,{children:[e.jsx(Se,{children:e.jsxs(A,{children:[e.jsx(p,{direction:c.directionFor("company"),onSort:()=>c.toggle("company"),children:"Company"}),e.jsx(p,{direction:c.directionFor("field"),onSort:()=>c.toggle("field"),children:"Field"}),e.jsx(p,{direction:c.directionFor("funding"),onSort:()=>c.toggle("funding"),children:"Funding"}),e.jsx(p,{direction:c.directionFor("contacts"),onSort:()=>c.toggle("contacts"),children:"Contacts"}),e.jsx(p,{direction:c.directionFor("fit"),onSort:()=>c.toggle("fit"),children:"Fit"}),e.jsx(p,{direction:c.directionFor("stage"),onSort:()=>c.toggle("stage"),children:"Stage"}),e.jsx(be,{className:"text-right",children:"Action"})]})}),e.jsx(Ce,{children:u.isLoading?e.jsx(A,{children:e.jsx(m,{colSpan:7,className:"py-10 text-center",children:e.jsx(G,{className:"mx-auto h-6 w-6 animate-spin text-primary"})})}):E.length===0?e.jsx(A,{children:e.jsx(m,{colSpan:7,className:"py-10 text-center text-muted-foreground",children:"No startup prospects match these filters."})}):E.map(s=>{const n=s.contacts.find(t=>t.contact_type==="decision_maker"),d=s.contacts.find(t=>t.contact_type==="company_inbox");return e.jsxs(A,{children:[e.jsxs(m,{children:[e.jsx("div",{className:"font-medium",children:s.trading_name||s.legal_name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:[s.city,s.country_code].filter(
1Boolean).join(", ")})]}),e.jsx(m,{children:e.jsx(C,{variant:"secondary",children:K(s.primary_field)})}),e.jsx(m,{children:e.jsx(C,{variant:s.funding_status==="accepted"?"default":"outline",children:s.funding_status.replace("_"," ")})}),e.jsx(m,{className:"text-sm",children:s.last_researched_at?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:n?"text-foreground":"text-muted-foreground",children:n?`${n.full_name||n.email}${n.role_title?`, ${n.role_title}`:""}`:"No named contact found"}),e.jsx("br",{}),e.jsx("span",{className:d?"text-foreground":"text-muted-foreground",children:d?d.email:"No company inbox found"})]}):e.jsx("span",{className:"text-muted-foreground",children:"Not researched yet"})}),e.jsx(m,{children:s.fit_score==null?"â":`${s.fit_score}/100`}),e.jsx(m,{children:e.jsx(C,{variant:"outline",children:Ee(s.status)})}),e.jsx(m,{className:"text-right",children:e.jsx(o,{size:"sm",variant:"outline",onClick:()=>X(s),children:"Review"})})]},s.id)})})]})})]})]}),e.jsx(H,{open:ue,onOpenChange:D,children:e.jsxs(U,{children:[e.jsx(q,{children:e.jsx(V,{children:"Research funded startups"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Searches public sources in a small, controlled batch. Every funding claim still needs your acceptance."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Fields"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:P.map(s=>e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Be,{checked:$.includes(s.value),onCheckedChange:n=>me(d=>n?Array.from(new Set([...d,s.value])):d.filter(t=>t!==s.value))}),s.label]},s.value))})]}),e.jsxs("div",{children:[e.jsx(b,{children:"Geography"}),e.jsx(R,{value:J,onChange:s=>xe(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(b,{children:"Target number of companies"}),e.jsx(R,{type:"number",min:1,max:100,value:Q,onChange:s=>he(s.target.value)}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Spread evenly across the ticked fields. Contacts are then looked up automatically."})]})]}),e.jsxs(W,{children:[e.jsx(o,{variant:"outline",onClick:()=>D(!1),children:"Cancel"}),e.jsx(o,{disabled:!!T,onClick:()=>{if(!$.length){i({title:"Tick at least one field.",variant:"destructive"});return}D(!1),pe({fields:$,country_scope:J,limit:Math.max(1,Math.min(100,Number(Q)||100))})},children:"Start search"})]})]})}),e.jsx(H,{open:!!a,onOpenChange:s=>!s&&X(null),children:e.jsx(U,{className:"max-h-[90vh] max-w-4xl overflow-y-auto",children:a&&e.jsxs(e.Fragment,{children:[e.jsx(q,{children:e.jsx(V,{children:a.trading_name||a.legal_name})}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{children:K(a.primary_field)}),e.jsx("span",{children:"·"}),e.jsx("span",{children:[a.city,a.country_code].filter(Boolean).join(", ")}),a.website_url&&e.jsxs("a",{className:"inline-flex items-center gap-1 text-primary hover:underline",href:a.website_url,target:"_blank",rel:"noreferrer",children:["Website ",e.jsx(z,{className:"h-3 w-3"})]})]}),a.intelligence[0]&&e.jsxs(y,{children:[e.jsx(N,{children:e.jsxs(_,{className:"text-sm",children:["Plain-language intelligence · ",a.intelligence[0].total_score,"/100"]})}),e.jsxs(S,{className:"space-y-3 text-sm",children:[e.jsx("p",{children:a.intelligence[0].plain_summary}),e.jsxs("div",{children:[e.jsx("strong",{children:"Why TPL:"})," ",a.intelligence[0].tpl_fit_reason||"Not enough evidence yet."]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Why D4:"})," ",a.intelligence[0].d4_fit_reason||"Not enough evidence yet."]}),a.intelligence[0].missing_evidence.length>0&&e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("strong",{children:"Still missing:"})," ",a.intelligence[0].missing_evidence.join("; ")]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(y,{children:[e.jsx(N,{children:e.jsx(_,{className:"text-sm",children:"Funding evidence"})}),e.jsx(S,{className:"space-y-3",children:a.funding.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No funding evidence yet."}):a.funding.map(s=>e.jsxs("div",{className:"rounded-md border p-3 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap justify-between gap-2",children:[e.jsx("strong",{children:s.round_type||s.funding_kind.replace("_"," ")}),e.jsx(C,{variant:s.review_status==="accepted"?"default":"outline",children:s.review_status})]}),e.jsx("p",{children:Ie(s.announced_amount,s.currency)}),s.evidence_excerpt&&e.jsx("p",{className:"mt-2 text-muted-foreground",children:s.evidence_excerpt}),e.jsxs("a",{className:"mt-2 inline-flex items-center gap-1 text-primary hover:underline",href:s.source_url,target:"_blank",rel:"noreferrer",children:["Open source ",e.jsx(z,{className:"h-3 w-3"})]}),s.review_status==="pending"&&e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsxs(o,{size:"sm",onClick:()=>h(()=>r.updateFunding.mutateAsync({id:s.id,prospectId:a.id,review_status:"accepted"}
1),"Funding accepted"),children:[e.jsx(re,{className:"mr-1 h-3 w-3"}),"Accept"]}),e.jsxs(o,{size:"sm",variant:"outline",onClick:()=>h(()=>r.updateFunding.mutateAsync({id:s.id,prospectId:a.id,review_status:"rejected"}),"Funding rejected"),children:[e.jsx(Ne,{className:"mr-1 h-3 w-3"}),"Reject"]})]})]},s.id))})]}),e.jsxs(y,{children:[e.jsx(N,{children:e.jsx(_,{className:"text-sm",children:"Contacts"})}),e.jsx(S,{className:"space-y-3",children:a.contacts.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No sourced contacts yet."}):a.contacts.map(s=>e.jsxs("div",{className:"rounded-md border p-3 text-sm",children:[e.jsx("div",{className:"font-medium",children:s.full_name||(s.contact_type==="company_inbox"?"Company inbox":"Named contact")}),e.jsx("div",{className:"text-muted-foreground",children:s.role_title}),e.jsx("div",{children:s.email}),e.jsxs("a",{className:"inline-flex items-center gap-1 text-primary hover:underline",href:s.source_url,target:"_blank",rel:"noreferrer",children:["Source ",e.jsx(z,{className:"h-3 w-3"})]}),e.jsx(C,{className:"ml-2",variant:"outline",children:s.quality_status.replace(/_/g," ")})]},s.id))})]})]}),a.drafts.length>0&&e.jsxs(y,{children:[e.jsx(N,{children:e.jsx(_,{className:"text-sm",children:"Drafts for approval"})}),e.jsx(S,{className:"space-y-2",children:a.drafts.map(s=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border p-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.subject}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.recipient_variant.replace("_"," ")," · ",s.status]})]}),e.jsx(o,{size:"sm",variant:"outline",onClick:()=>je(s),children:"Review draft"})]},s.id))})]}),e.jsxs(W,{className:"flex-wrap",children:[e.jsxs(o,{variant:"outline",disabled:r.researchProspect.isPending,onClick:()=>h(()=>r.researchProspect.mutateAsync(a.id),"Research updated"),children:[r.researchProspect.isPending?e.jsx(G,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Oe,{className:"mr-2 h-4 w-4"}),"Research company and contacts"]}),e.jsxs(o,{disabled:a.funding_status!=="accepted"||r.generateDrafts.isPending,onClick:()=>h(()=>r.generateDrafts.mutateAsync(a.id),"Drafts created for review"),children:[r.generateDrafts.isPending&&e.jsx(G,{className:"mr-2 h-4 w-4 animate-spin"}),"Create two drafts"]})]})]})})}),e.jsx(H,{open:!!g,onOpenChange:s=>!s&&v(null),children:e.jsxs(U,{className:"max-w-2xl",children:[e.jsx(q,{children:e.jsx(V,{children:"Review outreach draft"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(b,{children:"Subject"}),e.jsx(R,{value:M,onChange:s=>Z(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(b,{children:"Message"}),e.jsx(ke,{rows:14,value:O,onChange:s=>ee(s.target.value)})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Approval records your review. It does not send or schedule the email."})]}),e.jsxs(W,{children:[e.jsx(o,{variant:"outline",onClick:()=>v(null),children:"Cancel"}),e.jsx(o,{variant:"secondary",onClick:()=>g&&h(async()=>{await r.saveDraft.mutateAsync({id:g.id,subject:M,body:O}),v(null)},"Draft saved"),children:"Save"}),e.jsxs(o,{onClick:()=>g&&h(async()=>{await r.saveDraft.mutateAsync({id:g.id,subject:M,body:O,status:"approved"}),v(null)},"Draft approved, not sent"),children:[e.jsx(re,{className:"mr-2 h-4 w-4"}),"Approve only"]})]})]})})]})};export{ds as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.