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

export const useSiteManagementMenuValidationStore = defineStore('siteManagementMenuValidationStore', () => {
  const siteManagementMenuStore = useSiteManagementMenuStore()
  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(siteManagementMenuStore.menuItemData,invalidTexts,'title', 'Menü için başlık belirlemelisiniz.')
    validationStore.IsFieldEmpty(siteManagementMenuStore.menuItemData,invalidTexts,'slug', 'Tıklandığı zaman açılacak linki yazınız.')

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

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