react-chatbot-koodums
Version:
A customizable chatbot component for React applications
1 lines • 113 kB
JavaScript
import e,{useEffect as t,useState as o,useRef as n,useCallback as i,createContext as a,useContext as r}from"react";import{Stack as l,Box as s,Typography as c,Button as d,TextField as p,Paper as u,Icon as h,Fab as m,Skeleton as g,Alert as y,CircularProgress as b,Modal as f,FormControl as x,InputLabel as v,Select as w,MenuItem as C,FormHelperText as S,FormControlLabel as k,Checkbox as I,Slide as F,IconButton as R,Tooltip as T}from"@mui/material";import A from"@mui/icons-material/Lightbulb";import O from"@mui/material/Paper";import N from"@mui/material/InputBase";import P from"@mui/material/IconButton";import _ from"@mui/icons-material/Send";import{isMobile as z}from"react-device-detect";import{jsx as M,jsxs as E,Fragment as D}from"react/jsx-runtime";import{v4 as B}from"uuid";import L from"use-sound";import j from"react-helmet";import U from"@mui/icons-material/AddCircle";import{Stack as W}from"@mui/system";import V from"react-div-100vh";import{CloseOutlined as H,Star as q,StarHalf as G,StarBorder as Y,ArrowBack as J,Circle as Q,MapOutlined as K,Flight as Z}from"@mui/icons-material";import{Swiper as X,SwiperSlide as $}from"swiper/react";import{Pagination as ee,Navigation as te}from"swiper";import"swiper/css";import"swiper/css/pagination";import"swiper/css/navigation";import{APIProvider as oe,Map as ne,Marker as ie}from"@vis.gl/react-google-maps";import"react-dom/client";import{useFormik as ae}from"formik";import*as re from"yup";import"@mui/icons-material/Close";import{InlineWidget as le}from"react-calendly";import se from"react-youtube";function ce(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 de(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 pe(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?de(Object(o),!0).forEach(function(t){ce(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):de(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}function ue(e){let{onSendMessage:o,sending:n,inputRef:i,helperText:a,backgroundColor:r,hasQuickReply:s}=e;const c=()=>{const e=i.current.value;i.current.value="",""===e||n||o(e)};return t(()=>{var e;z||n||(null===(e=i.current)||void 0===e||e.focus())},[n]),M(l,{direction:"row",justifyContent:"center",sx:{background:r||"#FFFFFF",width:"100%",bottom:"0px",paddingTop:"5px",paddingBottom:"5px"},children:E(O,{elevation:0,component:"form",sx:{p:"2px 4px",display:"flex",alignItems:"center",width:"calc(100% - ".concat(s?25:48,"px)"),minHeight:"48px",maxWidth:800,borderRadius:"20px",boxShadow:"0px 4px 4px rgba(0, 0, 0, 0.1)"},children:[M(N,{disabled:n,inputRef:i,sx:{ml:1,flex:1,fontFamily:"Google Sans",fontWeight:"300",fontSize:"14px"},placeholder:a,inputProps:{"aria-label":a},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),c())}}),M(P,{disabled:n,onClick:c,color:"primary",sx:{p:"10px"},"aria-label":"send",children:M(_,{sx:{color:n?"#DADCE0":"#292929"}})})]})})}const he=(e,t)=>{t(e),document.cookie="chatUserEmail=".concat(e.email,"; SameSite=None; Secure"),document.cookie="chatUserName=".concat(e.name,"; SameSite=None; Secure")},me=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return{id:B(),type:"bot",author:"0",content:e,isTesting:t}},ge=e=>new Promise(t=>setTimeout(t,e));function ye(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 be(e,t){const o=e.match(/^SAY: (.*?)\s*ACT: ([\s\S]*)$/m);if(o){const[e,[t,n]]=[o[1],ye(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 fe=localStorage.getItem("apiKey");async function xe(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(!fe)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":fe},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 ve(e){let{context:t,params:o}=e,{urlPrefix:n,apiVersion:i,streamResults:a,setDisplayMessageList:r,setSending:l,language:s,playSoundOnResponse:c,playSound:d,playSound2:p,playSound3:u,playSound4:h,speakResponse:m,audioRef:g,globalData:y,printResponse:b,printGenericResponse:f}=t;console.log("🚀 ~ sendMessage ~ apiVersion:",i),a=!1;const{agentId:x,phrase:v,event:w,session:C,chatUserEmail:S,chatUserName:k,test:I,history:F,guestInfo:R}=o;try{y.debug&&console.log("#######Phrase = "+v);const e=n+"/api"+i+"/sendMessage/";if(!fe)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":fe},body:JSON.stringify({agentId:x,msg:v,session:C,chatUserEmail:S&&S.length>0?S:"",chatUserName:k&&k.length>0?k:"",stream:a,history:F?F.length>20?F.slice(-20):F:[],guestInfo:R||{}})});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:l}=await e.read();if(t){var T,A;if(a=n.decode(t,{stream:!0}),","==a[(null===(T=a)||void 0===T?void 0:T.length)-1])a=a.slice(0,(null===(A=a)||void 0===A?void 0:A.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=pe(pe({},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?pe(pe({},t),{},{content:(t.content?t.content:"")+(null!=e&&e.content?null==e?void 0:e.content:""),usage:e.usage}):t):[...t,e]))}}i=l}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)),c&&("beep1"===c&&d(),"beep2"===c&&p(),"beep3"===c&&u(),"beep4"===c&&h()),m){let t=e.content;if("string"==typeof t&&t.startsWith("SAY:")){t=be(t).content.say}"string"==typeof t&&(t=t.replace(/<[^>]*>/g,""),await xe(t,g))}if("string"==typeof e.content&&e.content.indexOf("SAY:")>=0){var O,N,P,_,z,M,E,D,L,j,U,W;console.log("IN HERE SAY ::",JSON.stringify(e.content));let t=be(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 V=t.content.say;t.content.act.params.region=V.substring(V.indexOf(" in ")+4)}if(t.content.act&&"display_widget"===(null===(O=t.content.act)||void 0===O?void 0:O.function_name))t.content.say.includes("{speak}")&&(t.content.say=t.content.say.replace("{speak}",""),xe(t.content.say,g)),b(t.content.say,s,"bot",!1),f("richContent",t.content.act.params,s);else if(t.content.act&&"display_image"===(null===(N=t.content.act)||void 0===N?void 0:N.function_name))b(t.content.say,s,"bot",!1),f("richContent",{type:"image",height:"200px",rawUrl:t.content.act.params.rawUrl},s);else if(t.content.act&&"display_email"===(null===(P=t.content.act)||void 0===P?void 0:P.function_name)){var H;b(t.content.say,s,"bot",!1),console.log("WHAT IS THIS - display_email ::",t.content.act.params),f("richContent",{type:"email",contactValue:t.content.act.params.contactValue,buttonText:t.content.act.params.buttonText,message:null!==(H=t.content.act.params.message)&&void 0!==H?H:""},s)}else if(t.content.act&&"display_call"===(null===(_=t.content.act)||void 0===_?void 0:_.function_name))b(t.content.say,s,"bot",!1),console.log("WHAT IS THIS - display_email ::",t.content.act.params),f("richContent",{type:"call",contactValue:t.content.act.params.contactValue,buttonText:t.content.act.params.buttonText},s);else if(t.content.act&&"display_whatsApp"===(null===(z=t.content.act)||void 0===z?void 0:z.function_name)){var q;b(t.content.say,s,"bot",!1),console.log("WHAT IS THIS - display_whatsApp ::",t.content.act.params),f("richContent",{type:"whatsApp",contactValue:t.content.act.params.contactValue,buttonText:t.content.act.params.buttonText,message:null!==(q=t.content.act.params.message)&&void 0!==q?q:""},s)}else if(t.content.act&&"display_table"===(null===(M=t.content.act)||void 0===M?void 0:M.function_name))b(t.content.say,s,"bot",!1),f("richContent",{type:"table",title:t.content.act.params.title,headers:t.content.act.params.headers,rows:t.content.act.params.rows},s);else if(t.content.act&&"display_cities"===(null===(E=t.content.act)||void 0===E?void 0:E.function_name)){b(t.content.say,s,"bot",!1);for(let e=0;e<t.content.act.params.cities.length;e++)await ge(2e3),f("citycard",{region:t.content.act.params.region,name:t.content.act.params.cities[e]},s)}else if(t.content.act&&"display_places"===(null===(D=t.content.act)||void 0===D?void 0:D.function_name)){b(t.content.say,s,"bot",!1);for(let e=0;e<t.content.act.params.places.length;e++)await ge(2e3),f("placecard",{city:t.content.act.params.city,name:t.content.act.params.places[e]},s)}else if(t.content.act&&"display_hotels"===(null===(L=t.content.act)||void 0===L?void 0:L.function_name)){if(b(t.content.say,s,"bot",!1),t.content.act.params.hotels)for(let e=0;e<t.content.act.params.hotels.length;e++)await ge(2e3),f("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},s);if(t.content.act.params.cities)for(let e=0;e<t.content.act.params.cities.length;e++)await ge(2e3),f("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},s)}else b(t.content.say,s,"bot",!1);if(l(!1),"string"==typeof(null==t||null===(j=t.content)||void 0===j?void 0:j.say)&&(null==t||null===(U=t.content)||void 0===U||null===(W=U.say)||void 0===W?void 0:W.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:B(),type:"email_form",author:"0",content:v};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 we="https://agent-dev.genaisolutions.ai",Ce={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(we),"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(we),"https://calendly.com","https://www.youtube.com"]},Se=e=>{var t=Ce.CONNECT_SOURCES.join(" ")+" ";return e.allowedURLs&&(t=t.concat(e.allowedURLs.join(" "))),M(D,{children:e.allowedURLs&&M(D,{children:E(j,{children:[M("meta",{httpEquiv:"Content-Security-Policy",content:"\n default-src 'self';\n img-src ".concat(Ce.IMAGE_SOURCES.join(" "),";\n connect-src ").concat(t,";\n media-src ").concat(Ce.MEDIA_SOURCES.join(" "),";\n script-src ").concat(Ce.SCRIPT_SOURCES.join(" "),";\n style-src ").concat(Ce.STYLE_SOURCES.join(" "),";\n frame-src ").concat(Ce.FRAME_SOURCES.join(" "),";\n frame-ancestors *;\n ")}),M("meta",{httpEquiv:"Cross-Origin-Opener-Policy",content:"same-origin-allow-popups"})]})})})},ke=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"},Ie=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 Fe=(e,t)=>{const o=Ie(t);return M("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,l)=>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>"):l?'<i style="font-weight: bold; color: '.concat(o,'; margin-inline: 2px;">').concat(l,"</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>")),M("p",{style:{margin:0},dangerouslySetInnerHTML:{__html:n}})})()})},Re=e=>{let{headerColor:t,headerFontColor:o,agentName:n}=e;return M(s,{sx:{paddingTop:"10px",width:"100%",height:"50px",backgroundColor:t,overflowY:"auto"},alignItems:"center",justifyContent:"center",display:"flex",margin:"auto",children:M(c,{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:o,children:n})})},Te=e=>{let{backgroundColor:t,companyName:o,appVersion:n,environment:i}=e;return E(s,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"1.5em",gap:"3px",backgroundColor:t},children:[M(c,{sx:{fontSize:"1.5em",color:t?Ie(t):"#292929",lineHeight:1},children:"©"}),E(c,{sx:{textAlign:"center",fontSize:"0.75em",color:t?Ie(t):"#292929",fontFamily:"Google Sans",lineHeight:1},children:[o," 2025, Version ",n," ","dev"===i||"test"===i?i:""]})]})},Ae=e=>{let{isOpen:t,onClose:o,children:n}=e;return M("div",{className:"modal-overlay",children:M("div",{className:"modal-content",children:n})})},Oe={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"}},Ne={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"}},Pe={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"}},_e=e=>{let{backgroundColor:t,isModalOpen:o,setModalOpen:n,privacyPolicy:i,handleAcceptPrivacyPolicy:a}=e;return M(s,{sx:{width:"100%",height:"inherit",overflowY:"auto",backgroundColor:t},children:M(Ae,{open:o,setOpen:()=>n(!1),children:E("div",{style:Pe.container,children:[M("h4",{dangerouslySetInnerHTML:{__html:i},style:Pe.customLineStyle}),M("h3",{style:Pe.desclaimerLineStyle,children:"Do you accept our privacy policy?"}),E("div",{style:{display:"flex",justifyContent:"center",gap:20},children:[M(d,{sx:{padding:"10px 20px",backgroundColor:"#4CAF50",color:"#fff",border:"10px",borderRadius:"10px",cursor:"pointer",fontSize:"16px","&:hover":{backgroundColor:"#45a049"}},onClick:()=>a(!0),children:"Yes"}),M(d,{sx:{padding:"10px 20px",backgroundColor:"#F44336",color:"#fff",border:"none",borderRadius:"10px",cursor:"pointer",fontSize:"16px","&:hover":{backgroundColor:"#d32f2f"}},onClick:()=>a(!1),children:"No"})]})]})})})},ze=e=>{let{backgroundColor:t,isModalOpen:o,setModalOpen:n,askForNamePhrase:i,formData:a,handleFormDataInputChange:r,handleFormSubmit:l,error:u}=e;return M(s,{sx:{width:"100%",height:"inherit",overflowY:"auto",backgroundColor:t},children:M(Ae,{open:o,setOpen:()=>n(!1),children:E("div",{style:Ne.formContainer,children:[M(c,{variant:"h6",sx:{textAlign:"center",marginBottom:"15px",color:"#292929"},children:i||"Enter Your Details"}),E("form",{onSubmit:l,children:[E("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"15px",color:"#292929"},children:[M(c,{component:"label",sx:{fontWeight:"bold",marginRight:"5px"},children:"Name:"}),M(p,{type:"text",name:"name",value:a.name,onChange:r,sx:Ne.inputField,placeholder:"Enter your name",variant:"outlined",size:"small"})]}),E("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"15px",color:"#292929"},children:[M(c,{component:"label",sx:{fontWeight:"bold",marginRight:"5px"},children:"Email:"}),M(p,{type:"email",name:"email",value:a.email,onChange:r,sx:Ne.inputField,placeholder:"Enter your email",variant:"outlined",size:"small"})]}),u&&M(c,{sx:Ne.errorStyle,color:"error",children:u}),M(d,{type:"submit",sx:Ne.submitButton,variant:"contained",children:"Submit"})]})]})})})},Me=e=>{let{headerColor:t,headerFontColor:o,agentName:n,backgroundColor:i,disabledMessage:a}=e;return E(l,{direction:"column",sx:{overflowY:"hidden",marginTop:"0px",height:"100%"},children:[M(s,{sx:{paddingTop:"10px",width:"100%",height:"50px",backgroundColor:t,overflowY:"auto"},alignItems:"center",justifyContent:"center",display:"flex",margin:"auto",children:M(c,{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:o,children:n})}),M(s,{sx:{width:"100%",flex:1,overflowY:"auto",backgroundColor:i},children:M("div",{dangerouslySetInnerHTML:{__html:a},style:{padding:"10px",fontSize:"16px",textAlign:"center",color:ke(i)}})})]})};function Ee(e){const{children:t,style:o}=e;return M(u,{elevation:0,sx:o,children:t})}const De=e=>{let{content:o,type:n,scrollToBottom:i,width:a="90%",maxWidth:r="400px",borderRadius:l="10px",altText:s="Rich content image"}=e;return t(()=>{i&&i()},[]),M("a",{href:o.link,target:"_blank",rel:"noopener noreferrer",style:{marginTop:"10px",display:"flex",justifyContent:o.isFirstImage?"center":"start"},children:M("img",{src:(c=o.rawUrl,c.startsWith("https://")?c:"".concat("https://agent-dev.genaisolutions.ai").concat(o.rawUrl)),style:{width:"90%",height:"auto",display:"block",borderRadius:l},alt:s})});var c};function Be(e){let{onClick:o,children:n,scrollToBottom:i}=e;return t(()=>{i&&i()}),M(u,{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:o&&o,children:E(W,{direction:"row",spacing:.5,children:[M(h,{children:M("svg",{style:{marginBottom:"4px"},xmlns:"http://www.w3.org/2000/svg",width:"10",height:"14",viewBox:"0 0 10 14",fill:"none",children:M("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"})})}),M("div",{style:{fontFamily:"Google Sans",fontSize:"14px",lineHeight:"18px"},children:n})]})})}const Le=e=>{var o;let{content:n,index:i,scrollToBottom:a,listStyle:r="none",itemSpacing:l="16px",maxWidth:d="400px"}=e;return t(()=>{a&&a()},[]),E(s,{sx:{width:"100%",marginBottom:"0%",marginTop:"10px"},children:[M(c,{sx:{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:"black"},children:n.title}),M(c,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:"black"},children:n.subtitle}),M(s,{component:"ul",sx:{listStyleType:r,paddingLeft:"0"},children:null===(o=n.options)||void 0===o?void 0:o.map((e,t)=>E(s,{sx:{margin:"".concat(l," 0"),display:"flex",flexDirection:"column",alignItems:"flex-start"},children:[M("img",{width:"100%",style:{maxWidth:d},src:e.url,alt:e.text||"Picture list item"}),M(c,{sx:{fontFamily:"Google Sans",fontSize:"16px",color:"black",marginTop:"8px"},children:e.text})]},t))})]},i)};function je(e){const{orig_lat:i,orig_lon:a,onClose:r,lat:c,lon:d,scrollToBottom:p}=e,[u,h]=o(null),g=n(null);return t(()=>{const e=new google.maps.LatLng(i,a);if(null!==g.current){const t=new google.maps.Map(g.current,{mapId:"69756bebb3f7f821",center:e,zoom:16});new google.maps.Marker({position:e}).setMap(t),console.log("MapCard useEffect "),h(t)}p&&p()},[]),M(l,{width:"100%",height:"100%",children:E(l,{width:"100%",height:"100%",position:"relative",sx:{top:0,left:0,zIndex:1e3,height:"300px"},justifyContent:"space-between",children:[M(l,{direction:"row",justifyContent:"space-between",alignItems:"center",alignContent:"center",sx:{margin:"20px",zIndex:1e3,color:"white"},children:M(m,{sx:{background:"rgba(0,0,0,0.4)"},onClick:()=>{r&&r()},children:M(H,{sx:{color:"#FFFFFF"}})})}),M(s,{position:"absolute",width:"100%",height:"100%",children:M(s,{width:"100%",height:"100%",ref:g,id:"map"})})]})})}const Ue=e=>{var o;let{content:n,index:i,scrollToBottom:a,textColor:r="black"}=e;return t(()=>{a&&a()},[]),E(s,{sx:{width:"100%",marginBottom:"0%",marginTop:"10px"},children:[M(c,{sx:{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:r},children:n.title}),M(c,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:r},children:n.subtitle}),M("ul",{children:null===(o=n.options)||void 0===o?void 0:o.map((e,t)=>M(s,{component:"li",sx:{margin:"8px 0",color:r},children:e.text},t))})]},i)},We=e=>{var o,n;let{content:i,index:a,scrollToBottom:r}=e;return t(()=>{r&&r()},[]),E(s,{sx:{width:"100%",marginBottom:"0%",marginTop:"10px"},children:[M("a",{href:i.actionLink,target:"_blank",rel:"noopener noreferrer",children:M("img",{width:"100%",style:{maxWidth:"400px"},height:i.height,src:null===(o=i.image)||void 0===o||null===(n=o.src)||void 0===n?void 0:n.rawUrl,alt:i.title||"Rich content image"})}),M(c,{sx:{fontFamily:"Google Sans",fontWeight:"bold",fontSize:"24px",color:"black"},children:i.title}),M(c,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:"black"},children:i.subtitle})]},a)},Ve=e=>{let{content:o,index:n,name:i,onSlideChange:a,scrollToBottom:r,maxWidth:d="400px",width:p="80%"}=e;const u=o.photos||[],h=u.length>0;return t(()=>{r&&r()},[]),E(X,{style:{width:p,maxWidth:d,height:"auto",backgroundColor:"black",marginTop:"10px"},slidesPerView:1,modules:[ee,te],navigation:{nextEl:".swiper-button-next",prevEl:".swiper-button-prev"},onSlideChange:a,children:[h?u.map((e,t)=>M($,{children:E(s,{width:"100%",height:"100%",children:[M(s,{width:"100%",height:"100%",children:M("img",{height:"100%",width:"100%",src:e,style:{objectFit:"cover",objectPosition:"center center"},alt:"Slide ".concat(t+1)})}),M(s,{width:"100%",height:"100%",sx:{position:"absolute",marginTop:"200px",zIndex:100},children:E(l,{direction:"column",color:"white",spacing:1.5,p:3,children:[M(c,{variant:"h4",fontFamily:"Google Sans",fontSize:"24px",fontWeight:"300",children:i}),M(c,{variant:"h7",fontFamily:"Google Sans",fontSize:"14px"})]})})]})},t)):M($,{children:E(s,{width:"100%",height:"100%",children:[M(s,{width:"100%",height:"100%",children:M(g,{height:"100%",width:"100%"})}),M(s,{width:"100%",height:"100%",sx:{position:"absolute",marginTop:"calc(".concat(window.innerHeight,"px * 0.4)"),zIndex:100},children:E(l,{direction:"column",color:"white",spacing:1.5,p:3,children:[M(c,{variant:"h4",fontFamily:"Google Sans",children:i}),M(c,{variant:"h7",fontFamily:"Google Sans"})]})})]})}),M(s,{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"}}}),M(s,{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"}}})]},n)},He=e=>{let{data:o,scrollToBottom:n,foregroundColor:i="#fff",backgroundColor:a="#000",backgroundColorLight:r,metadata:l}=e;const{header:s={},content:c={},border:d={},headerBackgroundColor:p="#ccc",rowAlternateColor:u=!0,alternateRowColors:h=[a,r],borderRadius:m="12px"}=l,g={width:"100%",borderCollapse:"collapse",border:"".concat((null==d?void 0:d.width)||"1px"," solid ").concat((null==d?void 0:d.color)||i),borderRadius:m,overflow:"hidden",backgroundColor:a,color:i},y={backgroundColor:p,color:(null==s?void 0:s.color)||"black",fontWeight:(null==s?void 0:s.fontWeight)||"bold",fontStyle:(null==s?void 0:s.fontStyle)||"normal",fontSize:(null==s?void 0:s.fontSize)||"16px",padding:"10px",border:"".concat(d.width||"1px"," solid ").concat(d.color||i)},b={color:(null==c?void 0:c.color)||i,fontWeight:(null==c?void 0:c.fontWeight)||"normal",fontStyle:(null==c?void 0:c.fontStyle)||"normal",fontSize:(null==c?void 0:c.fontSize)||"14px",padding:"10px",borderBottom:"".concat(d.width||"1px"," solid ").concat(d.color||i)};return t(()=>{n&&n()},[]),E("div",{children:[M("h2",{style:{color:i},children:o.title}),M("div",{style:g,children:E("table",{style:g,children:[M("thead",{children:M("tr",{children:o.headers.map((e,t)=>M("th",{style:y,children:e},t))})}),M("tbody",{children:o.rows.map((e,t)=>{const n=u?h[t%h.length]:a;return M("tr",{style:{backgroundColor:n},children:o.headers.map((t,o)=>M("td",{style:b,children:e[t]},o))},t)})})]})})]})},qe=import.meta.env.VITE_GOOGLE_MAPS_API_KEY,Ge={primary:"'Google Sans', Roboto, sans-serif",size:{title:"0.95rem",subtitle:"1rem",body:"1rem"}},Ye={primary:"#007BFF",secondary:"#28a745",text:"#292929",muted:"#555",background:"#F5F5F5",card:"#DDDDDD"},Je={xs:"3px",sm:"6px",md:"8px"},Qe="6px",Ke="0 1px 3px rgba(0, 0, 0, 0.08)",Ze=e=>{let{rating:t}=e;const o=[];for(let e=0;e<5;e++)e<Math.floor(t)?o.push(M(q,{sx:{color:"#FFD700",fontSize:18}},e)):e<t?o.push(M(G,{sx:{color:"#FFD700",fontSize:18}},e)):o.push(M(Y,{sx:{color:"#FFD700",fontSize:18}},e));return M(s,{sx:{display:"flex",gap:Je.xs},children:o})},Xe=e=>{let{item:n}=e;console.log("🚀 ~ MenuItem ~ item:",n);const{display_name:i,value:a,display_type:r}=n,[l,s]=o(0);t(()=>{if("map_photo"===r&&Array.isArray(a)&&a.length>1){const e=setInterval(()=>{s(e=>(e+1)%a.length)},3e3);return()=>clearInterval(e)}},[r,a]);const c={width:"100%",maxWidth:"300px",margin:"".concat(Je.sm," auto"),boxSizing:"border-box"},d={width:"100%",maxWidth:"300px",minWidth:"300px",height:"140px",position:"relative",display:"block",overflow:"hidden",boxSizing:"border-box"},p={width:"100%",height:"140px",objectFit:"cover",borderRadius:Qe,display:"block",boxSizing:"border-box"},u={position:"absolute",top:"50%",transform:"translateY(-50%)",background:"rgba(0, 0, 0, 0.6)",color:"white",border:"none",padding:Je.xs,cursor:"pointer",fontSize:"14px",borderRadius:"3px",zIndex:1},h=Array.isArray(a)?a:[],m=e=>"map_photo"===r?"https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=".concat(e,"&key=").concat(qe):e;switch(r){case"title":return M("h3",{style:{color:Ye.text,fontWeight:600,margin:Je.sm,fontFamily:Ge.primary,boxSizing:"border-box"},children:a});case"rating":return M("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",margin:Je.sm,boxSizing:"border-box"},children:M(Ze,{rating:a})});case"subtitle":return M("p",{style:{color:Ye.muted,fontSize:Ge.size.subtitle,margin:Je.xs,fontFamily:Ge.primary,boxSizing:"border-box"},children:a});case"description":return M("p",{style:{color:Ye.text,fontSize:Ge.size.body,margin:Je.xs,fontFamily:Ge.primary,boxSizing:"border-box"},children:a});case"price":case"text":return E("p",{style:{color:Ye.primary,fontSize:Ge.size.subtitle,fontWeight:500,margin:0,fontFamily:Ge.primary,boxSizing:"border-box",textTransform:"capitalize"},children:[i," : ",a]});case"link":return M("a",{href:a,target:"_blank",rel:"noopener noreferrer",style:{background:Ye.primary,color:"white",padding:"".concat(Je.sm),borderRadius:Qe,textDecoration:"none",display:"inline-block",fontSize:Ge.size.body,fontFamily:Ge.primary,boxSizing:"border-box",marginBottom:Je.sm},children:i});case"image":case"icon":return M("img",{loading:"lazy",src:a,alt:i||"menu item",style:{width:"100%",height:"100px",objectFit:"cover",borderRadius:Qe,margin:Je.sm,boxSizing:"border-box",alignSelf:"center"}});case"map_photo":case"photo":if("string"==typeof a){const e=m(a);return M("img",{loading:"lazy",src:e,alt:i||"menu item",style:{width:"100%",height:"100px",objectFit:"contain",borderRadius:Qe,margin:Je.sm,boxSizing:"border-box"}})}if(Array.isArray(a)){const e=m(a[l]);return E("div",{style:c,children:[M("div",{style:{display:"none"},children:h.map((e,t)=>M("img",{src:m(e),alt:"",loading:"lazy"},t))}),E("div",{style:d,children:[M("button",{style:pe(pe({},u),{},{left:Je.xs}),onClick:()=>s((l-1+a.length)%a.length),children:"❮"}),M("img",{loading:"lazy",src:e,alt:i||"menu item",style:p}),M("button",{style:pe(pe({},u),{},{right:Je.xs}),onClick:()=>s((l+1)%a.length),children:"❯"})]})]})}return null;default:return null}},$e=e=>{let{menu:t,action_type:o,sendMessage:n,onScrollToBottom:i}=e;return M("div",{children:null==t?void 0:t.map((e,t)=>{var o,a;const r=Number(null===(o=e.find(e=>"latitude"===(null==e?void 0:e.display_type)))||void 0===o?void 0:o.value),l=Number(null===(a=e.find(e=>"longitude"===(null==e?void 0:e.display_type)))||void 0===a?void 0:a.value);return E("div",{style:{backgroundColor:Ye.card,borderRadius:Qe,padding:Je.md,boxShadow:Ke,marginBottom:Je.sm,width:"100%",maxWidth:"340px !important",boxSizing:"border-box",display:"flex",flexDirection:"column",gap:Je.xs},children:[null==e?void 0:e.map((e,t)=>M(Xe,{item:e},t)),r&&l?M("div",{style:{display:"flex",justifyContent:"center",marginBottom:Je.sm},children:M(ne,{style:{width:"100%",height:"15vh",borderRadius:"20px"},defaultCenter:{lat:r,lng:l},defaultZoom:15,gestureHandling:"greedy",disableDefaultUI:!0,children:M(ie,{position:{lat:r,lng:l}})})}):null,M(d,{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||(n("I choose this: ".concat(JSON.stringify(e)),!0),null==i||i())})(e),sx:{backgroundColor:Ye.primary,color:"white",padding:"".concat(Je.xs," ").concat(Je.sm),borderRadius:Qe,fontSize:Ge.size.body,fontFamily:Ge.primary,textTransform:"none","&:hover":{backgroundColor:"#0056b3"},boxSizing:"border-box"},children:"Choose"})]},t)})})},et=e=>{var t,o,n,i,a,r,l,s,c;let{event:d}=e;const p=null===(t=d.find(e=>"title"===e.display_type))||void 0===t?void 0:t.value,u=null===(o=d.find(e=>"image"===e.display_type))||void 0===o?void 0:o.value,h=null===(n=d.find(e=>"date"===e.display_type))||void 0===n?void 0:n.value,m=null===(i=d.find(e=>"time"===e.display_type))||void 0===i?void 0:i.value,g=null===(a=d.find(e=>"subtitle"===e.display_type))||void 0===a?void 0:a.value,y=null===(r=d.find(e=>"location"===e.display_type))||void 0===r?void 0:r.value,b=null===(l=d.find(e=>"card_body"===e.display_type))||void 0===l?void 0:l.value,f=d.find(e=>"link"===e.display_type),x=null===(s=d.find(e=>"latitude"===e.display_name))||void 0===s?void 0:s.value,v=null===(c=d.find(e=>"longitude"===e.display_name))||void 0===c?void 0:c.value;return E("div",{style:{display:"flex",alignItems:"center",width:"90%",backgroundColor:Ye.card,borderRadius:Qe,padding:Je.sm,boxShadow:Ke,gap:Je.sm,boxSizing:"border-box"},children:[M("div",{style:{flex:1,minWidth:"80px"},children:u&&M("img",{loading:"lazy",src:u,alt:p,style:{width:"100%",height:"60px",objectFit:"cover",borderRadius:Qe,boxSizing:"border-box"}})}),E("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:Je.xs,boxSizing:"border-box"},children:[p&&M("h3",{style:{color:Ye.text,fontSize:Ge.size.title,fontWeight:600,margin:0,fontFamily:Ge.primary,boxSizing:"border-box"},children:p}),(h||m)&&E("p",{style:{color:Ye.muted,fontSize:Ge.size.body,margin:0,fontFamily:Ge.primary,boxSizing:"border-box"},children:[h," ",m?"| ".concat(m):""]}),g&&M("p",{style:{color:Ye.muted,fontSize:Ge.size.body,margin:0,fontFamily:Ge.primary,boxSizing:"border-box"},children:g}),y&&M("p",{style:{color:Ye.muted,fontSize:Ge.size.body,margin:0,fontFamily:Ge.primary,boxSizing:"border-box"},children:y}),b&&M("p",{style:{color:Ye.text,fontSize:Ge.size.body,margin:0,fontFamily:Ge.primary,boxSizing:"border-box"},children:b}),E("div",{style:{display:"flex",gap:Je.xs,marginTop:Je.xs,boxSizing:"border-box"},children:[f&&M("a",{href:null==f?void 0:f.value,target:"_blank",rel:"noopener noreferrer",style:{backgroundColor:Ye.primary,color:"white",padding:"".concat(Je.xs," ").concat(Je.sm),borderRadius:Qe,textDecoration:"none",fontSize:Ge.size.body,fontFamily:Ge.primary,boxSizing:"border-box"},children:(null==f?void 0:f.display_name)||"Click here"}),x&&v&&M("button",{onClick:()=>((e,t)=>{window.open("https://www.google.com/maps?q=".concat(e,",").concat(t),"_blank")})(x,v),style:{backgroundColor:Ye.secondary,color:"white",padding:"".concat(Je.xs," ").concat(Je.sm),borderRadius:Qe,border:"none",cursor:"pointer",fontSize:Ge.size.body,fontFamily:Ge.primary,boxSizing:"border-box"},children:"Open in Maps"})]})]})]})},tt=e=>{let{schema:t=[],sendMessage:n}=e;const i=t.reduce((e,t)=>("header"!==t.display_type&&"button"!==t.display_type&&(e[t.path]=""),e),{}),[a,r]=o(i),[l,s]=o(null),c=e=>{const{name:t,value:o}=e.target;r(e=>pe(pe({},e),{},{[t]:o}))},d=e=>{const t=e.target.files[0];if(t){const e=new FileReader;e.onload=()=>{s(e.result),r(t=>pe(pe({},t),{},{image:e.result}))},e.readAsDataURL(t)}};return M("div",{style:{width:"100%",maxWidth:"340px",backgroundColor:Ye.card,padding:Je.md,borderRadius:Qe,boxShadow:Ke,boxSizing:"border-box"},children:M("form",{onSubmit:e=>{e.preventDefault(),n(JSON.stringify(a))},style:{display:"flex",flexDirection:"column",gap:Je.sm,boxSizing:"border-box"},children:t.map(e=>M("div",{children:"header"===e.display_type?M("h2",{style:{fontSize:"1.1rem",fontWeight:600,marginBottom:Je.sm,textAlign:"center",fontFamily:Ge.primary,boxSizing:"border-box"},children:e.display_name}):"text"===e.display_type||"number"===e.display_type?E(D,{children:[M("label",{style:{display:"block",fontWeight:500,marginBottom:Je.xs,fontSize:Ge.size.subtitle,fontFamily:Ge.primary,boxSizing:"border-box"},children:e.display_name}),M("input",{type:e.display_type,name:e.path,value:a[e.path],onChange:c,required:!0,style:{width:"100%",padding:Je.sm,border:"1px solid ".concat(Ye.muted),borderRadius:Qe,fontSize:Ge.size.body,fontFamily:Ge.primary,backgroundColor:Ye.background,boxSizing:"border-box"}})]}):"image"===e.display_type?E(D,{children:[M("label",{style:{display:"block",fontWeight:500,marginBottom:Je.xs,fontSize:Ge.size.subtitle,fontFamily:Ge.primary,boxSizing:"border-box"},children:e.display_name}),M("input",{type:"file",accept:"image/*",onChange:d,required:!0,style:{width:"100%",padding:Je.sm,border:"1px solid ".concat(Ye.muted),borderRadius:Qe,fontSize:Ge.size.body,fontFamily:Ge.primary,backgroundColor:Ye.background,boxSizing:"border-box"}}),l&&M("img",{loading:"lazy",src:l,alt:"Preview",style:{marginTop:Je.sm,width:"60px",height:"60px",objectFit:"cover",borderRadius:Qe,border:"1px solid ".concat(Ye.muted),boxSizing:"border-box"}})]}):"button"===e.display_type?M("button",{type:"submit",style:{width:"100%",backgroundColor:Ye.primary,color:"white",padding:Je.sm,fontSize:Ge.size.subtitle,fontWeight:500,borderRadius:Qe,border:"none",cursor:"pointer",fontFamily:Ge.primary,transition:"background 0.3s",boxSizing:"border-box"},onMouseOver:e=>e.target.style.backgroundColor="#0056b3",onMouseOut:e=>e.target.style.backgroundColor=Ye.primary,children:e.display_name}):null},e.path))})})},ot={fontSize:"24px",fontWeight:"bold",margin:"16px 0",color:"#333",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},nt={fontSize:"16px",margin:"12px 0",color:"#555",lineHeight:"1.5",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},it={fontSize:"18px",fontStyle:"italic",margin:"16px 0",padding:"0 20px",borderLeft:"4px solid #1976d2",color:"#444",fontFamily:"Georgia, serif",transition:"all 0.3s ease"},at={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"},rt={fontSize:"16px",margin:"12px 0",paddingLeft:"20px",color:"#555",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},lt={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"},st={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"},ct={margin:"16px 0",borderRadius:"8px",height:"300px",width:"100%",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1)",transition:"all 0.3s ease"},dt={margin:"16px 0",borderCollapse:"collapse",width:"100%",fontFamily:"Arial, sans-serif",border:"1px solid #dee2e6",transition:"all 0.3s ease"},pt={margin:"16px 0",padding:"8px 0",color:"#555",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},ut={fontSize:"18px",fontWeight:"bold",color:"#333",marginBottom:"8px",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},ht={padding:"8px",backgroundColor:"transparent",borderRadius:"4px",marginBottom:"8px",transition:"all 0.3s ease"},mt=e.memo(e=>{var t;let{images:n=[],caption:a,css:r}=e;const[l,s]=o(0),c=i(()=>{s(e=>0===e?n.length-1:e-1)},[n]),p=i(()=>{s(e=>e===n.length-1?0:e+1)},[n]);return n.length?E("div",{style:{position:"relative",width:"100%",margin:(null==r?void 0:r.margin)||"0 0 16px 0"},children:[E("div",{style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",minHeight:"200px"},children:[M("img",{loading:"lazy",src:null===(t=n[l])||void 0===t?void 0:t.url,alt:"".concat(a||"Image"," ").concat(l+1),style:pe({width:"100%",height:"auto",objectFit:"cover",maxHeight:"400px",borderRadius:"8px"},r)}),M("div",{style:{position:"absolute",left:"12px",top:"50%",transform:"translateY(-50%)",zIndex:10},children:M(d,{variant:"contained",color:"",sx:{background:"#F5F5F5",width:"15px",opacity:.6,color:"black"},onClick:c,disabled:n.length<=1,children:"<"})}),M("div",{style:{position:"absolute",right:"12px",top:"50%",transform:"translateY(-50%)",zIndex:10},children:M(d,{variant:"contained",sx:{background:"#F5F5F5",width:"15px",opacity:.6,color:"black"},onClick:p,disabled:n.length<=1,children:">"})})]}),M("div",{style:{display:"flex",justifyContent:"center",gap:"8px",marginTop:"8px"}})]}):M("div",{style:{color:"#718096"},children:"No images to display"})}),gt=e.memo(e=>{let{lat:n,lng:i,css:a}=e;console.log("🚀 ~ MapBlockComponent ~ lat, lng:",n,i);const[r,l]=o(null);if(t(()=>{import("@vis.gl/react-google-maps").then(e=>{let{APIProvider:t,Map:o,Marker:n}=e;return l({APIProvider:t,Map:o,Marker:n})}).catch(e=>console.error("Error loading Google Maps:",e))},[]),!r)return M("div",{className:"p-4 text-gray-600",children:"Loading map..."});const{APIProvider:s,Map:c,Marker:d}=r;return M("div",{style:pe({width:"100%",height:"300px",borderRadius:"8px",overflow:"hidden",marginBottom:"16px"},a),children:M(s,{apiKey:qe,children:M(c,{style:{width:"100%",height:"100%"},defaultCenter:{lat:n,lng:i},defaultZoom:15,gestureHandling:"greedy",disableDefaultUI:!0,children:M(d,{position:{lat:n,lng:i}})})})})}),yt={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"]},bt=e.memo(e=>{let{blocks:t,onScrollToBottom:o,sendMessage:n}=e;const i=(e,t)=>{var o,n,i,a,r,l;return"display_name"===t?(null==e||null===(a=e.data)||void 0===a||null===(r=a.elements)||void 0===r||null===(l=r.find(e=>e.field===t))||void 0===l?void 0:l.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},a=e=>{console.log("🚀 ~ CardPreview ~ block:",e);let a=null==e?void 0:e.outerCss;const r=(e=>{if(!e)return null;const t=e.toLowerCase();for(const[e,o]of Object.entries(yt))if(o.includes(t)||e===t)return e;return null})(null==e?void 0:e.display_type)||e.type,l=e.add_display_name?i(e,"display_name")||"Unnamed Block":null,s=["image","map","form"].includes(r),u=e=>{let a=i(e,"url");a?window.open(i(e,"url"),"_blank","noopener,noreferrer"):(e=>{e||(n("I choose this: ".concat(JSON.stringify(t)),!0),null==o||o())})(a)},h=()=>{switch(r){case"header":return M("h1",{style:pe(pe(pe({},ot),e.css[r]),{},{margin:0}),className:"text-2xl font-bold",children:i(e,"text")||(null==e?void 0:e.value)});case"paragraph":return M("p",{style:pe(pe(pe({},nt),e.css[r]),{},{paddingInline:"8px",margin:0}),className:"text-gray-700",dangerouslySetInnerHTML:{__html:i(e,"text")||(null==e?void 0:e.value)}});case"list":return M("ul",{style:pe(pe(pe({},rt),e.css[r]),{},{margin:0}),className:"list-disc pl-5",children:(i(e,"items")||[]).map((e,t)=>M("li",{className:"text-gray-700",children:e},t))});case"quote":return M("blockquote",{style:pe(pe(pe({},it),e.css[r]),{},{margin:0}),className:"border-l-4 border-gray-300 pl-4 italic text-gray-600",children:i(e,"text")||(null==e?void 0:e.value)});case"button":return M(d,{variant:"contained",style:pe(pe(pe({marginBottom:"10px"},at),e.css[r]),{},{width:"90%",margin:0}),onClick:()=>u(e),className:"bg-blue-500 hover:bg-blue-700 text-white",children:i(e,"text")||(null==e?void 0:e.display_name)});case"image":let t=i(e,"files")||[];if(!t.length){t=(Array.isArray(null==e?void 0:e.value)?e.value:[null==e?void 0:e.value]).filter(Boolean).map(e=>({url:e}))}return M(mt,{images:t,caption:i(e,"caption"),css:pe(pe({},lt),e.css[r])});case"form":return E("div",{style:pe(pe({},st),e.css[r]),className:"space-y-4",children:[M("p",{className:"font-bold",children:i(e,"title")||"Form"}),(i(e,"fields")||[]).map((e,t)=>M(p,{label:e.label,name:e.name,type:e.field_type||"text",defaultValue:e.default_value||e.value,placeholder:e.placeholder,required:e.required||!1,fullWidth:!0,margin:"normal",className:"bg-white"},t)),M(d,{variant:"contained",color:"primary",className:"bg-blue-500 hover:bg-blue-700 text-white",children:i(e,"submitText")||"Submit"})]});case"map":if(console.log("blockssssssssssssssssssssmap",e,i(e,"lat"),i(e,"lng")),Number(i(e,"lat"))&&i(e,"lng")){let t=Number(i(e,"lat")),o=Number(i(e,"lng"));return M(gt,{lat:t,lng:o,css:pe(pe({},ct),e.css[r])})}return null;case"table":return M("div",{style:{overflow:"auto",width:"200px"},children:E("table",{style:pe(pe({},dt),e