react-chatbot-koodums
Version:
A customizable React chatbot component by Koodums, supporting dynamic conversations and integrations with Google Places, Open AI, and more
1 lines • 131 kB
JavaScript
"use strict";var e=require("react"),t=require("@mui/material"),o=require("@mui/icons-material/Lightbulb"),n=require("@mui/material/Paper"),r=require("@mui/material/InputBase"),i=require("@mui/material/IconButton"),a=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"),m=require("react-div-100vh"),g=require("@mui/icons-material"),x=require("swiper/react"),f=require("swiper");require("swiper/css"),require("swiper/css/pagination"),require("swiper/css/navigation");var y=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 T(o){let{onSendMessage:c,sending:d,inputRef:u,helperText:p,backgroundColor:h,hasQuickReply:m}=o;const g=()=>{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(m?25:48,"px)"),minHeight:"48px",maxWidth:800,borderRadius:"20px",boxShadow:"0px 4px 4px rgba(0, 0, 0, 0.1)"},children:[l.jsx(r,{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(),g())}}),l.jsx(i,{disabled:d,onClick:g,color:"primary",sx:{p:"10px"},"aria-label":"send",children:l.jsx(a,{sx:{color:d?"#DADCE0":"#292929"}})})]})})}const R=(e,t)=>{t(e),document.cookie="chatUserEmail=".concat(e.email,"; SameSite=None; Secure"),document.cookie="chatUserName=".concat(e.name,"; SameSite=None; Secure")},O=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}},E=e=>new Promise(t=>setTimeout(t,e));function A(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 r of e)"{"!==r&&"["!==r||o++,"}"!==r&&"]"!==r||o--,","===r&&0===o?(t.push(n.trim()),n=""):n+=r;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],A(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: ",""),"")}async function _(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{const o=await fetch("/api/v1/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e})});if(!o.ok)throw new Error("HTTP error! status: ".concat(o.status));const n=await o.blob(),r=URL.createObjectURL(n);t.current.src=r,t.current.play()}catch(e){console.error("Error fetching TTS:",e)}}async function N(e){let{context:t,params:o}=e,{urlPrefix:n,apiVersion:r,streamResults:i,setDisplayMessageList:a,setSending:s,language:l,playSoundOnResponse:d,playSound:u,playSound2:p,playSound3:h,playSound4:m,speakResponse:g,audioRef:x,globalData:f,printResponse:y,printGenericResponse:b}=t;console.log("🚀 ~ sendMessage ~ apiVersion:",r),i=!1;const{agentId:v,phrase:S,event:w,session:j,chatUserEmail:C,chatUserName:k,test:I,history:T,guestInfo:R}=o;try{f.debug&&console.log("#######Phrase = "+S);const e=n+"/api"+r+"/sendMessage/";f.debug&&console.log(e);const t=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:v,msg:S,session:j,chatUserEmail:C&&C.length>0?C:"",chatUserName:k&&k.length>0?k:"",stream:i,history:T?T.length>20?T.slice(-20):T:[],guestInfo:R||{}})});if(!t.ok)throw new Error("No Data Available");let o={content:""};if(i){const e=t.body.getReader(),n=new TextDecoder;let r=!1,i="";for(;!r;){const{value:t,done:s}=await e.read();if(t){var O,A;if(i=n.decode(t,{stream:!0}),","==i[(null===(O=i)||void 0===O?void 0:O.length)-1])i=i.slice(0,(null===(A=i)||void 0===A?void 0:A.length)-1);const e=JSON.parse("[".concat(i,"]"));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:"")}),f.debug&&console.log("🚀 ~ sendMessage ~ resultdata.data:",o),a(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]))}}r=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),f.debug&&console.log("#######Data = "+JSON.stringify(e)),d&&("beep1"===d&&u(),"beep2"===d&&p(),"beep3"===d&&h(),"beep4"===d&&m()),g){let t=e.content;if("string"==typeof t&&t.startsWith("SAY:")){t=P(t).content.say}"string"==typeof t&&(t=t.replace(/<[^>]*>/g,""),await _(t,x))}if("string"==typeof e.content&&e.content.indexOf("SAY:")>=0){var N,B,M,D,z,L,U,q,W,V,H,G;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 Y=t.content.say;t.content.act.params.region=Y.substring(Y.indexOf(" in ")+4)}if(t.content.act&&"display_widget"===(null===(N=t.content.act)||void 0===N?void 0:N.function_name))t.content.say.includes("{speak}")&&(t.content.say=t.content.say.replace("{speak}",""),_(t.content.say,x)),y(t.content.say,l,"bot",!1),b("richContent",t.content.act.params,l);else if(t.content.act&&"display_image"===(null===(B=t.content.act)||void 0===B?void 0:B.function_name))y(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 $;y(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!==($=t.content.act.params.message)&&void 0!==$?$:""},l)}else if(t.content.act&&"display_call"===(null===(D=t.content.act)||void 0===D?void 0:D.function_name))y(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===(z=t.content.act)||void 0===z?void 0:z.function_name)){var J;y(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!==(J=t.content.act.params.message)&&void 0!==J?J:""},l)}else if(t.content.act&&"display_table"===(null===(L=t.content.act)||void 0===L?void 0:L.function_name))y(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===(U=t.content.act)||void 0===U?void 0:U.function_name)){y(t.content.say,l,"bot",!1);for(let e=0;e<t.content.act.params.cities.length;e++)await E(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===(q=t.content.act)||void 0===q?void 0:q.function_name)){y(t.content.say,l,"bot",!1);for(let e=0;e<t.content.act.params.places.length;e++)await E(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===(W=t.content.act)||void 0===W?void 0:W.function_name)){if(y(t.content.say,l,"bot",!1),t.content.act.params.hotels)for(let e=0;e<t.content.act.params.hotels.length;e++)await E(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 E(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 y(t.content.say,l,"bot",!1);if(s(!1),"string"==typeof(null==t||null===(V=t.content)||void 0===V?void 0:V.say)&&(null==t||null===(H=t.content)||void 0===H||null===(G=H.say)||void 0===G?void 0:G.length)>0)return t.content.say}else a(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};a(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 B="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(B),"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(B),"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"})]})})})},z=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"},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,t)=>{const o=z(t);return l.jsx("div",{style:{margin:0},children:(()=>{const t=/^(https?:\/\/[^\s<>"']+[^\s<>"'.,!?])$/i;let n=e.replace(/(\*\*(.*?)\*\*|\*(.*?)\*|`(.*?)`|_(.*?)_)/g,(e,n,r,i,a,s)=>r?t.test(r)?'<strong style="color: '.concat(o,';"><a href="').concat(r,'" target="_blank" rel="noopener noreferrer" style="color: ').concat(o,'; text-decoration: underline;">').concat(r,"</a></strong>"):'<strong style="color: '.concat(o,';">').concat(r,"</strong>"):i?'<span style="color: '.concat(o,'; font-weight: 400;">').concat(i,"</span>"):a?'<i style="font-weight: bold; color: '.concat(o,'; margin-inline: 2px;">').concat(a,"</i>"):s?'<i style="font-weight: bold; color: '.concat(o,'; margin-inline: 2px;">').concat(s,"</i>"):e);return n=n.replace(/(^|\s)(https?:\/\/[^\s<>"']+\.(?:png|jpg|jpeg|gif|webp))(?![\w.,!?\/])(?=\s|$|[.,!?])/gi,(e,t,o)=>"".concat(t,'<img src="').concat(o,'" alt="Image" style="max-width: 95%; height: auto; display: block; margin: 10px 0; border-radius: 12px;" />')),n=n.replace(/(^|\s)(https?:\/\/[^\s<>"']+[^\s<>"'.,!?])/gi,(e,t,r)=>n.includes('<img src="'.concat(r,'"'))||n.includes('<a href="'.concat(r,'"'))?e:"".concat(t,'<a href="').concat(r,'" target="_blank" rel="noopener noreferrer" style="color: ').concat(o,'; text-decoration: underline;">').concat(r,"</a>")),l.jsx("p",{style:{margin:0},dangerouslySetInnerHTML:{__html:n}})})()})},q=e=>{let{headerColor:o,headerFontColor:n,agentName:r}=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:r})})},W=e=>{let{backgroundColor:o,companyName:n,appVersion:r,environment:i}=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?L(o):"#292929",lineHeight:1},children:"©"}),l.jsxs(t.Typography,{sx:{textAlign:"center",fontSize:"0.75em",color:o?L(o):"#292929",fontFamily:"Google Sans",lineHeight:1},children:[n," 2025, Version ",r," ","dev"===i||"test"===i?i:""]})]})},V=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})})},H={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"}},G={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"}},Y={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=>{let{backgroundColor:o,isModalOpen:n,setModalOpen:r,privacyPolicy:i,handleAcceptPrivacyPolicy:a}=e;return l.jsx(t.Box,{sx:{width:"100%",height:"inherit",overflowY:"auto",backgroundColor:o},children:l.jsx(V,{open:n,setOpen:()=>r(!1),children:l.jsxs("div",{style:Y.container,children:[l.jsx("h4",{dangerouslySetInnerHTML:{__html:i},style:Y.customLineStyle}),l.jsx("h3",{style:Y.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:()=>a(!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:()=>a(!1),children:"No"})]})]})})})},J=e=>{let{backgroundColor:o,isModalOpen:n,setModalOpen:r,askForNamePhrase:i,formData:a,handleFormDataInputChange:s,handleFormSubmit:c,error:d}=e;return l.jsx(t.Box,{sx:{width:"100%",height:"inherit",overflowY:"auto",backgroundColor:o},children:l.jsx(V,{open:n,setOpen:()=>r(!1),children:l.jsxs("div",{style:G.formContainer,children:[l.jsx(t.Typography,{variant:"h6",sx:{textAlign:"center",marginBottom:"15px",color:"#292929"},children:i||"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:a.name,onChange:s,sx:G.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:a.email,onChange:s,sx:G.inputField,placeholder:"Enter your email",variant:"outlined",size:"small"})]}),d&&l.jsx(t.Typography,{sx:G.errorStyle,color:"error",children:d}),l.jsx(t.Button,{type:"submit",sx:G.submitButton,variant:"contained",children:"Submit"})]})]})})})},Q=e=>{let{headerColor:o,headerFontColor:n,agentName:r,backgroundColor:i,disabledMessage:a}=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:r})}),l.jsx(t.Box,{sx:{width:"100%",flex:1,overflowY:"auto",backgroundColor:i},children:l.jsx("div",{dangerouslySetInnerHTML:{__html:a},style:{padding:"10px",fontSize:"16px",textAlign:"center",color:z(i)}})})]})};function K(e){const{children:o,style:n}=e;return l.jsx(t.Paper,{elevation:0,sx:n,children:o})}const Z=t=>{let{content:o,type:n,scrollToBottom:r,width:i="90%",maxWidth:a="400px",borderRadius:s="10px",altText:c="Rich content image"}=t;return e.useEffect(()=>{r&&r()},[]),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 X(o){let{onClick:n,children:r,scrollToBottom:i}=o;return e.useEffect(()=>{i&&i()}),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:r})]})})}const ee=o=>{var n;let{content:r,index:i,scrollToBottom:a,listStyle:s="none",itemSpacing:c="16px",maxWidth:d="400px"}=o;return e.useEffect(()=>{a&&a()},[]),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:r.title}),l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:"black"},children:r.subtitle}),l.jsx(t.Box,{component:"ul",sx:{listStyleType:s,paddingLeft:"0"},children:null===(n=r.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))})]},i)};function te(o){const{orig_lat:n,orig_lon:r,onClose:i,lat:a,lon:s,scrollToBottom:c}=o,[d,u]=e.useState(null),p=e.useRef(null);return e.useEffect(()=>{const e=new google.maps.LatLng(n,r);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:()=>{i&&i()},children:l.jsx(g.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 oe=o=>{var n;let{content:r,index:i,scrollToBottom:a,textColor:s="black"}=o;return e.useEffect(()=>{a&&a()},[]),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:r.title}),l.jsx(t.Typography,{sx:{fontFamily:"Google Sans",fontSize:"20px",color:s},children:r.subtitle}),l.jsx("ul",{children:null===(n=r.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))})]},i)},ne=o=>{var n,r;let{content:i,index:a,scrollToBottom:s}=o;return e.useEffect(()=>{s&&s()},[]),l.jsxs(t.Box,{sx:{width:"100%",marginBottom:"0%",marginTop:"10px"},children:[l.jsx("a",{href:i.actionLink,target:"_blank",rel:"noopener noreferrer",children:l.jsx("img",{width:"100%",style:{maxWidth:"400px"},height:i.height,src:null===(n=i.image)||void 0===n||null===(r=n.src)||void 0===r?void 0:r.rawUrl,alt:i.title||"Rich content image"})}),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})]},a)},re=o=>{let{content:n,index:r,name:i,onSlideChange:a,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:[f.Pagination,f.Navigation],navigation:{nextEl:".swiper-button-next",prevEl:".swiper-button-prev"},onSlideChange:a,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:i}),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:i}),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"}}})]},r)},ie=t=>{let{data:o,scrollToBottom:n,foregroundColor:r="#fff",backgroundColor:i="#000",backgroundColorLight:a,metadata:s}=t;const{header:c={},content:d={},border:u={},headerBackgroundColor:p="#ccc",rowAlternateColor:h=!0,alternateRowColors:m=[i,a],borderRadius:g="12px"}=s,x={width:"100%",borderCollapse:"collapse",border:"".concat((null==u?void 0:u.width)||"1px"," solid ").concat((null==u?void 0:u.color)||r),borderRadius:g,overflow:"hidden",backgroundColor:i,color:r},f={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||r)},y={color:(null==d?void 0:d.color)||r,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||r)};return e.useEffect(()=>{n&&n()},[]),l.jsxs("div",{children:[l.jsx("h2",{style:{color:r},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:f,children:e},t))})}),l.jsx("tbody",{children:o.rows.map((e,t)=>{const n=h?m[t%m.length]:i;return l.jsx("tr",{style:{backgroundColor:n},children:o.headers.map((t,o)=>l.jsx("td",{style:y,children:e[t]},o))},t)})})]})})]})},ae=(void 0).VITE_GOOGLE_MAPS_API_KEY,se={primary:"'Google Sans', Roboto, sans-serif",size:{title:"0.95rem",subtitle:"1rem",body:"1rem"}},le={primary:"#007BFF",secondary:"#28a745",text:"#292929",muted:"#555",background:"#F5F5F5",card:"#DDDDDD"},ce={xs:"3px",sm:"6px",md:"8px"},de="6px",ue="0 1px 3px rgba(0, 0, 0, 0.08)",pe=e=>{let{rating:o}=e;const n=[];for(let e=0;e<5;e++)e<Math.floor(o)?n.push(l.jsx(g.Star,{sx:{color:"#FFD700",fontSize:18}},e)):e<o?n.push(l.jsx(g.StarHalf,{sx:{color:"#FFD700",fontSize:18}},e)):n.push(l.jsx(g.StarBorder,{sx:{color:"#FFD700",fontSize:18}},e));return l.jsx(t.Box,{sx:{display:"flex",gap:ce.xs},children:n})},he=t=>{let{item:o}=t;console.log("🚀 ~ MenuItem ~ item:",o);const{display_name:n,value:r,display_type:i}=o,[a,s]=e.useState(0);e.useEffect(()=>{if("map_photo"===i&&Array.isArray(r)&&r.length>1){const e=setInterval(()=>{s(e=>(e+1)%r.length)},3e3);return()=>clearInterval(e)}},[i,r]);const c={width:"100%",maxWidth:"300px",margin:"".concat(ce.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:de,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:ce.xs,cursor:"pointer",fontSize:"14px",borderRadius:"3px",zIndex:1},h=Array.isArray(r)?r:[],m=e=>"map_photo"===i?"https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=".concat(e,"&key=").concat(ae):e;switch(i){case"title":return l.jsx("h3",{style:{color:le.text,fontWeight:600,margin:ce.sm,fontFamily:se.primary,boxSizing:"border-box"},children:r});case"rating":return l.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",margin:ce.sm,boxSizing:"border-box"},children:l.jsx(pe,{rating:r})});case"subtitle":return l.jsx("p",{style:{color:le.muted,fontSize:se.size.subtitle,margin:ce.xs,fontFamily:se.primary,boxSizing:"border-box"},children:r});case"description":return l.jsx("p",{style:{color:le.text,fontSize:se.size.body,margin:ce.xs,fontFamily:se.primary,boxSizing:"border-box"},children:r});case"price":case"text":return l.jsxs("p",{style:{color:le.primary,fontSize:se.size.subtitle,fontWeight:500,margin:0,fontFamily:se.primary,boxSizing:"border-box",textTransform:"capitalize"},children:[n," : ",r]});case"link":return l.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{background:le.primary,color:"white",padding:"".concat(ce.sm),borderRadius:de,textDecoration:"none",display:"inline-block",fontSize:se.size.body,fontFamily:se.primary,boxSizing:"border-box",marginBottom:ce.sm},children:n});case"image":case"icon":return l.jsx("img",{loading:"lazy",src:r,alt:n||"menu item",style:{width:"100%",height:"100px",objectFit:"cover",borderRadius:de,margin:ce.sm,boxSizing:"border-box",alignSelf:"center"}});case"map_photo":case"photo":if("string"==typeof r){const e=m(r);return l.jsx("img",{loading:"lazy",src:e,alt:n||"menu item",style:{width:"100%",height:"100px",objectFit:"contain",borderRadius:de,margin:ce.sm,boxSizing:"border-box"}})}if(Array.isArray(r)){const e=m(r[a]);return l.jsxs("div",{style:c,children:[l.jsx("div",{style:{display:"none"},children:h.map((e,t)=>l.jsx("img",{src:m(e),alt:"",loading:"lazy"},t))}),l.jsxs("div",{style:d,children:[l.jsx("button",{style:F(F({},p),{},{left:ce.xs}),onClick:()=>s((a-1+r.length)%r.length),children:"❮"}),l.jsx("img",{loading:"lazy",src:e,alt:n||"menu item",style:u}),l.jsx("button",{style:F(F({},p),{},{right:ce.xs}),onClick:()=>s((a+1)%r.length),children:"❯"})]})]})}return null;default:return null}},me=e=>{let{menu:o,action_type:n,sendMessage:r,onScrollToBottom:i}=e;return l.jsx("div",{children:null==o?void 0:o.map((e,o)=>{var n,a;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===(a=e.find(e=>"longitude"===(null==e?void 0:e.display_type)))||void 0===a?void 0:a.value);return l.jsxs("div",{style:{backgroundColor:le.card,borderRadius:de,padding:ce.md,boxShadow:ue,marginBottom:ce.sm,width:"100%",maxWidth:"340px !important",boxSizing:"border-box",display:"flex",flexDirection:"column",gap:ce.xs},children:[null==e?void 0:e.map((e,t)=>l.jsx(he,{item:e},t)),s&&c?l.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:ce.sm},children:l.jsx(y.Map,{style:{width:"100%",height:"15vh",borderRadius:"20px"},defaultCenter:{lat:s,lng:c},defaultZoom:15,gestureHandling:"greedy",disableDefaultUI:!0,children:l.jsx(y.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||(r("I choose this: ".concat(JSON.stringify(e)),!0),null==i||i())})(e),sx:{backgroundColor:le.primary,color:"white",padding:"".concat(ce.xs," ").concat(ce.sm),borderRadius:de,fontSize:se.size.body,fontFamily:se.primary,textTransform:"none","&:hover":{backgroundColor:"#0056b3"},boxSizing:"border-box"},children:"Choose"})]},o)})})},ge=e=>{var t,o,n,r,i,a,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,m=null===(n=u.find(e=>"date"===e.display_type))||void 0===n?void 0:n.value,g=null===(r=u.find(e=>"time"===e.display_type))||void 0===r?void 0:r.value,x=null===(i=u.find(e=>"subtitle"===e.display_type))||void 0===i?void 0:i.value,f=null===(a=u.find(e=>"location"===e.display_type))||void 0===a?void 0:a.value,y=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:le.card,borderRadius:de,padding:ce.sm,boxShadow:ue,gap:ce.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:de,boxSizing:"border-box"}})}),l.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:ce.xs,boxSizing:"border-box"},children:[p&&l.jsx("h3",{style:{color:le.text,fontSize:se.size.title,fontWeight:600,margin:0,fontFamily:se.primary,boxSizing:"border-box"},children:p}),(m||g)&&l.jsxs("p",{style:{color:le.muted,fontSize:se.size.body,margin:0,fontFamily:se.primary,boxSizing:"border-box"},children:[m," ",g?"| ".concat(g):""]}),x&&l.jsx("p",{style:{color:le.muted,fontSize:se.size.body,margin:0,fontFamily:se.primary,boxSizing:"border-box"},children:x}),f&&l.jsx("p",{style:{color:le.muted,fontSize:se.size.body,margin:0,fontFamily:se.primary,boxSizing:"border-box"},children:f}),y&&l.jsx("p",{style:{color:le.text,fontSize:se.size.body,margin:0,fontFamily:se.primary,boxSizing:"border-box"},children:y}),l.jsxs("div",{style:{display:"flex",gap:ce.xs,marginTop:ce.xs,boxSizing:"border-box"},children:[b&&l.jsx("a",{href:null==b?void 0:b.value,target:"_blank",rel:"noopener noreferrer",style:{backgroundColor:le.primary,color:"white",padding:"".concat(ce.xs," ").concat(ce.sm),borderRadius:de,textDecoration:"none",fontSize:se.size.body,fontFamily:se.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:le.secondary,color:"white",padding:"".concat(ce.xs," ").concat(ce.sm),borderRadius:de,border:"none",cursor:"pointer",fontSize:se.size.body,fontFamily:se.primary,boxSizing:"border-box"},children:"Open in Maps"})]})]})]})},xe=t=>{let{schema:o=[],sendMessage:n}=t;const r=o.reduce((e,t)=>("header"!==t.display_type&&"button"!==t.display_type&&(e[t.path]=""),e),{}),[i,a]=e.useState(r),[s,c]=e.useState(null),d=e=>{const{name:t,value:o}=e.target;a(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),a(t=>F(F({},t),{},{image:e.result}))},e.readAsDataURL(t)}};return l.jsx("div",{style:{width:"100%",maxWidth:"340px",backgroundColor:le.card,padding:ce.md,borderRadius:de,boxShadow:ue,boxSizing:"border-box"},children:l.jsx("form",{onSubmit:e=>{e.preventDefault(),n(JSON.stringify(i))},style:{display:"flex",flexDirection:"column",gap:ce.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:ce.sm,textAlign:"center",fontFamily:se.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:ce.xs,fontSize:se.size.subtitle,fontFamily:se.primary,boxSizing:"border-box"},children:e.display_name}),l.jsx("input",{type:e.display_type,name:e.path,value:i[e.path],onChange:d,required:!0,style:{width:"100%",padding:ce.sm,border:"1px solid ".concat(le.muted),borderRadius:de,fontSize:se.size.body,fontFamily:se.primary,backgroundColor:le.background,boxSizing:"border-box"}})]}):"image"===e.display_type?l.jsxs(l.Fragment,{children:[l.jsx("label",{style:{display:"block",fontWeight:500,marginBottom:ce.xs,fontSize:se.size.subtitle,fontFamily:se.primary,boxSizing:"border-box"},children:e.display_name}),l.jsx("input",{type:"file",accept:"image/*",onChange:u,required:!0,style:{width:"100%",padding:ce.sm,border:"1px solid ".concat(le.muted),borderRadius:de,fontSize:se.size.body,fontFamily:se.primary,backgroundColor:le.background,boxSizing:"border-box"}}),s&&l.jsx("img",{loading:"lazy",src:s,alt:"Preview",style:{marginTop:ce.sm,width:"60px",height:"60px",objectFit:"cover",borderRadius:de,border:"1px solid ".concat(le.muted),boxSizing:"border-box"}})]}):"button"===e.display_type?l.jsx("button",{type:"submit",style:{width:"100%",backgroundColor:le.primary,color:"white",padding:ce.sm,fontSize:se.size.subtitle,fontWeight:500,borderRadius:de,border:"none",cursor:"pointer",fontFamily:se.primary,transition:"background 0.3s",boxSizing:"border-box"},onMouseOver:e=>e.target.style.backgroundColor="#0056b3",onMouseOut:e=>e.target.style.backgroundColor=le.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"},ye={fontSize:"16px",margin:"12px 0",color:"#555",lineHeight:"1.5",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},be={fontSize:"18px",fontStyle:"italic",margin:"16px 0",padding:"0 20px",borderLeft:"4px solid #1976d2",color:"#444",fontFamily:"Georgia, serif",transition:"all 0.3s ease"},ve={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"},Se={fontSize:"16px",margin:"12px 0",paddingLeft:"20px",color:"#555",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},we={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"},je={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"},Ce={margin:"16px 0",borderRadius:"8px",height:"300px",width:"100%",boxShadow:"0 2px 4px rgba(0, 0, 0, 0.1)",transition:"all 0.3s ease"},ke={margin:"16px 0",borderCollapse:"collapse",width:"100%",fontFamily:"Arial, sans-serif",border:"1px solid #dee2e6",transition:"all 0.3s ease"},Ie={margin:"16px 0",padding:"8px 0",color:"#555",fontFamily:"Arial, sans-serif",transition:"all 0.3s ease"},Fe={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"},Re=e.memo(o=>{var n;let{images:r=[],caption:i,css:a}=o;const[s,c]=e.useState(0),d=e.useCallback(()=>{c(e=>0===e?r.length-1:e-1)},[r]),u=e.useCallback(()=>{c(e=>e===r.length-1?0:e+1)},[r]);return r.length?l.jsxs("div",{style:{position:"relative",width:"100%",margin:(null==a?void 0:a.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=r[s])||void 0===n?void 0:n.url,alt:"".concat(i||"Image"," ").concat(s+1),style:F({width:"100%",height:"auto",objectFit:"cover",maxHeight:"400px",borderRadius:"8px"},a)}),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:r.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:r.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:r}=t;console.log("🚀 ~ MapBlockComponent ~ lat, lng:",o,n);const[i,a]=e.useState(null);if(e.useEffect(()=>{import("@vis.gl/react-google-maps").then(e=>{let{APIProvider:t,Map:o,Marker:n}=e;return a({APIProvider:t,Map:o,Marker:n})}).catch(e=>console.error("Error loading Google Maps:",e))},[]),!i)return l.jsx("div",{className:"p-4 text-gray-600",children:"Loading map..."});const{APIProvider:s,Map:c,Marker:d}=i;return l.jsx("div",{style:F({width:"100%",height:"300px",borderRadius:"8px",overflow:"hidden",marginBottom:"16px"},r),children:l.jsx(s,{apiKey:ae,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}})})})})}),Ee={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"]},Ae=e.memo(e=>{let{blocks:o,onScrollToBottom:n,sendMessage:r}=e;const i=(e,t)=>{var o,n,r,i,a,s;return"display_name"===t?(null==e||null===(i=e.data)||void 0===i||null===(a=i.elements)||void 0===a||null===(s=a.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===(r=n.find(e=>e.field===t))||void 0===r?void 0:r.value)||null},a=e=>{console.log("🚀 ~ CardPreview ~ block:",e);let a=null==e?void 0:e.outerCss;const s=(e=>{if(!e)return null;const t=e.toLowerCase();for(const[e,o]of Object.entries(Ee))if(o.includes(t)||e===t)return e;return null})(null==e?void 0:e.display_type)||e.type,c=e.add_display_name?i(e,"display_name")||"Unnamed Block":null,d=["image","map","form"].includes(s),u=e=>{let t=i(e,"url");t?window.open(i(e,"url"),"_blank","noopener,noreferrer"):(e=>{e||(r("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:i(e,"text")||(null==e?void 0:e.value)});case"paragraph":return l.jsx("p",{style:F(F(F({},ye),e.css[s]),{},{paddingInline:"8px",margin:0}),className:"text-gray-700",dangerouslySetInnerHTML:{__html:i(e,"text")||(null==e?void 0:e.value)}});case"list":return l.jsx("ul",{style:F(F(F({},Se),e.css[s]),{},{margin:0}),className:"list-disc pl-5",children:(i(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({},be),e.css[s]),{},{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 l.jsx(t.Button,{variant:"contained",style:F(F(F({marginBottom:"10px"},ve),e.css[s]),{},{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 o=i(e,"files")||[];if(!o.length){o=(Array.isArray(null==e?void 0:e.value)?e.value:[null==e?void 0:e.value]).filter(Boolean).map(e=>({url:e}))}return l.jsx(Re,{images:o,caption:i(e,"caption"),css:F(F({},we),e.css[s])});case"form":return l.jsxs("div",{style:F(F({},je),e.css[s]),className:"space-y-4",children:[l.jsx("p",{className:"font-bold",children:i(e,"title")||"Form"}),(i(e,"fields")||[]).map((e,o)=>l.jsx(t.TextField,{label:e.label,name:e.name,type:e.field_type||"text",defaultValue:e.default_value||e.value,pl