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

export const useSiteManagementPageValidationStore = defineStore('siteManagementPageValidationStore', () => {
  const siteManagementPageStore = useSiteManagementPageStore()
  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(siteManagementPageStore.pageForm,invalidTexts,'title', 'Menü için başlık belirlemelisiniz.')
    validationStore.IsFieldEmpty(siteManagementPageStore.pageForm,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
  }
})