import React, { useState } from 'react';
import { useUser } from '../auth/useUser';
import { ChatBotContext } from './ChatBotContext';
var MessageStatus;
(function (MessageStatus) {
    MessageStatus[MessageStatus["Sent"] = 0] = "Sent";
    MessageStatus[MessageStatus["Delivered"] = 1] = "Delivered";
    MessageStatus[MessageStatus["Error"] = -1] = "Error";
})(MessageStatus || (MessageStatus = {}));
export const ChatBotProvider = ({ children }) => {
    const defaultCreatedAt = new Date().toLocaleString([], { hour: '2-digit', minute: '2-digit', hour12: true });
    const defaultCreatedBy = { loading: false, name: 'AI Assistant' };
    const messageText = 'Welcome! How can I help you search our Product Documentation?';
    const welcomeMessage = {
        createdAt: defaultCreatedAt,
        createdBy: defaultCreatedBy,
        messageContent: messageText,
        messageStatus: MessageStatus.Sent,
        outgoing: false,
        messageText
    };
    const [messageHistory, setMessageHistory] = useState([]);
    const user = useUser();
    const createMessage = (messageContent, createdBy, messageText) => {
        const newMessage = {
            createdAt: new Date().toLocaleString([], { hour: '2-digit', minute: '2-digit', hour12: true }),
            createdBy,
            messageContent,
            messageText,
            messageStatus: MessageStatus.Sent,
            outgoing: createdBy.id === (user === null || user === void 0 ? void 0 : user.id),
        };
        return newMessage;
    };
    const addMessage = (messageContent, createdBy, messageText) => {
        const newMessage = createMessage(messageContent, createdBy, messageText);
        setMessageHistory((prevState) => [...prevState, newMessage]);
    };
    const removeMessageHistory = (messageContent, createdBy) => {
        setMessageHistory(() => []);
    };
    const removeLoadingMessage = () => {
        setMessageHistory((prevState) => prevState.filter((message) => !message.createdBy.loading));
    };
    return (React.createElement(ChatBotContext.Provider, { value: {
            messageHistory,
            addMessage,
            removeMessageHistory,
            removeLoadingMessage,
        } }, children));
};
//# sourceMappingURL=ChatBotProvider.js.map