import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { useValidationStore } from '@/stores/validationStore'
import { usePiyangoTalihliStore } from '../stores/piyangoTalihliStore'
import { usePiyangoStore } from '../stores/piyangoStore'
import { useDateStore } from '@/stores/dateStore'

export const usePiyangoTalihliValidationStore = defineStore(
  'piyangoTalihliValidationStore',
  () => {
    const piyangoTalihliStore = usePiyangoTalihliStore()
    const validationStore = useValidationStore()
    const piyangoStore = usePiyangoStore()
    const dateStore = useDateStore()

    const userFormChanged = ref<boolean>(false)
    const isUserFormValid = ref<boolean>(true)
    const isFileFormValid = ref<boolean>(true)
    const userFormInvalidTexts = reactive<Record<string, any>>({})
    const fileFormInvalidTexts = reactive<Record<string, any>>({})

    const FileFormCheck = (): boolean => {
      Object.assign(userFormInvalidTexts, {})

      validationStore.IsFieldEmpty(
        piyangoTalihliStore.piyangoTalihliFileFormData,
        fileFormInvalidTexts,
        'excelFile',
        'Lütfen dosya seçiniz'
      )

      isFileFormValid.value = Object.keys(fileFormInvalidTexts).length === 0
      return isFileFormValid.value
    }

    return {
      userFormChanged,
      isUserFormValid,
      isFileFormValid,
      userFormInvalidTexts,
      fileFormInvalidTexts,
      FileFormCheck,
    }
  }
)
