import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { useValidationStore } from '@/stores/validationStore'
import { usePiyangoOnayStore } from '../stores/piyangoOnayStore'

export const usePiyangoOnayValidationStore = defineStore(
  'piyangoOnayValidationStore',
  () => {
    const validationStore = useValidationStore()
    const piyangoOnayStore = usePiyangoOnayStore()

    const formChanged = ref<boolean>(false)
    const isFormValid = ref<boolean>(true)
    const invalidTexts = reactive<Record<string, any>>({})

    const FormCheck = (): boolean => {
      Object.assign(invalidTexts, {})

      validationStore.IsFieldEmpty(
        piyangoOnayStore.piyangoOnayForm,
        invalidTexts,
        'onayDurumuIslemTipiId',
        'Bir işlem tipi seçmelisinz.'
      )
      isFormValid.value = Object.keys(invalidTexts).length === 0
      return isFormValid.value
    }

    return {
      formChanged,
      isFormValid,
      invalidTexts,
      FormCheck
    }
  }
)
