import{k as K,p as k,c as t,l as B,m as D,u as l,a as s,t as e,x as C,e as i,j as _,i as n,F,n as I,w as M,v as q,b as E,h as H,r as c,z as J,q as L,o}from"./index-B1lw4PRH.js";import{_ as O}from"./_plugin-vue_export-helper-DlAUqK2U.js";const P={class:"row",style:{"align-items":"center","margin-bottom":"12px"}},R={style:{margin:"0"}},U={key:0,class:"muted"},$=["disabled"],A={key:0,class:"spinner",style:{"margin-right":"4px"}},G={key:0,class:"card task"},Q={key:0},W={key:0,class:"bubble msg-customer muted"},X={key:2,class:"composer"},Y=["disabled","placeholder"],Z=["disabled"],ee={key:3,class:"card debrief"},se={key:0},ae={class:"json"},te={class:"primary",style:{"margin-top":"12px"}},le={__name:"Chat",setup(ne){const N=H(),m=N.params.gid,g=N.params.pid,r=c(null),f=c(!1),v=c([]),p=c(""),d=c(!1),u=c(null),w=c(""),j=c(null);function T(){J(()=>{y.value&&(y.value.scrollTop=y.value.scrollHeight)})}const y=c(null);K(async()=>{r.value=(await k.getPersona(m,g)).persona;const a=await k.chatStart(m,g);j.value=a.session.id,a.session.task&&(w.value=a.session.task),v.value=a.session.messages||[],f.value=!0,v.value.length&&T()});async function V(){if(p.value.trim()){d.value=!0;try{const a=await k.chatSend(m,g,p.value.trim());v.value=a.messages,p.value="",T()}catch(a){alert(a.message)}finally{d.value=!1}}}async function z(){if(confirm(n.t("finish")+"?")){d.value=!0;try{const a=await k.chatFinish(m,g);u.value=a.debrief,v.value=a.session.messages}catch(a){alert(a.message)}finally{d.value=!1}}}return(a,b)=>{const S=L("router-link");return o(),t("div",null,[B(S,{to:`/groups/${l(m)}/personas`,class:"btn-back"},{default:D(()=>[_("โ† "+e(l(n).t("personas")),1)]),_:1},8,["to"]),s("div",P,[s("h2",R,e(r.value?r.value.name:"..."),1),s("span",{class:C(["badge",r.value&&r.value.channel])},e(r.value?r.value.channel:""),3),r.value?(o(),t("span",U,e(r.value.profession)+" ยท "+e(r.value.age_group),1)):i("",!0),s("button",{class:"danger",style:{"margin-left":"auto"},onClick:z,disabled:v.value.length===0||!!u.value},[d.value?(o(),t("span",A)):i("",!0),_(e(l(n).t("finish")),1)],8,$)]),f.value?i("",!0):(o(),t("div",G,[s("strong",null,"๐Ÿ“ฃ "+e(l(n).t("sellerInitiated")),1),w.value?(o(),t("div",Q,e(w.value),1)):i("",!0)])),f.value?(o(),t("div",{key:1,class:"thread",ref_key:"thread",ref:y},[(o(!0),t(F,null,I(v.value,(h,x)=>(o(),t("div",{key:x,class:C(["bubble",h.role==="seller"?"msg-seller":"msg-customer"])},e(h.text),3))),128)),d.value?(o(),t("div",W,"...")):i("",!0)],512)):i("",!0),f.value&&!u.value?(o(),t("div",X,[M(s("input",{"onUpdate:modelValue":b[0]||(b[0]=h=>p.value=h),onKeyup:E(V,["enter"]),disabled:d.value,placeholder:l(n).t("send")},null,40,Y),[[q,p.value]]),s("button",{class:"primary",onClick:V,disabled:d.value||!p.value.trim()},e(l(n).t("send")),9,Z)])):i("",!0),u.value?(o(),t("div",ee,[s("h3",null,e(l(n).t("debrief")),1),s("p",null,[s("span",{class:C(["badge",u.value.outcome])},e(u.value.outcome==="won"?l(n).t("won"):l(n).t("lost")),3),_(" โ€” "+e(l(n).t("score"))+": ",1),s("strong",null,e(u.value.score),1)]),s("p",null,[s("strong",null,e(l(n).t("pain"))+":",1),_(" "+e(u.value.pain||"โ€”"),1)]),s("p",null,[s("strong",null,e(l(n).t("why"))+":",1),_(" "+e(u.value.why),1)]),u.value.coaching&&u.value.coaching.length?(o(),t("div",se,[b[1]||(b[1]=s("strong",null,"Coaching:",-1)),s("ul",null,[(o(!0),t(F,null,I(u.value.coaching,(h,x)=>(o(),t("li",{key:x},e(h),1))),128))])])):i("",!0),s("details",null,[s("summary",null,e(l(n).t("reveal")),1),s("pre",ae,e(JSON.stringify(u.value.revealed_persona,null,2)),1)]),B(S,{to:"/"},{default:D(()=>[s("button",te,e(l(n).t("dashboard")),1)]),_:1})])):i("",!0)])}}},re=O(le,[["__scopeId","data-v-4f54526a"]]);export{re as default};