1import{u as ie,r as o,s as b,j as e,W as le,C as oe,D as ne,o as ce,p as de,q as me,t as pe,Q as ue,B as q,Z as xe,v as fe}from"./index-Bg3Onjrj.js";import{u as ge}from"./useDocumentTitle-ClVLV4-9.js";import{A as he}from"./AppHeader-BnZsQZt1.js";import{P as ye}from"./PageHeader-CSgMY6M5.js";import{S as be}from"./slider-hgwTueAW.js";import{f as je}from"./fetchResolvedPlaybook-DBBIJmbl.js";import{f as ve}from"./resolverTypes-BwqPjrIh.js";import{e as _e,A as Q,C as T,b as we}from"./archetypeDisplay-BtgQkrzE.js";import{l as Ne,c as Ce,d as ke,a as Y}from"./buildPracticeDrill-BvRx5_Y2.js";import{U as Se}from"./UpgradeModal-BP6unu8O.js";import{u as Te}from"./useSubscription-DfiJgWO2.js";import{u as Me}from"./useUserMastery-BkcnbnBa.js";import{Q as Pe}from"./quote-CKPZ4tqS.js";import{V as Ae}from"./volume-2-BSeohR_K.js";import{A as Fe}from"./arrow-right-Cf3yTcrr.js";import"./dropdown-menu-CGUMN6se.js";import"./index-CZetrdVF.js";import"./chevron-right-BNkwTSID.js";import"./sheet-5eb6CxJM.js";import"./profileUtils-CQn6ptGn.js";import"./book-open-ECHikO1t.js";import"./target-Bwlean-H.js";import"./zap-Dc24AduK.js";import"./users-CKUTlB-C.js";import"./shield-check-CkpgyR85.js";import"./menu-D_c7nqGX.js";import"./user-B9Bzl6nh.js";import"./trophy-BBxD3Zpx.js";import"./activity-DKIF7fqO.js";import"./building-2-LGeXi5Jb.js";import"./plug-CAdgd6Lt.js";import"./briefcase-Af5xjo1x.js";import"./phone-call-XvbEcZ0r.js";import"./chrome-D3pzRdrO.js";import"./credit-card-B-niur1p.js";import"./log-out-8mgOuApa.js";import"./index-BdQq_4o_.js";import"./resolver-C1n7klAO.js";import"./snapshot-C3Js1j9u.js";import"./practiceCallContext-Dgy4B0iw.js";import"./circle-help-Dtl-IMBV.js";import"./heart-Cj6wjNHv.js";import"./clock-e5Y3Jxbr.js";import"./shuffle-GmCYZyOl.js";import"./hourglass-CzCZUbvD.js";import"./eye-off-CvDOuS16.js";import"./shield-alert-CJmh4C8o.js";import"./message-circle-question-xevoLDO0.js";import"./compass-rfYi5xkX.js";import"./umbrella-BNKwyeuI.js";import"./network-DJeUOXE_.js";import"./clipboard-list-hNbnXBVK.js";import"./triangle-alert-CADHZMVk.js";import"./salesContext-DIvO2S_L.js";import"./useMotions-Bz0M5W19.js";import"./useMotionFocus-Conpz-FF.js";import"./formatDistanceToNow-wdVttbCy.js";import"./getRoundingMethod-CRK7W-F-.js";import"./en-US-DETrzo_J.js";import"./endOfMonth-EuJ6n9dn.js";import"./useQuery-D4KMoL1d.js";import"./useAuthUserId-BQ3Wbln5.js";import"./scoreLevels-BAjwvMd7.js";const De={beginner:2,intermediate:3,advanced:4,elite:5};function Ee({archetype:s,onClick:i}){const m=T[s.color]??T.gray,[d,j]=o.useState(!1);return s.icon,e.jsxs(oe,{className:"group rounded-xl overflow-hidden p-0 cursor-pointer transition-all duration-200 hover:shadow-md hover:-translate-y-0.5 border-border/60",onClick:i,children:[e.jsxs("div",{className:`relative aspect-[3/4] border-b-2 ${m.border}`,children:[s.avatar?e.jsxs(e.Fragment,{children:[!d&&e.jsx("div",{className:"absolute inset-0 animate-pulse bg-muted"}),e.jsx("img",{src:s.avatar,alt:s.name,onLoad:()=>j(!0),className:`w-full h-full object-cover transition-all duration-200 group-hover:scale-105 ${d?"opacity-100":"opacity-0"}`})]}):e.jsx("div",{className:`w-full h-full flex items-end justify-center ${m.placeholder} overflow-hidden`,children:e.jsxs("svg",{viewBox:"0 0 160 200",className:`w-4/5 opacity-20 ${m.text}`,fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("ellipse",{cx:"80",cy:"62",rx:"38",ry:"42"}),e.jsx("path",{d:"M0 200 C0 140 30 118 80 118 C130 118 160 140 160 200Z"})]})}),e.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/75 via-black/10 to-transparent p-2 pt-6",children:e.jsx("h3",{className:"text-white font-semibold text-sm leading-tight",children:s.name})})]}),e.jsx("div",{className:"p-2.5",children:e.jsx("p",{className:"text-xs text-muted-foreground italic line-clamp-2 leading-snug",children:s.quote})})]})}function Be({archetype:s,selectedCallTypeId:i,onCallTypeChange:m,onClose:d,onPractice:j,starting:g,defaultDifficulty:M}){const N=s.icon,p=T[s.color]??T.gray,[h,P]=o.useState(M),A=s.difficultyMax>s.difficultyMin,n=ve(s.tiers,h);return e.jsx(ne,{open:!0,onOpenChange:r=>!r&&!g&&d(),children:e.jsxs(ce,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsx(de,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[s.avatar?e.jsx("img",{src:s.avatar,alt:s.name,className:`w-14 h-14 roun
1ded-full object-cover ring-2 ${p.border}`}):e.jsx("div",{className:`w-14 h-14 rounded-full flex items-center justify-center ring-2 ${p.border} ${p.placeholder}`,children:e.jsx(N,{className:`w-6 h-6 ${p.text} opacity-60`})}),e.jsxs("div",{children:[e.jsxs(me,{className:"text-lg flex items-center gap-1.5",children:[s.name,e.jsx(N,{className:`w-4 h-4 ${p.text}`})]}),e.jsx(pe,{className:"text-sm italic",children:s.quote})]})]})}),e.jsxs("div",{className:"space-y-4",children:[A&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-1.5",children:["Difficulty: ",h,"/5"]}),e.jsx(be,{min:s.difficultyMin,max:s.difficultyMax,step:1,value:[h],onValueChange:([r])=>P(r)}),e.jsx("div",{className:"flex justify-between px-0.5 mt-1 text-[10px] text-muted-foreground tabular-nums",children:Array.from({length:s.difficultyMax-s.difficultyMin+1},(r,C)=>s.difficultyMin+C).map(r=>e.jsx("span",{children:r},r))}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:["This buyer can be played anywhere from ",s.difficultyMin," to ",s.difficultyMax," â drag to pick how hard you want it."]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-1.5",children:"Behavior"}),e.jsx("ul",{className:"space-y-1",children:s.behaviors.map(r=>e.jsxs("li",{className:"text-sm flex items-start gap-2",children:[e.jsx("span",{className:"mt-1.5 w-1 h-1 rounded-full bg-primary flex-shrink-0"}),r]},r))}),(n==null?void 0:n.behavior)&&e.jsxs("p",{className:"text-sm mt-2 pl-3 border-l-2 border-primary/30 text-foreground/90",children:["At this difficulty: ",n.behavior]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-1.5",children:"You'll Hear"}),e.jsx("div",{className:"space-y-1.5",children:s.hears.map(r=>e.jsxs("div",{className:"bg-muted/60 rounded-lg px-3 py-2 text-sm italic flex items-center gap-2",children:[e.jsx(Pe,{className:"w-3.5 h-3.5 text-primary/60 flex-shrink-0"}),r]},r))})]}),s.voiceTraits&&e.jsxs("div",{className:"flex items-start gap-2 pt-1",children:[e.jsx(Ae,{className:"w-3.5 h-3.5 text-primary mt-0.5 flex-shrink-0"}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium text-foreground/80",children:"Voice traits: "}),e.jsx("span",{className:"text-foreground/85",children:s.voiceTraits})]})]}),e.jsxs("div",{className:"bg-primary/5 border border-primary/10 rounded-lg p-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-1",children:"How To Handle This Buyer"}),e.jsx("p",{className:"text-sm",children:(n==null?void 0:n.unlock_guidance)||s.needs})]}),s.applicableCallTypes.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2",children:"Practice scenario"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.applicableCallTypes.map(r=>e.jsx("button",{type:"button",onClick:()=>m(r.id),className:`text-sm px-3 py-1.5 rounded-lg border transition-colors ${i===r.id?"bg-primary text-primary-foreground border-primary":"bg-background border-border hover:border-primary/50 text-foreground"}`,children:r.label},r.id))}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-2",children:["Adjust which call types apply to each buyer in your"," ",e.jsx("a",{href:"/app/playbook",className:"underline hover:text-foreground",children:"playbook settings"}),"."]})]})]}),e.jsxs(ue,{className:"flex-col sm:flex-row gap-2",children:[e.jsx(q,{variant:"outline",onClick:d,disabled:g,className:"sm:flex-1",children:"Close"}),e.jsx(q,{onClick:()=>j(h),disabled:g,className:"sm:flex-1 flex items-center gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-4 h-4 animate-spin"}),"Preparing callâ¦"]}):e.jsxs(e.Fragment,{children:["Practice With This Buyer",e.jsx(Fe,{className:"w-4 h-4"})]})})]})]})})}function Qs(){ge("AI Buyers | Recurra");const s=ie(),[i,m]=o.useState(null),[d,j]=o.useState(null),[g,M]=o.use
1State(!0),[N,p]=o.useState([]),[h,P]=o.useState({}),[A,n]=o.useState(null),[r,C]=o.useState(null),[I,F]=o.useState(null),[W,D]=o.useState(!1),[Z,E]=o.useState(!1),{createCheckoutSession:z}=Te(),{currentLevel:G}=Me((i==null?void 0:i.id)??void 0);o.useEffect(()=>{b.auth.getSession().then(({data:{session:t}})=>{if(j(t),m((t==null?void 0:t.user)??null),!(t!=null&&t.user)){s("/auth");return}J(t.user.id)})},[s]);const J=async t=>{try{const l=await je(t);n(l);const{archetypes:u,existingProspects:x}=await _e(l,t);P(x),p(u)}catch{}finally{M(!1)}},K=async(t,l,u)=>{var v,$;const x=Math.max(t.difficultyMin,Math.min(t.difficultyMax,u??t.difficulty));if(!(!i||!d)){D(!0);try{const{data:_}=await b.functions.invoke("check-subscription-access",{headers:{Authorization:`Bearer ${d.access_token}`}});if((_==null?void 0:_.practiceCreditsRemaining)<=0){E(!0),D(!1);return}const{data:a}=await b.from("profiles").select("id, first_name, name, preferred_language, product_service, sales_domain, company_name, job_title, sales_model, business_vertical").eq("user_id",i.id).maybeSingle(),f=await Ne(i.id,A),y=we(t,h,f.salesContext),k={name:y.prospect_name,title:y.prospect_title,company:y.prospect_company,industry:y.prospect_industry},{data:U,error:X}=await b.from("prospects").insert({user_id:i.id,...y}).select().single();if(X||!U)throw new Error("Failed to create prospect");const R=Q[t.id]??{callType:"Cold Call",practiceFocus:"objection_handling"},B=l?t.applicableCallTypes.find(w=>w.id===l):null,H=Ce(f.resolved,R.callType),S=(B==null?void 0:B.id)??((v=t.applicableCallTypes.find(w=>w.id===H))==null?void 0:v.id)??(($=t.applicableCallTypes[0])==null?void 0:$.id)??H??"cold_call",L=ke(f.resolved,S),ee=[R.practiceFocus,L.defaultFocus],O=Y({resolved:f.resolved,callType:S,practiceFocusCandidates:ee}).practice_focus,se=b.functions.invoke("generate-scenario",{body:{prospect_name:k.name,prospect_title:k.title,prospect_company:k.company,prospect_industry:k.industry,trigger_event:y.trigger_event??void 0,call_type:S,sales_stage:L.defaultStage,practice_focus:O,difficulty:x,archetype_id:t.id,seller_product:(a==null?void 0:a.product_service)??"",seller_domain:(a==null?void 0:a.sales_domain)??"",seller_company:(a==null?void 0:a.company_name)??"",seller_job_title:(a==null?void 0:a.job_title)??"",seller_sales_model:(a==null?void 0:a.sales_model)??"",seller_industry:(a==null?void 0:a.business_vertical)??""}}),te=new Promise(w=>setTimeout(()=>w({data:null}),2e4)),{data:c}=await Promise.race([se,te]),re=Y({resolved:f.resolved,callType:S,archetype:t,difficulty:x,scenarioObjections:(c==null?void 0:c.objections)??null,practiceFocusCandidates:[O],motions:f.motions,selectedMotionIds:f.selectedMotionIds}),{data:V,error:ae}=await b.from("recommended_drills").insert({user_id:i.id,prospect_id:U.id,...re,sales_stage:L.defaultStage,origin:"user",source:"ai-buyers",scenario_source:"llm",status:"new",scenario_description:(c==null?void 0:c.scenario)??null,scenario_goals:(c==null?void 0:c.goals)??null}).select(` 2 *, 3 prospects:prospect_id ( 4 id, 5 prospect_name, 6 prospect_company, 7 prospect_title, 8 prospect_industry, 9 prospect_needs_summary, 10 prospect_type, 11 city, 12 state, 13 gender, 14 persona_traits, 15 trigger_event, 16 awareness_level, 17 persona_types:persona_type_id ( 18 name 19 ) 20 ) 21 `).single();if(ae||!V)throw new Error("Failed to create drill");s("/app/practice",{state:{drillData:{drill:V,profile:null,userId:i.id}}})}catch(_){fe.error(_.message??"Failed to start practice call"),D(!1)}}};return g?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):i?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(he,{user:i}),e.jsx("main",{className:"pt-16",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[e.jsx(ye,{title:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"w-5 h-5 text-primary"}),"AI Buyers"]}
21),subtitle:"Pick a buyer type and start a practice call. Each persona behaves differently â choose one to work on."}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3",children:N.map(t=>e.jsx(Ee,{archetype:t,onClick:()=>{var x;C(t);const l=Q[t.id],u=t.applicableCallTypes.find(v=>v.label===(l==null?void 0:l.callType)||v.id===(l==null?void 0:l.callType));F((u==null?void 0:u.id)??((x=t.applicableCallTypes[0])==null?void 0:x.id)??null)}},t.id))})]})}),r&&e.jsx(Be,{archetype:r,selectedCallTypeId:I,onCallTypeChange:F,onClose:()=>{C(null),F(null)},onPractice:t=>K(r,I,t),starting:W,defaultDifficulty:Math.max(r.difficultyMin,Math.min(r.difficultyMax,De[G.key]??3))}),e.jsx(Se,{open:Z,onOpenChange:E,onUpgrade:async()=>{await z(),E(!1)},inline:!0})]}):null}export{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.