1import{a as G,j as e,g as F,C as P,x as J,I as C,r as x,B as v,h as M,s as w,N as X,a5 as Z}from"./index-BBFlvp23.js";import{C as H}from"./Card-BeFnBzoj.js";import{u as I,C as ee,a as se}from"./ContactDetailsDialog-BSvCzBAq.js";import{e as te,f as ne,b as ae}from"./useLeadLists-CJD0koy-.js";import{T as oe,D as ce}from"./useCorporateSearch-B0EtZ7RD.js";import{f as le,A as ie}from"./AddLeadsDialog-DguFdznM.js";import{I as re,s as de,a as me,l as he,b as pe,c as k,r as ue,d as xe,e as _e,f as be}from"./leadListDisplay-Dw8ZZurP.js";import"./screeningCatalogue-D_1HFGx9.js";import{C as je}from"./CompanyMark-VkuK5M2l.js";import{H as K}from"./HubSpotLogo-lPn_sfZB.js";import{e as fe,f as ye}from"./tableColumns-CEvj2xtV.js";import{n as Ne}from"./contactAdapter-DaeKa_8z.js";import{L as R}from"./LeadListsState-CodPImaO.js";import"./integrationsApi-Bw_a5TzQ.js";import"./leadOrigination-C-S6kZQ5.js";import"./sicCodes-Dd-xtDmW.js";import"./companyStatus-CJapKeQJ.js";import"./companyAdapter-DzBda7tQ.js";import"./useNameSuggestions-BUujK34G.js";import"./logo-pewQ2a3_.js";import"./CompanyStatusBadge-CpXtVSnj.js";import"./NationalityFlag-BsmH5oJn.js";function ge(t){return["lead-list-snapshots",[...t].sort()]}async function ve(t){if(t.length===0)return{};const r={};for(const s of t)r[`Company number|${s}`]=!0;const m=await oe({...ce,selection:{checks:r,texts:{}}},t.length,!1),d={};for(const s of m.items)s.kind==="company"&&s.number&&(d[s.number]=s);return d}function Ce(t){return G({queryKey:ge(t),queryFn:()=>ve(t),enabled:t.length>0,staleTime:5*6e4})}function ke({row:t,columns:r=[]}){const{push:m,sending:d}=I();return e.jsx(F,{variant:"ghost",size:"sm",label:`Add ${t.name} to HubSpot`,disabled:d,onClick:()=>void m([t],`${t.name} added to HubSpot`,r),children:e.jsx("span",{"aria-hidden":"true",children:e.jsx(K,{size:16})})})}const Le="_scroll_1c63z_7",we="_table_1c63z_11",$e="_th_1c63z_17",ze="_thFirst_1c63z_34",Se="_thLast_1c63z_38",Te="_row_1c63z_45",Ee="_rowOn_1c63z_59",Ae="_td_1c63z_64",De="_tdFirst_1c63z_73",Oe="_tdLast_1c63z_76",Pe="_unknown_1c63z_80",He="_company_1c63z_85",Re="_companyText_1c63z_91",Be="_name_1c63z_94",Fe="_number_1c63z_104",Me="_actions_1c63z_113",Ie="_remove_1c63z_123",Ke="_srOnly_1c63z_136",qe="_ph_1c63z_147 _ph_1i2pu_127",Ue="_phHead_1c63z_150",We="_phCell_1c63z_154",a={scroll:Le,table:we,th:$e,thFirst:ze,thLast:Se,row:Te,rowOn:Ee,td:Ae,tdFirst:De,tdLast:Oe,unknown:Pe,company:He,companyText:Re,name:Be,number:Fe,actions:Me,remove:Ie,srOnly:Ke,ph:qe,phHead:Ue,phCell:We},E=t=>t.number??t.id;function Ye({columns:t,rows:r=6}){const m=Array.from({length:t+2},(d,s)=>s);return e.jsxs("div",{className:a.scroll,role:"status","aria-live":"polite","aria-busy":"true",children:[e.jsx("span",{className:a.srOnly,children:"Loading this list."}),e.jsxs("table",{className:a.table,children:[e.jsx("thead",{children:e.jsx("tr",{children:m.map(d=>e.jsx("th",{className:a.th,children:e.jsx("span",{className:`${a.ph} ${a.phHead}`})},d))})}),e.jsx("tbody",{children:Array.from({length:r},(d,s)=>e.jsx("tr",{className:a.row,children:m.map(c=>e.jsx("td",{className:a.td,children:e.jsx("span",{className:`${a.ph} ${a.phCell}`})},c))},s))})]})]})}function Qe({rows:t,columns:r,selected:m,onToggleSelect:d,onToggleSelectAll:s,onOpenCompany:c,onRemove:b,busy:g={}}){const y=r.filter(n=>!re.has(n.id)),h=t.length>0&&t.every(n=>m[E(n)]),f=t.some(n=>m[E(n)]),p=(n,N)=>{n.key!=="Enter"&&n.key!==" "||(n.preventDefault(),c(N))};return e.jsx("div",{className:a.scroll,children:e.jsxs("table",{className:a.table,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:`${a.th} ${a.thFirst}`,children:e.jsx(P,{checked:h,indeterminate:f&&!h,onChange:s,"aria-label":"Select all companies"})}),e.jsx("th",{className:a.th,children:"Company"}),y.map(n=>e.jsx("th",{className:a.th,style:{minWidth:n.min},children:n.label},n.id)),e.jsx("th",{className:`${a.th} ${a.thLast}`,children:"Actions"})]})}),e.jsx("tbody",{children:t.map(n=>{var L;const N=E(n);return e.jsxs("tr",{className:`${a.row} ${m[N]?a.rowOn:""}`,tabIndex:0,onClick:()=>c(n),onKeyDown:l=>p(l,n),children:[e.jsx("td",{className:`${a.td} ${a.tdFirst}`,onClick:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),children:e.jsx(P,{checked:!!m[N],onChange:()=>d(N),"aria-label":`Select ${n.name}`})}),e.jsx("td",{className:a.td,children:e.jsxs("div",{className:a.company,children:[e.jsx(je,{name:n.name,domain:(L=n.websites)==null?void 0:L[0]}),e.jsxs("div",{className:a.companyText,children:[e.jsx("div",{className:a.name,title:n.name,children:n.name}),e.jsx("div",{className:`tabular ${a.number}`,children:N})]})]})}
1),y.map(l=>e.jsx("td",{className:a.td,style:{minWidth:l.min},children:l.id==="status"?n.status?e.jsx(J,{tone:me(n.status),dot:!0,children:de(n.status)}):e.jsx("span",{className:a.unknown,children:"â"}):l.cell(n)},l.id)),e.jsx("td",{className:`${a.td} ${a.tdLast}`,onClick:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),children:e.jsxs("div",{className:a.actions,children:[e.jsx(ke,{row:n,columns:r}),e.jsx(F,{variant:"ghost",size:"sm",className:a.remove,label:`Remove ${n.name} from this list`,title:"Remove from list",disabled:!!g[N],onClick:()=>b(n),children:e.jsx(C,{name:"trash",size:16})})]})})]},N)})})]})})}const Ve={status:"idle",emails:[],phones:[],websites:[]},B=t=>{var r,m,d;return!!(t&&((r=t.emails)!=null&&r[0]||(m=t.phones)!=null&&m[0]||(d=t.websites)!=null&&d[0]))};function Ge({children:t}){const[r,m]=x.useState(new Map),d=x.useCallback((h,f)=>{m(p=>{const n=new Map(p);return n.set(h,{...n.get(h)??Ve,...f}),n})},[]),s=x.useMemo(()=>({byNumber:r,set:d}),[r,d]),[c,b]=x.useState(null),g=x.useCallback(h=>b(h),[]),y=x.useMemo(()=>{if(!c)return null;const h=c.contacts,f=r.get(Ne(c.companyNumber)),p=B(h)?h:B(f)?f:null;return p?{emails:p.emails??[],phones:p.phones??[],websites:p.websites??[],...p.favicon?{favicon:p.favicon}:{}}:null},[c,r]);return e.jsx(fe.Provider,{value:s,children:e.jsxs(ye.Provider,{value:g,children:[t,e.jsx(ee,{open:c!==null,onClose:()=>b(null),companyName:(c==null?void 0:c.companyName)??"",companyNumber:(c==null?void 0:c.companyNumber)??"",contacts:y,isLoading:!1,isError:!1,initialTab:(c==null?void 0:c.kind)??"email"})]})})}const Je="_root_p68cd_4",Xe="_menu_p68cd_6",Ze="_item_p68cd_22",es="_mark_p68cd_41",ss="_text_p68cd_52",ts="_label_p68cd_53",ns="_hint_p68cd_54",j={root:Je,menu:Xe,item:Ze,mark:es,text:ss,label:ts,hint:ns};function as({onSendToHubspot:t,onDownloadCsv:r,busy:m=!1,disabled:d=!1}){const[s,c]=x.useState(!1),b=x.useRef(null),g=x.useId();x.useEffect(()=>{if(!s)return;const h=p=>{b.current&&!b.current.contains(p.target)&&c(!1)},f=p=>{p.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",h),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",f)}},[s]);const y=h=>()=>{c(!1),h()};return e.jsxs("div",{className:j.root,ref:b,children:[e.jsx(v,{variant:"secondary",iconLeft:e.jsx(C,{name:"download",size:16}),loading:m,disabled:d,"aria-haspopup":"menu","aria-expanded":s,"aria-controls":g,onClick:()=>c(h=>!h),children:"Export"}),s&&e.jsxs("div",{className:j.menu,id:g,role:"menu",children:[e.jsxs("button",{type:"button",className:j.item,role:"menuitem",onClick:y(t),children:[e.jsx("span",{className:j.mark,"aria-hidden":"true",children:e.jsx(K,{size:16})}),e.jsxs("span",{className:j.text,children:[e.jsx("span",{className:j.label,children:"Add all to HubSpot"}),e.jsx("span",{className:j.hint,children:"Every company in this list"})]})]}),e.jsxs("button",{type:"button",className:j.item,role:"menuitem",onClick:y(r),children:[e.jsx("span",{className:j.mark,"aria-hidden":"true",children:e.jsx(C,{name:"download",size:16})}),e.jsxs("span",{className:j.text,children:[e.jsx("span",{className:j.label,children:"Download CSV"}),e.jsx("span",{className:j.hint,children:"The columns shown below"})]})]})]})]})}const os="_detail_1ol0e_4",cs="_backRow_1ol0e_12",ls="_head_1ol0e_18",is="_headText_1ol0e_25",rs="_title_1ol0e_28",ds="_sub_1ol0e_36",ms="_note_1ol0e_41",hs="_headActions_1ol0e_51",ps="_ph_1ol0e_62 _ph_1i2pu_127",us="_phTitle_1ol0e_65",xs="_phSub_1ol0e_69",_s="_phExport_1ol0e_74",bs="_selection_1ol0e_83",js="_selectionBadge_1ol0e_93",fs="_selectionText_1ol0e_105",ys="_selectionActions_1ol0e_111",Ns="_tableCard_1ol0e_123",i={detail:os,backRow:cs,head:ls,headText:is,title:rs,sub:ds,note:ms,headActions:hs,ph:ps,phTitle:us,phSub:xs,phExport:_s,selection:bs,selectionBadge:js,selectionText:fs,selectionActions:ys,tableCard:Ns};function gs({listId:t,onBack:r}){var D;
1const m=M(),d=te(t),s=d.data,[c,b]=x.useState({}),[g,y]=x.useState(!1),h=I(),[f,p]=x.useState(!1),n=x.useMemo(()=>he(s),[s]),N=x.useMemo(()=>((s==null?void 0:s.companies)??[]).filter(o=>!o.data).map(o=>o.companyNumber),[s==null?void 0:s.companies]),L=Ce(N),l=x.useMemo(()=>pe(s,L.data),[s,L.data]),$=ne(),q=$.isPending?{[((D=$.variables)==null?void 0:D.companyNumber)??""]:!0}:{},U=o=>b(_=>{const u={..._};return u[o]?delete u[o]:u[o]=!0,u}),W=()=>{const o=l.map(u=>u.number??u.id),_=o.length>0&&o.every(u=>c[u]);b(_?{}:Object.fromEntries(o.map(u=>[u,!0])))},A=o=>{const _=o.number??o.id;$.mutate({listId:t,companyNumber:_},{onSuccess:()=>b(u=>{const O={...u};return delete O[_],O}),onError:u=>w("error",u.message)})},z=ae(),Y=o=>z.mutate({listId:t,companies:o.map(_=>({..._,companyName:_.companyName||""}))},{onSuccess:()=>{p(!1),w("success",`Added ${k(o.length)} to ${(s==null?void 0:s.name)??"this list"}.`)},onError:_=>w("error",_.message)}),Q=async()=>{!s||l.length===0||await h.push(l,`${k(l.length)} added to HubSpot.`,n)},V=async()=>{if(!(!s||l.length===0)){y(!0);try{const{exportable:o,dropped:_}=xe(n);se(await _e(l,o),be(s.name)),w("success",_.length===0?`Exported ${k(l.length)}.`:`Exported ${k(l.length)} â ${_.map(u=>u.label).join(", ")} canât be exported and ${_.length===1?"was":"were"} left out.`)}catch(o){w("error",o instanceof Error?o.message:"Could not export this list.")}finally{y(!1)}}},S=e.jsx("div",{className:i.backRow,children:e.jsx(v,{variant:"ghost",size:"sm",iconLeft:e.jsx(C,{name:"chevronLeft",size:15}),onClick:r,children:"Back to lists"})});if(d.isError||!d.isLoading&&!s)return e.jsxs("div",{className:i.detail,children:[S,e.jsx(R,{icon:"alert",tone:"error",title:"Couldnât load this list",body:"It may have been deleted from another session.",action:e.jsx(v,{variant:"secondary",onClick:r,children:"Back to lists"})})]});if(!s)return e.jsxs("div",{className:i.detail,children:[S,e.jsxs("div",{className:i.head,"aria-hidden":"true",children:[e.jsxs("div",{className:i.headText,children:[e.jsx("span",{className:`${i.ph} ${i.phTitle}`}),e.jsx("span",{className:`${i.ph} ${i.phSub}`})]}),e.jsx("div",{className:i.headActions,children:e.jsx("span",{className:`${i.ph} ${i.phExport}`})})]}),e.jsx(H,{padded:!1,className:i.tableCard,children:e.jsx(Ye,{columns:n.length})})]});const T=Object.keys(c).length;return e.jsxs("div",{className:i.detail,children:[S,e.jsxs("div",{className:i.head,children:[e.jsxs("div",{className:i.headText,children:[e.jsx("h2",{className:i.title,children:s.name}),e.jsxs("div",{className:i.sub,children:[k(s.companyCount)," · Created ",le(s.createdAt)," · Updated"," ",ue(s.updatedAt)]}),s.note&&e.jsx("p",{className:i.note,children:s.note})]}),e.jsxs("div",{className:i.headActions,children:[e.jsx(as,{busy:g||h.sending,disabled:s.companies.length===0,onSendToHubspot:()=>void Q(),onDownloadCsv:()=>void V()}),e.jsx(v,{variant:"primary",iconLeft:e.jsx(C,{name:"plus",size:16}),loading:z.isPending,onClick:()=>p(!0),children:"Add companies"})]})]}),f&&e.jsx(ie,{existing:s.companies.map(o=>o.companyNumber),onAdd:Y,onClose:()=>p(!1),busy:z.isPending}),T>0&&e.jsxs("div",{className:i.selection,children:[e.jsx("span",{className:i.selectionBadge,"aria-hidden":"true",children:T}),e.jsxs("div",{className:i.selectionText,children:[k(T)," selected â removing takes them out of this list only."]}),e.jsxs("div",{className:i.selectionActions,children:[e.jsx(v,{variant:"ghost",size:"sm",onClick:()=>b({}),children:"Clear"}),e.jsx(v,{variant:"danger",size:"sm",iconLeft:e.jsx(C,{name:"trash",size:15}),loading:$.isPending,onClick:()=>l.filter(o=>c[o.number??o.id]).forEach(A),children:"Remove from list"})]})]}),e.jsx(H,{padded:!1,className:i.tableCard,children:s.companies.length===0?e.jsx(R,{icon:"search",title:"No companies in this list yet",body:"Companies join a list from Search: tick the ones you want, then choose âSend to â Lead generationâ.",action:e.jsx(v,{variant:"primary",iconLeft:e.jsx(C,{name:"search",size:18}),onClick:()=>m("/search"),children:"Find companies"})}):e.jsx(Ge,{children:e.jsx(Qe,{rows:l,columns:n,selected:c,onToggleSelect:U,onToggleSelectAll:W,onOpenCompany:o=>m(`/company/${o.number??o.id}`),onRemove:A,busy:q})})})]})}function Us(){const{listId:t}=X(),r=M();return t?e.jsx(gs,{listId:t,onBack:()=>r("/leads")}):e.jsx(Z,{to:"/leads",replace:!0})}export{Us as LeadListPage};
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.