"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const eA=require("react");function xo(j){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(j){for(const d in j)if(d!=="default"){const x=Object.getOwnPropertyDescriptor(j,d);Object.defineProperty(c,d,x.get?x:{enumerable:!0,get:()=>j[d]})}}return c.default=j,Object.freeze(c)}const WA=xo(eA);var fo={exports:{}},Nr={};/** * @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 Po;function ko(){if(Po)return Nr;Po=1;var j=eA,c=Symbol.for("react.element"),d=Symbol.for("react.fragment"),x=Object.prototype.hasOwnProperty,M=j.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,H={key:!0,ref:!0,__self:!0,__source:!0};function b(S,l,L){var q,Y={},_=null,EA=null;L!==void 0&&(_=""+L),l.key!==void 0&&(_=""+l.key),l.ref!==void 0&&(EA=l.ref);for(q in l)x.call(l,q)&&!H.hasOwnProperty(q)&&(Y[q]=l[q]);if(S&&S.defaultProps)for(q in l=S.defaultProps,l)Y[q]===void 0&&(Y[q]=l[q]);return{$$typeof:c,type:S,key:_,ref:EA,props:Y,_owner:M.current}}return Nr.Fragment=d,Nr.jsx=b,Nr.jsxs=b,Nr}var dr={};/** * @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 vo;function Yo(){return vo||(vo=1,process.env.NODE_ENV!=="production"&&function(){var j=eA,c=Symbol.for("react.element"),d=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),M=Symbol.for("react.strict_mode"),H=Symbol.for("react.profiler"),b=Symbol.for("react.provider"),S=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),L=Symbol.for("react.suspense"),q=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),EA=Symbol.for("react.offscreen"),gA=Symbol.iterator,aA="@@iterator";function m(v){if(v===null||typeof v!="object")return null;var K=gA&&v[gA]||v[aA];return typeof K=="function"?K:null}var k=j.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function $(v){{for(var K=arguments.length,V=new Array(K>1?K-1:0),oA=1;oA=1&&pA>=0&&uA[OA]!==ne[pA];)pA--;for(;OA>=1&&pA>=0;OA--,pA--)if(uA[OA]!==ne[pA]){if(OA!==1||pA!==1)do if(OA--,pA--,pA<0||uA[OA]!==ne[pA]){var _A=` `+uA[OA].replace(" at new "," at ");return v.displayName&&_A.includes("")&&(_A=_A.replace("",v.displayName)),typeof v=="function"&&le.set(v,_A),_A}while(OA>=1&&pA>=0);break}}}finally{Ae=!1,HA.current=dA,RA(),Error.prepareStackTrace=vA}var pe=v?v.displayName||v.name:"",Dg=pe?ve(pe):"";return typeof v=="function"&&le.set(v,Dg),Dg}function ee(v,K,V){return Ke(v,!1)}function Me(v){var K=v.prototype;return!!(K&&K.isReactComponent)}function Ne(v,K,V){if(v==null)return"";if(typeof v=="function")return Ke(v,Me(v));if(typeof v=="string")return ve(v);switch(v){case L:return ve("Suspense");case q:return ve("SuspenseList")}if(typeof v=="object")switch(v.$$typeof){case l:return ee(v.render);case Y:return Ne(v.type,K,V);case _:{var oA=v,vA=oA._payload,dA=oA._init;try{return Ne(dA(vA),K,V)}catch{}}}return""}var Oe=Object.prototype.hasOwnProperty,Mg={},ue=k.ReactDebugCurrentFrame;function de(v){if(v){var K=v._owner,V=Ne(v.type,v._source,K?K.type:null);ue.setExtraStackFrame(V)}else ue.setExtraStackFrame(null)}function Ge(v,K,V,oA,vA){{var dA=Function.call.bind(Oe);for(var NA in v)if(dA(v,NA)){var uA=void 0;try{if(typeof v[NA]!="function"){var ne=Error((oA||"React class")+": "+V+" type `"+NA+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof v[NA]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ne.name="Invariant Violation",ne}uA=v[NA](K,NA,oA,V,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(OA){uA=OA}uA&&!(uA instanceof Error)&&(de(vA),$("%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).",oA||"React class",V,NA,typeof uA),de(null)),uA instanceof Error&&!(uA.message in Mg)&&(Mg[uA.message]=!0,de(vA),$("Failed %s type: %s",V,uA.message),de(null))}}}var sg=Array.isArray;function se(v){return sg(v)}function oe(v){{var K=typeof Symbol=="function"&&Symbol.toStringTag,V=K&&v[Symbol.toStringTag]||v.constructor.name||"Object";return V}}function W(v){try{return CA(v),!1}catch{return!0}}function CA(v){return""+v}function jA(v){if(W(v))return $("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",oe(v)),CA(v)}var xA=k.ReactCurrentOwner,PA={key:!0,ref:!0,__self:!0,__source:!0},ge,TA,fe;fe={};function ie(v){if(Oe.call(v,"ref")){var K=Object.getOwnPropertyDescriptor(v,"ref").get;if(K&&K.isReactWarning)return!1}return v.ref!==void 0}function Je(v){if(Oe.call(v,"key")){var K=Object.getOwnPropertyDescriptor(v,"key").get;if(K&&K.isReactWarning)return!1}return v.key!==void 0}function gD(v,K){if(typeof v.ref=="string"&&xA.current&&K&&xA.current.stateNode!==K){var V=VA(xA.current.type);fe[V]||($('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',VA(xA.current.type),v.ref),fe[V]=!0)}}function Tg(v,K){{var V=function(){ge||(ge=!0,$("%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)",K))};V.isReactWarning=!0,Object.defineProperty(v,"key",{get:V,configurable:!0})}}function gg(v,K){{var V=function(){TA||(TA=!0,$("%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)",K))};V.isReactWarning=!0,Object.defineProperty(v,"ref",{get:V,configurable:!0})}}var Og=function(v,K,V,oA,vA,dA,NA){var uA={$$typeof:c,type:v,key:K,ref:V,props:NA,_owner:dA};return uA._store={},Object.defineProperty(uA._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(uA,"_self",{configurable:!1,enumerable:!1,writable:!1,value:oA}),Object.defineProperty(uA,"_source",{configurable:!1,enumerable:!1,writable:!1,value:vA}),Object.freeze&&(Object.freeze(uA.props),Object.freeze(uA)),uA};function mg(v,K,V,oA,vA){{var dA,NA={},uA=null,ne=null;V!==void 0&&(jA(V),uA=""+V),Je(K)&&(jA(K.key),uA=""+K.key),ie(K)&&(ne=K.ref,gD(K,vA));for(dA in K)Oe.call(K,dA)&&!PA.hasOwnProperty(dA)&&(NA[dA]=K[dA]);if(v&&v.defaultProps){var OA=v.defaultProps;for(dA in OA)NA[dA]===void 0&&(NA[dA]=OA[dA])}if(uA||ne){var pA=typeof v=="function"?v.displayName||v.name||"Unknown":v;uA&&Tg(NA,pA),ne&&gg(NA,pA)}return Og(v,uA,ne,vA,oA,xA.current,NA)}}var ae=k.ReactCurrentOwner,xe=k.ReactDebugCurrentFrame;function ze(v){if(v){var K=v._owner,V=Ne(v.type,v._source,K?K.type:null);xe.setExtraStackFrame(V)}else xe.setExtraStackFrame(null)}var yA;yA=!1;function be(v){return typeof v=="object"&&v!==null&&v.$$typeof===c}function fg(){{if(ae.current){var v=VA(ae.current.type);if(v)return` Check the render method of \``+v+"`."}return""}}function ig(v){{if(v!==void 0){var K=v.fileName.replace(/^.*[\\\/]/,""),V=v.lineNumber;return` Check your code at `+K+":"+V+"."}return""}}var ke={};function cg(v){{var K=fg();if(!K){var V=typeof v=="string"?v:v.displayName||v.name;V&&(K=` Check the top-level render call using <`+V+">.")}return K}}function me(v,K){{if(!v._store||v._store.validated||v.key!=null)return;v._store.validated=!0;var V=cg(K);if(ke[V])return;ke[V]=!0;var oA="";v&&v._owner&&v._owner!==ae.current&&(oA=" It was passed a child from "+VA(v._owner.type)+"."),ze(v),$('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',V,oA),ze(null)}}function ZA(v,K){{if(typeof v!="object")return;if(se(v))for(var V=0;V",uA=" Did you accidentally export a JSX literal instead of a component?"):OA=typeof v,$("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",OA,uA)}var pA=mg(v,K,V,vA,dA);if(pA==null)return pA;if(NA){var _A=K.children;if(_A!==void 0)if(oA)if(se(_A)){for(var pe=0;pe<_A.length;pe++)ZA(_A[pe],v);Object.freeze&&Object.freeze(_A)}else $("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ZA(_A,v)}return v===x?Ug(pA):pg(pA),pA}}function De(v,K,V){return xg(v,K,V,!0)}function kg(v,K,V){return xg(v,K,V,!1)}var DD=kg,nD=De;dr.Fragment=x,dr.jsx=DD,dr.jsxs=nD}()),dr}process.env.NODE_ENV==="production"?fo.exports=ko():fo.exports=Yo();var Z=fo.exports;const ao=eA.createContext({botOptions:{},setBotOptions:()=>null}),eg=()=>eA.useContext(ao);const Fo=({notificationToggledOn:j,audioToggledOn:c,handleToggleNotification:d,handleToggleAudio:x})=>{var L,q,Y,_,EA,gA,aA,m,k;const{botOptions:M,setBotOptions:H}=eg(),b={background:`linear-gradient(to right, ${(L=M.theme)==null?void 0:L.secondaryColor}, ${(q=M.theme)==null?void 0:q.primaryColor})`,...M.headerStyle},S={headerAvatar:{backgroundImage:`url(${(Y=M.header)==null?void 0:Y.avatar})`},notificationIcon:{backgroundImage:`url(${(_=M.notification)==null?void 0:_.icon})`},audioIcon:{backgroundImage:`url(${(EA=M.audio)==null?void 0:EA.icon})`},closeChatIcon:{backgroundImage:`url(${(gA=M.header)==null?void 0:gA.closeChatIcon})`}},l=()=>{H({...M,isOpen:!1})};return Z.jsxs("div",{style:b,className:"rcb-chat-header-container",children:[Z.jsxs("div",{className:"rcb-chat-header",children:[((aA=M.header)==null?void 0:aA.showAvatar)&&Z.jsx("div",{style:S.headerAvatar,className:"rcb-bot-avatar"}),(m=M.header)==null?void 0:m.title]}),Z.jsx("div",{className:"rcb-chat-header",children:!((k=M.theme)!=null&&k.embedded)&&Z.jsx("div",{style:S.closeChatIcon,onMouseDown:$=>{$.stopPropagation(),l()},className:"rcb-close-chat-icon"})})]})},uo=eA.createContext({messages:[],setMessages:()=>null}),ho=()=>eA.useContext(uo);const Ho=({chatBodyRef:j,isBotTyping:c,isLoadingChatHistory:d,prevScrollHeight:x,setPrevScrollHeight:M})=>{var EA,gA,aA,m,k,$;const{botOptions:H}=eg(),{messages:b}=ho(),S={...H==null?void 0:H.bodyStyle},l={backgroundColor:(EA=H.theme)==null?void 0:EA.primaryColor,color:"#fff",maxWidth:(gA=H.userBubble)!=null&&gA.showAvatar?"65%":"70%",...H.userBubbleStyle},L={backgroundColor:(aA=H.theme)==null?void 0:aA.secondaryColor,color:"#fff",maxWidth:(m=H.botBubble)!=null&&m.showAvatar?"65%":"70%",...H.botBubbleStyle};eA.useEffect(()=>{if(d&&j.current!=null){const{scrollHeight:BA}=j.current,sA=BA-x;j.current.scrollTop=j.current.scrollTop+sA,M(BA);return}j.current!=null&&(j.current.scrollTop=j.current.scrollHeight)},[b,c]);const q=()=>{(j==null?void 0:j.current)!=null&&M(j.current.scrollHeight)},Y=BA=>{var sA,rA;return Z.jsxs(Z.Fragment,{children:[Z.jsx("div",{style:l,className:"rcb-user-message",children:BA.content}),((sA=H.userBubble)==null?void 0:sA.showAvatar)&&Z.jsx("div",{style:{backgroundImage:`url(${(rA=H.userBubble)==null?void 0:rA.avatar})`},className:"rcb-message-user-avatar"})]})},_=BA=>{var sA,rA;return Z.jsxs(Z.Fragment,{children:[((sA=H.botBubble)==null?void 0:sA.showAvatar)&&Z.jsx("div",{style:{backgroundImage:`url(${(rA=H.botBubble)==null?void 0:rA.avatar})`},className:"rcb-message-bot-avatar"}),Z.jsx("div",{style:L,className:"rcb-bot-message",children:BA.content})]})};return Z.jsxs("div",{style:S,className:"rcb-chat-body-container",ref:j,onScroll:q,children:[b.map((BA,sA)=>typeof BA.content!="string"?Z.jsx("div",{children:BA.content},sA):Z.jsx("div",{className:BA.isUser?"rcb-user-message-container":"rcb-bot-message-container",children:BA.isUser?Y(BA):_(BA)},sA)),c&&Z.jsxs("div",{className:"rcb-bot-message-container",children:[((k=H.botBubble)==null?void 0:k.showAvatar)&&Z.jsx("div",{style:{backgroundImage:`url(${($=H.botBubble)==null?void 0:$.avatar})`},className:"rcb-message-bot-avatar"}),Z.jsx("div",{onMouseDown:BA=>{BA.preventDefault()},className:"rcb-bot-message",children:Z.jsxs("div",{className:"rcb-typing-indicator",children:[Z.jsx("span",{className:"rcb-dot"}),Z.jsx("span",{className:"rcb-dot"}),Z.jsx("span",{className:"rcb-dot"})]})})]})]})};const So=({handleSubmit:j})=>{var L,q,Y;const{botOptions:c}=eg(),[d,x]=eA.useState(!1),M={backgroundColor:(L=c.theme)==null?void 0:L.primaryColor,...c.sendButtonStyle},H={backgroundColor:(q=c.theme)==null?void 0:q.secondaryColor,...c.sendButtonHoveredStyle},b={backgroundImage:`url(${(Y=c.chatInput)==null?void 0:Y.sendButtonIcon})`},S=()=>{x(!0)},l=()=>{x(!1)};return Z.jsx("div",{onMouseEnter:S,onMouseLeave:l,style:d?H:M,onMouseDown:j,className:"rcb-send-button",children:Z.jsx("span",{className:"rcb-send-icon",style:b})})},lo=window.speechRecognition||window.webkitSpeechRecognition,eD=lo!=null?new lo:null;let mD,Qo,zt=!1;const Go=(j,c,d,x,M)=>{var S,l;if(eD==null)return;zt||(zt=!0,eD.start());const H=(S=j.voice)==null?void 0:S.timeoutPeriod,b=(l=j.voice)==null?void 0:l.autoSendPeriod;eD.onresult=L=>{var Y,_;clearTimeout(mD),mD=null,clearTimeout(Qo);const q=L.results[L.results.length-1][0].transcript;if(M.current){const EA=(Y=j.chatInput)==null?void 0:Y.characterLimit,gA=M.current.value+q;EA!=null&&EA>=0&&gA.length>EA?M.current.value=gA.slice(0,EA):M.current.value=gA,x(M.current.value.length)}mD=setTimeout(()=>Mo(c),H),(_=j.voice)!=null&&_.autoSendDisabled||(Qo=setTimeout(d,b))},eD.onend=()=>{zt?(eD.start(),mD==null&&(mD=setTimeout(()=>Mo(c),H))):(clearTimeout(mD),mD=null,clearTimeout(Qo))},mD=setTimeout(()=>Mo(c),H)},Eo=()=>{eD!=null&&(zt=!1,eD&&eD.stop())},Co=(j,c)=>{var d,x;(d=c.voice)!=null&&d.disabled||!((x=c.chatInput)!=null&&x.blockSpam)||eD==null||(j&&!zt?(zt=!0,eD.start()):j||Eo())},Mo=j=>{j(),Eo()};const bo=({inputRef:j,textAreaDisabled:c,voiceToggledOn:d,handleToggleVoice:x,triggerSendVoiceInput:M,setInputLength:H})=>{var S;const{botOptions:b}=eg();return eA.useEffect(()=>{d?Go(b,x,M,H,j):Eo()},[d]),Z.jsx("div",{onMouseDown:l=>{l.preventDefault(),x()},className:d&&!c?"rcb-voice-button-enabled":"rcb-voice-button-disabled",children:Z.jsx("span",{className:d&&!c?"rcb-voice-icon-on":"rcb-voice-icon-off",style:{backgroundImage:`url(${(S=b.voice)==null?void 0:S.icon})`}})})},so=["Quickstart","API Docs","Examples","Github","Discord"],mo={start:{message:"Hello, I am Sahar 👋! Welcome to Chatbot, 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:so,path:"process_options"},prompt_again:{message:"Do you need any other help?",options:so,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:so,path:"process_options"},process_options:{transition:{duration:0},path:j=>{let c="";switch(j.userInput){case"Quickstart":c="https://react-chatbotify.tjtanjin.com/docs/introduction/quickstart/";break;case"API Docs":c="https://react-chatbotify.tjtanjin.com/docs/api/bot_options";break;case"Examples":c="https://react-chatbotify.tjtanjin.com/docs/examples/basic_form";break;case"Github":c="https://github.com/tjtanjin/react-chatbotify/";break;case"Discord":c="https://discord.gg/6R4DK4G5Zh";break;default:return"unknown_input"}return j.injectMessage("Sit tight! I'll send you right there!"),setTimeout(()=>{window.open(c)},1e3),"repeat"}},repeat:{transition:{duration:3e3},path:"prompt_again"}},vD=!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);const Ro=({inputRef:j,textAreaDisabled:c,voiceToggledOn:d,getCurrPath:x,handleToggleVoice:M,handleActionInput:H})=>{var MA,XA,cA,UA,GA,zA,VA,qA,Ie,Te;const{botOptions:b}=eg(),[S,l]=eA.useState(!1),[L,q]=eA.useState(0),[Y,_]=eA.useState(!1);eA.useEffect(()=>{var kA;const bA=x();bA!=null&&(H(bA,(kA=j.current)==null?void 0:kA.value),q(0))},[Y]);const EA={outline:S&&!c?"none":"",boxShadow:S&&!c?`0 0 5px ${(MA=b.theme)==null?void 0:MA.primaryColor}`:"",cursor:c?`url(${(XA=b.theme)==null?void 0:XA.actionDisabledIcon}), auto`:"",caretColor:c?"transparent":"",boxSizing:vD?"content-box":"border-box",...b.chatInputAreaStyle},gA={color:"#989898",...b.characterLimitStyle},aA={color:"#ff0000",...b.characterLimitReachedStyle},m=c?(cA=b.chatInput)==null?void 0:cA.disabledPlaceholderText:(UA=b.chatInput)==null?void 0:UA.enabledPlaceholderText,k=()=>{c||l(!0)},$=()=>{l(!1)},BA=bA=>{bA.key==="Enter"&&(bA.preventDefault(),rA(bA))},sA=bA=>{var kA;if(c&&j.current){j.current.value="";return}if(j.current){const mA=(kA=b.chatInput)==null?void 0:kA.characterLimit,ce=bA.target.value.replace(/\n/g," ");mA!=null&&mA>=0&&ce.length>mA?j.current.value=ce.slice(0,mA):j.current.value=ce,q(j.current.value.length)}},rA=bA=>{var mA;bA.preventDefault();const kA=x();kA!=null&&(H(kA,(mA=j.current)==null?void 0:mA.value),q(0))},fA=()=>{_(bA=>!bA)};return Z.jsxs("div",{onMouseDown:bA=>{bA.stopPropagation()},style:b.chatInputContainerStyle,className:"rcb-chat-input",children:[Z.jsx("textarea",{ref:j,style:EA,rows:1,className:"rcb-chat-input-textarea",placeholder:m,onChange:sA,onKeyDown:BA,onFocus:k,onBlur:$}),Z.jsxs("div",{className:"rcb-chat-input-button-container",children:[!((GA=b.voice)!=null&&GA.disabled)&&vD&&Z.jsx(bo,{inputRef:j,textAreaDisabled:c,voiceToggledOn:d,handleToggleVoice:M,triggerSendVoiceInput:fA,setInputLength:q}),Z.jsx(So,{handleSubmit:rA}),((zA=b.chatInput)==null?void 0:zA.showCharacterCount)&&((VA=b.chatInput)==null?void 0:VA.characterLimit)!=null&&((qA=b.chatInput)==null?void 0:qA.characterLimit)>0&&Z.jsxs("div",{className:"rcb-chat-input-char-counter",style:L>=((Ie=b.chatInput)==null?void 0:Ie.characterLimit)?aA:gA,children:[L,"/",(Te=b.chatInput)==null?void 0:Te.characterLimit]})]})]})};const Ko=({inputRef:j,textAreaDisabled:c})=>{var q,Y,_,EA;const{botOptions:d}=eg(),x=eA.useRef(null),M=eA.useRef(null),[H,b]=eA.useState(!1),S={cursor:`url(${(q=d.theme)==null?void 0:q.actionDisabledIcon}), auto`};eA.useEffect(()=>{const gA=k=>{x.current&&!x.current.contains(k.target)&&M.current&&!M.current.contains(k.target)&&b(!1)},aA=()=>{if(x.current&&M.current){const k=M.current.getBoundingClientRect(),$=x.current.offsetHeight,BA=k.top-$-8;x.current.style.left=`${k.left}px`,x.current.style.top=`${BA}px`}},m=()=>{aA()};return document.addEventListener("mousedown",gA),window.addEventListener("resize",m),()=>{document.removeEventListener("mousedown",gA),window.removeEventListener("resize",m)}},[]);const l=(gA,aA)=>{var m;gA.preventDefault(),j.current&&(j.current.value=j.current.value+aA,(m=j.current)==null||m.focus()),b(!1)},L=gA=>{gA.preventDefault(),b(c?!1:!H)};return Z.jsxs(Z.Fragment,{children:[Z.jsx("div",{ref:M,style:c?S:{},className:`${c?"rcb-emoji-button-disabled":"rcb-emoji-button-enabled"}`,onMouseDown:L,children:Z.jsx("span",{style:{backgroundImage:`url(${(Y=d.emoji)==null?void 0:Y.icon})`},className:`${c?"rcb-emoji-icon-disabled":"rcb-emoji-icon-enabled"}`})}),H&&Z.jsx("div",{className:"rcb-emoji-picker-popup",ref:x,children:(EA=(_=d.emoji)==null?void 0:_.list)==null?void 0:EA.map((gA,aA)=>Z.jsx("span",{className:"rcb-emoji",onMouseDown:m=>l(m,gA),children:gA},aA))})]})},Io=eA.createContext({paths:[],setPaths:()=>null}),aB=()=>eA.useContext(Io);const Jo=({inputRef:j,flow:c,injectMessage:d,openChat:x,getCurrPath:M,getPrevPath:H,handleActionInput:b})=>{var _,EA,gA,aA,m;const{botOptions:S}=eg(),{paths:l}=aB(),[L,q]=eA.useState(!1);eA.useEffect(()=>{const k=M();if(k==null)return;const $=c[k];$!=null&&q(typeof $.file=="function")},[l]);const Y=async k=>{var fA,MA;const $=k.target.files;if($==null)return;const BA=M();if(BA==null)return;const rA=c[BA].file;if(rA!=null){const XA=[];for(let cA=0;cA<$.length;cA++)XA.push($[cA].name);b(BA,"📄 "+XA.join(", "),(fA=S.chatInput)==null?void 0:fA.sendAttachmentOutput),await rA({userInput:(MA=j.current)==null?void 0:MA.value,prevPath:H(),injectMessage:d,openChat:x,files:$})}};return Z.jsx(Z.Fragment,{children:L?Z.jsxs("label",{className:"rcb-attach-button-enabled",children:[Z.jsx("input",{className:"rcb-attach-input",type:"file",onChange:Y,multiple:(_=S.fileAttachment)==null?void 0:_.multiple,accept:(EA=S.fileAttachment)==null?void 0:EA.accept}),Z.jsx("span",{style:{backgroundImage:`url(${(gA=S.fileAttachment)==null?void 0:gA.icon})`},className:"rcb-attach-icon-enabled"})]}):Z.jsxs("label",{className:"rcb-attach-button-disabled",style:{cursor:`url(${(aA=S.theme)==null?void 0:aA.actionDisabledIcon}), auto`},children:[Z.jsx("input",{disabled:!0,type:"file"}),Z.jsx("span",{style:{backgroundImage:`url(${(m=S.fileAttachment)==null?void 0:m.icon})`},className:"rcb-attach-icon-disabled"})]})})};const Xo=({inputRef:j,flow:c,textAreaDisabled:d,injectMessage:x,openChat:M,getCurrPath:H,getPrevPath:b,handleActionInput:S})=>{var L,q,Y;const{botOptions:l}=eg();return Z.jsxs("div",{style:l.footerStyle,className:"rcb-chat-footer-container",children:[Z.jsxs("div",{className:"rcb-chat-footer",children:[!((L=l.fileAttachment)!=null&&L.disabled)&&Z.jsx(Jo,{inputRef:j,flow:c,getCurrPath:H,openChat:M,getPrevPath:b,handleActionInput:S,injectMessage:x}),!((q=l.emoji)!=null&&q.disabled)&&Z.jsx(Ko,{inputRef:j,textAreaDisabled:d})]}),Z.jsx("span",{children:(Y=l.footer)==null?void 0:Y.text})]})};const Zo=({unreadCount:j,position:c="bottom-right"})=>{var l,L,q,Y,_;const d=`rcb-${c}`,{botOptions:x,setBotOptions:M}=eg(),H=`rcb-toggle-button ${d} ${x.isOpen?"rcb-button-hide":"rcb-button-show"}`,b=()=>{M({...x,isOpen:!x.isOpen})},S={backgroundImage:`url(${(l=x.chatButton)==null?void 0:l.icon}), linear-gradient(to right, ${(L=x.theme)==null?void 0:L.secondaryColor}, ${(q=x.theme)==null?void 0:q.primaryColor})`,width:75,height:75,...x.chatButtonStyle};return Z.jsx(Z.Fragment,{children:!((Y=x.theme)!=null&&Y.embedded)&&Z.jsx("button",{style:S,className:H,onClick:b,children:!((_=x.notification)!=null&&_.disabled)&&Z.jsx("span",{style:x.notificationBadgeStyle,className:"rcb-badge",children:j})})})};const Wo=({chatHistory:j,showChatHistory:c})=>{var l,L,q;const{botOptions:d}=eg(),[x,M]=eA.useState(!1),H={color:(l=d.theme)==null?void 0:l.primaryColor,borderColor:(L=d.theme)==null?void 0:L.primaryColor,...d.chatHistoryButtonHoveredStyle},b=()=>{M(!0)},S=()=>{M(!1)};return Z.jsx("div",{className:"rcb-view-history-container",children:Z.jsx("div",{onMouseEnter:b,onMouseLeave:S,style:x?H:d.chatHistoryButtonStyle,onMouseDown:Y=>{Y.preventDefault(),c(j)},className:"rcb-view-history-button",children:(q=d.chatHistory)==null?void 0:q.viewChatHistoryButtonText})})};const Vo=({checkboxes:j,checkedItems:c,path:d,handleActionInput:x})=>{var aA,m,k,$,BA,sA,rA,fA,MA,XA,cA;const{botOptions:M}=eg(),{paths:H}=aB(),[b,S]=eA.useState(new Set),[l,L]=eA.useState(!1),q={cursor:l?`url(${(aA=M.theme)==null?void 0:aA.actionDisabledIcon}), auto`:"pointer",color:(m=M.theme)==null?void 0:m.primaryColor,borderColor:(k=M.theme)==null?void 0:k.primaryColor,...M.botCheckboxRowStyle},Y={cursor:l||b.size{H.length>0&&H[H.length-1]!==d&&L(!0)},[H]);const gA=UA=>{l||S(GA=>{const zA=new Set(GA);if(zA.has(UA))c.delete(UA),zA.delete(UA);else{if(b.size==j.max)return GA;c.add(UA),zA.add(UA)}return zA})};return Z.jsxs("div",{className:`rcb-checkbox-container ${(cA=M.botBubble)!=null&&cA.showAvatar?"rcb-checkbox-offset":""}`,children:[j.items.map(UA=>Z.jsx("div",{onMouseDown:GA=>{GA.preventDefault(),gA(UA)},style:q,className:"rcb-checkbox-row-container",children:Z.jsxs("div",{className:"rcb-checkbox-row",children:[Z.jsx("div",{style:b.has(UA)?EA:_,className:"rcb-checkbox-mark"}),Z.jsx("div",{className:"rcb-checkbox-label",children:UA})]})},UA)),Z.jsx("button",{style:Y,className:"rcb-checkbox-next-button",disabled:l||b.size{var zA;UA.preventDefault();const GA=Array.from(c).join(", ");x(d,GA,(zA=M.chatInput)==null?void 0:zA.sendCheckboxOutput)}})]})},qo=(j,c,d,x)=>{const M=j.checkboxes;if(M==null||M.items.length==0)return;M.min==null&&(M.min=1),M.max==null&&(M.max=M.items.length),M.min>M.max&&(M.min=M.max);const H=new Set;d(Z.jsx(Vo,{checkboxes:M,checkedItems:H,path:c,handleActionInput:x}))},_o=async(j,c)=>{const d=j.function;if(d==null)return;const x=d(c);return x instanceof Promise?await x:x},$o=async(j,c)=>{const d=j.message;if(d==null)return;if(typeof d=="string"){d.trim()!==""&&c.injectMessage(d);return}let x=d(c);x instanceof Promise&&(x=await x),x!=null&&x.trim()!==""&&c.injectMessage(x)};const Aw=({options:j,path:c,handleActionInput:d})=>{var EA,gA,aA,m,k,$;const{botOptions:x}=eg(),{paths:M}=aB(),[H,b]=eA.useState([]),[S,l]=eA.useState(!1),L={cursor:S?`url(${(EA=x.theme)==null?void 0:EA.actionDisabledIcon}), auto`:"pointer",color:(gA=x.theme)==null?void 0:gA.primaryColor,borderColor:(aA=x.theme)==null?void 0:aA.primaryColor,backgroundColor:"#fff",...x.botOptionStyle},q={color:"#fff",borderColor:(m=x.theme)==null?void 0:m.primaryColor,backgroundColor:(k=x.theme)==null?void 0:k.primaryColor,...x.botOptionHoveredStyle};eA.useEffect(()=>{M.length>0&&M[M.length-1]!==c&&l(!0)},[M]);const Y=BA=>{b(sA=>{const rA=[...sA];return rA[BA]=!0,rA})},_=BA=>{b(sA=>{const rA=[...sA];return rA[BA]=!1,rA})};return Z.jsx("div",{className:`rcb-options-container ${($=x.botBubble)!=null&&$.showAvatar?"rcb-options-offset":""}`,children:j.map((BA,sA)=>{const rA=H[sA]&&!S;return Z.jsx("div",{className:"rcb-options",style:rA?q:L,onMouseEnter:()=>Y(sA),onMouseLeave:()=>_(sA),onMouseDown:fA=>{var MA;fA.preventDefault(),!S&&d(c,BA,(MA=x.chatInput)==null?void 0:MA.sendOptionOutput)},children:BA},BA)})})},ew=(j,c,d,x)=>{const M=j.options;if(M==null)return;d(Z.jsx(Aw,{options:M,path:c,handleActionInput:x}))},gw=async(j,c,d)=>{const x=j.path;if(x==null)return!1;if(typeof x=="string")return d(H=>[...H,x]),!0;let M=x(c);return M instanceof Promise&&(M=await M),M==null?!1:(d(H=>[...H,M]),!0)},Dw=async(j,c)=>{const d=j.render;if(d!=null){if(typeof d=="function"){let x=d(c);if(x instanceof Promise&&(x=await x),x==null)return;c.injectMessage(x);return}c.injectMessage(d)}},nw=async(j,c,d,x,M)=>{const b=j[c].transition;let S;if(typeof b=="function"?(S=b(d),S instanceof Promise&&(S=await S)):S=b,S==null||S instanceof Promise||S.duration==null||typeof S.duration!="number")return;S.interruptable==null&&(S.interruptable=!1);const l=setTimeout(async()=>{await To(j,c,d,x)},S.duration);S.interruptable&&M(l)},tw=async(j,c,d,x,M,H,b)=>{const S=j[c],l=Object.keys(S);for(const L of l)switch(L){case"message":await $o(S,d);break;case"options":ew(S,c,d.injectMessage,b);break;case"checkboxes":qo(S,c,d.injectMessage,b);break;case"render":await Dw(S,d);break;case"chatDisabled":S.chatDisabled!=null&&x(S.chatDisabled);break;case"transition":await nw(j,c,d,M,H)}},To=async(j,c,d,x)=>{const M=j[c],H=Object.keys(M);for(const b of H)b==="function"&&await _o(M,d);return H.includes("path")?await gw(M,d,x):!1};var yn={},dn={};/** * @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 No;function rw(){if(No)return dn;No=1;var j=eA;function c(n){for(var w="https://reactjs.org/docs/error-decoder.html?invariant="+n,i=1;i