import React, { useState, useContext } from "react"; import type { OperoChatMessage, OperoChatError } from "../types"; import { OperoChatContainer } from "./OperoChatContainer"; import { OperoChatHeader } from "./OperoChatHeader"; import { OperoChatMessages } from "./OperoChatMessages"; import { OperoChatInput } from "./OperoChatInput"; import { OperoDisclaimer } from "./OperoDisclaimer"; import { OperoPoweredBy } from "./OperoPoweredBy"; import { OperoErrorBanner } from "./OperoErrorBanner"; import { OperoProgressBanner } from "./OperoProgressBanner"; import { OperoConfirmationDialog } from "./OperoConfirmationDialog"; import { OperoSampleQuestions } from "./OperoSampleQuestions"; import { OperoChatHistoryDrawer } from "./OperoChatHistoryDrawer"; import { OperoChatContext } from "./OperoChatContext"; export interface OperoChatOverlayProps { // State isVisible: boolean; messages: OperoChatMessage[]; isLoading: boolean; isConnected: boolean; errorMessage: string | null; progressMessage: string | null; conversationTitle: string; // Actions onCloseChat: () => void; onSendMessage: (message: string) => Promise; onDismissError: () => void; onClearMessages: () => void; onError?: (error: OperoChatError) => void; onReaction?: ( messageId: string, reactionType: "thumbs_up" | "thumbs_down", ) => void; // Configuration customStyles?: any; // Sample Questions Configuration apiKey: string; apiEndpoint?: string; userEmail?: string; userRole?: string; filters?: any; questionCount?: number; // History Configuration showHistory?: boolean; } export const OperoChatOverlay: React.FC = ({ isVisible, messages, isLoading, isConnected, errorMessage, progressMessage, conversationTitle, onCloseChat, onSendMessage, onDismissError, onClearMessages, onError, onReaction, customStyles, apiKey, apiEndpoint, userEmail, userRole, filters, questionCount = 3, showHistory = true, }) => { const [showConfirmDialog, setShowConfirmDialog] = useState(false); // Get history data and drawer state from context const context = useContext(OperoChatContext); const { conversations, isLoadingHistory, hasMoreConversations, loadConversations, loadMoreConversations, loadConversation, isHistoryDrawerVisible, openHistoryDrawer, closeHistoryDrawer, } = context || {}; // Enhanced sample question handler that will automatically trigger analytics const handleSampleQuestionPress = async (question: string) => { // The analytics will be tracked automatically when onSendMessage is called // since it goes through the OperoChatService.sendMessage method await onSendMessage(question); }; const handleNewConversation = () => { // Show confirmation dialog only if messages exist if (messages.length > 0) { setShowConfirmDialog(true); } else { // No messages, clear immediately onClearMessages(); } }; const handleConfirmNewConversation = () => { setShowConfirmDialog(false); onClearMessages(); }; const handleCancelNewConversation = () => { setShowConfirmDialog(false); }; return ( <> {/* Full-screen chat overlay */} {/* Sample Questions - Show only when no messages */} {messages.length === 0 && apiKey && ( )} {/* Progress Banner */} {/* Error Banner */} {errorMessage && ( )} {/* Disclaimer */} {/* Powered by Banner */} {/* Confirmation Dialog */} {/* History Drawer */} {showHistory && ( {})} onConversationSelect={loadConversation || (() => {})} onLoadMore={loadMoreConversations || (() => {})} onOpen={loadConversations || (() => {})} customStyles={customStyles} /> )} ); };