@opencx/widget-react 4.0.16 → 4.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -9
- package/dist-embed/script.js +0 -361
- package/dist-embed/script.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
${u.screens.welcome.width},
|
|
15
15
|
${u.screens.sessions.width},
|
|
16
16
|
${u.screens.chat.width}
|
|
17
|
-
)`)};return{theme:u,computed:y,cssVars:$t({palette:u.palette,primary:u.primaryColor})}}function $t({palette:t,primary:o}){const s=pt(t),r=Ye(o).toHsl(),n=Ye(o).isLight()?s[950]:s[50];return{"--opencx-primary":`${r.h} ${r.s*100}% ${r.l*100}%`,"--opencx-primary-foreground":n,"--opencx-background":s[100],"--opencx-foreground":s[950],"--opencx-destructive":"0 72.2% 50.6%","--opencx-destructive-foreground":s[50],"--opencx-accent":s[200],"--opencx-accent-foreground":"var(--opencx-foreground)","--opencx-secondary":s[200],"--opencx-secondary-foreground":"var(--opencx-foreground)","--opencx-muted":s[200],"--opencx-muted-foreground":s[500],"--opencx-input":s[300],"--opencx-border":s[300],"--opencx-ring":"var(--opencx-foreground)"}}function pt(t){const o={50:"0 0% 98%",100:"0 0% 96.1%",200:"0 0% 89.8%",300:"0 0% 83.1%",400:"0 0% 63.9%",500:"0 0% 45.1%",600:"0 0% 32.2%",700:"0 0% 25.1%",800:"0 0% 14.9%",900:"0 0% 9%",950:"0 0% 3.9%"},s={50:"60 9.1% 97.8%",100:"60 4.8% 95.9%",200:"20 5.9% 90%",300:"24 5.7% 82.9%",400:"24 5.4% 63.9%",500:"25 5.3% 44.7%",600:"33.3 5.5% 32.4%",700:"30 6.3% 25.1%",800:"12 6.5% 15.1%",900:"24 9.8% 10%",950:"20 14.3% 4.1%"},r={50:"0 0% 98%",100:"240 4.8% 95.9%",200:"240 5.9% 90%",300:"240 4.9% 83.9%",400:"240 5% 64.9%",500:"240 3.8% 46.1%",600:"240 5.2% 33.9%",700:"240 5.3% 26.1%",800:"240 3.7% 15.9%",900:"240 5.9% 10%",950:"240 10% 3.9%"},n={50:"210 40% 98%",100:"210 40% 96.1%",200:"214.3 31.8% 91.4%",300:"212.7 26.8% 83.9%",400:"215 20.2% 65.1%",500:"215.4 16.3% 46.9%",600:"215.3 19.3% 34.5%",700:"215.3 25% 26.7%",800:"217.2 32.6% 17.5%",900:"222.2 47.4% 11.2%",950:"222.2 84% 4.9%"};switch(t){case"neutral":return o;case"stone":return s;case"zinc":return r;case"slate":return n;default:return M.isExhaustive(t,pt.name),o}}function ht(){const{contentIframeRef:t}=l.useWidget(),{inline:o}=l.useConfig();return{setWidth:s=>{var r;(r=t==null?void 0:t.current)==null||r.style.setProperty("--opencx-widget-width",o?"100%":s)},setHeight:s=>{var r;(r=t==null?void 0:t.current)==null||r.style.setProperty("--opencx-widget-height",o?"100%":s)}}}function de({width:t,height:o}){const{isSmallScreen:s}=E(),{setWidth:r,setHeight:n}=ht();h.useEffect(()=>{t&&r(t),o&&n(o)},[s,o,t,r,n])}const Xe=m.CircleDashedIcon;function U({name:t,className:o}){const s=(()=>{switch(t){case"Check":return m.CheckIcon;case"CheckCheck":return m.CheckCheckIcon;case"CircleCheck":return m.CircleCheckIcon;case"CircleCheckBig":return m.CircleCheckBigIcon;case"CircleX":return m.CircleXIcon;case"Expand":return m.ExpandIcon;case"Maximize":return m.MaximizeIcon;case"Maximize2":return m.Maximize2Icon;case"Minimize":return m.MinimizeIcon;case"Minimize2":return m.Minimize2Icon;case"Shrink":return m.ShrinkIcon;case"SquareCheck":return m.SquareCheckIcon;case"SquareCheckBig":return m.SquareCheckBigIcon;case"SquareX":return m.SquareXIcon;case"X":return m.XIcon;case void 0:return Xe;default:return M.isExhaustive(t,U.name),Xe}})();return e.jsx(s,{className:p("size-4",o)})}function pe(){const{widgetCtx:{org:t}}=l.useWidget(),{routerState:{screen:o}}=l.useWidgetRouter(),{textContent:s}=l.useConfig();return(()=>{var n,a;switch(o){case"chat":return(n=s==null?void 0:s.chatScreen)==null?void 0:n.headerTitle;case"sessions":return(a=s==null?void 0:s.sessionsScreen)==null?void 0:a.headerTitle;case"welcome":return;default:M.isExhaustive(o,pe.name);return}})()??t.name??"Chat"}function Xt(t){switch(t){case"chat":return w("chat/header");case"sessions":return w("sessions/header");case"welcome":return;default:M.isExhaustive(t,pe.name);return}}function Ut(){const{router:t}=l.useConfig(),{routerState:{screen:o},toSessionsScreen:s}=l.useWidgetRouter();return o!=="chat"||t!=null&&t.chatScreenOnly?null:e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:s,children:e.jsx(m.ChevronLeftIcon,{className:"size-4 rtl:-scale-100"})})}function Vt({button:t}){const{setIsOpen:o}=l.useWidgetTrigger(),{isSmallScreen:s}=E();if(s&&t.hideOnSmallScreen||!s&&t.hideOnLargeScreen)return null;const r=()=>{if(t.handleClick)return t.handleClick();o(!1)};return e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:r,children:e.jsx(U,{name:t.icon})})}function ne({button:t}){const[o,s]=h.useState(!1),{routerState:{screen:r}}=l.useWidgetRouter(),{isSmallScreen:n}=E(),{theme:a}=q(),{setWidth:i,setHeight:d}=ht();if(r!=="chat"&&r!=="sessions")return null;const c=(()=>{switch(r){case"chat":return a.screens.chat.height;case"sessions":return a.screens.sessions.height;default:return M.isExhaustive(r,ne.name),a.screens.chat.height}})(),u=(()=>{switch(r){case"chat":return a.screens.chat.width;case"sessions":return a.screens.sessions.width;default:return M.isExhaustive(r,ne.name),a.screens.chat.width}})(),y=()=>{s(x=>{const g=!x;return d(g?"100vh":c),i(g?`max(40vw, ${u})`:u),g})};return n&&t.hideOnSmallScreen||!n&&t.hideOnLargeScreen?null:e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:y,children:e.jsx(U,{name:t.icon||(o?t.shrinkIcon:t.expandIcon)})})}function mt({button:t}){var N,I;const{close:o}=ee(),{widgetCtx:s}=l.useWidget(),{setIsOpen:r}=l.useWidgetTrigger(),{resolveSession:n,sessionState:a}=l.useSessions(),{isSmallScreen:i}=E(),d=!a.session,c=((N=a.session)==null?void 0:N.isOpened)===!1,u=t.onResolved||"stay-in-chat",y=t.behaviorBeforeSessionCreation||"disabled",x=t.behaviorIfSessionIsResolved||"disabled",g=!!(a.isResolvingSession||d&&y==="disabled"||c&&x==="disabled"),C=async()=>{const{success:_,error:T}=await n();if(o(),!_)return console.error(T);switch(u){case"stay-in-chat":return;case"close-widget":r(!1);break;case"reset-chat":s.resetChat();break;case"reset-chat-and-close-widget":r(!1),s.resetChat();break;default:M.isExhaustive(u,mt.name);break}},v=()=>{if(d)switch(y){case"disabled":return;case"close-widget":r(!1);break;default:M.isExhaustive(y,v.name)}if(c)switch(x){case"disabled":return;case"close-widget":r(!1);break;case"reset-chat":s.resetChat();break;case"reset-chat-and-close-widget":r(!1),setTimeout(()=>{s.resetChat()},200);break;default:M.isExhaustive(x,v.name)}};return i&&t.hideOnSmallScreen||!i&&t.hideOnLargeScreen?null:((I=t.confirmation)==null?void 0:I.type)==="modal"&&!c&&!d?e.jsx(nt,{trigger:e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",disabled:g,children:e.jsx(U,{name:t.icon})}),children:e.jsxs(Je,{children:[e.jsx(et,{children:e.jsx(ot,{children:t.confirmation.title||"Close conversation"})}),e.jsx(tt,{children:e.jsx(rt,{children:t.confirmation.description||"Are you sure you want to close this conversation?"})}),e.jsxs(st,{children:[e.jsx(k,{variant:"secondary",onClick:o,disabled:a.isResolvingSession,children:t.confirmation.cancelButtonText||"No"}),e.jsx(k,{variant:"destructive",onClick:C,disabled:a.isResolvingSession,children:t.confirmation.confirmButtonText||"Yes"})]})]})}):e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:c||d?v:C,disabled:g,children:e.jsx(U,{name:t.icon})})}function ie({button:t}){switch(t.functionality){case"close-widget":return e.jsx(Vt,{button:t});case"expand-shrink":return e.jsx(ne,{button:t});case"resolve-session":return e.jsx(mt,{button:t});default:return M.isExhaustive(t,ie.name),null}}const Gt={functionality:"close-widget",hideOnLargeScreen:!0,icon:"X"};function Kt(){const{routerState:{screen:t}}=l.useWidgetRouter(),{headerButtons:o}=l.useConfig(),s=t==="chat"?o==null?void 0:o.chatScreen:t==="sessions"?o==null?void 0:o.sessionsScreen:[];return!s||s.length===0?e.jsx(ie,{button:Gt}):e.jsx(e.Fragment,{children:s.map(r=>e.jsx(ie,{button:r},`${r.functionality}-${r.icon}`))})}function ut(){const{routerState:{screen:t}}=l.useWidgetRouter(),o=Xt(t),s=pe();return e.jsx("header",{...o,className:"py-2 px-4 shrink-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{}),e.jsx("div",{className:p("flex-1 h-8 flex items-center",t==="sessions"&&"ps-2"),children:e.jsx("h2",{className:"font-semibold",children:s})}),e.jsx(Kt,{})]})})}function gt({className:t}){return e.jsx(m.LoaderIcon,{className:p("size-4 animate-spin",t)})}function Zt(){const{messagesState:{isInitialFetchLoading:t}}=l.useMessages(),{isSmallScreen:o}=E(),{activeMode:s,Component:r}=l.useModes();return{isCanvasOpen:!t&&!o&&!!s&&!!r}}function Qt(){const{activeMode:t,Component:o}=l.useModes(),{sendMessage:s}=l.useMessages(),{createStateCheckpoint:r}=l.useSessions(),[n,a]=h.useState(!1),i=async d=>{try{a(!0),await s(d)}catch(c){console.error(c)}finally{a(!1)}};return!t||!o?null:e.jsx(o,{react:h,mode:t,createStateCheckpoint:r,sendMessage:i,isSendingMessage:n})}const O=h.forwardRef((t,o)=>{var s,r,n;return e.jsx(f,{...t,ref:o,className:p("overflow-hidden",t.className),overrides:{initial:{height:0,opacity:0,...(s=t.overrides)==null?void 0:s.initial},animate:{height:"auto",opacity:1,...(r=t.overrides)==null?void 0:r.animate},exit:{height:0,opacity:0,...(n=t.overrides)==null?void 0:n.exit}}})});O.displayName="MotionDiv__VerticalReveal";const Jt=[{label:"Terrible",value:1,emoji:"😡"},{label:"Poor",value:2,emoji:"😞"},{label:"Okay",value:3,emoji:"😐"},{label:"Good",value:4,emoji:"😊"},{label:"Great",value:5,emoji:"😍"}];function es(){const{isSmallScreen:t}=E(),{submitCsat:o,isCsatRequested:s,isCsatSubmitted:r,submittedScore:n,submittedFeedback:a}=l.useCsat(),[i,d]=h.useState(null),[c,u]=h.useState(null),y=g=>{d(C=>C===g?null:g)},x=()=>{i&&o({score:i,feedback:c||void 0})};return!s&&!r?null:e.jsxs("div",{className:"w-1/2 min-w-80 max-w-96 mx-auto overflow-hidden",children:[e.jsx(j.AnimatePresence,{mode:"wait",children:s&&!i?e.jsx(O,{children:e.jsx("p",{className:"text-sm text-muted-foreground text-center pt-2",children:"How was your conversation?"})},"csat-requested-title"):r?e.jsx(O,{children:e.jsx("p",{className:"text-sm text-muted-foreground text-center pt-2",children:"You rated the conversation as"})},"csat-submitted-title"):null}),e.jsx("div",{className:p("flex gap-4 justify-between pt-2 px-2 pb-2","transition-all",r&&"gap-0 justify-center"),children:Jt.map(g=>e.jsx(k,{variant:g.value===i?"secondary":"ghost",size:"selfless",className:p("transition-all overflow-hidden","text-2xl size-8 rounded-full","opacity-35","hover:opacity-100",!i&&"opacity-100",g.value===i&&"opacity-100",r&&g.value!==n&&"opacity-0 size-0",r&&g.value===n&&"opacity-100 size-fit text-4xl"),onClick:s?()=>y(g.value):void 0,children:g.emoji},g.value))}),e.jsx(j.AnimatePresence,{mode:"wait",children:(i||n)&&e.jsx(O,{children:e.jsxs("div",{className:"pb-2 px-2 flex items-end",children:[e.jsx("textarea",{rows:3,className:p("transition-all","max-h-40 [field-sizing:content]","w-full resize-none","bg-transparent outline-none","placeholder:text-muted-foreground",t?"text-[16px]":"text-sm",r&&"text-center"),value:r?a||"":c||"",onChange:s?g=>u(g.target.value):void 0,readOnly:r,placeholder:s?"Tell us more... (optional)":void 0}),e.jsx(k,{size:"fit",onClick:x,disabled:!i,className:p("transition-all overflow-hidden","rounded-full size-8 flex items-center justify-center p-0",r&&"opacity-0 size-0"),children:e.jsx(m.ArrowUpIcon,{className:"size-4"})})]})},"feedback-box")}),e.jsx("div",{className:p("h-0 transition-[height]",r&&"h-4")})]})}const ts={"write-a-message":"اكتب رسالة...","session-closed-lead":"تم حل مشكلتك!","new-conversation":"محادثة جديدة","welcome-title":"مرحبًا بك في دردشة الدعم الخاصة بنا","welcome-description":"نحن هنا للمساعدة! ابدأ محادثة وسنرد عليك في أقرب وقت ممكن.","your-name":"اسمك","your-email":"عنوان بريدك الإلكتروني","start-chat":"تحدث إلى الدعم","starting-chat":"جاري الاتصال...","i-need-more-help":"أحتاج المزيد من المساعدة","this-was-helpful":"كان هذا مفيدًا",optional:"اختياري","no-conversations-yet":"لا يوجد محادثات","back-to-conversations":"العودة إلى المحادثات","closed-conversations":"المحادثات المغلقة"},ss={"write-a-message":"Nachricht schreiben...","session-closed-lead":"Ihr Problem wurde gelöst!","new-conversation":"Neue Konversation","welcome-title":"Willkommen in unserem Support-Chat","welcome-description":"Wir sind hier, um zu helfen! Beginnen Sie ein Gesprách und wir werden so schnell wie mogelijk antworten.","your-name":"Ihr Name","your-email":"Ihre E-Mail-Adresse","start-chat":"Mit dem Support sprechen","starting-chat":"Verbindung wird hergestellt...","i-need-more-help":"Ich brauche weitere Hilfe","this-was-helpful":"Dies war hilfreich",optional:"Optional","no-conversations-yet":"noch keine Gespräche","back-to-conversations":"Zurück zur Konversationen","closed-conversations":"Geschlossene Konversationen"},os={"write-a-message":"Write a message...","session-closed-lead":"Your issue has been resolved!","new-conversation":"New conversation","welcome-title":"Welcome to our support chat","welcome-description":"We're here to help! Start a conversation and we'll get back to you as soon as possible.","your-name":"Your name","your-email":"Your email address","start-chat":"Talk to support","starting-chat":"Connecting...","i-need-more-help":"I need more help","this-was-helpful":"This was helpful",optional:"Optional","no-conversations-yet":"No conversations yet","back-to-conversations":"Back to conversations","closed-conversations":"Closed conversations"},rs={"write-a-message":"Écrivez un message...","session-closed-lead":"Votre problème a été résolu !","new-conversation":"Nouvelle conversation","welcome-title":"Bienvenue dans notre chat de support","welcome-description":"Nous sommes là pour vous aider ! Commencez une conversation et nous vous répondrons dès que possible.","your-name":"Votre nom","your-email":"Votre adresse e-mail","start-chat":"Parler au support","starting-chat":"Connexion...","i-need-more-help":"Je besoin d'aide plus","this-was-helpful":"C'était utile",optional:"Optionnel","no-conversations-yet":"Aucune conversation pour le moment","back-to-conversations":"Retour aux conversations","closed-conversations":"Conversations fermées"},ns={"write-a-message":"Schrijf een bericht...","session-closed-lead":"Uw probleem is opgelost!","new-conversation":"Nieuw gesprek","welcome-title":"Welkom bij onze supportchat","welcome-description":"We zijn hier om te helpen! Begin een gesprek en we nemen zo snel mogelijk contact met u op.","your-name":"Uw naam","your-email":"Uw e-mailadres","start-chat":"Praat met ondersteuning","starting-chat":"Verbinding maken...","i-need-more-help":"Ik heb nog meer hulp nodig","this-was-helpful":"Mijn vraag is opgelost",optional:"Optioneel","no-conversations-yet":"Nog geen gesprekken","back-to-conversations":"Terug naar gesprekken","closed-conversations":"Afgesloten gesprekken"},is={"write-a-message":"Escreva uma mensagem...","session-closed-lead":"Seu problema foi resolvido!","new-conversation":"Nova conversa","welcome-title":"Bem-vindo ao nosso chat de suporte","welcome-description":"Estamos aqui para ajudar! Inicie uma conversa e responderemos o mais rápido possível.","your-name":"Seu nome","your-email":"Seu endereço de email","start-chat":"Falar com o suporte","starting-chat":"Conectando...","i-need-more-help":"preciso de mais ajuda","this-was-helpful":"Isso foi útil",optional:"Opcional","no-conversations-yet":"Nenhuma conversa ainda","back-to-conversations":"Voltar para conversas","closed-conversations":"Conversas fechadas"},as={"write-a-message":"Escribe un mensaje...","session-closed-lead":"¡Tu problema fue resuelto!","new-conversation":"Nueva conversación","welcome-title":"Bienvenido a nuestro chat de soporte","welcome-description":"¡Estamos aquí para ayudarte! Inicia una conversación y responderemos lo antes posible.","your-name":"Tu nombre","your-email":"Tu correo electrónico","start-chat":"Hablar con soporte","starting-chat":"Conectando...","i-need-more-help":"Necesito más ayuda","this-was-helpful":"Esto fue útil",optional:"Opcional","no-conversations-yet":"Sin conversaciones aún","back-to-conversations":"Volver a conversaciones","closed-conversations":"Conversaciones cerradas"},ls={"write-a-message":"Bir mesaj yazın...","session-closed-lead":"Sorununuz çözüldü!","new-conversation":"Yeni konuşma","welcome-title":"Destek sohbetimize hoş geldiniz","welcome-description":"Yardım etmek için buradayız! Bir konuşma başlatın, en kısa sürede size geri döneceğiz.","your-name":"Adınız","your-email":"E-posta adresiniz","start-chat":"Destekle konuş","starting-chat":"Bağlanıyor...","i-need-more-help":"Daha fazla yardıma ihtiyacım var","this-was-helpful":"Bu yardımcı oldu",optional:"İsteğe bağlı","no-conversations-yet":"Henüz konuşma yok","back-to-conversations":"Konuşmalara geri dön","closed-conversations":"Kapatılan konuşmalar"},wt={en:os,ar:ts,nl:ns,fr:rs,de:ss,pt:is,es:as,tr:ls},cs=Object.keys(wt);function ds(t){return cs.includes(t)}function ps(t,o){const s=wt[o];return s&&s[t]||""}function B(){const{dir:t}=l.useDocumentDir(),o=l.useConfig();return h.useMemo(()=>{const s=ds(o.language)?o.language:"en";return{t:r=>ps(r,s),language:s,dir:s==="ar"?"rtl":"ltr",hostDocumentDir:t}},[o.language,t])}function he({suggestion:t,className:o,...s}){const{sendMessage:r}=l.useMessages(),n=()=>{const a=t.trim();a&&r({content:a})};return e.jsx(k,{...w("chat/suggested_reply_btn"),size:"sm",className:p("rounded-xl w-fit",o),...s,onClick:n,children:t})}function hs(){const{t}=B(),o=[t("i-need-more-help"),t("this-was-helpful")];return e.jsx("div",{...w("chat/might_solve_user_issue_suggested_replies_container"),className:"flex items-center gap-2 p-2 pb-0 flex-wrap",children:o.map(s=>e.jsx(he,{suggestion:s,className:"flex-1"},s))})}function ms({file:{status:t,file:o,error:s},onCancel:r}){const[n,a]=h.useState(null);h.useEffect(()=>{if(!o.type.startsWith("image/"))return;const c=new FileReader;return c.onload=()=>a(c.result),c.onerror=()=>console.error("Error reading file"),c.readAsDataURL(o),()=>c.abort()},[o]);const i=()=>{switch(t){case"uploading":return e.jsx(m.Loader2,{className:"size-4 animate-spin"});case"error":return e.jsx(m.AlertCircle,{className:"size-4 text-destructive"});default:return null}},d=()=>{const c=o.type.split("/")[0];return c==="image"&&n?e.jsx("img",{src:typeof n=="string"?n:"",className:"object-cover bg-secondary size-full",alt:o.name}):c==="audio"?e.jsx(m.FileAudio2Icon,{}):c==="video"?e.jsx(m.FileVideo2Icon,{}):e.jsx(m.FileIcon,{})};return e.jsx(X,{side:"bottom",content:t==="error"?e.jsxs("span",{className:"text-destructive",children:["Failed to upload: ",s]}):o.name,children:e.jsxs("div",{className:p(t==="uploading"&&"opacity-50","group","size-12 border rounded-2xl overflow-hidden relative","flex items-center justify-center shrink-0"),children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i()}),e.jsx("button",{type:"button",className:p("absolute bg-black/50 inset-0 size-full z-10 opacity-0","flex items-center justify-center","opacity-0 group-hover:opacity-100 transition"),onClick:r,children:e.jsx(m.XIcon,{className:"size-4 text-primary-foreground"})}),e.jsx(d,{})]})})}function us(){var D;const{isSmallScreen:t}=E(),o=h.useRef(null),{sendMessage:s}=l.useMessages(),{sessionState:r}=l.useSessions(),{t:n}=B(),[a,i]=h.useState(""),{allFiles:d,emptyTheFiles:c,handleCancelUpload:u,appendFiles:y,isUploading:x,successFiles:g}=l.useUploadFiles(),C=!!((D=r.session)!=null&&D.isHandedOff),{isAwaitingBotReply:v}=l.useIsAwaitingBotReply(),N=b=>{y(b)},I=!a.trim()&&g.length===0,_=async()=>{if(v||I)return;x&&console.info("please wait for the file(s) to upload");const b=a.trim();s({content:b,attachments:g.flatMap(z=>z.fileUrl?[{url:z.fileUrl,type:z.file.type,name:z.file.name,id:z.id,size:z.file.size}]:[])}),i(""),c()},{getRootProps:T,getInputProps:P,open:R}=It.useDropzone({onDrop:N,noClick:!0,onDropRejected(){console.error("unsupported file type, or the file is too large")},maxSize:5*1024*1024,accept:C?{"text/*":[".txt"],"image/*":[".png",".jpg",".jpeg",".gif"],"application/pdf":[".pdf"]}:{"image/png":[".png"],"image/jpeg":[".jpg",".jpeg"],"image/gif":[".gif"],"image/webp":[".webp"]}}),A=b=>{const z=b.clipboardData;z&&z.files.length>0&&N(Array.from(z.files))};return e.jsxs("div",{...w("chat/input_box/root"),className:"p-2 relative space-y-1",...T(),children:[e.jsx("input",{...P()}),e.jsxs("div",{...w("chat/input_box/inner_root"),className:p("transition-all","bg-white","relative rounded-3xl flex flex-col gap-2 p-2","hover:border-primary focus-within:border-primary"),children:[e.jsxs("div",{...w("chat/input_box/textarea_and_attachments_container"),className:"flex flex-col gap-2",children:[d.length>0&&e.jsx("div",{...w("chat/input_box/attachments_container"),className:"flex items-center gap-1",children:e.jsx(j.AnimatePresence,{mode:"popLayout",children:d.map(b=>e.jsx(f,{snapExit:!0,children:e.jsx(ms,{onCancel:()=>u(b.id),file:b})},b.id))})}),e.jsx("textarea",{...w("chat/input_box/textarea"),onPaste:A,ref:o,id:"chat-input",value:a,rows:3,className:p("max-h-16 [field-sizing:content]","w-full resize-none px-2",d.length===0&&"pt-1","bg-transparent outline-none","placeholder:text-muted-foreground",t?"text-[16px]":"text-sm"),onChange:b=>i(b.target.value),onKeyDown:async b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),_())},placeholder:n("write-a-message")})]}),e.jsxs("div",{className:"gap-2 flex justify-between",children:[e.jsx(X,{side:"top",align:"start",content:"attach files, (maximum size 5mb)",children:e.jsx(k,{onClick:R,size:"fit",variant:"ghost",className:p("rounded-full size-8 flex items-center justify-center p-0 overflow-hidden"),children:e.jsx(j.AnimatePresence,{mode:"wait",children:C?e.jsx(f,{children:e.jsx(m.PaperclipIcon,{className:"size-4"})},"paper-clip"):e.jsx(f,{children:e.jsx(m.ImageIcon,{className:"size-4"})},"image-icon")})})}),e.jsx(X,{content:"send message",side:"top",align:"end",children:e.jsx(k,{size:"fit",onClick:_,disabled:v||x||I,className:"rounded-full size-8 flex items-center justify-center p-0",children:e.jsx(j.AnimatePresence,{mode:"wait",children:v||x?e.jsx(f,{snapExit:!0,children:e.jsx(m.CircleDashed,{className:"size-4 animate-spin animate-iteration-infinite"})},"loading"):e.jsx(f,{snapExit:!0,children:e.jsx(m.ArrowUpIcon,{className:"size-4"})},"send")})})})]})]})]})}function Ue(){const{widgetCtx:t}=l.useWidget(),{router:o}=l.useConfig(),{canCreateNewSession:s}=l.useSessions(),{toSessionsScreen:r}=l.useWidgetRouter(),{t:n}=B();return e.jsx(e.Fragment,{children:s||o!=null&&o.chatScreenOnly?e.jsx(k,{onClick:t.resetChat,className:"rounded-2xl w-full",children:n("new-conversation")}):e.jsx(k,{onClick:r,className:"rounded-2xl w-full",children:n("back-to-conversations")})})}function gs(){const{t}=B(),{isCsatRequested:o,isCsatSubmitted:s}=l.useCsat();return e.jsx("div",{className:"p-2",children:e.jsx("div",{className:"p-2 bg-muted rounded-3xl",children:e.jsx(j.AnimatePresence,{mode:"wait",children:o||s?e.jsxs(O,{children:[e.jsx(es,{}),e.jsx(j.AnimatePresence,{mode:"wait",children:s&&e.jsx(O,{children:e.jsx(Ue,{})},"new-conv-or-back-to-convs-button")})]},"csat"):e.jsxs(O,{children:[e.jsxs("div",{className:"ps-2 flex items-center gap-1 pb-2",children:[e.jsx(m.CircleCheckIcon,{className:"size-4 text-emerald-600"}),e.jsx("h2",{className:"text-sm font-medium",children:t("session-closed-lead")})]}),e.jsx(Ue,{})]},"session-closed")})})})}function ws(){var i;const{initialQuestions:t,initialQuestionsPosition:o,thisWasHelpfulOrNot:s}=l.useConfig(),{sessionState:r}=l.useSessions(),{messagesState:n}=l.useMessages(),a=n.messages.length===0;return e.jsx("footer",{children:e.jsx("div",{children:e.jsx(j.AnimatePresence,{mode:"wait",children:r.session&&!((i=r.session)!=null&&i.isOpened)?e.jsx(O,{children:e.jsx(gs,{})},"session-closed"):e.jsxs(O,{children:[n.lastAIResMightSolveUserIssue&&(s==null?void 0:s.enabled)!==!1&&e.jsx(hs,{}),a&&t&&o!=="below-initial-messages"&&e.jsx("div",{className:"flex items-center flex-row justify-end gap-2 flex-wrap px-2",children:t==null?void 0:t.map((d,c)=>e.jsx(he,{suggestion:d},`${d}-${c}`))}),e.jsx(us,{})]},"chat-input")})})})}function fs({isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s,...r}){const{componentStore:n}=l.useWidget();if(r.type!=="AGENT"&&r.type!=="AI")return null;if(r.data.action){const i=n.getComponent(r.data.action.name);if(i)return e.jsx(i,{...r,id:r.id,isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s})}const a=n.getComponent(r.component);return a?e.jsx(a,{...r,id:r.id,isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s}):e.jsx(oe,{...r,isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s})}function ft({messages:t,className:o,containerClassName:s}){var i,d;const{timestamps:r}=l.useConfig();if(!((i=r==null?void 0:r.perMessageGroup)!=null&&i.enabled))return null;const n=(d=t[t.length-1])==null?void 0:d.timestamp;if(!n)return null;const a=(()=>{try{return new Date(n).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!0})}catch(c){return console.error(c),null}})();return a?e.jsx("div",{className:s,children:e.jsx("span",{className:p("text-xs text-muted-foreground",o),children:a})}):null}function me({messages:t,agent:o,suggestedReplies:s}){return e.jsxs("div",{...w("chat/agent_msg_group/root"),className:p("flex items-end gap-2"),children:[e.jsx(X,{content:o==null?void 0:o.name,side:"right",align:"end",children:e.jsx(re,{...w("chat/agent_msg_group/root/avatar"),agent:o,className:"hidden"})}),e.jsxs("div",{className:p("flex-1 flex flex-col gap-1"),children:[e.jsxs("div",{...w("chat/agent_msg_group/avatar_and_msgs/root"),className:p("flex items-end gap-2"),children:[e.jsx(X,{content:o==null?void 0:o.name,side:"right",align:"end",children:e.jsx(re,{...w("chat/agent_msg_group/avatar_and_msgs/avatar"),agent:o})}),e.jsxs("div",{...w("chat/agent_msg_group/avatar_and_msgs/msgs"),className:p("flex-1 flex flex-col gap-1"),children:[t.map((r,n,a)=>e.jsx(fs,{isFirstInGroup:n===0,isLastInGroup:n===a.length-1,isAloneInGroup:a.length===1,...r},r.id)),e.jsx(ft,{messages:t})]})]}),s&&s.length>0&&e.jsx("div",{...w("chat/agent_msg_group/suggestions"),className:p("flex flex-col gap-1 ps-8"),children:s==null?void 0:s.map((r,n)=>e.jsx(he,{suggestion:r},`${r}-${n}`))})]})]})}function xs(){var n;const{widgetCtx:{org:t}}=l.useWidget(),{sessionState:{session:o}}=l.useSessions(),s=l.useConfig();if(o!=null&&o.isOpened||!o)return null;const r=(n=s.specialComponents)==null?void 0:n.onSessionResolved;return r?e.jsx(r,{react:h,session:o,config:s,org:t}):null}function vs({message:t,isFirstInGroup:o,isLastInGroup:s,isAloneInGroup:r}){var n;return e.jsxs("div",{...w("chat/user_msg/root"),className:"w-5/6 flex flex-col items-end gap-1",children:[t.attachments&&t.attachments.length>0&&e.jsx("div",{className:"w-full flex gap-1 flex-wrap justify-end",children:(n=t.attachments)==null?void 0:n.map(a=>e.jsx(it,{attachment:a},a.id))}),t.content.length>0&&e.jsx("div",{...w("chat/user_msg/msg"),"data-first":o,"data-last":s,"data-alone":r,className:p("transition-all","w-fit py-3 px-4 rounded-3xl text-sm","bg-primary text-primary-foreground","break-words [word-break:break-word]","whitespace-pre-wrap",o&&!r&&"rounded-br-md",s&&!r&&"rounded-tr-md",!o&&!s&&!r&&"rounded-r-md"),children:t.content})]})}function bs({messages:t}){return e.jsxs("div",{...w("chat/user_msg_group/root"),className:p("group","flex flex-col gap-1 justify-end items-end"),children:[t.map((o,s,r)=>e.jsx(vs,{message:o,isFirstInGroup:s===0,isLastInGroup:s===r.length-1,isAloneInGroup:r.length===1},o.id)),e.jsx(ft,{messages:t,containerClassName:"ms-auto"})]})}function ys(t){const o=[];let s=null;return t.forEach(r=>{var n,a,i,d,c,u;(!s||((n=s[0])==null?void 0:n.type)!==r.type)&&(s=[],o.push(s)),((a=s[0])==null?void 0:a.type)==="AGENT"&&r.type==="AGENT"&&(((i=r.agent)==null?void 0:i.id)!==((d=s[0].agent)==null?void 0:d.id)||((c=r.agent)==null?void 0:c.name)!==((u=s[0].agent)==null?void 0:u.name))&&(s=[],o.push(s)),s.push(r)}),o}function js(t){var o;return((o=t==null?void 0:t[0])==null?void 0:o.type)==="USER"}function ks(t){var o;return((o=t==null?void 0:t[0])==null?void 0:o.type)==="AI"}function Cs(t){var o;return((o=t==null?void 0:t[0])==null?void 0:o.type)==="AGENT"}function zs(){const{messagesState:{messages:t}}=l.useMessages(),{advancedInitialMessages:o=[],initialQuestionsPosition:s,initialQuestions:r,bot:n}=l.useConfig();return e.jsx(e.Fragment,{children:t.length===0&&o.length>0&&e.jsx(me,{messages:o.map(({message:a},i)=>({component:"bot_message",data:{message:a},id:`${i}-${a}`,type:"AI",timestamp:null})),suggestedReplies:t.length===0&&s==="below-initial-messages"?r:void 0,agent:n?{...n,isAi:!0,id:null}:void 0})})}function Ss(){const{messagesState:{messages:t}}=l.useMessages(),{chatBannerItems:o}=l.useConfig();return!(o!=null&&o.length)||t.length>0&&o.every(s=>!s.persistent)?null:e.jsx("div",{className:"w-full text-center text-xs",children:o.map(({message:s,persistent:r},n)=>t.length>0&&!r?null:e.jsx("div",{children:e.jsx(lt,{children:s})},`${s}-${n}`))})}function Ns(){const{messagesState:{messages:t}}=l.useMessages(),o=l.useConfig(),{advancedInitialMessages:s=[],initialQuestions:r,initialQuestionsPosition:n}=o,a=(()=>{var i;return s.length?[]:t.length?[]:(i=o.initialMessages)!=null&&i.length?o.initialMessages:["Hello, how can I help you?"]})();return e.jsx(e.Fragment,{children:t.length===0&&a.length>0&&e.jsx(me,{messages:a.map((i,d)=>({component:"bot_message",data:{message:i},id:`${d}-${i}`,type:"AI",timestamp:null})),suggestedReplies:n==="below-initial-messages"?r:void 0,agent:o.bot?{...o.bot,isAi:!0,id:null}:void 0})})}function _s(){const{messagesState:{messages:t}}=l.useMessages(),{isAwaitingBotReply:o}=l.useIsAwaitingBotReply(),{componentStore:s}=l.useWidget(),r=l.useConfig(),n=h.useMemo(()=>ys(t),[t]),a=s.getComponent("loading"),i=h.useRef(null);function d(){setTimeout(()=>{const c=i.current;c&&(c.scrollTop=c.scrollHeight)},0)}return h.useEffect(()=>{d()},[t]),e.jsxs("div",{...w("chat/msgs/root"),ref:i,className:"max-h-full scroll-smooth relative flex-1 py-2 px-4 flex flex-col gap-2 overflow-auto",children:[e.jsx(Ss,{}),e.jsx(zs,{}),e.jsx(Ns,{}),n.map(c=>{var x,g,C;const u=(x=c==null?void 0:c[0])==null?void 0:x.type,y=(g=c[0])==null?void 0:g.id;if(!u||!y)return null;if(js(c))return e.jsx(bs,{messages:c},y);if(ks(c)||Cs(c)){const v=(C=c[0])==null?void 0:C.agent;return e.jsx(me,{messages:c,agent:v},y)}return null}),o&&a&&e.jsx(a,{agent:r.bot}),e.jsx(xs,{})]})}function Is(){const{messagesState:{isInitialFetchLoading:t}}=l.useMessages(),{sessionState:{session:o}}=l.useSessions(),{isCanvasOpen:s}=Zt(),{theme:r}=q();de({width:s?r.screens.chat.withCanvas.width:r.screens.chat.width,height:s?r.screens.chat.withCanvas.height:r.screens.chat.height});const n=h.useRef((o==null?void 0:o.id)||"chat").current;return e.jsx("div",{...w("chat/root"),className:p("flex flex-col overflow-hidden"),style:{width:"100vw",maxWidth:"100vw",height:"100vh",maxHeight:"100vh"},children:e.jsxs("div",{className:"size-full justify-between flex flex-col",children:[e.jsx(ut,{}),e.jsx(j.AnimatePresence,{mode:"wait",children:t?e.jsx(f,{className:"flex flex-col items-center justify-center w-full flex-1",children:e.jsx(gt,{})},"loading"):e.jsxs(f,{className:"flex items-start h-full flex-1 overflow-auto",snapExit:!0,children:[e.jsxs("div",{...w("chat/main/root"),className:p("flex flex-col h-full overflow-auto transition-all",s?"w-2/5":"w-full"),style:{transitionTimingFunction:r.screens.chat.withCanvas.transitionTimingFunction,transitionDuration:r.screens.chat.withCanvas.transitionDuration},children:[e.jsx(_s,{}),e.jsx(ws,{})]}),e.jsx("div",{...w("chat/canvas/root"),className:p("h-full overflow-auto transition-all",s?"w-3/5":"w-0"),style:{transitionTimingFunction:r.screens.chat.withCanvas.transitionTimingFunction,transitionDuration:r.screens.chat.withCanvas.transitionDuration},children:e.jsx(Qt,{})})]},n)})]})})}function Ts({className:t,...o}){return e.jsx("div",{className:p("animate-pulse rounded-md bg-secondary",t),...o})}function Ms({className:t}){return e.jsx("svg",{width:"26",height:"32",viewBox:"0 0 26 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:p("text-primary-foreground",t),children:e.jsx("path",{d:"M1.34103 25.6132H5.44245C5.74203 25.6228 6.02673 25.7462 6.23867 25.9582C6.45062 26.1703 6.5739 26.4551 6.58348 26.7548V30.8584C6.59305 31.1581 6.71634 31.443 6.92828 31.655C7.14023 31.8671 7.42492 31.9904 7.7245 32H18.2894C18.589 31.9904 18.8737 31.8671 19.0856 31.655C19.2976 31.443 19.4209 31.1581 19.4304 30.8584V26.7548C19.4401 26.4545 19.5638 26.1692 19.7765 25.957C19.9892 25.7449 20.2748 25.6219 20.5749 25.6132H24.659C24.9586 25.6036 25.2433 25.4803 25.4552 25.2682C25.6671 25.0562 25.7904 24.7713 25.8 24.4716V7.52839C25.7904 7.22865 25.6671 6.94381 25.4552 6.73176C25.2433 6.5197 24.9586 6.39635 24.659 6.38677H20.561C20.2603 6.37802 19.9742 6.25457 19.7614 6.04169C19.5487 5.82881 19.4253 5.54261 19.4165 5.24168V1.14161C19.4072 0.84419 19.2858 0.561291 19.0768 0.349589C18.8678 0.137887 18.5865 0.0130193 18.2894 0L7.7245 0C7.42492 0.00957792 7.14023 0.132929 6.92828 0.344983C6.71634 0.557036 6.59305 0.841878 6.58348 1.14161V5.24168C6.57477 5.54203 6.45187 5.82773 6.23983 6.04052C6.0278 6.25331 5.74262 6.37715 5.44245 6.38677H1.34103C1.04144 6.39635 0.756749 6.5197 0.544805 6.73176C0.332861 6.94381 0.209574 7.22865 0.200001 7.52839V24.4716C0.209574 24.7713 0.332861 25.0562 0.544805 25.2682C0.756749 25.4803 1.04144 25.6036 1.34103 25.6132ZM6.58348 24.4716V7.52839C6.59305 7.22865 6.71634 6.94381 6.92828 6.73176C7.14023 6.5197 7.42492 6.39635 7.7245 6.38677H18.2894C18.589 6.39635 18.8737 6.5197 19.0856 6.73176C19.2976 6.94381 19.4209 7.22865 19.4304 7.52839V24.4716C19.4209 24.7713 19.2976 25.0562 19.0856 25.2682C18.8737 25.4803 18.589 25.6036 18.2894 25.6132H7.7245C7.42492 25.6036 7.14023 25.4803 6.92828 25.2682C6.71634 25.0562 6.59305 24.7713 6.58348 24.4716Z",fill:"currentColor"})})}function xt({className:t}){const{token:o}=l.useConfig();return e.jsx("div",{className:p("flex items-center justify-center gap-2 p-2 pt-0",t),children:e.jsx(W,{children:e.jsxs("a",{href:`https://open.cx/?ref=${o}`,target:"_blank",rel:"noreferrer",className:p("text-[10px] flex items-center","text-muted-foreground/70 [&_svg]:text-muted-foreground/70","hover:text-primary [&_svg]:hover:text-primary"),children:[e.jsx("span",{children:"Powered by"}),e.jsx("span",{children:" "}),e.jsxs("span",{className:"flex items-center gap-[1px]",children:[e.jsx("span",{children:e.jsx(Ms,{className:"size-3 inline-block"})}),e.jsx("span",{className:"font-semibold",children:"open"})]})]})})})}function Ds({children:t}){return e.jsx("p",{className:"ps-4 text-xs text-muted-foreground/75 uppercase font-semibold tracking-tight",children:t})}function Ve({session:t,className:o}){const{bot:s}=l.useConfig(),{toChatScreen:r}=l.useWidgetRouter(),n=t.assignee.kind==="human"?t.assignee.name||"Support Agent":(s==null?void 0:s.name)||"AI Support Agent",a=t.assignee.kind==="human"?t.assignee.avatarUrl||"":(s==null?void 0:s.avatar)||"";return e.jsxs(k,{variant:"ghost",size:"lg",className:p("rounded-full p-2 pe-4 flex text-start justify-between w-full whitespace-normal",o),onClick:()=>r(t.id),children:[e.jsxs("div",{className:"flex-1 flex gap-2 items-center",children:[e.jsx(j.AnimatePresence,{mode:"wait",children:e.jsx(f,{snapExit:!0,children:e.jsxs(ae,{className:"size-10",children:[e.jsx(le,{src:a,alt:"Agent Icon"}),e.jsx(ce,{children:e.jsx(m.UserRoundIcon,{className:"size-4"})})]})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(j.AnimatePresence,{mode:"wait",children:e.jsx(f,{snapExit:!0,children:n},n)}),e.jsx(j.AnimatePresence,{mode:"wait",children:t.lastMessage?e.jsx(f,{snapExit:!0,children:e.jsx(at,{remarkPlugins:[Ge],rehypePlugins:[Ke],className:"line-clamp-1 overflow-hidden text-ellipsis text-xs text-muted-foreground",children:t.lastMessage})},t.lastMessage||"content"):e.jsx(f,{className:"w-1/2",snapExit:!0,children:e.jsx(Ts,{className:"h-4 w-full"})},"skeleton")})]})]}),e.jsx(m.ChevronRightIcon,{className:"size-4 text-muted-foreground shrink-0 rtl:-scale-100"})]})}function Es(){const{t}=B(),{toChatScreen:o}=l.useWidgetRouter(),{sessionsState:{data:s,isInitialFetchLoading:r},openSessions:n,closedSessions:a,canCreateNewSession:i}=l.useSessions();return e.jsx("div",{className:"flex-1 flex flex-col overflow-scroll py-2 px-2",children:e.jsx(j.AnimatePresence,{mode:"wait",children:r?e.jsx(f,{className:"flex-1 flex items-center justify-center",children:e.jsx(gt,{})},"loading"):e.jsx(f,{className:"flex-1 flex flex-col gap-2 relative",children:s.length?e.jsxs(e.Fragment,{children:[e.jsxs(j.AnimatePresence,{children:[n.length>0&&e.jsx(f,{fadeIn:"up",delay:.2,className:"space-y-2",snapExit:!0,children:n.map(d=>e.jsx(Ve,{session:d},d.id))},"open-sessions"),a.length>0&&e.jsxs(f,{className:"space-y-2",delay:.2,snapExit:!0,children:[e.jsx(Ds,{children:t("closed-conversations")}),a.map(d=>e.jsx(Ve,{session:d,className:"opacity-50 hover:opacity-100"},d.id))]},"closed-sessions")]}),i&&e.jsx("div",{className:"mt-auto w-full rounded-3xl sticky bottom-0 outline outline-8 outline-background bg-background",children:h.createElement(k,{...w("sessions/new_conversation_btn"),size:"lg",key:"new-session",className:"w-full",onClick:()=>o()},t("new-conversation"))})]}):e.jsxs("div",{className:"flex-1 flex flex-col gap-2 items-center",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:t("no-conversations-yet")})}),h.createElement(k,{...w("sessions/new_conversation_btn"),size:"lg",key:"new-session",className:"w-full",onClick:()=>o()},t("new-conversation"))]})},"sessions")})})}function Ps(){const{theme:t}=q();return de({width:t.screens.sessions.width,height:t.screens.sessions.height}),e.jsx("div",{...w("sessions/root"),className:p("flex flex-col overflow-hidden bg-background"),style:{width:"100vw",maxWidth:"100vw",height:"100vh",maxHeight:"100vh"},children:e.jsxs("div",{className:"size-full flex flex-col",children:[e.jsx(ut,{}),e.jsx(Es,{}),e.jsx(xt,{})]})})}const Z=Y.forwardRef(({className:t,type:o,...s},r)=>{const{isSmallScreen:n}=E();return e.jsx(W,{ref:r,children:e.jsx("input",{type:o,className:p(n?"text-[16px]":"text-sm","flex w-full rounded-xl p-2 ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-primary-foreground placeholder:text-muted-foreground/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition","rounded-2xl px-4","border shadow-sm",t),...s})})});Z.displayName="Input";function Rs(){const{contentIframeRef:t}=l.useWidget(),{inline:o}=l.useConfig(),s=h.useRef(null);return h.useEffect(()=>{const r=t==null?void 0:t.current;if(r&&s.current){const n=s.current;let a;const i=new ResizeObserver(()=>{a=requestAnimationFrame(()=>{const d=n.offsetHeight;r.style.setProperty("--opencx-widget-height",o?"100%":`${d.toFixed(1)}px`)})});return i.observe(n),()=>{cancelAnimationFrame(a),i.unobserve(n)}}},[t,o]),{observedElementRef:s}}const As=se.z.object({name:se.z.string().min(2),email:se.z.string().email()});function Ws(){var _,T,P,R,A,D,b,z;const{widgetCtx:{org:t}}=l.useWidget(),{setIsOpen:o}=l.useWidgetTrigger(),{createUnverifiedContact:s}=l.useContact(),{isSmallScreen:r}=E(),n=l.useConfig(),{theme:a}=q(),{t:i}=B(),{observedElementRef:d}=Rs();de({height:void 0,width:a.screens.welcome.width});const[c,u]=h.useState(((_=n.prefillUserData)==null?void 0:_.name)||""),[y,x]=h.useState(((T=n.prefillUserData)==null?void 0:T.email)||""),g=(n.extraDataCollectionFields||[]).filter(S=>S!=="name"&&S!=="email"&&!!S),[C,v]=h.useState({}),[N,I]=Tt(async S=>{S.preventDefault();const F=As.safeParse({name:c,email:y});F.success&&await s({email:F.data.email,non_verified_name:F.data.name},Object.values(C).filter(Boolean).length?C:void 0)},[c,y,C]);return e.jsx("div",{style:{width:"100vw",maxWidth:"100vw",minHeight:a.screens.welcome.minHeight,height:"100vh",maxHeight:"100vh",overflowY:"auto"},children:e.jsxs("div",{ref:d,className:p("flex flex-col",r&&"h-full","bg-[radial-gradient(ellipse_at_top_left,hsl(var(--opencx-primary)),transparent),radial-gradient(ellipse_at_top_right,hsl(var(--opencx-primary)),transparent)]"),children:[e.jsxs("div",{className:p("flex-1 flex flex-col px-4 py-12 text-start space-y-4 relative z-10","text-primary-foreground"),children:[r&&e.jsx(f,{className:"absolute top-6 end-6",children:e.jsx(k,{size:"selfless",onClick:()=>o(!1),children:e.jsx(m.XIcon,{className:"size-4"})})}),e.jsx("div",{className:"flex items-center justify-between w-full mb-2",children:(P=n.assets)!=null&&P.organizationLogo?e.jsx("img",{src:(R=n.assets)==null?void 0:R.organizationLogo,alt:"Company Logo",className:"h-8 w-auto object-contain"}):e.jsx("h2",{className:"font-bold text-sm",children:t.name})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-[1.75rem] font-semibold tracking-tight leading-none",children:((D=(A=n.textContent)==null?void 0:A.welcomeScreen)==null?void 0:D.title)||i("welcome-title")}),e.jsx("p",{className:"text-sm",children:((z=(b=n.textContent)==null?void 0:b.welcomeScreen)==null?void 0:z.description)||i("welcome-description")})]})]}),e.jsxs("div",{className:p("z-10 m-2 px-2 pt-2 bp-0 space-y-2","bg-[white]","border shadow","rounded-3xl"),children:[e.jsxs("form",{onSubmit:I,className:"space-y-2",children:[e.jsx(Z,{value:c,onChange:S=>u(S.target.value),required:!0,placeholder:i("your-name"),name:"name"}),e.jsx(Z,{required:!0,value:y,onChange:S=>x(S.target.value),type:"email",placeholder:i("your-email"),name:"email"}),g.map(S=>e.jsx(Z,{value:C[S],onChange:F=>v(G=>({...G,[S]:F.target.value})),placeholder:`${S} (${i("optional")})`},S)),e.jsxs(k,{disabled:N.loading,className:"w-full",size:"lg",children:[N.loading?i("starting-chat"):i("start-chat"),e.jsx(m.SendHorizontal,{className:"size-4 rtl:-scale-100"})]})]}),e.jsx(xt,{})]})]})})}function vt(){const{routerState:{screen:t}}=l.useWidgetRouter();return e.jsx("div",{className:"relative bg-background size-full",children:e.jsx(j.AnimatePresence,{mode:"wait",children:(()=>{switch(t){case"welcome":return e.jsx(f,{fadeIn:"right",className:"size-full",snapExit:!0,children:e.jsx(Ws,{})},t);case"sessions":return e.jsx(f,{fadeIn:"right",className:"size-full",snapExit:!0,children:e.jsx(Ps,{})},t);case"chat":return e.jsx(f,{fadeIn:"right",className:"size-full",snapExit:!0,children:e.jsx(Is,{})},t);default:return M.isExhaustive(t,vt.name),null}})()})})}const Os="4.0.16",Fs=`<!DOCTYPE html>
|
|
17
|
+
)`)};return{theme:u,computed:y,cssVars:$t({palette:u.palette,primary:u.primaryColor})}}function $t({palette:t,primary:o}){const s=pt(t),r=Ye(o).toHsl(),n=Ye(o).isLight()?s[950]:s[50];return{"--opencx-primary":`${r.h} ${r.s*100}% ${r.l*100}%`,"--opencx-primary-foreground":n,"--opencx-background":s[100],"--opencx-foreground":s[950],"--opencx-destructive":"0 72.2% 50.6%","--opencx-destructive-foreground":s[50],"--opencx-accent":s[200],"--opencx-accent-foreground":"var(--opencx-foreground)","--opencx-secondary":s[200],"--opencx-secondary-foreground":"var(--opencx-foreground)","--opencx-muted":s[200],"--opencx-muted-foreground":s[500],"--opencx-input":s[300],"--opencx-border":s[300],"--opencx-ring":"var(--opencx-foreground)"}}function pt(t){const o={50:"0 0% 98%",100:"0 0% 96.1%",200:"0 0% 89.8%",300:"0 0% 83.1%",400:"0 0% 63.9%",500:"0 0% 45.1%",600:"0 0% 32.2%",700:"0 0% 25.1%",800:"0 0% 14.9%",900:"0 0% 9%",950:"0 0% 3.9%"},s={50:"60 9.1% 97.8%",100:"60 4.8% 95.9%",200:"20 5.9% 90%",300:"24 5.7% 82.9%",400:"24 5.4% 63.9%",500:"25 5.3% 44.7%",600:"33.3 5.5% 32.4%",700:"30 6.3% 25.1%",800:"12 6.5% 15.1%",900:"24 9.8% 10%",950:"20 14.3% 4.1%"},r={50:"0 0% 98%",100:"240 4.8% 95.9%",200:"240 5.9% 90%",300:"240 4.9% 83.9%",400:"240 5% 64.9%",500:"240 3.8% 46.1%",600:"240 5.2% 33.9%",700:"240 5.3% 26.1%",800:"240 3.7% 15.9%",900:"240 5.9% 10%",950:"240 10% 3.9%"},n={50:"210 40% 98%",100:"210 40% 96.1%",200:"214.3 31.8% 91.4%",300:"212.7 26.8% 83.9%",400:"215 20.2% 65.1%",500:"215.4 16.3% 46.9%",600:"215.3 19.3% 34.5%",700:"215.3 25% 26.7%",800:"217.2 32.6% 17.5%",900:"222.2 47.4% 11.2%",950:"222.2 84% 4.9%"};switch(t){case"neutral":return o;case"stone":return s;case"zinc":return r;case"slate":return n;default:return M.isExhaustive(t,pt.name),o}}function ht(){const{contentIframeRef:t}=l.useWidget(),{inline:o}=l.useConfig();return{setWidth:s=>{var r;(r=t==null?void 0:t.current)==null||r.style.setProperty("--opencx-widget-width",o?"100%":s)},setHeight:s=>{var r;(r=t==null?void 0:t.current)==null||r.style.setProperty("--opencx-widget-height",o?"100%":s)}}}function de({width:t,height:o}){const{isSmallScreen:s}=E(),{setWidth:r,setHeight:n}=ht();h.useEffect(()=>{t&&r(t),o&&n(o)},[s,o,t,r,n])}const Xe=m.CircleDashedIcon;function U({name:t,className:o}){const s=(()=>{switch(t){case"Check":return m.CheckIcon;case"CheckCheck":return m.CheckCheckIcon;case"CircleCheck":return m.CircleCheckIcon;case"CircleCheckBig":return m.CircleCheckBigIcon;case"CircleX":return m.CircleXIcon;case"Expand":return m.ExpandIcon;case"Maximize":return m.MaximizeIcon;case"Maximize2":return m.Maximize2Icon;case"Minimize":return m.MinimizeIcon;case"Minimize2":return m.Minimize2Icon;case"Shrink":return m.ShrinkIcon;case"SquareCheck":return m.SquareCheckIcon;case"SquareCheckBig":return m.SquareCheckBigIcon;case"SquareX":return m.SquareXIcon;case"X":return m.XIcon;case void 0:return Xe;default:return M.isExhaustive(t,U.name),Xe}})();return e.jsx(s,{className:p("size-4",o)})}function pe(){const{widgetCtx:{org:t}}=l.useWidget(),{routerState:{screen:o}}=l.useWidgetRouter(),{textContent:s}=l.useConfig();return(()=>{var n,a;switch(o){case"chat":return(n=s==null?void 0:s.chatScreen)==null?void 0:n.headerTitle;case"sessions":return(a=s==null?void 0:s.sessionsScreen)==null?void 0:a.headerTitle;case"welcome":return;default:M.isExhaustive(o,pe.name);return}})()??t.name??"Chat"}function Xt(t){switch(t){case"chat":return w("chat/header");case"sessions":return w("sessions/header");case"welcome":return;default:M.isExhaustive(t,pe.name);return}}function Ut(){const{router:t}=l.useConfig(),{routerState:{screen:o},toSessionsScreen:s}=l.useWidgetRouter();return o!=="chat"||t!=null&&t.chatScreenOnly?null:e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:s,children:e.jsx(m.ChevronLeftIcon,{className:"size-4 rtl:-scale-100"})})}function Vt({button:t}){const{setIsOpen:o}=l.useWidgetTrigger(),{isSmallScreen:s}=E();if(s&&t.hideOnSmallScreen||!s&&t.hideOnLargeScreen)return null;const r=()=>{if(t.handleClick)return t.handleClick();o(!1)};return e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:r,children:e.jsx(U,{name:t.icon})})}function ne({button:t}){const[o,s]=h.useState(!1),{routerState:{screen:r}}=l.useWidgetRouter(),{isSmallScreen:n}=E(),{theme:a}=q(),{setWidth:i,setHeight:d}=ht();if(r!=="chat"&&r!=="sessions")return null;const c=(()=>{switch(r){case"chat":return a.screens.chat.height;case"sessions":return a.screens.sessions.height;default:return M.isExhaustive(r,ne.name),a.screens.chat.height}})(),u=(()=>{switch(r){case"chat":return a.screens.chat.width;case"sessions":return a.screens.sessions.width;default:return M.isExhaustive(r,ne.name),a.screens.chat.width}})(),y=()=>{s(x=>{const g=!x;return d(g?"100vh":c),i(g?`max(40vw, ${u})`:u),g})};return n&&t.hideOnSmallScreen||!n&&t.hideOnLargeScreen?null:e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:y,children:e.jsx(U,{name:t.icon||(o?t.shrinkIcon:t.expandIcon)})})}function mt({button:t}){var N,I;const{close:o}=ee(),{widgetCtx:s}=l.useWidget(),{setIsOpen:r}=l.useWidgetTrigger(),{resolveSession:n,sessionState:a}=l.useSessions(),{isSmallScreen:i}=E(),d=!a.session,c=((N=a.session)==null?void 0:N.isOpened)===!1,u=t.onResolved||"stay-in-chat",y=t.behaviorBeforeSessionCreation||"disabled",x=t.behaviorIfSessionIsResolved||"disabled",g=!!(a.isResolvingSession||d&&y==="disabled"||c&&x==="disabled"),C=async()=>{const{success:_,error:T}=await n();if(o(),!_)return console.error(T);switch(u){case"stay-in-chat":return;case"close-widget":r(!1);break;case"reset-chat":s.resetChat();break;case"reset-chat-and-close-widget":r(!1),s.resetChat();break;default:M.isExhaustive(u,mt.name);break}},v=()=>{if(d)switch(y){case"disabled":return;case"close-widget":r(!1);break;default:M.isExhaustive(y,v.name)}if(c)switch(x){case"disabled":return;case"close-widget":r(!1);break;case"reset-chat":s.resetChat();break;case"reset-chat-and-close-widget":r(!1),setTimeout(()=>{s.resetChat()},200);break;default:M.isExhaustive(x,v.name)}};return i&&t.hideOnSmallScreen||!i&&t.hideOnLargeScreen?null:((I=t.confirmation)==null?void 0:I.type)==="modal"&&!c&&!d?e.jsx(nt,{trigger:e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",disabled:g,children:e.jsx(U,{name:t.icon})}),children:e.jsxs(Je,{children:[e.jsx(et,{children:e.jsx(ot,{children:t.confirmation.title||"Close conversation"})}),e.jsx(tt,{children:e.jsx(rt,{children:t.confirmation.description||"Are you sure you want to close this conversation?"})}),e.jsxs(st,{children:[e.jsx(k,{variant:"secondary",onClick:o,disabled:a.isResolvingSession,children:t.confirmation.cancelButtonText||"No"}),e.jsx(k,{variant:"destructive",onClick:C,disabled:a.isResolvingSession,children:t.confirmation.confirmButtonText||"Yes"})]})]})}):e.jsx(k,{variant:"ghost",size:"fit",className:"rounded-full",onClick:c||d?v:C,disabled:g,children:e.jsx(U,{name:t.icon})})}function ie({button:t}){switch(t.functionality){case"close-widget":return e.jsx(Vt,{button:t});case"expand-shrink":return e.jsx(ne,{button:t});case"resolve-session":return e.jsx(mt,{button:t});default:return M.isExhaustive(t,ie.name),null}}const Gt={functionality:"close-widget",hideOnLargeScreen:!0,icon:"X"};function Kt(){const{routerState:{screen:t}}=l.useWidgetRouter(),{headerButtons:o}=l.useConfig(),s=t==="chat"?o==null?void 0:o.chatScreen:t==="sessions"?o==null?void 0:o.sessionsScreen:[];return!s||s.length===0?e.jsx(ie,{button:Gt}):e.jsx(e.Fragment,{children:s.map(r=>e.jsx(ie,{button:r},`${r.functionality}-${r.icon}`))})}function ut(){const{routerState:{screen:t}}=l.useWidgetRouter(),o=Xt(t),s=pe();return e.jsx("header",{...o,className:"py-2 px-4 shrink-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{}),e.jsx("div",{className:p("flex-1 h-8 flex items-center",t==="sessions"&&"ps-2"),children:e.jsx("h2",{className:"font-semibold",children:s})}),e.jsx(Kt,{})]})})}function gt({className:t}){return e.jsx(m.LoaderIcon,{className:p("size-4 animate-spin",t)})}function Zt(){const{messagesState:{isInitialFetchLoading:t}}=l.useMessages(),{isSmallScreen:o}=E(),{activeMode:s,Component:r}=l.useModes();return{isCanvasOpen:!t&&!o&&!!s&&!!r}}function Qt(){const{activeMode:t,Component:o}=l.useModes(),{sendMessage:s}=l.useMessages(),{createStateCheckpoint:r}=l.useSessions(),[n,a]=h.useState(!1),i=async d=>{try{a(!0),await s(d)}catch(c){console.error(c)}finally{a(!1)}};return!t||!o?null:e.jsx(o,{react:h,mode:t,createStateCheckpoint:r,sendMessage:i,isSendingMessage:n})}const O=h.forwardRef((t,o)=>{var s,r,n;return e.jsx(f,{...t,ref:o,className:p("overflow-hidden",t.className),overrides:{initial:{height:0,opacity:0,...(s=t.overrides)==null?void 0:s.initial},animate:{height:"auto",opacity:1,...(r=t.overrides)==null?void 0:r.animate},exit:{height:0,opacity:0,...(n=t.overrides)==null?void 0:n.exit}}})});O.displayName="MotionDiv__VerticalReveal";const Jt=[{label:"Terrible",value:1,emoji:"😡"},{label:"Poor",value:2,emoji:"😞"},{label:"Okay",value:3,emoji:"😐"},{label:"Good",value:4,emoji:"😊"},{label:"Great",value:5,emoji:"😍"}];function es(){const{isSmallScreen:t}=E(),{submitCsat:o,isCsatRequested:s,isCsatSubmitted:r,submittedScore:n,submittedFeedback:a}=l.useCsat(),[i,d]=h.useState(null),[c,u]=h.useState(null),y=g=>{d(C=>C===g?null:g)},x=()=>{i&&o({score:i,feedback:c||void 0})};return!s&&!r?null:e.jsxs("div",{className:"w-1/2 min-w-80 max-w-96 mx-auto overflow-hidden",children:[e.jsx(j.AnimatePresence,{mode:"wait",children:s&&!i?e.jsx(O,{children:e.jsx("p",{className:"text-sm text-muted-foreground text-center pt-2",children:"How was your conversation?"})},"csat-requested-title"):r?e.jsx(O,{children:e.jsx("p",{className:"text-sm text-muted-foreground text-center pt-2",children:"You rated the conversation as"})},"csat-submitted-title"):null}),e.jsx("div",{className:p("flex gap-4 justify-between pt-2 px-2 pb-2","transition-all",r&&"gap-0 justify-center"),children:Jt.map(g=>e.jsx(k,{variant:g.value===i?"secondary":"ghost",size:"selfless",className:p("transition-all overflow-hidden","text-2xl size-8 rounded-full","opacity-35","hover:opacity-100",!i&&"opacity-100",g.value===i&&"opacity-100",r&&g.value!==n&&"opacity-0 size-0",r&&g.value===n&&"opacity-100 size-fit text-4xl"),onClick:s?()=>y(g.value):void 0,children:g.emoji},g.value))}),e.jsx(j.AnimatePresence,{mode:"wait",children:(i||n)&&e.jsx(O,{children:e.jsxs("div",{className:"pb-2 px-2 flex items-end",children:[e.jsx("textarea",{rows:3,className:p("transition-all","max-h-40 [field-sizing:content]","w-full resize-none","bg-transparent outline-none","placeholder:text-muted-foreground",t?"text-[16px]":"text-sm",r&&"text-center"),value:r?a||"":c||"",onChange:s?g=>u(g.target.value):void 0,readOnly:r,placeholder:s?"Tell us more... (optional)":void 0}),e.jsx(k,{size:"fit",onClick:x,disabled:!i,className:p("transition-all overflow-hidden","rounded-full size-8 flex items-center justify-center p-0",r&&"opacity-0 size-0"),children:e.jsx(m.ArrowUpIcon,{className:"size-4"})})]})},"feedback-box")}),e.jsx("div",{className:p("h-0 transition-[height]",r&&"h-4")})]})}const ts={"write-a-message":"اكتب رسالة...","session-closed-lead":"تم حل مشكلتك!","new-conversation":"محادثة جديدة","welcome-title":"مرحبًا بك في دردشة الدعم الخاصة بنا","welcome-description":"نحن هنا للمساعدة! ابدأ محادثة وسنرد عليك في أقرب وقت ممكن.","your-name":"اسمك","your-email":"عنوان بريدك الإلكتروني","start-chat":"تحدث إلى الدعم","starting-chat":"جاري الاتصال...","i-need-more-help":"أحتاج المزيد من المساعدة","this-was-helpful":"كان هذا مفيدًا",optional:"اختياري","no-conversations-yet":"لا يوجد محادثات","back-to-conversations":"العودة إلى المحادثات","closed-conversations":"المحادثات المغلقة"},ss={"write-a-message":"Nachricht schreiben...","session-closed-lead":"Ihr Problem wurde gelöst!","new-conversation":"Neue Konversation","welcome-title":"Willkommen in unserem Support-Chat","welcome-description":"Wir sind hier, um zu helfen! Beginnen Sie ein Gesprách und wir werden so schnell wie mogelijk antworten.","your-name":"Ihr Name","your-email":"Ihre E-Mail-Adresse","start-chat":"Mit dem Support sprechen","starting-chat":"Verbindung wird hergestellt...","i-need-more-help":"Ich brauche weitere Hilfe","this-was-helpful":"Dies war hilfreich",optional:"Optional","no-conversations-yet":"noch keine Gespräche","back-to-conversations":"Zurück zur Konversationen","closed-conversations":"Geschlossene Konversationen"},os={"write-a-message":"Write a message...","session-closed-lead":"Your issue has been resolved!","new-conversation":"New conversation","welcome-title":"Welcome to our support chat","welcome-description":"We're here to help! Start a conversation and we'll get back to you as soon as possible.","your-name":"Your name","your-email":"Your email address","start-chat":"Talk to support","starting-chat":"Connecting...","i-need-more-help":"I need more help","this-was-helpful":"This was helpful",optional:"Optional","no-conversations-yet":"No conversations yet","back-to-conversations":"Back to conversations","closed-conversations":"Closed conversations"},rs={"write-a-message":"Écrivez un message...","session-closed-lead":"Votre problème a été résolu !","new-conversation":"Nouvelle conversation","welcome-title":"Bienvenue dans notre chat de support","welcome-description":"Nous sommes là pour vous aider ! Commencez une conversation et nous vous répondrons dès que possible.","your-name":"Votre nom","your-email":"Votre adresse e-mail","start-chat":"Parler au support","starting-chat":"Connexion...","i-need-more-help":"Je besoin d'aide plus","this-was-helpful":"C'était utile",optional:"Optionnel","no-conversations-yet":"Aucune conversation pour le moment","back-to-conversations":"Retour aux conversations","closed-conversations":"Conversations fermées"},ns={"write-a-message":"Schrijf een bericht...","session-closed-lead":"Uw probleem is opgelost!","new-conversation":"Nieuw gesprek","welcome-title":"Welkom bij onze supportchat","welcome-description":"We zijn hier om te helpen! Begin een gesprek en we nemen zo snel mogelijk contact met u op.","your-name":"Uw naam","your-email":"Uw e-mailadres","start-chat":"Praat met ondersteuning","starting-chat":"Verbinding maken...","i-need-more-help":"Ik heb nog meer hulp nodig","this-was-helpful":"Mijn vraag is opgelost",optional:"Optioneel","no-conversations-yet":"Nog geen gesprekken","back-to-conversations":"Terug naar gesprekken","closed-conversations":"Afgesloten gesprekken"},is={"write-a-message":"Escreva uma mensagem...","session-closed-lead":"Seu problema foi resolvido!","new-conversation":"Nova conversa","welcome-title":"Bem-vindo ao nosso chat de suporte","welcome-description":"Estamos aqui para ajudar! Inicie uma conversa e responderemos o mais rápido possível.","your-name":"Seu nome","your-email":"Seu endereço de email","start-chat":"Falar com o suporte","starting-chat":"Conectando...","i-need-more-help":"preciso de mais ajuda","this-was-helpful":"Isso foi útil",optional:"Opcional","no-conversations-yet":"Nenhuma conversa ainda","back-to-conversations":"Voltar para conversas","closed-conversations":"Conversas fechadas"},as={"write-a-message":"Escribe un mensaje...","session-closed-lead":"¡Tu problema fue resuelto!","new-conversation":"Nueva conversación","welcome-title":"Bienvenido a nuestro chat de soporte","welcome-description":"¡Estamos aquí para ayudarte! Inicia una conversación y responderemos lo antes posible.","your-name":"Tu nombre","your-email":"Tu correo electrónico","start-chat":"Hablar con soporte","starting-chat":"Conectando...","i-need-more-help":"Necesito más ayuda","this-was-helpful":"Esto fue útil",optional:"Opcional","no-conversations-yet":"Sin conversaciones aún","back-to-conversations":"Volver a conversaciones","closed-conversations":"Conversaciones cerradas"},ls={"write-a-message":"Bir mesaj yazın...","session-closed-lead":"Sorununuz çözüldü!","new-conversation":"Yeni konuşma","welcome-title":"Destek sohbetimize hoş geldiniz","welcome-description":"Yardım etmek için buradayız! Bir konuşma başlatın, en kısa sürede size geri döneceğiz.","your-name":"Adınız","your-email":"E-posta adresiniz","start-chat":"Destekle konuş","starting-chat":"Bağlanıyor...","i-need-more-help":"Daha fazla yardıma ihtiyacım var","this-was-helpful":"Bu yardımcı oldu",optional:"İsteğe bağlı","no-conversations-yet":"Henüz konuşma yok","back-to-conversations":"Konuşmalara geri dön","closed-conversations":"Kapatılan konuşmalar"},wt={en:os,ar:ts,nl:ns,fr:rs,de:ss,pt:is,es:as,tr:ls},cs=Object.keys(wt);function ds(t){return cs.includes(t)}function ps(t,o){const s=wt[o];return s&&s[t]||""}function B(){const{dir:t}=l.useDocumentDir(),o=l.useConfig();return h.useMemo(()=>{const s=ds(o.language)?o.language:"en";return{t:r=>ps(r,s),language:s,dir:s==="ar"?"rtl":"ltr",hostDocumentDir:t}},[o.language,t])}function he({suggestion:t,className:o,...s}){const{sendMessage:r}=l.useMessages(),n=()=>{const a=t.trim();a&&r({content:a})};return e.jsx(k,{...w("chat/suggested_reply_btn"),size:"sm",className:p("rounded-xl w-fit",o),...s,onClick:n,children:t})}function hs(){const{t}=B(),o=[t("i-need-more-help"),t("this-was-helpful")];return e.jsx("div",{...w("chat/might_solve_user_issue_suggested_replies_container"),className:"flex items-center gap-2 p-2 pb-0 flex-wrap",children:o.map(s=>e.jsx(he,{suggestion:s,className:"flex-1"},s))})}function ms({file:{status:t,file:o,error:s},onCancel:r}){const[n,a]=h.useState(null);h.useEffect(()=>{if(!o.type.startsWith("image/"))return;const c=new FileReader;return c.onload=()=>a(c.result),c.onerror=()=>console.error("Error reading file"),c.readAsDataURL(o),()=>c.abort()},[o]);const i=()=>{switch(t){case"uploading":return e.jsx(m.Loader2,{className:"size-4 animate-spin"});case"error":return e.jsx(m.AlertCircle,{className:"size-4 text-destructive"});default:return null}},d=()=>{const c=o.type.split("/")[0];return c==="image"&&n?e.jsx("img",{src:typeof n=="string"?n:"",className:"object-cover bg-secondary size-full",alt:o.name}):c==="audio"?e.jsx(m.FileAudio2Icon,{}):c==="video"?e.jsx(m.FileVideo2Icon,{}):e.jsx(m.FileIcon,{})};return e.jsx(X,{side:"bottom",content:t==="error"?e.jsxs("span",{className:"text-destructive",children:["Failed to upload: ",s]}):o.name,children:e.jsxs("div",{className:p(t==="uploading"&&"opacity-50","group","size-12 border rounded-2xl overflow-hidden relative","flex items-center justify-center shrink-0"),children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i()}),e.jsx("button",{type:"button",className:p("absolute bg-black/50 inset-0 size-full z-10 opacity-0","flex items-center justify-center","opacity-0 group-hover:opacity-100 transition"),onClick:r,children:e.jsx(m.XIcon,{className:"size-4 text-primary-foreground"})}),e.jsx(d,{})]})})}function us(){var D;const{isSmallScreen:t}=E(),o=h.useRef(null),{sendMessage:s}=l.useMessages(),{sessionState:r}=l.useSessions(),{t:n}=B(),[a,i]=h.useState(""),{allFiles:d,emptyTheFiles:c,handleCancelUpload:u,appendFiles:y,isUploading:x,successFiles:g}=l.useUploadFiles(),C=!!((D=r.session)!=null&&D.isHandedOff),{isAwaitingBotReply:v}=l.useIsAwaitingBotReply(),N=b=>{y(b)},I=!a.trim()&&g.length===0,_=async()=>{if(v||I)return;x&&console.info("please wait for the file(s) to upload");const b=a.trim();s({content:b,attachments:g.flatMap(z=>z.fileUrl?[{url:z.fileUrl,type:z.file.type,name:z.file.name,id:z.id,size:z.file.size}]:[])}),i(""),c()},{getRootProps:T,getInputProps:P,open:R}=It.useDropzone({onDrop:N,noClick:!0,onDropRejected(){console.error("unsupported file type, or the file is too large")},maxSize:5*1024*1024,accept:C?{"text/*":[".txt"],"image/*":[".png",".jpg",".jpeg",".gif"],"application/pdf":[".pdf"]}:{"image/png":[".png"],"image/jpeg":[".jpg",".jpeg"],"image/gif":[".gif"],"image/webp":[".webp"]}}),A=b=>{const z=b.clipboardData;z&&z.files.length>0&&N(Array.from(z.files))};return e.jsxs("div",{...w("chat/input_box/root"),className:"p-2 relative space-y-1",...T(),children:[e.jsx("input",{...P()}),e.jsxs("div",{...w("chat/input_box/inner_root"),className:p("transition-all","bg-white","relative rounded-3xl flex flex-col gap-2 p-2","hover:border-primary focus-within:border-primary"),children:[e.jsxs("div",{...w("chat/input_box/textarea_and_attachments_container"),className:"flex flex-col gap-2",children:[d.length>0&&e.jsx("div",{...w("chat/input_box/attachments_container"),className:"flex items-center gap-1",children:e.jsx(j.AnimatePresence,{mode:"popLayout",children:d.map(b=>e.jsx(f,{snapExit:!0,children:e.jsx(ms,{onCancel:()=>u(b.id),file:b})},b.id))})}),e.jsx("textarea",{...w("chat/input_box/textarea"),onPaste:A,ref:o,id:"chat-input",value:a,rows:3,className:p("max-h-16 [field-sizing:content]","w-full resize-none px-2",d.length===0&&"pt-1","bg-transparent outline-none","placeholder:text-muted-foreground",t?"text-[16px]":"text-sm"),onChange:b=>i(b.target.value),onKeyDown:async b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),_())},placeholder:n("write-a-message")})]}),e.jsxs("div",{className:"gap-2 flex justify-between",children:[e.jsx(X,{side:"top",align:"start",content:"attach files, (maximum size 5mb)",children:e.jsx(k,{onClick:R,size:"fit",variant:"ghost",className:p("rounded-full size-8 flex items-center justify-center p-0 overflow-hidden"),children:e.jsx(j.AnimatePresence,{mode:"wait",children:C?e.jsx(f,{children:e.jsx(m.PaperclipIcon,{className:"size-4"})},"paper-clip"):e.jsx(f,{children:e.jsx(m.ImageIcon,{className:"size-4"})},"image-icon")})})}),e.jsx(X,{content:"send message",side:"top",align:"end",children:e.jsx(k,{size:"fit",onClick:_,disabled:v||x||I,className:"rounded-full size-8 flex items-center justify-center p-0",children:e.jsx(j.AnimatePresence,{mode:"wait",children:v||x?e.jsx(f,{snapExit:!0,children:e.jsx(m.CircleDashed,{className:"size-4 animate-spin animate-iteration-infinite"})},"loading"):e.jsx(f,{snapExit:!0,children:e.jsx(m.ArrowUpIcon,{className:"size-4"})},"send")})})})]})]})]})}function Ue(){const{widgetCtx:t}=l.useWidget(),{router:o}=l.useConfig(),{canCreateNewSession:s}=l.useSessions(),{toSessionsScreen:r}=l.useWidgetRouter(),{t:n}=B();return e.jsx(e.Fragment,{children:s||o!=null&&o.chatScreenOnly?e.jsx(k,{onClick:t.resetChat,className:"rounded-2xl w-full",children:n("new-conversation")}):e.jsx(k,{onClick:r,className:"rounded-2xl w-full",children:n("back-to-conversations")})})}function gs(){const{t}=B(),{isCsatRequested:o,isCsatSubmitted:s}=l.useCsat();return e.jsx("div",{className:"p-2",children:e.jsx("div",{className:"p-2 bg-muted rounded-3xl",children:e.jsx(j.AnimatePresence,{mode:"wait",children:o||s?e.jsxs(O,{children:[e.jsx(es,{}),e.jsx(j.AnimatePresence,{mode:"wait",children:s&&e.jsx(O,{children:e.jsx(Ue,{})},"new-conv-or-back-to-convs-button")})]},"csat"):e.jsxs(O,{children:[e.jsxs("div",{className:"ps-2 flex items-center gap-1 pb-2",children:[e.jsx(m.CircleCheckIcon,{className:"size-4 text-emerald-600"}),e.jsx("h2",{className:"text-sm font-medium",children:t("session-closed-lead")})]}),e.jsx(Ue,{})]},"session-closed")})})})}function ws(){var i;const{initialQuestions:t,initialQuestionsPosition:o,thisWasHelpfulOrNot:s}=l.useConfig(),{sessionState:r}=l.useSessions(),{messagesState:n}=l.useMessages(),a=n.messages.length===0;return e.jsx("footer",{children:e.jsx("div",{children:e.jsx(j.AnimatePresence,{mode:"wait",children:r.session&&!((i=r.session)!=null&&i.isOpened)?e.jsx(O,{children:e.jsx(gs,{})},"session-closed"):e.jsxs(O,{children:[n.lastAIResMightSolveUserIssue&&(s==null?void 0:s.enabled)!==!1&&e.jsx(hs,{}),a&&t&&o!=="below-initial-messages"&&e.jsx("div",{className:"flex items-center flex-row justify-end gap-2 flex-wrap px-2",children:t==null?void 0:t.map((d,c)=>e.jsx(he,{suggestion:d},`${d}-${c}`))}),e.jsx(us,{})]},"chat-input")})})})}function fs({isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s,...r}){const{componentStore:n}=l.useWidget();if(r.type!=="AGENT"&&r.type!=="AI")return null;if(r.data.action){const i=n.getComponent(r.data.action.name);if(i)return e.jsx(i,{...r,id:r.id,isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s})}const a=n.getComponent(r.component);return a?e.jsx(a,{...r,id:r.id,isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s}):e.jsx(oe,{...r,isFirstInGroup:t,isLastInGroup:o,isAloneInGroup:s})}function ft({messages:t,className:o,containerClassName:s}){var i,d;const{timestamps:r}=l.useConfig();if(!((i=r==null?void 0:r.perMessageGroup)!=null&&i.enabled))return null;const n=(d=t[t.length-1])==null?void 0:d.timestamp;if(!n)return null;const a=(()=>{try{return new Date(n).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!0})}catch(c){return console.error(c),null}})();return a?e.jsx("div",{className:s,children:e.jsx("span",{className:p("text-xs text-muted-foreground",o),children:a})}):null}function me({messages:t,agent:o,suggestedReplies:s}){return e.jsxs("div",{...w("chat/agent_msg_group/root"),className:p("flex items-end gap-2"),children:[e.jsx(X,{content:o==null?void 0:o.name,side:"right",align:"end",children:e.jsx(re,{...w("chat/agent_msg_group/root/avatar"),agent:o,className:"hidden"})}),e.jsxs("div",{className:p("flex-1 flex flex-col gap-1"),children:[e.jsxs("div",{...w("chat/agent_msg_group/avatar_and_msgs/root"),className:p("flex items-end gap-2"),children:[e.jsx(X,{content:o==null?void 0:o.name,side:"right",align:"end",children:e.jsx(re,{...w("chat/agent_msg_group/avatar_and_msgs/avatar"),agent:o})}),e.jsxs("div",{...w("chat/agent_msg_group/avatar_and_msgs/msgs"),className:p("flex-1 flex flex-col gap-1"),children:[t.map((r,n,a)=>e.jsx(fs,{isFirstInGroup:n===0,isLastInGroup:n===a.length-1,isAloneInGroup:a.length===1,...r},r.id)),e.jsx(ft,{messages:t})]})]}),s&&s.length>0&&e.jsx("div",{...w("chat/agent_msg_group/suggestions"),className:p("flex flex-col gap-1 ps-8"),children:s==null?void 0:s.map((r,n)=>e.jsx(he,{suggestion:r},`${r}-${n}`))})]})]})}function xs(){var n;const{widgetCtx:{org:t}}=l.useWidget(),{sessionState:{session:o}}=l.useSessions(),s=l.useConfig();if(o!=null&&o.isOpened||!o)return null;const r=(n=s.specialComponents)==null?void 0:n.onSessionResolved;return r?e.jsx(r,{react:h,session:o,config:s,org:t}):null}function vs({message:t,isFirstInGroup:o,isLastInGroup:s,isAloneInGroup:r}){var n;return e.jsxs("div",{...w("chat/user_msg/root"),className:"w-5/6 flex flex-col items-end gap-1",children:[t.attachments&&t.attachments.length>0&&e.jsx("div",{className:"w-full flex gap-1 flex-wrap justify-end",children:(n=t.attachments)==null?void 0:n.map(a=>e.jsx(it,{attachment:a},a.id))}),t.content.length>0&&e.jsx("div",{...w("chat/user_msg/msg"),"data-first":o,"data-last":s,"data-alone":r,className:p("transition-all","w-fit py-3 px-4 rounded-3xl text-sm","bg-primary text-primary-foreground","break-words [word-break:break-word]","whitespace-pre-wrap",o&&!r&&"rounded-br-md",s&&!r&&"rounded-tr-md",!o&&!s&&!r&&"rounded-r-md"),children:t.content})]})}function bs({messages:t}){return e.jsxs("div",{...w("chat/user_msg_group/root"),className:p("group","flex flex-col gap-1 justify-end items-end"),children:[t.map((o,s,r)=>e.jsx(vs,{message:o,isFirstInGroup:s===0,isLastInGroup:s===r.length-1,isAloneInGroup:r.length===1},o.id)),e.jsx(ft,{messages:t,containerClassName:"ms-auto"})]})}function ys(t){const o=[];let s=null;return t.forEach(r=>{var n,a,i,d,c,u;(!s||((n=s[0])==null?void 0:n.type)!==r.type)&&(s=[],o.push(s)),((a=s[0])==null?void 0:a.type)==="AGENT"&&r.type==="AGENT"&&(((i=r.agent)==null?void 0:i.id)!==((d=s[0].agent)==null?void 0:d.id)||((c=r.agent)==null?void 0:c.name)!==((u=s[0].agent)==null?void 0:u.name))&&(s=[],o.push(s)),s.push(r)}),o}function js(t){var o;return((o=t==null?void 0:t[0])==null?void 0:o.type)==="USER"}function ks(t){var o;return((o=t==null?void 0:t[0])==null?void 0:o.type)==="AI"}function Cs(t){var o;return((o=t==null?void 0:t[0])==null?void 0:o.type)==="AGENT"}function zs(){const{messagesState:{messages:t}}=l.useMessages(),{advancedInitialMessages:o=[],initialQuestionsPosition:s,initialQuestions:r,bot:n}=l.useConfig();return e.jsx(e.Fragment,{children:t.length===0&&o.length>0&&e.jsx(me,{messages:o.map(({message:a},i)=>({component:"bot_message",data:{message:a},id:`${i}-${a}`,type:"AI",timestamp:null})),suggestedReplies:t.length===0&&s==="below-initial-messages"?r:void 0,agent:n?{...n,isAi:!0,id:null}:void 0})})}function Ss(){const{messagesState:{messages:t}}=l.useMessages(),{chatBannerItems:o}=l.useConfig();return!(o!=null&&o.length)||t.length>0&&o.every(s=>!s.persistent)?null:e.jsx("div",{className:"w-full text-center text-xs",children:o.map(({message:s,persistent:r},n)=>t.length>0&&!r?null:e.jsx("div",{children:e.jsx(lt,{children:s})},`${s}-${n}`))})}function Ns(){const{messagesState:{messages:t}}=l.useMessages(),o=l.useConfig(),{advancedInitialMessages:s=[],initialQuestions:r,initialQuestionsPosition:n}=o,a=(()=>{var i;return s.length?[]:t.length?[]:(i=o.initialMessages)!=null&&i.length?o.initialMessages:["Hello, how can I help you?"]})();return e.jsx(e.Fragment,{children:t.length===0&&a.length>0&&e.jsx(me,{messages:a.map((i,d)=>({component:"bot_message",data:{message:i},id:`${d}-${i}`,type:"AI",timestamp:null})),suggestedReplies:n==="below-initial-messages"?r:void 0,agent:o.bot?{...o.bot,isAi:!0,id:null}:void 0})})}function _s(){const{messagesState:{messages:t}}=l.useMessages(),{isAwaitingBotReply:o}=l.useIsAwaitingBotReply(),{componentStore:s}=l.useWidget(),r=l.useConfig(),n=h.useMemo(()=>ys(t),[t]),a=s.getComponent("loading"),i=h.useRef(null);function d(){setTimeout(()=>{const c=i.current;c&&(c.scrollTop=c.scrollHeight)},0)}return h.useEffect(()=>{d()},[t]),e.jsxs("div",{...w("chat/msgs/root"),ref:i,className:"max-h-full scroll-smooth relative flex-1 py-2 px-4 flex flex-col gap-2 overflow-auto",children:[e.jsx(Ss,{}),e.jsx(zs,{}),e.jsx(Ns,{}),n.map(c=>{var x,g,C;const u=(x=c==null?void 0:c[0])==null?void 0:x.type,y=(g=c[0])==null?void 0:g.id;if(!u||!y)return null;if(js(c))return e.jsx(bs,{messages:c},y);if(ks(c)||Cs(c)){const v=(C=c[0])==null?void 0:C.agent;return e.jsx(me,{messages:c,agent:v},y)}return null}),o&&a&&e.jsx(a,{agent:r.bot}),e.jsx(xs,{})]})}function Is(){const{messagesState:{isInitialFetchLoading:t}}=l.useMessages(),{sessionState:{session:o}}=l.useSessions(),{isCanvasOpen:s}=Zt(),{theme:r}=q();de({width:s?r.screens.chat.withCanvas.width:r.screens.chat.width,height:s?r.screens.chat.withCanvas.height:r.screens.chat.height});const n=h.useRef((o==null?void 0:o.id)||"chat").current;return e.jsx("div",{...w("chat/root"),className:p("flex flex-col overflow-hidden"),style:{width:"100vw",maxWidth:"100vw",height:"100vh",maxHeight:"100vh"},children:e.jsxs("div",{className:"size-full justify-between flex flex-col",children:[e.jsx(ut,{}),e.jsx(j.AnimatePresence,{mode:"wait",children:t?e.jsx(f,{className:"flex flex-col items-center justify-center w-full flex-1",children:e.jsx(gt,{})},"loading"):e.jsxs(f,{className:"flex items-start h-full flex-1 overflow-auto",snapExit:!0,children:[e.jsxs("div",{...w("chat/main/root"),className:p("flex flex-col h-full overflow-auto transition-all",s?"w-2/5":"w-full"),style:{transitionTimingFunction:r.screens.chat.withCanvas.transitionTimingFunction,transitionDuration:r.screens.chat.withCanvas.transitionDuration},children:[e.jsx(_s,{}),e.jsx(ws,{})]}),e.jsx("div",{...w("chat/canvas/root"),className:p("h-full overflow-auto transition-all",s?"w-3/5":"w-0"),style:{transitionTimingFunction:r.screens.chat.withCanvas.transitionTimingFunction,transitionDuration:r.screens.chat.withCanvas.transitionDuration},children:e.jsx(Qt,{})})]},n)})]})})}function Ts({className:t,...o}){return e.jsx("div",{className:p("animate-pulse rounded-md bg-secondary",t),...o})}function Ms({className:t}){return e.jsx("svg",{width:"26",height:"32",viewBox:"0 0 26 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:p("text-primary-foreground",t),children:e.jsx("path",{d:"M1.34103 25.6132H5.44245C5.74203 25.6228 6.02673 25.7462 6.23867 25.9582C6.45062 26.1703 6.5739 26.4551 6.58348 26.7548V30.8584C6.59305 31.1581 6.71634 31.443 6.92828 31.655C7.14023 31.8671 7.42492 31.9904 7.7245 32H18.2894C18.589 31.9904 18.8737 31.8671 19.0856 31.655C19.2976 31.443 19.4209 31.1581 19.4304 30.8584V26.7548C19.4401 26.4545 19.5638 26.1692 19.7765 25.957C19.9892 25.7449 20.2748 25.6219 20.5749 25.6132H24.659C24.9586 25.6036 25.2433 25.4803 25.4552 25.2682C25.6671 25.0562 25.7904 24.7713 25.8 24.4716V7.52839C25.7904 7.22865 25.6671 6.94381 25.4552 6.73176C25.2433 6.5197 24.9586 6.39635 24.659 6.38677H20.561C20.2603 6.37802 19.9742 6.25457 19.7614 6.04169C19.5487 5.82881 19.4253 5.54261 19.4165 5.24168V1.14161C19.4072 0.84419 19.2858 0.561291 19.0768 0.349589C18.8678 0.137887 18.5865 0.0130193 18.2894 0L7.7245 0C7.42492 0.00957792 7.14023 0.132929 6.92828 0.344983C6.71634 0.557036 6.59305 0.841878 6.58348 1.14161V5.24168C6.57477 5.54203 6.45187 5.82773 6.23983 6.04052C6.0278 6.25331 5.74262 6.37715 5.44245 6.38677H1.34103C1.04144 6.39635 0.756749 6.5197 0.544805 6.73176C0.332861 6.94381 0.209574 7.22865 0.200001 7.52839V24.4716C0.209574 24.7713 0.332861 25.0562 0.544805 25.2682C0.756749 25.4803 1.04144 25.6036 1.34103 25.6132ZM6.58348 24.4716V7.52839C6.59305 7.22865 6.71634 6.94381 6.92828 6.73176C7.14023 6.5197 7.42492 6.39635 7.7245 6.38677H18.2894C18.589 6.39635 18.8737 6.5197 19.0856 6.73176C19.2976 6.94381 19.4209 7.22865 19.4304 7.52839V24.4716C19.4209 24.7713 19.2976 25.0562 19.0856 25.2682C18.8737 25.4803 18.589 25.6036 18.2894 25.6132H7.7245C7.42492 25.6036 7.14023 25.4803 6.92828 25.2682C6.71634 25.0562 6.59305 24.7713 6.58348 24.4716Z",fill:"currentColor"})})}function xt({className:t}){const{token:o}=l.useConfig();return e.jsx("div",{className:p("flex items-center justify-center gap-2 p-2 pt-0",t),children:e.jsx(W,{children:e.jsxs("a",{href:`https://open.cx/?ref=${o}`,target:"_blank",rel:"noreferrer",className:p("text-[10px] flex items-center","text-muted-foreground/70 [&_svg]:text-muted-foreground/70","hover:text-primary [&_svg]:hover:text-primary"),children:[e.jsx("span",{children:"Powered by"}),e.jsx("span",{children:" "}),e.jsxs("span",{className:"flex items-center gap-[1px]",children:[e.jsx("span",{children:e.jsx(Ms,{className:"size-3 inline-block"})}),e.jsx("span",{className:"font-semibold",children:"open"})]})]})})})}function Ds({children:t}){return e.jsx("p",{className:"ps-4 text-xs text-muted-foreground/75 uppercase font-semibold tracking-tight",children:t})}function Ve({session:t,className:o}){const{bot:s}=l.useConfig(),{toChatScreen:r}=l.useWidgetRouter(),n=t.assignee.kind==="human"?t.assignee.name||"Support Agent":(s==null?void 0:s.name)||"AI Support Agent",a=t.assignee.kind==="human"?t.assignee.avatarUrl||"":(s==null?void 0:s.avatar)||"";return e.jsxs(k,{variant:"ghost",size:"lg",className:p("rounded-full p-2 pe-4 flex text-start justify-between w-full whitespace-normal",o),onClick:()=>r(t.id),children:[e.jsxs("div",{className:"flex-1 flex gap-2 items-center",children:[e.jsx(j.AnimatePresence,{mode:"wait",children:e.jsx(f,{snapExit:!0,children:e.jsxs(ae,{className:"size-10",children:[e.jsx(le,{src:a,alt:"Agent Icon"}),e.jsx(ce,{children:e.jsx(m.UserRoundIcon,{className:"size-4"})})]})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(j.AnimatePresence,{mode:"wait",children:e.jsx(f,{snapExit:!0,children:n},n)}),e.jsx(j.AnimatePresence,{mode:"wait",children:t.lastMessage?e.jsx(f,{snapExit:!0,children:e.jsx(at,{remarkPlugins:[Ge],rehypePlugins:[Ke],className:"line-clamp-1 overflow-hidden text-ellipsis text-xs text-muted-foreground",children:t.lastMessage})},t.lastMessage||"content"):e.jsx(f,{className:"w-1/2",snapExit:!0,children:e.jsx(Ts,{className:"h-4 w-full"})},"skeleton")})]})]}),e.jsx(m.ChevronRightIcon,{className:"size-4 text-muted-foreground shrink-0 rtl:-scale-100"})]})}function Es(){const{t}=B(),{toChatScreen:o}=l.useWidgetRouter(),{sessionsState:{data:s,isInitialFetchLoading:r},openSessions:n,closedSessions:a,canCreateNewSession:i}=l.useSessions();return e.jsx("div",{className:"flex-1 flex flex-col overflow-scroll py-2 px-2",children:e.jsx(j.AnimatePresence,{mode:"wait",children:r?e.jsx(f,{className:"flex-1 flex items-center justify-center",children:e.jsx(gt,{})},"loading"):e.jsx(f,{className:"flex-1 flex flex-col gap-2 relative",children:s.length?e.jsxs(e.Fragment,{children:[e.jsxs(j.AnimatePresence,{children:[n.length>0&&e.jsx(f,{fadeIn:"up",delay:.2,className:"space-y-2",snapExit:!0,children:n.map(d=>e.jsx(Ve,{session:d},d.id))},"open-sessions"),a.length>0&&e.jsxs(f,{className:"space-y-2",delay:.2,snapExit:!0,children:[e.jsx(Ds,{children:t("closed-conversations")}),a.map(d=>e.jsx(Ve,{session:d,className:"opacity-50 hover:opacity-100"},d.id))]},"closed-sessions")]}),i&&e.jsx("div",{className:"mt-auto w-full rounded-3xl sticky bottom-0 outline outline-8 outline-background bg-background",children:h.createElement(k,{...w("sessions/new_conversation_btn"),size:"lg",key:"new-session",className:"w-full",onClick:()=>o()},t("new-conversation"))})]}):e.jsxs("div",{className:"flex-1 flex flex-col gap-2 items-center",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:t("no-conversations-yet")})}),h.createElement(k,{...w("sessions/new_conversation_btn"),size:"lg",key:"new-session",className:"w-full",onClick:()=>o()},t("new-conversation"))]})},"sessions")})})}function Ps(){const{theme:t}=q();return de({width:t.screens.sessions.width,height:t.screens.sessions.height}),e.jsx("div",{...w("sessions/root"),className:p("flex flex-col overflow-hidden bg-background"),style:{width:"100vw",maxWidth:"100vw",height:"100vh",maxHeight:"100vh"},children:e.jsxs("div",{className:"size-full flex flex-col",children:[e.jsx(ut,{}),e.jsx(Es,{}),e.jsx(xt,{})]})})}const Z=Y.forwardRef(({className:t,type:o,...s},r)=>{const{isSmallScreen:n}=E();return e.jsx(W,{ref:r,children:e.jsx("input",{type:o,className:p(n?"text-[16px]":"text-sm","flex w-full rounded-xl p-2 ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-primary-foreground placeholder:text-muted-foreground/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 transition","rounded-2xl px-4","border shadow-sm",t),...s})})});Z.displayName="Input";function Rs(){const{contentIframeRef:t}=l.useWidget(),{inline:o}=l.useConfig(),s=h.useRef(null);return h.useEffect(()=>{const r=t==null?void 0:t.current;if(r&&s.current){const n=s.current;let a;const i=new ResizeObserver(()=>{a=requestAnimationFrame(()=>{const d=n.offsetHeight;r.style.setProperty("--opencx-widget-height",o?"100%":`${d.toFixed(1)}px`)})});return i.observe(n),()=>{cancelAnimationFrame(a),i.unobserve(n)}}},[t,o]),{observedElementRef:s}}const As=se.z.object({name:se.z.string().min(2),email:se.z.string().email()});function Ws(){var _,T,P,R,A,D,b,z;const{widgetCtx:{org:t}}=l.useWidget(),{setIsOpen:o}=l.useWidgetTrigger(),{createUnverifiedContact:s}=l.useContact(),{isSmallScreen:r}=E(),n=l.useConfig(),{theme:a}=q(),{t:i}=B(),{observedElementRef:d}=Rs();de({height:void 0,width:a.screens.welcome.width});const[c,u]=h.useState(((_=n.prefillUserData)==null?void 0:_.name)||""),[y,x]=h.useState(((T=n.prefillUserData)==null?void 0:T.email)||""),g=(n.extraDataCollectionFields||[]).filter(S=>S!=="name"&&S!=="email"&&!!S),[C,v]=h.useState({}),[N,I]=Tt(async S=>{S.preventDefault();const F=As.safeParse({name:c,email:y});F.success&&await s({email:F.data.email,non_verified_name:F.data.name},Object.values(C).filter(Boolean).length?C:void 0)},[c,y,C]);return e.jsx("div",{style:{width:"100vw",maxWidth:"100vw",minHeight:a.screens.welcome.minHeight,height:"100vh",maxHeight:"100vh",overflowY:"auto"},children:e.jsxs("div",{ref:d,className:p("flex flex-col",r&&"h-full","bg-[radial-gradient(ellipse_at_top_left,hsl(var(--opencx-primary)),transparent),radial-gradient(ellipse_at_top_right,hsl(var(--opencx-primary)),transparent)]"),children:[e.jsxs("div",{className:p("flex-1 flex flex-col px-4 py-12 text-start space-y-4 relative z-10","text-primary-foreground"),children:[r&&e.jsx(f,{className:"absolute top-6 end-6",children:e.jsx(k,{size:"selfless",onClick:()=>o(!1),children:e.jsx(m.XIcon,{className:"size-4"})})}),e.jsx("div",{className:"flex items-center justify-between w-full mb-2",children:(P=n.assets)!=null&&P.organizationLogo?e.jsx("img",{src:(R=n.assets)==null?void 0:R.organizationLogo,alt:"Company Logo",className:"h-8 w-auto object-contain"}):e.jsx("h2",{className:"font-bold text-sm",children:t.name})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-[1.75rem] font-semibold tracking-tight leading-none",children:((D=(A=n.textContent)==null?void 0:A.welcomeScreen)==null?void 0:D.title)||i("welcome-title")}),e.jsx("p",{className:"text-sm",children:((z=(b=n.textContent)==null?void 0:b.welcomeScreen)==null?void 0:z.description)||i("welcome-description")})]})]}),e.jsxs("div",{className:p("z-10 m-2 px-2 pt-2 bp-0 space-y-2","bg-[white]","border shadow","rounded-3xl"),children:[e.jsxs("form",{onSubmit:I,className:"space-y-2",children:[e.jsx(Z,{value:c,onChange:S=>u(S.target.value),required:!0,placeholder:i("your-name"),name:"name"}),e.jsx(Z,{required:!0,value:y,onChange:S=>x(S.target.value),type:"email",placeholder:i("your-email"),name:"email"}),g.map(S=>e.jsx(Z,{value:C[S],onChange:F=>v(G=>({...G,[S]:F.target.value})),placeholder:`${S} (${i("optional")})`},S)),e.jsxs(k,{disabled:N.loading,className:"w-full",size:"lg",children:[N.loading?i("starting-chat"):i("start-chat"),e.jsx(m.SendHorizontal,{className:"size-4 rtl:-scale-100"})]})]}),e.jsx(xt,{})]})]})})}function vt(){const{routerState:{screen:t}}=l.useWidgetRouter();return e.jsx("div",{className:"relative bg-background size-full",children:e.jsx(j.AnimatePresence,{mode:"wait",children:(()=>{switch(t){case"welcome":return e.jsx(f,{fadeIn:"right",className:"size-full",snapExit:!0,children:e.jsx(Ws,{})},t);case"sessions":return e.jsx(f,{fadeIn:"right",className:"size-full",snapExit:!0,children:e.jsx(Ps,{})},t);case"chat":return e.jsx(f,{fadeIn:"right",className:"size-full",snapExit:!0,children:e.jsx(Is,{})},t);default:return M.isExhaustive(t,vt.name),null}})()})})}const Os="4.0.17",Fs=`<!DOCTYPE html>
|
|
18
18
|
<html>
|
|
19
19
|
<head>
|
|
20
20
|
<style>
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencx/widget-react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.17",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/openchatai/widget"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
"dist-embed"
|
|
11
|
+
"dist"
|
|
13
12
|
],
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
@@ -38,8 +37,8 @@
|
|
|
38
37
|
"tailwind-merge": "^2.4.0",
|
|
39
38
|
"tinycolor2": "^1.6.0",
|
|
40
39
|
"zod": "^3.23.8",
|
|
41
|
-
"@opencx/widget-core": "4.0.
|
|
42
|
-
"@opencx/widget-react-headless": "4.0.
|
|
40
|
+
"@opencx/widget-core": "4.0.17",
|
|
41
|
+
"@opencx/widget-react-headless": "4.0.17"
|
|
43
42
|
},
|
|
44
43
|
"peerDependencies": {
|
|
45
44
|
"@types/react": ">=18 <20",
|
|
@@ -58,11 +57,9 @@
|
|
|
58
57
|
},
|
|
59
58
|
"scripts": {
|
|
60
59
|
"clean": "rm -rf node_modules dist .turbo",
|
|
61
|
-
"clean:dist": "rm -rf dist
|
|
60
|
+
"clean:dist": "rm -rf dist .turbo",
|
|
62
61
|
"dev": "vite --host",
|
|
63
|
-
"build
|
|
64
|
-
"build:embed": "vite build -c vite.embed.config.ts",
|
|
65
|
-
"build": "pnpm build:lib && pnpm build:embed",
|
|
62
|
+
"build": "vite build -c vite.config.ts",
|
|
66
63
|
"test": "vitest run",
|
|
67
64
|
"cs": "changeset",
|
|
68
65
|
"csv": "changeset version",
|