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

export const usePiyangoMecraValidationStore = defineStore(
  'piyangoMecraValidationStore',
  () => {
    const piyangoMecraStore = usePiyangoMecraStore()
    const validationStore = useValidationStore()

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

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

      validationStore.IsFieldEmpty(
        piyangoMecraStore.piyangoMecraForm,
        invalidTexts,
        'mecraAdi',
        'Yayınlanacak mecranın adını yazınız.'
      )

      isFormValid.value = Object.keys(invalidTexts).length === 0
      return isFormValid.value
    }

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