// composables/chat-api.ts
import { useI18n } from "vue-i18n";
import { useChatbotStore } from "src/stores/chatbot-store";

export const useChatbotApi = () => {
    const chatbot_store = useChatbotStore();
    const { t } = useI18n();

    const sendMessage = async (user_message: string) => {
        // push user input
        chatbot_store.messages.push({
            text: user_message,
            sent: true,
            isThinking: false,
        })

        // automatically push chatbot pending reply
        chatbot_store.messages.push({
            text: t('chatbot.chat_thinking'),
            sent: false,
            isThinking: true
        })

        await chatbot_store.sendChatMessage(user_message);
    };

    return { 
        sendMessage,
    };
};
