"use strict";const l=require("react"),u=require("react-chatbotify"),d={autoConfig:!0,promptBaseColors:{info:"#007bff",warning:"#ffc107",error:"#dc3545",success:"#28a745"},promptHoveredColors:{info:"#0056b3",warning:"#d39e00",error:"#c82333",success:"#218838"},textAreaHighlightColors:{info:"#007bff",warning:"#ffc107",error:"#dc3545",success:"#28a745"}},w=t=>({...d,...t,promptBaseColors:{...d.promptBaseColors,...t==null?void 0:t.promptBaseColors},promptHoveredColors:{...d.promptHoveredColors,...t==null?void 0:t.promptHoveredColors},textAreaHighlightColors:{...d.textAreaHighlightColors,...t==null?void 0:t.textAreaHighlightColors}}),H=(t,r)=>{const e=t.promptType??"info";let o={};return r.advancedStyles&&(o=r.advancedStyles[e]),r.promptBaseColors&&(o.toastPromptStyle={color:r.promptBaseColors[e],borderColor:r.promptBaseColors[e]}),r.promptHoveredColors&&(o.toastPromptHoveredStyle={color:r.promptHoveredColors[e],borderColor:r.promptHoveredColors[e]}),r.textAreaHighlightColors&&(t.highlightTextArea??!0)&&(o.chatInputAreaStyle={boxShadow:`${r.textAreaHighlightColors[e]} 0px 0px 5px`}),o},T=(t,r,e)=>{if(r!==t.detail.botId||!t.detail.currPath)return;const o=e[t.detail.currPath];if(!o)return;const a=o.validateInput;if(a&&typeof a=="function")return a},B=t=>{const{showToast:r}=u.useToasts(),{getBotId:e}=u.useBotId(),{getFlow:o}=u.useFlow(),{styles:a,updateStyles:i,replaceStyles:b}=u.useStyles(),m=w(t),[n,h]=l.useState(0),p=l.useRef({});l.useEffect(()=>{const y=c=>{const v=T(c,e(),o());if(!v)return;const s=v(c.data.inputText);if(s!=null&&s.success||c.preventDefault(),!s.promptContent)return;n===0&&(p.current=structuredClone(a));const P=H(s,m);i(P),r(s.promptContent,s.promptDuration??3e3),h(S=>S+1)},x=()=>{h(c=>c-1)};return window.addEventListener("rcb-user-submit-text",y),window.addEventListener("rcb-dismiss-toast",x),()=>{window.removeEventListener("rcb-user-submit-text",y),window.removeEventListener("rcb-dismiss-toast",x)}},[e,o,r,i,a,m,n]),l.useEffect(()=>{n===0&&setTimeout(()=>{b(p.current)})},[n,b,p]);const f={name:"@rcb-plugins/input-validator"};return m.autoConfig&&(f.settings={event:{rcbUserSubmitText:!0,rcbDismissToast:!0}}),f},A=t=>()=>B(t);module.exports=A;