@enjoys/react-chatbot-plugin 1.3.0 → 1.4.0

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.d.ts CHANGED
@@ -4448,6 +4448,14 @@ export declare interface ChatBotProps {
4448
4448
  actionHandlers?: Record<string, (data: Record<string, unknown>, ctx: ActionContext) => Promise<FlowActionResult>>;
4449
4449
  /** Override built-in form field renderers per field type. Each renderer receives strongly-typed props + the default element. */
4450
4450
  renderFormField?: FormFieldRenderMap;
4451
+ /** Fallback message when user types text with no active flow or unmatched input */
4452
+ fallbackMessage?: string | ((text: string) => string | null);
4453
+ /** Keyword routes — match user text to responses or flow steps */
4454
+ keywords?: KeywordRoute[];
4455
+ /** Convenience: auto-respond to common greetings (hello, hi, hey, etc.) */
4456
+ greetingResponse?: string;
4457
+ /** Typing delay in ms before bot sends keyword/fallback replies (default: 0) */
4458
+ typingDelay?: number;
4451
4459
  }
4452
4460
 
4453
4461
  export declare const ChatBubbleIcon: default_2.FC<IconProps>;
@@ -4465,6 +4473,10 @@ export declare interface ChatCallbacks {
4465
4473
  onFlowEnd?: (collectedData: Record<string, unknown>) => void;
4466
4474
  onError?: (error: Error) => void;
4467
4475
  onEvent?: (event: string, payload?: unknown) => void;
4476
+ /** Called when user types text the bot couldn't handle */
4477
+ onUnhandledMessage?: (text: string, context: {
4478
+ currentStepId: string | null;
4479
+ }) => void;
4468
4480
  }
4469
4481
 
4470
4482
  export declare const ChatContext: Context<ChatContextValue | null>;
@@ -4473,6 +4485,7 @@ declare interface ChatContextValue {
4473
4485
  state: ChatState;
4474
4486
  dispatch: React.Dispatch<ChatAction>;
4475
4487
  props: ChatBotProps;
4488
+ pluginManager?: PluginManager | null;
4476
4489
  }
4477
4490
 
4478
4491
  export declare const ChatHeader: default_2.FC<ChatHeaderProps>;
@@ -4783,10 +4796,22 @@ export declare interface FlowStep {
4783
4796
  condition?: FlowCondition;
4784
4797
  /** Key into ChatBotProps.components — renders a custom React component in this step */
4785
4798
  component?: string;
4799
+ /** Free-text input configuration — validates user input before advancing */
4800
+ input?: FlowStepInput;
4786
4801
  /** Async action to run when this step is entered (API calls, verification, etc.) */
4787
4802
  asyncAction?: FlowAsyncAction;
4788
4803
  }
4789
4804
 
