@enjoys/react-chatbot-plugin 1.2.0 โ 1.3.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/README.md +64 -435
- package/dist/index.cjs +5 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +73 -0
- package/dist/index.mjs +5 -2684
- package/dist/index.mjs.map +1 -1
- package/package.json +33 -3
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var ye=Object.create,W=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,ke=Object.getOwnPropertyNames,ve=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty,je=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(var o=ke(t),s=0,i=o.length,l;s<i;s++)l=o[s],!we.call(e,l)&&l!==n&&W(e,l,{get:(p=>t[p]).bind(null,l),enumerable:!(a=Se(t,l))||a.enumerable});return e},Ee=(e,t,n)=>(n=e!=null?ye(ve(e)):{},je(t||!e||!e.__esModule?W(n,"default",{value:e,enumerable:!0}):n,e));let d=require("react");d=Ee(d);let r=require("react/jsx-runtime");function Ce(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 n=-1;for(let o=e.messages.length-1;o>=0;o--)if(e.messages[o].quickReplies){n=o;break}if(n===-1)return e;const a=[...e.messages];return a[n]={...a[n],quickReplies:void 0},{...e,messages:a}}case"RESET_CHAT":return{...e,messages:[],isTyping:!1,currentStepId:null,collectedData:{}};case"UPDATE_MESSAGE":return{...e,messages:e.messages.map(n=>n.id===t.payload.id?{...n,...t.payload.updates}:n)};default:return e}}var Fe=e=>({isOpen:e.defaultOpen??!1,messages:e.initialMessages??[],isTyping:!1,showWelcome:!!e.welcomeScreen,currentStepId:null,collectedData:{},isLoggedIn:!e.loginForm}),R=(0,d.createContext)(null);function M(){const e=(0,d.useContext)(R);if(!e)throw new Error("useChatContext must be used within ChatProvider");return e}var De={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"},Ie={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 A(e){const t={...De,...e};return t.mode==="dark"?{...t,...Ie,...e}:t}function O(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 $(e,t){const 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 G=({size:e=18,color:t="currentColor"})=>(0,r.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:t,children:(0,r.jsx)("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})}),H=({size:e=28,color:t="currentColor"})=>(0,r.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),B=({size:e=20,color:t="currentColor"})=>(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),q=({size:e=20,color:t="currentColor"})=>(0,r.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})}),N=({size:e=20,color:t="currentColor"})=>(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("path",{d:"M8 14s1.5 2 4 2 4-2 4-2"}),(0,r.jsx)("line",{x1:"9",y1:"9",x2:"9.01",y2:"9"}),(0,r.jsx)("line",{x1:"15",y1:"9",x2:"15.01",y2:"9"})]}),U=({size:e=20,color:t="currentColor"})=>(0,r.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("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"})}),L=({size:e=16,color:t="currentColor"})=>(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),(0,r.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),Y=({size:e=16,color:t="currentColor"})=>(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,r.jsx)("polyline",{points:"21 15 16 10 5 21"})]}),Q=({size:e=14,color:t="currentColor"})=>(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,r.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}),K=({size:e=16,color:t="currentColor"})=>(0,r.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,r.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]}),V=({onClick:e,isOpen:t,position:n,styles:a,icon:o,closeIcon:s,zIndex:i})=>{const l=n==="bottom-left"?{bottom:"24px",left:"24px"}:{bottom:"24px",right:"24px"};return(0,r.jsx)("button",{onClick:e,"aria-label":t?"Close chat":"Open chat",style:{...a.launcher,...l,...i!=null?{zIndex:i}:{},transform:t?"scale(0.92) rotate(90deg)":"scale(1)",animation:t?"none":"cb-launcher-pulse 3s ease-in-out infinite"},children:t?s??(0,r.jsx)(B,{size:22}):o??(0,r.jsx)(H,{size:26})})},J=({config:e,styles:t,onClose:n,onRestart:a,logo:o,logoWidth:s})=>(0,r.jsxs)("div",{style:t.header,children:[(0,r.jsx)("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"}}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"12px",flex:1,position:"relative",zIndex:1},children:[e.avatar&&(0,r.jsxs)("div",{style:{position:"relative"},children:[(0,r.jsx)("img",{src:e.avatar,alt:"",style:{width:"40px",height:"40px",borderRadius:"50%",objectFit:"cover",border:"2px solid rgba(255,255,255,0.3)"}}),(0,r.jsx)("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)"}})]}),o&&!e.avatar&&(0,r.jsx)("img",{src:o,alt:"",style:{width:s??"36px",height:"auto",objectFit:"contain",filter:"brightness(1.1)"}}),!e.avatar&&!o&&(0,r.jsx)("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()}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{fontWeight:600,fontSize:"16px",letterSpacing:"-0.01em"},children:e.title??"Chat with us"}),e.subtitle&&(0,r.jsxs)("div",{style:{fontSize:"12px",opacity:.8,display:"flex",alignItems:"center",gap:"5px",marginTop:"1px"},children:[(0,r.jsx)("span",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#2ECC71",display:"inline-block"}}),e.subtitle]})]})]}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"2px",position:"relative",zIndex:1},children:[e.showRestart&&a&&(0,r.jsx)("button",{onClick:a,"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:i=>i.currentTarget.style.background="rgba(255,255,255,0.2)",onMouseLeave:i=>i.currentTarget.style.background="rgba(255,255,255,0.1)",children:(0,r.jsx)(K,{size:16})}),e.showMinimize&&(0,r.jsx)("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:i=>i.currentTarget.style.background="rgba(255,255,255,0.2)",onMouseLeave:i=>i.currentTarget.style.background="rgba(255,255,255,0.1)",children:(0,r.jsx)(q,{size:16})}),e.showClose!==!1&&(0,r.jsx)("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:i=>i.currentTarget.style.background="rgba(255,255,255,0.2)",onMouseLeave:i=>i.currentTarget.style.background="rgba(255,255,255,0.1)",children:(0,r.jsx)(B,{size:18})})]})]}),X=({content:e,onDismiss:t,primaryColor:n})=>(0,r.jsxs)("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:[(0,r.jsx)("div",{style:{flex:1,padding:"28px 24px",overflow:"auto"},children:e}),(0,r.jsx)("div",{style:{padding:"16px 20px",borderTop:"1px solid rgba(0,0,0,0.05)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",flexShrink:0},children:(0,r.jsx)("button",{onClick:t,style:{width:"100%",padding:"14px",background:`linear-gradient(135deg, ${n} 0%, ${Te(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:a=>{a.currentTarget.style.transform="translateY(-1px)",a.currentTarget.style.boxShadow=`0 8px 28px ${n}55`},onMouseLeave:a=>{a.currentTarget.style.transform="translateY(0)",a.currentTarget.style.boxShadow=`0 6px 20px ${n}44`},children:"Start Chat"})})]});function Te(e,t){const n=parseInt(e.replace("#",""),16),a=Math.min(255,(n>>16&255)+t),o=Math.min(255,(n>>8&255)+t),s=Math.min(255,(n&255)+t);return`#${(a<<16|o<<8|s).toString(16).padStart(6,"0")}`}var Z=({field:e,value:t,onChange:n,error:a})=>{const o=e.type==="textarea",s=e.type==="textarea"?void 0:e.type,i={width:"100%",padding:"10px 14px",border:`1.5px solid ${a?"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(0,r.jsxs)("div",{style:{marginBottom:"14px"},children:[e.label&&(0,r.jsxs)("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500,color:"#2D3436"},children:[e.label,e.required&&(0,r.jsx)("span",{style:{color:"#E53E3E",marginLeft:"3px"},children:"*"})]}),o?(0,r.jsx)("textarea",{value:t,onChange:l=>n(l.target.value),placeholder:e.placeholder,required:e.required,rows:3,style:{...i,resize:"vertical"},minLength:e.validation?.minLength,maxLength:e.validation?.maxLength}):(0,r.jsx)("input",{type:s,value:t,onChange:l=>n(l.target.value),placeholder:e.placeholder,required:e.required,style:i,min:e.validation?.min,max:e.validation?.max,minLength:e.validation?.minLength,maxLength:e.validation?.maxLength,pattern:e.validation?.pattern}),a&&(0,r.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},ee=({field:e,value:t,onChange:n,error:a})=>{const o=e.type==="multiselect"||e.multiple,s=l=>{n(o?Array.from(l.target.selectedOptions,p=>p.value):l.target.value)},i=o?Array.isArray(t)?t:[t].filter(Boolean):typeof t=="string"?t:"";return(0,r.jsxs)("div",{style:{marginBottom:"14px"},children:[e.label&&(0,r.jsxs)("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500,color:"#2D3436"},children:[e.label,e.required&&(0,r.jsx)("span",{style:{color:"#E53E3E",marginLeft:"3px"},children:"*"})]}),(0,r.jsxs)("select",{value:i,onChange:s,multiple:o,required:e.required,style:{width:"100%",padding:"10px 14px",border:`1.5px solid ${a?"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",...o?{minHeight:"80px"}:{}},children:[!o&&(0,r.jsx)("option",{value:"",children:"Select..."}),e.options?.map(l=>(0,r.jsx)("option",{value:l.value,children:l.label},l.value))]}),o&&(0,r.jsx)("div",{style:{fontSize:"11px",color:"#888",marginTop:"2px"},children:"Hold Ctrl/Cmd to select multiple"}),a&&(0,r.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},te=({field:e,value:t,onChange:n,error:a})=>(0,r.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,r.jsxs)("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,r.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.options?.map(o=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",fontSize:"13px"},children:[(0,r.jsx)("input",{type:"radio",name:e.name,value:o.value,checked:t===o.value,onChange:()=>n(o.value),style:{margin:0}}),o.label]},o.value))}),a&&(0,r.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]}),re=({field:e,value:t,onChange:n,error:a})=>{const o=s=>{t.includes(s)?n(t.filter(i=>i!==s)):n([...t,s])};return(0,r.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,r.jsxs)("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,r.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.options?.map(s=>(0,r.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",fontSize:"13px"},children:[(0,r.jsx)("input",{type:"checkbox",checked:t.includes(s.value),onChange:()=>o(s.value),style:{margin:0}}),s.label]},s.value))}),a&&(0,r.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},ne=({field:e,value:t,onChange:n,error:a,primaryColor:o})=>{const s=(0,d.useRef)(null),i=t?Array.from(t).map(l=>l.name).join(", "):"";return(0,r.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,r.jsxs)("label",{style:{display:"block",marginBottom:"4px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,r.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),(0,r.jsx)("input",{ref:s,type:"file",accept:e.accept,multiple:e.multiple,onChange:l=>n(l.target.files),style:{display:"none"}}),(0,r.jsx)("button",{type:"button",onClick:()=>s.current?.click(),style:{padding:"8px 16px",border:`1px dashed ${a?"#E53E3E":"#D1D5DB"}`,borderRadius:"8px",backgroundColor:"#FAFAFA",cursor:"pointer",fontSize:"13px",color:"#555",width:"100%",textAlign:"left"},children:i||e.placeholder||"Choose file(s)..."}),i&&(0,r.jsxs)("div",{style:{fontSize:"12px",color:o,marginTop:"4px"},children:[Array.from(t).length," file(s) selected"]}),a&&(0,r.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},_=({config:e,onSubmit:t,primaryColor:n})=>{const[a,o]=(0,d.useState)(()=>{const g={};for(const h of e.fields)h.defaultValue!==void 0?g[h.name]=h.defaultValue:h.type==="checkbox"||h.type==="multiselect"?g[h.name]=[]:h.type==="file"?g[h.name]=null:g[h.name]="";return g}),[s,i]=(0,d.useState)({}),[l,p]=(0,d.useState)(!1),y=(0,d.useCallback)((g,h)=>{o(k=>({...k,[g]:h})),i(k=>{const j={...k};return delete j[g],j})},[]),v=()=>{const g={};for(const h of e.fields){const k=a[h.name];if(h.required&&(k===""||k===null||k===void 0||Array.isArray(k)&&k.length===0)){g[h.name]=h.validation?.message??`${h.label||h.name} is required`;continue}if(h.validation?.pattern&&typeof k=="string"&&k)try{new RegExp(h.validation.pattern).test(k)||(g[h.name]=h.validation.message??"Invalid format")}catch{}}return i(g),Object.keys(g).length===0},x=g=>{g.preventDefault(),v()&&(p(!0),t(a))};return l?(0,r.jsx)("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"}):(0,r.jsxs)("form",{onSubmit:x,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&&(0,r.jsx)("div",{style:{fontWeight:600,fontSize:"15px",marginBottom:"4px",color:"#2D3436",letterSpacing:"-0.01em"},children:e.title}),e.description&&(0,r.jsx)("div",{style:{fontSize:"12px",color:"rgba(0,0,0,0.45)",marginBottom:"16px",lineHeight:"1.5"},children:e.description}),e.fields.map(g=>(0,r.jsx)(Re,{field:g,value:a[g.name],onChange:h=>y(g.name,h),error:s[g.name],primaryColor:n},g.name)),(0,r.jsx)("button",{type:"submit",style:{width:"100%",padding:"12px",background:`linear-gradient(135deg, ${n} 0%, ${Me(n,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 ${n}33`,transition:"all 0.25s cubic-bezier(0.4, 0, 0.2, 1)"},onMouseEnter:g=>{g.currentTarget.style.transform="translateY(-1px)",g.currentTarget.style.boxShadow=`0 6px 20px ${n}44`},onMouseLeave:g=>{g.currentTarget.style.transform="translateY(0)",g.currentTarget.style.boxShadow=`0 4px 14px ${n}33`},children:e.submitLabel??"Submit"})]})},Re=({field:e,value:t,onChange:n,error:a,primaryColor:o})=>{switch(e.type){case"text":case"email":case"password":case"number":case"tel":case"url":case"textarea":case"date":case"time":return(0,r.jsx)(Z,{field:e,value:String(t??""),onChange:n,error:a});case"select":case"multiselect":return(0,r.jsx)(ee,{field:e,value:t,onChange:n,error:a});case"radio":return(0,r.jsx)(te,{field:e,value:String(t??""),onChange:n,error:a});case"checkbox":return(0,r.jsx)(re,{field:e,value:t??[],onChange:n,error:a});case"file":return(0,r.jsx)(ne,{field:e,value:t,onChange:n,error:a,primaryColor:o});case"hidden":return(0,r.jsx)("input",{type:"hidden",name:e.name,value:String(t??"")});default:return null}};function Me(e,t){const n=parseInt(e.replace("#",""),16),a=Math.min(255,(n>>16&255)+t),o=Math.min(255,(n>>8&255)+t),s=Math.min(255,(n&255)+t);return`#${(a<<16|o<<8|s).toString(16).padStart(6,"0")}`}var ae=({config:e,onLogin:t,primaryColor:n})=>(0,r.jsx)("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:(0,r.jsx)(_,{config:e,onSubmit:t,primaryColor:n})}),oe=({message:e,styles:t})=>{const n=e.sender==="bot",a=e.sender==="system",o=n||a?t.botBubble:t.userBubble;if(!(e.text||e.attachments&&e.attachments.length>0))return null;const s=a?{background:"transparent",border:"none",boxShadow:"none",color:"#999",fontSize:"12px",alignSelf:"center",padding:"6px 12px",backdropFilter:"none",WebkitBackdropFilter:"none"}:{};return(0,r.jsxs)("div",{style:{...o,...s,animation:"cb-fade-in 0.3s ease-out"},children:[e.text&&(0,r.jsx)("span",{style:{display:"block"},children:e.text}),e.attachments&&e.attachments.length>0&&(0,r.jsx)("div",{style:{marginTop:e.text?"10px":0,display:"flex",flexDirection:"column",gap:"6px"},children:e.attachments.map((i,l)=>(0,r.jsx)(Ae,{attachment:i,isBot:n},l))})]})},Ae=({attachment:e,isBot:t})=>e.type.startsWith("image/")&&e.url?(0,r.jsxs)("div",{style:{borderRadius:"12px",overflow:"hidden",maxWidth:"220px"},children:[(0,r.jsx)("img",{src:e.url,alt:e.name,style:{width:"100%",height:"auto",display:"block",borderRadius:"12px"}}),(0,r.jsx)("div",{style:{fontSize:"11px",padding:"4px 0",opacity:.6},children:e.name})]}):(0,r.jsxs)("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:[(0,r.jsx)(L,{size:16}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:e.name}),e.size&&(0,r.jsx)("span",{style:{fontSize:"11px",opacity:.5,flexShrink:0},children:Be(e.size)})]});function Be(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}var se=({replies:e,onSelect:t,primaryColor:n})=>(0,r.jsx)("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(a=>(0,r.jsx)("button",{onClick:()=>t(a.value,a.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:o=>{o.currentTarget.style.backgroundColor=n,o.currentTarget.style.color="#fff",o.currentTarget.style.transform="translateY(-1px)",o.currentTarget.style.boxShadow=`0 4px 14px ${n}44`},onMouseLeave:o=>{o.currentTarget.style.backgroundColor="rgba(108, 92, 231, 0.06)",o.currentTarget.style.color=n,o.currentTarget.style.transform="translateY(0)",o.currentTarget.style.boxShadow="none"},children:a.label},a.value))}),ie=({color:e})=>{const t={width:"7px",height:"7px",borderRadius:"50%",backgroundColor:e,opacity:.35,animation:"cb-typing-bounce 1.4s infinite ease-in-out"};return(0,r.jsxs)("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:[(0,r.jsx)("span",{style:{...t,animationDelay:"0s"}}),(0,r.jsx)("span",{style:{...t,animationDelay:"0.2s"}}),(0,r.jsx)("span",{style:{...t,animationDelay:"0.4s"}})]})},le=({messages:e,isTyping:t,styles:n,primaryColor:a,onQuickReply:o,onFormSubmit:s,components:i,onComponentComplete:l,collectedData:p,currentStepId:y})=>{const v=(0,d.useRef)(null);return(0,d.useEffect)(()=>{v.current?.scrollIntoView({behavior:"smooth"})},[e,t]),(0,r.jsxs)("div",{style:n.messageList,className:"cb-scrollbar",children:[e.map(x=>(0,r.jsxs)(d.default.Fragment,{children:[(0,r.jsx)(oe,{message:x,styles:n}),x.quickReplies&&x.quickReplies.length>0&&(0,r.jsx)(se,{replies:x.quickReplies,onSelect:o,primaryColor:a}),x.form&&(0,r.jsx)("div",{style:{alignSelf:"flex-start",width:"92%",animation:"cb-slide-up 0.35s ease-out"},children:(0,r.jsx)(_,{config:x.form,onSubmit:g=>s(x.form.id,g),primaryColor:a})}),x.component&&i?.[x.component]&&(0,r.jsx)("div",{style:{alignSelf:"flex-start",width:"92%",animation:"cb-slide-up 0.35s ease-out"},children:d.default.createElement(i[x.component],{stepId:y??"",data:p??{},onComplete:g=>l?.(g)})})]},x.id)),t&&(0,r.jsx)(ie,{color:a}),(0,r.jsx)("div",{ref:v})]})},P=[{name:"Smileys",emojis:["๐","๐","๐","๐","๐
","๐","๐คฃ","๐","๐","๐","๐","๐","๐ฅฐ","๐","๐","๐","๐คช","๐ค","๐ค","๐คซ","๐คญ","๐","๐","๐","๐ถ","๐","๐ด","๐คค","๐ท","๐ค"]},{name:"Gestures",emojis:["๐","๐","๐","โ๏ธ","๐ค","๐ค","๐ค","๐","๐ค","โ","๐","๐","๐","๐ค","๐","๐ช","๐๏ธ","โ๏ธ","๐","๐","๐","๐","๐ค","๐ซก","๐ซถ","๐ซฐ","๐ซณ","๐ซด","๐ซฒ","๐ซฑ"]},{name:"Hearts",emojis:["โค๏ธ","๐งก","๐","๐","๐","๐","๐ค","๐ค","๐ค","๐","โฃ๏ธ","๐","๐","๐","๐","๐","๐","๐","๐","โฅ๏ธ","๐ซ","๐","๐","๐น","๐บ","๐ธ","๐ผ","๐ป","๐ท","๐ฎ"]},{name:"Objects",emojis:["๐ฅ","โญ","โจ","๐ฏ","๐","๐","๐ฏ","๐","๐ก","๐","๐","๐","๐ป","๐ฑ","โ๏ธ","๐ง","๐","๐","๐","๐","๐๏ธ","๐","๐","๐","โ๏ธ","๐ ๏ธ","๐ง","๐ฆ","๐ท๏ธ","โ
"]}],ce=({onSelect:e,onClose:t,primaryColor:n})=>{const[a,o]=(0,d.useState)(0),s=(0,d.useRef)(null);(0,d.useEffect)(()=>{const l=p=>{s.current&&!s.current.contains(p.target)&&t()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[t]);const i=P[a]?.emojis??[];return(0,r.jsxs)("div",{ref:s,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:[(0,r.jsx)("div",{style:{display:"flex",borderBottom:"1px solid rgba(0,0,0,0.06)",padding:"6px",gap:"3px"},children:P.map((l,p)=>(0,r.jsx)("button",{onClick:()=>o(p),title:l.name,style:{flex:1,padding:"6px 4px",border:"none",borderRadius:"8px",cursor:"pointer",fontSize:"11px",fontWeight:600,fontFamily:"inherit",letterSpacing:"0.02em",background:p===a?`linear-gradient(135deg, ${n}, ${n}CC)`:"transparent",color:p===a?"#fff":"rgba(0,0,0,0.4)",transition:"all 0.2s ease",boxShadow:p===a?`0 2px 8px ${n}33`:"none"},children:l.name},l.name))}),(0,r.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(8, 1fr)",gap:"2px",padding:"8px",maxHeight:"180px",overflowY:"auto"},children:i.map(l=>(0,r.jsx)("button",{onClick:()=>{e(l),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:p=>p.currentTarget.style.backgroundColor="rgba(108, 92, 231, 0.08)",onMouseLeave:p=>p.currentTarget.style.backgroundColor="transparent",children:l},l))})]})},de=({config:e,onFiles:t,selectedFiles:n,onRemoveFile:a,primaryColor:o})=>{const s=(0,d.useRef)(null),i=l=>{const p=l.target.files;if(!p||p.length===0)return;const y=Array.from(p);if(e.maxSize&&y.filter(x=>x.size>e.maxSize).length>0){alert(`File(s) too large. Max size: ${ue(e.maxSize)}`);return}const v=e.maxFiles??5;if(n.length+y.length>v){alert(`Maximum ${v} files allowed`);return}t(y),s.current&&(s.current.value="")};return(0,r.jsxs)("div",{children:[(0,r.jsx)("input",{ref:s,type:"file",accept:e.accept,multiple:e.multiple!==!1,onChange:i,style:{display:"none"}}),(0,r.jsx)("button",{type:"button",onClick:()=>s.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:l=>l.currentTarget.style.color=o,onMouseLeave:l=>l.currentTarget.style.color="#999",children:(0,r.jsx)(U,{size:20})})]})},pe=({files:e,onRemove:t,primaryColor:n})=>e.length===0?null:(0,r.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",padding:"8px 12px 0"},children:e.map((a,o)=>(0,r.jsx)(Le,{file:a,onRemove:()=>t(o),primaryColor:n},`${a.name}-${o}`))}),Le=({file:e,onRemove:t,primaryColor:n})=>{const a=e.type.startsWith("image/");return(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 8px",backgroundColor:"#F3F4F6",borderRadius:"8px",fontSize:"12px",maxWidth:"200px"},children:[(0,r.jsx)("span",{style:{color:n,flexShrink:0},children:a?(0,r.jsx)(Y,{size:14}):(0,r.jsx)(L,{size:14})}),(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#555"},children:e.name}),(0,r.jsx)("span",{style:{color:"#999",fontSize:"11px",flexShrink:0},children:ue(e.size)}),(0,r.jsx)("button",{onClick:t,style:{background:"none",border:"none",cursor:"pointer",padding:"0",display:"flex",color:"#999",flexShrink:0},children:(0,r.jsx)(Q,{size:14})})]})};function ue(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}var xe=({onSend:e,placeholder:t="Type a message...",primaryColor:n,isDark:a=!1,disabled:o,styleOverride:s,enableEmoji:i=!1,fileUpload:l,onFileUpload:p})=>{const[y,v]=(0,d.useState)(""),[x,g]=(0,d.useState)(!1),[h,k]=(0,d.useState)([]),j=(0,d.useRef)(null),F=(0,d.useCallback)(()=>{const u=y.trim();!u&&h.length===0||(e(u,h.length>0?h:void 0),v(""),k([]),j.current?.focus())},[y,h,e]),C=u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),F())},c=u=>{v(S=>S+u),j.current?.focus()},b=u=>{k(S=>[...S,...u]),p?.(u)},m=u=>{k(S=>S.filter((D,w)=>w!==u))},f=y.trim()||h.length>0;return(0,r.jsxs)("div",{style:{position:"relative",...s},children:[h.length>0&&(0,r.jsx)(pe,{files:h,onRemove:m,primaryColor:n}),x&&(0,r.jsx)(ce,{onSelect:c,onClose:()=>g(!1),primaryColor:n}),(0,r.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end",background:a?"rgba(40, 40, 65, 0.5)":"rgba(245, 247, 252, 0.7)",borderRadius:"16px",border:`1px solid ${a?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.05)"}`,backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",padding:"6px 6px 6px 12px"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"2px",flexShrink:0,paddingBottom:"2px"},children:[i&&(0,r.jsx)("button",{type:"button",onClick:()=>g(!x),"aria-label":"Emoji",title:"Emoji",style:{background:"none",border:"none",cursor:"pointer",padding:"6px",display:"flex",color:x?n:a?"rgba(255,255,255,0.35)":"rgba(0,0,0,0.3)",borderRadius:"8px",transition:"all 0.2s ease"},children:(0,r.jsx)(N,{size:20})}),l?.enabled&&(0,r.jsx)(de,{config:l,onFiles:b,selectedFiles:h,onRemoveFile:m,primaryColor:n})]}),(0,r.jsx)("textarea",{ref:j,value:y,onChange:u=>v(u.target.value),onKeyDown:C,placeholder:t,disabled:o,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:a?"#E0E0E0":"#2D3436",letterSpacing:"0.01em"}}),(0,r.jsx)("button",{onClick:F,disabled:o||!f,"aria-label":"Send message",style:{width:"36px",height:"36px",borderRadius:"12px",background:f?`linear-gradient(135deg, ${n} 0%, ${_e(n,30)} 100%)`:a?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",color:f?"#fff":a?"rgba(255,255,255,0.25)":"rgba(0,0,0,0.2)",border:"none",cursor:f?"pointer":"default",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"all 0.25s cubic-bezier(0.4, 0, 0.2, 1)",boxShadow:f?`0 4px 12px ${n}44`:"none"},children:(0,r.jsx)(G,{size:16})})]})]})};function _e(e,t){const n=parseInt(e.replace("#",""),16),a=Math.min(255,(n>>16&255)+t),o=Math.min(255,(n>>8&255)+t),s=Math.min(255,(n&255)+t);return`#${(a<<16|o<<8|s).toString(16).padStart(6,"0")}`}var ge=({config:e,primaryColor:t})=>{if(e.showBranding===!1)return null;const n=e.poweredBy??"React ChatBot";return(0,r.jsxs)("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?(0,r.jsx)("a",{href:e.poweredByUrl,target:"_blank",rel:"noopener noreferrer",style:{color:t,textDecoration:"none",fontWeight:600,transition:"opacity 0.2s ease"},children:n}):(0,r.jsx)("span",{style:{color:t,fontWeight:600},children:n})]})},be=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(t=>[t.id,t]))}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){const{field:n,operator:a,value:o,then:s,else:i}=e.condition,l=this.collectedData[n];return this.evaluate(l,a,o)?s:i}if(t&&e.quickReplies){const n=e.quickReplies.find(a=>a.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;const n=t.toLowerCase().trim(),a=e.quickReplies.find(s=>s.value.toLowerCase()===n);if(a)return a;const o=e.quickReplies.find(s=>s.label.toLowerCase().replace(/[^\w\s]/g,"").trim()===n);return o||e.quickReplies.find(s=>n.includes(s.value.toLowerCase())||s.label.toLowerCase().includes(n))}buildMessages(e){const t=[],n=e.messages??(e.message?[e.message]:[]);for(const a of n)t.push({id:this.uid(),sender:"bot",text:a,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}}},ze=0,E=()=>`msg_${Date.now()}_${++ze}`,I=e=>new Promise(t=>setTimeout(t,e)),Pe={"/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 he(){const{state:e,dispatch:t,props:n}=M(),a=(0,d.useRef)(null),o=(0,d.useRef)(!1),s=(0,d.useRef)(e);s.current=e;const i=(0,d.useRef)(n);i.current=n,(0,d.useEffect)(()=>{n.flow&&(a.current=new be(n.flow),o.current=!1)},[n.flow]);const l=(0,d.useCallback)(async(c,b)=>{t({type:"SET_TYPING",payload:!0}),await I(400);const m={id:E(),sender:"bot",text:c,timestamp:Date.now(),...b};t({type:"SET_TYPING",payload:!1}),t({type:"ADD_MESSAGE",payload:m}),i.current.callbacks?.onMessageReceive?.(m)},[t]),p=(0,d.useCallback)(c=>{t({type:"ADD_MESSAGE",payload:{id:E(),sender:"system",text:c,timestamp:Date.now()}})},[t]),y=(0,d.useRef)(async()=>{});y.current=async c=>{const b=a.current;if(!b)return;const m=b.getStep(c);if(!m)return;b.pushHistory(c),t({type:"SET_STEP",payload:c}),t({type:"SET_TYPING",payload:!0}),await I(m.delay??500);const f=b.buildMessages(m);if(t({type:"SET_TYPING",payload:!1}),t({type:"ADD_MESSAGES",payload:f}),f.forEach(u=>i.current.callbacks?.onMessageReceive?.(u)),m.asyncAction){const u=i.current.actionHandlers?.[m.asyncAction.handler];if(u){const S=E();t({type:"ADD_MESSAGE",payload:{id:S,sender:"bot",text:m.asyncAction.loadingMessage??"Processing...",timestamp:Date.now()}});const D={updateMessage:w=>{t({type:"UPDATE_MESSAGE",payload:{id:S,updates:{text:w}}})}};try{const w=await u(b.getData(),D);w.data&&(b.mergeData(w.data),t({type:"SET_DATA",payload:w.data})),t({type:"UPDATE_MESSAGE",payload:{id:S,updates:{text:w.message??(w.status==="success"?m.asyncAction.successMessage??"Done!":m.asyncAction.errorMessage??"Something went wrong.")}}});const z=v(m,w);z&&(await I(600),y.current(z))}catch{t({type:"UPDATE_MESSAGE",payload:{id:S,updates:{text:m.asyncAction.errorMessage??"โ Something went wrong."}}}),m.asyncAction.onError&&(await I(600),y.current(m.asyncAction.onError))}return}}m.component&&i.current.components?.[m.component]||!m.quickReplies&&!m.form&&m.next&&(await I(300),y.current(m.next))};function v(c,b){return b.next?b.next:c.asyncAction?.routes?.[b.status]?c.asyncAction.routes[b.status]:b.status==="success"&&c.asyncAction?.onSuccess?c.asyncAction.onSuccess:b.status==="error"&&c.asyncAction?.onError?c.asyncAction.onError:c.next}const x=(0,d.useCallback)(c=>y.current(c),[]),g=(0,d.useCallback)(()=>{const c=a.current;if(!c||!c.canGoBack()){p("There is no previous step to go back to.");return}t({type:"CLEAR_QUICK_REPLIES"});const b=c.popHistory();b?x(b):p("There is no previous step to go back to.")},[t,x,p]),h=(0,d.useCallback)(()=>{const c=a.current;c&&c.reset(),o.current=!1,t({type:"RESET_CHAT"}),c&&(o.current=!0,x(c.getStartStepId()))},[t,x]),k=(0,d.useRef)(()=>!1);k.current=c=>{const b=c.trim().toLowerCase();if(!b.startsWith("/"))return!1;switch(b){case"/help":return p(`Available commands:
|
|
2
|
-
${Object.entries(
|
|
3
|
-
`)}`),!0;case
|
|
4
|
-
`);t({type
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);let l=require(`react/jsx-runtime`);function u(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 d=e=>({isOpen:e.defaultOpen??!1,messages:e.initialMessages??[],isTyping:!1,showWelcome:!!e.welcomeScreen,currentStepId:null,collectedData:{},isLoggedIn:!e.loginForm}),f=(0,c.createContext)(null);function p(){let e=(0,c.useContext)(f);if(!e)throw Error(`useChatContext must be used within ChatProvider`);return e}var m={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`},h={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 g(e){let t={...m,...e};return t.mode===`dark`?{...t,...h,...e}:t}function _(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 v(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 y=({size:e=18,color:t=`currentColor`})=>(0,l.jsx)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:t,children:(0,l.jsx)(`path`,{d:`M2.01 21L23 12 2.01 3 2 10l15 2-15 2z`})}),b=({size:e=28,color:t=`currentColor`})=>(0,l.jsx)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`})}),x=({size:e=20,color:t=`currentColor`})=>(0,l.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,l.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,l.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]}),S=({size:e=20,color:t=`currentColor`})=>(0,l.jsx)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})}),C=({size:e=20,color:t=`currentColor`})=>(0,l.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,l.jsx)(`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`}),(0,l.jsx)(`line`,{x1:`9`,y1:`9`,x2:`9.01`,y2:`9`}),(0,l.jsx)(`line`,{x1:`15`,y1:`9`,x2:`15.01`,y2:`9`})]}),w=({size:e=20,color:t=`currentColor`})=>(0,l.jsx)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`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`})}),T=({size:e=16,color:t=`currentColor`})=>(0,l.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,l.jsx)(`path`,{d:`M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z`}),(0,l.jsx)(`polyline`,{points:`14 2 14 8 20 8`})]}),E=({size:e=16,color:t=`currentColor`})=>(0,l.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,l.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,l.jsx)(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),(0,l.jsx)(`polyline`,{points:`21 15 16 10 5 21`})]}),D=({size:e=14,color:t=`currentColor`})=>(0,l.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,l.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,l.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),O=({size:e=16,color:t=`currentColor`})=>(0,l.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:t,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,l.jsx)(`polyline`,{points:`1 4 1 10 7 10`}),(0,l.jsx)(`path`,{d:`M3.51 15a9 9 0 1 0 2.13-9.36L1 10`})]}),k=({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(0,l.jsx)(`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??(0,l.jsx)(x,{size:22}):i??(0,l.jsx)(b,{size:26})})},ee=({config:e,styles:t,onClose:n,onRestart:r,logo:i,logoWidth:a})=>(0,l.jsxs)(`div`,{style:t.header,children:[(0,l.jsx)(`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`}}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,flex:1,position:`relative`,zIndex:1},children:[e.avatar&&(0,l.jsxs)(`div`,{style:{position:`relative`},children:[(0,l.jsx)(`img`,{src:e.avatar,alt:``,style:{width:`40px`,height:`40px`,borderRadius:`50%`,objectFit:`cover`,border:`2px solid rgba(255,255,255,0.3)`}}),(0,l.jsx)(`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&&(0,l.jsx)(`img`,{src:i,alt:``,style:{width:a??`36px`,height:`auto`,objectFit:`contain`,filter:`brightness(1.1)`}}),!e.avatar&&!i&&(0,l.jsx)(`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()}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{style:{fontWeight:600,fontSize:`16px`,letterSpacing:`-0.01em`},children:e.title??`Chat with us`}),e.subtitle&&(0,l.jsxs)(`div`,{style:{fontSize:`12px`,opacity:.8,display:`flex`,alignItems:`center`,gap:`5px`,marginTop:`1px`},children:[(0,l.jsx)(`span`,{style:{width:`6px`,height:`6px`,borderRadius:`50%`,backgroundColor:`#2ECC71`,display:`inline-block`}}),e.subtitle]})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,position:`relative`,zIndex:1},children:[e.showRestart&&r&&(0,l.jsx)(`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:(0,l.jsx)(O,{size:16})}),e.showMinimize&&(0,l.jsx)(`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:(0,l.jsx)(S,{size:16})}),e.showClose!==!1&&(0,l.jsx)(`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:(0,l.jsx)(x,{size:18})})]})]}),te=({content:e,onDismiss:t,primaryColor:n})=>(0,l.jsxs)(`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:[(0,l.jsx)(`div`,{style:{flex:1,padding:`28px 24px`,overflow:`auto`},children:e}),(0,l.jsx)(`div`,{style:{padding:`16px 20px`,borderTop:`1px solid rgba(0,0,0,0.05)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,flexShrink:0},children:(0,l.jsx)(`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 A=({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(0,l.jsxs)(`div`,{style:{marginBottom:`14px`},children:[e.label&&(0,l.jsxs)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500,color:`#2D3436`},children:[e.label,e.required&&(0,l.jsx)(`span`,{style:{color:`#E53E3E`,marginLeft:`3px`},children:`*`})]}),i?(0,l.jsx)(`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}):(0,l.jsx)(`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&&(0,l.jsx)(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},j=({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(0,l.jsxs)(`div`,{style:{marginBottom:`14px`},children:[e.label&&(0,l.jsxs)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500,color:`#2D3436`},children:[e.label,e.required&&(0,l.jsx)(`span`,{style:{color:`#E53E3E`,marginLeft:`3px`},children:`*`})]}),(0,l.jsxs)(`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&&(0,l.jsx)(`option`,{value:``,children:`Select...`}),e.options?.map(e=>(0,l.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),i&&(0,l.jsx)(`div`,{style:{fontSize:`11px`,color:`#888`,marginTop:`2px`},children:`Hold Ctrl/Cmd to select multiple`}),r&&(0,l.jsx)(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},M=({field:e,value:t,onChange:n,error:r})=>(0,l.jsxs)(`div`,{style:{marginBottom:`12px`},children:[e.label&&(0,l.jsxs)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&(0,l.jsx)(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),(0,l.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:e.options?.map(r=>(0,l.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`13px`},children:[(0,l.jsx)(`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&&(0,l.jsx)(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]}),N=({field:e,value:t,onChange:n,error:r})=>{let i=e=>{t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])};return(0,l.jsxs)(`div`,{style:{marginBottom:`12px`},children:[e.label&&(0,l.jsxs)(`label`,{style:{display:`block`,marginBottom:`6px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&(0,l.jsx)(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),(0,l.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`},children:e.options?.map(e=>(0,l.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,cursor:`pointer`,fontSize:`13px`},children:[(0,l.jsx)(`input`,{type:`checkbox`,checked:t.includes(e.value),onChange:()=>i(e.value),style:{margin:0}}),e.label]},e.value))}),r&&(0,l.jsx)(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},P=({field:e,value:t,onChange:n,error:r,primaryColor:i})=>{let a=(0,c.useRef)(null),o=t?Array.from(t).map(e=>e.name).join(`, `):``;return(0,l.jsxs)(`div`,{style:{marginBottom:`12px`},children:[e.label&&(0,l.jsxs)(`label`,{style:{display:`block`,marginBottom:`4px`,fontSize:`13px`,fontWeight:500},children:[e.label,e.required&&(0,l.jsx)(`span`,{style:{color:`#E53E3E`,marginLeft:`2px`},children:`*`})]}),(0,l.jsx)(`input`,{ref:a,type:`file`,accept:e.accept,multiple:e.multiple,onChange:e=>n(e.target.files),style:{display:`none`}}),(0,l.jsx)(`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&&(0,l.jsxs)(`div`,{style:{fontSize:`12px`,color:i,marginTop:`4px`},children:[Array.from(t).length,` file(s) selected`]}),r&&(0,l.jsx)(`div`,{style:{color:`#E53E3E`,fontSize:`12px`,marginTop:`2px`},children:r})]})},F=({config:e,onSubmit:t,primaryColor:n,renderFormField:r})=>{let[i,a]=(0,c.useState)(()=>{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}),[o,s]=(0,c.useState)({}),[u,d]=(0,c.useState)(!1),f=(0,c.useCallback)((e,t)=>{a(n=>({...n,[e]:t})),s(t=>{let n={...t};return delete n[e],n})},[]),p=()=>{let t={};for(let n of e.fields){let e=i[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 s(t),Object.keys(t).length===0};return u?(0,l.jsx)(`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`}):(0,l.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()&&(d(!0),t(i))},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&&(0,l.jsx)(`div`,{style:{fontWeight:600,fontSize:`15px`,marginBottom:`4px`,color:`#2D3436`,letterSpacing:`-0.01em`},children:e.title}),e.description&&(0,l.jsx)(`div`,{style:{fontSize:`12px`,color:`rgba(0,0,0,0.45)`,marginBottom:`16px`,lineHeight:`1.5`},children:e.description}),e.fields.map(e=>(0,l.jsx)(re,{field:e,value:i[e.name],onChange:t=>f(e.name,t),error:o[e.name],primaryColor:n,renderFormField:r},e.name)),(0,l.jsx)(`button`,{type:`submit`,style:{width:`100%`,padding:`12px`,background:`linear-gradient(135deg, ${n} 0%, ${ie(n,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 ${n}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 ${n}44`},onMouseLeave:e=>{e.currentTarget.style.transform=`translateY(0)`,e.currentTarget.style.boxShadow=`0 4px 14px ${n}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=(0,l.jsx)(A,{field:e,value:String(t??``),onChange:n,error:r});return o?(0,l.jsx)(l.Fragment,{children:o(i,a)}):a}case`select`:case`multiselect`:{let i={type:e.type,field:e,value:t,onChange:n,error:r},a=(0,l.jsx)(j,{field:e,value:t,onChange:n,error:r});return o?(0,l.jsx)(l.Fragment,{children:o(i,a)}):a}case`radio`:{let i={type:`radio`,field:e,value:String(t??``),onChange:n,error:r},a=(0,l.jsx)(M,{field:e,value:String(t??``),onChange:n,error:r});return o?(0,l.jsx)(l.Fragment,{children:o(i,a)}):a}case`checkbox`:{let i={type:`checkbox`,field:e,value:t??[],onChange:n,error:r},a=(0,l.jsx)(N,{field:e,value:t??[],onChange:n,error:r});return o?(0,l.jsx)(l.Fragment,{children:o(i,a)}):a}case`file`:{let a={type:`file`,field:e,value:t,onChange:n,error:r,primaryColor:i},s=(0,l.jsx)(P,{field:e,value:t,onChange:n,error:r,primaryColor:i});return o?(0,l.jsx)(l.Fragment,{children:o(a,s)}):s}case`hidden`:return(0,l.jsx)(`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 I=({config:e,onLogin:t,primaryColor:n,renderFormField:r})=>(0,l.jsx)(`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:(0,l.jsx)(F,{config:e,onSubmit:t,primaryColor:n,renderFormField:r})}),L=({message:e,styles:t})=>{let n=e.sender===`bot`,r=e.sender===`system`,i=n||r?t.botBubble:t.userBubble;if(!(e.text||e.attachments&&e.attachments.length>0))return null;let a=r?{background:`transparent`,border:`none`,boxShadow:`none`,color:`#999`,fontSize:`12px`,alignSelf:`center`,padding:`6px 12px`,backdropFilter:`none`,WebkitBackdropFilter:`none`}:{};return(0,l.jsxs)(`div`,{style:{...i,...a,animation:`cb-fade-in 0.3s ease-out`},children:[e.text&&(0,l.jsx)(`span`,{style:{display:`block`},children:e.text}),e.attachments&&e.attachments.length>0&&(0,l.jsx)(`div`,{style:{marginTop:e.text?`10px`:0,display:`flex`,flexDirection:`column`,gap:`6px`},children:e.attachments.map((e,t)=>(0,l.jsx)(ae,{attachment:e,isBot:n},t))})]})},ae=({attachment:e,isBot:t})=>e.type.startsWith(`image/`)&&e.url?(0,l.jsxs)(`div`,{style:{borderRadius:`12px`,overflow:`hidden`,maxWidth:`220px`},children:[(0,l.jsx)(`img`,{src:e.url,alt:e.name,style:{width:`100%`,height:`auto`,display:`block`,borderRadius:`12px`}}),(0,l.jsx)(`div`,{style:{fontSize:`11px`,padding:`4px 0`,opacity:.6},children:e.name})]}):(0,l.jsxs)(`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:[(0,l.jsx)(T,{size:16}),(0,l.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,flex:1},children:e.name}),e.size&&(0,l.jsx)(`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 R=({replies:e,onSelect:t,primaryColor:n})=>(0,l.jsx)(`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=>(0,l.jsx)(`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))}),z=({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(0,l.jsxs)(`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:[(0,l.jsx)(`span`,{style:{...t,animationDelay:`0s`}}),(0,l.jsx)(`span`,{style:{...t,animationDelay:`0.2s`}}),(0,l.jsx)(`span`,{style:{...t,animationDelay:`0.4s`}})]})},B=({messages:e,isTyping:t,styles:n,primaryColor:r,onQuickReply:i,onFormSubmit:a,components:o,onComponentComplete:s,collectedData:u,currentStepId:d,renderFormField:f})=>{let p=(0,c.useRef)(null);return(0,c.useEffect)(()=>{p.current?.scrollIntoView({behavior:`smooth`})},[e,t]),(0,l.jsxs)(`div`,{style:n.messageList,className:`cb-scrollbar`,children:[e.map(e=>(0,l.jsxs)(c.default.Fragment,{children:[(0,l.jsx)(L,{message:e,styles:n}),e.quickReplies&&e.quickReplies.length>0&&(0,l.jsx)(R,{replies:e.quickReplies,onSelect:i,primaryColor:r}),e.form&&(0,l.jsx)(`div`,{style:{alignSelf:`flex-start`,width:`92%`,animation:`cb-slide-up 0.35s ease-out`},children:(0,l.jsx)(F,{config:e.form,onSubmit:t=>a(e.form.id,t),primaryColor:r,renderFormField:f})}),e.component&&o?.[e.component]&&(0,l.jsx)(`div`,{style:{alignSelf:`flex-start`,width:`92%`,animation:`cb-slide-up 0.35s ease-out`},children:c.default.createElement(o[e.component],{stepId:d??``,data:u??{},onComplete:e=>s?.(e)})})]},e.id)),t&&(0,l.jsx)(z,{color:r}),(0,l.jsx)(`div`,{ref:p})]})},V=[{name:`Smileys`,emojis:`๐.๐.๐.๐.๐
.๐.๐คฃ.๐.๐.๐.๐.๐.๐ฅฐ.๐.๐.๐.๐คช.๐ค.๐ค.๐คซ.๐คญ.๐.๐.๐.๐ถ.๐.๐ด.๐คค.๐ท.๐ค`.split(`.`)},{name:`Gestures`,emojis:`๐.๐.๐.โ๏ธ.๐ค.๐ค.๐ค.๐.๐ค.โ.๐.๐.๐.๐ค.๐.๐ช.๐๏ธ.โ๏ธ.๐.๐.๐.๐.๐ค.๐ซก.๐ซถ.๐ซฐ.๐ซณ.๐ซด.๐ซฒ.๐ซฑ`.split(`.`)},{name:`Hearts`,emojis:`โค๏ธ.๐งก.๐.๐.๐.๐.๐ค.๐ค.๐ค.๐.โฃ๏ธ.๐.๐.๐.๐.๐.๐.๐.๐.โฅ๏ธ.๐ซ.๐.๐.๐น.๐บ.๐ธ.๐ผ.๐ป.๐ท.๐ฎ`.split(`.`)},{name:`Objects`,emojis:`๐ฅ.โญ.โจ.๐ฏ.๐.๐.๐ฏ.๐.๐ก.๐.๐.๐.๐ป.๐ฑ.โ๏ธ.๐ง.๐.๐.๐.๐.๐๏ธ.๐.๐.๐.โ๏ธ.๐ ๏ธ.๐ง.๐ฆ.๐ท๏ธ.โ
`.split(`.`)}],H=({onSelect:e,onClose:t,primaryColor:n})=>{let[r,i]=(0,c.useState)(0),a=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=e=>{a.current&&!a.current.contains(e.target)&&t()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[t]);let o=V[r]?.emojis??[];return(0,l.jsxs)(`div`,{ref:a,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:[(0,l.jsx)(`div`,{style:{display:`flex`,borderBottom:`1px solid rgba(0,0,0,0.06)`,padding:`6px`,gap:`3px`},children:V.map((e,t)=>(0,l.jsx)(`button`,{onClick:()=>i(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))}),(0,l.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`repeat(8, 1fr)`,gap:`2px`,padding:`8px`,maxHeight:`180px`,overflowY:`auto`},children:o.map(n=>(0,l.jsx)(`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))})]})},U=({config:e,onFiles:t,selectedFiles:n,onRemoveFile:r,primaryColor:i})=>{let a=(0,c.useRef)(null);return(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`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: ${G(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`}}),(0,l.jsx)(`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:(0,l.jsx)(w,{size:20})})]})},W=({files:e,onRemove:t,primaryColor:n})=>e.length===0?null:(0,l.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:`6px`,padding:`8px 12px 0`},children:e.map((e,r)=>(0,l.jsx)(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(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`6px`,padding:`4px 8px`,backgroundColor:`#F3F4F6`,borderRadius:`8px`,fontSize:`12px`,maxWidth:`200px`},children:[(0,l.jsx)(`span`,{style:{color:n,flexShrink:0},children:r?(0,l.jsx)(E,{size:14}):(0,l.jsx)(T,{size:14})}),(0,l.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`,color:`#555`},children:e.name}),(0,l.jsx)(`span`,{style:{color:`#999`,fontSize:`11px`,flexShrink:0},children:G(e.size)}),(0,l.jsx)(`button`,{onClick:t,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`0`,display:`flex`,color:`#999`,flexShrink:0},children:(0,l.jsx)(D,{size:14})})]})};function G(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}var K=({onSend:e,placeholder:t=`Type a message...`,primaryColor:n,isDark:r=!1,disabled:i,styleOverride:a,enableEmoji:o=!1,fileUpload:s,onFileUpload:u})=>{let[d,f]=(0,c.useState)(``),[p,m]=(0,c.useState)(!1),[h,g]=(0,c.useState)([]),_=(0,c.useRef)(null),v=(0,c.useCallback)(()=>{let t=d.trim();!t&&h.length===0||(e(t,h.length>0?h:void 0),f(``),g([]),_.current?.focus())},[d,h,e]),b=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),v())},x=e=>{f(t=>t+e),_.current?.focus()},S=e=>{g(t=>[...t,...e]),u?.(e)},w=e=>{g(t=>t.filter((t,n)=>n!==e))},T=d.trim()||h.length>0;return(0,l.jsxs)(`div`,{style:{position:`relative`,...a},children:[h.length>0&&(0,l.jsx)(W,{files:h,onRemove:w,primaryColor:n}),p&&(0,l.jsx)(H,{onSelect:x,onClose:()=>m(!1),primaryColor:n}),(0,l.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`flex-end`,background:r?`rgba(40, 40, 65, 0.5)`:`rgba(245, 247, 252, 0.7)`,borderRadius:`16px`,border:`1px solid ${r?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.05)`}`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,padding:`6px 6px 6px 12px`},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`2px`,flexShrink:0,paddingBottom:`2px`},children:[o&&(0,l.jsx)(`button`,{type:`button`,onClick:()=>m(!p),"aria-label":`Emoji`,title:`Emoji`,style:{background:`none`,border:`none`,cursor:`pointer`,padding:`6px`,display:`flex`,color:p?n:r?`rgba(255,255,255,0.35)`:`rgba(0,0,0,0.3)`,borderRadius:`8px`,transition:`all 0.2s ease`},children:(0,l.jsx)(C,{size:20})}),s?.enabled&&(0,l.jsx)(U,{config:s,onFiles:S,selectedFiles:h,onRemoveFile:w,primaryColor:n})]}),(0,l.jsx)(`textarea`,{ref:_,value:d,onChange:e=>f(e.target.value),onKeyDown:b,placeholder:t,disabled:i,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:r?`#E0E0E0`:`#2D3436`,letterSpacing:`0.01em`}}),(0,l.jsx)(`button`,{onClick:v,disabled:i||!T,"aria-label":`Send message`,style:{width:`36px`,height:`36px`,borderRadius:`12px`,background:T?`linear-gradient(135deg, ${n} 0%, ${ce(n,30)} 100%)`:r?`rgba(255,255,255,0.08)`:`rgba(0,0,0,0.06)`,color:T?`#fff`:r?`rgba(255,255,255,0.25)`:`rgba(0,0,0,0.2)`,border:`none`,cursor:T?`pointer`:`default`,display:`flex`,alignItems:`center`,justifyContent:`center`,flexShrink:0,transition:`all 0.25s cubic-bezier(0.4, 0, 0.2, 1)`,boxShadow:T?`0 4px 12px ${n}44`:`none`},children:(0,l.jsx)(y,{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 q=({config:e,primaryColor:t})=>{if(e.showBranding===!1)return null;let n=e.poweredBy??`React ChatBot`;return(0,l.jsxs)(`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?(0,l.jsx)(`a`,{href:e.poweredByUrl,target:`_blank`,rel:`noopener noreferrer`,style:{color:t,textDecoration:`none`,fontWeight:600,transition:`opacity 0.2s ease`},children:n}):(0,l.jsx)(`span`,{style:{color:t,fontWeight:600},children:n})]})},J=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,Y=()=>`msg_${Date.now()}_${++le}`,X=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 Z(){let{state:e,dispatch:t,props:n}=p(),r=(0,c.useRef)(null),i=(0,c.useRef)(!1),a=(0,c.useRef)(e);a.current=e;let o=(0,c.useRef)(n);o.current=n,(0,c.useEffect)(()=>{n.flow&&(r.current=new J(n.flow),i.current=!1)},[n.flow]);let s=(0,c.useCallback)(async(e,n)=>{t({type:`SET_TYPING`,payload:!0}),await X(400);let r={id:Y(),sender:`bot`,text:e,timestamp:Date.now(),...n};t({type:`SET_TYPING`,payload:!1}),t({type:`ADD_MESSAGE`,payload:r}),o.current.callbacks?.onMessageReceive?.(r)},[t]),l=(0,c.useCallback)(e=>{t({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`system`,text:e,timestamp:Date.now()}})},[t]),u=(0,c.useRef)(async()=>{});u.current=async e=>{let n=r.current;if(!n)return;let i=n.getStep(e);if(!i)return;n.pushHistory(e),t({type:`SET_STEP`,payload:e}),t({type:`SET_TYPING`,payload:!0}),await X(i.delay??500);let a=n.buildMessages(i);if(t({type:`SET_TYPING`,payload:!1}),t({type:`ADD_MESSAGES`,payload:a}),a.forEach(e=>o.current.callbacks?.onMessageReceive?.(e)),i.asyncAction){let e=o.current.actionHandlers?.[i.asyncAction.handler];if(e){let r=Y();t({type:`ADD_MESSAGE`,payload:{id:r,sender:`bot`,text:i.asyncAction.loadingMessage??`Processing...`,timestamp:Date.now()}});let a={updateMessage:e=>{t({type:`UPDATE_MESSAGE`,payload:{id:r,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:r,updates:{text:o.message??(o.status===`success`?i.asyncAction.successMessage??`Done!`:i.asyncAction.errorMessage??`Something went wrong.`)}}});let s=d(i,o);s&&(await X(600),u.current(s))}catch{t({type:`UPDATE_MESSAGE`,payload:{id:r,updates:{text:i.asyncAction.errorMessage??`โ Something went wrong.`}}}),i.asyncAction.onError&&(await X(600),u.current(i.asyncAction.onError))}return}}i.component&&o.current.components?.[i.component]||!i.quickReplies&&!i.form&&i.next&&(await X(300),u.current(i.next))};function d(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 f=(0,c.useCallback)(e=>u.current(e),[]),m=(0,c.useCallback)(()=>{let e=r.current;if(!e||!e.canGoBack()){l(`There is no previous step to go back to.`);return}t({type:`CLEAR_QUICK_REPLIES`});let n=e.popHistory();n?f(n):l(`There is no previous step to go back to.`)},[t,f,l]),h=(0,c.useCallback)(()=>{let e=r.current;e&&e.reset(),i.current=!1,t({type:`RESET_CHAT`}),e&&(i.current=!0,f(e.getStartStepId()))},[t,f]),g=(0,c.useRef)(()=>!1);g.current=e=>{let t=e.trim().toLowerCase();if(!t.startsWith(`/`))return!1;switch(t){case`/help`:return l(`Available commands:
|
|
2
|
+
${Object.entries(ue).map(([e,t])=>`**${e}** โ ${t}`).join(`
|
|
3
|
+
`)}`),!0;case`/cancel`:case`/back`:return m(),!0;case`/restart`:return h(),!0;default:return l(`Unknown command: ${t}. Type /help for available commands.`),!0}};let _=(0,c.useCallback)(e=>{let n=r.current,i=a.current.currentStepId;if(!n||!i)return;let s=n.getStep(i);if(!s)return;e?.data&&(n.mergeData(e.data),t({type:`SET_DATA`,payload:e.data})),e?.message&&t({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`bot`,text:e.message,timestamp:Date.now()}});let c=e?.next??s.next;c?f(c):(o.current.callbacks?.onFlowEnd?.(n.getData()),t({type:`SET_STEP`,payload:null}))},[t,f]),v=(0,c.useCallback)(e=>{if(g.current(e))return;let n={id:Y(),sender:`user`,text:e,timestamp:Date.now()};t({type:`ADD_MESSAGE`,payload:n}),o.current.callbacks?.onMessageSend?.(n),o.current.callbacks?.onSubmit?.({message:e});let i=a.current.currentStepId;if(r.current&&i){let n=r.current.getStep(i);if(n){if(n.asyncAction||n.component){s(`Please wait, I'm still processing. You can type /back to go back.`);return}if(r.current.stepExpectsQuickReply(n)){let i=r.current.matchQuickReply(n,e);if(i){t({type:`CLEAR_QUICK_REPLIES`}),r.current.setData(n.id,i.value);let e=r.current.resolveNext(n,i.value);e?f(e):(o.current.callbacks?.onFlowEnd?.(r.current.getData()),t({type:`SET_STEP`,payload:null}))}else s(`I didn't quite get that. Please choose one of the options below:`,{quickReplies:n.quickReplies})}else if(r.current.stepExpectsForm(n))s(`Please fill out the form above to continue.`);else{r.current.setData(n.id,e);let i=r.current.resolveNext(n,e);i?f(i):(s(`Thanks for your message! Our team will get back to you soon. ๐`),o.current.callbacks?.onFlowEnd?.(r.current.getData()),t({type:`SET_STEP`,payload:null}))}}}},[t,s,f]),y=(0,c.useCallback)(()=>{let e=r.current;!e||i.current||(i.current=!0,f(e.getStartStepId()))},[f]);return(0,c.useEffect)(()=>{n.flow&&!e.showWelcome&&e.isLoggedIn&&!i.current&&y()},[n.flow,e.showWelcome,e.isLoggedIn,y]),{state:e,sendMessage:v,addBotMessage:s,handleQuickReply:(0,c.useCallback)((e,n)=>{t({type:`CLEAR_QUICK_REPLIES`}),t({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`user`,text:n,timestamp:Date.now()}}),o.current.callbacks?.onQuickReply?.(e,n);let i=a.current.currentStepId;if(r.current&&i){let n=r.current.getStep(i);if(n){r.current.setData(n.id,e);let i=r.current.resolveNext(n,e);i?f(i):(o.current.callbacks?.onFlowEnd?.(r.current.getData()),t({type:`SET_STEP`,payload:null}))}}},[t,f]),handleFormSubmit:(0,c.useCallback)(async(e,n)=>{t({type:`SET_DATA`,payload:n}),r.current&&r.current.mergeData(n);let i=Object.entries(n).filter(([,e])=>e!==void 0&&e!==``).map(([e,t])=>`${e}: ${String(t)}`).join(`
|
|
4
|
+
`);t({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`user`,text:i,formData:n,timestamp:Date.now()}}),await o.current.callbacks?.onFormSubmit?.(e,n);let s=a.current.currentStepId;if(r.current&&s){let e=r.current.getStep(s);if(e){let n=r.current.resolveNext(e);n?f(n):(o.current.callbacks?.onFlowEnd?.(r.current.getData()),t({type:`SET_STEP`,payload:null}))}}},[t,f]),handleLogin:(0,c.useCallback)(async e=>{await o.current.callbacks?.onLogin?.(e),t({type:`SET_LOGGED_IN`,payload:!0})},[t]),toggleChat:(0,c.useCallback)(()=>{let e=!a.current.isOpen;t({type:`TOGGLE_OPEN`}),e?o.current.callbacks?.onOpen?.():o.current.callbacks?.onClose?.()},[t]),dismissWelcome:(0,c.useCallback)(()=>{t({type:`DISMISS_WELCOME`})},[t]),startFlow:y,processFlowStep:f,goBack:m,restartSession:h,handleComponentComplete:_}}var Q=({styles:e,position:t,zIndex:n,hidden:r})=>{let{props:i,dispatch:a}=p(),o=g(i.theme),s=o.mode===`dark`,{state:u,sendMessage:d,handleQuickReply:f,handleFormSubmit:m,handleLogin:h,toggleChat:_,dismissWelcome:v,restartSession:y,handleComponentComplete:b}=Z(),x=t===`bottom-left`?{bottom:`96px`,left:`24px`}:{bottom:`96px`,right:`24px`},S=(0,c.useCallback)((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?(a({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`user`,text:e,timestamp:Date.now(),attachments:n}}),d(e)):a({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`user`,timestamp:Date.now(),attachments:n}}),i.callbacks?.onFileUpload?.(t)}else e&&d(e)},[d,a,i.callbacks]),C=(0,c.useMemo)(()=>({currentStepId:u.currentStepId,isOpen:u.isOpen,messages:u.messages,collectedData:u.collectedData,toggleChat:_,restartSession:y,sendMessage:d}),[u.currentStepId,u.isOpen,u.messages,u.collectedData,_,y,d]),w=(0,l.jsx)(ee,{config:i.header??{title:`Chat with us`},styles:e,onClose:_,onRestart:y,logo:i.branding?.logo,logoWidth:i.branding?.logoWidth}),T=(0,l.jsx)(K,{onSend:S,placeholder:i.inputPlaceholder,primaryColor:o.primaryColor,isDark:s,enableEmoji:i.enableEmoji,fileUpload:i.fileUpload,onFileUpload:i.callbacks?.onFileUpload});return r?(0,l.jsx)(`div`,{style:{display:`none`}}):(0,l.jsxs)(`div`,{style:{...e.window,...x,...n==null?{}:{zIndex:n}},children:[i.renderHeader?i.renderHeader(C,w):w,u.showWelcome&&i.welcomeScreen?(0,l.jsx)(te,{content:i.welcomeScreen,onDismiss:v,primaryColor:o.primaryColor}):!u.isLoggedIn&&i.loginForm?(0,l.jsx)(I,{config:i.loginForm,onLogin:h,primaryColor:o.primaryColor,renderFormField:i.renderFormField}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(B,{messages:u.messages,isTyping:u.isTyping,styles:e,primaryColor:o.primaryColor,onQuickReply:f,onFormSubmit:m,components:i.components,onComponentComplete:b,collectedData:u.collectedData,currentStepId:u.currentStepId,renderFormField:i.renderFormField}),(0,l.jsx)(`div`,{style:e.inputArea,children:i.renderInput?i.renderInput(C,T):T}),i.branding&&(0,l.jsx)(q,{config:i.branding,primaryColor:o.primaryColor})]})]})},de=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{}}},fe=`
|
|
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,6 +42,5 @@ ${Object.entries(Pe).map(([m,f])=>`**${m}** โ ${f}`).join(`
|
|
|
42
42
|
.cb-scrollbar::-webkit-scrollbar-thumb:hover {
|
|
43
43
|
background: rgba(108, 92, 231, 0.35);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
`,$=!1;function pe(){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=fe,document.head.appendChild(e),$=!0}var me=e=>{let[t,n]=(0,c.useReducer)(u,e,d),r=g(e.theme),i=v(r,e.style),a=_(r),o=e.position??`bottom-right`,s=e.showLauncher!==!1,p=(0,c.useRef)(null),m=(0,c.useRef)(t);m.current=t,(0,c.useEffect)(()=>{pe()},[]),(0,c.useEffect)(()=>{if(e.plugins&&e.plugins.length>0){let t=new de;return t.register(e.plugins),t.setContext({sendMessage:e=>{n({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`user`,text:e,timestamp:Date.now()}})},addBotMessage:e=>{n({type:`ADD_MESSAGE`,payload:{id:Y(),sender:`bot`,text:e,timestamp:Date.now()}})},getMessages:()=>m.current.messages,getData:()=>m.current.collectedData,setData:(e,t)=>n({type:`SET_DATA`,payload:{[e]:t}})}),t.init(),p.current=t,()=>{t.destroy()}}},[e.plugins]);let h=(0,c.useCallback)(()=>{let r=!t.isOpen;n({type:`TOGGLE_OPEN`}),r?e.callbacks?.onOpen?.():e.callbacks?.onClose?.()},[t.isOpen,e.callbacks]);return(0,l.jsx)(f.Provider,{value:{state:t,dispatch:n,props:e},children:(0,l.jsxs)(`div`,{style:{...i.root,...a},className:e.className,children:[(0,l.jsx)(Q,{styles:i,position:o,zIndex:e.zIndex,hidden:!t.isOpen}),s&&(0,l.jsx)(k,{onClick:h,isOpen:t.isOpen,position:o,styles:i,icon:e.launcherIcon,closeIcon:e.closeIcon,zIndex:e.zIndex})]})})};function he(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 ge(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 _e(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(){}}}exports.AttachmentIcon=w,exports.Branding=q,exports.ChatBot=me,exports.ChatBubbleIcon=b,exports.ChatContext=f,exports.ChatHeader=ee,exports.ChatInput=K,exports.ChatWindow=Q,exports.CheckboxField=N,exports.CloseIcon=x,exports.DynamicForm=F,exports.EmojiIcon=C,exports.EmojiPicker=H,exports.FileIcon=T,exports.FilePreviewList=W,exports.FileUploadButton=U,exports.FileUploadField=P,exports.FlowEngine=J,exports.ImageIcon=E,exports.Launcher=k,exports.LoginScreen=I,exports.MessageBubble=L,exports.MessageList=B,exports.MinimizeIcon=S,exports.PluginManager=de,exports.QuickReplies=R,exports.RadioField=M,exports.RemoveIcon=D,exports.RestartIcon=O,exports.SelectField=j,exports.SendIcon=y,exports.TextField=A,exports.TypingIndicator=z,exports.WelcomeScreen=te,exports.analyticsPlugin=he,exports.buildCSSVariables=_,exports.buildStyles=v,exports.persistencePlugin=_e,exports.resolveTheme=g,exports.useChat=Z,exports.useChatContext=p,exports.webhookPlugin=ge;
|
|
47
46
|
//# sourceMappingURL=index.cjs.map
|