1import{r as t,a as T,j as e,L as S}from"./index-zb99FpKi.js";import{S as F}from"./SalesNavigation-B_aJcZKB.js";import{s as q,g as A,b as I}from"./SalesCrm-DnD486YD.js";import"./logout-CmEwPxOI.js";const W=[50,100,200],K={q:"",channel:"all",limit:100,uncontacted:!0};function $(a){return String(a||"").trim().toLowerCase()}function j(a){return $(a==null?void 0:a.email)||$(a==null?void 0:a.contact_book_key)}function U(a){const r=String(a||"").trim();return r?/^https?:\/\//i.test(r)?r:/^[\w.-]+\.[a-z]{2,}(?:[/?#].*)?$/i.test(r)?`https://${r}`:"":""}function z(a){return{email:a.email,name:a.name,phone:a.phone,website:a.website,industry:a.target_bucket,location:a.location||a.source_address,stage:"Targeted",source:"Prospect scanner",target_channel:a.target_channel,outreach_order:a.outreach_order,scrape_query:a.scrape_query,contact_book_key:a.contact_book_key,target_bucket:a.target_bucket,target_score:a.target_score,next_step:a.phone?"Call prospect":"Send first email"}}function O(a,r){const m=new Set(a.map(j).filter(Boolean)),h=[...a];for(const c of r){const u=j(c);!u||m.has(u)||(m.add(u),h.push(c))}return h}function D(){const[a,r]=t.useState(K),[m,h]=t.useState([]),[c,u]=t.useState({offset:0,next_offset:0,scanned_count:0,total_candidates:0,total_candidates_exact:!0,has_more:!1}),[N,w]=t.useState(!0),[y,C]=t.useState(!1),[B,P]=t.useState(""),[v,x]=t.useState(null),k=t.useRef(null),b=t.useRef(0),p=T(),E=!!(c.has_more&&c.next_offset!==null&&c.next_offset!==void 0),_=t.useCallback(async({offset:s=0,append:l=!1}={})=>{var o;(o=k.current)==null||o.abort();const n=new AbortController;k.current=n;const f=b.current+1;b.current=f,l?C(!0):w(!0),x(null);try{const d=new URLSearchParams({limit:String(a.limit),offset:String(s),channel:a.channel,uncontacted:a.uncontacted?"true":"false",include_no_email:"true"});a.q.trim()&&d.set("q",a.q.trim());const i=await q(`${A}/targets?${d.toString()}`,{signal:n.signal});if(f!==b.current)return;u({offset:Number(i.offset||0),next_offset:i.next_offset??null,scanned_count:Number(i.scanned_count||0),total_candidates:Number(i.total_candidates||0),total_candidates_exact:i.total_candidates_exact!==!1,has_more:!!i.has_more}),h(L=>l?O(L,i.targets||[]):i.targets||[])}catch(d){if(d.name==="AbortError")return;if(d.message==="Missing sales session"){p("/sales-login");return}x({type:"error",text:d.message})}finally{f===b.current&&(w(!1),C(!1))}},[a,p]);t.useEffect(()=>{const s=window.setTimeout(()=>{_({offset:0,append:!1})},300);return()=>window.clearTimeout(s)},[_]),t.useEffect(()=>()=>{var s;return(s=k.current)==null?void 0:s.abort()},[]);const g=(s,l)=>{r(n=>({...n,[s]:l}))},M=()=>{!E||y||_({offset:c.next_offset,append:!0})},R=async s=>{const l=j(s);P(l),x(null);try{const n=await q(`${A}/business`,{method:"POST",body:JSON.stringify(z(s))});h(f=>f.map(o=>j(o)===l?{...o,already_in_crm:!0}:o)),x({type:"success",text:`${I(n.business)} added as an account.`})}catch(n){x({type:"error",text:n.message})}finally{P("")}};return e.jsxs("div",{className:"sales-crm-page",children:[e.jsx(F,{}),e.jsxs("main",{className:"sales-crm-shell",children:[e.jsxs("div",{className:"sales-crm-header",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"sales-crm-title",children:"Prospect Scanner"}),e.jsx("p",{className:"sales-crm-subtitle",children:"Ranked business targets from contact-book and outreach data."})]}),e.jsxs("div",{className:"sales-crm-actions",children:[e.jsx(S,{className:"sales-crm-button-secondary",to:"/sales/workbench",children:"Workbench"}),e.jsx(S,{className:"sales-crm-button-secondary",to:"/sales/businesses",children:"Businesses"})]})]}),v&&e.jsx("div",{className:`sales-crm-message ${v.type}`,children:v.text}),e.jsxs("section",{className:"sales-crm-explainer","aria-label":"Prospect scanner notes",children:[e.jsxs("div",{className:"sales-crm-explainer-card",children:[e.jsx("strong",{children:"Broader than email"}),e.jsx("p",{children:"The scan includes contact-book businesses that may only have a phone, website, or location."})]}),e.jsxs("div",{className:"sales-crm-explainer-card",children:[e.jsx("strong",{children:"Email needed for accounts"}),e.jsx("p",{children:"No-email prospects can still be called or researched, but adding an account requires an email key."})]}),e.jsxs("div",{className:"sales-crm-explainer-card",children:[e.jsx("strong",{children:"Website links"}),e.jsx("p",{children:"Website actions only appear when the value is already http/https or can be safely normalized into one."})]})]}),e.jsx("section",{className:"sales-crm-card sales-prospect-filter-panel",children:e.jsxs("div",{className:"sales-prospect-filters",children:[e.jsxs("div",{className:"sales-crm-field",children:[e.jsx("label",{htmlFor:"prospect-search",children:"Search"}),e.jsx("input",{id:"prospect-search",value:a.q,onChange:s=>g("q",s.target.value),placeholder:"Business, city, category, email"})]}),e.jsxs("div",{className:"sales-crm-field",children:[e.jsx("label",{htmlFor:"prospect-channel",children:"Mode"}),e.jsxs("select",{id:"prospect-channel",value:a.channel,onChange:s=>g("channel",s.target.value),children:[e.jsx("option",{value:"both",children:"Call-ready"}),e.jsx("option",{value:"email",children:"Email"}),e.jsx("option",{value:"call",children:"Call"}),e.jsx("option",{value:"all",children:"All"})]})]}),e.jsxs("div",{className:"sales-crm-field",children:[e.jsx("label",{htmlFor:"prospect-limit",children:"Page Size"}),e.jsx("select",{id:"prospect-limit",value:a.limit,onChange:s=>g("limit",Number(s.target.value)),children:W.map(s=>e.jsx("option",{value:s,children:s},s))})]}),e.jsxs("label",{className:"sales-workbench-checkbox",children:[e.jsx("input",{type:"checkbox",checked:a.uncontacted,onChange:s=>g("uncontacted",s.target.checked)}),e.jsx("span",{children:"Uncontacted"})]}),e.jsx("button",{className:"sales-crm-button-secondary",type:"button",disabled:N,onClick:()=>_({offset:0,append:!1}),children:"Refresh"}),e.jsx("button",{className:"sales-crm-button",type:"button",disabled:!E||N||y,onClick:M,children:y?"Scanning...":"Scan Next Batch"})]})}),e.jsxs("section",{className:"sales-crm-card",children:[e.jsx("div",{className:"sales-crm-header sales-workbench-list-header",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Prospects"}),e.jsx("p",{className:"sales-crm-subtitle",children:c.has_more?`Next offset ${c.next_offset}`:"End of ranked set"})]})}),N?e.jsx("div",{className:"sales-crm-meta",children:"Loading prospects..."}):e.jsx("div",{className:"sales-crm-table-wrap",children:e.jsxs("table",{className:"sales-crm-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Score"}),e.jsx("th",{children:"Business"}),e.jsx("th",{children:"Contact"}),e.jsx("th",{children:"Mode"}),e.jsx("th",{children:"Source"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Actions"})]})}),e.jsxs("tbody",{children:[m.map(s=>{const l=U(s.website),n=j(s);return e.jsxs("tr",{children:[e.jsx("td",{children:s.target_score}),e.jsxs("td",{children:[e.jsx("strong",{children:s.name||s.email}),e.jsx("div",{className:"sales-crm-meta",children:s.target_bucket||"No bucket"}),e.jsx("div",{className:"sales-crm-meta",children:s.location||s.source_address||"No location"})]}),e.jsxs("td",{children:[e.jsx("div",{children:s.email||"No email"}),e.jsx("div",{className:"sales-crm-meta",children:s.phone||"No phone"}),l&&e.jsx("a",{className:"sales-crm-name-link",href:l,target:"_blank",rel:"noreferrer",children:"Website"})]}),e.jsxs("td",{children:[e.jsx("span",{className:"sales-crm-badge",children:s.target_channel||"Email"}),e.jsx("div",{className:"sales-crm-meta",children:s.outreach_order})]}),e.jsxs("td",{children:[e.jsx("div",{children:s.scrape_query||"Contact book"}),e.jsx("div",{className:"sales-crm-meta",children:s.contact_book_key})]}),e.jsxs("td",{children:[e.jsx("span",{className:`sales-crm-badge ${s.already_in_crm?"hot":""}`,children:s.already_in_crm?"Account":"Prospect"}),e.jsx("div",{className:"sales-crm-meta",children:s.keep_on_schedule?`Sequence day ${s.day_sent}`:"Not scheduled"})]}),e.jsx("td",{children:e.jsxs("div",{className:"sales-crm-actions sales-prospect-actions",children:[e.jsx("button",{className:"sales-crm-button",type:"button",disabled:B===n||s.already_in_crm||!s.email,title:s.email?void 0:"Add an email before creating an account",onClick:()=>R(s),children:s.already_in_crm?"Added":s.email?"Add Account":"Needs Email"}),s.phone&&e.jsx("a",{className:"sales-crm-button-secondary",href:`tel:${s.phone}`,children:"Call"}),s.email&&e.jsx(S,{className:"sales-crm-button-secondary",to:`/sales/inbox?email=${encodeURIComponent(s.email)}`,children:"Email"})]})})]},n)}),m.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:"7",children:"No prospects found in this scan window."})})]})]})})]})]})]})}export{D 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.