import { defineStore } from 'pinia';
import { ref, computed } from 'vue';

export const useSurveyStore = defineStore('survey', () => {
  const questions = ref<string[]>([]);
  const answers = ref<Record<string, string>>({});
  
  const totalQuestions = computed(() => questions.value.length);
  const answeredCount = computed(() => Object.keys(answers.value).length);
  const isComplete = computed(() => answeredCount.value === totalQuestions.value);

  function addQuestion(question: string) {
    questions.value.push(question);
  }
  
  function answerQuestion(question: string, answer: string) {
    if (questions.value.includes(question)) {
      answers.value[question] = answer;
    }
  }
  
  function resetSurvey() {
    answers.value = {};
  }
  
  return {
    questions,
    answers,
    totalQuestions,
    answeredCount,
    isComplete,
    addQuestion,
    answerQuestion,
    resetSurvey,
  };
});