<template>
  <div class='form-part form-title'>
    <div class='form-title-buttons'>
      <div class='button-c button-save' @click='SendForApprove'>Onaya Gönder</div>
    </div>
  </div>
</template>
<script setup lang='ts'>
  import { ref, reactive, onBeforeMount, computed } from 'vue'
  import { useRoute } from 'vue-router'

  const route = useRoute()
  import { useDataStore } from '@/stores/dataStore'

  const dataStore = useDataStore()
  import { useGlobalStore } from '@/stores/globalStore'

  const globalStore = useGlobalStore()
  import { useUsersStore } from '@/stores/usersStore'

  const usersStore = useUsersStore()
  import { useCustomerStore } from '../../stores/customerStore'

  const customerStore = useCustomerStore()

  const formData = reactive<Record<string, any>>({
    onayDurumuIslemTipiId: 6,
    aciklama: '',
    file: ''
  })

  const SendForApprove = async () => {
    let form: any
    let dataForm = new FormData()
    dataForm.append('onayDurumuIslemTipiId', formData.onayDurumuIslemTipiId)
    dataForm.append('appUserId', String(usersStore.selectedUserId()))
    dataForm.append('onaylayanKisiId', String(usersStore.userId))
    dataForm.append('file', formData.file)
    dataForm.append('aciklama', formData.aciklama)
    form = await dataStore.dataPost('AppUserOnayDurum/', {
      data: dataForm,
      headers: { 'Content-Type': 'multipart/form-data' },
      toast: { toast: 'Onay durumu başarıyla kaydedildi', type: 'success' }
    })

    if (form !== 'errorfalse') {
      if (route.name === 'UyeDetay' || route.name === 'Profil') {
        usersStore.userApproveId = formData.onayDurumuIslemTipiId
      } else usersStore.userSubApproveId = formData.onayDurumuIslemTipiId
    }
  }
</script>
