UNPKG

react-chatbot-koodums

Version:

A customizable chatbot component for React applications

1 lines 117 kB
"use strict";var e=require("react"),t=require("@mui/material"),o=require("@mui/icons-material/Lightbulb"),n=require("@mui/material/Paper"),i=require("@mui/material/InputBase"),a=require("@mui/material/IconButton"),r=require("@mui/icons-material/Send"),s=require("react-device-detect"),l=require("react/jsx-runtime"),c=require("uuid"),d=require("use-sound"),u=require("react-helmet"),p=require("@mui/icons-material/AddCircle"),h=require("@mui/system"),g=require("react-div-100vh"),m=require("@mui/icons-material"),x=require("swiper/react"),y=require("swiper");require("swiper/css"),require("swiper/css/pagination"),require("swiper/css/navigation");var f=require("@vis.gl/react-google-maps");require("react-dom/client");var b=require("formik"),v=require("yup");require("@mui/icons-material/Close");var S=require("react-calendly"),w=require("react-youtube");function j(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(o){if("default"!==o){var n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:function(){return e[o]}})}}),t.default=e,Object.freeze(t)}var C=j(v);function k(e,t,o){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var n=o.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function I(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,n)}return o}function F(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?I(Object(o),!0).forEach(function(t){k(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):I(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}function R(o){let{onSendMessage:c,sending:d,inputRef:u,helperText:p,backgroundColor:h,hasQuickReply:g}=o;const m=()=>{const e=u.current.value;u.current.value="",""===e||d||c(e)};return e.useEffect(()=>{var e;s.isMobile||d||(null===(e=u.current)||void 0===e||e.focus())},[d]),l.jsx(t.Stack,{direction:"row",justifyContent:"center",sx:{background:h||"#FFFFFF",width:"100%",bottom:"0px",paddingTop:"5px",paddingBottom:"5px"},children:l.jsxs(n,{elevation:0,component:"form",sx:{p:"2px 4px",display:"flex",alignItems:"center",width:"calc(100% - ".concat(g?25:48,"px)"),minHeight:"48px",maxWidth:800,borderRadius:"20px",boxShadow:"0px 4px 4px rgba(0, 0, 0, 0.1)"},children:[l.jsx(i,{disabled:d,inputRef:u,sx:{ml:1,flex:1,fontFamily:"Google Sans",fontWeight:"300",fontSize:"14px"},placeholder:p,inputProps:{"aria-label":p},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),m())}}),l.jsx(a,{disabled:d,onClick:m,color:"primary",sx:{p:"10px"},"aria-label":"send",children:l.jsx(r,{sx:{color:d?"#DADCE0":"#292929"}})})]})})}const T=(e,t)=>{t(e),document.cookie="chatUserEmail=".concat(e.email,"; SameSite=None; Secure"),document.cookie="chatUserName=".concat(e.name,"; SameSite=None; Secure")},A=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return{id:c.v4(),type:"bot",author:"0",content:e,isTesting:t}},O=e=>new Promise(t=>setTimeout(t,e));function B(e){const t=e.match(/(\w+)\(([\s\S]*)\)/);if(!t)return console.log("Invalid ACT format"),[null,null];{const e=t[1];let o=t[2].replace(/\s+$/,"").replace(/\)+$/,"");if(!o)return[e,null];{let t="";try{if(o.startsWith("{")&&o.endsWith("}")||o.startsWith("[")&&o.endsWith("]")){const t=function(e){const t=[];let o=0,n="";for(let i of e)"{"!==i&&"["!==i||o++,"}"!==i&&"]"!==i||o--,","===i&&0===o?(t.push(n.trim()),n=""):n+=i;n&&t.push(n.trim());return t}(o);if(1===t.length){return[e,JSON.parse(t[0])]}const n=t.map(e=>JSON.parse(e.trim()));return[e,Object.assign({},...n)]}{const n=o.replace(/(\w+):/g,'"$1":').replace(/,\s*$/,"");t="{".concat(n,"}");return[e,JSON.parse(t)]}}catch(e){return console.error("JSON parse error:",e),[null,null]}}}}function P(e,t){const o=e.match(/^SAY: (.*?)\s*ACT: ([\s\S]*)$/m);if(o){const[e,[t,n]]=[o[1],B(o[2])];return{sender:"agent",content:{say:e,act:{function_name:t,params:n}}}}return function(e,t,o){return{sender:e,content:{say:t},element:o}}("agent",e.replace("SAY: ",""),"")}const E=localStorage.getItem("apiKey");async function N(e,t){e=function(e){return function(e){if("string"!=typeof e)return"";let t="";const o=e.split(/(\b(?:https?:\/\/|www\.)\S+\b|\b\w+\.\w+\b)/);for(let e=0;e<o.length;e++){const n=o[e].trim();""!==n&&(/^(https?:\/\/|www\.|[a-zA-Z0-9]+\.[a-zA-Z0-9]+)/.test(n)||(t+=n+" "))}return t.trim()}(e.replace(/<[^>]*>/g,"").replace(/\*/g,"").replace(/(?:[\u2600-\u27BF\u2B50\u2B55]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F\uDE80-\uDFFF]|\uD83E[\uDC00-\uDEFF])/g,""))}(e);try{if(!E)throw new Error("API key not found. Please initialize the chatbot.");const o=await fetch("/api/v1/tts",{method:"POST",headers:{"Content-Type":"application/json","x-api-key":E},body:JSON.stringify({text:e})});if(!o.ok)throw new Error("HTTP error! status: ".concat(o.status));const n=await o.blob(),i=URL.createObjectURL(n);t.current.src=i,t.current.play()}catch(e){console.error("Error fetching TTS:",e)}}async function _(e){let{context:t,params:o}=e,{urlPrefix:n,apiVersion:i,streamResults:a,setDisplayMessageList:r,setSending:s,language:l,playSoundOnResponse:d,playSound:u,playSound2:p,playSound3:h,playSound4:g,speakResponse:m,audioRef:x,globalData:y,printResponse:f,printGenericResponse:b}=t;console.log("🚀 ~ sendMessage ~ apiVersion:",i),a=!1;const{agentId:v,phrase:S,event:w,session:j,chatUserEmail:C,chatUserName:k,test:I,history:R,guestInfo:T}=o;try{y.debug&&console.log("#######Phrase = "+S);const e=n+"/api"+i+"/sendMessage/";if(!E)throw new Error("API key not found. Please initialize the chatbot.");y.debug&&console.log(e);const t=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":E},body:JSON.stringify({agentId:v,msg:S,session:j,chatUserEmail:C&&C.length>0?C:"",chatUserName:k&&k.length>0?k:"",stream:a,history:R?R.length>20?R.slice(-20):R:[],guestInfo:T||{}})});if(!t.ok)throw new Error("No Data Available");let o={content:""};if(a){const e=t.body.getReader(),n=new TextDecoder;let i=!1,a="";for(;!i;){const{value:t,done:s}=await e.read();if(t){var A,B;if(a=n.decode(t,{stream:!0}),","==a[(null===(A=a)||void 0===A?void 0:A.length)-1])a=a.slice(0,(null===(B=a)||void 0===B?void 0:B.length)-1);const e=JSON.parse("[".concat(a,"]"));for(let t of e)if(t&&""!=t){const e=t;!1!==(null==e?void 0:e.status)&&(o=F(F({},e),{},{content:(o.content?o.content:"")+(null!=e&&e.content?null==e?void 0:e.content:"")}),y.debug&&console.log("🚀 ~ sendMessage ~ resultdata.data:",o),r(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?F(F({},t),{},{content:(t.content?t.content:"")+(null!=e&&e.content?null==e?void 0:e.content:""),usage:e.usage}):t):[...t,e]))}}i=s}if(I)return console.log("IN HERE TEST = true..returning result"),o}else{const e=await t.json();if(console.log("going down here instead :: data ::",e),y.debug&&console.log("#######Data = "+JSON.stringify(e)),d&&("beep1"===d&&u(),"beep2"===d&&p(),"beep3"===d&&h(),"beep4"===d&&g()),m){let t=e.content;if("string"==typeof t&&t.startsWith("SAY:")){t=P(t).content.say}"string"==typeof t&&(t=t.replace(/<[^>]*>/g,""),await N(t,x))}if("string"==typeof e.content&&e.content.indexOf("SAY:")>=0){var _,z,M,D,L,U,q,W,V,H,G,Y;console.log("IN HERE SAY ::",JSON.stringify(e.content));let t=P(e.content);if(console.log("IN HERE SAY :: sender ::",JSON.stringify(t)),t.content.act&&t.content.act.params&&t.content.say.indexOf(" in ")>=0){var J=t.content.say;t.content.act.params.region=J.substring(J.indexOf(" in ")+4)}if(t.content.act&&"display_widget"===(null===(_=t.content.act)||void 0===_?void 0:_.function_name))t.content.say.includes("{speak}")&&(t.content.say=t.content.say.replace("{speak}",""),N(t.content.say,x)),f(t.content.say,l,"bot",!1),b("richContent",t.content.act.params,l);else if(t.content.act&&"display_image"===(null===(z=t.content.act)||void 0===z?void 0:z.function_name))f(t.content.say,l,"bot",!1),b("richContent",{type:"image",height:"200px",rawUrl:t.content.act.params.rawUrl},l);else if(t.content.act&&"display_email"===(null===(M=t.content.act)||void 0===M?void 0:M.function_name)){var Q;f(t.content.say,l,"bot",!1),console.log("WHAT IS THIS - display_email ::",t.content.act.params),b("richContent",{type:"email",contactValue:t.content.act.params.contactValue,buttonText:t.content.act.params.buttonText,message:null!==(Q=t.content.act.params.message)&&void 0!==Q?Q:""},l)}else if(t.content.act&&"display_call"===(null===(D=t.content.act)||void 0===D?void 0:D.function_name))f(t.content.say,l,"bot",!1),console.log("WHAT IS THIS - display_email ::",t.content.act.params),b("richContent",{type:"call",contactValue:t.content.act.params.contactValue,buttonText:t.content.act.params.buttonText},l);else if(t.content.act&&"display_whatsApp"===(null===(L=t.content.act)||void 0===L?void 0:L.function_name)){var K;f(t.content.say,l,"bot",!1),console.log("WHAT IS THIS - display_whatsApp ::",t.content.act.params),b("richContent",{type:"whatsApp",contactValue:t.content.act.params.contactValue,buttonText:t.content.act.params.buttonText,message:null!==(K=t.content.act.params.message)&&void 0!==K?K:""},l)}else if(t.content.act&&"display_table"===(null===(U=t.content.act)||void 0===U?void 0:U.function_name))f(t.content.say,l,"bot",!1),b("richContent",{type:"table",title:t.content.act.params.title,headers:t.content.act.params.headers,rows:t.content.act.params.rows},l);else if(t.content.act&&"display_cities"===(null===(q=t.content.act)||void 0===q?void 0:q.function_name)){f(t.content.say,l,"bot",!1);for(let e=0;e<t.content.act.params.cities.length;e++)await O(2e3),b("citycard",{region:t.content.act.params.region,name:t.content.act.params.cities[e]},l)}else if(t.content.act&&"display_places"===(null===(W=t.content.act)||void 0===W?void 0:W.function_name)){f(t.content.say,l,"bot",!1);for(let e=0;e<t.content.act.params.places.length;e++)await O(2e3),b("placecard",{city:t.content.act.params.city,name:t.content.act.params.places[e]},l)}else if(t.content.act&&"display_hotels"===(null===(V=t.content.act)||void 0===V?void 0:V.function_name)){if(f(t.content.say,l,"bot",!1),t.content.act.params.hotels)for(let e=0;e<t.content.act.params.hotels.length;e++)await O(2e3),b("hotelcard",{name:t.content.act.params.hotels[e].name,hotelObject:t.content.act.params.hotels[e],city:t.content.act.params.city,brand:t.content.act.params.brand},l);if(t.content.act.params.cities)for(let e=0;e<t.content.act.params.cities.length;e++)await O(2e3),b("hotelcard",{name:t.content.act.params.hotels[e].name,hotelObject:t.content.act.params.hotels[e],city:t.content.act.params.city,brand:t.content.act.params.brand},l)}else f(t.content.say,l,"bot",!1);if(s(!1),"string"==typeof(null==t||null===(H=t.content)||void 0===H?void 0:H.say)&&(null==t||null===(G=t.content)||void 0===G||null===(Y=G.say)||void 0===Y?void 0:Y.length)>0)return t.content.say}else r(t=>t.concat(e));if("string"==typeof e.content&&e.content.includes("{email_form}")){const t={id:c.v4(),type:"email_form",author:"0",content:S};r(e=>e.concat(t)),e.content=e.content.replace("{email_form}","")}if("string"==typeof e.content&&e.content.length>0)return e}}catch(e){return console.error("Failed to sendMessage"),console.error(e.stack),null}}const z="https://agent-dev.genaisolutions.ai",M={IMAGE_SOURCES:["*","data:"],CONNECT_SOURCES:["'self'","https://www.google.com/","https://identitytoolkit.googleapis.com","apis.google.com","https://www.googleapis.com","https://generativelanguage.googleapis.com","https://www.google-analytics.com","https://securetoken.googleapis.com","https://billing.stripe.com/","https://maps.googleapis.com","".concat(z),"https://agent-prod.koodums.com"],MEDIA_SOURCES:["'self'","blob:","data:"],SCRIPT_SOURCES:["'self'","'unsafe-inline'","https://www.google.com/","www.gstatic.com","apis.google.com","https://www.googletagmanager.com","https://maps.googleapis.com","http://www.youtube.com","https://unpkg.com"],STYLE_SOURCES:["'self'","'unsafe-inline'","https://www.google.com/"],FRAME_SOURCES:["'self'","https://www.google.com/","https://docs.google.com","https://billing.stripe.com/","https://maps.googleapis.com","".concat("https://koodums-dev-east4.firebaseapp.com"),"".concat(z),"https://calendly.com","https://www.youtube.com"]},D=e=>{var t=M.CONNECT_SOURCES.join(" ")+" ";return e.allowedURLs&&(t=t.concat(e.allowedURLs.join(" "))),l.jsx(l.Fragment,{children:e.allowedURLs&&l.jsx(l.Fragment,{children:l.jsxs(u,{children:[l.jsx("meta",{httpEquiv:"Content-Security-Policy",content:"\n default-src 'self';\n img-src ".concat(M.IMAGE_SOURCES.join(" "),";\n connect-src ").concat(t,";\n media-src ").concat(M.MEDIA_SOURCES.join(" "),";\n script-src ").concat(M.SCRIPT_SOURCES.join(" "),";\n style-src ").concat(M.STYLE_SOURCES.join(" "),";\n frame-src ").concat(M.FRAME_SOURCES.join(" "),";\n frame-ancestors *;\n ")}),l.jsx("meta",{httpEquiv:"Cross-Origin-Opener-Policy",content:"same-origin-allow-popups"})]})})})},L=e=>{if(void 0===e)return"#FFFFFF";const t=e.startsWith("#")?e.slice(1):e;return.2126*parseInt(t.substring(0,2),16)+.7152*parseInt(t.substring(2,4),16)+.0722*parseInt(t.substring(4,6),16)>128?"#000000":"#FFFFFF"},U=e=>{if(void 0===e)return"#FFFFFF";const t=e.startsWith("#")?e.slice(1):e;return.2126*parseInt(t.substring(0,2),16)+.7152*parseInt(t.substring(2,4),16)+.0722*parseInt(t.substring(4,6),16)>128?"#000000":"#FFFFFF"};const q=(e,t)=>{const o=U(t);return l.jsx("div",{style:{margin:0},children:(()=>{const t=/^(https?:\/\/[^\s<>"']+[^\s<>"'.,!?])$/i;let n=(e=e.replace(/\\u([\dA-Fa-f]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16)))).replace(/(^|\s)(https?:\/\/[^\s<>"']+\.(?:png|jpg|jpeg|gif|webp|svg|bmp|tiff|tif|ico|heic|heif)(?:\?[^\s<>"']*)?|data:image\/(?:png|jpeg|gif|webp|svg\+xml);base64,[^\s<>"']+)(?=\s|$|[.,!?;])/gi,(e,t,o)=>(console.log("🚀 ~ formattedText ~ match:",e),"".concat(t,'<img src="').concat(o,'" alt="Image" style="max-width: 95%; height: auto; display: block; margin: 10px 0; border-radius: 12px;" />')));return n=n.replace(/(\*{2,6}(.*?)\*{2,6}|\*(.*?)\*|`(.*?)`|_(.*?)_)/g,(e,n,i,a,r,s)=>n&&i?t.test(i)?'<strong style="color: '.concat(o,';"><a href="').concat(i,'" target="_blank" rel="noopener noreferrer" style="color: ').concat(o,'; text-decoration: underline;">').concat(i,"</a></strong>"):'<strong style="color: '.concat(o,';">').concat(i,"</strong>"):a?'<span style="color: '.concat(o,'; font-weight: 400;">').concat(a,"</span>"):r?'<i style="font-weight: bold; color: '.concat(o,'; margin-inline: 2px;">').concat(r,"</i>"):s?'<i style="font-weight: bold; color: '.concat(o,'; margin-inline: 2px;">').concat(s,"</i>"):e),n=n.replace(/(^|\s)(https?:\/\/[^\s<>"']+[^\s<>"'.,!?])/gi,(e,t,i)=>n.includes('<img src="'.concat(i,'"'))||n.includes('<a href="'.concat(i,'"'))?e:"".concat(t,'<a href="').concat(i,'" target="_blank" rel="noopener noreferrer" style="color: ').concat(o,'; text-decoration: underline;">').concat(i,"</a>")),l.jsx("p",{style:{margin:0},dangerouslySetInnerHTML:{__html:n}})})()})},W=e=>{let{headerColor:o,headerFontColor:n,agentName:i}=e;return l.jsx(t.Box,{sx:{paddingTop:"10px",width:"100%",height:"50px",backgroundColor:o,overflowY:"auto"},alignItems:"center",justifyContent:"center",display:"flex",margin:"auto",children:l.jsx(t.Typography,{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:n,children:i})})},V=e=>{let{backgroundColor:o,companyName:n,appVersion:i,environment:a}=e;return l.jsxs(t.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"1.5em",gap:"3px",backgroundColor:o},children:[l.jsx(t.Typography,{sx:{fontSize:"1.5em",color:o?U(o):"#292929",lineHeight:1},children:"©"}),l.jsxs(t.Typography,{sx:{textAlign:"center",fontSize:"0.75em",color:o?U(o):"#292929",fontFamily:"Google Sans",lineHeight:1},children:[n," 2025, Version ",i," ","dev"===a||"test"===a?a:""]})]})},H=e=>{let{isOpen:t,onClose:o,children:n}=e;return l.jsx("div",{className:"modal-overlay",children:l.jsx("div",{className:"modal-content",children:n})})},G={sender:{background:"lightblue",borderRadius:"20px 0px 20px 20px",padding:"10px 16px",gap:"10px",maxWidth:"85%",color:"#000000",fontSize:"16px"},botHighlighted:{background:"#FF0000",borderRadius:"0px 20px 20px 20px",padding:"10px 16px",gap:"10px",maxWidth:"85%",color:"#FFFFFF",fontSize:"16px"},bot:{background:"#EDEDED",borderRadius:"0px 20px 20px 20px",padding:"10px 16px",gap:"10px",maxWidth:"85%",color:"#000000",fontSize:"16px"}},Y={formContainer:{padding:"0px 10px 10px 10px",fontFamily:"Google Sans",width:"90%",margin:"auto",backgroundColor:"#fff",marginTop:"10px"},inputField:{flex:"1",padding:"5px",borderRadius:"5px",width:"80%",border:"1px solid #ccc",fontSize:"16px",backgroundColor:"#fff",color:"#292929"},submitButton:{width:"100%",padding:"10px",backgroundColor:"#4CAF50",color:"#fff",border:"none",borderRadius:"10px",cursor:"pointer",fontSize:"16px"},errorStyle:{color:"red",marginBottom:"5px",textAlign:"center",fontWeight:"bold"}},J={container:{padding:"0px 20px 20px 20px",fontFamily:"Google Sans",margin:"auto",backgroundColor:"#fff",marginTop:"10px"},customLineStyle:{flex:"1",width:"100%",color:"#292929",textAlign:"center"},desclaimerLineStyle:{width:"100%",backgroundColor:"#fff",color:"#292929",textAlign:"center"}},Q=e=>{let{backgroundColor:o,isModalOpen:n,setModalOpen:i,privacyPolicy:a,handleAcceptPrivacyPolicy:r}=e;return l.jsx(t.Box,{sx:{width:"100%",height:"inherit",overflowY:"auto",backgroundColor:o},children:l.jsx(H,{open:n,setOpen:()=>i(!1),children:l.jsxs("div",{style:J.container,children:[l.jsx("h4",{dangerouslySetInnerHTML:{__html:a},style:J.customLineStyle}),l.jsx("h3",{style:J.desclaimerLineStyle,children:"Do you accept our privacy policy?"}),l.jsxs("div",{style:{display:"flex",justifyContent:"center",gap:20},children:[l.jsx(t.Button,{sx:{padding:"10px 20px",backgroundColor:"#4CAF50",color:"#fff",border:"10px",borderRadius:"10px",cursor:"pointer",fontSize:"16px","&:hover":{backgroundColor:"#45a049"}},onClick:()=>r(!0),children:"Yes"}),l.jsx(t.Button,{sx:{padding:"10px 20px",backgroundColor:"#F44336",color:"#fff",border:"none",borderRadius:"10px",cursor:"pointer",fontSize:"16px","&:hover":{backgroundColor:"#d32f2f"}},onClick:()=>r(!1),children:"No"})]})]})})})},K=e=>{let{backgroundColor:o,isModalOpen:n,setModalOpen:i,askForNamePhrase:a,formData:r,handleFormDataInputChange:s,handleFormSubmit:c,error:d}=e;return l.jsx(t.Box,{sx:{width:"100%",height:"inherit",overflowY:"auto",backgroundColor:o},children:l.jsx(H,{open:n,setOpen:()=>i(!1),children:l.jsxs("div",{style:Y.formContainer,children:[l.jsx(t.Typography,{variant:"h6",sx:{textAlign:"center",marginBottom:"15px",color:"#292929"},children:a||"Enter Your Details"}),l.jsxs("form",{onSubmit:c,children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"15px",color:"#292929"},children:[l.jsx(t.Typography,{component:"label",sx:{fontWeight:"bold",marginRight:"5px"},children:"Name:"}),l.jsx(t.TextField,{type:"text",name:"name",value:r.name,onChange:s,sx:Y.inputField,placeholder:"Enter your name",variant:"outlined",size:"small"})]}),l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"15px",color:"#292929"},children:[l.jsx(t.Typography,{component:"label",sx:{fontWeight:"bold",marginRight:"5px"},children:"Email:"}),l.jsx(t.TextField,{type:"email",name:"email",value:r.email,onChange:s,sx:Y.inputField,placeholder:"Enter your email",variant:"outlined",size:"small"})]}),d&&l.jsx(t.Typography,{sx:Y.errorStyle,color:"error",children:d}),l.jsx(t.Button,{type:"submit",sx:Y.submitButton,variant:"contained",children:"Submit"})]})]})})})},Z=e=>{let{headerColor:o,headerFontColor:n,agentName:i,backgroundColor:a,disabledMessage:r}=e;return l.jsxs(t.Stack,{direction:"column",sx:{overflowY:"hidden",marginTop:"0px",height:"100%"},children:[l.jsx(t.Box,{sx:{paddingTop:"10px",width:"100%",height:"50px",backgroundColor:o,overflowY:"auto"},alignItems:"center",justifyContent:"center",display:"flex",margin:"auto",children:l.jsx(t.Typography,{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:n,children:i})}),l.jsx(t.Box,{sx:{width:"100%",flex:1,overflowY:"auto",backgroundColor:a},children:l.jsx("div",{dangerouslySetInnerHTML:{__html:r},style:{padding:"10px",fontSize:"16px",textAlign:"center",color:L(a)}})})]})};function X(e){const{children:o,style:n}=e;return l.jsx(t.Paper,{elevation:0,sx:n,children:o})}const $=t=>{let{content:o,type:n,scrollToBottom:i,width:a="90%",maxWidth:r="400px",borderRadius:s="10px",altText:c="Rich content image"}=t;return e.useEffect(()=>{i&&i()},[]),l.jsx("a",{href:o.link,target:"_blank",rel:"noopener noreferrer",style:{marginTop:"10px",display:"flex",justifyContent:o.isFirstImage?"center":"start"},children:l.jsx("img",{src:(d=o.rawUrl,d.startsWith("https://")?d:"".concat("https://agent-dev.genaisolutions.ai").concat(o.rawUrl)),style:{width:"90%",height:"auto",display:"block",borderRadius:s},alt:c})});var d};function ee(o){let{onClick:n,children:i,scrollToBottom:a}=o;return e.useEffect(()=>{a&&a()}),l.jsx(t.Paper,{elevation:0,sx:{width:"fit-content",background:"#FFFFFF",borderRadius:"32px",padding:"10px 10px",gap:"10px",color:"#614646",borderColor:"#AE9E9C",borderStyle:"solid",boxShadow:"rgba(0, 0, 0, 0.24) 0px 2px 2px 0px",borderWidth:"1px",cursor:"pointer",marginRight:"5px"},onClick:n&&n,children:l.jsxs(h.Stack,{direction:"row",spacing:.5,children:[l.jsx(t.Icon,{children:l.jsx("svg",{style:{marginBottom:"4px"},xmlns:"http://www.w3.org/2000/svg",width:"10",height:"14",viewBox:"0 0 10 14",fill:"none",children:l.jsx("path",{d:"M2.2077 9.53716C2.10917 9.40578 2.03732 9.26414 1.99216 9.11224C1.947 8.95624 1.92442 8.7756 1.92442 8.57032C1.92442 8.28705 1.85258 8.01404 1.70889 7.75129C1.5652 7.48854 1.39893 7.21142 1.21007 6.91994C1.02122 6.62434 0.854954 6.28975 0.711263 5.91616C0.567573 5.53845 0.495728 5.09507 0.495728 4.58599C0.495728 4.03997 0.606575 3.53295 0.828268 3.06492C1.05407 2.5928 1.36198 2.1802 1.75199 1.82713C2.14612 1.46996 2.60182 1.19284 3.11911 0.995781C3.63639 0.794614 4.19063 0.694031 4.78181 0.694031C5.37299 0.694031 5.92723 0.794614 6.44452 0.995781C6.9618 1.19284 7.41545 1.46996 7.80547 1.82713C8.19959 2.1802 8.5075 2.5928 8.7292 3.06492C8.95499 3.53295 9.06789 4.03997 9.06789 4.58599C9.06789 5.09507 8.99605 5.53845 8.85236 5.91616C8.70867 6.28975 8.5424 6.62434 8.35355 6.91994C8.1647 7.21142 7.99843 7.48854 7.85474 7.75129C7.71105 8.01404 7.6392 8.28705 7.6392 8.57032C7.6392 8.7756 7.61662 8.95624 7.57146 9.11224C7.5263 9.26414 7.45445 9.40578 7.35592 9.53716L6.47531 9.42631C6.63542 9.28262 6.74627 9.15946 6.80785 9.05682C6.86943 8.95008 6.90022 8.78791 6.90022 8.57032C6.90022 8.19262 6.97207 7.84982 7.11576 7.54191C7.25945 7.2299 7.42572 6.92609 7.61457 6.6305C7.80342 6.33081 7.96969 6.01879 8.11338 5.69446C8.25707 5.36603 8.32891 4.99654 8.32891 4.58599C8.32891 4.1426 8.23654 3.73001 8.0518 3.3482C7.86705 2.96639 7.61251 2.6318 7.28818 2.34442C6.96385 2.05704 6.58615 1.83329 6.15508 1.67318C5.72812 1.51307 5.27036 1.43301 4.78181 1.43301C4.29326 1.43301 3.83345 1.51307 3.40238 1.67318C2.97542 1.83329 2.59977 2.05704 2.27544 2.34442C1.95111 2.6318 1.69657 2.96639 1.51182 3.3482C1.32708 3.73001 1.23471 4.1426 1.23471 4.58599C1.23471 5.00064 1.30655 5.37218 1.45024 5.70062C1.59393 6.02905 1.7602 6.34107 1.94905 6.63666C2.13791 6.93225 2.30418 7.23606 2.44787 7.54807C2.59156 7.85598 2.6634 8.19673 2.6634 8.57032C2.6634 8.78791 2.69419 8.95008 2.75577 9.05682C2.81736 9.15946 2.9282 9.28262 3.08832 9.42631L2.2077 9.53716ZM4.78181 13.6262C4.35895 13.6262 4.03667 13.5235 3.81498 13.3183C3.59328 13.113 3.48244 12.8482 3.48244 12.5239C3.68771 12.6758 3.95456 12.7764 4.283 12.8256C4.61554 12.879 4.94603 12.879 5.27446 12.8256C5.60701 12.7764 5.87591 12.6758 6.08118 12.5239C6.08118 12.8482 5.97034 13.113 5.74864 13.3183C5.53105 13.5235 5.20878 13.6262 4.78181 13.6262ZM4.78181 12.647V12.1544L6.35214 11.9081V12.4007L4.78181 12.647ZM3.21764 11.9388V11.4462L6.88175 10.8673V11.36L3.21764 11.9388ZM4.78181 13.1397C4.33432 13.1397 3.92377 13.0719 3.55018 12.9365C3.18069 12.801 2.95284 12.606 2.86662 12.3514L2.54024 10.8427C2.40065 10.6744 2.30212 10.5101 2.24465 10.35C2.18717 10.1858 2.15843 9.9826 2.15843 9.74038H2.89741C2.89741 9.92923 2.91589 10.0668 2.95284 10.153C2.99389 10.2351 3.08216 10.348 3.21764 10.4917L3.57481 12.2467C3.61997 12.3001 3.76571 12.3596 4.01204 12.4253C4.25837 12.491 4.51496 12.5239 4.78181 12.5239C5.04866 12.5239 5.30525 12.491 5.55158 12.4253C5.79791 12.3596 5.94365 12.3001 5.98881 12.2467L6.34598 10.4917C6.48146 10.348 6.56768 10.2351 6.60463 10.153C6.64568 10.0668 6.66621 9.92923 6.66621 9.74038H7.40519C7.40519 9.9826 7.37645 10.1858 7.31898 10.35C7.2656 10.5101 7.16707 10.6744 7.02338 10.8427L6.697 12.3514C6.61079 12.606 6.38293 12.801 6.01344 12.9365C5.64395 13.0719 5.23341 13.1397 4.78181 13.1397ZM3.21764 10.9843V10.4917L6.88175 9.9128V10.4055L3.21764 10.9843ZM4.78181 10.2761C4.17421 10.2761 3.64255 10.2269 3.18685 10.1283C2.73525 10.0298 2.37602 9.89228 2.10917 9.71574C2.06401 9.6829 2.01885 9.63363 1.97369 9.56795C1.92853 9.50226 1.90595 9.41194 1.90595 9.29699C1.90595 9.21488 1.93263 9.13893 1.986 9.06914C2.03937 8.99934 2.11738 8.96445 2.22001 8.96445C2.2816 8.96445 2.32881 8.97882 2.36165 9.00755C2.58745 9.20462 2.90357 9.33804 3.31001 9.40784C3.71645 9.47763 4.20705 9.51252 4.78181 9.51252C5.35657 9.51252 5.84717 9.47763 6.25361 9.40784C6.66005 9.33804 6.97617 9.20462 7.20197 9.00755C7.23481 8.97882 7.28203 8.96445 7.34361 8.96445C7.45035 8.96445 7.52835 8.99934 7.57762 9.06914C7.63099 9.13893 7.65767 9.21488 7.65767 9.29699C7.65767 9.41194 7.63509 9.50226 7.58993 9.56795C7.54477 9.63363 7.49961 9.6829 7.45445 9.71574C7.1876 9.89228 6.82837 10.0298 6.37678 10.1283C5.92518 10.2269 5.39352 10.2761 4.78181 10.2761Z",fill:"#614646"})})}),l.jsx("div",{style:{fontFamily:"Google Sans",fontSize:"14px",lineHeight:"18px"},children:i})]})})}const te=o=>{var n;let{content:i,index:a,scrollToBottom:r,listStyle:s="none",itemSpacing:c="16px",maxWidth:d="400px"}=o;return e.useEffect(()=>{r&&r()},[]),l.jsxs(t.Box,{sx:{width:"100%",marginBottom:"0%",marginTop:"10px"},children:[l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:"black"},children:i.title}),l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:"black"},children:i.subtitle}),l.jsx(t.Box,{component:"ul",sx:{listStyleType:s,paddingLeft:"0"},children:null===(n=i.options)||void 0===n?void 0:n.map((e,o)=>l.jsxs(t.Box,{sx:{margin:"".concat(c," 0"),display:"flex",flexDirection:"column",alignItems:"flex-start"},children:[l.jsx("img",{width:"100%",style:{maxWidth:d},src:e.url,alt:e.text||"Picture list item"}),l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontSize:"16px",color:"black",marginTop:"8px"},children:e.text})]},o))})]},a)};function oe(o){const{orig_lat:n,orig_lon:i,onClose:a,lat:r,lon:s,scrollToBottom:c}=o,[d,u]=e.useState(null),p=e.useRef(null);return e.useEffect(()=>{const e=new google.maps.LatLng(n,i);if(null!==p.current){const t=new google.maps.Map(p.current,{mapId:"69756bebb3f7f821",center:e,zoom:16});new google.maps.Marker({position:e}).setMap(t),console.log("MapCard useEffect "),u(t)}c&&c()},[]),l.jsx(t.Stack,{width:"100%",height:"100%",children:l.jsxs(t.Stack,{width:"100%",height:"100%",position:"relative",sx:{top:0,left:0,zIndex:1e3,height:"300px"},justifyContent:"space-between",children:[l.jsx(t.Stack,{direction:"row",justifyContent:"space-between",alignItems:"center",alignContent:"center",sx:{margin:"20px",zIndex:1e3,color:"white"},children:l.jsx(t.Fab,{sx:{background:"rgba(0,0,0,0.4)"},onClick:()=>{a&&a()},children:l.jsx(m.CloseOutlined,{sx:{color:"#FFFFFF"}})})}),l.jsx(t.Box,{position:"absolute",width:"100%",height:"100%",children:l.jsx(t.Box,{width:"100%",height:"100%",ref:p,id:"map"})})]})})}const ne=o=>{var n;let{content:i,index:a,scrollToBottom:r,textColor:s="black"}=o;return e.useEffect(()=>{r&&r()},[]),l.jsxs(t.Box,{sx:{width:"100%",marginBottom:"0%",marginTop:"10px"},children:[l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:s},children:i.title}),l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:s},children:i.subtitle}),l.jsx("ul",{children:null===(n=i.options)||void 0===n?void 0:n.map((e,o)=>l.jsx(t.Box,{component:"li",sx:{margin:"8px 0",color:s},children:e.text},o))})]},a)},ie=o=>{var n,i;let{content:a,index:r,scrollToBottom:s}=o;return e.useEffect(()=>{s&&s()},[]),l.jsxs(t.Box,{sx:{width:"100%",marginBottom:"0%",marginTop:"10px"},children:[l.jsx("a",{href:a.actionLink,target:"_blank",rel:"noopener noreferrer",children:l.jsx("img",{width:"100%",style:{maxWidth:"400px"},height:a.height,src:null===(n=a.image)||void 0===n||null===(i=n.src)||void 0===i?void 0:i.rawUrl,alt:a.title||"Rich content image"})}),l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:"black"},children:a.title}),l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:"black"},children:a.subtitle})]},r)},ae=o=>{let{content:n,index:i,name:a,onSlideChange:r,scrollToBottom:s,maxWidth:c="400px",width:d="80%"}=o;const u=n.photos||[],p=u.length>0;return e.useEffect(()=>{s&&s()},[]),l.jsxs(x.Swiper,{style:{width:d,maxWidth:c,height:"auto",backgroundColor:"black",marginTop:"10px"},slidesPerView:1,modules:[y.Pagination,y.Navigation],navigation:{nextEl:".swiper-button-next",prevEl:".swiper-button-prev"},onSlideChange:r,children:[p?u.map((e,o)=>l.jsx(x.SwiperSlide,{children:l.jsxs(t.Box,{width:"100%",height:"100%",children:[l.jsx(t.Box,{width:"100%",height:"100%",children:l.jsx("img",{height:"100%",width:"100%",src:e,style:{objectFit:"cover",objectPosition:"center center"},alt:"Slide ".concat(o+1)})}),l.jsx(t.Box,{width:"100%",height:"100%",sx:{position:"absolute",marginTop:"200px",zIndex:100},children:l.jsxs(t.Stack,{direction:"column",color:"white",spacing:1.5,p:3,children:[l.jsx(t.Typography,{variant:"h4",fontFamily:"Google Sans",fontSize:"24px",fontWeight:"300",children:a}),l.jsx(t.Typography,{variant:"h7",fontFamily:"Google Sans",fontSize:"14px"})]})})]})},o)):l.jsx(x.SwiperSlide,{children:l.jsxs(t.Box,{width:"100%",height:"100%",children:[l.jsx(t.Box,{width:"100%",height:"100%",children:l.jsx(t.Skeleton,{height:"100%",width:"100%"})}),l.jsx(t.Box,{width:"100%",height:"100%",sx:{position:"absolute",marginTop:"calc(".concat(window.innerHeight,"px * 0.4)"),zIndex:100},children:l.jsxs(t.Stack,{direction:"column",color:"white",spacing:1.5,p:3,children:[l.jsx(t.Typography,{variant:"h4",fontFamily:"Google Sans",children:a}),l.jsx(t.Typography,{variant:"h7",fontFamily:"Google Sans"})]})})]})}),l.jsx(t.Box,{className:"swiper-button-prev",sx:{color:"white",backgroundColor:"rgba(0, 0, 0, 0.5)",borderRadius:"4px",border:"1px solid rgba(255, 255, 255, 0.3)",width:"32px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center","&::after":{fontSize:"16px"}}}),l.jsx(t.Box,{className:"swiper-button-next",sx:{color:"white",backgroundColor:"rgba(0, 0, 0, 0.5)",borderRadius:"4px",border:"1px solid rgba(255, 255, 255, 0.3)",width:"32px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center","&::after":{fontSize:"16px"}}})]},i)},re=t=>{let{data:o,scrollToBottom:n,foregroundColor:i="#fff",backgroundColor:a="#000",backgroundColorLight:r,metadata:s}=t;const{header:c={},content:d={},border:u={},headerBackgroundColor:p="#ccc",rowAlternateColor:h=!0,alternateRowColors:g=[a,r],borderRadius:m="12px"}=s,x={width:"100%",borderCollapse:"collapse",border:"".concat((null==u?void 0:u.width)||"1px"," solid ").concat((null==u?void 0:u.color)||i),borderRadius:m,overflow:"hidden",backgroundColor:a,color:i},y={backgroundColor:p,color:(null==c?void 0:c.color)||"black",fontWeight:(null==c?void 0:c.fontWeight)||"bold",fontStyle:(null==c?void 0:c.fontStyle)||"normal",fontSize:(null==c?void 0:c.fontSize)||"16px",padding:"10px",border:"".concat(u.width||"1px"," solid ").concat(u.color||i)},f={color:(null==d?void 0:d.color)||i,fontWeight:(null==d?void 0:d.fontWeight)||"normal",fontStyle:(null==d?void 0:d.fontStyle)||"normal",fontSize:(null==d?void 0:d.fontSize)||"14px",padding:"10px",borderBottom:"".concat(u.width||"1px"," solid ").concat(u.color||i)};return e.useEffect(()=>{n&&n()},[]),l.jsxs("div",{children:[l.jsx("h2",{style:{color:i},children:o.title}),l.jsx("div",{style:x,children:l.jsxs("table",{style:x,children:[l.jsx("thead",{children:l.jsx("tr",{children:o.headers.map((e,t)=>l.jsx("th",{style:y,children:e},t))})}),l.jsx("tbody",{children:o.rows.map((e,t)=>{const n=h?g[t%g.length]:a;return l.jsx("tr",{style:{backgroundColor:n},children:o.headers.map((t,o)=>l.jsx("td",{style:f,children:e[t]},o))},t)})})]})})]})},se=(void 0).VITE_GOOGLE_MAPS_API_KEY,le={primary:"'Google Sans', Roboto, sans-serif",size:{title:"0.95rem",subtitle:"1rem",body:"1rem"}},ce={primary:"#007BFF",secondary:"#28a745",text:"#292929",muted:"#555",background:"#F5F5F5",card:"#DDDDDD"},de={xs:"3px",sm:"6px",md:"8px"},ue="6px",pe="0 1px 3px rgba(0, 0, 0, 0.08)",he=e=>{let{rating:o}=e;const n=[];for(let e=0;e<5;e++)e<Math.floor(o)?n.push(l.jsx(m.Star,{sx:{color:"#FFD700",fontSize:18}},e)):e<o?n.push(l.jsx(m.StarHalf,{sx:{color:"#FFD700",fontSize:18}},e)):n.push(l.jsx(m.StarBorder,{sx:{color:"#FFD700",fontSize:18}},e));return l.jsx(t.Box,{sx:{display:"flex",gap:de.xs},children:n})},ge=t=>{let{item:o}=t;console.log("🚀 ~ MenuItem ~ item:",o);const{display_name:n,value:i,display_type:a}=o,[r,s]=e.useState(0);e.useEffect(()=>{if("map_photo"===a&&Array.isArray(i)&&i.length>1){const e=setInterval(()=>{s(e=>(e+1)%i.length)},3e3);return()=>clearInterval(e)}},[a,i]);const c={width:"100%",maxWidth:"300px",margin:"".concat(de.sm," auto"),boxSizing:"border-box"},d={width:"100%",maxWidth:"300px",minWidth:"300px",height:"140px",position:"relative",display:"block",overflow:"hidden",boxSizing:"border-box"},u={width:"100%",height:"140px",objectFit:"cover",borderRadius:ue,display:"block",boxSizing:"border-box"},p={position:"absolute",top:"50%",transform:"translateY(-50%)",background:"rgba(0, 0, 0, 0.6)",color:"white",border:"none",padding:de.xs,cursor:"pointer",fontSize:"14px",borderRadius:"3px",zIndex:1},h=Array.isArray(i)?i:[],g=e=>"map_photo"===a?"https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=".concat(e,"&key=").concat(se):e;switch(a){case"title":return l.jsx("h3",{style:{color:ce.text,fontWeight:600,margin:de.sm,fontFamily:le.primary,boxSizing:"border-box"},children:i});case"rating":return l.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",margin:de.sm,boxSizing:"border-box"},children:l.jsx(he,{rating:i})});case"subtitle":return l.jsx("p",{style:{color:ce.muted,fontSize:le.size.subtitle,margin:de.xs,fontFamily:le.primary,boxSizing:"border-box"},children:i});case"description":return l.jsx("p",{style:{color:ce.text,fontSize:le.size.body,margin:de.xs,fontFamily:le.primary,boxSizing:"border-box"},children:i});case"price":case"text":return l.jsxs("p",{style:{color:ce.primary,fontSize:le.size.subtitle,fontWeight:500,margin:0,fontFamily:le.primary,boxSizing:"border-box",textTransform:"capitalize"},children:[n," : ",i]});case"link":return l.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:{background:ce.primary,color:"white",padding:"".concat(de.sm),borderRadius:ue,textDecoration:"none",display:"inline-block",fontSize:le.size.body,fontFamily:le.primary,boxSizing:"border-box",marginBottom:de.sm},children:n});case"image":case"icon":return l.jsx("img",{loading:"lazy",src:i,alt:n||"menu item",style:{width:"100%",height:"100px",objectFit:"cover",borderRadius:ue,margin:de.sm,boxSizing:"border-box",alignSelf:"center"}});case"map_photo":case"photo":if("string"==typeof i){const e=g(i);return l.jsx("img",{loading:"lazy",src:e,alt:n||"menu item",style:{width:"100%",height:"100px",objectFit:"contain",borderRadius:ue,margin:de.sm,boxSizing:"border-box"}})}if(Array.isArray(i)){const e=g(i[r]);return l.jsxs("div",{style:c,children:[l.jsx("div",{style:{display:"none"},children:h.map((e,t)=>l.jsx("img",{src:g(e),alt:"",loading:"lazy"},t))}),l.jsxs("div",{style:d,children:[l.jsx("button",{style:F(F({},p),{},{left:de.xs}),onClick:()=>s((r-1+i.length)%i.length),children:"❮"}),l.jsx("img",{loading:"lazy",src:e,alt:n||"menu item",style:u}),l.jsx("button",{style:F(F({},p),{},{right:de.xs}),onClick:()=>s((r+1)%i.length),children:"❯"})]})]})}return null;default:return null}},me=e=>{let{menu:o,action_type:n,sendMessage:i,onScrollToBottom:a}=e;return l.jsx("div",{children:null==o?void 0:o.map((e,o)=>{var n,r;const s=Number(null===(n=e.find(e=>"latitude"===(null==e?void 0:e.display_type)))||void 0===n?void 0:n.value),c=Number(null===(r=e.find(e=>"longitude"===(null==e?void 0:e.display_type)))||void 0===r?void 0:r.value);return l.jsxs("div",{style:{backgroundColor:ce.card,borderRadius:ue,padding:de.md,boxShadow:pe,marginBottom:de.sm,width:"100%",maxWidth:"340px !important",boxSizing:"border-box",display:"flex",flexDirection:"column",gap:de.xs},children:[null==e?void 0:e.map((e,t)=>l.jsx(ge,{item:e},t)),s&&c?l.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:de.sm},children:l.jsx(f.Map,{style:{width:"100%",height:"15vh",borderRadius:"20px"},defaultCenter:{lat:s,lng:c},defaultZoom:15,gestureHandling:"greedy",disableDefaultUI:!0,children:l.jsx(f.Marker,{position:{lat:s,lng:c}})})}):null,l.jsx(t.Button,{onClick:()=>(e=>{if(!e||!Array.isArray(e))return void console.warn("Invalid item:",e);const t=e.some(e=>!0===e.isDemo);console.log("Item clicked, isDemo:",t),t||(i("I choose this: ".concat(JSON.stringify(e)),!0),null==a||a())})(e),sx:{backgroundColor:ce.primary,color:"white",padding:"".concat(de.xs," ").concat(de.sm),borderRadius:ue,fontSize:le.size.body,fontFamily:le.primary,textTransform:"none","&:hover":{backgroundColor:"#0056b3"},boxSizing:"border-box"},children:"Choose"})]},o)})})},xe=e=>{var t,o,n,i,a,r,s,c,d;let{event:u}=e;const p=null===(t=u.find(e=>"title"===e.display_type))||void 0===t?void 0:t.value,h=null===(o=u.find(e=>"image"===e.display_type))||void 0===o?void 0:o.value,g=null===(n=u.find(e=>"date"===e.display_type))||void 0===n?void 0:n.value,m=null===(i=u.find(e=>"time"===e.display_type))||void 0===i?void 0:i.value,x=null===(a=u.find(e=>"subtitle"===e.display_type))||void 0===a?void 0:a.value,y=null===(r=u.find(e=>"location"===e.display_type))||void 0===r?void 0:r.value,f=null===(s=u.find(e=>"card_body"===e.display_type))||void 0===s?void 0:s.value,b=u.find(e=>"link"===e.display_type),v=null===(c=u.find(e=>"latitude"===e.display_name))||void 0===c?void 0:c.value,S=null===(d=u.find(e=>"longitude"===e.display_name))||void 0===d?void 0:d.value;return l.jsxs("div",{style:{display:"flex",alignItems:"center",width:"90%",backgroundColor:ce.card,borderRadius:ue,padding:de.sm,boxShadow:pe,gap:de.sm,boxSizing:"border-box"},children:[l.jsx("div",{style:{flex:1,minWidth:"80px"},children:h&&l.jsx("img",{loading:"lazy",src:h,alt:p,style:{width:"100%",height:"60px",objectFit:"cover",borderRadius:ue,boxSizing:"border-box"}})}),l.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:de.xs,boxSizing:"border-box"},children:[p&&l.jsx("h3",{style:{color:ce.text,fontSize:le.size.title,fontWeight:600,margin:0,fontFamily:le.primary,boxSizing:"border-box"},children:p}),(g||m)&&l.jsxs("p",{style:{color:ce.muted,fontSize:le.size.body,margin:0,fontFamily:le.primary,boxSizing:"border-box"},children:[g," ",m?"| ".concat(m):""]}),x&&l.jsx("p",{style:{color:ce.muted,fontSize:le.size.body,margin:0,fontFamily:le.primary,boxSizing:"border-box"},children:x}),y&&l.jsx("p",{style:{color:ce.muted,fontSize:le.size.body,margin:0,fontFamily:le.primary,boxSizing:"border-box"},children:y}),f&&l.jsx("p",{style:{color:ce.text,fontSize:le.size.body,margin:0,fontFamily:le.primary,boxSizing:"border-box"},children:f}),l.jsxs("div",{style:{display:"flex",gap:de.xs,marginTop:de.xs,boxSizing:"border-box"},children:[b&&l.jsx("a",{href:null==b?void 0:b.value,target:"_blank",rel:"noopener noreferrer",style:{backgroundColor:ce.primary,color:"white",padding:"".concat(de.xs," ").concat(de.sm),borderRadius:ue,textDecoration:"none",fontSize:le.size.body,fontFamily:le.primary,boxSizing:"border-box"},children:(null==b?void 0:b.display_name)||"Click here"}),v&&S&&l.jsx("button",{onClick:()=>((e,t)=>{window.open("https://www.google.com/maps?q=".concat(e,",").concat(t),"_blank")})(v,S),style:{backgroundColor:ce.secondary,color:"white",padding:"".concat(de.xs," ").concat(de.sm),borderRadius:ue,border:"none",cursor:"pointer",fontSize:le.size.body,fontFamily:le.primary,boxSizing:"border-box"},children:"Open in Maps"})]})]})]})},ye=t=>{let{schema:o=[],sendMessage:n}=t;const i=o.reduce((e,t)=>("header"!==t.display_type&&"button"!==t.display_type&&(e[t.path]=""),e),{}),[a,r]=e.useState(i),[s,c]=e.useState(null),d=e=>{const{name:t,value:o}=e.target;r(e=>F(F({},e),{},{[t]:o}))},u=e=>{const t=e.target.files[0];if(t){const e=new FileReader;e.onload=()=>{c(e.result),r(t=>F(F({},t),{},{image:e.result}))},e.readAsDataURL(t)}};return l.jsx("div",{style:{width:"100%",maxWidth:"340px",backgroundColor:ce.card,padding:de.md,borderRadius:ue,boxShadow:pe,boxSizing:"border-box"},children:l.jsx("form",{onSubmit:e=>{e.preventDefault(),n(JSON.stringify(a))},style:{display:"flex",flexDirection:"column",gap:de.sm,boxSizing:"border-box"},children:o.map(e=>l.jsx("div",{children:"header"===e.display_type?l.jsx("h2",{style:{fontSize:"1.1rem",fontWeight:600,marginBottom:de.sm,textAlign:"center",fontFamily:le.primary,boxSizing:"border-box"},children:e.display_name}):"text"===e.display_type||"number"===e.display_type?l.jsxs(l.Fragment,{children:[l.jsx("label",{style:{display:"block",fontWeight:500,marginBottom:de.xs,fontSize:le.size.subtitle,fontFamily:le.primary,boxSizing:"border-box"},children:e.display_name}),l.jsx("input",{type:e.display_type,name:e.path,value:a[e.path],onChange:d,required:!0,style:{width:"100%",padding:de.sm,border:"1px solid ".concat(ce.muted),borderRadius:ue,fontSize:le.size.body,fontFamily:le.primary,backgroundColor:ce.background,boxSizing:"border-box"}})]}):"image"===e.display_type?l.jsxs(l.Fragment,{children:[l.jsx("label",{style:{display:"block",fontWeight:500,marginBottom:de.xs,fontSize:le.size.subtitle,fontFamily:le.primary,boxSizing:"border-box"},children:e.display_name}),l.jsx("input",{type:"file",accept:"image/*",onChange:u,required:!0,style:{width:"100%",padding:de.sm,border:"1px solid ".concat(ce.muted),borderRadius:ue,fontSize:le.size.body,fontFamily:le.primary,backgroundColor:ce.background,boxSizing:"border-box"}}),s&&l.jsx("img",{loading:"lazy",src:s,alt:"Preview",style:{marginTop:de.sm,width:"60px",height:"60px",objectFit:"cover",borderRadius:ue,border:"1px solid ".concat(ce.muted),boxSizing:"border-box"}})]}):"button"===e.display_type?l.jsx("button",{type:"submit",style:{width:"100%",backgroundColor:ce.primary,color:"white",padding:de.sm,fontSize:le.size.subtitle,fontWeight:500,borderRadius:ue,border:"none",cursor:"pointer",fontFamily:le.primary,transition:"background 0.3s",boxSizing:"border-box"},onMouseOver:e=>e.target.style.backgroundColor="#0056b3",onMouseOut:e=>e.target.style.backgroundColor=ce.primary,children:e.display_name}):null},e.path))})})},fe={fontSize:"24px",fontWeight:"bold",margin:"16px 0",color:"#333",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},be={fontSize:"16px",margin:"12px 0",color:"#555",lineHeight:"1.5",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},ve={fontSize:"18px",fontStyle:"italic",margin:"16px 0",padding:"0 20px",borderLeft:"4px solid #1976d2",color:"#444",fontFamily:"Georgia, serif",transition:"all 0.3s ease"},Se={fontSize:"16px",padding:"8px 16px",backgroundColor:"#1976d2",color:"#fff",borderRadius:"4px",fontFamily:"Arial, sans-serif",textTransform:"uppercase",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.2)",transition:"all 0.3s ease",cursor:"pointer"},we={fontSize:"16px",margin:"12px 0",paddingLeft:"20px",color:"#555",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},je={margin:"16px 0",borderRadius:"8px",maxWidth:"100%",width:"100%",height:"auto",objectFit:"cover",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1)",transition:"all 0.3s ease"},Ce={margin:"16px 0",padding:"16px",backgroundColor:"#f8f9fa",borderRadius:"8px",border:"1px solid #dee2e6",fontFamily:"Arial, sans-serif",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1)",transition:"all 0.3s ease"},ke={margin:"16px 0",borderRadius:"8px",height:"300px",width:"100%",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1)",transition:"all 0.3s ease"},Ie={margin:"16px 0",borderCollapse:"collapse",width:"100%",fontFamily:"Arial, sans-serif",border:"1px solid #dee2e6",transition:"all 0.3s ease"},Fe={margin:"16px 0",padding:"8px 0",color:"#555",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},Re={fontSize:"18px",fontWeight:"bold",color:"#333",marginBottom:"8px",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},Te={padding:"8px",backgroundColor:"transparent",borderRadius:"4px",marginBottom:"8px",transition:"all 0.3s ease"},Ae=e.memo(o=>{var n;let{images:i=[],caption:a,css:r}=o;const[s,c]=e.useState(0),d=e.useCallback(()=>{c(e=>0===e?i.length-1:e-1)},[i]),u=e.useCallback(()=>{c(e=>e===i.length-1?0:e+1)},[i]);return i.length?l.jsxs("div",{style:{position:"relative",width:"100%",margin:(null==r?void 0:r.margin)||"0 0 16px 0"},children:[l.jsxs("div",{style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",minHeight:"200px"},children:[l.jsx("img",{loading:"lazy",src:null===(n=i[s])||void 0===n?void 0:n.url,alt:"".concat(a||"Image"," ").concat(s+1),style:F({width:"100%",height:"auto",objectFit:"cover",maxHeight:"400px",borderRadius:"8px"},r)}),l.jsx("div",{style:{position:"absolute",left:"12px",top:"50%",transform:"translateY(-50%)",zIndex:10},children:l.jsx(t.Button,{variant:"contained",color:"",sx:{background:"#F5F5F5",width:"15px",opacity:.6,color:"black"},onClick:d,disabled:i.length<=1,children:"<"})}),l.jsx("div",{style:{position:"absolute",right:"12px",top:"50%",transform:"translateY(-50%)",zIndex:10},children:l.jsx(t.Button,{variant:"contained",sx:{background:"#F5F5F5",width:"15px",opacity:.6,color:"black"},onClick:u,disabled:i.length<=1,children:">"})})]}),l.jsx("div",{style:{display:"flex",justifyContent:"center",gap:"8px",marginTop:"8px"}})]}):l.jsx("div",{style:{color:"#718096"},children:"No images to display"})}),Oe=e.memo(t=>{let{lat:o,lng:n,css:i}=t;console.log("🚀 ~ MapBlockComponent ~ lat, lng:",o,n);const[a,r]=e.useState(null);if(e.useEffect(()=>{import("@vis.gl/react-google-maps").then(e=>{let{APIProvider:t,Map:o,Marker:n}=e;return r({APIProvider:t,Map:o,Marker:n})}).catch(e=>console.error("Error loading Google Maps:",e))},[]),!a)return l.jsx("div",{className:"p-4 text-gray-600",children:"Loading map..."});const{APIProvider:s,Map:c,Marker:d}=a;return l.jsx("div",{style:F({width:"100%",height:"300px",borderRadius:"8px",overflow:"hidden",marginBottom:"16px"},i),children:l.jsx(s,{apiKey:se,children:l.jsx(c,{style:{width:"100%",height:"100%"},defaultCenter:{lat:o,lng:n},defaultZoom:15,gestureHandling:"greedy",disableDefaultUI:!0,children:l.jsx(d,{position:{lat:o,lng:n}})})})})}),Be={header:["heading","header","title"],paragraph:["text","paragraph","description","subtitle","date","time","price"],quote:["quote","note"],button:["button","link"],list:["list"],image:["image"],form:["form","signup","quiz","feedback","catering","contest"],map:["map"],table:["table"],faq:["faq"]},Pe=e.memo(e=>{let{blocks:o,onScrollToBottom:n,sendMessage:i}=e;const a=(e,t)=>{var o,n,i,a,r,s;return"display_name"===t?(null==e||null===(a=e.data)||void 0===a||null===(r=a.elements)||void 0===r||null===(s=r.find(e=>e.field===t))||void 0===s?void 0:s.value)||(null==e?void 0:e.display_name):(null===(o=e.data)||void 0===o||null===(n=o.elements)||void 0===n||null===(i=n.find(e=>e.field===t))||void 0===i?void 0:i.value)||null},r=e=>{console.log("🚀 ~ CardPreview ~ block:",e);let r=null==e?void 0:e.outerCss;const s=(e=>{if(!e)return null;const t=e.toLowerCase();for(const[e,o]of Object.entries(Be))if(o.includes(t)||e===t)return e;return null})(null==e?void 0:e.display_type)||e.type,c=e.add_display_name?a(e,"display_name")||"Unnamed Block":null,d=["image","map","form"].includes(s),u=e=>{let t=a(e,"url");t?window.open(a(e,"url"),"_blank","noopener,noreferrer"):(e=>{e||(i("I choose this: ".concat(JSON.stringify(o)),!0),null==n||n())})(t)},p=()=>{switch(s){case"header":return l.jsx("h1",{style:F(F(F({},fe),e.css[s]),{},{margin:0}),className:"text-2xl font-bold",children:a(e,"text")||(null==e?void 0:e.value)});case"paragraph":return l.jsx("p",{style:F(F(F({},be),e.css[s]),{},{paddingInline:"8px",margin:0}),className:"text-gray-700",dangerouslySetInnerHTML:{__html:a(e,"text")||(null==e?void 0:e.value)}});case"list":return l.jsx("ul",{style:F(F(F({},we),e.css[s]),{},{margin:0}),className:"list-disc pl-5",children:(a(e,"items")||[]).map((e,t)=>l.jsx("li",{className:"text-gray-700",children:e},t))});case"quote":return l.jsx("blockquote",{style:F(F(F({},ve),e.css[s]),{},{margin:0}),className:"border-l-4 border-gray-300 pl-4 italic text-gray-600",children:a(e,"text")||(null==e?void 0:e.value)});case"button":return l.jsx(t.Button,{variant:"contained",style:F(F(F({marginBottom:"10px"},Se),e.css[s]),{},{width:"90%",margin:0}),onClick:()=>u(e),className:"bg-blue-500 hover:bg-blue-700 text-white",children:a(e,"text")||(null==e?void 0:e.display_name)});case"image":let o=a(e,"files")||[];if(!o.length){o=(Array.isArray(null==e?void