UNPKG

@forbespro/lead-agent

Version:
2 lines (1 loc) 2.77 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("react/jsx-runtime"),c=require("framer-motion"),w=require("./index3.js"),r=require("react"),g=require("react-dom"),u=({initialMessages:f,onStageComplete:l,onGoalComplete:s,onSubmit:d,initialChatId:p,isOpen:n,onClose:m,onToggle:y,onOpenChange:b,currentProduct:h})=>{const t=r.useRef(null);r.useEffect(()=>{if(!n)return;if(window.matchMedia("(max-width: 768px)").matches){const i={position:document.body.style.position,top:document.body.style.top,width:document.body.style.width,overflow:document.body.style.overflow},a=window.scrollY;return document.body.style.position="fixed",document.body.style.top=`-${a}px`,document.body.style.width="100%",document.body.style.overflow="hidden",()=>{document.body.style.position=i.position||"",document.body.style.top=i.top||"",document.body.style.width=i.width||"",document.body.style.overflow=i.overflow||"",window.scrollTo(0,a)}}},[n]),r.useEffect(()=>{if(!t.current){const e=document.createElement("div");e.id="forbes-lead-agent-root",e.style.position="fixed",e.style.bottom="0",e.style.right="0",e.style.width="100%",e.style.zIndex="99999999999",e.setAttribute("aria-label","Forbes Professional Lead Agent Widget"),document.body.appendChild(e),t.current=e}return()=>{t.current&&document.body.contains(t.current)&&(document.body.removeChild(t.current),t.current=null)}},[]);const x=async e=>d?d(e):e;return t.current?g.createPortal(o.jsx(c.AnimatePresence,{mode:"wait",children:n&&o.jsxs(c.motion.div,{className:"fpl-fixed fpl-bottom-0 fpl-right-0 fpl-z-[99999999999] fpl-w-full fpl-max-w-96 fpl-pointer-events-none",initial:{opacity:0,scale:.9,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.8,y:10},transition:{type:"spring",stiffness:300,damping:45,duration:.3},children:[o.jsx("div",{className:"fpl-fixed fpl-inset-0 fpl-pointer-events-none",style:{background:"radial-gradient(circle at bottom right, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0) 70%)",zIndex:-1},"aria-hidden":"true"}),o.jsx("div",{className:"fpl-flex fpl-justify-end fpl-pointer-events-auto",children:o.jsx(w.ChatbotWidget,{initialMessages:f,onStageComplete:l,onGoalComplete:s,onSubmit:x,isOpen:n,onClose:m,onToggle:y,onOpenChange:b,initialChatId:p,title:"Forbes Professional Assistant",subtitle:"You can request a quote or ask a question.",currentProduct:h})}),process.env.NODE_ENV==="development"&&o.jsxs("div",{className:"fpl-mt-4 fpl-p-2 fpl-bg-gray-100 fpl-text-xs fpl-max-w-96 fpl-ml-auto fpl-mr-4 fpl-pointer-events-auto",children:[o.jsxs("p",{children:["onStageComplete defined: ",l?"✅":"❌"]}),o.jsxs("p",{children:["onGoalComplete defined: ",s?"✅":"❌"]})]})]})}),t.current):null};exports.LeadAgent=u;exports.default=u;