<template>
  <list-table-content
    v-if="loaded"
    :tableHeader="tableHeader"
    formTitle="Üye Onay Logları"
    listText="Kayıt"
    :apiList="'AppUserOnayDurum/AppUserOnayDurumList/' + userId"
    apiText="Üye Onay Log Listesi"
    page="form"
    :refresh="customerStore.uyeOnayRefresh" />
</template>
<script setup lang="ts">
  import { ref, onBeforeMount, computed } from 'vue'
  import axios from 'axios'

  import { useDateStore } from '@/stores/dateStore'
  const dateStore = useDateStore()
  import { useGlobalStore } from '@/stores/globalStore'
  const globalStore = useGlobalStore()
  import { useUsersStore } from '@/stores/usersStore'
  const usersStore = useUsersStore()
  import { useCustomerStore } from '../../stores/customerStore'
  const customerStore = useCustomerStore()
  import { useCustomerService } from '../../service/customerService'
  const customerService = useCustomerService()
  import { useRoute } from 'vue-router'
  const route = useRoute()

  const loaded = ref<boolean>(false)

  const userId = ref<string | number>('')

  if (route.name === 'UyeYetkiliDetay') {
    userId.value = String(route.params.altUyeId)
  } else {
    if (usersStore.isPanelUser) userId.value = usersStore.selectedUserId()
    else userId.value = String(usersStore.userId)
  }

  const customerOnayIslemTipleri = computed<Record<string, any>[]>(() => {
    return customerStore.onayIslemTipleri
  })

  const tableHeader = ref<Record<string, any>[]>([
    {
      name: 'tarih',
      title: 'Tarih',
      compute: (v: Record<string, any>): string => {
        return dateStore.dateFormat({ pattern: 'dd-mm-yy', date: v.tarih })
      },
      sort: true,
      filter: {
        type: 'date',
        between: true
      },
      style:{width:'15%'}
    },
    {
      name: 'email',
      title: 'Kişi',
      sort: true,
      style:{width:'20%'}
    },
    {
      name: 'islemTipi',
      title: 'İşlem',
      sort: true,
      filter: {
        type: 'select',
        data: customerOnayIslemTipleri,
        listVal: 'id',
        listText: 'tipAdi',
        filterId: 'islemTipId'
      }
    },
    {
      name: 'aciklama',
      title: 'Açıklama',
      sort: true,
      style:{width:'35%'}
    },
    {
      dosyaUrl: 'aciklama',
      title: 'Dosya',
      computeHtml: (v: Record<string, any>) => {
        if (v.dosyaUrl !== null && v.dosyaUrl !== undefined) {
          return globalStore.TableCellDocument(v.dosyaUrl)
        }
      }
    }
  ])

  onBeforeMount(async () => {
    await customerService.GetCustomerOnayIslemTipleri()

    loaded.value = true
  })
</script>
