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

export const useExamDataStore = defineStore('exam', () => {
  interface exam {
    main: { columns: String[] }
    education: { columns: String[] }
    career: { columns: String[] }
  }

  const examData = ref<exam>({
    main: { columns: [] },
    education: { columns: [] },
    career: { columns: [] }
  })

  const consend = ref<boolean>(false)
  const status = ref<string>('')

  const changeExamColumns = (system: String, val: String[]) => {
    if (system == 'main') examData.value.main.columns = val
    if (system == 'education') examData.value.education.columns = val
    if (system == 'career') examData.value.career.columns = val
    localStorage.setItem('exam', JSON.stringify(examData.value))
  }

  if (localStorage.getItem('exam') !== null) {
    examData.value = JSON.parse(localStorage.getItem('exam') || '{}')
  }

  const changeStatus = (val: string) => {
    status.value = val
  }

  return {
    examData,
    changeExamColumns,
    consend,
    status,
    changeStatus
  }
})
