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

export const useAppUserUnitValidationStore = defineStore(
  'appUserUnitValidationStore',
  () => {
    const appUserUnitStore = useAppUserUnitStore()
    const validationStore = useValidationStore()

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

    const FormCheck = (): boolean => {
      Object.assign(invalidTexts, {})
      validationStore.IsFieldEmpty(
        appUserUnitStore.appUserUnitForm,
        invalidTexts,
        'birimAdi',
        'Lütfen birim adını giriniz.'
      )
      isFormValid.value = Object.keys(invalidTexts).length === 0
      return isFormValid.value
    }

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