(function() {
'use strict';
// Prevent duplicate widgets
if (document.getElementById('base44-chatbot-widget')) return;
// Embed configuration directly
const widgetConfig = {"business_id":"68f0072fb3ff868b42eb02ca","greeting_message":"Hi! Welcome to KC Air Conditioning . How can I help you today?","placeholder_text":"Type your message...","primary_color":"#02caf2","position":"bottom-right","button_style":"circle","button_icon":"live-chat","button_size":"medium","window_size":"medium","animation":"fade","theme":"modern","show_badge":false,"pulse_effect":true,"custom_image_url":null,"fallback_message":"I'm not sure about that. Please contact us at {contact_email} for more help.","id":"68f0072f88172291f5ee30cf","created_date":"2025-10-15T20:42:23.823000","updated_date":"2025-10-15T21:48:07.925000","created_by_id":"68ee89252f34796ff678736e","created_by":"ramo1312@gmail.com","is_sample":false};
const chatbotId = 'chatbot_1760560942814_2lnl93uam';
const apiBaseUrl = 'https://chat-flow-ai-b643e540.base44.app';
const buttonIcon = '📞';
const customImageUrl = null;
const companyLogoUrl = null;
const enableContactCapture = false;
console.log('Chatbot widget loaded. API Base URL:', apiBaseUrl);
// Wait for DOM to be ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initChatbot);
} else {
initChatbot();
}
function initChatbot() {
const primaryColor = widgetConfig.primary_color;
let conversationId = null;
const visitorId = 'visitor_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
let messages = [{ role: 'assistant', content: widgetConfig.greeting_message }];
let isOpen = false;
let isLoading = false;
let showContactForm = enableContactCapture; // Initialize based on config
let visitorInfo = { email: '', phone: '' };
// Function to parse markdown links
function parseMessageLinks(text) {
return text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1');
}
// Create widget container with maximum z-index
const widgetContainer = document.createElement('div');
widgetContainer.id = 'base44-chatbot-widget';
widgetContainer.style.cssText = 'position: fixed; right: 20px; bottom: 20px; z-index: 2147483647; font-family: system-ui, -apple-system, sans-serif; pointer-events: none;';
// Create toggle button
const toggleButton = document.createElement('button');
toggleButton.id = 'base44-chat-toggle';
toggleButton.style.cssText = `
width: 60px;
height: 60px;
border-radius: 50%;
background: ${primaryColor};
border: none;
cursor: pointer;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.2s;
color: white;
font-size: 24px;
pointer-events: auto;
`;
// Set button content (custom image or icon)
if (customImageUrl) {
toggleButton.innerHTML = '';
} else {
toggleButton.innerHTML = buttonIcon;
}
toggleButton.onclick = window.toggleBase44Chat = function() {
isOpen = !isOpen;
const btn = document.getElementById('base44-chat-toggle');
if (btn) {
if (customImageUrl) {
// Keep image, just rotate or change opacity to show state
btn.style.transform = isOpen ? 'rotate(90deg)' : 'rotate(0deg)';
} else {
btn.innerHTML = isOpen ? '✕' : buttonIcon;
btn.style.fontSize = isOpen ? '28px' : '24px';
}
}
renderWidget();
};
// Create chat window
const chatWindow = document.createElement('div');
chatWindow.id = 'base44-chat-window';
chatWindow.style.cssText = `
position: absolute;
bottom: 80px;
right: 0;
width: 380px;
height: 600px;
background: white;
border-radius: 16px;
box-shadow: 0 10px 40px rgba(0,0,0,0.15);
display: none;
flex-direction: column;
overflow: hidden;
pointer-events: auto;
`;
// Header with logo
const header = document.createElement('div');
header.style.cssText = `
background: ${primaryColor};
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
`;
const logoHtml = companyLogoUrl
? '
'
: '