/** * Vanilla JS adapter for the chat widget * * Provides a simple API for non-framework usage. */ import { initChatWidget } from '../index.js'; import type { ChatWidgetConfig, PageContext, ChatWidgetAPI as WidgetInstance } from '../index.js'; export type { ChatWidgetConfig, PageContext }; /** * Widget instance tracker */ let widgetInstance: WidgetInstance | null = null; let containerElement: HTMLElement | null = null; /** * Initialize the chat widget * * @param config - Widget configuration * @returns The created DOM element */ export function init(config: ChatWidgetConfig): HTMLElement { // Clean up existing instance if any if (widgetInstance && containerElement) { destroy(); } // Create container containerElement = document.createElement('div'); containerElement.id = 'chat-widget-container'; containerElement.style.cssText = 'position: fixed; z-index: 1000;'; document.body.appendChild(containerElement); // Initialize widget widgetInstance = initChatWidget(containerElement, config); return containerElement; } /** * Destroy the chat widget */ export function destroy(): void { if (widgetInstance) { // Properly destroy widget to prevent memory leaks widgetInstance.destroy(); widgetInstance = null; } if (containerElement) { containerElement.remove(); containerElement = null; } } /** * Check if widget is initialized */ export function isInitialized(): boolean { return widgetInstance !== null; } // Global export for