import{T as re,H as de,_ as ce}from"./DefaultUserIcon.cc4edf82.js";import{_ as ue}from"./nuxt-link.c11ad0c0.js";import{_ as me}from"./PButton.094b2d57.js";import{d as ge,u as he,a as pe,B as fe,b as c,r as xe,o as _e,c as ve,e as ye,f as M,g as be,h as n,i as l,j as i,w as h,k as p,t as u,l as t,m as e,F as $,n as Y,p as T,q as v,s as j,v as Q,x as W,y as X,z as ke,$ as we,A as Ue}from"./entry.73fe5fb5.js";import{u as Ce}from"./useFetchAPI.dfea07dd.js";import{r as Se}from"./ChevronLeftIcon.4920b682.js";import{r as Z,a as Le,b as Me,c as $e,d as Ae,U as Ne,h as ee,G as Ie,e as Be,V as Re,S as Te}from"./SpeakerXMarkIcon.e2fbbd2f.js";import"./index.75711a53.js";const je={class:"overflow-hidden bg-white dark:bg-neutral-100/10 text-gray-600 dark:text-neutral-400 shadow sm:rounded-md sm:mx-0 absolute inset-x-0 sm:inset-x-6 top-0 sm:top-6 bottom-0 sm:bottom-6"},Ee={class:"px-4 sm:px-6 py-3"},Ve={class:"flex"},De={"aria-label":"Back"},Oe={key:0,class:"flex-shrink-0 ml-auto"},Pe={class:"flex -space-x-1 justify-center"},ze=["src","alt"],Fe=e("div",{class:"w-full border-t border-gray-300 dark:border-neutral-100/10"},null,-1),Ge={class:"px-4 sm:px-6 py-4 sm:py-6"},He={class:"min-w-0 flex-1"},Je={class:"flex gap-x-3 -mt-1 sm:-mt-2 sm:-mb-1 text-lg sm:text-xl md:text-2xl leading-tight tracking-tight text-gray-900 dark:text-white"},Ke={class:"font-bold"},qe={key:0,class:"mt-2 text-sm sm:text-base text-gray-600 dark:text-neutral-400 text-left"},Ye=e("div",{class:"w-full border-t border-gray-300 dark:border-neutral-100/10"},null,-1),Qe={class:"px-4 sm:px-6 pt-6"},We={key:0},Xe={class:"flex-shrink-0 mr-3 relative"},Ze=["src"],et={class:"text-xs font-medium leading-none text-white unselectable"},tt={key:3,class:"absolute right-0 -bottom-2 inline-flex items-center rounded-md bg-gray-500 px-1 py-0.5 text-xs font-medium text-white ring-2 ring-white dark:ring-neutral-800"},st={class:"min-w-0 flex-1"},at={key:0,class:"font-medium text-gray-900 dark:text-white"},nt={key:1,class:"font-medium text-gray-900 dark:text-white"},ot={class:"text-sm text-gray-600 dark:text-neutral-400 ml-1.5"},lt={class:"font-normal text-gray-900 dark:text-white"},it={key:2,class:"flex font-normal text-[11px] text-rose-600 dark:text-rose-400"},rt=e("span",{class:"self-center"},"Couldn't send.",-1),dt={class:"flex items-start space-x-3 absolute inset-x-4 sm:inset-x-6 bottom-6"},ct={class:"flex-shrink-0 mt-12"},ut={class:"relative inline-block"},mt={class:"text-xs font-medium leading-none text-white unselectable"},gt={class:"absolute bottom-0 right-0 block translate-y-1 translate-x-1 transform rounded-full border-2 border-white dark:border-neutral-800"},ht={class:"mt-3 text-center"},pt={class:"min-w-0 flex-1"},ft={class:"relative w-full bg-indigo-600/10 dark:bg-indigo-400/10 dark:text-white/80 -bottom-2 h-12 rounded-t-lg px-3 py-2.5 text-sm"},xt=e("span",{class:"font-medium"},"AI hosts",-1),_t={class:"hidden sm:inline-block"},vt={class:"font-medium"},yt={class:"relative w-full"},bt={class:"overflow-hidden rounded-lg shadow-sm bg-white dark:bg-neutral-800 ring-1 ring-inset ring-gray-300 dark:ring-neutral-100/10 focus-within:ring-2 focus-within:ring-indigo-600"},kt=e("label",{for:"message-field",class:"sr-only"},"Message",-1),wt=["placeholder"],Ut=e("div",{class:"py-2","aria-hidden":"true"},[e("div",{class:"py-px"},[e("div",{class:"h-9"})])],-1),Ct={class:"absolute inset-x-0 bottom-0 flex justify-between py-2 pl-3 pr-2"},St={class:"flex-shrink-0 ml-auto"},Lt=["disabled"],Mt={key:0,class:"absolute left-[13px] mt-[3px] flex items-start space-x-4 text-gray-600 dark:text-neutral-400 text-[11px]"},$t=e("div",null,[p("An "),e("span",{class:"font-semibold"},"AI host"),p(" is responding")],-1),At=[$t],Nt=e("div",{class:"fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"},null,-1),It={class:"fixed inset-0 z-10 overflow-y-auto"},Bt={class:"flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0"},Rt={class:"bg-white dark:bg-neutral-900 px-4 pb-4 pt-5 sm:p-6 sm:pb-4"},Tt={class:"sm:flex sm:items-start"},jt={class:"mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-gray-100 dark:bg-neutral-800 sm:mx-0 sm:h-10 sm:w-10"},Et={class:"mt-3 mb-1 text-center sm:ml-4 sm:mt-0 sm:text-left"},Vt=e("div",{class:"mt-2"},[e("p",{class:"text-sm text-gray-600 dark:text-neutral-400"},"Personalize your settings.")],-1),Dt={class:"mt-4 grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-6"},Ot={class:"sm:col-span-4"},Pt=e("label",{for:"new-host-name",class:"block text-sm font-medium leading-6 text-gray-900 dark:text-white"},"Name",-1),zt={class:"mt-2"},Ft={class:"bg-gray-50 dark:bg-neutral-800 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6 sm:gap-x-2"},Gt=["disabled"],es=ge({__name:"chat",async setup(Ht){let A,z;const te=he(),r=pe(),{data:d}=([A,z]=fe(()=>Ce("/portal/shows/"+r.value.slug+"/episodes/"+te.params.episode_handle)),A=await A,z(),A),f=c(d.value.speakers);c(f.value.reduce((o,s)=>o+(s.duration?s.duration:0),0));const k=xe([]),m=c("Guest"),N=c(!1),y=c(!1),E=c(),F=c();_e(()=>{F.value.focus(),N.value=window.navigator.onLine,window.addEventListener("online",()=>I(!0)),window.addEventListener("offline",()=>I(!1)),m.value=localStorage.getItem("portalUserName")??"Guest"}),ve(()=>{window.removeEventListener("online",()=>I(!0)),window.removeEventListener("offline",()=>I(!1))}),ye(()=>{E.value.scrollTop=E.value.scrollHeight});const I=o=>{o.value=o.value},G=o=>{var s=o.split(" "),b=s[0].substring(0,1).toUpperCase();return s.length>1&&(b+=s[s.length-1].substring(0,1).toUpperCase()),b},se=o=>o.toLocaleTimeString([],{timeStyle:"short"}),ae=M(()=>"Message "+f.value.filter(s=>s.name&&s.host).map(s=>H(s.name)).join(", ")+"."),H=o=>r.value.slug==="twist"||r.value.slug==="allin"||r.value.slug==="liquidity"||r.value.slug==="timferriss"?o+" Bot":o+" AI",_=c(""),w=c(""),ne=M(()=>w.value!==""),V=M(()=>d.value.transcriptURL&&_.value.length>0&&N.value),J=async()=>{if(!V)return;const o=JSON.parse(JSON.stringify(k));o.forEach((g,U)=>{g.failed&&o.splice(U,1)});let s={id:crypto.randomUUID(),timestamp:new Date,speaker:null,message:_.value.trim(),failed:!1};k.push(s),w.value=s.id;const b=_.value.trim();_.value="",await we("/portal/shows/"+r.value.slug+"/episodes/"+d.value.handle+"/chat",{method:"POST",body:{userName:m.value==="Guest"?null:m.value,history:JSON.stringify(o),message:b,includeAudio:y.value}}).then(g=>{if(w.value===s.id){const U={id:crypto.randomUUID(),timestamp:new Date,speaker:g.data.speaker,message:g.data.message,failed:!1};if(k.push(U),y&&g.data.audio){let C=window.atob(g.data.audio),B=C.length,a=new Uint8Array(B);for(let L=0;L<B;L++)a[L]=C.charCodeAt(L);const S=new Blob([a.buffer],{type:"audio/mpeg"}),R=URL.createObjectURL(S);new Audio(R).play()}}},g=>{console.log(g),s.failed=!0}),w.value===s.id&&(w.value="")},oe=()=>{y.value=!y.value},x=c(""),D=c(!1),K=()=>{x.value=m.value,D.value=!0},O=()=>{D.value=!1},le=M(()=>x.value.length>=1&&x.value.length<=64&&x.value!==m.value),q=M(()=>!0),ie=async()=>{m.value=x.value,localStorage.setItem("portalUserName",m.value),O()};return be({title:"Chat - Portal Episode - PodcastAI",meta:[{name:"description",content:"Chat with the hosts of "+r.value.title+" about "+d.value.title+"."},{name:"og:title",content:"Chat - "+d.value.title+" - "+r.value.title},{name:"og:description",content:"Chat with the hosts of "+r.value.title+" about "+d.value.title+"."},{name:"og:image",content:r.value.imageURL??"/favicon.png"}],bodyAttrs:{class:"bg-gray-100 dark:bg-neutral-950"}}),(o,s)=>{const b=re,g=de,U=ue,C=ce,B=me;return n(),l($,null,[i(g,null,{default:h(()=>[i(b,null,{default:h(()=>[p("Chat - "+u(t(d).title)+" - "+u(t(r).title),1)]),_:1})]),_:1}),e("div",je,[e("div",Ee,[e("header",Ve,[e("nav",De,[i(U,{to:"/episodes/"+t(d).handle,class:"flex items-center leading-6 text-sm font-medium text-gray-600 dark:text-neutral-400 hover:text-gray-700 dark:hover:text-neutral-300"},{default:h(()=>[i(t(Se),{class:"-ml-1 mr-1 h-5 w-5 flex-shrink-0 text-gray-400 dark:text-neutral-500","aria-hidden":"true"}),p(" Back to the episode ")]),_:1},8,["to"])]),t(f).length>0?(n(),l("div",Oe,[e("div",Pe,[(n(!0),l($,null,Y(t(f),(a,S)=>(n(),l($,{key:S},[a.host?(n(),l($,{key:0},[a.host.imageURL?(n(),l("img",{key:0,class:"inline-block h-6 w-6 rounded-full ring-2 ring-white dark:ring-neutral-800",src:a.host.imageURL,alt:a.host.name},null,8,ze)):(n(),T(C,{key:1,class:"inline-block h-6 w-6 rounded-full ring-2 ring-gray-100 dark:ring-neutral-900"}))],64)):v("",!0)],64))),128))])])):v("",!0)])]),Fe,e("div",{ref_key:"conversationView",ref:E,class:"overflow-y-auto absolute top-[49px] bottom-[210px] sm:bottom-[215px]"},[e("div",Ge,[e("div",He,[e("h1",Je,[e("span",Ke,u(t(d).title?t(d).title:"Untitled Episode"),1)]),t(d).description?(n(),l("p",qe,u(t(d).description),1)):v("",!0)])]),Ye,e("div",Qe,[t(k).length>0?(n(),l("div",We,[(n(!0),l($,null,Y(t(k),(a,S)=>{var R,P;return n(),l("div",{key:S,class:"flex items-start my-6 first:mt-0 last:mb-0"},[e("div",Xe,[a.speaker&&t(f)[a.speaker.order].host&&((R=t(f)[a.speaker.order].host)!=null&&R.imageURL)?(n(),l("img",{key:0,class:"h-10 w-10 rounded-full",src:(P=t(f)[a.speaker.order].host)==null?void 0:P.imageURL,alt:""},null,8,Ze)):a.speaker?(n(),T(C,{key:2,class:"inline-block h-10 w-10 rounded-full"})):(n(),l("span",{key:1,onClick:s[0]||(s[0]=L=>K()),class:"inline-flex h-10 w-10 rounded-full items-center justify-center bg-gray-500 cursor-pointer"},[e("span",et,u(G(t(m))),1)])),a.speaker?(n(),l("span",tt,"AI")):v("",!0)]),e("div",st,[a.speaker?(n(),l("span",at,[p(u(H(t(f)[a.speaker.order].name?t(f)[a.speaker.order].name:"Speaker "+(o.paragraph.speaker+1))),1),i(t(Z),{class:"inline-block w-3 h-3 ml-1 -mt-1 text-indigo-600 dark:text-indigo-400"})])):(n(),l("span",nt,u(t(m)),1)),e("span",ot,u(se(a.timestamp)),1),e("div",lt,u(a.message),1),a.failed?(n(),l("div",it,[i(t(Le),{class:"self-center inline-block h-3 w-3 mr-0.5","aria-hidden":"true"}),rt])):v("",!0)])])}),128))])):v("",!0)])],512),e("div",dt,[e("div",ct,[e("span",ut,[e("span",{class:"inline-flex h-10 w-10 rounded-full items-center justify-center bg-gray-500 cursor-pointer",onClick:s[1]||(s[1]=a=>K())},[e("span",mt,u(G(t(m))),1)]),e("span",gt,[e("span",{class:j(["block h-2.5 w-2.5 rounded-full",{"bg-green-400":t(N),"bg-rose-400":!t(N)}])},null,2)])]),e("div",ht,[e("span",{onClick:s[2]||(s[2]=a=>oe()),class:j([t(y)?"bg-indigo-200 dark:bg-indigo-400":"bg-gray-100 dark:bg-neutral-100/10","inline-block items-center rounded-full px-1 py-1 text-xs font-medium"])},[t(y)?(n(),T(t(Me),{key:0,class:"text-indigo-600 dark:text-neutral-800 h-4 w-4","aria-hidden":"true"})):(n(),T(t($e),{key:1,class:"text-gray-600 dark:text-neutral-100/40 h-4 w-4","aria-hidden":"true"}))],2)])]),e("div",pt,[e("div",ft,[p(" You're chatting with "),i(t(Z),{class:"inline-block w-3 h-3 mr-1 -mt-1 text-indigo-600 dark:text-indigo-400"}),xt,e("span",_t,[p(" from "),e("span",vt,u(t(r).title),1)]),p(". ")]),e("div",yt,[e("div",bt,[kt,Q(e("textarea",{ref_key:"messageField",ref:F,"onUpdate:modelValue":s[3]||(s[3]=a=>X(_)?_.value=a:null),onKeydown:s[4]||(s[4]=ke(Ue(a=>J(),["prevent"]),["enter"])),rows:"3",name:"message-field",id:"message-field",class:"block w-full resize-none border-0 bg-transparent py-1.5 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-neutral-500 focus:ring-0 sm:text-sm sm:leading-6",placeholder:t(ae)},null,40,wt),[[W,t(_)]]),Ut]),e("div",Ct,[e("div",St,[e("button",{onClick:s[5]||(s[5]=a=>J()),disabled:!t(V),type:"button",class:j([t(V)?"hover:bg-indigo-500":"opacity-50 disabled","inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"])},[i(t(Ae),{class:"inline w-4 h-4"})],10,Lt)])]),t(ne)?(n(),l("div",Mt,At)):v("",!0)])])])]),i(t(Te),{as:"template",show:t(D)},{default:h(()=>[i(t(Ne),{as:"div",class:"relative z-10",onClose:s[9]||(s[9]=a=>O())},{default:h(()=>[i(t(ee),{as:"template",enter:"ease-out duration-300","enter-from":"opacity-0","enter-to":"opacity-100",leave:"ease-in duration-200","leave-from":"opacity-100","leave-to":"opacity-0"},{default:h(()=>[Nt]),_:1}),e("div",It,[e("div",Bt,[i(t(ee),{as:"template",enter:"ease-out duration-300","enter-from":"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95","enter-to":"opacity-100 translate-y-0 sm:scale-100",leave:"ease-in duration-200","leave-from":"opacity-100 translate-y-0 sm:scale-100","leave-to":"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"},{default:h(()=>[i(t(Ie),{class:"relative w-full transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg"},{default:h(()=>[e("div",Rt,[e("div",Tt,[e("div",jt,[i(t(Be),{class:"h-6 w-6 text-gray-600 dark:text-neutral-400","aria-hidden":"true"})]),e("div",Et,[i(t(Re),{as:"h3",class:"text-base font-semibold leading-6 text-gray-900 dark:text-white"},{default:h(()=>[p("Settings")]),_:1}),Vt,e("div",Dt,[e("div",Ot,[Pt,e("div",zt,[Q(e("input",{"onUpdate:modelValue":s[6]||(s[6]=a=>X(x)?x.value=a:null),type:"text",name:"new-host-name",id:"new-host-name",class:"block w-full rounded-md border-0 py-1.5 dark:bg-white/5 text-gray-900 dark:text-white shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-white/10 placeholder:text-gray-400 dark:placeholder:text-neutral-500 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6",placeholder:"John Smith"},null,512),[[W,t(x)]])])])])])])]),e("div",Ft,[i(B,{class:"w-full sm:w-auto",onClick:s[7]||(s[7]=a=>ie()),disabled:!t(le)},{default:h(()=>[p(" OK ")]),_:1},8,["disabled"]),e("button",{type:"button",class:j([t(q)?"hover:bg-gray-50 dark:hover:bg-neutral-700":"opacity-50 disabled","mt-3 inline-flex w-full justify-center rounded-md bg-white dark:bg-neutral-800 px-3 py-2 text-sm font-semibold text-gray-900 dark:text-white shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-neutral-700 sm:mt-0 sm:w-auto"]),onClick:s[8]||(s[8]=a=>O()),ref:"cancelButtonRef",disabled:!t(q)}," Cancel ",10,Gt)])]),_:1})]),_:1})])])]),_:1})]),_:1},8,["show"])],64)}}});export{es as default};
