@enjoys/react-chatbot-plugin 1.0.0 โ 1.1.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 +541 -6
- package/dist/index.cjs +45 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +372 -64
- package/dist/index.mjs +2076 -646
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,47 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var G=Object.create,w=Object.defineProperty,$=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyNames,Q=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,K=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(var l=H(t),o=0,c=l.length,s;o<c;o++)s=l[o],!Y.call(e,s)&&s!==r&&w(e,s,{get:(g=>t[g]).bind(null,s),enumerable:!(a=$(t,s))||a.enumerable});return e},U=(e,t,r)=>(r=e!=null?G(Q(e)):{},K(t||!e||!e.__esModule?w(r,"default",{value:e,enumerable:!0}):r,e));let x=require("react");x=U(x);let n=require("react/jsx-runtime");function V(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":return{...e,messages:e.messages.map(r=>r.quickReplies?{...r,quickReplies:void 0}:r)};default:return e}}var J=e=>({isOpen:e.defaultOpen??!1,messages:e.initialMessages??[],isTyping:!1,showWelcome:!!e.welcomeScreen,currentStepId:null,collectedData:{},isLoggedIn:!e.loginForm}),y=(0,x.createContext)(null);function S(){const e=(0,x.useContext)(y);if(!e)throw new Error("useChatContext must be used within ChatProvider");return e}var X={primaryColor:"#0066FF",headerBg:"#0066FF",headerText:"#FFFFFF",bubbleBg:"#F1F1F1",bubbleText:"#333333",userBubbleBg:"#0066FF",userBubbleText:"#FFFFFF",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",borderRadius:"12px",windowWidth:"380px",windowHeight:"550px"};function k(e){return{...X,...e}}function Z(e,t){return{root:{fontFamily:e.fontFamily,fontSize:e.fontSize,lineHeight:"1.5"},launcher:{position:"fixed",width:"60px",height:"60px",borderRadius:"50%",backgroundColor:e.primaryColor,color:"#fff",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",transition:"transform 0.2s ease",zIndex:9998,...t?.launcher},window:{position:"fixed",width:e.windowWidth,height:e.windowHeight,maxHeight:"80vh",borderRadius:e.borderRadius,overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.15)",backgroundColor:"#FFFFFF",zIndex:9999,...t?.window},header:{backgroundColor:e.headerBg,color:e.headerText,padding:"16px 20px",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px",flexShrink:0,...t?.header},messageList:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"8px",...t?.messageList},inputArea:{padding:"12px 16px",borderTop:"1px solid #E8E8E8",display:"flex",gap:"8px",alignItems:"flex-end",flexShrink:0,...t?.inputArea},botBubble:{backgroundColor:e.bubbleBg,color:e.bubbleText,padding:"10px 14px",borderRadius:"16px 16px 16px 4px",maxWidth:"80%",alignSelf:"flex-start",wordBreak:"break-word",whiteSpace:"pre-wrap"},userBubble:{backgroundColor:e.userBubbleBg,color:e.userBubbleText,padding:"10px 14px",borderRadius:"16px 16px 4px 16px",maxWidth:"80%",alignSelf:"flex-end",wordBreak:"break-word",whiteSpace:"pre-wrap"}}}var C=({onClick:e,isOpen:t,position:r,styles:a,icon:l,closeIcon:o,zIndex:c})=>{const s=r==="bottom-left"?{bottom:"20px",left:"20px"}:{bottom:"20px",right:"20px"};return(0,n.jsx)("button",{onClick:e,"aria-label":t?"Close chat":"Open chat",style:{...a.launcher,...s,...c!=null?{zIndex:c}:{},transform:t?"scale(0.9)":"scale(1)"},children:t?o??(0,n.jsx)(te,{}):l??(0,n.jsx)(ee,{})})},ee=()=>(0,n.jsx)("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.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"})}),te=()=>(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),F=({config:e,styles:t,onClose:r})=>(0,n.jsxs)("div",{style:t.header,children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"10px",flex:1},children:[e.avatar&&(0,n.jsx)("img",{src:e.avatar,alt:"",style:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover"}}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontWeight:600,fontSize:"15px"},children:e.title??"Chat with us"}),e.subtitle&&(0,n.jsx)("div",{style:{fontSize:"12px",opacity:.85},children:e.subtitle})]})]}),e.showClose!==!1&&(0,n.jsx)("button",{onClick:r,"aria-label":"Close chat",style:{background:"none",border:"none",color:"inherit",cursor:"pointer",padding:"4px",display:"flex",alignItems:"center"},children:(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),D=({content:e,onDismiss:t,primaryColor:r})=>(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:[(0,n.jsx)("div",{style:{flex:1,padding:"20px",overflow:"auto"},children:e}),(0,n.jsx)("div",{style:{padding:"12px 16px",borderTop:"1px solid #E8E8E8",flexShrink:0},children:(0,n.jsx)("button",{onClick:t,style:{width:"100%",padding:"12px",backgroundColor:r,color:"#fff",border:"none",borderRadius:"8px",fontSize:"14px",fontWeight:600,cursor:"pointer"},children:"Start Chat"})})]}),T=({field:e,value:t,onChange:r,error:a})=>{const l=e.type==="textarea",o=e.type==="textarea"?void 0:e.type,c={width:"100%",padding:"8px 12px",border:`1px solid ${a?"#E53E3E":"#D1D5DB"}`,borderRadius:"8px",fontSize:"13px",fontFamily:"inherit",outline:"none",boxSizing:"border-box",transition:"border-color 0.15s ease"};return(0,n.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,n.jsxs)("label",{style:{display:"block",marginBottom:"4px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,n.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),l?(0,n.jsx)("textarea",{value:t,onChange:s=>r(s.target.value),placeholder:e.placeholder,required:e.required,rows:3,style:{...c,resize:"vertical"},minLength:e.validation?.minLength,maxLength:e.validation?.maxLength}):(0,n.jsx)("input",{type:o,value:t,onChange:s=>r(s.target.value),placeholder:e.placeholder,required:e.required,style:c,min:e.validation?.min,max:e.validation?.max,minLength:e.validation?.minLength,maxLength:e.validation?.maxLength,pattern:e.validation?.pattern}),a&&(0,n.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},I=({field:e,value:t,onChange:r,error:a})=>{const l=e.type==="multiselect"||e.multiple,o=s=>{r(l?Array.from(s.target.selectedOptions,g=>g.value):s.target.value)},c=l?Array.isArray(t)?t:[t].filter(Boolean):typeof t=="string"?t:"";return(0,n.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,n.jsxs)("label",{style:{display:"block",marginBottom:"4px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,n.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),(0,n.jsxs)("select",{value:c,onChange:o,multiple:l,required:e.required,style:{width:"100%",padding:"8px 12px",border:`1px solid ${a?"#E53E3E":"#D1D5DB"}`,borderRadius:"8px",fontSize:"13px",fontFamily:"inherit",outline:"none",backgroundColor:"#fff",boxSizing:"border-box",...l?{minHeight:"80px"}:{}},children:[!l&&(0,n.jsx)("option",{value:"",children:"Select..."}),e.options?.map(s=>(0,n.jsx)("option",{value:s.value,children:s.label},s.value))]}),l&&(0,n.jsx)("div",{style:{fontSize:"11px",color:"#888",marginTop:"2px"},children:"Hold Ctrl/Cmd to select multiple"}),a&&(0,n.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},R=({field:e,value:t,onChange:r,error:a})=>(0,n.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,n.jsxs)("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,n.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.options?.map(l=>(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",fontSize:"13px"},children:[(0,n.jsx)("input",{type:"radio",name:e.name,value:l.value,checked:t===l.value,onChange:()=>r(l.value),style:{margin:0}}),l.label]},l.value))}),a&&(0,n.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]}),_=({field:e,value:t,onChange:r,error:a})=>{const l=o=>{t.includes(o)?r(t.filter(c=>c!==o)):r([...t,o])};return(0,n.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,n.jsxs)("label",{style:{display:"block",marginBottom:"6px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,n.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.options?.map(o=>(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer",fontSize:"13px"},children:[(0,n.jsx)("input",{type:"checkbox",checked:t.includes(o.value),onChange:()=>l(o.value),style:{margin:0}}),o.label]},o.value))}),a&&(0,n.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},L=({field:e,value:t,onChange:r,error:a,primaryColor:l})=>{const o=(0,x.useRef)(null),c=t?Array.from(t).map(s=>s.name).join(", "):"";return(0,n.jsxs)("div",{style:{marginBottom:"12px"},children:[e.label&&(0,n.jsxs)("label",{style:{display:"block",marginBottom:"4px",fontSize:"13px",fontWeight:500},children:[e.label,e.required&&(0,n.jsx)("span",{style:{color:"#E53E3E",marginLeft:"2px"},children:"*"})]}),(0,n.jsx)("input",{ref:o,type:"file",accept:e.accept,multiple:e.multiple,onChange:s=>r(s.target.files),style:{display:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>o.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:c||e.placeholder||"Choose file(s)..."}),c&&(0,n.jsxs)("div",{style:{fontSize:"12px",color:l,marginTop:"4px"},children:[Array.from(t).length," file(s) selected"]}),a&&(0,n.jsx)("div",{style:{color:"#E53E3E",fontSize:"12px",marginTop:"2px"},children:a})]})},v=({config:e,onSubmit:t,primaryColor:r})=>{const[a,l]=(0,x.useState)(()=>{const i={};for(const d of e.fields)d.defaultValue!==void 0?i[d.name]=d.defaultValue:d.type==="checkbox"||d.type==="multiselect"?i[d.name]=[]:d.type==="file"?i[d.name]=null:i[d.name]="";return i}),[o,c]=(0,x.useState)({}),[s,g]=(0,x.useState)(!1),u=(0,x.useCallback)((i,d)=>{l(b=>({...b,[i]:d})),c(b=>{const j={...b};return delete j[i],j})},[]),p=()=>{const i={};for(const d of e.fields){const b=a[d.name];if(d.required&&(b===""||b===null||b===void 0||Array.isArray(b)&&b.length===0)){i[d.name]=d.validation?.message??`${d.label||d.name} is required`;continue}d.validation?.pattern&&typeof b=="string"&&b&&(new RegExp(d.validation.pattern).test(b)||(i[d.name]=d.validation.message??"Invalid format"))}return c(i),Object.keys(i).length===0},h=i=>{i.preventDefault(),p()&&(g(!0),t(a))};return s?(0,n.jsx)("div",{style:{padding:"12px",backgroundColor:"#F0FFF4",borderRadius:"8px",fontSize:"13px",color:"#276749",textAlign:"center"},children:"Submitted successfully"}):(0,n.jsxs)("form",{onSubmit:h,style:{backgroundColor:"#FAFAFA",borderRadius:"10px",padding:"16px",border:"1px solid #E8E8E8"},children:[e.title&&(0,n.jsx)("div",{style:{fontWeight:600,fontSize:"14px",marginBottom:"4px"},children:e.title}),e.description&&(0,n.jsx)("div",{style:{fontSize:"12px",color:"#888",marginBottom:"12px"},children:e.description}),e.fields.map(i=>(0,n.jsx)(ne,{field:i,value:a[i.name],onChange:d=>u(i.name,d),error:o[i.name],primaryColor:r},i.name)),(0,n.jsx)("button",{type:"submit",style:{width:"100%",padding:"10px",backgroundColor:r,color:"#fff",border:"none",borderRadius:"8px",fontSize:"14px",fontWeight:600,cursor:"pointer",marginTop:"4px"},children:e.submitLabel??"Submit"})]})},ne=({field:e,value:t,onChange:r,error:a,primaryColor:l})=>{switch(e.type){case"text":case"email":case"password":case"number":case"tel":case"url":case"textarea":case"date":case"time":return(0,n.jsx)(T,{field:e,value:String(t??""),onChange:r,error:a});case"select":case"multiselect":return(0,n.jsx)(I,{field:e,value:t,onChange:r,error:a});case"radio":return(0,n.jsx)(R,{field:e,value:String(t??""),onChange:r,error:a});case"checkbox":return(0,n.jsx)(_,{field:e,value:t??[],onChange:r,error:a});case"file":return(0,n.jsx)(L,{field:e,value:t,onChange:r,error:a,primaryColor:l});case"hidden":return(0,n.jsx)("input",{type:"hidden",name:e.name,value:String(t??"")});default:return null}},O=({config:e,onLogin:t,primaryColor:r})=>(0,n.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",justifyContent:"center",padding:"20px",overflow:"auto"},children:(0,n.jsx)(v,{config:e,onSubmit:t,primaryColor:r})}),B=({message:e,styles:t})=>{const r=e.sender==="bot"?t.botBubble:t.userBubble;return!e.text&&!e.attachment?null:(0,n.jsxs)("div",{style:r,children:[e.text&&(0,n.jsx)("span",{children:e.text}),e.attachment&&(0,n.jsx)("div",{style:{marginTop:e.text?"6px":0},children:(0,n.jsxs)("a",{href:e.attachment.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline",fontSize:"13px"},children:["๐ ",e.attachment.name]})})]})},z=({replies:e,onSelect:t,primaryColor:r})=>(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",alignSelf:"flex-start",maxWidth:"90%"},children:e.map(a=>(0,n.jsx)("button",{onClick:()=>t(a.value,a.label),style:{padding:"6px 14px",borderRadius:"18px",border:`1px solid ${r}`,backgroundColor:"transparent",color:r,cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.15s ease"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor=r,l.currentTarget.style.color="#fff"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent",l.currentTarget.style.color=r},children:a.label},a.value))}),A=({color:e})=>{const t={width:"8px",height:"8px",borderRadius:"50%",backgroundColor:e,opacity:.4,animation:"chatbot-typing-bounce 1.4s infinite ease-in-out"};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("style",{children:`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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(Pe).map(([m,f])=>`**${m}** โ ${f}`).join(`
|
|
3
|
+
`)}`),!0;case"/cancel":case"/back":return g(),!0;case"/restart":return h(),!0;default:return p(`Unknown command: ${b}. Type /help for available commands.`),!0}};const j=(0,d.useCallback)(c=>{const b=a.current,m=s.current.currentStepId;if(!b||!m)return;const f=b.getStep(m);if(!f)return;c?.data&&(b.mergeData(c.data),t({type:"SET_DATA",payload:c.data})),c?.message&&t({type:"ADD_MESSAGE",payload:{id:E(),sender:"bot",text:c.message,timestamp:Date.now()}});const u=c?.next??f.next;u?x(u):(i.current.callbacks?.onFlowEnd?.(b.getData()),t({type:"SET_STEP",payload:null}))},[t,x]),F=(0,d.useCallback)(c=>{if(k.current(c))return;const b={id:E(),sender:"user",text:c,timestamp:Date.now()};t({type:"ADD_MESSAGE",payload:b}),i.current.callbacks?.onMessageSend?.(b),i.current.callbacks?.onSubmit?.({message:c});const m=s.current.currentStepId;if(a.current&&m){const f=a.current.getStep(m);if(f){if(f.asyncAction||f.component){l("Please wait, I'm still processing. You can type /back to go back.");return}if(a.current.stepExpectsQuickReply(f)){const u=a.current.matchQuickReply(f,c);if(u){t({type:"CLEAR_QUICK_REPLIES"}),a.current.setData(f.id,u.value);const S=a.current.resolveNext(f,u.value);S?x(S):(i.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:"SET_STEP",payload:null}))}else l("I didn't quite get that. Please choose one of the options below:",{quickReplies:f.quickReplies})}else if(a.current.stepExpectsForm(f))l("Please fill out the form above to continue.");else{a.current.setData(f.id,c);const u=a.current.resolveNext(f,c);u?x(u):(l("Thanks for your message! Our team will get back to you soon. ๐"),i.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:"SET_STEP",payload:null}))}}}},[t,l,x]),C=(0,d.useCallback)(()=>{const c=a.current;!c||o.current||(o.current=!0,x(c.getStartStepId()))},[x]);return(0,d.useEffect)(()=>{n.flow&&!e.showWelcome&&e.isLoggedIn&&!o.current&&C()},[n.flow,e.showWelcome,e.isLoggedIn,C]),{state:e,sendMessage:F,addBotMessage:l,handleQuickReply:(0,d.useCallback)((c,b)=>{t({type:"CLEAR_QUICK_REPLIES"}),t({type:"ADD_MESSAGE",payload:{id:E(),sender:"user",text:b,timestamp:Date.now()}}),i.current.callbacks?.onQuickReply?.(c,b);const m=s.current.currentStepId;if(a.current&&m){const f=a.current.getStep(m);if(f){a.current.setData(f.id,c);const u=a.current.resolveNext(f,c);u?x(u):(i.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:"SET_STEP",payload:null}))}}},[t,x]),handleFormSubmit:(0,d.useCallback)(async(c,b)=>{t({type:"SET_DATA",payload:b}),a.current&&a.current.mergeData(b);const m=Object.entries(b).filter(([,u])=>u!==void 0&&u!=="").map(([u,S])=>`${u}: ${String(S)}`).join(`
|
|
4
|
+
`);t({type:"ADD_MESSAGE",payload:{id:E(),sender:"user",text:m,formData:b,timestamp:Date.now()}}),await i.current.callbacks?.onFormSubmit?.(c,b);const f=s.current.currentStepId;if(a.current&&f){const u=a.current.getStep(f);if(u){const S=a.current.resolveNext(u);S?x(S):(i.current.callbacks?.onFlowEnd?.(a.current.getData()),t({type:"SET_STEP",payload:null}))}}},[t,x]),handleLogin:(0,d.useCallback)(async c=>{await i.current.callbacks?.onLogin?.(c),t({type:"SET_LOGGED_IN",payload:!0})},[t]),toggleChat:(0,d.useCallback)(()=>{const c=!s.current.isOpen;t({type:"TOGGLE_OPEN"}),c?i.current.callbacks?.onOpen?.():i.current.callbacks?.onClose?.()},[t]),dismissWelcome:(0,d.useCallback)(()=>{t({type:"DISMISS_WELCOME"})},[t]),startFlow:C,processFlowStep:x,goBack:g,restartSession:h,handleComponentComplete:j}}var me=({styles:e,position:t,zIndex:n,hidden:a})=>{const{props:o,dispatch:s}=M(),i=A(o.theme),l=i.mode==="dark",{state:p,sendMessage:y,handleQuickReply:v,handleFormSubmit:x,handleLogin:g,toggleChat:h,dismissWelcome:k,restartSession:j,handleComponentComplete:F}=he(),C=t==="bottom-left"?{bottom:"96px",left:"24px"}:{bottom:"96px",right:"24px"},c=(0,d.useCallback)((u,S)=>{if(S&&S.length>0){const D=S.map(w=>({name:w.name,url:URL.createObjectURL(w),type:w.type,size:w.size}));u?(s({type:"ADD_MESSAGE",payload:{id:E(),sender:"user",text:u,timestamp:Date.now(),attachments:D}}),y(u)):s({type:"ADD_MESSAGE",payload:{id:E(),sender:"user",timestamp:Date.now(),attachments:D}}),o.callbacks?.onFileUpload?.(S)}else u&&y(u)},[y,s,o.callbacks]),b=(0,d.useMemo)(()=>({currentStepId:p.currentStepId,isOpen:p.isOpen,messages:p.messages,collectedData:p.collectedData,toggleChat:h,restartSession:j,sendMessage:y}),[p.currentStepId,p.isOpen,p.messages,p.collectedData,h,j,y]),m=(0,r.jsx)(J,{config:o.header??{title:"Chat with us"},styles:e,onClose:h,onRestart:j,logo:o.branding?.logo,logoWidth:o.branding?.logoWidth}),f=(0,r.jsx)(xe,{onSend:c,placeholder:o.inputPlaceholder,primaryColor:i.primaryColor,isDark:l,enableEmoji:o.enableEmoji,fileUpload:o.fileUpload,onFileUpload:o.callbacks?.onFileUpload});return a?(0,r.jsx)("div",{style:{display:"none"}}):(0,r.jsxs)("div",{style:{...e.window,...C,...n!=null?{zIndex:n}:{}},children:[o.renderHeader?o.renderHeader(b,m):m,p.showWelcome&&o.welcomeScreen?(0,r.jsx)(X,{content:o.welcomeScreen,onDismiss:k,primaryColor:i.primaryColor}):!p.isLoggedIn&&o.loginForm?(0,r.jsx)(ae,{config:o.loginForm,onLogin:g,primaryColor:i.primaryColor}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(le,{messages:p.messages,isTyping:p.isTyping,styles:e,primaryColor:i.primaryColor,onQuickReply:v,onFormSubmit:x,components:o.components,onComponentComplete:F,collectedData:p.collectedData,currentStepId:p.currentStepId}),(0,r.jsx)("div",{style:e.inputArea,children:o.renderInput?o.renderInput(b,f):f}),o.branding&&(0,r.jsx)(ge,{config:o.branding,primaryColor:i.primaryColor})]})]})},fe=class{constructor(){this.plugins=[],this.context=null,this.eventHandlers=new Map}register(e){this.plugins=[...e]}setContext(e){this.context={...e,on:(t,n)=>this.on(t,n),emit:(t,...n)=>this.emit(t,...n)}}on(e,t){this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set),this.eventHandlers.get(e).add(t)}emit(e,...t){const n=this.eventHandlers.get(e);n&&n.forEach(a=>a(...t))}async init(){if(this.context)for(const e of this.plugins)try{await e.onInit?.(this.context)}catch(t){console.error(`[Plugin:${e.name}] onInit error:`,t)}}async onMessage(e){if(!this.context)return e;let t=e;for(const n of this.plugins)try{const a=await n.onMessage?.(t,this.context);a&&typeof a=="object"&&"id"in a&&(t=a)}catch(a){console.error(`[Plugin:${n.name}] onMessage error:`,a)}return this.dispatchEvent({type:"message",payload:t,timestamp:Date.now()}),t}async onSubmit(e){if(this.context){for(const t of this.plugins)try{await t.onSubmit?.(e,this.context)}catch(n){console.error(`[Plugin:${t.name}] onSubmit error:`,n)}this.dispatchEvent({type:"submit",payload:e,timestamp:Date.now()})}}async destroy(){if(this.context){for(const e of this.plugins)try{await e.onDestroy?.(this.context)}catch(t){console.error(`[Plugin:${e.name}] onDestroy error:`,t)}this.eventHandlers.clear(),this.plugins=[]}}dispatchEvent(e){if(this.context)for(const t of this.plugins)try{t.onEvent?.(e,this.context)}catch(n){console.error(`[Plugin:${t.name}] onEvent error:`,n)}}},We=`
|
|
5
|
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
|
6
|
+
|
|
7
|
+
@keyframes cb-window-enter {
|
|
8
|
+
0% { opacity: 0; transform: translateY(16px) scale(0.96); }
|
|
9
|
+
100% { opacity: 1; transform: translateY(0) scale(1); }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@keyframes cb-launcher-pulse {
|
|
13
|
+
0%, 100% { box-shadow: 0 6px 24px rgba(108, 92, 231, 0.4), 0 2px 8px rgba(0,0,0,0.1); }
|
|
14
|
+
50% { box-shadow: 0 8px 32px rgba(108, 92, 231, 0.55), 0 4px 12px rgba(0,0,0,0.15); }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@keyframes cb-fade-in {
|
|
18
|
+
0% { opacity: 0; transform: translateY(6px); }
|
|
19
|
+
100% { opacity: 1; transform: translateY(0); }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@keyframes cb-typing-bounce {
|
|
23
|
+
0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
|
|
24
|
+
40% { transform: scale(1); opacity: 1; }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@keyframes cb-slide-up {
|
|
28
|
+
0% { opacity: 0; transform: translateY(10px); }
|
|
29
|
+
100% { opacity: 1; transform: translateY(0); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.cb-scrollbar::-webkit-scrollbar {
|
|
33
|
+
width: 5px;
|
|
34
|
+
}
|
|
35
|
+
.cb-scrollbar::-webkit-scrollbar-track {
|
|
36
|
+
background: transparent;
|
|
37
|
+
}
|
|
38
|
+
.cb-scrollbar::-webkit-scrollbar-thumb {
|
|
39
|
+
background: rgba(108, 92, 231, 0.2);
|
|
40
|
+
border-radius: 10px;
|
|
41
|
+
}
|
|
42
|
+
.cb-scrollbar::-webkit-scrollbar-thumb:hover {
|
|
43
|
+
background: rgba(108, 92, 231, 0.35);
|
|
44
|
+
}
|
|
45
|
+
`,T=!1;function Oe(){if(T||typeof document>"u")return;if(document.querySelector("style[data-chatbot-styles]")){T=!0;return}const e=document.createElement("style");e.setAttribute("data-chatbot-styles",""),e.textContent=We,document.head.appendChild(e),T=!0}var $e=e=>{const[t,n]=(0,d.useReducer)(Ce,e,Fe),a=A(e.theme),o=$(a,e.style),s=O(a),i=e.position??"bottom-right",l=e.showLauncher!==!1,p=(0,d.useRef)(null),y=(0,d.useRef)(t);y.current=t,(0,d.useEffect)(()=>{Oe()},[]),(0,d.useEffect)(()=>{if(e.plugins&&e.plugins.length>0){const x=new fe;return x.register(e.plugins),x.setContext({sendMessage:g=>{n({type:"ADD_MESSAGE",payload:{id:E(),sender:"user",text:g,timestamp:Date.now()}})},addBotMessage:g=>{n({type:"ADD_MESSAGE",payload:{id:E(),sender:"bot",text:g,timestamp:Date.now()}})},getMessages:()=>y.current.messages,getData:()=>y.current.collectedData,setData:(g,h)=>n({type:"SET_DATA",payload:{[g]:h}})}),x.init(),p.current=x,()=>{x.destroy()}}},[e.plugins]);const v=(0,d.useCallback)(()=>{const x=!t.isOpen;n({type:"TOGGLE_OPEN"}),x?e.callbacks?.onOpen?.():e.callbacks?.onClose?.()},[t.isOpen,e.callbacks]);return(0,r.jsx)(R.Provider,{value:{state:t,dispatch:n,props:e},children:(0,r.jsxs)("div",{style:{...o.root,...s},className:e.className,children:[(0,r.jsx)(me,{styles:o,position:i,zIndex:e.zIndex,hidden:!t.isOpen}),l&&(0,r.jsx)(V,{onClick:v,isOpen:t.isOpen,position:i,styles:o,icon:e.launcherIcon,closeIcon:e.closeIcon,zIndex:e.zIndex})]})})};function Ge(e){let t=0,n=0;return{name:"analytics",onInit(a){t=0,n=0,e?.onTrack?.("chatbot:init")},onMessage(a,o){t++,e?.onTrack?.("chatbot:message",{sender:a.sender,messageCount:t})},onSubmit(a,o){n++,e?.onTrack?.("chatbot:submit",{formSubmissions:n,fields:Object.keys(a)})},onDestroy(){e?.onTrack?.("chatbot:destroy",{totalMessages:t,totalFormSubmissions:n})}}}function He(e){const t=e.events??["message","submit"],n=async(a,o)=>{try{await fetch(e.url,{method:"POST",headers:{"Content-Type":"application/json",...e.headers},body:JSON.stringify({type:a,payload:o,timestamp:Date.now()})})}catch(s){console.error(`[webhook] Failed to send ${a}:`,s)}};return{name:"webhook",async onInit(){t.includes("init")&&await n("init",{})},async onMessage(a){t.includes("message")&&await n("message",a)},async onSubmit(a){t.includes("submit")&&await n("submit",a)},async onDestroy(){t.includes("destroy")&&await n("destroy",{})}}}function qe(e){const t=e?.storageKey??"chatbot_history",n=e?.storage==="session"?sessionStorage:localStorage;return{name:"persistence",onInit(a){try{const o=n.getItem(t);if(o){const s=JSON.parse(o);Array.isArray(s)&&s.forEach(i=>{i.sender==="bot"&&a.addBotMessage(i.text)})}}catch{}},onMessage(a,o){try{const s=o.getMessages();n.setItem(t,JSON.stringify(s.slice(-50)))}catch{}},onDestroy(){}}}exports.AttachmentIcon=U;exports.Branding=ge;exports.ChatBot=$e;exports.ChatBubbleIcon=H;exports.ChatContext=R;exports.ChatHeader=J;exports.ChatInput=xe;exports.ChatWindow=me;exports.CheckboxField=re;exports.CloseIcon=B;exports.DynamicForm=_;exports.EmojiIcon=N;exports.EmojiPicker=ce;exports.FileIcon=L;exports.FilePreviewList=pe;exports.FileUploadButton=de;exports.FileUploadField=ne;exports.FlowEngine=be;exports.ImageIcon=Y;exports.Launcher=V;exports.LoginScreen=ae;exports.MessageBubble=oe;exports.MessageList=le;exports.MinimizeIcon=q;exports.PluginManager=fe;exports.QuickReplies=se;exports.RadioField=te;exports.RemoveIcon=Q;exports.RestartIcon=K;exports.SelectField=ee;exports.SendIcon=G;exports.TextField=Z;exports.TypingIndicator=ie;exports.WelcomeScreen=X;exports.analyticsPlugin=Ge;exports.buildCSSVariables=O;exports.buildStyles=$;exports.persistencePlugin=qe;exports.resolveTheme=A;exports.useChat=he;exports.useChatContext=M;exports.webhookPlugin=He;
|
|
8
46
|
|
|
9
47
|
//# sourceMappingURL=index.cjs.map
|