import type { Message } from "src/modules/chatbot/types/dialogue-message";
import { defineStore } from "pinia";
import { chatbotService } from "src/modules/chatbot/services/messageService";
import { ref } from "vue";
import { useI18n } from "vue-i18n";

export const useChatStore = defineStore("chat", () => {
  const messages = ref<Message[]>([]);
  const hasShownInstructions = ref(false);
  const { t } = useI18n();

  const sendMessage = async (userInput: string) => {
    const reply = await chatbotService.sendChatMessage(userInput);
    return reply;
  };

  const showInstructionsOnce = () => {
    if (!hasShownInstructions.value) {
      messages.value.push({
        text: t("chatbot.chat_initial_message"),
        sent: false,
        isThinking: false,
      });
      hasShownInstructions.value = true;
    }
  };

  return {
    messages,
    sendMessage,
    showInstructionsOnce,
  };
});
