!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="56b166ce-69b5-4ecf-88dc-bab994933c9c",e._sentryDebugIdIdentifier="sentry-dbid-56b166ce-69b5-4ecf-88dc-bab994933c9c")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8460],{23805:function(e,t,a){a.d(t,{J:function(){return b}});var r=a(85893),n=a(72010),c=a(23072),s=a(60848),l=a(11163),i=a(67294),o=a(85518),d=a(19293),u=a(58515),h=a(90893),f=a(49460),m=a(836),x=a(98155),p=a(81380);function v(e){let{open:t,onClose:a,contentClassName:n,shareUrl:c,characterAvatar:l,onLogCopyLink:o}=e,d=(0,f.nj)(t,200),{isCopied:u,copyToClipboard:v}=(0,p.m)({timeout:1e3});return(0,i.useEffect)(()=>{t?(0,x.lo)():(0,x.Tn)()},[t]),(0,r.jsx)(m.Vq,{open:t,children:(0,r.jsxs)(m.PK,{children:[(0,r.jsx)(m.t9,{}),(0,r.jsxs)(m.cZ,{showCloseButton:!1,className:(0,s.cn)("rounded-3xl sm:rounded-3xl bg-gradient-to-b from-[#7CD3FF] to-[#FFFFFF]",n),children:[d&&(0,r.jsxs)("div",{className:"flex-col-center gap-4 text-center w-full relative pt-12",children:[(0,r.jsx)("img",{src:l,className:"absolute -top-36 left-1/2 -translate-x-1/2 w-48 h-48"}),(0,r.jsx)("p",{className:"text-2xl font-semibold text-black",children:"Share this link so friends can try your character!"}),(0,r.jsxs)("div",{className:"flex-row-center max-w-full gap-2 text-lg font-semibold w-full text-left bg-white rounded-2xl px-4 py-2 border-4 border-[#E8E8E8]",children:[(0,r.jsx)("span",{className:"text-gray-500 flex-1 line-clamp-1 max-w-80 overflow-x-auto hide-scrollbar",children:c}),(0,r.jsx)("button",{className:"text-primary w-24 px-2 py-1",onClick:()=>{v(c),o()},children:u?"Copied!":"Copy link"})]})]}),(0,r.jsx)("button",{type:"button",className:"absolute -right-4 top-0 translate-x-full w-12 h-12 flex justify-center items-center rounded-full bg-black/30",onClick:a,children:(0,r.jsx)(h.bM,{className:"w-2/5 fill-white"})})]})]})})}var g=a(16913);function C(e){var t,a,n;let{userHook:c,character:s}=e,o=(0,l.useRouter)(),[d,u]=(0,i.useState)(!1),h={user_id:null==c?void 0:null===(t=c.user)||void 0===t?void 0:t._id,kid_id:null==c?void 0:null===(a=c.activeKid)||void 0===a?void 0:a._id,kid_name:null==c?void 0:null===(n=c.activeKid)||void 0===n?void 0:n.nickname,character_id:null==s?void 0:s._id,character_name:null==s?void 0:s.name};(0,i.useEffect)(()=>{g.Z.track("share_character_display",h)},[]);let f=(0,i.useMemo)(()=>o.isReady?"".concat(window.location.origin,"/share/chat/").concat(null==s?void 0:s._id):"",[o.isReady,s]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"w-full flex flex-row items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex flex-row-center gap-2",children:[(0,r.jsx)("span",{className:"text-xl font-semibold max-w-36 truncate",children:null==s?void 0:s.name}),(null==s?void 0:s.creator_detail)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("img",{src:(null==s?void 0:s.creator_detail.avatar)||(null==s?void 0:s.creator_detail.picture),alt:"",className:"w-6 h-6 rounded-full"}),(0,r.jsx)("span",{className:"text-sm opacity-90 max-w-28 truncate",children:null==s?void 0:s.creator_detail.nickname})]})]}),(0,r.jsx)("button",{className:"text-primary bg-white rounded-full px-2 py-1 font-semibold",onClick:()=>{u(!0),g.Z.track("share_character_click",h)},children:"Add friend"})]}),(0,r.jsx)(v,{characterAvatar:(null==s?void 0:s.avatar)||"",shareUrl:f,open:d,onClose:()=>u(!1),onLogCopyLink:()=>g.Z.track("share_character_copy_link",h)})]})}function b(e){var t,a,i;let{userHook:f,chatHook:m,homeHook:x}=e,p=(0,l.useRouter)();return(0,r.jsx)("div",{className:(0,s.cn)("w-full h-screen flex-center"),children:(0,r.jsx)("div",{className:"relative w-fit",children:(0,r.jsxs)("div",{className:(0,s.cn)("flex flex-row-center gap-10 relative","".concat(o.Dt?"gap-0":"")),children:[(0,r.jsx)(n.Z,{isTalking:m.isSpeaking,avatar:(null===(t=m.character)||void 0===t?void 0:t.avatar)||"",animateAvatar:null===(a=m.character)||void 0===a?void 0:a.animate_avatar,avatarVideo:null===(i=m.character)||void 0===i?void 0:i.avatar_video,className:"w-72 lg:w-96"},null==f?void 0:f.activeCharacterId),(0,r.jsx)("div",{className:"absolute -left-20 top-2/3 -translate-y-1/2 w-20 h-20 rounded-full bg-black/50 border-white mix-blend-overlay border-4 backdrop-blur-md flex-row-center cursor-pointer",onClick:()=>{m.stopActivities(),(0,s.CP)()?x.openModel(x.homeCharacterIndex,!0):p.push("/characters-list?from=home")},children:(0,r.jsx)(u.yI,{className:"w-10"})}),(0,r.jsxs)("div",{className:"flex flex-col ".concat(o.Dt?" pt-6 pr-6":""),children:[m.character&&(0,r.jsx)(C,{userHook:f,character:m.character}),(0,r.jsxs)(d.x,{bgClassName:"",className:"relative p-5 w-96 min-h-20 mt-2 mb-3 ".concat(o.Dt?"w-72":""," "),children:[m.isLoadingResponse?(0,r.jsx)("img",{src:"/animate/colorful-loading.svg",alt:"",className:"my-4 mx-auto w-48"}):(0,r.jsx)("div",{className:"text-lg text-black font-semibold whitespace-pre-wrap max-h-48 overflow-scroll hide-scrollbar",children:m.responseContent}),m.enableInput&&(0,r.jsx)("button",{className:"absolute w-8 h-8  bottom-2 ".concat(o.Dt?"right-6":"right-0"),onClick:m.continueChat,children:(0,r.jsx)(h.Ec,{className:"w-full fill-primary"})}),!m.enableInput&&!m.isLoadingResponse&&(0,r.jsx)("button",{className:"absolute w-8 h-8 right-0 bottom-2",onClick:m.stopActivities,children:(0,r.jsx)(h.ky,{className:"w-1/2 fill-red-500"})}),c.Z.enableTranslationButton&&(0,r.jsx)("div",{className:"absolute right-0 -bottom-3 translate-y-full",children:(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)("button",{type:"button",className:"active:opacity-80 disabled:opacity-40",onClick:m.toggleTranslations,disabled:!m.canReplay,children:(0,r.jsx)(h.Hg,{className:"w-10"})}),(0,r.jsx)("button",{type:"button",className:"active:opacity-80 disabled:opacity-40",onClick:m.replay,disabled:!m.canReplay,children:(0,r.jsx)(h.ys,{className:"w-10"})})]})})]}),(0,r.jsx)("div",{className:"inline-flex items-center mx-auto justify-center  ".concat(o.Dt?"w-32 h-32":"w-52 h-52 max-lg:w-32 max-lg:h-32"),children:m.isShowImage&&m.responseBrainImage.length>0&&(0,r.jsx)("img",{src:(0,s.sh)(m.responseBrainImage,400),className:"w-full h-full max-lg:rounded-xl rounded-3xl border-4 bg-[#DEEFFD] shadow-lg",alt:""})})]})]})})})}},19293:function(e,t,a){a.d(t,{x:function(){return c}});var r=a(85893),n=a(60848);function c(e){let{bgClassName:t,className:a,children:c}=e;return(0,r.jsxs)("div",{className:(0,n.cn)("relative w-full shadow-[inset_0_0_16px_0_white] backdrop-blur-[80px] rounded-2xl p-4 bg-white/40",t,a),children:[c,(0,r.jsx)("div",{className:(0,n.cn)("absolute w-10 h-10 -bottom-12 left-6 rounded-full shadow-[inset_0_0_12px_0_white] backdrop-blur-[80px] bg-white/40",t)}),(0,r.jsx)("div",{className:(0,n.cn)("absolute w-6 h-6 -bottom-16 left-0 rounded-full shadow-[inset_0_0_8px_0_white] backdrop-blur-[80px] bg-white/40",t)})]})}},86200:function(e,t,a){a.d(t,{e:function(){return s}});var r=a(85893),n=a(60848),c=a(90893);function s(e){let{className:t}=e;return(0,r.jsx)("div",{className:"fixed inset-0 w-screen h-screen flex-center",children:(0,r.jsx)(c.pA,{className:(0,n.cn)("animate-spin w-6 h-6 fill-white pointer-events-none",t)})})}},58515:function(e,t,a){a.d(t,{yI:function(){return B},ZP:function(){return q}});var r=a(85893),n=a(48846),c=a(83261),s=a(60848),l=a(1375),i=a(67294),o=a(15409),d=a(20303);let u=e=>{let{user:t,activeKid:a}=e,r=new Intl.Segmenter("en",{granularity:"sentence"}),u=(0,i.useRef)(new AbortController),h=(0,i.useRef)([]),f=(0,i.useRef)(null),m=(0,i.useRef)(-1),x=(0,i.useRef)(!1),[p,v]=(0,i.useState)(!1),[g,C]=(0,i.useState)(!1),{allowAutoPlay:b,audioPlayList:w,audioPlayIndex:j,isSpeaking:y,stop:_,setAudioPlayList:k,pushAudioPart:N}=(0,o.p)({canPlay:g}),[I,S]=(0,i.useState)(-1),[L,E]=(0,i.useState)(-1),[R,Z]=(0,i.useState)(!1),[T,D]=(0,i.useState)(!1),[A,H]=(0,i.useState)(""),[M,P]=(0,i.useState)(!1),{zhRegion:V}=(0,d.C)();(0,i.useEffect)(()=>(F(),O),[]),(0,i.useEffect)(()=>{g||_()},[g]);let F=async()=>{let e=(0,s.oT)(),a=await n.ZP.get("/api/v2/characters?kid_id=".concat(t.activeKidId||"","&vendor=").concat(e));if(a.data.length>0){let e=(0,s.zT)(),t=a.data.find(t=>t._id===e),r=a.data.filter(t=>t._id!==e);h.current=t?[t,...r]:r}v(!0)},K=async(e,t)=>{if(!f.current)return;let r=(0,s.kX)(t);if(r.length>0)try{N((0,c.Q)(f.current.voice_type.toUpperCase(),f.current.azure_voice_id,t,1,a.language)),k(t=>{let a=[...t];return a[e]={text:r,loaded:!0},a})}catch(e){}else k(t=>{let a=[...t];return a[e]={text:""},a})},O=()=>{Z(!1),D(!1);try{u.current.abort()}catch(e){}_()},B=e=>{if(m.current===e)return;O(),m.current=e,f.current=h.current[e],S((0,s.AR)(e));let a="",n=0;u.current=new AbortController,Z(!0),H(""),(0,l.L)("".concat("https://heeyo-backend-q3odvzjluq-uc.a.run.app","/chat/v1/HomeChat"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_id:t._id,active_kid_id:t.activeKidId||"",character_id:f.current._id,...V}),async onopen(e){D(!0),Z(!1)},onmessage(e){let t=JSON.parse(e.data);if(t.choices.length>0){if("assistant"===t.choices[0].delta.role){H((a+=t.choices[0].delta.content).replaceAll("\n\n","\n"));let e=Array.from(r.segment(a),e=>e.segment.trim()).filter(e=>e.length>0);e.length-n>1&&(K(n,e[n]),n+=1)}if("stop"===t.choices[0].finish_reason){let e=Array.from(r.segment(a),e=>e.segment.trim()).filter(e=>e.length>0);e.length==n+1&&K(n,e[n])}}},onclose(){},signal:u.current.signal}).catch(()=>{}).finally(()=>{Z(!1),D(!1)})};return{isLoadingResponse:R,isReceivingResponse:T,stop:_,allowAutoPlay:b,audioPlayList:w,audioPlayIndex:j,greetHtml:A,setIsLoadingResponse:Z,isSpeaking:y,showCharactersModelClose:x.current,isInit:p,openCharactersModel:g,setOpenCharactersModel:C,openModel:function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];x.current=t,C(!0),B(e)},characters:h.current,characterIndex:I,characterIndexRef:m,character:f.current,homeCharacterIndex:L,onSelectCharacter:B,setHomeCharacterIndex:E,isBeforeCreateDialogOpen:M,openBeforeCreateDialog:()=>{_(),P(!0)},closeBeforeCreateDialog:()=>{P(!1)},stopActivities:O}};var h=a(14640);a(41664);var f=a(11163),m=a(86200),x=a(72010),p=a(836),v=a(90893),g=a(22157),C=a(16913),b=a(33234),w=a(16014),j=a(96681);function y(e){let t=(0,j.h)(()=>(0,b.BX)(e)),{isStatic:a}=(0,i.useContext)(w._);if(a){let[,a]=(0,i.useState)(e);(0,i.useEffect)(()=>t.on("change",a),[])}return t}var _=a(40406),k=a(58868),N=a(80582),I=a(26166);function S(e){return"number"==typeof e?e:parseFloat(e)}var L=a(38138),E=a(78911),R=a(59820),Z=a(79262);function T(e){let{isOpen:t,onClose:a,user:c}=e,l=(0,h.useTranslations)(),{data:o}=(0,R.ZP)("/api/user/count?type=character&kid_id=".concat(c.activeKidId||""),n.ZP.get),[d,u]=i.useState(!1),{checkPoint:m,config:x}=(0,E.k)(),g=(0,f.useRouter)();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(p.Vq,{open:t,children:(0,r.jsxs)(p.cZ,{showCloseButton:!1,className:"max-w-3xl p-8 rounded-3xl sm:rounded-3xl backdrop-blur-2xl",children:[(0,r.jsxs)("div",{className:"relative flex flex-col items-center lg:justify-center",children:[(0,r.jsx)("h1",{className:"text-2xl font-bold",children:l("Character.createCharacter")}),(0,r.jsx)("div",{className:"mt-4",children:(0,r.jsx)("img",{src:(0,s.ak)("/character_shadow.png"),alt:"",className:"w-[200px] h-[200px] mix-blend-overlay"})}),(0,r.jsxs)("button",{className:"mt-10 flex-row-center gap-2 rounded-full py-3 px-8 text-xl font-semibold border border-white",onClick:()=>{1>(null==o?void 0:o.data)||m("create_character")?g.push("/create/character"):(a(),u(!0))},children:[(0,r.jsx)("span",{children:l("Operate.create")}),(0,r.jsx)("img",{src:(0,s.ak)("/icon-point.svg"),alt:"",className:"w-5 drag-none"})," ",1>(null==o?void 0:o.data)?l("Pricing.freeTrial"):x.create_character]})]}),(0,r.jsx)("div",{className:"absolute top-0 -right-16",children:(0,r.jsx)("button",{type:"button",className:"w-12 h-12 rounded-full bg-black/30 flex justify-center items-center",onClick:a,children:(0,r.jsx)(v.bM,{className:"w-5 h-5"})})})]})}),(0,r.jsx)(Z.Z,{user:c,open:d,onClose:()=>u(!1)})]})}var D=a(19293),A=a(25472);function H(e){var t,a,c,l;let{home:o,userHook:d,chatHook:u}=e;(0,f.useRouter)();let h=(0,i.useRef)(null),[m,b]=(0,i.useState)(!1),j=(0,i.useRef)(!1),E=function(e,t={}){let{isStatic:a}=(0,i.useContext)(w._),r=(0,i.useRef)(null),n=y((0,_.i)(e)?S(e.get()):e),c=(0,i.useRef)(n.get()),s=(0,i.useRef)(()=>{}),l=()=>{let e=r.current;e&&0===e.time&&e.sample(I.frameData.delta),o(),r.current=(0,N.y)({keyframes:[n.get(),c.current],velocity:n.getVelocity(),type:"spring",restDelta:.001,restSpeed:.01,...t,onUpdate:s.current})},o=()=>{r.current&&r.current.stop()};return(0,i.useInsertionEffect)(()=>n.attach((e,t)=>a?t(e):(c.current=e,s.current=t,I.Wi.update(l),n.get()),o),[JSON.stringify(t)]),(0,k.L)(()=>{if((0,_.i)(e))return e.on("change",e=>n.set(S(e)))},[n]),n}(y(0));(0,i.useEffect)(()=>{var e;open&&!(o.characterIndex<0)&&m&&E.set(((null===(e=h.current)||void 0===e?void 0:e.offsetTop)||0)-100*o.characterIndex-40)},[open,o.characterIndex,m]),(0,i.useEffect)(()=>{u.stopActivities()},[]);let R=(0,i.useMemo)(()=>{if(o.characterIndex<0)return"";let e=(0,s.Bs)(o.characterIndex);return Object.keys(g.Ef).includes(o.characters[e]._id)?g.Ef[o.characters[e]._id]:""},[o.characterIndex]);return o.characterIndex<0?(0,r.jsx)(r.Fragment,{}):(0,r.jsx)(p.Vq,{open:o.openCharactersModel,children:(0,r.jsxs)(p.t9,{className:"w-screen h-screen backdrop-blur-2xl",style:{background:R},children:[o.showCharactersModelClose&&(0,r.jsxs)("div",{className:"flex-row-center gap-2 fixed top-4 right-4",children:[(0,r.jsx)(A.Z,{user:d.user}),(0,r.jsx)("button",{className:" bg-black/40 w-14 h-14 flex-center rounded-full",onClick:()=>{o.stopActivities(),o.setOpenCharactersModel(!1)},children:(0,r.jsx)(v.bM,{className:"w-1/3"})})]}),(0,r.jsxs)("div",{className:"mx-auto container h-screen flex-row-center",children:[(0,r.jsxs)("div",{className:"relative mx-4 h-screen",children:[(0,r.jsx)(L.E.div,{className:"absolute left-0 top-1/2 -translate-y-1/2 w-[96px] h-[96px] ring-4 ring-white rounded-full",ref:h,style:{width:80,height:80},onViewportEnter:()=>b(!0),onViewportLeave:()=>b(!1)}),(0,r.jsxs)(L.E.div,{drag:"y",dragConstraints:h,onDragStart:()=>j.current=!0,onDragEnd:()=>{var e,t;j.current=!1;let a=Math.min(Math.max(0,Math.round((((null===(e=h.current)||void 0===e?void 0:e.offsetTop)||0)-E.get())/100)),o.characters.length);E.stop(),E.set(((null===(t=h.current)||void 0===t?void 0:t.offsetTop)||0)-100*a-40),a<o.characters.length?o.onSelectCharacter(a):o.openBeforeCreateDialog()},className:"space-y-[20px]",style:{y:E},children:[(0,r.jsx)(L.E.div,{className:"relative bg-black/50 rounded-full bg-cover bg-center p-3 cursor-pointer",onClick:()=>!j.current&&o.onSelectCharacter(0),style:{width:80,height:80},children:(0,r.jsx)("img",{src:(0,s.sh)(o.characters[0].avatar),alt:"",className:"w-full h-full drag-none"})}),(0,r.jsx)(L.E.div,{onClick:()=>{o.stopActivities(),o.openBeforeCreateDialog()},className:"bg-black/50 rounded-full flex items-center justify-center cursor-pointer",style:{width:80,height:80},children:(0,r.jsx)("span",{className:"text-6xl font-bold",children:"?"})}),o.characters.slice(1).map((e,t)=>(0,r.jsx)(L.E.div,{className:"relative bg-black/50 rounded-full bg-cover bg-center p-3 cursor-pointer",onClick:()=>!j.current&&o.onSelectCharacter(t+1),style:{width:80,height:80},children:(0,r.jsx)("img",{src:(0,s.sh)(e.avatar),alt:"",className:"w-full h-full drag-none"})},e._id))]}),(0,r.jsx)(T,{user:d.user,isOpen:o.isBeforeCreateDialogOpen,onClose:o.closeBeforeCreateDialog})]}),(0,r.jsxs)("div",{className:"flex flex-col relative items-center justify-center gap-12 w-96 max-lg:landscape:w-56 max-lg:landscape:gap-4",children:[(0,r.jsx)("p",{className:"font-semibold text-white text-3xl mx-auto",children:null===(t=o.character)||void 0===t?void 0:t.name}),(0,r.jsx)("div",{className:"w-full aspect-square rounded-2xl",children:(0,r.jsx)(x.Z,{isTalking:o.isSpeaking,avatar:(null===(a=o.character)||void 0===a?void 0:a.avatar)||"",animateAvatar:null===(c=o.character)||void 0===c?void 0:c.animate_avatar,avatarVideo:null===(l=o.character)||void 0===l?void 0:l.avatar_video})})]}),(0,r.jsxs)("div",{className:"flex flex-col relative justify-center items-center gap-36 max-lg:landscape:gap-8",children:[(0,r.jsx)(D.x,{bgClassName:"",className:"p-6 w-96 min-h-32 ",children:o.isLoadingResponse?(0,r.jsx)("img",{src:"/animate/colorful-loading.svg",alt:"",className:"w-48 absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2"}):(0,r.jsx)("div",{className:"text-lg font-semibold text-gray-800 whitespace-pre-wrap max-h-48 overflow-scroll hide-scrollbar",children:o.greetHtml})}),(0,r.jsx)("button",{className:"w-24 h-24 flex-center rounded-full bg-gradient-to-b bg-[#FFCC01] text-gray-800",style:{boxShadow:"0 4px 20px 0 rgb(0 0 0 / 0.15), inset 0 -8px 8px 0 rgb(0 0 0 / 0.3), inset 0 8px 8px 0 rgb(255 255 255 / 0.6)"},onClick:()=>{d.user.activeCharacterId,o.stopActivities(),o.setHomeCharacterIndex(o.characterIndexRef.current),n.ZP.post("/api/user",{activeCharacterId:o.character._id}),d.setUser({...d.user,activeCharacterId:o.character._id}),C.Z.track("select_character_submit",{character_id:o.character._id,character_name:o.character.name,kid_name:d.activeKid.nickname}),u.startChat(o.character._id),o.setOpenCharactersModel(!1)},children:(0,r.jsx)(v.NO,{className:"w-1/3"})})]})]})]})})}var M=a(49460),P=a(19967),V=a(23805),F=a(3512),K=a(86501),O=a(67288);let B=e=>(0,r.jsxs)("svg",{viewBox:"0 0 56 53",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[(0,r.jsx)("path",{d:"M11.6715 21.0226C12.505 18.6435 13.858 16.4063 15.763 14.4965C22.528 7.67565 33.4928 7.67565 40.2578 14.4965L42.1087 16.3736H38.396C36.4802 16.3736 34.9323 17.9342 34.9323 19.8658C34.9323 21.7975 36.4802 23.3581 38.396 23.3581H50.4648H50.5081C52.4239 23.3581 53.9718 21.7975 53.9718 19.8658V7.64291C53.9718 5.71125 52.4239 4.15065 50.5081 4.15065C48.5922 4.15065 47.0444 5.71125 47.0444 7.64291V11.4844L45.1502 9.56365C35.6792 0.0145085 20.3308 0.0145085 10.8597 9.56365C8.21868 12.2265 6.31365 15.3586 5.14466 18.709C4.50604 20.5315 5.45856 22.5177 7.25534 23.1616C9.05213 23.8055 11.0329 22.8451 11.6715 21.0335V21.0226ZM4.51687 30.4845C3.97567 30.6482 3.45611 30.9428 3.03398 31.3794C2.60102 31.8159 2.30877 32.3397 2.15723 32.9072C2.12476 33.0382 2.09229 33.18 2.07064 33.3219C2.03817 33.5074 2.02734 33.693 2.02734 33.8785V46.0578C2.02734 47.9894 3.57518 49.55 5.49103 49.55C7.40688 49.55 8.95471 47.9894 8.95471 46.0578V42.2272L10.8597 44.137C20.3308 53.6752 35.6792 53.6752 45.1394 44.137C47.7804 41.4742 49.6963 38.342 50.8653 34.9917C51.5039 33.1691 50.5514 31.1829 48.7546 30.539C46.9578 29.8951 44.977 30.8555 44.3384 32.6671C43.505 35.0462 42.152 37.2835 40.2469 39.1933C33.4819 46.0141 22.5172 46.0141 15.7522 39.1933L15.7414 39.1824L13.8905 37.3271H17.6139C19.5298 37.3271 21.0776 35.7665 21.0776 33.8348C21.0776 31.9032 19.5298 30.3426 17.6139 30.3426H5.53432C5.36114 30.3426 5.18796 30.3535 5.01477 30.3753C4.84159 30.3972 4.67923 30.4299 4.51687 30.4845Z",fill:"white"}),(0,r.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.80263 8.48438C19.8578 -1.66146 36.1532 -1.66146 46.2084 8.48438L46.2105 8.4865L46.3533 8.63139V7.2723C46.3533 4.72073 48.3979 2.6577 50.9266 2.6577C53.4554 2.6577 55.5 4.72073 55.5 7.2723V19.7317C55.5 22.2833 53.4554 24.3463 50.9266 24.3463H38.5896C36.0608 24.3463 34.0162 22.2833 34.0162 19.7317C34.0162 17.1802 36.0608 15.1171 38.5896 15.1171H39.8579L39.7467 15.0043C39.7463 15.0039 39.7459 15.0034 39.7455 15.003C33.2629 8.46342 22.7573 8.46385 16.2753 15.0043L16.2732 15.0064C14.4932 16.7923 13.2169 18.8756 12.414 21.0945V21.1039L12.3537 21.2753C11.5116 23.6658 8.89949 24.9384 6.52037 24.0852C4.15162 23.2357 2.89105 20.6124 3.73469 18.2018C4.97606 14.6416 6.99937 11.3129 9.80263 8.48438ZM44.7292 9.97516C35.4904 0.654029 20.5194 0.654321 11.281 9.97604C8.70417 12.5761 6.84673 15.6326 5.70666 18.9026L5.7062 18.9039C5.24935 20.2087 5.92918 21.6343 7.22053 22.0975C8.46058 22.5422 9.83354 21.9144 10.3365 20.6924L10.383 20.5596C11.2821 17.9914 12.7426 15.574 14.7982 13.5114C22.0972 6.14793 33.9266 6.14835 41.2251 13.5126L41.2272 13.5148L44.8845 17.2267H38.5896C37.2155 17.2267 36.1069 18.3452 36.1069 19.7317C36.1069 21.1182 37.2155 22.2368 38.5896 22.2368H50.9266C52.3008 22.2368 53.4093 21.1182 53.4093 19.7317V7.2723C53.4093 5.8858 52.3008 4.76723 50.9266 4.76723C49.5525 4.76723 48.444 5.8858 48.444 7.2723V13.7448L44.7301 9.97604C44.7298 9.97575 44.7295 9.97545 44.7292 9.97516ZM43.6574 32.4275C44.4994 30.037 47.1115 28.7644 49.4907 29.6176C51.8596 30.4672 53.1202 33.0908 52.2761 35.5016C51.0341 39.0633 48.9992 42.3913 46.1974 45.2184C36.1532 55.3532 19.8585 55.3527 9.80363 45.2194C9.80344 45.2192 9.80382 45.2196 9.80363 45.2194L9.64673 45.062V46.4305C9.64673 48.9821 7.60213 51.0451 5.07336 51.0451C2.5446 51.0451 0.5 48.9821 0.5 46.4305V34.0156C0.5 33.7895 0.512849 33.5397 0.558003 33.2765C0.58732 33.0878 0.62862 32.9105 0.663512 32.7697L0.665796 32.7604L0.668244 32.7513C0.868614 32.0003 1.25618 31.3043 1.82694 30.7268C2.3881 30.1479 3.06934 29.7634 3.76616 29.55C4.0074 29.4702 4.23803 29.4258 4.4586 29.398C4.67768 29.3703 4.89739 29.3565 5.11746 29.3565H17.4214C19.9502 29.3565 21.9948 31.4195 21.9948 33.9711C21.9948 36.5226 19.9502 38.5857 17.4214 38.5857H16.163L16.2533 38.6762L16.2643 38.6874C22.7467 45.2282 33.2533 45.2282 39.7357 38.6874L39.7378 38.6852C41.5626 36.8545 42.858 34.7111 43.6567 32.4295L43.6574 32.4275ZM45.6276 33.1331C44.7286 35.7008 43.2684 38.1175 41.2134 40.1797C33.9144 47.5437 22.0846 47.5435 14.786 40.179L14.7771 40.1701L14.7749 40.1679L11.0946 36.4761H17.4214C18.7956 36.4761 19.9041 35.3576 19.9041 33.9711C19.9041 32.5846 18.7956 31.466 17.4214 31.466H5.11746C4.98474 31.466 4.85164 31.4744 4.71792 31.4912C4.59045 31.5073 4.49551 31.5283 4.41167 31.5565L4.39665 31.5615L4.38148 31.5661C3.98282 31.6868 3.61313 31.9001 3.31914 32.2044L3.3099 32.2139C3.00335 32.5233 2.79778 32.8904 2.68936 33.2911C2.65995 33.4103 2.63693 33.5148 2.62262 33.6086L2.62087 33.6201L2.61887 33.6315C2.5995 33.7423 2.59068 33.8667 2.59068 34.0156V46.4305C2.59068 47.817 3.69925 48.9356 5.07336 48.9356C6.44748 48.9356 7.55605 47.817 7.55605 46.4305V39.9896L11.2805 43.7263C20.5196 53.038 35.4916 53.0374 44.719 43.7267C47.2971 41.1254 49.1649 38.0684 50.3044 34.8002L50.3048 34.7989C50.7617 33.4941 50.0819 32.0684 48.7905 31.6053C47.5096 31.146 46.0868 31.8309 45.6276 33.1331Z",fill:"white"})]});function q(e){let{userHook:t}=e;(0,h.useTranslations)();let a=(0,f.useRouter)(),n=u({user:t.user,activeKid:t.activeKid});(0,i.useEffect)(()=>{if(n.isInit&&((0,s.CP)()||"init"===d)){if(t.user.activeCharacterId&&(0,s.CP)()){if(n.characters.map(e=>e._id).includes(t.user.activeCharacterId)){for(let e=0;e<n.characters.length;e++)if(n.characters[e]._id===t.user.activeCharacterId){n.setHomeCharacterIndex(e);break}}else n.openModel(0,!1)}else(0,s.CP)()?n.openModel(0,!1):(K.ZP.success("Let's choose fun characters!"),a.push("/characters-list?from=init"))}},[n.isInit]);let{isDarkMode:c}=(0,M.vs)(),l=(0,i.useRef)(Date.now().toString()),o=(0,P.R)({user:t.user,activeKid:t.activeKid,isDarkMode:c}),{from:d}=a.query||{};return((0,i.useEffect)(()=>{var e,r;if(!n.isInit||!o.isInit)return;a.query.character_id&&(o.startChat(a.query.character_id),a.push("/",void 0,{shallow:!0}));let c=t.activeKid._id,s=t.activeKid.nickname;C.Z.track("start_chat_with_character",{kid_id:c,kid_name:s,character_id:null===(e=o.character)||void 0===e?void 0:e._id,character_name:null===(r=o.character)||void 0===r?void 0:r.name});let i=()=>{var e,t;let a=parseInt(l.current||"0"),r=Date.now();C.Z.track("end_chat_with_character",{kid_id:c,kid_name:s,character_id:null===(e=o.character)||void 0===e?void 0:e._id,character_name:null===(t=o.character)||void 0===t?void 0:t.name,duration:Math.round((r-a)/1e3),chat_rounds:o.rounds.current})};return window.addEventListener("beforeunload",i),()=>{i(),window.removeEventListener("beforeunload",i)}},[o.isInit,n.isInit]),o.isInit&&n.isInit&&(t.user.activeCharacterId||(0,s.CP)()))?(0,r.jsxs)(r.Fragment,{children:[((0,s.CP)()||"init"===d)&&n.homeCharacterIndex<0&&(0,r.jsx)(m.e,{}),(!(0,s.CP)()&&"init"!==d||n.homeCharacterIndex>=0)&&(0,r.jsx)(r.Fragment,{children:!o.openTravelDialog&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(V.J,{chatHook:o,homeHook:n,userHook:t}),(0,r.jsx)("div",{className:"fixed w-full bottom-20 right-10 lg:bottom-28 pointer-events-none",children:(0,r.jsx)("div",{className:"w-full mx-auto",children:(0,r.jsx)(F.x,{enableInput:o.enableInput,sendText:o.sendText,isPaused:o.isPaused})})})]})}),(0,r.jsx)(H,{home:n,userHook:t,chatHook:o})]}):(0,r.jsx)("div",{className:"w-screen h-screen flex-center fixed inset-0 z-50",children:(0,r.jsx)(O.nI,{src:"/animate/loading-rocket.lottie",loop:!0,autoplay:!0,className:"w-64 h-64"})})}},39574:function(e,t,a){a.d(t,{Z:function(){return l}});var r=a(85893),n=a(60848),c=a(38138),s=a(49460);function l(){return(0,s.ac)("(orientation: landscape)")?(0,r.jsx)(r.Fragment,{}):(0,r.jsx)("div",{className:"landscape fixed inset-0 flex-center bg-black z-50",children:(0,r.jsxs)("div",{className:"flex-col-center gap-6",children:[(0,r.jsx)(c.E.div,{className:"text-5xl font-semibold",animate:{scale:[1,.8,1,.8,1]},transition:{duration:2,repeat:1/0,type:"tween"},children:"Rotate Screen"}),(0,r.jsx)(c.E.img,{src:(0,n.ak)("/rotate-screen.png"),className:"w-56",alt:"",animate:{rotate:[0,90,90]},transition:{duration:2.5,times:[0,.75,.75,1],repeat:1/0,type:"tween"}})]})})}},19967:function(e,t,a){a.d(t,{R:function(){return x}});var r=a(22157),n=a(83261),c=a(60848),s=a(1375),l=a(87066),i=a(25675),o=a(11163),d=a(67294),u=a(49460),h=a(15409),f=a(20303),m=a(16371);let x=e=>{let{user:t,activeKid:a,isDarkMode:x}=e,p=new Intl.Segmenter("en",{granularity:"sentence"}),[v,g]=(0,d.useState)(!1),C=(0,d.useRef)(v),b=(0,d.useRef)(0),w=(0,d.useRef)(),j=(0,d.useRef)(new AbortController),y=(0,d.useRef)(new AbortController),_=(0,i._)(),[k,N]=(0,d.useState)(!1),[I,S]=(0,d.useState)(""),[L,E]=(0,d.useState)(!1),[R,Z]=(0,d.useState)(!1),[T,D]=(0,d.useState)(""),[A,H]=(0,d.useState)(!1),[M,P]=(0,d.useState)(""),[V,F]=(0,d.useState)(!1),[K,O]=(0,d.useState)([]),[B,q]=(0,d.useState)([]),{allowAutoPlay:z,audioPlayList:J,audioPlayIndex:U,isSpeaking:X,stop:Q,setAudioPlayList:G,pushAudioPart:W,replay:Y,canReplay:$,clearSounds:ee,setSounds:et,getSounds:ea}=(0,h.p)({}),[er,en,ec]=(0,u._)(r.dR.ChatPreInteraction,null),[es]=(0,u._)(r.dR.SysLanguage,"en"),{zhRegion:el}=(0,f.C)(),ei=(0,o.useRouter)(),{toggleTranslations:eo,clearTranslations:ed}=(0,m.C)({character:w.current,activeKid:a,clearSounds:ee,setSentenceList:O,setAudioPlayList:G,setSounds:et,replay:Y,pushAudioPart:W,getSounds:ea,setIsLoadingResponse:E});(0,d.useEffect)(()=>{ei.isReady&&l.Z.get("/api/character?character_id=".concat(t.activeCharacterId,"&kid_id=").concat(t.activeKidId,"&chat=1&creator=1")).then(e=>{let{status:t,data:a}=e;200===t&&(w.current=a.data)}).catch(console.error).finally(()=>N(!0))},[ei.isReady]),(0,d.useEffect)(()=>{if(k)return er?(ex("",{pre_interaction:er}),ec()):ex(""),ep},[k]),(0,d.useEffect)(()=>{K.length>U&&D(K[U])},[K,U]),(0,d.useEffect)(()=>{C.current=v},[v]);let eu=async(e,t)=>{let r=(0,c.kX)(t);if(r.length>0)try{if(!C.current){var s,l;W((0,n.Q)(null===(s=w.current)||void 0===s?void 0:s.voice_type.toUpperCase(),(null===(l=w.current)||void 0===l?void 0:l.azure_voice_id)||"",t,1,a.language)),G(t=>{let a=[...t];return a[e]={text:r,loaded:!0},a})}}catch(e){}else C.current||G(t=>{let a=[...t];return a[e]={text:""},a})},eh=()=>{ex("Continue.")},ef=()=>{ep(),S(""),D(""),O([]),H(!1),P(""),q([]),ed(),G([])},em=e=>{y.current=new AbortController,l.Z.get("".concat("https://heeyo-backend-q3odvzjluq-uc.a.run.app","/image/v1/GenerateImage?api_type=replicate&prompt=").concat(encodeURIComponent(e)),{timeout:5e3,signal:y.current.signal}).then(e=>{200===e.status&&200===e.data.code&&(H(!0),P(e.data.data))}).catch(()=>{})},ex=(e,a)=>{var r;g(!1),Q(),O([]),S(e),E(!0),H(!1),P(""),D(""),q([]),ed();let n="",c=0;j.current=new AbortController,(0,s.L)("".concat("https://heeyo-backend-q3odvzjluq-uc.a.run.app","/chat/v1/ChatInHome"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_id:t._id,active_kid_id:t.activeKidId||"",character_id:null===(r=w.current)||void 0===r?void 0:r._id,user_message:e,is_bedtime:x,...a}),async onopen(e){Z(!0),E(!1)},onmessage(e){let t=JSON.parse(e.data);if(t.choices.length>0){if("gen_image_prompt"===t.choices[0].delta.role&&em(t.choices[0].delta.content),"recommend_place"===t.choices[0].delta.role&&eg(JSON.parse(t.choices[0].delta.content)),"shake_button"===t.choices[0].delta.role&&_.start({scale:[1,.75,1.25,.75,1.25,.75,1.25,.75,1.25,.75,1],transition:{duration:5}}),"assistant"===t.choices[0].delta.role){n+=t.choices[0].delta.content;let e=Array.from(p.segment(n),e=>e.segment.trim()).filter(e=>e.length>0);O(e),e.length-c>1&&(eu(c,e[c]),c+=1)}if("stop"===t.choices[0].finish_reason){let e=Array.from(p.segment(n),e=>e.segment.trim()).filter(e=>e.length>0);O(e),e.length==c+1&&eu(c,e[c])}}},onclose(){},signal:j.current.signal}).catch(()=>{}).finally(()=>{E(!1),Z(!1)})},ep=()=>{E(!1),Z(!1);try{j.current.abort(),y.current.abort()}catch(e){}Q(),g(!0),O([])},ev=(0,d.useMemo)(()=>!!z&&(!!v||!L&&!R&&K.length>0&&K.length<=U),[L,R,z,U,K,v]),eg=e=>{q(e),F(!0)};return{requestText:I,isLoadingResponse:L,isReceivingResponse:R,responseContent:T,sendText:ex,continueChat:eh,rounds:b,responseBrainImage:M,isShowImage:A,stopActivities:ep,allowAutoPlay:z,audioPlayList:J,audioPlayIndex:U,enableInput:ev,setIsShowImage:H,setIsLoadingResponse:E,setResponseBrainImage:P,houses:B,isSpeaking:X,onCloseTravelDialog:()=>{ep(),F(!1),eh()},onTravel:()=>{ep(),ex("",{pre_interaction:{type:"click_play",content:""}}),F(!0)},openTravelDialog:V,setOpenTravelDialog:F,character:w.current,isInit:k,playAnimation:_,replay:Y,canReplay:$,toggleTranslations:()=>eo(K,J),isPaused:v,startChat:e=>{ef(),l.Z.get("/api/character?character_id=".concat(e,"&kid_id=").concat(t.activeKidId,"&chat=1&creator=1")).then(e=>{let{status:t,data:a}=e;200===t&&(w.current=a.data,ex("",{new_chat:!0}))}).catch(console.error)}}}},81380:function(e,t,a){a.d(t,{m:function(){return n}});var r=a(67294);function n(e){let{timeout:t=2e3}=e,[a,n]=r.useState(!1);return{isCopied:a,copyToClipboard:e=>{var a;(null===(a=navigator.clipboard)||void 0===a?void 0:a.writeText)&&e&&navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>{n(!1)},t)})}}}},78911:function(e,t,a){a.d(t,{k:function(){return l}});var r=a(48846),n=a(67294),c=a(59820),s=a(86510);function l(){let{user:e}=(0,s.a)(),{data:t={data:{}}}=(0,c.ZP)("/api/creation/config",r.ZP.get);return{checkPoint:(0,n.useCallback)(a=>e&&t&&(e.point||0)>=t.data[a],[e,t]),config:t.data}}},25675:function(e,t,a){a.d(t,{_:function(){return d}});var r=a(45487),n=a(66803),c=a(76432);function s(e,t){[...t].reverse().forEach(a=>{let r=e.getVariant(a);r&&(0,n.C)(e,r),e.variantChildren&&e.variantChildren.forEach(e=>{s(e,t)})})}function l(){let e=!1,t=new Set,a={subscribe:e=>(t.add(e),()=>void t.delete(e)),start(a,n){(0,r.k)(e,"controls.start() should only be called after a component has mounted. Consider calling within a useEffect hook.");let s=[];return t.forEach(e=>{s.push((0,c.d)(e,a,{transitionOverride:n}))}),Promise.all(s)},set:a=>((0,r.k)(e,"controls.set() should only be called after a component has mounted. Consider calling within a useEffect hook."),t.forEach(e=>{Array.isArray(a)?s(e,a):"string"==typeof a?s(e,[a]):(0,n.C)(e,a)})),stop(){t.forEach(e=>{!function(e){e.values.forEach(e=>e.stop())}(e)})},mount:()=>(e=!0,()=>{e=!1,a.stop()})};return a}var i=a(96681),o=a(58868);let d=function(){let e=(0,i.h)(l);return(0,o.L)(e.mount,[]),e}}}]);