4805
+ /** Configuration for a free-text input step with optional validation */
4806
+ export declare interface FlowStepInput {
4807
+ /** Placeholder text for the input */
4808
+ placeholder?: string;
4809
+ /** Validation rules (reuses form validation) */
4810
+ validation?: FormFieldValidation;
4811
+ /** Transform user input before storing */
4812
+ transform?: 'lowercase' | 'uppercase' | 'trim' | 'email';
4813
+ }
4814
+
4790
4815
  export declare interface FormConfig {
4791
4816
  id: string;
4792
4817
  title?: string;
@@ -4837,6 +4862,7 @@ export declare type FormFieldRenderProps = TextFieldRenderProps | SelectFieldRen
4837
4862
  export declare type FormFieldType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'textarea' | 'select' | 'multiselect' | 'radio' | 'checkbox' | 'file' | 'date' | 'time' | 'hidden';
4838
4863
 
4839
4864
  export declare interface FormFieldValidation {
4865
+ required?: boolean;
4840
4866
  pattern?: string;
4841
4867
  minLength?: number;
4842
4868
  maxLength?: number;
@@ -4863,6 +4889,22 @@ declare interface IconProps {
4863
4889
 
4864
4890
  export declare const ImageIcon: default_2.FC<IconProps>;
4865
4891
 
4892
+ /** Route configuration for keyword-based text matching */
4893
+ export declare interface KeywordRoute {
4894
+ /** Patterns to match against user text */
4895
+ patterns: string[];
4896
+ /** Bot response message when matched */
4897
+ response?: string;
4898
+ /** Jump to this flow step when matched */
4899
+ next?: string;
4900
+ /** Case-sensitive matching (default: false) */
4901
+ caseSensitive?: boolean;
4902
+ /** Matching strategy (default: 'contains') */
4903
+ matchType?: 'exact' | 'contains' | 'startsWith' | 'regex';
4904
+ /** Priority — higher wins when multiple routes match (default: 0) */
4905
+ priority?: number;
4906
+ }
4907
+
4866
4908
  export declare const Launcher: default_2.FC<LauncherProps>;
4867
4909
 
4868
4910
  declare interface LauncherProps {
@@ -5056,7 +5098,7 @@ declare interface TypingIndicatorProps {
5056
5098
 
5057
5099
  export declare function useChat(): {
5058
5100
  state: ChatState;
5059
- sendMessage: (text: string) => void;
5101
+ sendMessage: (text: string) => Promise<void>;
5060
5102
  addBotMessage: (text: string, extras?: Partial<ChatMessage>) => Promise<void>;
5061
5103
  handleQuickReply: (value: string, label: string) => void;
5062
5104
  handleFormSubmit: (formId: string, data: Record<string, unknown>) => Promise<void>;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,useMemo as a,useReducer as o,useRef as s,useState as c}from"react";import{Fragment as l,jsx as u,jsxs as d}from"react/jsx-runtime";function f(e,t){switch(t.type){case`TOGGLE_OPEN`:return{...e,isOpen:!e.isOpen};case`SET_OPEN`:return{...e,isOpen:t.payload};case`ADD_MESSAGE`:return{...e,messages:[...e.messages,t.payload]};case`ADD_MESSAGES`:return{...e,messages:[...e.messages,...t.payload]};case`SET_TYPING`:return{...e,isTyping:t.payload};case`DISMISS_WELCOME`:return{...e,showWelcome:!1};case`SET_STEP`:return{...e,currentStepId:t.payload};case`SET_DATA`:return{...e,collectedData:{...e.collectedData,...t.payload}};case`SET_LOGGED_IN`:return{...e,isLoggedIn:t.payload};case`CLEAR_QUICK_REPLIES`:{let t=-1;for(let n=e.messages.length-1;n>=0;n--)if(e.messages[n].quickReplies){t=n;break}if(t===-1)return e;let n=[...e.messages];return n[t]={...n[t],quickReplies:void 0},{...e,messages:n}}case`RESET_CHAT`:return{...e,messages:[],isTyping:!1,currentStepId:null,collectedData:{}};case`UPDATE_MESSAGE`:return{...e,messages:e.messages.map(e=>e.id===t.payload.id?{...e,...t.payload.updates}:e)};default:return e}}var p=e=>({isOpen:e.defaultOpen??!1,messages:e.initialMessages??[],isTyping:!1,showWelcome:!!e.welcomeScreen,currentStepId:null,collectedData:{},isLoggedIn:!e.loginForm}),m=t(null);function h(){let e=r(m);if(!e)throw Error(`useChatContext must be used within ChatProvider`);return e}var g={primaryColor:`#6C5CE7`,headerBg:`linear-gradient(135deg, #6C5CE7 0%, #A29BFE 100%)`,headerText:`#FFFFFF`,bubbleBg:`rgba(241, 243, 249, 0.85)`,bubbleText:`#2D3436`,userBubbleBg:`linear-gradient(135deg, #6C5CE7 0%, #A29BFE 100%)`,userBubbleText:`#FFFFFF`,fontFamily:`"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,fontSize:`14px`,borderRadius:`20px`,windowWidth:`400px`,windowHeight:`600px`,mode:`light`},_={headerBg:`linear-gradient(135deg, #2D1B69 0%, #4A3298 100%)`,headerText:`#F0F0FF`,bubbleBg:`rgba(45, 45, 70, 0.85)`,bubbleText:`#E8E8F0`,userBubbleBg:`linear-gradient(135deg, #6C5CE7 0%, #A29BFE 100%)`,userBubbleText:`#FFFFFF`};function v(e){let t={...g,...e};return t.mode===`dark`?{...t,..._,...e}:t}function y(e){return{"--cb-primary":e.primaryColor,"--cb-header-bg":e.headerBg,"--cb-header-text":e.headerText,"--cb-bubble-bg":e.bubbleBg,"--cb-bubble-text":e.bubbleText,"--cb-user-bubble-bg":e.userBubbleBg,"--cb-user-bubble-text":e.userBubbleText,"--cb-font-family":e.fontFamily,"--cb-font-size":e.fontSize,"--cb-border-radius":e.borderRadius,"--cb-window-width":e.windowWidth,"--cb-window-height":e.windowHeight,"--cb-bg":e.mode===`dark`?`rgba(22, 22, 40, 0.95)`:`rgba(255, 255, 255, 0.92)`,"--cb-border":e.mode===`dark`?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.06)`,"--cb-input-bg":e.mode===`dark`?`rgba(40, 40, 65, 0.8)`:`rgba(245, 247, 252, 0.9)`,"--cb-input-border":e.mode===`dark`?`rgba(255,255,255,0.1)`:`rgba(0,0,0,0.06)`,"--cb-input-text":e.mode===`dark`?`#E0E0E0`:`#2D3436`,"--cb-branding-bg":e.mode===`dark`?`rgba(20, 20, 35, 0.8)`:`rgba(250, 250, 255, 0.8)`}}function b(e,t){let n=e.mode===`dark`;return{root:{fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:`1.5`},launcher:{position:`fixed`,width:`62px`,height:`62px`,borderRadius:`50%`,background:e.headerBg,color:`#fff`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,boxShadow:`0 6px 24px rgba(108, 92, 231, 0.4), 0 2px 8px rgba(0,0,0,0.1)`,transition:`all 0.3s cubic-bezier(0.4, 0, 0.2, 1)`,zIndex:9998,...t?.launcher},window:{position:`fixed`,width:e.windowWidth,height:e.windowHeight,maxHeight:`85vh`,borderRadius:e.borderRadius,overflow:`hidden`,display:`flex`,flexDirection:`column`,boxShadow:n?`0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05)`:`0 20px 60px rgba(108, 92, 231, 0.15), 0 8px 24px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04)`,backgroundColor:n?`rgba(22, 22, 40, 0.95)`:`rgba(255, 255, 255, 0.95)`,backdropFilter:`blur(20px)`,WebkitBackdropFilter:`blur(20px)`,border:n?`1px solid rgba(255,255,255,0.08)`:`1px solid rgba(255,255,255,0.8)`,zIndex:9999,animation:`cb-window-enter 0.35s cubic-bezier(0.4, 0, 0.2, 1)`,...t?.window},header:{background:e.headerBg,color:e.headerText,padding:`18px 20px`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`12px`,flexShrink:0,position:`relative`,overflow:`hidden`,...t?.header},messageList:{flex:1,overflowY:`auto`,padding:`20px 16px`,display:`flex`,flexDirection:`column`,gap:`10px`,background:n?`linear-gradient(180deg, rgba(22, 22, 40, 0.98) 0%, rgba(30, 30, 50, 0.98) 100%)`:`linear-gradient(180deg, rgba(248, 249, 254, 0.95) 0%, rgba(255, 255, 255, 0.95) 100%)`,...t?.messageList},inputArea:{padding:`12px 16px 14px`,borderTop:`1px solid ${n?`rgba(255,255,255,0.06)`:`rgba(0,0,0,0.05)`}`,backgroundColor:n?`rgba(20, 20, 38, 0.9)`:`rgba(255, 255, 255, 0.95)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,flexShrink:0,...t?.inputArea},botBubble:{background:n?`rgba(45, 45, 70, 0.7)`:`rgba(241, 243, 249, 0.9)`,color:n?`#E8E8F0`:`#2D3436`,padding:`12px 16px`,borderRadius:`18px 18px 18px 4px`,maxWidth:`82%`,alignSelf:`flex-start`,wordBreak:`break-word`,whiteSpace:`pre-wrap`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,border:n?`1px solid rgba(255,255,255,0.06)`:`1px solid rgba(0,0,0,0.04)`,boxShadow:n?`0 2px 8px rgba(0,0,0,0.2)`:`0 2px 8px rgba(0,0,0,0.04)`,fontSize:`14px`,lineHeight:`1.55`,letterSpacing:`0.01em`},userBubble:{background:e.userBubbleBg,color:e.userBubbleText,padding:`12px 16px`,borderRadius:`18px 18px 4px 18px`,maxWidth:`82%`,alignSelf:`flex-end`,wordBreak:`break-word`,whiteSpace:`pre-wrap`,boxShadow:`0 4px 14px rgba(108, 92, 231, 0.25)`,fontSize:`14px`,lineHeight:`1.55`,letterSpacing:`0.01em`}}}var x=({size:e=18,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:t,children:u(`path`,{d:`M2.01 21L23 12 2.01 3 2 10l15 2-15 2z`})}),S=({size:e=28,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:u(`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`})}),C=({size:e=20,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),u(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]}),w=({size:e=20,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:u(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})}),T=({size:e=20,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`circle`,{cx:`12`,cy:`12`,r:`10`}),u(`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`}),u(`line`,{x1:`9`,y1:`9`,x2:`9.01`,y2:`9`}),u(`line`,{x1:`15`,y1:`9`,x2:`15.01`,y2:`9`})]}),E=({size:e=20,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:u(`path`,{d:`M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48`})}),D=({size:e=16,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`path`,{d:`M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z`}),u(`polyline`,{points:`14 2 14 8 20 8`})]}),O=({size:e=16,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),u(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),u(`polyline`,{points:`21 15 16 10 5 21`})]}),k=({size:e=14,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`circle`,{cx:`12`,cy:`12`,r:`10`}),u(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),u(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),A=({size:e=16,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`polyline`,{points:`1 4 1 10 7 10`}),u(`path`,{d:`M3.51 15a9 9 0 1 0 2.13-9.36L1 10`})]}),j=({onClick:e,isOpen:t,position:n,styles:r,icon:i,closeIcon:a,zIndex:o})=>{let s=n===`bottom-left`?{bottom:`24px`,left:`24px`}:{bottom:`24px`,right:`24px`};return u(`button`,{onClick:e,"aria-label":t?`Close chat`:`Open chat`,style:{...r.launcher,...s,...o==null?{}:{zIndex:o},transform:t?`scale(0.92) rotate(90deg)`:`scale(1)`,animation:t?`none`:`cb-launcher-pulse 3s ease-in-out infinite`},children:t?a??u(C,{size:22}):i??u(S,{size:26})})},ee=({config:e,styles:t,onClose:n,onRestart:r,logo:i,logoWidth:a})=>d(`div`,{style:t.header,children:[u(`div`,{style:{position:`absolute`,top:0,left:0,right:0,bottom:0,background:`linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 50%)`,pointerEvents:`none`}}),d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,flex:1,position:`relative`,zIndex:1},children:[e.avatar&&d(`div`,{style:{position:`relative`},children:[u(`img`,{src:e.avatar,alt:``,style:{width:`40px`,height:`40px`,borderRadius:`50%`,objectFit:`cover`,border:`2px solid rgba(255,255,255,0.3)`}}),u(`span`,{style:{position:`absolute`,bottom:`1px`,right:`1px`,width:`10px`,height:`10px`,backgroundColor:`#2ECC71`,borderRadius:`50%`,border:`2px solid rgba(255,255,255,0.8)`}})]}),i&&!e.avatar&&u(`img`,{src:i,alt:``,style:{width:a??`36px`,height:`auto`,objectFit:`contain`,filter:`brightness(1.1)`}}),!e.avatar&&!i&&u(`div`,{style:{width:`40px`,height:`40px`,borderRadius:`50%`,background:`rgba(255,255,255,0.2)`,backdropFilter:`blur(4px)`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,color:`rgba(255,255,255,0.9)`,border:`1px solid rgba(255,255,255,0.2)`},children:(e.title??`C`).charAt(0).toUpperCase()}),d(`div`,{children:[u(`div`,{style:{fontWeight:600,fontSize:`16px`,letterSpacing:`-0.01em`},children:e.title??`Chat with us`}),e.subtitle&&d(`div`,{style:{fontSize:`12px`,opacity:.8,display:`flex`,alignItems:`center`,gap:`5px`,marginTop:`1px`},children:[u(`span`,{style:{width:`6px`,height:`6px`,borderRadius:`50%`,backgroundColor:`#2ECC71`,display:`inline-block`}}),e.subtitle]})]})]}),d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,position:`relative`,zIndex:1},children:[e.showRestart&&r&&u(`button`,{onClick:r,"aria-label":`Restart conversation`,title:`Restart conversation`,style:{background:`rgba(255,255,255,0.1)`,border:`none`,color:`inherit`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,borderRadius:`8px`,transition:`background 0.2s ease`},onMouseEnter:e=>e.currentTarget.style.background=`rgba(255,255,255,0.2)`,onMouseLeave:e=>e.currentTarget.style.background=`rgba(255,255,255,0.1)`,children:u(A,{size:16})}),e.showMinimize&&u(`button`,{onClick:n,"aria-label":`Minimize chat`,style:{background:`rgba(255,255,255,0.1)`,border:`none`,color:`inherit`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,borderRadius:`8px`,transition:`background 0.2s ease`},onMouseEnter:e=>e.currentTarget.style.background=`rgba(255,255,255,0.2)`,onMouseLeave:e=>e.currentTarget.style.background=`rgba(255,255,255,0.1)`,children:u(w,{size:16})}),e.showClose!==!1&&u(`button`,{onClick:n,"aria-label":`Close chat`,style:{background:`rgba(255,255,255,0.1)`,border:`none`,color:`inherit`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,borderRadius:`8px`,transition:`background 0.2s ease`},onMouseEnter:e=>e.currentTarget.style.background=`rgba(255,255,255,0.2)`,onMouseLeave:e=>e.currentTarget.style.background=`rgba(255,255,255,0.1)`,children:u(C,{size:18})})]})]}),te=({content:e,onDismiss:t,primaryColor:n})=>d(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,overflow:`auto`,background:`linear-gradient(180deg, rgba(248, 249, 254, 0.95) 0%, rgba(255, 255, 255, 0.98) 100%)`},children:[u(`div`,{style:{flex:1,padding:`28px 24px`,overflow:`auto`},children:e}),u(`div`,{style:{padding:`16px 20px`,borderTop:`1px solid rgba(0,0,0,0.05)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,flexShrink:0},children:u(`button`,{onClick:t,style:{width:`100%`,padding:`14px`,background:`linear-gradient(135deg, ${n} 0%, ${ne(n,30)} 100%)`,color:`#fff`,border:`none`,borderRadius:`14px`,fontSize:`15px`,fontWeight:600,cursor:`pointer`,fontFamily:`inherit`,letterSpacing:`0.02em`,boxShadow:`0 6px 20px ${n}44`,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`},onMouseEnter:e=>{e.currentTarget.style.transform=`translateY(-1px)`,e.currentTarget.style.boxShadow=`0 8px 28px ${n}55`},onMouseLeave:e=>{e.currentTarget.style.transform=`translateY(0)`,e.currentTarget.style.boxShadow=`0 6px 20px ${n}44`},children:`Start Chat`})})]});function ne(e,t){let n=parseInt(e.replace(`#`,``),16),r=Math.min(255,(n>>16&255)+t),i=Math.min(255,(n>>8&255)+t),a=Math.min(255,(n&255)+t);return`#${(r<<16|i<<8|a).toString(16).padStart(6,`0`)}`}var M=({field:e,value:t,onChange:n,error:r})=>{let i=e.type===`textarea`,a=e.type===`textarea`?void 0:e.type,o={width:`100%`,padding:`10px 14px`,border:`1.5px solid ${r?`rgba(229, 62, 62, 0.5)`:`rgba(0,0,0,0.08)`}`,borderRadius:`12px`,fontSize:`13px`,fontFamily:`inherit`,outline:`none`,boxSizing:`border-box`,transition:`all 0.2s ease`,backgroundColor:`rgba(245, 247, 252, 0.6)`,color:`#2D3436`,letterSpacing:`0.01em`};return d(`div`,{style:{marginBottom:`14px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500,color:`#2D3436`},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`3px`},children:`*`})]}),i?u(`textarea`,{value:t,onChange:e=>n(e.target.value),placeholder:e.placeholder,required:e.required,rows:3,style:{...o,resize:`vertical`},minLength:e.validation?.minLength,maxLength:e.validation?.maxLength}):u(`input`,{type:a,value:t,onChange:e=>n(e.target.value),placeholder:e.placeholder,required:e.required,style:o,min:e.validation?.min,max:e.validation?.max,minLength:e.validation?.minLength,maxLength:e.validation?.maxLength,pattern:e.validation?.pattern}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},N=({field:e,value:t,onChange:n,error:r})=>{let i=e.type===`multiselect`||e.multiple,a=e=>{n(i?Array.from(e.target.selectedOptions,e=>e.value):e.target.value)},o=i?Array.isArray(t)?t:[t].filter(Boolean):typeof t==`string`?t:``;return d(`div`,{style:{marginBottom:`14px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500,color:`#2D3436`},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`3px`},children:`*`})]}),d(`select`,{value:o,onChange:a,multiple:i,required:e.required,style:{width:`100%`,padding:`10px 14px`,border:`1.5px solid ${r?`rgba(229, 62, 62, 0.5)`:`rgba(0,0,0,0.08)`}`,borderRadius:`12px`,fontSize:`13px`,fontFamily:`inherit`,outline:`none`,backgroundColor:`rgba(245, 247, 252, 0.6)`,color:`#2D3436`,boxSizing:`border-box`,transition:`all 0.2s ease`,...i?{minHeight:`80px`}:{}},children:[!i&&u(`option`,{value:``,children:`Select...`}),e.options?.map(e=>u(`option`,{value:e.value,children:e.label},e.value))]}),i&&u(`div`,{style:{fontSize:`11px`,color:`#888`,marginTop:`2px`},children:`Hold Ctrl/Cmd to select multiple`}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},P=({field:e,value:t,onChange:n,error:r})=>d(`div`,{style:{marginBottom:`12px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),u(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:e.options?.map(r=>d(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`13px`},children:[u(`input`,{type:`radio`,name:e.name,value:r.value,checked:t===r.value,onChange:()=>n(r.value),style:{margin:0}}),r.label]},r.value))}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]}),F=({field:e,value:t,onChange:n,error:r})=>{let i=e=>{t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])};return d(`div`,{style:{marginBottom:`12px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),u(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:e.options?.map(e=>d(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`13px`},children:[u(`input`,{type:`checkbox`,checked:t.includes(e.value),onChange:()=>i(e.value),style:{margin:0}}),e.label]},e.value))}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},I=({field:e,value:t,onChange:n,error:r,primaryColor:i})=>{let a=s(null),o=t?Array.from(t).map(e=>e.name).join(`, `):``;return d(`div`,{style:{marginBottom:`12px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`4px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),u(`input`,{ref:a,type:`file`,accept:e.accept,multiple:e.multiple,onChange:e=>n(e.target.files),style:{display:`none`}}),u(`button`,{type:`button`,onClick:()=>a.current?.click(),style:{padding:`8px 16px`,border:`1px dashed ${r?`#E53E3E`:`#D1D5DB`}`,borderRadius:`8px`,backgroundColor:`#FAFAFA`,cursor:`pointer`,fontSize:`13px`,color:`#555`,width:`100%`,textAlign:`left`},children:o||e.placeholder||`Choose file(s)...`}),o&&d(`div`,{style:{fontSize:`12px`,color:i,marginTop:`4px`},children:[Array.from(t).length,` file(s) selected`]}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},L=({config:e,onSubmit:t,primaryColor:r,renderFormField:i})=>{let[a,o]=c(()=>{let t={};for(let n of e.fields)n.defaultValue===void 0?n.type===`checkbox`||n.type===`multiselect`?t[n.name]=[]:n.type===`file`?t[n.name]=null:t[n.name]=``:t[n.name]=n.defaultValue;return t}),[s,l]=c({}),[f,p]=c(!1),m=n((e,t)=>{o(n=>({...n,[e]:t})),l(t=>{let n={...t};return delete n[e],n})},[]),h=()=>{let t={};for(let n of e.fields){let e=a[n.name];if(n.required&&(e===``||e==null||Array.isArray(e)&&e.length===0)){t[n.name]=n.validation?.message??`${n.label||n.name} is required`;continue}if(n.validation?.pattern&&typeof e==`string`&&e)try{new RegExp(n.validation.pattern).test(e)||(t[n.name]=n.validation.message??`Invalid format`)}catch{}}return l(t),Object.keys(t).length===0};return f?u(`div`,{style:{padding:`16px`,background:`linear-gradient(135deg, rgba(46, 213, 115, 0.1), rgba(46, 213, 115, 0.05))`,borderRadius:`14px`,fontSize:`14px`,color:`#2ecc71`,textAlign:`center`,fontWeight:500,border:`1px solid rgba(46, 213, 115, 0.15)`,animation:`cb-fade-in 0.3s ease-out`},children:`✓ Submitted successfully`}):d(`form`,{onSubmit:e=>{e.preventDefault(),h()&&(p(!0),t(a))},style:{background:`rgba(255, 255, 255, 0.7)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,borderRadius:`16px`,padding:`20px`,border:`1px solid rgba(0,0,0,0.06)`,boxShadow:`0 4px 16px rgba(0,0,0,0.04)`,animation:`cb-slide-up 0.35s ease-out`},children:[e.title&&u(`div`,{style:{fontWeight:600,fontSize:`15px`,marginBottom:`4px`,color:`#2D3436`,letterSpacing:`-0.01em`},children:e.title}),e.description&&u(`div`,{style:{fontSize:`12px`,color:`rgba(0,0,0,0.45)`,marginBottom:`16px`,lineHeight:`1.5`},children:e.description}),e.fields.map(e=>u(re,{field:e,value:a[e.name],onChange:t=>m(e.name,t),error:s[e.name],primaryColor:r,renderFormField:i},e.name)),u(`button`,{type:`submit`,style:{width:`100%`,padding:`12px`,background:`linear-gradient(135deg, ${r} 0%, ${ie(r,30)} 100%)`,color:`#fff`,border:`none`,borderRadius:`12px`,fontSize:`14px`,fontWeight:600,cursor:`pointer`,marginTop:`8px`,fontFamily:`inherit`,letterSpacing:`0.02em`,boxShadow:`0 4px 14px ${r}33`,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`},onMouseEnter:e=>{e.currentTarget.style.transform=`translateY(-1px)`,e.currentTarget.style.boxShadow=`0 6px 20px ${r}44`},onMouseLeave:e=>{e.currentTarget.style.transform=`translateY(0)`,e.currentTarget.style.boxShadow=`0 4px 14px ${r}33`},children:e.submitLabel??`Submit`})]})},re=({field:e,value:t,onChange:n,error:r,primaryColor:i,renderFormField:a})=>{let o=a?.[e.type];switch(e.type){case`text`:case`email`:case`password`:case`number`:case`tel`:case`url`:case`textarea`:case`date`:case`time`:{let i={type:e.type,field:e,value:String(t??``),onChange:n,error:r},a=u(M,{field:e,value:String(t??``),onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`select`:case`multiselect`:{let i={type:e.type,field:e,value:t,onChange:n,error:r},a=u(N,{field:e,value:t,onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`radio`:{let i={type:`radio`,field:e,value:String(t??``),onChange:n,error:r},a=u(P,{field:e,value:String(t??``),onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`checkbox`:{let i={type:`checkbox`,field:e,value:t??[],onChange:n,error:r},a=u(F,{field:e,value:t??[],onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`file`:{let a={type:`file`,field:e,value:t,onChange:n,error:r,primaryColor:i},s=u(I,{field:e,value:t,onChange:n,error:r,primaryColor:i});return o?u(l,{children:o(a,s)}):s}case`hidden`:return u(`input`,{type:`hidden`,name:e.name,value:String(t??``)});default:return null}};function ie(e,t){let n=parseInt(e.replace(`#`,``),16),r=Math.min(255,(n>>16&255)+t),i=Math.min(255,(n>>8&255)+t),a=Math.min(255,(n&255)+t);return`#${(r<<16|i<<8|a).toString(16).padStart(6,`0`)}`}var R=({config:e,onLogin:t,primaryColor:n,renderFormField:r})=>u(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,justifyContent:`center`,padding:`24px`,overflow:`auto`,background:`linear-gradient(180deg, rgba(248, 249, 254, 0.95) 0%, rgba(255, 255, 255, 0.98) 100%)`},children:u(L,{config:e,onSubmit:t,primaryColor:n,renderFormField:r})}),z=({message:e,styles:t})=>{let n=e.sender===`bot`,r=e.sender===`system`,i=n||r?t.botBubble:t.userBubble;return e.text||e.attachments&&e.attachments.length>0?d(`div`,{style:{...i,...r?{background:`transparent`,border:`none`,boxShadow:`none`,color:`#999`,fontSize:`12px`,alignSelf:`center`,padding:`6px 12px`,backdropFilter:`none`,WebkitBackdropFilter:`none`}:{},animation:`cb-fade-in 0.3s ease-out`},children:[e.text&&u(`span`,{style:{display:`block`},children:e.text}),e.attachments&&e.attachments.length>0&&u(`div`,{style:{marginTop:e.text?`10px`:0,display:`flex`,flexDirection:`column`,gap:`6px`},children:e.attachments.map((e,t)=>u(ae,{attachment:e,isBot:n},t))})]}):null},ae=({attachment:e,isBot:t})=>e.type.startsWith(`image/`)&&e.url?d(`div`,{style:{borderRadius:`12px`,overflow:`hidden`,maxWidth:`220px`},children:[u(`img`,{src:e.url,alt:e.name,style:{width:`100%`,height:`auto`,display:`block`,borderRadius:`12px`}}),u(`div`,{style:{fontSize:`11px`,padding:`4px 0`,opacity:.6},children:e.name})]}):d(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,style:{display:`flex`,alignItems:`center`,gap:`8px`,padding:`8px 12px`,backgroundColor:t?`rgba(0,0,0,0.04)`:`rgba(255,255,255,0.15)`,borderRadius:`10px`,textDecoration:`none`,color:`inherit`,fontSize:`13px`,border:t?`1px solid rgba(0,0,0,0.06)`:`1px solid rgba(255,255,255,0.15)`,transition:`background 0.2s ease`},children:[u(D,{size:16}),u(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},children:e.name}),e.size&&u(`span`,{style:{fontSize:`11px`,opacity:.5,flexShrink:0},children:oe(e.size)})]});function oe(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}var B=({replies:e,onSelect:t,primaryColor:n})=>u(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,alignSelf:`flex-start`,maxWidth:`90%`,animation:`cb-slide-up 0.35s ease-out`,padding:`4px 0`},children:e.map(e=>u(`button`,{onClick:()=>t(e.value,e.label),style:{padding:`8px 18px`,borderRadius:`22px`,border:`1.5px solid ${n}`,backgroundColor:`rgba(108, 92, 231, 0.06)`,color:n,cursor:`pointer`,fontSize:`13px`,fontWeight:500,fontFamily:`inherit`,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`,backdropFilter:`blur(4px)`,WebkitBackdropFilter:`blur(4px)`,letterSpacing:`0.01em`},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=n,e.currentTarget.style.color=`#fff`,e.currentTarget.style.transform=`translateY(-1px)`,e.currentTarget.style.boxShadow=`0 4px 14px ${n}44`},onMouseLeave:e=>{e.currentTarget.style.backgroundColor=`rgba(108, 92, 231, 0.06)`,e.currentTarget.style.color=n,e.currentTarget.style.transform=`translateY(0)`,e.currentTarget.style.boxShadow=`none`},children:e.label},e.value))}),V=({color:e})=>{let t={width:`7px`,height:`7px`,borderRadius:`50%`,backgroundColor:e,opacity:.35,animation:`cb-typing-bounce 1.4s infinite ease-in-out`};return d(`div`,{style:{display:`flex`,gap:`5px`,padding:`14px 18px`,background:`rgba(241, 243, 249, 0.8)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderRadius:`18px 18px 18px 4px`,alignSelf:`flex-start`,alignItems:`center`,border:`1px solid rgba(0,0,0,0.04)`,boxShadow:`0 2px 8px rgba(0,0,0,0.04)`,animation:`cb-fade-in 0.3s ease-out`},children:[u(`span`,{style:{...t,animationDelay:`0s`}}),u(`span`,{style:{...t,animationDelay:`0.2s`}}),u(`span`,{style:{...t,animationDelay:`0.4s`}})]})},H=({messages:t,isTyping:n,styles:r,primaryColor:a,onQuickReply:o,onFormSubmit:c,components:l,onComponentComplete:f,collectedData:p,currentStepId:m,renderFormField:h})=>{let g=s(null);return i(()=>{g.current?.scrollIntoView({behavior:`smooth`})},[t,n]),d(`div`,{style:r.messageList,className:`cb-scrollbar`,children:[t.map(t=>d(e.Fragment,{children:[u(z,{message:t,styles:r}),t.quickReplies&&t.quickReplies.length>0&&u(B,{replies:t.quickReplies,onSelect:o,primaryColor:a}),t.form&&u(`div`,{style:{alignSelf:`flex-start`,width:`92%`,animation:`cb-slide-up 0.35s ease-out`},children:u(L,{config:t.form,onSubmit:e=>c(t.form.id,e),primaryColor:a,renderFormField:h})}),t.component&&l?.[t.component]&&u(`div`,{style:{alignSelf:`flex-start`,width:`92%`,animation:`cb-slide-up 0.35s ease-out`},children:e.createElement(l[t.component],{stepId:m??``,data:p??{},onComplete:e=>f?.(e)})})]},t.id)),n&&u(V,{color:a}),u(`div`,{ref:g})]})},U=[{name:`Smileys`,emojis:`😀.😃.😄.😁.😅.😂.🤣.😊.😇.🙂.😉.😍.🥰.😘.😋.😜.🤪.🤗.🤔.🤫.🤭.😏.😐.😑.😶.😌.😴.🤤.😷.🤒`.split(`.`)},{name:`Gestures`,emojis:`👍.👎.👌.✌️.🤞.🤟.🤘.👋.🤚.✋.🖖.👏.🙌.🤝.🙏.💪.🖐️.☝️.👆.👇.👈.👉.🤙.🫡.🫶.🫰.🫳.🫴.🫲.🫱`.split(`.`)},{name:`Hearts`,emojis:`❤️.🧡.💛.💚.💙.💜.🖤.🤍.🤎.💔.❣️.💕.💞.💓.💗.💖.💘.💝.💟.♥️.🫀.💌.💐.🌹.🌺.🌸.🌼.🌻.🌷.💮`.split(`.`)},{name:`Objects`,emojis:`🔥.⭐.✨.💯.🎉.🎊.🎯.🚀.💡.📌.📎.🔗.💻.📱.☎️.📧.📝.📋.📊.📈.🗂️.📁.🔒.🔑.⚙️.🛠️.🔧.📦.🏷️.✅`.split(`.`)}],W=({onSelect:e,onClose:t,primaryColor:n})=>{let[r,a]=c(0),o=s(null);i(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&t()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[t]);let l=U[r]?.emojis??[];return d(`div`,{ref:o,style:{position:`absolute`,bottom:`100%`,left:0,width:`280px`,backgroundColor:`rgba(255, 255, 255, 0.92)`,backdropFilter:`blur(20px)`,WebkitBackdropFilter:`blur(20px)`,borderRadius:`16px`,boxShadow:`0 8px 32px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)`,border:`1px solid rgba(255,255,255,0.8)`,overflow:`hidden`,zIndex:10,marginBottom:`8px`,animation:`cb-slide-up 0.25s ease-out`},children:[u(`div`,{style:{display:`flex`,borderBottom:`1px solid rgba(0,0,0,0.06)`,padding:`6px`,gap:`3px`},children:U.map((e,t)=>u(`button`,{onClick:()=>a(t),title:e.name,style:{flex:1,padding:`6px 4px`,border:`none`,borderRadius:`8px`,cursor:`pointer`,fontSize:`11px`,fontWeight:600,fontFamily:`inherit`,letterSpacing:`0.02em`,background:t===r?`linear-gradient(135deg, ${n}, ${n}CC)`:`transparent`,color:t===r?`#fff`:`rgba(0,0,0,0.4)`,transition:`all 0.2s ease`,boxShadow:t===r?`0 2px 8px ${n}33`:`none`},children:e.name},e.name))}),u(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(8, 1fr)`,gap:`2px`,padding:`8px`,maxHeight:`180px`,overflowY:`auto`},children:l.map(n=>u(`button`,{onClick:()=>{e(n),t()},style:{width:`30px`,height:`30px`,border:`none`,backgroundColor:`transparent`,cursor:`pointer`,fontSize:`18px`,borderRadius:`6px`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.backgroundColor=`rgba(108, 92, 231, 0.08)`,onMouseLeave:e=>e.currentTarget.style.backgroundColor=`transparent`,children:n},n))})]})},G=({config:e,onFiles:t,selectedFiles:n,onRemoveFile:r,primaryColor:i})=>{let a=s(null);return d(`div`,{children:[u(`input`,{ref:a,type:`file`,accept:e.accept,multiple:e.multiple!==!1,onChange:r=>{let i=r.target.files;if(!i||i.length===0)return;let o=Array.from(i);if(e.maxSize&&o.filter(t=>t.size>e.maxSize).length>0){alert(`File(s) too large. Max size: ${q(e.maxSize)}`);return}let s=e.maxFiles??5;if(n.length+o.length>s){alert(`Maximum ${s} files allowed`);return}t(o),a.current&&(a.current.value=``)},style:{display:`none`}}),u(`button`,{type:`button`,onClick:()=>a.current?.click(),"aria-label":`Attach file`,title:`Attach file`,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,color:`#999`,borderRadius:`6px`,transition:`color 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.color=i,onMouseLeave:e=>e.currentTarget.style.color=`#999`,children:u(E,{size:20})})]})},K=({files:e,onRemove:t,primaryColor:n})=>e.length===0?null:u(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`6px`,padding:`8px 12px 0`},children:e.map((e,r)=>u(se,{file:e,onRemove:()=>t(r),primaryColor:n},`${e.name}-${r}`))}),se=({file:e,onRemove:t,primaryColor:n})=>{let r=e.type.startsWith(`image/`);return d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,padding:`4px 8px`,backgroundColor:`#F3F4F6`,borderRadius:`8px`,fontSize:`12px`,maxWidth:`200px`},children:[u(`span`,{style:{color:n,flexShrink:0},children:u(r?O:D,{size:14})}),u(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,color:`#555`},children:e.name}),u(`span`,{style:{color:`#999`,fontSize:`11px`,flexShrink:0},children:q(e.size)}),u(`button`,{onClick:t,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`0`,display:`flex`,color:`#999`,flexShrink:0},children:u(k,{size:14})})]})};function q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}var J=({onSend:e,placeholder:t=`Type a message...`,primaryColor:r,isDark:i=!1,disabled:a,styleOverride:o,enableEmoji:l=!1,fileUpload:f,onFileUpload:p})=>{let[m,h]=c(``),[g,_]=c(!1),[v,y]=c([]),b=s(null),S=n(()=>{let t=m.trim();!t&&v.length===0||(e(t,v.length>0?v:void 0),h(``),y([]),b.current?.focus())},[m,v,e]),C=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),S())},w=e=>{h(t=>t+e),b.current?.focus()},E=e=>{y(t=>[...t,...e]),p?.(e)},D=e=>{y(t=>t.filter((t,n)=>n!==e))},O=m.trim()||v.length>0;return d(`div`,{style:{position:`relative`,...o},children:[v.length>0&&u(K,{files:v,onRemove:D,primaryColor:r}),g&&u(W,{onSelect:w,onClose:()=>_(!1),primaryColor:r}),d(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`flex-end`,background:i?`rgba(40, 40, 65, 0.5)`:`rgba(245, 247, 252, 0.7)`,borderRadius:`16px`,border:`1px solid ${i?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.05)`}`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,padding:`6px 6px 6px 12px`},children:[d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,flexShrink:0,paddingBottom:`2px`},children:[l&&u(`button`,{type:`button`,onClick:()=>_(!g),"aria-label":`Emoji`,title:`Emoji`,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`6px`,display:`flex`,color:g?r:i?`rgba(255,255,255,0.35)`:`rgba(0,0,0,0.3)`,borderRadius:`8px`,transition:`all 0.2s ease`},children:u(T,{size:20})}),f?.enabled&&u(G,{config:f,onFiles:E,selectedFiles:v,onRemoveFile:D,primaryColor:r})]}),u(`textarea`,{ref:b,value:m,onChange:e=>h(e.target.value),onKeyDown:C,placeholder:t,disabled:a,rows:1,style:{flex:1,padding:`8px 2px`,border:`none`,borderRadius:`12px`,outline:`none`,resize:`none`,fontFamily:`inherit`,fontSize:`14px`,lineHeight:`1.45`,maxHeight:`100px`,overflowY:`auto`,backgroundColor:`transparent`,color:i?`#E0E0E0`:`#2D3436`,letterSpacing:`0.01em`}}),u(`button`,{onClick:S,disabled:a||!O,"aria-label":`Send message`,style:{width:`36px`,height:`36px`,borderRadius:`12px`,background:O?`linear-gradient(135deg, ${r} 0%, ${ce(r,30)} 100%)`:i?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.06)`,color:O?`#fff`:i?`rgba(255,255,255,0.25)`:`rgba(0,0,0,0.2)`,border:`none`,cursor:O?`pointer`:`default`,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`,boxShadow:O?`0 4px 12px ${r}44`:`none`},children:u(x,{size:16})})]})]})};function ce(e,t){let n=parseInt(e.replace(`#`,``),16),r=Math.min(255,(n>>16&255)+t),i=Math.min(255,(n>>8&255)+t),a=Math.min(255,(n&255)+t);return`#${(r<<16|i<<8|a).toString(16).padStart(6,`0`)}`}var Y=({config:e,primaryColor:t})=>{if(e.showBranding===!1)return null;let n=e.poweredBy??`React ChatBot`;return d(`div`,{style:{padding:`8px 16px`,textAlign:`center`,fontSize:`11px`,color:`rgba(0,0,0,0.35)`,background:`rgba(250, 250, 255, 0.7)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderTop:`1px solid rgba(0,0,0,0.04)`,flexShrink:0,letterSpacing:`0.02em`},children:[`Powered by`,` `,e.poweredByUrl?u(`a`,{href:e.poweredByUrl,target:`_blank`,rel:`noopener noreferrer`,style:{color:t,textDecoration:`none`,fontWeight:600,transition:`opacity 0.2s ease`},children:n}):u(`span`,{style:{color:t,fontWeight:600},children:n})]})},X=class{constructor(e){this.collectedData={},this.idCounter=0,this.uid=()=>`msg_${Date.now()}_${++this.idCounter}`,this.stepHistory=[],this.startStep=e.startStep,this.steps=new Map(e.steps.map(e=>[e.id,e]))}getStartStepId(){return this.startStep}getStep(e){return this.steps.get(e)}getData(){return{...this.collectedData}}setData(e,t){this.collectedData[e]=t}mergeData(e){Object.assign(this.collectedData,e)}pushHistory(e){this.stepHistory.push(e)}popHistory(){return this.stepHistory.pop(),this.stepHistory.pop()}canGoBack(){return this.stepHistory.length>1}reset(){this.collectedData={},this.stepHistory=[]}resolveNext(e,t){if(e.condition){let{field:t,operator:n,value:r,then:i,else:a}=e.condition,o=this.collectedData[t];return this.evaluate(o,n,r)?i:a}if(t&&e.quickReplies){let n=e.quickReplies.find(e=>e.value===t);if(n?.next)return n.next}return e.next}stepExpectsQuickReply(e){return!!(e.quickReplies&&e.quickReplies.length>0)}stepExpectsForm(e){return!!e.form}matchQuickReply(e,t){if(!e.quickReplies)return;let n=t.toLowerCase().trim();return e.quickReplies.find(e=>e.value.toLowerCase()===n)||e.quickReplies.find(e=>e.label.toLowerCase().replace(/[^\w\s]/g,``).trim()===n)||e.quickReplies.find(e=>n.includes(e.value.toLowerCase())||e.label.toLowerCase().includes(n))}buildMessages(e){let t=[],n=e.messages??(e.message?[e.message]:[]);for(let e of n)t.push({id:this.uid(),sender:`bot`,text:e,timestamp:Date.now()});return e.quickReplies&&t.length>0&&(t[t.length-1].quickReplies=e.quickReplies),e.form&&t.push({id:this.uid(),sender:`bot`,timestamp:Date.now(),form:e.form}),e.component&&t.push({id:this.uid(),sender:`bot`,timestamp:Date.now(),component:e.component}),t}evaluate(e,t,n){switch(t){case`eq`:return String(e)===String(n);case`neq`:return String(e)!==String(n);case`contains`:return String(e).includes(String(n));case`gt`:return Number(e)>Number(n);case`lt`:return Number(e)<Number(n);default:return!1}}},le=0,Z=()=>`msg_${Date.now()}_${++le}`,Q=e=>new Promise(t=>setTimeout(t,e)),ue={"/help":`Show available commands`,"/cancel":`Cancel current step and go back`,"/back":`Go back to the previous step`,"/restart":`Restart the conversation from the beginning`};function de(){let{state:e,dispatch:t,props:r}=h(),a=s(null),o=s(!1),c=s(e);c.current=e;let l=s(r);l.current=r,i(()=>{r.flow&&(a.current=new X(r.flow),o.current=!1)},[r.flow]);let u=n(async(e,n)=>{t({type:`SET_TYPING`,payload:!0}),await Q(400);let r={id:Z(),sender:`bot`,text:e,timestamp:Date.now(),...n};t({type:`SET_TYPING`,payload:!1}),t({type:`ADD_MESSAGE`,payload:r}),l.current.callbacks?.onMessageReceive?.(r)},[t]),d=n(e=>{t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`system`,text:e,timestamp:Date.now()}})},[t]),f=s(async()=>{});f.current=async e=>{let n=a.current;if(!n)return;let r=n.getStep(e);if(!r)return;n.pushHistory(e),t({type:`SET_STEP`,payload:e}),t({type:`SET_TYPING`,payload:!0}),await Q(r.delay??500);let i=n.buildMessages(r);if(t({type:`SET_TYPING`,payload:!1}),t({type:`ADD_MESSAGES`,payload:i}),i.forEach(e=>l.current.callbacks?.onMessageReceive?.(e)),r.asyncAction){let e=l.current.actionHandlers?.[r.asyncAction.handler];if(e){let i=Z();t({type:`ADD_MESSAGE`,payload:{id:i,sender:`bot`,text:r.asyncAction.loadingMessage??`Processing...`,timestamp:Date.now()}});let a={updateMessage:e=>{t({type:`UPDATE_MESSAGE`,payload:{id:i,updates:{text:e}}})}};try{let o=await e(n.getData(),a);o.data&&(n.mergeData(o.data),t({type:`SET_DATA`,payload:o.data})),t({type:`UPDATE_MESSAGE`,payload:{id:i,updates:{text:o.message??(o.status===`success`?r.asyncAction.successMessage??`Done!`:r.asyncAction.errorMessage??`Something went wrong.`)}}});let s=p(r,o);s&&(await Q(600),f.current(s))}catch{t({type:`UPDATE_MESSAGE`,payload:{id:i,updates:{text:r.asyncAction.errorMessage??`❌ Something went wrong.`}}}),r.asyncAction.onError&&(await Q(600),f.current(r.asyncAction.onError))}return}}r.component&&l.current.components?.[r.component]||!r.quickReplies&&!r.form&&r.next&&(await Q(300),f.current(r.next))};function p(e,t){return t.next?t.next:e.asyncAction?.routes?.[t.status]?e.asyncAction.routes[t.status]:t.status===`success`&&e.asyncAction?.onSuccess?e.asyncAction.onSuccess:t.status===`error`&&e.asyncAction?.onError?e.asyncAction.onError:e.next}let m=n(e=>f.current(e),[]),g=n(()=>{let e=a.current;if(!e||!e.canGoBack()){d(`There is no previous step to go back to.`);return}t({type:`CLEAR_QUICK_REPLIES`});let n=e.popHistory();n?m(n):d(`There is no previous step to go back to.`)},[t,m,d]),_=n(()=>{let e=a.current;e&&e.reset(),o.current=!1,t({type:`RESET_CHAT`}),e&&(o.current=!0,m(e.getStartStepId()))},[t,m]),v=s(()=>!1);v.current=e=>{let t=e.trim().toLowerCase();if(!t.startsWith(`/`))return!1;switch(t){case`/help`:return d(`Available commands:
1
+ import e,{createContext as t,useCallback as n,useContext as r,useEffect as i,useMemo as a,useReducer as o,useRef as s,useState as c}from"react";import{Fragment as l,jsx as u,jsxs as d}from"react/jsx-runtime";function f(e,t){switch(t.type){case`TOGGLE_OPEN`:return{...e,isOpen:!e.isOpen};case`SET_OPEN`:return{...e,isOpen:t.payload};case`ADD_MESSAGE`:return{...e,messages:[...e.messages,t.payload]};case`ADD_MESSAGES`:return{...e,messages:[...e.messages,...t.payload]};case`SET_TYPING`:return{...e,isTyping:t.payload};case`DISMISS_WELCOME`:return{...e,showWelcome:!1};case`SET_STEP`:return{...e,currentStepId:t.payload};case`SET_DATA`:return{...e,collectedData:{...e.collectedData,...t.payload}};case`SET_LOGGED_IN`:return{...e,isLoggedIn:t.payload};case`CLEAR_QUICK_REPLIES`:{let t=-1;for(let n=e.messages.length-1;n>=0;n--)if(e.messages[n].quickReplies){t=n;break}if(t===-1)return e;let n=[...e.messages];return n[t]={...n[t],quickReplies:void 0},{...e,messages:n}}case`RESET_CHAT`:return{...e,messages:[],isTyping:!1,currentStepId:null,collectedData:{}};case`UPDATE_MESSAGE`:return{...e,messages:e.messages.map(e=>e.id===t.payload.id?{...e,...t.payload.updates}:e)};default:return e}}var p=e=>({isOpen:e.defaultOpen??!1,messages:e.initialMessages??[],isTyping:!1,showWelcome:!!e.welcomeScreen,currentStepId:null,collectedData:{},isLoggedIn:!e.loginForm}),m=t(null);function h(){let e=r(m);if(!e)throw Error(`useChatContext must be used within ChatProvider`);return e}var g={primaryColor:`#6C5CE7`,headerBg:`linear-gradient(135deg, #6C5CE7 0%, #A29BFE 100%)`,headerText:`#FFFFFF`,bubbleBg:`rgba(241, 243, 249, 0.85)`,bubbleText:`#2D3436`,userBubbleBg:`linear-gradient(135deg, #6C5CE7 0%, #A29BFE 100%)`,userBubbleText:`#FFFFFF`,fontFamily:`"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,fontSize:`14px`,borderRadius:`20px`,windowWidth:`400px`,windowHeight:`600px`,mode:`light`},_={headerBg:`linear-gradient(135deg, #2D1B69 0%, #4A3298 100%)`,headerText:`#F0F0FF`,bubbleBg:`rgba(45, 45, 70, 0.85)`,bubbleText:`#E8E8F0`,userBubbleBg:`linear-gradient(135deg, #6C5CE7 0%, #A29BFE 100%)`,userBubbleText:`#FFFFFF`};function v(e){let t={...g,...e};return t.mode===`dark`?{...t,..._,...e}:t}function y(e){return{"--cb-primary":e.primaryColor,"--cb-header-bg":e.headerBg,"--cb-header-text":e.headerText,"--cb-bubble-bg":e.bubbleBg,"--cb-bubble-text":e.bubbleText,"--cb-user-bubble-bg":e.userBubbleBg,"--cb-user-bubble-text":e.userBubbleText,"--cb-font-family":e.fontFamily,"--cb-font-size":e.fontSize,"--cb-border-radius":e.borderRadius,"--cb-window-width":e.windowWidth,"--cb-window-height":e.windowHeight,"--cb-bg":e.mode===`dark`?`rgba(22, 22, 40, 0.95)`:`rgba(255, 255, 255, 0.92)`,"--cb-border":e.mode===`dark`?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.06)`,"--cb-input-bg":e.mode===`dark`?`rgba(40, 40, 65, 0.8)`:`rgba(245, 247, 252, 0.9)`,"--cb-input-border":e.mode===`dark`?`rgba(255,255,255,0.1)`:`rgba(0,0,0,0.06)`,"--cb-input-text":e.mode===`dark`?`#E0E0E0`:`#2D3436`,"--cb-branding-bg":e.mode===`dark`?`rgba(20, 20, 35, 0.8)`:`rgba(250, 250, 255, 0.8)`}}function b(e,t){let n=e.mode===`dark`;return{root:{fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:`1.5`},launcher:{position:`fixed`,width:`62px`,height:`62px`,borderRadius:`50%`,background:e.headerBg,color:`#fff`,border:`none`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,boxShadow:`0 6px 24px rgba(108, 92, 231, 0.4), 0 2px 8px rgba(0,0,0,0.1)`,transition:`all 0.3s cubic-bezier(0.4, 0, 0.2, 1)`,zIndex:9998,...t?.launcher},window:{position:`fixed`,width:e.windowWidth,height:e.windowHeight,maxHeight:`85vh`,borderRadius:e.borderRadius,overflow:`hidden`,display:`flex`,flexDirection:`column`,boxShadow:n?`0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05)`:`0 20px 60px rgba(108, 92, 231, 0.15), 0 8px 24px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04)`,backgroundColor:n?`rgba(22, 22, 40, 0.95)`:`rgba(255, 255, 255, 0.95)`,backdropFilter:`blur(20px)`,WebkitBackdropFilter:`blur(20px)`,border:n?`1px solid rgba(255,255,255,0.08)`:`1px solid rgba(255,255,255,0.8)`,zIndex:9999,animation:`cb-window-enter 0.35s cubic-bezier(0.4, 0, 0.2, 1)`,...t?.window},header:{background:e.headerBg,color:e.headerText,padding:`18px 20px`,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:`12px`,flexShrink:0,position:`relative`,overflow:`hidden`,...t?.header},messageList:{flex:1,overflowY:`auto`,padding:`20px 16px`,display:`flex`,flexDirection:`column`,gap:`10px`,background:n?`linear-gradient(180deg, rgba(22, 22, 40, 0.98) 0%, rgba(30, 30, 50, 0.98) 100%)`:`linear-gradient(180deg, rgba(248, 249, 254, 0.95) 0%, rgba(255, 255, 255, 0.95) 100%)`,...t?.messageList},inputArea:{padding:`12px 16px 14px`,borderTop:`1px solid ${n?`rgba(255,255,255,0.06)`:`rgba(0,0,0,0.05)`}`,backgroundColor:n?`rgba(20, 20, 38, 0.9)`:`rgba(255, 255, 255, 0.95)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,flexShrink:0,...t?.inputArea},botBubble:{background:n?`rgba(45, 45, 70, 0.7)`:`rgba(241, 243, 249, 0.9)`,color:n?`#E8E8F0`:`#2D3436`,padding:`12px 16px`,borderRadius:`18px 18px 18px 4px`,maxWidth:`82%`,alignSelf:`flex-start`,wordBreak:`break-word`,whiteSpace:`pre-wrap`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,border:n?`1px solid rgba(255,255,255,0.06)`:`1px solid rgba(0,0,0,0.04)`,boxShadow:n?`0 2px 8px rgba(0,0,0,0.2)`:`0 2px 8px rgba(0,0,0,0.04)`,fontSize:`14px`,lineHeight:`1.55`,letterSpacing:`0.01em`},userBubble:{background:e.userBubbleBg,color:e.userBubbleText,padding:`12px 16px`,borderRadius:`18px 18px 4px 18px`,maxWidth:`82%`,alignSelf:`flex-end`,wordBreak:`break-word`,whiteSpace:`pre-wrap`,boxShadow:`0 4px 14px rgba(108, 92, 231, 0.25)`,fontSize:`14px`,lineHeight:`1.55`,letterSpacing:`0.01em`}}}var x=({size:e=18,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:t,children:u(`path`,{d:`M2.01 21L23 12 2.01 3 2 10l15 2-15 2z`})}),S=({size:e=28,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:u(`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`})}),C=({size:e=20,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),u(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]}),w=({size:e=20,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:u(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})}),T=({size:e=20,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`circle`,{cx:`12`,cy:`12`,r:`10`}),u(`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`}),u(`line`,{x1:`9`,y1:`9`,x2:`9.01`,y2:`9`}),u(`line`,{x1:`15`,y1:`9`,x2:`15.01`,y2:`9`})]}),E=({size:e=20,color:t=`currentColor`})=>u(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:u(`path`,{d:`M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48`})}),D=({size:e=16,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`path`,{d:`M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z`}),u(`polyline`,{points:`14 2 14 8 20 8`})]}),O=({size:e=16,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),u(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),u(`polyline`,{points:`21 15 16 10 5 21`})]}),k=({size:e=14,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`circle`,{cx:`12`,cy:`12`,r:`10`}),u(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),u(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),A=({size:e=16,color:t=`currentColor`})=>d(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[u(`polyline`,{points:`1 4 1 10 7 10`}),u(`path`,{d:`M3.51 15a9 9 0 1 0 2.13-9.36L1 10`})]}),j=({onClick:e,isOpen:t,position:n,styles:r,icon:i,closeIcon:a,zIndex:o})=>{let s=n===`bottom-left`?{bottom:`24px`,left:`24px`}:{bottom:`24px`,right:`24px`};return u(`button`,{onClick:e,"aria-label":t?`Close chat`:`Open chat`,style:{...r.launcher,...s,...o==null?{}:{zIndex:o},transform:t?`scale(0.92) rotate(90deg)`:`scale(1)`,animation:t?`none`:`cb-launcher-pulse 3s ease-in-out infinite`},children:t?a??u(C,{size:22}):i??u(S,{size:26})})},ee=({config:e,styles:t,onClose:n,onRestart:r,logo:i,logoWidth:a})=>d(`div`,{style:t.header,children:[u(`div`,{style:{position:`absolute`,top:0,left:0,right:0,bottom:0,background:`linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 50%)`,pointerEvents:`none`}}),d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,flex:1,position:`relative`,zIndex:1},children:[e.avatar&&d(`div`,{style:{position:`relative`},children:[u(`img`,{src:e.avatar,alt:``,style:{width:`40px`,height:`40px`,borderRadius:`50%`,objectFit:`cover`,border:`2px solid rgba(255,255,255,0.3)`}}),u(`span`,{style:{position:`absolute`,bottom:`1px`,right:`1px`,width:`10px`,height:`10px`,backgroundColor:`#2ECC71`,borderRadius:`50%`,border:`2px solid rgba(255,255,255,0.8)`}})]}),i&&!e.avatar&&u(`img`,{src:i,alt:``,style:{width:a??`36px`,height:`auto`,objectFit:`contain`,filter:`brightness(1.1)`}}),!e.avatar&&!i&&u(`div`,{style:{width:`40px`,height:`40px`,borderRadius:`50%`,background:`rgba(255,255,255,0.2)`,backdropFilter:`blur(4px)`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`18px`,fontWeight:700,color:`rgba(255,255,255,0.9)`,border:`1px solid rgba(255,255,255,0.2)`},children:(e.title??`C`).charAt(0).toUpperCase()}),d(`div`,{children:[u(`div`,{style:{fontWeight:600,fontSize:`16px`,letterSpacing:`-0.01em`},children:e.title??`Chat with us`}),e.subtitle&&d(`div`,{style:{fontSize:`12px`,opacity:.8,display:`flex`,alignItems:`center`,gap:`5px`,marginTop:`1px`},children:[u(`span`,{style:{width:`6px`,height:`6px`,borderRadius:`50%`,backgroundColor:`#2ECC71`,display:`inline-block`}}),e.subtitle]})]})]}),d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,position:`relative`,zIndex:1},children:[e.showRestart&&r&&u(`button`,{onClick:r,"aria-label":`Restart conversation`,title:`Restart conversation`,style:{background:`rgba(255,255,255,0.1)`,border:`none`,color:`inherit`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,borderRadius:`8px`,transition:`background 0.2s ease`},onMouseEnter:e=>e.currentTarget.style.background=`rgba(255,255,255,0.2)`,onMouseLeave:e=>e.currentTarget.style.background=`rgba(255,255,255,0.1)`,children:u(A,{size:16})}),e.showMinimize&&u(`button`,{onClick:n,"aria-label":`Minimize chat`,style:{background:`rgba(255,255,255,0.1)`,border:`none`,color:`inherit`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,borderRadius:`8px`,transition:`background 0.2s ease`},onMouseEnter:e=>e.currentTarget.style.background=`rgba(255,255,255,0.2)`,onMouseLeave:e=>e.currentTarget.style.background=`rgba(255,255,255,0.1)`,children:u(w,{size:16})}),e.showClose!==!1&&u(`button`,{onClick:n,"aria-label":`Close chat`,style:{background:`rgba(255,255,255,0.1)`,border:`none`,color:`inherit`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,borderRadius:`8px`,transition:`background 0.2s ease`},onMouseEnter:e=>e.currentTarget.style.background=`rgba(255,255,255,0.2)`,onMouseLeave:e=>e.currentTarget.style.background=`rgba(255,255,255,0.1)`,children:u(C,{size:18})})]})]}),te=({content:e,onDismiss:t,primaryColor:n})=>d(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,overflow:`auto`,background:`linear-gradient(180deg, rgba(248, 249, 254, 0.95) 0%, rgba(255, 255, 255, 0.98) 100%)`},children:[u(`div`,{style:{flex:1,padding:`28px 24px`,overflow:`auto`},children:e}),u(`div`,{style:{padding:`16px 20px`,borderTop:`1px solid rgba(0,0,0,0.05)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,flexShrink:0},children:u(`button`,{onClick:t,style:{width:`100%`,padding:`14px`,background:`linear-gradient(135deg, ${n} 0%, ${ne(n,30)} 100%)`,color:`#fff`,border:`none`,borderRadius:`14px`,fontSize:`15px`,fontWeight:600,cursor:`pointer`,fontFamily:`inherit`,letterSpacing:`0.02em`,boxShadow:`0 6px 20px ${n}44`,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`},onMouseEnter:e=>{e.currentTarget.style.transform=`translateY(-1px)`,e.currentTarget.style.boxShadow=`0 8px 28px ${n}55`},onMouseLeave:e=>{e.currentTarget.style.transform=`translateY(0)`,e.currentTarget.style.boxShadow=`0 6px 20px ${n}44`},children:`Start Chat`})})]});function ne(e,t){let n=parseInt(e.replace(`#`,``),16),r=Math.min(255,(n>>16&255)+t),i=Math.min(255,(n>>8&255)+t),a=Math.min(255,(n&255)+t);return`#${(r<<16|i<<8|a).toString(16).padStart(6,`0`)}`}var M=({field:e,value:t,onChange:n,error:r})=>{let i=e.type===`textarea`,a=e.type===`textarea`?void 0:e.type,o={width:`100%`,padding:`10px 14px`,border:`1.5px solid ${r?`rgba(229, 62, 62, 0.5)`:`rgba(0,0,0,0.08)`}`,borderRadius:`12px`,fontSize:`13px`,fontFamily:`inherit`,outline:`none`,boxSizing:`border-box`,transition:`all 0.2s ease`,backgroundColor:`rgba(245, 247, 252, 0.6)`,color:`#2D3436`,letterSpacing:`0.01em`};return d(`div`,{style:{marginBottom:`14px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500,color:`#2D3436`},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`3px`},children:`*`})]}),i?u(`textarea`,{value:t,onChange:e=>n(e.target.value),placeholder:e.placeholder,required:e.required,rows:3,style:{...o,resize:`vertical`},minLength:e.validation?.minLength,maxLength:e.validation?.maxLength}):u(`input`,{type:a,value:t,onChange:e=>n(e.target.value),placeholder:e.placeholder,required:e.required,style:o,min:e.validation?.min,max:e.validation?.max,minLength:e.validation?.minLength,maxLength:e.validation?.maxLength,pattern:e.validation?.pattern}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},N=({field:e,value:t,onChange:n,error:r})=>{let i=e.type===`multiselect`||e.multiple,a=e=>{n(i?Array.from(e.target.selectedOptions,e=>e.value):e.target.value)},o=i?Array.isArray(t)?t:[t].filter(Boolean):typeof t==`string`?t:``;return d(`div`,{style:{marginBottom:`14px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500,color:`#2D3436`},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`3px`},children:`*`})]}),d(`select`,{value:o,onChange:a,multiple:i,required:e.required,style:{width:`100%`,padding:`10px 14px`,border:`1.5px solid ${r?`rgba(229, 62, 62, 0.5)`:`rgba(0,0,0,0.08)`}`,borderRadius:`12px`,fontSize:`13px`,fontFamily:`inherit`,outline:`none`,backgroundColor:`rgba(245, 247, 252, 0.6)`,color:`#2D3436`,boxSizing:`border-box`,transition:`all 0.2s ease`,...i?{minHeight:`80px`}:{}},children:[!i&&u(`option`,{value:``,children:`Select...`}),e.options?.map(e=>u(`option`,{value:e.value,children:e.label},e.value))]}),i&&u(`div`,{style:{fontSize:`11px`,color:`#888`,marginTop:`2px`},children:`Hold Ctrl/Cmd to select multiple`}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},P=({field:e,value:t,onChange:n,error:r})=>d(`div`,{style:{marginBottom:`12px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),u(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:e.options?.map(r=>d(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`13px`},children:[u(`input`,{type:`radio`,name:e.name,value:r.value,checked:t===r.value,onChange:()=>n(r.value),style:{margin:0}}),r.label]},r.value))}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]}),F=({field:e,value:t,onChange:n,error:r})=>{let i=e=>{t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])};return d(`div`,{style:{marginBottom:`12px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),u(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:e.options?.map(e=>d(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`13px`},children:[u(`input`,{type:`checkbox`,checked:t.includes(e.value),onChange:()=>i(e.value),style:{margin:0}}),e.label]},e.value))}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},I=({field:e,value:t,onChange:n,error:r,primaryColor:i})=>{let a=s(null),o=t?Array.from(t).map(e=>e.name).join(`, `):``;return d(`div`,{style:{marginBottom:`12px`},children:[e.label&&d(`label`,{style:{display:`block`,marginBottom:`4px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&u(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),u(`input`,{ref:a,type:`file`,accept:e.accept,multiple:e.multiple,onChange:e=>n(e.target.files),style:{display:`none`}}),u(`button`,{type:`button`,onClick:()=>a.current?.click(),style:{padding:`8px 16px`,border:`1px dashed ${r?`#E53E3E`:`#D1D5DB`}`,borderRadius:`8px`,backgroundColor:`#FAFAFA`,cursor:`pointer`,fontSize:`13px`,color:`#555`,width:`100%`,textAlign:`left`},children:o||e.placeholder||`Choose file(s)...`}),o&&d(`div`,{style:{fontSize:`12px`,color:i,marginTop:`4px`},children:[Array.from(t).length,` file(s) selected`]}),r&&u(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},L=({config:e,onSubmit:t,primaryColor:r,renderFormField:i})=>{let[a,o]=c(()=>{let t={};for(let n of e.fields)n.defaultValue===void 0?n.type===`checkbox`||n.type===`multiselect`?t[n.name]=[]:n.type===`file`?t[n.name]=null:t[n.name]=``:t[n.name]=n.defaultValue;return t}),[s,l]=c({}),[f,p]=c(!1),m=n((e,t)=>{o(n=>({...n,[e]:t})),l(t=>{let n={...t};return delete n[e],n})},[]),h=()=>{let t={};for(let n of e.fields){let e=a[n.name];if(n.required&&(e===``||e==null||Array.isArray(e)&&e.length===0)){t[n.name]=n.validation?.message??`${n.label||n.name} is required`;continue}if(n.validation?.pattern&&typeof e==`string`&&e)try{new RegExp(n.validation.pattern).test(e)||(t[n.name]=n.validation.message??`Invalid format`)}catch{}}return l(t),Object.keys(t).length===0};return f?u(`div`,{style:{padding:`16px`,background:`linear-gradient(135deg, rgba(46, 213, 115, 0.1), rgba(46, 213, 115, 0.05))`,borderRadius:`14px`,fontSize:`14px`,color:`#2ecc71`,textAlign:`center`,fontWeight:500,border:`1px solid rgba(46, 213, 115, 0.15)`,animation:`cb-fade-in 0.3s ease-out`},children:`✓ Submitted successfully`}):d(`form`,{onSubmit:e=>{e.preventDefault(),h()&&(p(!0),t(a))},style:{background:`rgba(255, 255, 255, 0.7)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,borderRadius:`16px`,padding:`20px`,border:`1px solid rgba(0,0,0,0.06)`,boxShadow:`0 4px 16px rgba(0,0,0,0.04)`,animation:`cb-slide-up 0.35s ease-out`},children:[e.title&&u(`div`,{style:{fontWeight:600,fontSize:`15px`,marginBottom:`4px`,color:`#2D3436`,letterSpacing:`-0.01em`},children:e.title}),e.description&&u(`div`,{style:{fontSize:`12px`,color:`rgba(0,0,0,0.45)`,marginBottom:`16px`,lineHeight:`1.5`},children:e.description}),e.fields.map(e=>u(re,{field:e,value:a[e.name],onChange:t=>m(e.name,t),error:s[e.name],primaryColor:r,renderFormField:i},e.name)),u(`button`,{type:`submit`,style:{width:`100%`,padding:`12px`,background:`linear-gradient(135deg, ${r} 0%, ${ie(r,30)} 100%)`,color:`#fff`,border:`none`,borderRadius:`12px`,fontSize:`14px`,fontWeight:600,cursor:`pointer`,marginTop:`8px`,fontFamily:`inherit`,letterSpacing:`0.02em`,boxShadow:`0 4px 14px ${r}33`,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`},onMouseEnter:e=>{e.currentTarget.style.transform=`translateY(-1px)`,e.currentTarget.style.boxShadow=`0 6px 20px ${r}44`},onMouseLeave:e=>{e.currentTarget.style.transform=`translateY(0)`,e.currentTarget.style.boxShadow=`0 4px 14px ${r}33`},children:e.submitLabel??`Submit`})]})},re=({field:e,value:t,onChange:n,error:r,primaryColor:i,renderFormField:a})=>{let o=a?.[e.type];switch(e.type){case`text`:case`email`:case`password`:case`number`:case`tel`:case`url`:case`textarea`:case`date`:case`time`:{let i={type:e.type,field:e,value:String(t??``),onChange:n,error:r},a=u(M,{field:e,value:String(t??``),onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`select`:case`multiselect`:{let i={type:e.type,field:e,value:t,onChange:n,error:r},a=u(N,{field:e,value:t,onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`radio`:{let i={type:`radio`,field:e,value:String(t??``),onChange:n,error:r},a=u(P,{field:e,value:String(t??``),onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`checkbox`:{let i={type:`checkbox`,field:e,value:t??[],onChange:n,error:r},a=u(F,{field:e,value:t??[],onChange:n,error:r});return o?u(l,{children:o(i,a)}):a}case`file`:{let a={type:`file`,field:e,value:t,onChange:n,error:r,primaryColor:i},s=u(I,{field:e,value:t,onChange:n,error:r,primaryColor:i});return o?u(l,{children:o(a,s)}):s}case`hidden`:return u(`input`,{type:`hidden`,name:e.name,value:String(t??``)});default:return null}};function ie(e,t){let n=parseInt(e.replace(`#`,``),16),r=Math.min(255,(n>>16&255)+t),i=Math.min(255,(n>>8&255)+t),a=Math.min(255,(n&255)+t);return`#${(r<<16|i<<8|a).toString(16).padStart(6,`0`)}`}var R=({config:e,onLogin:t,primaryColor:n,renderFormField:r})=>u(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,justifyContent:`center`,padding:`24px`,overflow:`auto`,background:`linear-gradient(180deg, rgba(248, 249, 254, 0.95) 0%, rgba(255, 255, 255, 0.98) 100%)`},children:u(L,{config:e,onSubmit:t,primaryColor:n,renderFormField:r})}),z=({message:e,styles:t})=>{let n=e.sender===`bot`,r=e.sender===`system`,i=n||r?t.botBubble:t.userBubble;return e.text||e.attachments&&e.attachments.length>0?d(`div`,{style:{...i,...r?{background:`transparent`,border:`none`,boxShadow:`none`,color:`#999`,fontSize:`12px`,alignSelf:`center`,padding:`6px 12px`,backdropFilter:`none`,WebkitBackdropFilter:`none`}:{},animation:`cb-fade-in 0.3s ease-out`},children:[e.text&&u(`span`,{style:{display:`block`},children:e.text}),e.attachments&&e.attachments.length>0&&u(`div`,{style:{marginTop:e.text?`10px`:0,display:`flex`,flexDirection:`column`,gap:`6px`},children:e.attachments.map((e,t)=>u(ae,{attachment:e,isBot:n},t))})]}):null},ae=({attachment:e,isBot:t})=>e.type.startsWith(`image/`)&&e.url?d(`div`,{style:{borderRadius:`12px`,overflow:`hidden`,maxWidth:`220px`},children:[u(`img`,{src:e.url,alt:e.name,style:{width:`100%`,height:`auto`,display:`block`,borderRadius:`12px`}}),u(`div`,{style:{fontSize:`11px`,padding:`4px 0`,opacity:.6},children:e.name})]}):d(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,style:{display:`flex`,alignItems:`center`,gap:`8px`,padding:`8px 12px`,backgroundColor:t?`rgba(0,0,0,0.04)`:`rgba(255,255,255,0.15)`,borderRadius:`10px`,textDecoration:`none`,color:`inherit`,fontSize:`13px`,border:t?`1px solid rgba(0,0,0,0.06)`:`1px solid rgba(255,255,255,0.15)`,transition:`background 0.2s ease`},children:[u(D,{size:16}),u(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},children:e.name}),e.size&&u(`span`,{style:{fontSize:`11px`,opacity:.5,flexShrink:0},children:oe(e.size)})]});function oe(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}var B=({replies:e,onSelect:t,primaryColor:n})=>u(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`8px`,alignSelf:`flex-start`,maxWidth:`90%`,animation:`cb-slide-up 0.35s ease-out`,padding:`4px 0`},children:e.map(e=>u(`button`,{onClick:()=>t(e.value,e.label),style:{padding:`8px 18px`,borderRadius:`22px`,border:`1.5px solid ${n}`,backgroundColor:`rgba(108, 92, 231, 0.06)`,color:n,cursor:`pointer`,fontSize:`13px`,fontWeight:500,fontFamily:`inherit`,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`,backdropFilter:`blur(4px)`,WebkitBackdropFilter:`blur(4px)`,letterSpacing:`0.01em`},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=n,e.currentTarget.style.color=`#fff`,e.currentTarget.style.transform=`translateY(-1px)`,e.currentTarget.style.boxShadow=`0 4px 14px ${n}44`},onMouseLeave:e=>{e.currentTarget.style.backgroundColor=`rgba(108, 92, 231, 0.06)`,e.currentTarget.style.color=n,e.currentTarget.style.transform=`translateY(0)`,e.currentTarget.style.boxShadow=`none`},children:e.label},e.value))}),V=({color:e})=>{let t={width:`7px`,height:`7px`,borderRadius:`50%`,backgroundColor:e,opacity:.35,animation:`cb-typing-bounce 1.4s infinite ease-in-out`};return d(`div`,{style:{display:`flex`,gap:`5px`,padding:`14px 18px`,background:`rgba(241, 243, 249, 0.8)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderRadius:`18px 18px 18px 4px`,alignSelf:`flex-start`,alignItems:`center`,border:`1px solid rgba(0,0,0,0.04)`,boxShadow:`0 2px 8px rgba(0,0,0,0.04)`,animation:`cb-fade-in 0.3s ease-out`},children:[u(`span`,{style:{...t,animationDelay:`0s`}}),u(`span`,{style:{...t,animationDelay:`0.2s`}}),u(`span`,{style:{...t,animationDelay:`0.4s`}})]})},H=({messages:t,isTyping:n,styles:r,primaryColor:a,onQuickReply:o,onFormSubmit:c,components:l,onComponentComplete:f,collectedData:p,currentStepId:m,renderFormField:h})=>{let g=s(null);return i(()=>{g.current?.scrollIntoView({behavior:`smooth`})},[t,n]),d(`div`,{style:r.messageList,className:`cb-scrollbar`,children:[t.map(t=>d(e.Fragment,{children:[u(z,{message:t,styles:r}),t.quickReplies&&t.quickReplies.length>0&&u(B,{replies:t.quickReplies,onSelect:o,primaryColor:a}),t.form&&u(`div`,{style:{alignSelf:`flex-start`,width:`92%`,animation:`cb-slide-up 0.35s ease-out`},children:u(L,{config:t.form,onSubmit:e=>c(t.form.id,e),primaryColor:a,renderFormField:h})}),t.component&&l?.[t.component]&&u(`div`,{style:{alignSelf:`flex-start`,width:`92%`,animation:`cb-slide-up 0.35s ease-out`},children:e.createElement(l[t.component],{stepId:m??``,data:p??{},onComplete:e=>f?.(e)})})]},t.id)),n&&u(V,{color:a}),u(`div`,{ref:g})]})},U=[{name:`Smileys`,emojis:`😀.😃.😄.😁.😅.😂.🤣.😊.😇.🙂.😉.😍.🥰.😘.😋.😜.🤪.🤗.🤔.🤫.🤭.😏.😐.😑.😶.😌.😴.🤤.😷.🤒`.split(`.`)},{name:`Gestures`,emojis:`👍.👎.👌.✌️.🤞.🤟.🤘.👋.🤚.✋.🖖.👏.🙌.🤝.🙏.💪.🖐️.☝️.👆.👇.👈.👉.🤙.🫡.🫶.🫰.🫳.🫴.🫲.🫱`.split(`.`)},{name:`Hearts`,emojis:`❤️.🧡.💛.💚.💙.💜.🖤.🤍.🤎.💔.❣️.💕.💞.💓.💗.💖.💘.💝.💟.♥️.🫀.💌.💐.🌹.🌺.🌸.🌼.🌻.🌷.💮`.split(`.`)},{name:`Objects`,emojis:`🔥.⭐.✨.💯.🎉.🎊.🎯.🚀.💡.📌.📎.🔗.💻.📱.☎️.📧.📝.📋.📊.📈.🗂️.📁.🔒.🔑.⚙️.🛠️.🔧.📦.🏷️.✅`.split(`.`)}],W=({onSelect:e,onClose:t,primaryColor:n})=>{let[r,a]=c(0),o=s(null);i(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&t()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[t]);let l=U[r]?.emojis??[];return d(`div`,{ref:o,style:{position:`absolute`,bottom:`100%`,left:0,width:`280px`,backgroundColor:`rgba(255, 255, 255, 0.92)`,backdropFilter:`blur(20px)`,WebkitBackdropFilter:`blur(20px)`,borderRadius:`16px`,boxShadow:`0 8px 32px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)`,border:`1px solid rgba(255,255,255,0.8)`,overflow:`hidden`,zIndex:10,marginBottom:`8px`,animation:`cb-slide-up 0.25s ease-out`},children:[u(`div`,{style:{display:`flex`,borderBottom:`1px solid rgba(0,0,0,0.06)`,padding:`6px`,gap:`3px`},children:U.map((e,t)=>u(`button`,{onClick:()=>a(t),title:e.name,style:{flex:1,padding:`6px 4px`,border:`none`,borderRadius:`8px`,cursor:`pointer`,fontSize:`11px`,fontWeight:600,fontFamily:`inherit`,letterSpacing:`0.02em`,background:t===r?`linear-gradient(135deg, ${n}, ${n}CC)`:`transparent`,color:t===r?`#fff`:`rgba(0,0,0,0.4)`,transition:`all 0.2s ease`,boxShadow:t===r?`0 2px 8px ${n}33`:`none`},children:e.name},e.name))}),u(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(8, 1fr)`,gap:`2px`,padding:`8px`,maxHeight:`180px`,overflowY:`auto`},children:l.map(n=>u(`button`,{onClick:()=>{e(n),t()},style:{width:`30px`,height:`30px`,border:`none`,backgroundColor:`transparent`,cursor:`pointer`,fontSize:`18px`,borderRadius:`6px`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`all 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.backgroundColor=`rgba(108, 92, 231, 0.08)`,onMouseLeave:e=>e.currentTarget.style.backgroundColor=`transparent`,children:n},n))})]})},G=({config:e,onFiles:t,selectedFiles:n,onRemoveFile:r,primaryColor:i})=>{let a=s(null);return d(`div`,{children:[u(`input`,{ref:a,type:`file`,accept:e.accept,multiple:e.multiple!==!1,onChange:r=>{let i=r.target.files;if(!i||i.length===0)return;let o=Array.from(i);if(e.maxSize&&o.filter(t=>t.size>e.maxSize).length>0){alert(`File(s) too large. Max size: ${q(e.maxSize)}`);return}let s=e.maxFiles??5;if(n.length+o.length>s){alert(`Maximum ${s} files allowed`);return}t(o),a.current&&(a.current.value=``)},style:{display:`none`}}),u(`button`,{type:`button`,onClick:()=>a.current?.click(),"aria-label":`Attach file`,title:`Attach file`,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`6px`,display:`flex`,alignItems:`center`,color:`#999`,borderRadius:`6px`,transition:`color 0.15s ease`},onMouseEnter:e=>e.currentTarget.style.color=i,onMouseLeave:e=>e.currentTarget.style.color=`#999`,children:u(E,{size:20})})]})},K=({files:e,onRemove:t,primaryColor:n})=>e.length===0?null:u(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`6px`,padding:`8px 12px 0`},children:e.map((e,r)=>u(se,{file:e,onRemove:()=>t(r),primaryColor:n},`${e.name}-${r}`))}),se=({file:e,onRemove:t,primaryColor:n})=>{let r=e.type.startsWith(`image/`);return d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,padding:`4px 8px`,backgroundColor:`#F3F4F6`,borderRadius:`8px`,fontSize:`12px`,maxWidth:`200px`},children:[u(`span`,{style:{color:n,flexShrink:0},children:u(r?O:D,{size:14})}),u(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,color:`#555`},children:e.name}),u(`span`,{style:{color:`#999`,fontSize:`11px`,flexShrink:0},children:q(e.size)}),u(`button`,{onClick:t,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`0`,display:`flex`,color:`#999`,flexShrink:0},children:u(k,{size:14})})]})};function q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}var J=({onSend:e,placeholder:t=`Type a message...`,primaryColor:r,isDark:i=!1,disabled:a,styleOverride:o,enableEmoji:l=!1,fileUpload:f,onFileUpload:p})=>{let[m,h]=c(``),[g,_]=c(!1),[v,y]=c([]),b=s(null),S=n(()=>{let t=m.trim();!t&&v.length===0||(e(t,v.length>0?v:void 0),h(``),y([]),b.current?.focus())},[m,v,e]),C=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),S())},w=e=>{h(t=>t+e),b.current?.focus()},E=e=>{y(t=>[...t,...e]),p?.(e)},D=e=>{y(t=>t.filter((t,n)=>n!==e))},O=m.trim()||v.length>0;return d(`div`,{style:{position:`relative`,...o},children:[v.length>0&&u(K,{files:v,onRemove:D,primaryColor:r}),g&&u(W,{onSelect:w,onClose:()=>_(!1),primaryColor:r}),d(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`flex-end`,background:i?`rgba(40, 40, 65, 0.5)`:`rgba(245, 247, 252, 0.7)`,borderRadius:`16px`,border:`1px solid ${i?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.05)`}`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,padding:`6px 6px 6px 12px`},children:[d(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,flexShrink:0,paddingBottom:`2px`},children:[l&&u(`button`,{type:`button`,onClick:()=>_(!g),"aria-label":`Emoji`,title:`Emoji`,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`6px`,display:`flex`,color:g?r:i?`rgba(255,255,255,0.35)`:`rgba(0,0,0,0.3)`,borderRadius:`8px`,transition:`all 0.2s ease`},children:u(T,{size:20})}),f?.enabled&&u(G,{config:f,onFiles:E,selectedFiles:v,onRemoveFile:D,primaryColor:r})]}),u(`textarea`,{ref:b,value:m,onChange:e=>h(e.target.value),onKeyDown:C,placeholder:t,disabled:a,rows:1,style:{flex:1,padding:`8px 2px`,border:`none`,borderRadius:`12px`,outline:`none`,resize:`none`,fontFamily:`inherit`,fontSize:`14px`,lineHeight:`1.45`,maxHeight:`100px`,overflowY:`auto`,backgroundColor:`transparent`,color:i?`#E0E0E0`:`#2D3436`,letterSpacing:`0.01em`}}),u(`button`,{onClick:S,disabled:a||!O,"aria-label":`Send message`,style:{width:`36px`,height:`36px`,borderRadius:`12px`,background:O?`linear-gradient(135deg, ${r} 0%, ${ce(r,30)} 100%)`:i?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.06)`,color:O?`#fff`:i?`rgba(255,255,255,0.25)`:`rgba(0,0,0,0.2)`,border:`none`,cursor:O?`pointer`:`default`,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`,boxShadow:O?`0 4px 12px ${r}44`:`none`},children:u(x,{size:16})})]})]})};function ce(e,t){let n=parseInt(e.replace(`#`,``),16),r=Math.min(255,(n>>16&255)+t),i=Math.min(255,(n>>8&255)+t),a=Math.min(255,(n&255)+t);return`#${(r<<16|i<<8|a).toString(16).padStart(6,`0`)}`}var Y=({config:e,primaryColor:t})=>{if(e.showBranding===!1)return null;let n=e.poweredBy??`React ChatBot`;return d(`div`,{style:{padding:`8px 16px`,textAlign:`center`,fontSize:`11px`,color:`rgba(0,0,0,0.35)`,background:`rgba(250, 250, 255, 0.7)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderTop:`1px solid rgba(0,0,0,0.04)`,flexShrink:0,letterSpacing:`0.02em`},children:[`Powered by`,` `,e.poweredByUrl?u(`a`,{href:e.poweredByUrl,target:`_blank`,rel:`noopener noreferrer`,style:{color:t,textDecoration:`none`,fontWeight:600,transition:`opacity 0.2s ease`},children:n}):u(`span`,{style:{color:t,fontWeight:600},children:n})]})},X=class{constructor(e){this.collectedData={},this.idCounter=0,this.uid=()=>`msg_${Date.now()}_${++this.idCounter}`,this.stepHistory=[],this.startStep=e.startStep,this.steps=new Map(e.steps.map(e=>[e.id,e]))}getStartStepId(){return this.startStep}getStep(e){return this.steps.get(e)}getData(){return{...this.collectedData}}setData(e,t){this.collectedData[e]=t}mergeData(e){Object.assign(this.collectedData,e)}pushHistory(e){this.stepHistory.push(e)}popHistory(){return this.stepHistory.pop(),this.stepHistory.pop()}canGoBack(){return this.stepHistory.length>1}reset(){this.collectedData={},this.stepHistory=[]}resolveNext(e,t){if(e.condition){let{field:t,operator:n,value:r,then:i,else:a}=e.condition,o=this.collectedData[t];return this.evaluate(o,n,r)?i:a}if(t&&e.quickReplies){let n=e.quickReplies.find(e=>e.value===t);if(n?.next)return n.next}return e.next}stepExpectsQuickReply(e){return!!(e.quickReplies&&e.quickReplies.length>0)}stepExpectsForm(e){return!!e.form}matchQuickReply(e,t){if(!e.quickReplies)return;let n=t.toLowerCase().trim();return e.quickReplies.find(e=>e.value.toLowerCase()===n)||e.quickReplies.find(e=>e.label.toLowerCase().replace(/[^\w\s]/g,``).trim()===n)||e.quickReplies.find(e=>n.includes(e.value.toLowerCase())||e.label.toLowerCase().includes(n))}buildMessages(e){let t=[],n=e.messages??(e.message?[e.message]:[]);for(let e of n)t.push({id:this.uid(),sender:`bot`,text:e,timestamp:Date.now()});return e.quickReplies&&t.length>0&&(t[t.length-1].quickReplies=e.quickReplies),e.form&&t.push({id:this.uid(),sender:`bot`,timestamp:Date.now(),form:e.form}),e.component&&t.push({id:this.uid(),sender:`bot`,timestamp:Date.now(),component:e.component}),t}evaluate(e,t,n){switch(t){case`eq`:return String(e)===String(n);case`neq`:return String(e)!==String(n);case`contains`:return String(e).includes(String(n));case`gt`:return Number(e)>Number(n);case`lt`:return Number(e)<Number(n);default:return!1}}},le=0,Z=()=>`msg_${Date.now()}_${++le}`,Q=e=>new Promise(t=>setTimeout(t,e)),ue={"/help":`Show available commands`,"/cancel":`Cancel current step and go back`,"/back":`Go back to the previous step`,"/restart":`Restart the conversation from the beginning`},de=[`hi`,`hello`,`hey`,`howdy`,`hola`,`greetings`,`good morning`,`good afternoon`,`good evening`,`sup`,`yo`,`hii`,`hiii`];function fe(e,t){let n=t.caseSensitive?e:e.toLowerCase();for(let r of t.patterns){let i=t.caseSensitive?r:r.toLowerCase();switch(t.matchType??`contains`){case`exact`:if(n===i)return!0;break;case`startsWith`:if(n.startsWith(i))return!0;break;case`regex`:try{if(new RegExp(i,t.caseSensitive?``:`i`).test(e))return!0}catch{}break;default:if(n.includes(i))return!0;break}}return!1}function pe(e,t){return[...t].sort((e,t)=>(t.priority??0)-(e.priority??0)).find(t=>fe(e,t))}function me(e,t){let n=e;if(t.transform)switch(t.transform){case`trim`:n=n.trim();break;case`lowercase`:n=n.toLowerCase();break;case`uppercase`:n=n.toUpperCase();break;case`email`:n=n.trim().toLowerCase();break}if(t.validation){let e=t.validation;if(e.required&&!n.trim())return{valid:!1,value:n,error:e.message??`This field is required.`};if(e.minLength&&n.length<e.minLength)return{valid:!1,value:n,error:e.message??`Must be at least ${e.minLength} characters.`};if(e.maxLength&&n.length>e.maxLength)return{valid:!1,value:n,error:e.message??`Must be at most ${e.maxLength} characters.`};if(e.pattern)try{if(!new RegExp(e.pattern).test(n))return{valid:!1,value:n,error:e.message??`Invalid format.`}}catch{}}return{valid:!0,value:n}}function he(){let{state:e,dispatch:t,props:r,pluginManager:a}=h(),o=s(null),c=s(!1),l=s(e);l.current=e;let u=s(r);u.current=r,i(()=>{r.flow&&(o.current=new X(r.flow),c.current=!1)},[r.flow]);let d=n(async(e,n)=>{t({type:`SET_TYPING`,payload:!0}),await Q(400);let r={id:Z(),sender:`bot`,text:e,timestamp:Date.now(),...n};t({type:`SET_TYPING`,payload:!1}),t({type:`ADD_MESSAGE`,payload:r}),u.current.callbacks?.onMessageReceive?.(r)},[t]),f=n(e=>{t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`system`,text:e,timestamp:Date.now()}})},[t]),p=s(async()=>{});p.current=async e=>{let n=o.current;if(!n)return;let r=n.getStep(e);if(!r)return;n.pushHistory(e),t({type:`SET_STEP`,payload:e}),t({type:`SET_TYPING`,payload:!0}),await Q(r.delay??500);let i=n.buildMessages(r);if(t({type:`SET_TYPING`,payload:!1}),t({type:`ADD_MESSAGES`,payload:i}),i.forEach(e=>u.current.callbacks?.onMessageReceive?.(e)),r.asyncAction){let e=u.current.actionHandlers?.[r.asyncAction.handler];if(e){let i=Z();t({type:`ADD_MESSAGE`,payload:{id:i,sender:`bot`,text:r.asyncAction.loadingMessage??`Processing...`,timestamp:Date.now()}});let a={updateMessage:e=>{t({type:`UPDATE_MESSAGE`,payload:{id:i,updates:{text:e}}})}};try{let o=await e(n.getData(),a);o.data&&(n.mergeData(o.data),t({type:`SET_DATA`,payload:o.data})),t({type:`UPDATE_MESSAGE`,payload:{id:i,updates:{text:o.message??(o.status===`success`?r.asyncAction.successMessage??`Done!`:r.asyncAction.errorMessage??`Something went wrong.`)}}});let s=m(r,o);s&&(await Q(600),p.current(s))}catch{t({type:`UPDATE_MESSAGE`,payload:{id:i,updates:{text:r.asyncAction.errorMessage??`❌ Something went wrong.`}}}),r.asyncAction.onError&&(await Q(600),p.current(r.asyncAction.onError))}return}}r.component&&u.current.components?.[r.component]||!r.quickReplies&&!r.form&&!r.input&&r.next&&(await Q(300),p.current(r.next))};function m(e,t){return t.next?t.next:e.asyncAction?.routes?.[t.status]?e.asyncAction.routes[t.status]:t.status===`success`&&e.asyncAction?.onSuccess?e.asyncAction.onSuccess:t.status===`error`&&e.asyncAction?.onError?e.asyncAction.onError:e.next}let g=n(e=>p.current(e),[]),_=n(()=>{let e=o.current;if(!e||!e.canGoBack()){f(`There is no previous step to go back to.`);return}t({type:`CLEAR_QUICK_REPLIES`});let n=e.popHistory();n?g(n):f(`There is no previous step to go back to.`)},[t,g,f]),v=n(()=>{let e=o.current;e&&e.reset(),c.current=!1,t({type:`RESET_CHAT`}),e&&(c.current=!0,g(e.getStartStepId()))},[t,g]),y=s(()=>!1);y.current=e=>{let t=e.trim().toLowerCase();if(!t.startsWith(`/`))return!1;switch(t){case`/help`:return f(`Available commands:
2
2
  ${Object.entries(ue).map(([e,t])=>`**${e}** — ${t}`).join(`
3
- `)}`),!0;case`/cancel`:case`/back`:return g(),!0;case`/restart`:return _(),!0;default:return d(`Unknown command: ${t}. Type /help for available commands.`),!0}};let y=n(e=>{let n=a.current,r=c.current.currentStepId;if(!n||!r)return;let i=n.getStep(r);if(!i)return;e?.data&&(n.mergeData(e.data),t({type:`SET_DATA`,payload:e.data})),e?.message&&t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`bot`,text:e.message,timestamp:Date.now()}});let o=e?.next??i.next;o?m(o):(l.current.callbacks?.onFlowEnd?.(n.getData()),t({type:`SET_STEP`,payload:null}))},[t,m]),b=n(e=>{if(v.current(e))return;let n={id:Z(),sender:`user`,text:e,timestamp:Date.now()};t({type:`ADD_MESSAGE`,payload:n}),l.current.callbacks?.onMessageSend?.(n),l.current.callbacks?.onSubmit?.({message:e});let r=c.current.currentStepId;if(a.current&&r){let n=a.current.getStep(r);if(n){if(n.asyncAction||n.component){u(`Please wait, I'm still processing. You can type /back to go back.`);return}if(a.current.stepExpectsQuickReply(n)){let r=a.current.matchQuickReply(n,e);if(r){t({type:`CLEAR_QUICK_REPLIES`}),a.current.setData(n.id,r.value);let e=a.current.resolveNext(n,r.value);e?m(e):(l.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:`SET_STEP`,payload:null}))}else u(`I didn't quite get that. Please choose one of the options below:`,{quickReplies:n.quickReplies})}else if(a.current.stepExpectsForm(n))u(`Please fill out the form above to continue.`);else{a.current.setData(n.id,e);let r=a.current.resolveNext(n,e);r?m(r):(u(`Thanks for your message! Our team will get back to you soon. 🙌`),l.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:`SET_STEP`,payload:null}))}}}},[t,u,m]),x=n(()=>{let e=a.current;!e||o.current||(o.current=!0,m(e.getStartStepId()))},[m]);return i(()=>{r.flow&&!e.showWelcome&&e.isLoggedIn&&!o.current&&x()},[r.flow,e.showWelcome,e.isLoggedIn,x]),{state:e,sendMessage:b,addBotMessage:u,handleQuickReply:n((e,n)=>{t({type:`CLEAR_QUICK_REPLIES`}),t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:n,timestamp:Date.now()}}),l.current.callbacks?.onQuickReply?.(e,n);let r=c.current.currentStepId;if(a.current&&r){let n=a.current.getStep(r);if(n){a.current.setData(n.id,e);let r=a.current.resolveNext(n,e);r?m(r):(l.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:`SET_STEP`,payload:null}))}}},[t,m]),handleFormSubmit:n(async(e,n)=>{t({type:`SET_DATA`,payload:n}),a.current&&a.current.mergeData(n);let r=Object.entries(n).filter(([,e])=>e!==void 0&&e!==``).map(([e,t])=>`${e}: ${String(t)}`).join(`
4
- `);t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:r,formData:n,timestamp:Date.now()}}),await l.current.callbacks?.onFormSubmit?.(e,n);let i=c.current.currentStepId;if(a.current&&i){let e=a.current.getStep(i);if(e){let n=a.current.resolveNext(e);n?m(n):(l.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:`SET_STEP`,payload:null}))}}},[t,m]),handleLogin:n(async e=>{await l.current.callbacks?.onLogin?.(e),t({type:`SET_LOGGED_IN`,payload:!0})},[t]),toggleChat:n(()=>{let e=!c.current.isOpen;t({type:`TOGGLE_OPEN`}),e?l.current.callbacks?.onOpen?.():l.current.callbacks?.onClose?.()},[t]),dismissWelcome:n(()=>{t({type:`DISMISS_WELCOME`})},[t]),startFlow:x,processFlowStep:m,goBack:g,restartSession:_,handleComponentComplete:y}}var fe=({styles:e,position:t,zIndex:r,hidden:i})=>{let{props:o,dispatch:s}=h(),c=v(o.theme),f=c.mode===`dark`,{state:p,sendMessage:m,handleQuickReply:g,handleFormSubmit:_,handleLogin:y,toggleChat:b,dismissWelcome:x,restartSession:S,handleComponentComplete:C}=de(),w=t===`bottom-left`?{bottom:`96px`,left:`24px`}:{bottom:`96px`,right:`24px`},T=n((e,t)=>{if(t&&t.length>0){let n=t.map(e=>({name:e.name,url:URL.createObjectURL(e),type:e.type,size:e.size}));e?(s({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:e,timestamp:Date.now(),attachments:n}}),m(e)):s({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,timestamp:Date.now(),attachments:n}}),o.callbacks?.onFileUpload?.(t)}else e&&m(e)},[m,s,o.callbacks]),E=a(()=>({currentStepId:p.currentStepId,isOpen:p.isOpen,messages:p.messages,collectedData:p.collectedData,toggleChat:b,restartSession:S,sendMessage:m}),[p.currentStepId,p.isOpen,p.messages,p.collectedData,b,S,m]),D=u(ee,{config:o.header??{title:`Chat with us`},styles:e,onClose:b,onRestart:S,logo:o.branding?.logo,logoWidth:o.branding?.logoWidth}),O=u(J,{onSend:T,placeholder:o.inputPlaceholder,primaryColor:c.primaryColor,isDark:f,enableEmoji:o.enableEmoji,fileUpload:o.fileUpload,onFileUpload:o.callbacks?.onFileUpload});return i?u(`div`,{style:{display:`none`}}):d(`div`,{style:{...e.window,...w,...r==null?{}:{zIndex:r}},children:[o.renderHeader?o.renderHeader(E,D):D,p.showWelcome&&o.welcomeScreen?u(te,{content:o.welcomeScreen,onDismiss:x,primaryColor:c.primaryColor}):!p.isLoggedIn&&o.loginForm?u(R,{config:o.loginForm,onLogin:y,primaryColor:c.primaryColor,renderFormField:o.renderFormField}):d(l,{children:[u(H,{messages:p.messages,isTyping:p.isTyping,styles:e,primaryColor:c.primaryColor,onQuickReply:g,onFormSubmit:_,components:o.components,onComponentComplete:C,collectedData:p.collectedData,currentStepId:p.currentStepId,renderFormField:o.renderFormField}),u(`div`,{style:e.inputArea,children:o.renderInput?o.renderInput(E,O):O}),o.branding&&u(Y,{config:o.branding,primaryColor:c.primaryColor})]})]})},pe=class{constructor(){this.plugins=[],this.context=null,this.eventHandlers=new Map}register(e){this.plugins=[...e]}setContext(e){this.context={...e,on:(e,t)=>this.on(e,t),emit:(e,...t)=>this.emit(e,...t)}}on(e,t){this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set),this.eventHandlers.get(e).add(t)}emit(e,...t){let n=this.eventHandlers.get(e);n&&n.forEach(e=>e(...t))}async init(){if(this.context)for(let e of this.plugins)try{await e.onInit?.(this.context)}catch{}}async onMessage(e){if(!this.context)return e;let t=e;for(let e of this.plugins)try{let n=await e.onMessage?.(t,this.context);n&&typeof n==`object`&&`id`in n&&(t=n)}catch{}return this.dispatchEvent({type:`message`,payload:t,timestamp:Date.now()}),t}async onSubmit(e){if(this.context){for(let t of this.plugins)try{await t.onSubmit?.(e,this.context)}catch{}this.dispatchEvent({type:`submit`,payload:e,timestamp:Date.now()})}}async destroy(){if(this.context){for(let e of this.plugins)try{await e.onDestroy?.(this.context)}catch{}this.eventHandlers.clear(),this.plugins=[]}}dispatchEvent(e){if(this.context)for(let t of this.plugins)try{t.onEvent?.(e,this.context)}catch{}}},me=`
3
+ `)}`),!0;case`/cancel`:case`/back`:return _(),!0;case`/restart`:return v(),!0;default:return f(`Unknown command: ${t}. Type /help for available commands.`),!0}};let b=n(e=>{let n=o.current,r=l.current.currentStepId;if(!n||!r)return;let i=n.getStep(r);if(!i)return;e?.data&&(n.mergeData(e.data),t({type:`SET_DATA`,payload:e.data})),e?.message&&t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`bot`,text:e.message,timestamp:Date.now()}});let a=e?.next??i.next;a?g(a):(u.current.callbacks?.onFlowEnd?.(n.getData()),t({type:`SET_STEP`,payload:null}))},[t,g]),x=n(async e=>{if(y.current(e))return;let n={id:Z(),sender:`user`,text:e,timestamp:Date.now()},r=a?await a.onMessage(n):n;t({type:`ADD_MESSAGE`,payload:r}),u.current.callbacks?.onMessageSend?.(r),u.current.callbacks?.onSubmit?.({message:r.text});let i=l.current.currentStepId,s=u.current.typingDelay??0;if(o.current&&i){let n=o.current.getStep(i);if(n){if(n.asyncAction||n.component){d(`Please wait, I'm still processing. You can type /back to go back.`);return}if(o.current.stepExpectsQuickReply(n)){let r=o.current.matchQuickReply(n,e);if(r){t({type:`CLEAR_QUICK_REPLIES`}),o.current.setData(n.id,r.value);let e=o.current.resolveNext(n,r.value);e?g(e):(u.current.callbacks?.onFlowEnd?.(o.current.getData()),t({type:`SET_STEP`,payload:null}))}else d(`I didn't quite get that. Please choose one of the options below:`,{quickReplies:n.quickReplies})}else if(o.current.stepExpectsForm(n))d(`Please fill out the form above to continue.`);else if(n.input){let r=me(e,n.input);if(!r.valid){d(r.error??`Invalid input. Please try again.`);return}o.current.setData(n.id,r.value);let i=o.current.resolveNext(n,r.value);i?g(i):(d(`Thanks for your message! Our team will get back to you soon. 🙌`),u.current.callbacks?.onFlowEnd?.(o.current.getData()),t({type:`SET_STEP`,payload:null}))}else{o.current.setData(n.id,e);let r=o.current.resolveNext(n,e);r?g(r):(d(`Thanks for your message! Our team will get back to you soon. 🙌`),u.current.callbacks?.onFlowEnd?.(o.current.getData()),t({type:`SET_STEP`,payload:null}))}return}}let c=[...u.current.keywords??[]];if(u.current.greetingResponse&&c.push({patterns:de,response:u.current.greetingResponse,matchType:`exact`,priority:-1}),c.length>0){let n=pe(e.trim(),c);if(n){if(n.next&&o.current){s>0&&await Q(s),g(n.next);return}if(n.response){s>0&&(t({type:`SET_TYPING`,payload:!0}),await Q(s),t({type:`SET_TYPING`,payload:!1})),await d(n.response);return}}}let f=u.current.fallbackMessage;if(f){let n=typeof f==`function`?f(e):f;if(n){s>0&&(t({type:`SET_TYPING`,payload:!0}),await Q(s),t({type:`SET_TYPING`,payload:!1})),await d(n);return}}u.current.callbacks?.onUnhandledMessage?.(e,{currentStepId:i})},[t,d,g,a]),S=n(()=>{let e=o.current;!e||c.current||(c.current=!0,g(e.getStartStepId()))},[g]);return i(()=>{r.flow&&!e.showWelcome&&e.isLoggedIn&&!c.current&&S()},[r.flow,e.showWelcome,e.isLoggedIn,S]),{state:e,sendMessage:x,addBotMessage:d,handleQuickReply:n((e,n)=>{t({type:`CLEAR_QUICK_REPLIES`}),t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:n,timestamp:Date.now()}}),u.current.callbacks?.onQuickReply?.(e,n);let r=l.current.currentStepId;if(o.current&&r){let n=o.current.getStep(r);if(n){o.current.setData(n.id,e);let r=o.current.resolveNext(n,e);r?g(r):(u.current.callbacks?.onFlowEnd?.(o.current.getData()),t({type:`SET_STEP`,payload:null}))}}},[t,g]),handleFormSubmit:n(async(e,n)=>{t({type:`SET_DATA`,payload:n}),o.current&&o.current.mergeData(n);let r=Object.entries(n).filter(([,e])=>e!==void 0&&e!==``).map(([e,t])=>`${e}: ${String(t)}`).join(`
4
+ `);t({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:r,formData:n,timestamp:Date.now()}}),await u.current.callbacks?.onFormSubmit?.(e,n);let i=l.current.currentStepId;if(o.current&&i){let e=o.current.getStep(i);if(e){let n=o.current.resolveNext(e);n?g(n):(u.current.callbacks?.onFlowEnd?.(o.current.getData()),t({type:`SET_STEP`,payload:null}))}}},[t,g]),handleLogin:n(async e=>{await u.current.callbacks?.onLogin?.(e),t({type:`SET_LOGGED_IN`,payload:!0})},[t]),toggleChat:n(()=>{let e=!l.current.isOpen;t({type:`TOGGLE_OPEN`}),e?u.current.callbacks?.onOpen?.():u.current.callbacks?.onClose?.()},[t]),dismissWelcome:n(()=>{t({type:`DISMISS_WELCOME`})},[t]),startFlow:S,processFlowStep:g,goBack:_,restartSession:v,handleComponentComplete:b}}var ge=({styles:e,position:t,zIndex:r,hidden:i})=>{let{props:o,dispatch:s}=h(),c=v(o.theme),f=c.mode===`dark`,{state:p,sendMessage:m,handleQuickReply:g,handleFormSubmit:_,handleLogin:y,toggleChat:b,dismissWelcome:x,restartSession:S,handleComponentComplete:C}=he(),w=t===`bottom-left`?{bottom:`96px`,left:`24px`}:{bottom:`96px`,right:`24px`},T=n((e,t)=>{if(t&&t.length>0){let n=t.map(e=>({name:e.name,url:URL.createObjectURL(e),type:e.type,size:e.size}));e?(s({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:e,timestamp:Date.now(),attachments:n}}),m(e)):s({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,timestamp:Date.now(),attachments:n}}),o.callbacks?.onFileUpload?.(t)}else e&&m(e)},[m,s,o.callbacks]),E=a(()=>({currentStepId:p.currentStepId,isOpen:p.isOpen,messages:p.messages,collectedData:p.collectedData,toggleChat:b,restartSession:S,sendMessage:m}),[p.currentStepId,p.isOpen,p.messages,p.collectedData,b,S,m]),D=u(ee,{config:o.header??{title:`Chat with us`},styles:e,onClose:b,onRestart:S,logo:o.branding?.logo,logoWidth:o.branding?.logoWidth}),O=u(J,{onSend:T,placeholder:o.inputPlaceholder,primaryColor:c.primaryColor,isDark:f,enableEmoji:o.enableEmoji,fileUpload:o.fileUpload,onFileUpload:o.callbacks?.onFileUpload});return i?u(`div`,{style:{display:`none`}}):d(`div`,{style:{...e.window,...w,...r==null?{}:{zIndex:r}},children:[o.renderHeader?o.renderHeader(E,D):D,p.showWelcome&&o.welcomeScreen?u(te,{content:o.welcomeScreen,onDismiss:x,primaryColor:c.primaryColor}):!p.isLoggedIn&&o.loginForm?u(R,{config:o.loginForm,onLogin:y,primaryColor:c.primaryColor,renderFormField:o.renderFormField}):d(l,{children:[u(H,{messages:p.messages,isTyping:p.isTyping,styles:e,primaryColor:c.primaryColor,onQuickReply:g,onFormSubmit:_,components:o.components,onComponentComplete:C,collectedData:p.collectedData,currentStepId:p.currentStepId,renderFormField:o.renderFormField}),u(`div`,{style:e.inputArea,children:o.renderInput?o.renderInput(E,O):O}),o.branding&&u(Y,{config:o.branding,primaryColor:c.primaryColor})]})]})},_e=class{constructor(){this.plugins=[],this.context=null,this.eventHandlers=new Map}register(e){this.plugins=[...e]}setContext(e){this.context={...e,on:(e,t)=>this.on(e,t),emit:(e,...t)=>this.emit(e,...t)}}on(e,t){this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set),this.eventHandlers.get(e).add(t)}emit(e,...t){let n=this.eventHandlers.get(e);n&&n.forEach(e=>e(...t))}async init(){if(this.context)for(let e of this.plugins)try{await e.onInit?.(this.context)}catch{}}async onMessage(e){if(!this.context)return e;let t=e;for(let e of this.plugins)try{let n=await e.onMessage?.(t,this.context);n&&typeof n==`object`&&`id`in n&&(t=n)}catch{}return this.dispatchEvent({type:`message`,payload:t,timestamp:Date.now()}),t}async onSubmit(e){if(this.context){for(let t of this.plugins)try{await t.onSubmit?.(e,this.context)}catch{}this.dispatchEvent({type:`submit`,payload:e,timestamp:Date.now()})}}async destroy(){if(this.context){for(let e of this.plugins)try{await e.onDestroy?.(this.context)}catch{}this.eventHandlers.clear(),this.plugins=[]}}dispatchEvent(e){if(this.context)for(let t of this.plugins)try{t.onEvent?.(e,this.context)}catch{}}},ve=`
5
5
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
6
6
 
7
7
  @keyframes cb-window-enter {
@@ -42,5 +42,5 @@ ${Object.entries(ue).map(([e,t])=>`**${e}** — ${t}`).join(`
42
42
  .cb-scrollbar::-webkit-scrollbar-thumb:hover {
43
43
  background: rgba(108, 92, 231, 0.35);
44
44
  }
