1import{k as bs,r,i as M,l as j,dF as ys,j as e,A as ge,dw as vs,al as o,bK as Ns,am as Je,ap as he,X as pe,bG as Le,cz as _s,c$ as Ss,ax as ws,an as ks}from"./vendor-CJ3Pa3Ob.js";import{D as Qe}from"./DiscoveryGovernancePanel-YH8lq3ui.js";import{bl as Cs,cu as Ps,bj as Is,s as _,aS as ze,ao as l,cb as f,cc as b,cd as y,ce as v,cf as K,ai as Es,cv as Ds,cw as qs,cx as U,cy as G,ad as Be,ae as Te,af as $e,ag as Ve,ah as Oe}from"./index-CT7QwV5N.js";import{P as je}from"./progress-DURQ2Zcq.js";import{m as S}from"./maIntelligence-C1t2El_x.js";const Ue=new Set(["paused","completed","failed","cancelled"]),As=i=>i==="paused"||i==="failed"||i==="cancelled",w=i=>{if(typeof i=="number"&&Number.isFinite(i))return i;if(typeof i=="string"&&i.trim()!==""){const m=Number(i);if(Number.isFinite(m))return m}},Qs=()=>{const i=bs(),{showToast:m}=Cs(),{subscribe:fe}=Ps(),{user:Ge}=Is(),be=Ge?.is_superuser??!1,[u,B]=r.useState(null),[P,ye]=r.useState("generic"),[R,ve]=r.useState(""),[W,We]=r.useState(30),[Y,Ye]=r.useState(500),[I,H]=r.useState(null),[J,X]=r.useState(null),[T,L]=r.useState(10),[k,Z]=r.useState(""),[N,ee]=r.useState([]),[se,Ne]=r.useState(!1),[_e,He]=r.useState("software"),[Se,Xe]=r.useState(25),[x,E]=r.useState(null),[Ze,D]=r.useState(null),[we,ke]=r.useState(null),[Ce,Pe]=r.useState(null),[te,es]=r.useState(""),ae=r.useRef(null);r.useEffect(()=>{ae.current=x},[x]);const{data:d,isLoading:$,refetch:ss}=M({queryKey:["ma","stats"],queryFn:async()=>await _.get("/ma/stats"),refetchInterval:5e3});r.useEffect(()=>{if(d?.active_jobs&&d.active_jobs.length>0&&!u){const s=d.active_jobs.filter(c=>c.job_type==="edgar_backfill"),t=s.find(c=>c.status==="running"||c.status==="pending"),n=s.find(c=>c.status==="paused"),h=t??n;h&&B(h.id)}},[d?.active_jobs,u]);const{data:a}=M({queryKey:["ma","backfill","status",u],queryFn:async()=>{if(!u)throw new Error("No active job");return await _.get(`/ma/backfill/status/${u}`)},enabled:!!u,refetchInterval:2e3}),{data:Q}=M({queryKey:["ma","ingestion","sec","status",x],queryFn:async()=>{if(!x)throw new Error("No SEC ingestion job");return await S.getSecIngestionStatus(x)},enabled:!!x}),{data:ts}=M({queryKey:["ma","ingestion","sec","jobs"],queryFn:async()=>await S.listSecIngestionJobs(20),enabled:be}),{data:Ie=[]}=M({queryKey:["ma","import","providers"],queryFn:S.listImportProviders,enabled:be}),C=Ie.filter(s=>s.supports_api_pull),q=Ie.filter(s=>s.supports_file_import),ne=ts?.jobs??[];r.useEffect(()=>{q.length!==0&&(q.some(s=>s.slug===P)||ye(q[0].slug))},[q,P]),r.useEffect(()=>{C.length!==0&&(C.some(s=>s.slug===R)||ve(C[0].slug))},[C,R]),r.useEffect(()=>{Q&&D(s=>!s||s.id===Q.id?Q:s)},[Q]),r.useEffect(()=>fe(t=>{if(t.task_type!=="ma_sec_ingestion")return;const n=t.payload??{},h=t.metadata??{},c=typeof n.job_id=="string"&&n.job_id||typeof h.job_id=="string"&&h.job_id||"";if(!c)return;const xe=ae.current;xe&&xe!==c||(xe||(ae.current=c,E(c)),D(p=>{const V=t.task_status||p?.status||"running",O=n.result&&typeof n.result=="object"?n.result:{},gs=w(n.created)??w(O.created)??0,hs=w(n.updated)??w(O.updated)??0,ps=w(n.failed)??w(O.failed)??0,js=w(n.duration_ms)??w(O.duration_ms)??void 0,fs={...p?.progress??{},stage:typeof n.stage=="string"&&n.stage||typeof h.stage=="string"&&h.stage||V,message:typeof n.message=="string"&&n.message||t.current_step||typeof h.message=="string"&&h.message||void 0,created:gs,updated:hs,failed:ps,duration_ms:js};return{...p??{},id:c,job_type:"sec_ingestion",status:V,task_id:t.celery_task_id||p?.task_id||null,progress:fs,started_at:p?.started_at??t.started_at??new Date().toISOString(),completed_at:Ue.has(V)?t.completed_at??new Date().toISOString():p?.completed_at,error_message:V==="failed"?typeof n.error=="string"&&n.error||typeof n.error_message=="string"&&n.error_message||p?.error_message||"SEC ingestion failed":p?.error_message,created_at:p?.created_at,config:p?.config,celery_task:p?.celery_task}}),Ue.has(t.task_status||"")&&(i.invalidateQueries({queryKey:["ma","stats"]}),i.invalidateQueries({queryKey:["ma","ingestion","sec","jobs"]}),i.invalidateQueries({queryKey:["ma","ingestion","sec","status",c]})))}),[i,fe]);const{data:ie}=M({queryKey:["ma","companies","search",k],queryFn:async()=>!k||k.length<1?{results:[]}:await _.get(`/ma/companies/search?q=${encodeURIComponent(k)}&limit=10`),enabled:k.length>=1}),A=j({mutationFn:async s=>await _.post("/ma/backfill/start",s),onSuccess:s=>{B(s.job_id),ee([]),Z(""),i.invalidateQueries({queryKey:["ma","stats"]})}}),re=j({mutationFn:async s=>await _.post(`/ma/backfill/cancel/${s}`,{}),onSuccess:()=>{i.invalidateQueries({queryKey:["ma","stats"]})}}),le=j({mutationFn:async s=>
1await _.post(`/ma/backfill/retry/${s}`,{}),onSuccess:()=>{i.invalidateQueries({queryKey:["ma","stats"]}),i.invalidateQueries({queryKey:["ma","backfill","status",u]})},onError:s=>{m({title:"Backfill Resume Failed",description:s.message||"Could not resume the EDGAR backfill.",variant:"error"})}}),Ee=j({mutationFn:async s=>{const t=new FormData;return t.append("file",s),await _.postFormData(`/ma/import/preview?provider=${P}`,t)},onSuccess:s=>{H(s)}}),ce=j({mutationFn:async s=>{const t=new FormData;return t.append("file",s),await _.postFormData(`/ma/import/upload?provider=${P}`,t)},onSuccess:()=>{X(null),H(null),i.invalidateQueries({queryKey:["ma","stats"]})}}),de=j({mutationFn:async s=>await S.runProviderPull(s),onSuccess:s=>{B(s.job_id),i.invalidateQueries({queryKey:["ma","stats"]})},onError:s=>{m({title:"API Pull Failed",description:s.message||"Could not start provider API pull. Check credentials and try again.",variant:"error"})}}),oe=j({mutationFn:async s=>await S.runScheduledProviderPulls(s),onSuccess:()=>{i.invalidateQueries({queryKey:["ma","stats"]})},onError:s=>{m({title:"Scheduled Pull Failed",description:s.message||"Could not trigger scheduled provider pulls.",variant:"error"})}}),me=j({mutationFn:async s=>await S.startSecIngestion(s),onSuccess:s=>{E(s.job_id),D({id:s.job_id,job_type:"sec_ingestion",status:"pending",task_id:s.task_id??null,progress:{stage:"queued",message:s.message,created:0,updated:0,failed:0}}),i.invalidateQueries({queryKey:["ma","stats"]}),i.invalidateQueries({queryKey:["ma","ingestion","sec","jobs"]}),m({title:"SEC Ingestion Started",description:`Job ${s.job_id.slice(0,8)} queued.`,variant:"success"})},onError:s=>{let t=s.message||"Could not start SEC ingestion job.";if(s instanceof ze){const n=s.data?.detail;if(typeof n=="string"&&n.trim()){t=n;const h="Duplicate SEC ingestion already running:";if(n.startsWith(h)){const c=n.replace(h,"").trim();c&&(E(c),i.invalidateQueries({queryKey:["ma","ingestion","sec","jobs"]}))}}}m({title:"SEC Ingestion Failed",description:t,variant:"error"})}}),ue=j({mutationFn:async s=>await S.cancelSecIngestion(s),onSuccess:()=>{i.invalidateQueries({queryKey:["ma","stats"]}),i.invalidateQueries({queryKey:["ma","ingestion","sec","jobs"]}),D(s=>s&&{...s,status:"cancelled",completed_at:new Date().toISOString(),progress:{...s.progress??{},stage:"cancelled",message:"SEC ingestion cancelled"}}),m({title:"SEC Ingestion Cancelled",description:"Cancellation requested for the active SEC ingestion job.",variant:"success"})},onError:s=>{m({title:"Cancellation Failed",description:s.message||"Could not cancel SEC ingestion job.",variant:"error"})}}),z=j({mutationFn:async s=>await S.retrySecIngestion(s),onSuccess:s=>{E(s.job_id),D({id:s.job_id,job_type:"sec_ingestion",status:"pending",task_id:s.task_id??null,progress:{stage:"queued",message:s.message,created:0,updated:0,failed:0}}),i.invalidateQueries({queryKey:["ma","stats"]}),i.invalidateQueries({queryKey:["ma","ingestion","sec","jobs"]}),m({title:"SEC Ingestion Retried",description:`Retry job ${s.job_id.slice(0,8)} queued.`,variant:"success"})},onError:s=>{let t=s.message||"Could not retry SEC ingestion job.";if(s instanceof ze){const n=s.data?.detail;typeof n=="string"&&n.trim()&&(t=n)}m({title:"Retry Failed",description:t,variant:"error"})}}),as=r.useCallback(s=>{if(s.length>0){const t=s[0];X(t),Ee.mutate(t)}},[Ee,P]),{getRootProps:ns,getInputProps:is,isDragActive:De}=ys({onDrop:as,accept:{"text/csv":[".csv"]},maxFiles:1}),qe=a?.total_ciks?Math.round(a.processed_ciks/a.total_ciks*100):0,Ae=s=>{switch(s){case"completed":return e.jsx(Le,{className:"h-4 w-4 text-green-600"});case"failed":case"cancelled":return e.jsx(ks,{className:"h-4 w-4 text-red-600"});case"running":case"pending":return e.jsx(o,{className:"h-4 w-4 animate-spin text-theme-accent-text"});default:return e.jsx(ws,{className:"h-4 w-4 text-yellow-600"})}},rs=s=>s==="edgar_backfill"?"EDGAR Backfill":s==="provider_import"?"Provider Import":s==="provider_api_pull"?"Provider API Pull":s,g=Ze??Q??null,F=g?.progress??{},Fe=g?.celery_task?.state,Me=g?.celery_task?.progress??{},ls=typeof Me.message=="string"?Me.message:void 0,Ke=g?.task_id||g?.celery_task?.task_id,Re=F.message||ls||g?.error_message,cs=g?.status==="running"||g?.status==="pending",ds=As(g?.status),os=()=>{const s=_e.split(",").map(t=>
1t.trim()).filter(Boolean);if(s.length===0){m({title:"Keywords Required",description:"Enter at least one keyword to run SEC ingestion.",variant:"error"});return}me.mutate({industry_keywords:s,max_results:Se})},ms=s=>{E(s.id),D(s)},us=s=>{Pe(null),ke(JSON.stringify(s.config??{},null,2))},xs=s=>{ke(null),Pe(s.error_message||"No error captured for this job.")};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"M&A Intelligence Ingestion"}),e.jsx("p",{className:"text-muted-foreground",children:"Populate the M&A deal database from SEC EDGAR and commercial providers"})]}),e.jsxs(l,{variant:"outline",size:"sm",onClick:()=>{ss(),i.invalidateQueries({queryKey:["ma","ingestion","sec","jobs"]}),x&&i.invalidateQueries({queryKey:["ma","ingestion","sec","status",x]})},disabled:$,children:[e.jsx(ge,{className:`mr-2 h-4 w-4 ${$?"animate-spin":""}`}),"Refresh"]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs(f,{children:[e.jsxs(b,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"Total Deals"}),e.jsx(vs,{className:"text-muted-foreground h-4 w-4"})]}),e.jsx(v,{children:e.jsx("div",{className:"text-2xl font-bold",children:$?e.jsx(o,{className:"h-5 w-5 animate-spin"}):(d?.total_deals||0).toLocaleString()})})]}),e.jsxs(f,{children:[e.jsxs(b,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"Companies"}),e.jsx(Ns,{className:"text-muted-foreground h-4 w-4"})]}),e.jsx(v,{children:e.jsx("div",{className:"text-2xl font-bold",children:$?e.jsx(o,{className:"h-5 w-5 animate-spin"}):(d?.total_companies||0).toLocaleString()})})]}),e.jsxs(f,{children:[e.jsxs(b,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"Active Jobs"}),e.jsx(o,{className:"text-muted-foreground h-4 w-4"})]}),e.jsx(v,{children:e.jsx("div",{className:"text-2xl font-bold",children:d?.active_jobs?.length||0})})]}),e.jsxs(f,{children:[e.jsxs(b,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(y,{className:"text-sm font-medium",children:"Years Covered"}),e.jsx(Je,{className:"text-muted-foreground h-4 w-4"})]}),e.jsx(v,{children:e.jsx("div",{className:"text-2xl font-bold",children:d?.deals_by_year?.length||0})})]})]}),e.jsx(Qe,{scope:"platform"}),e.jsxs(f,{children:[e.jsxs(b,{children:[e.jsx(y,{children:"Tenant Discovery Overrides"}),e.jsx(K,{children:"Superuser view for company-level discovery policy controls."})]}),e.jsxs(v,{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx(Es,{value:te,onChange:s=>es(s.target.value),placeholder:"Enter company_id to edit tenant override",className:"max-w-xl"})}),te.trim().length>0&&e.jsx(Qe,{scope:"company",companyId:te.trim()})]})]}),e.jsxs(Ds,{defaultValue:"overview",className:"w-full",children:[e.jsxs(qs,{children:[e.jsx(U,{value:"overview",children:"Overview"}),e.jsx(U,{value:"edgar",children:"EDGAR Backfill"}),e.jsx(U,{value:"api-pull",children:"API Pull Connectors"}),e.jsx(U,{value:"import",children:"Provider Import"})]}),e.jsx(G,{value:"overview",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(f,{children:[e.jsxs(b,{children:[e.jsx(y,{children:"Deals by Year"}),e.jsx(K,{children:"Distribution of M&A deals in the database"})]}),e.jsx(v,{children:d?.deals_by_year&&d.deals_by_year.length>0?e.jsx("div",{className:"space-y-2",children:d.deals_by_year.slice(-10).map(s=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-12 text-sm font-medium",children:s.year}),e.jsx("div",{className:"bg-muted h-4 flex-1 overflow-hidden rounded-full",children:e.jsx("div",{className:"h-full bg-[var(--theme-button-primary-bg)]",style:{width:`${Math.min(100,s.count/Math.max(...d.deals_by_year.map(t=>t.count))*100)}%`}})}),e.jsx("span",{className:"text-muted-foreground w-16 text-right text-sm",children:s.count.toLocaleStr
1ing()})]},s.year))}):e.jsx("p",{className:"text-muted-foreground py-8 text-center",children:"No deals in database. Start a backfill to populate."})})]}),e.jsxs(f,{children:[e.jsxs(b,{children:[e.jsx(y,{children:"Active Jobs"}),e.jsx(K,{children:"Currently running ingestion jobs"})]}),e.jsx(v,{children:d?.active_jobs&&d.active_jobs.length>0?e.jsx("div",{className:"space-y-3",children:d.active_jobs.map(s=>e.jsxs("div",{className:"hover:bg-muted/50 cursor-pointer rounded-lg border p-3",onClick:()=>{s.job_type==="edgar_backfill"?B(s.id):s.job_type==="sec_ingestion"&&E(s.id)},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Ae(s.status),e.jsx("span",{className:"font-medium",children:rs(s.job_type)})]}),e.jsx("span",{className:"text-muted-foreground text-sm",children:s.status})]}),s.progress?.processed_ciks&&s.progress?.total_ciks&&e.jsx(je,{value:s.progress.processed_ciks/s.progress.total_ciks*100,className:"mt-2"})]},s.id))}):e.jsx("p",{className:"text-muted-foreground py-8 text-center",children:"No active jobs"})})]})]})}),e.jsx(G,{value:"edgar",className:"space-y-4",children:e.jsxs(f,{children:[e.jsxs(b,{children:[e.jsx(y,{children:"SEC EDGAR 25-Year Backfill"}),e.jsx(K,{children:"Crawl all SEC filings (8-K, S-4, DEFM14A, SC TO) to populate M&A deals from public companies"})]}),e.jsxs(v,{className:"space-y-4",children:[e.jsxs("div",{className:"bg-muted/20 space-y-3 rounded-lg border p-4","data-testid":"sec-ingestion-panel",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Quick SEC Ingestion"}),e.jsx("p",{className:"text-muted-foreground text-xs",children:"Run targeted SEC ingestion by keywords with real-time SSE status updates."})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[2fr_120px_auto]",children:[e.jsx("input",{type:"text",value:_e,onChange:s=>He(s.target.value),placeholder:"Keywords (comma-separated)",className:"bg-background rounded border px-3 py-2 text-sm","data-testid":"sec-ingestion-keywords"}),e.jsx("input",{type:"number",min:1,max:500,value:Se,onChange:s=>Xe(Math.max(1,parseInt(s.target.value,10)||25)),className:"bg-background rounded border px-3 py-2 text-sm","data-testid":"sec-ingestion-max-results"}),e.jsxs(l,{onClick:os,disabled:me.isPending,"data-testid":"sec-ingestion-start",children:[me.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(he,{className:"mr-2 h-4 w-4"}),"Start"]})]}),g&&e.jsxs("div",{className:"bg-background rounded border p-3 text-sm","data-testid":"sec-ingestion-status",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium","data-testid":"sec-ingestion-job-id",children:["SEC Job ",g.id.slice(0,8),"..."]}),e.jsx("span",{className:"text-muted-foreground capitalize","data-testid":"sec-ingestion-state",children:g.status})]}),e.jsxs("div",{className:"text-muted-foreground mt-2 grid gap-1 text-xs md:grid-cols-2",children:[e.jsxs("span",{children:["Task ID:"," ",e.jsx("span",{className:"text-foreground font-medium","data-testid":"sec-ingestion-task-id",children:Ke?`${Ke.slice(0,12)}...`:"-"})]}),e.jsxs("span",{children:["Worker State:"," ",e.jsx("span",{className:"text-foreground font-medium","data-testid":"sec-ingestion-worker-state",children:Fe??"-"})]})]}),e.jsxs("div",{className:"text-muted-foreground mt-2 grid gap-1 text-xs md:grid-cols-4",children:[e.jsxs("span",{children:["Created:"," ",e.jsx("span",{className:"text-foreground font-medium","data-testid":"sec-ingestion-created",children:F.created??0})]}),e.jsxs("span",{children:["Updated:"," ",e.jsx("span",{className:"text-foreground font-medium","data-testid":"sec-ingestion-updated",children:F.updated??0})]}),e.jsxs("span",{children:["Failed:"," ",e.jsx("span",{className:"text-foreground font-medium","data-testid":"sec-ingestion-failed",children:F.failed??0})]}),e.jsxs("span",{children:["Duration:"," ",e.jsx("span",{className:"text-foreground font-medium",children:F.duration_ms?`${Math.round(F.duration_ms/1e3)}s`:"-"})]})]}),Re&&e.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:Re}),Fe==="UNAVAILABLE"&&e.jsx("p",{className:"mt-1 text-xs text-amber-700",children:"Celery worker status unavailable; showing persisted database status."}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[cs&&x&&e.jsxs(l,{size:"sm",variant:"destructive",onClick:()=>ue.mutate(x),disabled:ue.isPending,"data-testid":"sec-ingestion-cancel",children:[ue.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Cancel"]}),ds&&x&&e.jsxs(l,{size:"sm",variant:"outline",onClick:()=>z.mutate(x),disabled:z.isPending,"data-testid":"sec-ingestion-retry",children:[z.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ge,{className:"mr-2 h-4 w-4"}),"Retry"]})]})]}),e.jsxs("div",{className:"bg-background rounded border p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Recent SEC Jobs"}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[ne.length," shown"]})]}),ne.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:"No SEC ingestion jobs yet."}):e.jsx("div",{className:"max-h-56 overflow-auto rounded border",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Job"}),e.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Status"}),e.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Created"}),e.jsx("th",{className:"px-2 py-1 text-right font-medium",children:"Actions"})]})}),e.jsx("tbody",{children:ne.map(s=>{const t=s.status==="running"||s.status==="pending";return e.jsxs("tr",{className:"hover:bg-muted/40 border-t",children:[e.jsxs("td",{className:"px-2 py-1 font-mono",children:[s.id.slice(0,8),"..."]}),e.jsx("td",{className:"px-2 py-1 capitalize",children:s.status}),e.jsx("td",{className:"px-2 py-1",children:s.created_at?new Date(s.created_at).toLocaleStr
1ing():"-"}),e.jsx("td",{className:"px-2 py-1 text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>ms(s),children:"Select"}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>us(s),children:"Config"}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>xs(s),disabled:!s.error_message,children:"Error"}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>z.mutate(s.id),disabled:t||z.isPending,children:"Retry"})]})})]},s.id)})})]})})]}),we&&e.jsxs("div",{className:"bg-background rounded border p-3",children:[e.jsx("div",{className:"mb-1 text-xs font-medium",children:"Selected Job Config"}),e.jsx("pre",{className:"text-muted-foreground max-h-44 overflow-auto text-xs whitespace-pre-wrap",children:we})]}),Ce&&e.jsxs("div",{className:"bg-background rounded border p-3",children:[e.jsx("div",{className:"mb-1 text-xs font-medium text-red-700",children:"Selected Job Error"}),e.jsx("p",{className:"text-xs text-red-700",children:Ce})]})]}),u&&a&&e.jsxs("div",{className:"bg-muted/30 space-y-4 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Ae(a.status),e.jsxs("span",{className:"font-medium",children:["Job: ",u.slice(0,8),"..."]})]}),e.jsx("span",{className:"text-muted-foreground text-sm capitalize",children:a.status})]}),a.current_company_name&&e.jsxs("div",{className:"rounded-lg bg-[var(--theme-accent)]/10 p-3 dark:bg-blue-950",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-sm",children:"Processing: "}),e.jsx("span",{className:"font-medium text-theme-text dark:text-blue-300",children:a.current_company_name})]}),a.current_filing_form&&e.jsx("span",{className:"rounded bg-blue-100 px-2 py-1 text-xs dark:bg-blue-900",children:a.current_filing_form})]}),a.filings_for_current_cik&&a.filings_for_current_cik>0&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"text-muted-foreground mb-1 flex justify-between text-xs",children:[e.jsx("span",{children:"Filing progress"}),e.jsxs("span",{children:[a.filings_processed_for_current_cik||0," /"," ",a.filings_for_current_cik]})]}),e.jsx(je,{value:(a.filings_processed_for_current_cik||0)/a.filings_for_current_cik*100,className:"h-1"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Overall Progress"}),e.jsxs("span",{children:[qe,"%"]})]}),e.jsx(je,{value:qe,className:"mb-3"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"CIKs:"}),e.jsxs("span",{className:"ml-2 font-medium",children:[a.processed_ciks?.toLocaleString()," /"," ",a.total_ciks?.toLocaleString()]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Created:"}),e.jsx("span",{className:"ml-2 font-medium text-green-600",children:a.deals_created?.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Updated:"}),e.jsx("span",{className:"ml-2 font-medium text-theme-accent-text",children:a.deals_updated?.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Failures:"}),e.jsx("span",{className:"ml-2 font-medium text-red-600",children:a.failures?.toLocaleString()})]}),a.last_deal_extracted&&e.jsxs("div",{className:"col-span-2 md:col-span-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last deal:"}),e.jsx("span",{className:"ml-2 block truncate text-xs font-medium",title:a.last_deal_extracted,children:a.last_deal_extracted})]})]}),a.activity_log&&a.activity_log.length>0&&e.jsxs("div",{className:"border-t pt-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Recent Activity"}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["Last ",a.activity_log.length," events"]})]}),e.jsx("div",{className:"max-h-32 space-y-1 overflow-y-auto text-xs",children:[...a.activity_log].reverse().map((s,t)=>e.jsxs("div",{className:`flex items-start gap-2 rounded p-1.5 ${s.type==="deal_extracted"?"bg-green-50 dark:bg-green-950":s.type==="deal_updated"?"bg-[var(--theme-accent)]/10 dark:bg-blue-950":s.type==="error"?"bg-red-50 dark:bg-red-950":"bg-muted/50"}`,children:[e.jsx("span",{className:"text-muted-foreground whitespace-nowrap",children:new Date(s.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"truncate",title:s.message,children:s.message})]},t))})]}),(a.status==="running"||a.status==="pending")&&e.jsxs(l,{variant:"destructive",size:"sm",onClick:()=>re.mutate(u),disabled:re.isPending,children:[re.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Cancel Backfill"]}),a.status==="paused"&&e.jsxs(l,{size:"sm",onClick:()=>le.mutate(u),disabled:le.isPending,children:[le.isPending&&e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}),"Resume Backfill"]})]}),(!u||["completed","failed","cancelled"].includes(a?.status??""))&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(l,{variant:se?"outline":"default",size:"sm",onClick:()=>Ne(!1),children:"Process by count"}),e.jsx(l,{variant:se?"default":"outline",size:"sm",onClick:()=>Ne(!0),children:"Select specific companies"})]}),se?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",placeholder:"Search by ticker or company name...",value:k,onChange:s=>Z(s.target.value),className:"bg-background w-full rounded border px-3 py-2 text-sm"}),ie?.results&&ie.results.length>0&&k&&e.jsx("div",{className:"absolute z-50 mt-1 max-h-60 w-full overflow-auto rounded-lg border border-theme-divider bg-theme-surface shadow-lg",children:ie.results.map(s=>e.jsxs("button",{className:"flex w-full items-center justify-between px-3 py-2 text-left text-sm text-theme-text hover:bg-theme-surface-light",onClick:()=>{N.find(t=>t.cik===s.cik)||ee([...N,s]),Z("")},children:[e.jsxs("span",{children:[e.jsx("span",{className:"font-medium",children:s.ticker}),e.jsx("span",{className:"ml-2 text-theme-text-muted",children:s.name})]}),N.find(t=>t.cik===s.cik)&&e.jsx(Le,{className:"h-4 w-4 text-green-600"})]},s.cik))})]}),N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-blue-100 px-2 py-1 text-sm dark:bg-blue-900",children:[e.jsx("span",{className:"font-medium",children:s.ticker}),e.jsx("button",{onClick:()=>ee(N.filter(t=>t.cik!==s.cik)),className:"hover:text-red-600",children:e.jsx(pe,{className:"h-3 w-3"})})]},s.cik))}),e.jsxs(l,{onClick:()=>A.mutate({specific_ciks:N.map(s=>s.cik)}),disabled:A.isPending||N.length===0,children:[A.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(he,{className:"mr-2 h-4 w-4"}),"Process ",N.length," Selected Companies"]})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm font-medium whitespace-nowrap",children:"Companies to process:"}),e.jsx("input",{type:"number",min:1,max:1e4,value:T,onChange:s=>L(Math.max(1,parseInt(s.target.value)||10)),className:"bg-background w-24 rounded border px-2 py-1 text-sm"})]}),e.jsxs(l,{onClick:()=>A.mutate({max_ciks:T}),disabled:A.isPending,children:[A.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(he,{className:"mr-2 h-4 w-4"}),"Start Backfill"]})]}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:["Will process ",T.toLocaleStr
1ing()," companies (~",Math.ceil(T*30/60)," min estimated)."]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{variant:"outline",size:"sm",onClick:()=>L(10),children:"10 (test)"}),e.jsx(l,{variant:"outline",size:"sm",onClick:()=>L(100),children:"100"}),e.jsx(l,{variant:"outline",size:"sm",onClick:()=>L(1e3),children:"1,000"}),e.jsx(l,{variant:"outline",size:"sm",onClick:()=>L(8e3),children:"All (~8K)"})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-[var(--theme-accent)]/10 p-4 text-theme-text",children:[e.jsx("h4",{className:"mb-2 font-medium",children:"What gets imported?"}),e.jsxs("ul",{className:"space-y-1 text-sm",children:[e.jsxs("li",{children:["⢠",e.jsx("strong",{children:"8-K Item 2.01"})," - Completion of acquisition"]}),e.jsxs("li",{children:["⢠",e.jsx("strong",{children:"8-K Item 1.01"})," - Entry into definitive agreement"]}),e.jsxs("li",{children:["⢠",e.jsx("strong",{children:"S-4"})," - Merger registration statements"]}),e.jsxs("li",{children:["⢠",e.jsx("strong",{children:"DEFM14A"})," - Merger proxy statements"]}),e.jsxs("li",{children:["⢠",e.jsx("strong",{children:"SC TO"})," - Tender offer statements"]})]})]})]})]})}),e.jsx(G,{value:"api-pull",className:"space-y-4",children:e.jsxs(f,{children:[e.jsxs(b,{children:[e.jsx(y,{children:"Provider API Pull Connectors"}),e.jsx(K,{children:"Run scheduled-ready API pulls for licensed providers when credentials are configured"})]}),e.jsx(v,{className:"space-y-4",children:C.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:"No API pull-capable providers are registered."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Provider"}),e.jsxs(Be,{value:R,onValueChange:ve,children:[e.jsx(Te,{children:e.jsx($e,{placeholder:"Select provider"})}),e.jsx(Ve,{children:C.map(s=>e.jsx(Oe,{value:s.slug,children:s.label},s.slug))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Lookback (days)"}),e.jsx("input",{type:"number",min:1,max:3650,value:W,onChange:s=>We(Math.max(1,Number(s.target.value)||30)),className:"bg-background w-full rounded border px-3 py-2 text-sm"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Row limit"}),e.jsx("input",{type:"number",min:1,max:5e3,value:Y,onChange:s=>Ye(Math.max(1,Number(s.target.value)||500)),className:"bg-background w-full rounded border px-3 py-2 text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Actions"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(l,{onClick:()=>de.mutate({provider:R,lookback_days:W,limit:Y,dry_run:!1}),disabled:de.isPending||!R,children:[de.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Run Pull"]}),e.jsxs(l,{variant:"outline",onClick:()=>oe.mutate({lookback_days:W,limit:Y}),disabled:oe.isPending,children:[oe.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ge,{className:"mr-2 h-4 w-4"}),"Trigger Scheduled Batch"]})]})]})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:C.map(s=>e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.label}),e.jsx("div",{className:"text-muted-foreground text-xs",children:s.slug})]}),e.jsx("span",{className:`rounded px-2 py-0.5 text-xs ${s.configured?"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300":"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300"}`,children:s.configured?"Configured":"Missing Config"})]}),s.default_pull_schedule_minutes?e.jsxs("p",{className:"text-muted-foreground mt-2 text-xs",children:["Default cadence: every ",s.default_pull_schedule_minutes," minutes"]}):null,!s.configured&&s.required_env?.length?e.jsxs("p",{className:"text-muted-foreground mt-2 text-xs",children:["Required env: ",s.required_env.join(", ")
1]}):null]},s.slug))})]})})]})}),e.jsx(G,{value:"import",className:"space-y-4",children:e.jsxs(f,{children:[e.jsxs(b,{children:[e.jsx(y,{children:"Commercial Provider Import"}),e.jsx(K,{children:"Upload CSV files from PitchBook, Capital IQ, Refinitiv, or FactSet"})]}),e.jsxs(v,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("label",{className:"text-sm font-medium",children:"Data Provider:"}),e.jsxs(Be,{value:P,onValueChange:ye,children:[e.jsx(Te,{className:"w-48",children:e.jsx($e,{placeholder:"Select provider"})}),e.jsx(Ve,{children:(q.length>0?q:[{slug:"generic",label:"Generic CSV"}]).map(s=>e.jsx(Oe,{value:s.slug,children:s.label},s.slug))})]})]}),e.jsxs("div",{...ns(),className:`cursor-pointer rounded-lg border-2 border-dashed p-8 text-center transition-colors ${De?"border-theme-accent bg-[var(--theme-accent)]/10":"border-muted-foreground/25 hover:border-[var(--theme-accent)]"} `,children:[e.jsx("input",{...is()}),e.jsx(_s,{className:"text-muted-foreground mx-auto mb-4 h-8 w-8"}),De?e.jsx("p",{children:"Drop the CSV file here..."}):e.jsx("p",{children:"Drag & drop a CSV file here, or click to select"}),J&&e.jsxs("p",{className:"mt-2 text-sm font-medium text-theme-accent-text",children:["Selected: ",J.name]})]}),I&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-medium",children:"Preview"}),e.jsxs("div",{className:"bg-muted rounded-lg p-3",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Detected Column Mapping:"}),e.jsx("div",{className:"grid grid-cols-2 gap-2 text-sm md:grid-cols-3",children:Object.entries(I.detected_mapping).map(([s,t])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-muted-foreground",children:[s,":"]}),e.jsx("span",{className:"rounded bg-theme-surface px-1 font-mono",children:t})]},s))})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full border text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-muted",children:I.headers.slice(0,6).map(s=>e.jsx("th",{className:"border p-2 text-left",children:s},s))})}),e.jsx("tbody",{children:I.sample_rows.map((s,t)=>e.jsx("tr",{className:"border-b",children:I.headers.slice(0,6).map(n=>e.jsx("td",{className:"max-w-32 truncate border p-2",children:s[n]},n))},t))})]})}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(l,{onClick:()=>J&&ce.mutate(J),disabled:ce.isPending||!J,children:[ce.isPending?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ss,{className:"mr-2 h-4 w-4"}),"Import ",I.sample_rows.length,"+ Deals"]}),e.jsx(l,{variant:"outline",onClick:()=>{H(null),X(null)},children:"Cancel"})]})]})]})]})})]})]})};export{As as canRetrySecIngestionStatus,Qs 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.