1import{j as e}from"./markdown-B-XC8faE.js";import{r as d}from"./icons-FOYoml-d.js";import{u as E,s as p,m as l,H as B,L as T,B as c}from"./index-CnEchNE5.js";import{A as z}from"./AdminNav-Cit4RV9G.js";import"./three-CWrCzQay.js";import"./radix-CZPgPwSx.js";import"./supabase-DRo1YIZv.js";import"./motion-Bqrfl3ZR.js";const D={captured:"Captured",engaged:"Engaged",high_intent:"High Intent",booked:"Booked",customer:"Customer"},$=n=>`$${(n/100).toLocaleString()}`,i=n=>n?new Date(n).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}):"-",o=({children:n})=>e.jsx("span",{className:"border border-foreground px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.16em]",children:n});function G(){const{id:n=""}=E(),[r,C]=d.useState(null),[j,L]=d.useState([]),[A,N]=d.useState(!0),[v,_]=d.useState(""),[u,k]=d.useState(""),[y,S]=d.useState(!1),m=d.useCallback(async()=>{N(!0);const[s,t]=await Promise.all([p.from("revenue_prospects").select("*").eq("id",n).maybeSingle(),p.from("revenue_touches").select("*").eq("prospect_id",n).order("created_at",{ascending:!1}).limit(200)]);s.error&&l.error(s.error.message),t.error&&l.error(t.error.message);const a=s.data??null;C(a),_((a==null?void 0:a.owner_notes)??""),k(a!=null&&a.next_action_at?a.next_action_at.slice(0,16):""),L(t.data??[]),N(!1)},[n]);d.useEffect(()=>{m()},[m]);const P=async()=>{S(!0);const{error:s}=await p.from("revenue_prospects").update({owner_notes:v.trim()||null,next_action_at:u?new Date(u).toISOString():null}).eq("id",n);if(S(!1),s){l.error(s.message);return}l.success("Saved"),m()},g=async(s,t)=>{const a=new Date().toISOString(),x={status:t,approved_at:t==="sent"?void 0:a,sent_at:t==="sent"?a:void 0},{error:w}=await p.from("revenue_touches").update(x).eq("id",s);if(w){l.error(w.message);return}m()},h=async(s,t,a)=>{const{error:x}=await p.from("revenue_touches").insert({prospect_id:n,channel:"manual",touch_type:s,mode:"manual",status:"sent",subject:t,body:"Logged by operator from the prospect page.",destination:a,sent_at:new Date().toISOString(),payload:{logged_by:"operator"}});if(x){l.error(x.message);return}l.success("Touch logged"),m()},b=j.filter(s=>s.status==="pending"||s.status==="approved"),f=j.filter(s=>s.status!=="pending"&&s.status!=="approved");return e.jsxs("div",{className:"min-h-screen bg-background px-4 py-8 md:px-8",children:[e.jsxs(B,{children:[e.jsxs("title",{children:[r!=null&&r.email?`${r.email} | Prospect`:"Prospect"," | Kodiak Engine"]}),e.jsx("meta",{name:"robots",content:"noindex,nofollow"})]}),e.jsx(z,{className:"mb-8"}),e.jsxs("div",{className:"mx-auto max-w-5xl",children:[e.jsx(T,{to:"/kodiak-engine/revenue",className:"text-[10px] font-semibold uppercase tracking-[0.16em] underline",children:"Back to pipeline"}),A?e.jsx("p",{className:"mt-6 text-sm text-muted-foreground",children:"Loading..."}):r?e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"mt-4 border-b-2 border-foreground pb-4",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:r.email}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:[r.name,r.company].filter(Boolean).join(" / ")||"No name on file yet"}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(o,{children:D[r.stage]??r.stage}),e.jsxs(o,{children:["score ",r.intent_score]}),r.icp&&e.jsx(o,{children:r.icp}),r.first_source&&e.jsxs(o,{children:["first: ",r.first_source]}),r.last_source&&e.jsxs(o,{children:["last: ",r.last_source]}),e.jsx(o,{children:r.capture_mode==="live"?"captured live":"backfilled by sync"})]})]}),e.jsx("section",{className:"mt-6 grid grid-cols-2 gap-px border-2 border-foreground bg-foreground md:grid-cols-4",children:[["First Seen",i(r.first_seen_at??r.created_at)],["Last Signal",i(r.last_signal_at??r.updated_at)],["Booked",i(r.booked_at)],["Purchased",i(r.purchased_at)],["Revenue",r.revenue_cents?$(r.revenue_cents):"$0"]].map(([s,t])=>e.jsxs("div",{className:"bg-background px-3 py-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.16em]",children:s}),e.jsx("p",{className:"mt-1 text-sm font-bold",children:t})]},s))}),e.jsxs("section",{className:"mt-8",children:[e.jsx("h2",{className:"mb-3 text-lg font-bold uppercase tracking-tight",children:"Attribution"}),e.jsx("div",{className:"grid grid-cols-2 gap-px border-2 border-foreground bg-foreground md:grid-cols-3",children:[["Source",r.utm_source??r.first_source??"-"],["Medium",r.utm_medium??"-"],["Campaign",r.utm_campaign??"-"],["Landing Page",r.landing_page??r.last_page??"-"],["Referrer",r.referrer??"-"],["Capture Mode",r.capture_mode==="live"?"Live form or chat":"Daily sync backfill"]].map(([s,t])=>e.jsxs("div",{className:"bg-background px-3 py-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.16em]",children:s}),e.jsx("p",{className:"mt-1 break-words text-sm font-bold",children:t})]},s))})]}),e.jsxs("section",{className:"mt-8",children:[e.jsxs("h2",{className:"mb-3 text-lg font-bold uppercase tracking-tight",children:["Next Action (",b.length,")"]}),b.length===0?e.jsx("p",{className:"border-2 border-foreground p-4 text-sm text-muted-foreground",children:"Nothing queued. Log a manual touch below or run the sync from the pipeline page."}):e.jsx("div",{className:"space-y-3",children:b.map(s=>e.jsxs("div",{className:"border-2 border-foreground p-4",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[e.jsx(o,{children:s.touch_type}),e.jsx(o,{children:s.channel}),e.jsx(o,{children:s.mode}),e.jsx(o,{children:s.status}),s.destination&&e.jsx(o,{children:s.destination})]}),e.jsx("p",{className:"font-semibold",children:s.subject}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.body}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Due ",i(s.due_at)]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[s.status==="pending"&&e.jsx(c,{size:"sm",className:"rounded-none border-2 border-foreground",onClick:()=>g(s.id,"approved"),children:"Approve"}),e.jsx(c,{size:"sm",variant:"outline",className:"rounded-none border-2 border-foreground",onClick:()=>g(s.id,"sent"),children:"Mark Sent"}),e.jsx(c,{size:"sm",variant:"outline",className:"rounded-none border-2 border-foreground",onClick:()=>g(s.id,"skipped"),children:"Skip"})]})]},s.id))}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(c,{size:"sm",variant:"outline",className:"rounded-none border-2 border-foreground",onClick:()=>h("call","Call logged","/book"),children:"Log Call"}),e.jsx(c,{size:"sm",variant:"outline",className:"rounded-none border-2 border-foreground",onClick:()=>h("email","Manual email sent","/clarity-pilot"),children:"Log Email"}),e.jsx(c,{size:"sm",variant:"outline",className:"rounded-none border-2 border-foreground",onClick:()=>h("proposal","Proposal sent","/pricing"),children:"Log Proposal"})]})]}),e.jsxs("section",{className:"mt-10",children:[e.jsxs("h2",{className:"mb-3 text-lg font-bold uppercase tracking-tight",children:["Signals (",(r.signals??[]).length,")"]}),e.jsx("ol",{className:"border-2 border-foreground",children:(r.signals??[]).length===0?e.jsx("li",{className:"p-4 text-sm text-muted-foreground",children:"No signals recorded."}):(r.signals??[]).map((s,t)=>
1e.jsxs("li",{className:"border-b border-foreground/30 p-3 text-sm last:border-b-0",children:[e.jsx("span",{className:"mr-2 text-[10px] font-semibold uppercase tracking-[0.16em]",children:String(t+1).padStart(2,"0")}),s]},`${s}-${t}`))}),r.last_page&&e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Last page: ",r.last_page]})]}),e.jsxs("section",{className:"mt-10",children:[e.jsxs("h2",{className:"mb-3 text-lg font-bold uppercase tracking-tight",children:["Touch History (",f.length,")"]}),f.length===0?e.jsx("p",{className:"border-2 border-foreground p-4 text-sm text-muted-foreground",children:"Nothing sent or skipped yet."}):e.jsx("div",{className:"overflow-x-auto border-2 border-foreground",children:e.jsxs("table",{className:"w-full min-w-[640px] text-sm",children:[e.jsx("thead",{className:"border-b-2 border-foreground text-[10px] uppercase tracking-[0.16em]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3 text-left",children:"When"}),e.jsx("th",{className:"p-3 text-left",children:"Type"}),e.jsx("th",{className:"p-3 text-left",children:"Channel"}),e.jsx("th",{className:"p-3 text-left",children:"Status"}),e.jsx("th",{className:"p-3 text-left",children:"Subject"})]})}),e.jsx("tbody",{children:f.map(s=>
1e.jsxs("tr",{className:"border-b border-foreground/30 align-top",children:[e.jsx("td",{className:"p-3 whitespace-nowrap",children:i(s.sent_at??s.created_at)}),e.jsx("td",{className:"p-3",children:s.touch_type}),e.jsx("td",{className:"p-3",children:s.channel}),e.jsx("td",{className:"p-3 font-semibold",children:s.status}),e.jsxs("td",{className:"p-3",children:[s.subject,s.last_error&&e.jsx("span",{className:"block text-xs text-destructive",children:s.last_error})]})]},s.id))})]})})]}),e.jsxs("section",{className:"mt-10 mb-16",children:[e.jsx("h2",{className:"mb-3 text-lg font-bold uppercase tracking-tight",children:"Operator Notes"}),e.jsx("textarea",{value:v,onChange:s=>_(s.target.value),rows:6,placeholder:"What they said, what they need, what happens next.",className:"w-full border-2 border-foreground bg-background p-3 text-sm"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-3",children:[e.jsxs("label",{className:"text-[10px] font-semibold uppercase tracking-[0.16em]",children:["Next action date",e.jsx("input",{type:"datetime-local",value:u,onChange:s=>k(s.target.value),className:"mt-1 block border-2 border-foreground bg-background p-2 text-sm normal-case tracking-normal"})]}),e.jsx(c,{onClick:P,disabled:y,className:"rounded-none border-2 border-foreground",children:y?"Saving...":"Save"})]}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Notes and the next action date survive every sync. The sync only updates scores, stages, and signals."})]})]}):e.jsx("p",{className:"mt-6 border-2 border-foreground p-4 text-sm",children:"No prospect with that id. It may have been archived."})]})]})}export{G 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.