45
- `,$=!1;function he(){if($||typeof document>`u`)return;if(document.querySelector(`style[data-chatbot-styles]`)){$=!0;return}let e=document.createElement(`style`);e.setAttribute(`data-chatbot-styles`,``),e.textContent=me,document.head.appendChild(e),$=!0}var ge=e=>{let[t,r]=o(f,e,p),a=v(e.theme),c=b(a,e.style),l=y(a),h=e.position??`bottom-right`,g=e.showLauncher!==!1,_=s(null),x=s(t);x.current=t,i(()=>{he()},[]),i(()=>{if(e.plugins&&e.plugins.length>0){let t=new pe;return t.register(e.plugins),t.setContext({sendMessage:e=>{r({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:e,timestamp:Date.now()}})},addBotMessage:e=>{r({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`bot`,text:e,timestamp:Date.now()}})},getMessages:()=>x.current.messages,getData:()=>x.current.collectedData,setData:(e,t)=>r({type:`SET_DATA`,payload:{[e]:t}})}),t.init(),_.current=t,()=>{t.destroy()}}},[e.plugins]);let S=n(()=>{let n=!t.isOpen;r({type:`TOGGLE_OPEN`}),n?e.callbacks?.onOpen?.():e.callbacks?.onClose?.()},[t.isOpen,e.callbacks]);return u(m.Provider,{value:{state:t,dispatch:r,props:e},children:d(`div`,{style:{...c.root,...l},className:e.className,children:[u(fe,{styles:c,position:h,zIndex:e.zIndex,hidden:!t.isOpen}),g&&u(j,{onClick:S,isOpen:t.isOpen,position:h,styles:c,icon:e.launcherIcon,closeIcon:e.closeIcon,zIndex:e.zIndex})]})})};function _e(e){let t=0,n=0;return{name:`analytics`,onInit(r){t=0,n=0,e?.onTrack?.(`chatbot:init`)},onMessage(n,r){t++,e?.onTrack?.(`chatbot:message`,{sender:n.sender,messageCount:t})},onSubmit(t,r){n++,e?.onTrack?.(`chatbot:submit`,{formSubmissions:n,fields:Object.keys(t)})},onDestroy(){e?.onTrack?.(`chatbot:destroy`,{totalMessages:t,totalFormSubmissions:n})}}}function ve(e){let t=e.events??[`message`,`submit`],n=async(t,n)=>{try{await fetch(e.url,{method:`POST`,headers:{"Content-Type":`application/json`,...e.headers},body:JSON.stringify({type:t,payload:n,timestamp:Date.now()})})}catch{}};return{name:`webhook`,async onInit(){t.includes(`init`)&&await n(`init`,{})},async onMessage(e){t.includes(`message`)&&await n(`message`,e)},async onSubmit(e){t.includes(`submit`)&&await n(`submit`,e)},async onDestroy(){t.includes(`destroy`)&&await n(`destroy`,{})}}}function ye(e){let t=e?.storageKey??`chatbot_history`,n=e?.storage===`session`?sessionStorage:localStorage;return{name:`persistence`,onInit(e){try{let r=n.getItem(t);if(r){let t=JSON.parse(r);Array.isArray(t)&&t.forEach(t=>{t.sender===`bot`&&e.addBotMessage(t.text)})}}catch{}},onMessage(e,r){try{let e=r.getMessages();n.setItem(t,JSON.stringify(e.slice(-50)))}catch{}},onDestroy(){}}}export{E as AttachmentIcon,Y as Branding,ge as ChatBot,S as ChatBubbleIcon,m as ChatContext,ee as ChatHeader,J as ChatInput,fe as ChatWindow,F as CheckboxField,C as CloseIcon,L as DynamicForm,T as EmojiIcon,W as EmojiPicker,D as FileIcon,K as FilePreviewList,G as FileUploadButton,I as FileUploadField,X as FlowEngine,O as ImageIcon,j as Launcher,R as LoginScreen,z as MessageBubble,H as MessageList,w as MinimizeIcon,pe as PluginManager,B as QuickReplies,P as RadioField,k as RemoveIcon,A as RestartIcon,N as SelectField,x as SendIcon,M as TextField,V as TypingIndicator,te as WelcomeScreen,_e as analyticsPlugin,y as buildCSSVariables,b as buildStyles,ye as persistencePlugin,v as resolveTheme,de as useChat,h as useChatContext,ve as webhookPlugin};
45
+ `,$=!1;function ye(){if($||typeof document>`u`)return;if(document.querySelector(`style[data-chatbot-styles]`)){$=!0;return}let e=document.createElement(`style`);e.setAttribute(`data-chatbot-styles`,``),e.textContent=ve,document.head.appendChild(e),$=!0}var be=e=>{let[t,r]=o(f,e,p),a=v(e.theme),c=b(a,e.style),l=y(a),h=e.position??`bottom-right`,g=e.showLauncher!==!1,_=s(null),x=s(t);x.current=t,i(()=>{ye()},[]),i(()=>{if(e.plugins&&e.plugins.length>0){let t=new _e;return t.register(e.plugins),t.setContext({sendMessage:e=>{r({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`user`,text:e,timestamp:Date.now()}})},addBotMessage:e=>{r({type:`ADD_MESSAGE`,payload:{id:Z(),sender:`bot`,text:e,timestamp:Date.now()}})},getMessages:()=>x.current.messages,getData:()=>x.current.collectedData,setData:(e,t)=>r({type:`SET_DATA`,payload:{[e]:t}})}),t.init(),_.current=t,()=>{t.destroy()}}},[e.plugins]);let S=n(()=>{let n=!t.isOpen;r({type:`TOGGLE_OPEN`}),n?e.callbacks?.onOpen?.():e.callbacks?.onClose?.()},[t.isOpen,e.callbacks]);return u(m.Provider,{value:{state:t,dispatch:r,props:e,pluginManager:_.current},children:d(`div`,{style:{...c.root,...l},className:e.className,children:[u(ge,{styles:c,position:h,zIndex:e.zIndex,hidden:!t.isOpen}),g&&u(j,{onClick:S,isOpen:t.isOpen,position:h,styles:c,icon:e.launcherIcon,closeIcon:e.closeIcon,zIndex:e.zIndex})]})})};function xe(e){let t=0,n=0;return{name:`analytics`,onInit(r){t=0,n=0,e?.onTrack?.(`chatbot:init`)},onMessage(n,r){t++,e?.onTrack?.(`chatbot:message`,{sender:n.sender,messageCount:t})},onSubmit(t,r){n++,e?.onTrack?.(`chatbot:submit`,{formSubmissions:n,fields:Object.keys(t)})},onDestroy(){e?.onTrack?.(`chatbot:destroy`,{totalMessages:t,totalFormSubmissions:n})}}}function Se(e){let t=e.events??[`message`,`submit`],n=async(t,n)=>{try{await fetch(e.url,{method:`POST`,headers:{"Content-Type":`application/json`,...e.headers},body:JSON.stringify({type:t,payload:n,timestamp:Date.now()})})}catch{}};return{name:`webhook`,async onInit(){t.includes(`init`)&&await n(`init`,{})},async onMessage(e){t.includes(`message`)&&await n(`message`,e)},async onSubmit(e){t.includes(`submit`)&&await n(`submit`,e)},async onDestroy(){t.includes(`destroy`)&&await n(`destroy`,{})}}}function Ce(e){let t=e?.storageKey??`chatbot_history`,n=e?.storage===`session`?sessionStorage:localStorage;return{name:`persistence`,onInit(e){try{let r=n.getItem(t);if(r){let t=JSON.parse(r);Array.isArray(t)&&t.forEach(t=>{t.sender===`bot`&&e.addBotMessage(t.text)})}}catch{}},onMessage(e,r){try{let e=r.getMessages();n.setItem(t,JSON.stringify(e.slice(-50)))}catch{}},onDestroy(){}}}export{E as AttachmentIcon,Y as Branding,be as ChatBot,S as ChatBubbleIcon,m as ChatContext,ee as ChatHeader,J as ChatInput,ge as ChatWindow,F as CheckboxField,C as CloseIcon,L as DynamicForm,T as EmojiIcon,W as EmojiPicker,D as FileIcon,K as FilePreviewList,G as FileUploadButton,I as FileUploadField,X as FlowEngine,O as ImageIcon,j as Launcher,R as LoginScreen,z as MessageBubble,H as MessageList,w as MinimizeIcon,_e as PluginManager,B as QuickReplies,P as RadioField,k as RemoveIcon,A as RestartIcon,N as SelectField,x as SendIcon,M as TextField,V as TypingIndicator,te as WelcomeScreen,xe as analyticsPlugin,y as buildCSSVariables,b as buildStyles,Ce as persistencePlugin,v as resolveTheme,he as useChat,h as useChatContext,Se as webhookPlugin};
46
46
  //# sourceMappingURL=index.mjs.map