"use strict";var Al=require("./react-chatbotify.css");Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const q=require("react");function Fu(I){const h=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const T in I)if(T!=="default"){const x=Object.getOwnPropertyDescriptor(I,T);Object.defineProperty(h,T,x.get?x:{enumerable:!0,get:()=>I[T]})}}return h.default=I,Object.freeze(h)}const At=Fu(q);var yu={exports:{}},wi={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var wu;function Wu(){if(wu)return wi;wu=1;var I=q,h=Symbol.for("react.element"),T=Symbol.for("react.fragment"),x=Object.prototype.hasOwnProperty,f=I.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,R={key:!0,ref:!0,__self:!0,__source:!0};function W(U,N,m){var Z,P={},$=null,Me=null;m!==void 0&&($=""+m),N.key!==void 0&&($=""+N.key),N.ref!==void 0&&(Me=N.ref);for(Z in N)x.call(N,Z)&&!R.hasOwnProperty(Z)&&(P[Z]=N[Z]);if(U&&U.defaultProps)for(Z in N=U.defaultProps,N)P[Z]===void 0&&(P[Z]=N[Z]);return{$$typeof:h,type:U,key:$,ref:Me,props:P,_owner:f.current}}return wi.Fragment=T,wi.jsx=W,wi.jsxs=W,wi}var Ti={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Tu;function Vu(){return Tu||(Tu=1,process.env.NODE_ENV!=="production"&&function(){var I=q,h=Symbol.for("react.element"),T=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),f=Symbol.for("react.strict_mode"),R=Symbol.for("react.profiler"),W=Symbol.for("react.provider"),U=Symbol.for("react.context"),N=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),Z=Symbol.for("react.suspense_list"),P=Symbol.for("react.memo"),$=Symbol.for("react.lazy"),Me=Symbol.for("react.offscreen"),te=Symbol.iterator,ne="@@iterator";function H(j){if(j===null||typeof j!="object")return null;var V=te&&j[te]||j[ne];return typeof V=="function"?V:null}var b=I.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function ee(j){{for(var V=arguments.length,_=new Array(V>1?V-1:0),fe=1;fe=1&&Fe>=0&&Se[He]!==nt[Fe];)Fe--;for(;He>=1&&Fe>=0;He--,Fe--)if(Se[He]!==nt[Fe]){if(He!==1||Fe!==1)do if(He--,Fe--,Fe<0||Se[He]!==nt[Fe]){var vt=` `+Se[He].replace(" at new "," at ");return j.displayName&&vt.includes("")&&(vt=vt.replace("",j.displayName)),typeof j=="function"&&tt.set(j,vt),vt}while(He>=1&&Fe>=0);break}}}finally{Lt=!1,Qe.current=Ye,qe(),Error.prepareStackTrace=Ee}var Bt=j?j.displayName||j.name:"",Dt=Bt?Qt(Bt):"";return typeof j=="function"&&tt.set(j,Dt),Dt}function Ze(j,V,_){return Xt(j,!1)}function yt(j){var V=j.prototype;return!!(V&&V.isReactComponent)}function It(j,V,_){if(j==null)return"";if(typeof j=="function")return Xt(j,yt(j));if(typeof j=="string")return Qt(j);switch(j){case m:return Qt("Suspense");case Z:return Qt("SuspenseList")}if(typeof j=="object")switch(j.$$typeof){case N:return Ze(j.render);case P:return It(j.type,V,_);case $:{var fe=j,Ee=fe._payload,Ye=fe._init;try{return It(Ye(Ee),V,_)}catch{}}}return""}var wt=Object.prototype.hasOwnProperty,Jt={},Tt=b.ReactDebugCurrentFrame;function mt(j){if(j){var V=j._owner,_=It(j.type,j._source,V?V.type:null);Tt.setExtraStackFrame(_)}else Tt.setExtraStackFrame(null)}function Kt(j,V,_,fe,Ee){{var Ye=Function.call.bind(wt);for(var me in j)if(Ye(j,me)){var Se=void 0;try{if(typeof j[me]!="function"){var nt=Error((fe||"React class")+": "+_+" type `"+me+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof j[me]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw nt.name="Invariant Violation",nt}Se=j[me](V,me,fe,_,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(He){Se=He}Se&&!(Se instanceof Error)&&(mt(Ee),ee("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",fe||"React class",_,me,typeof Se),mt(null)),Se instanceof Error&&!(Se.message in Jt)&&(Jt[Se.message]=!0,mt(Ee),ee("Failed %s type: %s",_,Se.message),mt(null))}}}var jr=Array.isArray;function St(j){return jr(j)}function ft(j){{var V=typeof Symbol=="function"&&Symbol.toStringTag,_=V&&j[Symbol.toStringTag]||j.constructor.name||"Object";return _}}function at(j){try{return ar(j),!1}catch{return!0}}function ar(j){return""+j}function ur(j){if(at(j))return ee("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ft(j)),ar(j)}var Pt=b.ReactCurrentOwner,_e={key:!0,ref:!0,__self:!0,__source:!0},qt,sr,_t;_t={};function lr(j){if(wt.call(j,"ref")){var V=Object.getOwnPropertyDescriptor(j,"ref").get;if(V&&V.isReactWarning)return!1}return j.ref!==void 0}function $t(j){if(wt.call(j,"key")){var V=Object.getOwnPropertyDescriptor(j,"key").get;if(V&&V.isReactWarning)return!1}return j.key!==void 0}function Ir(j,V){if(typeof j.ref=="string"&&Pt.current&&V&&Pt.current.stateNode!==V){var _=Ve(Pt.current.type);_t[_]||(ee('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',Ve(Pt.current.type),j.ref),_t[_]=!0)}}function cr(j,V){{var _=function(){qt||(qt=!0,ee("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",V))};_.isReactWarning=!0,Object.defineProperty(j,"key",{get:_,configurable:!0})}}function K(j,V){{var _=function(){sr||(sr=!0,ee("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",V))};_.isReactWarning=!0,Object.defineProperty(j,"ref",{get:_,configurable:!0})}}var ue=function(j,V,_,fe,Ee,Ye,me){var Se={$$typeof:h,type:j,key:V,ref:_,props:me,_owner:Ye};return Se._store={},Object.defineProperty(Se._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Se,"_self",{configurable:!1,enumerable:!1,writable:!1,value:fe}),Object.defineProperty(Se,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Ee}),Object.freeze&&(Object.freeze(Se.props),Object.freeze(Se)),Se};function ve(j,V,_,fe,Ee){{var Ye,me={},Se=null,nt=null;_!==void 0&&(ur(_),Se=""+_),$t(V)&&(ur(V.key),Se=""+V.key),lr(V)&&(nt=V.ref,Ir(V,Ee));for(Ye in V)wt.call(V,Ye)&&!_e.hasOwnProperty(Ye)&&(me[Ye]=V[Ye]);if(j&&j.defaultProps){var He=j.defaultProps;for(Ye in He)me[Ye]===void 0&&(me[Ye]=He[Ye])}if(Se||nt){var Fe=typeof j=="function"?j.displayName||j.name||"Unknown":j;Se&&cr(me,Fe),nt&&K(me,Fe)}return ue(j,Se,nt,Ee,fe,Pt.current,me)}}var se=b.ReactCurrentOwner,De=b.ReactDebugCurrentFrame;function Ie(j){if(j){var V=j._owner,_=It(j.type,j._source,V?V.type:null);De.setExtraStackFrame(_)}else De.setExtraStackFrame(null)}var ae;ae=!1;function Re(j){return typeof j=="object"&&j!==null&&j.$$typeof===h}function $e(){{if(se.current){var j=Ve(se.current.type);if(j)return` Check the render method of \``+j+"`."}return""}}function Xe(j){{if(j!==void 0){var V=j.fileName.replace(/^.*[\\\/]/,""),_=j.lineNumber;return` Check your code at `+V+":"+_+"."}return""}}var ut={};function pt(j){{var V=$e();if(!V){var _=typeof j=="string"?j:j.displayName||j.name;_&&(V=` Check the top-level render call using <`+_+">.")}return V}}function Et(j,V){{if(!j._store||j._store.validated||j.key!=null)return;j._store.validated=!0;var _=pt(V);if(ut[_])return;ut[_]=!0;var fe="";j&&j._owner&&j._owner!==se.current&&(fe=" It was passed a child from "+Ve(j._owner.type)+"."),Ie(j),ee('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',_,fe),Ie(null)}}function rt(j,V){{if(typeof j!="object")return;if(St(j))for(var _=0;_",Se=" Did you accidentally export a JSX literal instead of a component?"):He=typeof j,ee("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",He,Se)}var Fe=ve(j,V,_,Ee,Ye);if(Fe==null)return Fe;if(me){var vt=V.children;if(vt!==void 0)if(fe)if(St(vt)){for(var Bt=0;Bt0?"{key: someKey, "+ke.join(": ..., ")+": ...}":"{key: someKey}";if(!Br[Dt+Ut]){var Yt=ke.length>0?"{"+ke.join(": ..., ")+": ...}":"{}";ee(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,Ut,Dt,Yt,Dt),Br[Dt+Ut]=!0}}return j===x?Pr(Fe):Qr(Fe),Fe}}function Ur(j,V,_){return st(j,V,_,!0)}function An(j,V,_){return st(j,V,_,!1)}var on=An,Zt=Ur;Ti.Fragment=x,Ti.jsx=on,Ti.jsxs=Zt}()),Ti}process.env.NODE_ENV==="production"?yu.exports=Wu():yu.exports=Vu();var F=yu.exports;const Lu=q.createContext({botOptions:{},setBotOptions:()=>null}),Gt=()=>q.useContext(Lu);const Gu=({notificationToggledOn:I,audioToggledOn:h,handleToggleNotification:T,handleToggleAudio:x})=>{var m,Z,P,$,Me,te,ne,H,b,ee,de,ye;const{botOptions:f,setBotOptions:R}=Gt(),W={background:`linear-gradient(to right, ${(m=f.theme)==null?void 0:m.secondaryColor}, ${(Z=f.theme)==null?void 0:Z.primaryColor})`,...f.headerStyle},U={headerAvatar:{backgroundImage:`url(${(P=f.header)==null?void 0:P.avatar})`},notificationIcon:{backgroundImage:`url(${($=f.notification)==null?void 0:$.icon})`},audioIcon:{backgroundImage:`url(${(Me=f.audio)==null?void 0:Me.icon})`},closeChatIcon:{backgroundImage:`url(${(te=f.header)==null?void 0:te.closeChatIcon})`}},N=()=>{R({...f,isOpen:!1})};return F.jsxs("div",{style:W,className:"rcb-chat-header-container",children:[F.jsxs("div",{className:"rcb-chat-header",children:[((ne=f.header)==null?void 0:ne.showAvatar)&&F.jsx("div",{style:U.headerAvatar,className:"rcb-bot-avatar"}),(H=f.header)==null?void 0:H.title]}),F.jsxs("div",{className:"rcb-chat-header",children:[!((b=f.notification)!=null&&b.disabled)&&!((ee=f.theme)!=null&&ee.embedded)&&F.jsx("div",{style:U.notificationIcon,onMouseDown:Ae=>{Ae.preventDefault(),T()},className:`rcb-notification-icon-${I?"on":"off"}`}),!((de=f.audio)!=null&&de.disabled)&&F.jsx("div",{style:U.audioIcon,onMouseDown:Ae=>{Ae.preventDefault(),x()},className:`rcb-audio-icon-${h?"on":"off"}`}),!((ye=f.theme)!=null&&ye.embedded)&&F.jsx("div",{style:U.closeChatIcon,onMouseDown:Ae=>{Ae.stopPropagation(),N()},className:"rcb-close-chat-icon"})]})]})};const Zu=({chatBodyRef:I,isScrolling:h,setIsScrolling:T,unreadCount:x})=>{var Me,te,ne;const{botOptions:f}=Gt(),[R,W]=q.useState(!1),U={color:(Me=f.theme)==null?void 0:Me.primaryColor,borderColor:(te=f.theme)==null?void 0:te.primaryColor,...f.chatMessagePromptHoveredStyle},N=()=>{W(!0)},m=()=>{W(!1)};function Z(H){if(!I.current)return;const b=I.current.scrollTop,de=I.current.scrollHeight-I.current.clientHeight-b,ye=20;let Ae=0;function pe(){if(!I.current)return;Ae+=ye;const ce=P(Ae,b,de,H);I.current.scrollTop=ce,Ae(H/=de/2,H<1?ee/2*H*H+b:(H--,-ee/2*(H*(H-2)-1)+b)),$=()=>{var b;return I.current&&((b=f.chatWindow)==null?void 0:b.showMessagePrompt)&&h&&x>0?"visible":"hidden"};return F.jsx("div",{className:`rcb-message-prompt-container ${$()}`,children:F.jsx("div",{onMouseEnter:N,onMouseLeave:m,style:R?U:f.chatMessagePromptStyle,onMouseDown:H=>{H.preventDefault(),Z(600)},className:"rcb-message-prompt-text",children:(ne=f.chatWindow)==null?void 0:ne.messagePromptText})})},Nu=q.createContext({messages:[],setMessages:()=>null}),Qu=()=>q.useContext(Nu);const Xu=({chatBodyRef:I,isBotTyping:h,isLoadingChatHistory:T,chatScrollHeight:x,setChatScrollHeight:f,setIsLoadingChatHistory:R,isScrolling:W,setIsScrolling:U,unreadCount:N,setUnreadCount:m})=>{var ye,Ae,pe,ce,Oe,we,xe,We,be,Ve;const{botOptions:Z}=Gt(),{messages:P}=Qu(),$={...Z==null?void 0:Z.bodyStyle,scrollbarWidth:(ye=Z.chatWindow)!=null&&ye.showScrollbar?"auto":"none"},Me={backgroundColor:(Ae=Z.theme)==null?void 0:Ae.primaryColor,color:"#fff",maxWidth:(pe=Z.userBubble)!=null&&pe.showAvatar?"65%":"70%",...Z.userBubbleStyle},te=(ce=Z.userBubble)!=null&&ce.animate?"rcb-user-message-entry":"",ne={backgroundColor:(Oe=Z.theme)==null?void 0:Oe.secondaryColor,color:"#fff",maxWidth:(we=Z.botBubble)!=null&&we.showAvatar?"65%":"70%",...Z.botBubbleStyle},H=(xe=Z.botBubble)!=null&&xe.animate?"rcb-bot-message-entry":"";q.useEffect(()=>{var Le;if(I.current){if(T){const{scrollHeight:Ue}=I.current,Ke=Ue-x;I.current.scrollTop=I.current.scrollTop+Ke,R(!1);return}((Le=Z.chatWindow)!=null&&Le.autoJumpToBottom||!W)&&(I.current.scrollTop=I.current.scrollHeight,Z.isOpen&&m(0))}},[P.length,h]),q.useEffect(()=>{I.current&&(f(I.current.scrollHeight),W||(I.current.scrollTop=I.current.scrollHeight,Z.isOpen&&m(0)))},[(We=I.current)==null?void 0:We.scrollHeight]),q.useEffect(()=>{W||m(0)},[W]);const b=()=>{var ot;if(!I.current)return;const{scrollTop:Le,clientHeight:Ue,scrollHeight:Ke}=I.current;U(Le+Ue=Ke-1&&(I.current.scrollTop=Ke-Ue-1)},ee=Le=>{var Ue,Ke,ot;return F.jsxs(F.Fragment,{children:[(Ue=Z==null?void 0:Z.userBubble)!=null&&Ue.dangerouslySetInnerHtml?F.jsx("div",{style:{...Me,display:"inline"},className:`rcb-user-message ${te}`,dangerouslySetInnerHTML:{__html:Le.content}}):F.jsx("div",{style:Me,className:`rcb-user-message ${te}`,children:Le.content}),((Ke=Z.userBubble)==null?void 0:Ke.showAvatar)&&F.jsx("div",{style:{backgroundImage:`url(${(ot=Z.userBubble)==null?void 0:ot.avatar})`},className:"rcb-message-user-avatar"})]})},de=Le=>{var Ue,Ke,ot;return F.jsxs(F.Fragment,{children:[((Ue=Z.botBubble)==null?void 0:Ue.showAvatar)&&F.jsx("div",{style:{backgroundImage:`url(${(Ke=Z.botBubble)==null?void 0:Ke.avatar})`},className:"rcb-message-bot-avatar"}),(ot=Z==null?void 0:Z.botBubble)!=null&&ot.dangerouslySetInnerHtml?F.jsx("div",{style:{...ne,display:"inline"},className:`rcb-bot-message ${H}`,dangerouslySetInnerHTML:{__html:Le.content}}):F.jsx("div",{style:ne,className:`rcb-bot-message ${H}`,children:Le.content})]})};return F.jsxs("div",{style:$,className:"rcb-chat-body-container",ref:I,onScroll:b,children:[P.map((Le,Ue)=>typeof Le.content!="string"?F.jsx("div",{children:Le.content},Ue):F.jsx("div",{className:Le.sender==="user"?"rcb-user-message-container":"rcb-bot-message-container",children:Le.sender==="user"?ee(Le):de(Le)},Ue)),h&&F.jsxs("div",{className:"rcb-bot-message-container",children:[((be=Z.botBubble)==null?void 0:be.showAvatar)&&F.jsx("div",{style:{backgroundImage:`url(${(Ve=Z.botBubble)==null?void 0:Ve.avatar})`},className:"rcb-message-bot-avatar"}),F.jsx("div",{onMouseDown:Le=>{Le.preventDefault()},className:`rcb-bot-message ${H}`,children:F.jsxs("div",{className:"rcb-typing-indicator",children:[F.jsx("span",{className:"rcb-dot"}),F.jsx("span",{className:"rcb-dot"}),F.jsx("span",{className:"rcb-dot"})]})})]}),F.jsx(Zu,{chatBodyRef:I,isScrolling:W,setIsScrolling:U,unreadCount:N})]})};const Ju=({handleSubmit:I})=>{var m,Z,P;const{botOptions:h}=Gt(),[T,x]=q.useState(!1),f={backgroundColor:(m=h.theme)==null?void 0:m.primaryColor,...h.sendButtonStyle},R={backgroundColor:(Z=h.theme)==null?void 0:Z.secondaryColor,...h.sendButtonHoveredStyle},W={backgroundImage:`url(${(P=h.chatInput)==null?void 0:P.sendButtonIcon})`},U=()=>{x(!0)},N=()=>{x(!1)};return F.jsx("div",{onMouseEnter:U,onMouseLeave:N,style:T?R:f,onMouseDown:I,className:"rcb-send-button",children:F.jsx("span",{className:"rcb-send-icon",style:W})})},Eu=window.SpeechRecognition||window.webkitSpeechRecognition,nn=Eu!=null?new Eu:null;let Wn,du,To=!1;const Ku=(I,h,T,x,f)=>{var U,N;if(!nn)return;To||(To=!0,nn.start());const R=(U=I.voice)==null?void 0:U.timeoutPeriod,W=(N=I.voice)==null?void 0:N.autoSendPeriod;nn.onresult=m=>{var P,$;clearTimeout(Wn),Wn=null,clearTimeout(du);const Z=m.results[m.results.length-1][0].transcript;if(f.current){const Me=(P=I.chatInput)==null?void 0:P.characterLimit,te=f.current.value+Z;Me!=null&&Me>=0&&te.length>Me?f.current.value=te.slice(0,Me):f.current.value=te,x(f.current.value.length)}Wn=setTimeout(()=>gu(h),R),($=I.voice)!=null&&$.autoSendDisabled||(du=setTimeout(T,W))},nn.onend=()=>{To?(nn.start(),Wn||(Wn=setTimeout(()=>gu(h),R))):(clearTimeout(Wn),Wn=null,clearTimeout(du))},Wn=setTimeout(()=>gu(h),R)},ju=()=>{nn&&(To=!1,nn&&nn.stop())},Mu=(I,h)=>{var T,x;(T=h.voice)!=null&&T.disabled||!((x=h.chatInput)!=null&&x.blockSpam)||!nn||(I&&!To?(To=!0,nn.start()):I||ju())},gu=I=>{I(),ju()};const qu=({inputRef:I,textAreaDisabled:h,voiceToggledOn:T,handleToggleVoice:x,triggerSendVoiceInput:f,setInputLength:R})=>{var U;const{botOptions:W}=Gt();return q.useEffect(()=>{T?Ku(W,x,f,R,I):ju()},[T]),F.jsx("div",{onMouseDown:N=>{N.preventDefault(),x()},className:T&&!h?"rcb-voice-button-enabled":"rcb-voice-button-disabled",children:F.jsx("span",{className:T&&!h?"rcb-voice-icon-on":"rcb-voice-icon-off",style:{backgroundImage:`url(${(U=W.voice)==null?void 0:U.icon})`}})})},hu=["Quickstart","API Docs","Examples","Github","Discord"],_u={start:{message:"Hello, I am Tan Jin 👋! Welcome to React ChatBotify, I'm excited that you are using our chatbot 😊!",transition:{duration:1e3},path:"show_options"},show_options:{message:"It looks like you have not set up a conversation flow yet. No worries! Here are a few helpful things you can check out to get started:",options:hu,path:"process_options"},prompt_again:{message:"Do you need any other help?",options:hu,path:"process_options"},unknown_input:{message:"Sorry, I do not understand your message 😢! If you require further assistance, you may click on the Github option and open an issue there or visit our discord.",options:hu,path:"process_options"},process_options:{transition:{duration:0},path:I=>{let h="";switch(I.userInput){case"Quickstart":h="https://react-chatbotify.tjtanjin.com/docs/introduction/quickstart/";break;case"API Docs":h="https://react-chatbotify.tjtanjin.com/docs/api/bot_options";break;case"Examples":h="https://react-chatbotify.tjtanjin.com/docs/examples/basic_form";break;case"Github":h="https://github.com/tjtanjin/react-chatbotify/";break;case"Discord":h="https://discord.gg/6R4DK4G5Zh";break;default:return"unknown_input"}return I.injectMessage("Sit tight! I'll send you right there!"),setTimeout(()=>{window.open(h)},1e3),"repeat"}},repeat:{transition:{duration:3e3},path:"prompt_again"}},Or=!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),$u=I=>{const h=[];let T="",x=!1;for(let f=0;f"?(T+=R,h.push(T),T="",x=!1):x?T+=R:h.push(R)}return T!==""&&h.push(T),h};const es=({inputRef:I,textAreaDisabled:h,textAreaSensitiveMode:T,voiceToggledOn:x,getCurrPath:f,handleToggleVoice:R,handleActionInput:W})=>{var xe,We,be,Ve,Le,Ue,Ke,ot,it,Mt,bt;const{botOptions:U}=Gt(),[N,m]=q.useState(!1),[Z,P]=q.useState(0),[$,Me]=q.useState(!1);q.useEffect(()=>{var ze;const Ne=f();Ne&&(W(Ne,(ze=I.current)==null?void 0:ze.value),P(0))},[$]);const te={boxSizing:Or?"content-box":"border-box",...U.chatInputAreaStyle},ne={outline:h?"":"none",boxShadow:h?"":`0 0 5px ${(xe=U.theme)==null?void 0:xe.primaryColor}`,boxSizing:Or?"content-box":"border-box",...U.chatInputAreaFocusedStyle},H={cursor:`url(${(We=U.theme)==null?void 0:We.actionDisabledIcon}), auto`,caretColor:"transparent",boxSizing:Or?"content-box":"border-box",...U.chatInputAreaDisabledStyle},b={color:"#989898",...U.characterLimitStyle},ee={color:"#ff0000",...U.characterLimitReachedStyle},de=h?(be=U.chatInput)==null?void 0:be.disabledPlaceholderText:(Ve=U.chatInput)==null?void 0:Ve.enabledPlaceholderText,ye=()=>{h||m(!0)},Ae=()=>{m(!1)},pe=Ne=>{Ne.key==="Enter"&&(Ne.preventDefault(),Oe(Ne))},ce=Ne=>{var ze,jt;if(h&&I.current){I.current.value="";return}if(I.current){const gt=(ze=U.chatInput)==null?void 0:ze.characterLimit,Qe=((jt=U.chatInput)==null?void 0:jt.inputValueFormat)?Ne.target.value.replace(/\n/g," "):Ne.target.value;gt!=null&>>=0&&Qe.length>gt?I.current.value=Qe.slice(0,gt):I.current.value=Qe,P(I.current.value.length)}},Oe=Ne=>{var jt;Ne.preventDefault();const ze=f();ze&&(W(ze,(jt=I.current)==null?void 0:jt.value),P(0))},we=()=>{Me(Ne=>!Ne)};return F.jsxs("div",{onMouseDown:Ne=>{Ne.stopPropagation()},style:U.chatInputContainerStyle,className:"rcb-chat-input",children:[T&&((Le=U.sensitiveInput)!=null&&Le.maskInTextArea)?F.jsx("input",{ref:I,type:"password",className:"rcb-chat-input-textarea",style:h?H:N?ne:te,placeholder:de,onChange:ce,onKeyDown:pe,onFocus:ye,onBlur:Ae}):F.jsx("textarea",{ref:I,style:h?H:N?ne:te,rows:1,className:"rcb-chat-input-textarea",placeholder:de,onChange:ce,onKeyDown:pe,onFocus:ye,onBlur:Ae}),F.jsxs("div",{className:"rcb-chat-input-button-container",children:[!((Ue=U.voice)!=null&&Ue.disabled)&&Or&&F.jsx(qu,{inputRef:I,textAreaDisabled:h,voiceToggledOn:x,handleToggleVoice:R,triggerSendVoiceInput:we,setInputLength:P}),F.jsx(Ju,{handleSubmit:Oe}),((Ke=U.chatInput)==null?void 0:Ke.showCharacterCount)&&((ot=U.chatInput)==null?void 0:ot.characterLimit)!=null&&((it=U.chatInput)==null?void 0:it.characterLimit)>0&&F.jsxs("div",{className:"rcb-chat-input-char-counter",style:Z>=((Mt=U.chatInput)==null?void 0:Mt.characterLimit)?ee:b,children:[Z,"/",(bt=U.chatInput)==null?void 0:bt.characterLimit]})]})]})};const ts=({inputRef:I,textAreaDisabled:h})=>{var Z,P,$,Me;const{botOptions:T}=Gt(),x=q.useRef(null),f=q.useRef(null),[R,W]=q.useState(!1),U={cursor:`url(${(Z=T.theme)==null?void 0:Z.actionDisabledIcon}), auto`};q.useEffect(()=>{const te=b=>{x.current&&!x.current.contains(b.target)&&f.current&&!f.current.contains(b.target)&&W(!1)},ne=()=>{if(x.current&&f.current){const b=f.current.getBoundingClientRect(),ee=x.current.offsetHeight,de=b.top-ee-8;x.current.style.left=`${b.left}px`,x.current.style.top=`${de}px`}},H=()=>{ne()};return document.addEventListener("mousedown",te),window.addEventListener("resize",H),()=>{document.removeEventListener("mousedown",te),window.removeEventListener("resize",H)}},[]);const N=(te,ne)=>{te.preventDefault(),I.current&&(I.current.value=I.current.value+ne,setTimeout(()=>{const H=I.current;if(H){H.focus();const b=H.value.length;H.setSelectionRange(b,b)}},50)),W(!1)},m=te=>{te.preventDefault(),W(h?!1:!R)};return F.jsxs(F.Fragment,{children:[F.jsx("div",{ref:f,style:h?U:{},className:`${h?"rcb-emoji-button-disabled":"rcb-emoji-button-enabled"}`,onMouseDown:m,children:F.jsx("span",{style:{backgroundImage:`url(${(P=T.emoji)==null?void 0:P.icon})`},className:`${h?"rcb-emoji-icon-disabled":"rcb-emoji-icon-enabled"}`})}),R&&F.jsx("div",{className:"rcb-emoji-picker-popup",ref:x,children:(Me=($=T.emoji)==null?void 0:$.list)==null?void 0:Me.map((te,ne)=>F.jsx("span",{className:"rcb-emoji",onMouseDown:H=>N(H,te),children:te},ne))})]})},Iu=q.createContext({paths:[],setPaths:()=>null}),va=()=>q.useContext(Iu);const rs=({inputRef:I,flow:h,injectMessage:T,streamMessage:x,openChat:f,getCurrPath:R,getPrevPath:W,handleActionInput:U})=>{var Me,te,ne,H,b;const{botOptions:N}=Gt(),{paths:m}=va(),[Z,P]=q.useState(!1);q.useEffect(()=>{const ee=R();if(!ee)return;const de=h[ee];de&&P(typeof de.file=="function")},[m]);const $=async ee=>{var ce,Oe;const de=ee.target.files;if(!de)return;const ye=R();if(!ye)return;const Ae=h[ye];if(!Ae)return;const pe=Ae.file;if(pe!=null){const we=[];for(let xe=0;xe{var Z,P,$;const{botOptions:m}=Gt();return F.jsxs("div",{style:m.footerStyle,className:"rcb-chat-footer-container",children:[F.jsxs("div",{className:"rcb-chat-footer",children:[!((Z=m.fileAttachment)!=null&&Z.disabled)&&F.jsx(rs,{inputRef:I,flow:h,getCurrPath:W,openChat:R,getPrevPath:U,handleActionInput:N,injectMessage:x,streamMessage:f}),!((P=m.emoji)!=null&&P.disabled)&&F.jsx(ts,{inputRef:I,textAreaDisabled:T})]}),F.jsx("span",{children:($=m.footer)==null?void 0:$.text})]})};const As=({unreadCount:I})=>{var R,W,U,N,m;const{botOptions:h,setBotOptions:T}=Gt(),x=()=>{T({...h,isOpen:!h.isOpen})},f={backgroundImage:`url(${(R=h.chatButton)==null?void 0:R.icon}), linear-gradient(to right, ${(W=h.theme)==null?void 0:W.secondaryColor}, ${(U=h.theme)==null?void 0:U.primaryColor})`,width:75,height:75,...h.chatButtonStyle};return F.jsx(F.Fragment,{children:!((N=h.theme)!=null&&N.embedded)&&F.jsx("button",{"aria-label":"Open Chat",style:f,className:`rcb-toggle-button ${h.isOpen?"rcb-button-hide":"rcb-button-show"}`,onClick:x,children:!((m=h.notification)!=null&&m.disabled)&&F.jsx("span",{style:h.notificationBadgeStyle,className:"rcb-badge",children:I})})})};const os=()=>{var Z,P,$,Me,te;const{botOptions:I,setBotOptions:h}=Gt(),[T,x]=q.useState(!1),[f,R]=q.useState(!1),[W,U]=q.useState(0);q.useEffect(()=>{var H,b,ee;const ne=(H=I.tooltip)==null?void 0:H.mode;if(ne==="ALWAYS")if(Or){let de;I.isOpen?de=(((b=I.chatWindowStyle)==null?void 0:b.width)||375)-(((ee=I.chatButtonStyle)==null?void 0:ee.width)||75):de=0,U(de),x(!0)}else I.isOpen?x(!1):x(!0);else ne==="NEVER"?x(!1):ne==="START"?f?x(!1):(R(!0),x(!0)):ne==="CLOSE"&&x(!I.isOpen)},[I.isOpen]);const N={transform:`translateX(-${W}px)`,right:(((Z=I.chatButtonStyle)==null?void 0:Z.width)||75)+40,bottom:30,backgroundColor:(P=I.theme)==null?void 0:P.secondaryColor,color:($=I.theme)==null?void 0:$.secondaryColor,...I.tooltipStyle},m={borderColor:`transparent transparent transparent ${N.backgroundColor}`};return F.jsx(F.Fragment,{children:!((Me=I.theme)!=null&&Me.embedded)&&F.jsxs("div",{style:N,className:`rcb-chat-tooltip ${T?"rcb-tooltip-show":"rcb-tooltip-hide"}`,onClick:()=>h({...I,isOpen:!0}),children:[F.jsx("span",{style:{color:"#fff"},children:(te=I.tooltip)==null?void 0:te.text}),F.jsx("span",{className:"rcb-chat-tooltip-tail",style:m})]})})};const is=({chatHistory:I,showChatHistory:h})=>{var N,m,Z;const{botOptions:T}=Gt(),[x,f]=q.useState(!1),R={color:(N=T.theme)==null?void 0:N.primaryColor,borderColor:(m=T.theme)==null?void 0:m.primaryColor,...T.chatHistoryButtonHoveredStyle},W=()=>{f(!0)},U=()=>{f(!1)};return F.jsx("div",{className:"rcb-view-history-container",children:F.jsx("div",{onMouseEnter:W,onMouseLeave:U,style:x?R:T.chatHistoryButtonStyle,onMouseDown:P=>{P.preventDefault(),h(I)},className:"rcb-view-history-button",children:F.jsx("p",{children:(Z=T.chatHistory)==null?void 0:Z.viewChatHistoryButtonText})})})};const as=({checkboxes:I,checkedItems:h,path:T,handleActionInput:x})=>{var ne,H,b,ee,de,ye,Ae,pe,ce,Oe,we;const{botOptions:f}=Gt(),{paths:R}=va(),[W,U]=q.useState(new Set),[N,m]=q.useState(!1),Z={cursor:N?`url(${(ne=f.theme)==null?void 0:ne.actionDisabledIcon}), auto`:"pointer",color:(H=f.theme)==null?void 0:H.primaryColor,borderColor:(b=f.theme)==null?void 0:b.primaryColor,...f.botCheckboxRowStyle},P={cursor:N||W.size{R.length>0&&R[R.length-1]!==T&&m(!0)},[R]);const te=xe=>{N||U(We=>{const be=new Set(We);if(be.has(xe))h.delete(xe),be.delete(xe);else{if(W.size==I.max)return We;h.add(xe),be.add(xe)}return be})};return F.jsxs("div",{className:`rcb-checkbox-container ${(we=f.botBubble)!=null&&we.showAvatar?"rcb-checkbox-offset":""}`,children:[I.items.map(xe=>F.jsx("div",{onMouseDown:We=>{We.preventDefault(),te(xe)},style:Z,className:"rcb-checkbox-row-container",children:F.jsxs("div",{className:"rcb-checkbox-row",children:[F.jsx("div",{style:W.has(xe)?Me:$,className:"rcb-checkbox-mark"}),F.jsx("div",{className:"rcb-checkbox-label",children:xe})]})},xe)),F.jsx("button",{style:P,className:"rcb-checkbox-next-button",disabled:N||W.size{var be;xe.preventDefault();const We=Array.from(h).join(", ");m(!0),x(T,We,(be=f.chatInput)==null?void 0:be.sendCheckboxOutput)}})]})},us=(I,h,T,x)=>{const f=I.checkboxes;if(!f||f.items.length==0)return;f.min==null&&(f.min=1),f.max==null&&(f.max=f.items.length),f.min>f.max&&(f.min=f.max);const R=new Set;T(F.jsx(as,{checkboxes:f,checkedItems:R,path:h,handleActionInput:x}))},ss=async(I,h)=>{const T=I.function;if(!T)return;const x=T(h);return x instanceof Promise?await x:x},ls=async(I,h)=>{const T=I.message;if(!T)return;if(typeof T=="string"){T.trim()!==""&&await h.injectMessage(T);return}let x=T(h);x instanceof Promise&&(x=await x),x&&x.trim()!==""&&await h.injectMessage(x)};const cs=({options:I,path:h,handleActionInput:T})=>{var Me,te,ne,H,b,ee;const{botOptions:x}=Gt(),{paths:f}=va(),[R,W]=q.useState([]),[U,N]=q.useState(!1),m={cursor:U?`url(${(Me=x.theme)==null?void 0:Me.actionDisabledIcon}), auto`:"pointer",color:(te=x.theme)==null?void 0:te.primaryColor,borderColor:(ne=x.theme)==null?void 0:ne.primaryColor,backgroundColor:"#fff",...x.botOptionStyle},Z={color:"#fff",borderColor:(H=x.theme)==null?void 0:H.primaryColor,backgroundColor:(b=x.theme)==null?void 0:b.primaryColor,...x.botOptionHoveredStyle};q.useEffect(()=>{f.length>0&&f[f.length-1]!==h&&N(!0)},[f]);const P=de=>{W(ye=>{const Ae=[...ye];return Ae[de]=!0,Ae})},$=de=>{W(ye=>{const Ae=[...ye];return Ae[de]=!1,Ae})};return F.jsx("div",{className:`rcb-options-container ${(ee=x.botBubble)!=null&&ee.showAvatar?"rcb-options-offset":""}`,children:I.map((de,ye)=>{const Ae=R[ye]&&!U;return F.jsx("div",{className:"rcb-options",style:Ae?Z:m,onMouseEnter:()=>P(ye),onMouseLeave:()=>$(ye),onMouseDown:pe=>{var ce;pe.preventDefault(),!U&&(N(!0),T(h,de,(ce=x.chatInput)==null?void 0:ce.sendOptionOutput))},children:de},de)})})},fs=(I,h,T,x)=>{const f=I.options;if(!f)return;T(F.jsx(cs,{options:f,path:h,handleActionInput:x}))},ds=async(I,h,T)=>{const x=I.path;if(!x)return!1;if(typeof x=="string")return T(W=>[...W,x]),!0;let f=x(h);if(f instanceof Promise&&(f=await f),!f)return!1;const R=f;return T(W=>[...W,R]),!0},Ms=async(I,h)=>{const T=I.render;if(T){if(typeof T=="function"){let x=T(h);if(x instanceof Promise&&(x=await x),!x)return;await h.injectMessage(x);return}await h.injectMessage(T)}},gs=async(I,h,T,x,f)=>{const R=I[h];if(!R)throw new Error("block is not valid.");const W=R.transition;let U;if(typeof W=="function"?(U=W(T),U instanceof Promise&&(U=await U)):U=W,!U||U instanceof Promise||U.duration==null||typeof U.duration!="number")return;U.interruptable||(U.interruptable=!1);const N=setTimeout(async()=>{await Pu(I,h,T,x)},U.duration);U.interruptable&&f(N)},hs=async(I,h,T,x,f,R,W,U)=>{const N=I[h];if(!N)throw new Error("Block is not valid.");for(const m of Object.keys(N))switch(m){case"message":await ls(N,T);break;case"options":fs(N,h,T.injectMessage,U);break;case"checkboxes":us(N,h,T.injectMessage,U);break;case"render":await Ms(N,T);break;case"chatDisabled":N.chatDisabled&&x(N.chatDisabled);break;case"isSensitive":N.isSensitive&&f(N.isSensitive);break;case"transition":await gs(I,h,T,R,W)}},Pu=async(I,h,T,x)=>{const f=I[h];if(!f)throw new Error("Block is not valid.");const R=Object.keys(f);for(const W of R)W==="function"&&await ss(f,T);return R.includes("path")?await ds(f,T,x):!1};var EA={},SA={};/** * @license React * react-dom-server-legacy.browser.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var mu;function ys(){if(mu)return SA;mu=1;var I=q;function h(A){for(var s="https://reactjs.org/docs/error-decoder.html?invariant="+A,g=1;g