(function() { if (window.__LiveChatLoaded) return; window.__LiveChatLoaded = true; const WIDGET_ID = "livechat-iframe-" + Math.random().toString(36).substr(2, 9); const BUTTON_ID = "livechat-button-" + Math.random().toString(36).substr(2, 9); const BUBBLE_ID = "livechat-bubble-" + Math.random().toString(36).substr(2, 9); let iframe = null; let button = null; let bubble = null; // Create chat button function createButton() { if (button) return; button = document.createElement("div"); button.id = BUTTON_ID; button.innerHTML = ''; button.style.cssText = "position:fixed!important;bottom:20px!important;right:20px!important;width:56px!important;height:56px!important;border-radius:50%!important;background:#0492c2!important;color:white!important;border:none!important;cursor:pointer!important;display:flex!important;align-items:center!important;justify-content:center!important;box-shadow:0 4px 12px rgba(0,0,0,0.15)!important;z-index:2147483647!important;transition:transform 0.2s!important;pointer-events:auto!important;"; button.addEventListener("mouseenter", function() { button.style.transform = "scale(1.05)"; }); button.addEventListener("mouseleave", function() { button.style.transform = "scale(1)"; }); button.addEventListener("click", openChat); document.body.appendChild(button); } // Create iframe function createIframe() { if (iframe) return; const pageUrl = encodeURIComponent(window.location.href); const pageTitle = encodeURIComponent(document.title || 'Untitled Page'); iframe = document.createElement("iframe"); iframe.id = WIDGET_ID; iframe.src = "https://convo-flow-693a0c69.base44.app/WidgetEmbed?site_id=demo-site-1&embed=true&page_url=" + pageUrl + "&page_title=" + pageTitle; iframe.style.cssText = "position:fixed!important;bottom:20px!important;right:20px!important;z-index:2147483647!important;width:360px!important;height:520px!important;border:none!important;background:transparent!important;margin:0!important;padding:0!important;display:none!important;pointer-events:auto!important;"; iframe.allow = "microphone; camera"; document.body.appendChild(iframe); } // Open chat function openChat() { if (!iframe) createIframe(); iframe.style.display = "block"; if (button) button.style.display = "none"; } // Close chat function closeChat() { if (iframe) iframe.style.display = "none"; if (button) button.style.display = "flex"; } // Create proactive bubble function createBubble() { const bubbleShown = localStorage.getItem("livechat-bubble-shown"); if (bubbleShown || bubble) return; bubble = document.createElement("div"); bubble.id = BUBBLE_ID; const container = document.createElement("div"); container.style.cssText = "position:relative;background:white;padding:12px 16px;border-radius:12px;box-shadow:0 4px 12px rgba(0,0,0,0.15);max-width:240px;"; const closeBtn = document.createElement("button"); closeBtn.innerHTML = "×"; closeBtn.style.cssText = "position:absolute;top:4px;right:4px;background:none;border:none;color:#94a3b8;cursor:pointer;font-size:18px;line-height:1;padding:0;width:20px;height:20px;display:flex;align-items:center;justify-content:center;"; closeBtn.onclick = function() { bubble.remove(); localStorage.setItem("livechat-bubble-shown", "true"); }; const text = document.createElement("p"); text.style.cssText = "margin:0;color:#1e293b;font-size:14px;line-height:1.5;padding-right:16px;"; text.textContent = "Hi there! 👋 Need any help? We're here to assist you."; container.appendChild(closeBtn); container.appendChild(text); bubble.appendChild(container); bubble.style.cssText = "position:fixed!important;bottom:90px!important;right:20px!important;z-index:2147483646!important;animation:slideUp 0.3s ease-out!important;pointer-events:auto!important;cursor:pointer!important;"; const style = document.createElement("style"); style.textContent = "@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }"; document.head.appendChild(style); document.body.appendChild(bubble); localStorage.setItem("livechat-bubble-shown", "true"); bubble.addEventListener("click", function(e) { if (e.target.tagName !== "BUTTON") { bubble.remove(); openChat(); } }); } // Listen for messages from iframe window.addEventListener("message", function(event) { if (event.data === "livechat-close") { closeChat(); } }); // Initialize when DOM is ready function init() { if (document.body) { createButton(); setTimeout(createBubble, 5000); } else { document.addEventListener("DOMContentLoaded", function() { createButton(); setTimeout(createBubble, 5000); }); } } init(); })();