import axios from 'axios';

const handleSendEmail = async (email) => {
    try {
        // Fetch chatHistory from localStorage
        const storedChatHistory = localStorage.getItem('chatHistory');
        
        // If it doesn't exist or is empty, return
        if (!storedChatHistory || storedChatHistory.length === 0) {
            console.error("Chat history is empty.");
            return;
        }
        
        const response = await axios.post('http://localhost:5000/exportChat', {
            email: email,
            chatHistory: JSON.parse(storedChatHistory) // Convert the stringified JSON to an object
        });

        console.log(response.data);

    } catch (error) {
        console.error("Error sending email:", error);
    }
};

export default handleSendEmail;