import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import { useUsersStore } from '@/stores/usersStore'

export const useIzinBedelOraniStore = defineStore('izinBedelOraniStore', () => {
  const usersStore = useUsersStore()

  const izinBedelOraniBaseForm = reactive<Record<string, any>>({
    ad: '',
    oran: 0,
    aciklama: '',
    aktif: true,
    appUserId: usersStore.userId
  })
  
  const izinBedelOraniForm = reactive<Record<string, any>>({})
  const izinBedelOraniSafeForm = reactive<Record<string, any>>({})
  const izinBedelOraniList = ref<Record<string, any>[]>([])
  const aktifIzinBedelOraniList = ref<Record<string, any>[]>([])
  const isNew = ref<boolean>(false)
  const izinBedelOraniLoaded = ref<boolean>(false)

  const ResetForm = () => {
    Object.assign(izinBedelOraniForm, izinBedelOraniBaseForm)
  }
  
  const SafeServerData = () => {
    Object.assign(izinBedelOraniSafeForm, izinBedelOraniForm)
  }

  const RestoreData = () => {
    Object.assign(izinBedelOraniForm, izinBedelOraniSafeForm)
  }

  const NewForm = () => {
    ResetForm()
    isNew.value = true
  }

  const EditForm = (item: Record<string, any>) => {
    Object.assign(izinBedelOraniForm, item)
    isNew.value = false
  }

  return {
    izinBedelOraniBaseForm,
    izinBedelOraniForm,
    izinBedelOraniSafeForm,
    izinBedelOraniList,
    aktifIzinBedelOraniList,
    isNew,
    izinBedelOraniLoaded,
    ResetForm,
    SafeServerData,
    RestoreData,
    NewForm,
    EditForm
  }
})
