1import{ai as ee,au as ue,o as l,A as _,al as se,a4 as ae,a5 as te,U as f,j as e,C as b,G as o,aN as me,$ as xe,Y as pe,D as Y,L as ge,W as P,X as C,av as fe,aw as je,a0 as we,ac as Se,T as p,E as g,ad as ye,S as ve,H as be,I as Ce,Z as ke}from"./index-dE8a1mPK.js";import{P as Te}from"./ProspectClaimBadge-2xQ265-n.js";import{W as ze}from"./WatchAuthorButton-VV-g86IZ.js";import{S as I}from"./Select-DebRlW67.js";import{S as Ie}from"./SegmentedControl-CNEtbfTu.js";import{I as $e}from"./IconAt-o0rM45xa.js";import{T as Ae}from"./Textarea-BtbUvWWM.js";import{N as Z}from"./NumberInput-EbCp_odp.js";import{I as Me}from"./IconWand-C0msnEB9.js";import{I as Le}from"./IconPlus-B47PY1MC.js";import{T as n}from"./Table-5ftamFSf.js";import{C as J}from"./Checkbox-CVTqs_Fd.js";import{I as De}from"./IconExternalLink-DcQXcLz7.js";import{I as Pe}from"./IconArrowRight-Ajq43paw.js";import"./IconX-B50qDTAe.js";import"./OptionsDropdown-wonErrz5.js";import"./CheckIcon-DkMc45y2.js";import"./get-env-uyVen0u2.js";import"./InputsGroupFieldset-C0syow2C.js";const V=["merchant","agency","dev","creator","unclear"];function as(){var R,W,U,K,G,O,Q,X;const i=ee(),{capFor:k,planLabel:T}=ue(),c=k("discoverPerDay"),j=c===null||c>0,[d,h]=l.useState("handle"),[w,S]=l.useState(""),[r,ne]=l.useState(null),[z,E]=l.useState(""),[$,F]=l.useState("followers"),[y,le]=l.useState(500),[a,q]=l.useState(null),[u,m]=l.useState(new Set),[x,N]=l.useState(null),[A,re]=l.useState(0),[ie,M]=l.useState(!1),L=_({queryKey:["lists"],queryFn:()=>f.listLists()}),B=_({queryKey:["discovery-runs"],queryFn:()=>f.listDiscoveryRuns()}),D=se({mutationFn:()=>d==="list"?f.runListLookalike({listId:r,audienceDescription:z.trim(),maxPerSeed:Math.max(50,Math.min(500,Math.round((Number(y)||500)/5)
1)),seedSample:5}):f.runSeedDiscovery({seedHandle:w.trim().replace(/^@/,""),audienceDescription:z.trim(),mode:$,maxCandidates:Number(y)||500}),onSuccess:s=>{var t;q({...s,seedMode:d}),m(new Set),i.invalidateQueries({queryKey:["discovery-runs"]}),te(`Classified ${((t=s.candidates)==null?void 0:t.length)||0} candidates from ${s.total} fetched.`)},onError:s=>ae(s)}),v=l.useMemo(()=>((a==null?void 0:a.candidates)||[]).filter(t=>!(x&&t.category!==x||(t.score||0)<A)),[a,x,A]),H=v.length>0&&v.every(s=>u.has(s.handle)),oe=()=>{m(H?new Set:new Set(v.map(s=>s.handle)))},de=s=>{const t=new Set(u);t.has(s)?t.delete(s):t.add(s),m(t)},ce=l.useMemo(()=>{const s={};return((a==null?void 0:a.candidates)||[]).forEach(t=>{s[t.category]=(s[t.category]||0)+1}),s},[a]),he=(d==="handle"?w.trim():!!r)&&z.trim();return e.jsxs(b,{gap:"md",children:[e.jsxs(o,{justify:"space-between",wrap:"wrap",gap:"xs",children:[e.jsxs(o,{gap:"xs",children:[e.jsx(me,{size:20}),e.jsx(xe,{order:2,children:"Discover similar accounts"})]}),((W=(R=B.data)==null?void 0:R.runs)==null?void 0:W.length)>0&&e.jsx(I,{size:"xs",w:280,placeholder:"Load a previous runâ¦",leftSection:e.jsx(pe,{size:14}),data:B.data.runs.map(s=>({value:s.id,label:`@${s.seedHandle} · ${new Date(s.createdAt).toLocaleString()}`})),value:null,onChange:async s=>{if(!s)return;const t=await f.getDiscoveryRun(s);q(t),S(t.seedHandle||""),E(t.audienceDescription||""),F(t.mode||"followers"),m(new Set)},searchable:!0})]}),e.jsx(Y,{withBorder:!0,children:e.jsxs(b,{gap:"sm",children:[e.jsx(Ie,{value:d,onChange:h,data:[{value:"handle",label:"Seed: X handle"},{value:"list",label:"Seed: a list of mine (look-alike)"}],size:"xs"}),d==="handle"&&e.jsxs(o,{grow:!0,children:[e.jsx(ge,{label:"Seed X account",description:"An influencer / known persona whose followers (or following) are your audience",placeholder:"@ashen_one",leftSection:e.jsx($e,{size:14}),value:w.replace(/^@/,""),onChange:s=>S(s.currentTarget.value)}),e.jsx(I,{label:"Pull from",data:[{value:"followers",label:"Their followers (the broader pool)"},{value:"following",label:"Who they follow (the curated pool)"}],value:$,onChange:F})]}),d==="list"&&e.jsx(I,{label:"Source list",description:"We sample 5 handles from this list and pull their followers â anyone already in the list is excluded from results. Best when the list is tightly themed.",data:(((U=L.data)==null?void 0:U.lists)||[]).map(s=>({value:s.id,label:`${s.name} · ${s.handleCount||0} handles${s.kind==="smart"?" · auto":""}`})),value:r,onChange:ne,placeholder:(G=(K=L.data)==null?void 0:K.lists)!=null&&G.length?"Pick a listâ¦":"No lists yet",searchable:!0}),e.jsx(Ae,{label:"Target audience",description:"Plain English. Be ruthless about exclusions â every dimension you mention here is a knife the AI can use.",placeholder:"Shopify merchants who actually run their own store (not agencies, app devs, consultants, or SaaS founders). Bonus signal: bio mentions their store URL, recent posts about products or fulfillment.",value:z,onChange:s=>E(s.currentTarget.value),minRows:3,autosize:!0,maxLength:800}),e.jsxs(o,{justify:"space-between",align:"flex-end",gap:"sm",wrap:"wrap",children:[e.jsx(Z,{label:"Max candidates to pull",description:"Larger pulls = better signal but slower run",value:y,onChange:s=>le(Math.max(50,Math.min(2e3,Number(s)||500))),min:50,max:2e3,step:50,w:200}),j?e.jsx(P,{label:`Costs ${Math.round((Number(y)||500)/200)} GetXAPI credits + Gemini classification (~${Math.round((Number(y)||500)/8)} credits). ${c!==null?`${c} runs/day on ${T}.`:"Unlimited runs."}`,multiline:!0,maw:300,withArrow:!0,children:e.jsx(C,{size:"md",leftSection:e.jsx(Me,{size:16}),onClick:()=>D.mutate(),loading:D.isPending,disabled:!he,children:"Find them"})}):e.jsx(P,{label:`Discover isn't on your ${T} plan. Upgrade to Starter to unlock.`,withArrow:!0,children:e.jsx(C,{size:"md",variant:"light",color:"dark",leftSection:e.jsx(je,{size:16}),onClick:()=>fe({reason:"Discover requires a paid plan.",code:"plan-gate"}),children:"Upgrade to unlock"})})]})]})}),D.isPending&&e.jsxs(we,{color:"gray",variant:"light",icon:e.jsx(Se,{size:16}),children:["Fetching ",$==="following"?"who they follow":"their followers"," from X, then classifying with AI. Typically 20-60s for 500 candidates."]}),a&&e.jsx(Y,{withBorder:!0,children:e.jsxs(b,{gap:"sm",children:[e.jsxs(o,{justify:"space-between",wrap:"wrap",children:[e.jsxs(o,{gap:"xs",children:[e.jsxs(p,{fw:600,children:["Candidates (",v.length," shown · ",((O=a.candidates)==null?void 0:O.length)||0," total)"]}),a.seedHandle&&e.jsxs(g,{variant:"light",children:["@",a.seedHandle]}),Array.isArray(a.seeds)&&a.seeds.length>0&&e.jsxs(g,{variant:"light",leftSection:e.jsx(ye,{size:10}),children:["look-alike of ",a.seeds.length," seeds"]}),a.mode&&e.jsx(g,{variant:"light",color:"gray",children:a.mode==="following"?"following":"followers"})]}),u.size>0&&e.jsxs(C,{size:"xs",leftSection:e.jsx(Le,{size:14}),onClick:()=>M(!0),children:["Save ",u.size," to list"]})]}),e.jsxs(o,{gap:"xs",wrap:"wrap",children:[e.jsxs(g,{variant:x?"light":"filled",color:"dark",style:{cursor:"pointer"},onClick:()=>N(null),children:["All · ",((Q=a.candidates)==null?void 0:Q.length)||0]}),Object.entries(ce).map(([s,t])=>e.jsxs(g,{variant:x===s?"filled":"light",color:s===V[0]?"green":s==="unclear"?"gray":"orange",style:{cursor:"pointer"},onClick:()=>N(x===s?null:s),children:[s," · ",t]},s)),e.jsx(Z,{size:"xs",w:150,label:"",placeholder:"min score",value:A,onChange:s=>re(Math.max(0,Math.min(100,Number(s)||0))),min:0,max:100,leftSection:e.jsx(p,{size:"xs",c:"dimmed",children:"â¥"})})]}),e.jsx(ve,{h:520,children:e.jsxs(n,{verticalSpacing:"xs",fz:"sm",children:[e.jsx(n.Thead,{children:e.jsxs(n.Tr,{children:[e.jsx(n.Th,{w:24,children:e.jsx(J,{checked:H,onChange:oe,"aria-label":"Select all"})}),e.jsx(n.Th,{children:"Profile"}),e.jsx(n.Th,{children:"Category"}),e.jsx(n.Th,{children:"Score"}),e.jsx(n.Th,{children:"Why"})]})}),e.jsx(n.Tbody,{children:v.map(s=>e.jsxs(n.Tr,{children:[e.jsx(n.Td,{children:e.jsx(J,{checked:u.has(s.handle),onChange:()=>de(s.handle),"aria-label":`Select @${s.handle}`})}),e.jsx(n.Td,{children:e.jsxs(o,{gap:"xs",wrap:"nowrap",children:[e.jsx(be,{src:s.avatar,radius:"xl",size:"sm",children:(s.handle||"?").slice(0,1).toUpperCase()}),e.jsxs(b,{gap:0,style:{minWidth:0},children:[e.jsxs(o,{gap:4,wrap:"nowrap",children:[e.jsxs(Ce,{href:`https://x.com/${s.handle}`,target:"_blank",rel:"noreferrer",size:"sm",fw:500,children:["@",s.handle]}
1),e.jsx(De,{size:10,color:"var(--mantine-color-dimmed)"}),e.jsx(Te,{handle:s.handle}),e.jsx(ze,{handle:s.handle,size:"xs"})]}),e.jsxs(p,{size:"xs",c:"dimmed",truncate:!0,maw:300,children:[s.name||"",s.location?` · ${s.location}`:"",s.followers!=null?` · ${Fe(s.followers)} followers`:""]}),s.bio&&e.jsx(p,{size:"xs",c:"dimmed",lineClamp:2,maw:400,children:s.bio})]})]})}),e.jsx(n.Td,{children:e.jsx(g,{variant:"light",color:s.category===V[0]?"green":s.category==="unclear"?"gray":"orange",children:s.category})}),e.jsx(n.Td,{children:e.jsx(p,{fw:600,size:"sm",c:s.score>=70?"green":s.score>=40?"orange":"dimmed",children:s.score})}),e.jsx(n.Td,{children:e.jsx(P,{label:s.reason||"",multiline:!0,w:280,withArrow:!0,disabled:!s.reason,children:e.jsx(p,{size:"xs",c:"dimmed",lineClamp:2,maw:260,children:s.reason||"â"})})})]},s.handle))})]})})]})}),e.jsx(Ee,{opened:ie,onClose:()=>M(!1),lists:((X=L.data)==null?void 0:X.lists)||[],candidates:((a==null?void 0:a.candidates)||[]).filter(s=>u.has(s.handle)),onSaved:()=>{M(!1),m(new Set)}})]})}function Ee({opened:i,onClose:k,lists:T,candidates:c,onSaved:j}){const d=ee(),[h,w]=l.useState(null),S=se({mutationFn:()=>f.saveDiscoveryToList({listId:h,candidates:c}),onSuccess:r=>{te(`Saved ${r.added} (skipped ${r.skipped}) â list now has ${r.total} handles`),d.invalidateQueries({queryKey:["lists"]}),d.invalidateQueries({queryKey:["list",h]}),j==null||j()},onError:r=>ae(r)});return e.jsx(ke,{opened:i,onClose:k,title:`Save ${c.length} candidates to a list`,size:"md",children:e.jsxs(b,{gap:"sm",children:[e.jsx(I,{label:"List",placeholder:"Pick a list",data:T.map(r=>({value:r.id,label:`${r.name} (${r.handleCount||0})`})),value:h,onChange:w,searchable:!0}),e.jsxs(o,{justify:"flex-end",children:[e.jsx(C,{variant:"subtle",onClick:k,children:"Cancel"}),e.jsx(C,{leftSection:e.jsx(Pe,{size:14}),onClick:()=>S.mutate(),disabled:!h||!c.length,loading:S.isPending,children:"Save"})]})]})})}function Fe(i){return i==null?"?":i>=1e6?`${(i/1e6).toFixed(1)}M`:i>=1e3?`${(i/1e3).toFixed(1)}K`:String(i)}export{as 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.